[syslinux:master] memdisk: make mstructs.h includable from Linux

syslinux-bot for H. Peter Anvin hpa at linux.intel.com
Mon Jun 21 17:33:07 PDT 2010


Commit-ID:  7556a891b2f28617f6c95aa271aeaf29883d0981
Gitweb:     http://syslinux.zytor.com/commit/7556a891b2f28617f6c95aa271aeaf29883d0981
Author:     H. Peter Anvin <hpa at linux.intel.com>
AuthorDate: Mon, 21 Jun 2010 17:29:11 -0700
Committer:  H. Peter Anvin <hpa at linux.intel.com>
CommitDate: Mon, 21 Jun 2010 17:29:11 -0700

memdisk: make mstructs.h includable from Linux

Make mstructs.h includable from a Linux utility.

Signed-off-by: H. Peter Anvin <hpa at linux.intel.com>


---
 dosutil/mdiskchk.c   |    6 +-----
 dosutil/mdiskchk.com |  Bin 8246 -> 8106 bytes
 memdisk/Makefile     |    2 +-
 memdisk/compiler.h   |    9 +++++++++
 memdisk/eltorito.h   |    1 +
 memdisk/memdisk.h    |    4 ----
 memdisk/mstructs.h   |   11 +++--------
 memdisk/setup.c      |   19 +++++++++----------
 8 files changed, 24 insertions(+), 28 deletions(-)

diff --git a/dosutil/mdiskchk.c b/dosutil/mdiskchk.c
index f7bde61..47bb08e 100644
--- a/dosutil/mdiskchk.c
+++ b/dosutil/mdiskchk.c
@@ -31,10 +31,6 @@ typedef unsigned long uint32_t;
 typedef unsigned short uint16_t;
 typedef unsigned char uint8_t;
 
-/* OpenWatcom uses a packed structure prefix */
-#define MEMDISK_PACKED_PREFIX _Packed
-#define MEMDISK_PACKED_POSTFIX
-
 /* Pull in MEMDISK common structures */
 #include "../memdisk/mstructs.h"
 
@@ -277,7 +273,7 @@ static MDISKCHK_FUNC_DECL(show_safe_hooks)
 	    struct patch_area far *patch_area;
 
 	    /* Copy the MDI from the mBFT.  Offset is a misnomer here */
-	    mbft = MK_FP(hook->mBFT.offset >> 4, 0);	/* Always aligned */
+	    mbft = MK_FP(hook->mbft >> 4, 0);	/* Always aligned */
 	    _fmemcpy((void far *)&m, &mbft->mdi, sizeof(struct mdi));
 	    /* Adjust C/H/S since we actually know
 	     * it directly for any MEMDISK with an mBFT
diff --git a/dosutil/mdiskchk.com b/dosutil/mdiskchk.com
index b18a187..22ccfe5 100644
Binary files a/dosutil/mdiskchk.com and b/dosutil/mdiskchk.com differ
diff --git a/memdisk/Makefile b/memdisk/Makefile
index 2e6330f..d2f20c5 100644
--- a/memdisk/Makefile
+++ b/memdisk/Makefile
@@ -16,7 +16,7 @@ include $(topdir)/MCONFIG.embedded
 -include $(topdir)/version.mk
 
 INCLUDES = -I$(topdir)/com32/include
-CFLAGS  += -DDATE='"$(DATE)"'
+CFLAGS  += -D__MEMDISK__ -DDATE='"$(DATE)"'
 LDFLAGS  = $(GCCOPT) -g
 NASM     = nasm
 NASMOPT  = -O9999
diff --git a/memdisk/compiler.h b/memdisk/compiler.h
new file mode 100644
index 0000000..d1b03e0
--- /dev/null
+++ b/memdisk/compiler.h
@@ -0,0 +1,9 @@
+
+#ifdef __WATCOMC__
+# define MEMDISK_PACKED_PREFIX _Packed
+# define MEMDISK_PACKED_POSTFIX
+#else
+/* Assume GNU C for now */
+# define MEMDISK_PACKED_PREFIX
+# define MEMDISK_PACKED_POSTFIX __attribute__((packed))
+#endif
diff --git a/memdisk/eltorito.h b/memdisk/eltorito.h
index 27b570d..494c4a1 100644
--- a/memdisk/eltorito.h
+++ b/memdisk/eltorito.h
@@ -17,6 +17,7 @@
  */
 
 #include <stdint.h>
+#include "compiler.h"
 
 /* EDD-4 Bootable Optical Disc Drive Boot Volume Descriptor */
 MEMDISK_PACKED_PREFIX
diff --git a/memdisk/memdisk.h b/memdisk/memdisk.h
index af40823..b6b277a 100644
--- a/memdisk/memdisk.h
+++ b/memdisk/memdisk.h
@@ -134,8 +134,4 @@ extern int check_zip(void *indata, uint32_t size, uint32_t * zbytes_p,
 extern void *unzip(void *indata, uint32_t zbytes, uint32_t dbytes,
 		   uint32_t orig_crc, void *target);
 
-/* Structure packing can be different for different compilers */
-#define MEMDISK_PACKED_PREFIX
-#define MEMDISK_PACKED_POSTFIX __attribute__ (( packed ))
-
 #endif
diff --git a/memdisk/mstructs.h b/memdisk/mstructs.h
index e060ace..c2e6352 100644
--- a/memdisk/mstructs.h
+++ b/memdisk/mstructs.h
@@ -16,6 +16,7 @@
 /* These structures are common to MEMDISK and MDISKCHK.COM */
 
 #include <stdint.h>
+#include "compiler.h"
 
 struct seg_off {
     uint16_t offset;
@@ -38,10 +39,7 @@ struct safe_hook {
     real_addr_t old_hook;	/* SEG:OFF for previous INT 13h hook */
     uint32_t flags;		/* "Safe hook" flags */
     /* The next field is a MEMDISK extension to the "safe hook" structure */
-    union {
-	uint32_t offset;	/* Offset from hook to the mBFT; refilled */
-	struct mBFT *ptr;	/* by setup() with the physical address */
-    } mBFT;
+    uint32_t mbft;
 } MEMDISK_PACKED_POSTFIX;
 
 struct memdisk_header {
@@ -106,10 +104,7 @@ struct mdi {
 MEMDISK_PACKED_PREFIX
 struct mBFT {
     struct acpi_description_header acpi;
-    union {
-	struct safe_hook *ptr;
-	uint32_t phys_addr;
-    } safe_hook;		/* "Safe hook" physical address */
+    uint32_t safe_hook;		/* "Safe hook" physical address */
     struct mdi mdi;
 } MEMDISK_PACKED_POSTFIX;
 
diff --git a/memdisk/setup.c b/memdisk/setup.c
index ffaa2c6..20b48c4 100644
--- a/memdisk/setup.c
+++ b/memdisk/setup.c
@@ -718,6 +718,7 @@ void setup(const struct real_mode_args *rm_args_ptr)
     char *memdisk_hook;
     struct memdisk_header *hptr;
     struct patch_area *pptr;
+    struct mBFT *mbft;
     uint16_t driverseg;
     uint32_t driverptr, driveraddr;
     uint16_t dosmem_k;
@@ -1090,8 +1091,8 @@ void setup(const struct real_mode_args *rm_args_ptr)
     hptr->safe_hook.old_hook.uint32 = pptr->mdi.oldint13.uint32;
 
     /* Re-fill the "safe hook" mBFT field with the physical address */
-    hptr->safe_hook.mBFT.ptr =
-        (struct mBFT *)(((const char *)hptr) + hptr->safe_hook.mBFT.offset);
+    mbft = (struct mBFT *)(((const char *)hptr) + hptr->safe_hook.mbft);
+    hptr->safe_hook.mbft = (size_t)mbft;
 
     /* Update various BIOS magic data areas (gotta love this shit) */
 
@@ -1128,14 +1129,12 @@ void setup(const struct real_mode_args *rm_args_ptr)
     }
 
     /* Complete the mBFT */
-    hptr->safe_hook.mBFT.ptr->acpi.signature[0] = 'm';	/* "mBFT" */
-    hptr->safe_hook.mBFT.ptr->acpi.signature[1] = 'B';
-    hptr->safe_hook.mBFT.ptr->acpi.signature[2] = 'F';
-    hptr->safe_hook.mBFT.ptr->acpi.signature[3] = 'T';
-    hptr->safe_hook.mBFT.ptr->safe_hook.ptr = &hptr->safe_hook;
-    hptr->safe_hook.mBFT.ptr->acpi.checksum =
-	-checksum_buf(hptr->safe_hook.mBFT.ptr,
-		      hptr->safe_hook.mBFT.ptr->acpi.length);
+    mbft->acpi.signature[0] = 'm';	/* "mBFT" */
+    mbft->acpi.signature[1] = 'B';
+    mbft->acpi.signature[2] = 'F';
+    mbft->acpi.signature[3] = 'T';
+    mbft->safe_hook = (size_t)&hptr->safe_hook;
+    mbft->acpi.checksum = -checksum_buf(mbft, mbft->acpi.length);
 
     /* Install the interrupt handlers */
     printf("old: int13 = %08x  int15 = %08x  int1e = %08x\n",



More information about the Syslinux-commits mailing list