diff options
author | Per Fogelstrom <pefo@cvs.openbsd.org> | 2004-09-09 22:11:40 +0000 |
---|---|---|
committer | Per Fogelstrom <pefo@cvs.openbsd.org> | 2004-09-09 22:11:40 +0000 |
commit | 3e2fc1bb21e67310e10ff7c7ea903a52d1d146c5 (patch) | |
tree | a2c47bb3faeb2e75c409ab493a08dfc31618f2ac /sys/arch/sgi | |
parent | a43c3f9026f27033758dccd3e48b089490114475 (diff) |
Kernel moves to 64 bit. A few more tweaks when binutils is updated.
Diffstat (limited to 'sys/arch/sgi')
-rw-r--r-- | sys/arch/sgi/conf/GENERIC | 9 | ||||
-rw-r--r-- | sys/arch/sgi/conf/Makefile.sgi | 9 | ||||
-rw-r--r-- | sys/arch/sgi/conf/files.sgi | 7 | ||||
-rw-r--r-- | sys/arch/sgi/conf/ld.script | 6 | ||||
-rw-r--r-- | sys/arch/sgi/include/exec.h | 27 | ||||
-rw-r--r-- | sys/arch/sgi/localbus/macebus.c | 12 | ||||
-rw-r--r-- | sys/arch/sgi/localbus/macectrl.S | 4 | ||||
-rw-r--r-- | sys/arch/sgi/pci/macepcimap.c | 7 | ||||
-rw-r--r-- | sys/arch/sgi/sgi/locore.S | 8 | ||||
-rw-r--r-- | sys/arch/sgi/sgi/machdep.c | 18 | ||||
-rw-r--r-- | sys/arch/sgi/stand/boot/Makefile | 6 | ||||
-rw-r--r-- | sys/arch/sgi/stand/boot/boot.c | 215 |
12 files changed, 222 insertions, 106 deletions
diff --git a/sys/arch/sgi/conf/GENERIC b/sys/arch/sgi/conf/GENERIC index 4c6d8dba7e1..9df34babddc 100644 --- a/sys/arch/sgi/conf/GENERIC +++ b/sys/arch/sgi/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.7 2004/08/11 15:13:21 deraadt Exp $ +# $OpenBSD: GENERIC,v 1.8 2004/09/09 22:11:39 pefo Exp $ # machine sgi mips64 @@ -8,14 +8,11 @@ include "../../../conf/GENERIC" maxusers 32 # Make options -#makeoption ISALEV="-mips3 -mlong64 -fno-builtin" -makeoption ISALEV="-mips2 -D_MIPS_ISA=_MIPS_ISA_MIPS2" -makeoption ENDIAN="-EB" +#makeoption ABI="-mabi=64" +#makeoption ENDIAN="-EB" # MD options option ARCBIOS # We use arcbios for FW comminication. -#option COMPAT_O32 # Mips o32 ABI compat -#option DB_ELFSIZE=32 #option APERTURE diff --git a/sys/arch/sgi/conf/Makefile.sgi b/sys/arch/sgi/conf/Makefile.sgi index 53bea276d82..72ea3cad98f 100644 --- a/sys/arch/sgi/conf/Makefile.sgi +++ b/sys/arch/sgi/conf/Makefile.sgi @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.sgi,v 1.4 2004/08/23 14:26:24 pefo Exp $ +# $OpenBSD: Makefile.sgi,v 1.5 2004/09/09 22:11:39 pefo Exp $ # Makefile for OpenBSD # @@ -29,7 +29,6 @@ CPP?= cpp LD?= ld ${ENDIAN} STRIP?= strip TOUCH?= touch -ISALEV?=-mips3 -mlong64 -fno-builtin CPP+=${ENDIAN} CC+=${ENDIAN} AS+=${ENDIAN} @@ -48,9 +47,9 @@ CPPFLAGS= ${INCLUDES} ${IDENT} -D_KERNEL -D__sgi__ CDIAGFLAGS= -Werror -Wall -Wmissing-prototypes -Wstrict-prototypes \ -Wno-uninitialized -Wno-format -Wno-main -CFLAGS= ${DEBUG} -O2 ${CDIAGFLAGS} -mno-abicalls ${ISALEV} \ - ${COPTS} -AFLAGS= -x assembler-with-cpp -traditional-cpp -mno-abicalls ${ISALEV} -D_LOCORE +CFLAGS= ${DEBUG} -O2 ${CDIAGFLAGS} -mno-abicalls ${ABI} \ + ${COPTS} -msoft-float -fno-builtin +AFLAGS= -x assembler-with-cpp -traditional-cpp -mno-abicalls ${ABI} -D_LOCORE ### find out what to use for libkern .include "$S/lib/libkern/Makefile.inc" diff --git a/sys/arch/sgi/conf/files.sgi b/sys/arch/sgi/conf/files.sgi index 2caff721db0..bd27e76f11f 100644 --- a/sys/arch/sgi/conf/files.sgi +++ b/sys/arch/sgi/conf/files.sgi @@ -1,4 +1,4 @@ -# $OpenBSD: files.sgi,v 1.3 2004/08/10 19:08:18 deraadt Exp $ +# $OpenBSD: files.sgi,v 1.4 2004/09/09 22:11:39 pefo Exp $ # # maxpartitions must be first item in files.${ARCH} # @@ -118,8 +118,3 @@ file dev/cninit.c file netinet/in_cksum.c file netns/ns_cksum.c ns -# -# mips o32 ABI compat. -# -#include "compat/mipso32/files.mipso32" - diff --git a/sys/arch/sgi/conf/ld.script b/sys/arch/sgi/conf/ld.script index f9393c3eec1..9076ac46476 100644 --- a/sys/arch/sgi/conf/ld.script +++ b/sys/arch/sgi/conf/ld.script @@ -1,11 +1,11 @@ -OUTPUT_FORMAT("elf32-tradbigmips", "elf32-tradlittlemips", - "elf32-tradbigmips") +OUTPUT_FORMAT("elf64-tradbigmips", "elf64-tradlittlemips", + "elf64-tradbigmips") OUTPUT_ARCH(mips) ENTRY(_start) SECTIONS { /* Read-only sections, merged into text segment: */ - . = 0x80100000 + SIZEOF_HEADERS; + . = 0xffffffff80100000 + SIZEOF_HEADERS; .text : { _ftext = . ; diff --git a/sys/arch/sgi/include/exec.h b/sys/arch/sgi/include/exec.h index de11ac4ac1d..fc07310e027 100644 --- a/sys/arch/sgi/include/exec.h +++ b/sys/arch/sgi/include/exec.h @@ -1,4 +1,4 @@ -/* $OpenBSD: exec.h,v 1.6 2004/08/11 09:55:41 deraadt Exp $ */ +/* $OpenBSD: exec.h,v 1.7 2004/09/09 22:11:39 pefo Exp $ */ /* * Copyright (c) 1996-2004 Per Fogelstrom, Opsycon AB @@ -35,11 +35,22 @@ * Define what exec "formats" we should handle. */ #define NATIVE_EXEC_ELF +#define NATIVE_ELFSIZE 64 #define EXEC_SCRIPT -#define ARCH_ELFSIZE 32 +/* + * If included from sys/exec.h define kernels ELF format. + */ +#ifdef __LP64__ +#define ARCH_ELFSIZE 64 +#define DB_ELFSIZE 64 +#define ELF_TARG_CLASS ELFCLASS64 +#else +#define ARCH_ELFSIZE 32 +#define DB_ELFSIZE 32 +#define ELF_TARG_CLASS ELFCLASS32 +#endif -#define ELF_TARG_CLASS ELFCLASS32 #if defined(__MIPSEB__) #define ELF_TARG_DATA ELFDATA2MSB #else @@ -49,9 +60,13 @@ #define _NLIST_DO_ELF -#define _KERN_DO_ELF #if defined(_LP64) #define _KERN_DO_ELF64 +#if defined(COMPAT_O32) +#define _KERN_DO_ELF +#endif +#else +#define _KERN_DO_ELF #endif /* Information taken from MIPS ABI supplemental */ @@ -165,5 +180,9 @@ typedef struct { #define R_MIPS_CALL16 11 /* 16 bit GOT entry for function */ #define R_MIPS_GPREL32 12 /* GP relative 32 bit */ +#define R_MIPS_64 18 + +#define R_MIPS_REL32_64 ((R_MIPS_64 << 8) | R_MIPS_REL32) + #endif /* !_MIPS_EXEC_H_ */ diff --git a/sys/arch/sgi/localbus/macebus.c b/sys/arch/sgi/localbus/macebus.c index 07529a93fa7..aff96b984d3 100644 --- a/sys/arch/sgi/localbus/macebus.c +++ b/sys/arch/sgi/localbus/macebus.c @@ -1,4 +1,4 @@ -/* $OpenBSD: macebus.c,v 1.5 2004/08/11 15:13:35 deraadt Exp $ */ +/* $OpenBSD: macebus.c,v 1.6 2004/09/09 22:11:39 pefo Exp $ */ /* * Copyright (c) 2000-2004 Opsycon AB (www.opsycon.se) @@ -322,7 +322,11 @@ mace_read_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o) u_int64_t mace_read_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o) { +#ifdef __LP64__ + return *(volatile u_int64_t *)(h + o); +#else return lp32_read8((u_int64_t *)(h + o)); +#endif } void @@ -346,7 +350,11 @@ mace_write_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, u_int32_t v) void mace_write_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, u_int64_t v) { +#ifdef __LP64__ + *(volatile u_int64_t *)(h + o) = v; +#else lp32_write8((u_int64_t *)(h + o), v); +#endif } int @@ -725,7 +733,7 @@ macebus_aux(intrmask_t hwpend, struct trap_frame *cf) } bus_space_write_8(&macebus_tag, mace_h, MACE_ISA_MISC_REG, mask); - if (maceticks++ > 100*15) { + if (maceticks++ > 100*5) { maceticks = 0; } diff --git a/sys/arch/sgi/localbus/macectrl.S b/sys/arch/sgi/localbus/macectrl.S index 83e6820a8a9..153ce326cc9 100644 --- a/sys/arch/sgi/localbus/macectrl.S +++ b/sys/arch/sgi/localbus/macectrl.S @@ -1,4 +1,4 @@ -/* $OpenBSD: macectrl.S,v 1.2 2004/08/10 19:16:18 deraadt Exp $ */ +/* $OpenBSD: macectrl.S,v 1.3 2004/09/09 22:11:39 pefo Exp $ */ /* * Copyright (c) 2004 Opsycon AB (www.opsycon.se / www.opsycon.com) @@ -52,4 +52,4 @@ END(hw_setintrmask) .data .globl hwmask_addr -hwmask_addr: .long 0 +hwmask_addr: PTR_VAL 0 diff --git a/sys/arch/sgi/pci/macepcimap.c b/sys/arch/sgi/pci/macepcimap.c index 623ba93cb7e..41d7bacd3a3 100644 --- a/sys/arch/sgi/pci/macepcimap.c +++ b/sys/arch/sgi/pci/macepcimap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: macepcimap.c,v 1.2 2004/08/11 15:13:35 deraadt Exp $ */ +/* $OpenBSD: macepcimap.c,v 1.3 2004/09/09 22:11:39 pefo Exp $ */ /* $NetBSD: pci_mace.c,v 1.2 2004/01/19 10:28:28 sekiya Exp $ */ /* @@ -63,6 +63,11 @@ void pciaddr_print_devid(pci_chipset_tag_t, pcitag_t); unsigned int ioaddr_base = 0x1000; unsigned int memaddr_base = 0x80100000; +#ifdef DEBUG +int pcibiosverbose = 1; +#endif + + void pciaddr_remap(pci_chipset_tag_t pc) { diff --git a/sys/arch/sgi/sgi/locore.S b/sys/arch/sgi/sgi/locore.S index 3be0143e7ed..f9ec31d795a 100644 --- a/sys/arch/sgi/sgi/locore.S +++ b/sys/arch/sgi/sgi/locore.S @@ -1,4 +1,4 @@ -/* $OpenBSD: locore.S,v 1.3 2004/08/10 19:16:18 deraadt Exp $ */ +/* $OpenBSD: locore.S,v 1.4 2004/09/09 22:11:39 pefo Exp $ */ /* * Copyright (c) 2001-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) @@ -40,8 +40,6 @@ .set noreorder # Noreorder is default style! -#define ITLBNOPFIX nop;nop;nop;nop;nop;nop;nop;nop;nop;nop; - .globl idle_stack # idle stack just below kernel. idle_stack: @@ -55,8 +53,8 @@ start: /* * Initialize stack and call machine startup. */ - la sp, start - FRAMESZ(CF_SZ) - la gp, _gp + LA sp, start - FRAMESZ(CF_SZ) + LA gp, _gp jal mips_init # mips_init(argc, argv, envp) sw zero, CF_RA_OFFS(sp) # Zero out old ra for debugger diff --git a/sys/arch/sgi/sgi/machdep.c b/sys/arch/sgi/sgi/machdep.c index be785845a35..ff7229a4836 100644 --- a/sys/arch/sgi/sgi/machdep.c +++ b/sys/arch/sgi/sgi/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.9 2004/09/09 10:25:52 miod Exp $ */ +/* $OpenBSD: machdep.c,v 1.10 2004/09/09 22:11:39 pefo Exp $ */ /* * Copyright (c) 2003-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) @@ -188,8 +188,8 @@ mips_init(int argc, int32_t *argv) ssym = (char *)(long)*(int *)end; esym = (char *)(long)*((int *)end + 1); ekern = esym; - if (((int)ssym - (int)end) < 0 || - ((int)ssym - (int)end) > 0x1000 || + if (((long)ssym - (long)end) < 0 || + ((long)ssym - (long)end) > 0x1000 || ssym[0] != ELFMAG0 || ssym[1] != ELFMAG1 || ssym[2] != ELFMAG2 || ssym[3] != ELFMAG3 ) { ssym = NULL; @@ -401,7 +401,7 @@ mips_init(int argc, int32_t *argv) * Copy down exception vector code. If code is to large * copy down trampolines instead of doing a panic. */ - if (e_tlb_miss - tlb_miss > 0x100) { + if (e_tlb_miss - tlb_miss > 0x80) { bcopy(tlb_miss_tramp, (char *)TLB_MISS_EXC_VEC, e_tlb_miss_tramp - tlb_miss_tramp); bcopy(xtlb_miss_tramp, (char *)XTLB_MISS_EXC_VEC, @@ -506,7 +506,7 @@ dobootopts(int argc, int32_t *argv) /* XXX Should this be done differently, eg env vs. args? */ for (i = 1; i < argc; i++) { - cp = (char *)argv[i]; + cp = (char *)(long)argv[i]; if (cp != NULL && strncmp(cp, "OSLoadOptions=", 14) == 0) { if (strcmp(&cp[14], "auto") == 0) boothowto &= ~(RB_SINGLE|RB_ASKNAME); @@ -701,16 +701,18 @@ setregs(p, pack, stack, retval) } #endif -#if !defined(_LP64) +#if !defined(__LP64__) p->p_md.md_flags |= MDP_O32; +#else + p->p_md.md_flags &= ~MDP_O32; #endif bzero((caddr_t)p->p_md.md_regs, sizeof(struct trap_frame)); p->p_md.md_regs->sp = stack; p->p_md.md_regs->pc = pack->ep_entry & ~3; p->p_md.md_regs->t9 = pack->ep_entry & ~3; /* abicall req */ -#if 0 - p->p_md.md_regs->sr = SR_FR_32|SR_KSU_USER|SR_UX|SR_EXL|SR_INT_ENAB; +#if defined(__LP64__) + p->p_md.md_regs->sr = SR_FR_32|SR_XX|SR_KSU_USER|SR_UX|SR_EXL|SR_INT_ENAB; #else p->p_md.md_regs->sr = SR_KSU_USER|SR_XX|SR_EXL|SR_INT_ENAB; #endif diff --git a/sys/arch/sgi/stand/boot/Makefile b/sys/arch/sgi/stand/boot/Makefile index f0a9a98c5c9..f286c8dc408 100644 --- a/sys/arch/sgi/stand/boot/Makefile +++ b/sys/arch/sgi/stand/boot/Makefile @@ -1,16 +1,16 @@ -# $OpenBSD: Makefile,v 1.1 2004/08/23 14:22:40 pefo Exp $ +# $OpenBSD: Makefile,v 1.2 2004/09/09 22:11:39 pefo Exp $ PROG= boot NOMAN= noman -CFLAGS+= -O2 -mno-abicalls -D_NO_ABICALLS -nostdinc -D__sgi__ \ +CFLAGS+= -O2 -mabi=32 -mno-abicalls -D_NO_ABICALLS -nostdinc -D__sgi__ \ -I${.CURDIR}/../include -I${.CURDIR}/../../../.. \ -I${.CURDIR}/../../../../lib/libsa \ -I${.OBJDIR} CFLAGS+= -D__INTERNAL_LIBSA_CREAD ${STANDALONE} -LDFLAGS+= ${SALDFLAGS} -T ${.CURDIR}/../../conf/ld.script -Ttext 80002000 -e __start +LDFLAGS+= ${SALDFLAGS} -T ${.CURDIR}/../../conf/ld.script -Ttext 80010000 -e __start SRCS= start.S boot.c filesystem.c conf.c diskio.c arcbios.c diff --git a/sys/arch/sgi/stand/boot/boot.c b/sys/arch/sgi/stand/boot/boot.c index b5db5c1ad6f..43987048049 100644 --- a/sys/arch/sgi/stand/boot/boot.c +++ b/sys/arch/sgi/stand/boot/boot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: boot.c,v 1.1 2004/08/23 14:22:40 pefo Exp $ */ +/* $OpenBSD: boot.c,v 1.2 2004/09/09 22:11:39 pefo Exp $ */ /* * Copyright (c) 2004 Opsycon AB, www.opsycon.se. @@ -38,12 +38,17 @@ void gets(char *); ssize_t read(int, void *, size_t); int close(int); -void pmon_write(int, char *, int); -void pmon_synccache(void); -int main(int, char **, char **); -int loadfile(char *); -int loadsymtab(int fd, Elf32_Ehdr *eh, int flags); +int main(int, char **); +void dobootopts(int, char **); +Elf32_Addr loadfile(char *); +Elf32_Addr loadfile32(int, Elf32_Ehdr *); +Elf32_Addr loadfile64(int, Elf64_Ehdr *); +int loadsymtab(int, Elf32_Ehdr *, int); + +enum { AUTO_NONE, AUTO_YES, AUTO_NO, AUTO_DEBUG } bootauto = AUTO_NONE; +char *OSLoadPartition = NULL; +char *OSLoadFilename = NULL; unsigned long tablebase; @@ -72,96 +77,187 @@ gettable (int size, char *name, int flags) /* */ int -main(argc, argv, envp) +main(argc, argv) int argc; char **argv; - char **envp; { - char *cp; - int i, ask, entry; char line[1024]; + char *cp; + int i; + Elf32_Addr entry; - ask = 0; - - cp = Bios_GetEnvironmentVariable("OSLoadPartition"); - if (cp != NULL) { - strncpy(line, cp, sizeof(line)); + dobootopts(argc, argv); + if (OSLoadPartition != NULL) { + strlcpy(line, OSLoadPartition, sizeof(line)); i = strlen(line); - cp = Bios_GetEnvironmentVariable("OSLoadFilename"); - if (cp != NULL) - strncpy(&line[i], cp, sizeof(line) - i -1); - else - ask = 1; + if (OSLoadFilename != NULL) + strlcpy(&line[i], OSLoadFilename, sizeof(line) - i -1); } else - ask = 1; + strlcpy("invalid argument setup", line, sizeof(line)); printf("\nOpenBSD/sgi Arcbios boot\n"); for (entry = 0; entry < argc; entry++) printf("arg %d: %s\n", entry, argv[entry]); - while (1) { - do { - printf("Boot: "); - if (ask) { - gets(line); - } - else - printf("%s\n", line); - } while(ask && line[0] == '\0'); + printf("Boot: %s\n", line); + + entry = loadfile(line); + if (entry != NULL) { + printf("start at 0x%x\n", entry); + ((void (*)())entry)(argc, argv); + } + printf("Boot FAILED!\n "); + Bios_Restart(); +} - entry = loadfile(line); - if (entry != -1) { - ((void (*)())entry)(argc, argv); +/* + * Decode boot options. + */ +void +dobootopts(int argc, char **argv) +{ + char *cp; + int i; + + /* XXX Should this be done differently, eg env vs. args? */ + for (i = 1; i < argc; i++) { + cp = argv[i]; + if (cp == NULL) + continue; + + if (strncmp(cp, "OSLoadOptions=", 14) == 0) { + if (strcmp(&cp[14], "auto") == 0) + bootauto = AUTO_YES; + else if (strcmp(&cp[14], "single") == 0) + bootauto = AUTO_NO; + else if (strcmp(&cp[14], "debug") == 0) + bootauto = AUTO_DEBUG; } - ask = 1; + else if (strncmp(cp, "OSLoadPartition=", 16) == 0) + OSLoadPartition = &cp[16]; + else if (strncmp(cp, "OSLoadFilename=", 15) == 0) + OSLoadFilename = &cp[15]; } - return(0); + /* If "OSLoadOptions=" is missing, see if any arg was given */ + if (bootauto == AUTO_NONE && *argv[1] == '/') + OSLoadFilename = argv[1]; } /* * Open 'filename', read in program and return the entry point or -1 if error. */ -int +Elf32_Addr loadfile(fname) register char *fname; { + union { + Elf32_Ehdr eh32; + Elf64_Ehdr eh64; + } eh; int fd, i; - Elf32_Ehdr eh; - Elf32_Phdr *ph; + Elf32_Addr entry; char *errs = 0; - char buf[4096]; if ((fd = oopen(fname, 0)) < 0) { - errs="open err: %s\n"; - goto err; + printf("can't open file %s\n", fname); + return NULL; + } + + /* read the ELF header and check that it IS an ELF header */ + if (oread(fd, (char *)&eh, sizeof(eh)) != sizeof(eh)) { + printf("error: ELF header read error\n"); + return NULL; + } + if (!IS_ELF(eh.eh32)) { + printf("not an elf file\n"); + return NULL; } - /* read the elf header */ - if(oread(fd, (char *)&eh, sizeof(eh)) != sizeof(eh)) { - goto serr; + /* Determine CLASS */ + if (eh.eh32.e_ident[EI_CLASS] == ELFCLASS32) + entry = loadfile32(fd, (void *)&eh); + else if (eh.eh32.e_ident[EI_CLASS] == ELFCLASS64) + entry = loadfile64(fd, (void *)&eh); + else { + printf("unknown ELF class\n"); + return NULL; } + return entry; +} + +Elf32_Addr +loadfile32(int fd, Elf32_Ehdr *eh) +{ + char buf[4096]; + Elf32_Phdr *ph; + int i; ph = (Elf32_Phdr *) buf; - olseek(fd, eh.e_phoff, 0); - if(oread(fd, (char *)ph, 4096) != 4096) { - goto serr; + olseek(fd, eh->e_phoff, 0); + if (oread(fd, (char *)ph, 4096) != 4096) { + printf("unexpected EOF\n"); + return NULL; } tablebase = 0; + printf("Loading ELF32 file\n"); - for(i = 0; i < eh.e_phnum; i++, ph++) { - if(ph->p_type == PT_LOAD) { + for (i = 0; i < eh->e_phnum; i++, ph++) { + if (ph->p_type == PT_LOAD) { + olseek(fd, ph->p_offset, 0); + printf("0x%x:0x%x, ",(long)ph->p_paddr, (long)ph->p_filesz); + if (oread(fd, (char *)ph->p_paddr, ph->p_filesz) != ph->p_filesz) { + printf("unexpected EOF\n"); + return NULL; + } + if(ph->p_memsz > ph->p_filesz) { + printf("Zero 0x%x:0x%x, ", + (long)(ph->p_paddr + ph->p_filesz), + (long)(ph->p_memsz - ph->p_filesz)); + bzero((void *)(ph->p_paddr + ph->p_filesz), + ph->p_memsz - ph->p_filesz); + } + if((ph->p_paddr + ph->p_memsz) > tablebase) { + tablebase = ph->p_paddr + ph->p_memsz; + } + } + } + memset((void *)tablebase, 0, 4096); + loadsymtab(fd, eh, 0); + return(eh->e_entry); +} + +Elf32_Addr +loadfile64(int fd, Elf64_Ehdr *eh) +{ + char buf[4096]; + Elf64_Phdr *ph; + int i; + + ph = (Elf64_Phdr *) buf; + olseek(fd, eh->e_phoff, 0); + if (oread(fd, (char *)ph, 4096) != 4096) { + printf("unexpected EOF\n"); + return NULL; + } + + tablebase = 0; + printf("Loading ELF64 file\n"); + + for (i = 0; i < eh->e_phnum; i++, ph++) { + if (ph->p_type == PT_LOAD) { olseek(fd, ph->p_offset, 0); printf("0x%x:0x%x, ",ph->p_paddr, ph->p_filesz); - if(oread(fd, (char *)ph->p_paddr, ph->p_filesz) != ph->p_filesz) { - goto serr; + if (oread(fd, (char *)(long)ph->p_paddr, ph->p_filesz) != ph->p_filesz) { + printf("unexpected EOF\n"); + return NULL; } if(ph->p_memsz > ph->p_filesz) { printf("Zero 0x%x:0x%x, ", ph->p_paddr + ph->p_filesz, ph->p_memsz - ph->p_filesz); - bzero((void *)(ph->p_paddr + ph->p_filesz), + bzero((void *)(long)(ph->p_paddr + ph->p_filesz), ph->p_memsz - ph->p_filesz); } if((ph->p_paddr + ph->p_memsz) > tablebase) { @@ -169,16 +265,13 @@ loadfile(fname) } } } - printf("start at 0x%x\n", eh.e_entry); - memset(tablebase, 0, 4096); - loadsymtab(fd, &eh, 0); - return(eh.e_entry); -serr: - errs = "%s sz err\n"; -err: - printf(errs, fname); - return (-1); + memset((void *)tablebase, 0, 4096); +// loadsymtab(fd, &eh, 0); + return(eh->e_entry); } + + + int loadsymtab(int fd, Elf32_Ehdr *eh, int flags) { |