scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

mach.h (3150B)


      1 /*
      2  * some systems define macros with this name even when
      3  * they should be c99 compliant.
      4  */
      5 #undef LITTLE_ENDIAN
      6 #undef BIG_ENDIAN
      7 
      8 #define NBYTES 32
      9 #define OBJ(format,arch,order) ((order) << 10 | (arch) << 5 | (format))
     10 #define FORMAT(t) ((t) & 0x1f)
     11 #define ARCH(t) (((t) >> 5) & 0x1f)
     12 #define ORDER(t) (((t) >> 10) & 0x1f)
     13 #define objfmt(o) FORMAT((o)->type)
     14 
     15 typedef struct section Section;
     16 typedef struct symbol Symbol;
     17 typedef struct obj Obj;
     18 typedef struct map Map;
     19 typedef struct mapsec Mapsec;
     20 
     21 enum objformat {
     22 	COFF32,
     23 	ELF,
     24 	NFORMATS,
     25 };
     26 
     27 enum objarch {
     28 	ARCH286,
     29 	ARCH386,
     30 	ARCHAMD64,
     31 	ARCHZ80,
     32 	ARCHARM32,
     33 	ARCHARM64,
     34 	ARCHUNK32,
     35 	ARCHUNK64,
     36 };
     37 
     38 enum order {
     39 	LITTLE_ENDIAN,
     40 	BIG_ENDIAN,
     41 };
     42 
     43 /**
     44  * enum sectype - Section property flags
     45  * @SREAD: The segment has read rights
     46  * @SWRITE: The segment has write rights
     47  * @SEXEC: The segment has execution rights
     48  * @SLOAD: Segment data is loaded from disk to memory
     49  * @SALLOC: Segment is allocated in memory
     50  * @SRELOC: Segment has to be relocated
     51  * @SABS: Segment is loaded in a specific address
     52  */
     53 enum sectype {
     54 	SREAD   = 1 << 0,
     55 	SWRITE  = 1 << 1,
     56 	SEXEC   = 1 << 2,
     57 	SLOAD   = 1 << 3,
     58 	SALLOC  = 1 << 4,
     59 	SRELOC  = 1 << 5,
     60 	SABS    = 1 << 6,
     61 };
     62 
     63 enum symtype {
     64 	SYMNOTYPE,
     65 	SYMOBJECT,
     66 	SYMFUNC,
     67 	SYMSECTION,
     68 	SYMFILE,
     69 	SYMCOMMON,
     70 };
     71 
     72 struct ar_hdr;
     73 
     74 struct obj {
     75 	char *index;
     76 	int type;
     77 	long pos;
     78 	void *data;
     79 	Obj *next;
     80 };
     81 
     82 struct section {
     83 	char *name;
     84 	unsigned long long base;
     85 	unsigned long long load;
     86 	unsigned long long size;
     87 	long offset;
     88 
     89 	unsigned flags;
     90 	int index;
     91 	int align;
     92 	int fill;
     93 	char type;
     94 };
     95 
     96 #ifdef stdin
     97 struct mapsec {
     98 	Section sec;
     99 	int used;
    100 	int loaded;
    101 	FILE *fp;
    102 	long fsiz;
    103 
    104 	int nchild;
    105 	struct mapsec **child;
    106 };
    107 #endif
    108 
    109 struct map {
    110 	int nsec, nseg;
    111 	struct mapsec *sec;
    112 	struct mapsec *seg;
    113 };
    114 
    115 /**
    116  * @stype: Used internally by libmach
    117  * @dtype: Coff debug type
    118  * @flags: Used only by the assembler
    119  */
    120 struct symbol {
    121 	char *name;
    122 	unsigned long long size;
    123 	unsigned long long value;
    124 	int index;
    125 	int section;
    126 	char type;
    127 	int stype;
    128 	int dtype;
    129 	unsigned flags;
    130 };
    131 
    132 #ifdef stdin
    133 extern int archive(FILE *);
    134 extern long armember(FILE *, char *, struct ar_hdr *);
    135 
    136 extern int objprobe(FILE *, char **);
    137 extern int objpos(Obj *, FILE *, long);
    138 
    139 extern int readobj(Obj *, FILE *);
    140 extern int writeobj(Obj *, Map *, FILE *);
    141 
    142 extern Map *loadmap(Obj *, FILE *);
    143 
    144 extern int mapsec(Map *, Section *, FILE *, long);
    145 extern int mapseg(Map *, Section *, FILE *, long);
    146 
    147 extern int setindex(int, long, char **, long *, FILE *);
    148 extern int getindex(int, long *, char ***, long **, FILE *);
    149 
    150 #endif
    151 
    152 extern Map *newmap(int, int);
    153 extern Map *remap(Map *, int, int);
    154 extern void delmap(Map *);
    155 
    156 extern int objtype(char *);
    157 extern Obj *newobj(int);
    158 extern void delobj(Obj *);
    159 
    160 extern int strip(Obj *);
    161 extern int pc2line(Obj *, unsigned long long, char *, int *);
    162 extern int rebase(Obj *, int, unsigned long long);
    163 
    164 extern int findsec(Map *, char *);
    165 
    166 extern Symbol *getsym(Obj *, int *, Symbol *);
    167 extern Symbol *setsym(Obj *, int *, Symbol *);
    168 extern Section *getsec(Obj *, int *, Section *);
    169 extern Section *setsec(Obj *, int *, Section *);