]>
Commit | Line | Data |
---|---|---|
92f5a8d4 | 1 | /******************************************************* |
f67539c2 TL |
2 | * ------------------------------------------------- * |
3 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * | |
4 | * ------------------------------------------------- * | |
5 | * | 0 | 8 | 16 | 24 | * | |
6 | * ------------------------------------------------- * | |
7 | * | t.fctx | t.data | r2 | r6 | * | |
8 | * ------------------------------------------------- * | |
9 | * ------------------------------------------------- * | |
10 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * | |
11 | * ------------------------------------------------- * | |
12 | * | 32 | 40 | 48 | 56 | * | |
13 | * ------------------------------------------------- * | |
14 | * | r7 | r8 | r9 | r10 | * | |
15 | * ------------------------------------------------- * | |
16 | * ------------------------------------------------- * | |
17 | * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * | |
18 | * ------------------------------------------------- * | |
19 | * | 64 | 72 | 80 | 88 | * | |
20 | * ------------------------------------------------- * | |
21 | * | r11 | r12 | r13 | r14 | * | |
22 | * ------------------------------------------------- * | |
23 | * ------------------------------------------------- * | |
24 | * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * | |
25 | * ------------------------------------------------- * | |
26 | * | 96 | 104 | 112 | 120 | * | |
27 | * ------------------------------------------------- * | |
28 | * | f8 | f9 | f10 | f11 | * | |
29 | * ------------------------------------------------- * | |
30 | * ------------------------------------------------- * | |
31 | * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * | |
32 | * ------------------------------------------------- * | |
33 | * | 128 | 136 | 144 | 152 | * | |
34 | * ------------------------------------------------- * | |
35 | * | f12 | f13 | f14 | f15 | * | |
36 | * ------------------------------------------------- * | |
37 | * ------------------------------------------------- * | |
38 | * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * | |
39 | * ------------------------------------------------- * | |
40 | * | 160 | 168 | 176 | | * | |
41 | * ------------------------------------------------- * | |
42 | * | fpc | pc | | | * | |
43 | * ------------------------------------------------- * | |
44 | *******************************************************/ | |
45 | ||
92f5a8d4 | 46 | .text |
f67539c2 | 47 | .align 8 |
92f5a8d4 TL |
48 | .global ontop_fcontext |
49 | .type ontop_fcontext, @function | |
50 | ||
f67539c2 TL |
51 | #define ARG_OFFSET 0 |
52 | #define GR_OFFSET 16 | |
53 | #define R14_OFFSET 88 | |
54 | #define FP_OFFSET 96 | |
55 | #define FPC_OFFSET 160 | |
56 | #define PC_OFFSET 168 | |
57 | #define CONTEXT_SIZE 176 | |
58 | ||
59 | ||
60 | /* | |
61 | ||
62 | typedef void* fcontext_t; | |
63 | ||
64 | struct transfer_t { | |
65 | fcontext_t fctx; | |
66 | void * data; | |
67 | }; | |
68 | ||
69 | transfer_t ontop_fcontext( fcontext_t const to, | |
70 | void * vp, | |
71 | transfer_t (* fn)( transfer_t) ); | |
72 | ||
73 | Incoming args | |
74 | r2 - Hidden argument to the location where the return transfer_t needs to be returned | |
75 | r3 - Target context | |
76 | r4 - Data pointer | |
77 | r5 - Function to be executed | |
78 | ||
79 | This implementation assumes that ontop_fcontext will never be called with target contexts | |
80 | created via make_fcontext. | |
81 | ||
82 | */ | |
92f5a8d4 TL |
83 | |
84 | ontop_fcontext: | |
f67539c2 TL |
85 | /* Reserve stack space to store the current context. */ |
86 | aghi %r15,-CONTEXT_SIZE | |
87 | ||
88 | /* Save the argument register holding the location of the return value. */ | |
89 | stg %r2,GR_OFFSET(%r15) | |
90 | ||
91 | /* Save the call-saved general purpose registers. */ | |
92 | stmg %r6,%r14,GR_OFFSET+8(%r15) | |
93 | ||
94 | /* Save call-saved floating point registers. */ | |
95 | std %f8,FP_OFFSET(%r15) | |
96 | std %f9,FP_OFFSET+8(%r15) | |
97 | std %f10,FP_OFFSET+16(%r15) | |
98 | std %f11,FP_OFFSET+24(%r15) | |
99 | std %f12,FP_OFFSET+32(%r15) | |
100 | std %f13,FP_OFFSET+40(%r15) | |
101 | std %f14,FP_OFFSET+48(%r15) | |
102 | std %f15,FP_OFFSET+56(%r15) | |
103 | ||
104 | /* Save the return address as current pc. */ | |
105 | stg %r14,PC_OFFSET(%r15) | |
106 | ||
107 | /* Save the floating point control register. */ | |
108 | stfpc FPC_OFFSET(%r15) | |
109 | ||
110 | /* Backup the stack pointer pointing to the old context-data into r1. */ | |
111 | lgr %r1,%r15 | |
112 | ||
113 | /* Load the new context pointer as stack pointer. */ | |
114 | lgr %r15,%r3 | |
115 | ||
116 | /* Restore the call-saved GPRs from the new context. */ | |
117 | lmg %r6,%r14,GR_OFFSET+8(%r15) | |
118 | ||
119 | /* Restore call-saved floating point registers. */ | |
120 | ld %f8,FP_OFFSET(%r15) | |
121 | ld %f9,FP_OFFSET+8(%r15) | |
122 | ld %f10,FP_OFFSET+16(%r15) | |
123 | ld %f11,FP_OFFSET+24(%r15) | |
124 | ld %f12,FP_OFFSET+32(%r15) | |
125 | ld %f13,FP_OFFSET+40(%r15) | |
126 | ld %f14,FP_OFFSET+48(%r15) | |
127 | ld %f15,FP_OFFSET+56(%r15) | |
128 | ||
129 | /* Load the floating point control register. */ | |
130 | lfpc FPC_OFFSET(%r15) | |
131 | ||
132 | /* Store the transfer_t values located in the saved context. */ | |
133 | stg %r1,0(%r1) /* transfer_t.fctx = old context */ | |
134 | stg %r4,8(%r1) /* transfer_t.data = data */ | |
135 | ||
136 | /* Set up the arguments for the target function. */ | |
137 | lg %r2,GR_OFFSET(%r15) | |
138 | lgr %r3,%r1 | |
139 | ||
140 | /* Deallocate the context. */ | |
141 | aghi %r15,CONTEXT_SIZE | |
142 | ||
143 | br %r5 | |
92f5a8d4 TL |
144 | |
145 | .size ontop_fcontext,.-ontop_fcontext | |
92f5a8d4 | 146 | .section .note.GNU-stack,"",%progbits |