mirror of
https://gitlab.com/qemu-project/openbios.git
synced 2024-02-13 08:34:06 +08:00
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> git-svn-id: svn://coreboot.org/openbios/trunk/openbios-devel@719 f158a5a8-5612-0410-a976-696ce0be7e32
This commit is contained in:
committed by
Mark Cave-Ayland
parent
dc5c530885
commit
c60fad9646
@@ -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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,15 +44,10 @@ 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");
|
||||
retval = LOADER_NOT_SUPPORT;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user