memdisk: Use MEMDISK header to access "safe hook"
authorShao Miller <shao.miller@yrdsb.edu.on.ca>
Tue, 9 Mar 2010 21:02:39 +0000 (16:02 -0500)
committerShao Miller <shao.miller@yrdsb.edu.on.ca>
Fri, 11 Jun 2010 01:49:10 +0000 (01:49 +0000)
This commit moves the MEMDISK header structure into
the common structures header file.

It also adds the "safe hook" structure to the MEMDISK
header structure, since that matches what's in the hook
binaries.  Thus, we access the "safe hook" via the
header pointer, instead of separately.

Tested against a DOS floppy image including an
experimental MDISKCHK.COM and also gainst WinVBlock.

Signed-off-by: Shao Miller <shao.miller@yrdsb.edu.on.ca>
memdisk/mstructs.h
memdisk/setup.c

index d6b6265..ee9568f 100644 (file)
@@ -41,6 +41,15 @@ struct safe_hook {
     } mBFT;
 } MEMDISK_PACKED_POSTFIX;
 
+struct memdisk_header {
+    uint16_t int13_offs;
+    uint16_t int15_offs;
+    uint16_t patch_offs;
+    uint16_t total_size;
+    uint16_t iret_offs;
+    struct safe_hook safe_hook;
+};
+
 /* Requirement for struct acpi_description_header */
 #include "../memdisk/acpi.h"
 
index 1e0655e..9f9eb7d 100644 (file)
@@ -39,14 +39,6 @@ extern const char _binary_memdisk_iso_2048_bin_start[];
 extern const char _binary_memdisk_iso_2048_bin_end[];
 extern const char _binary_memdisk_iso_2048_bin_size[];
 
-struct memdisk_header {
-    uint16_t int13_offs;
-    uint16_t int15_offs;
-    uint16_t patch_offs;
-    uint16_t total_size;
-    uint16_t iret_offs;
-};
-
 /* The Disk Parameter Table may be required */
 typedef union {
     struct hd_dpt {
@@ -758,7 +750,6 @@ void setup(const struct real_mode_args *rm_args_ptr)
     unsigned int bin_size;
     char *memdisk_hook;
     struct memdisk_header *hptr;
-    struct safe_hook *safe_hook;
     struct patch_area *pptr;
     uint16_t driverseg;
     uint32_t driverptr, driveraddr;
@@ -842,7 +833,6 @@ void setup(const struct real_mode_args *rm_args_ptr)
 
     /* Figure out where it needs to go */
     hptr = (struct memdisk_header *)memdisk_hook;
-    safe_hook = (struct safe_hook *)(memdisk_hook + hptr->int13_offs);
     pptr = (struct patch_area *)(memdisk_hook + hptr->patch_offs);
 
     dosmem_k = rdz_16(BIOS_BASEMEM);
@@ -1096,9 +1086,6 @@ 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.uint32 = pptr->oldint13.uint32;
-
     /* Add ourselves to the drive count */
     pptr->drivecnt++;
 
@@ -1123,7 +1110,6 @@ void setup(const struct real_mode_args *rm_args_ptr)
 
        /* Adjust these pointers to point to the installed image */
        /* Careful about the order here... the image isn't copied yet! */
-       safe_hook = (struct safe_hook *)(dpp + hptr->int13_offs);
        pptr = (struct patch_area *)(dpp + hptr->patch_offs);
        hptr = (struct memdisk_header *)dpp;
 
@@ -1133,9 +1119,12 @@ void setup(const struct real_mode_args *rm_args_ptr)
        dpp = mempcpy(dpp, shdr->cmdline, cmdline_len);
     }
 
+    /* Note the previous INT 13h hook in the "safe hook" structure */
+    hptr->safe_hook.old_hook.uint32 = pptr->oldint13.uint32;
+
     /* Re-fill the "safe hook" mBFT field with the physical address */
-    safe_hook->mBFT.ptr =
-        (struct mBFT *)(((const char *)hptr) + safe_hook->mBFT.offset);
+    hptr->safe_hook.mBFT.ptr =
+        (struct mBFT *)(((const char *)hptr) + hptr->safe_hook.mBFT.offset);
 
     /* Update various BIOS magic data areas (gotta love this shit) */
 
@@ -1171,13 +1160,14 @@ void setup(const struct real_mode_args *rm_args_ptr)
     }
 
     /* Complete the mBFT */
-    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);
+    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 = &hptr->safe_hook;
+    hptr->safe_hook.mBFT.ptr->acpi.checksum =
+       -checksum_buf(hptr->safe_hook.mBFT.ptr,
+                     hptr->safe_hook.mBFT.ptr->acpi.length);
 
     /* Install the interrupt handlers */
     printf("old: int13 = %08x  int15 = %08x  int1e = %08x\n",