[syslinux:elflink] Use pxe_call() instead of COMBOOT API

syslinux-bot for Matt Fleming matt.fleming at intel.com
Tue Aug 14 09:21:06 PDT 2012


Commit-ID:  f0bbf9dd40f37f8c4870a33784996efd56955a75
Gitweb:     http://www.syslinux.org/commit/f0bbf9dd40f37f8c4870a33784996efd56955a75
Author:     Matt Fleming <matt.fleming at intel.com>
AuthorDate: Thu, 12 Jul 2012 13:34:06 +0100
Committer:  Matt Fleming <matt.fleming at intel.com>
CommitDate: Fri, 20 Jul 2012 10:20:19 +0100

Use pxe_call() instead of COMBOOT API

This involved some other changes, such as passing flags to
unload_pxe() now that we only call it from C code, and hence don't
need to update KeepPXE.

We also needed to move some of the pxe function prototypes to
com32/include/syslinux/pxe_api.h because they are now referenced
outside of the core.

Signed-off-by: Matt Fleming <matt.fleming at intel.com>

---
 com32/include/syslinux/pxe_api.h    |    4 ++++
 com32/lib/sys/gpxe.c                |   14 ++++----------
 com32/lib/syslinux/cleanup.c        |   12 +++++++-----
 com32/lib/syslinux/pxe_dns.c        |   14 +++-----------
 com32/lib/syslinux/pxe_get_cached.c |   11 ++---------
 com32/lib/syslinux/pxe_get_nic.c    |   12 +++---------
 com32/libupload/upload_tftp.c       |   18 +++---------------
 com32/modules/gpxecmd.c             |   11 +----------
 com32/modules/pxechn.c              |   16 ++--------------
 com32/modules/sanboot.c             |   11 +----------
 com32/samples/resolv.c              |   17 ++---------------
 core/fs/pxe/pxe.c                   |    4 ++--
 core/fs/pxe/pxe.h                   |    2 --
 13 files changed, 34 insertions(+), 112 deletions(-)

diff --git a/com32/include/syslinux/pxe_api.h b/com32/include/syslinux/pxe_api.h
index 27166b0..203ab38 100644
--- a/com32/include/syslinux/pxe_api.h
+++ b/com32/include/syslinux/pxe_api.h
@@ -568,4 +568,8 @@ typedef struct s_PXENV_UNLOAD_STACK {
 #define PXENV_STATUS_LOADER_UNDI_START			 0xca
 #define PXENV_STATUS_LOADER_BC_START			 0xcb
 
+int __weak pxe_call(int, void *);
+void __weak unload_pxe(uint16_t flags);
+uint32_t __weak dns_resolv(const char *);
+
 #endif /* _SYSLINUX_PXE_API_H */
diff --git a/com32/lib/sys/gpxe.c b/com32/lib/sys/gpxe.c
index 06c4510..3cc2b84 100644
--- a/com32/lib/sys/gpxe.c
+++ b/com32/lib/sys/gpxe.c
@@ -7,9 +7,9 @@
 bool is_gpxe(void)
 {
     const struct syslinux_version *sv;
-    com32sys_t reg;
     struct s_PXENV_FILE_CHECK_API *fca;
     bool gpxe;
+    int err;
 
     sv = syslinux_version();
     if (sv->filesystem != SYSLINUX_FS_PXELINUX)
@@ -22,20 +22,14 @@ bool is_gpxe(void)
     fca->Size = sizeof *fca;
     fca->Magic = 0x91d447b2;
 
-    memset(&reg, 0, sizeof reg);
-    reg.eax.w[0] = 0x0009;
-    reg.ebx.w[0] = PXENV_FILE_API_CHECK;
-    /* reg.edi.w[0] = OFFS(fca); */
-    reg.es = SEG(fca);
-
-    __intcall(0x22, &reg, &reg);
+    err = pxe_call(PXENV_FILE_API_CHECK, fca);
 
     gpxe = true;
 
-    if (reg.eflags.l & EFLAGS_CF)
+    if (err)
 	gpxe = false;           /* Cannot invoke PXE stack */
 
-    if (reg.eax.w[0] || fca->Status)
+    if (fca->Status)
         gpxe = false;           /* PXE failure */
 
     if (fca->Magic != 0xe9c17b20)
diff --git a/com32/lib/syslinux/cleanup.c b/com32/lib/syslinux/cleanup.c
index 12140e5..066f174 100644
--- a/com32/lib/syslinux/cleanup.c
+++ b/com32/lib/syslinux/cleanup.c
@@ -26,15 +26,17 @@
  * ----------------------------------------------------------------------- */
 
 #include <syslinux/boot.h>
+#include <syslinux/config.h>
+#include <syslinux/pxe_api.h>
 #include <stddef.h>
+#include <bios.h>
 #include <com32.h>
+#include <core.h>
 
 void syslinux_final_cleanup(uint16_t flags)
 {
-    static com32sys_t ireg;
+    if (syslinux_filesystem() == SYSLINUX_FS_PXELINUX)
+	unload_pxe(flags);
 
-    ireg.eax.w[0] = 0x000c;
-    ireg.edx.w[0] = flags;
-
-    __intcall(0x22, &ireg, NULL);
+    cleanup_hardware();
 }
diff --git a/com32/lib/syslinux/pxe_dns.c b/com32/lib/syslinux/pxe_dns.c
index 6620396..b813b54 100644
--- a/com32/lib/syslinux/pxe_dns.c
+++ b/com32/lib/syslinux/pxe_dns.c
@@ -43,12 +43,12 @@
    or -1 on invocation failure */
 uint32_t pxe_dns(const char *hostname)
 {
-    com32sys_t regs;
     union {
 	unsigned char b[4];
 	uint32_t ip;
     } q;
     char *lm_hostname;
+    uint32_t status;
 
     /* Is this a dot-quad? */
     if (sscanf(hostname, "%hhu.%hhu.%hhu.%hhu",
@@ -59,17 +59,9 @@ uint32_t pxe_dns(const char *hostname)
     if (!lm_hostname)
 	return 0;
 
-    memset(&regs, 0, sizeof regs);
-    regs.eax.w[0] = 0x0010;
-    regs.es = SEG(lm_hostname);
-    /* regs.ebx.w[0] = OFFS(lm_hostname); */
-
-    __intcall(0x22, &regs, &regs);
+    status = dns_resolv(lm_hostname);
 
     lfree(lm_hostname);
 
-    if (regs.eflags.l & EFLAGS_CF)
-	return 0;
-
-    return regs.eax.l;
+    return status;
 }
diff --git a/com32/lib/syslinux/pxe_get_cached.c b/com32/lib/syslinux/pxe_get_cached.c
index 4704037..a090a4c 100644
--- a/com32/lib/syslinux/pxe_get_cached.c
+++ b/com32/lib/syslinux/pxe_get_cached.c
@@ -43,7 +43,6 @@
 int pxe_get_cached_info(int level, void **buf, size_t * len)
 {
     const int max_dhcp_packet = 2048;
-    com32sys_t regs;
     t_PXENV_GET_CACHED_INFO *gci;
     void *bbuf, *nbuf;
     int err;
@@ -52,12 +51,6 @@ int pxe_get_cached_info(int level, void **buf, size_t * len)
     if (!gci)
 	return -1;
 
-    memset(&regs, 0, sizeof regs);
-    regs.eax.w[0] = 0x0009;
-    regs.ebx.w[0] = PXENV_GET_CACHED_INFO;
-    regs.es = SEG(gci);
-    /* regs.edi.w[0] = OFFS(gci); */
-
     bbuf = &gci[1];
 
     gci->Status = PXENV_STATUS_FAILURE;
@@ -66,9 +59,9 @@ int pxe_get_cached_info(int level, void **buf, size_t * len)
     gci->Buffer.seg = SEG(bbuf);
     gci->Buffer.offs = OFFS(bbuf);
 
-    __intcall(0x22, &regs, &regs);
+    err = pxe_call(PXENV_GET_CACHED_INFO, gci);
 
-    if (regs.eflags.l & EFLAGS_CF) {
+    if (err) {
 	err = -1;
 	goto exit;
     }
diff --git a/com32/lib/syslinux/pxe_get_nic.c b/com32/lib/syslinux/pxe_get_nic.c
index b301a75..6e256f9 100644
--- a/com32/lib/syslinux/pxe_get_nic.c
+++ b/com32/lib/syslinux/pxe_get_nic.c
@@ -42,25 +42,19 @@
    or -1 on invocation failure */
 int pxe_get_nic_type(t_PXENV_UNDI_GET_NIC_TYPE *gnt)
 {
-    com32sys_t regs;
     t_PXENV_UNDI_GET_NIC_TYPE *lgnt;
+    int err;
 
     lgnt = lzalloc(sizeof *lgnt);
     if (!lgnt)
 	return -1;
 
-    memset(&regs, 0, sizeof regs);
-    regs.eax.w[0] = 0x0009;
-    regs.ebx.w[0] = PXENV_UNDI_GET_NIC_TYPE;
-    regs.es = SEG(lgnt);
-    /* regs.edi.w[0] = OFFS(lgnt); */
-
-    __intcall(0x22, &regs, &regs);
+    err = pxe_call(PXENV_UNDI_GET_NIC_TYPE, lgnt);
 
     memcpy(gnt, lgnt, sizeof(t_PXENV_UNDI_GET_NIC_TYPE));
     lfree(lgnt);
 
-    if (regs.eflags.l & EFLAGS_CF)
+    if (err)
 	return -1;
 
     return gnt->Status;
diff --git a/com32/libupload/upload_tftp.c b/com32/libupload/upload_tftp.c
index 5e73c1c..6a0dacb 100644
--- a/com32/libupload/upload_tftp.c
+++ b/com32/libupload/upload_tftp.c
@@ -53,7 +53,6 @@ const char *tftp_string_error_message[]={
 static int send_ack_packet(struct tftp_state *tftp,
 			   const void *pkt, size_t len)
 {
-    com32sys_t ireg, oreg;
     t_PXENV_UDP_WRITE *uw;
     t_PXENV_UDP_READ  *ur;
     clock_t start;
@@ -67,9 +66,6 @@ static int send_ack_packet(struct tftp_state *tftp,
     uw = lmalloc(sizeof *uw + len);
     ur = lmalloc(sizeof *ur + RCV_BUF);
 
-    memset(&ireg, 0, sizeof ireg);
-    ireg.eax.w[0] = 0x0009;
-
     for (timeout = timeouts ; *timeout ; timeout++) {
 	memset(uw, 0, sizeof *uw);
 	memcpy(uw+1, pkt, len);
@@ -80,11 +76,7 @@ static int send_ack_packet(struct tftp_state *tftp,
 	uw->buffer_size = len;
 	uw->buffer = FAR_PTR(uw+1);
 
-	ireg.ebx.w[0] = PXENV_UDP_WRITE;
-	ireg.es = SEG(uw);
-	ireg.edi.w[0] = OFFS(uw);
-
-	__intcall(0x22, &ireg, &oreg);
+	pxe_call(PXENV_UDP_WRITE, uw);
 
 	start = times(NULL);
 
@@ -97,13 +89,9 @@ static int send_ack_packet(struct tftp_state *tftp,
 	    ur->buffer_size = RCV_BUF;
 	    ur->buffer = FAR_PTR(ur+1);
 
-	    ireg.ebx.w[0] = PXENV_UDP_READ;
-	    ireg.es = SEG(ur);
-	    ireg.edi.w[0] = OFFS(ur);
-	    __intcall(0x22, &ireg, &oreg);
+	    err = pxe_call(PXENV_UDP_READ, ur);
 
-	    if (!(oreg.eflags.l & EFLAGS_CF) &&
-		ur->status == PXENV_STATUS_SUCCESS &&
+	    if (!err &&	ur->status == PXENV_STATUS_SUCCESS &&
 		tftp->srv_ip == ur->src_ip &&
 		(tftp->srv_port == 0 ||
 		 tftp->srv_port == ur->s_port)) {
diff --git a/com32/modules/gpxecmd.c b/com32/modules/gpxecmd.c
index 9d4f456..d2d90a2 100644
--- a/com32/modules/gpxecmd.c
+++ b/com32/modules/gpxecmd.c
@@ -39,9 +39,6 @@ static void gpxecmd(const char **args)
 {
     char *q;
     struct s_PXENV_FILE_EXEC *fx;
-    com32sys_t reg;
-
-    memset(&reg, 0, sizeof reg);
 
     fx = lmalloc(sizeof *fx);
     if (!fx)
@@ -60,13 +57,7 @@ static void gpxecmd(const char **args)
     }
     *--q = '\0';
 
-    memset(&reg, 0, sizeof reg);
-    reg.eax.w[0] = 0x0009;
-    reg.ebx.w[0] = PXENV_FILE_EXEC;
-    reg.edi.w[0] = OFFS(fx);
-    reg.es = SEG(fx);
-
-    __intcall(0x22, &reg, &reg);
+    pxe_call(PXENV_FILE_EXEC, fx);
 
     /* This should not return... */
 }
diff --git a/com32/modules/pxechn.c b/com32/modules/pxechn.c
index 1902d4e..39ac72e 100644
--- a/com32/modules/pxechn.c
+++ b/com32/modules/pxechn.c
@@ -845,7 +845,6 @@ int pxechn_args(int argc, char *argv[], struct pxelinux_opt *pxe)
  */
 int dhcp_pkt2pxe(pxe_bootp_t *p, size_t len, int ptype)
 {
-    com32sys_t reg;
     t_PXENV_GET_CACHED_INFO *ci;
     void *cp;
     int rv = -1;
@@ -857,12 +856,7 @@ int dhcp_pkt2pxe(pxe_bootp_t *p, size_t len, int ptype)
     }
     ci->Status = PXENV_STATUS_FAILURE;
     ci->PacketType = ptype;
-    memset(&reg, 0, sizeof(reg));
-    reg.eax.w[0] = 0x0009;
-    reg.ebx.w[0] = PXENV_GET_CACHED_INFO;
-    reg.edi.w[0] = OFFS(ci);
-    reg.es = SEG(ci);
-    __intcall(0x22, &reg, &reg);
+    pxe_call(PXENV_GET_CACHED_INFO, ci);
 
     if (ci->Status != PXENV_STATUS_SUCCESS) {
 	dprintf("PXE Get Cached Info failed: %d\n", ci->Status);
@@ -1015,7 +1009,6 @@ int pxe_restart(char *ifn)
 {
     int rv = 0;
     struct pxelinux_opt pxe;
-    com32sys_t reg;
     t_PXENV_RESTART_TFTP *pxep;	/* PXENV callback Parameter */
 
     pxe.fn = ifn;
@@ -1030,7 +1023,6 @@ int pxe_restart(char *ifn)
 	goto ret;
     }
     printf("  Attempting to boot '%s'...\n\n", pxe.fn);
-    memset(&reg, 0, sizeof reg);
     if (!(pxep = lzalloc(sizeof(t_PXENV_RESTART_TFTP)))){
 	dprintf("Unable to lzalloc() for PXE call structure\n");
 	goto ret;
@@ -1044,12 +1036,8 @@ int pxe_restart(char *ifn)
 	pxep->ServerIPAddress, (unsigned int)pxep,
 	pxep->BufferSize, (unsigned int)pxep->Buffer);
     dprintf("PXENV_RESTART_TFTP status %d\n", pxep->Status);
-    reg.eax.w[0] = 0x0009;
-    reg.ebx.w[0] = PXENV_RESTART_TFTP;
-    reg.edi.w[0] = OFFS(pxep);
-    reg.es = SEG(pxep);
 
-    __intcall(0x22, &reg, &reg);
+    pxe_call(PXENV_RESTART_TFTP, pxep);
 
     printf("PXENV_RESTART_TFTP returned %d\n", pxep->Status);
     lfree(pxep);
diff --git a/com32/modules/sanboot.c b/com32/modules/sanboot.c
index d55fbc0..ff55f68 100644
--- a/com32/modules/sanboot.c
+++ b/com32/modules/sanboot.c
@@ -39,9 +39,6 @@ static void sanboot(const char **args)
 {
     char *q;
     struct s_PXENV_FILE_EXEC *fx;
-    com32sys_t reg;
-
-    memset(&reg, 0, sizeof reg);
 
     fx = lmalloc(sizeof *fx);
     if (!fx)
@@ -61,13 +58,7 @@ static void sanboot(const char **args)
 	args++;
     }
 
-    memset(&reg, 0, sizeof reg);
-    reg.eax.w[0] = 0x0009;
-    reg.ebx.w[0] = PXENV_FILE_EXEC;
-    reg.edi.w[0] = OFFS(fx);
-    reg.es = SEG(fx);
-
-    __intcall(0x22, &reg, &reg);
+    pxe_call(PXENV_FILE_EXEC, fx);
 
     /* This should not return... */
 }
diff --git a/com32/samples/resolv.c b/com32/samples/resolv.c
index bd49d9f..f4a0e52 100644
--- a/com32/samples/resolv.c
+++ b/com32/samples/resolv.c
@@ -16,6 +16,7 @@
  * Resolve an IP address
  */
 
+#include <syslinux/pxe_api.h>
 #include <string.h>
 #include <stdio.h>
 #include <console.h>
@@ -24,21 +25,7 @@
 
 uint32_t resolv(const char *name)
 {
-    com32sys_t reg;
-
-    strcpy((char *)__com32.cs_bounce, name);
-
-    memset(&reg, 0, sizeof reg);
-    reg.eax.w[0] = 0x0010;
-    reg.ebx.w[0] = OFFS(__com32.cs_bounce);
-    reg.es = SEG(__com32.cs_bounce);
-
-    __intcall(0x22, &reg, &reg);
-
-    if (reg.eflags.l & EFLAGS_CF)
-	return 0;
-    else
-	return reg.eax.l;
+    return dns_resolv(name);
 }
 
 int main(int argc, char *argv[])
diff --git a/core/fs/pxe/pxe.c b/core/fs/pxe/pxe.c
index 1e64b58..6f490ce 100644
--- a/core/fs/pxe/pxe.c
+++ b/core/fs/pxe/pxe.c
@@ -1653,7 +1653,7 @@ int reset_pxe(void)
  * This function unloads the PXE and UNDI stacks and
  * unclaims the memory.
  */
-void unload_pxe(void)
+void unload_pxe(uint16_t flags)
 {
     /* PXE unload sequences */
     static const uint8_t new_api_unload[] = {
@@ -1682,7 +1682,7 @@ void unload_pxe(void)
     dprintf("FBM after reset_pxe = %d, err = %d\n", BIOS_fbm, err);
 
     /* If we want to keep PXE around, we still need to reset it */
-    if (KeepPXE || err)
+    if (flags || err)
 	return;
 
     dprintf("APIVer = %04x\n", APIVer);
diff --git a/core/fs/pxe/pxe.h b/core/fs/pxe/pxe.h
index 47ed8f0..c754106 100644
--- a/core/fs/pxe/pxe.h
+++ b/core/fs/pxe/pxe.h
@@ -232,14 +232,12 @@ static inline uint32_t gateway(uint32_t ip)
 
 /* pxe.c */
 bool ip_ok(uint32_t);
-int pxe_call(int, void *);
 
 /* dhcp_options.c */
 void parse_dhcp(const void *, size_t);
 
 /* dnsresolv.c */
 int dns_mangle(char **, const char *);
-uint32_t dns_resolv(const char *);
 
 /* idle.c */
 void pxe_idle_init(void);


More information about the Syslinux-commits mailing list