[OpenBIOS] [PATCHv2 19/25] bootcode: implement load/init-program as per IEEE-1275 specification

Mark Cave-Ayland mark.cave-ayland at ilande.co.uk
Thu Sep 8 09:00:58 CEST 2016


load should place the file at load-base, whilst init-program should parse
the memory at load-base and set up the context accordingly.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland at ilande.co.uk>
---
 include/libopenbios/bootcode_load.h |    2 ++
 libopenbios/bootcode_load.c         |   25 +++++++++++++++++++++++--
 libopenbios/initprogram.c           |    8 ++++++++
 libopenbios/load.c                  |    9 +++------
 4 files changed, 36 insertions(+), 8 deletions(-)

diff --git a/include/libopenbios/bootcode_load.h b/include/libopenbios/bootcode_load.h
index 147783a..b20380d 100644
--- a/include/libopenbios/bootcode_load.h
+++ b/include/libopenbios/bootcode_load.h
@@ -18,5 +18,7 @@
 #define _H_BOOTCODELOAD
 
 extern int bootcode_load(ihandle_t dev);
+int is_bootcode(char *addr);
+void bootcode_init_program(void);
 
 #endif   /* _H__H_BOOTCODELOAD */
diff --git a/libopenbios/bootcode_load.c b/libopenbios/bootcode_load.c
index c560240..2a307ae 100644
--- a/libopenbios/bootcode_load.c
+++ b/libopenbios/bootcode_load.c
@@ -7,6 +7,7 @@
 #include "kernel/kernel.h"
 #include "libopenbios/bindings.h"
 #include "libopenbios/bootcode_load.h"
+#include "libopenbios/initprogram.h"
 #include "libc/diskio.h"
 #include "drivers/drivers.h"
 #define printf printk
@@ -90,10 +91,30 @@ bootcode_load(ihandle_t dev)
     feval("load-state >ls.file-size !");
     feval("bootcode load-state >ls.file-type !");
 
-    feval("-1 state-valid !");
-
 out:
     close_io(fd);
     return retval;
 }
 
+int 
+is_bootcode(char *addr)
+{
+    /* Bootcode has no magic, and is executed directly. So we'll
+     * say that something is bootcode if the loader detected the
+     * %BOOT type sucessfully */
+    ucell filetype;
+    
+    feval("load-state >ls.file-type @");
+    filetype = POP();
+    
+    return (filetype == 0x12);
+}
+
+void
+bootcode_init_program(void)
+{
+    /* Entry point is already set, just need to setup the context */
+    arch_init_program();
+    
+    feval("-1 state-valid !");
+}
diff --git a/libopenbios/initprogram.c b/libopenbios/initprogram.c
index 93222b7..1008a90 100644
--- a/libopenbios/initprogram.c
+++ b/libopenbios/initprogram.c
@@ -24,6 +24,7 @@
 #include "libopenbios/aout_load.h"
 #endif
 
+#include "libopenbios/bootcode_load.h"
 #include "libopenbios/bootinfo_load.h"
 #include "libopenbios/elf_load.h"
 #include "libopenbios/fcode_load.h"
@@ -47,6 +48,13 @@ void init_program(void)
 	}
 #endif
 
+#ifdef CONFIG_LOADER_BOOTCODE
+	if (is_bootcode((char *)cell2pointer(addr))) {
+		bootcode_init_program();
+		return;
+	}
+#endif
+
 #ifdef CONFIG_LOADER_BOOTINFO
 	if (is_bootinfo((char *)cell2pointer(addr))) {
 		bootinfo_init_program();
diff --git a/libopenbios/load.c b/libopenbios/load.c
index f43679d..a78e3b3 100644
--- a/libopenbios/load.c
+++ b/libopenbios/load.c
@@ -109,12 +109,9 @@ void load(ihandle_t dev)
 
 #ifdef CONFIG_LOADER_BOOTCODE
 	/* Check for a "raw" %BOOT bootcode payload */
-	bootcode_load(dev);
-        feval("state-valid @");
-        valid = POP();
-        if (valid) {
-                feval("load-state >ls.file-size @");
-                return;
+	if (bootcode_load(dev) != LOADER_NOT_SUPPORT) {
+            feval("load-state >ls.file-size @");
+            return;
         }
 #endif
 
-- 
1.7.10.4




More information about the OpenBIOS mailing list