From a481180f3bcb979fecdced3851506bf572327fcf Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 24 Feb 2024 17:29:16 +0100 Subject: Kernel: Important commit, see below. - Rename EFIKit to FirmwareKit. - Reworked DriveManager, a mountpoint is a class which contains 4 disks at maximum, they act as virtual ones, their format doesn't matter. - Add KeHCFSRead, and KeHCFSWrite. Signed-off-by: Amlal El Mahrouss --- Private/Drivers/AHCI/API.hxx | 1 + Private/EFIKit/.gitkeep | 0 Private/EFIKit/Api.hxx | 86 --- Private/EFIKit/EFI.hxx | 749 --------------------- Private/EFIKit/EPM.hxx | 90 --- Private/EFIKit/Handover.hxx | 92 --- Private/EFIKit/UEFI.hxx | 10 - Private/FirmwareKit/.gitkeep | 0 Private/FirmwareKit/EFI.hxx | 11 + Private/FirmwareKit/EFI/API.hxx | 86 +++ Private/FirmwareKit/EFI/EFI.hxx | 749 +++++++++++++++++++++ Private/FirmwareKit/EPM.hxx | 90 +++ Private/FirmwareKit/Handover.hxx | 92 +++ Private/KernelKit/DriveManager.hpp | 53 +- Private/KernelKit/HError.hpp | 1 + Private/NewBoot/BootKit/BootKit.hxx | 2 +- Private/NewBoot/BootKit/Protocol.hxx | 4 +- Private/NewBoot/NetBoot/EfiModule.cxx | 3 +- Private/NewBoot/Source/BootMain.cxx | 1 - Private/NewBoot/Source/FileReader.cxx | 3 +- Private/NewBoot/Source/HEL/AMD64/AMD64-ATA.cxx | 1 - .../NewBoot/Source/HEL/AMD64/AMD64-Platform.cxx | 1 - Private/NewBoot/Source/String.cxx | 1 - Private/NewBoot/Source/TextWriter.cxx | 1 - Private/NewBoot/Source/Utils.cxx | 3 +- Private/Source/DriveManager.cxx | 45 +- Private/Source/KernelMain.cxx | 2 +- Private/Source/NewFS+IO.cxx | 59 +- 28 files changed, 1132 insertions(+), 1104 deletions(-) create mode 100644 Private/Drivers/AHCI/API.hxx delete mode 100644 Private/EFIKit/.gitkeep delete mode 100644 Private/EFIKit/Api.hxx delete mode 100644 Private/EFIKit/EFI.hxx delete mode 100644 Private/EFIKit/EPM.hxx delete mode 100644 Private/EFIKit/Handover.hxx delete mode 100644 Private/EFIKit/UEFI.hxx create mode 100644 Private/FirmwareKit/.gitkeep create mode 100644 Private/FirmwareKit/EFI.hxx create mode 100644 Private/FirmwareKit/EFI/API.hxx create mode 100644 Private/FirmwareKit/EFI/EFI.hxx create mode 100644 Private/FirmwareKit/EPM.hxx create mode 100644 Private/FirmwareKit/Handover.hxx diff --git a/Private/Drivers/AHCI/API.hxx b/Private/Drivers/AHCI/API.hxx new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/Private/Drivers/AHCI/API.hxx @@ -0,0 +1 @@ + diff --git a/Private/EFIKit/.gitkeep b/Private/EFIKit/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/Private/EFIKit/Api.hxx b/Private/EFIKit/Api.hxx deleted file mode 100644 index d2cb73f8..00000000 --- a/Private/EFIKit/Api.hxx +++ /dev/null @@ -1,86 +0,0 @@ -/* - * ======================================================== - * - * h-core - * Copyright, Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#ifndef __EFI_API__ -#define __EFI_API__ - -#include -#include -#include - -inline EfiSystemTable *ST = nullptr; -inline EfiBootServices *BS = nullptr; - -namespace EFI { -/** -@brief Stop Execution of program. -*/ -Void Stop() noexcept; - -/** -@brief Exit EFI API to let the OS load correctly. -Bascially frees everything we have in the EFI side. -*/ -inline void ExitBootServices(UInt64 MapKey, EfiHandlePtr ImageHandle) noexcept { - if (!ST) return; - - ST->BootServices->ExitBootServices(ImageHandle, MapKey); -} - -enum { - kPartEPM, - kPartGPT, - kPartMBR, - kPartCnt, -}; - -inline UInt32 Platform() noexcept { return kPEMachineAMD64; } - -/*** - * @brief Raise Hard kernel error. - */ -inline void RaiseHardError(const EfiCharType *ErrorCode, - const EfiCharType *Reason) noexcept { - ST->ConOut->OutputString(ST->ConOut, L"*** STOP ***\r\n"); - - ST->ConOut->OutputString(ST->ConOut, L"*** Error: "); - ST->ConOut->OutputString(ST->ConOut, ErrorCode); - -#ifdef __DEBUG__ - ST->ConOut->OutputString(ST->ConOut, L", Reason: "); - ST->ConOut->OutputString(ST->ConOut, Reason); -#endif // ifdef __DEBUG__ - - ST->ConOut->OutputString(ST->ConOut, L" ***\r\n"); - - EFI::Stop(); -} -} // namespace EFI - -inline void InitEFI(EfiSystemTable *SystemTable) noexcept { - if (!SystemTable) return; - - ST = SystemTable; - BS = ST->BootServices; - - ST->ConOut->ClearScreen(SystemTable->ConOut); - ST->ConOut->SetAttribute(SystemTable->ConOut, kEFIYellow); - - ST->BootServices->SetWatchdogTimer(0, 0, 0, nullptr); -} - -#ifdef __BOOTLOADER__ - -#include - -#endif // ifdef __BOOTLOADER__ - -#define kHCoreSubsystem 17 - -#endif /* ifndef __EFI_API__ */ diff --git a/Private/EFIKit/EFI.hxx b/Private/EFIKit/EFI.hxx deleted file mode 100644 index aeadfc01..00000000 --- a/Private/EFIKit/EFI.hxx +++ /dev/null @@ -1,749 +0,0 @@ -/* - * ======================================================== - * - * h-core - * Copyright, Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#ifndef __EFI__ -#define __EFI__ - -/** -@brief HCore Implementation of EFI. -@note This API is in WiP, so it's not 'pretty', just deal with it. We'll be -improving that later. -@author Amlal El Mahrouss -*/ - -#include - -using namespace HCore; - -/* we always use stdcall in EFI, the pascal way of calling functions. */ - -#ifndef EPI_API -#define EFI_API __attribute__((ms_abi)) -#endif // ifndef EPI_API - -// Forward decls - -struct EfiTableHeader; -struct EfiLoadFileProtocol; -struct EfiSimpleTextOutputProtocol; -struct EfiDevicePathProtocol; -struct EfiBootServices; -struct EfiMemoryDescriptor; -struct EfiSystemTable; -struct EfiGUID; -struct EfiFileDevicePathProtocol; -struct EfiHandle; -struct EfiGraphicsOutputProtocol; -struct EfiBitmask; -struct EfiFileProtocol; - -typedef UInt64 EfiStatusType; - -/// @brief Core Handle Type -/// This is like NT's Win32 HANDLE type. -typedef struct EfiHandle { -} *EfiHandlePtr; - -/* UEFI uses wide characters by default. */ -typedef WideChar EfiCharType; - -/// What's BootBolicy? -/// If TRUE, indicates that the request originates from the boot manager, and -/// that the boot manager is attempting to load FilePath as a boot selection. If -/// FALSE, then FilePath must match an exact file to be loaded. - -typedef UInt64(EFI_API *EfiTextString)(struct EfiSimpleTextOutputProtocol *This, - const WideChar *OutputString); - -typedef UInt64(EFI_API *EfiTextAttrib)(struct EfiSimpleTextOutputProtocol *This, - const WideChar Attribute); - -typedef UInt64(EFI_API *EfiTextClear)(struct EfiSimpleTextOutputProtocol *This); - -typedef UInt64(EFI_API *EfiLoadFile)(EfiLoadFileProtocol *This, - EfiFileDevicePathProtocol *FilePath, - Boolean BootPolicy, UInt32 *BufferSize, - VoidPtr Buffer); - -typedef UInt64(EFI_API *EfiCopyMem)(VoidPtr DstBuf, VoidPtr SrcBuf, - SizeT Length); -typedef UInt64(EFI_API *EfiSetMem)(VoidPtr DstBuf, Char Byte, SizeT Length); - -typedef UInt64(EFI_API *EfiHandleProtocol)(EfiHandlePtr Handle, EfiGUID *Guid, - VoidPtr *Device); - -typedef UInt64(EFI_API *EfiLocateDevicePath)(EfiGUID *Protocol, - EfiDevicePathProtocol **DevicePath, - EfiHandlePtr Device); - -typedef UInt64(EFI_API *EfiStartImage)(EfiHandlePtr Handle, VoidPtr ArgsSize, - VoidPtr ArgsPtr); - -typedef UInt64(EFI_API *EfiLoadImage)(Boolean BootPolicy, - EfiHandlePtr ParentHandle, - EfiFileDevicePathProtocol *DeviceFile, - VoidPtr buffer, SizeT size, - EfiHandlePtr *ppHandle); - -/// EFI pool helpers, taken from iPXE. - -typedef enum EfiMemoryType { - /// - /// Not used. - /// - EfiReservedMemoryType, - /// - /// The code portions of a loaded application. - /// (Note that UEFI OS loaders are UEFI applications.) - /// - EfiLoaderCode, - /// - /// The data portions of a loaded application and the default data allocation - /// type used by an application to allocate pool memory. - /// - EfiLoaderData, - /// - /// The code portions of a loaded Boot Services Driver. - /// - EfiBootServicesCode, - /// - /// The data portions of a loaded Boot Serves Driver, and the default data - /// allocation type used by a Boot Services Driver to allocate pool memory. - /// - EfiBootServicesData, - /// - /// The code portions of a loaded Runtime Services Driver. - /// - EfiRuntimeServicesCode, - /// - /// The data portions of a loaded Runtime Services Driver and the default - /// data allocation type used by a Runtime Services Driver to allocate pool - /// memory. - /// - EfiRuntimeServicesData, - /// - /// Free (unallocated) memory. - /// - EfiConventionalMemory, - /// - /// Memory in which errors have been detected. - /// - EfiUnusableMemory, - /// - /// Memory that holds the ACPI tables. - /// - EfiACPIReclaimMemory, - /// - /// Address space reserved for use by the firmware. - /// - EfiACPIMemoryNVS, - /// - /// Used by system firmware to request that a memory-mapped IO region - /// be mapped by the OS to a virtual address so it can be accessed by EFI - /// runtime services. - /// - EfiMemoryMappedIO, - /// - /// System memory-mapped IO region that is used to translate memory - /// cycles to IO cycles by the processor. - /// - EfiMemoryMappedIOPortSpace, - /// - /// Address space reserved by the firmware for code that is part of the - /// processor. - /// - EfiPalCode, - /// - /// A memory region that operates as EfiConventionalMemory, - /// however it happens to also support byte-addressable non-volatility. - /// - EfiPersistentMemory, - /// - /// A memory region that describes system memory that has not been accepted - /// by a corresponding call to the underlying isolation architecture. - /// - EfiUnacceptedMemoryType, - /// - /// The last type of memory. - /// Not a real type. - /// - EfiMaxMemoryType, -} EfiMemoryType; - -typedef enum EfiAllocateType { - /// Anything that satisfy the request. - AllocateAnyPages, - AllocateMaxAddress, - /// - /// Allocate pages at a specified address. - /// - AllocateAddress, - /// - /// Maximum enumeration value that may be used for bounds checking. - /// - MaxAllocateType -} EfiAllocateType; - -typedef struct EfiMemoryDescriptor { - /// - /// Type of the memory region. - /// Type EFI_MEMORY_TYPE is defined in the - /// AllocatePages() function description. - /// - UInt32 Type; - /// - /// Physical address of the first byte in the memory region. PhysicalStart - /// must be aligned on a 4 KiB boundary, and must not be above - /// 0xfffffffffffff000. Type EFI_PHYSICAL_ADDRESS is defined in the - /// AllocatePages() function description - /// - UIntPtr PhysicalStart; - /// - /// Virtual address of the first byte in the memory region. - /// VirtualStart must be aligned on a 4 KiB boundary, - /// and must not be above 0xfffffffffffff000. - /// - UIntPtr VirtualStart; - /// - /// NumberOfPagesNumber of 4 KiB pages in the memory region. - /// NumberOfPages must not be 0, and must not be any value - /// that would represent a memory page with a start address, - /// either physical or virtual, above 0xfffffffffffff000. - /// - UInt64 NumberOfPages; - /// - /// Attributes of the memory region that describe the bit mask of capabilities - /// for that memory region, and not necessarily the current settings for that - /// memory region. - /// - UInt64 Attribute; -} EfiMemoryDescriptor; - -typedef UInt64(EFI_API *EfiAllocatePool)(EfiMemoryType PoolType, UInt32 Size, - VoidPtr *Buffer); - -typedef UInt64(EFI_API *EfiFreePool)(VoidPtr Buffer); - -typedef UInt64(EFI_API *EfiCalculateCrc32)(VoidPtr Data, UInt32 DataSize, - UInt32 *CrcOut); - -/** -@brief Present in every header, used to identify a UEFI structure. -*/ -typedef struct EfiTableHeader { - UInt64 Signature; - UInt32 Revision; - UInt32 HeaderSize; - UInt32 Crc32; - UInt32 Reserved; -} EfiTableHeader; - -#define EFI_ACPI_TABLE_PROTOCOL_GUID \ - { \ - 0xffe06bdd, 0x6107, 0x46a6, { \ - 0x7b, 0xb2, 0x5a, 0x9c, 0x7e, 0xc5, 0x27, 0x5c \ - } \ - } - -#define EFI_LOAD_FILE_PROTOCOL_GUID \ - { \ - 0x56EC3091, 0x954C, 0x11d2, { \ - 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b \ - } \ - } - -#define EFI_LOAD_FILE2_PROTOCOL_GUID \ - { \ - 0x4006c0c1, 0xfcb3, 0x403e, { \ - 0x99, 0x6d, 0x4a, 0x6c, 0x87, 0x24, 0xe0, 0x6d \ - } \ - } - -#define EFI_LOADED_IMAGE_PROTOCOL_GUID \ - { \ - 0x5B1B31A1, 0x9562, 0x11d2, { \ - 0x8E, 0x3F, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B \ - } \ - } - -#define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \ - { \ - 0x9042a9de, 0x23dc, 0x4a38, { \ - 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a \ - } \ - } - -#define EFI_LOADED_IMAGE_PROTOCOL_REVISION 0x1000 - -#define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \ - { \ - 0x0964e5b22, 0x6459, 0x11d2, { \ - 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b \ - } \ - } - -#define EFI_LOADED_IMAGE_DEVICE_PATH_PROTOCOL_GUID \ - { \ - 0xbc62157e, 0x3e33, 0x4fec, { \ - 0x99, 0x20, 0x2d, 0x3b, 0x36, 0xd7, 0x50, 0xdf \ - } \ - } - -#define EFI_DEVICE_PATH_PROTOCOL_GUID \ - { \ - 0x9576e91, 0x6d3f, 0x11d2, { \ - 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b \ - } \ - } - -#define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \ - { \ - 0x0964e5b22, 0x6459, 0x11d2, { \ - 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b \ - } \ - } - -typedef UInt64(EfiImageUnload)(EfiHandlePtr ImageHandle); - -enum { - kPixelRedGreenBlueReserved8BitPerColor, - kPixelBlueGreenRedReserved8BitPerColor, - kPixelBitMask, - kPixelBltOnly, - kPixelFormatMax -}; - -typedef struct EfiBitmask { - UInt32 RedMask; - UInt32 GreenMask; - UInt32 BlueMask; - UInt32 ReservedMask; -} EfiBitmask; - -typedef struct { - UInt8 Blue; - UInt8 Green; - UInt8 Red; - UInt8 Reserved; -} EfiGraphicsOutputBltPixel; - -typedef enum EfiGraphicsOutputProtocolBltOperation { - EfiBltVideoFill, - EfiBltVideoToBltBuffer, - EfiBltBufferToVideo, - EfiBltVideoToVideo, - EfiGraphicsOutputBltOperationMax -} EfiGraphicsOutputProtocolBltOperation; - -typedef struct EfiGraphicsOutputProtocolModeInformation { - UInt32 Version; - UInt32 HorizontalResolution; - UInt32 VerticalResolution; - UInt32 PixelFormat; - EfiBitmask PixelInformation; - UInt32 PixelsPerScanLine; -} EfiGraphicsOutputProtocolModeInformation; - -typedef UInt64(EFI_API *EfiGraphicsOutputProtocolQueryMode)( - EfiGraphicsOutputProtocol *This, UInt32 ModeNumber, UInt32 *SizeOfInfo, - EfiGraphicsOutputProtocolModeInformation **Info); - -typedef UInt64(EFI_API *EfiGraphicsOutputProtocolSetMode)( - EfiGraphicsOutputProtocol *This, UInt32 ModeNumber); - -typedef UInt64(EFI_API *EfiGraphicsOutputProtocolBlt)( - EfiGraphicsOutputProtocol *This, EfiGraphicsOutputBltPixel *BltBuffer, - EfiGraphicsOutputProtocolBltOperation BltOperation, UInt32 SourceX, - UInt32 SourceY, UInt32 DestinationX, UInt32 DestinationY, UInt32 Width, - UInt32 Height, UInt32 Delta); - -typedef struct { - UInt32 MaxMode; - UInt32 Mode; - EfiGraphicsOutputProtocolModeInformation *Info; - UInt32 SizeOfInfo; - UIntPtr FrameBufferBase; - UInt32 FrameBufferSize; -} EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE; - -typedef struct EfiGraphicsOutputProtocol { - EfiGraphicsOutputProtocolQueryMode QueryMode; - EfiGraphicsOutputProtocolSetMode SetMode; - EfiGraphicsOutputProtocolBlt Blt; - EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *Mode; -} EfiGraphicsOutputProtocol; - -typedef struct EfiLoadImageProtocol { - UInt32 Revision; - EfiHandlePtr ParentHandle; - EfiSystemTable *SystemTable; - - // Source location of the image - EfiHandlePtr DeviceHandle; - EfiDevicePathProtocol *FilePath; - Void *Reserved; - - // Image’s load options - UInt32 LoadOptionsSize; - Void *LoadOptions; - - // Location where image was loaded - Void *ImageBase; - UInt64 ImageSize; - EfiMemoryType ImageCodeType; - EfiMemoryType ImageDataType; - EfiImageUnload Unload; -} EfiLoadImageProtocol; - -typedef struct EfiLoadFileProtocol { - EfiLoadFile LoadFile; -} EfiLoadFileProtocol; - -typedef struct EfiDevicePathProtocol { - UInt8 Type; - UInt8 SubType; - UInt8 Length[2]; -} EfiDevicePathProtocol; - -typedef struct EfiFileDevicePathProtocol { - EfiDevicePathProtocol Proto; - - /// - /// File Path of this struct - /// - WideChar Path[kPathLen]; -} EfiFileDevicePathProtocol; - -typedef UInt64 EfiPhysicalAddress; -typedef UIntPtr EfiVirtualAddress; - -typedef UInt64(EFI_API *EfiExitBootServices)(VoidPtr ImageHandle, - UInt32 MapKey); - -typedef UInt64(EFI_API *EfiAllocatePages)(EfiAllocateType AllocType, - EfiMemoryType MemType, UInt32 Count, - EfiPhysicalAddress *Memory); - -typedef UInt64(EFI_API *EfiFreePages)(EfiPhysicalAddress *Memory, UInt32 Pages); - -typedef UInt64(EFI_API *EfiGetMemoryMap)(UInt32 *MapSize, - EfiMemoryDescriptor *DescPtr, - UInt32 *MapKey, UInt32 *DescSize, - UInt32 *DescVersion); - -/** - * @brief GUID type, something you can also find in CFKit. - */ -typedef struct EfiGUID { - UInt32 Data1; - UInt16 Data2; - UInt16 Data3; - UInt8 Data4[8]; -} EfiGUID; - -/*** - * Protocol stuff... - */ - -/** some helpers */ -#define EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL 0x00000001 -#define EFI_OPEN_PROTOCOL_GET_PROTOCOL 0x00000002 -#define EFI_OPEN_PROTOCOL_TEST_PROTOCOL 0x00000004 -#define EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER 0x00000008 -#define EFI_OPEN_PROTOCOL_BY_DRIVER 0x00000010 -#define EFI_OPEN_PROTOCOL_EXCLUSIVE 0x00000020 - -typedef UInt64(EFI_API *EfiLocateProtocol)(EfiGUID *Protocol, - VoidPtr Registration, - VoidPtr *Interface); - -typedef UInt64(EFI_API *EfiOpenProtocol)(EfiHandlePtr Handle, EfiGUID *Guid, - VoidPtr *Interface, - EfiHandlePtr AgentHandle, - EfiHandlePtr ControllerHandle, - UInt32 Attributes); - -/** -@name EfiBootServices -@brief UEFI Boot Services record, it contains functions necessary to a -firmware level application. -*/ -typedef struct EfiBootServices { - EfiTableHeader SystemTable; - VoidPtr RaiseTPL; - VoidPtr RestoreTPL; - EfiAllocatePages AllocatePages; - EfiFreePages FreePages; - EfiGetMemoryMap GetMemoryMap; - EfiAllocatePool AllocatePool; - EfiFreePool FreePool; - VoidPtr CreateEvent; - VoidPtr SetTimer; - VoidPtr WaitForEvent; - VoidPtr SignalEvent; - VoidPtr CloseEvent; - VoidPtr CheckEvent; - VoidPtr InstallProtocolInterface; - VoidPtr ReinstallProtocolInterface; - VoidPtr UninstallProtocolInterface; - EfiHandleProtocol HandleProtocol; - VoidPtr Reserved; - VoidPtr RegisterProtocolNotify; - VoidPtr LocateHandle; - EfiLocateDevicePath LocateDevicePath; - VoidPtr InstallConfigurationTable; - EfiLoadImage LoadImage; - EfiStartImage StartImage; - VoidPtr Exit; - VoidPtr UnloadImage; - EfiExitBootServices ExitBootServices; - VoidPtr GetNextMonotonicCount; - VoidPtr Stall; - EfiStatusType(EFI_API *SetWatchdogTimer)(UInt32 Timeout, UInt64 WatchdogCode, - UInt32 DataSize, EfiCharType *Data); - VoidPtr ConnectController; - VoidPtr DisconnectController; - EfiOpenProtocol OpenProtocol; - VoidPtr CloseProtocol; - VoidPtr OpenProtocolInformation; - VoidPtr ProtocolsPerHandle; - VoidPtr LocateHandleBuffer; - EfiLocateProtocol LocateProtocol; - VoidPtr InstallMultipleProtocolInterfaces; - VoidPtr UninstallMultipleProtocolInterfaces; - EfiCalculateCrc32 CalculateCrc32; - EfiCopyMem CopyMem; - EfiSetMem SetMem; - VoidPtr CreateEventEx; -} EfiBootServices; - -#define kEntireDevPath 0xFF -#define kThisInstancePath 0x01 - -/** -@brief PrintF like protocol. -*/ -typedef struct EfiSimpleTextOutputProtocol { - VoidPtr Reset; - EfiTextString OutputString; - VoidPtr TestString; - VoidPtr QueryMode; - VoidPtr SetMode; - EfiTextAttrib SetAttribute; - EfiTextClear ClearScreen; - VoidPtr SetCursorPosition; - VoidPtr EnableCursor; - VoidPtr Mode; -} EfiSimpleTextOutputProtocol; - -typedef UInt64(EFI_API *EfiOpenVolume)(struct EfiSimpleFilesystemProtocol *, - struct EfiFileProtocol **); - -struct EfiSimpleFilesystemProtocol { - UInt64 Revision; - EfiOpenVolume OpenVolume; -}; - -/** -@brief The Structure that they give you when booting. -*/ -typedef struct EfiSystemTable { - EfiTableHeader SystemHeader; - WideChar *FirmwareVendor; - UInt32 FirmwareRevision; - EfiHandlePtr ConsoleInHandle; - VoidPtr ConIn; - EfiHandlePtr ConsoleOutHandle; - EfiSimpleTextOutputProtocol *ConOut; - EfiHandlePtr StandardErrorHandle; - VoidPtr StdErr; - VoidPtr RuntimeServices; - EfiBootServices *BootServices; - UInt64 NumberOfTableEntries; - struct { - EfiGUID VendorGUID; - VoidPtr VendorTable; - } *ConfigurationTable; -} EfiSystemTable; - -#define EfiMain efi_main - -#define kEfiOk 0 -#define kEfiFail -1 - -#define EFI_EXTERN_C extern "C" - -typedef struct EfiIPV4 { - UInt8 Addr[4]; -} EfiIPV4; - -/// -/// 16-byte buffer. An IPv6 internet protocol address. -/// -typedef struct EfiIPV6 { - UInt8 Addr[16]; -} EfiIPV6; - -#define kEFIYellow (0x01 | 0x02 | 0x04 | 0x08) - -#ifdef __x86_64 -#define __EFI_x86_64__ 1 -#endif // __x86_64 - -enum { - kEFIHwDevicePath = 0x01, - kEFIAcpiDevicePath = 0x02, - kEFIMessaingDevicePath = 0x03, - kEFIMediaDevicePath = 0x04, - kEFIBiosBootPath = 0x05, - kEFIEndOfPath = 0x06, - kEFICount = 6, -}; - -#define END_DEVICE_PATH_TYPE 0x7f -#define END_ENTIRE_DEVICE_PATH_SUBTYPE 0xFF -#define END_INSTANCE_DEVICE_PATH_SUBTYPE 0x01 - -#define kEfiOffsetOf(T, F) __builtin_offsetof(T, F) - -/// File I/O macros - -#define kEFIFileRead 0x0000000000000001 -#define kEFIFileWrite 0x0000000000000002 -#define kEFIFileCreate 0x0000000000000000 - -#define kEFIReadOnly 0x01 -#define kEFIHidden 0x02 -#define kEFISystem 0x04 -#define kEFIReserved 0x08 -#define kEFIDirectory 0x10 -#define kEFIArchive 0x20 - -typedef struct EfiIOToken { - // - // If Event is NULL, then blocking I/O is performed. - // If Event is not NULL and non-blocking I/O is supported, then non-blocking - // I/O is performed, and Event will be signaled when the read request is - // completed. The caller must be prepared to handle the case where the - // callback associated with Event occurs before the original asynchronous I/O - // request call returns. - // - UInt64 Event; - - // - // Defines whether or not the signaled event encountered an error. - // - UInt64 Status; - - // - // For OpenEx(): Not Used, ignored. - // For ReadEx(): On input, the size of the Buffer. On output, the amount of - // data returned in Buffer. - // In both cases, the size is measured in bytes. - // For WriteEx(): On input, the size of the Buffer. On output, the amount of - // data actually written. - // In both cases, the size is measured in bytes. - // For FlushEx(): Not used, ignored. - // - UInt32 BufferSize; - - // - // For OpenEx(): Not Used, ignored. - // For ReadEx(): The buffer into which the data is read. - // For WriteEx(): The buffer of data to write. - // For FlushEx(): Not Used, ignored. - // - Void *Buffer; -} EfiIOToken; - -typedef struct EfiFileProtocol { - UInt64 Revision; - - EfiStatusType(EFI_API *Open)(struct EfiFileProtocol *This, - struct EfiFileProtocol **Out, - EfiCharType *CharType, UInt64 OpenMode, - UInt64 Attrib); - - EfiStatusType(EFI_API *Close)(struct EfiFileProtocol *This); - - EfiStatusType(EFI_API *Delete)(struct EfiFileProtocol *This); - - EfiStatusType(EFI_API *Read)(struct EfiFileProtocol *This, UInt64 *BufSize, - VoidPtr BufOut); - - EfiStatusType(EFI_API *Write)(struct EfiFileProtocol *This, UInt64 *BufSize, - VoidPtr BufOut); - - EfiStatusType(EFI_API *GetPosition)(EfiFileProtocol *This, UInt64 *Position); - - EfiStatusType(EFI_API *SetPosition)(EfiFileProtocol *This, UInt64 *Position); - - EfiStatusType(EFI_API *GetInfo)(struct EfiFileProtocol *, struct EfiGUID *, - UInt32 *, void *); - - EfiStatusType(EFI_API *SetInfo)(struct EfiFileProtocol *, struct EfiGUID *, - UInt32 *, void *); - - EfiStatusType(EFI_API *Flush)(EfiFileProtocol *); - - EfiStatusType(EFI_API *OpenEx)(EfiFileProtocol *This, - EfiFileProtocol **OutHandle, EfiCharType *Path, - UInt64 Mode, UInt64 Attrib, - struct EfiIOToken *Token); - - EfiStatusType(EFI_API *ReadEx)(EfiFileProtocol *This, - struct EfiIOToken *Token); - EfiStatusType(EFI_API *WriteEx)(EfiFileProtocol *This, - struct EfiIOToken *Token); - EfiStatusType(EFI_API *FlushEx)(EfiFileProtocol *This, - struct EfiIOToken *Token); -} EfiFileProtocol, *EfiFileProtocolPtr; - -typedef UInt64 EfiCursorType; - -typedef struct EfiTime { - UInt16 Year; - UInt8 Month; - UInt8 Day; - UInt8 Hour; - UInt8 Minute; - UInt8 Second; - UInt8 Pad1; - UInt32 Nanosecond; - Int16 TimeZone; - UInt8 Daylight; - UInt8 Pad2; -} EfiTime; - -#define EFI_FILE_INFO_GUID \ - { \ - 0x09576e92, 0x6d3f, 0x11d2, { \ - 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b \ - } \ - } - -struct EfiFileInfo final { - UInt64 Size; - UInt64 FileSize; - UInt64 PhysicalSize; - EfiTime CreateTime; - EfiTime LastAccessTime; - EfiTime EditTime; - UInt64 Attribute; - // Do not touch that, it's EFI specific. - WideChar FileName[1]; -}; - -#define EFI_FILE_PROTOCOL_REVISION 0x00010000 -#define EFI_FILE_PROTOCOL_REVISION2 0x00020000 -#define EFI_FILE_PROTOCOL_LATEST_REVISION EFI_FILE_PROTOCOL_REVISION2 - -#define EFI_EXTRA_DESCRIPTOR_SIZE 8 - -#endif // ifndef __EFI__ diff --git a/Private/EFIKit/EPM.hxx b/Private/EFIKit/EPM.hxx deleted file mode 100644 index db6b8b2f..00000000 --- a/Private/EFIKit/EPM.hxx +++ /dev/null @@ -1,90 +0,0 @@ -/* - * ======================================================== - * - * h-core - * Copyright, Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -/** - @brief The Explicit Partition Map scheme. -*/ - -#ifndef __PARTITION_MAP__ -#define __PARTITION_MAP__ - -#define kUUIDLen 37 -#define kNameLen 32 -#define kMagicLen 4 - -/* the first 512 > x > 1024 bytes of a disk contains this headers. */ - -/** - * @brief The EPM bootloader block. - * boot code info - */ -struct __attribute__((packed)) BootBlock { - char magic[kMagicLen]; - char name[kNameLen]; - char uuid[kUUIDLen]; - int version; - long long int num_blocks; - long long int sector_sz; - long long int sector_start; -}; - -/** - * @brief The EPM partition block. - * used to explain a partition inside a media. - */ -struct __attribute__((packed)) PartitionBlock { - char name[32]; - int magic; - long long int sector_end; - long long int sector_sz; - long long int sector_start; - short type; - int version; - char fs[16]; /* ffs_2 */ -}; - -/* @brief AMD64 magic for EPM */ -#define kMagic86 "EPMAM" - -/* @brief RISC-V magic for EPM */ -#define kMagicRISCV "EPMRV" - -/* @brief ARM magic for EPM */ -#define kMagicARM "EPMAR" - -/* @brief 64x0 magic for EPM */ -#define kMagic64k "EPM64" - -/* @brief 32x0 magic for EPM */ -#define kMagic32k "EPM32" - -#define kMaxBlks 128 - -//! version types. -//! use in boot block version field. - -enum { - kEPMMpUx = 0xcf, - kEPMLinux = 0x8f, - kEPMBSD = 0x9f, - kEPMHCore = 0x1f, -}; - -/// END SPECS - -typedef struct BootBlock BootBlockType; -typedef struct PartitionBlock PartitionBlockType; - -#ifdef __x86_64__ -#define kMag kMagic86 -#else -#define kMag "EPM??" -#endif - -#endif // ifndef __PARTITION_MAP__ diff --git a/Private/EFIKit/Handover.hxx b/Private/EFIKit/Handover.hxx deleted file mode 100644 index c85eaddd..00000000 --- a/Private/EFIKit/Handover.hxx +++ /dev/null @@ -1,92 +0,0 @@ -/* - * ======================================================== - * - * NewBoot - * Copyright Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -/** - * @file Handover.hxx - * @author Amlal El Mahrouss (amlalelmahrouss@icloud.com) - * @brief The handover boot protocol. - * @version 0.2 - * @date 2024-02-23 - * - * @copyright Copyright (c) 2024, Mahrouss Logic - * - */ - -#pragma once - -#include - -/* useful macros */ - -#define kHandoverMagic 0xBADCC - -#define kHandoverStructSz sizeof(HEL::HandoverHeader) - -namespace HCore::HEL { -/** - @brief the kind of executable we're loading. -*/ -enum { - kTypeKernel = 100, - kTypeKernelDriver = 101, - kTypeRsrc = 102, - kTypeCount = 3, -}; - -/** - @brief The executable architecture. -*/ - -enum { - kArchAmd64 = 122, - kArchCount = 2, -}; - -/** -@brief The first struct that we read when inspecting The executable -it tells us more about it and IS format independent. -*/ -typedef struct HandoverHeader final { - UInt64 f_TargetMagic; - Int32 f_TargetType; - Int32 f_TargetArch; - UIntPtr f_TargetStartAddress; -} __attribute__((packed)) HandoverHeader, *HandoverHeaderPtr; - -struct HandoverInformationHeader { - UInt64 f_Magic; - UInt64 f_Version; - UInt64 f_Bootloader; - - voidPtr f_VirtualStart; - SizeT f_VirtualSize; - voidPtr f_PhysicalStart; - SizeT f_PhysicalSize; - WideChar f_FirmwareVendorName[32]; - SizeT f_FirmwareVendorLen; - struct { - VoidPtr f_AcpiTable; - VoidPtr f_SmBIOS; - VoidPtr f_RTC; - } f_HardwareTables; - struct { - UIntPtr f_The; - SizeT f_Size; - UInt32 f_Width; - UInt32 f_Height; - UInt32 f_PixelFormat; - UInt32 f_PixelPerLine; - } f_GOP; -}; - -/** - @brief Handover Jump Proc -*/ -typedef void (*HandoverProc)(HandoverInformationHeader* pHandover); -} // namespace HCore::HEL diff --git a/Private/EFIKit/UEFI.hxx b/Private/EFIKit/UEFI.hxx deleted file mode 100644 index de211a4a..00000000 --- a/Private/EFIKit/UEFI.hxx +++ /dev/null @@ -1,10 +0,0 @@ -/* - * ======================================================== - * - * h-core - * Copyright, Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#include diff --git a/Private/FirmwareKit/.gitkeep b/Private/FirmwareKit/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Private/FirmwareKit/EFI.hxx b/Private/FirmwareKit/EFI.hxx new file mode 100644 index 00000000..3ef28288 --- /dev/null +++ b/Private/FirmwareKit/EFI.hxx @@ -0,0 +1,11 @@ +/* + * ======================================================== + * + * h-core + * Copyright, Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#include +#include diff --git a/Private/FirmwareKit/EFI/API.hxx b/Private/FirmwareKit/EFI/API.hxx new file mode 100644 index 00000000..8856c676 --- /dev/null +++ b/Private/FirmwareKit/EFI/API.hxx @@ -0,0 +1,86 @@ +/* + * ======================================================== + * + * h-core + * Copyright, Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#ifndef __EFI_API__ +#define __EFI_API__ + +#include +#include +#include + +inline EfiSystemTable *ST = nullptr; +inline EfiBootServices *BS = nullptr; + +namespace EFI { +/** +@brief Stop Execution of program. +*/ +Void Stop() noexcept; + +/** +@brief Exit EFI API to let the OS load correctly. +Bascially frees everything we have in the EFI side. +*/ +inline void ExitBootServices(UInt64 MapKey, EfiHandlePtr ImageHandle) noexcept { + if (!ST) return; + + ST->BootServices->ExitBootServices(ImageHandle, MapKey); +} + +enum { + kPartEPM, + kPartGPT, + kPartMBR, + kPartCnt, +}; + +inline UInt32 Platform() noexcept { return kPEMachineAMD64; } + +/*** + * @brief Raise Hard kernel error. + */ +inline void RaiseHardError(const EfiCharType *ErrorCode, + const EfiCharType *Reason) noexcept { + ST->ConOut->OutputString(ST->ConOut, L"*** STOP ***\r\n"); + + ST->ConOut->OutputString(ST->ConOut, L"*** Error: "); + ST->ConOut->OutputString(ST->ConOut, ErrorCode); + +#ifdef __DEBUG__ + ST->ConOut->OutputString(ST->ConOut, L", Reason: "); + ST->ConOut->OutputString(ST->ConOut, Reason); +#endif // ifdef __DEBUG__ + + ST->ConOut->OutputString(ST->ConOut, L" ***\r\n"); + + EFI::Stop(); +} +} // namespace EFI + +inline void InitEFI(EfiSystemTable *SystemTable) noexcept { + if (!SystemTable) return; + + ST = SystemTable; + BS = ST->BootServices; + + ST->ConOut->ClearScreen(SystemTable->ConOut); + ST->ConOut->SetAttribute(SystemTable->ConOut, kEFIYellow); + + ST->BootServices->SetWatchdogTimer(0, 0, 0, nullptr); +} + +#ifdef __BOOTLOADER__ + +#include + +#endif // ifdef __BOOTLOADER__ + +#define kHCoreSubsystem 17 + +#endif /* ifndef __EFI_API__ */ diff --git a/Private/FirmwareKit/EFI/EFI.hxx b/Private/FirmwareKit/EFI/EFI.hxx new file mode 100644 index 00000000..aeadfc01 --- /dev/null +++ b/Private/FirmwareKit/EFI/EFI.hxx @@ -0,0 +1,749 @@ +/* + * ======================================================== + * + * h-core + * Copyright, Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#ifndef __EFI__ +#define __EFI__ + +/** +@brief HCore Implementation of EFI. +@note This API is in WiP, so it's not 'pretty', just deal with it. We'll be +improving that later. +@author Amlal El Mahrouss +*/ + +#include + +using namespace HCore; + +/* we always use stdcall in EFI, the pascal way of calling functions. */ + +#ifndef EPI_API +#define EFI_API __attribute__((ms_abi)) +#endif // ifndef EPI_API + +// Forward decls + +struct EfiTableHeader; +struct EfiLoadFileProtocol; +struct EfiSimpleTextOutputProtocol; +struct EfiDevicePathProtocol; +struct EfiBootServices; +struct EfiMemoryDescriptor; +struct EfiSystemTable; +struct EfiGUID; +struct EfiFileDevicePathProtocol; +struct EfiHandle; +struct EfiGraphicsOutputProtocol; +struct EfiBitmask; +struct EfiFileProtocol; + +typedef UInt64 EfiStatusType; + +/// @brief Core Handle Type +/// This is like NT's Win32 HANDLE type. +typedef struct EfiHandle { +} *EfiHandlePtr; + +/* UEFI uses wide characters by default. */ +typedef WideChar EfiCharType; + +/// What's BootBolicy? +/// If TRUE, indicates that the request originates from the boot manager, and +/// that the boot manager is attempting to load FilePath as a boot selection. If +/// FALSE, then FilePath must match an exact file to be loaded. + +typedef UInt64(EFI_API *EfiTextString)(struct EfiSimpleTextOutputProtocol *This, + const WideChar *OutputString); + +typedef UInt64(EFI_API *EfiTextAttrib)(struct EfiSimpleTextOutputProtocol *This, + const WideChar Attribute); + +typedef UInt64(EFI_API *EfiTextClear)(struct EfiSimpleTextOutputProtocol *This); + +typedef UInt64(EFI_API *EfiLoadFile)(EfiLoadFileProtocol *This, + EfiFileDevicePathProtocol *FilePath, + Boolean BootPolicy, UInt32 *BufferSize, + VoidPtr Buffer); + +typedef UInt64(EFI_API *EfiCopyMem)(VoidPtr DstBuf, VoidPtr SrcBuf, + SizeT Length); +typedef UInt64(EFI_API *EfiSetMem)(VoidPtr DstBuf, Char Byte, SizeT Length); + +typedef UInt64(EFI_API *EfiHandleProtocol)(EfiHandlePtr Handle, EfiGUID *Guid, + VoidPtr *Device); + +typedef UInt64(EFI_API *EfiLocateDevicePath)(EfiGUID *Protocol, + EfiDevicePathProtocol **DevicePath, + EfiHandlePtr Device); + +typedef UInt64(EFI_API *EfiStartImage)(EfiHandlePtr Handle, VoidPtr ArgsSize, + VoidPtr ArgsPtr); + +typedef UInt64(EFI_API *EfiLoadImage)(Boolean BootPolicy, + EfiHandlePtr ParentHandle, + EfiFileDevicePathProtocol *DeviceFile, + VoidPtr buffer, SizeT size, + EfiHandlePtr *ppHandle); + +/// EFI pool helpers, taken from iPXE. + +typedef enum EfiMemoryType { + /// + /// Not used. + /// + EfiReservedMemoryType, + /// + /// The code portions of a loaded application. + /// (Note that UEFI OS loaders are UEFI applications.) + /// + EfiLoaderCode, + /// + /// The data portions of a loaded application and the default data allocation + /// type used by an application to allocate pool memory. + /// + EfiLoaderData, + /// + /// The code portions of a loaded Boot Services Driver. + /// + EfiBootServicesCode, + /// + /// The data portions of a loaded Boot Serves Driver, and the default data + /// allocation type used by a Boot Services Driver to allocate pool memory. + /// + EfiBootServicesData, + /// + /// The code portions of a loaded Runtime Services Driver. + /// + EfiRuntimeServicesCode, + /// + /// The data portions of a loaded Runtime Services Driver and the default + /// data allocation type used by a Runtime Services Driver to allocate pool + /// memory. + /// + EfiRuntimeServicesData, + /// + /// Free (unallocated) memory. + /// + EfiConventionalMemory, + /// + /// Memory in which errors have been detected. + /// + EfiUnusableMemory, + /// + /// Memory that holds the ACPI tables. + /// + EfiACPIReclaimMemory, + /// + /// Address space reserved for use by the firmware. + /// + EfiACPIMemoryNVS, + /// + /// Used by system firmware to request that a memory-mapped IO region + /// be mapped by the OS to a virtual address so it can be accessed by EFI + /// runtime services. + /// + EfiMemoryMappedIO, + /// + /// System memory-mapped IO region that is used to translate memory + /// cycles to IO cycles by the processor. + /// + EfiMemoryMappedIOPortSpace, + /// + /// Address space reserved by the firmware for code that is part of the + /// processor. + /// + EfiPalCode, + /// + /// A memory region that operates as EfiConventionalMemory, + /// however it happens to also support byte-addressable non-volatility. + /// + EfiPersistentMemory, + /// + /// A memory region that describes system memory that has not been accepted + /// by a corresponding call to the underlying isolation architecture. + /// + EfiUnacceptedMemoryType, + /// + /// The last type of memory. + /// Not a real type. + /// + EfiMaxMemoryType, +} EfiMemoryType; + +typedef enum EfiAllocateType { + /// Anything that satisfy the request. + AllocateAnyPages, + AllocateMaxAddress, + /// + /// Allocate pages at a specified address. + /// + AllocateAddress, + /// + /// Maximum enumeration value that may be used for bounds checking. + /// + MaxAllocateType +} EfiAllocateType; + +typedef struct EfiMemoryDescriptor { + /// + /// Type of the memory region. + /// Type EFI_MEMORY_TYPE is defined in the + /// AllocatePages() function description. + /// + UInt32 Type; + /// + /// Physical address of the first byte in the memory region. PhysicalStart + /// must be aligned on a 4 KiB boundary, and must not be above + /// 0xfffffffffffff000. Type EFI_PHYSICAL_ADDRESS is defined in the + /// AllocatePages() function description + /// + UIntPtr PhysicalStart; + /// + /// Virtual address of the first byte in the memory region. + /// VirtualStart must be aligned on a 4 KiB boundary, + /// and must not be above 0xfffffffffffff000. + /// + UIntPtr VirtualStart; + /// + /// NumberOfPagesNumber of 4 KiB pages in the memory region. + /// NumberOfPages must not be 0, and must not be any value + /// that would represent a memory page with a start address, + /// either physical or virtual, above 0xfffffffffffff000. + /// + UInt64 NumberOfPages; + /// + /// Attributes of the memory region that describe the bit mask of capabilities + /// for that memory region, and not necessarily the current settings for that + /// memory region. + /// + UInt64 Attribute; +} EfiMemoryDescriptor; + +typedef UInt64(EFI_API *EfiAllocatePool)(EfiMemoryType PoolType, UInt32 Size, + VoidPtr *Buffer); + +typedef UInt64(EFI_API *EfiFreePool)(VoidPtr Buffer); + +typedef UInt64(EFI_API *EfiCalculateCrc32)(VoidPtr Data, UInt32 DataSize, + UInt32 *CrcOut); + +/** +@brief Present in every header, used to identify a UEFI structure. +*/ +typedef struct EfiTableHeader { + UInt64 Signature; + UInt32 Revision; + UInt32 HeaderSize; + UInt32 Crc32; + UInt32 Reserved; +} EfiTableHeader; + +#define EFI_ACPI_TABLE_PROTOCOL_GUID \ + { \ + 0xffe06bdd, 0x6107, 0x46a6, { \ + 0x7b, 0xb2, 0x5a, 0x9c, 0x7e, 0xc5, 0x27, 0x5c \ + } \ + } + +#define EFI_LOAD_FILE_PROTOCOL_GUID \ + { \ + 0x56EC3091, 0x954C, 0x11d2, { \ + 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b \ + } \ + } + +#define EFI_LOAD_FILE2_PROTOCOL_GUID \ + { \ + 0x4006c0c1, 0xfcb3, 0x403e, { \ + 0x99, 0x6d, 0x4a, 0x6c, 0x87, 0x24, 0xe0, 0x6d \ + } \ + } + +#define EFI_LOADED_IMAGE_PROTOCOL_GUID \ + { \ + 0x5B1B31A1, 0x9562, 0x11d2, { \ + 0x8E, 0x3F, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B \ + } \ + } + +#define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \ + { \ + 0x9042a9de, 0x23dc, 0x4a38, { \ + 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a \ + } \ + } + +#define EFI_LOADED_IMAGE_PROTOCOL_REVISION 0x1000 + +#define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \ + { \ + 0x0964e5b22, 0x6459, 0x11d2, { \ + 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b \ + } \ + } + +#define EFI_LOADED_IMAGE_DEVICE_PATH_PROTOCOL_GUID \ + { \ + 0xbc62157e, 0x3e33, 0x4fec, { \ + 0x99, 0x20, 0x2d, 0x3b, 0x36, 0xd7, 0x50, 0xdf \ + } \ + } + +#define EFI_DEVICE_PATH_PROTOCOL_GUID \ + { \ + 0x9576e91, 0x6d3f, 0x11d2, { \ + 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b \ + } \ + } + +#define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \ + { \ + 0x0964e5b22, 0x6459, 0x11d2, { \ + 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b \ + } \ + } + +typedef UInt64(EfiImageUnload)(EfiHandlePtr ImageHandle); + +enum { + kPixelRedGreenBlueReserved8BitPerColor, + kPixelBlueGreenRedReserved8BitPerColor, + kPixelBitMask, + kPixelBltOnly, + kPixelFormatMax +}; + +typedef struct EfiBitmask { + UInt32 RedMask; + UInt32 GreenMask; + UInt32 BlueMask; + UInt32 ReservedMask; +} EfiBitmask; + +typedef struct { + UInt8 Blue; + UInt8 Green; + UInt8 Red; + UInt8 Reserved; +} EfiGraphicsOutputBltPixel; + +typedef enum EfiGraphicsOutputProtocolBltOperation { + EfiBltVideoFill, + EfiBltVideoToBltBuffer, + EfiBltBufferToVideo, + EfiBltVideoToVideo, + EfiGraphicsOutputBltOperationMax +} EfiGraphicsOutputProtocolBltOperation; + +typedef struct EfiGraphicsOutputProtocolModeInformation { + UInt32 Version; + UInt32 HorizontalResolution; + UInt32 VerticalResolution; + UInt32 PixelFormat; + EfiBitmask PixelInformation; + UInt32 PixelsPerScanLine; +} EfiGraphicsOutputProtocolModeInformation; + +typedef UInt64(EFI_API *EfiGraphicsOutputProtocolQueryMode)( + EfiGraphicsOutputProtocol *This, UInt32 ModeNumber, UInt32 *SizeOfInfo, + EfiGraphicsOutputProtocolModeInformation **Info); + +typedef UInt64(EFI_API *EfiGraphicsOutputProtocolSetMode)( + EfiGraphicsOutputProtocol *This, UInt32 ModeNumber); + +typedef UInt64(EFI_API *EfiGraphicsOutputProtocolBlt)( + EfiGraphicsOutputProtocol *This, EfiGraphicsOutputBltPixel *BltBuffer, + EfiGraphicsOutputProtocolBltOperation BltOperation, UInt32 SourceX, + UInt32 SourceY, UInt32 DestinationX, UInt32 DestinationY, UInt32 Width, + UInt32 Height, UInt32 Delta); + +typedef struct { + UInt32 MaxMode; + UInt32 Mode; + EfiGraphicsOutputProtocolModeInformation *Info; + UInt32 SizeOfInfo; + UIntPtr FrameBufferBase; + UInt32 FrameBufferSize; +} EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE; + +typedef struct EfiGraphicsOutputProtocol { + EfiGraphicsOutputProtocolQueryMode QueryMode; + EfiGraphicsOutputProtocolSetMode SetMode; + EfiGraphicsOutputProtocolBlt Blt; + EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *Mode; +} EfiGraphicsOutputProtocol; + +typedef struct EfiLoadImageProtocol { + UInt32 Revision; + EfiHandlePtr ParentHandle; + EfiSystemTable *SystemTable; + + // Source location of the image + EfiHandlePtr DeviceHandle; + EfiDevicePathProtocol *FilePath; + Void *Reserved; + + // Image’s load options + UInt32 LoadOptionsSize; + Void *LoadOptions; + + // Location where image was loaded + Void *ImageBase; + UInt64 ImageSize; + EfiMemoryType ImageCodeType; + EfiMemoryType ImageDataType; + EfiImageUnload Unload; +} EfiLoadImageProtocol; + +typedef struct EfiLoadFileProtocol { + EfiLoadFile LoadFile; +} EfiLoadFileProtocol; + +typedef struct EfiDevicePathProtocol { + UInt8 Type; + UInt8 SubType; + UInt8 Length[2]; +} EfiDevicePathProtocol; + +typedef struct EfiFileDevicePathProtocol { + EfiDevicePathProtocol Proto; + + /// + /// File Path of this struct + /// + WideChar Path[kPathLen]; +} EfiFileDevicePathProtocol; + +typedef UInt64 EfiPhysicalAddress; +typedef UIntPtr EfiVirtualAddress; + +typedef UInt64(EFI_API *EfiExitBootServices)(VoidPtr ImageHandle, + UInt32 MapKey); + +typedef UInt64(EFI_API *EfiAllocatePages)(EfiAllocateType AllocType, + EfiMemoryType MemType, UInt32 Count, + EfiPhysicalAddress *Memory); + +typedef UInt64(EFI_API *EfiFreePages)(EfiPhysicalAddress *Memory, UInt32 Pages); + +typedef UInt64(EFI_API *EfiGetMemoryMap)(UInt32 *MapSize, + EfiMemoryDescriptor *DescPtr, + UInt32 *MapKey, UInt32 *DescSize, + UInt32 *DescVersion); + +/** + * @brief GUID type, something you can also find in CFKit. + */ +typedef struct EfiGUID { + UInt32 Data1; + UInt16 Data2; + UInt16 Data3; + UInt8 Data4[8]; +} EfiGUID; + +/*** + * Protocol stuff... + */ + +/** some helpers */ +#define EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL 0x00000001 +#define EFI_OPEN_PROTOCOL_GET_PROTOCOL 0x00000002 +#define EFI_OPEN_PROTOCOL_TEST_PROTOCOL 0x00000004 +#define EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER 0x00000008 +#define EFI_OPEN_PROTOCOL_BY_DRIVER 0x00000010 +#define EFI_OPEN_PROTOCOL_EXCLUSIVE 0x00000020 + +typedef UInt64(EFI_API *EfiLocateProtocol)(EfiGUID *Protocol, + VoidPtr Registration, + VoidPtr *Interface); + +typedef UInt64(EFI_API *EfiOpenProtocol)(EfiHandlePtr Handle, EfiGUID *Guid, + VoidPtr *Interface, + EfiHandlePtr AgentHandle, + EfiHandlePtr ControllerHandle, + UInt32 Attributes); + +/** +@name EfiBootServices +@brief UEFI Boot Services record, it contains functions necessary to a +firmware level application. +*/ +typedef struct EfiBootServices { + EfiTableHeader SystemTable; + VoidPtr RaiseTPL; + VoidPtr RestoreTPL; + EfiAllocatePages AllocatePages; + EfiFreePages FreePages; + EfiGetMemoryMap GetMemoryMap; + EfiAllocatePool AllocatePool; + EfiFreePool FreePool; + VoidPtr CreateEvent; + VoidPtr SetTimer; + VoidPtr WaitForEvent; + VoidPtr SignalEvent; + VoidPtr CloseEvent; + VoidPtr CheckEvent; + VoidPtr InstallProtocolInterface; + VoidPtr ReinstallProtocolInterface; + VoidPtr UninstallProtocolInterface; + EfiHandleProtocol HandleProtocol; + VoidPtr Reserved; + VoidPtr RegisterProtocolNotify; + VoidPtr LocateHandle; + EfiLocateDevicePath LocateDevicePath; + VoidPtr InstallConfigurationTable; + EfiLoadImage LoadImage; + EfiStartImage StartImage; + VoidPtr Exit; + VoidPtr UnloadImage; + EfiExitBootServices ExitBootServices; + VoidPtr GetNextMonotonicCount; + VoidPtr Stall; + EfiStatusType(EFI_API *SetWatchdogTimer)(UInt32 Timeout, UInt64 WatchdogCode, + UInt32 DataSize, EfiCharType *Data); + VoidPtr ConnectController; + VoidPtr DisconnectController; + EfiOpenProtocol OpenProtocol; + VoidPtr CloseProtocol; + VoidPtr OpenProtocolInformation; + VoidPtr ProtocolsPerHandle; + VoidPtr LocateHandleBuffer; + EfiLocateProtocol LocateProtocol; + VoidPtr InstallMultipleProtocolInterfaces; + VoidPtr UninstallMultipleProtocolInterfaces; + EfiCalculateCrc32 CalculateCrc32; + EfiCopyMem CopyMem; + EfiSetMem SetMem; + VoidPtr CreateEventEx; +} EfiBootServices; + +#define kEntireDevPath 0xFF +#define kThisInstancePath 0x01 + +/** +@brief PrintF like protocol. +*/ +typedef struct EfiSimpleTextOutputProtocol { + VoidPtr Reset; + EfiTextString OutputString; + VoidPtr TestString; + VoidPtr QueryMode; + VoidPtr SetMode; + EfiTextAttrib SetAttribute; + EfiTextClear ClearScreen; + VoidPtr SetCursorPosition; + VoidPtr EnableCursor; + VoidPtr Mode; +} EfiSimpleTextOutputProtocol; + +typedef UInt64(EFI_API *EfiOpenVolume)(struct EfiSimpleFilesystemProtocol *, + struct EfiFileProtocol **); + +struct EfiSimpleFilesystemProtocol { + UInt64 Revision; + EfiOpenVolume OpenVolume; +}; + +/** +@brief The Structure that they give you when booting. +*/ +typedef struct EfiSystemTable { + EfiTableHeader SystemHeader; + WideChar *FirmwareVendor; + UInt32 FirmwareRevision; + EfiHandlePtr ConsoleInHandle; + VoidPtr ConIn; + EfiHandlePtr ConsoleOutHandle; + EfiSimpleTextOutputProtocol *ConOut; + EfiHandlePtr StandardErrorHandle; + VoidPtr StdErr; + VoidPtr RuntimeServices; + EfiBootServices *BootServices; + UInt64 NumberOfTableEntries; + struct { + EfiGUID VendorGUID; + VoidPtr VendorTable; + } *ConfigurationTable; +} EfiSystemTable; + +#define EfiMain efi_main + +#define kEfiOk 0 +#define kEfiFail -1 + +#define EFI_EXTERN_C extern "C" + +typedef struct EfiIPV4 { + UInt8 Addr[4]; +} EfiIPV4; + +/// +/// 16-byte buffer. An IPv6 internet protocol address. +/// +typedef struct EfiIPV6 { + UInt8 Addr[16]; +} EfiIPV6; + +#define kEFIYellow (0x01 | 0x02 | 0x04 | 0x08) + +#ifdef __x86_64 +#define __EFI_x86_64__ 1 +#endif // __x86_64 + +enum { + kEFIHwDevicePath = 0x01, + kEFIAcpiDevicePath = 0x02, + kEFIMessaingDevicePath = 0x03, + kEFIMediaDevicePath = 0x04, + kEFIBiosBootPath = 0x05, + kEFIEndOfPath = 0x06, + kEFICount = 6, +}; + +#define END_DEVICE_PATH_TYPE 0x7f +#define END_ENTIRE_DEVICE_PATH_SUBTYPE 0xFF +#define END_INSTANCE_DEVICE_PATH_SUBTYPE 0x01 + +#define kEfiOffsetOf(T, F) __builtin_offsetof(T, F) + +/// File I/O macros + +#define kEFIFileRead 0x0000000000000001 +#define kEFIFileWrite 0x0000000000000002 +#define kEFIFileCreate 0x0000000000000000 + +#define kEFIReadOnly 0x01 +#define kEFIHidden 0x02 +#define kEFISystem 0x04 +#define kEFIReserved 0x08 +#define kEFIDirectory 0x10 +#define kEFIArchive 0x20 + +typedef struct EfiIOToken { + // + // If Event is NULL, then blocking I/O is performed. + // If Event is not NULL and non-blocking I/O is supported, then non-blocking + // I/O is performed, and Event will be signaled when the read request is + // completed. The caller must be prepared to handle the case where the + // callback associated with Event occurs before the original asynchronous I/O + // request call returns. + // + UInt64 Event; + + // + // Defines whether or not the signaled event encountered an error. + // + UInt64 Status; + + // + // For OpenEx(): Not Used, ignored. + // For ReadEx(): On input, the size of the Buffer. On output, the amount of + // data returned in Buffer. + // In both cases, the size is measured in bytes. + // For WriteEx(): On input, the size of the Buffer. On output, the amount of + // data actually written. + // In both cases, the size is measured in bytes. + // For FlushEx(): Not used, ignored. + // + UInt32 BufferSize; + + // + // For OpenEx(): Not Used, ignored. + // For ReadEx(): The buffer into which the data is read. + // For WriteEx(): The buffer of data to write. + // For FlushEx(): Not Used, ignored. + // + Void *Buffer; +} EfiIOToken; + +typedef struct EfiFileProtocol { + UInt64 Revision; + + EfiStatusType(EFI_API *Open)(struct EfiFileProtocol *This, + struct EfiFileProtocol **Out, + EfiCharType *CharType, UInt64 OpenMode, + UInt64 Attrib); + + EfiStatusType(EFI_API *Close)(struct EfiFileProtocol *This); + + EfiStatusType(EFI_API *Delete)(struct EfiFileProtocol *This); + + EfiStatusType(EFI_API *Read)(struct EfiFileProtocol *This, UInt64 *BufSize, + VoidPtr BufOut); + + EfiStatusType(EFI_API *Write)(struct EfiFileProtocol *This, UInt64 *BufSize, + VoidPtr BufOut); + + EfiStatusType(EFI_API *GetPosition)(EfiFileProtocol *This, UInt64 *Position); + + EfiStatusType(EFI_API *SetPosition)(EfiFileProtocol *This, UInt64 *Position); + + EfiStatusType(EFI_API *GetInfo)(struct EfiFileProtocol *, struct EfiGUID *, + UInt32 *, void *); + + EfiStatusType(EFI_API *SetInfo)(struct EfiFileProtocol *, struct EfiGUID *, + UInt32 *, void *); + + EfiStatusType(EFI_API *Flush)(EfiFileProtocol *); + + EfiStatusType(EFI_API *OpenEx)(EfiFileProtocol *This, + EfiFileProtocol **OutHandle, EfiCharType *Path, + UInt64 Mode, UInt64 Attrib, + struct EfiIOToken *Token); + + EfiStatusType(EFI_API *ReadEx)(EfiFileProtocol *This, + struct EfiIOToken *Token); + EfiStatusType(EFI_API *WriteEx)(EfiFileProtocol *This, + struct EfiIOToken *Token); + EfiStatusType(EFI_API *FlushEx)(EfiFileProtocol *This, + struct EfiIOToken *Token); +} EfiFileProtocol, *EfiFileProtocolPtr; + +typedef UInt64 EfiCursorType; + +typedef struct EfiTime { + UInt16 Year; + UInt8 Month; + UInt8 Day; + UInt8 Hour; + UInt8 Minute; + UInt8 Second; + UInt8 Pad1; + UInt32 Nanosecond; + Int16 TimeZone; + UInt8 Daylight; + UInt8 Pad2; +} EfiTime; + +#define EFI_FILE_INFO_GUID \ + { \ + 0x09576e92, 0x6d3f, 0x11d2, { \ + 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b \ + } \ + } + +struct EfiFileInfo final { + UInt64 Size; + UInt64 FileSize; + UInt64 PhysicalSize; + EfiTime CreateTime; + EfiTime LastAccessTime; + EfiTime EditTime; + UInt64 Attribute; + // Do not touch that, it's EFI specific. + WideChar FileName[1]; +}; + +#define EFI_FILE_PROTOCOL_REVISION 0x00010000 +#define EFI_FILE_PROTOCOL_REVISION2 0x00020000 +#define EFI_FILE_PROTOCOL_LATEST_REVISION EFI_FILE_PROTOCOL_REVISION2 + +#define EFI_EXTRA_DESCRIPTOR_SIZE 8 + +#endif // ifndef __EFI__ diff --git a/Private/FirmwareKit/EPM.hxx b/Private/FirmwareKit/EPM.hxx new file mode 100644 index 00000000..77f9901a --- /dev/null +++ b/Private/FirmwareKit/EPM.hxx @@ -0,0 +1,90 @@ +/* + * ======================================================== + * + * h-core + * Copyright, Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +/** + @brief The Explicit Partition Map scheme. +*/ + +#ifndef __PARTITION_MAP__ +#define __PARTITION_MAP__ + +#define kEPMUUIDLength 37 +#define kEPMNameLength 32 +#define kEPMMagicLength 4 + +/* the first 512 > x > 1024 bytes of a disk contains this headers. */ + +/** + * @brief The EPM bootloader block. + * boot code info + */ +struct __attribute__((packed)) BootBlock { + char magic[kEPMMagicLength]; + char name[kEPMNameLength]; + char uuid[kEPMUUIDLength]; + int version; + long long int num_blocks; + long long int sector_sz; + long long int sector_start; +}; + +/** + * @brief The EPM partition block. + * used to explain a partition inside a media. + */ +struct __attribute__((packed)) PartitionBlock { + char name[32]; + int magic; + long long int sector_end; + long long int sector_sz; + long long int sector_start; + short type; + int version; + char fs[16]; /* ffs_2 */ +}; + +/* @brief AMD64 magic for EPM */ +#define kMagic86 "EPMAM" + +/* @brief RISC-V magic for EPM */ +#define kMagicRISCV "EPMRV" + +/* @brief ARM magic for EPM */ +#define kMagicARM "EPMAR" + +/* @brief 64x0 magic for EPM */ +#define kMagic64k "EPM64" + +/* @brief 32x0 magic for EPM */ +#define kMagic32k "EPM32" + +#define kMaxBlks 128 + +//! version types. +//! use in boot block version field. + +enum { + kEPMMpUx = 0xcf, + kEPMLinux = 0x8f, + kEPMBSD = 0x9f, + kEPMHCore = 0x1f, +}; + +/// END SPECS + +typedef struct BootBlock BootBlockType; +typedef struct PartitionBlock PartitionBlockType; + +#ifdef __x86_64__ +#define kMag kMagic86 +#else +#define kMag "EPM??" +#endif + +#endif // ifndef __PARTITION_MAP__ diff --git a/Private/FirmwareKit/Handover.hxx b/Private/FirmwareKit/Handover.hxx new file mode 100644 index 00000000..c85eaddd --- /dev/null +++ b/Private/FirmwareKit/Handover.hxx @@ -0,0 +1,92 @@ +/* + * ======================================================== + * + * NewBoot + * Copyright Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +/** + * @file Handover.hxx + * @author Amlal El Mahrouss (amlalelmahrouss@icloud.com) + * @brief The handover boot protocol. + * @version 0.2 + * @date 2024-02-23 + * + * @copyright Copyright (c) 2024, Mahrouss Logic + * + */ + +#pragma once + +#include + +/* useful macros */ + +#define kHandoverMagic 0xBADCC + +#define kHandoverStructSz sizeof(HEL::HandoverHeader) + +namespace HCore::HEL { +/** + @brief the kind of executable we're loading. +*/ +enum { + kTypeKernel = 100, + kTypeKernelDriver = 101, + kTypeRsrc = 102, + kTypeCount = 3, +}; + +/** + @brief The executable architecture. +*/ + +enum { + kArchAmd64 = 122, + kArchCount = 2, +}; + +/** +@brief The first struct that we read when inspecting The executable +it tells us more about it and IS format independent. +*/ +typedef struct HandoverHeader final { + UInt64 f_TargetMagic; + Int32 f_TargetType; + Int32 f_TargetArch; + UIntPtr f_TargetStartAddress; +} __attribute__((packed)) HandoverHeader, *HandoverHeaderPtr; + +struct HandoverInformationHeader { + UInt64 f_Magic; + UInt64 f_Version; + UInt64 f_Bootloader; + + voidPtr f_VirtualStart; + SizeT f_VirtualSize; + voidPtr f_PhysicalStart; + SizeT f_PhysicalSize; + WideChar f_FirmwareVendorName[32]; + SizeT f_FirmwareVendorLen; + struct { + VoidPtr f_AcpiTable; + VoidPtr f_SmBIOS; + VoidPtr f_RTC; + } f_HardwareTables; + struct { + UIntPtr f_The; + SizeT f_Size; + UInt32 f_Width; + UInt32 f_Height; + UInt32 f_PixelFormat; + UInt32 f_PixelPerLine; + } f_GOP; +}; + +/** + @brief Handover Jump Proc +*/ +typedef void (*HandoverProc)(HandoverInformationHeader* pHandover); +} // namespace HCore::HEL diff --git a/Private/KernelKit/DriveManager.hpp b/Private/KernelKit/DriveManager.hpp index 8e6aaefd..d48b8aae 100644 --- a/Private/KernelKit/DriveManager.hpp +++ b/Private/KernelKit/DriveManager.hpp @@ -11,7 +11,9 @@ #define __DRIVE_MANAGER__ #include +#include #include +#include #include #include @@ -41,17 +43,15 @@ struct DriveTraits final { DriveID fId; // Drive id. Int32 fFlags; // fReadOnly, fXPMDrive, fXPTDrive - //! disk mount, unmount operations - void (*fMount)(void); - void (*fUnmount)(void); - - bool (*fReady)(void); //! is drive ready? + Handle fDriveHandle; //! for StorageKit. struct DrivePacket final { voidPtr fPacketContent; // packet body. Char fPacketMime[32]; //! identify what we're sending. SizeT fPacketSize; // packet size + UInt32 fPacketCRC32; // sanity crc, in case if good is set to false + Boolean fPacketGood; } fPacket; }; @@ -61,23 +61,44 @@ struct DriveTraits final { #define kPacketZip "file/x-zip" //! drive as a device. -typedef DeviceInterface Drive; -typedef Drive *DrivePtr; +typedef DeviceInterface DriveDevice; +typedef DriveDevice* DriveDevicePtr; -class DriveSelector final { +class Mountpoint final { public: - explicit DriveSelector(); - ~DriveSelector(); + explicit Mountpoint() = default; + ~Mountpoint() = default; - public: - HCORE_COPY_DEFAULT(DriveSelector); + HCORE_COPY_DEFAULT(Mountpoint); - DriveTraits &GetMounted(); - bool Mount(DriveTraits *drive); - DriveTraits *Unmount(); + public: + DriveDevicePtr A() { return mA; } + DriveDevicePtr B() { return mB; } + DriveDevicePtr C() { return mC; } + DriveDevicePtr D() { return mD; } + + DriveDevicePtr* GetAddressOf(int index) { + switch (index) { + case 0: + return &mA; + case 1: + return &mB; + case 2: + return &mC; + case 3: + return &mD; + default: { + GetLastError() = kErrorNoSuchDisk; + kcout << "Krnl\\Mountpoint: Check HError.\n"; + break; + } + } + + return nullptr; + } private: - DriveTraits *fDrive; + DriveDevicePtr mA, mB, mC, mD; }; } // namespace HCore diff --git a/Private/KernelKit/HError.hpp b/Private/KernelKit/HError.hpp index 247608f9..f050027f 100644 --- a/Private/KernelKit/HError.hpp +++ b/Private/KernelKit/HError.hpp @@ -27,6 +27,7 @@ inline constexpr HError kErrorThreadLocalStorage = 41; inline constexpr HError kErrorMath = 42; inline constexpr HError kErrorNoNetwork = 43; inline constexpr HError kErrorHeapOutOfMemory = 44; +inline constexpr HError kErrorNoSuchDisk = 45; Boolean ke_bug_check(void) noexcept; } // namespace HCore diff --git a/Private/NewBoot/BootKit/BootKit.hxx b/Private/NewBoot/BootKit/BootKit.hxx index 5128d02f..81624ce5 100644 --- a/Private/NewBoot/BootKit/BootKit.hxx +++ b/Private/NewBoot/BootKit/BootKit.hxx @@ -19,7 +19,7 @@ class BFileReader; class BFileRunner; #include -#include +#include #include using namespace HCore; diff --git a/Private/NewBoot/BootKit/Protocol.hxx b/Private/NewBoot/BootKit/Protocol.hxx index 055858a8..d3dc1ab1 100644 --- a/Private/NewBoot/BootKit/Protocol.hxx +++ b/Private/NewBoot/BootKit/Protocol.hxx @@ -9,5 +9,5 @@ #pragma once -#include -#include +#include +#include diff --git a/Private/NewBoot/NetBoot/EfiModule.cxx b/Private/NewBoot/NetBoot/EfiModule.cxx index a0ce13a5..36a7288c 100644 --- a/Private/NewBoot/NetBoot/EfiModule.cxx +++ b/Private/NewBoot/NetBoot/EfiModule.cxx @@ -7,8 +7,7 @@ * ======================================================== */ -#include -#include +#include extern "C" Int32 EfiMain(EfiHandlePtr handle, EfiSystemTable* SystemTable) { return kEfiOk; diff --git a/Private/NewBoot/Source/BootMain.cxx b/Private/NewBoot/Source/BootMain.cxx index c2ee87e3..35270b4b 100644 --- a/Private/NewBoot/Source/BootMain.cxx +++ b/Private/NewBoot/Source/BootMain.cxx @@ -10,7 +10,6 @@ #define __BOOTLOADER__ 1 #include -#include #include #include #include diff --git a/Private/NewBoot/Source/FileReader.cxx b/Private/NewBoot/Source/FileReader.cxx index 6696a1b4..193184c4 100644 --- a/Private/NewBoot/Source/FileReader.cxx +++ b/Private/NewBoot/Source/FileReader.cxx @@ -13,8 +13,7 @@ ------------------------------------------- */ #include -#include -#include +#include /// BUGS: 0 diff --git a/Private/NewBoot/Source/HEL/AMD64/AMD64-ATA.cxx b/Private/NewBoot/Source/HEL/AMD64/AMD64-ATA.cxx index 04755dcf..0adf7707 100644 --- a/Private/NewBoot/Source/HEL/AMD64/AMD64-ATA.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/AMD64-ATA.cxx @@ -20,7 +20,6 @@ #include #include -#include /// bugs: 0 diff --git a/Private/NewBoot/Source/HEL/AMD64/AMD64-Platform.cxx b/Private/NewBoot/Source/HEL/AMD64/AMD64-Platform.cxx index e6c962b1..ff07b4c7 100644 --- a/Private/NewBoot/Source/HEL/AMD64/AMD64-Platform.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/AMD64-Platform.cxx @@ -16,7 +16,6 @@ #include #include -#include #ifndef __BUNDLE_KERNEL__ diff --git a/Private/NewBoot/Source/String.cxx b/Private/NewBoot/Source/String.cxx index c59e2bba..9fbe1a11 100644 --- a/Private/NewBoot/Source/String.cxx +++ b/Private/NewBoot/Source/String.cxx @@ -12,7 +12,6 @@ ------------------------------------------- */ #include -#include /// bugs 0 diff --git a/Private/NewBoot/Source/TextWriter.cxx b/Private/NewBoot/Source/TextWriter.cxx index fe058aa4..b35866a5 100644 --- a/Private/NewBoot/Source/TextWriter.cxx +++ b/Private/NewBoot/Source/TextWriter.cxx @@ -12,7 +12,6 @@ ------------------------------------------- */ #include -#include /// BUGS: 0 diff --git a/Private/NewBoot/Source/Utils.cxx b/Private/NewBoot/Source/Utils.cxx index 4165af2e..4f7293bc 100644 --- a/Private/NewBoot/Source/Utils.cxx +++ b/Private/NewBoot/Source/Utils.cxx @@ -8,8 +8,7 @@ */ #include -#include -#include +#include /// BUGS: 0 diff --git a/Private/Source/DriveManager.cxx b/Private/Source/DriveManager.cxx index 371758b1..27f6cc42 100644 --- a/Private/Source/DriveManager.cxx +++ b/Private/Source/DriveManager.cxx @@ -10,47 +10,4 @@ #include #include -namespace HCore { -DriveSelector::DriveSelector() : fDrive(nullptr) {} - -DriveSelector::~DriveSelector() { - if (fDrive) { - this->Unmount(); - } -} - -DriveTraits &DriveSelector::GetMounted() { - MUST_PASS(fDrive != nullptr); - return *fDrive; -} - -bool DriveSelector::Mount(DriveTraits *drive) { - if (drive && drive->fReady()) { - if (fDrive != nullptr) { - this->Unmount(); - } - - fDrive = drive; - fDrive->fMount(); - - kcout << "Mount: " << fDrive->fName << "\n"; - - return true; - } - - return false; -} - -DriveTraits *DriveSelector::Unmount() { - if (!fDrive) return nullptr; - - DriveTraits *drivePointer = fDrive; - - fDrive->fUnmount(); - fDrive = nullptr; - - kcout << "Unmount: " << fDrive->fName << "\n"; - - return drivePointer; -} -} // namespace HCore +namespace HCore {} // namespace HCore diff --git a/Private/Source/KernelMain.cxx b/Private/Source/KernelMain.cxx index e641c7e9..1b2698c4 100644 --- a/Private/Source/KernelMain.cxx +++ b/Private/Source/KernelMain.cxx @@ -8,7 +8,7 @@ */ #include -#include +#include #include #include #include diff --git a/Private/Source/NewFS+IO.cxx b/Private/Source/NewFS+IO.cxx index 681b198a..2e6559c5 100644 --- a/Private/Source/NewFS+IO.cxx +++ b/Private/Source/NewFS+IO.cxx @@ -18,8 +18,63 @@ #ifdef __FSKIT_NEWFS__ -/// @brief This implements NewFS with Device Abstraction in mind. +#include -/// BUGS: 0 +/// Useful macros. + +#define NEWFS_WRITE(DRV, TRAITS, MP) (*MP->DRV()) << TRAITS +#define NEWFS_READ(DRV, TRAITS, MP) (*MP->DRV()) >> TRAITS + +using namespace HCore; + +Int32 KeHCFSRead(Mountpoint* Mnt, DriveTraits& DrvTraits, Int32 DrvIndex) { + if (!Mnt) return -1; + + switch (DrvIndex) { + case 0: { + NEWFS_READ(A, DrvTraits, Mnt); + break; + } + case 1: { + NEWFS_READ(B, DrvTraits, Mnt); + break; + } + case 2: { + NEWFS_READ(C, DrvTraits, Mnt); + break; + } + case 3: { + NEWFS_READ(D, DrvTraits, Mnt); + break; + } + } + + return DrvTraits.fPacket.fPacketGood; +} + +Int32 KeHCFSWrite(Mountpoint* Mnt, DriveTraits& DrvTraits, Int32 DrvIndex) { + if (!Mnt) return -1; + + switch (DrvIndex) { + case 0: { + NEWFS_WRITE(A, DrvTraits, Mnt); + break; + } + case 1: { + NEWFS_WRITE(B, DrvTraits, Mnt); + break; + } + case 2: { + NEWFS_WRITE(C, DrvTraits, Mnt); + break; + } + case 3: { + NEWFS_WRITE(D, DrvTraits, Mnt); + break; + } + } + + return DrvTraits.fPacket.fPacketGood; +} #endif // ifdef __FSKIT_NEWFS__ -- cgit v1.2.3