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>


git-svn-id: svn://coreboot.org/openbios/trunk/openbios-devel@711 f158a5a8-5612-0410-a976-696ce0be7e32
This commit is contained in:
Mark Cave-Ayland
2010-03-27 11:30:14 +00:00
committed by Mark Cave-Ayland
parent 1264ad95d2
commit f02d2bde53
12 changed files with 46 additions and 165 deletions

View File

@@ -1,145 +0,0 @@
/* 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"
#define CONFIG_SPARC64_PAGE_SIZE_8KB
#include "arch/common/a.out.h"
#include "libopenbios/sys_info.h"
#include "libopenbios/bindings.h"
#include "libc/diskio.h"
#include "boot.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 ((unsigned long)read_io(fd, (void *)start, ehdr.a_text) != ehdr.a_text) {
printf("Can't read program text segment (size 0x%x)\n", ehdr.a_text);
goto out;
}
if ((unsigned long)read_io(fd, (void *)(start + N_DATADDR(ehdr)), ehdr.a_data) != ehdr.a_data) {
printf("Can't read program data segment (size 0x%x)\n", ehdr.a_data);
goto out;
}
} else {
if ((unsigned long)read_io(fd, (void *)start, size) != size) {
printf("Can't read program (size 0x%lx)\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 !");
retval = 0;
out:
close_io(fd);
return retval;
}

View File

@@ -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;

View File

@@ -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);

View File

@@ -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"/>