Author: mcayland Date: Sat Mar 27 12:30:14 2010 New Revision: 711 URL: http://tracker.coreboot.org/trac/openbios/changeset/711
Log: Move the a.out loader from arch/*/aoutload.c into libopenbios as aout_load.c.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@siriusit.co.uk
Added: trunk/openbios-devel/include/libopenbios/aout_load.h trunk/openbios-devel/libopenbios/aout_load.c Deleted: trunk/openbios-devel/arch/sparc32/aoutload.c trunk/openbios-devel/arch/sparc64/aoutload.c Modified: trunk/openbios-devel/arch/sparc32/boot.c trunk/openbios-devel/arch/sparc32/boot.h trunk/openbios-devel/arch/sparc32/build.xml trunk/openbios-devel/arch/sparc64/boot.c trunk/openbios-devel/arch/sparc64/boot.h trunk/openbios-devel/arch/sparc64/build.xml trunk/openbios-devel/include/arch/sparc32/types.h trunk/openbios-devel/include/arch/sparc64/types.h trunk/openbios-devel/libopenbios/build.xml
Modified: trunk/openbios-devel/arch/sparc32/boot.c ============================================================================== --- trunk/openbios-devel/arch/sparc32/boot.c Sat Mar 27 11:57:03 2010 (r710) +++ trunk/openbios-devel/arch/sparc32/boot.c Sat Mar 27 12:30:14 2010 (r711) @@ -9,6 +9,8 @@ #include "libc/diskio.h" #include "libc/vsprintf.h" #include "libopenbios/sys_info.h" +#include "libopenbios/elf_load.h" +#include "libopenbios/aout_load.h" #include "openprom.h" #include "boot.h"
@@ -22,6 +24,7 @@
static int try_path(const char *path, char *param, const void *romvec) { + void *boot_notes = NULL; ucell valid, address, type, size; int image_retval = 0;
@@ -31,7 +34,7 @@ printk("Trying %s (%s)\n", path, bootpath);
/* ELF Boot loader */ - elf_load(&sys_info, path, param, romvec); + elf_load(&sys_info, path, param, &boot_notes); feval("state-valid @"); valid = POP(); if (valid) @@ -41,7 +44,7 @@ linux_load(&sys_info, path, param);
/* a.out loader */ - aout_load(&sys_info, path, romvec); + aout_load(&sys_info, path); feval("state-valid @"); valid = POP(); if (valid)
Modified: trunk/openbios-devel/arch/sparc32/boot.h ============================================================================== --- trunk/openbios-devel/arch/sparc32/boot.h Sat Mar 27 11:57:03 2010 (r710) +++ trunk/openbios-devel/arch/sparc32/boot.h Sat Mar 27 12:30:14 2010 (r711) @@ -9,13 +9,6 @@ // forthload.c int forth_load(const char *filename);
-// elfload.c -int elf_load(struct sys_info *, const char *filename, const char *cmdline, - const void *romvec); - -// aout_load.c -int aout_load(struct sys_info *info, const char *filename, const void *romvec); - // linux_load.c int linux_load(struct sys_info *info, const char *file, const char *cmdline);
Modified: trunk/openbios-devel/arch/sparc32/build.xml ============================================================================== --- trunk/openbios-devel/arch/sparc32/build.xml Sat Mar 27 11:57:03 2010 (r710) +++ trunk/openbios-devel/arch/sparc32/build.xml Sat Mar 27 12:30:14 2010 (r711) @@ -15,7 +15,6 @@ <object source="udiv.S"/> <object source="linux_load.c"/> <object source="sys_info.c"/> - <object source="aoutload.c"/> <object source="forthload.c"/> <object source="romvec.c"/> <object source="entry.S"/>
Modified: trunk/openbios-devel/arch/sparc64/boot.c ============================================================================== --- trunk/openbios-devel/arch/sparc64/boot.c Sat Mar 27 11:57:03 2010 (r710) +++ trunk/openbios-devel/arch/sparc64/boot.c Sat Mar 27 12:30:14 2010 (r711) @@ -9,6 +9,7 @@ #include "libc/vsprintf.h" #include "libopenbios/sys_info.h" #include "libopenbios/elf_load.h" +#include "libopenbios/aout_load.h" #include "boot.h"
struct sys_info sys_info;
Modified: trunk/openbios-devel/arch/sparc64/boot.h ============================================================================== --- trunk/openbios-devel/arch/sparc64/boot.h Sat Mar 27 11:57:03 2010 (r710) +++ trunk/openbios-devel/arch/sparc64/boot.h Sat Mar 27 12:30:14 2010 (r711) @@ -9,9 +9,6 @@ // forthload.c int forth_load(const char *filename);
-// aout_load.c -int aout_load(struct sys_info *info, const char *filename); - // linux_load.c int linux_load(struct sys_info *info, const char *file, const char *cmdline);
Modified: trunk/openbios-devel/arch/sparc64/build.xml ============================================================================== --- trunk/openbios-devel/arch/sparc64/build.xml Sat Mar 27 11:57:03 2010 (r710) +++ trunk/openbios-devel/arch/sparc64/build.xml Sat Mar 27 12:30:14 2010 (r711) @@ -14,7 +14,6 @@ <object source="switch.S"/> <object source="linux_load.c"/> <object source="sys_info.c"/> - <object source="aoutload.c"/> <object source="forthload.c"/> <object source="fcodeload.c"/> <object source="ofmem_sparc64.c"/>
Modified: trunk/openbios-devel/include/arch/sparc32/types.h ============================================================================== --- trunk/openbios-devel/include/arch/sparc32/types.h Sat Mar 27 11:57:03 2010 (r710) +++ trunk/openbios-devel/include/arch/sparc32/types.h Sat Mar 27 12:30:14 2010 (r711) @@ -41,6 +41,8 @@ #define FMT_ucellX "%08X"
#define FMT_elf "%#x" +#define FMT_sizet "%lx" +#define FMT_aout_ehdr "%lx"
#define bitspercell (sizeof(cell)<<3) #define bitsperdcell (sizeof(dcell)<<3)
Modified: trunk/openbios-devel/include/arch/sparc64/types.h ============================================================================== --- trunk/openbios-devel/include/arch/sparc64/types.h Sat Mar 27 11:57:03 2010 (r710) +++ trunk/openbios-devel/include/arch/sparc64/types.h Sat Mar 27 12:30:14 2010 (r711) @@ -37,8 +37,8 @@ #define FMT_ucellx "%016llx" #define FMT_ucellX "%016llX"
-#define FMT_sizet "%lx" #define FMT_elf "%#llx" +#define FMT_sizet "%lx" #define FMT_aout_ehdr "%x"
#ifdef NEED_FAKE_INT128_T
Added: trunk/openbios-devel/include/libopenbios/aout_load.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/openbios-devel/include/libopenbios/aout_load.h Sat Mar 27 12:30:14 2010 (r711) @@ -0,0 +1,24 @@ +/* + * Creation Date: <2010/03/22 18:00:00 mcayland> + * Time-stamp: <2010/03/22 18:00:00 mcayland> + * + * <aout_load.h> + * + * a.out loader + * + * Copyright (C) 2010 Mark Cave-Ayland (mark.cave-ayland@siriusit.co.uk) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + +#ifndef _H_AOUTLOAD +#define _H_AOUTLOAD + +#include "libopenbios/sys_info.h" + +extern int aout_load(struct sys_info *info, const char *filename); + +#endif /* _H_AOUTLOAD */ \ No newline at end of file
Added: trunk/openbios-devel/libopenbios/aout_load.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/openbios-devel/libopenbios/aout_load.c Sat Mar 27 12:30:14 2010 (r711) @@ -0,0 +1,147 @@ +/* a.out boot loader + * As we have seek, this implementation can be straightforward. + * 2003-07 by SONE Takeshi + */ + +#include "config.h" +#include "kernel/kernel.h" + +#ifdef CONFIG_SPARC64 +#define CONFIG_SPARC64_PAGE_SIZE_8KB +#endif + +#include "arch/common/a.out.h" +#include "libopenbios/sys_info.h" +#include "libopenbios/bindings.h" +#include "libopenbios/aout_load.h" +#include "libc/diskio.h" +#define printf printk +#define debug printk + +#define addr_fixup(addr) ((addr) & 0x00ffffff) + +static char *image_name, *image_version; +static int fd; + +static int check_mem_ranges(struct sys_info *info, + unsigned long start, + unsigned long size) +{ + int j; + unsigned long end; + unsigned long prog_start, prog_end; + struct memrange *mem; + + prog_start = virt_to_phys(&_start); + prog_end = virt_to_phys(&_end); + + end = start + size; + + if (start < prog_start && end > prog_start) + goto conflict; + if (start < prog_end && end > prog_end) + goto conflict; + mem = info->memrange; + for (j = 0; j < info->n_memranges; j++) { + if (mem[j].base <= start && mem[j].base + mem[j].size >= end) + break; + } + if (j >= info->n_memranges) + goto badseg; + return 1; + + conflict: + printf("%s occupies [%#lx-%#lx]\n", program_name, prog_start, prog_end); + + badseg: + printf("A.out file [%#lx-%#lx] doesn't fit into memory\n", start, end - 1); + return 0; +} + +int aout_load(struct sys_info *info, const char *filename) +{ + int retval = -1; + struct exec ehdr; + unsigned long start, size; + unsigned int offset; + + image_name = image_version = NULL; + + /* Mark the saved-program-state as invalid */ + feval("0 state-valid !"); + + fd = open_io(filename); + if (!fd) + goto out; + + for (offset = 0; offset < 16 * 512; offset += 512) { + seek_io(fd, offset); + if (read_io(fd, &ehdr, sizeof ehdr) != sizeof ehdr) { + debug("Can't read a.out header\n"); + retval = LOADER_NOT_SUPPORT; + goto out; + } + if (!N_BADMAG(ehdr)) + break; + } + + if (N_BADMAG(ehdr)) { + debug("Not a bootable a.out image\n"); + retval = LOADER_NOT_SUPPORT; + goto out; + } + + if (ehdr.a_text == 0x30800007) + ehdr.a_text=64*1024; + + if (N_MAGIC(ehdr) == NMAGIC) { + size = addr_fixup(N_DATADDR(ehdr)) + addr_fixup(ehdr.a_data); + } else { + size = addr_fixup(ehdr.a_text) + addr_fixup(ehdr.a_data); + } + + if (size < 7680) + size = 7680; + + + start = 0x4000; // N_TXTADDR(ehdr); + + if (!check_mem_ranges(info, start, size)) + goto out; + + printf("Loading a.out %s...\n", image_name ? image_name : "image"); + + seek_io(fd, offset + N_TXTOFF(ehdr)); + + if (N_MAGIC(ehdr) == NMAGIC) { + if ((size_t)read_io(fd, (void *)start, ehdr.a_text) != ehdr.a_text) { + printf("Can't read program text segment (size 0x" FMT_aout_ehdr ")\n", ehdr.a_text); + goto out; + } + if ((size_t)read_io(fd, (void *)(start + N_DATADDR(ehdr)), ehdr.a_data) != ehdr.a_data) { + printf("Can't read program data segment (size 0x" FMT_aout_ehdr ")\n", ehdr.a_data); + goto out; + } + } else { + if ((size_t)read_io(fd, (void *)start, size) != size) { + printf("Can't read program (size 0x" FMT_sizet ")\n", size); + goto out; + } + } + + debug("Loaded %lu bytes\n", size); + debug("entry point is %#lx\n", start); + + // Initialise saved-program-state + PUSH(addr_fixup(start)); + feval("saved-program-state >sps.entry !"); + PUSH(size); + feval("saved-program-state >sps.file-size !"); + feval("aout saved-program-state >sps.file-type !"); + + feval("-1 state-valid !"); + +out: + close_io(fd); + return retval; +}
Modified: trunk/openbios-devel/libopenbios/build.xml ============================================================================== --- trunk/openbios-devel/libopenbios/build.xml Sat Mar 27 11:57:03 2010 (r710) +++ trunk/openbios-devel/libopenbios/build.xml Sat Mar 27 12:30:14 2010 (r711) @@ -1,6 +1,8 @@ <build>
<library name="openbios" type="static" target="target"> + <object source="aout_load.c" condition="SPARC32"/> + <object source="aout_load.c" condition="SPARC64"/> <object source="bindings.c"/> <object source="client.c"/> <object source="console_common.c"/>