1 /* Definitions of target machine for GNU compiler, for Advanced RISC Machines 2 ARM compilation, AOF Assembler. 3 Copyright (C) 1995, 1996, 1997, 2000 Free Software Foundation, Inc. 4 Contributed by Richard Earnshaw (rearnsha@armltd.co.uk) 5 6 This file is part of GNU CC. 7 8 GNU CC is free software; you can redistribute it and/or modify 9 it under the terms of the GNU General Public License as published by 10 the Free Software Foundation; either version 2, or (at your option) 11 any later version. 12 13 GNU CC is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with GNU CC; see the file COPYING. If not, write to 20 the Free Software Foundation, 59 Temple Place - Suite 330, 21 Boston, MA 02111-1307, USA. */ 22 23 24 25 #define AOF_ASSEMBLER 26 27 #define LINK_LIBGCC_SPECIAL 1 28 29 #define LINK_SPEC "%{aof} %{bin} %{aif} %{ihf} %{shl,*} %{reent*} %{split} \ 30 %{ov*,*} %{reloc*} -nodebug" 31 32 #define STARTFILE_SPEC "crtbegin.o%s" 33 34 #define ENDFILE_SPEC "crtend.o%s" 35 36 #ifndef ASM_SPEC 37 #define ASM_SPEC "%{g -g} -arch 4 \ 38 -apcs 3%{mapcs-32:/32bit}%{mapcs-26:/26bit}%{!mapcs-26:%{!macps-32:/26bit}}" 39 #endif 40 41 #ifndef LIB_SPEC 42 #define LIB_SPEC "%{Eb: armlib_h.32b%s}%{!Eb: armlib_h.32l%s}" 43 #endif 44 45 #define LIBGCC_SPEC "libgcc.a%s" 46 47 /* Dividing the Output into Sections (Text, Data, ...) */ 48 /* AOF Assembler syntax is a nightmare when it comes to areas, since once 49 we change from one area to another, we can't go back again. Instead, 50 we must create a new area with the same attributes and add the new output 51 to that. Unfortunately, there is nothing we can do here to guarantee that 52 two areas with the same attributes will be linked adjacently in the 53 resulting executable, so we have to be careful not to do pc-relative 54 addressing across such boundaries. */ 55 #define TEXT_SECTION_ASM_OP aof_text_section () 56 57 #define DATA_SECTION_ASM_OP aof_data_section () 58 59 #define EXTRA_SECTIONS in_zero_init, in_common 60 61 #define EXTRA_SECTION_FUNCTIONS \ 62 ZERO_INIT_SECTION \ 63 COMMON_SECTION 64 65 #define ZERO_INIT_SECTION \ 66 void \ 67 zero_init_section () \ 68 { \ 69 static int zero_init_count = 1; \ 70 if (in_section != in_zero_init) \ 71 { \ 72 fprintf (asm_out_file, "\tAREA |C$$zidata%d|,NOINIT\n", \ 73 zero_init_count++); \ 74 in_section = in_zero_init; \ 75 } \ 76 } 77 78 /* Used by ASM_OUTPUT_COMMON (below) to tell varasm.c that we've 79 changed areas. */ 80 #define COMMON_SECTION \ 81 void \ 82 common_section () \ 83 { \ 84 if (in_section != in_common) \ 85 { \ 86 in_section = in_common; \ 87 } \ 88 } 89 #define CTOR_LIST_BEGIN \ 90 asm (CTORS_SECTION_ASM_OP); \ 91 extern func_ptr __CTOR_END__[1]; \ 92 func_ptr __CTOR_LIST__[1] = {__CTOR_END__}; 93 94 #define CTOR_LIST_END \ 95 asm (CTORS_SECTION_ASM_OP); \ 96 func_ptr __CTOR_END__[1] = { (func_ptr) 0 }; 97 98 #define DO_GLOBAL_CTORS_BODY \ 99 do { \ 100 func_ptr *ptr = __CTOR_LIST__ + 1; \ 101 while (*ptr) \ 102 (*ptr++) (); \ 103 } while (0) 104 105 #define DTOR_LIST_BEGIN \ 106 asm (DTORS_SECTION_ASM_OP); \ 107 extern func_ptr __DTOR_END__[1]; \ 108 func_ptr __DTOR_LIST__[1] = {__DTOR_END__}; 109 110 #define DTOR_LIST_END \ 111 asm (DTORS_SECTION_ASM_OP); \ 112 func_ptr __DTOR_END__[1] = { (func_ptr) 0 }; 113 114 #define DO_GLOBAL_DTORS_BODY \ 115 do { \ 116 func_ptr *ptr = __DTOR_LIST__ + 1; \ 117 while (*ptr) \ 118 (*ptr++) (); \ 119 } while (0) 120 121 /* We really want to put Thumb tables in a read-only data section, but 122 switching to another section during function output is not 123 possible. We could however do what the SPARC does and defer the 124 whole table generation until the end of the function. */ 125 #define JUMP_TABLES_IN_TEXT_SECTION 1 126 127 #ifndef ARM_OS_NAME 128 #define ARM_OS_NAME "(generic)" 129 #endif 130 131 /* For the AOF linker, we need to reference __main to force the standard 132 library to get linked in. */ 133 134 #define ASM_FILE_START(STREAM) \ 135 { \ 136 fprintf ((STREAM), "%s Generated by gcc %s for ARM/%s\n", \ 137 ASM_COMMENT_START, version_string, ARM_OS_NAME); \ 138 fprintf ((STREAM), "__r0\tRN\t0\n"); \ 139 fprintf ((STREAM), "__a1\tRN\t0\n"); \ 140 fprintf ((STREAM), "__a2\tRN\t1\n"); \ 141 fprintf ((STREAM), "__a3\tRN\t2\n"); \ 142 fprintf ((STREAM), "__a4\tRN\t3\n"); \ 143 fprintf ((STREAM), "__v1\tRN\t4\n"); \ 144 fprintf ((STREAM), "__v2\tRN\t5\n"); \ 145 fprintf ((STREAM), "__v3\tRN\t6\n"); \ 146 fprintf ((STREAM), "__v4\tRN\t7\n"); \ 147 fprintf ((STREAM), "__v5\tRN\t8\n"); \ 148 fprintf ((STREAM), "__v6\tRN\t9\n"); \ 149 fprintf ((STREAM), "__sl\tRN\t10\n"); \ 150 fprintf ((STREAM), "__fp\tRN\t11\n"); \ 151 fprintf ((STREAM), "__ip\tRN\t12\n"); \ 152 fprintf ((STREAM), "__sp\tRN\t13\n"); \ 153 fprintf ((STREAM), "__lr\tRN\t14\n"); \ 154 fprintf ((STREAM), "__pc\tRN\t15\n"); \ 155 fprintf ((STREAM), "__f0\tFN\t0\n"); \ 156 fprintf ((STREAM), "__f1\tFN\t1\n"); \ 157 fprintf ((STREAM), "__f2\tFN\t2\n"); \ 158 fprintf ((STREAM), "__f3\tFN\t3\n"); \ 159 fprintf ((STREAM), "__f4\tFN\t4\n"); \ 160 fprintf ((STREAM), "__f5\tFN\t5\n"); \ 161 fprintf ((STREAM), "__f6\tFN\t6\n"); \ 162 fprintf ((STREAM), "__f7\tFN\t7\n"); \ 163 text_section (); \ 164 } 165 166 /* Some systems use __main in a way incompatible with its use in gcc, in these 167 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to 168 give the same symbol without quotes for an alternative entry point. You 169 must define both, or neither. */ 170 #define NAME__MAIN "__gccmain" 171 #define SYMBOL__MAIN __gccmain 172 173 #define ASM_FILE_END(STREAM) \ 174 do \ 175 { \ 176 if (flag_pic) \ 177 aof_dump_pic_table (STREAM); \ 178 aof_dump_imports (STREAM); \ 179 fputs ("\tEND\n", (STREAM)); \ 180 } while (0); 181 182 #define ASM_COMMENT_START ";" 183 184 #define ASM_APP_ON "" 185 186 #define ASM_APP_OFF "" 187 188 #define ASM_OUTPUT_ASCII(STREAM,PTR,LEN) \ 189 { \ 190 int i; \ 191 const char *ptr = (PTR); \ 192 fprintf ((STREAM), "\tDCB"); \ 193 for (i = 0; i < (long)(LEN); i++) \ 194 fprintf ((STREAM), " &%02x%s", \ 195 (unsigned ) *(ptr++), \ 196 (i + 1 < (long)(LEN) \ 197 ? ((i & 3) == 3 ? "\n\tDCB" : ",") \ 198 : "\n")); \ 199 } 200 201 #define IS_ASM_LOGICAL_LINE_SEPARATOR(C) ((C) == '\n') 202 203 /* Output of Uninitialized Variables */ 204 205 #define ASM_OUTPUT_COMMON(STREAM,NAME,SIZE,ROUNDED) \ 206 (common_section (), \ 207 fprintf ((STREAM), "\tAREA "), \ 208 assemble_name ((STREAM), (NAME)), \ 209 fprintf ((STREAM), ", DATA, COMMON\n\t%% %d\t%s size=%d\n", \ 210 (ROUNDED), ASM_COMMENT_START, SIZE)) 211 212 #define ASM_OUTPUT_LOCAL(STREAM,NAME,SIZE,ROUNDED) \ 213 (zero_init_section (), \ 214 assemble_name ((STREAM), (NAME)), \ 215 fprintf ((STREAM), "\n"), \ 216 fprintf ((STREAM), "\t%% %d\t%s size=%d\n", \ 217 (ROUNDED), ASM_COMMENT_START, SIZE)) 218 219 /* Output and Generation of Labels */ 220 221 extern int arm_main_function; 222 223 /* Globalizing directive for a label. */ 224 #define GLOBAL_ASM_OP "\tEXPORT\t" 225 226 #define ASM_OUTPUT_LABEL(STREAM,NAME) \ 227 do { \ 228 assemble_name (STREAM,NAME); \ 229 fputs ("\n", STREAM); \ 230 } while (0) 231 232 #define ASM_DECLARE_FUNCTION_NAME(STREAM,NAME,DECL) \ 233 { \ 234 if (TARGET_POKE_FUNCTION_NAME) \ 235 arm_poke_function_name ((STREAM), (NAME)); \ 236 ASM_OUTPUT_LABEL (STREAM, NAME); \ 237 if (! TREE_PUBLIC (DECL)) \ 238 { \ 239 fputs ("\tKEEP ", STREAM); \ 240 ASM_OUTPUT_LABEL (STREAM, NAME); \ 241 } \ 242 aof_delete_import ((NAME)); \ 243 } 244 245 #define ASM_DECLARE_OBJECT_NAME(STREAM,NAME,DECL) \ 246 { \ 247 ASM_OUTPUT_LABEL (STREAM, NAME); \ 248 if (! TREE_PUBLIC (DECL)) \ 249 { \ 250 fputs ("\tKEEP ", STREAM); \ 251 ASM_OUTPUT_LABEL (STREAM, NAME); \ 252 } \ 253 aof_delete_import ((NAME)); \ 254 } 255 256 #define ASM_OUTPUT_EXTERNAL(STREAM,DECL,NAME) \ 257 aof_add_import ((NAME)) 258 259 #define ASM_OUTPUT_EXTERNAL_LIBCALL(STREAM,SYMREF) \ 260 (fprintf ((STREAM), "\tIMPORT\t"), \ 261 assemble_name ((STREAM), XSTR ((SYMREF), 0)), \ 262 fputc ('\n', (STREAM))) 263 264 #define ASM_OUTPUT_LABELREF(STREAM,NAME) \ 265 fprintf ((STREAM), "|%s|", NAME) 266 267 #define ASM_GENERATE_INTERNAL_LABEL(STRING,PREFIX,NUM) \ 268 sprintf ((STRING), "*|%s..%ld|", (PREFIX), (long)(NUM)) 269 270 #define ASM_FORMAT_PRIVATE_NAME(OUTVAR,NAME,NUMBER) \ 271 ((OUTVAR) = (char *) alloca (strlen ((NAME)) + 10), \ 272 sprintf ((OUTVAR), "%s.%d", (NAME), (NUMBER))) 273 274 /* How initialization functions are handled */ 275 276 #define CTORS_SECTION_ASM_OP "\tAREA\t|C$$gnu_ctorsvec|, DATA, READONLY" 277 #define DTORS_SECTION_ASM_OP "\tAREA\t|C$$gnu_dtorsvec|, DATA, READONLY" 278 279 /* Output of Assembler Instructions */ 280 281 #define REGISTER_NAMES \ 282 { \ 283 "a1", "a2", "a3", "a4", \ 284 "v1", "v2", "v3", "v4", \ 285 "v5", "v6", "sl", "fp", \ 286 "ip", "sp", "lr", "pc", \ 287 "f0", "f1", "f2", "f3", \ 288 "f4", "f5", "f6", "f7", \ 289 "cc", "sfp", "afp" \ 290 } 291 292 #define ADDITIONAL_REGISTER_NAMES \ 293 { \ 294 {"r0", 0}, {"a1", 0}, \ 295 {"r1", 1}, {"a2", 1}, \ 296 {"r2", 2}, {"a3", 2}, \ 297 {"r3", 3}, {"a4", 3}, \ 298 {"r4", 4}, {"v1", 4}, \ 299 {"r5", 5}, {"v2", 5}, \ 300 {"r6", 6}, {"v3", 6}, \ 301 {"r7", 7}, {"wr", 7}, \ 302 {"r8", 8}, {"v5", 8}, \ 303 {"r9", 9}, {"v6", 9}, \ 304 {"r10", 10}, {"sl", 10}, {"v7", 10}, \ 305 {"r11", 11}, {"fp", 11}, \ 306 {"r12", 12}, {"ip", 12}, \ 307 {"r13", 13}, {"sp", 13}, \ 308 {"r14", 14}, {"lr", 14}, \ 309 {"r15", 15}, {"pc", 15} \ 310 } 311 312 #define REGISTER_PREFIX "__" 313 #define USER_LABEL_PREFIX "" 314 #define LOCAL_LABEL_PREFIX "" 315 316 /* AOF does not prefix user function names with an underscore. */ 317 #define ARM_MCOUNT_NAME "_mcount" 318 319 /* Output of Dispatch Tables */ 320 321 #define ASM_OUTPUT_ADDR_DIFF_ELT(STREAM,BODY,VALUE,REL) \ 322 do { \ 323 if (TARGET_ARM) \ 324 fprintf ((STREAM), "\tb\t|L..%d|\n", (VALUE)); \ 325 else \ 326 fprintf ((STREAM), "\tDCD\t|L..%d| - |L..%d|\n", (VALUE), (REL)); \ 327 } while (0) 328 329 #define ASM_OUTPUT_ADDR_VEC_ELT(STREAM,VALUE) \ 330 fprintf ((STREAM), "\tDCD\t|L..%d|\n", (VALUE)) 331 332 /* A label marking the start of a jump table is a data label. */ 333 #define ASM_OUTPUT_CASE_LABEL(STREAM,PREFIX,NUM,TABLE) \ 334 fprintf ((STREAM), "\tALIGN\n|%s..%d|\n", (PREFIX), (NUM)) 335 336 /* Assembler Commands for Alignment */ 337 338 #define ASM_OUTPUT_SKIP(STREAM,NBYTES) \ 339 fprintf ((STREAM), "\t%%\t%d\n", (NBYTES)) 340 341 #define ASM_OUTPUT_ALIGN(STREAM,POWER) \ 342 do { \ 343 register int amount = 1 << (POWER); \ 344 if (amount == 2) \ 345 fprintf ((STREAM), "\tALIGN 2\n"); \ 346 else if (amount == 4) \ 347 fprintf ((STREAM), "\tALIGN\n"); \ 348 else \ 349 fprintf ((STREAM), "\tALIGN %d\n", amount); \ 350 } while (0) 351 352 #undef DBX_DEBUGGING_INFO 353