00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #define E_SYMNMLEN 8
00018 #define E_FILNMLEN 14
00019 #define E_DIMNUM 4
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #define COFF_SHORT_L(ps) ((short)(((unsigned short)((unsigned char)ps[1])<<8)|\
00034 ((unsigned short)((unsigned char)ps[0]))))
00035
00036
00037 #define COFF_LONG_L(ps) (((long)(((unsigned long)((unsigned char)ps[3])<<24) |\
00038 ((unsigned long)((unsigned char)ps[2])<<16) |\
00039 ((unsigned long)((unsigned char)ps[1])<<8) |\
00040 ((unsigned long)((unsigned char)ps[0])))))
00041
00042
00043 #define COFF_SHORT_H(ps) ((short)(((unsigned short)((unsigned char)ps[0])<<8)|\
00044 ((unsigned short)((unsigned char)ps[1]))))
00045
00046
00047 #define COFF_LONG_H(ps) (((long)(((unsigned long)((unsigned char)ps[0])<<24) |\
00048 ((unsigned long)((unsigned char)ps[1])<<16) |\
00049 ((unsigned long)((unsigned char)ps[2])<<8) |\
00050 ((unsigned long)((unsigned char)ps[3])))))
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 #define COFF_LONG(v) COFF_LONG_L(v)
00062 #define COFF_SHORT(v) COFF_SHORT_L(v)
00063
00064
00065
00066
00067
00068 struct COFF_filehdr {
00069 char f_magic[2];
00070 char f_nscns[2];
00071 char f_timdat[4];
00072 char f_symptr[4];
00073 char f_nsyms[4];
00074 char f_opthdr[2];
00075 char f_flags[2];
00076 };
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 #define COFF_F_RELFLG 0000001
00105 #define COFF_F_EXEC 0000002
00106 #define COFF_F_LNNO 0000004
00107 #define COFF_F_LSYMS 0000010
00108 #define COFF_F_MINMAL 0000020
00109 #define COFF_F_UPDATE 0000040
00110 #define COFF_F_SWABD 0000100
00111 #define COFF_F_AR16WR 0000200
00112 #define COFF_F_AR32WR 0000400
00113 #define COFF_F_AR32W 0001000
00114 #define COFF_F_PATCH 0002000
00115 #define COFF_F_NODF 0002000
00116
00117 #define COFF_I386MAGIC 0x14c
00118
00119 #if 0
00120 #define COFF_I386PTXMAGIC 0x154
00121 #define COFF_I386AIXMAGIC 0x175
00122 #define COFF_I386BADMAG(x) ((COFF_SHORT((x).f_magic) != COFF_I386MAGIC) \
00123 && COFF_SHORT((x).f_magic) != COFF_I386PTXMAGIC \
00124 && COFF_SHORT((x).f_magic) != COFF_I386AIXMAGIC)
00125 #else
00126 #define COFF_I386BADMAG(x) (COFF_SHORT((x).f_magic) != COFF_I386MAGIC)
00127 #endif
00128
00129 #define COFF_FILHDR struct COFF_filehdr
00130 #define COFF_FILHSZ sizeof(COFF_FILHDR)
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149 typedef struct
00150 {
00151 char magic[2];
00152 char vstamp[2];
00153 char tsize[4];
00154 char dsize[4];
00155 char bsize[4];
00156 char entry[4];
00157 char text_start[4];
00158 char data_start[4];
00159 }
00160 COFF_AOUTHDR;
00161
00162 #define COFF_AOUTSZ (sizeof(COFF_AOUTHDR))
00163
00164 #define COFF_STMAGIC 0401
00165 #define COFF_OMAGIC 0404
00166 #define COFF_JMAGIC 0407
00167 #define COFF_DMAGIC 0410
00168 #define COFF_ZMAGIC 0413
00169 #define COFF_SHMAGIC 0443
00170
00171
00172
00173 struct COFF_scnhdr {
00174 char s_name[8];
00175 char s_paddr[4];
00176 char s_vaddr[4];
00177 char s_size[4];
00178 char s_scnptr[4];
00179 char s_relptr[4];
00180 char s_lnnoptr[4];
00181 char s_nreloc[2];
00182 char s_nlnno[2];
00183 char s_flags[4];
00184 };
00185
00186 #define COFF_SCNHDR struct COFF_scnhdr
00187 #define COFF_SCNHSZ sizeof(COFF_SCNHDR)
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197 #define COFF_TEXT ".text"
00198 #define COFF_DATA ".data"
00199 #define COFF_BSS ".bss"
00200 #define COFF_COMMENT ".comment"
00201 #define COFF_LIB ".lib"
00202
00203 #define COFF_SECT_TEXT 0
00204 #define COFF_SECT_DATA 1
00205 #define COFF_SECT_BSS 2
00206 #define COFF_SECT_REQD 3
00207
00208 #define COFF_STYP_REG 0x00
00209 #define COFF_STYP_DSECT 0x01
00210 #define COFF_STYP_NOLOAD 0x02
00211 #define COFF_STYP_GROUP 0x04
00212 #define COFF_STYP_PAD 0x08
00213 #define COFF_STYP_COPY 0x10
00214 #define COFF_STYP_TEXT 0x20
00215 #define COFF_STYP_DATA 0x40
00216 #define COFF_STYP_BSS 0x80
00217 #define COFF_STYP_INFO 0x200
00218 #define COFF_STYP_OVER 0x400
00219 #define COFF_STYP_LIB 0x800
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230 struct COFF_slib {
00231 char sl_entsz[4];
00232 char sl_pathndx[4];
00233 };
00234
00235 #define COFF_SLIBHD struct COFF_slib
00236 #define COFF_SLIBSZ sizeof(COFF_SLIBHD)
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250 struct COFF_lineno {
00251 union {
00252 char l_symndx[4];
00253 char l_paddr[4];
00254 } l_addr;
00255 char l_lnno[2];
00256 };
00257
00258 #define COFF_LINENO struct COFF_lineno
00259 #define COFF_LINESZ 6
00260
00261
00262
00263 #define COFF_E_SYMNMLEN 8
00264 #define COFF_E_FILNMLEN 14
00265 #define COFF_E_DIMNUM 4
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275 struct COFF_syment
00276 {
00277 union {
00278 char e_name[E_SYMNMLEN];
00279 struct {
00280 char e_zeroes[4];
00281 char e_offset[4];
00282 } e;
00283 } e;
00284
00285 char e_value[4];
00286 char e_scnum[2];
00287 char e_type[2];
00288 char e_sclass[1];
00289 char e_numaux[1];
00290 };
00291
00292 #define COFF_N_BTMASK (0xf)
00293 #define COFF_N_TMASK (0x30)
00294 #define COFF_N_BTSHFT (4)
00295 #define COFF_N_TSHIFT (2)
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305 union COFF_auxent {
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315 struct {
00316 char x_tagndx[4];
00317 union {
00318 struct {
00319 char x_lnno[2];
00320 char x_size[2];
00321 } x_lnsz;
00322 char x_fsize[4];
00323 } x_misc;
00324
00325 union {
00326 struct {
00327 char x_lnnoptr[4];
00328 char x_endndx[4];
00329 } x_fcn;
00330
00331 struct {
00332 char x_dimen[E_DIMNUM][2];
00333 } x_ary;
00334 } x_fcnary;
00335
00336 char x_tvndx[2];
00337 } x_sym;
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347 union {
00348 char x_fname[E_FILNMLEN];
00349 struct {
00350 char x_zeroes[4];
00351 char x_offset[4];
00352 } x_n;
00353 } x_file;
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363 struct {
00364 char x_scnlen[4];
00365 char x_nreloc[2];
00366 char x_nlinno[2];
00367 } x_scn;
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377 struct {
00378 char x_tvfill[4];
00379 char x_tvlen[2];
00380 char x_tvran[2][2];
00381 } x_tv;
00382 };
00383
00384 #define COFF_SYMENT struct COFF_syment
00385 #define COFF_SYMESZ 18
00386 #define COFF_AUXENT union COFF_auxent
00387 #define COFF_AUXESZ 18
00388
00389 #define COFF_ETEXT "etext"
00390
00391
00392
00393 struct COFF_reloc {
00394 char r_vaddr[4];
00395 char r_symndx[4];
00396 char r_type[2];
00397 };
00398
00399 #define COFF_RELOC struct COFF_reloc
00400 #define COFF_RELSZ 10
00401
00402 #define COFF_DEF_DATA_SECTION_ALIGNMENT 4
00403 #define COFF_DEF_BSS_SECTION_ALIGNMENT 4
00404 #define COFF_DEF_TEXT_SECTION_ALIGNMENT 4
00405
00406
00407 #define COFF_DEF_SECTION_ALIGNMENT 4