sdk-core v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Loading...
Searching...
No Matches
asm.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 1996-2007 MIPS Technologies, Inc.
3 * Copyright (C) 2009 CodeSourcery, LLC.
4 *
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright
15 * notice, this list of conditions and the following disclaimer
16 * in the documentation and/or other materials provided with
17 * the distribution.
18 * * Neither the name of MIPS Technologies Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35/*
36 * asm.h: various macros to help assembly language writers
37 */
38
43#ifndef _MIPS_ASM_H_
44#define _MIPS_ASM_H_
45
46/* ABI specific stack frame layout and manipulation. */
47#if _MIPS_SIM==_ABIO32 && ! __mips64
48/* Standard O32 */
49#define SZREG 4 /* saved register size */
50#define REG_S sw /* store saved register */
51#define REG_L lw /* load saved register */
52#define SZARG 4 /* argument register size */
53#define NARGSAVE 4 /* arg register space on caller stack */
54#define ALSZ 7 /* stack alignment - 1 */
55#define ALMASK (~7) /* stack alignment mask */
56#define LOG2_STACK_ALGN 3 /* log2(8) */
57#define SZPTR 4 /* pointer size */
58#define LOG2_SZPTR 2 /* log2(4) */
59#define PTR_S sw /* store pointer */
60#define PTR_L lw /* load pointer */
61#define PTR_SUBU subu /* decrement pointer */
62#define PTR_ADDU addu /* increment pointer */
63#define PTR .word /* pointer type pseudo */
64#elif _MIPS_SIM==_ABIO32 && __mips64
65/* Algorithmics O32+64-bit */
66#define SZREG 8 /* saved register size */
67#define REG_S sd /* store saved register */
68#define REG_L ld /* load saved register */
69#define SZARG 4 /* argument register size */
70#define NARGSAVE 4 /* arg register space on caller stack */
71#define ALSZ 7 /* stack alignment - 1 */
72#define ALMASK (~7) /* stack alignment mask */
73#define LOG2_STACK_ALGN 3 /* log2(8) */
74#define SZPTR 4 /* pointer size */
75#define LOG2_SZPTR 2 /* log2(4) */
76#define PTR_S sw /* store pointer */
77#define PTR_L lw /* load pointer */
78#define PTR_SUBU subu /* decrement pointer */
79#define PTR_ADDU addu /* increment pointer */
80#define PTR .word /* pointer type pseudo */
81#elif _MIPS_SIM==_ABIO64
82/* Cygnus O64 */
83#define SZREG 8 /* saved register size */
84#define REG_S sd /* store saved register */
85#define REG_L ld /* load saved register */
86#define SZARG 8 /* argument register size */
87#define NARGSAVE 4 /* arg register space on caller stack */
88#define ALSZ 7 /* stack alignment - 1 */
89#define ALMASK (~7) /* stack alignment mask */
90#define LOG2_STACK_ALGN 3 /* log2(8) */
91#define SZPTR 4 /* pointer size */
92#define LOG2_SZPTR 2 /* log2(4) */
93#define PTR_S sw /* store pointer */
94#define PTR_L lw /* load pointer */
95#define PTR_SUBU subu /* decrement pointer */
96#define PTR_ADDU addu /* increment pointer */
97#define PTR .word /* pointer type pseudo */
98#elif _MIPS_SIM==_ABIN32
99/* Standard N32 */
100#define SZREG 8 /* saved register size */
101#define REG_S sd /* store saved register */
102#define REG_L ld /* load saved register */
103#define SZARG 8 /* argument register size */
104#define NARGSAVE 0 /* arg register space on caller stack */
105#define ALSZ 15 /* stack alignment - 1 */
106#define ALMASK (~15) /* stack alignment mask */
107#define LOG2_STACK_ALGN 4 /* log2(16) */
108#define SZPTR 4 /* pointer size */
109#define LOG2_SZPTR 2 /* log2(4) */
110#define PTR_S sw /* store pointer */
111#define PTR_L lw /* load pointer */
112#define PTR_SUBU subu /* decrement pointer (SGI uses sub) */
113#define PTR_ADDU addu /* increment pointer (SGI uses add) */
114#define PTR .word /* pointer type pseudo */
115#elif _MIPS_SIM==_ABI64
116/* Standard N64 */
117#define SZREG 8 /* saved register size */
118#define REG_S sd /* store saved register */
119#define REG_L ld /* load saved register */
120#define SZARG 8 /* argument register size */
121#define NARGSAVE 0 /* arg register space on caller stack */
122#define ALSZ 15 /* stack alignment - 1 */
123#define ALMASK (~15) /* stack alignment mask */
124#define LOG2_STACK_ALGN 4 /* log2(16) */
125#define SZPTR 8 /* pointer size */
126#define LOG2_SZPTR 3 /* log2(8) */
127#define PTR_S sd /* store pointer */
128#define PTR_L ld /* load pointer */
129#define PTR_SUBU dsubu /* decrement pointer */
130#define PTR_ADDU daddu /* increment pointer */
131#define PTR .dword /* pointer type pseudo */
132#else
133#error Unknown ABI
134#endif
135
136/* Concatenate two names. */
137#ifdef __STDC__
138# define _ASMCONCAT(A, B) A ## B
139#else
140# define _ASMCONCAT(A, B) A/**/B
141#endif
142
143/* Name of reset code section. */
144#ifndef _RESET_SECTION
145# define _RESET_SECTION .section .reset, "ax", @progbits
146#endif
147
148#ifndef _RESET_SECTION_NAMED
149/* No function section support for now, since binutils fails to cope with
150 external branches. */
151# define _RESET_SECTION_NAMED(name) .pushsection .reset, "ax", @progbits
152#endif
153
154/* Name of boot code section. */
155#ifndef _BOOT_SECTION
156# define _BOOT_SECTION .section .boot, "ax", @progbits
157#endif
158
159#ifndef _BOOT_SECTION_NAMED
160/* No function section support for now, since binutils fails to cope with
161 external branches. */
162# define _BOOT_SECTION_NAMED(name) .pushsection .boot, "ax", @progbits
163#endif
164
165/* Name of standard code section. */
166#ifndef _NORMAL_SECTION_UNNAMED
167# define _NORMAL_SECTION_UNNAMED .section .text, "ax", @progbits
168#endif
169
170#ifndef _NORMAL_SECTION_NAMED
171# ifdef _FUNCTION_SECTIONS_
172# define _NORMAL_SECTION_NAMED(name) .pushsection .text ##.name, "ax", @progbits
173# else
174# define _NORMAL_SECTION_NAMED(name) .pushsection .text, "ax", @progbits
175# endif
176#endif
177
178/* Default code section. */
179#ifndef _TEXT_SECTION_NAMED
180# if defined(_RESETCODE)
181# define _TEXT_SECTION_NAMED _RESET_SECTION_NAMED
182# elif defined(_BOOTCODE)
183# define _TEXT_SECTION_NAMED _BOOT_SECTION_NAMED
184# else
185# define _TEXT_SECTION_NAMED _NORMAL_SECTION_NAMED
186# endif
187#endif
188
189#ifndef _TEXT_SECTION
190# if defined(_RESETCODE)
191# define _TEXT_SECTION _RESET_SECTION
192# elif defined(_BOOTCODE)
193# define _TEXT_SECTION _BOOT_SECTION
194# else
195# define _TEXT_SECTION _NORMAL_SECTION_UNNAMED
196# endif
197 _TEXT_SECTION
198#endif
199
200/*
201 * Leaf functions declarations.
202 */
203
204/* Global leaf function. */
205#define LEAF(name) \
206 _TEXT_SECTION_NAMED(name); \
207 .globl name; \
208 .balign 4; \
209 .ent name; \
210name:
211
212/* Static/Local leaf function. */
213#define SLEAF(name) \
214 _TEXT_SECTION_NAMED(name); \
215 .balign 4; \
216 .ent name; \
217name:
218
219/* Weak leaf function. */
220#define WLEAF(name) \
221 _TEXT_SECTION_NAMED(name); \
222 .weakext name; \
223 .balign 4; \
224 .ent name; \
225name:
226
227/* Weak alias leaf function. */
228#define ALEAF(name,alias) \
229 _TEXT_SECTION_NAMED(name); \
230 .weakext alias,name; \
231 .balign 4; \
232 .ent name; \
233name:
234
235/*
236 * Alternative function entrypoints.
237 */
238
239/* Global alternative entrypoint. */
240#define AENT(name) \
241 .globl name; \
242 .balign 4; \
243 .aent name; \
244name:
245#define XLEAF(name) AENT(name)
246
247/* Local/static alternative entrypoint. */
248#define SAENT(name) \
249 .balign 4; \
250 .aent name; \
251name:
252#define SXLEAF(name) SAENT(name)
253
254
255/*
256 * Leaf functions declarations.
257 */
258
259/* Global nested function. */
260#define NESTED(name, framesz, rareg) \
261 _TEXT_SECTION_NAMED(name); \
262 .globl name; \
263 .balign 4; \
264 .ent name; \
265 .frame sp, framesz, rareg; \
266name:
267
268/* Static/Local nested function. */
269#define SNESTED(name, framesz, rareg) \
270 _TEXT_SECTION_NAMED(name); \
271 .balign 4; \
272 .ent name; \
273 .frame sp, framesz, rareg; \
274name:
275
276/* Weak nested function. */
277#define WNESTED(name, framesz, rareg) \
278 _TEXT_SECTION_NAMED(name); \
279 .weakext name; \
280 .balign 4; \
281 .ent name; \
282 .frame sp, framesz, rareg; \
283name:
284
285/* Weak alias nested function. */
286#define ANESTED(name, alias, framesz, rareg) \
287 _TEXT_SECTION_NAMED(name); \
288 .weakext alias, name; \
289 .balign 4; \
290 .ent name; \
291 .frame sp, framesz, rareg; \
292name:
293
294/*
295 * Function termination
296 */
297#define END(name) \
298 .size name,.-name; \
299 .end name; \
300 .popsection
301
302#define SEND(name) END(name)
303#define WEND(name) END(name)
304#define AEND(name,alias) END(name)
305
306/*
307 * Global data declaration.
308 */
309#define EXPORT(name) \
310 .globl name; \
311 .type name,@object; \
312name:
313
314/*
315 * Global data declaration with size.
316 */
317#define EXPORTS(name,sz) \
318 .globl name; \
319 .type name,@object; \
320 .size name,sz; \
321name:
322
323/*
324 * Weak data declaration with size.
325 */
326#define WEXPORT(name,sz) \
327 .weakext name; \
328 .type name,@object; \
329 .size name,sz; \
330name:
331
332/*
333 * Global data reference with size.
334 */
335#define IMPORT(name, size) \
336 .extern name,size
337
338/*
339 * Global zeroed data.
340 */
341#define BSS(name,size) \
342 .type name,@object; \
343 .comm name,size
344
345/*
346 * Local zeroed data.
347 */
348#define LBSS(name,size) \
349 .lcomm name,size
350
351/*
352 * Insert call to _mcount if profiling.
353 */
354#ifdef __PROFILING__
355#define _MCOUNT \
356 .set push; \
357 .set noat; \
358 move $1,$31; \
359 jal _mcount; \
360 .set pop
361#else
362#define _MCOUNT
363#endif
364
365#endif