scc

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

coff32getsec.c (1579B)


      1 #include <stdio.h>
      2 
      3 #include <scc/mach.h>
      4 
      5 #include "../libmach.h"
      6 #include "coff32.h"
      7 
      8 Section *
      9 coff32getsec(Obj *obj, int *idx, Section *sec)
     10 {
     11 	long n = *idx;
     12 	int type;
     13 	unsigned sflags;
     14 	SCNHDR *scn;
     15 	Coff32 *coff = obj->data;
     16 	FILHDR *hdr = &coff->hdr;
     17 
     18 	if (n >= hdr->f_nscns)
     19 		return NULL;
     20 
     21 	scn = &coff->scns[n];
     22 	switch (scn->s_flags) {
     23 	case STYP_REG:
     24 		type = 'D';
     25 		sflags = SALLOC | SRELOC | SLOAD | SWRITE | SREAD;
     26 		break;
     27 	case STYP_DSECT:
     28 		type = '?';
     29 		sflags = SRELOC;
     30 		break;
     31 	case STYP_NOLOAD:
     32 		type = 'D';
     33 		sflags = SALLOC | SREAD | SWRITE;
     34 		break;
     35 	case TYP_REVERSE_PAD:
     36 	case STYP_PAD:
     37 		type = '?';
     38 		sflags = SLOAD;
     39 		break;
     40 	case STYP_COPY:
     41 		type = '?';
     42 		sflags |= SLOAD | SRELOC;
     43 		break;
     44 	case STYP_TEXT:
     45 		type = 'T';
     46 		sflags = SALLOC | SRELOC | SLOAD | SEXEC | SREAD;
     47 		break;
     48 	case STYP_DATA:
     49 		type = 'D';
     50 		sflags = SALLOC | SRELOC | SLOAD | SWRITE | SREAD;
     51 		break;
     52 	case STYP_BSS:
     53 		type = 'B';
     54 		sflags = SALLOC | SREAD | SWRITE;
     55 		break;
     56 	case STYP_TEXT | STYP_DATA:
     57 		type = 'D';
     58 		sflags = SEXEC | SALLOC | SRELOC | SLOAD | SREAD;
     59 		break;
     60 	case STYP_LIT:
     61 	case STYP_RDATA:
     62 		type = 'D';
     63 		sflags = SALLOC | SRELOC | SLOAD | SREAD;
     64 		break;
     65 	case STYP_LIB:
     66 	case STYP_INFO:
     67 		type = 'N';
     68 		sflags = 0;
     69 		break;
     70 	case STYP_OVER:
     71 		type = '?';
     72 		sflags = SRELOC;
     73 		break;
     74 	case STYP_GROUP:
     75 	case STYP_MERGE:
     76 	default:
     77 		type = '?';
     78 		sflags = 0;
     79 		break;
     80 	}
     81 
     82 	sec->name = scn->s_name;
     83 	sec->index = n;
     84 	sec->size = scn->s_size;
     85 	sec->base = scn->s_vaddr;
     86 	sec->type = type;
     87 	sec->flags = sflags;
     88 	sec->align = 16;
     89 
     90 	return sec;
     91 }