|
| 1 | +// SPDX-FileCopyrightText: 2025 RizinOrg <info@rizin.re> |
| 2 | +// SPDX-FileCopyrightText: 2025 deroad <deroad@kumo.xn--q9jyb4c> |
| 3 | +// SPDX-License-Identifier: LGPL-3.0-only |
| 4 | + |
| 5 | +#ifndef ECOFF_GEN_H |
| 6 | +#define ECOFF_GEN_H |
| 7 | + |
| 8 | +#define ECOFF_GEN_HEADER(size) \ |
| 9 | + typedef struct ecoff_header_##size##_t { \ |
| 10 | + ut16 f_magic; /* magic/machine number */ \ |
| 11 | + ut16 f_nscns; /* number of sections */ \ |
| 12 | + st32 f_timedate; /* time & date stamp */ \ |
| 13 | + st##size f_symptr; /* file pointer to symtab */ \ |
| 14 | + st32 f_nsyms; /* number of symtab entries */ \ |
| 15 | + ut16 f_opthdr; /* size of ECoff_Optional */ \ |
| 16 | + ut16 f_flags; /* flags */ \ |
| 17 | + } ECoff_Header_##size |
| 18 | + |
| 19 | +#define ECOFF_GEN_SECTION(size) \ |
| 20 | + typedef struct ecoff_section_##size##_t { \ |
| 21 | + char s_name[8]; /* section entry name or an index to a name */ \ |
| 22 | + ut##size s_paddr; /* physical address */ \ |
| 23 | + ut##size s_vaddr; /* virtual address */ \ |
| 24 | + ut##size s_size; /* section size */ \ |
| 25 | + ut##size s_scnptr; /* file ptr to raw data for section */ \ |
| 26 | + ut##size s_relptr; /* file ptr to relocation */ \ |
| 27 | + ut##size s_lnnoptr; /* file ptr to line numbers */ \ |
| 28 | + ut16 s_nreloc; /* number of relocation entries */ \ |
| 29 | + ut16 s_nlnno; /* number of line number entries */ \ |
| 30 | + ut32 s_flags; /* flags */ \ |
| 31 | + /* not part of the actual section object */ \ |
| 32 | + char *resolved_name; \ |
| 33 | + } ECoff_Section_##size |
| 34 | + |
| 35 | +#define ECOFF_GEN_SYMBOLIC_HEADER_1992(size) \ |
| 36 | + typedef struct ecoff_symbolic_header_1992_##size##_t { \ |
| 37 | + st32 iline_max; /* Number of line number entries */ \ |
| 38 | + st32 idn_max; /* Number of dense number table (unused) */ \ |
| 39 | + st32 ipd_max; /* Number of procedure descriptors. */ \ |
| 40 | + st32 isym_max; /* Number of local symbols. */ \ |
| 41 | + st32 iopt_max; /* Size of optimization symbol table. */ \ |
| 42 | + st32 iaux_max; /* Number of auxiliary symbols. */ \ |
| 43 | + st32 iss_max; /* Size of local string table. */ \ |
| 44 | + st32 iss_ext_max; /* Size of external string table. */ \ |
| 45 | + st32 ifd_max; /* Number of file descriptors. */ \ |
| 46 | + st32 crfd; /* Number of relative file descriptors. */ \ |
| 47 | + st32 iext_max; /* Number of external symbols. */ \ |
| 48 | + st##size cb_line; /* Size of (packed) line number entries. */ \ |
| 49 | + ut##size cb_line_offset; /* Offset to start of (packed) line numbers. */ \ |
| 50 | + ut##size cb_dn_offset; /* Offset to start of dense number table (unused) */ \ |
| 51 | + ut##size cb_pd_offset; /* Offset to start of procedure descriptors */ \ |
| 52 | + ut##size cb_sym_offset; /* Offset to start of local symbols */ \ |
| 53 | + ut##size cb_opt_offset; /* Offset to start of optimization entries */ \ |
| 54 | + ut##size cb_aux_offset; /* Offset to start of auxiliary symbols */ \ |
| 55 | + ut##size cb_ss_offset; /* Offset to start of local strings */ \ |
| 56 | + ut##size cb_ss_ext_offset; /* Offset to start of external strings. */ \ |
| 57 | + ut##size cb_fd_offset; /* Offset to start of file descriptors. */ \ |
| 58 | + ut##size cb_rfd_offset; /* Offset to start of relative file descriptors. */ \ |
| 59 | + ut##size cb_ext_offset; /* Offset to start of external symbols. */ \ |
| 60 | + } ECoff_SymHdr1992_##size |
| 61 | + |
| 62 | +#define ECOFF_GEN_SYMBOLIC_HEADER_7009(size) \ |
| 63 | + typedef struct ecoff_symbolic_header_7009_##size##_t { \ |
| 64 | + st32 iline_max; /* Number of line number entries */ \ |
| 65 | + st##size cb_line; /* Size of (packed) line number entries. */ \ |
| 66 | + ut##size cb_line_offset; /* Offset to start of (packed) line numbers. */ \ |
| 67 | + st32 idn_max; /* Size of dense number table */ \ |
| 68 | + ut##size cb_dn_offset; /* Offset to start of dense number table */ \ |
| 69 | + st32 ipd_max; /* Number of procedure descriptors. */ \ |
| 70 | + ut##size cb_pd_offset; /* Offset to start of procedure descriptors */ \ |
| 71 | + st32 isym_max; /* Number of local symbols. */ \ |
| 72 | + ut##size cb_sym_offset; /* Offset to start of local symbols */ \ |
| 73 | + st32 iopt_max; /* Number of optimization symbol table. */ \ |
| 74 | + ut##size cb_opt_offset; /* Offset to start of optimization entries */ \ |
| 75 | + st32 iaux_max; /* Number of auxiliary symbols. */ \ |
| 76 | + ut##size cb_aux_offset; /* Offset to start of auxiliary symbols */ \ |
| 77 | + st32 iss_max; /* Size of local string table. */ \ |
| 78 | + ut##size cb_ss_offset; /* Offset to start of local strings */ \ |
| 79 | + st32 iss_ext_max; /* Size of external string table. */ \ |
| 80 | + ut##size cb_ss_ext_offset; /* Offset to start of external strings. */ \ |
| 81 | + st32 ifd_max; /* Number of file descriptors. */ \ |
| 82 | + ut##size cb_fd_offset; /* Offset to start of file descriptors. */ \ |
| 83 | + st32 crfd; /* Size of relative file descriptors. */ \ |
| 84 | + ut##size cb_rfd_offset; /* Offset to start of relative file descriptors. */ \ |
| 85 | + st32 iext_max; /* Number of external symbols. */ \ |
| 86 | + ut##size cb_ext_offset; /* Offset to start of external symbols. */ \ |
| 87 | + } ECoff_SymHdr7009_##size |
| 88 | + |
| 89 | +#define ECOFF_GEN_SYMBOLIC_HEADER(size) \ |
| 90 | + ECOFF_GEN_SYMBOLIC_HEADER_1992(size); \ |
| 91 | + ECOFF_GEN_SYMBOLIC_HEADER_7009(size); \ |
| 92 | + typedef struct ecoff_symbolic_header_##size##_t { \ |
| 93 | + st16 magic; /* Symbol table magic must be 0x1992 (alpha) or 0x7009 (mips) */ \ |
| 94 | + ut16 vstamp; /* Symbol table version stamp (major.minor) */ \ |
| 95 | + union { \ |
| 96 | + ECoff_SymHdr1992_##size _1992; \ |
| 97 | + ECoff_SymHdr7009_##size _7009; \ |
| 98 | + }; \ |
| 99 | + } ECoff_SymHdr_##size |
| 100 | + |
| 101 | +#define ECOFF_GEN_FDE_7009(size) \ |
| 102 | + typedef struct ecoff_file_descriptor_entry_7009_##size##_t { \ |
| 103 | + ut##size adr; /* Address of first instruction */ \ |
| 104 | + st32 rss; /* Offset from start of file's local string table entries to source file name (-1 if unknown). */ \ |
| 105 | + st32 iss_base; /* Start of local strings for this file. */ \ |
| 106 | + st##size cb_ss; /* Size of local string table entries for this file. */ \ |
| 107 | + st32 isym_base; /* Starting index of local symbol entries for this file */ \ |
| 108 | + st32 csym; /* Count of local symbol entries for this file. */ \ |
| 109 | + st32 iopt_base; /* Offset from start of optimization symbol table to optimization symbol entries for this file. */ \ |
| 110 | + st32 copt; /* Size of optimization symbol entries for this file. */ \ |
| 111 | + st32 ipd_first; /* Starting index of procedure descriptors for this file. */ \ |
| 112 | + st32 cpd; /* Count of procedure descriptors for this file. */ \ |
| 113 | + st32 iaux_base; /* Starting index of auxiliary symbol entries for this file. */ \ |
| 114 | + st32 caux; /* Count of auxiliary symbol entries for this file. */ \ |
| 115 | + st32 iind_base; /* Starting index of indirect symbol entries for this file. */ \ |
| 116 | + st32 cind; /* Count of indirect symbol entries for this file. */ \ |
| 117 | + ut32 lang; /* : 5 | Source language for this file */ \ |
| 118 | + ut32 f_merge; /* : 1 | Informs linker whether this file can be merged. */ \ |
| 119 | + ut32 f_readin; /* : 1 | True if file was read in (as opposed to just created). */ \ |
| 120 | + ut32 f_bigendian; /* : 1 | When true, was compiled on big endian machine. */ \ |
| 121 | + ut32 glevel; /* : 2 | Symbolic information level with which this file was compiled. */ \ |
| 122 | + ut32 reserved; /* : 22 | reserved bits */ \ |
| 123 | + st##size cb_line_offset; /* Offset from start of packed line numbers to start of entries for this file */ \ |
| 124 | + st32 cline; /* Count of line number entries (if expanded) for this file. */ \ |
| 125 | + } ECoff_FileDescEntry7009_##size |
| 126 | + |
| 127 | +#define ECOFF_GEN_FDE_1992(size) \ |
| 128 | + typedef struct ecoff_file_descriptor_entry_1992_##size##_t { \ |
| 129 | + ut##size adr; /* Address of first instruction */ \ |
| 130 | + st##size cb_line_offset; /* Offset from start of packed line numbers to start of entries for this file */ \ |
| 131 | + st##size cb_line; /* Size of packed line numbers for this file. */ \ |
| 132 | + st##size cb_ss; /* Size of local string table entries for this file. */ \ |
| 133 | + st32 rss; /* Offset from start of file's local string table entries to source file name (-1 if unknown). */ \ |
| 134 | + st32 iss_base; /* Start of local strings for this file. */ \ |
| 135 | + st32 isym_base; /* Starting index of local symbol entries for this file */ \ |
| 136 | + st32 csym; /* Count of local symbol entries for this file. */ \ |
| 137 | + st32 iline_base; /* Starting index of line number entries (if expanded) for this file. */ \ |
| 138 | + st32 cline; /* Count of line number entries (if expanded) for this file. */ \ |
| 139 | + st32 iopt_base; /* Offset from start of optimization symbol table to optimization symbol entries for this file. */ \ |
| 140 | + st32 copt; /* Size of optimization symbol entries for this file. */ \ |
| 141 | + st32 ipd_first; /* Starting index of procedure descriptors for this file. */ \ |
| 142 | + st32 cpd; /* Count of procedure descriptors for this file. */ \ |
| 143 | + st32 iaux_base; /* Starting index of auxiliary symbol entries for this file. */ \ |
| 144 | + st32 caux; /* Count of auxiliary symbol entries for this file. */ \ |
| 145 | + st32 rfd_base; /* Starting index of relative file descriptors for this file. */ \ |
| 146 | + st32 crfd; /* Count of relative file descriptors for this file. */ \ |
| 147 | + ut16 lang; /* : 5 | Source language for this file */ \ |
| 148 | + ut16 f_merge; /* : 1 | Informs linker whether this file can be merged. */ \ |
| 149 | + ut16 f_readin; /* : 1 | True if file was read in (as opposed to just created). */ \ |
| 150 | + ut16 f_bigendian; /* : 1 | When true, was compiled on big endian machine. */ \ |
| 151 | + ut16 glevel; /* : 2 | Symbolic information level with which this file was compiled. */ \ |
| 152 | + ut16 f_trim; /* : 1 | Unused. */ \ |
| 153 | + ut16 reserved; /* : 5 | reserved bits */ \ |
| 154 | + ut16 vstamp; /* Symbol table version stamp from the .o files. */ \ |
| 155 | + ut32 reserved2; /* reserved bytes */ \ |
| 156 | + } ECoff_FileDescEntry1992_##size |
| 157 | + |
| 158 | +#define ECOFF_GEN_FDE(size) \ |
| 159 | + ECOFF_GEN_FDE_7009(size); \ |
| 160 | + ECOFF_GEN_FDE_1992(size); \ |
| 161 | + typedef struct ecoff_file_descriptor_entry_##size##_t { \ |
| 162 | + union { \ |
| 163 | + ECoff_FileDescEntry7009_##size _7009; \ |
| 164 | + ECoff_FileDescEntry1992_##size _1992; \ |
| 165 | + }; \ |
| 166 | + } ECoff_FileDescEntry_##size |
| 167 | + |
| 168 | +#define ECOFF_GEN_PDE_7009(size) \ |
| 169 | + typedef struct ecoff_procedure_descriptor_entry_7009_##size##_t { \ |
| 170 | + ut##size adr; /* The start address of this procedure. (-1 if no .text) */ \ |
| 171 | + st32 isym; /* Start of local symbols for this procedure. */ \ |
| 172 | + st##size cb_line_offset; /* Offset to the start of this procedure's line numbers from the start of the file descriptor entry */ \ |
| 173 | + ut32 regmask; /* Saved general register mask */ \ |
| 174 | + st32 regoffset; /* Offset from the virtual frame pointer to the general register save area in the stack frame. */ \ |
| 175 | + st32 iopt; /* Start of procedure's optimization symbol entries. */ \ |
| 176 | + ut32 fregmask; /* Saved floating-point register mask. */ \ |
| 177 | + st32 fregoffset; /* Offset from the virtual frame pointer to the floating-point register save area in the stack frame. */ \ |
| 178 | + st32 frameoffset; /* Size of the fixed part of the stack frame. */ \ |
| 179 | + st16 framereg; /* Frame pointer register number. */ \ |
| 180 | + st16 pcreg; /* PC (Program Counter) register number. */ \ |
| 181 | + st32 sline; /* Start of line number entries (if expanded) for this procedure (-1 if unknown). */ \ |
| 182 | + st32 eline; /* End of line number entries (if expanded) for this procedure (-1 if unknown). */ \ |
| 183 | + st32 oline; /* Offset of line number entries (if expanded) for this procedure (-1 if unknown). */ \ |
| 184 | + } ECoff_ProcDescEntry7009_##size |
| 185 | + |
| 186 | +#define ECOFF_GEN_PDE_1992(size) \ |
| 187 | + typedef struct ecoff_procedure_descriptor_entry_1992_##size##_t { \ |
| 188 | + ut##size adr; /* The start address of this procedure. (-1 if no .text) */ \ |
| 189 | + st##size cb_line_offset; /* Offset to the start of this procedure's line numbers from the start of the file descriptor entry */ \ |
| 190 | + st32 isym; /* Start of local symbols for this procedure. */ \ |
| 191 | + st32 iline; /* Start of line number entries (if expanded) for this procedure (-1 if unknown). */ \ |
| 192 | + ut32 regmask; /* Saved general register mask */ \ |
| 193 | + st32 regoffset; /* Offset from the virtual frame pointer to the general register save area in the stack frame. */ \ |
| 194 | + st32 iopt; /* Start of procedure's optimization symbol entries. */ \ |
| 195 | + ut32 fregmask; /* Saved floating-point register mask. */ \ |
| 196 | + st32 fregoffset; /* Offset from the virtual frame pointer to the floating-point register save area in the stack frame. */ \ |
| 197 | + st32 frameoffset; /* Size of the fixed part of the stack frame. */ \ |
| 198 | + st32 ln_low; /* Lowest source line number within this file for the procedure */ \ |
| 199 | + st32 ln_high; /* Highest source line number within this file for the procedure */ \ |
| 200 | + ut32 gp_prologue; /* : 8 | Size of gp prologue. */ \ |
| 201 | + ut32 gp_used; /* : 1 | Flag set if the procedure uses gp. */ \ |
| 202 | + ut32 reg_frame; /* : 1 | True if the procedure is a light-weight or null-weight procedure. */ \ |
| 203 | + ut32 prof; /* : 1 | True if the procedure has been compiled with –pg for gprof profiling. */ \ |
| 204 | + ut32 reserved; /* : 13 | Must be zero. */ \ |
| 205 | + ut32 localoff; /* : 8 | Bias value for accessing local symbols on the stack at run time. */ \ |
| 206 | + st16 framereg; /* Frame pointer register number. */ \ |
| 207 | + st16 pcreg; /* PC (Program Counter) register number. */ \ |
| 208 | + } ECoff_ProcDescEntry1992_##size |
| 209 | + |
| 210 | +#define ECOFF_GEN_PDE(size) \ |
| 211 | + ECOFF_GEN_PDE_7009(size); \ |
| 212 | + ECOFF_GEN_PDE_1992(size); \ |
| 213 | + typedef struct ecoff_procedure_descriptor_entry_##size##_t { \ |
| 214 | + union { \ |
| 215 | + ECoff_ProcDescEntry7009_##size _7009; \ |
| 216 | + ECoff_ProcDescEntry1992_##size _1992; \ |
| 217 | + }; \ |
| 218 | + } ECoff_ProcDescEntry_##size |
| 219 | + |
| 220 | +#define ECOFF_GEN_LOC_SYM(size) \ |
| 221 | + typedef struct ecoff_local_symbol_##size##_t { \ |
| 222 | + st##size value; /* A field that can contain an address, size, offset, or index. */ \ |
| 223 | + st32 iss; /* Offset from the iss_base field of a file descriptor table entry to the name of the symbol (-1 if no name). */ \ |
| 224 | + ut32 st; /* : 6 | Symbol type */ \ |
| 225 | + ut32 sc; /* : 5 | Storage class */ \ |
| 226 | + ut32 reserved; /* : 1 | Must be zero. */ \ |
| 227 | + ut32 index; /* : 20 | An index into either the local symbol table or auxiliary symbol table. */ \ |
| 228 | + /* not part of the actual section object */ \ |
| 229 | + char *resolved_name; \ |
| 230 | + } ECoff_LocalSymbol_##size |
| 231 | + |
| 232 | +#define ECOFF_GEN_EXT_SYM(size) \ |
| 233 | + typedef struct ecoff_external_symbol_##size##_t { \ |
| 234 | + ECoff_LocalSymbol_##size asym; /* External symbol table entry */ \ |
| 235 | + ut32 jmptbl; /* : 1 | Unused. */ \ |
| 236 | + ut32 cobol_main; /* : 1 | Flag set to indicate that the symbol is a COBOL main procedure. */ \ |
| 237 | + ut32 weakext; /* : 1 | Flag set to identify the symbol as a weak external. */ \ |
| 238 | + ut32 alignment; /* : 4 | Power of two byte alignment for common storage class symbols biased by 2^3 (8) */ \ |
| 239 | + ut32 xport; /* : 1 | Flag set to indicate the symbol is to be exported from a shared library. */ \ |
| 240 | + ut32 multiext; /* : 1 | Flag set to indicate that multiple definitions of the symbol are allowed. */ \ |
| 241 | + ut32 reserved; /* : 23 | Must be zero. */ \ |
| 242 | + st32 ifd; /* Index of the file descriptor where the symbol is defined. (-1 for undefined) */ \ |
| 243 | + } ECoff_ExternSymbol_##size |
| 244 | + |
| 245 | +#define ECOFF_GEN_TYPES(size) \ |
| 246 | + ECOFF_GEN_HEADER(size); \ |
| 247 | + ECOFF_GEN_SECTION(size); \ |
| 248 | + ECOFF_GEN_SYMBOLIC_HEADER(size); \ |
| 249 | + ECOFF_GEN_FDE(size); \ |
| 250 | + ECOFF_GEN_PDE(size); \ |
| 251 | + ECOFF_GEN_LOC_SYM(size); \ |
| 252 | + ECOFF_GEN_EXT_SYM(size) |
| 253 | + |
| 254 | +#endif /* ECOFF_GEN_H */ |
0 commit comments