Author: mcayland Date: Fri Mar 26 23:33:50 2010 New Revision: 709 URL: http://tracker.coreboot.org/trac/openbios/changeset/709
Log: Switch the loaders for x86, sparc64 and sparc32 over to use the new saved-program-state in boot() rather than try to execute the device payload directly. This is the first stage in isolating the OF "load" and "go" words, and in preparation for moving the majority of the loaders into libopenbios.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@siriusit.co.uk
Modified: trunk/openbios-devel/arch/sparc32/aoutload.c trunk/openbios-devel/arch/sparc32/boot.c trunk/openbios-devel/arch/sparc32/elfload.c trunk/openbios-devel/arch/sparc32/forthload.c trunk/openbios-devel/arch/sparc64/aoutload.c trunk/openbios-devel/arch/sparc64/boot.c trunk/openbios-devel/arch/sparc64/elfload.c trunk/openbios-devel/arch/sparc64/fcodeload.c trunk/openbios-devel/arch/sparc64/forthload.c trunk/openbios-devel/arch/x86/boot.c trunk/openbios-devel/arch/x86/elfload.c trunk/openbios-devel/arch/x86/forthload.c trunk/openbios-devel/include/arch/sparc32/types.h trunk/openbios-devel/include/arch/x86/types.h
Modified: trunk/openbios-devel/arch/sparc32/aoutload.c ============================================================================== --- trunk/openbios-devel/arch/sparc32/aoutload.c Fri Mar 26 22:17:32 2010 (r708) +++ trunk/openbios-devel/arch/sparc32/aoutload.c Fri Mar 26 23:33:50 2010 (r709) @@ -56,7 +56,6 @@ int aout_load(struct sys_info *info, const char *filename, const void *romvec) { int retval = -1; - int image_retval; struct exec ehdr; unsigned long start, size; unsigned int offset = 512; @@ -134,18 +133,6 @@
feval("-1 state-valid !");
- printf("Jumping to entry point...\n"); - -#if 1 - { - int (*entry)(const void *romvec_ptr, int p2, int p3, int p4, int p5); - - entry = (void *) addr_fixup(start); - image_retval = entry(romvec, 0, 0, 0, 0); - } -#endif - - printf("Image returned with return value %#x\n", image_retval); retval = 0;
out:
Modified: trunk/openbios-devel/arch/sparc32/boot.c ============================================================================== --- trunk/openbios-devel/arch/sparc32/boot.c Fri Mar 26 22:17:32 2010 (r708) +++ trunk/openbios-devel/arch/sparc32/boot.c Fri Mar 26 23:33:50 2010 (r709) @@ -4,7 +4,6 @@ #undef BOOTSTRAP #include "config.h" #include "libopenbios/bindings.h" -#include "libopenbios/elfload.h" #include "arch/common/nvram.h" #include "drivers/drivers.h" #include "libc/diskio.h" @@ -19,25 +18,78 @@ uint32_t qemu_cmdline; uint32_t cmdline_size; char boot_device; +int (*entry)(const void *romvec_ptr, int p2, int p3, int p4, int p5);
-static void try_path(const char *path, char *param, const void *romvec) +static int try_path(const char *path, char *param, const void *romvec) { + ucell valid, address, type, size; + int image_retval = 0; + push_str(path); fword("pathres-resolve-aliases"); bootpath = pop_fstr_copy(); printk("Trying %s (%s)\n", path, bootpath);
- elf_load(&sys_info, path, param, romvec); - linux_load(&sys_info, path, param); - aout_load(&sys_info, path, romvec); + /* ELF Boot loader */ + elf_load(&sys_info, path, param, romvec); + feval("state-valid @"); + valid = POP(); + if (valid) + goto start_image; + + /* Linux loader (not using Forth) */ + linux_load(&sys_info, path, param); + + /* a.out loader */ + aout_load(&sys_info, path, romvec); + feval("state-valid @"); + valid = POP(); + if (valid) + goto start_image; + + return 0; + + +start_image: + /* Get the entry point and the type (see forth/debugging/client.fs) */ + feval("saved-program-state >sps.entry @"); + address = POP(); + feval("saved-program-state >sps.file-type @"); + type = POP(); + feval("saved-program-state >sps.file-size @"); + size = POP(); + + printk("Jumping to entry point " FMT_ucellx " for type " FMT_ucellx "...\n", address, type); + + switch (type) { + case 0x0: + /* Start ELF boot image */ + entry = (void *) address; + image_retval = entry(romvec, 0, 0, 0, 0); + + break; + + case 0x5: + /* Start a.out image */ + entry = (void *) address; + image_retval = entry(romvec, 0, 0, 0, 0); + + break; + } + + printk("Image returned with return value %#x\n", image_retval); + + return -1; }
+ void boot(void) { char *path = pop_fstr_copy(), *param, altpath[256]; const char *oldpath = path; int unit = 0; const void *romvec; + int result;
if(!path) { push_str("boot-device"); @@ -102,8 +154,6 @@ romvec = init_openprom();
if (kernel_size) { - int (*entry)(const void *romvec_ptr, int p2, int p3, int p4, int p5); - printk("[sparc] Kernel already loaded\n"); entry = (void *) kernel_image; entry(romvec, 0, 0, 0, 0); @@ -115,17 +165,19 @@ else printk("without parameters.\n");
- try_path(path, param, romvec); - - push_str(path); - PUSH(':'); - fword("left-split"); - snprintf(altpath, sizeof(altpath), "%s:d", pop_fstr_copy()); - POP(); - POP(); + result = try_path(path, param, romvec); + if (!result) { + push_str(path); + PUSH(':'); + fword("left-split"); + snprintf(altpath, sizeof(altpath), "%s:d", pop_fstr_copy()); + POP(); + POP(); + + try_path(altpath, param, romvec); + }
- try_path(altpath, param, romvec); - printk("Unsupported image format\n"); + printk("Unsupported image format\n");
free(path); }
Modified: trunk/openbios-devel/arch/sparc32/elfload.c ============================================================================== --- trunk/openbios-devel/arch/sparc32/elfload.c Fri Mar 26 22:17:32 2010 (r708) +++ trunk/openbios-devel/arch/sparc32/elfload.c Fri Mar 26 23:33:50 2010 (r709) @@ -312,7 +312,6 @@ unsigned short checksum = 0; Elf_Bhdr *boot_notes = NULL; int retval = -1; - int image_retval; unsigned int offset;
image_name = image_version = NULL; @@ -394,21 +393,6 @@
feval("-1 state-valid !");
- printf("Jumping to entry point...\n"); - -#if 1 - { - int (*entry)(const void *romvec_ptr, int p2, int p3, int p4, int p5); - - entry = (void *) addr_fixup(ehdr.e_entry); - image_retval = entry(romvec, 0, 0, 0, 0); - } -#else - image_retval = start_elf(addr_fixup(ehdr.e_entry), virt_to_phys(boot_notes)); -#endif - - // console_init(); FIXME - printf("Image returned with return value %#x\n", image_retval); retval = 0;
out:
Modified: trunk/openbios-devel/arch/sparc32/forthload.c ============================================================================== --- trunk/openbios-devel/arch/sparc32/forthload.c Fri Mar 26 22:17:32 2010 (r708) +++ trunk/openbios-devel/arch/sparc32/forthload.c Fri Mar 26 23:33:50 2010 (r709) @@ -68,9 +68,6 @@
feval("-1 state-valid !");
- PUSH ( (ucell)forthtext ); - PUSH ( (ucell)forthsize ); - fword("eval2"); retval=0;
out:
Modified: trunk/openbios-devel/arch/sparc64/aoutload.c ============================================================================== --- trunk/openbios-devel/arch/sparc64/aoutload.c Fri Mar 26 22:17:32 2010 (r708) +++ trunk/openbios-devel/arch/sparc64/aoutload.c Fri Mar 26 23:33:50 2010 (r709) @@ -57,7 +57,6 @@ int aout_load(struct sys_info *info, const char *filename) { int retval = -1; - int image_retval; struct exec ehdr; unsigned long start, size; unsigned int offset; @@ -138,14 +137,6 @@
feval("-1 state-valid !");
- printf("Jumping to entry point...\n"); - - { - extern int sparc64_of_client_interface( int *params ); - image_retval = start_client_image(addr_fixup(start), (uint64_t)&sparc64_of_client_interface); - } - - printf("Image returned with return value %#x\n", image_retval); retval = 0;
out:
Modified: trunk/openbios-devel/arch/sparc64/boot.c ============================================================================== --- trunk/openbios-devel/arch/sparc64/boot.c Fri Mar 26 22:17:32 2010 (r708) +++ trunk/openbios-devel/arch/sparc64/boot.c Fri Mar 26 23:33:50 2010 (r709) @@ -4,7 +4,6 @@ #undef BOOTSTRAP #include "config.h" #include "libopenbios/bindings.h" -#include "libopenbios/elfload.h" #include "arch/common/nvram.h" #include "libc/diskio.h" #include "libc/vsprintf.h" @@ -17,16 +16,88 @@ uint64_t qemu_cmdline; uint64_t cmdline_size; char boot_device; +extern int sparc64_of_client_interface( int *params ); + + +static int try_path(const char *path, char *param) +{ + void *boot_notes = NULL; + ucell valid, address, type, size; + int image_retval = 0; + + /* ELF Boot loader */ + elf_load(&sys_info, path, param); + feval("state-valid @"); + valid = POP(); + if (valid) + goto start_image; + + /* Linux loader (not using Forth) */ + linux_load(&sys_info, path, param); + + /* a.out loader */ + aout_load(&sys_info, path); + feval("state-valid @"); + valid = POP(); + if (valid) + goto start_image; + + /* Fcode loader */ + fcode_load(path); + feval("state-valid @"); + valid = POP(); + if (valid) + goto start_image; + + return 0; + + +start_image: + /* Get the entry point and the type (see forth/debugging/client.fs) */ + feval("saved-program-state >sps.entry @"); + address = POP(); + feval("saved-program-state >sps.file-type @"); + type = POP(); + feval("saved-program-state >sps.file-size @"); + size = POP(); + + printk("Jumping to entry point " FMT_ucellx " for type " FMT_ucellx "...\n", address, type); + + switch (type) { + case 0x0: + /* Start ELF boot image */ + image_retval = start_elf(address, (uint64_t)boot_notes); + break; + + case 0x5: + /* Start a.out image */ + image_retval = start_client_image(address, (uint64_t)&sparc64_of_client_interface); + break; + + case 0x10: + /* Start Fcode image */ + printk("Evaluating FCode...\n"); + PUSH(address); + PUSH(1); + fword("byte-load"); + image_retval = 0; + break; + } + + printk("Image returned with return value %#x\n", image_retval); + + return -1; +}
void boot(void) { char *path=pop_fstr_copy(), *param; char altpath[256]; + int result;
if (kernel_size) { void (*entry)(unsigned long p1, unsigned long p2, unsigned long p3, - unsigned long p4, unsigned long p5); - extern int sparc64_of_client_interface( int *params ); + unsigned long p4, unsigned long p5);;
printk("[sparc64] Kernel already loaded\n"); entry = (void *) (unsigned long)kernel_image; @@ -82,24 +153,13 @@ else printk("without parameters.\n");
+ result = try_path(path, param); + if (!result) { + snprintf(altpath, sizeof(altpath), "%s:f", path); + try_path(altpath, param); + }
- if (elf_load(&sys_info, path, param) == LOADER_NOT_SUPPORT) - if (linux_load(&sys_info, path, param) == LOADER_NOT_SUPPORT) - if (aout_load(&sys_info, path) == LOADER_NOT_SUPPORT) - if (fcode_load(path) == LOADER_NOT_SUPPORT) { - - snprintf(altpath, sizeof(altpath), "%s:f", path); - - if (elf_load(&sys_info, altpath, param) - == LOADER_NOT_SUPPORT) - if (linux_load(&sys_info, altpath, param) - == LOADER_NOT_SUPPORT) - if (aout_load(&sys_info, altpath) - == LOADER_NOT_SUPPORT) - if (fcode_load(altpath) - == LOADER_NOT_SUPPORT) - printk("Unsupported image format\n"); - } + printk("Unsupported image format\n");
free(path); }
Modified: trunk/openbios-devel/arch/sparc64/elfload.c ============================================================================== --- trunk/openbios-devel/arch/sparc64/elfload.c Fri Mar 26 22:17:32 2010 (r708) +++ trunk/openbios-devel/arch/sparc64/elfload.c Fri Mar 26 23:33:50 2010 (r709) @@ -311,7 +311,6 @@ unsigned short checksum = 0; Elf_Bhdr *boot_notes = NULL; int retval = -1; - int image_retval; unsigned int offset;
image_name = image_version = NULL; @@ -393,27 +392,6 @@
feval("-1 state-valid !");
- printf("Jumping to entry point...\n"); - -#if 0 - { - extern unsigned int qemu_mem_size; - extern char boot_device; - void *init_openprom(unsigned long memsize, const char *cmdline, char boot_device); - - int (*entry)(const void *romvec, int p2, int p3, int p4, int p5); - const void *romvec; - - romvec = init_openprom(qemu_mem_size, cmdline, boot_device); - entry = (void *) addr_fixup(ehdr.e_entry); - image_retval = entry(romvec, 0, 0, 0, 0); - } -#else - image_retval = start_elf(addr_fixup(ehdr.e_entry), virt_to_phys(boot_notes)); -#endif - - // console_init(); FIXME - printf("Image returned with return value %#x\n", image_retval); retval = 0;
out:
Modified: trunk/openbios-devel/arch/sparc64/fcodeload.c ============================================================================== --- trunk/openbios-devel/arch/sparc64/fcodeload.c Fri Mar 26 22:17:32 2010 (r708) +++ trunk/openbios-devel/arch/sparc64/fcodeload.c Fri Mar 26 23:33:50 2010 (r709) @@ -74,11 +74,7 @@ feval("saved-program-state >sps.file-size !"); feval("fcode saved-program-state >sps.file-type !");
- printf("Evaluating FCode...\n"); - - PUSH(start); - PUSH(1); - fword("byte-load"); + feval("-1 state-valid !");
retval = 0;
Modified: trunk/openbios-devel/arch/sparc64/forthload.c ============================================================================== --- trunk/openbios-devel/arch/sparc64/forthload.c Fri Mar 26 22:17:32 2010 (r708) +++ trunk/openbios-devel/arch/sparc64/forthload.c Fri Mar 26 23:33:50 2010 (r709) @@ -68,9 +68,6 @@
feval("-1 state-valid !");
- PUSH ( (ucell)forthtext ); - PUSH ( (ucell)forthsize ); - fword("eval2"); retval=0;
out:
Modified: trunk/openbios-devel/arch/x86/boot.c ============================================================================== --- trunk/openbios-devel/arch/x86/boot.c Fri Mar 26 22:17:32 2010 (r708) +++ trunk/openbios-devel/arch/x86/boot.c Fri Mar 26 23:33:50 2010 (r709) @@ -9,7 +9,6 @@ #undef BOOTSTRAP #include "config.h" #include "libopenbios/bindings.h" -#include "libopenbios/elfload.h" #include "arch/common/nvram.h" #include "libc/diskio.h" #include "libopenbios/sys_info.h" @@ -17,6 +16,62 @@
struct sys_info sys_info;
+static int try_path(const char *path, char *param) +{ + ucell valid, address, type, size; + int image_retval = 0;; + + /* ELF Boot loader */ + elf_load(&sys_info, path, param); + feval("state-valid @"); + valid = POP(); + if (valid) + goto start_image; + + /* Linux loader (not using Forth) */ + linux_load(&sys_info, path, param); + + /* Forth loader */ + forth_load(&sys_info, path, param); + feval("state-valid @"); + valid = POP(); + if (valid) + goto start_image; + + return 0; + + +start_image: + /* Get the entry point and the type (see forth/debugging/client.fs) */ + feval("saved-program-state >sps.entry @"); + address = POP(); + feval("saved-program-state >sps.file-type @"); + type = POP(); + feval("saved-program-state >sps.file-size @"); + size = POP(); + + printk("Jumping to entry point " FMT_ucellx " for type " FMT_ucellx "...\n", address, type); + + switch (type) { + case 0x0: + /* Start ELF boot image */ + image_retval = start_elf(address, (uint32_t)NULL); + break; + + case 0x11: + /* Start Forth image */ + PUSH(address); + PUSH(size); + fword("eval2"); + image_retval = 0; + break; + } + + printk("Image returned with return value %#x\n", image_retval); + + return -1; +} + void boot(void) { char *path=pop_fstr_copy(), *param; @@ -34,15 +89,9 @@
printk("[x86] Booting file '%s' with parameters '%s'\n",path, param);
- if (elf_load(&sys_info, path, param) != LOADER_NOT_SUPPORT) - goto loaded; - if (linux_load(&sys_info, path, param) != LOADER_NOT_SUPPORT) - goto loaded; - if (forth_load(&sys_info, path, param) != LOADER_NOT_SUPPORT) - goto loaded; + try_path(path, param);
printk("Unsupported image format\n");
-loaded: free(path); }
Modified: trunk/openbios-devel/arch/x86/elfload.c ============================================================================== --- trunk/openbios-devel/arch/x86/elfload.c Fri Mar 26 22:17:32 2010 (r708) +++ trunk/openbios-devel/arch/x86/elfload.c Fri Mar 26 23:33:50 2010 (r709) @@ -313,7 +313,6 @@ unsigned short checksum = 0; Elf_Bhdr *boot_notes = NULL; int retval = -1; - int image_retval;
image_name = image_version = NULL;
@@ -379,7 +378,7 @@ debug("entry point is %#x\n", ehdr.e_entry);
// Initialise saved-program-state - PUSH(ehdr.e_entry); + PUSH(ehdr.e_entry & ADDRMASK); feval("saved-program-state >sps.entry !"); PUSH(file_size); feval("saved-program-state >sps.file-size !"); @@ -387,11 +386,6 @@
feval("-1 state-valid !");
- printk("Jumping to entry point...\n"); - image_retval = start_elf(ehdr.e_entry & ADDRMASK, virt_to_phys(boot_notes)); - - // console_init(); FIXME - printk("Image returned with return value %#x\n", image_retval); retval = 0;
out:
Modified: trunk/openbios-devel/arch/x86/forthload.c ============================================================================== --- trunk/openbios-devel/arch/x86/forthload.c Fri Mar 26 22:17:32 2010 (r708) +++ trunk/openbios-devel/arch/x86/forthload.c Fri Mar 26 23:33:50 2010 (r709) @@ -68,11 +68,6 @@
feval("-1 state-valid !");
- PUSH ( (ucell)forthtext ); - PUSH ( (ucell)forthsize ); - fword("eval2"); - retval=0; - out: //if (forthtext) // free(forthtext);
Modified: trunk/openbios-devel/include/arch/sparc32/types.h ============================================================================== --- trunk/openbios-devel/include/arch/sparc32/types.h Fri Mar 26 22:17:32 2010 (r708) +++ trunk/openbios-devel/include/arch/sparc32/types.h Fri Mar 26 23:33:50 2010 (r709) @@ -35,6 +35,11 @@ typedef long long dcell; typedef unsigned long long ducell;
+#define FMT_cell "%ld" +#define FMT_ucell "%lu" +#define FMT_ucellx "%08x" +#define FMT_ucellX "%08X" + #define bitspercell (sizeof(cell)<<3) #define bitsperdcell (sizeof(dcell)<<3)
Modified: trunk/openbios-devel/include/arch/x86/types.h ============================================================================== --- trunk/openbios-devel/include/arch/x86/types.h Fri Mar 26 22:17:32 2010 (r708) +++ trunk/openbios-devel/include/arch/x86/types.h Fri Mar 26 23:33:50 2010 (r709) @@ -24,6 +24,11 @@ typedef int64_t dcell; typedef uint64_t ducell;
+#define FMT_cell "%ld" +#define FMT_ucell "%lu" +#define FMT_ucellx "%08x" +#define FMT_ucellX "%08X" + #define bitspercell (sizeof(cell)<<3) #define bitsperdcell (sizeof(dcell)<<3)