clean up headers, obsd socket.h needs types.h
[arla.git] / lwp / process.ppc.S
blobb46f0c1f4253ad54607b81741af8d0fe02b1cd8b
1 /* $Id$ */
3 /*
4 ****************************************************************************
5 *        Copyright IBM Corporation 1988, 1989 - All Rights Reserved        *
6 *                                                                          *
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.                              *
14 *                                                                          *
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 ****************************************************************************
24 #include <config.h>
26 #undef RCSID
29 /* Comments:
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.
36  */
39  * PowerPC Stack structure (according to apple)
40  *
41  * -----------------------------------------
42  * | Parameter area
43  * |     [...]
44  * -----------------------------------------
45  * | Linkage area: (each row is 4 bytes)
46  * |  Saved GPR 2 [saved by calling if imported routine,or pointer-based call]
47  * |  Reserved
48  * |  Reserved
49  * |  Saved LR  [ may be set by called ]
50  * |  Saved CR  [ may be set by called ]
51  * |  Saved SP  [ saved by calling ]
52  * -----------------------------------------  <-- SP
53  * | Local variables
54  * |     [...]
55  * -----------------------------------------
56  * | Parameter area
57  * |     [...]
58  * -----------------------------------------
59  * | Linkage area:
60  * |     [...]
61  * -----------------------------------------  <-- SP
62  */
64 /* Mach-O assemblers */
65 #if !defined(NeXT) && !defined(__APPLE__)
66 #define r0    0
67 #define r1    1
68 #define r2    2
69 #define r3    3
70 #define r4    4
71 #define r5    5
72 #define r6    6
73 #define r7    7
74 #define r8    8
75 #define r9    9
76 #define r10   10
77 #define r11   11
78 #define r12   12
79 #define r13   13
80 #define r14   14
81 #define r15   15
82 #define r16   16
83 #define r17   17
84 #define r18   18
85 #define r19   19
86 #define r20   20
87 #define r21   21
88 #define r22   22
89 #define r23   23
90 #define r24   24
91 #define r25   25
92 #define r26   26
93 #define r27   27
94 #define r28   28
95 #define r29   29
96 #define r30   30
97 #define r31   31
98 #endif /* !NeXT && !__APPLE__ */
102  * savecontext(int (*f)(), struct savearea *save, char *newsp)
103  */
105 #define FRAME_SIZE    (32*4)+(8*4)
106 #define FRAME_OFFSET  (8*4)
108 #define TOP_OF_STACK  (0*4)
109 #define RETURN                (1*4)
110 #define CCR           (2*4)
112 #if defined(NeXT) || defined(__APPLE__)
113       .globl  _savecontext
114 _savecontext:
115       lis     r9,ha16(_PRE_Block)     /* Disable interrupt fiddling */
116       li      r8,1
117       stw     r8,lo16(_PRE_Block)(r9)
118 #else   
119       .globl  savecontext
120 savecontext:
121       lis     r9,PRE_Block@ha         /* Disable interrupt fiddling */
122       li      r8,1
123       stw     r8,PRE_Block@l(r9)
124 #endif /* NeXT || __APPLE__ */
125       subi    r1,r1,FRAME_SIZE
126       mfcr    r9
127       stw     r9,CCR(r4)
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? */
152       mflr    r0
153       stw     r0,RETURN(r4)
154       mtlr    r3
155       beq     L1                             /* No - don't muck with pointer */
157       mr      r1,r5
158 L1:   blr                                     /* Return */
161  * returnto(struct savearea *area)
162  */
163 #if defined(NeXT) || defined(__APPLE__)
164       .globl  _returnto
165 _returnto:
166 #else   
167       .globl  returnto
168 returnto:
169 #endif /* NeXT || __APPLE__ */
170       lwz     r1,TOP_OF_STACK(r3)             /* Update stack pointer */
171       lwz     r0,RETURN(r3)                   /* Get return address */
172       mtlr    r0
173       lwz     r4,CCR(r3)
174       mtcrf   0xFF,r4
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 */
199       li      r8,0
200       stw     r8,lo16(_PRE_Block)(r9)
201 #else   
202       lis     r9,PRE_Block@ha         /* Re-enable interrupt fiddling */
203       li      r8,0
204       stw     r8,PRE_Block@l(r9)
205 #endif /* NeXT || __APPLE__ */
206       addi    r1,r1,FRAME_SIZE
207       blr