Home | History | Annotate | Line # | Download | only in aout2hux
      1  1.1  itohy /*
      2  1.2  itohy  *	m68k a.out / ELF file structure definitions
      3  1.1  itohy  *
      4  1.4  itohy  *	written by ITOH Yasufumi
      5  1.1  itohy  *	public domain
      6  1.1  itohy  *
      7  1.4  itohy  *	$NetBSD: aout68k.h,v 1.4 2011/02/21 02:31:58 itohy 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.2  itohy 
     61  1.2  itohy /*
     62  1.2  itohy  * m68k ELF executable format
     63  1.2  itohy  *
     64  1.2  itohy  *	--------------------------------------
     65  1.2  itohy  *	|  ELF header     (52 bytes)         |
     66  1.2  itohy  *	|------------------------------------|
     67  1.2  itohy  *	|  Program header (32bytes x 1 or 2) |
     68  1.2  itohy  *	|------------------------------------|
     69  1.2  itohy  *	|  section 1 (text)                  |
     70  1.2  itohy  *	|------------------------------------|
     71  1.2  itohy  *	|  section 2 (data)                  |
     72  1.2  itohy  *	|------------------------------------|
     73  1.2  itohy  *	|  ...                               |
     74  1.2  itohy  *	|------------------------------------|
     75  1.2  itohy  *	|  section header table (optional)   |
     76  1.2  itohy  *	--------------------------------------
     77  1.2  itohy  */
     78  1.2  itohy 
     79  1.2  itohy /*
     80  1.2  itohy  * ELF header for m68k
     81  1.2  itohy  */
     82  1.2  itohy struct elf_m68k_hdr {
     83  1.2  itohy #define EI_MAG0		0
     84  1.2  itohy #define EI_MAG1		1
     85  1.2  itohy #define EI_MAG2		2
     86  1.2  itohy #define EI_MAG3		3
     87  1.2  itohy #define EI_CLASS	4
     88  1.2  itohy #define EI_DATA		5
     89  1.2  itohy #define EI_VERSION	6
     90  1.2  itohy #define EL_NIDENT	16
     91  1.2  itohy 	u_int8_t	e_ident[EL_NIDENT];	/* ELF magic */
     92  1.2  itohy #define ELFMAG0		0x7f
     93  1.2  itohy #define ELFMAG1		0x45	/* 'E' */
     94  1.2  itohy #define ELFMAG2		0x4c	/* 'L' */
     95  1.2  itohy #define ELFMAG3		0x46	/* 'F' */
     96  1.2  itohy #define ELFCLASS32	1	/* 32bit */
     97  1.2  itohy #define ELFDATA2MSB	2	/* big endian */
     98  1.2  itohy 	be_uint16_t	e_type;		/* type of this file */
     99  1.3  itohy #define ET_EXEC		2
    100  1.2  itohy 	be_uint16_t	e_machine;	/* architecture id */
    101  1.2  itohy #define EM_68K		4
    102  1.2  itohy 	be_uint32_t	e_version;
    103  1.2  itohy #define EV_CURRENT	1
    104  1.2  itohy 	be_uint32_t	e_entry;	/* entry address */
    105  1.2  itohy 	be_uint32_t	e_phoff;	/* program header address */
    106  1.2  itohy 	be_uint32_t	e_shoff;
    107  1.2  itohy 	be_uint32_t	e_flags;
    108  1.2  itohy 	be_uint16_t	e_ehsize;
    109  1.2  itohy 	be_uint16_t	e_phentsize;	/* program header entry size */
    110  1.2  itohy 	be_uint16_t	e_phnum;	/* number of program header entries */
    111  1.2  itohy 	be_uint16_t	e_shentsize;	/* section header entry size */
    112  1.2  itohy 	be_uint16_t	e_shnum;	/* number of section header entries */
    113  1.2  itohy 	be_uint16_t	e_shstrndx;
    114  1.2  itohy };
    115  1.2  itohy 
    116  1.2  itohy #define SIZE_ELF68K_HDR		(sizeof(struct elf_m68k_hdr))
    117  1.2  itohy 
    118  1.2  itohy /*
    119  1.2  itohy  * Section header for m68k ELF
    120  1.2  itohy  */
    121  1.2  itohy struct elf_m68k_shdr {
    122  1.2  itohy 	be_uint32_t	sh_name;
    123  1.2  itohy 	be_uint32_t	sh_type;
    124  1.2  itohy #define SHT_PROGBITS	1
    125  1.2  itohy 	be_uint32_t	sh_flags;
    126  1.2  itohy #define SHF_WRITE	1
    127  1.2  itohy #define SHF_ALLOC	2
    128  1.2  itohy #define SHF_EXECINSTR	4
    129  1.2  itohy 	be_uint32_t	sh_addr;
    130  1.2  itohy 	be_uint32_t	sh_offset;
    131  1.2  itohy 	be_uint32_t	sh_size;
    132  1.2  itohy 	be_uint32_t	sh_link;
    133  1.2  itohy 	be_uint32_t	sh_info;
    134  1.2  itohy 	be_uint32_t	sh_addralign;
    135  1.2  itohy 	be_uint32_t	sh_entsize;
    136  1.2  itohy };
    137  1.2  itohy 
    138  1.2  itohy #define ELF68K_ISDATASEG(sh)	\
    139  1.2  itohy 	(get_uint32(&(sh)->sh_type) == SHT_PROGBITS &&		\
    140  1.2  itohy 	 (get_uint32(&(sh)->sh_flags) &				\
    141  1.2  itohy 		(SHF_WRITE | SHF_ALLOC | SHF_EXECINSTR)) ==	\
    142  1.2  itohy 			(SHF_WRITE | SHF_ALLOC))	/* no SHF_EXECINSTR */
    143  1.2  itohy 
    144  1.2  itohy #define SIZE_ELF68K_SHDR	(sizeof(struct elf_m68k_shdr))
    145  1.2  itohy 
    146  1.2  itohy /*
    147  1.2  itohy  * Program header for m68k ELF
    148  1.2  itohy  */
    149  1.2  itohy struct elf_m68k_phdr {
    150  1.2  itohy 	be_uint32_t	p_type;		/* type of segment */
    151  1.2  itohy #define PT_LOAD		1
    152  1.2  itohy 	be_uint32_t	p_offset;	/* file offset */
    153  1.2  itohy 	be_uint32_t	p_vaddr;	/* virtual address */
    154  1.2  itohy 	be_uint32_t	p_paddr;	/* physical address (ignored) */
    155  1.2  itohy 	be_uint32_t	p_filesz;	/* size on file */
    156  1.2  itohy 	be_uint32_t	p_memsz;	/* size on memory */
    157  1.2  itohy 	be_uint32_t	p_flags;
    158  1.2  itohy #define PF_R		4
    159  1.2  itohy #define PF_W		2
    160  1.2  itohy #define PF_X		1
    161  1.2  itohy 	be_uint32_t	p_align;
    162  1.2  itohy };
    163  1.2  itohy 
    164  1.2  itohy #define SIZE_ELF68K_PHDR	(sizeof(struct elf_m68k_phdr))
    165