Home | History | Annotate | Line # | Download | only in aout2hux
aout68k.h revision 1.1.14.1
      1       1.1   itohy /*
      2  1.1.14.1  bouyer  *	m68k a.out / ELF file structure definitions
      3       1.1   itohy  *
      4       1.1   itohy  *	written by Yasha (ITOH Yasufumi)
      5       1.1   itohy  *	public domain
      6       1.1   itohy  *
      7  1.1.14.1  bouyer  *	$NetBSD: aout68k.h,v 1.1.14.1 2000/11/20 20:30:11 bouyer Exp $
      8       1.1   itohy  */
      9       1.1   itohy /*
     10       1.1   itohy  * NetBSD/m68k a.out format (OMAGIC, NMAGIC)
     11       1.1   itohy  *
     12       1.1   itohy  *	----------------------------
     13       1.1   itohy  *	|  file header (32 bytes)  |
     14       1.1   itohy  *	|--------------------------|
     15       1.1   itohy  *	|  text                    |
     16       1.1   itohy  *	|--------------------------|
     17       1.1   itohy  *	|  data                    |
     18       1.1   itohy  *	|--------------------------|
     19       1.1   itohy  *	|  text relocation table   |
     20       1.1   itohy  *	|--------------------------|
     21       1.1   itohy  *	|  data relocation table   |
     22       1.1   itohy  *	|--------------------------|
     23       1.1   itohy  *	|  symbol table            |
     24       1.1   itohy  *	|--------------------------|
     25       1.1   itohy  *	|  string table            |
     26       1.1   itohy  *	----------------------------
     27       1.1   itohy  *
     28       1.1   itohy  * OMAGIC: text and data segments are loaded contiguous
     29       1.1   itohy  * NMAGIC: data segment is loaded at the next page of the text
     30       1.1   itohy  */
     31       1.1   itohy 
     32       1.1   itohy struct aout_m68k {
     33       1.1   itohy 	be_uint32_t	a_magic;	/* encoded magic number */
     34       1.1   itohy 	be_uint32_t	a_text;		/* size of text section */
     35       1.1   itohy 	be_uint32_t	a_data;		/* size of data section */
     36       1.1   itohy 	be_uint32_t	a_bss;		/* size of bss */
     37       1.1   itohy 	be_uint32_t	a_syms;		/* size of symbol table */
     38       1.1   itohy 	be_uint32_t	a_entry;	/* entry point address */
     39       1.1   itohy 	be_uint32_t	a_trsize;	/* size of text relocation */
     40       1.1   itohy 	be_uint32_t	a_drsize;	/* size of data relocation */
     41       1.1   itohy };
     42       1.1   itohy 
     43       1.1   itohy #define AOUT_GET_MAGIC(e)	(((e)->a_magic.val[2]<<8) | (e)->a_magic.val[3])
     44       1.1   itohy #define	AOUT_OMAGIC	0407
     45       1.1   itohy #define	AOUT_NMAGIC	0410
     46       1.1   itohy #define	AOUT_ZMAGIC	0413	/* demand paging --- header is in the text */
     47       1.1   itohy 
     48       1.1   itohy #define AOUT_GET_FLAGS(e)	((e)->a_magic.val[0] >> 2)
     49       1.1   itohy #define AOUT_FLAG_PIC		0x10
     50       1.1   itohy #define AOUT_FLAG_DYNAMIC	0x20
     51       1.1   itohy 
     52       1.1   itohy /* machine ID */
     53       1.1   itohy #define AOUT_GET_MID(e)		((((e)->a_magic.val[0] & 0x03) << 8) |	\
     54       1.1   itohy 					(e)->a_magic.val[1])
     55       1.1   itohy #define	AOUT_MID_M68K	135	/* m68k BSD binary, 8KB page */
     56       1.1   itohy #define	AOUT_MID_M68K4K	136	/* m68k BSD binary, 4KB page */
     57       1.1   itohy 
     58       1.1   itohy #define AOUT_PAGESIZE(e)	(AOUT_GET_MAGIC(e) == AOUT_OMAGIC ? 1 :	\
     59       1.1   itohy 				AOUT_GET_MID(e) == AOUT_MID_M68K ? 8192 : 4096)
     60  1.1.14.1  bouyer 
     61  1.1.14.1  bouyer /*
     62  1.1.14.1  bouyer  * m68k ELF executable format
     63  1.1.14.1  bouyer  *
     64  1.1.14.1  bouyer  *	--------------------------------------
     65  1.1.14.1  bouyer  *	|  ELF header     (52 bytes)         |
     66  1.1.14.1  bouyer  *	|------------------------------------|
     67  1.1.14.1  bouyer  *	|  Program header (32bytes x 1 or 2) |
     68  1.1.14.1  bouyer  *	|------------------------------------|
     69  1.1.14.1  bouyer  *	|  section 1 (text)                  |
     70  1.1.14.1  bouyer  *	|------------------------------------|
     71  1.1.14.1  bouyer  *	|  section 2 (data)                  |
     72  1.1.14.1  bouyer  *	|------------------------------------|
     73  1.1.14.1  bouyer  *	|  ...                               |
     74  1.1.14.1  bouyer  *	|------------------------------------|
     75  1.1.14.1  bouyer  *	|  section header table (optional)   |
     76  1.1.14.1  bouyer  *	--------------------------------------
     77  1.1.14.1  bouyer  */
     78  1.1.14.1  bouyer 
     79  1.1.14.1  bouyer /*
     80  1.1.14.1  bouyer  * ELF header for m68k
     81  1.1.14.1  bouyer  */
     82  1.1.14.1  bouyer struct elf_m68k_hdr {
     83  1.1.14.1  bouyer #define EI_MAG0		0
     84  1.1.14.1  bouyer #define EI_MAG1		1
     85  1.1.14.1  bouyer #define EI_MAG2		2
     86  1.1.14.1  bouyer #define EI_MAG3		3
     87  1.1.14.1  bouyer #define EI_CLASS	4
     88  1.1.14.1  bouyer #define EI_DATA		5
     89  1.1.14.1  bouyer #define EI_VERSION	6
     90  1.1.14.1  bouyer #define EL_NIDENT	16
     91  1.1.14.1  bouyer 	u_int8_t	e_ident[EL_NIDENT];	/* ELF magic */
     92  1.1.14.1  bouyer #define ELFMAG0		0x7f
     93  1.1.14.1  bouyer #define ELFMAG1		0x45	/* 'E' */
     94  1.1.14.1  bouyer #define ELFMAG2		0x4c	/* 'L' */
     95  1.1.14.1  bouyer #define ELFMAG3		0x46	/* 'F' */
     96  1.1.14.1  bouyer #define ELFCLASS32	1	/* 32bit */
     97  1.1.14.1  bouyer #define ELFDATA2MSB	2	/* big endian */
     98  1.1.14.1  bouyer 	be_uint16_t	e_type;		/* type of this file */
     99  1.1.14.1  bouyer #define ET_EXEC		2
    100  1.1.14.1  bouyer 	be_uint16_t	e_machine;	/* architecture id */
    101  1.1.14.1  bouyer #define EM_68K		4
    102  1.1.14.1  bouyer 	be_uint32_t	e_version;
    103  1.1.14.1  bouyer #define EV_CURRENT	1
    104  1.1.14.1  bouyer 	be_uint32_t	e_entry;	/* entry address */
    105  1.1.14.1  bouyer 	be_uint32_t	e_phoff;	/* program header address */
    106  1.1.14.1  bouyer 	be_uint32_t	e_shoff;
    107  1.1.14.1  bouyer 	be_uint32_t	e_flags;
    108  1.1.14.1  bouyer 	be_uint16_t	e_ehsize;
    109  1.1.14.1  bouyer 	be_uint16_t	e_phentsize;	/* program header entry size */
    110  1.1.14.1  bouyer 	be_uint16_t	e_phnum;	/* number of program header entries */
    111  1.1.14.1  bouyer 	be_uint16_t	e_shentsize;	/* section header entry size */
    112  1.1.14.1  bouyer 	be_uint16_t	e_shnum;	/* number of section header entries */
    113  1.1.14.1  bouyer 	be_uint16_t	e_shstrndx;
    114  1.1.14.1  bouyer };
    115  1.1.14.1  bouyer 
    116  1.1.14.1  bouyer #define SIZE_ELF68K_HDR		(sizeof(struct elf_m68k_hdr))
    117  1.1.14.1  bouyer 
    118  1.1.14.1  bouyer /*
    119  1.1.14.1  bouyer  * Section header for m68k ELF
    120  1.1.14.1  bouyer  */
    121  1.1.14.1  bouyer struct elf_m68k_shdr {
    122  1.1.14.1  bouyer 	be_uint32_t	sh_name;
    123  1.1.14.1  bouyer 	be_uint32_t	sh_type;
    124  1.1.14.1  bouyer #define SHT_PROGBITS	1
    125  1.1.14.1  bouyer 	be_uint32_t	sh_flags;
    126  1.1.14.1  bouyer #define SHF_WRITE	1
    127  1.1.14.1  bouyer #define SHF_ALLOC	2
    128  1.1.14.1  bouyer #define SHF_EXECINSTR	4
    129  1.1.14.1  bouyer 	be_uint32_t	sh_addr;
    130  1.1.14.1  bouyer 	be_uint32_t	sh_offset;
    131  1.1.14.1  bouyer 	be_uint32_t	sh_size;
    132  1.1.14.1  bouyer 	be_uint32_t	sh_link;
    133  1.1.14.1  bouyer 	be_uint32_t	sh_info;
    134  1.1.14.1  bouyer 	be_uint32_t	sh_addralign;
    135  1.1.14.1  bouyer 	be_uint32_t	sh_entsize;
    136  1.1.14.1  bouyer };
    137  1.1.14.1  bouyer 
    138  1.1.14.1  bouyer #define ELF68K_ISDATASEG(sh)	\
    139  1.1.14.1  bouyer 	(get_uint32(&(sh)->sh_type) == SHT_PROGBITS &&		\
    140  1.1.14.1  bouyer 	 (get_uint32(&(sh)->sh_flags) &				\
    141  1.1.14.1  bouyer 		(SHF_WRITE | SHF_ALLOC | SHF_EXECINSTR)) ==	\
    142  1.1.14.1  bouyer 			(SHF_WRITE | SHF_ALLOC))	/* no SHF_EXECINSTR */
    143  1.1.14.1  bouyer 
    144  1.1.14.1  bouyer #define SIZE_ELF68K_SHDR	(sizeof(struct elf_m68k_shdr))
    145  1.1.14.1  bouyer 
    146  1.1.14.1  bouyer /*
    147  1.1.14.1  bouyer  * Program header for m68k ELF
    148  1.1.14.1  bouyer  */
    149  1.1.14.1  bouyer struct elf_m68k_phdr {
    150  1.1.14.1  bouyer 	be_uint32_t	p_type;		/* type of segment */
    151  1.1.14.1  bouyer #define PT_LOAD		1
    152  1.1.14.1  bouyer 	be_uint32_t	p_offset;	/* file offset */
    153  1.1.14.1  bouyer 	be_uint32_t	p_vaddr;	/* virtual address */
    154  1.1.14.1  bouyer 	be_uint32_t	p_paddr;	/* physical address (ignored) */
    155  1.1.14.1  bouyer 	be_uint32_t	p_filesz;	/* size on file */
    156  1.1.14.1  bouyer 	be_uint32_t	p_memsz;	/* size on memory */
    157  1.1.14.1  bouyer 	be_uint32_t	p_flags;
    158  1.1.14.1  bouyer #define PF_R		4
    159  1.1.14.1  bouyer #define PF_W		2
    160  1.1.14.1  bouyer #define PF_X		1
    161  1.1.14.1  bouyer 	be_uint32_t	p_align;
    162  1.1.14.1  bouyer };
    163  1.1.14.1  bouyer 
    164  1.1.14.1  bouyer #define SIZE_ELF68K_PHDR	(sizeof(struct elf_m68k_phdr))
    165