summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-29 22:38:43 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-29 22:38:43 +0100
commita8c17ccd6d97cc78830917dc6282b040b21ba16c (patch)
tree2181e96ccf9c89c677d2208661bce5584a667470
parent78861f1b16f18a85e9f6890e16eb320412b6ab80 (diff)
Kernel: Update SPECS and TODO list.
Cleaned up the SPECS to get into the point. Current Task: Load kernel into memory. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
-rw-r--r--Private/HALKit/AMD64/ACPI/ACPIManager.hpp3
-rw-r--r--Private/HALKit/AMD64/DebugOutput.cxx23
-rw-r--r--Private/NewBoot/BootKit/Boot.hxx84
-rw-r--r--Private/NewBoot/BootKit/Protocol.hxx5
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/Boot.cxx15
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx9
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/Platform.cxx (renamed from Private/NewBoot/Source/HEL/AMD64/Processor.cxx)0
-rw-r--r--Private/NewBoot/Source/makefile8
-rw-r--r--Private/NewKit/CRC32.hpp9
-rw-r--r--Private/Source/Crc32.cxx2
-rw-r--r--Private/Source/ErrorOr.cxx5
-rw-r--r--Private/Source/ProcessManager.cxx370
-rw-r--r--Private/Source/SharedObjectEntry.cxx (renamed from Private/Source/SharedObject.cxx)16
-rw-r--r--Private/Source/Storage/ATA.cxx21
-rw-r--r--Private/StorageKit/PRDT.hpp71
-rw-r--r--SPECIFICATION.TXT59
-rw-r--r--TODO_LIST.TXT5
17 files changed, 341 insertions, 364 deletions
diff --git a/Private/HALKit/AMD64/ACPI/ACPIManager.hpp b/Private/HALKit/AMD64/ACPI/ACPIManager.hpp
index 385ea854..da01f1c7 100644
--- a/Private/HALKit/AMD64/ACPI/ACPIManager.hpp
+++ b/Private/HALKit/AMD64/ACPI/ACPIManager.hpp
@@ -18,13 +18,12 @@
namespace hCore {
class ACPIManager {
public:
- ACPIManager(voidPtr rsdptr);
+ explicit ACPIManager(voidPtr rsdptr);
public:
~ACPIManager() = default;
ACPIManager &operator=(const ACPIManager &) = default;
-
ACPIManager(const ACPIManager &) = default;
public:
diff --git a/Private/HALKit/AMD64/DebugOutput.cxx b/Private/HALKit/AMD64/DebugOutput.cxx
index 43ab2538..123ad4c6 100644
--- a/Private/HALKit/AMD64/DebugOutput.cxx
+++ b/Private/HALKit/AMD64/DebugOutput.cxx
@@ -12,10 +12,20 @@
#include <NewKit/Utils.hpp>
namespace hCore {
+enum CommStatus {
+ kStateReady = 0xCF,
+ kStateTransmit = 0xFC,
+ kStateLimbo,
+ kStateCnt = 3
+};
+
namespace Detail {
constexpr short PORT = 0x3F8;
+static int kState = kStateLimbo;
+
bool serial_init() {
+#ifdef __DEBUG__
HAL::out8(PORT + 1, 0x00); // Disable all interrupts
HAL::out8(PORT + 3, 0x80); // Enable DLAB (set baud rate divisor)
HAL::out8(PORT + 0, 0x03); // Set divisor to 3 (lo byte) 38400 baud
@@ -29,23 +39,24 @@ bool serial_init() {
// Check if serial is faulty (i.e: not same byte as sent)
if (HAL::in8(PORT) != 0xAE) {
-#ifdef __DEBUG__
panic(RUNTIME_CHECK_HANDSHAKE);
-#else
- return false;
-#endif
}
+ kReady = kStateReady;
+
// If serial is not faulty set it in normal operation mode
// (not-loopback with IRQs enabled and OUT#1 and OUT#2 bits enabled)
HAL::out8(Detail::PORT + 4, 0x0F);
+#endif
return true;
}
} // namespace Detail
void system_io_print(const char *bytes) {
- if (!bytes) return;
+ if (!bytes || Detail::kState != kStateReady) return;
+
+ Detail::kState = kStateTransmit;
SizeT index = 0;
SizeT len = string_length(bytes, 256);
@@ -54,6 +65,8 @@ void system_io_print(const char *bytes) {
HAL::out8(Detail::PORT, bytes[index]);
++index;
}
+
+ Detail::kState = kStateReady;
}
TerminalDevice kcout(hCore::system_io_print, nullptr);
diff --git a/Private/NewBoot/BootKit/Boot.hxx b/Private/NewBoot/BootKit/Boot.hxx
index 07148702..4bdc9c84 100644
--- a/Private/NewBoot/BootKit/Boot.hxx
+++ b/Private/NewBoot/BootKit/Boot.hxx
@@ -7,6 +7,11 @@
* ========================================================
*/
+/***********************************************************************************/
+/// @file Boot.hxx
+/// @brief Bootloader API.
+/***********************************************************************************/
+
#pragma once
#include <NewKit/Defines.hpp>
@@ -15,55 +20,62 @@ using namespace hCore;
typedef void *PEFImage;
-enum
-{
- kSegmentCode = 2,
- kSegmentData = 4,
- kSegmentBss = 6,
+enum {
+ kSegmentCode = 2,
+ kSegmentData = 4,
+ kSegmentBss = 6,
};
/**
* @brief BootKit Text Writer class
* Writes to VGA.
*/
-class BKTextWriter final
-{
- volatile UInt16 *fWhere{nullptr};
+class BKTextWriter final {
+ volatile UInt16 *fWhere{nullptr};
- public:
- void WriteString(const char *c, unsigned char forecolour, unsigned char backcolour, int x, int y);
+ public:
+ void WriteString(const char *c, unsigned char forecolour,
+ unsigned char backcolour, int x, int y);
- void WriteCharacter(char c, unsigned char forecolour, unsigned char backcolour, int x, int y);
+ void WriteCharacter(char c, unsigned char forecolour,
+ unsigned char backcolour, int x, int y);
- public:
- BKTextWriter() = default;
- ~BKTextWriter() = default;
+ public:
+ BKTextWriter() = default;
+ ~BKTextWriter() = default;
- public:
- BKTextWriter &operator=(const BKTextWriter &) = default;
- BKTextWriter(const BKTextWriter &) = default;
+ public:
+ BKTextWriter &operator=(const BKTextWriter &) = default;
+ BKTextWriter(const BKTextWriter &) = default;
};
-enum
-{
- kBlack,
- kBlue,
- kGreen,
- kCyan,
- kRed,
- kMagenta,
- kBrown,
- kLightGray,
- kDarkGray,
- kLightBlue,
- kLightGreen,
- kLightCyan,
- kLightRed,
- kLightMagenta,
- kYellow,
- kWhite,
+enum {
+ kBlack,
+ kBlue,
+ kGreen,
+ kCyan,
+ kRed,
+ kMagenta,
+ kBrown,
+ kLightGray,
+ kDarkGray,
+ kLightBlue,
+ kLightGreen,
+ kLightCyan,
+ kLightRed,
+ kLightMagenta,
+ kYellow,
+ kWhite,
};
-#define BK_START_KERNEL (0x10000000)
+#define BK_START_KERNEL (0x80000000)
hCore::SizeT BStrLen(const char *ptr);
+hCore::SizeT BSetMem(char *src, const char byte, const hCore::SizeT len);
+
+/***********************************************************************************/
+/// Include other APIs.
+/***********************************************************************************/
+
+#include <BootKit/Processor.hxx>
+#include <BootKit/Protocol.hxx>
diff --git a/Private/NewBoot/BootKit/Protocol.hxx b/Private/NewBoot/BootKit/Protocol.hxx
index bcbb43a3..26eef7e7 100644
--- a/Private/NewBoot/BootKit/Protocol.hxx
+++ b/Private/NewBoot/BootKit/Protocol.hxx
@@ -55,8 +55,11 @@ struct HandoverInformationHeader {
SizeT f_VirtualSize;
voidPtr f_PhysicalStart;
SizeT f_PhysicalSize;
- voidPtr f_FirmwareVendorName;
+ Char f_FirmwareVendorName[32];
SizeT f_FirmwareVendorLen;
+ voidPtr f_RsdPtr;
+ voidPtr f_SmBIOS;
+ voidPtr f_RTC;
};
/**
diff --git a/Private/NewBoot/Source/HEL/AMD64/Boot.cxx b/Private/NewBoot/Source/HEL/AMD64/Boot.cxx
index 70f280e6..6bf63ffe 100644
--- a/Private/NewBoot/Source/HEL/AMD64/Boot.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/Boot.cxx
@@ -22,6 +22,21 @@ hCore::SizeT BStrLen(const char *ptr) {
return cnt;
}
+hCore::SizeT BSetMem(char *src, const char byte, const hCore::SizeT len) {
+ hCore::SizeT cnt = 0UL;
+
+ while (*src != 0) {
+ if (cnt > len) break;
+
+ *src = byte;
+ ++src;
+
+ ++cnt;
+ }
+
+ return cnt;
+}
+
/**
@brief puts wrapper over VGA.
*/
diff --git a/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx b/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx
index 5422d368..a1868144 100644
--- a/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx
@@ -8,16 +8,13 @@
*/
#include <BootKit/Boot.hxx>
-#include <BootKit/Processor.hxx>
-#include <BootKit/Protocol.hxx>
// don't remove EfiGUID, it will call initializer_list!
EFI_EXTERN_C int EfiMain(EfiHandlePtr ImageHandle,
EfiSystemTable* SystemTable) {
- EfiCharType* string = L"HCoreLdr: Initializing...\r\n";
-
- SystemTable->ConOut->OutputString(SystemTable->ConOut, string);
+ SystemTable->ConOut->OutputString(SystemTable->ConOut,
+ L"HCoreLdr: Initializing Kernel...\r\n");
EfiLoadImageProtocol* protocol;
EfiGUID guid = EFI_LOADED_IMAGE_PROTOCOL_GUID;
@@ -42,7 +39,7 @@ EFI_EXTERN_C int EfiMain(EfiHandlePtr ImageHandle,
SystemTable->ConOut, L"HCoreLdr: Could not exit Boot Services!\r\n");
SystemTable->ConOut->OutputString(SystemTable->ConOut,
- L"HCoreLdr: Hanging...\r\n");
+ L"HCoreLdr: Entering limbo state...\r\n");
while (true) {
rt_cli();
diff --git a/Private/NewBoot/Source/HEL/AMD64/Processor.cxx b/Private/NewBoot/Source/HEL/AMD64/Platform.cxx
index a0c93ab5..a0c93ab5 100644
--- a/Private/NewBoot/Source/HEL/AMD64/Processor.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/Platform.cxx
diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile
index 1fa6cc46..9ae30d13 100644
--- a/Private/NewBoot/Source/makefile
+++ b/Private/NewBoot/Source/makefile
@@ -8,6 +8,10 @@ LD_GNU=x86_64-w64-mingw32-ld
FLAG_GNU=-fshort-wchar -fPIC -D__DBG__ -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)/
+.PHONY: invalid-recipe
+invalid-recipe:
+ @echo "invalid-recipe: Use make arch-<arch> all instead."
+
.PHONY: arch-amd64
arch-amd64:
$(CC_GNU) $(FLAG_GNU) HEL/AMD64/*.cxx
@@ -15,8 +19,8 @@ arch-amd64:
cp HCORELDR.EXE CDROM/EFI/BOOT/BOOTX64.EFI
cp -r ../../Root ./CDROM/MAHROUSS
-.PHONY: efi-debug
-efi-debug:
+.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 -bios OVMF.fd -net none -drive file=fat:rw:CDROM,format=raw -d int
diff --git a/Private/NewKit/CRC32.hpp b/Private/NewKit/CRC32.hpp
index b5859cfa..751f98b9 100644
--- a/Private/NewKit/CRC32.hpp
+++ b/Private/NewKit/CRC32.hpp
@@ -14,9 +14,8 @@
#define kCrcCnt (256)
-namespace hCore
-{
- Int crc32(const Char* crc, Int len);
-} // namespace hCore
+namespace hCore {
+Int ke_crc32(const Char* crc, Int len);
+} // namespace hCore
-#endif // !__CRC32_H__
+#endif // !__CRC32_H__
diff --git a/Private/Source/Crc32.cxx b/Private/Source/Crc32.cxx
index 37663b8d..e711626d 100644
--- a/Private/Source/Crc32.cxx
+++ b/Private/Source/Crc32.cxx
@@ -67,7 +67,7 @@ static Int crc_byte(Int crc, UChar byte) {
return crc;
}
-Int crc32(const Char *byte, Int len) {
+Int ke_crc32(const Char *byte, Int len) noexcept {
Int checksum = 0;
for (UChar index = 1; index < len; ++index)
diff --git a/Private/Source/ErrorOr.cxx b/Private/Source/ErrorOr.cxx
index 4137c243..aff86ed0 100644
--- a/Private/Source/ErrorOr.cxx
+++ b/Private/Source/ErrorOr.cxx
@@ -9,4 +9,7 @@
#include <NewKit/ErrorOr.hpp>
-/* BUILDME needs that file */
+/***********************************************************************************/
+/// @file ErrorOr.cxx
+/// @brief ErrorOr class.
+/***********************************************************************************/
diff --git a/Private/Source/ProcessManager.cxx b/Private/Source/ProcessManager.cxx
index 987b8093..ce20cad4 100644
--- a/Private/Source/ProcessManager.cxx
+++ b/Private/Source/ProcessManager.cxx
@@ -7,13 +7,17 @@
* ========================================================
*/
-#include "NewKit/Panic.hpp"
+/***********************************************************************************/
+/// @file ProcessManager.cxx
+/// @brief Process Scheduler API.
+/***********************************************************************************/
+
#include <KernelKit/ProcessManager.hpp>
#include <KernelKit/SMPManager.hpp>
#include <NewKit/KernelHeap.hpp>
#include <NewKit/String.hpp>
-#define kPoolAlign (4)
+#include "NewKit/Panic.hpp"
///! bugs = 0
@@ -23,312 +27,260 @@
* For MT see SMPManager. */
/***********************************************************************************/
-namespace hCore
-{
+namespace hCore {
/***********************************************************************************/
/// Exit Code stuff
/***********************************************************************************/
static Int32 kExitCode = 0;
-const Int32 &rt_get_exit_code() noexcept
-{
- return kExitCode;
-}
+const Int32 &rt_get_exit_code() noexcept { return kExitCode; }
/***********************************************************************************/
-void Process::Crash()
-{
- kcout << this->Name << ": Crashed\n";
- this->Exit(-1);
+void Process::Crash() {
+ kcout << this->Name << ": Crashed\n";
+ this->Exit(-1);
}
-void Process::Wake(const bool should_wakeup)
-{
- this->Status = should_wakeup ? ProcessStatus::kRunning : ProcessStatus::kFrozen;
+void Process::Wake(const bool should_wakeup) {
+ this->Status =
+ should_wakeup ? ProcessStatus::kRunning : ProcessStatus::kFrozen;
}
/***********************************************************************************/
-VoidPtr Process::New(const SizeT &sz)
-{
- if (this->FreeMemory < 1)
- return nullptr;
-
- // RAM allocation
- if (this->PoolCursor)
- {
- VoidPtr ptr = this->PoolCursor;
- this->PoolCursor = (VoidPtr)((UIntPtr)this->PoolCursor + (sizeof(sz) + kPoolAlign));
+VoidPtr Process::New(const SizeT &sz) {
+ if (this->FreeMemory < 1) return nullptr;
- ++this->UsedMemory;
- --this->FreeMemory;
+ // RAM allocation
+ if (this->PoolCursor) {
+ VoidPtr ptr = this->PoolCursor;
+ this->PoolCursor = (VoidPtr)((UIntPtr)this->PoolCursor + (sizeof(sz)));
- return ptr;
- }
+ ++this->UsedMemory;
+ --this->FreeMemory;
- //! TODO: Disk allocation
+ return ptr;
+ }
- return nullptr;
+ return nullptr;
}
/***********************************************************************************/
/* @brief checks if runtime pointer is in region. */
-bool rt_in_pool_region(VoidPtr pool_ptr, VoidPtr pool, const SizeT &sz)
-{
- Char *_pool_ptr = (Char *)pool_ptr;
- Char *_pool = (Char *)pool;
-
- for (SizeT index = sz; _pool[sz] != 0x55; --index)
- {
- if (&_pool[index] > &_pool_ptr[sz])
- continue;
-
- if (_pool[index] == _pool_ptr[index])
- return true;
- }
+bool rt_in_pool_region(VoidPtr pool_ptr, VoidPtr pool, const SizeT &sz) {
+ Char *_pool_ptr = (Char *)pool_ptr;
+ Char *_pool = (Char *)pool;
- return false;
+ for (SizeT index = sz; _pool[sz] != 0x55; --index) {
+ if (&_pool[index] > &_pool_ptr[sz]) continue;
+
+ if (_pool[index] == _pool_ptr[index]) return true;
+ }
+
+ return false;
}
/* @brief free pointer from usage. */
-Boolean Process::Delete(VoidPtr ptr, const SizeT &sz)
-{
- if (sz < 1 || this->PoolCursor == this->Pool)
- return false;
+Boolean Process::Delete(VoidPtr ptr, const SizeT &sz) {
+ if (sz < 1 || this->PoolCursor == this->Pool) return false;
- // also check for the amount of allocations we've done so far.
- if (this->UsedMemory < 1)
- return false;
+ // also check for the amount of allocations we've done so far.
+ if (this->UsedMemory < 1) return false;
- if (rt_in_pool_region(ptr, this->PoolCursor, this->UsedMemory))
- {
- this->PoolCursor = (VoidPtr)((UIntPtr)this->PoolCursor - (sizeof(sz) - kPoolAlign));
- rt_zero_memory(ptr, sz);
+ if (rt_in_pool_region(ptr, this->PoolCursor, this->UsedMemory)) {
+ this->PoolCursor = (VoidPtr)((UIntPtr)this->PoolCursor - (sizeof(sz)));
+ rt_zero_memory(ptr, sz);
- ++this->FreeMemory;
- --this->UsedMemory;
+ ++this->FreeMemory;
+ --this->UsedMemory;
- return true;
- }
+ return true;
+ }
- return false;
+ return false;
}
-const Char *Process::GetName()
-{
- return this->Name;
-}
+const Char *Process::GetName() { return this->Name; }
-const ProcessSelector &Process::GetSelector()
-{
- return this->Selector;
-}
+const ProcessSelector &Process::GetSelector() { return this->Selector; }
-const ProcessStatus &Process::GetStatus()
-{
- return this->Status;
-}
+const ProcessStatus &Process::GetStatus() { return this->Status; }
/***********************************************************************************/
/**
@brief Affinity is the time slot allowed for the process.
*/
-const AffinityKind &Process::GetAffinity()
-{
- return this->Affinity;
-}
+const AffinityKind &Process::GetAffinity() { return this->Affinity; }
/**
@brief Standard exit proc.
*/
-void Process::Exit(Int32 exit_code)
-{
- if (this->ProcessId != ProcessManager::Shared().Leak().GetCurrent().Leak().ProcessId)
- panic(RUNTIME_CHECK_PROCESS);
+void Process::Exit(Int32 exit_code) {
+ if (this->ProcessId !=
+ ProcessManager::Shared().Leak().GetCurrent().Leak().ProcessId)
+ panic(RUNTIME_CHECK_PROCESS);
- if (this->Ring == (Int32)ProcessSelector::kRingKernel &&
- ProcessManager::Shared().Leak().GetCurrent().Leak().Ring > 0)
- panic(RUNTIME_CHECK_PROCESS);
+ if (this->Ring == (Int32)ProcessSelector::kRingKernel &&
+ ProcessManager::Shared().Leak().GetCurrent().Leak().Ring > 0)
+ panic(RUNTIME_CHECK_PROCESS);
- kExitCode = exit_code;
+ kExitCode = exit_code;
- if (this->Ring != (Int32)ProcessSelector::kRingDriver && this->Ring != (Int32)ProcessSelector::kRingKernel)
- {
- pool_free_ptr(this->Pool);
+ if (this->Ring != (Int32)ProcessSelector::kRingDriver &&
+ this->Ring != (Int32)ProcessSelector::kRingKernel) {
+ pool_free_ptr(this->Pool);
- this->PoolCursor = nullptr;
+ this->PoolCursor = nullptr;
- this->FreeMemory = kPoolMaxSz;
- this->UsedMemory = 0UL;
- }
+ this->FreeMemory = kPoolMaxSz;
+ this->UsedMemory = 0UL;
+ }
- //! Delete image if not done already.
- if (this->Image)
- kernel_delete_ptr(this->Image);
+ //! Delete image if not done already.
+ if (this->Image) kernel_delete_ptr(this->Image);
- if (this->StackFrame)
- kernel_delete_ptr((VoidPtr)this->StackFrame);
+ if (this->StackFrame) kernel_delete_ptr((VoidPtr)this->StackFrame);
- ProcessManager::Shared().Leak().Remove(this->ProcessId);
+ ProcessManager::Shared().Leak().Remove(this->ProcessId);
}
-bool ProcessManager::Add(Ref<Process> &process)
-{
- if (!process)
- return false;
+bool ProcessManager::Add(Ref<Process> &process) {
+ if (!process) return false;
- kcout << "ProcessManager::Add(Ref<Process>& process)\r\n";
+ kcout << "ProcessManager::Add(Ref<Process>& process)\r\n";
- process.Leak().Pool = pool_new_ptr(kPoolUser | kPoolRw);
- process.Leak().ProcessId = this->m_Headers.Count();
- process.Leak().PoolCursor = process.Leak().Pool;
+ process.Leak().Pool = pool_new_ptr(kPoolUser | kPoolRw);
+ process.Leak().ProcessId = this->m_Headers.Count();
+ process.Leak().PoolCursor = process.Leak().Pool;
- process.Leak().StackFrame =
- reinterpret_cast<HAL::StackFrame *>(kernel_new_ptr(sizeof(HAL::StackFrame), true, false));
+ process.Leak().StackFrame = reinterpret_cast<HAL::StackFrame *>(
+ kernel_new_ptr(sizeof(HAL::StackFrame), true, false));
- MUST_PASS(process.Leak().StackFrame);
+ MUST_PASS(process.Leak().StackFrame);
- UIntPtr imageStart = reinterpret_cast<UIntPtr>(process.Leak().Image);
+ UIntPtr imageStart = reinterpret_cast<UIntPtr>(process.Leak().Image);
- process.Leak().AssignStart(imageStart);
+ process.Leak().AssignStart(imageStart);
- this->m_Headers.Add(process);
+ this->m_Headers.Add(process);
- return true;
+ return true;
}
-bool ProcessManager::Remove(SizeT process)
-{
- if (process > this->m_Headers.Count())
- return false;
+bool ProcessManager::Remove(SizeT process) {
+ if (process > this->m_Headers.Count()) return false;
- kcout << "ProcessManager::Remove(SizeT process)\r\n";
+ kcout << "ProcessManager::Remove(SizeT process)\r\n";
- return this->m_Headers.Remove(process);
+ return this->m_Headers.Remove(process);
}
-SizeT ProcessManager::Run() noexcept
-{
- SizeT processIndex = 0; //! we store this guy to tell the scheduler how many things we
- //! have scheduled.
+SizeT ProcessManager::Run() noexcept {
+ SizeT processIndex = 0; //! we store this guy to tell the scheduler how many
+ //! things we have scheduled.
- for (; processIndex < this->m_Headers.Count(); ++processIndex)
- {
- auto process = this->m_Headers[processIndex];
+ for (; processIndex < this->m_Headers.Count(); ++processIndex) {
+ auto process = this->m_Headers[processIndex];
- MUST_PASS(
- process); //! no need for a MUST_PASS(process.Leak());, it is recursive because of the nature of the class;
+ MUST_PASS(process); //! no need for a MUST_PASS(process.Leak());, it is
+ //! recursive because of the nature of the class;
- //! run any process needed to be scheduled.
- if (ProcessHelper::CanBeScheduled(process.Leak()))
- {
- auto unwrapped_process = *process.Leak();
+ //! run any process needed to be scheduled.
+ if (ProcessHelper::CanBeScheduled(process.Leak())) {
+ auto unwrapped_process = *process.Leak();
- unwrapped_process.PTime = 0;
+ unwrapped_process.PTime = 0;
- // set the current process.
- m_CurrentProcess = unwrapped_process;
+ // set the current process.
+ m_CurrentProcess = unwrapped_process;
- ProcessHelper::Switch(m_CurrentProcess.Leak().StackFrame, m_CurrentProcess.Leak().ProcessId);
- }
- else
- {
- // otherwise increment the micro-time.
- ++m_CurrentProcess.Leak().PTime;
- }
+ ProcessHelper::Switch(m_CurrentProcess.Leak().StackFrame,
+ m_CurrentProcess.Leak().ProcessId);
+ } else {
+ // otherwise increment the micro-time.
+ ++m_CurrentProcess.Leak().PTime;
}
+ }
- return processIndex;
+ return processIndex;
}
-Ref<ProcessManager> ProcessManager::Shared()
-{
- static ProcessManager ref;
- return {ref};
+Ref<ProcessManager> ProcessManager::Shared() {
+ static ProcessManager ref;
+ return {ref};
}
-Ref<Process> &ProcessManager::GetCurrent()
-{
- return m_CurrentProcess;
-}
+Ref<Process> &ProcessManager::GetCurrent() { return m_CurrentProcess; }
-PID &ProcessHelper::GetCurrentPID()
-{
- kcout << "ProcessHelper::GetCurrentPID\r\n";
- return ProcessManager::Shared().Leak().GetCurrent().Leak().ProcessId;
+PID &ProcessHelper::GetCurrentPID() {
+ kcout << "ProcessHelper::GetCurrentPID\r\n";
+ return ProcessManager::Shared().Leak().GetCurrent().Leak().ProcessId;
}
-bool ProcessHelper::CanBeScheduled(Ref<Process> &process)
-{
- if (process.Leak().Status == ProcessStatus::kFrozen || process.Leak().Status == ProcessStatus::kDead)
- return false;
-
- if (process.Leak().GetStatus() == ProcessStatus::kStarting)
- {
- if (process.Leak().PTime < static_cast<Int>(kMinMicroTime))
- {
- process.Leak().Status = ProcessStatus::kRunning;
- process.Leak().Affinity = AffinityKind::kStandard;
+bool ProcessHelper::CanBeScheduled(Ref<Process> &process) {
+ if (process.Leak().Status == ProcessStatus::kFrozen ||
+ process.Leak().Status == ProcessStatus::kDead)
+ return false;
- return true;
- }
+ 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().PTime;
+ return true;
}
- return process.Leak().PTime > static_cast<Int>(kMinMicroTime);
+ ++process.Leak().PTime;
+ }
+
+ return process.Leak().PTime > static_cast<Int>(kMinMicroTime);
}
-bool ProcessHelper::StartScheduling()
-{
- if (ProcessHelper::CanBeScheduled(ProcessManager::Shared().Leak().GetCurrent()))
- {
- --ProcessManager::Shared().Leak().GetCurrent().Leak().PTime;
- return false;
- }
+bool ProcessHelper::StartScheduling() {
+ if (ProcessHelper::CanBeScheduled(
+ ProcessManager::Shared().Leak().GetCurrent())) {
+ --ProcessManager::Shared().Leak().GetCurrent().Leak().PTime;
+ return false;
+ }
- auto process_ref = ProcessManager::Shared().Leak();
+ auto process_ref = ProcessManager::Shared().Leak();
- if (!process_ref)
- return false; // we have nothing to schedule. simply return.
+ if (!process_ref)
+ return false; // we have nothing to schedule. simply return.
- SizeT ret = process_ref.Run();
+ SizeT ret = process_ref.Run();
- kcout << StringBuilder::FromInt("ProcessHelper::StartScheduling() iterated over: % processes\r\n", ret);
+ kcout << StringBuilder::FromInt(
+ "ProcessHelper::StartScheduling() iterated over: % processes\r\n", ret);
- return true;
+ return true;
}
-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().StackFrame() == the_stack)
- {
- SMPManager::Shared().Leak()[index].Leak().Busy(false);
- continue;
- }
-
- if (SMPManager::Shared().Leak()[index].Leak().IsBusy())
- continue;
-
- if (SMPManager::Shared().Leak()[index].Leak().Kind() != ThreadKind::kBoot ||
- SMPManager::Shared().Leak()[index].Leak().Kind() != ThreadKind::kSystemReserved)
- {
- SMPManager::Shared().Leak()[index].Leak().Busy(true);
- ProcessHelper::GetCurrentPID() = new_pid;
-
- return SMPManager::Shared().Leak()[index].Leak().Switch(the_stack);
- }
+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().StackFrame() == the_stack) {
+ SMPManager::Shared().Leak()[index].Leak().Busy(false);
+ continue;
}
- return false;
+ if (SMPManager::Shared().Leak()[index].Leak().IsBusy()) continue;
+
+ if (SMPManager::Shared().Leak()[index].Leak().Kind() != ThreadKind::kBoot ||
+ SMPManager::Shared().Leak()[index].Leak().Kind() !=
+ ThreadKind::kSystemReserved) {
+ SMPManager::Shared().Leak()[index].Leak().Busy(true);
+ ProcessHelper::GetCurrentPID() = new_pid;
+
+ return SMPManager::Shared().Leak()[index].Leak().Switch(the_stack);
+ }
+ }
+
+ return false;
}
-} // namespace hCore
+} // namespace hCore
diff --git a/Private/Source/SharedObject.cxx b/Private/Source/SharedObjectEntry.cxx
index 0e824b27..9fe14b39 100644
--- a/Private/Source/SharedObject.cxx
+++ b/Private/Source/SharedObjectEntry.cxx
@@ -17,13 +17,16 @@
using namespace hCore;
/***********************************************************************************/
+/// @file SharedObjectEntry.cxx
+/// @brief Shared Object Init code.
+/***********************************************************************************/
-extern "C" SharedObject *__LibMain(VoidPtr image) {
- /***********************************************************************************/
- /* Allocate new library to be added to the lookup table.
- */
- /***********************************************************************************/
+/***********************************************************************************/
+/* @brief Allocate new library to be added to the lookup table.
+ */
+/***********************************************************************************/
+extern "C" SharedObject *__LibMain(VoidPtr image) {
SharedObject *library = hcore_tls_new_class<SharedObject>();
if (!library) {
@@ -44,9 +47,10 @@ extern "C" SharedObject *__LibMain(VoidPtr image) {
library->Get()->fImageObject =
ProcessManager::Shared().Leak().GetCurrent().Leak().Image;
+
library->Get()->fImageEntrypointOffset = library->Load<VoidPtr>(kPefStart);
- kcout << "__LibMain: Done allocating Shared Library...\n";
+ kcout << "__LibMain: Done jumping to library...\n";
return library;
}
diff --git a/Private/Source/Storage/ATA.cxx b/Private/Source/Storage/ATA.cxx
index f960907b..ed62df4f 100644
--- a/Private/Source/Storage/ATA.cxx
+++ b/Private/Source/Storage/ATA.cxx
@@ -10,8 +10,12 @@
#include <ArchKit/Arch.hpp>
#include <StorageKit/ATA.hpp>
-//! @brief Driver for ATA, listens to a specific address for data to come.
-//! mapped by NewFirmware.
+#include "NewKit/Utils.hpp"
+
+//! @brief ATA DMA Driver
+//! mapped by UEFI.
+
+/// bugs 0
#define kATAError 2
@@ -51,10 +55,13 @@ const char* ata_read_28(ULong lba) {
return buffer;
}
+#define kBufferLen 512
+
const char* ata_read_48(ULong lba) {
- static char buffer[512];
+ static char buffer[kBufferLen];
+ rt_set_memory(buffer, 0, kBufferLen);
- UIntPtr* packet = (UIntPtr*)kPrdt.Leak()->PhysicalAddress();
+ UIntPtr* packet = reinterpret_cast<UIntPtr*>(kPrdt.Leak()->PhysicalAddress());
packet[0] = k48BitRead;
packet[1] = (UIntPtr)&buffer;
@@ -65,11 +72,11 @@ const char* ata_read_48(ULong lba) {
return buffer;
}
-Int32 ata_write_48(ULong lba, const char* text) {
- UIntPtr* packet = (UIntPtr*)kPrdt.Leak()->PhysicalAddress();
+Int32 ata_write_48(ULong lba, const char* buffer) {
+ UIntPtr* packet = reinterpret_cast<UIntPtr*>(kPrdt.Leak()->PhysicalAddress());
packet[0] = k48BitWrite;
- packet[1] = (UIntPtr)&text;
+ packet[1] = (UIntPtr)&buffer;
packet[2] = lba;
rt_wait_for_io();
diff --git a/Private/StorageKit/PRDT.hpp b/Private/StorageKit/PRDT.hpp
index 96e0c5cd..9522ccab 100644
--- a/Private/StorageKit/PRDT.hpp
+++ b/Private/StorageKit/PRDT.hpp
@@ -13,42 +13,35 @@
#define PRDT_TRANSFER_SIZE (sizeof(hCore::UShort))
-namespace hCore
-{
- class PRDT final
- {
- public:
- PRDT() = delete;
- explicit PRDT(const UIntPtr &physAddr);
- ~PRDT();
-
- PRDT &operator=(const PRDT &) = default;
- PRDT(const PRDT &) = default;
-
- public:
- const UInt &Low();
- const UShort &High();
- const UIntPtr &PhysicalAddress();
-
- public:
- PRDT &operator=(const UIntPtr& prdtAddress);
-
- public:
- operator bool()
- {
- return m_PrdtAddr != 0;
- }
-
- private:
- union
- {
- UInt m_Low;
- UShort m_High;
- };
-
- UIntPtr m_PrdtAddr;
-
- };
-
- using PhysicalAddress = PRDT; // here
-} // namespace hCore
+namespace hCore {
+class PRDT final {
+ public:
+ PRDT() = delete;
+ explicit PRDT(const UIntPtr &physAddr);
+ ~PRDT();
+
+ PRDT &operator=(const PRDT &) = default;
+ PRDT(const PRDT &) = default;
+
+ public:
+ const UInt &Low();
+ const UShort &High();
+ const UIntPtr &PhysicalAddress();
+
+ public:
+ PRDT &operator=(const UIntPtr &prdtAddress);
+
+ public:
+ operator bool() { return m_PrdtAddr != 0; }
+
+ private:
+ union {
+ UInt m_Low;
+ UShort m_High;
+ };
+
+ UIntPtr m_PrdtAddr;
+};
+
+using PhysicalAddress = PRDT; // here
+} // namespace hCore
diff --git a/SPECIFICATION.TXT b/SPECIFICATION.TXT
index 504e1278..0b2238e7 100644
--- a/SPECIFICATION.TXT
+++ b/SPECIFICATION.TXT
@@ -2,55 +2,30 @@
0: Generic Information
===================================
-- ABI/Format: Portable Executable Format.
+- ABI/Format: PEF/PE32+.
- Architecture: Microkernel.
-- Language: C++/C/Assembly (AMD64, X64000, X86S, ARM64)
+- Language: C++/(Assembly (AMD64, X64000, X86S, ARM64))
===================================
1: The HCore Microkernel
===================================
-HCore mounts NewFS by default, a journal filesystem meant for GUI use.
-It makes use of a concept named 'Fork'
-It contains data about a specific 'Catalog'
-
-Programs are load using the PEF. PEF is a multiplatform container
-for executables/shared libraries. Dwarf is used for debugging.
-
-HCore has SMP in it's core with a preemptive multi-threaded scheduler.
-It also supports dynamic loading of symbols and has a rich driver system.
-
-====================================
-2: The GUI Kit
-====================================
-
-We have a Look and Feel system, to support custom application themes.
-CWindowLookAndFeel interface takes care of that.
-
-===================================
-3: The System Kit
-===================================
-
-We use C++ for this API, use it when dealing with C++ code. For C use RTKit.
-It is the unstable APIs with RTKit, they change a lot.
-
-Use the App Subsystem to create apps.
-
-===================================
-4: The RunTime Kit
-===================================
-
-It is a C API, they're mostly system calls, use this to make hCore
-optimizations.
-
+- Drive Abstraction.
+- SMP, Preemptive MT.
+- Separation of Files/Devices.
+- Networking.
+- Hardware Abstraction Layer.
+- Native Filesystem support (NewFS).
+- Program Loader.
+- TLS.
+- Dynamic Libraries.
+- Cross platform code (it has to work for each platform)
===================================
-5: The New Filesystem
+2: The Filesystem
===================================
-Based on HFS+ design of catalogs and forks, it is designed with journaling and recovery in mind.
-It's going to take advantage of the disk hardware.
-
-Such as RAID for NVME.
-
-SPECS:
+- Catalog based with forks.
+- Large storage support.
+- Long file names.
+- UNIX path style.
diff --git a/TODO_LIST.TXT b/TODO_LIST.TXT
index 14c6a6d5..54bece13 100644
--- a/TODO_LIST.TXT
+++ b/TODO_LIST.TXT
@@ -1,9 +1,10 @@
- We need preemptive multi-threading. [ X ]
- We then need sync primitives. [ X ]
- We also need a system library for the OS. [ X ]
-- We need a bootloader for AMD64 [ X ]
+- We need a bootloader for AMD64/ARM [ X ]
- Implement Boot Services [ X ]
- Design Handover [ X ]
- Load kernel into memory [ ]
- Jump to kernel [ ]
-- Add Native Subsystem and GUI [ ]
+- Context switch x87/SSE/AVX registers [ ]
+- Native Subsystem and GUI [ ]