0001
0002
0003
0004
0005
0006 #include <stdint.h>
0007
0008 typedef struct filehdr {
0009 uint16_t f_magic;
0010 uint16_t f_nscns;
0011 int32_t f_timdat;
0012 int32_t f_symptr;
0013 int32_t f_nsyms;
0014 uint16_t f_opthdr;
0015 uint16_t f_flags;
0016 } FILHDR;
0017 #define FILHSZ sizeof(FILHDR)
0018
0019 #define MIPSEBMAGIC 0x160
0020 #define MIPSELMAGIC 0x162
0021
0022 typedef struct scnhdr {
0023 char s_name[8];
0024 int32_t s_paddr;
0025 int32_t s_vaddr;
0026 int32_t s_size;
0027 int32_t s_scnptr;
0028 int32_t s_relptr;
0029 int32_t s_lnnoptr;
0030 uint16_t s_nreloc;
0031 uint16_t s_nlnno;
0032 int32_t s_flags;
0033 } SCNHDR;
0034 #define SCNHSZ sizeof(SCNHDR)
0035 #define SCNROUND ((int32_t)16)
0036
0037 typedef struct aouthdr {
0038 int16_t magic;
0039 int16_t vstamp;
0040 int32_t tsize;
0041 int32_t dsize;
0042 int32_t bsize;
0043 int32_t entry;
0044 int32_t text_start;
0045 int32_t data_start;
0046 int32_t bss_start;
0047 int32_t gprmask;
0048 int32_t cprmask[4];
0049 int32_t gp_value;
0050 } AOUTHDR;
0051 #define AOUTHSZ sizeof(AOUTHDR)
0052
0053 #define OMAGIC 0407
0054 #define NMAGIC 0410
0055 #define ZMAGIC 0413
0056 #define SMAGIC 0411
0057 #define LIBMAGIC 0443
0058
0059 #define N_TXTOFF(f, a) \
0060 ((a).magic == ZMAGIC || (a).magic == LIBMAGIC ? 0 : \
0061 ((a).vstamp < 23 ? \
0062 ((FILHSZ + AOUTHSZ + (f).f_nscns * SCNHSZ + 7) & 0xfffffff8) : \
0063 ((FILHSZ + AOUTHSZ + (f).f_nscns * SCNHSZ + SCNROUND-1) & ~(SCNROUND-1)) ) )
0064 #define N_DATOFF(f, a) \
0065 N_TXTOFF(f, a) + (a).tsize;