From 8b584217d5b18b7737c344bfb45570af1379da24 Mon Sep 17 00:00:00 2001 From: Liu Aleaxander Date: Mon, 31 Aug 2009 05:51:38 +0800 Subject: [PATCH] Core: get rid of passing com32sys_t structure as parameter in PMode Well, this molstly be about xxx_load_config function, with function type changed. The new load_config function will return 1 if failed, or 0 if successed. Signed-off-by: Liu Aleaxander --- core/fs.c | 9 +++-- core/fs/ext2/ext2.c | 17 +++++---- core/fs/fat/fat.c | 19 +++++----- core/fs/iso9660/iso9660.c | 19 ++++------ core/fs/pxe/pxe.c | 91 +++++++++++++++++++---------------------------- core/include/core.h | 2 +- core/include/fs.h | 2 +- 7 files changed, 71 insertions(+), 88 deletions(-) diff --git a/core/fs.c b/core/fs.c index f7bf68c..a3407cf 100644 --- a/core/fs.c +++ b/core/fs.c @@ -55,9 +55,14 @@ inline struct file *handle_to_file(uint16_t handle) return handle ? &files[handle-1] : NULL; } -void load_config(com32sys_t *regs) +void load_config(void) { - this_fs->fs_ops->load_config(regs); + int err; + err = this_fs->fs_ops->load_config(); + +#if 0 + printf("Loading config file %s\n", err ? "failed" : "successed"); +#endif } void mangle_name(com32sys_t *regs) diff --git a/core/fs/ext2/ext2.c b/core/fs/ext2/ext2.c index dcd4a49..7db45fc 100644 --- a/core/fs/ext2/ext2.c +++ b/core/fs/ext2/ext2.c @@ -679,21 +679,20 @@ static void ext2_searchdir(char *filename, struct file *file) } -static void ext2_load_config(com32sys_t *regs) +/* Load the config file, return 1 if failed, or 0 */ +static int ext2_load_config(void) { char *config_name = "extlinux.conf"; + com32sys_t regs; strcpy(ConfigName, config_name); *(uint32_t *)CurrentDirName = 0x00002f2e; + + memset(®s, 0, sizeof regs); + regs.edi.w[0] = OFFS_WRT(ConfigName, 0); + call16(core_open, ®s, ®s); - regs->edi.w[0] = OFFS_WRT(ConfigName, 0); - call16(core_open, regs, regs); - -#if 0 - printf("the zero flag is %s\n", regs->eax.w[0] ? \ - "CLEAR, means we found the config file" : - "SET, menas we didn't find the config file"); -#endif + return regs.eflags.l & EFLAGS_ZF; } diff --git a/core/fs/fat/fat.c b/core/fs/fat/fat.c index 58226a7..e7931b0 100644 --- a/core/fs/fat/fat.c +++ b/core/fs/fat/fat.c @@ -797,16 +797,16 @@ struct dirent* vfat_readdir(struct file *dir) return &de; } -static void vfat_load_config(com32sys_t *regs) +/* Load the config file, return 1 if failed, or 0 */ +static int vfat_load_config(void) { static const char syslinux_cfg1[] = "/boot/syslinux/syslinux.cfg"; static const char syslinux_cfg2[] = "/syslinux/syslinux.cfg"; static const char syslinux_cfg3[] = "/syslinux.cfg"; - static const char config_name[] = "syslinux.cfg"; - + static const char config_name[] = "syslinux.cfg"; const char * const syslinux_cfg[] = { syslinux_cfg1, syslinux_cfg2, syslinux_cfg3 }; - com32sys_t oregs; + com32sys_t regs; int i = 0; *(uint16_t *)CurrentDirName = ROOT_DIR_WORD; @@ -816,25 +816,26 @@ static void vfat_load_config(com32sys_t *regs) * we use the ConfigName to pass the config path because * it is under the address 0xffff */ - regs->edi.w[0] = OFFS_WRT(ConfigName, 0); + memset(®s, 0, sizeof regs); + regs.edi.w[0] = OFFS_WRT(ConfigName, 0); for (; i < 3; i++) { strcpy(ConfigName, syslinux_cfg[i]); - memset(&oregs, 0, sizeof oregs); - call16(core_open, regs, &oregs); + call16(core_open, ®s, ®s); /* if zf flag set, then failed; try another */ - if (! (oregs.eflags.l & EFLAGS_ZF)) + if (! (regs.eflags.l & EFLAGS_ZF)) break; } if (i == 3) { printf("no config file found\n"); - return; /* no config file */ + return 1; /* no config file */ } strcpy(ConfigName, config_name); strcpy(CurrentDirName, syslinux_cfg[i]); CurrentDirName[strlen(syslinux_cfg[i])-strlen(config_name)] = '\0'; CurrentDir = PrevDir; + return 0; } static inline __constfunc uint32_t bsr(uint32_t num) diff --git a/core/fs/iso9660/iso9660.c b/core/fs/iso9660/iso9660.c index 68d5736..eb9dede 100644 --- a/core/fs/iso9660/iso9660.c +++ b/core/fs/iso9660/iso9660.c @@ -445,23 +445,18 @@ static void iso_searchdir(char *filename, struct file *file) #endif } -static void iso_load_config(com32sys_t *regs) +/* Load the config file, return 1 if failed, or 0 */ +static int iso_load_config(void) { char *config_name = "isolinux.cfg"; + com32sys_t regs; -#if DEBUG - printf("About to load config file...\n"); -#endif - + memset(®s, 0, sizeof regs); strcpy(ConfigName, config_name); - regs->edi.w[0] = OFFS_WRT(ConfigName, 0); - call16(core_open, regs, regs); + regs.edi.w[0] = OFFS_WRT(ConfigName, 0); + call16(core_open, ®s, ®s); -#if DEBUG - printf("the zero flag is %s\n", regs->eax.w[0] ? - "CLEAR, means we found the config file" : - "SET, menas we didn't find the config file"); -#endif + return regs.eflags.l & EFLAGS_ZF; } diff --git a/core/fs/pxe/pxe.c b/core/fs/pxe/pxe.c index e73211c..bbc77e0 100644 --- a/core/fs/pxe/pxe.c +++ b/core/fs/pxe/pxe.c @@ -254,20 +254,19 @@ static const char *parse_dotquad(const char *ip_str, uint32_t *res) int pxe_call(int opcode, void *data) { extern void pxenv(void); - com32sys_t in_regs, out_regs; + com32sys_t regs; #if 0 printf("pxe_call op %04x data %p\n", opcode, data); #endif - memset(&in_regs, 0, sizeof in_regs); - - in_regs.ebx.w[0] = opcode; - in_regs.es = SEG(data); - in_regs.edi.w[0] = OFFS(data); - call16(pxenv, &in_regs, &out_regs); + memset(®s, 0, sizeof regs); + regs.ebx.w[0] = opcode; + regs.es = SEG(data); + regs.edi.w[0] = OFFS(data); + call16(pxenv, ®s, ®s); - return out_regs.eflags.l & EFLAGS_CF; /* CF SET if fail */ + return regs.eflags.l & EFLAGS_CF; /* CF SET if fail */ } /** @@ -1022,17 +1021,17 @@ static void get_prefix(void) * try to load a config file, if found, return 1, or return 0 * */ -static int try_load(com32sys_t *regs) +static int try_load(char *config_name) { - extern char KernelName[]; - char *config_name = (char *)MK_PTR(regs->ds, regs->edi.w[0]); - + com32sys_t regs; + printf("Trying to load: %-50s ", config_name); pxe_mangle_name(KernelName, config_name); - regs->edi.w[0] = OFFS_WRT(KernelName, 0); - call16(core_open, regs, regs); - if (regs->eflags.l & EFLAGS_ZF) { + memset(®s, 0, sizeof regs); + regs.edi.w[0] = OFFS_WRT(KernelName, 0); + call16(core_open, ®s, ®s); + if (regs.eflags.l & EFLAGS_ZF) { printf(" [FAILED]\n"); return 0; } else { @@ -1042,35 +1041,31 @@ static int try_load(com32sys_t *regs) } - /* - * load configuration file - * - */ -static void pxe_load_config(com32sys_t *regs) +/* Load the config file, return 1 if failed, or 0 */ +static int pxe_load_config(void) { - char *cfgprefix = "pxelinux.cfg/"; - char *default_str = "default"; - char *config_file; /* Pointer to the variable suffix */ - char *p; - + const char *cfgprefix = "pxelinux.cfg/"; + const char *default_str = "default"; + char *config_file; + char *last; + char *p; uint8_t *uuid_ptr; - int tries = 8; - char *last; get_prefix(); if (DHCPMagic & 0x02) { /* We got a DHCP option, try it first */ - if (try_load(regs)) - return; + /* XXX: I have no idea where the config_file came from */ + //if (try_load(NULL)) + //return 0; } - memcpy(ConfigName, cfgprefix, strlen(cfgprefix)); - config_file = ConfigName + strlen(cfgprefix); /* * Have to guess config file name ... - */ - + */ + memcpy(ConfigName, cfgprefix, strlen(cfgprefix)); + config_file = ConfigName + strlen(cfgprefix); + /* Try loading by UUID */ if (have_uuid) { uuid_ptr = uuid_dashes; @@ -1087,44 +1082,34 @@ static void pxe_load_config(com32sys_t *regs) } /* Remove last dash and zero-terminate */ *--p = '\0'; - regs->edi.w[0] = OFFS_WRT(ConfigName, 0); - if (try_load(regs)) - return; + if (try_load(ConfigName)) + return 0; } /* Try loading by MAC address */ strcpy(config_file, MAC_str); - regs->edi.w[0] = OFFS_WRT(ConfigName, 0); - if (try_load(regs)) - return; - -#if 0 - printf("MY IP: %p(%X)\n", MyIP, *(uint32_t *)MyIP); - #endif + if (try_load(ConfigName)) + return 0; /* Nope, try hexadecimal IP prefixes... */ uchexbytes(config_file, (uint8_t *)&MyIP, 4); /* Convet to hex string */ last = &config_file[8]; while (tries) { *last = '\0'; /* Zero-terminate string */ - regs->edi.w[0] = OFFS_WRT(ConfigName, 0); - if (try_load(regs)) - return; + if (try_load(ConfigName)) + return 0; last--; /* Drop one character */ tries--; }; /* Final attempt: "default" string */ strcpy(config_file, default_str); - regs->edi.w[0] = OFFS_WRT(ConfigName, 0); - if (try_load(regs)) - return; + if (try_load(ConfigName)) + return 0; printf("Unable to locate configuration file\n"); kaboom(); } - - /* * Generate the botif string, and the hardware-based config string @@ -1319,9 +1304,7 @@ static void pxe_init(void) if (is_pxenv(pxenv)) goto have_pxenv; - /* - * Plan C: PXENV+ structure via INT 1Ah AX=5650h - */ + /* Plan C: PXENV+ structure via INT 1Ah AX=5650h */ plan++; memset(®s, 0, sizeof regs); regs.eax.w[0] = 0x5650; diff --git a/core/include/core.h b/core/include/core.h index 9ab0351..004c729 100644 --- a/core/include/core.h +++ b/core/include/core.h @@ -9,7 +9,7 @@ extern char core_cache_buf[65536]; extern char trackbuf[]; extern char CurrentDirName[]; extern char ConfigName[]; - +extern char KernelName[]; /* diskstart.inc isolinux.asm*/ extern void getlinsec(void); diff --git a/core/include/fs.h b/core/include/fs.h index e66c3bd..df10302 100644 --- a/core/include/fs.h +++ b/core/include/fs.h @@ -49,7 +49,7 @@ struct fs_ops { void (*close_file)(struct file *); void (*mangle_name)(char *, const char *); char * (*unmangle_name)(char *, const char *); - void (*load_config)(com32sys_t *); + int (*load_config)(); /* the _dir_ stuff */ void (*opendir)(com32sys_t *); -- 2.7.4