From 8abf9484aa165999b93d86ff28183b14db4f75ab Mon Sep 17 00:00:00 2001 From: obrien Date: Tue, 22 Jun 2004 17:05:39 +0000 Subject: Adjust the system endian and a.out headers to be more MI and cross-building friendly. Use the systems headers rather than local versions. Reviewed by: ru --- usr.sbin/btxld/Makefile | 1 - usr.sbin/btxld/btxld.c | 84 +++++++++++++++++++------------------- usr.sbin/btxld/elfh.c | 104 ++++++++++++++++++++++++------------------------ 3 files changed, 94 insertions(+), 95 deletions(-) (limited to 'usr.sbin/btxld') diff --git a/usr.sbin/btxld/Makefile b/usr.sbin/btxld/Makefile index 912be22..32cf99d 100644 --- a/usr.sbin/btxld/Makefile +++ b/usr.sbin/btxld/Makefile @@ -3,6 +3,5 @@ PROG= btxld MAN= btxld.8 SRCS= btxld.c elfh.c -CFLAGS+=-I${.CURDIR}/../kgzip .include diff --git a/usr.sbin/btxld/btxld.c b/usr.sbin/btxld/btxld.c index 9216031..6fd7f45 100644 --- a/usr.sbin/btxld/btxld.c +++ b/usr.sbin/btxld/btxld.c @@ -30,9 +30,11 @@ static const char rcsid[] = #endif /* not lint */ #include +#include #include #include +#include #include #include #include @@ -44,8 +46,6 @@ static const char rcsid[] = #include "btx.h" #include "elfh.h" -#include "endian.h" -#include "i386_a.out.h" #define BTX_PATH "/sys/boot/i386/btx" @@ -261,9 +261,9 @@ btxld(const char *iname) break; case I_BTX: btxle = btx; - btxle.btx_pgctl = HTOLE16(btxle.btx_pgctl); - btxle.btx_textsz = HTOLE16(btxle.btx_textsz); - btxle.btx_entry = HTOLE32(btxle.btx_entry); + btxle.btx_pgctl = htole16(btxle.btx_pgctl); + btxle.btx_textsz = htole16(btxle.btx_textsz); + btxle.btx_entry = htole32(btxle.btx_entry); writex(fdo, &btxle, sizeof(btxle)); copy(fdi[i], fdo, btx.btx_textsz - sizeof(btx), sizeof(btx)); @@ -305,9 +305,9 @@ getbtx(int fd, struct btx_hdr * btx) btx->btx_magic[1] != BTX_MAG1 || btx->btx_magic[2] != BTX_MAG2) errx(1, "%s: Not a BTX kernel", fname); - btx->btx_pgctl = LE16TOH(btx->btx_pgctl); - btx->btx_textsz = LE16TOH(btx->btx_textsz); - btx->btx_entry = LE32TOH(btx->btx_entry); + btx->btx_pgctl = le16toh(btx->btx_pgctl); + btx->btx_textsz = le16toh(btx->btx_textsz); + btx->btx_entry = le32toh(btx->btx_entry); } /* @@ -317,7 +317,7 @@ static void gethdr(int fd, struct hdr *hdr) { struct stat sb; - const struct i386_exec *ex; + const struct exec *ex; const Elf32_Ehdr *ee; const Elf32_Phdr *ep; void *p; @@ -336,20 +336,20 @@ gethdr(int fd, struct hdr *hdr) switch (fmt) { case F_AOUT: ex = p; - if (hdr->size >= sizeof(struct i386_exec) && !I386_N_BADMAG(*ex)) { + if (hdr->size >= sizeof(struct exec) && !N_BADMAG(*ex)) { hdr->fmt = fmt; - x = I386_N_GETMAGIC(*ex); + x = N_GETMAGIC(*ex); if (x == OMAGIC || x == NMAGIC) { if (x == NMAGIC) Warn(fname, "Treating %s NMAGIC as OMAGIC", fmtlist[fmt]); hdr->flags |= IMPURE; } - hdr->text = LE32TOH(ex->a_text); - hdr->data = LE32TOH(ex->a_data); - hdr->bss = LE32TOH(ex->a_bss); - hdr->entry = LE32TOH(ex->a_entry); - if (LE32TOH(ex->a_entry) >= BTX_PGSIZE) + hdr->text = le32toh(ex->a_text); + hdr->data = le32toh(ex->a_data); + hdr->bss = le32toh(ex->a_bss); + hdr->entry = le32toh(ex->a_entry); + if (le32toh(ex->a_entry) >= BTX_PGSIZE) hdr->org = BTX_PGSIZE; } break; @@ -357,21 +357,21 @@ gethdr(int fd, struct hdr *hdr) ee = p; if (hdr->size >= sizeof(Elf32_Ehdr) && IS_ELF(*ee)) { hdr->fmt = fmt; - for (n = i = 0; i < LE16TOH(ee->e_phnum); i++) { - ep = (void *)((uint8_t *)p + LE32TOH(ee->e_phoff) + - LE16TOH(ee->e_phentsize) * i); - if (LE32TOH(ep->p_type) == PT_LOAD) + for (n = i = 0; i < le16toh(ee->e_phnum); i++) { + ep = (void *)((uint8_t *)p + le32toh(ee->e_phoff) + + le16toh(ee->e_phentsize) * i); + if (le32toh(ep->p_type) == PT_LOAD) switch (n++) { case 0: - hdr->text = LE32TOH(ep->p_filesz); - hdr->org = LE32TOH(ep->p_paddr); - if (LE32TOH(ep->p_flags) & PF_W) + hdr->text = le32toh(ep->p_filesz); + hdr->org = le32toh(ep->p_paddr); + if (le32toh(ep->p_flags) & PF_W) hdr->flags |= IMPURE; break; case 1: - hdr->data = LE32TOH(ep->p_filesz); - hdr->bss = LE32TOH(ep->p_memsz) - - LE32TOH(ep->p_filesz); + hdr->data = le32toh(ep->p_filesz); + hdr->bss = le32toh(ep->p_memsz) - + le32toh(ep->p_filesz); break; case 2: Warn(fname, @@ -379,7 +379,7 @@ gethdr(int fd, struct hdr *hdr) fmtlist[fmt]); } } - hdr->entry = LE32TOH(ee->e_entry); + hdr->entry = le32toh(ee->e_entry); } } if (munmap(p, hdr->size)) @@ -392,33 +392,33 @@ gethdr(int fd, struct hdr *hdr) static void puthdr(int fd, struct hdr *hdr) { - struct i386_exec ex; + struct exec ex; struct elfh eh; switch (hdr->fmt) { case F_AOUT: memset(&ex, 0, sizeof(ex)); - I386_N_SETMAGIC(ex, ZMAGIC, MID_ZERO, 0); - hdr->text = I386_N_ALIGN(ex, hdr->text); - ex.a_text = HTOLE32(hdr->text); - hdr->data = I386_N_ALIGN(ex, hdr->data); - ex.a_data = HTOLE32(hdr->data); - ex.a_entry = HTOLE32(hdr->entry); + N_SETMAGIC(ex, ZMAGIC, MID_ZERO, 0); + hdr->text = N_ALIGN(ex, hdr->text); + ex.a_text = htole32(hdr->text); + hdr->data = N_ALIGN(ex, hdr->data); + ex.a_data = htole32(hdr->data); + ex.a_entry = htole32(hdr->entry); writex(fd, &ex, sizeof(ex)); - hdr->size = I386_N_ALIGN(ex, sizeof(ex)); + hdr->size = N_ALIGN(ex, sizeof(ex)); seekx(fd, hdr->size); break; case F_ELF: eh = elfhdr; - eh.e.e_entry = HTOLE32(hdr->entry); - eh.p[0].p_vaddr = eh.p[0].p_paddr = HTOLE32(hdr->org); - eh.p[0].p_filesz = eh.p[0].p_memsz = HTOLE32(hdr->text); - eh.p[1].p_offset = HTOLE32(LE32TOH(eh.p[0].p_offset) + - LE32TOH(eh.p[0].p_filesz)); + eh.e.e_entry = htole32(hdr->entry); + eh.p[0].p_vaddr = eh.p[0].p_paddr = htole32(hdr->org); + eh.p[0].p_filesz = eh.p[0].p_memsz = htole32(hdr->text); + eh.p[1].p_offset = htole32(le32toh(eh.p[0].p_offset) + + le32toh(eh.p[0].p_filesz)); eh.p[1].p_vaddr = eh.p[1].p_paddr = - HTOLE32(align(LE32TOH(eh.p[0].p_paddr) + LE32TOH(eh.p[0].p_memsz), + htole32(align(le32toh(eh.p[0].p_paddr) + le32toh(eh.p[0].p_memsz), 4)); - eh.p[1].p_filesz = eh.p[1].p_memsz = HTOLE32(hdr->data); + eh.p[1].p_filesz = eh.p[1].p_memsz = htole32(hdr->data); eh.sh[2].sh_addr = eh.p[0].p_vaddr; eh.sh[2].sh_offset = eh.p[0].p_offset; eh.sh[2].sh_size = eh.p[0].p_filesz; diff --git a/usr.sbin/btxld/elfh.c b/usr.sbin/btxld/elfh.c index 75b7e33..2790d5a 100644 --- a/usr.sbin/btxld/elfh.c +++ b/usr.sbin/btxld/elfh.c @@ -27,10 +27,10 @@ */ #include +#include #include #include "elfh.h" -#include "endian.h" #define SET_ME 0xeeeeeeee /* filled in by btxld */ @@ -44,80 +44,80 @@ const struct elfh elfhdr = { ELFCLASS32, ELFDATA2LSB, EV_CURRENT, 0, 'F', 'r', 'e', 'e', 'B', 'S', 'D', 0 }, - HTOLE16(ET_EXEC), /* e_type */ - HTOLE16(EM_386), /* e_machine */ - HTOLE32(EV_CURRENT), /* e_version */ - HTOLE32(SET_ME), /* e_entry */ - HTOLE32(offsetof(struct elfh, p)), /* e_phoff */ - HTOLE32(offsetof(struct elfh, sh)), /* e_shoff */ + htole16(ET_EXEC), /* e_type */ + htole16(EM_386), /* e_machine */ + htole32(EV_CURRENT), /* e_version */ + htole32(SET_ME), /* e_entry */ + htole32(offsetof(struct elfh, p)), /* e_phoff */ + htole32(offsetof(struct elfh, sh)), /* e_shoff */ 0, /* e_flags */ - HTOLE16(sizeof(elfhdr.e)), /* e_ehsize */ - HTOLE16(sizeof(elfhdr.p[0])), /* e_phentsize */ - HTOLE16(sizeof(elfhdr.p) / sizeof(elfhdr.p[0])), /* e_phnum */ - HTOLE16(sizeof(elfhdr.sh[0])), /* e_shentsize */ - HTOLE16(sizeof(elfhdr.sh) / sizeof(elfhdr.sh[0])), /* e_shnum */ - HTOLE16(1) /* e_shstrndx */ + htole16(sizeof(elfhdr.e)), /* e_ehsize */ + htole16(sizeof(elfhdr.p[0])), /* e_phentsize */ + htole16(sizeof(elfhdr.p) / sizeof(elfhdr.p[0])), /* e_phnum */ + htole16(sizeof(elfhdr.sh[0])), /* e_shentsize */ + htole16(sizeof(elfhdr.sh) / sizeof(elfhdr.sh[0])), /* e_shnum */ + htole16(1) /* e_shstrndx */ }, { { - HTOLE32(PT_LOAD), /* p_type */ - HTOLE32(sizeof(elfhdr)), /* p_offset */ - HTOLE32(SET_ME), /* p_vaddr */ - HTOLE32(SET_ME), /* p_paddr */ - HTOLE32(SET_ME), /* p_filesz */ - HTOLE32(SET_ME), /* p_memsz */ - HTOLE32(PF_R | PF_X), /* p_flags */ - HTOLE32(0x1000) /* p_align */ + htole32(PT_LOAD), /* p_type */ + htole32(sizeof(elfhdr)), /* p_offset */ + htole32(SET_ME), /* p_vaddr */ + htole32(SET_ME), /* p_paddr */ + htole32(SET_ME), /* p_filesz */ + htole32(SET_ME), /* p_memsz */ + htole32(PF_R | PF_X), /* p_flags */ + htole32(0x1000) /* p_align */ }, { - HTOLE32(PT_LOAD), /* p_type */ - HTOLE32(SET_ME), /* p_offset */ - HTOLE32(SET_ME), /* p_vaddr */ - HTOLE32(SET_ME), /* p_paddr */ - HTOLE32(SET_ME), /* p_filesz */ - HTOLE32(SET_ME), /* p_memsz */ - HTOLE32(PF_R | PF_W), /* p_flags */ - HTOLE32(0x1000) /* p_align */ + htole32(PT_LOAD), /* p_type */ + htole32(SET_ME), /* p_offset */ + htole32(SET_ME), /* p_vaddr */ + htole32(SET_ME), /* p_paddr */ + htole32(SET_ME), /* p_filesz */ + htole32(SET_ME), /* p_memsz */ + htole32(PF_R | PF_W), /* p_flags */ + htole32(0x1000) /* p_align */ } }, { { - 0, HTOLE32(SHT_NULL), 0, 0, 0, 0, HTOLE32(SHN_UNDEF), 0, 0, 0 + 0, htole32(SHT_NULL), 0, 0, 0, 0, htole32(SHN_UNDEF), 0, 0, 0 }, { - HTOLE32(1), /* sh_name */ - HTOLE32(SHT_STRTAB), /* sh_type */ + htole32(1), /* sh_name */ + htole32(SHT_STRTAB), /* sh_type */ 0, /* sh_flags */ 0, /* sh_addr */ - HTOLE32(offsetof(struct elfh, shstrtab)), /* sh_offset */ - HTOLE32(sizeof(elfhdr.shstrtab)), /* sh_size */ - HTOLE32(SHN_UNDEF), /* sh_link */ + htole32(offsetof(struct elfh, shstrtab)), /* sh_offset */ + htole32(sizeof(elfhdr.shstrtab)), /* sh_size */ + htole32(SHN_UNDEF), /* sh_link */ 0, /* sh_info */ - HTOLE32(1), /* sh_addralign */ + htole32(1), /* sh_addralign */ 0 /* sh_entsize */ }, { - HTOLE32(0xb), /* sh_name */ - HTOLE32(SHT_PROGBITS), /* sh_type */ - HTOLE32(SHF_EXECINSTR | SHF_ALLOC), /* sh_flags */ - HTOLE32(SET_ME), /* sh_addr */ - HTOLE32(SET_ME), /* sh_offset */ - HTOLE32(SET_ME), /* sh_size */ - HTOLE32(SHN_UNDEF), /* sh_link */ + htole32(0xb), /* sh_name */ + htole32(SHT_PROGBITS), /* sh_type */ + htole32(SHF_EXECINSTR | SHF_ALLOC), /* sh_flags */ + htole32(SET_ME), /* sh_addr */ + htole32(SET_ME), /* sh_offset */ + htole32(SET_ME), /* sh_size */ + htole32(SHN_UNDEF), /* sh_link */ 0, /* sh_info */ - HTOLE32(4), /* sh_addralign */ + htole32(4), /* sh_addralign */ 0 /* sh_entsize */ }, { - HTOLE32(0x11), /* sh_name */ - HTOLE32(SHT_PROGBITS), /* sh_type */ - HTOLE32(SHF_ALLOC | SHF_WRITE), /* sh_flags */ - HTOLE32(SET_ME), /* sh_addr */ - HTOLE32(SET_ME), /* sh_offset */ - HTOLE32(SET_ME), /* sh_size */ - HTOLE32(SHN_UNDEF), /* sh_link */ + htole32(0x11), /* sh_name */ + htole32(SHT_PROGBITS), /* sh_type */ + htole32(SHF_ALLOC | SHF_WRITE), /* sh_flags */ + htole32(SET_ME), /* sh_addr */ + htole32(SET_ME), /* sh_offset */ + htole32(SET_ME), /* sh_size */ + htole32(SHN_UNDEF), /* sh_link */ 0, /* sh_info */ - HTOLE32(4), /* sh_addralign */ + htole32(4), /* sh_addralign */ 0 /* sh_entsize */ } }, -- cgit v1.1