[OpenBIOS] [PATCH 17/24] libopenbios: move go() function into libopenbios
Mark Cave-Ayland
mark.cave-ayland at ilande.co.uk
Tue Sep 6 00:01:33 CEST 2016
Add an (arch-go) hook for architectures that need to do their own thing before
starting an image, and switch the callers over to use it.
Also clarify the state-valid check: any non-zero value is considered true.
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland at ilande.co.uk>
---
arch/ppc/qemu/init.c | 14 +++--------
arch/sparc32/boot.c | 48 +------------------------------------
arch/sparc32/boot.h | 2 +-
arch/sparc32/openbios.c | 2 +-
arch/sparc64/boot.c | 44 ----------------------------------
arch/sparc64/boot.h | 1 -
arch/sparc64/openbios.c | 1 -
arch/unix/boot.c | 8 +++++++
arch/x86/boot.c | 43 ---------------------------------
arch/x86/boot.h | 2 +-
arch/x86/openbios.c | 1 -
forth/debugging/client.fs | 14 ++++++-----
include/libopenbios/initprogram.h | 2 ++
libopenbios/init.c | 3 +++
libopenbios/initprogram.c | 33 +++++++++++++++++++++++++
15 files changed, 61 insertions(+), 157 deletions(-)
diff --git a/arch/ppc/qemu/init.c b/arch/ppc/qemu/init.c
index a401a9c..2f66ab4 100644
--- a/arch/ppc/qemu/init.c
+++ b/arch/ppc/qemu/init.c
@@ -595,23 +595,15 @@ id_cpu(void)
}
}
-static void go(void);
-unsigned int start_elf(unsigned long entry_point);
+static void arch_go(void);
static void
-go(void)
+arch_go(void)
{
- ucell addr;
-
/* Insert copyright property for MacOS 9 and below */
if (find_dev("/rom/macos")) {
fword("insert-copyright-property");
}
-
- feval("load-state >ls.entry @");
- addr = POP();
-
- start_elf((unsigned long)addr);
}
static void kvm_of_init(void)
@@ -1016,5 +1008,5 @@ arch_of_init(void)
bind_func("(adler32)", adler32);
bind_func("platform-boot", boot);
- bind_func("(go)", go);
+ bind_func("(arch-go)", arch_go);
}
diff --git a/arch/sparc32/boot.c b/arch/sparc32/boot.c
index d65913a..35fd473 100644
--- a/arch/sparc32/boot.c
+++ b/arch/sparc32/boot.c
@@ -24,7 +24,7 @@ const void *romvec;
static struct linux_mlist_v0 *totphyslist, *availlist, *prommaplist;
-static void setup_romvec(void)
+void setup_romvec(void)
{
/* SPARC32 is slightly unusual in that before invoking any loaders, a romvec array
needs to be set up to pass certain parameters using a C struct. Hence this function
@@ -191,52 +191,6 @@ static void setup_romvec(void)
}
-void go(void)
-{
- ucell address, type;
- int image_retval = 0;
-
- /* Get the entry point and the type (see forth/debugging/client.fs) */
- feval("load-state >ls.entry @");
- address = POP();
- feval("load-state >ls.file-type @");
- type = POP();
-
- setup_romvec();
-
- printk("\nJumping to entry point " FMT_ucellx " for type " FMT_ucellx "...\n", address, type);
-
- switch (type) {
- case 0x0:
- /* Start ELF boot image */
- image_retval = start_elf((unsigned long)address);
- break;
-
- case 0x1:
- /* Start ELF image */
- image_retval = start_elf((unsigned long)address);
- break;
-
- case 0x5:
- /* Start a.out image */
- image_retval = start_elf((unsigned long)address);
- break;
-
- case 0x10:
- /* Start Fcode image */
- image_retval = start_elf((unsigned long)&init_fcode_context);
- break;
-
- case 0x11:
- /* Start Forth image */
- image_retval = start_elf((unsigned long)&init_forth_context);
- break;
- }
-
- printk("Image returned with return value %#x\n", image_retval);
-}
-
-
void boot(void)
{
/* Boot preloaded kernel */
diff --git a/arch/sparc32/boot.h b/arch/sparc32/boot.h
index 0001699..e372acc 100644
--- a/arch/sparc32/boot.h
+++ b/arch/sparc32/boot.h
@@ -12,7 +12,7 @@ int linux_load(struct sys_info *info, const char *file, const char *cmdline);
// boot.c
extern const char *bootpath;
extern void boot(void);
-extern void go(void);
+extern void setup_romvec(void);
// sys_info.c
extern unsigned int qemu_mem_size;
diff --git a/arch/sparc32/openbios.c b/arch/sparc32/openbios.c
index 10ac9b9..dd31c23 100644
--- a/arch/sparc32/openbios.c
+++ b/arch/sparc32/openbios.c
@@ -915,7 +915,7 @@ arch_init( void )
device_end();
bind_func("platform-boot", boot );
- bind_func("(go)", go );
+ bind_func("(arch-go)", setup_romvec );
/* Set up other properties */
push_str("/chosen");
diff --git a/arch/sparc64/boot.c b/arch/sparc64/boot.c
index 9eac52c..7a287f2 100644
--- a/arch/sparc64/boot.c
+++ b/arch/sparc64/boot.c
@@ -19,50 +19,6 @@ char boot_device;
extern int sparc64_of_client_interface( int *params );
-
-void go(void)
-{
- ucell address, type;
- int image_retval = 0;
-
- /* Get the entry point and the type (see forth/debugging/client.fs) */
- feval("load-state >ls.entry @");
- address = POP();
- feval("load-state >ls.file-type @");
- type = POP();
-
- printk("\nJumping 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);
- break;
-
- case 0x1:
- /* Start ELF image */
- image_retval = start_elf(address);
- break;
-
- case 0x5:
- /* Start a.out image */
- image_retval = start_elf(address);
- break;
-
- case 0x10:
- /* Start Fcode image */
- image_retval = start_elf((unsigned long)&init_fcode_context);
- break;
-
- case 0x11:
- /* Start Forth image */
- image_retval = start_elf((unsigned long)&init_forth_context);
- break;
- }
-
- printk("Image returned with return value %#x\n", image_retval);
-}
-
/* ( path len -- path len ) */
void boot(void)
diff --git a/arch/sparc64/boot.h b/arch/sparc64/boot.h
index f7b739f..fef0573 100644
--- a/arch/sparc64/boot.h
+++ b/arch/sparc64/boot.h
@@ -16,7 +16,6 @@ extern uint64_t qemu_cmdline;
extern uint64_t cmdline_size;
extern char boot_device;
extern void boot(void);
-extern void go(void);
// sys_info.c
extern uint64_t qemu_mem_size;
diff --git a/arch/sparc64/openbios.c b/arch/sparc64/openbios.c
index 4557f7f..9a1d56c 100644
--- a/arch/sparc64/openbios.c
+++ b/arch/sparc64/openbios.c
@@ -586,7 +586,6 @@ arch_init( void )
obp_ticks_pointer = cell2pointer(POP());
bind_func("platform-boot", boot );
- bind_func("(go)", go);
}
unsigned long isa_io_base;
diff --git a/arch/unix/boot.c b/arch/unix/boot.c
index f4a2942..d65681f 100644
--- a/arch/unix/boot.c
+++ b/arch/unix/boot.c
@@ -10,6 +10,7 @@
void boot(void);
void *load_elf(char *spec);
+unsigned int start_elf(unsigned long address);
void
*load_elf(char *spec)
@@ -82,3 +83,10 @@ boot( void )
else
printk("failed.\n");
}
+
+unsigned int
+start_elf(unsigned long address)
+{
+ return 0;
+}
+
diff --git a/arch/x86/boot.c b/arch/x86/boot.c
index 688b24e..61f6562 100644
--- a/arch/x86/boot.c
+++ b/arch/x86/boot.c
@@ -15,49 +15,6 @@
#include "libopenbios/sys_info.h"
#include "boot.h"
-void go(void)
-{
- ucell address, type;
- int image_retval = 0;
-
- /* Get the entry point and the type (see forth/debugging/client.fs) */
- feval("load-state >ls.entry @");
- address = POP();
- feval("load-state >ls.file-type @");
- type = POP();
-
- printk("\nJumping 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);
- break;
-
- case 0x1:
- /* Start ELF image */
- image_retval = start_elf(address);
- break;
-
- case 0x5:
- /* Start a.out image */
- image_retval = start_elf(address);
- break;
-
- case 0x10:
- /* Start Fcode image */
- image_retval = start_elf((unsigned long)&init_fcode_context);
- break;
-
- case 0x11:
- /* Start Forth image */
- image_retval = start_elf((unsigned long)&init_forth_context);
- break;
- }
-
- printk("Image returned with return value %#x\n", image_retval);
-}
-
void boot(void)
{
diff --git a/arch/x86/boot.h b/arch/x86/boot.h
index 94c37b5..cdc5435 100644
--- a/arch/x86/boot.h
+++ b/arch/x86/boot.h
@@ -11,4 +11,4 @@ int linux_load(struct sys_info *info, const char *file, const char *cmdline);
/* boot.c */
extern void boot(void);
-extern void go(void);
+
diff --git a/arch/x86/openbios.c b/arch/x86/openbios.c
index 6145436..d8a0f9e 100644
--- a/arch/x86/openbios.c
+++ b/arch/x86/openbios.c
@@ -73,7 +73,6 @@ arch_init( void )
#endif
device_end();
bind_func("platform-boot", boot );
- bind_func("(go)", go );
}
extern struct _console_ops arch_console_ops;
diff --git a/forth/debugging/client.fs b/forth/debugging/client.fs
index d3c986a..acad733 100644
--- a/forth/debugging/client.fs
+++ b/forth/debugging/client.fs
@@ -204,18 +204,20 @@ variable file-size
;
: go ( -- )
- state-valid @ not if
+ state-valid @ 0= if
s" No valid state has been set by load or init-program" type cr
exit
then
- \ Call the architecture-specific code to launch the client image
+ \ Call any architecture-specific code
+ s" (arch-go)" $find if
+ execute
+ then
+
+ \ go
s" (go)" $find if
execute
- else
- ." go is not yet implemented"
- 2drop
- then
+ then
;
diff --git a/include/libopenbios/initprogram.h b/include/libopenbios/initprogram.h
index c42d956..33f2723 100644
--- a/include/libopenbios/initprogram.h
+++ b/include/libopenbios/initprogram.h
@@ -26,4 +26,6 @@ extern void init_program(void);
void init_fcode_context(void);
void init_forth_context(void);
+void go(void);
+
#endif /* _H_INITPROGRAM */
diff --git a/libopenbios/init.c b/libopenbios/init.c
index 10fb55c..9b81821 100644
--- a/libopenbios/init.c
+++ b/libopenbios/init.c
@@ -24,4 +24,7 @@ openbios_init( void )
{
// Bind the C implementation of (init-program) into Forth
bind_func("(init-program)", init_program);
+
+ // Bind the C implementation of (go) into Forth
+ bind_func("(go)", go);
}
diff --git a/libopenbios/initprogram.c b/libopenbios/initprogram.c
index 9cf3780..93222b7 100644
--- a/libopenbios/initprogram.c
+++ b/libopenbios/initprogram.c
@@ -102,3 +102,36 @@ void init_forth_context(void)
feval("load-state >ls.file-size @");
fword("eval2");
}
+
+void go(void)
+{
+ ucell address, type;
+ int image_retval = 0;
+
+ /* Get the entry point and the type (see forth/debugging/client.fs) */
+ feval("load-state >ls.entry @");
+ address = POP();
+ feval("load-state >ls.file-type @");
+ type = POP();
+
+ printk("\nJumping to entry point " FMT_ucellx " for type " FMT_ucellx "...\n", address, type);
+
+ switch (type) {
+ default:
+ /* Start native binary */
+ image_retval = start_elf((unsigned long)address);
+ break;
+
+ case 0x10:
+ /* Start Fcode image */
+ image_retval = start_elf((unsigned long)&init_fcode_context);
+ break;
+
+ case 0x11:
+ /* Start Forth image */
+ image_retval = start_elf((unsigned long)&init_forth_context);
+ break;
+ }
+
+ printk("Image returned with return value %#x\n", image_retval);
+}
--
1.7.10.4
More information about the OpenBIOS
mailing list