Mercurial > pub > dyncall > dyncall
comparison doc/disas_examples/mips.eabi.disas @ 327:c0390dc85a07
- doc: added disassembly examples for many platforms and calling conventions, for reference
author | Tassilo Philipp |
---|---|
date | Fri, 22 Nov 2019 23:08:59 +0100 |
parents | |
children | 06c9adae114d |
comparison
equal
deleted
inserted
replaced
326:09aaa2e774cd | 327:c0390dc85a07 |
---|---|
1 ; #include <stdlib.h> | |
2 ; | |
3 ; void leaf_call(int b, int c, int d, int e, int f, int g, int h) | |
4 ; { | |
5 ; } | |
6 ; | |
7 ; void nonleaf_call(int a, int b, int c, int d, int e, int f, int g, int h) | |
8 ; { | |
9 ; /* use some local data */ | |
10 ; *(char*)alloca(220) = 'L'; | |
11 ; leaf_call(b, c, d, e, f, g, h); | |
12 ; } | |
13 ; | |
14 ; int main() | |
15 ; { | |
16 ; nonleaf_call(0, 1, 2, 3, 4, 5, 6, 7); | |
17 ; return 0; | |
18 ; } | |
19 | |
20 | |
21 | |
22 ; output from psptoolchain-20111215-psp w/ gcc 4.9.3 | |
23 | |
24 00000000 <leaf_call>: | |
25 0: 27bdffd8 addiu sp,sp,-40 | |
26 4: afbe0024 sw s8,36(sp) | |
27 8: 03a0f021 move s8,sp | |
28 c: afc40000 sw a0,0(s8) | |
29 10: afc50004 sw a1,4(s8) | |
30 14: afc60008 sw a2,8(s8) | |
31 18: afc7000c sw a3,12(s8) | |
32 1c: afc80010 sw t0,16(s8) | |
33 20: afc90014 sw t1,20(s8) | |
34 24: afca0018 sw t2,24(s8) | |
35 28: 03c0e821 move sp,s8 | |
36 2c: 8fbe0024 lw s8,36(sp) | |
37 30: 27bd0028 addiu sp,sp,40 | |
38 34: 03e00008 jr ra | |
39 38: 00000000 nop | |
40 | |
41 0000003c <nonleaf_call>: | |
42 3c: 27bdffd8 addiu sp,sp,-40 ; | | |
43 40: afbf0024 sw ra,36(sp) ; | | |
44 44: afbe0020 sw s8,32(sp) ; | prolog | |
45 48: 03a0f021 move s8,sp ; / frame pointer (note: with offset to frame start, but static compared to sp) | |
46 4c: afc40000 sw a0,0(s8) ; \ | |
47 50: afc50004 sw a1,4(s8) ; | | |
48 54: afc60008 sw a2,8(s8) ; | | |
49 58: afc7000c sw a3,12(s8) ; | | |
50 5c: afc80010 sw t0,16(s8) ; | in args 0,1,2,3,4,5,6,7 -> temp space in local area | |
51 60: afc90014 sw t1,20(s8) ; | | |
52 64: afca0018 sw t2,24(s8) ; | | |
53 68: afcb001c sw t3,28(s8) ; | | |
54 6c: 27bdff18 addiu sp,sp,-232 ; alloca(220) - with padding to guarantee alignment | |
55 70: 03a01021 move v0,sp ; | | |
56 74: 24420007 addiu v0,v0,7 ; | | |
57 78: 000210c2 srl v0,v0,0x3 ; | start of alloca()'d memory -> v1, by ... | |
58 7c: 000210c0 sll v0,v0,0x3 ; | ... using v0 as helper to align to 8b | |
59 80: 00401821 move v1,v0 ; | | |
60 84: 2402004c li v0,76 ; 'L' -> v0, and... | |
61 88: a0620000 sb v0,0(v1) ; ... store in local area (of alloca()'d space) | |
62 8c: 8fc40004 lw a0,4(s8) ; | | |
63 90: 8fc50008 lw a1,8(s8) ; | | |
64 94: 8fc6000c lw a2,12(s8) ; | | |
65 98: 8fc70010 lw a3,16(s8) ; | arg 0,1,2,3,4,5,6 (fetched from local area stored to above) | |
66 9c: 8fc80014 lw t0,20(s8) ; | (t0 = a4) | |
67 a0: 8fc90018 lw t1,24(s8) ; | (t1 = a5) | |
68 a4: 8fca001c lw t2,28(s8) ; | (t2 = a6) | |
69 a8: 0c000000 jal 0 <leaf_call> ; call and ret addr -> ra | |
70 ac: 00000000 nop ; branch delay slot | |
71 b0: 03c0e821 move sp,s8 ; | | |
72 b4: 8fbf0024 lw ra,36(sp) ; | | |
73 b8: 8fbe0020 lw s8,32(sp) ; | | |
74 bc: 27bd0028 addiu sp,sp,40 ; | epilog | |
75 c0: 03e00008 jr ra ; | | |
76 c4: 00000000 nop ; | branch delay slot | |
77 | |
78 000000c8 <main>: | |
79 c8: 27bdfff8 addiu sp,sp,-8 ; | | |
80 cc: afbf0004 sw ra,4(sp) ; | | |
81 d0: afbe0000 sw s8,0(sp) ; | prolog | |
82 d4: 03a0f021 move s8,sp ; | frame pointer (note: with offset to frame start, but static compared to sp) | |
83 d8: 00002021 move a0,zero ; arg 0 | |
84 dc: 24050001 li a1,1 ; arg 1 | |
85 e0: 24060002 li a2,2 ; arg 2 | |
86 e4: 24070003 li a3,3 ; arg 3 | |
87 e8: 24080004 li t0,4 ; arg 4 (t0 = a4) | |
88 ec: 24090005 li t1,5 ; arg 5 (t1 = a5) | |
89 f0: 240a0006 li t2,6 ; arg 6 (t2 = a6) | |
90 f4: 240b0007 li t3,7 ; arg 7 (t3 = a7) | |
91 f8: 0c000000 jal 0 <leaf_call> ; call and ret addr -> ra | |
92 fc: 00000000 nop ; branch delay slot | |
93 100: 00001021 move v0,zero ; return value | |
94 104: 03c0e821 move sp,s8 ; | | |
95 108: 8fbf0004 lw ra,4(sp) ; | | |
96 10c: 8fbe0000 lw s8,0(sp) ; | | |
97 110: 27bd0008 addiu sp,sp,8 ; | epilog | |
98 114: 03e00008 jr ra ; | | |
99 118: 00000000 nop ; | branch delay slot | |
100 | |
101 | |
102 | |
103 ; ------------- as above but more args to use stack params -----------> | |
104 | |
105 ; #include <stdlib.h> | |
106 ; | |
107 ; void leaf_call(int b, int c, int d, int e, int f, int g, int h, int i, int j) | |
108 ; { | |
109 ; } | |
110 ; | |
111 ; void nonleaf_call(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j) | |
112 ; { | |
113 ; /* use some local data */ | |
114 ; *(char*)alloca(220) = 'L'; | |
115 ; leaf_call(b, c, d, e, f, g, h, i, j); | |
116 ; } | |
117 ; | |
118 ; int main() | |
119 ; { | |
120 ; nonleaf_call(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); | |
121 ; return 0; | |
122 ; } | |
123 | |
124 | |
125 | |
126 ; output from psptoolchain-20111215-psp w/ gcc 4.9.3 | |
127 | |
128 00000000 <leaf_call>: | |
129 0: 27bdffd8 addiu sp,sp,-40 | |
130 4: afbe0024 sw s8,36(sp) | |
131 8: 03a0f021 move s8,sp | |
132 c: afc40000 sw a0,0(s8) | |
133 10: afc50004 sw a1,4(s8) | |
134 14: afc60008 sw a2,8(s8) | |
135 18: afc7000c sw a3,12(s8) | |
136 1c: afc80010 sw t0,16(s8) | |
137 20: afc90014 sw t1,20(s8) | |
138 24: afca0018 sw t2,24(s8) | |
139 28: afcb001c sw t3,28(s8) | |
140 2c: 03c0e821 move sp,s8 | |
141 30: 8fbe0024 lw s8,36(sp) | |
142 34: 27bd0028 addiu sp,sp,40 | |
143 38: 03e00008 jr ra | |
144 3c: 00000000 nop | |
145 | |
146 00000040 <nonleaf_call>: | |
147 40: 27bdffd0 addiu sp,sp,-48 ; | | |
148 44: afbf002c sw ra,44(sp) ; | | |
149 48: afbe0028 sw s8,40(sp) ; | prolog | |
150 4c: 03a0f021 move s8,sp ; / frame pointer (note: with offset to frame start, but static compared to sp) | |
151 50: afc40008 sw a0,8(s8) ; \ | |
152 54: afc5000c sw a1,12(s8) ; | | |
153 58: afc60010 sw a2,16(s8) ; | | |
154 5c: afc70014 sw a3,20(s8) ; | | |
155 60: afc80018 sw t0,24(s8) ; | in args 0,1,2,3,4,5,6,7 -> temp space in local area | |
156 64: afc9001c sw t1,28(s8) ; | | |
157 68: afca0020 sw t2,32(s8) ; | | |
158 6c: afcb0024 sw t3,36(s8) ; | | |
159 70: 27bdff18 addiu sp,sp,-232 ; alloca(220) - with padding to guarantee alignment | |
160 74: 27a20008 addiu v0,sp,8 ; | | |
161 78: 24420007 addiu v0,v0,7 ; | | |
162 7c: 000210c2 srl v0,v0,0x3 ; | start of alloca()'d memory -> v1, by ... | |
163 80: 000210c0 sll v0,v0,0x3 ; | ... using v0 as helper to align to 8b | |
164 84: 00401821 move v1,v0 ; | | |
165 88: 2402004c li v0,76 ; 'L' -> v0, and... | |
166 8c: a0620000 sb v0,0(v1) ; ... store in local area (of alloca()'d space) | |
167 90: 8fc20034 lw v0,52(s8) ; arg 8 (fetched from prev frame's param area), and ... | |
168 94: afa20000 sw v0,0(sp) ; ... "pushed" onto stack | |
169 98: 8fc4000c lw a0,12(s8) ; | | |
170 9c: 8fc50010 lw a1,16(s8) ; | | |
171 a0: 8fc60014 lw a2,20(s8) ; | | |
172 a4: 8fc70018 lw a3,24(s8) ; | arg 0,1,2,3,4,5,6 (fetched from local area stored to above) | |
173 a8: 8fc8001c lw t0,28(s8) ; | (t0 = a4) | |
174 ac: 8fc90020 lw t1,32(s8) ; | (t1 = a5) | |
175 b0: 8fca0024 lw t2,36(s8) ; | (t2 = a6) | |
176 b4: 8fcb0030 lw t3,48(s8) ; | (t3 = a7) | |
177 b8: 0c000000 jal 0 <leaf_call> ; call and ret addr -> ra | |
178 bc: 00000000 nop ; branch delay slot | |
179 c0: 03c0e821 move sp,s8 ; | | |
180 c4: 8fbf002c lw ra,44(sp) ; | | |
181 c8: 8fbe0028 lw s8,40(sp) ; | | |
182 cc: 27bd0030 addiu sp,sp,48 ; | epilog | |
183 d0: 03e00008 jr ra ; | | |
184 d4: 00000000 nop ; | branch delay slot | |
185 | |
186 000000d8 <main>: | |
187 d8: 27bdfff0 addiu sp,sp,-16 ; | | |
188 dc: afbf000c sw ra,12(sp) ; | | |
189 e0: afbe0008 sw s8,8(sp) ; | prolog | |
190 e4: 03a0f021 move s8,sp ; | frame pointer (note: with offset to frame start, but static compared to sp) | |
191 e8: 24020008 li v0,8 ; arg 8 | |
192 ec: afa20000 sw v0,0(sp) ; ... "pushed" onto stack | |
193 f0: 24020009 li v0,9 ; arg 9 | |
194 f4: afa20004 sw v0,4(sp) ; ... "pushed" onto stack | |
195 f8: 00002021 move a0,zero ; arg 0 | |
196 fc: 24050001 li a1,1 ; arg 1 | |
197 100: 24060002 li a2,2 ; arg 2 | |
198 104: 24070003 li a3,3 ; arg 3 | |
199 108: 24080004 li t0,4 ; arg 4 (t0 = a4) | |
200 10c: 24090005 li t1,5 ; arg 5 (t1 = a5) | |
201 110: 240a0006 li t2,6 ; arg 6 (t2 = a6) | |
202 114: 240b0007 li t3,7 ; arg 7 (t3 = a7) | |
203 118: 0c000000 jal 0 <leaf_call> ; call and ret addr -> ra | |
204 11c: 00000000 nop ; branch delay slot | |
205 120: 00001021 move v0,zero ; return value | |
206 124: 03c0e821 move sp,s8 ; | | |
207 128: 8fbf000c lw ra,12(sp) ; | | |
208 12c: 8fbe0008 lw s8,8(sp) ; | | |
209 130: 27bd0010 addiu sp,sp,16 ; | epilog | |
210 134: 03e00008 jr ra ; | | |
211 138: 00000000 nop ; | branch delay slot | |
212 | |
213 | |
214 | |
215 ; ------------- with var args to see spilling -----------> | |
216 | |
217 ; #include <stdlib.h> | |
218 ; #include <stdarg.h> | |
219 ; | |
220 ; void leaf_call(int b, int c, int d, int e, int f, int g, int h, int i, int j) | |
221 ; { | |
222 ; } | |
223 ; | |
224 ; void nonleaf_call(int a, ...) | |
225 ; { | |
226 ; int b, c, d, e, f, g, h, i, j; | |
227 ; va_list ap; | |
228 ; va_start(ap, a); | |
229 ; b = va_arg(ap, int); | |
230 ; c = va_arg(ap, int); | |
231 ; d = va_arg(ap, int); | |
232 ; e = va_arg(ap, int); | |
233 ; f = va_arg(ap, int); | |
234 ; g = va_arg(ap, int); | |
235 ; h = va_arg(ap, int); | |
236 ; i = va_arg(ap, int); | |
237 ; j = va_arg(ap, int); | |
238 ; /* use some local data */ | |
239 ; *(char*)alloca(220) = 'L'; | |
240 ; leaf_call(b, c, d, e, f, g, h, i, j); | |
241 ; } | |
242 ; | |
243 ; int main() | |
244 ; { | |
245 ; nonleaf_call(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); | |
246 ; return 0; | |
247 ; } | |
248 | |
249 | |
250 | |
251 ; output from psptoolchain-20111215-psp w/ gcc 4.9.3 | |
252 | |
253 00000000 <leaf_call>: | |
254 0: 27bdffd8 addiu sp,sp,-40 | |
255 4: afbe0024 sw s8,36(sp) | |
256 8: 03a0f021 move s8,sp | |
257 c: afc40000 sw a0,0(s8) | |
258 10: afc50004 sw a1,4(s8) | |
259 14: afc60008 sw a2,8(s8) | |
260 18: afc7000c sw a3,12(s8) | |
261 1c: afc80010 sw t0,16(s8) | |
262 20: afc90014 sw t1,20(s8) | |
263 24: afca0018 sw t2,24(s8) | |
264 28: afcb001c sw t3,28(s8) | |
265 2c: 03c0e821 move sp,s8 | |
266 30: 8fbe0024 lw s8,36(sp) | |
267 34: 27bd0028 addiu sp,sp,40 | |
268 38: 03e00008 jr ra | |
269 3c: 00000000 nop | |
270 | |
271 00000040 <nonleaf_call>: | |
272 40: 27bdffa0 addiu sp,sp,-96 ; | leaving 32b extra space adjacent to prev frame's param area for spilling | |
273 44: afbf003c sw ra,60(sp) ; | | |
274 48: afbe0038 sw s8,56(sp) ; | prolog | |
275 4c: 03a0f021 move s8,sp ; / frame pointer (note: with offset to frame start, but static compared to sp) | |
276 50: afc50044 sw a1,68(s8) ; \ | |
277 54: afc60048 sw a2,72(s8) ; | | |
278 58: afc7004c sw a3,76(s8) ; | | |
279 5c: afc80050 sw t0,80(s8) ; | in args 1,2,3,4,5,6,7 -> spill area in current frame (adjacent to prev frame's param area) | |
280 60: afc90054 sw t1,84(s8) ; | | |
281 64: afca0058 sw t2,88(s8) ; | | |
282 68: afcb005c sw t3,92(s8) ; | | |
283 6c: afc40030 sw a0,48(s8) ; in arg 0 -> temp space in local area | |
284 70: 27c20060 addiu v0,s8,96 ; v0 initialized to point ... | |
285 74: 2442ffe4 addiu v0,v0,-28 ; ... to start of spill area (96 - 28 = 68, where we spilled a1) | |
286 78: afc2002c sw v0,44(s8) ; store read ptr in local area | |
287 7c: 8fc2002c lw v0,44(s8) ; | get read pointer in v0 (pointless here, but part of following pattern) ... | |
288 80: 24430004 addiu v1,v0,4 ; | ... advance ... | |
289 84: afc3002c sw v1,44(s8) ; | in arg 1 ... store again ... | |
290 88: 8c420000 lw v0,0(v0) ; | ... arg -> v0 (using pre-inc read location), then ... | |
291 8c: afc20008 sw v0,8(s8) ; / ... write to local area on stack for later | |
292 90: 8fc2002c lw v0,44(s8) ; \ | |
293 94: 24430004 addiu v1,v0,4 ; | | |
294 98: afc3002c sw v1,44(s8) ; | in arg 2 | |
295 9c: 8c420000 lw v0,0(v0) ; | | |
296 a0: afc2000c sw v0,12(s8) ; / | |
297 a4: 8fc2002c lw v0,44(s8) ; \ | |
298 a8: 24430004 addiu v1,v0,4 ; | | |
299 ac: afc3002c sw v1,44(s8) ; | in arg 3 | |
300 b0: 8c420000 lw v0,0(v0) ; | | |
301 b4: afc20010 sw v0,16(s8) ; / | |
302 b8: 8fc2002c lw v0,44(s8) ; \ | |
303 bc: 24430004 addiu v1,v0,4 ; | | |
304 c0: afc3002c sw v1,44(s8) ; | in arg 4 | |
305 c4: 8c420000 lw v0,0(v0) ; | | |
306 c8: afc20014 sw v0,20(s8) ; / | |
307 cc: 8fc2002c lw v0,44(s8) ; \ | |
308 d0: 24430004 addiu v1,v0,4 ; | | |
309 d4: afc3002c sw v1,44(s8) ; | in arg 5 | |
310 d8: 8c420000 lw v0,0(v0) ; | | |
311 dc: afc20018 sw v0,24(s8) ; / | |
312 e0: 8fc2002c lw v0,44(s8) ; \ | |
313 e4: 24430004 addiu v1,v0,4 ; | | |
314 e8: afc3002c sw v1,44(s8) ; | in arg 6 | |
315 ec: 8c420000 lw v0,0(v0) ; | | |
316 f0: afc2001c sw v0,28(s8) ; / | |
317 f4: 8fc2002c lw v0,44(s8) ; \ | |
318 f8: 24430004 addiu v1,v0,4 ; | | |
319 fc: afc3002c sw v1,44(s8) ; | in arg 7 | |
320 100: 8c420000 lw v0,0(v0) ; | | |
321 104: afc20020 sw v0,32(s8) ; / | |
322 108: 8fc2002c lw v0,44(s8) ; \ | |
323 10c: 24430004 addiu v1,v0,4 ; | | |
324 110: afc3002c sw v1,44(s8) ; | in arg 8 | |
325 114: 8c420000 lw v0,0(v0) ; | | |
326 118: afc20024 sw v0,36(s8) ; / | |
327 11c: 8fc2002c lw v0,44(s8) ; \ | |
328 120: 24430004 addiu v1,v0,4 ; | | |
329 124: afc3002c sw v1,44(s8) ; | in arg 9 | |
330 128: 8c420000 lw v0,0(v0) ; | | |
331 12c: afc20028 sw v0,40(s8) ; / | |
332 130: 27bdff18 addiu sp,sp,-232 ; alloca(220) - with padding to guarantee alignment | |
333 134: 27a20008 addiu v0,sp,8 ; | | |
334 138: 24420007 addiu v0,v0,7 ; | | |
335 13c: 000210c2 srl v0,v0,0x3 ; | start of alloca()'d memory -> v1, by ... | |
336 140: 000210c0 sll v0,v0,0x3 ; | ... using v0 as helper to align to 8b | |
337 144: 00401821 move v1,v0 ; | | |
338 148: 2402004c li v0,76 ; 'L' -> v0, and... | |
339 14c: a0620000 sb v0,0(v1) ; ... store in local area (of alloca()'d space) | |
340 150: 8fc20028 lw v0,40(s8) ; arg 8 (fetched from local area stored to above) and ... | |
341 154: afa20000 sw v0,0(sp) ; ... "pushed" onto stack | |
342 158: 8fc40008 lw a0,8(s8) ; | | |
343 15c: 8fc5000c lw a1,12(s8) ; | | |
344 160: 8fc60010 lw a2,16(s8) ; | | |
345 164: 8fc70014 lw a3,20(s8) ; | arg 0,1,2,3,4,5,6 (fetched from local area stored to above) | |
346 168: 8fc80018 lw t0,24(s8) ; | (t0 = a4) | |
347 16c: 8fc9001c lw t1,28(s8) ; | (t1 = a5) | |
348 170: 8fca0020 lw t2,32(s8) ; | (t2 = a6) | |
349 174: 8fcb0024 lw t3,36(s8) ; | (t3 = a7) | |
350 178: 0c000000 jal 0 <leaf_call> ; call and ret addr -> ra | |
351 17c: 00000000 nop ; branch delay slot | |
352 180: 03c0e821 move sp,s8 ; | | |
353 184: 8fbf003c lw ra,60(sp) ; | | |
354 188: 8fbe0038 lw s8,56(sp) ; | | |
355 18c: 27bd0060 addiu sp,sp,96 ; | epilog | |
356 190: 03e00008 jr ra ; | | |
357 194: 00000000 nop | branch delay slot | |
358 | |
359 00000198 <main>: | |
360 198: 27bdfff0 addiu sp,sp,-16 ; | | |
361 19c: afbf000c sw ra,12(sp) ; | | |
362 1a0: afbe0008 sw s8,8(sp) ; | prolog | |
363 1a4: 03a0f021 move s8,sp ; | frame pointer (note: with offset to frame start, but static compared to sp) | |
364 1a8: 24020008 li v0,8 ; arg 8 | |
365 1ac: afa20000 sw v0,0(sp) ; ... "pushed" onto stack | |
366 1b0: 24020009 li v0,9 ; arg 9 | |
367 1b4: afa20004 sw v0,4(sp) ; ... "pushed" onto stack | |
368 1b8: 00002021 move a0,zero ; arg 0 | |
369 1bc: 24050001 li a1,1 ; arg 1 | |
370 1c0: 24060002 li a2,2 ; arg 2 | |
371 1c4: 24070003 li a3,3 ; arg 3 | |
372 1c8: 24080004 li t0,4 ; arg 4 (t0 = a4) | |
373 1cc: 24090005 li t1,5 ; arg 5 (t1 = a5) | |
374 1d0: 240a0006 li t2,6 ; arg 6 (t2 = a6) | |
375 1d4: 240b0007 li t3,7 ; arg 7 (t3 = a7) | |
376 1d8: 0c000000 jal 0 <leaf_call> ; call and ret addr -> ra | |
377 1dc: 00000000 nop ; branch delay slot | |
378 1e0: 00001021 move v0,zero ; return value | |
379 1e4: 03c0e821 move sp,s8 ; | | |
380 1e8: 8fbf000c lw ra,12(sp) ; | | |
381 1ec: 8fbe0008 lw s8,8(sp) ; | | |
382 1f0: 27bd0010 addiu sp,sp,16 ; | epilog | |
383 1f4: 03e00008 jr ra ; | | |
384 1f8: 00000000 nop ; | branch delay slot | |
385 | |
386 | |
387 | |
388 ; ------------- var args with ints and floats to see spilling (which remains only a?-a7 regs), b/c doubles are passed via them and floats are promoted to doubles in (...) -----------> | |
389 | |
390 ; #include <stdlib.h> | |
391 ; #include <stdarg.h> | |
392 ; | |
393 ; void leaf_call(int b, int c, int d, int e, float f, float g, int h, int i, float j) | |
394 ; { | |
395 ; } | |
396 ; | |
397 ; void nonleaf_call(int a, ...) | |
398 ; { | |
399 ; int b, c, d, e, h, i; | |
400 ; float f, g, j; | |
401 ; va_list ap; | |
402 ; va_start(ap, a); | |
403 ; b = va_arg(ap, int); | |
404 ; c = va_arg(ap, int); | |
405 ; d = va_arg(ap, int); | |
406 ; e = va_arg(ap, int); | |
407 ; f = (float)va_arg(ap, double); | |
408 ; g = (float)va_arg(ap, double); | |
409 ; h = va_arg(ap, int); | |
410 ; i = va_arg(ap, int); | |
411 ; j = (float)va_arg(ap, double); | |
412 ; /* use some local data */ | |
413 ; *(char*)alloca(220) = 'L'; | |
414 ; leaf_call(b, c, d, e, f, g, h, i, j); | |
415 ; } | |
416 ; | |
417 ; int main() | |
418 ; { | |
419 ; nonleaf_call(0, 1, 2, 3, 4, 5.f, 6.f, 7, 8, 9.f); | |
420 ; return 0; | |
421 ; } | |
422 | |
423 | |
424 | |
425 ; output from psptoolchain-20111215-psp w/ gcc 4.9.3 | |
426 | |
427 00000000 <leaf_call>: | |
428 0: 27bdffd0 addiu sp,sp,-48 | |
429 4: afbe002c sw s8,44(sp) | |
430 8: 03a0f021 move s8,sp | |
431 c: afc40000 sw a0,0(s8) | |
432 10: afc50004 sw a1,4(s8) | |
433 14: afc60008 sw a2,8(s8) | |
434 18: afc7000c sw a3,12(s8) | |
435 1c: e7cc0010 swc1 $f12,16(s8) | |
436 20: e7cd0014 swc1 $f13,20(s8) | |
437 24: afc80018 sw t0,24(s8) | |
438 28: afc9001c sw t1,28(s8) | |
439 2c: e7ce0020 swc1 $f14,32(s8) | |
440 30: 03c0e821 move sp,s8 | |
441 34: 8fbe002c lw s8,44(sp) | |
442 38: 27bd0030 addiu sp,sp,48 | |
443 3c: 03e00008 jr ra | |
444 40: 00000000 nop | |
445 | |
446 00000044 <nonleaf_call>: | |
447 44: 27bdffa8 addiu sp,sp,-88 ; | leaving 32b extra space adjacent to prev frame's param area for spilling | |
448 48: afbf0034 sw ra,52(sp) ; | | |
449 4c: afbe0030 sw s8,48(sp) ; | prolog | |
450 50: 03a0f021 move s8,sp ; / frame pointer (note: with offset to frame start, but static compared to sp) | |
451 54: afc5003c sw a1,60(s8) ; \ | |
452 58: afc60040 sw a2,64(s8) ; | | |
453 5c: afc70044 sw a3,68(s8) ; | | |
454 60: afc80048 sw t0,72(s8) ; | in args 1,2,3,4,5 (spread out over 7 param regs) -> spill area in current frame (adjacent to prev frame's param area) | |
455 64: afc9004c sw t1,76(s8) ; | this one is just padding | |
456 68: afca0050 sw t2,80(s8) ; | | | |
457 6c: afcb0054 sw t3,84(s8) ; | | this is arg 5, passed as a double, spilled like integers | |
458 70: afc40028 sw a0,40(s8) ; in arg 0 -> temp space in local area | |
459 74: 27c20058 addiu v0,s8,88 ; v0 initialized to point ... | |
460 78: 2442ffe4 addiu v0,v0,-28 ; ... to start of spill area (88 - 28 = 60, where we spilled a1) | |
461 7c: afc20024 sw v0,36(s8) ; store read ptr in local area | |
462 80: 8fc20024 lw v0,36(s8) ; | get read pointer in v0 (pointless here, but part of following pattern) ... | |
463 84: 24430004 addiu v1,v0,4 ; | ... advance ... | |
464 88: afc30024 sw v1,36(s8) ; | in arg 1 ... store again ... | |
465 8c: 8c420000 lw v0,0(v0) ; | ... arg -> v0 (using pre-inc read location), then ... | |
466 90: afc20000 sw v0,0(s8) ; / ... write to local area on stack for later | |
467 94: 8fc20024 lw v0,36(s8) ; \ | |
468 98: 24430004 addiu v1,v0,4 ; | | |
469 9c: afc30024 sw v1,36(s8) ; | in arg 2 | |
470 a0: 8c420000 lw v0,0(v0) ; | | |
471 a4: afc20004 sw v0,4(s8) ; / | |
472 a8: 8fc20024 lw v0,36(s8) ; \ | |
473 ac: 24430004 addiu v1,v0,4 ; | | |
474 b0: afc30024 sw v1,36(s8) ; | in arg 3 | |
475 b4: 8c420000 lw v0,0(v0) ; | | |
476 b8: afc20008 sw v0,8(s8) ; / | |
477 bc: 8fc20024 lw v0,36(s8) ; \ | |
478 c0: 24430004 addiu v1,v0,4 ; | | |
479 c4: afc30024 sw v1,36(s8) ; | in arg 4 | |
480 c8: 8c420000 lw v0,0(v0) ; | | |
481 cc: afc2000c sw v0,12(s8) ; / | |
482 d0: 8fc20024 lw v0,36(s8) ; \ get read ptr in v0 | |
483 d4: 24430007 addiu v1,v0,7 ; | | | |
484 d8: 2402fff8 li v0,-8 ; | | align | |
485 dc: 00621024 and v0,v1,v0 ; | | | |
486 e0: 24430008 addiu v1,v0,8 ; | advance read ptr to point to double | |
487 e4: afc30024 sw v1,36(s8) ; | restore read ptr | |
488 e8: 8c430004 lw v1,4(v0) ; | in arg 5 | | |
489 ec: 8c420000 lw v0,0(v0) ; | | load both parts of double ... | |
490 f0: 00402021 move a0,v0 ; | | ... and store in a{0,1} pair (used to pass doubles, used in next call) | |
491 f4: 00602821 move a1,v1 ; | / | |
492 f8: 0c000000 jal 0 <leaf_call> ; | \ call to cast double to float, returned in f0 | |
493 fc: 00000000 nop ; | | NOTE: not a call to leaf_call() (objdump done from .o file, not finally linked executable) | |
494 100: e7c00010 swc1 $f0,16(s8) ; / write float to local area on stack for later | |
495 104: 8fc20024 lw v0,36(s8) ; \ | |
496 108: 24430007 addiu v1,v0,7 ; | | |
497 10c: 2402fff8 li v0,-8 ; | | |
498 110: 00621024 and v0,v1,v0 ; | | |
499 114: 24430008 addiu v1,v0,8 ; | | |
500 118: afc30024 sw v1,36(s8) ; | | |
501 11c: 8c430004 lw v1,4(v0) ; | in arg 6 | |
502 120: 8c420000 lw v0,0(v0) ; | | |
503 124: 00402021 move a0,v0 ; | | |
504 128: 00602821 move a1,v1 ; | | |
505 12c: 0c000000 jal 0 <leaf_call> ; | | |
506 130: 00000000 nop ; | | |
507 134: e7c00014 swc1 $f0,20(s8) ; / | |
508 138: 8fc20024 lw v0,36(s8) ; \ | |
509 13c: 24430004 addiu v1,v0,4 ; | | |
510 140: afc30024 sw v1,36(s8) ; | in arg 7 | |
511 144: 8c420000 lw v0,0(v0) ; | | |
512 148: afc20018 sw v0,24(s8) ; / | |
513 14c: 8fc20024 lw v0,36(s8) ; \ | |
514 150: 24430004 addiu v1,v0,4 ; | | |
515 154: afc30024 sw v1,36(s8) ; | in arg 8 | |
516 158: 8c420000 lw v0,0(v0) ; | | |
517 15c: afc2001c sw v0,28(s8) ; / | |
518 160: 8fc20024 lw v0,36(s8) ; \ | |
519 164: 24430007 addiu v1,v0,7 ; | | |
520 168: 2402fff8 li v0,-8 ; | | |
521 16c: 00621024 and v0,v1,v0 ; | | |
522 170: 24430008 addiu v1,v0,8 ; | | |
523 174: afc30024 sw v1,36(s8) ; | | |
524 178: 8c430004 lw v1,4(v0) ; | in arg 9 | |
525 17c: 8c420000 lw v0,0(v0) ; | | |
526 180: 00402021 move a0,v0 ; | | |
527 184: 00602821 move a1,v1 ; | | |
528 188: 0c000000 jal 0 <leaf_call> ; | | |
529 18c: 00000000 nop ; | | |
530 190: e7c00020 swc1 $f0,32(s8) ; / | |
531 194: 27bdff18 addiu sp,sp,-232 ; alloca(220) - with padding to guarantee alignment | |
532 198: 03a01021 move v0,sp ; | | |
533 19c: 24420007 addiu v0,v0,7 ; | | |
534 1a0: 000210c2 srl v0,v0,0x3 ; | start of alloca()'d memory -> v1, by ... | |
535 1a4: 000210c0 sll v0,v0,0x3 ; | ... using v0 as helper to align to 8b | |
536 1a8: 00401821 move v1,v0 ; | | |
537 1ac: 2402004c li v0,76 ; 'L' -> v0, and... | |
538 1b0: a0620000 sb v0,0(v1) ; ... store in local area (of alloca()'d space) | |
539 1b4: 8fc40000 lw a0,0(s8) ; | | |
540 1b8: 8fc50004 lw a1,4(s8) ; | | |
541 1bc: 8fc60008 lw a2,8(s8) ; | arg 0,1,2,3 (int args, fetched from local area stored to above) | |
542 1c0: 8fc7000c lw a3,12(s8) ; | | |
543 1c4: c7cc0010 lwc1 $f12,16(s8) ; arg 4 (float, fetched from local area stored to above) | |
544 1c8: c7cd0014 lwc1 $f13,20(s8) ; arg 5 (float, fetched from local area stored to above) | |
545 1cc: 8fc80018 lw t0,24(s8) ; arg 6 (int, fetched from local area stored to above, t0 = a4) | |
546 1d0: 8fc9001c lw t1,28(s8) ; arg 7 (int, fetched from local area stored to above, t1 = a5) | |
547 1d4: c7ce0020 lwc1 $f14,32(s8) ; arg 9 (float, fetched from local area stored to above) | |
548 1d8: 0c000000 jal 0 <leaf_call> ; call and ret addr -> ra | |
549 1dc: 00000000 nop ; branch delay slot | |
550 1e0: 03c0e821 move sp,s8 ; | | |
551 1e4: 8fbf0034 lw ra,52(sp) ; | | |
552 1e8: 8fbe0030 lw s8,48(sp) ; | | |
553 1ec: 27bd0058 addiu sp,sp,88 ; | epilog | |
554 1f0: 03e00008 jr ra ; | | |
555 1f4: 00000000 nop ; | branch delay slot | |
556 | |
557 000001f8 <main>: | |
558 1f8: 27bdffe0 addiu sp,sp,-32 ; | | |
559 1fc: afbf001c sw ra,28(sp) ; | | |
560 200: afbe0018 sw s8,24(sp) ; | prolog | |
561 204: 03a0f021 move s8,sp ; / frame pointer (note: with offset to frame start, but static compared to sp) | |
562 208: 8f8a0000 lw t2,0(gp) ; \ | |
563 20c: 8f8b0004 lw t3,4(gp) ; / arg 5 (t1,t2 = a4,a5), as double b/c of vararg, effectively skipping t1 (=a5) | |
564 210: 8f820008 lw v0,8(gp) ; \ | |
565 214: 8f83000c lw v1,12(gp) ; | arg 6, as double b/c of vararg, via v0 and v1 ... | |
566 218: afa20000 sw v0,0(sp) ; | | |
567 21c: afa30004 sw v1,4(sp) ; | ... "pushed" onto stack | |
568 220: 24020007 li v0,7 ; arg 7 | |
569 224: afa20008 sw v0,8(sp) ; ... "pushed" onto stack | |
570 228: 24020008 li v0,8 ; arg 8 | |
571 22c: afa2000c sw v0,12(sp) ; ... "pushed" onto stack | |
572 230: 8f820010 lw v0,16(gp) ; | | |
573 234: 8f830014 lw v1,20(gp) ; | arg 9, as double b/c of vararg ... | |
574 238: afa20010 sw v0,16(sp) ; | | |
575 23c: afa30014 sw v1,20(sp) ; | ... "pushed" onto stack | |
576 240: 00002021 move a0,zero ; arg 0 | |
577 244: 24050001 li a1,1 ; arg 1 | |
578 248: 24060002 li a2,2 ; arg 2 | |
579 24c: 24070003 li a3,3 ; arg 3 | |
580 250: 24080004 li t0,4 ; arg 4 (t0 = a4) | |
581 254: 0c000000 jal 0 <leaf_call> ; call and ret addr -> ra | |
582 258: 00000000 nop ; branch delay slot | |
583 25c: 00001021 move v0,zero ; return value | |
584 260: 03c0e821 move sp,s8 ; | | |
585 264: 8fbf001c lw ra,28(sp) ; | | |
586 268: 8fbe0018 lw s8,24(sp) ; | | |
587 26c: 27bd0020 addiu sp,sp,32 ; | epilog | |
588 270: 03e00008 jr ra ; | | |
589 274: 00000000 nop ; | branch delay slot | |
590 | |
591 | |
592 | |
593 ; --------------------- further notes -------------------> | |
594 | |
595 ; when passing less arguments than stack params, involving an ellipse, spill area still spills all registers, | |
596 ; excluding named ones, e.g.: | |
597 ; | |
598 ; void c(int a, ...) { ... } | |
599 ; c(0, 1, 2, 3, 4); | |
600 ; | |
601 ; contains as spilling code same as above: | |
602 | |
603 84: afc5002c sw a1,44(s8) | |
604 88: afc60030 sw a2,48(s8) | |
605 8c: afc70034 sw a3,52(s8) | |
606 90: afc80038 sw t0,56(s8) | |
607 94: afc9003c sw t1,60(s8) | |
608 98: afca0040 sw t2,64(s8) | |
609 9c: afcb0044 sw t3,68(s8) | |
610 | |
611 | |
612 ; vim: ft=asm | |
613 |