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 <mark.cave-ayland@siriusit.co.uk>


git-svn-id: svn://coreboot.org/openbios/trunk/openbios-devel@708 f158a5a8-5612-0410-a976-696ce0be7e32
This commit is contained in:
Mark Cave-Ayland
2010-03-26 21:17:32 +00:00
committed by Mark Cave-Ayland
parent d66540542d
commit 8a6d445d38
11 changed files with 166 additions and 28 deletions

View File

@@ -311,6 +311,9 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline)
image_name = image_version = 0; image_name = image_version = 0;
/* Mark the saved-program-state as invalid */
feval("0 state-valid !");
if (!file_open(filename)) if (!file_open(filename))
goto out; 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); debug("entry point is %#x\n", ehdr.e_entry);
printf("Jumping to entry point...\n"); 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)); image_retval = start_elf(ehdr.e_entry, virt_to_phys(boot_notes));
// console_init(); FIXME // console_init(); FIXME

View File

@@ -7,6 +7,7 @@
#include "kernel/kernel.h" #include "kernel/kernel.h"
#include "arch/common/a.out.h" #include "arch/common/a.out.h"
#include "libopenbios/sys_info.h" #include "libopenbios/sys_info.h"
#include "libopenbios/bindings.h"
#include "libc/diskio.h" #include "libc/diskio.h"
#include "boot.h" #include "boot.h"
#define printf printk #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; image_name = image_version = NULL;
/* Mark the saved-program-state as invalid */
feval("0 state-valid !");
fd = open_io(filename); fd = open_io(filename);
if (!fd) if (!fd)
goto out; 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("Loaded %lu bytes\n", size);
debug("entry point is %#lx\n", start); 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"); printf("Jumping to entry point...\n");
#if 1 #if 1

View File

@@ -10,6 +10,7 @@
#include "arch/common/elf_boot.h" #include "arch/common/elf_boot.h"
#include "libopenbios/sys_info.h" #include "libopenbios/sys_info.h"
#include "libopenbios/ipchecksum.h" #include "libopenbios/ipchecksum.h"
#include "libopenbios/bindings.h"
#include "libc/diskio.h" #include "libc/diskio.h"
#include "boot.h" #include "boot.h"
#define printf printk #define printf printk
@@ -135,13 +136,12 @@ out:
static int load_segments(Elf_phdr *phdr, int phnum, static int load_segments(Elf_phdr *phdr, int phnum,
unsigned long checksum_offset, unsigned long checksum_offset,
unsigned int offset) unsigned int offset, unsigned long *bytes)
{ {
unsigned long bytes;
//unsigned int start_time, time; //unsigned int start_time, time;
int i; int i;
bytes = 0; *bytes = 0;
// start_time = currticks(); // start_time = currticks();
for (i = 0; i < phnum; i++) { for (i = 0; i < phnum; i++) {
if (phdr[i].p_type != PT_LOAD) 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); printf("Can't read program segment %d\n", i);
return 0; return 0;
} }
bytes += phdr[i].p_filesz; *bytes += phdr[i].p_filesz;
debug("clearing... "); debug("clearing... ");
memset(phys_to_virt(addr_fixup(phdr[i].p_paddr) + phdr[i].p_filesz), 0, memset(phys_to_virt(addr_fixup(phdr[i].p_paddr) + phdr[i].p_filesz), 0,
phdr[i].p_memsz - phdr[i].p_filesz); 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; // time = currticks() - start_time;
//debug("Loaded %lu bytes in %ums (%luKB/s)\n", bytes, time, //debug("Loaded %lu bytes in %ums (%luKB/s)\n", bytes, time,
// time? bytes/time : 0); // time? bytes/time : 0);
debug("Loaded %lu bytes \n", bytes); debug("Loaded %lu bytes \n", *bytes);
return 1; return 1;
} }
@@ -308,7 +308,7 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline,
Elf_ehdr ehdr; Elf_ehdr ehdr;
Elf_phdr *phdr = NULL; Elf_phdr *phdr = NULL;
unsigned long phdr_size; unsigned long phdr_size;
unsigned long checksum_offset; unsigned long checksum_offset, file_size;
unsigned short checksum = 0; unsigned short checksum = 0;
Elf_Bhdr *boot_notes = NULL; Elf_Bhdr *boot_notes = NULL;
int retval = -1; 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; image_name = image_version = NULL;
/* Mark the saved-program-state as invalid */
feval("0 state-valid !");
fd = open_io(filename); fd = open_io(filename);
if (!fd) if (!fd)
goto out; 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(" version %s", image_version);
printf("...\n"); 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; goto out;
if (checksum_offset) { 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("current time: %lu\n", currticks());
debug("entry point is %#x\n", addr_fixup(ehdr.e_entry)); 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"); printf("Jumping to entry point...\n");
#if 1 #if 1

View File

@@ -24,6 +24,9 @@ int forth_load(const char *filename)
unsigned long forthsize; unsigned long forthsize;
int retval = -1; int retval = -1;
/* Mark the saved-program-state as invalid */
feval("0 state-valid !");
fd = open_io(filename); fd = open_io(filename);
if (!fd) if (!fd)
goto out; goto out;
@@ -54,6 +57,17 @@ int forth_load(const char *filename)
forthtext[forthsize]=0; forthtext[forthsize]=0;
printk("ok\n"); 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)forthtext );
PUSH ( (ucell)forthsize ); PUSH ( (ucell)forthsize );
fword("eval2"); fword("eval2");

View File

@@ -8,6 +8,7 @@
#define CONFIG_SPARC64_PAGE_SIZE_8KB #define CONFIG_SPARC64_PAGE_SIZE_8KB
#include "arch/common/a.out.h" #include "arch/common/a.out.h"
#include "libopenbios/sys_info.h" #include "libopenbios/sys_info.h"
#include "libopenbios/bindings.h"
#include "libc/diskio.h" #include "libc/diskio.h"
#include "boot.h" #include "boot.h"
#define printf printk #define printf printk
@@ -63,6 +64,9 @@ int aout_load(struct sys_info *info, const char *filename)
image_name = image_version = NULL; image_name = image_version = NULL;
/* Mark the saved-program-state as invalid */
feval("0 state-valid !");
fd = open_io(filename); fd = open_io(filename);
if (!fd) if (!fd)
goto out; goto out;
@@ -123,8 +127,17 @@ int aout_load(struct sys_info *info, const char *filename)
} }
debug("Loaded %lu bytes\n", size); debug("Loaded %lu bytes\n", size);
debug("entry point is %#lx\n", start); 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"); printf("Jumping to entry point...\n");
{ {

View File

@@ -10,6 +10,7 @@
#include "arch/common/elf_boot.h" #include "arch/common/elf_boot.h"
#include "libopenbios/sys_info.h" #include "libopenbios/sys_info.h"
#include "libopenbios/ipchecksum.h" #include "libopenbios/ipchecksum.h"
#include "libopenbios/bindings.h"
#include "libc/diskio.h" #include "libc/diskio.h"
#include "boot.h" #include "boot.h"
#define printf printk #define printf printk
@@ -135,13 +136,12 @@ out:
static int load_segments(Elf_phdr *phdr, int phnum, static int load_segments(Elf_phdr *phdr, int phnum,
unsigned long checksum_offset, unsigned long checksum_offset,
unsigned int offset) unsigned int offset, unsigned long *bytes)
{ {
unsigned long bytes;
//unsigned int start_time, time; //unsigned int start_time, time;
int i; int i;
bytes = 0; *bytes = 0;
// start_time = currticks(); // start_time = currticks();
for (i = 0; i < phnum; i++) { for (i = 0; i < phnum; i++) {
if (phdr[i].p_type != PT_LOAD) 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); printf("Can't read program segment %d\n", i);
return 0; return 0;
} }
bytes += phdr[i].p_filesz; *bytes += phdr[i].p_filesz;
debug("clearing... "); debug("clearing... ");
memset(phys_to_virt(addr_fixup(phdr[i].p_paddr) + phdr[i].p_filesz), 0, memset(phys_to_virt(addr_fixup(phdr[i].p_paddr) + phdr[i].p_filesz), 0,
phdr[i].p_memsz - phdr[i].p_filesz); 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; // time = currticks() - start_time;
//debug("Loaded %lu bytes in %ums (%luKB/s)\n", bytes, time, //debug("Loaded %lu bytes in %ums (%luKB/s)\n", bytes, time,
// time? bytes/time : 0); // time? bytes/time : 0);
debug("Loaded %lu bytes \n", bytes); debug("Loaded %lu bytes \n", *bytes);
return 1; return 1;
} }
@@ -307,7 +307,7 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline)
Elf_ehdr ehdr; Elf_ehdr ehdr;
Elf_phdr *phdr = NULL; Elf_phdr *phdr = NULL;
unsigned long phdr_size; unsigned long phdr_size;
unsigned long checksum_offset; unsigned long checksum_offset, file_size;
unsigned short checksum = 0; unsigned short checksum = 0;
Elf_Bhdr *boot_notes = NULL; Elf_Bhdr *boot_notes = NULL;
int retval = -1; 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; image_name = image_version = NULL;
/* Mark the saved-program-state as invalid */
feval("0 state-valid !");
fd = open_io(filename); fd = open_io(filename);
if (!fd) if (!fd)
goto out; 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(" version %s", image_version);
printf("...\n"); 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; goto out;
if (checksum_offset) { 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("current time: %lu\n", currticks());
debug("entry point is %#llx\n", addr_fixup(ehdr.e_entry)); 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"); printf("Jumping to entry point...\n");
#if 0 #if 0

View File

@@ -20,6 +20,9 @@ int fcode_load(const char *filename)
unsigned long start, size; unsigned long start, size;
unsigned int offset; unsigned int offset;
/* Mark the saved-program-state as invalid */
feval("0 state-valid !");
fd = open_io(filename); fd = open_io(filename);
if (!fd) if (!fd)
goto out; goto out;
@@ -62,8 +65,15 @@ int fcode_load(const char *filename)
} }
debug("Loaded %lu bytes\n", size); debug("Loaded %lu bytes\n", size);
debug("entry point is %#lx\n", start); 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"); printf("Evaluating FCode...\n");
PUSH(start); PUSH(start);

View File

@@ -24,6 +24,9 @@ int forth_load(const char *filename)
unsigned long forthsize; unsigned long forthsize;
int retval = -1; int retval = -1;
/* Mark the saved-program-state as invalid */
feval("0 state-valid !");
fd = open_io(filename); fd = open_io(filename);
if (!fd) if (!fd)
goto out; goto out;
@@ -56,6 +59,15 @@ int forth_load(const char *filename)
close_io(fd); 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)forthtext );
PUSH ( (ucell)forthsize ); PUSH ( (ucell)forthsize );
fword("eval2"); fword("eval2");

View File

@@ -10,6 +10,7 @@
#include "arch/common/elf_boot.h" #include "arch/common/elf_boot.h"
#include "libopenbios/sys_info.h" #include "libopenbios/sys_info.h"
#include "libopenbios/ipchecksum.h" #include "libopenbios/ipchecksum.h"
#include "libopenbios/bindings.h"
#include "libc/diskio.h" #include "libc/diskio.h"
#include "boot.h" #include "boot.h"
@@ -137,13 +138,12 @@ out:
} }
static int load_segments(Elf_phdr *phdr, int phnum, 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; //unsigned int start_time, time;
int i; int i;
bytes = 0; *bytes = 0;
// start_time = currticks(); // start_time = currticks();
for (i = 0; i < phnum; i++) { for (i = 0; i < phnum; i++) {
if (phdr[i].p_type != PT_LOAD) 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); printk("Can't read program segment %d\n", i);
return 0; return 0;
} }
bytes += phdr[i].p_filesz; *bytes += phdr[i].p_filesz;
debug("clearing... "); debug("clearing... ");
memset(phys_to_virt(phdr[i].p_paddr + phdr[i].p_filesz), 0, memset(phys_to_virt(phdr[i].p_paddr + phdr[i].p_filesz), 0,
phdr[i].p_memsz - phdr[i].p_filesz); 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; // time = currticks() - start_time;
//debug("Loaded %lu bytes in %ums (%luKB/s)\n", bytes, time, //debug("Loaded %lu bytes in %ums (%luKB/s)\n", bytes, time,
// time? bytes/time : 0); // time? bytes/time : 0);
debug("Loaded %lu bytes \n", bytes); debug("Loaded %lu bytes \n", *bytes);
return 1; return 1;
} }
@@ -309,7 +309,7 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline)
Elf_ehdr ehdr; Elf_ehdr ehdr;
Elf_phdr *phdr = NULL; Elf_phdr *phdr = NULL;
unsigned long phdr_size; unsigned long phdr_size;
unsigned long checksum_offset; unsigned long checksum_offset, file_size;
unsigned short checksum = 0; unsigned short checksum = 0;
Elf_Bhdr *boot_notes = NULL; Elf_Bhdr *boot_notes = NULL;
int retval = -1; 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; image_name = image_version = NULL;
/* Mark the saved-program-state as invalid */
feval("0 state-valid !");
fd = open_io(filename); fd = open_io(filename);
if (!fd) if (!fd)
goto out; 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(" version %s", image_version);
printk("...\n"); printk("...\n");
if (!load_segments(phdr, ehdr.e_phnum, checksum_offset)) if (!load_segments(phdr, ehdr.e_phnum, checksum_offset, &file_size))
goto out; goto out;
if (checksum_offset) { 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("current time: %lu\n", currticks());
debug("entry point is %#x\n", ehdr.e_entry); 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"); printk("Jumping to entry point...\n");
image_retval = start_elf(ehdr.e_entry & ADDRMASK, virt_to_phys(boot_notes)); image_retval = start_elf(ehdr.e_entry & ADDRMASK, virt_to_phys(boot_notes));

View File

@@ -24,6 +24,9 @@ int forth_load(struct sys_info *info, const char *filename, const char *cmdline)
unsigned long forthsize; unsigned long forthsize;
int retval = -1; int retval = -1;
/* Mark the saved-program-state as invalid */
feval("0 state-valid !");
fd = open_io(filename); fd = open_io(filename);
if (!fd) if (!fd)
goto out; goto out;
@@ -54,6 +57,17 @@ int forth_load(struct sys_info *info, const char *filename, const char *cmdline)
forthtext[forthsize]=0; forthtext[forthsize]=0;
printk("ok\n"); 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)forthtext );
PUSH ( (ucell)forthsize ); PUSH ( (ucell)forthsize );
fword("eval2"); fword("eval2");

View File

@@ -16,6 +16,12 @@
\ 7.6.2 Program download and execute \ 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 variable state-valid
0 state-valid ! 0 state-valid !
@@ -28,10 +34,14 @@ variable file-size
variable file-type variable file-type
0 constant elf 0 constant elf-boot
1 constant bootinfo 1 constant elf
2 constant xcoff 2 constant bootinfo
3 constant pe 3 constant xcoff
4 constant pe
5 constant aout
10 constant fcode
11 constant forth
\ Array indexes and values for e_type \ Array indexes and values for e_type