diff options
| -rw-r--r-- | Boot/BootKit/BootKit.hxx | 33 | ||||
| -rw-r--r-- | Boot/BootKit/Vendor/Support.hxx | 2 | ||||
| -rw-r--r-- | Boot/Sources/HEL/AMD64/BootMain.cxx | 18 | ||||
| -rw-r--r-- | Kernel/FSKit/NewFS.hxx | 10 | ||||
| -rw-r--r-- | Kernel/FirmwareKit/EPM.hxx | 19 | ||||
| -rw-r--r-- | Kernel/HALKit/AMD64/HalInterruptAPI.asm | 4 | ||||
| -rw-r--r-- | Kernel/Sources/FS/NewFS.cxx | 50 |
7 files changed, 85 insertions, 51 deletions
diff --git a/Boot/BootKit/BootKit.hxx b/Boot/BootKit/BootKit.hxx index 77943a10..3eeb8633 100644 --- a/Boot/BootKit/BootKit.hxx +++ b/Boot/BootKit/BootKit.hxx @@ -12,12 +12,13 @@ #pragma once #include <BootKit/HW/ATA.hxx> +#include <FirmwareKit/EPM.hxx> #include <CompilerKit/Version.hxx> /// include NewFS header and Support header as well. -#include <FSKit/NewFS.hxx> #include <cstring> +#include <FSKit/NewFS.hxx> #include <BootKit/Vendor/Support.hxx> /***********************************************************************************/ @@ -215,7 +216,7 @@ public: /// @brief check if partition is good. Bool IsPartitionValid() noexcept { - fDiskDev.Leak().mBase = (kNewFSAddressAsLba); + fDiskDev.Leak().mBase = (kNewFSStartLba); fDiskDev.Leak().mSize = BootDev::kSectorSize; Char buf[BootDev::kSectorSize] = {0}; @@ -284,7 +285,7 @@ private: EFI::ThrowError(L"Developer-Error", L"This is caused by the developer of the bootloader."); } - writer.Write((catalogKind->Kind == kNewFSCatalogKindFile) ? L"newosldr: Write-File: " : L"newosldr: Write-Directory: ").Write(blob->fFileName).Write(L"\r"); + writer.Write(L"newosldr: root directory: ").Write(blob->fFileName).Write(L"\r"); memcpy(catalogKind->Name, blob->fFileName, strlen(blob->fFileName)); @@ -354,13 +355,35 @@ inline Boolean BDiskFormatFactory<BootDev>::Format(const char* partName, /// if we can write a root catalog, then write the partition block. if (this->WriteRootCatalog(fileBlobs, blobCount, *partBlock)) { - fDiskDev.Leak().mBase = kNewFSAddressAsLba; + fDiskDev.Leak().mBase = kNewFSStartLba; fDiskDev.Leak().mSize = sectorSz; fDiskDev.Write(buf, sectorSz); + /// Reset buffer. + SetMem(buf, 0, sectorSz); + + BootBlockType* epmBoot = (BootBlockType*)buf; + + constexpr auto cFsName = "NewFS"; + + CopyMem(reinterpret_cast<VoidPtr>(const_cast<Char*>(cFsName)), epmBoot->Fs, StrLen(cFsName)); + + epmBoot->FsVersion = kNewFSVersionInteger; + epmBoot->LbaStart = kNewFSStartLba; + epmBoot->SectorSz = partBlock->SectorSize; + epmBoot->NumBlocks = partBlock->CatalogCount; + + CopyMem(reinterpret_cast<VoidPtr>(const_cast<Char*>("BOOT:")), epmBoot->Name, StrLen("BOOT:")); + CopyMem(reinterpret_cast<VoidPtr>(const_cast<Char*>(kEPMMagic)), epmBoot->Magic, StrLen(kEPMMagic)); + BTextWriter writer; - writer.Write(L"newosldr: Write-Partition: OK.\r"); + writer.Write(L"newosldr: wrote parition.\r"); + + fDiskDev.Leak().mBase = kEpmBase; + fDiskDev.Leak().mSize = sectorSz; + + fDiskDev.Write(buf, sectorSz); return true; } diff --git a/Boot/BootKit/Vendor/Support.hxx b/Boot/BootKit/Vendor/Support.hxx index eed59424..54183558 100644 --- a/Boot/BootKit/Vendor/Support.hxx +++ b/Boot/BootKit/Vendor/Support.hxx @@ -9,8 +9,6 @@ /// @file Support.hxx /// @brief Purpose of this file is to help port libs into the bootloader. -#include <BootKit/BootKit.hxx> - #define cLongMax ((long)(~0UL >> 1)) #define cLongMin (~cLongMax) diff --git a/Boot/Sources/HEL/AMD64/BootMain.cxx b/Boot/Sources/HEL/AMD64/BootMain.cxx index 145bdadb..6591f61e 100644 --- a/Boot/Sources/HEL/AMD64/BootMain.cxx +++ b/Boot/Sources/HEL/AMD64/BootMain.cxx @@ -89,21 +89,15 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, /// Splash screen stuff writer.Write(L"Zeta Electronics Corporation (R) newosldr: ") - .Write(BVersionString::The()); + .Write(BVersionString::The()).Write("\r"); - if (SystemTable->FirmwareVendor[0] != '\\' || - SystemTable->FirmwareVendor[1] != 'E' || - SystemTable->FirmwareVendor[2] != 'P' || - SystemTable->FirmwareVendor[3] != 'M') - { - writer.Write(L"\rnewosldr: vendor: ") - .Write(SystemTable->FirmwareVendor) - .Write(L" isn't supported.\r"); +#ifndef __DEBUG__ + writer.Write(L"\rnewosldr: AMD64 is only supported in debug mode.\r"); - EFI::Stop(); + EFI::Stop(); - CANT_REACH(); - } + CANT_REACH(); +#endif UInt32* MapKey = new UInt32(); UInt32* SizePtr = new UInt32(); diff --git a/Kernel/FSKit/NewFS.hxx b/Kernel/FSKit/NewFS.hxx index 47e42c88..8b2129da 100644 --- a/Kernel/FSKit/NewFS.hxx +++ b/Kernel/FSKit/NewFS.hxx @@ -80,8 +80,8 @@ default. #define kNewFSLbaType (NewOS::Lba) /// Start After the PM headers, pad 1024 bytes. -#define kNewFSAddressAsLba (512) -#define kNewFSCatalogStartAddress (1024 + sizeof(NewPartitionBlock) + sizeof(NewCatalog)) +#define kNewFSStartLba (1024) +#define kNewFSCatalogStartAddress ((2048) + sizeof(NewPartitionBlock) + sizeof(NewCatalog)) #define kResourceTypeDialog (10) #define kResourceTypeString (11) @@ -106,7 +106,7 @@ enum kNewFSOpticalDrive = 0x0C, // Blu-Ray/DVD kNewFSMassStorageDevice = 0xCC, // USB kNewFSScsi = 0xC4, // SCSI Hard Drive - kNewFSFlashDrive = 0xC6, + kNewFSFlashDrive = 0xC6, kNewFSUnknown = 0xFF, // Unknown device. (floppy) kNewFSDriveCount = 5, }; @@ -225,7 +225,7 @@ namespace NewOS /// @param theFork the fork itself. /// @return the fork _Output NewFork* CreateFork(_Input NewCatalog* catalog, - _Input NewFork& theFork); + _Input NewFork& theFork); /// @brief Find fork inside New filesystem. /// @param catalog the catalog. @@ -243,7 +243,7 @@ namespace NewOS _Output NewCatalog* GetCatalog(_Input const char* name); - _Output NewCatalog* CreateCatalog(_Input const char* name, + _Output NewCatalog* CreateCatalog(_Input const char* name, _Input const Int32& flags, _Input const Int32& kind); diff --git a/Kernel/FirmwareKit/EPM.hxx b/Kernel/FirmwareKit/EPM.hxx index 47e3fbfb..b3f17889 100644 --- a/Kernel/FirmwareKit/EPM.hxx +++ b/Kernel/FirmwareKit/EPM.hxx @@ -41,22 +41,10 @@ struct PACKED BootBlock NewOS::Int64 NumBlocks; NewOS::Int64 SectorSz; NewOS::Int64 LbaStart; -}; - -/** - * @brief The EPM partition block. - * used to describe a partition inside a media, doesn't exist on some platforms. - */ -struct PACKED PartitionBlock -{ - NewOS::Char Name[kEPMNameLength]; - NewOS::Int32 Version; - NewOS::Int64 LbaEnd; - NewOS::Int64 SectorSz; - NewOS::Int64 LbaStart; NewOS::Int16 Kind; NewOS::Int32 FsVersion; NewOS::Char Fs[kEPMFilesystemLength]; /* NewFS, ffs2... */ + NewOS::Char Reserved[409]; // to fill a full sector. }; /* @brief AMD64 magic for EPM */ @@ -102,8 +90,7 @@ enum kEPMKind kEPMNewOS = 0x1f, // This kernel. }; -typedef struct BootBlock BootBlockType; -typedef struct PartitionBlock PartitionBlockType; +typedef struct BootBlock BootBlockType; #ifdef __NEWOS_AMD64__ #define kEPMMagic kEPMMagic86 @@ -123,6 +110,8 @@ typedef struct PartitionBlock PartitionBlockType; #define kEPMRevision (0xAD) ///! @brief Current EPM revision #define kEPMRevisionUEFI (0xAF) +/// !@brief EPM base address +#define kEpmBase (0U) /// END OF SPECS diff --git a/Kernel/HALKit/AMD64/HalInterruptAPI.asm b/Kernel/HALKit/AMD64/HalInterruptAPI.asm index 9c5b0d6a..016c9cd8 100644 --- a/Kernel/HALKit/AMD64/HalInterruptAPI.asm +++ b/Kernel/HALKit/AMD64/HalInterruptAPI.asm @@ -122,6 +122,8 @@ IntNormal 31 [extern hal_apic_acknowledge] __NEW_INT_32: +;; make this active, SMP works again. +%if 0 push rax push rcx push rdx @@ -160,7 +162,7 @@ __NEW_INT_32: ;; tell there local apic that we're done. mov [0xFEE00000 + 0xB0], rax ; LAPIC_EOI - +%endif iretq IntNormal 33 diff --git a/Kernel/Sources/FS/NewFS.cxx b/Kernel/Sources/FS/NewFS.cxx index 255511e3..541b7eef 100644 --- a/Kernel/Sources/FS/NewFS.cxx +++ b/Kernel/Sources/FS/NewFS.cxx @@ -15,6 +15,7 @@ #include <NewKit/KernelCheck.hpp> #include <NewKit/String.hpp> #include <NewKit/Utils.hpp> +#include <FirmwareKit/EPM.hxx> using namespace NewOS; @@ -36,7 +37,7 @@ STATIC MountpointInterface sMountpointInterface; /// @param theFork the fork itself. /// @return the fork _Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog, - _Input NewFork& theFork) + _Input NewFork& theFork) { if (!sMountpointInterface.GetAddressOf(this->fDriveIndex)) return nullptr; @@ -205,7 +206,7 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name) /// @param flags the flags of the catalog. /// @param kind the catalog kind. /// @return catalog pointer. -_Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, +_Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, _Input const Int32& flags, _Input const Int32& kind) { @@ -320,7 +321,7 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, { nextSibling = (NewCatalog*)catalogBuf; - if (startFree <= kNewFSAddressAsLba) + if (startFree <= kNewFSStartLba) { delete catalogChild; delete catalog; @@ -335,7 +336,7 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, drive->fPacket.fPacketContent = sectorBufPartBlock; drive->fPacket.fPacketSize = kNewFSSectorSz; - drive->fPacket.fLba = kNewFSAddressAsLba; + drive->fPacket.fLba = kNewFSStartLba; drive->fInput(&drive->fPacket); @@ -380,7 +381,7 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, drive->fPacket.fPacketContent = sectorBufPartBlock; drive->fPacket.fPacketSize = kNewFSSectorSz; - drive->fPacket.fLba = kNewFSAddressAsLba; + drive->fPacket.fLba = kNewFSStartLba; drive->fInput(&drive->fPacket); @@ -433,7 +434,7 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive) drive->fPacket.fPacketContent = sectorBuf; drive->fPacket.fPacketSize = kNewFSSectorSz; - drive->fPacket.fLba = kNewFSAddressAsLba; + drive->fPacket.fLba = kNewFSStartLba; drive->fInput(&drive->fPacket); @@ -472,7 +473,7 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive) drive->fPacket.fPacketContent = sectorBuf; drive->fPacket.fPacketSize = kNewFSSectorSz; - drive->fPacket.fLba = kNewFSAddressAsLba; + drive->fPacket.fLba = kNewFSStartLba; drive->fOutput(&drive->fPacket); @@ -488,6 +489,33 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive) /// write the root catalog. this->CreateCatalog(kNewFSRoot, 0, kNewFSCatalogKindDir); + if (partBlock->Flags & kNewFSPartitionTypeBoot) + { + /// make it bootable when needed. + Char bufEpmHdr[kNewFSSectorSz] = {0}; + + BootBlockType* epmBoot = (BootBlockType*)bufEpmHdr; + + constexpr auto cFsName = "NewFS"; + + rt_copy_memory(reinterpret_cast<VoidPtr>(const_cast<Char*>(cFsName)), epmBoot->Fs, rt_string_len(cFsName)); + + epmBoot->FsVersion = kNewFSVersionInteger; + epmBoot->LbaStart = kNewFSStartLba; + epmBoot->SectorSz = partBlock->SectorSize; + epmBoot->NumBlocks = partBlock->CatalogCount; + + rt_copy_memory(reinterpret_cast<VoidPtr>(const_cast<Char*>("BOOT:")), epmBoot->Name, rt_string_len("BOOT:")); + + rt_copy_memory(reinterpret_cast<VoidPtr>(const_cast<Char*>(kEPMMagic)), epmBoot->Magic, rt_string_len(kEPMMagic)); + + drive->fPacket.fPacketContent = bufEpmHdr; + drive->fPacket.fPacketSize = (epmBoot->SectorSz); + drive->fPacket.fLba = kEpmBase; + + drive->fOutput(&drive->fPacket); + } + return true; } @@ -604,7 +632,7 @@ _Output NewCatalog* NewFSParser::FindCatalog(_Input const char* catalogName, drive->fPacket.fPacketContent = sectorBuf; drive->fPacket.fPacketSize = sizeof(NewPartitionBlock); - drive->fPacket.fLba = kNewFSAddressAsLba; + drive->fPacket.fLba = kNewFSStartLba; drive->fInput(&drive->fPacket); @@ -688,7 +716,7 @@ _NewFSSearchThroughCatalogList: _NewFSContinueSearch: startCatalogList = catalog->NextSibling; - if (startCatalogList <= kNewFSAddressAsLba) + if (startCatalogList <= kNewFSStartLba) break; drive->fPacket.fLba = startCatalogList; @@ -769,7 +797,7 @@ Boolean NewFSParser::RemoveCatalog(_Input const Char* catalogName) Char partitionBlockBuf[sizeof(NewPartitionBlock)] = {0}; - drive->fPacket.fLba = kNewFSAddressAsLba; + drive->fPacket.fLba = kNewFSStartLba; drive->fPacket.fPacketContent = partitionBlockBuf; drive->fPacket.fPacketSize = sizeof(NewPartitionBlock); @@ -927,7 +955,7 @@ namespace NewOS::Detail Char partitionBlockBuf[sizeof(NewPartitionBlock)] = {0}; - sMountpointInterface.A().fPacket.fLba = kNewFSAddressAsLba; + sMountpointInterface.A().fPacket.fLba = kNewFSStartLba; sMountpointInterface.A().fPacket.fPacketContent = partitionBlockBuf; sMountpointInterface.A().fPacket.fPacketSize = sizeof(NewPartitionBlock); |
