com32: Avoid gpxe detection code duplication
authorErwan Velu <erwan.velu@free.fr>
Sun, 29 Nov 2009 14:20:33 +0000 (15:20 +0100)
committerErwan Velu <erwan.velu@free.fr>
Fri, 4 Dec 2009 09:11:15 +0000 (10:11 +0100)
Impact: avoid code duplication

This will make code more generic, hdt will need it ;)

com32/include/sys/gpxe.h [new file with mode: 0644]
com32/lib/Makefile
com32/lib/sys/gpxe.c [new file with mode: 0644]
com32/modules/gpxecmd.c
com32/modules/sanboot.c

diff --git a/com32/include/sys/gpxe.h b/com32/include/sys/gpxe.h
new file mode 100644 (file)
index 0000000..adbbefe
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef _GPXE_H
+#define _GPXE_H
+
+#include <com32.h>
+
+struct s_PXENV_FILE_CHECK_API {
+    uint16_t Status;
+    uint16_t Size;
+    uint32_t Magic;
+    uint32_t Provider;
+    uint32_t APIMask;
+    uint32_t Flags;
+};
+
+bool is_gpxe(void);
+#endif
index f1e2680..d136d2b 100644 (file)
@@ -57,6 +57,8 @@ LIBOBJS = \
        \
        sys/libansi.o                                                   \
        \
+       sys/gpxe.o                                                      \
+       \
        sys/ansicon_write.o sys/ansiserial_write.o                      \
        \
        sys/vesacon_write.o sys/vesaserial_write.o                      \
diff --git a/com32/lib/sys/gpxe.c b/com32/lib/sys/gpxe.c
new file mode 100644 (file)
index 0000000..fae03f8
--- /dev/null
@@ -0,0 +1,45 @@
+#include <sys/gpxe.h>
+#include <syslinux/config.h>
+#include <string.h>
+
+bool is_gpxe(void)
+{
+    const struct syslinux_version *sv;
+    com32sys_t reg;
+    struct s_PXENV_FILE_CHECK_API *fca;
+
+    sv = syslinux_version();
+    if (sv->filesystem != SYSLINUX_FS_PXELINUX)
+        return false;           /* Not PXELINUX */
+
+    fca = __com32.cs_bounce;
+    memset(fca, 0, sizeof *fca);
+    fca->Size = sizeof *fca;
+    fca->Magic = 0x91d447b2;
+
+    memset(&reg, 0, sizeof reg);
+    reg.eax.w[0] = 0x0009;
+    reg.ebx.w[0] = 0x00e6;      /* PXENV_FILE_API_CHECK */
+    reg.edi.w[0] = OFFS(fca);
+    reg.es = SEG(fca);
+
+    __intcall(0x22, &reg, &reg);
+
+    if (reg.eflags.l & EFLAGS_CF)
+        return false;           /* Cannot invoke PXE stack */
+
+    if (reg.eax.w[0] || fca->Status)
+        return false;           /* PXE failure */
+
+    if (fca->Magic != 0xe9c17b20)
+        return false;           /* Incorrect magic */
+
+    if (fca->Size < sizeof *fca)
+        return false;           /* Short return */
+
+    if (!(fca->APIMask & (1 << 5)))
+        return false;           /* No FILE EXEC */
+
+    return true;
+}
+
index de6ffb2..057659b 100644 (file)
 #include <stdio.h>
 #include <console.h>
 #include <com32.h>
-#include <stdbool.h>
 #include <string.h>
-#include <syslinux/config.h>
+#include <sys/gpxe.h>
 
 struct segoff16 {
     uint16_t offs, seg;
 };
 
-struct s_PXENV_FILE_CHECK_API {
-    uint16_t Status;
-    uint16_t Size;
-    uint32_t Magic;
-    uint32_t Provider;
-    uint32_t APIMask;
-    uint32_t Flags;
-};
-
-static bool is_gpxe(void)
-{
-    const struct syslinux_version *sv;
-    com32sys_t reg;
-    struct s_PXENV_FILE_CHECK_API *fca;
-
-    sv = syslinux_version();
-    if (sv->filesystem != SYSLINUX_FS_PXELINUX)
-       return false;           /* Not PXELINUX */
-
-    fca = __com32.cs_bounce;
-    memset(fca, 0, sizeof *fca);
-    fca->Size = sizeof *fca;
-    fca->Magic = 0x91d447b2;
-
-    memset(&reg, 0, sizeof reg);
-    reg.eax.w[0] = 0x0009;
-    reg.ebx.w[0] = 0x00e6;     /* PXENV_FILE_API_CHECK */
-    reg.edi.w[0] = OFFS(fca);
-    reg.es = SEG(fca);
-
-    __intcall(0x22, &reg, &reg);
-
-    if (reg.eflags.l & EFLAGS_CF)
-       return false;           /* Cannot invoke PXE stack */
-
-    if (reg.eax.w[0] || fca->Status)
-       return false;           /* PXE failure */
-
-    if (fca->Magic != 0xe9c17b20)
-       return false;           /* Incorrect magic */
-
-    if (fca->Size < sizeof *fca)
-       return false;           /* Short return */
-
-    if (!(fca->APIMask & (1 << 5)))
-       return false;           /* No FILE EXEC */
-
-    return true;
-}
-
 struct s_PXENV_FILE_EXEC {
     uint16_t Status;
     struct segoff16 Command;
index eee9f44..46df6bc 100644 (file)
 #include <stdio.h>
 #include <console.h>
 #include <com32.h>
-#include <stdbool.h>
 #include <string.h>
-#include <syslinux/config.h>
+#include <sys/gpxe.h>
 
 struct segoff16 {
     uint16_t offs, seg;
 };
 
-struct s_PXENV_FILE_CHECK_API {
-    uint16_t Status;
-    uint16_t Size;
-    uint32_t Magic;
-    uint32_t Provider;
-    uint32_t APIMask;
-    uint32_t Flags;
-};
-
-static bool is_gpxe(void)
-{
-    const struct syslinux_version *sv;
-    com32sys_t reg;
-    struct s_PXENV_FILE_CHECK_API *fca;
-
-    sv = syslinux_version();
-    if (sv->filesystem != SYSLINUX_FS_PXELINUX)
-       return false;           /* Not PXELINUX */
-
-    fca = __com32.cs_bounce;
-    memset(fca, 0, sizeof *fca);
-    fca->Size = sizeof *fca;
-    fca->Magic = 0x91d447b2;
-
-    memset(&reg, 0, sizeof reg);
-    reg.eax.w[0] = 0x0009;
-    reg.ebx.w[0] = 0x00e6;     /* PXENV_FILE_API_CHECK */
-    reg.edi.w[0] = OFFS(fca);
-    reg.es = SEG(fca);
-
-    __intcall(0x22, &reg, &reg);
-
-    if (reg.eflags.l & EFLAGS_CF)
-       return false;           /* Cannot invoke PXE stack */
-
-    if (reg.eax.w[0] || fca->Status)
-       return false;           /* PXE failure */
-
-    if (fca->Magic != 0xe9c17b20)
-       return false;           /* Incorrect magic */
-
-    if (fca->Size < sizeof *fca)
-       return false;           /* Short return */
-
-    if (!(fca->APIMask & (1 << 5)))
-       return false;           /* No FILE EXEC */
-
-    return true;
-}
-
 struct s_PXENV_FILE_EXEC {
     uint16_t Status;
     struct segoff16 Command;