mirror of
https://github.com/reactos/reactos.git
synced 2024-10-08 10:24:06 +00:00
[freeldr] Add some functions to read partition tables
Add some stubs, link to mini-HAL svn path=/trunk/; revision=45815
This commit is contained in:
parent
c1f8063dc7
commit
e1e7f82deb
97
reactos/boot/freeldr/freeldr/arch/i386/halstub.c
Normal file
97
reactos/boot/freeldr/freeldr/arch/i386/halstub.c
Normal file
|
@ -0,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
|
||||
};
|
|
@ -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
|
||||
|
|
114
reactos/boot/freeldr/freeldr/arch/i386/ntoskrnl.c
Normal file
114
reactos/boot/freeldr/freeldr/arch/i386/ntoskrnl.c
Normal file
|
@ -0,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;
|
||||
}
|
||||
}
|
|
@ -240,4 +240,152 @@ BOOLEAN DiskReadBootRecord(ULONG DriveNumber, ULONGLONG LogicalSectorNumber, PMA
|
|||
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
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
19
reactos/boot/freeldr/freeldr/include/ntoskrnl.h
Normal file
19
reactos/boot/freeldr/freeldr/include/ntoskrnl.h
Normal file
|
@ -0,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>
|
Loading…
Reference in a new issue