Author: mcayland Date: Sun Mar 28 22:55:10 2010 New Revision: 719 URL: http://tracker.coreboot.org/trac/openbios/changeset/719
Log: Add is_fcode(), is_forth() and is_aout() functions which take a pointer to an area of memory which may contain a valid loader image.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@siriusit.co.uk
Modified: trunk/openbios-devel/include/libopenbios/aout_load.h trunk/openbios-devel/include/libopenbios/fcode_load.h trunk/openbios-devel/include/libopenbios/forth_load.h trunk/openbios-devel/libopenbios/aout_load.c trunk/openbios-devel/libopenbios/fcode_load.c trunk/openbios-devel/libopenbios/forth_load.c
Modified: trunk/openbios-devel/include/libopenbios/aout_load.h ============================================================================== --- trunk/openbios-devel/include/libopenbios/aout_load.h Sun Mar 28 22:48:53 2010 (r718) +++ trunk/openbios-devel/include/libopenbios/aout_load.h Sun Mar 28 22:55:10 2010 (r719) @@ -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 */
Modified: trunk/openbios-devel/include/libopenbios/fcode_load.h ============================================================================== --- trunk/openbios-devel/include/libopenbios/fcode_load.h Sun Mar 28 22:48:53 2010 (r718) +++ trunk/openbios-devel/include/libopenbios/fcode_load.h Sun Mar 28 22:55:10 2010 (r719) @@ -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 */
Modified: trunk/openbios-devel/include/libopenbios/forth_load.h ============================================================================== --- trunk/openbios-devel/include/libopenbios/forth_load.h Sun Mar 28 22:48:53 2010 (r718) +++ trunk/openbios-devel/include/libopenbios/forth_load.h Sun Mar 28 22:55:10 2010 (r719) @@ -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 */
Modified: trunk/openbios-devel/libopenbios/aout_load.c ============================================================================== --- trunk/openbios-devel/libopenbios/aout_load.c Sun Mar 28 22:48:53 2010 (r718) +++ trunk/openbios-devel/libopenbios/aout_load.c Sun Mar 28 22:55:10 2010 (r719) @@ -58,6 +58,15 @@ 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 @@ 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;
Modified: trunk/openbios-devel/libopenbios/fcode_load.c ============================================================================== --- trunk/openbios-devel/libopenbios/fcode_load.c Sun Mar 28 22:48:53 2010 (r718) +++ trunk/openbios-devel/libopenbios/fcode_load.c Sun Mar 28 22:55:10 2010 (r719) @@ -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 @@ 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");
Modified: trunk/openbios-devel/libopenbios/forth_load.c ============================================================================== --- trunk/openbios-devel/libopenbios/forth_load.c Sun Mar 28 22:48:53 2010 (r718) +++ trunk/openbios-devel/libopenbios/forth_load.c Sun Mar 28 22:55:10 2010 (r719) @@ -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 @@ goto out; }
- if (magic[0] != '\' || magic[1] != ' ') { + if (!is_forth(magic)) { debug("No forth source image\n"); retval = LOADER_NOT_SUPPORT; goto out;