Author: hpoussin Date: Wed Mar 3 23:59:32 2010 New Revision: 45815
URL: http://svn.reactos.org/svn/reactos?rev=45815&view=rev Log: [freeldr] Add some functions to read partition tables Add some stubs, link to mini-HAL
Added: trunk/reactos/boot/freeldr/freeldr/arch/i386/halstub.c (with props) trunk/reactos/boot/freeldr/freeldr/arch/i386/ntoskrnl.c (with props) trunk/reactos/boot/freeldr/freeldr/include/ntoskrnl.h (with props) Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/loader.c trunk/reactos/boot/freeldr/freeldr/disk/partition.c trunk/reactos/boot/freeldr/freeldr/freeldr.rbuild trunk/reactos/boot/freeldr/freeldr/freeldr_arch.rbuild trunk/reactos/boot/freeldr/freeldr/include/freeldr.h
Added: trunk/reactos/boot/freeldr/freeldr/arch/i386/halstub.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/i... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/arch/i386/halstub.c (added) +++ trunk/reactos/boot/freeldr/freeldr/arch/i386/halstub.c [iso-8859-1] Wed Mar 3 23:59:32 2010 @@ -1,0 +1,97 @@ +/* +* PROJECT: ReactOS Kernel +* LICENSE: GPL - See COPYING in the top level directory +* FILE: boot/freeldr/freeldr/arch/i386/hal/halstub.c +* PURPOSE: I/O Stub HAL Routines +* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org) +*/ + +/* INCLUDES ******************************************************************/ + +#include <ntoskrnl.h> +#define NDEBUG +#include <debug.h> + +/* FUNCTIONS *****************************************************************/ + +NTSTATUS +FASTCALL +xHalIoReadPartitionTable( + IN PDEVICE_OBJECT DeviceObject, + IN ULONG SectorSize, + IN BOOLEAN ReturnRecognizedPartitions, + OUT PDRIVE_LAYOUT_INFORMATION *PartitionBuffer) +{ + return IoReadPartitionTable(DeviceObject, + SectorSize, + ReturnRecognizedPartitions, + PartitionBuffer); +} + +UCHAR +NTAPI +xHalVectorToIDTEntry(IN ULONG Vector) +{ + /* Return the vector */ + return Vector; +} + +VOID +NTAPI +xHalHaltSystem(VOID) +{ + /* Halt execution */ + while (TRUE); +} + +/* GLOBALS *******************************************************************/ + +HAL_DISPATCH HalDispatchTable = +{ + HAL_DISPATCH_VERSION, + (pHalQuerySystemInformation)NULL, + (pHalSetSystemInformation)NULL, + (pHalQueryBusSlots)NULL, + 0, + (pHalExamineMBR)NULL, + (pHalIoAssignDriveLetters)NULL, + (pHalIoReadPartitionTable)xHalIoReadPartitionTable, + (pHalIoSetPartitionInformation)NULL, + (pHalIoWritePartitionTable)NULL, + (pHalHandlerForBus)NULL, + (pHalReferenceBusHandler)NULL, + (pHalReferenceBusHandler)NULL, + (pHalInitPnpDriver)NULL, + (pHalInitPowerManagement)NULL, + (pHalGetDmaAdapter)NULL, + (pHalGetInterruptTranslator)NULL, + (pHalStartMirroring)NULL, + (pHalEndMirroring)NULL, + (pHalMirrorPhysicalMemory)NULL, + (pHalEndOfBoot)NULL, + (pHalMirrorVerify)NULL +}; + +HAL_PRIVATE_DISPATCH HalPrivateDispatchTable = +{ + HAL_PRIVATE_DISPATCH_VERSION, + (pHalHandlerForBus)NULL, + (pHalHandlerForConfigSpace)NULL, + (pHalLocateHiberRanges)NULL, + (pHalRegisterBusHandler)NULL, + (pHalSetWakeEnable)NULL, + (pHalSetWakeAlarm)NULL, + (pHalTranslateBusAddress)NULL, + (pHalAssignSlotResources)NULL, + (pHalHaltSystem)xHalHaltSystem, + (pHalFindBusAddressTranslation)NULL, + (pHalResetDisplay)NULL, + (pHalAllocateMapRegisters)NULL, + (pKdSetupPciDeviceForDebugging)NULL, + (pKdReleasePciDeviceForDebugging)NULL, + (pKdGetAcpiTablePhase0)NULL, + (pKdCheckPowerButton)NULL, + (pHalVectorToIDTEntry)xHalVectorToIDTEntry, + (pKdMapPhysicalMemory64)NULL, + (pKdUnmapVirtualAddress)NULL +};
Propchange: trunk/reactos/boot/freeldr/freeldr/arch/i386/halstub.c ------------------------------------------------------------------------------ svn:eol-style = native
Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/loader.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/i... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/arch/i386/loader.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/arch/i386/loader.c [iso-8859-1] Wed Mar 3 23:59:32 2010 @@ -17,7 +17,6 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#define _NTSYSTEM_ #include <freeldr.h>
#define NDEBUG
Added: trunk/reactos/boot/freeldr/freeldr/arch/i386/ntoskrnl.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/i... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/arch/i386/ntoskrnl.c (added) +++ trunk/reactos/boot/freeldr/freeldr/arch/i386/ntoskrnl.c [iso-8859-1] Wed Mar 3 23:59:32 2010 @@ -1,0 +1,114 @@ +#include <ntoskrnl.h> +#define NDEBUG +#include <arch.h> + +VOID +NTAPI +KeInitializeEvent( + IN PRKEVENT Event, + IN EVENT_TYPE Type, + IN BOOLEAN State) +{ +} + +VOID +FASTCALL +KiAcquireSpinLock( + IN PKSPIN_LOCK SpinLock) +{ +} + +VOID +FASTCALL +KiReleaseSpinLock( + IN PKSPIN_LOCK SpinLock) +{ +} + +VOID +NTAPI +KeSetTimeIncrement( + IN ULONG MaxIncrement, + IN ULONG MinIncrement) +{ +} + +NTKERNELAPI +VOID +FASTCALL +IoAssignDriveLetters( + IN struct _LOADER_PARAMETER_BLOCK *LoaderBlock, + IN PSTRING NtDeviceName, + OUT PUCHAR NtSystemPath, + OUT PSTRING NtSystemPathString) +{ +} + +NTKERNELAPI +NTSTATUS +FASTCALL +IoSetPartitionInformation( + IN PDEVICE_OBJECT DeviceObject, + IN ULONG SectorSize, + IN ULONG PartitionNumber, + IN ULONG PartitionType) +{ + return STATUS_NOT_IMPLEMENTED; +} + +NTKERNELAPI +NTSTATUS +FASTCALL +IoWritePartitionTable( + IN PDEVICE_OBJECT DeviceObject, + IN ULONG SectorSize, + IN ULONG SectorsPerTrack, + IN ULONG NumberOfHeads, + IN struct _DRIVE_LAYOUT_INFORMATION *PartitionBuffer) +{ + return STATUS_NOT_IMPLEMENTED; +} + +NTHALAPI +VOID +NTAPI +KeStallExecutionProcessor( + IN ULONG MicroSeconds) +{ + REGS Regs; + ULONG usec_this; + + // Int 15h AH=86h + // BIOS - WAIT (AT,PS) + // + // AH = 86h + // CX:DX = interval in microseconds + // Return: + // CF clear if successful (wait interval elapsed) + // CF set on error or AH=83h wait already in progress + // AH = status (see #00496) + + // Note: The resolution of the wait period is 977 microseconds on + // many systems because many BIOSes use the 1/1024 second fast + // interrupt from the AT real-time clock chip which is available on INT 70; + // because newer BIOSes may have much more precise timers available, it is + // not possible to use this function accurately for very short delays unless + // the precise behavior of the BIOS is known (or found through testing) + + while (MicroSeconds) + { + usec_this = MicroSeconds; + + if (usec_this > 4000000) + { + usec_this = 4000000; + } + + Regs.b.ah = 0x86; + Regs.w.cx = usec_this >> 16; + Regs.w.dx = usec_this & 0xffff; + Int386(0x15, &Regs, &Regs); + + MicroSeconds -= usec_this; + } +}
Propchange: trunk/reactos/boot/freeldr/freeldr/arch/i386/ntoskrnl.c ------------------------------------------------------------------------------ svn:eol-style = native
Modified: trunk/reactos/boot/freeldr/freeldr/disk/partition.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/disk/p... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/disk/partition.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/disk/partition.c [iso-8859-1] Wed Mar 3 23:59:32 2010 @@ -240,4 +240,152 @@ return TRUE; }
+NTSTATUS +NTAPI +IopReadBootRecord( + IN PDEVICE_OBJECT DeviceObject, + IN ULONGLONG LogicalSectorNumber, + IN ULONG SectorSize, + OUT PMASTER_BOOT_RECORD BootRecord) +{ + ULONG FileId = (ULONG)DeviceObject; + LARGE_INTEGER Position; + ULONG BytesRead; + ULONG Status; + + Position.QuadPart = LogicalSectorNumber * SectorSize; + Status = ArcSeek(FileId, &Position, SeekAbsolute); + if (Status != ESUCCESS) + return STATUS_IO_DEVICE_ERROR; + + Status = ArcRead(FileId, BootRecord, SectorSize, &BytesRead); + if (Status != ESUCCESS || BytesRead != SectorSize) + return STATUS_IO_DEVICE_ERROR; + + return STATUS_SUCCESS; +} + +BOOLEAN +NTAPI +IopCopyPartitionRecord( + IN BOOLEAN ReturnRecognizedPartitions, + IN ULONG SectorSize, + IN PPARTITION_TABLE_ENTRY PartitionTableEntry, + OUT PARTITION_INFORMATION *PartitionEntry) +{ + BOOLEAN IsRecognized; + + IsRecognized = TRUE; /* FIXME */ + if (!IsRecognized && ReturnRecognizedPartitions) + return FALSE; + + PartitionEntry->StartingOffset.QuadPart = (ULONGLONG)PartitionTableEntry->SectorCountBeforePartition * SectorSize; + PartitionEntry->PartitionLength.QuadPart = (ULONGLONG)PartitionTableEntry->PartitionSectorCount * SectorSize; + PartitionEntry->HiddenSectors = 0; + PartitionEntry->PartitionNumber = 0; /* Will be filled later */ + PartitionEntry->PartitionType = PartitionTableEntry->SystemIndicator; + PartitionEntry->BootIndicator = (PartitionTableEntry->BootIndicator & 0x80) ? TRUE : FALSE; + PartitionEntry->RecognizedPartition = IsRecognized; + PartitionEntry->RewritePartition = FALSE; + + return TRUE; +} + +NTKERNELAPI +NTSTATUS +FASTCALL +IoReadPartitionTable( + IN PDEVICE_OBJECT DeviceObject, + IN ULONG SectorSize, + IN BOOLEAN ReturnRecognizedPartitions, + OUT PDRIVE_LAYOUT_INFORMATION *PartitionBuffer) +{ + PMASTER_BOOT_RECORD MasterBootRecord; + PDRIVE_LAYOUT_INFORMATION Partitions; + ULONG NbPartitions, i, Size; + NTSTATUS ret; + + *PartitionBuffer = NULL; + + if (SectorSize < sizeof(MASTER_BOOT_RECORD)) + return STATUS_NOT_SUPPORTED; + + MasterBootRecord = ExAllocatePool(NonPagedPool, SectorSize); + if (!MasterBootRecord) + return STATUS_NO_MEMORY; + + /* Read disk MBR */ + ret = IopReadBootRecord(DeviceObject, 0, SectorSize, MasterBootRecord); + if (!NT_SUCCESS(ret)) + { + ExFreePool(MasterBootRecord); + return ret; + } + + /* Check validity of boot record */ + if (MasterBootRecord->MasterBootRecordMagic != 0xaa55) + { + ExFreePool(MasterBootRecord); + return STATUS_NOT_SUPPORTED; + } + + /* Count number of partitions */ + NbPartitions = 0; + for (i = 0; i < 4; i++) + { + NbPartitions++; + + if (MasterBootRecord->PartitionTable[i].SystemIndicator == PARTITION_EXTENDED || + MasterBootRecord->PartitionTable[i].SystemIndicator == PARTITION_XINT13_EXTENDED) + { + /* FIXME: unhandled case; count number of partitions */ + UNIMPLEMENTED; + } + } + + if (NbPartitions == 0) + { + ExFreePool(MasterBootRecord); + return STATUS_NOT_SUPPORTED; + } + + /* Allocation space to store partitions */ + Size = FIELD_OFFSET(DRIVE_LAYOUT_INFORMATION, PartitionEntry) + + NbPartitions * sizeof(PARTITION_INFORMATION); + Partitions = ExAllocatePool(NonPagedPool, Size); + if (!Partitions) + { + ExFreePool(MasterBootRecord); + return STATUS_NO_MEMORY; + } + + /* Count number of partitions */ + NbPartitions = 0; + for (i = 0; i < 4; i++) + { + if (IopCopyPartitionRecord(ReturnRecognizedPartitions, + SectorSize, + &MasterBootRecord->PartitionTable[i], + &Partitions->PartitionEntry[NbPartitions])) + { + Partitions->PartitionEntry[NbPartitions].PartitionNumber = NbPartitions + 1; + NbPartitions++; + } + + if (MasterBootRecord->PartitionTable[i].SystemIndicator == PARTITION_EXTENDED || + MasterBootRecord->PartitionTable[i].SystemIndicator == PARTITION_XINT13_EXTENDED) + { + /* FIXME: unhandled case; copy partitions */ + UNIMPLEMENTED; + } + } + + Partitions->PartitionCount = NbPartitions; + Partitions->Signature = MasterBootRecord->Signature; + ExFreePool(MasterBootRecord); + + *PartitionBuffer = Partitions; + return STATUS_SUCCESS; +} + #endif
Modified: trunk/reactos/boot/freeldr/freeldr/freeldr.rbuild URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/freeld... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/freeldr.rbuild [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/freeldr.rbuild [iso-8859-1] Wed Mar 3 23:59:32 2010 @@ -7,6 +7,7 @@ <library>freeldr_startup</library> <library>freeldr_base64k</library> <library>freeldr_base</library> + <library>mini_hal</library> <library>freeldr_arch</library> <library>freeldr_main</library> <library>rossym</library>
Modified: trunk/reactos/boot/freeldr/freeldr/freeldr_arch.rbuild URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/freeld... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/freeldr_arch.rbuild [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/freeldr_arch.rbuild [iso-8859-1] Wed Mar 3 23:59:32 2010 @@ -7,6 +7,7 @@ <include base="ReactOS">include/reactos/libs</include> <include base="ReactOS">include/reactos/elf</include> <define name="_NTHAL_" /> + <define name="_NTSYSTEM_" /> <directory name="arch"> <directory name="i386"> <if property="ARCH" value="i386"> @@ -14,6 +15,7 @@ <file>archmach.c</file> <file>custom.c</file> <file>drivemap.c</file> + <file>halstub.c</file> <file>hardware.c</file> <file>hwacpi.c</file> <file>hwapm.c</file> @@ -24,6 +26,7 @@ <file>loader.c</file> <file>machpc.c</file> <file>miscboot.c</file> + <file>ntoskrnl.c</file> <file>pccons.c</file> <file>pcdisk.c</file> <file>pcmem.c</file>
Modified: trunk/reactos/boot/freeldr/freeldr/include/freeldr.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/includ... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/include/freeldr.h [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/include/freeldr.h [iso-8859-1] Wed Mar 3 23:59:32 2010 @@ -60,6 +60,8 @@ #include <reactos.h> #include <registry.h> #include <winldr.h> +#include <ntdddisk.h> +#include <internal/hal.h> /* file system headers */ #include <fs/ext2.h> #include <fs/fat.h>
Added: trunk/reactos/boot/freeldr/freeldr/include/ntoskrnl.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/includ... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/include/ntoskrnl.h (added) +++ trunk/reactos/boot/freeldr/freeldr/include/ntoskrnl.h [iso-8859-1] Wed Mar 3 23:59:32 2010 @@ -1,0 +1,19 @@ +#include <ntdef.h> +#undef _NTHAL_ +#undef DECLSPEC_IMPORT +#define DECLSPEC_IMPORT +#undef NTSYSAPI +#define NTSYSAPI + +#include <wdm.h> + +typedef GUID UUID; + +/* Windows Device Driver Kit */ +#include <winddk.h> +#include <ndk/haltypes.h> + +/* Disk stuff */ +typedef PVOID PLOADER_PARAMETER_BLOCK; +#include <ntdddisk.h> +#include <internal/hal.h>
Propchange: trunk/reactos/boot/freeldr/freeldr/include/ntoskrnl.h ------------------------------------------------------------------------------ svn:eol-style = native