https://git.reactos.org/?p=reactos.git;a=commitdiff;h=bc3314d4aa64d58222e5a0...
commit bc3314d4aa64d58222e5a0941293f0447a16903d Author: Hermès Bélusca-Maïto hermes.belusca-maito@reactos.org AuthorDate: Wed Aug 7 19:30:55 2019 +0200 Commit: Hermès Bélusca-Maïto hermes.belusca-maito@reactos.org CommitDate: Wed Aug 7 19:30:55 2019 +0200
[FREELDR] Better fix for x64. Addendum to 268cdf57. --- boot/freeldr/freeldr/CMakeLists.txt | 2 +- boot/freeldr/freeldr/arch/i386/drivemap.c | 126 ++++++++++++---------- boot/freeldr/freeldr/include/arch/i386/drivemap.h | 27 +++-- boot/freeldr/freeldr/include/freeldr.h | 2 +- 4 files changed, 87 insertions(+), 70 deletions(-)
diff --git a/boot/freeldr/freeldr/CMakeLists.txt b/boot/freeldr/freeldr/CMakeLists.txt index 05489b3bda6..d4263050ad4 100644 --- a/boot/freeldr/freeldr/CMakeLists.txt +++ b/boot/freeldr/freeldr/CMakeLists.txt @@ -154,7 +154,7 @@ elseif(ARCH STREQUAL "amd64") list(APPEND FREELDR_ARC_SOURCE lib/fs/pxe.c arch/i386/ntoskrnl.c - # arch/i386/drivemap.c + arch/i386/drivemap.c arch/i386/hardware.c arch/i386/hwacpi.c arch/i386/hwapm.c diff --git a/boot/freeldr/freeldr/arch/i386/drivemap.c b/boot/freeldr/freeldr/arch/i386/drivemap.c index f03d14e783e..2d38f346e28 100644 --- a/boot/freeldr/freeldr/arch/i386/drivemap.c +++ b/boot/freeldr/freeldr/arch/i386/drivemap.c @@ -22,11 +22,76 @@
DBG_DEFAULT_CHANNEL(DISK);
+#ifdef _M_IX86 + BOOLEAN DriveMapInstalled = FALSE; // Tells us if we have already installed our drive map int 13h handler code ULONG OldInt13HandlerAddress = 0; // Address of BIOS int 13h handler ULONG DriveMapHandlerAddress = 0; // Linear address of our drive map handler ULONG DriveMapHandlerSegOff = 0; // Segment:offset style address of our drive map handler
+#endif // _M_IX86 + +BOOLEAN DriveMapIsValidDriveString(PCSTR DriveString) +{ + ULONG Index; + + // Now verify that the user has given us appropriate strings + if ((strlen(DriveString) < 3) || + ((DriveString[0] != 'f') && (DriveString[0] != 'F') && + (DriveString[0] != 'h') && (DriveString[0] != 'H')) || + ((DriveString[1] != 'd') && (DriveString[1] != 'D'))) + { + return FALSE; + } + + // Now verify that the user has given us appropriate numbers + // Make sure that only numeric characters were given + for (Index = 2; Index < strlen(DriveString); Index++) + { + if (DriveString[Index] < '0' || DriveString[Index] > '9') + { + return FALSE; + } + } + + // Now make sure that they are not outrageous values (i.e. hd90874) + if ((atoi(&DriveString[2]) < 0) || (atoi(&DriveString[2]) > 0xff)) + { + return FALSE; + } + + return TRUE; +} + +UCHAR DriveMapGetBiosDriveNumber(PCSTR DeviceName) +{ + UCHAR BiosDriveNumber = 0; + + TRACE("DriveMapGetBiosDriveNumber(%s)\n", DeviceName); + + // If they passed in a number string then just + // convert it to decimal and return it + if (DeviceName[0] >= '0' && DeviceName[0] <= '9') + { + return (UCHAR)strtoul(DeviceName, NULL, 0); + } + + // Convert the drive number string into a number + // 'hd1' = 1 + BiosDriveNumber = atoi(&DeviceName[2]); + + // If it's a hard disk then set the high bit + if ((DeviceName[0] == 'h' || DeviceName[0] == 'H') && + (DeviceName[1] == 'd' || DeviceName[1] == 'D')) + { + BiosDriveNumber |= 0x80; + } + + return BiosDriveNumber; +} + +#ifdef _M_IX86 + VOID DriveMapMapDrivesInSection(PCSTR SectionName) { CHAR SettingName[80]; @@ -111,65 +176,6 @@ VOID DriveMapMapDrivesInSection(PCSTR SectionName) } }
-BOOLEAN DriveMapIsValidDriveString(PCSTR DriveString) -{ - ULONG Index; - - // Now verify that the user has given us appropriate strings - if ((strlen(DriveString) < 3) || - ((DriveString[0] != 'f') && (DriveString[0] != 'F') && - (DriveString[0] != 'h') && (DriveString[0] != 'H')) || - ((DriveString[1] != 'd') && (DriveString[1] != 'D'))) - { - return FALSE; - } - - // Now verify that the user has given us appropriate numbers - // Make sure that only numeric characters were given - for (Index = 2; Index < strlen(DriveString); Index++) - { - if (DriveString[Index] < '0' || DriveString[Index] > '9') - { - return FALSE; - } - } - - // Now make sure that they are not outrageous values (i.e. hd90874) - if ((atoi(&DriveString[2]) < 0) || (atoi(&DriveString[2]) > 0xff)) - { - return FALSE; - } - - return TRUE; -} - -UCHAR DriveMapGetBiosDriveNumber(PCSTR DeviceName) -{ - UCHAR BiosDriveNumber = 0; - - TRACE("DriveMapGetBiosDriveNumber(%s)\n", DeviceName); - - // If they passed in a number string then just - // convert it to decimal and return it - if (DeviceName[0] >= '0' && DeviceName[0] <= '9') - { - return (UCHAR)strtoul(DeviceName, NULL, 0); - } - - // Convert the drive number string into a number - // 'hd1' = 1 - BiosDriveNumber = atoi(&DeviceName[2]); - - // If it's a hard disk then set the high bit - if ((DeviceName[0] == 'h' || DeviceName[0] == 'H') && - (DeviceName[1] == 'd' || DeviceName[1] == 'D')) - { - BiosDriveNumber |= 0x80; - } - - return BiosDriveNumber; -} - VOID DriveMapInstallInt13Handler(PDRIVE_MAP_LIST DriveMap) { ULONG* RealModeIVT = (ULONG*)UlongToPtr(0x00000000); @@ -225,3 +231,5 @@ VOID DriveMapRemoveInt13Handler(VOID) DriveMapInstalled = FALSE; } } + +#endif // _M_IX86 diff --git a/boot/freeldr/freeldr/include/arch/i386/drivemap.h b/boot/freeldr/freeldr/include/arch/i386/drivemap.h index c999649a746..8c1d1088523 100644 --- a/boot/freeldr/freeldr/include/arch/i386/drivemap.h +++ b/boot/freeldr/freeldr/include/arch/i386/drivemap.h @@ -19,21 +19,30 @@
#pragma once
+#ifdef _M_IX86 + #include <pshpack1.h> typedef struct { - UCHAR DriveMapCount; // Count of drives currently mapped - CHAR DriveMap[8]; // Map of BIOS drives + UCHAR DriveMapCount; // Count of drives currently mapped + CHAR DriveMap[8]; // Map of BIOS drives } DRIVE_MAP_LIST, *PDRIVE_MAP_LIST; #include <poppack.h>
-VOID DriveMapMapDrivesInSection(PCSTR SectionName); -BOOLEAN DriveMapIsValidDriveString(PCSTR DriveString); // Checks the drive string ("hd0") for validity -UCHAR DriveMapGetBiosDriveNumber(PCSTR DeviceName); // Returns a BIOS drive number for any given device name (e.g. 0x80 for 'hd0') -VOID DriveMapInstallInt13Handler(PDRIVE_MAP_LIST DriveMap); // Installs the int 13h handler for the drive mapper -VOID DriveMapRemoveInt13Handler(VOID); // Removes a previously installed int 13h drive map handler +#endif // _M_IX86 + +BOOLEAN DriveMapIsValidDriveString(PCSTR DriveString); // Checks the drive string ("hd0") for validity +UCHAR DriveMapGetBiosDriveNumber(PCSTR DeviceName); // Returns a BIOS drive number for any given device name (e.g. 0x80 for 'hd0') + +#ifdef _M_IX86 + +VOID DriveMapMapDrivesInSection(PCSTR SectionName); +VOID DriveMapInstallInt13Handler(PDRIVE_MAP_LIST DriveMap); // Installs the int 13h handler for the drive mapper +VOID DriveMapRemoveInt13Handler(VOID); // Removes a previously installed int 13h drive map handler
extern PVOID DriveMapInt13HandlerStart; extern PVOID DriveMapInt13HandlerEnd; -extern ULONG DriveMapOldInt13HandlerAddress; -extern DRIVE_MAP_LIST DriveMapInt13HandlerMapList; +extern ULONG DriveMapOldInt13HandlerAddress; +extern DRIVE_MAP_LIST DriveMapInt13HandlerMapList; + +#endif // _M_IX86 diff --git a/boot/freeldr/freeldr/include/freeldr.h b/boot/freeldr/freeldr/include/freeldr.h index 0ef42e40595..841fd4c64ee 100644 --- a/boot/freeldr/freeldr/include/freeldr.h +++ b/boot/freeldr/freeldr/include/freeldr.h @@ -107,10 +107,10 @@ #include <arch/pc/machpc.h> #include <arch/pc/x86common.h> #include <arch/pc/pxe.h> +#include <arch/i386/drivemap.h> #endif #if defined(_M_IX86) #include <arch/i386/i386.h> -#include <arch/i386/drivemap.h> #include <arch/i386/machxbox.h> #include <internal/i386/intrin_i.h> #elif defined(_M_AMD64)