From 8a6d445d38f8aeeb6ab086a76bf63b28d9d8e774 Mon Sep 17 00:00:00 2001 From: Mark Cave-Ayland Date: Fri, 26 Mar 2010 21:17:32 +0000 Subject: [PATCH] Introduce the concept of the OF saved-program-state structure and modify all of the loaders (except PPC) to make use of it. Signed-off-by: Mark Cave-Ayland git-svn-id: svn://coreboot.org/openbios/trunk/openbios-devel@708 f158a5a8-5612-0410-a976-696ce0be7e32 --- arch/amd64/elfload.c | 13 +++++++++++++ arch/sparc32/aoutload.c | 15 ++++++++++++++- arch/sparc32/elfload.c | 27 ++++++++++++++++++++------- arch/sparc32/forthload.c | 14 ++++++++++++++ arch/sparc64/aoutload.c | 15 ++++++++++++++- arch/sparc64/elfload.c | 27 ++++++++++++++++++++------- arch/sparc64/fcodeload.c | 12 +++++++++++- arch/sparc64/forthload.c | 12 ++++++++++++ arch/x86/elfload.c | 27 ++++++++++++++++++++------- arch/x86/forthload.c | 14 ++++++++++++++ forth/debugging/client.fs | 18 ++++++++++++++---- 11 files changed, 166 insertions(+), 28 deletions(-) diff --git a/arch/amd64/elfload.c b/arch/amd64/elfload.c index eca2a34..02694ce 100644 --- a/arch/amd64/elfload.c +++ b/arch/amd64/elfload.c @@ -311,6 +311,9 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline) image_name = image_version = 0; + /* Mark the saved-program-state as invalid */ + feval("0 state-valid !"); + if (!file_open(filename)) goto out; @@ -368,6 +371,16 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline) debug("entry point is %#x\n", ehdr.e_entry); printf("Jumping to entry point...\n"); + + // Initialise saved-program-state + PUSH(ehdr.e_entry); + feval("saved-program-state >sps.entry !"); + PUSH(file_size); + feval("saved-program-state >sps.file-size !"); + feval("elf-boot saved-program-state >sps.file-type !"); + + feval("-1 state-valid !"); + image_retval = start_elf(ehdr.e_entry, virt_to_phys(boot_notes)); // console_init(); FIXME diff --git a/arch/sparc32/aoutload.c b/arch/sparc32/aoutload.c index b9633ee..ddfe4ae 100644 --- a/arch/sparc32/aoutload.c +++ b/arch/sparc32/aoutload.c @@ -7,6 +7,7 @@ #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 @@ -62,6 +63,9 @@ int aout_load(struct sys_info *info, const char *filename, const void *romvec) image_name = image_version = NULL; + /* Mark the saved-program-state as invalid */ + feval("0 state-valid !"); + fd = open_io(filename); if (!fd) goto out; @@ -119,8 +123,17 @@ int aout_load(struct sys_info *info, const char *filename, const void *romvec) } 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 !"); + printf("Jumping to entry point...\n"); #if 1 diff --git a/arch/sparc32/elfload.c b/arch/sparc32/elfload.c index 5164245..43858bd 100644 --- a/arch/sparc32/elfload.c +++ b/arch/sparc32/elfload.c @@ -10,6 +10,7 @@ #include "arch/common/elf_boot.h" #include "libopenbios/sys_info.h" #include "libopenbios/ipchecksum.h" +#include "libopenbios/bindings.h" #include "libc/diskio.h" #include "boot.h" #define printf printk @@ -135,13 +136,12 @@ out: static int load_segments(Elf_phdr *phdr, int phnum, unsigned long checksum_offset, - unsigned int offset) + unsigned int offset, unsigned long *bytes) { - unsigned long bytes; //unsigned int start_time, time; int i; - bytes = 0; + *bytes = 0; // start_time = currticks(); for (i = 0; i < phnum; i++) { if (phdr[i].p_type != PT_LOAD) @@ -155,7 +155,7 @@ static int load_segments(Elf_phdr *phdr, int phnum, printf("Can't read program segment %d\n", i); return 0; } - bytes += phdr[i].p_filesz; + *bytes += phdr[i].p_filesz; debug("clearing... "); memset(phys_to_virt(addr_fixup(phdr[i].p_paddr) + phdr[i].p_filesz), 0, phdr[i].p_memsz - phdr[i].p_filesz); @@ -171,7 +171,7 @@ static int load_segments(Elf_phdr *phdr, int phnum, // time = currticks() - start_time; //debug("Loaded %lu bytes in %ums (%luKB/s)\n", bytes, time, // time? bytes/time : 0); - debug("Loaded %lu bytes \n", bytes); + debug("Loaded %lu bytes \n", *bytes); return 1; } @@ -308,7 +308,7 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline, Elf_ehdr ehdr; Elf_phdr *phdr = NULL; unsigned long phdr_size; - unsigned long checksum_offset; + unsigned long checksum_offset, file_size; unsigned short checksum = 0; Elf_Bhdr *boot_notes = NULL; int retval = -1; @@ -317,6 +317,9 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline, image_name = image_version = NULL; + /* Mark the saved-program-state as invalid */ + feval("0 state-valid !"); + fd = open_io(filename); if (!fd) goto out; @@ -368,7 +371,7 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline, printf(" version %s", image_version); printf("...\n"); - if (!load_segments(phdr, ehdr.e_phnum, checksum_offset, offset)) + if (!load_segments(phdr, ehdr.e_phnum, checksum_offset, offset, &file_size)) goto out; if (checksum_offset) { @@ -381,6 +384,16 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline, //debug("current time: %lu\n", currticks()); debug("entry point is %#x\n", addr_fixup(ehdr.e_entry)); + + // Initialise saved-program-state + PUSH(addr_fixup(ehdr.e_entry)); + feval("saved-program-state >sps.entry !"); + PUSH(file_size); + feval("saved-program-state >sps.file-size !"); + feval("elf-boot saved-program-state >sps.file-type !"); + + feval("-1 state-valid !"); + printf("Jumping to entry point...\n"); #if 1 diff --git a/arch/sparc32/forthload.c b/arch/sparc32/forthload.c index da60849..8abb21c 100644 --- a/arch/sparc32/forthload.c +++ b/arch/sparc32/forthload.c @@ -24,6 +24,9 @@ int forth_load(const char *filename) unsigned long forthsize; int retval = -1; + /* Mark the saved-program-state as invalid */ + feval("0 state-valid !"); + fd = open_io(filename); if (!fd) goto out; @@ -54,6 +57,17 @@ int forth_load(const char *filename) forthtext[forthsize]=0; printk("ok\n"); + close_io(fd); + + // Initialise saved-program-state + PUSH((ucell)forthtext); + feval("saved-program-state >sps.entry !"); + PUSH((ucell)forthsize); + feval("saved-program-state >sps.file-size !"); + feval("forth saved-program-state >sps.file-type !"); + + feval("-1 state-valid !"); + PUSH ( (ucell)forthtext ); PUSH ( (ucell)forthsize ); fword("eval2"); diff --git a/arch/sparc64/aoutload.c b/arch/sparc64/aoutload.c index f239e33..7d706fe 100644 --- a/arch/sparc64/aoutload.c +++ b/arch/sparc64/aoutload.c @@ -8,6 +8,7 @@ #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 @@ -63,6 +64,9 @@ int aout_load(struct sys_info *info, const char *filename) image_name = image_version = NULL; + /* Mark the saved-program-state as invalid */ + feval("0 state-valid !"); + fd = open_io(filename); if (!fd) goto out; @@ -123,8 +127,17 @@ int aout_load(struct sys_info *info, const char *filename) } 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 !"); + printf("Jumping to entry point...\n"); { diff --git a/arch/sparc64/elfload.c b/arch/sparc64/elfload.c index d6f0f8c..2c4b73a 100644 --- a/arch/sparc64/elfload.c +++ b/arch/sparc64/elfload.c @@ -10,6 +10,7 @@ #include "arch/common/elf_boot.h" #include "libopenbios/sys_info.h" #include "libopenbios/ipchecksum.h" +#include "libopenbios/bindings.h" #include "libc/diskio.h" #include "boot.h" #define printf printk @@ -135,13 +136,12 @@ out: static int load_segments(Elf_phdr *phdr, int phnum, unsigned long checksum_offset, - unsigned int offset) + unsigned int offset, unsigned long *bytes) { - unsigned long bytes; //unsigned int start_time, time; int i; - bytes = 0; + *bytes = 0; // start_time = currticks(); for (i = 0; i < phnum; i++) { if (phdr[i].p_type != PT_LOAD) @@ -155,7 +155,7 @@ static int load_segments(Elf_phdr *phdr, int phnum, printf("Can't read program segment %d\n", i); return 0; } - bytes += phdr[i].p_filesz; + *bytes += phdr[i].p_filesz; debug("clearing... "); memset(phys_to_virt(addr_fixup(phdr[i].p_paddr) + phdr[i].p_filesz), 0, phdr[i].p_memsz - phdr[i].p_filesz); @@ -171,7 +171,7 @@ static int load_segments(Elf_phdr *phdr, int phnum, // time = currticks() - start_time; //debug("Loaded %lu bytes in %ums (%luKB/s)\n", bytes, time, // time? bytes/time : 0); - debug("Loaded %lu bytes \n", bytes); + debug("Loaded %lu bytes \n", *bytes); return 1; } @@ -307,7 +307,7 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline) Elf_ehdr ehdr; Elf_phdr *phdr = NULL; unsigned long phdr_size; - unsigned long checksum_offset; + unsigned long checksum_offset, file_size; unsigned short checksum = 0; Elf_Bhdr *boot_notes = NULL; int retval = -1; @@ -316,6 +316,9 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline) image_name = image_version = NULL; + /* Mark the saved-program-state as invalid */ + feval("0 state-valid !"); + fd = open_io(filename); if (!fd) goto out; @@ -367,7 +370,7 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline) printf(" version %s", image_version); printf("...\n"); - if (!load_segments(phdr, ehdr.e_phnum, checksum_offset, offset)) + if (!load_segments(phdr, ehdr.e_phnum, checksum_offset, offset, &file_size)) goto out; if (checksum_offset) { @@ -380,6 +383,16 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline) //debug("current time: %lu\n", currticks()); debug("entry point is %#llx\n", addr_fixup(ehdr.e_entry)); + + // Initialise saved-program-state + PUSH(addr_fixup(ehdr.e_entry)); + feval("saved-program-state >sps.entry !"); + PUSH(file_size); + feval("saved-program-state >sps.file-size !"); + feval("elf-boot saved-program-state >sps.file-type !"); + + feval("-1 state-valid !"); + printf("Jumping to entry point...\n"); #if 0 diff --git a/arch/sparc64/fcodeload.c b/arch/sparc64/fcodeload.c index af589af..4207b17 100644 --- a/arch/sparc64/fcodeload.c +++ b/arch/sparc64/fcodeload.c @@ -20,6 +20,9 @@ int fcode_load(const char *filename) unsigned long start, size; unsigned int offset; + /* Mark the saved-program-state as invalid */ + feval("0 state-valid !"); + fd = open_io(filename); if (!fd) goto out; @@ -62,8 +65,15 @@ int fcode_load(const char *filename) } debug("Loaded %lu bytes\n", size); - debug("entry point is %#lx\n", start); + + // Initialise saved-program-state + PUSH(start); + feval("saved-program-state >sps.entry !"); + PUSH(size); + feval("saved-program-state >sps.file-size !"); + feval("fcode saved-program-state >sps.file-type !"); + printf("Evaluating FCode...\n"); PUSH(start); diff --git a/arch/sparc64/forthload.c b/arch/sparc64/forthload.c index 9b43d82..8abb21c 100644 --- a/arch/sparc64/forthload.c +++ b/arch/sparc64/forthload.c @@ -24,6 +24,9 @@ int forth_load(const char *filename) unsigned long forthsize; int retval = -1; + /* Mark the saved-program-state as invalid */ + feval("0 state-valid !"); + fd = open_io(filename); if (!fd) goto out; @@ -56,6 +59,15 @@ int forth_load(const char *filename) close_io(fd); + // Initialise saved-program-state + PUSH((ucell)forthtext); + feval("saved-program-state >sps.entry !"); + PUSH((ucell)forthsize); + feval("saved-program-state >sps.file-size !"); + feval("forth saved-program-state >sps.file-type !"); + + feval("-1 state-valid !"); + PUSH ( (ucell)forthtext ); PUSH ( (ucell)forthsize ); fword("eval2"); diff --git a/arch/x86/elfload.c b/arch/x86/elfload.c index 9dcd29b..a3a7ca7 100644 --- a/arch/x86/elfload.c +++ b/arch/x86/elfload.c @@ -10,6 +10,7 @@ #include "arch/common/elf_boot.h" #include "libopenbios/sys_info.h" #include "libopenbios/ipchecksum.h" +#include "libopenbios/bindings.h" #include "libc/diskio.h" #include "boot.h" @@ -137,13 +138,12 @@ out: } static int load_segments(Elf_phdr *phdr, int phnum, - unsigned long checksum_offset) + unsigned long checksum_offset, unsigned long *bytes) { - unsigned long bytes; //unsigned int start_time, time; int i; - bytes = 0; + *bytes = 0; // start_time = currticks(); for (i = 0; i < phnum; i++) { if (phdr[i].p_type != PT_LOAD) @@ -157,7 +157,7 @@ static int load_segments(Elf_phdr *phdr, int phnum, printk("Can't read program segment %d\n", i); return 0; } - bytes += phdr[i].p_filesz; + *bytes += phdr[i].p_filesz; debug("clearing... "); memset(phys_to_virt(phdr[i].p_paddr + phdr[i].p_filesz), 0, phdr[i].p_memsz - phdr[i].p_filesz); @@ -173,7 +173,7 @@ static int load_segments(Elf_phdr *phdr, int phnum, // time = currticks() - start_time; //debug("Loaded %lu bytes in %ums (%luKB/s)\n", bytes, time, // time? bytes/time : 0); - debug("Loaded %lu bytes \n", bytes); + debug("Loaded %lu bytes \n", *bytes); return 1; } @@ -309,7 +309,7 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline) Elf_ehdr ehdr; Elf_phdr *phdr = NULL; unsigned long phdr_size; - unsigned long checksum_offset; + unsigned long checksum_offset, file_size; unsigned short checksum = 0; Elf_Bhdr *boot_notes = NULL; int retval = -1; @@ -317,6 +317,9 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline) image_name = image_version = NULL; + /* Mark the saved-program-state as invalid */ + feval("0 state-valid !"); + fd = open_io(filename); if (!fd) goto out; @@ -361,7 +364,7 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline) printk(" version %s", image_version); printk("...\n"); - if (!load_segments(phdr, ehdr.e_phnum, checksum_offset)) + if (!load_segments(phdr, ehdr.e_phnum, checksum_offset, &file_size)) goto out; if (checksum_offset) { @@ -374,6 +377,16 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline) //debug("current time: %lu\n", currticks()); debug("entry point is %#x\n", ehdr.e_entry); + + // Initialise saved-program-state + PUSH(ehdr.e_entry); + feval("saved-program-state >sps.entry !"); + PUSH(file_size); + feval("saved-program-state >sps.file-size !"); + feval("elf-boot saved-program-state >sps.file-type !"); + + feval("-1 state-valid !"); + printk("Jumping to entry point...\n"); image_retval = start_elf(ehdr.e_entry & ADDRMASK, virt_to_phys(boot_notes)); diff --git a/arch/x86/forthload.c b/arch/x86/forthload.c index a50b8d2..0631840 100644 --- a/arch/x86/forthload.c +++ b/arch/x86/forthload.c @@ -24,6 +24,9 @@ int forth_load(struct sys_info *info, const char *filename, const char *cmdline) unsigned long forthsize; int retval = -1; + /* Mark the saved-program-state as invalid */ + feval("0 state-valid !"); + fd = open_io(filename); if (!fd) goto out; @@ -54,6 +57,17 @@ int forth_load(struct sys_info *info, const char *filename, const char *cmdline) forthtext[forthsize]=0; printk("ok\n"); + close_io(fd); + + // Initialise saved-program-state + PUSH((ucell)forthtext); + feval("saved-program-state >sps.entry !"); + PUSH((ucell)forthsize); + feval("saved-program-state >sps.file-size !"); + feval("forth saved-program-state >sps.file-type !"); + + feval("-1 state-valid !"); + PUSH ( (ucell)forthtext ); PUSH ( (ucell)forthsize ); fword("eval2"); diff --git a/forth/debugging/client.fs b/forth/debugging/client.fs index 2e08e7d..8ab0d20 100644 --- a/forth/debugging/client.fs +++ b/forth/debugging/client.fs @@ -16,6 +16,12 @@ \ 7.6.2 Program download and execute +struct ( saved-program-state ) + /n field >sps.entry + /n field >sps.file-size + /n field >sps.file-type +constant saved-program-state.size +create saved-program-state saved-program-state.size allot variable state-valid 0 state-valid ! @@ -28,10 +34,14 @@ variable file-size variable file-type -0 constant elf -1 constant bootinfo -2 constant xcoff -3 constant pe +0 constant elf-boot +1 constant elf +2 constant bootinfo +3 constant xcoff +4 constant pe +5 constant aout +10 constant fcode +11 constant forth \ Array indexes and values for e_type