aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiu Aleaxander <Aleaxander@gmail.com>2009-08-05 16:47:43 +0800
committerLiu Aleaxander <Aleaxander@gmail.com>2009-08-05 16:47:43 +0800
commit3509c0d4854f811ed3aa67f24b39870d1da76630 (patch)
tree01df33083a522e380e464f4907cc3b15c06c9c3d
parentbfded9469080eb6752a5070605dce073da0e7d45 (diff)
downloadpxelinux-3509c0d4854f811ed3aa67f24b39870d1da76630.tar.gz
pxelinux-3509c0d4854f811ed3aa67f24b39870d1da76630.tar.xz
pxelinux-3509c0d4854f811ed3aa67f24b39870d1da76630.zip
Core:PXELINUX: code clean -- 1
-rw-r--r--core/pxe.c113
1 files changed, 48 insertions, 65 deletions
diff --git a/core/pxe.c b/core/pxe.c
index eec23fdf..d16d783c 100644
--- a/core/pxe.c
+++ b/core/pxe.c
@@ -476,58 +476,42 @@ void uchexbytes(char *dst, const void *src, int count)
* Clobbers CX and SI
*
*/
-int is_pxe(com32sys_t *regs)
+int is_pxe(char *buf)
{
- uint8_t *p = MK_PTR(regs->es, regs->ebx.w[0]);
- int i;
+ int i = buf[4];
uint8_t sum = 0;
- if (memcmp(p, "!PXE", 4))
- goto bad;
- i = p[4];
- if (i < 0x58)
- goto bad;
+ if (memcmp(buf, "!PXE", 4) || i < 0x58)
+ return 0;
while (i--)
- sum += *p++;
+ sum += *buf++;
- if (sum == 0) {
- regs->eflags.l |= EFLAGS_ZF;
+ if (sum == 0)
return 1;
- }
-
- bad:
- regs->eflags.l &= ~EFLAGS_ZF;
- return 0;
+ else
+ return 0;
}
/**
* Just like is_pxe, it checks PXENV+ structure
*
*/
-int is_pxenv(com32sys_t *regs)
+int is_pxenv(char *buf)
{
- uint8_t *p = MK_PTR(regs->es, regs->ebx.w[0]);
- int i;
+ int i = buf[8];
uint8_t sum = 0;
- if (memcmp(p, "PXENV+", 6))
- goto bad;
- i = p[8];
- if (i < 0x28)
- goto bad;
+ if (memcmp(buf, "PXENV+", 6) || i < 0x28)
+ return 0;
while (i--)
- sum += *p++;
+ sum += *buf++;
- if (sum == 0) {
- regs->eflags.l |= EFLAGS_ZF;
+ if (sum == 0)
return 1;
- }
-
- bad:
- regs->eflags.l &= ~EFLAGS_ZF;
- return 0;
+ else
+ return 0;
}
@@ -550,32 +534,29 @@ int is_pxenv(com32sys_t *regs)
;
********************************************************************/
-inline int memory_scan(uint16_t seg, com32sys_t *regs,
- int (*func)(com32sys_t *))
+inline int memory_scan(uint16_t seg, int (*func)(char *))
{
while (seg < 0xA000) {
- regs->es = seg;
- regs->ebx.w[0] = 0;
- if (func(regs))
+ if (func(MK_PTR(seg, 0)))
return 1; /* found it */
seg++;
}
return 0;
}
-int memory_scan_for_pxe_struct(com32sys_t *regs)
+int memory_scan_for_pxe_struct()
{
extern uint16_t BIOS_fbm; /* Starting segment */
uint16_t seg = BIOS_fbm << (10 - 4);
- return memory_scan(seg, regs, is_pxe);
+ return memory_scan(seg, is_pxe);
}
-int memory_scan_for_pxenv_struct(com32sys_t *regs)
+int memory_scan_for_pxenv_struct()
{
uint16_t seg = 0x1000;
- return memory_scan(seg, regs, is_pxenv);
+ return memory_scan(seg, is_pxenv);
}
@@ -1612,6 +1593,7 @@ void ip_init(void)
void pxe_init(com32sys_t *regs)
{
char plan = 'A';
+ uint16_t seg, off;
uint16_t code_seg, code_len;
uint16_t data_seg, data_len;
char *base = GET_PTR(InitStack);
@@ -1620,16 +1602,16 @@ void pxe_init(com32sys_t *regs)
APIVer = 0x201;
/* Plan A: !PXE structure as SS:[SP + 4] */
- regs->ebx.w[0] = *(uint16_t *)(base + 48);
- regs->es = *(uint16_t *)(base + 50);
- if (is_pxe(regs))
+ off = *(uint16_t *)(base + 48);
+ seg = *(uint16_t *)(base + 50);
+ if (is_pxe(MK_PTR(seg, off)))
goto have_pxe;
/* Plan B: PXENV+ structure at [ES:BX] */
plan++;
- regs->ebx.w[0] = *(uint16_t *)(base + 24); /* Original BX */
- regs->es = *(uint16_t *)(base + 4); /* Original ES */
- if (is_pxenv(regs))
+ off = *(uint16_t *)(base + 24); /* Original BX */
+ seg = *(uint16_t *)(base + 4); /* Original ES */
+ if (is_pxenv(MK_PTR(seg, off)))
goto have_pxenv;
/*
@@ -1641,21 +1623,22 @@ void pxe_init(com32sys_t *regs)
plan++;
goto plan_D;
call16(plan_c, regs, regs);
- if (((regs->eflags.l & EFLAGS_CF) == 0) && (regs->eax.w[0] == 0x564e))
- if (is_pxenv(regs))
+ if (((regs->eflags.l & EFLAGS_CF) == 0) && (regs->eax.w[0] == 0x564e)) {
+ seg = regs->es;
+ off = regs->ebx.w[0];
+ if (is_pxenv(MK_PTR(seg, off)))
goto have_pxenv;
+ }
plan_D:
/* Plan D: !PXE memory scan */
plan++;
- goto plan_E;
- if (memory_scan_for_pxe_struct(regs))
+ if (memory_scan_for_pxe_struct())
goto have_pxe;
-
- plan_E:
+
/* Plan E: PXENV+ memory scan */
plan++;
- if (memory_scan_for_pxenv_struct(regs))
+ if (memory_scan_for_pxenv_struct())
goto have_pxenv;
/* Found nothing at all !! */
@@ -1663,28 +1646,28 @@ void pxe_init(com32sys_t *regs)
call16(kaboom, regs, regs);
have_pxenv:
- StructPtr[0] = regs->ebx.w[0];
- StructPtr[1] = regs->es;
- base = (void *)((StructPtr[1] << 4) + StructPtr[0]);
+ StructPtr[0] = off;
+ StructPtr[1] = seg;
+ base = MK_PTR(seg, off);
APIVer = *(uint16_t *)(base + 6);
printf("Found PXENV+ structure\nPXE API version is %04x\n", APIVer);
/* if the API version number is 0x0201 or higher, use the !PXE structure */
if (APIVer >= 0x201) {
if (*(char *)(base + 8) < 0x2c) { /* Length of PXENV+ structure in bytes */
- if (memory_scan_for_pxe_struct(regs))
+ if (memory_scan_for_pxe_struct())
goto have_pxe;
}
- regs->ebx.w[0] = *(uint16_t *)(base + 0x28);
- regs->es = *(uint16_t *)(base + 0x2a);
- if (is_pxe(regs))
+ off = *(uint16_t *)(base + 0x28);
+ seg = *(uint16_t *)(base + 0x2a);
+ if (is_pxe(MK_PTR(seg, off)))
goto have_pxe;
/*
* Nope, !PXE structuremissing despite API 2.1+, or at least
* the pointer is missing. Do a last-ditch attempt to find it
*/
- if (memory_scan_for_pxe_struct(regs))
+ if (memory_scan_for_pxe_struct())
goto have_pxe;
}
@@ -1698,9 +1681,9 @@ void pxe_init(com32sys_t *regs)
goto have_entrypoint;
have_pxe:
- StructPtr[0] = regs->ebx.w[0];
- StructPtr[1] = regs->es;
- base = (void *)((StructPtr[1] << 4) + StructPtr[0]);
+ StructPtr[0] = off;
+ StructPtr[1] = seg;
+ base = MK_PTR(seg, off);
data_len = *(uint16_t *)(base + 0x2e); /* UNDI data len */
data_seg = *(uint16_t *)(base + 0x28); /* UNDI data seg */