scc

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

coff32loadmap.c (647B)


      1 #include <stdio.h>
      2 
      3 #include <scc/mach.h>
      4 
      5 #include "../libmach.h"
      6 #include "coff32.h"
      7 
      8 Map *
      9 coff32loadmap(Obj *obj, FILE *fp)
     10 {
     11 	long i;
     12 	Map *map;
     13 	long nsec;
     14 	FILE *src;
     15 	SCNHDR *scn;
     16 	struct coff32 *coff = obj->data;
     17 	FILHDR *hdr = &coff->hdr;
     18 
     19 	nsec = hdr->f_nscns;
     20 	if ((map = newmap(NULL, nsec)) == NULL)
     21 		return NULL;
     22 
     23 	for (scn = coff->scns; nsec--; ++scn) {
     24 		unsigned long o;
     25 		unsigned long long b = scn->s_paddr;
     26 		unsigned long long e = b + scn->s_size;
     27 
     28 		if (scn->s_scnptr != 0) {
     29 			o = obj->pos + scn->s_scnptr;
     30 			src = fp;
     31 		} else {
     32 			o = 0;
     33 			src = NULL;
     34 		}
     35 
     36 		setmap(map, scn->s_name, src, b, e, o);
     37 	}
     38 
     39 	return map;
     40 }