Unified · Split
| @@ -5,7 +5,7 @@ version 0.9.21: · 4 unmodified lines | |||
| 5 | '-Wimplicit-function-declaration' | 5 | '-Wimplicit-function-declaration' |
| 6 | - fixed assignment of const struct in struct | 6 | - fixed assignment of const struct in struct |
| 7 | - line comment fix (reported by Bertram Felgenhauer) | 7 | - line comment fix (reported by Bertram Felgenhauer) |
| 8 | - initial TMS320C67xx support (TK) | 8 | - initial TMS320C67xx target support (TK) |
| 9 | 9 | ||
| 10 | version 0.9.20: | 10 | version 0.9.20: |
| 11 | 11 | ||
| @@ -114,7 +114,7 @@ tcc_g: tcc.c i386-gen.c tccelf.c tccasm.c i386-asm.c tcctok.h libtcc.h i386-asm. · 113 unmodified lines | |||
| 114 | tcc: tcc_g Makefile | 114 | tcc: tcc_g Makefile |
| 115 | strip -s -R .comment -R .note -o $@ $< | 115 | strip -s -R .comment -R .note -o $@ $< |
| 116 | 116 | ||
| 117 | c67-tcc: tcc.c c67-gen.c tccelf.c tccasm.c tcctok.h libtcc.h Makefile | 117 | c67-tcc: tcc.c c67-gen.c tccelf.c tccasm.c tcctok.h libtcc.h tcccoff.c Makefile |
| 118 | $(CC) $(CFLAGS) -DTCC_TARGET_C67 -o $@ $< $(LIBS) | 118 | $(CC) $(CFLAGS) -DTCC_TARGET_C67 -o $@ $< $(LIBS) |
| 119 | 119 | ||
| 120 | arm-tcc: tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h Makefile | 120 | arm-tcc: tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h Makefile |
| @@ -18,7 +18,7 @@ · 17 unmodified lines | |||
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ | 19 | */ |
| 20 | 20 | ||
| 21 | #define ASSEMBLY_LISTING_C67 | 21 | //#define ASSEMBLY_LISTING_C67 |
| 22 | 22 | ||
| 23 | /* number of available registers */ | 23 | /* number of available registers */ |
| 24 | #define NB_REGS 24 | 24 | #define NB_REGS 24 |
| @@ -139,16 +139,6 @@ int TranslateStackToReg[NoCallArgsPassedOnStack]; · 114 unmodified lines | |||
| 139 | int ParamLocOnStack[NoCallArgsPassedOnStack]; | 139 | int ParamLocOnStack[NoCallArgsPassedOnStack]; |
| 140 | int TotalBytesPushedOnStack; | 140 | int TotalBytesPushedOnStack; |
| 141 | 141 | ||
| 142 | // intrinsic functions | ||
| 143 | |||
| 144 | TokenSym *ts_divi; | ||
| 145 | TokenSym *ts_divu; | ||
| 146 | TokenSym *ts_divf; | ||
| 147 | TokenSym *ts_divd; | ||
| 148 | TokenSym *ts_remi; | ||
| 149 | TokenSym *ts_remu; | ||
| 150 | |||
| 151 | |||
| 152 | /* defined if function parameters must be evaluated in reverse order */ | 142 | /* defined if function parameters must be evaluated in reverse order */ |
| 153 | 143 | ||
| 154 | //#define INVERT_FUNC_PARAMS | 144 | //#define INVERT_FUNC_PARAMS |
| @@ -2288,7 +2278,7 @@ void gen_opi(int op) · 2133 unmodified lines | |||
| 2288 | break; | 2278 | break; |
| 2289 | 2279 | ||
| 2290 | case '/': | 2280 | case '/': |
| 2291 | t = ts_divi->tok; | 2281 | t = TOK__divi; |
| 2292 | call_func: | 2282 | call_func: |
| 2293 | vswap(); | 2283 | vswap(); |
| 2294 | /* call generic idiv function */ | 2284 | /* call generic idiv function */ |
| @@ -2301,13 +2291,13 @@ void gen_opi(int op) · 6 unmodified lines | |||
| 2301 | break; | 2291 | break; |
| 2302 | case TOK_UDIV: | 2292 | case TOK_UDIV: |
| 2303 | case TOK_PDIV: | 2293 | case TOK_PDIV: |
| 2304 | t = ts_divu->tok; | 2294 | t = TOK__divu; |
| 2305 | goto call_func; | 2295 | goto call_func; |
| 2306 | case '%': | 2296 | case '%': |
| 2307 | t = ts_remi->tok; | 2297 | t = TOK__remi; |
| 2308 | goto call_func; | 2298 | goto call_func; |
| 2309 | case TOK_UMOD: | 2299 | case TOK_UMOD: |
| 2310 | t = ts_remu->tok; | 2300 | t = TOK__remu; |
| 2311 | goto call_func; | 2301 | goto call_func; |
| 2312 | 2302 | ||
| 2313 | default: | 2303 | default: |
| @@ -2423,7 +2413,7 @@ void gen_opf(int op) · 109 unmodified lines | |||
| 2423 | // must call intrinsic DP floating point divide | 2413 | // must call intrinsic DP floating point divide |
| 2424 | vswap(); | 2414 | vswap(); |
| 2425 | /* call generic idiv function */ | 2415 | /* call generic idiv function */ |
| 2426 | vpush_global_sym(&func_old_type, ts_divd->tok); | 2416 | vpush_global_sym(&func_old_type, TOK__divd); |
| 2427 | vrott(3); | 2417 | vrott(3); |
| 2428 | gfunc_call(2); | 2418 | gfunc_call(2); |
| 2429 | vpushi(0); | 2419 | vpushi(0); |
| @@ -2434,7 +2424,7 @@ void gen_opf(int op) · 4 unmodified lines | |||
| 2434 | // must call intrinsic SP floating point divide | 2424 | // must call intrinsic SP floating point divide |
| 2435 | vswap(); | 2425 | vswap(); |
| 2436 | /* call generic idiv function */ | 2426 | /* call generic idiv function */ |
| 2437 | vpush_global_sym(&func_old_type, ts_divf->tok); | 2427 | vpush_global_sym(&func_old_type, TOK__divf); |
| 2438 | vrott(3); | 2428 | vrott(3); |
| 2439 | gfunc_call(2); | 2429 | gfunc_call(2); |
| 2440 | vpushi(0); | 2430 | vpushi(0); |
| @@ -0,0 +1,446 @@ | |||
| 1 | /**************************************************************************/ | ||
| 2 | /* COFF.H */ | ||
| 3 | /* COFF data structures and related definitions used by the linker */ | ||
| 4 | /**************************************************************************/ | ||
| 5 | |||
| 6 | /*------------------------------------------------------------------------*/ | ||
| 7 | /* COFF FILE HEADER */ | ||
| 8 | /*------------------------------------------------------------------------*/ | ||
| 9 | struct filehdr { | ||
| 10 | unsigned short f_magic; /* magic number */ | ||
| 11 | unsigned short f_nscns; /* number of sections */ | ||
| 12 | long f_timdat; /* time & date stamp */ | ||
| 13 | long f_symptr; /* file pointer to symtab */ | ||
| 14 | long f_nsyms; /* number of symtab entries */ | ||
| 15 | unsigned short f_opthdr; /* sizeof(optional hdr) */ | ||
| 16 | unsigned short f_flags; /* flags */ | ||
| 17 | unsigned short f_TargetID; /* for C6x = 0x0099 */ | ||
| 18 | }; | ||
| 19 | |||
| 20 | /*------------------------------------------------------------------------*/ | ||
| 21 | /* File header flags */ | ||
| 22 | /*------------------------------------------------------------------------*/ | ||
| 23 | #define F_RELFLG 0x01 /* relocation info stripped from file */ | ||
| 24 | #define F_EXEC 0x02 /* file is executable (no unresolved refs) */ | ||
| 25 | #define F_LNNO 0x04 /* line nunbers stripped from file */ | ||
| 26 | #define F_LSYMS 0x08 /* local symbols stripped from file */ | ||
| 27 | #define F_GSP10 0x10 /* 34010 version */ | ||
| 28 | #define F_GSP20 0x20 /* 34020 version */ | ||
| 29 | #define F_SWABD 0x40 /* bytes swabbed (in names) */ | ||
| 30 | #define F_AR16WR 0x80 /* byte ordering of an AR16WR (PDP-11) */ | ||
| 31 | #define F_LITTLE 0x100 /* byte ordering of an AR32WR (vax) */ | ||
| 32 | #define F_BIG 0x200 /* byte ordering of an AR32W (3B, maxi) */ | ||
| 33 | #define F_PATCH 0x400 /* contains "patch" list in optional header */ | ||
| 34 | #define F_NODF 0x400 | ||
| 35 | |||
| 36 | #define F_VERSION (F_GSP10 | F_GSP20) | ||
| 37 | #define F_BYTE_ORDER (F_LITTLE | F_BIG) | ||
| 38 | #define FILHDR struct filehdr | ||
| 39 | |||
| 40 | //#define FILHSZ sizeof(FILHDR) | ||
| 41 | #define FILHSZ 22 // above rounds to align on 4 bytes which causes problems | ||
| 42 | |||
| 43 | #define COFF_C67_MAGIC 0x00c2 | ||
| 44 | |||
| 45 | /*------------------------------------------------------------------------*/ | ||
| 46 | /* Macros to recognize magic numbers */ | ||
| 47 | /*------------------------------------------------------------------------*/ | ||
| 48 | #define ISMAGIC(x) (((unsigned short)(x))==(unsigned short)magic) | ||
| 49 | #define ISARCHIVE(x) ((((unsigned short)(x))==(unsigned short)ARTYPE)) | ||
| 50 | #define BADMAGIC(x) (((unsigned short)(x) & 0x8080) && !ISMAGIC(x)) | ||
| 51 | |||
| 52 | |||
| 53 | /*------------------------------------------------------------------------*/ | ||
| 54 | /* OPTIONAL FILE HEADER */ | ||
| 55 | /*------------------------------------------------------------------------*/ | ||
| 56 | typedef struct aouthdr { | ||
| 57 | short magic; /* see magic.h */ | ||
| 58 | short vstamp; /* version stamp */ | ||
| 59 | long tsize; /* text size in bytes, padded to FW bdry*/ | ||
| 60 | long dsize; /* initialized data " " */ | ||
| 61 | long bsize; /* uninitialized data " " */ | ||
| 62 | long entrypt; /* entry pt. */ | ||
| 63 | long text_start; /* base of text used for this file */ | ||
| 64 | long data_start; /* base of data used for this file */ | ||
| 65 | } AOUTHDR; | ||
| 66 | |||
| 67 | #define AOUTSZ sizeof(AOUTHDR) | ||
| 68 | |||
| 69 | /*----------------------------------------------------------------------*/ | ||
| 70 | /* When a UNIX aout header is to be built in the optional header, */ | ||
| 71 | /* the following magic numbers can appear in that header: */ | ||
| 72 | /* */ | ||
| 73 | /* AOUT1MAGIC : default : readonly sharable text segment */ | ||
| 74 | /* AOUT2MAGIC: : writable text segment */ | ||
| 75 | /* PAGEMAGIC : : configured for paging */ | ||
| 76 | /*----------------------------------------------------------------------*/ | ||
| 77 | #define AOUT1MAGIC 0410 | ||
| 78 | #define AOUT2MAGIC 0407 | ||
| 79 | #define PAGEMAGIC 0413 | ||
| 80 | |||
| 81 | |||
| 82 | /*------------------------------------------------------------------------*/ | ||
| 83 | /* COMMON ARCHIVE FILE STRUCTURES */ | ||
| 84 | /* */ | ||
| 85 | /* ARCHIVE File Organization: */ | ||
| 86 | /* _______________________________________________ */ | ||
| 87 | /* |__________ARCHIVE_MAGIC_STRING_______________| */ | ||
| 88 | /* |__________ARCHIVE_FILE_MEMBER_1______________| */ | ||
| 89 | /* | | */ | ||
| 90 | /* | Archive File Header "ar_hdr" | */ | ||
| 91 | /* |.............................................| */ | ||
| 92 | /* | Member Contents | */ | ||
| 93 | /* | 1. External symbol directory | */ | ||
| 94 | /* | 2. Text file | */ | ||
| 95 | /* |_____________________________________________| */ | ||
| 96 | /* |________ARCHIVE_FILE_MEMBER_2________________| */ | ||
| 97 | /* | "ar_hdr" | */ | ||
| 98 | /* |.............................................| */ | ||
| 99 | /* | Member Contents (.o or text file) | */ | ||
| 100 | /* |_____________________________________________| */ | ||
| 101 | /* | . . . | */ | ||
| 102 | /* | . . . | */ | ||
| 103 | /* | . . . | */ | ||
| 104 | /* |_____________________________________________| */ | ||
| 105 | /* |________ARCHIVE_FILE_MEMBER_n________________| */ | ||
| 106 | /* | "ar_hdr" | */ | ||
| 107 | /* |.............................................| */ | ||
| 108 | /* | Member Contents | */ | ||
| 109 | /* |_____________________________________________| */ | ||
| 110 | /* */ | ||
| 111 | /*------------------------------------------------------------------------*/ | ||
| 112 | |||
| 113 | #define COFF_ARMAG "!<arch>\n" | ||
| 114 | #define SARMAG 8 | ||
| 115 | #define ARFMAG "`\n" | ||
| 116 | |||
| 117 | struct ar_hdr /* archive file member header - printable ascii */ | ||
| 118 | { | ||
| 119 | char ar_name[16]; /* file member name - `/' terminated */ | ||
| 120 | char ar_date[12]; /* file member date - decimal */ | ||
| 121 | char ar_uid[6]; /* file member user id - decimal */ | ||
| 122 | char ar_gid[6]; /* file member group id - decimal */ | ||
| 123 | char ar_mode[8]; /* file member mode - octal */ | ||
| 124 | char ar_size[10]; /* file member size - decimal */ | ||
| 125 | char ar_fmag[2]; /* ARFMAG - string to end header */ | ||
| 126 | }; | ||
| 127 | |||
| 128 | |||
| 129 | /*------------------------------------------------------------------------*/ | ||
| 130 | /* SECTION HEADER */ | ||
| 131 | /*------------------------------------------------------------------------*/ | ||
| 132 | struct scnhdr { | ||
| 133 | char s_name[8]; /* section name */ | ||
| 134 | long s_paddr; /* physical address */ | ||
| 135 | long s_vaddr; /* virtual address */ | ||
| 136 | long s_size; /* section size */ | ||
| 137 | long s_scnptr; /* file ptr to raw data for section */ | ||
| 138 | long s_relptr; /* file ptr to relocation */ | ||
| 139 | long s_lnnoptr; /* file ptr to line numbers */ | ||
| 140 | unsigned int s_nreloc; /* number of relocation entries */ | ||
| 141 | unsigned int s_nlnno; /* number of line number entries */ | ||
| 142 | unsigned int s_flags; /* flags */ | ||
| 143 | unsigned short s_reserved; /* reserved byte */ | ||
| 144 | unsigned short s_page; /* memory page id */ | ||
| 145 | }; | ||
| 146 | |||
| 147 | #define SCNHDR struct scnhdr | ||
| 148 | #define SCNHSZ sizeof(SCNHDR) | ||
| 149 | |||
| 150 | /*------------------------------------------------------------------------*/ | ||
| 151 | /* Define constants for names of "special" sections */ | ||
| 152 | /*------------------------------------------------------------------------*/ | ||
| 153 | //#define _TEXT ".text" | ||
| 154 | #define _DATA ".data" | ||
| 155 | #define _BSS ".bss" | ||
| 156 | #define _CINIT ".cinit" | ||
| 157 | #define _TV ".tv" | ||
| 158 | |||
| 159 | /*------------------------------------------------------------------------*/ | ||
| 160 | /* The low 4 bits of s_flags is used as a section "type" */ | ||
| 161 | /*------------------------------------------------------------------------*/ | ||
| 162 | #define STYP_REG 0x00 /* "regular" : allocated, relocated, loaded */ | ||
| 163 | #define STYP_DSECT 0x01 /* "dummy" : not allocated, relocated, not loaded */ | ||
| 164 | #define STYP_NOLOAD 0x02 /* "noload" : allocated, relocated, not loaded */ | ||
| 165 | #define STYP_GROUP 0x04 /* "grouped" : formed of input sections */ | ||
| 166 | #define STYP_PAD 0x08 /* "padding" : not allocated, not relocated, loaded */ | ||
| 167 | #define STYP_COPY 0x10 /* "copy" : used for C init tables - | ||
| 168 | not allocated, relocated, | ||
| 169 | loaded; reloc & lineno | ||
| 170 | entries processed normally */ | ||
| 171 | #define STYP_TEXT 0x20 /* section contains text only */ | ||
| 172 | #define STYP_DATA 0x40 /* section contains data only */ | ||
| 173 | #define STYP_BSS 0x80 /* section contains bss only */ | ||
| 174 | |||
| 175 | #define STYP_ALIGN 0x100 /* align flag passed by old version assemblers */ | ||
| 176 | #define ALIGN_MASK 0x0F00 /* part of s_flags that is used for align vals */ | ||
| 177 | #define ALIGNSIZE(x) (1 << ((x & ALIGN_MASK) >> 8)) | ||
| 178 | |||
| 179 | |||
| 180 | /*------------------------------------------------------------------------*/ | ||
| 181 | /* RELOCATION ENTRIES */ | ||
| 182 | /*------------------------------------------------------------------------*/ | ||
| 183 | struct reloc | ||
| 184 | { | ||
| 185 | long r_vaddr; /* (virtual) address of reference */ | ||
| 186 | short r_symndx; /* index into symbol table */ | ||
| 187 | unsigned short r_disp; /* additional bits for address calculation */ | ||
| 188 | unsigned short r_type; /* relocation type */ | ||
| 189 | }; | ||
| 190 | |||
| 191 | #define RELOC struct reloc | ||
| 192 | #define RELSZ 10 /* sizeof(RELOC) */ | ||
| 193 | |||
| 194 | /*--------------------------------------------------------------------------*/ | ||
| 195 | /* define all relocation types */ | ||
| 196 | /*--------------------------------------------------------------------------*/ | ||
| 197 | |||
| 198 | #define R_ABS 0 /* absolute address - no relocation */ | ||
| 199 | #define R_DIR16 01 /* UNUSED */ | ||
| 200 | #define R_REL16 02 /* UNUSED */ | ||
| 201 | #define R_DIR24 04 /* UNUSED */ | ||
| 202 | #define R_REL24 05 /* 24 bits, direct */ | ||
| 203 | #define R_DIR32 06 /* UNUSED */ | ||
| 204 | #define R_RELBYTE 017 /* 8 bits, direct */ | ||
| 205 | #define R_RELWORD 020 /* 16 bits, direct */ | ||
| 206 | #define R_RELLONG 021 /* 32 bits, direct */ | ||
| 207 | #define R_PCRBYTE 022 /* 8 bits, PC-relative */ | ||
| 208 | #define R_PCRWORD 023 /* 16 bits, PC-relative */ | ||
| 209 | #define R_PCRLONG 024 /* 32 bits, PC-relative */ | ||
| 210 | #define R_OCRLONG 030 /* GSP: 32 bits, one's complement direct */ | ||
| 211 | #define R_GSPPCR16 031 /* GSP: 16 bits, PC relative (in words) */ | ||
| 212 | #define R_GSPOPR32 032 /* GSP: 32 bits, direct big-endian */ | ||
| 213 | #define R_PARTLS16 040 /* Brahma: 16 bit offset of 24 bit address*/ | ||
| 214 | #define R_PARTMS8 041 /* Brahma: 8 bit page of 24 bit address */ | ||
| 215 | #define R_PARTLS7 050 /* DSP: 7 bit offset of 16 bit address */ | ||
| 216 | #define R_PARTMS9 051 /* DSP: 9 bit page of 16 bit address */ | ||
| 217 | #define R_REL13 052 /* DSP: 13 bits, direct */ | ||
| 218 | |||
| 219 | |||
| 220 | /*------------------------------------------------------------------------*/ | ||
| 221 | /* LINE NUMBER ENTRIES */ | ||
| 222 | /*------------------------------------------------------------------------*/ | ||
| 223 | struct lineno | ||
| 224 | { | ||
| 225 | union | ||
| 226 | { | ||
| 227 | long l_symndx ; /* sym. table index of function name | ||
| 228 | iff l_lnno == 0 */ | ||
| 229 | long l_paddr ; /* (physical) address of line number */ | ||
| 230 | } l_addr ; | ||
| 231 | unsigned short l_lnno ; /* line number */ | ||
| 232 | }; | ||
| 233 | |||
| 234 | #define LINENO struct lineno | ||
| 235 | #define LINESZ 6 /* sizeof(LINENO) */ | ||
| 236 | |||
| 237 | |||
| 238 | /*------------------------------------------------------------------------*/ | ||
| 239 | /* STORAGE CLASSES */ | ||
| 240 | /*------------------------------------------------------------------------*/ | ||
| 241 | #define C_EFCN -1 /* physical end of function */ | ||
| 242 | #define C_NULL 0 | ||
| 243 | #define C_AUTO 1 /* automatic variable */ | ||
| 244 | #define C_EXT 2 /* external symbol */ | ||
| 245 | #define C_STAT 3 /* static */ | ||
| 246 | #define C_REG 4 /* register variable */ | ||
| 247 | #define C_EXTDEF 5 /* external definition */ | ||
| 248 | #define C_LABEL 6 /* label */ | ||
| 249 | #define C_ULABEL 7 /* undefined label */ | ||
| 250 | #define C_MOS 8 /* member of structure */ | ||
| 251 | #define C_ARG 9 /* function argument */ | ||
| 252 | #define C_STRTAG 10 /* structure tag */ | ||
| 253 | #define C_MOU 11 /* member of union */ | ||
| 254 | #define C_UNTAG 12 /* union tag */ | ||
| 255 | #define C_TPDEF 13 /* type definition */ | ||
| 256 | #define C_USTATIC 14 /* undefined static */ | ||
| 257 | #define C_ENTAG 15 /* enumeration tag */ | ||
| 258 | #define C_MOE 16 /* member of enumeration */ | ||
| 259 | #define C_REGPARM 17 /* register parameter */ | ||
| 260 | #define C_FIELD 18 /* bit field */ | ||
| 261 | |||
| 262 | #define C_BLOCK 100 /* ".bb" or ".eb" */ | ||
| 263 | #define C_FCN 101 /* ".bf" or ".ef" */ | ||
| 264 | #define C_EOS 102 /* end of structure */ | ||
| 265 | #define C_FILE 103 /* file name */ | ||
| 266 | #define C_LINE 104 /* dummy sclass for line number entry */ | ||
| 267 | #define C_ALIAS 105 /* duplicate tag */ | ||
| 268 | #define C_HIDDEN 106 /* special storage class for external */ | ||
| 269 | /* symbols in dmert public libraries */ | ||
| 270 | |||
| 271 | /*------------------------------------------------------------------------*/ | ||
| 272 | /* SYMBOL TABLE ENTRIES */ | ||
| 273 | /*------------------------------------------------------------------------*/ | ||
| 274 | |||
| 275 | #define SYMNMLEN 8 /* Number of characters in a symbol name */ | ||
| 276 | #define FILNMLEN 14 /* Number of characters in a file name */ | ||
| 277 | #define DIMNUM 4 /* Number of array dimensions in auxiliary entry */ | ||
| 278 | |||
| 279 | |||
| 280 | struct syment | ||
| 281 | { | ||
| 282 | union | ||
| 283 | { | ||
| 284 | char _n_name[SYMNMLEN]; /* old COFF version */ | ||
| 285 | struct | ||
| 286 | { | ||
| 287 | long _n_zeroes; /* new == 0 */ | ||
| 288 | long _n_offset; /* offset into string table */ | ||
| 289 | } _n_n; | ||
| 290 | char *_n_nptr[2]; /* allows for overlaying */ | ||
| 291 | } _n; | ||
| 292 | long n_value; /* value of symbol */ | ||
| 293 | short n_scnum; /* section number */ | ||
| 294 | unsigned short n_type; /* type and derived type */ | ||
| 295 | char n_sclass; /* storage class */ | ||
| 296 | char n_numaux; /* number of aux. entries */ | ||
| 297 | }; | ||
| 298 | |||
| 299 | #define n_name _n._n_name | ||
| 300 | #define n_nptr _n._n_nptr[1] | ||
| 301 | #define n_zeroes _n._n_n._n_zeroes | ||
| 302 | #define n_offset _n._n_n._n_offset | ||
| 303 | |||
| 304 | /*------------------------------------------------------------------------*/ | ||
| 305 | /* Relocatable symbols have a section number of the */ | ||
| 306 | /* section in which they are defined. Otherwise, section */ | ||
| 307 | /* numbers have the following meanings: */ | ||
| 308 | /*------------------------------------------------------------------------*/ | ||
| 309 | #define N_UNDEF 0 /* undefined symbol */ | ||
| 310 | #define N_ABS -1 /* value of symbol is absolute */ | ||
| 311 | #define N_DEBUG -2 /* special debugging symbol */ | ||
| 312 | #define N_TV (unsigned short)-3 /* needs transfer vector (preload) */ | ||
| 313 | #define P_TV (unsigned short)-4 /* needs transfer vector (postload) */ | ||
| 314 | |||
| 315 | |||
| 316 | /*------------------------------------------------------------------------*/ | ||
| 317 | /* The fundamental type of a symbol packed into the low */ | ||
| 318 | /* 4 bits of the word. */ | ||
| 319 | /*------------------------------------------------------------------------*/ | ||
| 320 | #define _EF ".ef" | ||
| 321 | |||
| 322 | #define T_NULL 0 /* no type info */ | ||
| 323 | #define T_ARG 1 /* function argument (only used by compiler) */ | ||
| 324 | #define T_CHAR 2 /* character */ | ||
| 325 | #define T_SHORT 3 /* short integer */ | ||
| 326 | #define T_INT 4 /* integer */ | ||
| 327 | #define T_LONG 5 /* long integer */ | ||
| 328 | #define T_FLOAT 6 /* floating point */ | ||
| 329 | #define T_DOUBLE 7 /* double word */ | ||
| 330 | #define T_STRUCT 8 /* structure */ | ||
| 331 | #define T_UNION 9 /* union */ | ||
| 332 | #define T_ENUM 10 /* enumeration */ | ||
| 333 | #define T_MOE 11 /* member of enumeration */ | ||
| 334 | #define T_UCHAR 12 /* unsigned character */ | ||
| 335 | #define T_USHORT 13 /* unsigned short */ | ||
| 336 | #define T_UINT 14 /* unsigned integer */ | ||
| 337 | #define T_ULONG 15 /* unsigned long */ | ||
| 338 | |||
| 339 | /*------------------------------------------------------------------------*/ | ||
| 340 | /* derived types are: */ | ||
| 341 | /*------------------------------------------------------------------------*/ | ||
| 342 | #define DT_NON 0 /* no derived type */ | ||
| 343 | #define DT_PTR 1 /* pointer */ | ||
| 344 | #define DT_FCN 2 /* function */ | ||
| 345 | #define DT_ARY 3 /* array */ | ||
| 346 | |||
| 347 | #define MKTYPE(basic, d1,d2,d3,d4,d5,d6) \ | ||
| 348 | ((basic) | ((d1) << 4) | ((d2) << 6) | ((d3) << 8) |\ | ||
| 349 | ((d4) << 10) | ((d5) << 12) | ((d6) << 14)) | ||
| 350 | |||
| 351 | /*------------------------------------------------------------------------*/ | ||
| 352 | /* type packing constants and macros */ | ||
| 353 | /*------------------------------------------------------------------------*/ | ||
| 354 | #define N_BTMASK_COFF 017 | ||
| 355 | #define N_TMASK_COFF 060 | ||
| 356 | #define N_TMASK1_COFF 0300 | ||
| 357 | #define N_TMASK2_COFF 0360 | ||
| 358 | #define N_BTSHFT_COFF 4 | ||
| 359 | #define N_TSHIFT_COFF 2 | ||
| 360 | |||
| 361 | #define BTYPE_COFF(x) ((x) & N_BTMASK_COFF) | ||
| 362 | #define ISINT(x) (((x) >= T_CHAR && (x) <= T_LONG) || \ | ||
| 363 | ((x) >= T_UCHAR && (x) <= T_ULONG) || (x) == T_ENUM) | ||
| 364 | #define ISFLT_COFF(x) ((x) == T_DOUBLE || (x) == T_FLOAT) | ||
| 365 | #define ISPTR_COFF(x) (((x) & N_TMASK_COFF) == (DT_PTR << N_BTSHFT_COFF)) | ||
| 366 | #define ISFCN_COFF(x) (((x) & N_TMASK_COFF) == (DT_FCN << N_BTSHFT_COFF)) | ||
| 367 | #define ISARY_COFF(x) (((x) & N_TMASK_COFF) == (DT_ARY << N_BTSHFT_COFF)) | ||
| 368 | #define ISTAG_COFF(x) ((x)==C_STRTAG || (x)==C_UNTAG || (x)==C_ENTAG) | ||
| 369 | |||
| 370 | #define INCREF_COFF(x) ((((x)&~N_BTMASK_COFF)<<N_TSHIFT_COFF)|(DT_PTR<<N_BTSHFT_COFF)|(x&N_BTMASK_COFF)) | ||
| 371 | #define DECREF_COFF(x) ((((x)>>N_TSHIFT_COFF)&~N_BTMASK_COFF)|((x)&N_BTMASK_COFF)) | ||
| 372 | |||
| 373 | |||
| 374 | /*------------------------------------------------------------------------*/ | ||
| 375 | /* AUXILIARY SYMBOL ENTRY */ | ||
| 376 | /*------------------------------------------------------------------------*/ | ||
| 377 | union auxent | ||
| 378 | { | ||
| 379 | struct | ||
| 380 | { | ||
| 381 | long x_tagndx; /* str, un, or enum tag indx */ | ||
| 382 | union | ||
| 383 | { | ||
| 384 | struct | ||
| 385 | { | ||
| 386 | unsigned short x_lnno; /* declaration line number */ | ||
| 387 | unsigned short x_size; /* str, union, array size */ | ||
| 388 | } x_lnsz; | ||
| 389 | long x_fsize; /* size of function */ | ||
| 390 | } x_misc; | ||
| 391 | union | ||
| 392 | { | ||
| 393 | struct /* if ISFCN, tag, or .bb */ | ||
| 394 | { | ||
| 395 | long x_lnnoptr; /* ptr to fcn line # */ | ||
| 396 | long x_endndx; /* entry ndx past block end */ | ||
| 397 | } x_fcn; | ||
| 398 | struct /* if ISARY, up to 4 dimen. */ | ||
| 399 | { | ||
| 400 | unsigned short x_dimen[DIMNUM]; | ||
| 401 | } x_ary; | ||
| 402 | } x_fcnary; | ||
| 403 | unsigned short x_regcount; /* number of registers used by func */ | ||
| 404 | } x_sym; | ||
| 405 | struct | ||
| 406 | { | ||
| 407 | char x_fname[FILNMLEN]; | ||
| 408 | } x_file; | ||
| 409 | struct | ||
| 410 | { | ||
| 411 | long x_scnlen; /* section length */ | ||
| 412 | unsigned short x_nreloc; /* number of relocation entries */ | ||
| 413 | unsigned short x_nlinno; /* number of line numbers */ | ||
| 414 | } x_scn; | ||
| 415 | }; | ||
| 416 | |||
| 417 | #define SYMENT struct syment | ||
| 418 | #define SYMESZ 18 /* sizeof(SYMENT) */ | ||
| 419 | |||
| 420 | #define AUXENT union auxent | ||
| 421 | #define AUXESZ 18 /* sizeof(AUXENT) */ | ||
| 422 | |||
| 423 | /*------------------------------------------------------------------------*/ | ||
| 424 | /* NAMES OF "SPECIAL" SYMBOLS */ | ||
| 425 | /*------------------------------------------------------------------------*/ | ||
| 426 | #define _STEXT ".text" | ||
| 427 | #define _ETEXT "etext" | ||
| 428 | #define _SDATA ".data" | ||
| 429 | #define _EDATA "edata" | ||
| 430 | #define _SBSS ".bss" | ||
| 431 | #define _END "end" | ||
| 432 | #define _CINITPTR "cinit" | ||
| 433 | |||
| 434 | /*--------------------------------------------------------------------------*/ | ||
| 435 | /* ENTRY POINT SYMBOLS */ | ||
| 436 | /*--------------------------------------------------------------------------*/ | ||
| 437 | #define _START "_start" | ||
| 438 | #define _MAIN "_main" | ||
| 439 | /* _CSTART "_c_int00" (defined in params.h) */ | ||
| 440 | |||
| 441 | |||
| 442 | #define _TVORIG "_tvorig" | ||
| 443 | #define _TORIGIN "_torigin" | ||
| 444 | #define _DORIGIN "_dorigin" | ||
| 445 | |||
| 446 | #define _SORIGIN "_sorigin" | ||
| @@ -80,6 +80,11 @@ · 79 unmodified lines | |||
| 80 | #define CONFIG_TCC_ASM | 80 | #define CONFIG_TCC_ASM |
| 81 | #endif | 81 | #endif |
| 82 | 82 | ||
| 83 | /* object format selection */ | ||
| 84 | #if defined(TCC_TARGET_C67) | ||
| 85 | #define TCC_TARGET_COFF | ||
| 86 | #endif | ||
| 87 | |||
| 83 | #if !defined(WIN32) | 88 | #if !defined(WIN32) |
| 84 | #define FALSE 0 | 89 | #define FALSE 0 |
| 85 | #define false 0 | 90 | #define false 0 |
| @@ -765,6 +770,9 @@ static int tcc_add_dll(TCCState *s, const char *filename, int flags); · 679 unmodified lines | |||
| 765 | #define AFF_REFERENCED_DLL 0x0002 /* load a referenced dll from another dll */ | 770 | #define AFF_REFERENCED_DLL 0x0002 /* load a referenced dll from another dll */ |
| 766 | static int tcc_add_file_internal(TCCState *s, const char *filename, int flags); | 771 | static int tcc_add_file_internal(TCCState *s, const char *filename, int flags); |
| 767 | 772 | ||
| 773 | /* tcccoff.c */ | ||
| 774 | int tcc_output_coff(TCCState *s1, const char *OutFile); | ||
| 775 | |||
| 768 | /* tccasm.c */ | 776 | /* tccasm.c */ |
| 769 | 777 | ||
| 770 | #ifdef CONFIG_TCC_ASM | 778 | #ifdef CONFIG_TCC_ASM |
| @@ -5577,7 +5585,11 @@ static void gen_cast(CType *type) · 4806 unmodified lines | |||
| 5577 | } | 5585 | } |
| 5578 | } else { | 5586 | } else { |
| 5579 | do_itof: | 5587 | do_itof: |
| 5588 | #if !defined(TCC_TARGET_ARM) | ||
| 5589 | gen_cvt_itof1(dbt); | ||
| 5590 | #else | ||
| 5580 | gen_cvt_itof(dbt); | 5591 | gen_cvt_itof(dbt); |
| 5592 | #endif | ||
| 5581 | } | 5593 | } |
| 5582 | } else if (sf) { | 5594 | } else if (sf) { |
| 5583 | /* convert fp to int */ | 5595 | /* convert fp to int */ |
| @@ -9003,6 +9015,10 @@ static void asm_instr(void) · 3419 unmodified lines | |||
| 9003 | 9015 | ||
| 9004 | #include "tccelf.c" | 9016 | #include "tccelf.c" |
| 9005 | 9017 | ||
| 9018 | #ifdef TCC_TARGET_COFF | ||
| 9019 | #include "tcccoff.c" | ||
| 9020 | #endif | ||
| 9021 | |||
| 9006 | /* print the position in the source file of PC value 'pc' by reading | 9022 | /* print the position in the source file of PC value 'pc' by reading |
| 9007 | the stabs debug information */ | 9023 | the stabs debug information */ |
| 9008 | static void rt_printline(unsigned long wanted_pc) | 9024 | static void rt_printline(unsigned long wanted_pc) |
| @@ -9545,7 +9561,7 @@ static int tcc_add_file_internal(TCCState *s1, const char *filename, int flags) · 536 unmodified lines | |||
| 9545 | } else if (ret != sizeof(ehdr)) { | 9561 | } else if (ret != sizeof(ehdr)) { |
| 9546 | goto try_load_script; | 9562 | goto try_load_script; |
| 9547 | } | 9563 | } |
| 9548 | 9564 | ||
| 9549 | if (ehdr.e_ident[0] == ELFMAG0 && | 9565 | if (ehdr.e_ident[0] == ELFMAG0 && |
| 9550 | ehdr.e_ident[1] == ELFMAG1 && | 9566 | ehdr.e_ident[1] == ELFMAG1 && |
| 9551 | ehdr.e_ident[2] == ELFMAG2 && | 9567 | ehdr.e_ident[2] == ELFMAG2 && |
| @@ -9572,7 +9588,13 @@ static int tcc_add_file_internal(TCCState *s1, const char *filename, int flags) · 20 unmodified lines | |||
| 9572 | } else if (memcmp((char *)&ehdr, ARMAG, 8) == 0) { | 9588 | } else if (memcmp((char *)&ehdr, ARMAG, 8) == 0) { |
| 9573 | file->line_num = 0; /* do not display line number if error */ | 9589 | file->line_num = 0; /* do not display line number if error */ |
| 9574 | ret = tcc_load_archive(s1, fd); | 9590 | ret = tcc_load_archive(s1, fd); |
| 9575 | } else { | 9591 | } else |
| 9592 | #ifdef TCC_TARGET_COFF | ||
| 9593 | if (*(uint16_t *)(&ehdr) == COFF_C67_MAGIC) { | ||
| 9594 | ret = tcc_load_coff(s1, fd); | ||
| 9595 | } else | ||
| 9596 | #endif | ||
| 9597 | { | ||
| 9576 | /* as GNU ld, consider it is an ld script if not recognized */ | 9598 | /* as GNU ld, consider it is an ld script if not recognized */ |
| 9577 | try_load_script: | 9599 | try_load_script: |
| 9578 | ret = tcc_load_ldscript(s1); | 9600 | ret = tcc_load_ldscript(s1); |
| @@ -0,0 +1,982 @@ | |||
| 1 | /* | ||
| 2 | * COFF file handling for TCC | ||
| 3 | * | ||
| 4 | * Copyright (c) 2003, 2004 TK | ||
| 5 | * Copyright (c) 2004 Fabrice Bellard | ||
| 6 | * | ||
| 7 | * This library is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This library is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with this library; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 20 | */ | ||
| 21 | #include "coff.h" | ||
| 22 | |||
| 23 | #define MAXNSCNS 255 /* MAXIMUM NUMBER OF SECTIONS */ | ||
| 24 | #define MAX_STR_TABLE 1000000 | ||
| 25 | AOUTHDR o_filehdr; /* OPTIONAL (A.OUT) FILE HEADER */ | ||
| 26 | |||
| 27 | SCNHDR section_header[MAXNSCNS]; | ||
| 28 | |||
| 29 | #define MAX_FUNCS 1000 | ||
| 30 | #define MAX_FUNC_NAME_LENGTH 128 | ||
| 31 | |||
| 32 | int nFuncs; | ||
| 33 | char Func[MAX_FUNCS][MAX_FUNC_NAME_LENGTH]; | ||
| 34 | char AssociatedFile[MAX_FUNCS][MAX_FUNC_NAME_LENGTH]; | ||
| 35 | int LineNoFilePtr[MAX_FUNCS]; | ||
| 36 | int EndAddress[MAX_FUNCS]; | ||
| 37 | int LastLineNo[MAX_FUNCS]; | ||
| 38 | int FuncEntries[MAX_FUNCS]; | ||
| 39 | |||
| 40 | BOOL OutputTheSection(Section * sect); | ||
| 41 | short int GetCoffFlags(const char *s); | ||
| 42 | void SortSymbolTable(void); | ||
| 43 | Section *FindSection(TCCState * s1, const char *sname); | ||
| 44 | |||
| 45 | int C67_main_entry_point; | ||
| 46 | |||
| 47 | int FindCoffSymbolIndex(const char *func_name); | ||
| 48 | int nb_syms; | ||
| 49 | |||
| 50 | typedef struct { | ||
| 51 | long tag; | ||
| 52 | long size; | ||
| 53 | long fileptr; | ||
| 54 | long nextsym; | ||
| 55 | short int dummy; | ||
| 56 | } AUXFUNC; | ||
| 57 | |||
| 58 | typedef struct { | ||
| 59 | long regmask; | ||
| 60 | unsigned short lineno; | ||
| 61 | unsigned short nentries; | ||
| 62 | int localframe; | ||
| 63 | int nextentry; | ||
| 64 | short int dummy; | ||
| 65 | } AUXBF; | ||
| 66 | |||
| 67 | typedef struct { | ||
| 68 | long dummy; | ||
| 69 | unsigned short lineno; | ||
| 70 | unsigned short dummy1; | ||
| 71 | int dummy2; | ||
| 72 | int dummy3; | ||
| 73 | unsigned short dummy4; | ||
| 74 | } AUXEF; | ||
| 75 | |||
| 76 | int tcc_output_coff(TCCState *s1, const char *OutFile) | ||
| 77 | { | ||
| 78 | FILE *f; | ||
| 79 | Section *tcc_sect; | ||
| 80 | SCNHDR *coff_sec; | ||
| 81 | int file_pointer; | ||
| 82 | char *Coff_str_table, *pCoff_str_table; | ||
| 83 | int CoffTextSectionNo, coff_nb_syms; | ||
| 84 | FILHDR file_hdr; /* FILE HEADER STRUCTURE */ | ||
| 85 | Section *stext, *sdata, *sbss; | ||
| 86 | |||
| 87 | f = fopen(OutFile, "wb"); | ||
| 88 | |||
| 89 | if (!f) { | ||
| 90 | error("Unable to open output file"); | ||
| 91 | } | ||
| 92 | |||
| 93 | stext = FindSection(s1, ".text"); | ||
| 94 | sdata = FindSection(s1, ".data"); | ||
| 95 | sbss = FindSection(s1, ".bss"); | ||
| 96 | |||
| 97 | nb_syms = symtab_section->data_offset / sizeof(Elf32_Sym); | ||
| 98 | coff_nb_syms = FindCoffSymbolIndex("XXXXXXXXXX1"); | ||
| 99 | |||
| 100 | file_hdr.f_magic = COFF_C67_MAGIC; /* magic number */ | ||
| 101 | file_hdr.f_timdat = 0; /* time & date stamp */ | ||
| 102 | file_hdr.f_opthdr = sizeof(AOUTHDR); /* sizeof(optional hdr) */ | ||
| 103 | file_hdr.f_flags = 0x1143; /* flags (copied from what code composer does) */ | ||
| 104 | file_hdr.f_TargetID = 0x99; /* for C6x = 0x0099 */ | ||
| 105 | |||
| 106 | o_filehdr.magic = 0x0108; /* see magic.h */ | ||
| 107 | o_filehdr.vstamp = 0x0190; /* version stamp */ | ||
| 108 | o_filehdr.tsize = stext->data_offset; /* text size in bytes, padded to FW bdry */ | ||
| 109 | o_filehdr.dsize = sdata->data_offset; /* initialized data " " */ | ||
| 110 | o_filehdr.bsize = sbss->data_offset; /* uninitialized data " " */ | ||
| 111 | o_filehdr.entrypt = C67_main_entry_point; /* entry pt. */ | ||
| 112 | o_filehdr.text_start = stext->sh_addr; /* base of text used for this file */ | ||
| 113 | o_filehdr.data_start = sdata->sh_addr; /* base of data used for this file */ | ||
| 114 | |||
| 115 | |||
| 116 | // create all the section headers | ||
| 117 | |||
| 118 | int i, NSectionsToOutput = 0; | ||
| 119 | |||
| 120 | file_pointer = FILHSZ + sizeof(AOUTHDR); | ||
| 121 | |||
| 122 | CoffTextSectionNo = -1; | ||
| 123 | |||
| 124 | for (i = 1; i < s1->nb_sections; i++) { | ||
| 125 | coff_sec = §ion_header[i]; | ||
| 126 | tcc_sect = s1->sections[i]; | ||
| 127 | |||
| 128 | if (OutputTheSection(tcc_sect)) { | ||
| 129 | NSectionsToOutput++; | ||
| 130 | |||
| 131 | if (CoffTextSectionNo == -1 && tcc_sect == stext) | ||
| 132 | CoffTextSectionNo = NSectionsToOutput; // rem which coff sect number the .text sect is | ||
| 133 | |||
| 134 | strcpy(coff_sec->s_name, tcc_sect->name); /* section name */ | ||
| 135 | |||
| 136 | coff_sec->s_paddr = tcc_sect->sh_addr; /* physical address */ | ||
| 137 | coff_sec->s_vaddr = tcc_sect->sh_addr; /* virtual address */ | ||
| 138 | coff_sec->s_size = tcc_sect->data_offset; /* section size */ | ||
| 139 | coff_sec->s_scnptr = 0; /* file ptr to raw data for section */ | ||
| 140 | coff_sec->s_relptr = 0; /* file ptr to relocation */ | ||
| 141 | coff_sec->s_lnnoptr = 0; /* file ptr to line numbers */ | ||
| 142 | coff_sec->s_nreloc = 0; /* number of relocation entries */ | ||
| 143 | coff_sec->s_flags = GetCoffFlags(coff_sec->s_name); /* flags */ | ||
| 144 | coff_sec->s_reserved = 0; /* reserved byte */ | ||
| 145 | coff_sec->s_page = 0; /* memory page id */ | ||
| 146 | |||
| 147 | file_pointer += sizeof(SCNHDR); | ||
| 148 | } | ||
| 149 | } | ||
| 150 | |||
| 151 | file_hdr.f_nscns = NSectionsToOutput; /* number of sections */ | ||
| 152 | |||
| 153 | // now loop through and determine file pointer locations | ||
| 154 | // for the raw data | ||
| 155 | |||
| 156 | |||
| 157 | for (i = 1; i < s1->nb_sections; i++) { | ||
| 158 | coff_sec = §ion_header[i]; | ||
| 159 | tcc_sect = s1->sections[i]; | ||
| 160 | |||
| 161 | if (OutputTheSection(tcc_sect)) { | ||
| 162 | // put raw data | ||
| 163 | coff_sec->s_scnptr = file_pointer; /* file ptr to raw data for section */ | ||
| 164 | file_pointer += coff_sec->s_size; | ||
| 165 | } | ||
| 166 | } | ||
| 167 | |||
| 168 | // now loop through and determine file pointer locations | ||
| 169 | // for the relocation data | ||
| 170 | |||
| 171 | for (i = 1; i < s1->nb_sections; i++) { | ||
| 172 | coff_sec = §ion_header[i]; | ||
| 173 | tcc_sect = s1->sections[i]; | ||
| 174 | |||
| 175 | if (OutputTheSection(tcc_sect)) { | ||
| 176 | // put relocations data | ||
| 177 | if (coff_sec->s_nreloc > 0) { | ||
| 178 | coff_sec->s_relptr = file_pointer; /* file ptr to relocation */ | ||
| 179 | file_pointer += coff_sec->s_nreloc * sizeof(struct reloc); | ||
| 180 | } | ||
| 181 | } | ||
| 182 | } | ||
| 183 | |||
| 184 | // now loop through and determine file pointer locations | ||
| 185 | // for the line number data | ||
| 186 | |||
| 187 | for (i = 1; i < s1->nb_sections; i++) { | ||
| 188 | coff_sec = §ion_header[i]; | ||
| 189 | tcc_sect = s1->sections[i]; | ||
| 190 | |||
| 191 | coff_sec->s_nlnno = 0; | ||
| 192 | coff_sec->s_lnnoptr = 0; | ||
| 193 | |||
| 194 | if (do_debug && tcc_sect == stext) { | ||
| 195 | // count how many line nos data | ||
| 196 | |||
| 197 | // also find association between source file name and function | ||
| 198 | // so we can sort the symbol table | ||
| 199 | |||
| 200 | |||
| 201 | Stab_Sym *sym, *sym_end; | ||
| 202 | char func_name[MAX_FUNC_NAME_LENGTH], | ||
| 203 | last_func_name[MAX_FUNC_NAME_LENGTH]; | ||
| 204 | unsigned long func_addr, last_pc, pc; | ||
| 205 | const char *incl_files[INCLUDE_STACK_SIZE]; | ||
| 206 | int incl_index, len, last_line_num; | ||
| 207 | const char *str, *p; | ||
| 208 | |||
| 209 | coff_sec->s_lnnoptr = file_pointer; /* file ptr to linno */ | ||
| 210 | |||
| 211 | |||
| 212 | func_name[0] = '\0'; | ||
| 213 | func_addr = 0; | ||
| 214 | incl_index = 0; | ||
| 215 | last_func_name[0] = '\0'; | ||
| 216 | last_pc = 0xffffffff; | ||
| 217 | last_line_num = 1; | ||
| 218 | sym = (Stab_Sym *) stab_section->data + 1; | ||
| 219 | sym_end = | ||
| 220 | (Stab_Sym *) (stab_section->data + | ||
| 221 | stab_section->data_offset); | ||
| 222 | |||
| 223 | nFuncs = 0; | ||
| 224 | while (sym < sym_end) { | ||
| 225 | switch (sym->n_type) { | ||
| 226 | /* function start or end */ | ||
| 227 | case N_FUN: | ||
| 228 | if (sym->n_strx == 0) { | ||
| 229 | // end of function | ||
| 230 | |||
| 231 | coff_sec->s_nlnno++; | ||
| 232 | file_pointer += LINESZ; | ||
| 233 | |||
| 234 | pc = sym->n_value + func_addr; | ||
| 235 | func_name[0] = '\0'; | ||
| 236 | func_addr = 0; | ||
| 237 | EndAddress[nFuncs] = pc; | ||
| 238 | FuncEntries[nFuncs] = | ||
| 239 | (file_pointer - | ||
| 240 | LineNoFilePtr[nFuncs]) / LINESZ; | ||
| 241 | LastLineNo[nFuncs++] = last_line_num + 1; | ||
| 242 | } else { | ||
| 243 | // beginning of function | ||
| 244 | |||
| 245 | LineNoFilePtr[nFuncs] = file_pointer; | ||
| 246 | coff_sec->s_nlnno++; | ||
| 247 | file_pointer += LINESZ; | ||
| 248 | |||
| 249 | str = | ||
| 250 | (const char *) stabstr_section->data + | ||
| 251 | sym->n_strx; | ||
| 252 | |||
| 253 | p = strchr(str, ':'); | ||
| 254 | if (!p) { | ||
| 255 | pstrcpy(func_name, sizeof(func_name), str); | ||
| 256 | pstrcpy(Func[nFuncs], sizeof(func_name), str); | ||
| 257 | } else { | ||
| 258 | len = p - str; | ||
| 259 | if (len > sizeof(func_name) - 1) | ||
| 260 | len = sizeof(func_name) - 1; | ||
| 261 | memcpy(func_name, str, len); | ||
| 262 | memcpy(Func[nFuncs], str, len); | ||
| 263 | func_name[len] = '\0'; | ||
| 264 | } | ||
| 265 | |||
| 266 | // save the file that it came in so we can sort later | ||
| 267 | pstrcpy(AssociatedFile[nFuncs], sizeof(func_name), | ||
| 268 | incl_files[incl_index - 1]); | ||
| 269 | |||
| 270 | func_addr = sym->n_value; | ||
| 271 | } | ||
| 272 | break; | ||
| 273 | |||
| 274 | /* line number info */ | ||
| 275 | case N_SLINE: | ||
| 276 | pc = sym->n_value + func_addr; | ||
| 277 | |||
| 278 | last_pc = pc; | ||
| 279 | last_line_num = sym->n_desc; | ||
| 280 | |||
| 281 | /* XXX: slow! */ | ||
| 282 | strcpy(last_func_name, func_name); | ||
| 283 | |||
| 284 | coff_sec->s_nlnno++; | ||
| 285 | file_pointer += LINESZ; | ||
| 286 | break; | ||
| 287 | /* include files */ | ||
| 288 | case N_BINCL: | ||
| 289 | str = | ||
| 290 | (const char *) stabstr_section->data + sym->n_strx; | ||
| 291 | add_incl: | ||
| 292 | if (incl_index < INCLUDE_STACK_SIZE) { | ||
| 293 | incl_files[incl_index++] = str; | ||
| 294 | } | ||
| 295 | break; | ||
| 296 | case N_EINCL: | ||
| 297 | if (incl_index > 1) | ||
| 298 | incl_index--; | ||
| 299 | break; | ||
| 300 | case N_SO: | ||
| 301 | if (sym->n_strx == 0) { | ||
| 302 | incl_index = 0; /* end of translation unit */ | ||
| 303 | } else { | ||
| 304 | str = | ||
| 305 | (const char *) stabstr_section->data + | ||
| 306 | sym->n_strx; | ||
| 307 | /* do not add path */ | ||
| 308 | len = strlen(str); | ||
| 309 | if (len > 0 && str[len - 1] != '/') | ||
| 310 | goto add_incl; | ||
| 311 | } | ||
| 312 | break; | ||
| 313 | } | ||
| 314 | sym++; | ||
| 315 | } | ||
| 316 | } | ||
| 317 | |||
| 318 | } | ||
| 319 | |||
| 320 | file_hdr.f_symptr = file_pointer; /* file pointer to symtab */ | ||
| 321 | |||
| 322 | if (do_debug) | ||
| 323 | file_hdr.f_nsyms = coff_nb_syms; /* number of symtab entries */ | ||
| 324 | else | ||
| 325 | file_hdr.f_nsyms = 0; | ||
| 326 | |||
| 327 | file_pointer += file_hdr.f_nsyms * SYMNMLEN; | ||
| 328 | |||
| 329 | // OK now we are all set to write the file | ||
| 330 | |||
| 331 | |||
| 332 | fwrite(&file_hdr, FILHSZ, 1, f); | ||
| 333 | fwrite(&o_filehdr, sizeof(o_filehdr), 1, f); | ||
| 334 | |||
| 335 | // write section headers | ||
| 336 | for (i = 1; i < s1->nb_sections; i++) { | ||
| 337 | coff_sec = §ion_header[i]; | ||
| 338 | tcc_sect = s1->sections[i]; | ||
| 339 | |||
| 340 | if (OutputTheSection(tcc_sect)) { | ||
| 341 | fwrite(coff_sec, sizeof(SCNHDR), 1, f); | ||
| 342 | } | ||
| 343 | } | ||
| 344 | |||
| 345 | // write raw data | ||
| 346 | for (i = 1; i < s1->nb_sections; i++) { | ||
| 347 | coff_sec = §ion_header[i]; | ||
| 348 | tcc_sect = s1->sections[i]; | ||
| 349 | |||
| 350 | if (OutputTheSection(tcc_sect)) { | ||
| 351 | fwrite(tcc_sect->data, tcc_sect->data_offset, 1, f); | ||
| 352 | } | ||
| 353 | } | ||
| 354 | |||
| 355 | // write relocation data | ||
| 356 | for (i = 1; i < s1->nb_sections; i++) { | ||
| 357 | coff_sec = §ion_header[i]; | ||
| 358 | tcc_sect = s1->sections[i]; | ||
| 359 | |||
| 360 | if (OutputTheSection(tcc_sect)) { | ||
| 361 | // put relocations data | ||
| 362 | if (coff_sec->s_nreloc > 0) { | ||
| 363 | fwrite(tcc_sect->reloc, | ||
| 364 | coff_sec->s_nreloc * sizeof(struct reloc), 1, f); | ||
| 365 | } | ||
| 366 | } | ||
| 367 | } | ||
| 368 | |||
| 369 | |||
| 370 | // group the symbols in order of filename, func1, func2, etc | ||
| 371 | // finally global symbols | ||
| 372 | |||
| 373 | if (do_debug) | ||
| 374 | SortSymbolTable(); | ||
| 375 | |||
| 376 | // write line no data | ||
| 377 | |||
| 378 | for (i = 1; i < s1->nb_sections; i++) { | ||
| 379 | coff_sec = §ion_header[i]; | ||
| 380 | tcc_sect = s1->sections[i]; | ||
| 381 | |||
| 382 | if (do_debug && tcc_sect == stext) { | ||
| 383 | // count how many line nos data | ||
| 384 | |||
| 385 | |||
| 386 | Stab_Sym *sym, *sym_end; | ||
| 387 | char func_name[128], last_func_name[128]; | ||
| 388 | unsigned long func_addr, last_pc, pc; | ||
| 389 | const char *incl_files[INCLUDE_STACK_SIZE]; | ||
| 390 | int incl_index, len, last_line_num; | ||
| 391 | const char *str, *p; | ||
| 392 | |||
| 393 | LINENO CoffLineNo; | ||
| 394 | |||
| 395 | func_name[0] = '\0'; | ||
| 396 | func_addr = 0; | ||
| 397 | incl_index = 0; | ||
| 398 | last_func_name[0] = '\0'; | ||
| 399 | last_pc = 0; | ||
| 400 | last_line_num = 1; | ||
| 401 | sym = (Stab_Sym *) stab_section->data + 1; | ||
| 402 | sym_end = | ||
| 403 | (Stab_Sym *) (stab_section->data + | ||
| 404 | stab_section->data_offset); | ||
| 405 | |||
| 406 | while (sym < sym_end) { | ||
| 407 | switch (sym->n_type) { | ||
| 408 | /* function start or end */ | ||
| 409 | case N_FUN: | ||
| 410 | if (sym->n_strx == 0) { | ||
| 411 | // end of function | ||
| 412 | |||
| 413 | CoffLineNo.l_addr.l_paddr = last_pc; | ||
| 414 | CoffLineNo.l_lnno = last_line_num + 1; | ||
| 415 | fwrite(&CoffLineNo, 6, 1, f); | ||
| 416 | |||
| 417 | pc = sym->n_value + func_addr; | ||
| 418 | func_name[0] = '\0'; | ||
| 419 | func_addr = 0; | ||
| 420 | } else { | ||
| 421 | // beginning of function | ||
| 422 | |||
| 423 | str = | ||
| 424 | (const char *) stabstr_section->data + | ||
| 425 | sym->n_strx; | ||
| 426 | |||
| 427 | |||
| 428 | p = strchr(str, ':'); | ||
| 429 | if (!p) { | ||
| 430 | pstrcpy(func_name, sizeof(func_name), str); | ||
| 431 | } else { | ||
| 432 | len = p - str; | ||
| 433 | if (len > sizeof(func_name) - 1) | ||
| 434 | len = sizeof(func_name) - 1; | ||
| 435 | memcpy(func_name, str, len); | ||
| 436 | func_name[len] = '\0'; | ||
| 437 | } | ||
| 438 | func_addr = sym->n_value; | ||
| 439 | last_pc = func_addr; | ||
| 440 | last_line_num = -1; | ||
| 441 | |||
| 442 | // output a function begin | ||
| 443 | |||
| 444 | CoffLineNo.l_addr.l_symndx = | ||
| 445 | FindCoffSymbolIndex(func_name); | ||
| 446 | CoffLineNo.l_lnno = 0; | ||
| 447 | |||
| 448 | fwrite(&CoffLineNo, 6, 1, f); | ||
| 449 | } | ||
| 450 | break; | ||
| 451 | |||
| 452 | /* line number info */ | ||
| 453 | case N_SLINE: | ||
| 454 | pc = sym->n_value + func_addr; | ||
| 455 | |||
| 456 | |||
| 457 | /* XXX: slow! */ | ||
| 458 | strcpy(last_func_name, func_name); | ||
| 459 | |||
| 460 | // output a line reference | ||
| 461 | |||
| 462 | CoffLineNo.l_addr.l_paddr = last_pc; | ||
| 463 | |||
| 464 | if (last_line_num == -1) { | ||
| 465 | CoffLineNo.l_lnno = sym->n_desc; | ||
| 466 | } else { | ||
| 467 | CoffLineNo.l_lnno = last_line_num + 1; | ||
| 468 | } | ||
| 469 | |||
| 470 | fwrite(&CoffLineNo, 6, 1, f); | ||
| 471 | |||
| 472 | last_pc = pc; | ||
| 473 | last_line_num = sym->n_desc; | ||
| 474 | |||
| 475 | break; | ||
| 476 | |||
| 477 | /* include files */ | ||
| 478 | case N_BINCL: | ||
| 479 | str = | ||
| 480 | (const char *) stabstr_section->data + sym->n_strx; | ||
| 481 | add_incl2: | ||
| 482 | if (incl_index < INCLUDE_STACK_SIZE) { | ||
| 483 | incl_files[incl_index++] = str; | ||
| 484 | } | ||
| 485 | break; | ||
| 486 | case N_EINCL: | ||
| 487 | if (incl_index > 1) | ||
| 488 | incl_index--; | ||
| 489 | break; | ||
| 490 | case N_SO: | ||
| 491 | if (sym->n_strx == 0) { | ||
| 492 | incl_index = 0; /* end of translation unit */ | ||
| 493 | } else { | ||
| 494 | str = | ||
| 495 | (const char *) stabstr_section->data + | ||
| 496 | sym->n_strx; | ||
| 497 | /* do not add path */ | ||
| 498 | len = strlen(str); | ||
| 499 | if (len > 0 && str[len - 1] != '/') | ||
| 500 | goto add_incl2; | ||
| 501 | } | ||
| 502 | break; | ||
| 503 | } | ||
| 504 | sym++; | ||
| 505 | } | ||
| 506 | } | ||
| 507 | } | ||
| 508 | |||
| 509 | // write symbol table | ||
| 510 | if (do_debug) { | ||
| 511 | int k; | ||
| 512 | struct syment csym; | ||
| 513 | AUXFUNC auxfunc; | ||
| 514 | AUXBF auxbf; | ||
| 515 | AUXEF auxef; | ||
| 516 | int i; | ||
| 517 | Elf32_Sym *p; | ||
| 518 | char *name; | ||
| 519 | char _name[MAX_FUNCS]; | ||
| 520 | int nstr; | ||
| 521 | int n = 0; | ||
| 522 | |||
| 523 | Coff_str_table = (char *) tcc_malloc(MAX_STR_TABLE); | ||
| 524 | pCoff_str_table = Coff_str_table; | ||
| 525 | nstr = 0; | ||
| 526 | |||
| 527 | p = (Elf32_Sym *) symtab_section->data; | ||
| 528 | |||
| 529 | |||
| 530 | for (i = 0; i < nb_syms; i++) { | ||
| 531 | |||
| 532 | /* don't add underscores for Code Composer Version 2.xx */ | ||
| 533 | |||
| 534 | #define ADD_UNDERSCORE 0 | ||
| 535 | |||
| 536 | name = (char *) symtab_section->link->data + p->st_name; | ||
| 537 | |||
| 538 | #if ADD_UNDERSCORE | ||
| 539 | _name[0] = '_'; | ||
| 540 | strcpy(_name + 1, name); | ||
| 541 | #else | ||
| 542 | strcpy(_name, name); | ||
| 543 | #endif | ||
| 544 | |||
| 545 | for (k = 0; k < 8; k++) | ||
| 546 | csym._n._n_name[k] = 0; | ||
| 547 | |||
| 548 | if (strlen(_name) <= 8) { | ||
| 549 | strcpy(csym._n._n_name, _name); | ||
| 550 | } else { | ||
| 551 | if (pCoff_str_table - Coff_str_table + strlen(_name) > | ||
| 552 | MAX_STR_TABLE - 1) | ||
| 553 | error("String table too large"); | ||
| 554 | |||
| 555 | csym._n._n_n._n_zeroes = 0; | ||
| 556 | csym._n._n_n._n_offset = | ||
| 557 | pCoff_str_table - Coff_str_table + 4; | ||
| 558 | |||
| 559 | strcpy(pCoff_str_table, _name); | ||
| 560 | pCoff_str_table += strlen(_name) + 1; // skip over null | ||
| 561 | nstr++; | ||
| 562 | } | ||
| 563 | |||
| 564 | if (p->st_info == 4) { | ||
| 565 | // put a filename symbol | ||
| 566 | csym.n_value = 33; // ????? | ||
| 567 | csym.n_scnum = N_DEBUG; | ||
| 568 | csym.n_type = 0; | ||
| 569 | csym.n_sclass = C_FILE; | ||
| 570 | csym.n_numaux = 0; | ||
| 571 | fwrite(&csym, 18, 1, f); | ||
| 572 | n++; | ||
| 573 | |||
| 574 | } else if (p->st_info == 0x12) { | ||
| 575 | // find the function data | ||
| 576 | |||
| 577 | for (k = 0; k < nFuncs; k++) { | ||
| 578 | if (strcmp(name, Func[k]) == 0) | ||
| 579 | break; | ||
| 580 | } | ||
| 581 | |||
| 582 | if (k >= nFuncs) { | ||
| 583 | char s[256]; | ||
| 584 | |||
| 585 | sprintf(s, "debug info can't find function: %s", name); | ||
| 586 | |||
| 587 | error(s); | ||
| 588 | } | ||
| 589 | // put a Function Name | ||
| 590 | |||
| 591 | csym.n_value = p->st_value; // physical address | ||
| 592 | csym.n_scnum = CoffTextSectionNo; | ||
| 593 | csym.n_type = MKTYPE(T_INT, DT_FCN, 0, 0, 0, 0, 0); | ||
| 594 | csym.n_sclass = C_EXT; | ||
| 595 | csym.n_numaux = 1; | ||
| 596 | fwrite(&csym, 18, 1, f); | ||
| 597 | |||
| 598 | // now put aux info | ||
| 599 | |||
| 600 | auxfunc.tag = 0; | ||
| 601 | auxfunc.size = EndAddress[k] - p->st_value; | ||
| 602 | auxfunc.fileptr = LineNoFilePtr[k]; | ||
| 603 | auxfunc.nextsym = n + 6; // tktk | ||
| 604 | auxfunc.dummy = 0; | ||
| 605 | fwrite(&auxfunc, 18, 1, f); | ||
| 606 | |||
| 607 | // put a .bf | ||
| 608 | |||
| 609 | strcpy(csym._n._n_name, ".bf"); | ||
| 610 | csym.n_value = p->st_value; // physical address | ||
| 611 | csym.n_scnum = CoffTextSectionNo; | ||
| 612 | csym.n_type = 0; | ||
| 613 | csym.n_sclass = C_FCN; | ||
| 614 | csym.n_numaux = 1; | ||
| 615 | fwrite(&csym, 18, 1, f); | ||
| 616 | |||
| 617 | // now put aux info | ||
| 618 | |||
| 619 | auxbf.regmask = 0; | ||
| 620 | auxbf.lineno = 0; | ||
| 621 | auxbf.nentries = FuncEntries[k]; | ||
| 622 | auxbf.localframe = 0; | ||
| 623 | auxbf.nextentry = n + 6; | ||
| 624 | auxbf.dummy = 0; | ||
| 625 | fwrite(&auxbf, 18, 1, f); | ||
| 626 | |||
| 627 | // put a .ef | ||
| 628 | |||
| 629 | strcpy(csym._n._n_name, ".ef"); | ||
| 630 | csym.n_value = EndAddress[k]; // physical address | ||
| 631 | csym.n_scnum = CoffTextSectionNo; | ||
| 632 | csym.n_type = 0; | ||
| 633 | csym.n_sclass = C_FCN; | ||
| 634 | csym.n_numaux = 1; | ||
| 635 | fwrite(&csym, 18, 1, f); | ||
| 636 | |||
| 637 | // now put aux info | ||
| 638 | |||
| 639 | auxef.dummy = 0; | ||
| 640 | auxef.lineno = LastLineNo[k]; | ||
| 641 | auxef.dummy1 = 0; | ||
| 642 | auxef.dummy2 = 0; | ||
| 643 | auxef.dummy3 = 0; | ||
| 644 | auxef.dummy4 = 0; | ||
| 645 | fwrite(&auxef, 18, 1, f); | ||
| 646 | |||
| 647 | n += 6; | ||
| 648 | |||
| 649 | } else { | ||
| 650 | // try an put some type info | ||
| 651 | |||
| 652 | if ((p->st_other & VT_BTYPE) == VT_DOUBLE) { | ||
| 653 | csym.n_type = T_DOUBLE; // int | ||
| 654 | csym.n_sclass = C_EXT; | ||
| 655 | } else if ((p->st_other & VT_BTYPE) == VT_FLOAT) { | ||
| 656 | csym.n_type = T_FLOAT; | ||
| 657 | csym.n_sclass = C_EXT; | ||
| 658 | } else if ((p->st_other & VT_BTYPE) == VT_INT) { | ||
| 659 | csym.n_type = T_INT; // int | ||
| 660 | csym.n_sclass = C_EXT; | ||
| 661 | } else if ((p->st_other & VT_BTYPE) == VT_SHORT) { | ||
| 662 | csym.n_type = T_SHORT; | ||
| 663 | csym.n_sclass = C_EXT; | ||
| 664 | } else if ((p->st_other & VT_BTYPE) == VT_BYTE) { | ||
| 665 | csym.n_type = T_CHAR; | ||
| 666 | csym.n_sclass = C_EXT; | ||
| 667 | } else { | ||
| 668 | csym.n_type = T_INT; // just mark as a label | ||
| 669 | csym.n_sclass = C_LABEL; | ||
| 670 | } | ||
| 671 | |||
| 672 | |||
| 673 | csym.n_value = p->st_value; | ||
| 674 | csym.n_scnum = 2; | ||
| 675 | csym.n_numaux = 1; | ||
| 676 | fwrite(&csym, 18, 1, f); | ||
| 677 | |||
| 678 | auxfunc.tag = 0; | ||
| 679 | auxfunc.size = 0x20; | ||
| 680 | auxfunc.fileptr = 0; | ||
| 681 | auxfunc.nextsym = 0; | ||
| 682 | auxfunc.dummy = 0; | ||
| 683 | fwrite(&auxfunc, 18, 1, f); | ||
| 684 | n++; | ||
| 685 | n++; | ||
| 686 | |||
| 687 | } | ||
| 688 | |||
| 689 | p++; | ||
| 690 | } | ||
| 691 | } | ||
| 692 | |||
| 693 | if (do_debug) { | ||
| 694 | // write string table | ||
| 695 | |||
| 696 | // first write the size | ||
| 697 | i = pCoff_str_table - Coff_str_table; | ||
| 698 | fwrite(&i, 4, 1, f); | ||
| 699 | |||
| 700 | // then write the strings | ||
| 701 | fwrite(Coff_str_table, i, 1, f); | ||
| 702 | |||
| 703 | tcc_free(Coff_str_table); | ||
| 704 | } | ||
| 705 | |||
| 706 | fclose(f); | ||
| 707 | |||
| 708 | return 0; | ||
| 709 | } | ||
| 710 | |||
| 711 | |||
| 712 | |||
| 713 | // group the symbols in order of filename, func1, func2, etc | ||
| 714 | // finally global symbols | ||
| 715 | |||
| 716 | void SortSymbolTable(void) | ||
| 717 | { | ||
| 718 | int i, j, k, n = 0; | ||
| 719 | Elf32_Sym *p, *p2, *NewTable; | ||
| 720 | char *name, *name2; | ||
| 721 | |||
| 722 | NewTable = (Elf32_Sym *) tcc_malloc(nb_syms * sizeof(Elf32_Sym)); | ||
| 723 | |||
| 724 | p = (Elf32_Sym *) symtab_section->data; | ||
| 725 | |||
| 726 | |||
| 727 | // find a file symbol, copy it over | ||
| 728 | // then scan the whole symbol list and copy any function | ||
| 729 | // symbols that match the file association | ||
| 730 | |||
| 731 | for (i = 0; i < nb_syms; i++) { | ||
| 732 | if (p->st_info == 4) { | ||
| 733 | name = (char *) symtab_section->link->data + p->st_name; | ||
| 734 | |||
| 735 | // this is a file symbol, copy it over | ||
| 736 | |||
| 737 | NewTable[n++] = *p; | ||
| 738 | |||
| 739 | p2 = (Elf32_Sym *) symtab_section->data; | ||
| 740 | |||
| 741 | for (j = 0; j < nb_syms; j++) { | ||
| 742 | if (p2->st_info == 0x12) { | ||
| 743 | // this is a func symbol | ||
| 744 | |||
| 745 | name2 = | ||
| 746 | (char *) symtab_section->link->data + p2->st_name; | ||
| 747 | |||
| 748 | // find the function data index | ||
| 749 | |||
| 750 | for (k = 0; k < nFuncs; k++) { | ||
| 751 | if (strcmp(name2, Func[k]) == 0) | ||
| 752 | break; | ||
| 753 | } | ||
| 754 | |||
| 755 | if (k >= nFuncs) { | ||
| 756 | char s[256]; | ||
| 757 | |||
| 758 | sprintf(s, | ||
| 759 | "debug (sort) info can't find function: %s", | ||
| 760 | name2); | ||
| 761 | |||
| 762 | error(s); | ||
| 763 | } | ||
| 764 | |||
| 765 | if (strcmp(AssociatedFile[k], name) == 0) { | ||
| 766 | // yes they match copy it over | ||
| 767 | |||
| 768 | NewTable[n++] = *p2; | ||
| 769 | } | ||
| 770 | } | ||
| 771 | p2++; | ||
| 772 | } | ||
| 773 | } | ||
| 774 | p++; | ||
| 775 | } | ||
| 776 | |||
| 777 | // now all the filename and func symbols should have been copied over | ||
| 778 | // copy all the rest over (all except file and funcs) | ||
| 779 | |||
| 780 | p = (Elf32_Sym *) symtab_section->data; | ||
| 781 | for (i = 0; i < nb_syms; i++) { | ||
| 782 | if (p->st_info != 4 && p->st_info != 0x12) { | ||
| 783 | NewTable[n++] = *p; | ||
| 784 | } | ||
| 785 | p++; | ||
| 786 | } | ||
| 787 | |||
| 788 | if (n != nb_syms) | ||
| 789 | error("Internal Compiler error, debug info"); | ||
| 790 | |||
| 791 | // copy it all back | ||
| 792 | |||
| 793 | p = (Elf32_Sym *) symtab_section->data; | ||
| 794 | for (i = 0; i < nb_syms; i++) { | ||
| 795 | *p++ = NewTable[i]; | ||
| 796 | } | ||
| 797 | |||
| 798 | tcc_free(NewTable); | ||
| 799 | } | ||
| 800 | |||
| 801 | |||
| 802 | int FindCoffSymbolIndex(const char *func_name) | ||
| 803 | { | ||
| 804 | int i, n = 0; | ||
| 805 | Elf32_Sym *p; | ||
| 806 | char *name; | ||
| 807 | |||
| 808 | p = (Elf32_Sym *) symtab_section->data; | ||
| 809 | |||
| 810 | for (i = 0; i < nb_syms; i++) { | ||
| 811 | |||
| 812 | name = (char *) symtab_section->link->data + p->st_name; | ||
| 813 | |||
| 814 | if (p->st_info == 4) { | ||
| 815 | // put a filename symbol | ||
| 816 | n++; | ||
| 817 | } else if (p->st_info == 0x12) { | ||
| 818 | |||
| 819 | if (strcmp(func_name, name) == 0) | ||
| 820 | return n; | ||
| 821 | |||
| 822 | n += 6; | ||
| 823 | |||
| 824 | // put a Function Name | ||
| 825 | |||
| 826 | // now put aux info | ||
| 827 | |||
| 828 | // put a .bf | ||
| 829 | |||
| 830 | // now put aux info | ||
| 831 | |||
| 832 | // put a .ef | ||
| 833 | |||
| 834 | // now put aux info | ||
| 835 | |||
| 836 | } else { | ||
| 837 | n += 2; | ||
| 838 | } | ||
| 839 | |||
| 840 | p++; | ||
| 841 | } | ||
| 842 | |||
| 843 | return n; // total number of symbols | ||
| 844 | } | ||
| 845 | |||
| 846 | |||
| 847 | |||
| 848 | |||
| 849 | |||
| 850 | |||
| 851 | BOOL OutputTheSection(Section * sect) | ||
| 852 | { | ||
| 853 | const char *s = sect->name; | ||
| 854 | |||
| 855 | if (s == ".text") | ||
| 856 | return true; | ||
| 857 | else if (s == ".data") | ||
| 858 | return true; | ||
| 859 | else | ||
| 860 | return 0; | ||
| 861 | } | ||
| 862 | |||
| 863 | short int GetCoffFlags(const char *s) | ||
| 864 | { | ||
| 865 | if (s == ".text") | ||
| 866 | return STYP_TEXT | STYP_DATA | STYP_ALIGN | 0x400; | ||
| 867 | else if (s == ".data") | ||
| 868 | return STYP_DATA; | ||
| 869 | else if (s == ".bss") | ||
| 870 | return STYP_BSS; | ||
| 871 | else if (s == ".stack") | ||
| 872 | return STYP_BSS | STYP_ALIGN | 0x200; | ||
| 873 | else if (s == ".cinit") | ||
| 874 | return STYP_COPY | STYP_DATA | STYP_ALIGN | 0x200; | ||
| 875 | else | ||
| 876 | return 0; | ||
| 877 | } | ||
| 878 | |||
| 879 | Section *FindSection(TCCState * s1, const char *sname) | ||
| 880 | { | ||
| 881 | Section *s; | ||
| 882 | int i; | ||
| 883 | |||
| 884 | for (i = 1; i < s1->nb_sections; i++) { | ||
| 885 | s = s1->sections[i]; | ||
| 886 | |||
| 887 | if (!strcmp(sname, s->name)) | ||
| 888 | return s; | ||
| 889 | } | ||
| 890 | |||
| 891 | error("could not find section %s", sname); | ||
| 892 | return 0; | ||
| 893 | } | ||
| 894 | |||
| 895 | int tcc_load_coff(TCCState * s1, int fd) | ||
| 896 | { | ||
| 897 | // tktk TokenSym *ts; | ||
| 898 | |||
| 899 | FILE *f; | ||
| 900 | unsigned int str_size; | ||
| 901 | char *Coff_str_table, *name; | ||
| 902 | int i, k; | ||
| 903 | struct syment csym; | ||
| 904 | char name2[9]; | ||
| 905 | FILHDR file_hdr; /* FILE HEADER STRUCTURE */ | ||
| 906 | |||
| 907 | f = fdopen(fd, "rb"); | ||
| 908 | if (!f) { | ||
| 909 | error("Unable to open .out file for input"); | ||
| 910 | } | ||
| 911 | |||
| 912 | if (fread(&file_hdr, FILHSZ, 1, f) != 1) | ||
| 913 | error("error reading .out file for input"); | ||
| 914 | |||
| 915 | if (fread(&o_filehdr, sizeof(o_filehdr), 1, f) != 1) | ||
| 916 | error("error reading .out file for input"); | ||
| 917 | |||
| 918 | // first read the string table | ||
| 919 | |||
| 920 | if (fseek(f, file_hdr.f_symptr + file_hdr.f_nsyms * SYMESZ, SEEK_SET)) | ||
| 921 | error("error reading .out file for input"); | ||
| 922 | |||
| 923 | if (fread(&str_size, sizeof(int), 1, f) != 1) | ||
| 924 | error("error reading .out file for input"); | ||
| 925 | |||
| 926 | |||
| 927 | Coff_str_table = (char *) tcc_malloc(str_size); | ||
| 928 | |||
| 929 | if (fread(Coff_str_table, str_size - 4, 1, f) != 1) | ||
| 930 | error("error reading .out file for input"); | ||
| 931 | |||
| 932 | // read/process all the symbols | ||
| 933 | |||
| 934 | // seek back to symbols | ||
| 935 | |||
| 936 | if (fseek(f, file_hdr.f_symptr, SEEK_SET)) | ||
| 937 | error("error reading .out file for input"); | ||
| 938 | |||
| 939 | for (i = 0; i < file_hdr.f_nsyms; i++) { | ||
| 940 | if (fread(&csym, SYMESZ, 1, f) != 1) | ||
| 941 | error("error reading .out file for input"); | ||
| 942 | |||
| 943 | if (csym._n._n_n._n_zeroes == 0) { | ||
| 944 | name = Coff_str_table + csym._n._n_n._n_offset - 4; | ||
| 945 | } else { | ||
| 946 | name = csym._n._n_name; | ||
| 947 | |||
| 948 | if (name[7] != 0) { | ||
| 949 | for (k = 0; k < 8; k++) | ||
| 950 | name2[k] = name[k]; | ||
| 951 | |||
| 952 | name2[8] = 0; | ||
| 953 | |||
| 954 | name = name2; | ||
| 955 | } | ||
| 956 | } | ||
| 957 | // if (strcmp("_DAC_Buffer",name)==0) // tktk | ||
| 958 | // name[0]=0; | ||
| 959 | |||
| 960 | if (((csym.n_type & 0x30) == 0x20 && csym.n_sclass == 0x2) || ((csym.n_type & 0x30) == 0x30 && csym.n_sclass == 0x2) || (csym.n_type == 0x4 && csym.n_sclass == 0x2) || (csym.n_type == 0x8 && csym.n_sclass == 0x2) || // structures | ||
| 961 | (csym.n_type == 0x18 && csym.n_sclass == 0x2) || // pointer to structure | ||
| 962 | (csym.n_type == 0x7 && csym.n_sclass == 0x2) || // doubles | ||
| 963 | (csym.n_type == 0x6 && csym.n_sclass == 0x2)) // floats | ||
| 964 | { | ||
| 965 | // strip off any leading underscore (except for other main routine) | ||
| 966 | |||
| 967 | if (name[0] == '_' && strcmp(name, "_main") != 0) | ||
| 968 | name++; | ||
| 969 | |||
| 970 | tcc_add_symbol(s1, name, csym.n_value); | ||
| 971 | } | ||
| 972 | // skip any aux records | ||
| 973 | |||
| 974 | if (csym.n_numaux == 1) { | ||
| 975 | if (fread(&csym, SYMESZ, 1, f) != 1) | ||
| 976 | error("error reading .out file for input"); | ||
| 977 | i++; | ||
| 978 | } | ||
| 979 | } | ||
| 980 | |||
| 981 | return 0; | ||
| 982 | } | ||
| @@ -552,6 +552,24 @@ static void relocate_section(TCCState *s1, Section *s) · 551 unmodified lines | |||
| 552 | case R_C60_32: | 552 | case R_C60_32: |
| 553 | *(int *)ptr += val; | 553 | *(int *)ptr += val; |
| 554 | break; | 554 | break; |
| 555 | case R_C60LO16: | ||
| 556 | { | ||
| 557 | uint32_t orig; | ||
| 558 | |||
| 559 | /* put the low 16 bits of the absolute address */ | ||
| 560 | // add to what is already there | ||
| 561 | |||
| 562 | orig = ((*(int *)(ptr )) >> 7) & 0xffff; | ||
| 563 | orig |= (((*(int *)(ptr+4)) >> 7) & 0xffff) << 16; | ||
| 564 | |||
| 565 | //patch both at once - assumes always in pairs Low - High | ||
| 566 | |||
| 567 | *(int *) ptr = (*(int *) ptr & (~(0xffff << 7)) ) | (((val+orig) & 0xffff) << 7); | ||
| 568 | *(int *)(ptr+4) = (*(int *)(ptr+4) & (~(0xffff << 7)) ) | ((((val+orig)>>16) & 0xffff) << 7); | ||
| 569 | } | ||
| 570 | break; | ||
| 571 | case R_C60HI16: | ||
| 572 | break; | ||
| 555 | default: | 573 | default: |
| 556 | fprintf(stderr,"FIXME: handle reloc type %x at %lx [%.8x] to %lx\n", | 574 | fprintf(stderr,"FIXME: handle reloc type %x at %lx [%.8x] to %lx\n", |
| 557 | type,addr,(unsigned int )ptr,val); | 575 | type,addr,(unsigned int )ptr,val); |
| @@ -1536,6 +1554,9 @@ int tcc_output_file(TCCState *s1, const char *filename) · 978 unmodified lines | |||
| 1536 | ehdr.e_entry = text_section->sh_addr; /* XXX: is it correct ? */ | 1554 | ehdr.e_entry = text_section->sh_addr; /* XXX: is it correct ? */ |
| 1537 | } | 1555 | } |
| 1538 | 1556 | ||
| 1557 | #ifdef TCC_TARGET_COFF | ||
| 1558 | ret = tcc_output_coff(s1, filename); | ||
| 1559 | #else | ||
| 1539 | sort_syms(s1, symtab_section); | 1560 | sort_syms(s1, symtab_section); |
| 1540 | 1561 | ||
| 1541 | /* align to 4 */ | 1562 | /* align to 4 */ |
| @@ -1629,6 +1650,7 @@ int tcc_output_file(TCCState *s1, const char *filename) · 87 unmodified lines | |||
| 1629 | fclose(f); | 1650 | fclose(f); |
| 1630 | 1651 | ||
| 1631 | ret = 0; | 1652 | ret = 0; |
| 1653 | #endif | ||
| 1632 | the_end: | 1654 | the_end: |
| 1633 | tcc_free(s1->symtab_to_dynsym); | 1655 | tcc_free(s1->symtab_to_dynsym); |
| 1634 | tcc_free(section_order); | 1656 | tcc_free(section_order); |
| @@ -111,7 +111,7 @@ · 110 unmodified lines | |||
| 111 | DEF(TOK___moddi3, "__moddi3") | 111 | DEF(TOK___moddi3, "__moddi3") |
| 112 | DEF(TOK___udivdi3, "__udivdi3") | 112 | DEF(TOK___udivdi3, "__udivdi3") |
| 113 | DEF(TOK___umoddi3, "__umoddi3") | 113 | DEF(TOK___umoddi3, "__umoddi3") |
| 114 | #ifdef TCC_TARGET_ARM | 114 | #if defined(TCC_TARGET_ARM) |
| 115 | DEF(TOK___divsi3, "__divsi3") | 115 | DEF(TOK___divsi3, "__divsi3") |
| 116 | DEF(TOK___modsi3, "__modsi3") | 116 | DEF(TOK___modsi3, "__modsi3") |
| 117 | DEF(TOK___udivsi3, "__udivsi3") | 117 | DEF(TOK___udivsi3, "__udivsi3") |
| @@ -126,6 +126,16 @@ · 8 unmodified lines | |||
| 126 | DEF(TOK___fixsfdi, "__fixsfdi") | 126 | DEF(TOK___fixsfdi, "__fixsfdi") |
| 127 | DEF(TOK___fixdfdi, "__fixdfdi") | 127 | DEF(TOK___fixdfdi, "__fixdfdi") |
| 128 | DEF(TOK___fixxfdi, "__fixxfdi") | 128 | DEF(TOK___fixxfdi, "__fixxfdi") |
| 129 | #elif defined(TCC_TARGET_C67) | ||
| 130 | DEF(TOK__divi, "_divi") | ||
| 131 | DEF(TOK__divu, "_divu") | ||
| 132 | DEF(TOK__divf, "_divf") | ||
| 133 | DEF(TOK__divd, "_divd") | ||
| 134 | DEF(TOK__remi, "_remi") | ||
| 135 | DEF(TOK__remu, "_remu") | ||
| 136 | DEF(TOK___sardi3, "__sardi3") | ||
| 137 | DEF(TOK___shrdi3, "__shrdi3") | ||
| 138 | DEF(TOK___shldi3, "__shldi3") | ||
| 129 | #else | 139 | #else |
| 130 | /* XXX: same names on i386 ? */ | 140 | /* XXX: same names on i386 ? */ |
| 131 | DEF(TOK___sardi3, "__sardi3") | 141 | DEF(TOK___sardi3, "__sardi3") |