summaryrefslogtreecommitdiffhomepage
path: root/Private
diff options
context:
space:
mode:
authorAmlal <amlalelmahrouss@icloud.com>2024-04-26 14:06:51 +0000
committerAmlal <amlalelmahrouss@icloud.com>2024-04-26 14:06:51 +0000
commitdb0681412191dcceb5aa99cf31fb8339d6bc4adb (patch)
tree590a4ccfa858b45ddeef4a4a279bdbb57f2c80e8 /Private
parent97eb8462433a831f8a02a08acfc7ca32e794d37d (diff)
parent3210d2e3f38a73090bcdbdd68623c676868529ce (diff)
Merged in MHR-16 (pull request #7)
MHR-16
Diffstat (limited to 'Private')
-rw-r--r--Private/ArchKit/ArchKit.hpp1
-rw-r--r--Private/FirmwareKit/EFI/API.hxx3
-rw-r--r--Private/FirmwareKit/EFI/EFI.hxx10
-rw-r--r--Private/FirmwareKit/Handover.hxx2
-rw-r--r--Private/HALKit/AMD64/HalACPIFactoryInterface.cxx17
-rw-r--r--Private/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp16
-rw-r--r--Private/HALKit/AMD64/HalKernelMain.cxx1
-rw-r--r--Private/NewBoot/BootKit/BootKit.hxx5
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootMain.cxx73
-rw-r--r--Private/NewBoot/Source/makefile10
10 files changed, 77 insertions, 61 deletions
diff --git a/Private/ArchKit/ArchKit.hpp b/Private/ArchKit/ArchKit.hpp
index 93e39ee3..d7c52108 100644
--- a/Private/ArchKit/ArchKit.hpp
+++ b/Private/ArchKit/ArchKit.hpp
@@ -48,6 +48,5 @@ inline NewOS::VoidPtr kKernelVirtualStart;
inline NewOS::UIntPtr kKernelVirtualSize;
inline NewOS::VoidPtr kKernelPhysicalStart;
-inline NewOS::UIntPtr kKernelPhysicalSize;
#include <FirmwareKit/Handover.hxx>
diff --git a/Private/FirmwareKit/EFI/API.hxx b/Private/FirmwareKit/EFI/API.hxx
index 0e2ef200..4cf8e603 100644
--- a/Private/FirmwareKit/EFI/API.hxx
+++ b/Private/FirmwareKit/EFI/API.hxx
@@ -47,8 +47,7 @@ Bascially frees everything we have in the EFI side.
inline void ExitBootServices(UInt64 MapKey, EfiHandlePtr ImageHandle) noexcept {
if (!ST) return;
- while (ST->BootServices->ExitBootServices(ImageHandle, MapKey) != kEfiOk)
- ;
+ ST->BootServices->ExitBootServices(ImageHandle, MapKey);
}
enum {
diff --git a/Private/FirmwareKit/EFI/EFI.hxx b/Private/FirmwareKit/EFI/EFI.hxx
index 7f8223cf..c967647c 100644
--- a/Private/FirmwareKit/EFI/EFI.hxx
+++ b/Private/FirmwareKit/EFI/EFI.hxx
@@ -50,6 +50,9 @@ typedef struct EfiHandle {
/* UEFI uses wide characters by default. */
typedef WideChar EfiCharType;
+typedef UInt64 EfiPhysicalAddress;
+typedef UIntPtr EfiVirtualAddress;
+
/// 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
@@ -200,13 +203,13 @@ typedef struct EfiMemoryDescriptor {
/// 0xfffffffffffff000. Kind EFI_PHYSICAL_ADDRESS is defined in the
/// AllocatePages() function description
///
- UIntPtr PhysicalStart;
+ EfiPhysicalAddress 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;
+ EfiVirtualAddress VirtualStart;
///
/// NumberOfPagesNumber of 4 KiB pages in the memory region.
/// NumberOfPages must not be 0, and must not be any value
@@ -417,9 +420,6 @@ typedef struct EfiFileDevicePathProtocol {
WideChar Path[kPathLen];
} EfiFileDevicePathProtocol;
-typedef UInt64 EfiPhysicalAddress;
-typedef UIntPtr EfiVirtualAddress;
-
typedef UInt64(EFI_API *EfiExitBootServices)(VoidPtr ImageHandle,
UInt32 MapKey);
diff --git a/Private/FirmwareKit/Handover.hxx b/Private/FirmwareKit/Handover.hxx
index 4131467d..afec440d 100644
--- a/Private/FirmwareKit/Handover.hxx
+++ b/Private/FirmwareKit/Handover.hxx
@@ -64,7 +64,6 @@ struct HandoverInformationHeader {
voidPtr f_VirtualStart;
SizeT f_VirtualSize;
voidPtr f_PhysicalStart;
- SizeT f_PhysicalSize;
WideChar f_FirmwareVendorName[32];
SizeT f_FirmwareVendorLen;
struct {
@@ -79,6 +78,7 @@ struct HandoverInformationHeader {
UInt32 f_PixelFormat;
UInt32 f_PixelPerLine;
} f_GOP;
+ UInt64 f_FirmwareSpecific[8];
};
/// @brief Bootloader main type.
diff --git a/Private/HALKit/AMD64/HalACPIFactoryInterface.cxx b/Private/HALKit/AMD64/HalACPIFactoryInterface.cxx
index 983c7219..d18d49cf 100644
--- a/Private/HALKit/AMD64/HalACPIFactoryInterface.cxx
+++ b/Private/HALKit/AMD64/HalACPIFactoryInterface.cxx
@@ -37,7 +37,7 @@ Void ACPIFactoryInterface::Shutdown() {
}
/// @brief Reboot (shutdowns on qemu.)
-/// @return
+/// @return
Void ACPIFactoryInterface::Reboot() {
#ifdef __DEBUG__
rt_shutdown_acpi_qemu_30_plus();
@@ -60,22 +60,23 @@ ErrorOr<voidPtr> ACPIFactoryInterface::Find(const char *signature) {
return ErrorOr<voidPtr>{-4};
}
- SDT* xsdt = (SDT*)(rsdPtr->XsdtAddress >> (rsdPtr->XsdtAddress & 0xfff));
- SizeT num = (xsdt->Length + sizeof(SDT)) / 8;
+ SDT* xsdt = (SDT*)(rsdPtr->RsdtAddress + rsdPtr->XsdtAddress);
+ SizeT num = xsdt->Length + sizeof(SDT) / 8;
kcout << "ACPI: Number of entries: " << number(num) << endl;
+ kcout << "ACPI: Address of XSDT: " << number((UIntPtr)xsdt) << endl;
constexpr short ACPI_SIGNATURE_LENGTH = 4;
for (Size index = 0; index < num; ++index) {
SDT *sdt = (SDT*)*((UInt64*)(UInt64)xsdt + sizeof(SDT) + (index * 8));
- for (int signature_index = 0; signature_index < 4; signature_index++){
- if (sdt->Signature[signature_index] != signature[signature_index])
- break;
+ for (int signature_index = 0; signature_index < 4; signature_index++){
+ if (sdt->Signature[signature_index] != signature[signature_index])
+ break;
- if (signature_index == 3) return ErrorOr<voidPtr>(reinterpret_cast<voidPtr>((SDT*)sdt));;
- }
+ if (signature_index == 3) return ErrorOr<voidPtr>(reinterpret_cast<voidPtr>((SDT*)sdt));
+ }
}
return ErrorOr<voidPtr>{-1};
diff --git a/Private/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp b/Private/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp
index 0761114d..37e8f0cc 100644
--- a/Private/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp
+++ b/Private/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp
@@ -6,6 +6,7 @@
#include <Builtins/ACPI/ACPIFactoryInterface.hxx>
#include <HALKit/AMD64/Processor.hpp>
+#include "NewKit/KernelCheck.hpp"
///////////////////////////////////////////////////////////////////////////////////////
@@ -45,12 +46,12 @@ STATIC const char* kApicSignature = "APIC";
/// @brief Multiple APIC descriptor table.
struct MadtType final : public SDT {
struct MadtAddress final {
- UInt32 fPhysicalAddress;
UInt32 fFlags; // 1 = Dual Legacy PICs installed
+ UInt32 fPhysicalAddress;
Char fType;
Char fRecLen; // record length
- };
+ } Madt[];
};
struct MadtProcessorLocalApic final {
@@ -97,11 +98,12 @@ void hal_system_get_cores(voidPtr rsdPtr) {
auto acpi = ACPIFactoryInterface(rsdPtr);
kApicMadt = acpi.Find(kApicSignature).Leak().Leak();
- MUST_PASS(kApicMadt); // MADT must exist.
-
- kcout << "New OS: Successfuly fetched the MADT!\r\n";
-
- kApicInfoBlock = (MadtType*)kApicMadt;
+ if (kApicMadt) {
+ kcout << "New OS: Successfuly fetched the MADT!\r\n";
+ kApicInfoBlock = (MadtType*)kApicMadt;
+ } else {
+ MUST_PASS(false);
+ }
}
} // namespace NewOS::HAL
diff --git a/Private/HALKit/AMD64/HalKernelMain.cxx b/Private/HALKit/AMD64/HalKernelMain.cxx
index 57c37778..d6b4ab76 100644
--- a/Private/HALKit/AMD64/HalKernelMain.cxx
+++ b/Private/HALKit/AMD64/HalKernelMain.cxx
@@ -34,7 +34,6 @@ EXTERN_C void hal_init_platform(
reinterpret_cast<NewOS::UIntPtr>(HandoverHeader->f_VirtualStart) +
kVirtualAddressStartOffset);
- kKernelPhysicalSize = HandoverHeader->f_PhysicalSize;
kKernelPhysicalStart = HandoverHeader->f_PhysicalStart;
STATIC NewOS::HAL::Detail::NewOSGDT GDT = {
diff --git a/Private/NewBoot/BootKit/BootKit.hxx b/Private/NewBoot/BootKit/BootKit.hxx
index f7f33958..e2e371dd 100644
--- a/Private/NewBoot/BootKit/BootKit.hxx
+++ b/Private/NewBoot/BootKit/BootKit.hxx
@@ -255,7 +255,12 @@ private:
Lba startLba = partBlock.StartCatalog;
BTextWriter writer;
+ SizeT blobCounter = 0UL;
+
while (blob) {
+ if (blobCounter > blobCount) break;
+ ++blobCounter;
+
NewCatalog* catalogKind = new NewCatalog();
memset(catalogKind, 0, sizeof(NewCatalog));
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
index 68762089..558bf001 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
@@ -70,31 +70,15 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
.Write(SystemTable->FirmwareVendor)
.Write(L"\r\n");
- UInt32 MapKey = 0;
- UInt32* SizePtr = nullptr;
- EfiMemoryDescriptor* Descriptor = nullptr;
- UInt32 SzDesc = 0;
- UInt32 RevDesc = 0;
-
- if (BS->AllocatePool(EfiLoaderData, sizeof(UInt32), (VoidPtr*)&SizePtr) !=
- kEfiOk) {
- EFI::ThrowError(L"Bad-Alloc", L"New Boot ran out of memory!");
- }
-
- /****
- *
- * Load kernel into memory.
- *
- */
+ UInt32* MapKey = new UInt32();
+ UInt32* SizePtr = new UInt32();
+ EfiMemoryDescriptor* Descriptor = new EfiMemoryDescriptor();
+ UInt32* SzDesc = new UInt32();
+ UInt32* RevDesc = new UInt32();
*SizePtr = sizeof(EfiMemoryDescriptor);
- if (BS->AllocatePool(EfiLoaderData, sizeof(EfiMemoryDescriptor),
- (VoidPtr*)&Descriptor) != kEfiOk) {
- EFI::ThrowError(L"Bad-Alloc", L"New Boot ran out of memory!");
- }
-
- HEL::HandoverInformationHeader* handoverHdrPtr = nullptr;
+ HEL::HandoverInformationHeader* handoverHdrPtr = new HEL::HandoverInformationHeader();
for (SizeT indexVT = 0; indexVT < SystemTable->NumberOfTableEntries;
++indexVT) {
@@ -141,20 +125,21 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
ToolboxClearRsrc();
- BS->AllocatePool(EfiLoaderData, sizeof(HEL::HandoverInformationHeader),
- (VoidPtr*)&handoverHdrPtr);
+ EfiPhysicalAddress* whereAddress =
+ reinterpret_cast<EfiPhysicalAddress*>(kBootVirtualAddress);
- handoverHdrPtr->f_PhysicalStart = 0;
- handoverHdrPtr->f_PhysicalSize = 0;
+ BS->GetMemoryMap(SizePtr, Descriptor, MapKey, SzDesc, RevDesc);
+
+ handoverHdrPtr->f_PhysicalStart = (VoidPtr)Descriptor->PhysicalStart;
+
+ handoverHdrPtr->f_FirmwareSpecific[0] = Descriptor->Attribute;
+ handoverHdrPtr->f_FirmwareSpecific[1] = Descriptor->Kind;
- EfiPhysicalAddress* whereAddress =
- reinterpret_cast<EfiPhysicalAddress*>(kBootVirtualAddress);
BS->AllocatePages(EfiAllocateType::AllocateAnyPages,
EfiMemoryType::EfiConventionalMemory, 1, whereAddress);
- handoverHdrPtr->f_VirtualStart = reinterpret_cast<voidPtr>(whereAddress);
-
+ handoverHdrPtr->f_VirtualStart = (VoidPtr)Descriptor->VirtualStart;
handoverHdrPtr->f_VirtualSize = Descriptor->NumberOfPages; /* # of pages */
handoverHdrPtr->f_FirmwareVendorLen = BStrLen(SystemTable->FirmwareVendor);
@@ -209,7 +194,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
memcpy(bootDesc.fForkName, kNewFSResourceFork, strlen(kNewFSResourceFork));
bootDesc.fBlobSz = BootDeviceATA::kSectorSize;
- bootDesc.fBlob = new Char[rootDesc.fBlobSz];
+ bootDesc.fBlob = new Char[bootDesc.fBlobSz];
memset(bootDesc.fBlob, 0, bootDesc.fBlobSz);
@@ -217,12 +202,32 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
strlen(kMachineModel " startup folder."));
rootDesc.fNext = &bootDesc;
- rootDesc.fNext->fPrev = &rootDesc;
+ rootDesc.fNext->fPrev = nullptr;
+
+ BDiskFormatFactory<BootDeviceATA>::BFileDescriptor appDesc{0};
+
+ appDesc.fKind = kNewFSCatalogKindDir;
+
+ memcpy(appDesc.fFileName, "/Applications", strlen("/Applications"));
+ memcpy(appDesc.fForkName, kNewFSResourceFork, strlen(kNewFSResourceFork));
+
+ appDesc.fBlobSz = BootDeviceATA::kSectorSize;
+ appDesc.fBlob = new Char[appDesc.fBlobSz];
+
+ memset(appDesc.fBlob, 0, appDesc.fBlobSz);
+
+ memcpy(appDesc.fBlob, kMachineModel " applications folder.",
+ strlen(kMachineModel " applications folder."));
+
+ appDesc.fNext = nullptr;
+ appDesc.fNext->fPrev = &bootDesc;
+
+ bootDesc.fNext = &appDesc;
- diskFormatter.Format(kMachineModel, &rootDesc, 2);
+ diskFormatter.Format(kMachineModel, &rootDesc, 3);
}
- EFI::ExitBootServices(MapKey, ImageHandle);
+ EFI::ExitBootServices(*MapKey, ImageHandle);
hal_init_platform(kHandoverHeader);
diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile
index 8306f844..f3a292c5 100644
--- a/Private/NewBoot/Source/makefile
+++ b/Private/NewBoot/Source/makefile
@@ -28,7 +28,13 @@ EMU_FLAGS=-net none -smp 4 -m 8G -M q35 -bios OVMF.fd -device piix3-ide,id=ide -
LD_FLAGS=-e Main --subsystem=10
+ifeq ($(NEWS_STANDLONE), )
OBJ=*.o ../../Objects/*.obj
+else
+RESCMD=$(WINDRES) BootloaderRsrc.rsrc -O coff -o BootloaderRsrc.o
+STANDALONE_MACRO=-D__STANDALONE__
+OBJ=*.o
+endif
REM=rm
REM_FLAG=-f
@@ -60,8 +66,8 @@ endif
.PHONY: compile-amd64
compile-amd64:
- # $(WINDRES) BootloaderRsrc.rsrc -O coff -o BootloaderRsrc.o
- $(CC_GNU) $(NEWOS_MODEL) $(FLAG_GNU) $(DEBUG) $(wildcard HEL/AMD64/*.cxx) $(wildcard HEL/AMD64/*.S) $(wildcard *.cxx)
+ $(RESCMD)
+ $(CC_GNU) $(NEWOS_MODEL) $(STANDALONE_MACRO) $(FLAG_GNU) $(DEBUG) $(wildcard HEL/AMD64/*.cxx) $(wildcard HEL/AMD64/*.S) $(wildcard *.cxx)
.PHONY: run-efi-amd64
run-efi-amd64: