1 /* gpcoff.h - header file for pic object files 2 Copyright (C) 2001, 2002, 2003, 2004, 2005 3 Craig Franklin 4 5 Copyright (C) 2015-2016 Molnar Karoly 6 7 This file is part of gputils. 8 9 gputils is free software; you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation; either version 2, or (at your option) 12 any later version. 13 14 gputils is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with gputils; see the file COPYING. If not, write to 21 the Free Software Foundation, 59 Temple Place - Suite 330, 22 Boston, MA 02111-1307, USA. */ 23 24 #ifndef __GPCOFF_H__ 25 #define __GPCOFF_H__ 26 27 /* These definitions are for the COFF as stored in a file. */ 28 29 /* define the typical values, if they aren't found warn the user */ 30 #define MICROCHIP_MAGIC_v1 0x1234 31 #define MICROCHIP_MAGIC_v2 0x1240 32 33 #define OPTMAGIC_v1 0x5678 34 #define OPTMAGIC_v2 0x5678 35 36 /* coff file header format */ 37 struct __attribute__ ((packed)) filehdr 38 { 39 uint16_t f_magic; /* magic number */ 40 uint16_t f_nscns; /* number of sections */ 41 uint32_t f_timdat; /* time and date stamp */ 42 uint32_t f_symptr; /* file ptr to symtab */ 43 uint32_t f_nsyms; /* # symtab entries */ 44 uint16_t f_opthdr; /* sizeof(opt hdr) */ 45 uint16_t f_flags; /* flags */ 46 }; 47 48 /* define the size in the file, don't use sizeof() !! */ 49 #define FILE_HDR_SIZ_v1 20 50 #define FILE_HDR_SIZ_v2 20 51 52 /* relocation info has been stripped */ 53 #define F_RELFLG 0x0001 54 /* file is executable - has no unresolved external symbols */ 55 #define F_EXEC 0x0002 56 /* line numbers have been stripped */ 57 #define F_LINENO 0x0004 58 /* the MPASM assembler object file is from absolute (as opposed to relocatable) assembly code */ 59 #define F_ABSOLUTE 0x0010 60 /* local symbols have been stripped */ 61 #define L_SYMS 0x0080 62 /* the COFF file produced utilizing the Extended mode */ 63 #define F_EXTENDED18 0x4000 64 /* processor independent file for a core */ 65 #define F_GENERIC 0x8000 66 67 /* optional header format */ 68 struct __attribute__ ((packed)) opthdr 69 { 70 uint16_t opt_magic; 71 uint32_t vstamp; /* version of the compiler assembler */ 72 uint32_t proc_type; 73 uint32_t rom_width_bits; 74 uint32_t ram_width_bits; 75 }; 76 77 #define OPT_HDR_SIZ_v1 16 78 #define OPT_HDR_SIZ_v2 18 79 80 /* section header format */ 81 struct __attribute__ ((packed)) scnhdr 82 { 83 union __attribute__ ((packed)) { 84 char name[8]; /* section name if less then 8 characters */ 85 struct __attribute__ ((packed)) { 86 uint32_t s_zeros; /* first four characters are 0 */ 87 uint32_t s_offset; /* pointer to the string table */ 88 } ptr; 89 } s_name; 90 91 uint32_t s_paddr; /* physical address */ 92 uint32_t s_vaddr; /* virtual address */ 93 uint32_t s_size; /* section size */ 94 uint32_t s_scnptr; /* file ptr to raw data */ 95 uint32_t s_relptr; /* file ptr to relocation */ 96 uint32_t s_lnnoptr; /* file ptr to line numbers */ 97 uint16_t s_nreloc; /* # reloc entries */ 98 uint16_t s_nlnno; /* # line number entries */ 99 uint32_t s_flags; /* flags */ 100 }; 101 102 #define SEC_HDR_SIZ_v1 40 103 #define SEC_HDR_SIZ_v2 40 104 105 /* Section contains executable code. (.text) */ 106 #define STYP_TEXT 0x00000020 107 /* Section contains initialized data. (.data) */ 108 #define STYP_DATA 0x00000040 109 /* Section contains uninitialized data. (.bss) */ 110 #define STYP_BSS 0x00000080 111 /* Section contains initialized data for ROM. */ 112 #define STYP_DATA_ROM 0x00000100 113 /* Section is absolute. */ 114 #define STYP_ABS 0x00001000 115 /* Section is shared across banks. */ 116 #define STYP_SHARED 0x00002000 117 /* Section is overlaid with other sections of the same name from different objects modules. */ 118 #define STYP_OVERLAY 0x00004000 119 /* Section is available using access bit. */ 120 #define STYP_ACCESS 0x00008000 121 /* Section contains the activation record for a function. */ 122 #define STYP_ACTREC 0x00010000 123 /* Section has been relocated. This is a temporary flag used by the linker. */ 124 #define STYP_RELOC 0x00020000 125 /* Section is byte packed on 16bit devices. */ 126 #define STYP_BPACK 0x00040000 127 128 #define STYP_RAM_AREA (STYP_DATA | STYP_BSS) 129 #define STYP_ROM_AREA (STYP_TEXT | STYP_DATA_ROM) 130 131 /* relocation entry */ 132 struct __attribute__ ((packed)) reloc 133 { 134 uint32_t r_vaddr; /* entry relative virtual address */ 135 uint32_t r_symndx; /* index into symbol table */ 136 int16_t r_offset; /* offset to be added to address of symbol 'r_symndx' */ 137 uint16_t r_type; /* relocation type */ 138 }; 139 140 #define RELOC_SIZ 12 141 142 #define RELOC_NONE 0 143 /* relocation for the CALL instruction (first word only on 18cxx) */ 144 #define RELOC_CALL 1 145 /* relocation for the GOTO instruction (first word only on 18cxx) */ 146 #define RELOC_GOTO 2 147 /* relocation for the second 8 bits of an address */ 148 #define RELOC_HIGH 3 149 /* relocation for the low order 8 bits of an address */ 150 #define RELOC_LOW 4 151 /* relocation for the 5 bits of address for the P operand of a 17cxx MOVFP 152 or MOVPF instruction */ 153 #define RELOC_P 5 154 /* relocation to generate the appropriate instruction to bank switch for a symbol */ 155 #define RELOC_BANKSEL 6 156 /* relocation to generate the appropriate instruction to page switch for a symbol */ 157 #define RELOC_PAGESEL 7 158 /* FIXME */ 159 #define RELOC_ALL 8 160 /* FIXME */ 161 #define RELOC_IBANKSEL 9 162 /* relocation for the 8 bits of address for the F operand of a 17cxx MOVFP or 163 MOVPF instruction */ 164 #define RELOC_F 10 165 /* FIXME */ 166 #define RELOC_TRIS 11 167 /* relocation for the MOVLR bank 17cxx banking instruction */ 168 #define RELOC_MOVLR 12 169 /* relocation for the MOVLB 17cxx and 18cxx banking instruction */ 170 #define RELOC_MOVLB 13 171 /* relocation for the second word of an 18cxx goto instruction */ 172 #define RELOC_GOTO2 14 173 /* relocation for the second word of an 18cxx call instruction */ 174 #define RELOC_CALL2 RELOC_GOTO2 175 /* relocation for the source register of the 18cxx MOVFF instruction */ 176 #define RELOC_FF1 15 177 /* relocation for the destination register of the 18cxx MOVFF instruction */ 178 #define RELOC_FF2 16 179 /* relocation for the first word of the 18cxx LFSR instruction */ 180 #define RELOC_LFSR1 17 181 /* relocation for the second word of the 18cxx LFSR instruction */ 182 #define RELOC_LFSR2 18 183 /* relocation for the 18cxx BRA instruction */ 184 #define RELOC_BRA 19 185 /* relocation for the 18cxx RCALL instruction */ 186 #define RELOC_RCALL RELOC_BRA 187 /* relocation for the 18cxx relative conditional branch instructions */ 188 #define RELOC_CONDBRA 20 189 /* relocation for the highest order 8 bits of a 24-bit address */ 190 #define RELOC_UPPER 21 191 /* relocation for the 18cxx access bit */ 192 #define RELOC_ACCESS 22 193 /* relocation for selecting the correct page using WREG as scratch */ 194 #define RELOC_PAGESEL_WREG 23 195 /* relocation for selecting the correct page using bit set/clear instructions */ 196 #define RELOC_PAGESEL_BITS 24 197 /* relocation for the size of a section */ 198 #define RELOC_SCNSZ_LOW 25 199 #define RELOC_SCNSZ_HIGH 26 200 #define RELOC_SCNSZ_UPPER 27 201 /* relocation for the address of the end of a section */ 202 #define RELOC_SCNEND_LOW 28 203 #define RELOC_SCNEND_HIGH 29 204 #define RELOC_SCNEND_UPPER 30 205 /* relocation for the address of the end of a section on LFSR */ 206 #define RELOC_SCNEND_LFSR1 31 207 #define RELOC_SCNEND_LFSR2 32 208 #define RELOC_TRIS_3BIT 33 209 /* relocation for selecting the correct page using pic14 enhanced MOVLP instruction */ 210 #define RELOC_PAGESEL_MOVLP 34 211 212 /* linenumber entry */ 213 struct __attribute__ ((packed)) lineno { 214 uint32_t l_srcndx; /* symbol table index of associated source file */ 215 uint16_t l_lnno; /* line number */ 216 uint32_t l_paddr; /* address of code for this lineno */ 217 uint16_t l_flags; /* bit flags for the line number */ 218 uint32_t l_fcnndx; /* symbol table index of associated function, if there is one */ 219 }; 220 221 #define LINENO_SIZ 16 222 223 /* Set if l_fcnndx is valid. */ 224 #define LINENO_HASFCN 1 225 226 #define COFF_SSYMBOL_NAME_MAX 8 227 228 /* symbol table entry */ 229 struct __attribute__ ((packed)) syment { 230 union __attribute__ ((packed)) { 231 char name[COFF_SSYMBOL_NAME_MAX]; /* symbol name if less than 8 characters */ 232 struct __attribute__ ((packed)) { 233 uint32_t s_zeros; /* first four characters are 0 */ 234 uint32_t s_offset; /* pointer to the string table */ 235 } ptr; 236 } sym_name; 237 238 uint32_t value; /* symbol value */ 239 int16_t sec_num; /* section number */ 240 uint32_t type; /* type */ 241 int8_t st_class; /* storage class */ 242 uint8_t num_auxsym; /* number of auxiliary symbols */ 243 }; 244 245 #define SYMBOL_SIZE_v1 18 246 #define SYMBOL_SIZE_v2 20 247 248 /* Symbol section numbers. -- "sec_num" */ 249 #define N_DEBUG -2 250 #define N_ABS -1 251 #define N_UNDEF 0 252 #define N_SCNUM 1 253 254 /* Symbol types 255 256 Type in an unsigned short (16 bits). The lowest four or five bits contains 257 the basic type. The next higher three bits contain the derived symbol type. 258 The rest of the bits are unused. */ 259 260 /* Basic symbol types */ 261 #define T_NULL 0 /* null */ 262 #define T_VOID 1 /* void */ 263 #define T_CHAR 2 /* character */ 264 #define T_SHORT 3 /* short integer */ 265 #define T_INT 4 /* integer */ 266 #define T_LONG 5 /* long integer */ 267 #define T_FLOAT 6 /* floating point */ 268 #define T_DOUBLE 7 /* double floating point */ 269 #define T_STRUCT 8 /* structure */ 270 #define T_UNION 9 /* union */ 271 #define T_ENUM 10 /* enumeration */ 272 #define T_MOE 11 /* member of enumeration */ 273 #define T_UCHAR 12 /* unsigned character */ 274 #define T_USHORT 13 /* unsigned short */ 275 #define T_UINT 14 /* unsigned integer */ 276 #define T_ULONG 15 /* unsigned long */ 277 /* Basic symbol types for new format only */ 278 #define T_LNGDBL 16 /* long double floating point */ 279 #define T_SLONG 17 /* short long */ 280 #define T_USLONG 18 /* unsigned short long */ 281 282 /* Derived types */ 283 #define DT_NON 0 /* no derived type */ 284 #define DT_PTR 1 /* pointer */ 285 #define DT_FUNCTION 2 /* function */ 286 #define DT_ARRAY 3 /* array */ 287 #define DT_ROMPTR 4 288 #define DT_FARROMPTR 5 289 290 #define T_SHIFT_v1 4 291 #define T_MASK_v1 ((UINT32_MAX << T_SHIFT_v1) ^ UINT32_MAX) 292 293 #define T_SHIFT_v2 5 294 #define T_MASK_v2 ((UINT32_MAX << T_SHIFT_v2) ^ UINT32_MAX) 295 296 /* Storage classes */ 297 #define C_NULL 0 /* null */ 298 #define C_AUTO 1 /* automatic variable */ 299 #define C_EXT 2 /* external symbol */ 300 #define C_STAT 3 /* static */ 301 #define C_REG 4 /* register variable */ 302 #define C_EXTDEF 5 /* external definition */ 303 #define C_LABEL 6 /* label */ 304 #define C_ULABEL 7 /* undefined label */ 305 #define C_MOS 8 /* member of structure */ 306 #define C_ARG 9 /* function argument */ 307 #define C_STRTAG 10 /* structure tag */ 308 #define C_MOU 11 /* member of union */ 309 #define C_UNTAG 12 /* union tag */ 310 #define C_TPDEF 13 /* type definition */ 311 #define C_USTATIC 14 /* undefined static */ 312 #define C_ENTAG 15 /* enumeration tag */ 313 #define C_MOE 16 /* member of enumeration */ 314 #define C_REGPARM 17 /* register parameter */ 315 #define C_FIELD 18 /* bit field */ 316 #define C_AUTOARG 19 /* auto argument */ 317 #define C_LASTENT 20 /* dummy entry (end of block) */ 318 #define C_BLOCK 100 /* ".bb" or ".eb" */ 319 #define C_FCN 101 /* ".bf" or ".ef" */ 320 #define C_EOS 102 /* end of structure */ 321 #define C_FILE 103 /* file name */ 322 #define C_LINE 104 /* line number reformatted as symbol table entry */ 323 #define C_ALIAS 105 /* duplicate tag */ 324 #define C_HIDDEN 106 /* ext symbol in dmert public lib */ 325 #define C_EOF 107 /* end of file */ 326 #define C_LIST 108 /* absoulte listing on or off */ 327 #define C_SECTION 109 /* section */ 328 #define C_EFCN 255 /* physical end of function */ 329 330 /* Auxiliary symbol table entry for a file. */ 331 struct __attribute__ ((packed)) aux_file { 332 /* AUX_FILE -- 20 bytes length */ 333 uint32_t x_offset; /* String table offset for file name. */ 334 uint32_t x_incline; /* Line number at which this file was included, 0->not included. */ 335 uint8_t x_flags; 336 uint8_t _unused[11]; 337 }; 338 339 /* Auxiliary symbol table entry for a section. */ 340 struct __attribute__ ((packed)) aux_scn { 341 /* AUX_SECTION -- 20 bytes length */ 342 uint32_t x_scnlen; /* Section Length. */ 343 uint16_t x_nreloc; /* Number of relocation entries. */ 344 uint16_t x_nlinno; /* Number of line numbers. */ 345 uint8_t _unused[12]; 346 }; 347 348 /* Auxiliary symbol table entry for the tagname of a struct/union/enum. */ 349 struct __attribute__ ((packed)) aux_tag { 350 /* AUX_SUE_TAG -- 20 bytes length */ 351 uint8_t _unused0[6]; 352 uint16_t x_size; /* Size of struct/union/enum. */ 353 uint8_t _unused1[4]; 354 uint32_t x_endndx; /* Symbol index of next entry beyond this struct/union/enum. */ 355 uint8_t _unused2[4]; 356 }; 357 358 /* Auxiliary symbol table entry for an end of struct/union/enum. */ 359 struct __attribute__ ((packed)) aux_eos { 360 /* AUX_SUE_END -- 20 bytes length */ 361 uint32_t x_tagndx; /* Symbol index of struct/union/enum tag. */ 362 uint8_t _unused0[2]; 363 uint16_t x_size; /* Size of struct/union/enum. */ 364 uint8_t _unused1[12]; 365 }; 366 367 /* Auxiliary symbol table entry for a function name. */ 368 struct __attribute__ ((packed)) aux_fcn { 369 /* AUX_FUNCTION -- 20 bytes length */ 370 uint32_t x_tagndx; /* Unused?? Tag Index. */ 371 uint32_t x_size; /* Unused?? Size of function in bits. */ 372 uint32_t x_lnnoptr; /* File pointer to line numbers for this function. */ 373 uint32_t x_endndx; /* Symbol Index of next entry beyond this function. */ 374 uint16_t x_actscnum; /* Size of static activation record to allocate. */ 375 uint8_t _unused[2]; 376 }; 377 378 /* Auxiliary symbol table entry for an array. */ 379 struct __attribute__ ((packed)) aux_arr { 380 /* AUX_ARR -- 20 bytes length */ 381 uint32_t x_tagndx; /* Unused?? Tag Index. */ 382 uint16_t x_lnno; /* Unused?? Line number declaration. */ 383 uint16_t x_size; /* Size of array. */ 384 uint16_t x_dimen[4]; /* Size of first four dimensions. */ 385 uint8_t _unused[4]; 386 }; 387 388 /* Auxiliary symbol table entry for the end of a block or function. */ 389 struct __attribute__ ((packed)) aux_eobf { 390 /* AUX_EOBF -- 20 bytes length */ 391 uint8_t _unused0[4]; 392 uint16_t x_lnno; /* C source line number of the end, relative to start of block/func. */ 393 uint8_t _unused1[14]; 394 }; 395 396 /* Auxiliary symbol table entry for the beginning of a block or function. */ 397 struct __attribute__ ((packed)) aux_bobf { 398 /* AUX_BOBF -- 20 bytes length */ 399 uint8_t _unused0[4]; 400 uint16_t x_lnno; /* C source line number of the beginning, relative to start enclosing scope. */ 401 uint8_t _unused1[6]; 402 uint32_t x_endndx; /* Symbol Index of next entry past this block/func. */ 403 uint8_t _unused2[4]; 404 }; 405 406 /* Auxiliary symbol table entry for a variable of type struct/union/enum. */ 407 struct __attribute__ ((packed)) aux_var { 408 /* AUX_VAR -- 20 bytes length */ 409 uint32_t x_tagndx; /* Symbol index of struct/union/enum tagname. */ 410 uint8_t _unused0[2]; 411 uint16_t x_size; /* Size of the struct/union/enum. */ 412 uint8_t _unused1[12]; 413 }; 414 415 struct __attribute__ ((packed)) aux_field { 416 /* AUX_???? -- 20 bytes length */ 417 uint8_t _unused0[6]; 418 uint16_t x_size; 419 uint8_t _unused1[12]; 420 }; 421 422 struct __attribute__ ((packed)) aux_fcn_calls { 423 /* AUX_FCN_CALLS -- 20 bytes length */ 424 uint32_t x_calleendx; /* Symbol table entry of callee - 1. */ 425 uint32_t x_is_interrupt; /* 0: not, 1: low, 2: high */ 426 uint8_t _unused[12]; 427 }; 428 429 /* Auxiliary symbol table entry for a direct command. */ 430 struct __attribute__ ((packed)) aux_direct { 431 /* AUX_DIRECT -- 20 bytes length */ 432 uint32_t x_command; 433 uint32_t x_offset; /* String table offset for direct string. */ 434 uint8_t _unused[12]; 435 }; 436 437 /* Auxiliary symbol table entry for a ident string. */ 438 struct __attribute__ ((packed)) aux_ident { 439 /* AUX_IDENT -- 20 bytes length */ 440 uint32_t x_offset; /* String table offset for ident string. */ 441 uint8_t _unused[16]; 442 }; 443 444 /* Auxiliary entries */ 445 #define X_DIMNUM 4 446 447 #define AUX_NONE 0 448 #define AUX_FILE 1 /* detail information for a source file */ 449 #define AUX_SECTION 2 /* detail information for a section */ 450 #define AUX_SUE_TAG 3 /* detail information for a struct/union/enum tag */ 451 #define AUX_SUE_END 4 /* end of struct/union/enum */ 452 #define AUX_FUNCTION 5 /* detail information for a function */ 453 #define AUX_ARR 6 /* FIXME */ 454 #define AUX_EOBF 7 /* end of block or function */ 455 #define AUX_BOBF 8 /* beginning of block or function */ 456 #define AUX_VAR 9 /* variable */ 457 #define AUX_DIRECT 10 /* direct message */ 458 #define AUX_IDENT 11 /* ident */ 459 #define AUX_FCN_CALLS 12 /* function called by this function */ 460 461 /* These definitions are for the COFF as stored in memory. */ 462 463 /* relocation linked list */ 464 465 typedef struct gp_reloc { 466 /* This always should be the first item! (gplist.c) */ 467 GPNodeHeader(struct gp_reloc); 468 469 /* entry relative address in bytes */ 470 uint32_t address; 471 472 /* symbol */ 473 struct gp_symbol *symbol; 474 475 /* symbol number, only valid when generating a coff file */ 476 uint32_t symbol_number; 477 478 /* offset added to address of symbol */ 479 int16_t offset; 480 481 /* relocation type */ 482 uint16_t type; 483 484 /* unique identification number of owner section */ 485 unsigned int section_id; 486 } gp_reloc_t; 487 488 typedef struct gp_reloc_list { 489 /* head of relocations 490 * tail of relocations 491 * number of relocations */ 492 GPListHeader(gp_reloc_t); 493 } gp_reloc_list_t; 494 495 /* line number linked list */ 496 497 typedef struct gp_linenum { 498 /* This always should be the first item! (gplist.c) */ 499 GPNodeHeader(struct gp_linenum); 500 501 /* source file symbol */ 502 const struct gp_symbol *symbol; 503 504 /* line number */ 505 uint16_t line_number; 506 507 /* byte address for this line number */ 508 uint32_t address; 509 510 /* unique identification number of owner section */ 511 unsigned int section_id; 512 } gp_linenum_t; 513 514 typedef struct gp_linenum_list { 515 /* head of line numbers 516 * tail of line numbers 517 * number of line numbers */ 518 GPListHeader(gp_linenum_t); 519 } gp_linenum_list_t; 520 521 /* auxiliary symbol linked list */ 522 523 typedef struct gp_aux { 524 /* This always should be the first item! (gplist.c) */ 525 GPNodeHeader(struct gp_aux); 526 527 /* auxiliary symbol type */ 528 uint32_t type; 529 530 /* FIXME: Finish the aux entries. */ 531 union { 532 struct { 533 uint8_t command; 534 const char *string; 535 } _aux_direct; 536 537 struct { 538 const char *filename; 539 uint32_t line_number; 540 uint8_t flags; 541 } _aux_file; 542 543 struct { 544 const char *string; 545 } _aux_ident; 546 547 struct { 548 uint32_t length; 549 uint16_t nreloc; 550 uint16_t nlineno; 551 } _aux_scn; 552 553 struct { 554 struct gp_symbol *callee; /* NULL for call through pointer */ 555 uint32_t is_interrupt; /* 0 not, 1 low, 2 high */ 556 } _aux_fcn_calls; 557 558 uint8_t data[SYMBOL_SIZE_v2]; 559 } _aux_symbol; 560 } gp_aux_t; 561 562 typedef struct gp_aux_list { 563 /* head of auxiliary symbols 564 * tail of auxiliary symbols 565 * number of auxiliary symbols */ 566 GPListHeader(gp_aux_t); 567 } gp_aux_list_t; 568 569 /* A optimize constant for the gpcoffgen.c module. */ 570 #define OPT_FLAGS_GPCOFFGEN_MODULE (1 << 0) 571 572 /* A optimize constant for the gpcoffopt.c module. */ 573 #define OPT_FLAGS_GPCOFFOPT_MODULE (1 << 1) 574 575 /* A optimize constant for the gpsymbol.c module. */ 576 #define OPT_FLAGS_GPSYMBOL_MODULE (1 << 2) 577 578 /* This is a non-erasable section. */ 579 #define OPT_FLAGS_PROTECTED_SECTION (1 << 16) 580 581 /* symbol linked list */ 582 583 typedef struct gp_symbol { 584 /* This always should be the first item! (gplist.c) */ 585 GPNodeHeader(struct gp_symbol); 586 587 /* symbol name */ 588 char *name; 589 590 /* symbol value */ 591 gp_symvalue_t value; 592 593 /* section name of symbol */ 594 const char *section_name; 595 596 /* Section number, only for used for determining symbol type: 597 N_DEBUG = -2, N_ABS = -1, N_UNDEF = 0, or N_SCNUM = 1 if defined */ 598 int16_t section_number; 599 600 /* defining section */ 601 struct gp_section *section; 602 603 /* type */ 604 uint8_t type; 605 606 /* derived type */ 607 uint32_t derived_type; 608 609 /* storage class */ 610 uint8_t class; 611 612 /* list of auxiliary symbols (See above.) */ 613 gp_aux_list_t aux_list; 614 615 /* symbol number, only valid when writing coff or cod file */ 616 uint32_t number; 617 618 /* Number of relocation references from all section. */ 619 unsigned int reloc_count_all_section; 620 /* Number of relocation references from own section. */ 621 unsigned int reloc_count_own_section; 622 /* Number of relocation references from another section. */ 623 unsigned int reloc_count_other_section; 624 625 /* unique identification number of owner object */ 626 unsigned int object_id; 627 628 /***************************************************************************** 629 * 630 * Optimization part of this structure. 631 * 632 *****************************************************************************/ 633 634 /* use optimization -- "OPT_FLAGS_..." 635 or other -- "WARN_..." */ 636 unsigned int opt_flags; 637 } gp_symbol_t; 638 639 typedef struct gp_symbol_list { 640 /* head of symbols 641 * tail of symbols 642 * number of symbols */ 643 GPListHeader(gp_symbol_t); 644 } gp_symbol_list_t; 645 646 /* hash table for find symbol name */ 647 648 typedef struct gp_hash { 649 hash128_t hash; 650 const gp_symbol_t *symbol; 651 } gp_hash_t; 652 653 /* section linked list */ 654 655 typedef struct gp_section { 656 /* This always should be the first item! (gplist.c) */ 657 GPNodeHeader(struct gp_section); 658 659 /* section name */ 660 char *name; 661 662 /* section symbol */ 663 gp_symbol_t *symbol; 664 665 /* flags -- "STYP_..." */ 666 uint32_t flags; 667 668 /* section physical address in bytes */ 669 uint32_t address; 670 671 /* section virtual address in bytes */ 672 uint32_t virtual_address; 673 674 /* section shadow address in bytes */ 675 uint32_t shadow_address; 676 677 /* section size in bytes */ 678 uint32_t size; 679 680 /* memory linked list */ 681 MemBlock_t *data; 682 683 /* list of relocations (See above.) */ 684 gp_reloc_list_t relocation_list; 685 686 /* list of line numbers (See above.) */ 687 gp_linenum_list_t line_number_list; 688 689 /* Ordered, filtered array unto binary searches. */ 690 gp_linenum_t **line_numbers_array; 691 uint16_t line_numbers_array_length; 692 693 /* section number, only valid when writing coff file */ 694 uint32_t number; 695 696 /* data pointer, only valid when writing coff file */ 697 uint32_t data_ptr; 698 699 /* relocations pointer, only valid when writing coff file */ 700 uint32_t reloc_ptr; 701 702 /* linenumber pointer, only valid when writing coff file */ 703 uint32_t lineno_ptr; 704 705 /* number of relocation references */ 706 unsigned int reloc_count; 707 708 /* unique identification number of owner object */ 709 unsigned int object_id; 710 711 /* unique identification number */ 712 unsigned int serial_id; 713 714 /***************************************************************************** 715 * 716 * Optimization part of this structure. 717 * 718 *****************************************************************************/ 719 720 /* Label array of this section. 721 The "label" mean: A symbol which has type of C_EXT or C_LABEL, 722 in a STYP_TEXT or STYP_ROM_DATA type of section. */ 723 gp_symbol_t **label_array; 724 unsigned int num_labels; 725 726 /* use the optimization -- "OPT_FLAGS_..." */ 727 uint32_t opt_flags; 728 } gp_section_t; 729 730 typedef struct gp_section_list { 731 /* head of sections 732 * tail of sections 733 * number of sections */ 734 GPListHeader(gp_section_t); 735 } gp_section_list_t; 736 737 typedef struct gp_object { 738 /* object filename */ 739 char *filename; 740 741 /* format version/magic number */ 742 uint16_t version; 743 744 /* to reduce conditionals, store the size of symbols in this object */ 745 size_t symbol_size; 746 747 /* new style coff file? */ 748 gp_boolean isnew; 749 750 /* processor */ 751 pic_processor_t processor; 752 753 /* processor class */ 754 proc_class_t class; 755 756 /* time object was created */ 757 uint32_t time; 758 759 /* flags */ 760 uint16_t flags; 761 762 /* block of section pointers: Created by gp_coffgen_make_block_section function. */ 763 gp_section_t **section_ptr_array; 764 765 /* list of sections (See above.) */ 766 gp_section_list_t section_list; 767 768 /* list of reserved sections: It is necessary for the gplink/cod.c. */ 769 gp_section_list_t dead_section_list; 770 771 /* number of symbols */ 772 uint32_t num_symbols; 773 774 /* block of symbol pointers: Created by gp_coffgen_make_block_symbol function. */ 775 gp_symbol_t **symbol_ptr_array; 776 777 /* list of symbols (See above.) */ 778 gp_symbol_list_t symbol_list; 779 780 /* list of reserved symbols: It is necessary for the gplink/cod.c. */ 781 gp_symbol_list_t dead_symbol_list; 782 783 /* pointer array for relocation symbols without section */ 784 gp_symbol_t **orphan_reloc_symbol_ptr_array; 785 unsigned int num_orphan_reloc_symbols; 786 787 /* hash table of symbols */ 788 gp_hash_t *symbol_hashtable; 789 unsigned int symbol_hashtable_size; 790 791 /* symbol table pointer, only valid when writing coff file */ 792 uint32_t symbol_ptr; 793 794 /* unique identification number */ 795 unsigned int serial_id; 796 797 /* next object in the linked list */ 798 struct gp_object *next; 799 } gp_object_t; 800 801 #endif 802