diff --git a/include/libopenbios/aout_load.h b/include/libopenbios/aout_load.h index 359035a..6ec3950 100644 --- a/include/libopenbios/aout_load.h +++ b/include/libopenbios/aout_load.h @@ -17,8 +17,10 @@ #ifndef _H_AOUTLOAD #define _H_AOUTLOAD +#include "arch/common/a.out.h" #include "libopenbios/sys_info.h" +extern int is_aout(struct exec *ehdr); extern int aout_load(struct sys_info *info, const char *filename); #endif /* _H_AOUTLOAD */ diff --git a/include/libopenbios/fcode_load.h b/include/libopenbios/fcode_load.h index 806c565..c9750a6 100644 --- a/include/libopenbios/fcode_load.h +++ b/include/libopenbios/fcode_load.h @@ -17,6 +17,7 @@ #ifndef _H_FCODELOAD #define _H_FCODELOAD +extern int is_fcode(unsigned char *fcode); extern int fcode_load(const char *filename); #endif /* _H_FCODELOAD */ diff --git a/include/libopenbios/forth_load.h b/include/libopenbios/forth_load.h index 3e8e773..6940cfe 100644 --- a/include/libopenbios/forth_load.h +++ b/include/libopenbios/forth_load.h @@ -17,6 +17,7 @@ #ifndef _H_FORTHLOAD #define _H_FORTHLOAD +extern int is_forth(char *forth); extern int forth_load(const char *filename); #endif /* _H_FORTHLOAD */ diff --git a/libopenbios/aout_load.c b/libopenbios/aout_load.c index 6d9cd94..458850a 100644 --- a/libopenbios/aout_load.c +++ b/libopenbios/aout_load.c @@ -58,6 +58,15 @@ static int check_mem_ranges(struct sys_info *info, return 0; } +int is_aout(struct exec *ehdr) +{ + return ((ehdr->a_info & 0xffff) == OMAGIC + || (ehdr->a_info & 0xffff) == NMAGIC + || (ehdr->a_info & 0xffff) == ZMAGIC + || (ehdr->a_info & 0xffff) == QMAGIC); + +} + int aout_load(struct sys_info *info, const char *filename) { int retval = -1; @@ -81,11 +90,11 @@ int aout_load(struct sys_info *info, const char *filename) retval = LOADER_NOT_SUPPORT; goto out; } - if (!N_BADMAG(ehdr)) + if (is_aout(&ehdr)) break; } - if (N_BADMAG(ehdr)) { + if (!is_aout(&ehdr)) { debug("Not a bootable a.out image\n"); retval = LOADER_NOT_SUPPORT; goto out; diff --git a/libopenbios/fcode_load.c b/libopenbios/fcode_load.c index a8a5d6b..038563c 100644 --- a/libopenbios/fcode_load.c +++ b/libopenbios/fcode_load.c @@ -13,6 +13,15 @@ static int fd; +int is_fcode(unsigned char *fcode) +{ + return (fcode[0] == 0xf0 // start0 + || fcode[0] == 0xf1 // start1 + || fcode[0] == 0xf2 // start2 + || fcode[0] == 0xf3 // start4 + || fcode[0] == 0xfd); // version1 +} + int fcode_load(const char *filename) { int retval = -1; @@ -35,14 +44,9 @@ int fcode_load(const char *filename) retval = LOADER_NOT_SUPPORT; goto out; } - switch (fcode_header[0]) { - case 0xf0: // start0 - case 0xf1: // start1 - case 0xf2: // start2 - case 0xf3: // start4 - case 0xfd: // version1 + + if (is_fcode(fcode_header)) goto found; - } } debug("Not a bootable FCode image\n"); diff --git a/libopenbios/forth_load.c b/libopenbios/forth_load.c index 76fee6b..b0ee295 100644 --- a/libopenbios/forth_load.c +++ b/libopenbios/forth_load.c @@ -16,8 +16,13 @@ #define debug printk static int fd; - static char *forthtext=NULL; + +int is_forth(char *forth) +{ + return (forth[0] == '\\' && forth[1] == ' '); +} + int forth_load(const char *filename) { char magic[2]; @@ -37,7 +42,7 @@ int forth_load(const char *filename) goto out; } - if (magic[0] != '\\' || magic[1] != ' ') { + if (!is_forth(magic)) { debug("No forth source image\n"); retval = LOADER_NOT_SUPPORT; goto out;