diff --git a/arch/sparc32/aoutload.c b/arch/sparc32/aoutload.c
deleted file mode 100644
index 71b9a5e..0000000
--- a/arch/sparc32/aoutload.c
+++ /dev/null
@@ -1,141 +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"
-#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, const void *romvec)
-{
- int retval = -1;
- struct exec ehdr;
- unsigned long start, size;
- unsigned int offset = 512;
-
- image_name = image_version = NULL;
-
- /* Mark the saved-program-state as invalid */
- feval("0 state-valid !");
-
- fd = open_io(filename);
- if (!fd)
- goto out;
-
- 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)) {
- 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%lx)\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%lx)\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;
-}
diff --git a/arch/sparc32/boot.c b/arch/sparc32/boot.c
index d7a1b24..8bbf153 100644
--- a/arch/sparc32/boot.c
+++ b/arch/sparc32/boot.c
@@ -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 @@ int (*entry)(const void *romvec_ptr, int p2, int p3, int p4, int p5);
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 @@ static int try_path(const char *path, char *param, const void *romvec)
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 @@ static int try_path(const char *path, char *param, const void *romvec)
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)
diff --git a/arch/sparc32/boot.h b/arch/sparc32/boot.h
index 571e999..646b795 100644
--- a/arch/sparc32/boot.h
+++ b/arch/sparc32/boot.h
@@ -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);
diff --git a/arch/sparc32/build.xml b/arch/sparc32/build.xml
index df2e452..0667a36 100644
--- a/arch/sparc32/build.xml
+++ b/arch/sparc32/build.xml
@@ -15,7 +15,6 @@
-
diff --git a/arch/sparc64/boot.c b/arch/sparc64/boot.c
index 66fc91d..34172ad 100644
--- a/arch/sparc64/boot.c
+++ b/arch/sparc64/boot.c
@@ -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;
diff --git a/arch/sparc64/boot.h b/arch/sparc64/boot.h
index 71ad135..a46dd4e 100644
--- a/arch/sparc64/boot.h
+++ b/arch/sparc64/boot.h
@@ -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);
diff --git a/arch/sparc64/build.xml b/arch/sparc64/build.xml
index 8d348eb..040718b 100644
--- a/arch/sparc64/build.xml
+++ b/arch/sparc64/build.xml
@@ -14,7 +14,6 @@
-
diff --git a/include/arch/sparc32/types.h b/include/arch/sparc32/types.h
index c6e4d01..3f89da4 100644
--- a/include/arch/sparc32/types.h
+++ b/include/arch/sparc32/types.h
@@ -41,6 +41,8 @@ typedef unsigned long long ducell;
#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)
diff --git a/include/arch/sparc64/types.h b/include/arch/sparc64/types.h
index 4099865..67fea5c 100644
--- a/include/arch/sparc64/types.h
+++ b/include/arch/sparc64/types.h
@@ -37,8 +37,8 @@ typedef unsigned long long ucell;
#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
diff --git a/include/libopenbios/aout_load.h b/include/libopenbios/aout_load.h
new file mode 100644
index 0000000..7b85601
--- /dev/null
+++ b/include/libopenbios/aout_load.h
@@ -0,0 +1,24 @@
+/*
+ * Creation Date: <2010/03/22 18:00:00 mcayland>
+ * Time-stamp: <2010/03/22 18:00:00 mcayland>
+ *
+ *
+ *
+ * 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
diff --git a/arch/sparc64/aoutload.c b/libopenbios/aout_load.c
similarity index 84%
rename from arch/sparc64/aoutload.c
rename to libopenbios/aout_load.c
index 27f1f56..6d9cd94 100644
--- a/arch/sparc64/aoutload.c
+++ b/libopenbios/aout_load.c
@@ -5,12 +5,16 @@
#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"
-#include "boot.h"
#define printf printk
#define debug printk
@@ -110,17 +114,17 @@ int aout_load(struct sys_info *info, const char *filename)
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);
+ 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 ((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);
+ 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 ((unsigned long)read_io(fd, (void *)start, size) != size) {
- printf("Can't read program (size 0x%lx)\n", size);
+ if ((size_t)read_io(fd, (void *)start, size) != size) {
+ printf("Can't read program (size 0x" FMT_sizet ")\n", size);
goto out;
}
}
@@ -137,8 +141,6 @@ int aout_load(struct sys_info *info, const char *filename)
feval("-1 state-valid !");
- retval = 0;
-
out:
close_io(fd);
return retval;
diff --git a/libopenbios/build.xml b/libopenbios/build.xml
index 3ca87c0..055aea3 100644
--- a/libopenbios/build.xml
+++ b/libopenbios/build.xml
@@ -1,6 +1,8 @@
+
+