[syslinux:pathbased] memdisk: Use real_addr_t for SEG:OFF fields

syslinux-bot for Shao Miller shao.miller at yrdsb.edu.on.ca
Thu Jun 17 11:45:22 PDT 2010


Commit-ID:  345a7cba6786de010359607e40f96f6fccbf40a5
Gitweb:     http://syslinux.zytor.com/commit/345a7cba6786de010359607e40f96f6fccbf40a5
Author:     Shao Miller <shao.miller at yrdsb.edu.on.ca>
AuthorDate: Tue, 9 Mar 2010 14:45:12 -0500
Committer:  Shao Miller <shao.miller at yrdsb.edu.on.ca>
CommitDate: Fri, 11 Jun 2010 01:49:10 +0000

memdisk: Use real_addr_t for SEG:OFF fields

We used uint32_t in a few places where it's also handy
to refer to those fields' segment and offset components.
Now we can do so via the real_addr_t union type.

Additionally, there are a couple of places where we now
have pointer fields instead of uint32_t fields, because
we know what kind of struct the field is pointing to.

Signed-off-by: Shao Miller <shao.miller at yrdsb.edu.on.ca>


---
 memdisk/mstructs.h |   37 ++++++++++++++++++++++++++-----------
 memdisk/setup.c    |   32 +++++++++++++++-----------------
 2 files changed, 41 insertions(+), 28 deletions(-)

diff --git a/memdisk/mstructs.h b/memdisk/mstructs.h
index 635e47e..d6b6265 100644
--- a/memdisk/mstructs.h
+++ b/memdisk/mstructs.h
@@ -15,17 +15,30 @@
 
 /* These structures are common to MEMDISK and MDISKCHK.COM */
 
+#include <stdint.h>
+
+struct seg_off {
+    uint16_t offset;
+    uint16_t segment;
+};
+
+typedef union {
+    struct seg_off seg_off;
+    uint32_t uint32;
+} real_addr_t;
+
 MEMDISK_PACKED_PREFIX
 struct safe_hook {
     uint8_t jump[3];		/* Max. three bytes for jump */
     uint8_t signature[8];	/* "$INT13SF" */
     uint8_t vendor[8];		/* "MEMDISK " */
-    uint32_t old_hook;		/* SEG:OFF for previous INT 13h 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 */
-    uint32_t mBFT;		/* Offset from hook to the mBFT; refilled
-				 * by setup() with the physical address
-				 */
+    union {
+	uint32_t offset;	/* Offset from hook to the mBFT; refilled */
+	struct mBFT *ptr;	/* by setup() with the physical address */
+    } mBFT;
 } MEMDISK_PACKED_POSTFIX;
 
 /* Requirement for struct acpi_description_header */
@@ -34,7 +47,10 @@ struct safe_hook {
 MEMDISK_PACKED_PREFIX
 struct mBFT {
     struct acpi_description_header acpi;
-    uint32_t safe_hook;		/* "Safe hook" physical address */
+    struct safe_hook *safe_hook;	/* "Safe hook" physical address */
+    /* An mBFT is 70 bytes in total */
+    uint8_t _pad[70 - (sizeof(struct acpi_description_header) +
+		       sizeof(uint32_t))];
 } MEMDISK_PACKED_POSTFIX;
 
 MEMDISK_PACKED_PREFIX
@@ -47,7 +63,7 @@ struct edd_dpt {
     uint32_t s;			/* Physical sectors/track (count!) */
     uint64_t sectors;		/* Total sectors */
     uint16_t bytespersec;	/* Bytes/sector */
-    uint16_t dpte_off, dpte_seg;	/* DPTE pointer */
+    real_addr_t dpte;		/* DPTE pointer */
     uint16_t dpikey;		/* Device Path Info magic */
     uint8_t  dpilen;		/* Device Path Info length */
     uint8_t  res1;		/* Reserved */
@@ -67,10 +83,10 @@ MEMDISK_PACKED_PREFIX
 struct patch_area {
     uint32_t diskbuf;
     uint32_t disksize;
-    uint16_t cmdline_off, cmdline_seg;
+    real_addr_t cmdline;
 
-    uint32_t oldint13;
-    uint32_t oldint15;
+    real_addr_t oldint13;
+    real_addr_t oldint15;
 
     uint16_t olddosmem;
     uint8_t bootloaderid;
@@ -107,6 +123,5 @@ struct patch_area {
 
     dpt_t dpt;
     struct edd_dpt edd_dpt;
-    struct edd4_cd_pkt cd_pkt; /* Only really in a memdisk_iso_* hook */
+    struct edd4_cd_pkt cd_pkt;	/* Only really in a memdisk_iso_* hook */
 } MEMDISK_PACKED_POSTFIX;
-
diff --git a/memdisk/setup.c b/memdisk/setup.c
index 067a8ac..1e0655e 100644
--- a/memdisk/setup.c
+++ b/memdisk/setup.c
@@ -1032,8 +1032,8 @@ void setup(const struct real_mode_args *rm_args_ptr)
     /* Anything beyond the end is for the stack */
     pptr->mystack = (uint16_t) (stddosmem - driveraddr);
 
-    pptr->oldint13 = rdz_32(BIOS_INT13);
-    pptr->oldint15 = rdz_32(BIOS_INT15);
+    pptr->oldint13.uint32 = rdz_32(BIOS_INT13);
+    pptr->oldint15.uint32 = rdz_32(BIOS_INT15);
 
     /* Adjust the E820 table: if there are null ranges (type 0)
        at the end, change them to type end of list (-1).
@@ -1048,7 +1048,7 @@ void setup(const struct real_mode_args *rm_args_ptr)
 	bios_drives = 0;
 	pptr->drivecnt = 0;
 	no_bpt = 1;
-	pptr->oldint13 = driverptr + hptr->iret_offs;
+	pptr->oldint13.uint32 = driverptr + hptr->iret_offs;
 	wrz_8(BIOS_EQUIP, rdz_8(BIOS_EQUIP) & ~0xc1);
 	wrz_8(BIOS_HD_COUNT, 0);
     } else if (getcmditem("nopass") != CMD_NOTFOUND) {
@@ -1097,7 +1097,7 @@ void setup(const struct real_mode_args *rm_args_ptr)
     }
 
     /* Note the previous INT 13h hook in the "safe hook" structure */
-    safe_hook->old_hook = pptr->oldint13;
+    safe_hook->old_hook.uint32 = pptr->oldint13.uint32;
 
     /* Add ourselves to the drive count */
     pptr->drivecnt++;
@@ -1114,8 +1114,8 @@ void setup(const struct real_mode_args *rm_args_ptr)
 	pptr->driveshiftlimit);
 
     /* Pointer to the command line */
-    pptr->cmdline_off = bin_size + (nranges + 1) * sizeof(ranges[0]);
-    pptr->cmdline_seg = driverseg;
+    pptr->cmdline.seg_off.offset = bin_size + (nranges + 1) * sizeof(ranges[0]);
+    pptr->cmdline.seg_off.segment = driverseg;
 
     /* Copy driver followed by E820 table followed by command line */
     {
@@ -1134,7 +1134,8 @@ void setup(const struct real_mode_args *rm_args_ptr)
     }
 
     /* Re-fill the "safe hook" mBFT field with the physical address */
-    safe_hook->mBFT += (uint32_t)hptr;
+    safe_hook->mBFT.ptr =
+        (struct mBFT *)(((const char *)hptr) + safe_hook->mBFT.offset);
 
     /* Update various BIOS magic data areas (gotta love this shit) */
 
@@ -1170,16 +1171,13 @@ void setup(const struct real_mode_args *rm_args_ptr)
     }
 
     /* Complete the mBFT */
-    {
-	struct mBFT *mBFT = (struct mBFT *)safe_hook->mBFT;
-
-	mBFT->acpi.signature[0] = 'm';	/* "mBFT" */
-	mBFT->acpi.signature[1] = 'B';
-	mBFT->acpi.signature[2] = 'F';
-	mBFT->acpi.signature[3] = 'T';
-	mBFT->safe_hook = (uint32_t)safe_hook;
-	mBFT->acpi.checksum = -checksum_buf(mBFT, mBFT->acpi.length);
-    }
+    safe_hook->mBFT.ptr->acpi.signature[0] = 'm';	/* "mBFT" */
+    safe_hook->mBFT.ptr->acpi.signature[1] = 'B';
+    safe_hook->mBFT.ptr->acpi.signature[2] = 'F';
+    safe_hook->mBFT.ptr->acpi.signature[3] = 'T';
+    safe_hook->mBFT.ptr->safe_hook = safe_hook;
+    safe_hook->mBFT.ptr->acpi.checksum =
+	-checksum_buf(safe_hook->mBFT.ptr, safe_hook->mBFT.ptr->acpi.length);
 
     /* Install the interrupt handlers */
     printf("old: int13 = %08x  int15 = %08x  int1e = %08x\n",



More information about the Syslinux-commits mailing list