chiark / gitweb /
Make run_directory.c stat the place it is going to try to run.
[elogind.git] / klibc / klibc / arch / ia64 / setjmp.S
1 /*
2  * IA-64 specific setjmp/longjmp routines
3  *
4  * Inspired by setjmp.s from the FreeBSD kernel.
5  */
6
7 #define J_UNAT          0
8 #define J_NATS          0x8
9 #define J_PFS           0x10
10 #define J_BSP           0x18
11 #define J_RNAT          0x20
12 #define J_PREDS         0x28
13 #define J_LC            0x30
14 #define J_R4            0x38
15 #define J_R5            0x40
16 #define J_R6            0x48
17 #define J_R7            0x50
18 #define J_SP            0x58
19 #define J_F2            0x60
20 #define J_F3            0x70
21 #define J_F4            0x80
22 #define J_F5            0x90
23 #define J_F16           0xa0
24 #define J_F17           0xb0
25 #define J_F18           0xc0
26 #define J_F19           0xd0
27 #define J_F20           0xe0
28 #define J_F21           0xf0
29 #define J_F22           0x100
30 #define J_F23           0x110
31 #define J_F24           0x120
32 #define J_F25           0x130
33 #define J_F26           0x140
34 #define J_F27           0x150
35 #define J_F28           0x160
36 #define J_F29           0x170
37 #define J_F30           0x180
38 #define J_F31           0x190
39 #define J_FPSR          0x1a0
40 #define J_B0            0x1a8
41 #define J_B1            0x1b0
42 #define J_B2            0x1b8
43 #define J_B3            0x1c0
44 #define J_B4            0x1c8
45 #define J_B5            0x1d0
46 #define J_SIGMASK       0x1d8
47 #define J_SIGSET        0x1e0
48 #define J_GP            0x1f0
49         
50 // int setjmp(struct jmp_buffer *)
51 //
52 //  Setup a non-local goto.
53 //
54 // Description:
55 //
56 //  SetJump stores the current register set in the area pointed to
57 //  by "save".  It returns zero.  Subsequent calls to "LongJump" will
58 //  restore the registers and return non-zero to the same location.
59 //
60 // On entry, r32 contains the pointer to the jmp_buffer
61 //
62         .align 32
63         .global setjmp
64         .proc setjmp
65 setjmp:
66     //
67     //  Make sure buffer is aligned at 16byte boundary
68     //
69     add     r10 = -0x10,r0  ;;  // mask the lower 4 bits
70     and     r32 = r32, r10;; 
71     add     r32 = 0x10, r32;;   // move to next 16 byte boundary
72
73     add     r10 = J_PREDS, r32  // skip Unats & pfs save area
74     add     r11 = J_BSP, r32
75     //
76     //  save immediate context
77     //
78     mov     r2 = ar.bsp         // save backing store pointer
79     mov     r3 = pr             // save predicates
80     flushrs
81     ;;
82     //
83     // save user Unat register
84     //
85     mov     r16 = ar.lc         // save loop count register
86     mov     r14 = ar.unat       // save user Unat register
87
88     st8     [r10] = r3, J_LC-J_PREDS
89     st8     [r11] = r2, J_R4-J_BSP
90     ;;
91     st8     [r10] = r16, J_R5-J_LC
92     st8     [r32] = r14, J_NATS // Note: Unat at the 
93                                 // beginning of the save area
94     mov     r15 = ar.pfs
95     ;;
96     //
97     //  save preserved general registers & NaT's
98     //
99     st8.spill   [r11] = r4, J_R6-J_R4
100     ;;
101     st8.spill   [r10] = r5, J_R7-J_R5 
102     ;;
103     st8.spill   [r11] = r6, J_SP-J_R6
104     ;;
105     st8.spill   [r10] = r7, J_F3-J_R7 
106     ;;
107     st8.spill   [r11] = sp, J_F2-J_SP
108     ;;
109     //
110     // save spilled Unat and pfs registers
111     //
112     mov     r2 = ar.unat        // save Unat register after spill
113     ;;
114     st8     [r32] = r2, J_PFS-J_NATS    // save unat for spilled regs
115     ;;
116     st8     [r32] = r15         // save pfs
117     //
118     //  save floating registers 
119     //
120     stf.spill   [r11] = f2, J_F4-J_F2
121     stf.spill   [r10] = f3, J_F5-J_F3 
122     ;;
123     stf.spill   [r11] = f4, J_F16-J_F4
124     stf.spill   [r10] = f5, J_F17-J_F5 
125     ;;
126     stf.spill   [r11] = f16, J_F18-J_F16
127     stf.spill   [r10] = f17, J_F19-J_F17 
128     ;;
129     stf.spill   [r11] = f18, J_F20-J_F18
130     stf.spill   [r10] = f19, J_F21-J_F19 
131     ;;
132     stf.spill   [r11] = f20, J_F22-J_F20
133     stf.spill   [r10] = f21, J_F23-J_F21 
134     ;;
135     stf.spill   [r11] = f22, J_F24-J_F22
136     stf.spill   [r10] = f23, J_F25-J_F23 
137     ;;
138     stf.spill   [r11] = f24, J_F26-J_F24
139     stf.spill   [r10] = f25, J_F27-J_F25 
140     ;;
141     stf.spill   [r11] = f26, J_F28-J_F26
142     stf.spill   [r10] = f27, J_F29-J_F27 
143     ;;
144     stf.spill   [r11] = f28, J_F30-J_F28
145     stf.spill   [r10] = f29, J_F31-J_F29 
146     ;;
147     stf.spill   [r11] = f30, J_FPSR-J_F30
148     stf.spill   [r10] = f31, J_B0-J_F31     // size of f31 + fpsr
149     //
150     // save FPSR register & branch registers
151     //
152     mov     r2 = ar.fpsr    // save fpsr register
153     mov     r3 = b0 
154     ;;
155     st8     [r11] = r2, J_B1-J_FPSR
156     st8     [r10] = r3, J_B2-J_B0
157     mov     r2 = b1
158     mov     r3 = b2 
159     ;;
160     st8     [r11] = r2, J_B3-J_B1
161     st8     [r10] = r3, J_B4-J_B2
162     mov     r2 = b3
163     mov     r3 = b4 
164     ;;
165     st8     [r11] = r2, J_B5-J_B3
166     st8     [r10] = r3
167     mov     r2 = b5 
168     ;;
169     st8     [r11] = r2
170     ;;
171     //
172     // return
173     //
174     mov     r8 = r0         // return 0 from setjmp
175     mov     ar.unat = r14   // restore unat
176     br.ret.sptk b0
177     .endp setjmp
178
179 //
180 // void longjmp(struct jmp_buffer *, int val)
181 //
182 //  Perform a non-local goto.
183 //
184 // Description:
185 //
186 //  LongJump initializes the register set to the values saved by a
187 //  previous 'SetJump' and jumps to the return location saved by that
188 //  'SetJump'.  This has the effect of unwinding the stack and returning
189 //  for a second time to the 'SetJump'.
190 //
191         
192         .align 32
193         .global longjmp
194         .proc longjmp
195 longjmp:
196     //
197     //  Make sure buffer is aligned at 16byte boundary
198     //
199     add     r10 = -0x10,r0  ;;  // mask the lower 4 bits
200     and     r32 = r32, r10;; 
201     add     r32 = 0x10, r32;;   // move to next 16 byte boundary
202
203     //
204     // caching the return value as we do invala in the end
205     //
206     mov     r8 = r33            // return value
207
208     //
209     //  get immediate context
210     //
211     mov     r14 = ar.rsc        // get user RSC conf 
212     add     r10 = J_PFS, r32    // get address of pfs
213     add     r11 = J_NATS, r32
214     ;;
215     ld8     r15 = [r10], J_BSP-J_PFS    // get pfs
216     ld8     r2 = [r11], J_LC-J_NATS     // get unat for spilled regs
217     ;;
218     mov     ar.unat = r2
219     ;;
220     ld8     r16 = [r10], J_PREDS-J_BSP  // get backing store pointer
221     mov     ar.rsc = r0         // put RSE in enforced lazy 
222     mov     ar.pfs = r15
223     ;;
224     
225     //
226     // while returning from longjmp the BSPSTORE and BSP needs to be
227     // same and discard all the registers allocated after we did
228     // setjmp. Also, we need to generate the RNAT register since we
229     // did not flushed the RSE on setjmp.
230     //
231     mov     r17 = ar.bspstore   // get current BSPSTORE
232     ;;
233     cmp.ltu p6,p7 = r17, r16    // is it less than BSP of 
234 (p6)    br.spnt.few .flush_rse
235     mov     r19 = ar.rnat       // get current RNAT
236     ;;
237     loadrs                      // invalidate dirty regs
238     br.sptk.many    .restore_rnat       // restore RNAT
239
240 .flush_rse:
241     flushrs
242     ;;
243     mov     r19 = ar.rnat       // get current RNAT
244     mov     r17 = r16           // current BSPSTORE
245     ;;
246 .restore_rnat:
247     //
248     // check if RNAT is saved between saved BSP and curr BSPSTORE
249     //
250     mov     r18 = 0x3f
251     ;; 
252     dep     r18 = r18,r16,3,6   // get RNAT address
253     ;;
254     cmp.ltu p8,p9 = r18, r17    // RNAT saved on RSE
255     ;;
256 (p8)    ld8     r19 = [r18]     // get RNAT from RSE
257     ;;
258     mov     ar.bspstore = r16   // set new BSPSTORE 
259     ;;
260     mov     ar.rnat = r19       // restore RNAT
261     mov     ar.rsc = r14        // restore RSC conf
262
263
264     ld8     r3 = [r11], J_R4-J_LC       // get lc register
265     ld8     r2 = [r10], J_R5-J_PREDS    // get predicates
266     ;;
267     mov     pr = r2, -1
268     mov     ar.lc = r3
269     //
270     //  restore preserved general registers & NaT's
271     //
272     ld8.fill    r4 = [r11], J_R6-J_R4
273     ;;
274     ld8.fill    r5 = [r10], J_R7-J_R5 
275     ld8.fill    r6 = [r11], J_SP-J_R6
276     ;;
277     ld8.fill    r7 = [r10], J_F2-J_R7
278     ld8.fill    sp = [r11], J_F3-J_SP
279     ;;
280     //
281     //  restore floating registers 
282     //
283     ldf.fill    f2 = [r10], J_F4-J_F2
284     ldf.fill    f3 = [r11], J_F5-J_F3 
285     ;;
286     ldf.fill    f4 = [r10], J_F16-J_F4
287     ldf.fill    f5 = [r11], J_F17-J_F5 
288     ;;
289     ldf.fill    f16 = [r10], J_F18-J_F16
290     ldf.fill    f17 = [r11], J_F19-J_F17
291     ;;
292     ldf.fill    f18 = [r10], J_F20-J_F18
293     ldf.fill    f19 = [r11], J_F21-J_F19
294     ;;
295     ldf.fill    f20 = [r10], J_F22-J_F20
296     ldf.fill    f21 = [r11], J_F23-J_F21
297     ;;
298     ldf.fill    f22 = [r10], J_F24-J_F22
299     ldf.fill    f23 = [r11], J_F25-J_F23 
300     ;;
301     ldf.fill    f24 = [r10], J_F26-J_F24
302     ldf.fill    f25 = [r11], J_F27-J_F25
303     ;;
304     ldf.fill    f26 = [r10], J_F28-J_F26
305     ldf.fill    f27 = [r11], J_F29-J_F27
306     ;;
307     ldf.fill    f28 = [r10], J_F30-J_F28
308     ldf.fill    f29 = [r11], J_F31-J_F29 
309     ;;
310     ldf.fill    f30 = [r10], J_FPSR-J_F30
311     ldf.fill    f31 = [r11], J_B0-J_F31 ;;
312
313     //
314     // restore branch registers and fpsr
315     //
316     ld8     r16 = [r10], J_B1-J_FPSR    // get fpsr
317     ld8     r17 = [r11], J_B2-J_B0      // get return pointer
318     ;;
319     mov     ar.fpsr = r16
320     mov     b0 = r17
321     ld8     r2 = [r10], J_B3-J_B1
322     ld8     r3 = [r11], J_B4-J_B2
323     ;;
324     mov     b1 = r2
325     mov     b2 = r3
326     ld8     r2 = [r10], J_B5-J_B3
327     ld8     r3 = [r11]
328     ;;
329     mov     b3 = r2
330     mov     b4 = r3 
331     ld8     r2 = [r10]
332     ld8     r21 = [r32]         // get user unat
333     ;;
334     mov     b5 = r2
335     mov     ar.unat = r21
336
337     //
338     // invalidate ALAT
339     //
340     invala ;;
341
342     br.ret.sptk b0
343     .endp longjmp