scc

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

coff32.c (3772B)


      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 
      4 #include <scc/mach.h>
      5 #include <scc/coff32.h>
      6 
      7 #include "objdump.h"
      8 
      9 void
     10 coff32syms(Obj *obj)
     11 {
     12 	long i;
     13 	struct coff32 *coff = obj->data;
     14 	FILHDR *hdr = &coff->hdr;
     15 
     16 	for (i = 0; i < hdr->f_nsyms; i++) {
     17 		SYMENT *ent;
     18 		AUXENT *aux;
     19 		Entry *ep = &coff->ents[i];
     20 
     21 		aux = &ep->u.aux;
     22 		switch (ep->type) {
     23 		case SYM_ENT:
     24 			ent = &ep->u.sym;
     25 			printf("[%4ld](sec %2d)(ty %4x)(scl %3d) (nx %d) 0x%04lX %s\n", 
     26 			       i,
     27 			       ent->n_scnum,
     28 			       ent->n_type,
     29 			       ent->n_sclass,
     30 			       ent->n_numaux,
     31 			       ent->n_value,
     32 			       coff32str(coff, ent));
     33 			break;
     34 		case SYM_AUX_UNK:
     35 			puts("AUX");
     36 			break;
     37 		case SYM_AUX_SYM:
     38 			printf("AUX tagndx %ld lnno %d size 0x%x lnnoptr %ld endndx %ld tv %d\n",
     39 			       aux->x_tagndx,
     40 			       aux->x_lnno,
     41 			       aux->x_size,
     42 			       aux->x_lnnoptr,
     43 			       aux->x_endndx,
     44 			       aux->x_tvndx);
     45 			break;
     46 		case SYM_AUX_FILE:
     47 			printf("File %s\n", coff32str(coff, aux));
     48 			break;
     49 		case SYM_AUX_SCN:
     50 			printf("AUX scnlen 0x%lx nreloc %d nlnno %d chk %lu ass %d comdat %d\n",
     51 			       aux->x_scnlen,
     52 			       aux->x_nreloc,
     53 			       aux->x_nlinno,
     54 			       aux->x_checksum,
     55 			       aux->x_associated,
     56 			       aux->x_comdat);
     57 			break;
     58 		case SYM_AUX_FUN:
     59 			printf("AUX tagndx %ld fsize 0x%lx lnnoptr %ld endndx %ld tv %d\n",
     60 			       aux->x_fsize,
     61 			       aux->x_tagndx,
     62 			       aux->x_lnnoptr,
     63 			       aux->x_endndx,
     64 			       aux->x_tvndx);
     65 			break;
     66 		case SYM_AUX_ARY:
     67 		break;
     68 			abort();
     69 		}
     70 	}
     71 }
     72 
     73 void
     74 coff32scns(Obj *obj)
     75 {
     76 	int i;
     77 	char *name;
     78 	SCNHDR *scn;
     79 	struct coff32 *coff = obj->data;
     80 	FILHDR *hdr = &coff->hdr;
     81 
     82 	for (i = 0; i < hdr->f_nscns; i++) {
     83 		scn = &coff->scns[i];
     84 		name = coff32str(coff, scn);
     85 		if (!selected(name))
     86 			continue;
     87 		printf("\nscnhdr: %d\n"
     88 		       "\tname: %s\n"
     89 		       "\ts_paddr: 0x%04lx\n"
     90 		       "\ts_vaddr: 0x%04lx\n"
     91 		       "\ts_size: 0x%04lx\n"
     92 		       "\ts_scnptr: %ld\n"
     93 		       "\ts_relptr: %ld\n"
     94 		       "\ts_lnnoptr: %ld\n"
     95 		       "\ts_nrelloc: %u\n"
     96 		       "\ts_nlnno: %u\n"
     97 		       "\ts_flags: %#lx\n",
     98 		       i,
     99 		       name,
    100 		       scn->s_paddr,
    101 		       scn->s_vaddr,
    102 		       scn->s_size,
    103 		       scn->s_scnptr,
    104 		       scn->s_relptr,
    105 		       scn->s_lnnoptr,
    106 		       scn->s_nrelloc,
    107 		       scn->s_nlnno,
    108 		       scn->s_flags);
    109 	}	
    110 }
    111 
    112 void
    113 coff32fhdr(Obj *obj, unsigned long long *start, Flags *f)
    114 {
    115 	unsigned flags;
    116 	struct coff32 *coff = obj->data;
    117 	FILHDR *hdr = &coff->hdr;
    118 	AOUTHDR *aout = &coff->aout;
    119 
    120 	flags = hdr->f_flags;
    121 	setflag(f, (flags & F_RELFLG) == 0, HAS_RELOC);
    122 	setflag(f, (flags & F_LMNO) == 0, HAS_LINENO);
    123 	setflag(f, (flags & F_LSYMS) == 0, HAS_LOCALS);
    124 	setflag(f, hdr->f_nsyms > 0, HAS_SYMS);
    125 	setflag(f, flags & F_EXEC, EXEC_P);
    126 	setflag(f, flags & F_EXEC, D_PAGED);
    127 
    128 	if (pflag) {
    129 		printf("FILEHDR:\n"
    130 		       "\tf_magic: %#x\n"
    131 		       "\tf_nscns: %u\n"
    132 		       "\tf_timdat: %ld\n"
    133 		       "\tf_symptr: %ld\n"
    134 		       "\tf_nsyms: %ld\n"
    135 		       "\tf_opthdr: %u\n"
    136 		       "\tf_flags: 0x%04x\n\n",
    137 		       hdr->f_magic,
    138 		       hdr->f_nscns,
    139 		       hdr->f_timdat,
    140 		       hdr->f_symptr,
    141 		       hdr->f_nsyms,
    142 		       hdr->f_opthdr,
    143 		       hdr->f_flags);
    144 	}
    145 
    146 	if (hdr->f_opthdr > 0) {
    147 		*start = aout->entry;
    148 		if (pflag) {
    149 			printf("AOUTHDR:\n"
    150 			       "\tmagic: %x\n"
    151 			       "\tvstamp: %x\n"
    152 			       "\ttsize: %04lx\n"
    153 			       "\tdsize: %04lx\n"
    154 			       "\tbsize: %04lx\n"
    155 			       "\tentry: %04lx\n"
    156 			       "\ttext_start: %04lx\n"
    157 		           "\tdata_start: %04lx\n\n",
    158 			       aout->magic,
    159 			       aout->vstamp,
    160 			       aout->tsize,
    161 			       aout->dsize,
    162 			       aout->bsize,
    163 			       aout->entry,
    164 			       aout->text_start,
    165 			       aout->data_start);
    166 		}
    167 	}
    168 }