summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-05 19:19:12 +0100
committerAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-05 19:19:12 +0100
commitf3e49a9d6b865e7a3f6361ed88863cd12a5f90f1 (patch)
treebb1ba85c3bc627be09f397f44eb216459f34d902
parent6191833a26e887c2b91ba4ad655297bfe70c97d5 (diff)
HCR-13 : Optimize filesystem operations on UEFI.
- Stream concept, on demand. Signed-off-by: Amlal El Mahrouss <amlalelmahrouss@icloud.com>
-rw-r--r--Private/EFIKit/EFI.hxx6
-rw-r--r--Private/HALKit/AMD64/HalSMPCore.cxx (renamed from Private/HALKit/AMD64/HalProcessPrimitives.cxx)9
-rw-r--r--Private/KernelKit/FileManager.hpp2
-rw-r--r--Private/KernelKit/MSDOS.hpp44
-rw-r--r--Private/KernelKit/PE.hpp2
-rw-r--r--Private/KernelKit/ProcessManager.hpp4
-rw-r--r--Private/KernelKit/SMPManager.hpp16
-rw-r--r--Private/NewBoot/BootKit/BootKit.hxx22
-rw-r--r--Private/NewBoot/Source/FileReader.cxx9
-rw-r--r--Private/NewBoot/Source/RuntimeMain.cxx (renamed from Private/NewBoot/Source/Entrypoint.cxx)35
-rw-r--r--Private/NewBoot/Source/TextWriter.cxx5
-rw-r--r--Private/NewBoot/Source/makefile2
-rw-r--r--Private/Source/ProcessManager.cxx8
-rw-r--r--Private/Source/RuntimeMain.cxx6
-rw-r--r--Private/Source/SMPManager.cxx10
-rw-r--r--ReadMe.md8
16 files changed, 125 insertions, 63 deletions
diff --git a/Private/EFIKit/EFI.hxx b/Private/EFIKit/EFI.hxx
index 0e7e22eb..8e1b46c7 100644
--- a/Private/EFIKit/EFI.hxx
+++ b/Private/EFIKit/EFI.hxx
@@ -650,10 +650,10 @@ typedef struct EfiFileProtocol {
EfiStatusType(EFI_API *Delete)(struct EfiFileProtocol *This);
- EfiStatusType(EFI_API *Read)(struct EfiFileProtocol *This, UInt32 *BufSize,
+ EfiStatusType(EFI_API *Read)(struct EfiFileProtocol *This, UInt64 *BufSize,
VoidPtr BufOut);
- EfiStatusType(EFI_API *Write)(struct EfiFileProtocol *This, UInt32 *BufSize,
+ EfiStatusType(EFI_API *Write)(struct EfiFileProtocol *This, UInt64 *BufSize,
VoidPtr BufOut);
EfiStatusType(EFI_API *GetPosition)(EfiFileProtocol *This, UInt64 *Position);
@@ -681,6 +681,8 @@ typedef struct EfiFileProtocol {
struct EfiIOToken *Token);
} EfiFileProtocol;
+typedef UInt64 EfiCursorType;
+
typedef struct EfiTime {
UInt16 Year;
UInt8 Month;
diff --git a/Private/HALKit/AMD64/HalProcessPrimitives.cxx b/Private/HALKit/AMD64/HalSMPCore.cxx
index 36cd26db..bff14236 100644
--- a/Private/HALKit/AMD64/HalProcessPrimitives.cxx
+++ b/Private/HALKit/AMD64/HalSMPCore.cxx
@@ -17,3 +17,12 @@ Void Process::AssignStart(UIntPtr &imageStart) noexcept {
this->StackFrame->Rbp = imageStart;
this->StackFrame->Rsp = this->StackFrame->Rbp;
}
+
+namespace HCore {
+bool rt_check_stack(HAL::StackFramePtr stackPtr) {
+ if (!stackPtr) return false;
+ if (stackPtr->Rbp == 0 || stackPtr->Rsp == 0) return false;
+
+ return true;
+}
+} // namespace HCore
diff --git a/Private/KernelKit/FileManager.hpp b/Private/KernelKit/FileManager.hpp
index d31cdf68..fea63a0a 100644
--- a/Private/KernelKit/FileManager.hpp
+++ b/Private/KernelKit/FileManager.hpp
@@ -232,6 +232,8 @@ class FileStream final {
using FileStreamUTF8 = FileStream<char>;
using FileStreamUTF16 = FileStream<wchar_t>;
+typedef UInt64 CursorType;
+
template <typename Encoding, typename Class>
FileStream<Encoding, Class>::FileStream(const Encoding *path,
const Encoding *restrict_type)
diff --git a/Private/KernelKit/MSDOS.hpp b/Private/KernelKit/MSDOS.hpp
new file mode 100644
index 00000000..021d62aa
--- /dev/null
+++ b/Private/KernelKit/MSDOS.hpp
@@ -0,0 +1,44 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+ File: MSDOS.hpp
+ Purpose: MS-DOS header for HCore.
+
+ Revision History:
+
+ 30/01/24: Added file (amlel)
+
+------------------------------------------- */
+
+#ifndef __MSDOS_EXEC__
+#define __MSDOS_EXEC__
+
+#include <NewKit/Defines.hpp>
+
+typedef HCore::UInt32 DosWord;
+typedef HCore::Long DosLong;
+
+typedef struct _DosHeader {
+ DosWord eMagic;
+ DosWord eMagLen;
+ DosWord ePagesCount;
+ DosWord eCrlc;
+ DosWord eCParHdr;
+ DosWord eMinAlloc;
+ DosWord eMaxAlloc;
+ DosWord eStackSeg;
+ DosWord eStackPtr;
+ DosWord eChksum;
+ DosWord eIp;
+ DosWord eCs;
+ DosWord eLfarlc;
+ DosWord eOvno;
+ DosWord eRes[4];
+ DosWord eOemid;
+ DosWord eOeminfo;
+ DosWord eRes2[10];
+ DosLong eLfanew;
+} DosHeader, *DosHeaderPtr;
+
+#endif /* ifndef __MSDOS_EXEC__ */
diff --git a/Private/KernelKit/PE.hpp b/Private/KernelKit/PE.hpp
index 88ee319a..6cc0ff60 100644
--- a/Private/KernelKit/PE.hpp
+++ b/Private/KernelKit/PE.hpp
@@ -27,7 +27,7 @@ typedef char CHAR;
#define kPeMagic 0x00004550
typedef struct ExecHeader final {
- U32 mMagic; // PE\0\0 or 0x00004550
+ U8 mMagic[4]; // PE\0\0 or 0x00004550
U16 mMachine;
U16 mNumberOfSections;
U32 mTimeDateStamp;
diff --git a/Private/KernelKit/ProcessManager.hpp b/Private/KernelKit/ProcessManager.hpp
index 52c3e7b3..ddde3d3c 100644
--- a/Private/KernelKit/ProcessManager.hpp
+++ b/Private/KernelKit/ProcessManager.hpp
@@ -17,7 +17,7 @@
#include <NewKit/MutableArray.hpp>
#include <NewKit/UserHeap.hpp>
-#define kMinMicroTime AffinityKind::kStandard
+#define kMinMicroTime AffinityKind::kHartStandard
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -48,7 +48,7 @@ enum class AffinityKind : Int32 {
kInvalid = 300,
kVeryHigh = 250,
kHigh = 200,
- kStandard = 150,
+ kHartStandard = 150,
kLowUsage = 100,
kVeryLowUsage = 50,
};
diff --git a/Private/KernelKit/SMPManager.hpp b/Private/KernelKit/SMPManager.hpp
index 8cbe3259..dc3518a7 100644
--- a/Private/KernelKit/SMPManager.hpp
+++ b/Private/KernelKit/SMPManager.hpp
@@ -22,13 +22,13 @@ namespace HCore {
using ThreadID = UInt32;
enum ThreadKind {
- kSystemReserved, // System reserved thread, well user can't use it
- kStandard, // user thread, cannot be used by kernel
- kFallback, // fallback thread, cannot be used by user if not clear or used by
- // kernel.
- kBoot, // The core we booted from, the mama.
- kInvalidThread,
- kThreadCount,
+ kHartSystemReserved, // System reserved thread, well user can't use it
+ kHartStandard, // user thread, cannot be used by kernel
+ kHartFallback, // fallback thread, cannot be used by user if not clear or
+ // used by kernel.
+ kHartBoot, // The core we booted from, the mama.
+ kInvalidHart,
+ kHartCount,
};
///
@@ -105,8 +105,6 @@ class SMPManager final {
private:
Array<HardwareThread, kMaxHarts> m_ThreadList;
ThreadID m_CurrentThread{0};
- SizeT m_UsedThreads{0};
- SizeT m_MaxThreads{0};
};
// @brief wakes up thread.
diff --git a/Private/NewBoot/BootKit/BootKit.hxx b/Private/NewBoot/BootKit/BootKit.hxx
index 7a45e7e2..68d91deb 100644
--- a/Private/NewBoot/BootKit/BootKit.hxx
+++ b/Private/NewBoot/BootKit/BootKit.hxx
@@ -78,7 +78,7 @@ class BFileReader final {
Int32 &Error() { return mErrorCode; }
VoidPtr Blob() { return mBlob; }
EfiFileProtocol *File() { return mFile; }
- UInt32 &Size() { return mSizeFile; }
+ UInt64 &Size() { return mSizeFile; }
public:
BFileReader &operator=(const BFileReader &) = default;
@@ -90,7 +90,7 @@ class BFileReader final {
CharacterType mPath[kPathLen];
BTextWriter mWriter;
EfiFileProtocol *mFile{nullptr};
- UInt32 mSizeFile{0};
+ UInt64 mSizeFile{0};
};
#define kMaxReadSize (320)
@@ -157,27 +157,21 @@ const UInt32 kRgbBlue = 0x00FF0000;
const UInt32 kRgbBlack = 0x00000000;
const UInt32 kRgbWhite = 0x00FFFFFF;
-/** QT GOP. */
+/** QT GOP and related. */
inline EfiGraphicsOutputProtocol *kGop;
+inline UInt16 kStride;
+inline EfiGUID kGopGuid;
/**
@brief Init the QuickTemplate GUI framework.
*/
inline Void InitQT() noexcept {
- EfiGUID gopGuid = EfiGUID(EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID);
+ kGopGuid = EfiGUID(EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID);
kGop = nullptr;
extern EfiBootServices *BS;
- BS->LocateProtocol(&gopGuid, nullptr, (VoidPtr *)&kGop);
+ BS->LocateProtocol(&kGopGuid, nullptr, (VoidPtr *)&kGop);
- 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 * x + kStride * y)) =
- RGB(19, 19, 19);
- }
- }
+ kStride = 4;
}
diff --git a/Private/NewBoot/Source/FileReader.cxx b/Private/NewBoot/Source/FileReader.cxx
index 54e59dde..efd53020 100644
--- a/Private/NewBoot/Source/FileReader.cxx
+++ b/Private/NewBoot/Source/FileReader.cxx
@@ -113,10 +113,6 @@ Void BFileReader::ReadAll() {
.WriteString(mPath)
.WriteString(L"\r\n");
- mWriter.WriteString(L"HCoreLdr: ReadAll: FETCH: ")
- .WriteString(mPath)
- .WriteString(L"\r\n");
-
/// Allocate Handover page.
UInt8* blob = (UInt8*)kHandoverStartKernel;
@@ -131,10 +127,5 @@ Void BFileReader::ReadAll() {
if (mFile->Read(mFile, &mSizeFile, mBlob) != kEfiOk) return;
- mSizeFile = KIB(kMaxReadSize);
mErrorCode = kOperationOkay;
-
- mWriter.WriteString(L"HCoreLdr: ReadAll: OK: ")
- .WriteString(mPath)
- .WriteString(L"\r\n");
}
diff --git a/Private/NewBoot/Source/Entrypoint.cxx b/Private/NewBoot/Source/RuntimeMain.cxx
index b63fb0a1..6feefea5 100644
--- a/Private/NewBoot/Source/Entrypoint.cxx
+++ b/Private/NewBoot/Source/RuntimeMain.cxx
@@ -11,6 +11,7 @@
#include <BootKit/BootKit.hxx>
#include <EFIKit/Api.hxx>
+#include <KernelKit/MSDOS.hpp>
#include <KernelKit/PE.hpp>
#include <NewKit/Ref.hpp>
@@ -21,28 +22,40 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
BTextWriter writer;
+#ifndef __DEBUG__
+
+ writer.WriteString(
+ L"MahroussLogic (R) HCore Version 1.0.0 (Release Channel)\r\n");
+
+#else
+
+ writer.WriteString(
+ L"MahroussLogic (R) HCore Version 1.0.0 (Insiders Channel)\r\n");
+
+#endif
+
writer.WriteString(L"HCoreLdr: Firmware Vendor: ")
.WriteString(SystemTable->FirmwareVendor)
.WriteString(L"\r\n");
BFileReader img(L"HCOREKRNL.EXE", ImageHandle);
+ img.ReadAll();
- UInt8 buf[1024] = {0};
- UInt32 bufSz = 1024;
+ if (img.Error() == BFileReader::kOperationOkay) {
+ VoidPtr blob = img.Blob();
- img.File()->Read(img.File(), &bufSz, buf);
+ UInt64 MapKey = 0;
- if (buf[0] != kMagMz0 || buf[1] != kMagMz1) {
- EFI::RaiseHardError(L"HCoreLdr_NoBlob", L"No Such blob.");
- return kEfiFail;
- }
+ EFI::ExitBootServices(MapKey, ImageHandle);
+ EFI::Stop();
- writer.WriteString(L"HCoreLdr: Loading HCOREKRNL.EXE...\r\n");
+ return kEfiOk;
+ }
- UInt64 MapKey = 0;
+ writer.WriteString(
+ L"HCoreLdr: Missing HCOREKRNL.EXE! Your system is damaged.\r\n");
- EFI::ExitBootServices(MapKey, ImageHandle);
EFI::Stop();
- return kEfiOk;
+ return kEfiFail;
}
diff --git a/Private/NewBoot/Source/TextWriter.cxx b/Private/NewBoot/Source/TextWriter.cxx
index b6a8e3b8..c885f317 100644
--- a/Private/NewBoot/Source/TextWriter.cxx
+++ b/Private/NewBoot/Source/TextWriter.cxx
@@ -22,12 +22,9 @@
@brief puts wrapper over EFI ConOut.
*/
BTextWriter &BTextWriter::WriteString(const CharacterType *str) {
-#ifdef __DEBUG__
-
if (*str == 0 || !str) return *this;
ST->ConOut->OutputString(ST->ConOut, str);
-#endif
return *this;
}
@@ -36,12 +33,10 @@ BTextWriter &BTextWriter::WriteString(const CharacterType *str) {
@brief putc wrapper over EFI ConOut.
*/
BTextWriter &BTextWriter::WriteCharacter(CharacterType c) {
-#ifdef __DEBUG__
EfiCharType str[2];
str[0] = c;
str[1] = 0;
ST->ConOut->OutputString(ST->ConOut, str);
-#endif
return *this;
}
diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile
index 02990084..cc550bdd 100644
--- a/Private/NewBoot/Source/makefile
+++ b/Private/NewBoot/Source/makefile
@@ -31,7 +31,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 -smp 2 -m 4G -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 -net none -smp 2 -m 4G -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/Source/ProcessManager.cxx b/Private/Source/ProcessManager.cxx
index af3fa351..71f38e2f 100644
--- a/Private/Source/ProcessManager.cxx
+++ b/Private/Source/ProcessManager.cxx
@@ -233,7 +233,7 @@ bool ProcessHelper::CanBeScheduled(Ref<Process> &process) {
if (process.Leak().GetStatus() == ProcessStatus::kStarting) {
if (process.Leak().PTime < static_cast<Int>(kMinMicroTime)) {
process.Leak().Status = ProcessStatus::kRunning;
- process.Leak().Affinity = AffinityKind::kStandard;
+ process.Leak().Affinity = AffinityKind::kHartStandard;
return true;
}
@@ -271,7 +271,7 @@ bool ProcessHelper::Switch(HAL::StackFrame *the_stack, const PID &new_pid) {
if (!the_stack || new_pid < 0) return false;
for (SizeT index = 0UL; index < kMaxHarts; ++index) {
- if (SMPManager::Shared().Leak()[index].Leak().Kind() == kInvalidThread)
+ if (SMPManager::Shared().Leak()[index].Leak().Kind() == kInvalidHart)
continue;
if (SMPManager::Shared().Leak()[index].Leak().StackFrame() == the_stack) {
@@ -281,9 +281,9 @@ bool ProcessHelper::Switch(HAL::StackFrame *the_stack, const PID &new_pid) {
if (SMPManager::Shared().Leak()[index].Leak().IsBusy()) continue;
- if (SMPManager::Shared().Leak()[index].Leak().Kind() != ThreadKind::kBoot ||
+ if (SMPManager::Shared().Leak()[index].Leak().Kind() != ThreadKind::kHartBoot ||
SMPManager::Shared().Leak()[index].Leak().Kind() !=
- ThreadKind::kSystemReserved) {
+ ThreadKind::kHartSystemReserved) {
SMPManager::Shared().Leak()[index].Leak().Busy(true);
ProcessHelper::GetCurrentPID() = new_pid;
diff --git a/Private/Source/RuntimeMain.cxx b/Private/Source/RuntimeMain.cxx
index e26ce13a..abbfb749 100644
--- a/Private/Source/RuntimeMain.cxx
+++ b/Private/Source/RuntimeMain.cxx
@@ -17,22 +17,28 @@
extern "C" void RuntimeMain(
HCore::HEL::HandoverInformationHeader* HandoverHeader) {
+ /// Setup kernel globals.
kKernelVirtualSize = HandoverHeader->f_VirtualSize;
kKernelVirtualStart = HandoverHeader->f_VirtualStart;
kKernelPhysicalSize = HandoverHeader->f_VirtualSize;
kKernelPhysicalStart = HandoverHeader->f_VirtualStart;
+ /// Setup base page.
HCore::HAL::hal_page_base((HCore::UIntPtr)kKernelVirtualStart);
+ /// Init memory managers.
HCore::ke_init_ke_heap();
HCore::ke_init_heap();
+ /// Init the HAL.
MUST_PASS(HCore::ke_init_hal());
+ /// Mount a New partition.
HCore::IFilesystemManager::Mount(new HCore::NewFilesystemManager());
HCore::PEFLoader img("/System/HCoreShell.exe");
+ /// Run the shell.
if (!HCore::Utils::execute_from_image(img)) {
HCore::ke_stop(RUNTIME_CHECK_BOOTSTRAP);
}
diff --git a/Private/Source/SMPManager.cxx b/Private/Source/SMPManager.cxx
index d3c7a4c8..9b976412 100644
--- a/Private/Source/SMPManager.cxx
+++ b/Private/Source/SMPManager.cxx
@@ -60,8 +60,10 @@ void HardwareThread::Wake(const bool wakeup) noexcept {
rt_wakeup_thread(m_Stack);
}
+extern bool rt_check_stack(HAL::StackFramePtr stackPtr);
+
bool HardwareThread::Switch(HAL::StackFrame* stack) {
- if (stack == nullptr) return false;
+ if (!rt_check_stack(stack)) return false;
m_Stack = stack;
@@ -129,12 +131,12 @@ bool SMPManager::Switch(HAL::StackFrame* stack) {
*/
Ref<HardwareThread> SMPManager::operator[](const SizeT& idx) {
if (idx == 0) {
- if (m_ThreadList[idx].Leak().Leak().Kind() != kSystemReserved) {
- m_ThreadList[idx].Leak().Leak().m_Kind = kBoot;
+ if (m_ThreadList[idx].Leak().Leak().Kind() != kHartSystemReserved) {
+ m_ThreadList[idx].Leak().Leak().m_Kind = kHartBoot;
}
} else if (idx >= kMaxHarts) {
HardwareThread fakeThread;
- fakeThread.m_Kind = kInvalidThread;
+ fakeThread.m_Kind = kInvalidHart;
return {fakeThread};
}
diff --git a/ReadMe.md b/ReadMe.md
index d01c3c92..2115dd94 100644
--- a/ReadMe.md
+++ b/ReadMe.md
@@ -1,6 +1,12 @@
# h-core (codename: SuperTrouper)
-## Microkernel and it's components source code.
+## uKernel and components source code.
+
+You need:
+
+- The GCC toolchain (MinGW) for the kernel and bootloader.
+- HintKit for Compilation check.
+- Netwide Assembler to output COFF object code.
Start by cloning the repo: