[probe] Split GRUB4DOS out into its own module
authorShao Miller <Shao.Miller@yrdsb.edu.on.ca>
Tue, 29 Dec 2009 02:58:36 +0000 (21:58 -0500)
committerShao Miller <Shao.Miller@yrdsb.edu.on.ca>
Tue, 29 Dec 2009 02:59:01 +0000 (21:59 -0500)
GRUB4DOS specifics are now in their own module.

Probing of the aBFT for a boot-time AoE disk should
undergo the same treatment.

CHANGES.log
WinVBlock.dev
config.bat
src/grub4dos.c [new file with mode: 0644]
src/grub4dos.h [new file with mode: 0644]
src/probe.c

index 7adfe06..787a860 100644 (file)
@@ -1,4 +1,15 @@
 Author: Shao Miller <Shao.Miller@yrdsb.edu.on.ca>\r
+Date:   Mon Dec 28 21:58:36 2009 -0500\r
+\r
+    [probe] Split GRUB4DOS out into its own module\r
+    \r
+    GRUB4DOS specifics are now in their own module.\r
+    \r
+    Probing of the aBFT for a boot-time AoE disk should\r
+    undergo the same treatment.\r
+\r
+commit 91dcb15f46e362f84cfecbbf30783dfafe95534a\r
+Author: Shao Miller <Shao.Miller@yrdsb.edu.on.ca>\r
 Date:   Mon Dec 28 21:38:36 2009 -0500\r
 \r
     [probe] Split MEMDISK out into its own module\r
index d2aebf8..ac9288b 100644 (file)
@@ -1,7 +1,7 @@
 [Project]\r
 FileName=WinVBlock.dev\r
 Name=WinVBlock\r
-UnitCount=38\r
+UnitCount=40\r
 PchHead=-1\r
 PchSource=-1\r
 Ver=3\r
@@ -463,3 +463,23 @@ Priority=1000
 OverrideBuildCmd=0\r
 BuildCmd=\r
 \r
+[Unit39]\r
+FileName=src\grub4dos.h\r
+CompileCpp=1\r
+Folder=WinVBlock\r
+Compile=1\r
+Link=1\r
+Priority=1000\r
+OverrideBuildCmd=0\r
+BuildCmd=\r
+\r
+[Unit40]\r
+FileName=src\grub4dos.c\r
+CompileCpp=1\r
+Folder=WinVBlock\r
+Compile=1\r
+Link=1\r
+Priority=1000\r
+OverrideBuildCmd=0\r
+BuildCmd=\r
+\r
index 07b827a..9fae289 100644 (file)
@@ -2,5 +2,5 @@ rem This is the root directory of the ddk.
 set ddkdir=c:\winddk\6001.18001\r
 \r
 rem Next two lines are duplicated in Makefile, edit both when adding files or changing pxe style.\r
-set c=driver.c registry.c bus.c bus_pnp.c bus_dev_ctl.c disk.c ramdisk.c memdisk.c disk_pnp.c disk_dev_ctl.c disk_scsi.c aoe.c protocol.c debug.c probe.c winvblock.rc\r
+set c=driver.c registry.c bus.c bus_pnp.c bus_dev_ctl.c disk.c ramdisk.c memdisk.c grub4dos.c disk_pnp.c disk_dev_ctl.c disk_scsi.c aoe.c protocol.c debug.c probe.c winvblock.rc\r
 set pxestyle=asm\r
diff --git a/src/grub4dos.c b/src/grub4dos.c
new file mode 100644 (file)
index 0000000..c55b5e6
--- /dev/null
@@ -0,0 +1,187 @@
+/**
+ * Copyright (C) 2009, Shao Miller <shao.miller@yrdsb.edu.on.ca>.
+ *
+ * This file is part of WinVBlock, derived from WinAoE.
+ *
+ * WinVBlock is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * WinVBlock is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with WinVBlock.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * @file
+ *
+ * GRUB4DOS RAM disk specifics
+ *
+ */
+
+#include <stdio.h>
+#include <ntddk.h>
+
+#include "winvblock.h"
+#include "portable.h"
+#include "irp.h"
+#include "driver.h"
+#include "mount.h"
+#include "disk.h"
+#include "bus.h"
+#include "ramdisk.h"
+#include "debug.h"
+#include "probe.h"
+
+/* From GRUB4DOS 0.4.4's stage2/shared.h */
+winvblock__def_struct ( grub4dos_drive_mapping )
+{
+  winvblock__uint8 SourceDrive;
+  winvblock__uint8 DestDrive;
+  winvblock__uint8 MaxHead;
+  winvblock__uint8 MaxSector:6;
+  winvblock__uint8 RestrictionX:1;
+  winvblock__uint16 DestMaxCylinder:13;
+  winvblock__uint16 SourceODD:1;
+  winvblock__uint16 DestODD:1;
+  winvblock__uint16 DestLBASupport:1;
+  winvblock__uint8 DestMaxHead;
+  winvblock__uint8 DestMaxSector:6;
+  winvblock__uint8 RestrictionY:1;
+  winvblock__uint8 InSituOption:1;
+  winvblock__uint64 SectorStart;
+  winvblock__uint64 SectorCount;
+};
+
+void
+grub4dos__find (
+  void
+ )
+{
+  PHYSICAL_ADDRESS PhysicalAddress;
+  winvblock__uint8_ptr PhysicalMemory;
+  int_vector_ptr InterruptVector;
+  winvblock__uint32 Int13Hook;
+  safe_mbr_hook_ptr SafeMbrHookPtr;
+  grub4dos_drive_mapping_ptr Grub4DosDriveMapSlotPtr;
+  winvblock__uint32 i = 8;
+  winvblock__bool FoundGrub4DosMapping = FALSE;
+  ramdisk__type ramdisk;
+  bus__type_ptr bus_ptr;
+
+  /*
+   * Establish a pointer into the bus device's extension space
+   */
+  bus_ptr = get_bus_ptr ( ( driver__dev_ext_ptr ) bus__fdo->DeviceExtension );
+
+  /*
+   * Find a GRUB4DOS memory-mapped disk.  Start by looking at the
+   * real-mode IDT and following the "SafeMBRHook" INT 0x13 hook
+   */
+  PhysicalAddress.QuadPart = 0LL;
+  PhysicalMemory = MmMapIoSpace ( PhysicalAddress, 0x100000, MmNonCached );
+  if ( !PhysicalMemory )
+    {
+      DBG ( "Could not map low memory\n" );
+      return;
+    }
+  InterruptVector =
+    ( int_vector_ptr ) ( PhysicalMemory + 0x13 * sizeof ( int_vector ) );
+  /*
+   * Walk the "safe hook" chain of INT 13h hooks as far as possible
+   */
+  while ( SafeMbrHookPtr = get_safe_hook ( PhysicalMemory, InterruptVector ) )
+    {
+      if ( !
+          ( RtlCompareMemory ( SafeMbrHookPtr->VendorID, "GRUB4DOS", 8 ) ==
+            8 ) )
+       {
+         DBG ( "Non-GRUB4DOS INT 0x13 Safe Hook\n" );
+         InterruptVector = &SafeMbrHookPtr->PrevHook;
+         continue;
+       }
+      Grub4DosDriveMapSlotPtr =
+       ( grub4dos_drive_mapping_ptr ) ( PhysicalMemory +
+                                        ( ( ( winvblock__uint32 )
+                                            InterruptVector->
+                                            Segment ) << 4 ) + 0x20 );
+      while ( i-- )
+       {
+         DBG ( "GRUB4DOS SourceDrive: 0x%02x\n",
+               Grub4DosDriveMapSlotPtr[i].SourceDrive );
+         DBG ( "GRUB4DOS DestDrive: 0x%02x\n",
+               Grub4DosDriveMapSlotPtr[i].DestDrive );
+         DBG ( "GRUB4DOS MaxHead: %d\n", Grub4DosDriveMapSlotPtr[i].MaxHead );
+         DBG ( "GRUB4DOS MaxSector: %d\n",
+               Grub4DosDriveMapSlotPtr[i].MaxSector );
+         DBG ( "GRUB4DOS DestMaxCylinder: %d\n",
+               Grub4DosDriveMapSlotPtr[i].DestMaxCylinder );
+         DBG ( "GRUB4DOS DestMaxHead: %d\n",
+               Grub4DosDriveMapSlotPtr[i].DestMaxHead );
+         DBG ( "GRUB4DOS DestMaxSector: %d\n",
+               Grub4DosDriveMapSlotPtr[i].DestMaxSector );
+         DBG ( "GRUB4DOS SectorStart: 0x%08x\n",
+               Grub4DosDriveMapSlotPtr[i].SectorStart );
+         DBG ( "GRUB4DOS SectorCount: %d\n",
+               Grub4DosDriveMapSlotPtr[i].SectorCount );
+         if ( !( Grub4DosDriveMapSlotPtr[i].DestDrive == 0xff ) )
+           {
+             DBG ( "Skipping non-RAM disk GRUB4DOS mapping\n" );
+             continue;
+           }
+         ramdisk.disk.Initialize = ramdisk__no_init;
+         /*
+          * Possible precision loss
+          */
+         if ( Grub4DosDriveMapSlotPtr[i].SourceODD )
+           {
+             ramdisk.disk.DiskType = OpticalDisc;
+             ramdisk.disk.SectorSize = 2048;
+           }
+         else
+           {
+             ramdisk.disk.DiskType =
+               Grub4DosDriveMapSlotPtr[i].SourceDrive & 0x80 ? HardDisk :
+               FloppyDisk;
+             ramdisk.disk.SectorSize = 512;
+           }
+         DBG ( "RAM Drive is type: %d\n", ramdisk.disk.DiskType );
+         ramdisk.DiskBuf =
+           ( winvblock__uint32 ) ( Grub4DosDriveMapSlotPtr[i].SectorStart *
+                                   512 );
+         ramdisk.disk.LBADiskSize = ramdisk.DiskSize =
+           ( winvblock__uint32 ) Grub4DosDriveMapSlotPtr[i].SectorCount;
+         ramdisk.disk.Heads = Grub4DosDriveMapSlotPtr[i].MaxHead + 1;
+         ramdisk.disk.Sectors = Grub4DosDriveMapSlotPtr[i].DestMaxSector;
+         ramdisk.disk.Cylinders =
+           ramdisk.disk.LBADiskSize / ( ramdisk.disk.Heads *
+                                        ramdisk.disk.Sectors );
+         ramdisk.disk.io = ramdisk__io;
+         ramdisk.disk.max_xfer_len = ramdisk__max_xfer_len;
+         ramdisk.disk.query_id = ramdisk__query_id;
+         ramdisk.disk.dev_ext.size = sizeof ( ramdisk__type );
+         FoundGrub4DosMapping = TRUE;
+         if ( !Bus_AddChild ( bus__fdo, &ramdisk.disk, TRUE ) )
+           {
+             DBG ( "Bus_AddChild() failed for GRUB4DOS\n" );
+           }
+         else if ( bus_ptr->PhysicalDeviceObject != NULL )
+           {
+             IoInvalidateDeviceRelations ( bus_ptr->PhysicalDeviceObject,
+                                           BusRelations );
+           }
+       }
+      InterruptVector = &SafeMbrHookPtr->PrevHook;
+    }
+
+  MmUnmapIoSpace ( PhysicalMemory, 0x100000 );
+  if ( !FoundGrub4DosMapping )
+    {
+      DBG ( "No GRUB4DOS drive mappings found\n" );
+    }
+}
diff --git a/src/grub4dos.h b/src/grub4dos.h
new file mode 100644 (file)
index 0000000..5f15d4d
--- /dev/null
@@ -0,0 +1,33 @@
+/**
+ * Copyright (C) 2009, Shao Miller <shao.miller@yrdsb.edu.on.ca>.
+ *
+ * This file is part of WinVBlock, derived from WinAoE.
+ *
+ * WinVBlock is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * WinVBlock is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with WinVBlock.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _grub4dos_h
+#  define _grub4dos_h
+
+/**
+ * @file
+ *
+ * GRUB4DOS RAM disk specifics
+ *
+ */
+
+extern void grub4dos__find (
+  void
+ );
+
+#endif                         /* _grub4dos_h */
index 0ca4294..dcedb64 100644 (file)
@@ -40,6 +40,7 @@
 #include "aoe.h"
 #include "ramdisk.h"
 #include "memdisk.h"
+#include "grub4dos.h"
 #include "probe.h"
 
 #ifdef _MSC_VER
@@ -65,26 +66,6 @@ __attribute__ ( ( __packed__ ) );
 #  pragma pack()
 #endif
 
-/* From GRUB4DOS 0.4.4's stage2/shared.h */
-winvblock__def_struct ( grub4dos_drive_mapping )
-{
-  winvblock__uint8 SourceDrive;
-  winvblock__uint8 DestDrive;
-  winvblock__uint8 MaxHead;
-  winvblock__uint8 MaxSector:6;
-  winvblock__uint8 RestrictionX:1;
-  winvblock__uint16 DestMaxCylinder:13;
-  winvblock__uint16 SourceODD:1;
-  winvblock__uint16 DestODD:1;
-  winvblock__uint16 DestLBASupport:1;
-  winvblock__uint8 DestMaxHead;
-  winvblock__uint8 DestMaxSector:6;
-  winvblock__uint8 RestrictionY:1;
-  winvblock__uint8 InSituOption:1;
-  winvblock__uint64 SectorStart;
-  winvblock__uint64 SectorCount;
-};
-
 void
 find_aoe_disks (
   void
@@ -218,134 +199,6 @@ get_safe_hook (
   return SafeMbrHookPtr;
 }
 
-void
-find_grub4dos_disks (
-  void
- )
-{
-  PHYSICAL_ADDRESS PhysicalAddress;
-  winvblock__uint8_ptr PhysicalMemory;
-  int_vector_ptr InterruptVector;
-  winvblock__uint32 Int13Hook;
-  safe_mbr_hook_ptr SafeMbrHookPtr;
-  grub4dos_drive_mapping_ptr Grub4DosDriveMapSlotPtr;
-  winvblock__uint32 i = 8;
-  winvblock__bool FoundGrub4DosMapping = FALSE;
-  ramdisk__type ramdisk;
-  bus__type_ptr bus_ptr;
-
-  /*
-   * Establish a pointer into the bus device's extension space
-   */
-  bus_ptr = get_bus_ptr ( ( driver__dev_ext_ptr ) bus__fdo->DeviceExtension );
-
-  /*
-   * Find a GRUB4DOS memory-mapped disk.  Start by looking at the
-   * real-mode IDT and following the "SafeMBRHook" INT 0x13 hook
-   */
-  PhysicalAddress.QuadPart = 0LL;
-  PhysicalMemory = MmMapIoSpace ( PhysicalAddress, 0x100000, MmNonCached );
-  if ( !PhysicalMemory )
-    {
-      DBG ( "Could not map low memory\n" );
-      return;
-    }
-  InterruptVector =
-    ( int_vector_ptr ) ( PhysicalMemory + 0x13 * sizeof ( int_vector ) );
-  /*
-   * Walk the "safe hook" chain of INT 13h hooks as far as possible
-   */
-  while ( SafeMbrHookPtr = get_safe_hook ( PhysicalMemory, InterruptVector ) )
-    {
-      if ( !
-          ( RtlCompareMemory ( SafeMbrHookPtr->VendorID, "GRUB4DOS", 8 ) ==
-            8 ) )
-       {
-         DBG ( "Non-GRUB4DOS INT 0x13 Safe Hook\n" );
-         InterruptVector = &SafeMbrHookPtr->PrevHook;
-         continue;
-       }
-      Grub4DosDriveMapSlotPtr =
-       ( grub4dos_drive_mapping_ptr ) ( PhysicalMemory +
-                                        ( ( ( winvblock__uint32 )
-                                            InterruptVector->Segment ) << 4 )
-                                        + 0x20 );
-      while ( i-- )
-       {
-         DBG ( "GRUB4DOS SourceDrive: 0x%02x\n",
-               Grub4DosDriveMapSlotPtr[i].SourceDrive );
-         DBG ( "GRUB4DOS DestDrive: 0x%02x\n",
-               Grub4DosDriveMapSlotPtr[i].DestDrive );
-         DBG ( "GRUB4DOS MaxHead: %d\n", Grub4DosDriveMapSlotPtr[i].MaxHead );
-         DBG ( "GRUB4DOS MaxSector: %d\n",
-               Grub4DosDriveMapSlotPtr[i].MaxSector );
-         DBG ( "GRUB4DOS DestMaxCylinder: %d\n",
-               Grub4DosDriveMapSlotPtr[i].DestMaxCylinder );
-         DBG ( "GRUB4DOS DestMaxHead: %d\n",
-               Grub4DosDriveMapSlotPtr[i].DestMaxHead );
-         DBG ( "GRUB4DOS DestMaxSector: %d\n",
-               Grub4DosDriveMapSlotPtr[i].DestMaxSector );
-         DBG ( "GRUB4DOS SectorStart: 0x%08x\n",
-               Grub4DosDriveMapSlotPtr[i].SectorStart );
-         DBG ( "GRUB4DOS SectorCount: %d\n",
-               Grub4DosDriveMapSlotPtr[i].SectorCount );
-         if ( !( Grub4DosDriveMapSlotPtr[i].DestDrive == 0xff ) )
-           {
-             DBG ( "Skipping non-RAM disk GRUB4DOS mapping\n" );
-             continue;
-           }
-         ramdisk.disk.Initialize = ramdisk__no_init;
-         /*
-          * Possible precision loss
-          */
-         if ( Grub4DosDriveMapSlotPtr[i].SourceODD )
-           {
-             ramdisk.disk.DiskType = OpticalDisc;
-             ramdisk.disk.SectorSize = 2048;
-           }
-         else
-           {
-             ramdisk.disk.DiskType =
-               Grub4DosDriveMapSlotPtr[i].
-               SourceDrive & 0x80 ? HardDisk : FloppyDisk;
-             ramdisk.disk.SectorSize = 512;
-           }
-         DBG ( "RAM Drive is type: %d\n", ramdisk.disk.DiskType );
-         ramdisk.DiskBuf =
-           ( winvblock__uint32 ) ( Grub4DosDriveMapSlotPtr[i].SectorStart *
-                                   512 );
-         ramdisk.disk.LBADiskSize = ramdisk.DiskSize =
-           ( winvblock__uint32 ) Grub4DosDriveMapSlotPtr[i].SectorCount;
-         ramdisk.disk.Heads = Grub4DosDriveMapSlotPtr[i].MaxHead + 1;
-         ramdisk.disk.Sectors = Grub4DosDriveMapSlotPtr[i].DestMaxSector;
-         ramdisk.disk.Cylinders =
-           ramdisk.disk.LBADiskSize / ( ramdisk.disk.Heads *
-                                        ramdisk.disk.Sectors );
-         ramdisk.disk.io = ramdisk__io;
-         ramdisk.disk.max_xfer_len = ramdisk__max_xfer_len;
-         ramdisk.disk.query_id = ramdisk__query_id;
-         ramdisk.disk.dev_ext.size = sizeof ( ramdisk__type );
-         FoundGrub4DosMapping = TRUE;
-         if ( !Bus_AddChild ( bus__fdo, &ramdisk.disk, TRUE ) )
-           {
-             DBG ( "Bus_AddChild() failed for GRUB4DOS\n" );
-           }
-         else if ( bus_ptr->PhysicalDeviceObject != NULL )
-           {
-             IoInvalidateDeviceRelations ( bus_ptr->PhysicalDeviceObject,
-                                           BusRelations );
-           }
-       }
-      InterruptVector = &SafeMbrHookPtr->PrevHook;
-    }
-
-  MmUnmapIoSpace ( PhysicalMemory, 0x100000 );
-  if ( !FoundGrub4DosMapping )
-    {
-      DBG ( "No GRUB4DOS drive mappings found\n" );
-    }
-}
-
 extern void
 probe__disks (
   void
@@ -353,5 +206,5 @@ probe__disks (
 {
   find_aoe_disks (  );
   memdisk__find (  );
-  find_grub4dos_disks (  );
+  grub4dos__find (  );
 }