4 ****************************************************************************
5 * Copyright IBM Corporation 1988, 1989 - All Rights Reserved *
7 * Permission to use, copy, modify, and distribute this software and its *
8 * documentation for any purpose and without fee is hereby granted, *
9 * provided that the above copyright notice appear in all copies and *
10 * that both that copyright notice and this permission notice appear in *
11 * supporting documentation, and that the name of IBM not be used in *
12 * advertising or publicity pertaining to distribution of the software *
13 * without specific, written prior permission. *
15 * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL *
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL IBM *
17 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY *
18 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER *
19 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING *
20 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *
21 ****************************************************************************
30 * 1. Registers R10..R31 and CR0..CR7 are saved
31 * 2. "struct savearea" must hold at least 3 pointers (long)
32 * 3. This code will only work on 32 bit machines (601..604), not 620
33 * 4. No floating point registers are saved
34 * 5. The save stack "frame" is bigger than absolutely necessary. The
35 * PowerPC [AIX] ABI needs this extra space.
39 * PowerPC Stack structure (according to apple)
41 * -----------------------------------------
44 * -----------------------------------------
45 * | Linkage area: (each row is 4 bytes)
46 * | Saved GPR 2 [saved by calling if imported routine,or pointer-based call]
49 * | Saved LR [ may be set by called ]
50 * | Saved CR [ may be set by called ]
51 * | Saved SP [ saved by calling ]
52 * ----------------------------------------- <-- SP
55 * -----------------------------------------
58 * -----------------------------------------
61 * ----------------------------------------- <-- SP
64 /* Mach-O assemblers */
65 #if !defined(NeXT) && !defined(__APPLE__)
98 #endif /* !NeXT && !__APPLE__ */
102 * savecontext(int (*f)(), struct savearea *save, char *newsp)
105 #define FRAME_SIZE (32*4)+(8*4)
106 #define FRAME_OFFSET (8*4)
108 #define TOP_OF_STACK (0*4)
112 #if defined(NeXT) || defined(__APPLE__)
115 lis r9,ha16(_PRE_Block) /* Disable interrupt fiddling */
117 stw r8,lo16(_PRE_Block)(r9)
121 lis r9,PRE_Block@ha /* Disable interrupt fiddling */
123 stw r8,PRE_Block@l(r9)
124 #endif /* NeXT || __APPLE__ */
125 subi r1,r1,FRAME_SIZE
128 stw r10,10*4+FRAME_OFFSET(r1) /* Save registers */
129 stw r11,11*4+FRAME_OFFSET(r1)
130 stw r12,12*4+FRAME_OFFSET(r1)
131 stw r13,13*4+FRAME_OFFSET(r1)
132 stw r14,14*4+FRAME_OFFSET(r1)
133 stw r15,15*4+FRAME_OFFSET(r1)
134 stw r16,16*4+FRAME_OFFSET(r1)
135 stw r17,17*4+FRAME_OFFSET(r1)
136 stw r18,18*4+FRAME_OFFSET(r1)
137 stw r19,19*4+FRAME_OFFSET(r1)
138 stw r20,20*4+FRAME_OFFSET(r1)
139 stw r21,21*4+FRAME_OFFSET(r1)
140 stw r22,22*4+FRAME_OFFSET(r1)
141 stw r23,23*4+FRAME_OFFSET(r1)
142 stw r24,24*4+FRAME_OFFSET(r1)
143 stw r25,25*4+FRAME_OFFSET(r1)
144 stw r26,26*4+FRAME_OFFSET(r1)
145 stw r27,27*4+FRAME_OFFSET(r1)
146 stw r28,28*4+FRAME_OFFSET(r1)
147 stw r29,29*4+FRAME_OFFSET(r1)
148 stw r30,30*4+FRAME_OFFSET(r1)
149 stw r31,31*4+FRAME_OFFSET(r1)
150 stw r1,TOP_OF_STACK(r4)
151 cmpi 0,r5,0 /* New stack specified? */
155 beq L1 /* No - don't muck with pointer */
161 * returnto(struct savearea *area)
163 #if defined(NeXT) || defined(__APPLE__)
169 #endif /* NeXT || __APPLE__ */
170 lwz r1,TOP_OF_STACK(r3) /* Update stack pointer */
171 lwz r0,RETURN(r3) /* Get return address */
175 lwz r10,10*4+FRAME_OFFSET(r1) /* Restore registers */
176 lwz r11,11*4+FRAME_OFFSET(r1)
177 lwz r12,12*4+FRAME_OFFSET(r1)
178 lwz r13,13*4+FRAME_OFFSET(r1)
179 lwz r14,14*4+FRAME_OFFSET(r1)
180 lwz r15,15*4+FRAME_OFFSET(r1)
181 lwz r16,16*4+FRAME_OFFSET(r1)
182 lwz r17,17*4+FRAME_OFFSET(r1)
183 lwz r18,18*4+FRAME_OFFSET(r1)
184 lwz r19,19*4+FRAME_OFFSET(r1)
185 lwz r20,20*4+FRAME_OFFSET(r1)
186 lwz r21,21*4+FRAME_OFFSET(r1)
187 lwz r22,22*4+FRAME_OFFSET(r1)
188 lwz r23,23*4+FRAME_OFFSET(r1)
189 lwz r24,24*4+FRAME_OFFSET(r1)
190 lwz r25,25*4+FRAME_OFFSET(r1)
191 lwz r26,26*4+FRAME_OFFSET(r1)
192 lwz r27,27*4+FRAME_OFFSET(r1)
193 lwz r28,28*4+FRAME_OFFSET(r1)
194 lwz r29,29*4+FRAME_OFFSET(r1)
195 lwz r30,30*4+FRAME_OFFSET(r1)
196 lwz r31,31*4+FRAME_OFFSET(r1)
197 #if defined(NeXT) || defined(__APPLE__)
198 lis r9,ha16(_PRE_Block) /* Re-enable interrupt fiddling */
200 stw r8,lo16(_PRE_Block)(r9)
202 lis r9,PRE_Block@ha /* Re-enable interrupt fiddling */
204 stw r8,PRE_Block@l(r9)
205 #endif /* NeXT || __APPLE__ */
206 addi r1,r1,FRAME_SIZE