summaryrefslogtreecommitdiffhomepage
path: root/Private
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@el-mahrouss-logic.com>2024-03-27 17:38:23 +0100
committerAmlal El Mahrouss <amlal@el-mahrouss-logic.com>2024-03-27 17:38:23 +0100
commit1ce16b83dba0326b13dfa3399c1497ac6b1af14d (patch)
tree8a5e4063b5d4cf6ce4f42dd500073994e9ef8954 /Private
parent6a18e607ffc4e83f2bd953c9de5c14f18e077df8 (diff)
Kernel && Developer:
Developer: - Rework System API to use C instead of C++ - Add new calls in Thread.h - Documented code. Kernel: - Rework handover stage, separated the Processor specific code from the cross platform code. Signed-off-by: Amlal El Mahrouss <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'Private')
-rw-r--r--Private/Builtins/Toolbox/Toolbox.hxx2
-rw-r--r--Private/Builtins/Toolbox/Utils.hxx (renamed from Private/Builtins/Toolbox/Util.hxx)5
-rw-r--r--Private/FSKit/NewFS.hxx6
-rw-r--r--Private/FirmwareKit/EPM.hxx6
-rw-r--r--Private/HALKit/AMD64/HalKernelMain.cxx12
-rw-r--r--Private/HALKit/AMD64/HalNewBoot.asm7
-rw-r--r--Private/HALKit/AMD64/HalSMPCore.cxx2
-rw-r--r--Private/HALKit/AMD64/HalSMPCoreManager.asm7
-rw-r--r--Private/KernelKit/DriveManager.hxx7
-rw-r--r--Private/KernelKit/FileManager.hpp7
-rw-r--r--Private/KernelKit/ProcessScheduler.hpp23
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx4
-rw-r--r--Private/NewBoot/Source/download-edk.ps12
-rw-r--r--Private/NewBoot/Source/run-qemu.ps11
-rw-r--r--Private/NewKit/Function.hpp79
-rw-r--r--Private/NewKit/Json.hpp6
-rw-r--r--Private/Source/PEFSharedObjectRT.cxx14
-rw-r--r--Private/Source/ProcessScheduler.cxx6
-rw-r--r--Private/Source/RuntimeMain.cxx30
19 files changed, 135 insertions, 91 deletions
diff --git a/Private/Builtins/Toolbox/Toolbox.hxx b/Private/Builtins/Toolbox/Toolbox.hxx
index 82d0f953..ebd8fc1e 100644
--- a/Private/Builtins/Toolbox/Toolbox.hxx
+++ b/Private/Builtins/Toolbox/Toolbox.hxx
@@ -15,4 +15,4 @@ EXTERN_C HCore::Boolean _hal_left_button_pressed();
EXTERN_C HCore::Boolean _hal_middle_button_pressed();
EXTERN_C HCore::Boolean _hal_right_button_pressed();
-#include <Builtins/Toolbox/Util.hxx>
+#include <Builtins/Toolbox/Utils.hxx>
diff --git a/Private/Builtins/Toolbox/Util.hxx b/Private/Builtins/Toolbox/Utils.hxx
index 2be185e1..7dec8608 100644
--- a/Private/Builtins/Toolbox/Util.hxx
+++ b/Private/Builtins/Toolbox/Utils.hxx
@@ -10,7 +10,7 @@
#define ToolboxClearRsrc() uA = 0
-/// @brief draws a resource.
+/// @brief Draws a resource.
#define ToolboxDrawRsrc(ImgPtr, _Height, _Width, BaseX, BaseY) \
uA = 0; \
\
@@ -37,7 +37,7 @@
}
-/// @brief cleans a resource.
+/// @brief Cleans a resource.
#define ToolboxClearZone(_Height, _Width, BaseX, BaseY) \
\
for (HCore::SizeT i = BaseX; i < _Height + BaseX; ++i) { \
@@ -52,6 +52,7 @@
}
+/// @brief Draws inside a zone.
#define ToolboxDrawZone(_Clr, _Height, _Width, BaseX, BaseY) \
\
for (HCore::SizeT i = BaseX; i < _Width + BaseX; ++i) { \
diff --git a/Private/FSKit/NewFS.hxx b/Private/FSKit/NewFS.hxx
index ffd198d2..70ea0881 100644
--- a/Private/FSKit/NewFS.hxx
+++ b/Private/FSKit/NewFS.hxx
@@ -35,12 +35,16 @@
#define kNewFSIdent " NewFS"
#define kNewFSPadLen 16
-//! On EPM and GPT disks.
+/// @brief Partition GUID on EPM and GPT disks.
#define kNewFSUUID "@{DD997393-9CCE-4288-A8D5-C0FDE3908DBE}"
#define kNewFSVersionInteger 0x121
#define kNewFSVerionString "1.2.1"
+/// @brief Standard fork types.
+#define kNewFSDataFork "data"
+#define kNewFSResourceFork "rsrc"
+
#define kNewFSCatalogKindFile 1
#define kNewFSCatalogKindDir 2
#define kNewFSCatalogKindAlias 3
diff --git a/Private/FirmwareKit/EPM.hxx b/Private/FirmwareKit/EPM.hxx
index 2c68b40a..4c8d48f2 100644
--- a/Private/FirmwareKit/EPM.hxx
+++ b/Private/FirmwareKit/EPM.hxx
@@ -77,10 +77,10 @@ struct PACKED PartitionBlock {
#define kEPMMaxBlks 128
-//! version types.
-//! use in boot block version field.
+///! @brief Version kind enum.
+///! @brief Use in boot block version field.
-enum {
+enum kEPMKind {
kEPMMpUx = 0xcf,
kEPMLinux = 0x8f,
kEPMBSD = 0x9f,
diff --git a/Private/HALKit/AMD64/HalKernelMain.cxx b/Private/HALKit/AMD64/HalKernelMain.cxx
index 266ef18a..29cbdff2 100644
--- a/Private/HALKit/AMD64/HalKernelMain.cxx
+++ b/Private/HALKit/AMD64/HalKernelMain.cxx
@@ -17,8 +17,9 @@
#include <NewKit/Json.hpp>
EXTERN_C HCore::VoidPtr kInterruptVectorTable[];
+EXTERN_C void RuntimeMain();
-EXTERN_C void RuntimeMain(
+EXTERN_C void hal_init_platform(
HCore::HEL::HandoverInformationHeader* HandoverHeader) {
kHandoverHeader = HandoverHeader;
@@ -65,12 +66,6 @@ EXTERN_C void RuntimeMain(
/// END POST
- /// Mounts a NewFS block.
- HCore::NewFilesystemManager* newFS = new HCore::NewFilesystemManager();
- HCore::ke_protect_ke_heap(newFS);
-
- HCore::FilesystemManagerInterface::Mount(newFS);
-
ToolboxInitRsrc();
ToolboxDrawRsrc(
@@ -80,6 +75,7 @@ EXTERN_C void RuntimeMain(
ToolboxClearRsrc();
- HCore::ke_delete_ke_heap(newFS);
+ RuntimeMain();
+
HCore::ke_stop(RUNTIME_CHECK_BOOTSTRAP);
}
diff --git a/Private/HALKit/AMD64/HalNewBoot.asm b/Private/HALKit/AMD64/HalNewBoot.asm
index 3a16cd24..54d05f2f 100644
--- a/Private/HALKit/AMD64/HalNewBoot.asm
+++ b/Private/HALKit/AMD64/HalNewBoot.asm
@@ -15,10 +15,11 @@
%define kTypeKernel 100
%define kArchAmd64 122
+%define kHandoverMagic 0xBADCC
section .NewBoot
-HandoverMagic: dq 0xBAD55
+HandoverMagic: dq kHandoverMagic
HandoverType: dw kTypeKernel
HandoverArch: dw kArchAmd64
;; This NewBootStart points to Main.
@@ -27,13 +28,13 @@ HandoverStart: dq Main
section .text
global Main
-extern RuntimeMain
+extern hal_init_platform
;; Just a simple setup, we'd also need to tell some before
Main:
push rax
push rcx
- call RuntimeMain
+ call hal_init_platform
pop rcx
pop rax
;; Go to sleep.
diff --git a/Private/HALKit/AMD64/HalSMPCore.cxx b/Private/HALKit/AMD64/HalSMPCore.cxx
index d213b2fc..3be9c0c7 100644
--- a/Private/HALKit/AMD64/HalSMPCore.cxx
+++ b/Private/HALKit/AMD64/HalSMPCore.cxx
@@ -7,7 +7,7 @@
#include <KernelKit/ProcessScheduler.hpp>
using namespace HCore;
-Void ProcessHeader::SetStart(UIntPtr &imageStart) noexcept {
+Void ProcessHeader::SetEntrypoint(UIntPtr &imageStart) noexcept {
if (imageStart == 0) this->Crash();
this->StackFrame->Rbp = imageStart;
diff --git a/Private/HALKit/AMD64/HalSMPCoreManager.asm b/Private/HALKit/AMD64/HalSMPCoreManager.asm
index 66cfec3a..d896a66c 100644
--- a/Private/HALKit/AMD64/HalSMPCoreManager.asm
+++ b/Private/HALKit/AMD64/HalSMPCoreManager.asm
@@ -14,8 +14,13 @@
section .text
+;; writes to rdx the stackframe inside rcx.
+;; rcx: Stack Pointer
+;; rdx: SMP core address.
rt_do_context_switch:
- retfq
+
+ retfq
+;; gets the current stack frame.
rt_get_current_context:
retfq
diff --git a/Private/KernelKit/DriveManager.hxx b/Private/KernelKit/DriveManager.hxx
index bec490d9..8d0289aa 100644
--- a/Private/KernelKit/DriveManager.hxx
+++ b/Private/KernelKit/DriveManager.hxx
@@ -24,6 +24,7 @@ enum {
kMassStorage = 0xDA,
kFloppyDisc = 0xCD,
kOpticalDisc = 0xDC, // CD-ROM/DVD-ROM/Blu-Ray
+ /// combine with below.
kReadOnly = 0x10, // Read only drive
kEPMDrive = 0x11, // Explicit Partition Map.
kEPTDrive = 0x12, // ESP w/ EPM partition.
@@ -42,10 +43,10 @@ struct DriveTrait final {
/// @brief Packet drive (StorageKit compilant.)
struct DrivePacket final {
- VoidPtr fPacketContent; // packet body.
+ VoidPtr fPacketContent; //! packet body.
Char fPacketMime[kDriveNameLen]; //! identify what we're sending.
- SizeT fPacketSize; // packet size
- UInt32 fPacketCRC32; // sanity crc, in case if good is set to false
+ SizeT fPacketSize; //! packet size
+ UInt32 fPacketCRC32; //! sanity crc, in case if good is set to false
Boolean fPacketGood;
} fPacket;
diff --git a/Private/KernelKit/FileManager.hpp b/Private/KernelKit/FileManager.hpp
index d02c087c..87de3d9e 100644
--- a/Private/KernelKit/FileManager.hpp
+++ b/Private/KernelKit/FileManager.hpp
@@ -18,13 +18,18 @@
#include <FSKit/NewFS.hxx>
#endif // __FSKIT_NEWFS__
+#ifdef __FSKIT_HCFS__
+#include <FSKit/HCFS.hxx>
+#endif // __FSKIT_HCFS__
+
#include <CompilerKit/CompilerKit.hxx>
#include <HintKit/CompilerHint.hxx>
#include <NewKit/ErrorID.hpp>
#include <NewKit/Ref.hpp>
#include <NewKit/Stream.hpp>
-/// Main filesystem abstraction manager.
+/// @brief Filesystem abstraction manager.
+/// Works like the VFS or IFS.
#define kBootFolder "/Boot"
#define kBinFolder "/Applications"
diff --git a/Private/KernelKit/ProcessScheduler.hpp b/Private/KernelKit/ProcessScheduler.hpp
index 4f499033..1b55be4a 100644
--- a/Private/KernelKit/ProcessScheduler.hpp
+++ b/Private/KernelKit/ProcessScheduler.hpp
@@ -121,7 +121,7 @@ class ProcessHeader final {
HCORE_COPY_DEFAULT(ProcessHeader)
public:
- void SetStart(UIntPtr &imageStart) noexcept;
+ void SetEntrypoint(UIntPtr &imageStart) noexcept;
public:
Char Name[kProcessLen] = {"HCore Process"};
@@ -141,22 +141,27 @@ class ProcessHeader final {
SizeT FreeMemory{0};
enum {
- ExecutableType,
- DLLType,
- DriverType,
- TypeCount,
+ kUserKind = 3,
+ kLibKind = 3,
+ kDriverKind = 0,
+ kKindCount,
+ };
+
+ enum {
+ kRingUserKind = 3,
+ kRingDriverKind = 0,
};
ProcessTime PTime;
- PID ProcessId{-1};
- Int32 Ring{3};
- Int32 Kind{0};
+ PID ProcessId{kPIDInvalid};
+ Int32 Ring{kRingDriverKind};
+ Int32 Kind{kUserKind};
public:
//! @brief boolean operator, check status.
operator bool() { return Status != ProcessStatus::kDead; }
- //! @brief Crash app, exits with code ~0.
+ //! @brief Crash the app, exits with code ~0.
void Crash();
//! @brief Exits app.
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx b/Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx
index bd650031..b8df12a0 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx
@@ -96,7 +96,7 @@ EXTERN_C Boolean boot_write_newfs_partition(const Char* namePart, SizeT namePart
swapBlock->SectorSz = kATASectorSize;
swapBlock->SectorStart = kEPMStartPartition;
swapBlock->Version = kNewFSVersionInteger;
- swapBlock->Kind = kNewFSPartitionTypeBoot;
+ swapBlock->Kind = kNewFSPartitionTypePage;
swapBlock->SectorEnd = MIB(4); /// 4 MIB swap partition.
ataInterface->Write(buf, 1);
@@ -105,6 +105,6 @@ EXTERN_C Boolean boot_write_newfs_partition(const Char* namePart, SizeT namePart
}
}
- writer.Write(L"NewBoot.exe: Partition found, everything is OK.\r\n");
+ writer.Write(L"NewBoot.exe: Partition found, everything's OK.\r\n");
return Yes;
} \ No newline at end of file
diff --git a/Private/NewBoot/Source/download-edk.ps1 b/Private/NewBoot/Source/download-edk.ps1
index 744d2c1d..5a2c5f0e 100644
--- a/Private/NewBoot/Source/download-edk.ps1
+++ b/Private/NewBoot/Source/download-edk.ps1
@@ -1,4 +1,4 @@
$client = new-object System.Net.WebClient
$output = "$PSScriptRoot\OVMF.fd"
-$client.DownloadFile("https://retrage.github.io/edk2-nightly/bin/DEBUGX64_OVMF.fd", $output) \ No newline at end of file
+$client.DownloadFile("https://retrage.github.io/edk2-nightly/bin/DEBUGX64_OVMF.fd", $output)
diff --git a/Private/NewBoot/Source/run-qemu.ps1 b/Private/NewBoot/Source/run-qemu.ps1
deleted file mode 100644
index d84c9327..00000000
--- a/Private/NewBoot/Source/run-qemu.ps1
+++ /dev/null
@@ -1 +0,0 @@
-qemu-system-x86_64w.exe -net none -smp 2 -m 4G -M q35 -bios OVMF.fd -drive file=fat:rw:CDROM,index=1,format=raw -d int \ No newline at end of file
diff --git a/Private/NewKit/Function.hpp b/Private/NewKit/Function.hpp
index 04a93bee..20d63f80 100644
--- a/Private/NewKit/Function.hpp
+++ b/Private/NewKit/Function.hpp
@@ -3,48 +3,37 @@
#include <NewKit/Defines.hpp>
-namespace HCore
-{
- template <typename T, typename... Args>
- class Function final
- {
- public:
- Function() = default;
-
- public:
- explicit Function(T (*Fn)(Args... args))
- : m_Fn(Fn)
- {}
-
- ~Function() = default;
-
- Function &operator=(const Function &) = default;
- Function(const Function &) = default;
-
- template <typename... XArgs> T operator()(Args... args)
- {
- return m_Fn(args...);
- }
-
- template <typename... XArgs> T Call(Args... args)
- {
- return m_Fn(args...);
- }
-
- operator bool()
- {
- return m_Fn;
- }
-
- bool operator!()
- {
- return !m_Fn;
- }
-
- private:
- T (*m_Fn)(Args... args);
-
- };
-} // namespace HCore
-
-#endif // !_INC_FUNCTION_HPP__
+namespace HCore {
+template <typename T, typename... Args>
+class Function final {
+ public:
+ Function() = default;
+
+ public:
+ explicit Function(T (*Fn)(Args... args)) : m_Fn(Fn) {}
+
+ ~Function() = default;
+
+ Function &operator=(const Function &) = default;
+ Function(const Function &) = default;
+
+ template <typename... XArgs>
+ T operator()(Args... args) {
+ return m_Fn(args...);
+ }
+
+ template <typename... XArgs>
+ T Call(Args... args) {
+ return m_Fn(args...);
+ }
+
+ operator bool() { return m_Fn; }
+
+ bool operator!() { return !m_Fn; }
+
+ private:
+ T (*m_Fn)(Args... args);
+};
+} // namespace HCore
+
+#endif // !_INC_FUNCTION_HPP__
diff --git a/Private/NewKit/Json.hpp b/Private/NewKit/Json.hpp
index 115e893f..373b0772 100644
--- a/Private/NewKit/Json.hpp
+++ b/Private/NewKit/Json.hpp
@@ -16,6 +16,7 @@
#include <NewKit/Utils.hpp>
namespace HCore {
+/// @brief Json value class
class JsonType final {
public:
explicit JsonType() : HCore::JsonType(1, 1) {}
@@ -32,13 +33,18 @@ class JsonType final {
StringView fValue;
public:
+ /// @brief returns the key of the json
+ /// @return
StringView &AsKey() { return fKey; }
+ /// @brief returns the value of the json.
+ /// @return
StringView &AsValue() { return fValue; }
static JsonType kUndefined;
};
+/// @brief Json stream helper class.
struct JsonStreamTrait final {
JsonType In(const char *full_array) {
SizeT len = rt_string_len(full_array);
diff --git a/Private/Source/PEFSharedObjectRT.cxx b/Private/Source/PEFSharedObjectRT.cxx
index dc75e8b6..871552d7 100644
--- a/Private/Source/PEFSharedObjectRT.cxx
+++ b/Private/Source/PEFSharedObjectRT.cxx
@@ -18,9 +18,9 @@
Revision History:
- 01/02/24: Rework shared library ABI, except a rt_library_init and rt_library_free
- (amlel)
- 15/02/24: Breaking changes, changed the name of the routines. (amlel)
+ 01/02/24: Rework shared library ABI, except a rt_library_init and
+ rt_library_free (amlel) 15/02/24: Breaking changes, changed the name of the
+ routines. (amlel)
------------------------------------------- */
@@ -76,7 +76,7 @@ EXTERN_C SharedObjectPtr rt_library_init(void) {
EXTERN_C Void rt_library_free(SharedObjectPtr lib, bool *successful) {
MUST_PASS(successful);
- // sanity check (will also trigger a bug check)
+ // sanity check (will also trigger a bug check if this fails)
if (lib == nullptr) {
*successful = false;
ProcessScheduler::Shared().Leak().GetCurrent().Leak().Crash();
@@ -92,7 +92,9 @@ EXTERN_C Void rt_library_free(SharedObjectPtr lib, bool *successful) {
/***********************************************************************************/
-extern "C" void __mh_purecall(void) {
- // virtual placeholder.
+/// @brief Unimplemented function (crashes by default)
+/// @param
+EXTERN_C void __mh_purecall(void) {
+ ProcessScheduler::Shared().Leak().GetCurrent().Leak().Crash();
return;
}
diff --git a/Private/Source/ProcessScheduler.cxx b/Private/Source/ProcessScheduler.cxx
index ebcf82c0..54a4afe8 100644
--- a/Private/Source/ProcessScheduler.cxx
+++ b/Private/Source/ProcessScheduler.cxx
@@ -162,15 +162,15 @@ SizeT ProcessScheduler::Add(Ref<ProcessHeader> &process) {
UIntPtr imageStart = reinterpret_cast<UIntPtr>(process.Leak().Image);
- process.Leak().SetStart(imageStart);
+ process.Leak().SetEntrypoint(imageStart);
mTeam.AsArray().Add(process);
- if (!imageStart && process.Leak().Kind == ProcessHeader::ExecutableType) {
+ if (!imageStart && process.Leak().Kind == ProcessHeader::kUserKind) {
process.Leak().Crash();
}
- if (!imageStart && process.Leak().Kind == ProcessHeader::DriverType) {
+ if (!imageStart && process.Leak().Kind == ProcessHeader::kDriverKind) {
if (process.Leak().Ring == 3)
process.Leak().Crash();
else
diff --git a/Private/Source/RuntimeMain.cxx b/Private/Source/RuntimeMain.cxx
new file mode 100644
index 00000000..ffecaa18
--- /dev/null
+++ b/Private/Source/RuntimeMain.cxx
@@ -0,0 +1,30 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+------------------------------------------- */
+
+#include <ArchKit/ArchKit.hpp>
+#include <Builtins/Toolbox/Rsrc/Splash.rsrc>
+#include <Builtins/Toolbox/Toolbox.hxx>
+#include <FirmwareKit/Handover.hxx>
+#include <KernelKit/FileManager.hpp>
+#include <KernelKit/Framebuffer.hpp>
+#include <KernelKit/KernelHeap.hpp>
+#include <KernelKit/PEFCodeManager.hxx>
+#include <KernelKit/ProcessScheduler.hpp>
+#include <KernelKit/UserHeap.hpp>
+#include <NewKit/Json.hpp>
+
+/// @file Main microkernel entrypoint.
+
+EXTERN_C void RuntimeMain(void) {
+ ///! Mounts a NewFS block.
+ HCore::NewFilesystemManager* newFS = new HCore::NewFilesystemManager();
+ HCore::ke_protect_ke_heap(newFS);
+
+ HCore::FilesystemManagerInterface::Mount(newFS);
+
+ ///! we're done, unmount.
+ delete newFS;
+} \ No newline at end of file