| 1 | /* |
|---|
| 2 | * Copyright (c) 1996-2006 MIPS Technologies, Inc. |
|---|
| 3 | * All rights reserved. |
|---|
| 4 | * |
|---|
| 5 | * Unpublished rights (if any) reserved under the copyright laws of the |
|---|
| 6 | * United States of America and other countries. |
|---|
| 7 | * |
|---|
| 8 | * This code is proprietary to MIPS Technologies, Inc. ("MIPS |
|---|
| 9 | * Technologies"). Any copying, reproducing, modifying or use of |
|---|
| 10 | * this code (in whole or in part) that is not expressly permitted |
|---|
| 11 | * in writing by MIPS Technologies or an authorized third party is |
|---|
| 12 | * strictly prohibited. At a minimum, this code is protected under |
|---|
| 13 | * unfair competition and copyright laws. Violations thereof may result |
|---|
| 14 | * in criminal penalties and fines. |
|---|
| 15 | * |
|---|
| 16 | * MIPS Technologies reserves the right to change this code to improve |
|---|
| 17 | * function, design or otherwise. MIPS Technologies does not assume any |
|---|
| 18 | * liability arising out of the application or use of this code, or of |
|---|
| 19 | * any error or omission in such code. Any warranties, whether express, |
|---|
| 20 | * statutory, implied or otherwise, including but not limited to the |
|---|
| 21 | * implied warranties of merchantability or fitness for a particular |
|---|
| 22 | * purpose, are excluded. Except as expressly provided in any written |
|---|
| 23 | * license agreement from MIPS Technologies or an authorized third party, |
|---|
| 24 | * the furnishing of this code does not give recipient any license to |
|---|
| 25 | * any intellectual property rights, including any patent rights, that |
|---|
| 26 | * cover this code. |
|---|
| 27 | * |
|---|
| 28 | * This code shall not be exported, reexported, transferred, or released, |
|---|
| 29 | * directly or indirectly, in violation of the law of any country or |
|---|
| 30 | * international law, regulation, treaty, Executive Order, statute, |
|---|
| 31 | * amendments or supplements thereto. Should a conflict arise regarding |
|---|
| 32 | * the export, reexport, transfer, or release of this code, the laws of |
|---|
| 33 | * the United States of America shall be the governing law. |
|---|
| 34 | * |
|---|
| 35 | * This code constitutes one or more of the following: commercial |
|---|
| 36 | * computer software, commercial computer software documentation or |
|---|
| 37 | * other commercial items. If the user of this code, or any related |
|---|
| 38 | * documentation of any kind, including related technical data or |
|---|
| 39 | * manuals, is an agency, department, or other entity of the United |
|---|
| 40 | * States government ("Government"), the use, duplication, reproduction, |
|---|
| 41 | * release, modification, disclosure, or transfer of this code, or |
|---|
| 42 | * any related documentation of any kind, is restricted in accordance |
|---|
| 43 | * with Federal Acquisition Regulation 12.212 for civilian agencies |
|---|
| 44 | * and Defense Federal Acquisition Regulation Supplement 227.7202 for |
|---|
| 45 | * military agencies. The use of this code by the Government is further |
|---|
| 46 | * restricted in accordance with the terms of the license agreement(s) |
|---|
| 47 | * and/or applicable contract terms and conditions covering this code |
|---|
| 48 | * from MIPS Technologies or an authorized third party. |
|---|
| 49 | * |
|---|
| 50 | * |
|---|
| 51 | */ |
|---|
| 52 | |
|---|
| 53 | /* |
|---|
| 54 | * asm.h: various macros to help assembly language writers |
|---|
| 55 | */ |
|---|
| 56 | |
|---|
| 57 | /* ABI specific stack frame layout and manipulation. */ |
|---|
| 58 | /* Standard O32 */ |
|---|
| 59 | #define SZREG 4 /* saved register size */ |
|---|
| 60 | #define REG_S sw /* store saved register */ |
|---|
| 61 | #define REG_L lw /* load saved register */ |
|---|
| 62 | #define SZARG 4 /* argument register size */ |
|---|
| 63 | #define NARGSAVE 4 /* arg register space on caller stack */ |
|---|
| 64 | #define ALSZ 7 /* stack alignment - 1 */ |
|---|
| 65 | #define ALMASK (~7) /* stack alignment mask */ |
|---|
| 66 | #define LOG2_STACK_ALGN 3 /* log2(8) */ |
|---|
| 67 | #define SZPTR 4 /* pointer size */ |
|---|
| 68 | #define LOG2_SZPTR 2 /* log2(4) */ |
|---|
| 69 | #define PTR_S sw /* store pointer */ |
|---|
| 70 | #define PTR_L lw /* load pointer */ |
|---|
| 71 | #define PTR_SUBU subu /* decrement pointer */ |
|---|
| 72 | #define PTR_ADDU addu /* increment pointer */ |
|---|
| 73 | #define PTR .word /* pointer type pseudo */ |
|---|
| 74 | |
|---|
| 75 | /* Concatenate two names. */ |
|---|
| 76 | #ifdef __STDC__ |
|---|
| 77 | # define _ASMCONCAT(A, B) A ## B |
|---|
| 78 | #else |
|---|
| 79 | # define _ASMCONCAT(A, B) A/**/B |
|---|
| 80 | #endif |
|---|
| 81 | |
|---|
| 82 | /* Name of reset code section. */ |
|---|
| 83 | #ifndef _RESET_SECTION |
|---|
| 84 | # define _RESET_SECTION .section .reset, "ax", @progbits |
|---|
| 85 | #endif |
|---|
| 86 | |
|---|
| 87 | #ifndef _RESET_SECTION_NAMED |
|---|
| 88 | /* No function section support for now, since binutils fails to cope with |
|---|
| 89 | external branches. */ |
|---|
| 90 | # define _RESET_SECTION_NAMED(name) .pushsection .reset, "ax", @progbits |
|---|
| 91 | #endif |
|---|
| 92 | |
|---|
| 93 | /* Name of boot code section. */ |
|---|
| 94 | #ifndef _BOOT_SECTION |
|---|
| 95 | # define _BOOT_SECTION .section .boot, "ax", @progbits |
|---|
| 96 | #endif |
|---|
| 97 | |
|---|
| 98 | #ifndef _BOOT_SECTION_NAMED |
|---|
| 99 | /* No function section support for now, since binutils fails to cope with |
|---|
| 100 | external branches. */ |
|---|
| 101 | # define _BOOT_SECTION_NAMED(name) .pushsection .boot, "ax", @progbits |
|---|
| 102 | #endif |
|---|
| 103 | |
|---|
| 104 | /* Name of standard code section. */ |
|---|
| 105 | #ifndef _NORMAL_SECTION_UNNAMED |
|---|
| 106 | # define _NORMAL_SECTION_UNNAMED .section .text, "ax", @progbits |
|---|
| 107 | #endif |
|---|
| 108 | |
|---|
| 109 | #ifndef _NORMAL_SECTION_NAMED |
|---|
| 110 | # ifdef _FUNCTION_SECTIONS_ |
|---|
| 111 | # define _NORMAL_SECTION_NAMED(name) .pushsection .text ##.name, "ax", @progbits |
|---|
| 112 | # else |
|---|
| 113 | # define _NORMAL_SECTION_NAMED(name) .pushsection .text, "ax", @progbits |
|---|
| 114 | # endif |
|---|
| 115 | #endif |
|---|
| 116 | |
|---|
| 117 | /* Default code section. */ |
|---|
| 118 | #ifndef _TEXT_SECTION_NAMED |
|---|
| 119 | # if defined(_RESETCODE) |
|---|
| 120 | # define _TEXT_SECTION_NAMED _RESET_SECTION_NAMED |
|---|
| 121 | # elif defined(_BOOTCODE) |
|---|
| 122 | # define _TEXT_SECTION_NAMED _BOOT_SECTION_NAMED |
|---|
| 123 | # else |
|---|
| 124 | # define _TEXT_SECTION_NAMED _NORMAL_SECTION_NAMED |
|---|
| 125 | # endif |
|---|
| 126 | #endif |
|---|
| 127 | |
|---|
| 128 | #ifndef _TEXT_SECTION |
|---|
| 129 | # if defined(_RESETCODE) |
|---|
| 130 | # define _TEXT_SECTION _RESET_SECTION |
|---|
| 131 | # elif defined(_BOOTCODE) |
|---|
| 132 | # define _TEXT_SECTION _BOOT_SECTION |
|---|
| 133 | # else |
|---|
| 134 | # define _TEXT_SECTION _NORMAL_SECTION_UNNAMED |
|---|
| 135 | # endif |
|---|
| 136 | _TEXT_SECTION |
|---|
| 137 | #endif |
|---|
| 138 | |
|---|
| 139 | /* |
|---|
| 140 | * Leaf functions declarations. |
|---|
| 141 | */ |
|---|
| 142 | |
|---|
| 143 | /* Global leaf function. */ |
|---|
| 144 | #define LEAF(name) \ |
|---|
| 145 | _TEXT_SECTION_NAMED(name); \ |
|---|
| 146 | .globl name; \ |
|---|
| 147 | .ent name; \ |
|---|
| 148 | name: |
|---|
| 149 | |
|---|
| 150 | /* Static/Local leaf function. */ |
|---|
| 151 | #define SLEAF(name) \ |
|---|
| 152 | _TEXT_SECTION_NAMED(name); \ |
|---|
| 153 | .ent name; \ |
|---|
| 154 | name: |
|---|
| 155 | |
|---|
| 156 | /* Weak leaf function. */ |
|---|
| 157 | #define WLEAF(name) \ |
|---|
| 158 | _TEXT_SECTION_NAMED(name); \ |
|---|
| 159 | .weakext name; \ |
|---|
| 160 | .ent name; \ |
|---|
| 161 | name: |
|---|
| 162 | |
|---|
| 163 | /* Weak alias leaf function. */ |
|---|
| 164 | #define ALEAF(name,alias) \ |
|---|
| 165 | _TEXT_SECTION_NAMED(name); \ |
|---|
| 166 | .weakext alias,name; \ |
|---|
| 167 | .ent name; \ |
|---|
| 168 | name: |
|---|
| 169 | |
|---|
| 170 | /* |
|---|
| 171 | * Alternative function entrypoints. |
|---|
| 172 | */ |
|---|
| 173 | |
|---|
| 174 | /* Global alternative entrypoint. */ |
|---|
| 175 | #define AENT(name) \ |
|---|
| 176 | .globl name; \ |
|---|
| 177 | .aent name; \ |
|---|
| 178 | name: |
|---|
| 179 | #define XLEAF(name) AENT(name) |
|---|
| 180 | |
|---|
| 181 | /* Local/static alternative entrypoint. */ |
|---|
| 182 | #define SAENT(name) \ |
|---|
| 183 | .aent name; \ |
|---|
| 184 | name: |
|---|
| 185 | #define SXLEAF(name) SAENT(name) |
|---|
| 186 | |
|---|
| 187 | |
|---|
| 188 | /* |
|---|
| 189 | * Leaf functions declarations. |
|---|
| 190 | */ |
|---|
| 191 | |
|---|
| 192 | /* Global nested function. */ |
|---|
| 193 | #define NESTED(name, framesz, rareg) \ |
|---|
| 194 | _TEXT_SECTION_NAMED(name); \ |
|---|
| 195 | .globl name; \ |
|---|
| 196 | .ent name; \ |
|---|
| 197 | .frame $sp, framesz, rareg; \ |
|---|
| 198 | name: |
|---|
| 199 | |
|---|
| 200 | /* Static/Local nested function. */ |
|---|
| 201 | #define SNESTED(name, framesz, rareg) \ |
|---|
| 202 | _TEXT_SECTION_NAMED(name); \ |
|---|
| 203 | .ent name; \ |
|---|
| 204 | .frame $sp, framesz, rareg; \ |
|---|
| 205 | name: |
|---|
| 206 | |
|---|
| 207 | /* Weak nested function. */ |
|---|
| 208 | #define WNESTED(name, framesz, rareg) \ |
|---|
| 209 | _TEXT_SECTION_NAMED(name); \ |
|---|
| 210 | .weakext name; \ |
|---|
| 211 | .ent name; \ |
|---|
| 212 | .frame $sp, framesz, rareg; \ |
|---|
| 213 | name: |
|---|
| 214 | |
|---|
| 215 | /* Weak alias nested function. */ |
|---|
| 216 | #define ANESTED(name, alias, framesz, rareg) \ |
|---|
| 217 | _TEXT_SECTION_NAMED(name); \ |
|---|
| 218 | .weakext alias, name; \ |
|---|
| 219 | .ent name; \ |
|---|
| 220 | .frame $sp, framesz, rareg; \ |
|---|
| 221 | name: |
|---|
| 222 | |
|---|
| 223 | /* |
|---|
| 224 | * Function termination |
|---|
| 225 | */ |
|---|
| 226 | #define END(name) \ |
|---|
| 227 | .size name,.-name; \ |
|---|
| 228 | .end name; \ |
|---|
| 229 | .popsection |
|---|
| 230 | |
|---|
| 231 | #define SEND(name) END(name) |
|---|
| 232 | #define WEND(name) END(name) |
|---|
| 233 | #define AEND(name,alias) END(name) |
|---|
| 234 | |
|---|
| 235 | /* |
|---|
| 236 | * Global data declaration. |
|---|
| 237 | */ |
|---|
| 238 | #define EXPORT(name) \ |
|---|
| 239 | .globl name; \ |
|---|
| 240 | .type name,@object; \ |
|---|
| 241 | name: |
|---|
| 242 | |
|---|
| 243 | /* |
|---|
| 244 | * Global data declaration with size. |
|---|
| 245 | */ |
|---|
| 246 | #define EXPORTS(name,sz) \ |
|---|
| 247 | .globl name; \ |
|---|
| 248 | .type name,@object; \ |
|---|
| 249 | .size name,sz; \ |
|---|
| 250 | name: |
|---|
| 251 | |
|---|
| 252 | /* |
|---|
| 253 | * Weak data declaration with size. |
|---|
| 254 | */ |
|---|
| 255 | #define WEXPORT(name,sz) \ |
|---|
| 256 | .weakext name; \ |
|---|
| 257 | .type name,@object; \ |
|---|
| 258 | .size name,sz; \ |
|---|
| 259 | name: |
|---|
| 260 | |
|---|
| 261 | /* |
|---|
| 262 | * Global data reference with size. |
|---|
| 263 | */ |
|---|
| 264 | #define IMPORT(name, size) \ |
|---|
| 265 | .extern name,size |
|---|
| 266 | |
|---|
| 267 | /* |
|---|
| 268 | * Global zeroed data. |
|---|
| 269 | */ |
|---|
| 270 | #define BSS(name,size) \ |
|---|
| 271 | .type name,@object; \ |
|---|
| 272 | .comm name,size |
|---|
| 273 | |
|---|
| 274 | /* |
|---|
| 275 | * Local zeroed data. |
|---|
| 276 | */ |
|---|
| 277 | #define LBSS(name,size) \ |
|---|
| 278 | .lcomm name,size |
|---|
| 279 | |
|---|
| 280 | /* |
|---|
| 281 | * Insert call to _mcount if profiling. |
|---|
| 282 | */ |
|---|
| 283 | #ifdef __PROFILING__ |
|---|
| 284 | #define _MCOUNT \ |
|---|
| 285 | .set push; \ |
|---|
| 286 | .set noat; \ |
|---|
| 287 | move $1,$31; \ |
|---|
| 288 | jal _mcount; \ |
|---|
| 289 | .set pop |
|---|
| 290 | #else |
|---|
| 291 | #define _MCOUNT |
|---|
| 292 | #endif |
|---|