summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-04 20:32:18 +0100
committerAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-04 20:32:18 +0100
commitb76f26d281c77e3fa028d4217a1456c43ab68d06 (patch)
tree66cebff0951c52fbf0b5289ca4c1ee3584e33776
parent9fe3b6e1e2447a11644307e83df2b109b24fe0d1 (diff)
HCR-11 : Found the reason why it doesn't work, fixing it tomorrow.
Signed-off-by: Amlal El Mahrouss <amlalelmahrouss@icloud.com>
-rw-r--r--Private/EFIKit/Api.hxx2
-rw-r--r--Private/EFIKit/EFI.hxx101
-rw-r--r--Private/EFIKit/Handover.hxx2
-rw-r--r--Private/NetworkKit/MAC.hxx30
-rw-r--r--Private/NewBoot/BootKit/BootKit.hxx8
-rw-r--r--Private/NewBoot/Source/Entrypoint.cxx6
-rw-r--r--Private/NewBoot/Source/FileReader.cxx42
-rw-r--r--Private/NewBoot/Source/makefile8
-rw-r--r--Private/NewKit/Defines.hpp8
-rw-r--r--Private/makefile2
10 files changed, 151 insertions, 58 deletions
diff --git a/Private/EFIKit/Api.hxx b/Private/EFIKit/Api.hxx
index a96eb603..0c667cb2 100644
--- a/Private/EFIKit/Api.hxx
+++ b/Private/EFIKit/Api.hxx
@@ -64,6 +64,8 @@ inline void InitEFI(EfiSystemTable *SystemTable) noexcept {
ST->ConOut->ClearScreen(SystemTable->ConOut);
ST->ConOut->SetAttribute(SystemTable->ConOut, kEFIYellow);
+
+ ST->BootServices->SetWatchdogTimer(0, 0, 0, nullptr);
}
#ifdef __BOOTLOADER__
diff --git a/Private/EFIKit/EFI.hxx b/Private/EFIKit/EFI.hxx
index 7b034f7c..0e7e22eb 100644
--- a/Private/EFIKit/EFI.hxx
+++ b/Private/EFIKit/EFI.hxx
@@ -24,7 +24,7 @@ using namespace HCore;
/* we always use stdcall in EFI, the pascal way of calling functions. */
#ifndef EPI_API
-#define EFI_API __attribute__((stdcall))
+#define EFI_API __attribute__((ms_abi))
#endif // ifndef EPI_API
// Forwar decls
@@ -43,6 +43,8 @@ struct EfiGraphicsOutputProtocol;
struct EfiBitmask;
struct EfiFileProtocol;
+typedef UInt64 EfiStatusType;
+
/// @brief Core Handle Type
/// This is like NT's Win32 HANDLE type.
typedef struct EfiHandle {
@@ -409,7 +411,7 @@ typedef UInt64(EFI_API *EfiExitBootServices)(VoidPtr ImageHandle,
UInt32 MapKey);
typedef UInt64(EFI_API *EfiAllocatePages)(EfiAllocateType AllocType,
- EfiMemoryType MemType,
+ EfiMemoryType MemType, UInt32 Count,
EfiPhysicalAddress *Memory);
typedef UInt64(EFI_API *EfiFreePages)(EfiPhysicalAddress *Memory, UInt32 Pages);
@@ -482,7 +484,8 @@ typedef struct EfiBootServices {
EfiExitBootServices ExitBootServices;
UIntPtr GetNextMonotonicCount;
UIntPtr Stall;
- UIntPtr SetWatchdogTimer;
+ EfiStatusType(EFI_API *SetWatchdogTimer)(UInt32 Timeout, UInt64 WatchdogCode,
+ UInt32 DataSize, EfiCharType *Data);
UIntPtr ConnectController;
UIntPtr DisconnectController;
EfiOpenProtocol OpenProtocol;
@@ -518,8 +521,6 @@ typedef struct EfiSimpleTextOutputProtocol {
VoidPtr Mode;
} EfiSimpleTextOutputProtocol;
-typedef UInt32 EfiStatusType;
-
typedef UInt64(EFI_API *EfiOpenVolume)(struct EfiSimpleFilesystemProtocol *,
struct EfiFileProtocol **);
@@ -600,35 +601,85 @@ enum {
#define kEFIDirectory 0x10
#define kEFIArchive 0x20
-struct EfiFileProtocol final {
+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 (*Open)(struct EfiFileProtocol *This,
- struct EfiFileProtocol **Out, EfiCharType *CharType,
- UInt64 OpenMode, UInt64 Attrib);
+ EfiStatusType(EFI_API *Open)(struct EfiFileProtocol *This,
+ struct EfiFileProtocol **Out,
+ EfiCharType *CharType, UInt64 OpenMode,
+ UInt64 Attrib);
- EfiStatusType (*Close)(struct EfiFileProtocol *This);
+ EfiStatusType(EFI_API *Close)(struct EfiFileProtocol *This);
- EfiStatusType (*Delete)(struct EfiFileProtocol *This);
+ EfiStatusType(EFI_API *Delete)(struct EfiFileProtocol *This);
- EfiStatusType (*Read)(struct EfiFileProtocol *This, UInt32 *BufSize,
- VoidPtr BufOut);
+ EfiStatusType(EFI_API *Read)(struct EfiFileProtocol *This, UInt32 *BufSize,
+ VoidPtr BufOut);
- EfiStatusType (*Write)(struct EfiFileProtocol *This, UInt32 *BufSize,
- VoidPtr BufOut);
+ EfiStatusType(EFI_API *Write)(struct EfiFileProtocol *This, UInt32 *BufSize,
+ VoidPtr BufOut);
- EfiStatusType (*GetPosition)(EfiFileProtocol *This, UInt64 *Position);
+ EfiStatusType(EFI_API *GetPosition)(EfiFileProtocol *This, UInt64 *Position);
- EfiStatusType (*SetPosition)(EfiFileProtocol *This, UInt64 *Position);
+ EfiStatusType(EFI_API *SetPosition)(EfiFileProtocol *This, UInt64 *Position);
- EfiStatusType (*GetInfo)(struct EfiFileProtocol *, struct EfiGUID *, UInt32 *,
- void *);
+ EfiStatusType(EFI_API *GetInfo)(struct EfiFileProtocol *, struct EfiGUID *,
+ UInt32 *, void *);
- EfiStatusType (*SetInfo)(struct EfiFileProtocol *, struct EfiGUID *, UInt32 *,
- void *);
+ EfiStatusType(EFI_API *SetInfo)(struct EfiFileProtocol *, struct EfiGUID *,
+ UInt32 *, void *);
- EfiStatusType (*Flush)(EfiFileProtocol *);
-};
+ 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;
typedef struct EfiTime {
UInt16 Year;
@@ -656,7 +707,7 @@ struct EfiFileInfo final {
UInt64 FileSize;
UInt64 PhysicalSize;
EfiTime CreateTime;
- EfiTime LastAccessTome;
+ EfiTime LastAccessTime;
EfiTime EditTime;
UInt64 Attribute;
// Do not touch that, it's EFI specific.
@@ -667,4 +718,4 @@ struct EfiFileInfo final {
#define EFI_FILE_PROTOCOL_REVISION2 0x00020000
#define EFI_FILE_PROTOCOL_LATEST_REVISION EFI_FILE_PROTOCOL_REVISION2
-#endif // __EFI__
+#endif // ifndef __EFI__
diff --git a/Private/EFIKit/Handover.hxx b/Private/EFIKit/Handover.hxx
index a8248296..deb62eeb 100644
--- a/Private/EFIKit/Handover.hxx
+++ b/Private/EFIKit/Handover.hxx
@@ -26,7 +26,7 @@
#define kHandoverMagic 0xBADCC
-#define kHandoverStartKernel 0xFFFF800000000000
+#define kHandoverStartKernel 0xffffffff10000000
#define kHandoverStructSz sizeof(HEL::HandoverHeader)
namespace HCore::HEL {
diff --git a/Private/NetworkKit/MAC.hxx b/Private/NetworkKit/MAC.hxx
new file mode 100644
index 00000000..29a85d7a
--- /dev/null
+++ b/Private/NetworkKit/MAC.hxx
@@ -0,0 +1,30 @@
+/*
+ * ========================================================
+ *
+ * HCore
+ * Copyright Mahrouss Logic, all rights reserved.
+ *
+ * ========================================================
+ */
+
+#pragma once
+
+#include <NewKit/Array.hpp>
+#include <NewKit/Defines.hpp>
+#include <NewKit/String.hpp>
+
+namespace HCore {
+class MacAddressGetter;
+
+/// \brief This retrieves the MAC address of the device.
+/// \note Checks on \Mount\Devices\MacAddr
+class MacAddressGetter final {
+ public:
+ explicit MacAddressGetter() = default;
+
+ public:
+ StringView& AsString();
+ Array<WideChar, 12>& AsBytes();
+};
+
+} // namespace HCore
diff --git a/Private/NewBoot/BootKit/BootKit.hxx b/Private/NewBoot/BootKit/BootKit.hxx
index 61ad81f2..5e0ca135 100644
--- a/Private/NewBoot/BootKit/BootKit.hxx
+++ b/Private/NewBoot/BootKit/BootKit.hxx
@@ -166,10 +166,12 @@ inline Void InitQT() noexcept {
BS->LocateProtocol(&gopGuid, nullptr, (VoidPtr *)&kGop);
- for (int w = 0; w < kGop->Mode->Info->VerticalResolution; ++w) {
- for (int h = 0; h < kGop->Mode->Info->HorizontalResolution; ++h) {
+ UInt16 kStride = 4;
+
+ for (int x = 0; x < kGop->Mode->Info->VerticalResolution; ++x) {
+ for (int y = 0; y < kGop->Mode->Info->HorizontalResolution; ++y) {
*((UInt32 *)(kGop->Mode->FrameBufferBase +
- 4 * kGop->Mode->Info->PixelsPerScanLine * w + 4 * h)) =
+ 4 * kGop->Mode->Info->PixelsPerScanLine * x + kStride * y)) =
RGB(10, 10, 10);
}
}
diff --git a/Private/NewBoot/Source/Entrypoint.cxx b/Private/NewBoot/Source/Entrypoint.cxx
index bdcfab4d..c6ae4572 100644
--- a/Private/NewBoot/Source/Entrypoint.cxx
+++ b/Private/NewBoot/Source/Entrypoint.cxx
@@ -14,8 +14,8 @@
#include <KernelKit/PE.hpp>
#include <NewKit/Ref.hpp>
-EFI_EXTERN_C Int EfiMain(EfiHandlePtr ImageHandle,
- EfiSystemTable* SystemTable) {
+EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
+ EfiSystemTable* SystemTable) {
InitEFI(SystemTable);
InitQT();
@@ -29,7 +29,7 @@ EFI_EXTERN_C Int EfiMain(EfiHandlePtr ImageHandle,
.WriteString(SystemTable->FirmwareVendor)
.WriteString(L"\r\n");
- BFileReader img(L"\\EFI\\BOOT\\HCOREKRNL.EXE");
+ BFileReader img(L"HCOREKRNL.EXE");
img.Fetch(ImageHandle);
VoidPtr blob = img.Blob();
diff --git a/Private/NewBoot/Source/FileReader.cxx b/Private/NewBoot/Source/FileReader.cxx
index a66f2c71..be0e7746 100644
--- a/Private/NewBoot/Source/FileReader.cxx
+++ b/Private/NewBoot/Source/FileReader.cxx
@@ -16,6 +16,10 @@
#include <EFIKit/Api.hxx>
#include <EFIKit/Handover.hxx>
+#include "EFIKit/EFI.hxx"
+#include "KernelKit/PE.hpp"
+#include "NewKit/Defines.hpp"
+
////////////////////////////////////////////////////////////////////////////////////////////////////
//
//
@@ -85,12 +89,10 @@ Void BFileReader::Fetch(EfiHandlePtr ImageHandle) {
return;
}
- /// Open kernel.
-
- EfiFileProtocol* kernelFile;
+ EfiFileProtocol* kernelFile = nullptr;
- if (rootFs->Open(rootFs, &kernelFile, mPath, kEFIFileRead,
- kEFIReadOnly | kEFIHidden | kEFISystem) != kEfiOk) {
+ if (rootFs->Open(rootFs, &kernelFile, mPath, kEFIFileRead, kEFIReadOnly) !=
+ kEfiOk) {
mWriter.WriteString(L"HCoreLdr: Fetch-Protocol: No-Such-Path: ")
.WriteString(mPath)
.WriteString(L"\r\n");
@@ -98,6 +100,8 @@ Void BFileReader::Fetch(EfiHandlePtr ImageHandle) {
return;
}
+ rootFs->Close(rootFs);
+
if (kernelFile->Revision < EFI_FILE_PROTOCOL_REVISION2) {
mWriter.WriteString(L"HCoreLdr: Fetch-Protocol: Invalid-Revision: ")
.WriteString(mPath)
@@ -108,12 +112,13 @@ Void BFileReader::Fetch(EfiHandlePtr ImageHandle) {
/// File FAT info.
UInt32 szInfo = sizeof(EfiFileInfo);
- EfiFileInfo info{0};
+ EfiFileInfo* info = nullptr;
+
+ BS->AllocatePool(EfiLoaderData, szInfo, (void**)&info);
guidEfp = EfiGUID(EFI_FILE_INFO_GUID);
- if (kernelFile->GetInfo(kernelFile, &guidEfp, &szInfo, (void*)&info) !=
- kEfiOk) {
+ if (kernelFile->GetInfo(kernelFile, &guidEfp, &szInfo, info) != kEfiOk) {
mWriter.WriteString(L"HCoreLdr: Fetch-Protocol: No-Such-Path: ")
.WriteString(mPath)
.WriteString(L"\r\n");
@@ -126,23 +131,26 @@ Void BFileReader::Fetch(EfiHandlePtr ImageHandle) {
VoidPtr blob = (VoidPtr)kHandoverStartKernel;
- mWriter.WriteString(L"HCoreLdr: Fetch-Info: OK...").WriteString(L"\r\n");
+ if (BS->AllocatePages(AllocateAnyPages, EfiLoaderData, 1,
+ (EfiPhysicalAddress*)&blob) != kEfiOk) {
+ EFI::RaiseHardError(L"HCoreLdr_PageError", L"Allocation error.");
+ }
+
+ UInt32* sz = nullptr;
+
+ BS->AllocatePool(EfiLoaderData, sizeof(UInt32), (VoidPtr*)&sz);
- UInt32 sz = info.FileSize;
+ *sz = info->FileSize;
- BSetMem((CharacterType*)blob, 0, sz);
+ mWriter.WriteString(L"HCoreLdr: Fetch-Info: Read...").WriteString(L"\r\n");
- auto resultEfiRead = kernelFile->Read(kernelFile, &sz, blob);
- kernelFile->Close(kernelFile);
+ kernelFile->Read(kernelFile, sz, blob);
- if (resultEfiRead != kEfiOk) return;
+ mWriter.WriteString(L"HCoreLdr: Fetch-Info: Success...").WriteString(L"\r\n");
mCached = true;
mErrorCode = kOperationOkay;
-
mBlob = blob;
// We are done!
-
- mWriter.WriteString(L"HCoreLdr: Fetch: OK.").WriteString(L"\r\n");
}
diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile
index cf6bb579..2c08426e 100644
--- a/Private/NewBoot/Source/makefile
+++ b/Private/NewBoot/Source/makefile
@@ -8,7 +8,7 @@ LD_GNU=x86_64-w64-mingw32-ld
ASM=nasm
FLAG_ASM=-f win64
-FLAG_GNU=-fshort-wchar -fPIC -D__DEBUG__ -DEFI_FUNCTION_WRAPPER -I../ -I../../ -I../../efiSDK/inc -I./ -c -ffreestanding -fno-rtti -fno-exceptions -std=c++20 -D__HAVE_HCORE_APIS__ -D__HCORE__ -I./ -I$(HOME)/
+FLAG_GNU=-fshort-wchar -D__DEBUG__ -fPIC -DEFI_FUNCTION_WRAPPER -I../ -I../../ -I./ -c -ffreestanding -fno-rtti -fno-exceptions -std=c++20 -D__HAVE_HCORE_APIS__ -D__HCORE__ -I./ -I$(HOME)/
.PHONY: invalid-recipe
invalid-recipe:
@@ -18,9 +18,9 @@ invalid-recipe:
bootloader-amd64:
$(CC_GNU) $(FLAG_GNU) HEL/AMD64/*.cxx *.cxx
$(ASM) $(FLAG_ASM) HEl/AMD64/AMD64-VirtualMemory.asm
- $(LD_GNU) *.o HEL/AMD64/*.obj -e efi_main -filealign:16 -shared --subsystem=10 -ffreestanding -o HCoreLdr.exe
+ $(LD_GNU) *.o HEL/AMD64/*.obj -e efi_main -shared --subsystem=10 -ffreestanding -o HCoreLdr.exe
cp HCoreLdr.exe CDROM/EFI/BOOT/BOOTX64.EFI
- cp ../../HCoreKrnl.exe CDROM/EFI/BOOT/HCOREKRNL.EXE
+ cp ../../HCoreKrnl.exe CDROM/HCOREKRNL.EXE
.PHONY: make-disk
make-disk:
@@ -29,7 +29,7 @@ make-disk:
.PHONY: run-efi-debug
run-efi-debug:
wget https://retrage.github.io/edk2-nightly/bin/DEBUGX64_OVMF.fd -O OVMF.fd
- qemu-system-x86_64 -m 8G -M q35 -bios OVMF.fd -drive file=os.epm,index=0,if=ide,format=qcow2 -drive file=fat:rw:CDROM,index=1,format=raw -serial stdio
+ qemu-system-x86_64 -smp 8,maxcpus=16 -m 8G -M q35 -bios OVMF.fd -drive file=os.epm,index=0,if=ide,format=qcow2 -drive file=fat:rw:CDROM,index=1,format=raw -serial stdio
.PHONY: clean
clean:
diff --git a/Private/NewKit/Defines.hpp b/Private/NewKit/Defines.hpp
index cc8c141d..f46dd5bd 100644
--- a/Private/NewKit/Defines.hpp
+++ b/Private/NewKit/Defines.hpp
@@ -37,10 +37,10 @@ using Short = short;
using Int16 = short;
using UInt = unsigned int;
using UInt32 = unsigned int;
-using Long = long int;
-using Int64 = long int;
-using ULong = unsigned long int;
-using UInt64 = unsigned long int;
+using Long = __INT64_TYPE__;
+using Int64 = __INT64_TYPE__;
+using ULong = __UINT64_TYPE__;
+using UInt64 = __UINT64_TYPE__;
using Boolean = bool;
using Bool = bool;
using Char = char;
diff --git a/Private/makefile b/Private/makefile
index 1f1d7b27..39e23636 100644
--- a/Private/makefile
+++ b/Private/makefile
@@ -8,7 +8,7 @@ LD = x86_64-w64-mingw32-ld
CCFLAGS = -c -ffreestanding -fno-rtti -fno-exceptions -std=c++20 -D__USE_NEWFS__ -D__HAVE_HCORE_APIS__ -D__HCORE__ -I../ -I./ -I$(HOME)/
ASM = nasm
ASMFLAGS = -f win64
-LDFLAGS = -e Main -filealign:16 -shared --subsystem=10
+LDFLAGS = -e Main -shared --subsystem=10
LDOBJ = Obj/*.obj
# This file is the kernel, responsible of task management, memory, drivers and more.