summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@el-mahrouss-logic.com>2024-03-29 23:10:36 +0100
committerAmlal El Mahrouss <amlal@el-mahrouss-logic.com>2024-03-29 23:14:16 +0100
commit995e1580f9291c5b8e95687c59b95e561c0c4569 (patch)
tree50616d08887f2ca193683ff188ca952a0bb0ce3e
parent43ae417266c3127bbae35527c95c26e01ed50bd9 (diff)
Kernel: See below.
- Fix ACPI. - Parsing SDT correctly now. - Fix ke_runtime_check line endings. - Update Kernel heap magic and add padding to header. - Document Code Manager add limit for process teams. - Add execute_from_image for Code Manager. - Add loop for scheduler inside RuntimeMain. - Set SMP core to 4 for testing purposes. - Check for ACPI 2.x+ Signed-off-by: Amlal El Mahrouss <amlal@el-mahrouss-logic.com>
-rw-r--r--Private/HALKit/AMD64/HalACPIFactoryInterface.cxx64
-rw-r--r--Private/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp31
-rw-r--r--Private/HALKit/AMD64/HalKernelMain.cxx8
-rw-r--r--Private/KernelKit/CodeManager.hpp17
-rw-r--r--Private/KernelKit/HError.hpp2
-rw-r--r--Private/KernelKit/PEFCodeManager.hxx5
-rw-r--r--Private/KernelKit/ProcessScheduler.hpp8
-rw-r--r--Private/KernelKit/UserHeap.hpp2
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootMain.cxx11
-rw-r--r--Private/NewBoot/Source/makefile2
-rw-r--r--Private/Source/CodeManager.cxx26
-rw-r--r--Private/Source/KernelCheck.cxx4
-rw-r--r--Private/Source/KernelHeap.cxx24
-rw-r--r--Private/Source/PEFCodeManager.cxx18
-rw-r--r--Private/Source/ProcessScheduler.cxx5
-rw-r--r--Private/Source/RuntimeMain.cxx2
-rw-r--r--Private/Source/UserHeap.cxx13
17 files changed, 154 insertions, 88 deletions
diff --git a/Private/HALKit/AMD64/HalACPIFactoryInterface.cxx b/Private/HALKit/AMD64/HalACPIFactoryInterface.cxx
index 83642206..4d1844d9 100644
--- a/Private/HALKit/AMD64/HalACPIFactoryInterface.cxx
+++ b/Private/HALKit/AMD64/HalACPIFactoryInterface.cxx
@@ -9,15 +9,42 @@
#include <NewKit/String.hpp>
namespace NewOS {
-ACPIFactoryInterface::ACPIFactoryInterface(voidPtr rsdPtr) : m_Rsdp(rsdPtr), m_Entries(0) {
+
+/// Custom to the virtual machine, you'll need to parse the MADT instead.
+
+void rt_shutdown_acpi_qemu_20(void) { HAL::Out16(0xb004, 0x2000); }
+
+void rt_shutdown_acpi_qemu_30_plus(void) { HAL::Out16(0x604, 0x2000); }
+
+void rt_shutdown_acpi_virtualbox(void) { HAL::Out16(0x4004, 0x3400); }
+
+/// You have to parse the MADT!
+
+ACPIFactoryInterface::ACPIFactoryInterface(voidPtr rsdPtr)
+ : m_Rsdp(rsdPtr), m_Entries(0) {
volatile RSDP *_rsdPtr = reinterpret_cast<volatile RSDP *>(this->m_Rsdp);
MUST_PASS(_rsdPtr);
MUST_PASS(_rsdPtr->Revision >= 2);
}
-Void ACPIFactoryInterface::Shutdown() {}
-Void ACPIFactoryInterface::Reboot() {}
+Void ACPIFactoryInterface::Shutdown() {
+#ifdef __DEBUG__
+ rt_shutdown_acpi_qemu_30_plus();
+#else
+
+#endif
+}
+
+/// @brief Reboot (shutdowns on qemu.)
+/// @return
+Void ACPIFactoryInterface::Reboot() {
+#ifdef __DEBUG__
+ rt_shutdown_acpi_qemu_30_plus();
+#else
+
+#endif
+}
/// @brief Finds a descriptor table inside ACPI XSDT.
ErrorOr<voidPtr> ACPIFactoryInterface::Find(const char *signature) {
@@ -29,19 +56,26 @@ ErrorOr<voidPtr> ACPIFactoryInterface::Find(const char *signature) {
RSDP *rsdPtr = reinterpret_cast<RSDP *>(this->m_Rsdp);
- auto xsdt = rsdPtr->XsdtAddress;
- SizeT num = (rsdPtr->Length + sizeof(SDT)) / 8;
+ if (rsdPtr->Revision <= 1) {
+ return ErrorOr<voidPtr>{-4};
+ }
+
+ SDT* xsdt = (SDT*)(rsdPtr->XsdtAddress >> (rsdPtr->XsdtAddress & 0xfff));
+ SizeT num = (xsdt->Length + sizeof(SDT)) / 8;
+
+ kcout << "ACPI: Number of entries: " << number(num) << endl;
constexpr short ACPI_SIGNATURE_LENGTH = 4;
for (Size index = 0; index < num; ++index) {
- SDT *sdt = reinterpret_cast<SDT *>(xsdt + sizeof(SDT) + index * 8);
+ SDT *sdt = (SDT*)*((UInt64*)(UInt64)xsdt + sizeof(SDT) + (index * 8));
- if (!Checksum(sdt->Signature, ACPI_SIGNATURE_LENGTH)) ke_stop(RUNTIME_CHECK_ACPI);
+ for (int signature_index = 0; signature_index < 4; signature_index++){
+ if (sdt->Signature[signature_index] != signature[signature_index])
+ break;
- if (StringBuilder::Equals(const_cast<const char *>(sdt->Signature),
- signature))
- return ErrorOr<voidPtr>(reinterpret_cast<voidPtr>(sdt));
+ if (signature_index == 3) return ErrorOr<voidPtr>(reinterpret_cast<voidPtr>((SDT*)sdt));;
+ }
}
return ErrorOr<voidPtr>{-1};
@@ -63,14 +97,4 @@ bool ACPIFactoryInterface::Checksum(const char *checksum, SSizeT len) {
return chr == 0;
}
-
-/// Custom to the virtual machine, you'll need to parse the MADT instead.
-
-void rt_shutdown_acpi_qemu_20(void) { HAL::Out16(0xb004, 0x2000); }
-
-void rt_shutdown_acpi_qemu_30_plus(void) { HAL::Out16(0x604, 0x2000); }
-
-void rt_shutdown_acpi_virtualbox(void) { HAL::Out16(0x4004, 0x3400); }
-
-/// You have to parse the MADT!
} // namespace NewOS
diff --git a/Private/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp b/Private/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp
index bbd3c6ea..f31e67c2 100644
--- a/Private/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp
+++ b/Private/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp
@@ -43,11 +43,7 @@ STATIC voidPtr kApicMadt = nullptr;
STATIC const char* kApicSignature = "APIC";
/// @brief Multiple APIC descriptor table.
-struct MadtType final {
- char fMag[4];
- Int32 fLength;
- char fRev;
-
+struct MadtType final : public SDT {
struct MadtAddress final {
UInt32 fPhysicalAddress;
UInt32 fFlags; // 1 = Dual Legacy PICs installed
@@ -91,36 +87,21 @@ struct MadtLocalApicAddressOverride final {
///////////////////////////////////////////////////////////////////////////////////////
-STATIC MadtType kApicMadtList[256];
-
-MadtType* _hal_system_find_core(MadtType* madt) {
- madt = madt + sizeof(MadtType);
-
- if (rt_string_cmp(madt->fMag, kApicSignature,
- rt_string_len(kApicSignature)) == 0)
- return madt;
-
- return nullptr;
-}
+STATIC MadtType* kApicInfoBlock = nullptr;
///////////////////////////////////////////////////////////////////////////////////////
void hal_system_get_cores(voidPtr rsdPtr) {
+ kcout << "NewKernel.exe: Constructing ACPIFactoryInterface...\r\n";
+
auto acpi = ACPIFactoryInterface(rsdPtr);
kApicMadt = acpi.Find(kApicSignature).Leak().Leak();
MUST_PASS(kApicMadt); // MADT must exist.
- SizeT counter = 0UL;
- MadtType* offset = _hal_system_find_core((MadtType*)kApicMadt);
- //! now find core addresses.
- while (offset != nullptr) {
- // calls rt_copy_memory in NewC++
- kApicMadtList[counter] = *offset;
- offset = _hal_system_find_core(offset);
+ kcout << "NewKernel.exe: Successfuly fetched the MADT!\r\n";
- ++counter;
- }
+ kApicInfoBlock = (MadtType*)kApicMadt;
}
} // namespace NewOS::HAL
diff --git a/Private/HALKit/AMD64/HalKernelMain.cxx b/Private/HALKit/AMD64/HalKernelMain.cxx
index 029bca3c..f6b8e957 100644
--- a/Private/HALKit/AMD64/HalKernelMain.cxx
+++ b/Private/HALKit/AMD64/HalKernelMain.cxx
@@ -19,6 +19,12 @@
EXTERN_C NewOS::VoidPtr kInterruptVectorTable[];
EXTERN_C void RuntimeMain();
+namespace NewOS::HAL {
+/// @brief Gets the system cores using the MADT.
+/// @param rsdPtr the RSD PTR.
+extern void hal_system_get_cores(NewOS::voidPtr rsdPtr);
+} // namespace NewOS::HAL
+
EXTERN_C void hal_init_platform(
NewOS::HEL::HandoverInformationHeader* HandoverHeader) {
kHandoverHeader = HandoverHeader;
@@ -64,6 +70,8 @@ EXTERN_C void hal_init_platform(
NewOS::HAL::Detail::_ke_power_on_self_test();
+ NewOS::HAL::hal_system_get_cores(kHandoverHeader->f_HardwareTables.f_RsdPtr);
+
/// END POST
ToolboxInitRsrc();
diff --git a/Private/KernelKit/CodeManager.hpp b/Private/KernelKit/CodeManager.hpp
index 5b06e4a4..adb37ff0 100644
--- a/Private/KernelKit/CodeManager.hpp
+++ b/Private/KernelKit/CodeManager.hpp
@@ -21,13 +21,12 @@
#define kUPPNameLen 64
namespace NewOS {
-/// \brief Much like Mac OS's UPP.
-/// This is read-only by design.
-/// It handles different kind of code.
-/// ARM <-> AMD64 for example.
-typedef struct UniversalProcedureTable final {
- const Char NAME[kUPPNameLen];
- const VoidPtr TRAP;
- const SizeT ARCH;
-} PACKED UniversalProcedureTableType;
+/// @brief Main process entrypoint.
+typedef void (*MainKind)(void);
+
+/// @brief Executes a new process from memory.
+/// @param main
+/// @param processName
+/// @return
+bool execute_from_image(MainKind main, const char* processName);
} // namespace NewOS \ No newline at end of file
diff --git a/Private/KernelKit/HError.hpp b/Private/KernelKit/HError.hpp
index 6885003f..d5a16fd6 100644
--- a/Private/KernelKit/HError.hpp
+++ b/Private/KernelKit/HError.hpp
@@ -31,6 +31,8 @@ inline constexpr HError kErrorFormatFailed = 47;
inline constexpr HError kErrorNetworkTimeout = 48;
inline constexpr HError kErrorInternal = 49;
inline constexpr HError kErrorForkAlreadyExists = 50;
+inline constexpr HError kErrorOutOfTeamSlot = 51;
+inline constexpr HError kErrorHeapNotPresent = 52;
inline constexpr HError kErrorUnimplemented = 0;
Boolean ke_bug_check(void) noexcept;
diff --git a/Private/KernelKit/PEFCodeManager.hxx b/Private/KernelKit/PEFCodeManager.hxx
index 45b475f5..ed43e924 100644
--- a/Private/KernelKit/PEFCodeManager.hxx
+++ b/Private/KernelKit/PEFCodeManager.hxx
@@ -11,7 +11,7 @@
#include <NewKit/ErrorOr.hpp>
#include <NewKit/String.hpp>
-#define kPefApplicationMime "application/x-hcore-exec"
+#define kPefApplicationMime "application/x-newos-exec"
namespace NewOS {
///
@@ -31,9 +31,6 @@ class PEFLoader : public LoaderInterface {
HCORE_COPY_DEFAULT(PEFLoader);
public:
- typedef void (*MainKind)(void);
-
- public:
const char *Path() override;
const char *Format() override;
const char *MIME() override;
diff --git a/Private/KernelKit/ProcessScheduler.hpp b/Private/KernelKit/ProcessScheduler.hpp
index 0cc531b9..c9e3b379 100644
--- a/Private/KernelKit/ProcessScheduler.hpp
+++ b/Private/KernelKit/ProcessScheduler.hpp
@@ -14,8 +14,10 @@
#include <KernelKit/UserHeap.hpp>
#include <NewKit/MutableArray.hpp>
-#define kMinMicroTime AffinityKind::kHartStandard
-#define kPIDInvalid (-1)
+#define kSchedMinMicroTime AffinityKind::kHartStandard
+#define kSchedInvalidPID (-1)
+
+#define kSchedProcessLimitPerTeam (100U)
////////////////////////////////////////////////////
@@ -153,7 +155,7 @@ class ProcessHeader final {
};
ProcessTime PTime;
- PID ProcessId{kPIDInvalid};
+ PID ProcessId{kSchedInvalidPID};
Int32 Ring{kRingDriverKind};
Int32 Kind{kUserKind};
diff --git a/Private/KernelKit/UserHeap.hpp b/Private/KernelKit/UserHeap.hpp
index 728fcd80..c919db53 100644
--- a/Private/KernelKit/UserHeap.hpp
+++ b/Private/KernelKit/UserHeap.hpp
@@ -18,7 +18,7 @@
/// @brief memory heap for user programs.
#define kUserHeapMaxSz (4096)
-#define kUserHeapMag (0x5500A1)
+#define kUserHeapMag (0xFAF0FEF0)
namespace NewOS {
typedef enum {
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
index 33491867..21cc4b92 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
@@ -17,6 +17,8 @@
#define kMaxBufSize 256
+EXTERN_C void Main(HEL::HandoverInformationHeader* handoverInfo);
+
/// @brief Bootloader main type.
typedef void (*bt_main_type)(HEL::HandoverInformationHeader* handoverInfo);
@@ -151,12 +153,17 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
}
if (!isIniNotFound) {
- writer.Write(L"NewBoot.exe: No partition found for s10. (HCR-1000)\r\n");
+ writer.Write(L"NewBoot.exe: No partition found for NewOS. (HCR-1000)\r\n");
+ writer.Write(L"NewBoot.exe: Running setup for NewOS...\r\n");
+
+ EFI::ExitBootServices(MapKey, ImageHandle);
+
+ Main(handoverHdrPtr);
} else {
handoverHdrPtr->f_Magic = kHandoverMagic;
handoverHdrPtr->f_Version = kHandoverVersion;
- writer.Write(L"NewBoot.exe: Running s10...\r\n");
+ writer.Write(L"NewBoot.exe: Running NewOS...\r\n");
EFI::ExitBootServices(MapKey, ImageHandle);
diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile
index 9e2dbca6..78d5f663 100644
--- a/Private/NewBoot/Source/makefile
+++ b/Private/NewBoot/Source/makefile
@@ -17,7 +17,7 @@ EMU=qemu-system-x86_64w.exe
endif
IMG=epm.img
-EMU_FLAGS=-net none -smp 2 -m 4G -M q35 -bios OVMF.fd -device piix3-ide,id=ide -drive id=disk,file=$(IMG),format=raw,if=none -device ide-hd,drive=disk,bus=ide.0 -drive file=fat:rw:CDROM,index=2,format=raw -d int
+EMU_FLAGS=-net none -smp 4 -m 4G -M q35 -bios OVMF.fd -device piix3-ide,id=ide -drive id=disk,file=$(IMG),format=raw,if=none -device ide-hd,drive=disk,bus=ide.0 -drive file=fat:rw:CDROM,index=2,format=raw -d int
LD_FLAGS=-e efi_main --subsystem=10
OBJ=$(wildcard *.o) $(wildcard ../../Objects/*.obj) $(wildcard HEL/AMD64/*.obj)
diff --git a/Private/Source/CodeManager.cxx b/Private/Source/CodeManager.cxx
new file mode 100644
index 00000000..db2a7017
--- /dev/null
+++ b/Private/Source/CodeManager.cxx
@@ -0,0 +1,26 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+------------------------------------------- */
+
+#include <NewKit/Utils.hpp>
+#include <KernelKit/CodeManager.hpp>
+#include <KernelKit/ProcessScheduler.hpp>
+
+using namespace NewOS;
+
+/// @brief Executes a new process from a function. kernel code only.
+/// @param main the start of the process.
+/// @return
+bool execute_from_image(MainKind main, const char* processName) noexcept {
+ if (!main) return false;
+
+ ProcessHeader proc((VoidPtr)main);
+ proc.Kind = ProcessHeader::kDriverKind;
+ rt_copy_memory((VoidPtr)processName, proc.Name, rt_string_len(proc.Name));
+
+ Ref<ProcessHeader> refProc = proc;
+
+ return ProcessScheduler::Shared().Leak().Add(refProc);
+} \ No newline at end of file
diff --git a/Private/Source/KernelCheck.cxx b/Private/Source/KernelCheck.cxx
index d290ca3d..2c5431e8 100644
--- a/Private/Source/KernelCheck.cxx
+++ b/Private/Source/KernelCheck.cxx
@@ -91,8 +91,8 @@ void ke_stop(const NewOS::Int &id) {
void ke_runtime_check(bool expr, const char *file, const char *line) {
if (!expr) {
#ifdef __DEBUG__
- kcout << "NewKernel: File: " << file << "\n";
- kcout << "NewKernel: Line: " << line << "\n";
+ kcout << "NewKernel: File: " << file << "\r\n";
+ kcout << "NewKernel: Line: " << line << "\r\n";
#endif // __DEBUG__
diff --git a/Private/Source/KernelHeap.cxx b/Private/Source/KernelHeap.cxx
index cdeabb24..10991b36 100644
--- a/Private/Source/KernelHeap.cxx
+++ b/Private/Source/KernelHeap.cxx
@@ -13,7 +13,8 @@
//! @file KernelHeap.cxx
//! @brief Kernel allocator.
-#define kHeapMagic 0xD4D7
+#define kHeapMagic (0xD4D7D5)
+#define kHeapHeaderPaddingSz (16U)
namespace NewOS {
STATIC SizeT kHeapCount = 0UL;
@@ -24,11 +25,12 @@ namespace Detail {
/// Located before the address bytes.
/// | HIB | ADDRESS |
struct PACKED HeapInformationBlock final {
- UInt16 hMagic;
- Boolean hPresent;
- Int32 hCRC32;
- Int64 hSizeAddress;
- UIntPtr hAddress;
+ UInt32 hMagic;
+ Boolean hPresent;
+ UInt32 hCRC32;
+ SizeT hSizeAddress;
+ UIntPtr hTargetAddress;
+ UInt8 hPadding[kHeapHeaderPaddingSz];
};
typedef HeapInformationBlock *HeapInformationBlockPtr;
@@ -51,7 +53,7 @@ VoidPtr ke_new_ke_heap(SizeT sz, const bool rw, const bool user) {
heapInfo->hSizeAddress = sz;
heapInfo->hMagic = kHeapMagic;
heapInfo->hCRC32 = 0; // dont fill it for now.
- heapInfo->hAddress = wrapper.VirtualAddress();
+ heapInfo->hTargetAddress = wrapper.VirtualAddress();
++kHeapCount;
@@ -70,11 +72,13 @@ Int32 ke_delete_ke_heap(VoidPtr heapPtr) {
(UIntPtr)heapPtr - sizeof(Detail::HeapInformationBlock));
if (virtualAddress && virtualAddress->hMagic == kHeapMagic) {
- MUST_PASS(virtualAddress->hPresent);
+ if (!virtualAddress->hPresent) {
+ return -kErrorHeapNotPresent;
+ }
if (virtualAddress->hCRC32 != 0) {
if (virtualAddress->hCRC32 !=
- ke_calculate_crc32((Char *)virtualAddress->hAddress,
+ ke_calculate_crc32((Char *)virtualAddress->hTargetAddress,
virtualAddress->hSizeAddress)) {
ke_stop(RUNTIME_CHECK_POINTER);
}
@@ -82,7 +86,7 @@ Int32 ke_delete_ke_heap(VoidPtr heapPtr) {
virtualAddress->hSizeAddress = 0UL;
virtualAddress->hPresent = false;
- virtualAddress->hAddress = 0;
+ virtualAddress->hTargetAddress = 0;
virtualAddress->hCRC32 = 0;
virtualAddress->hMagic = 0;
diff --git a/Private/Source/PEFCodeManager.cxx b/Private/Source/PEFCodeManager.cxx
index 0ac703a3..ed247963 100644
--- a/Private/Source/PEFCodeManager.cxx
+++ b/Private/Source/PEFCodeManager.cxx
@@ -30,6 +30,8 @@ UInt32 rt_get_pef_platform(void) noexcept {
}
} // namespace Detail
+/// @brief PEF loader constructor w/ blob.
+/// @param blob
PEFLoader::PEFLoader(const VoidPtr blob) : fCachedBlob(nullptr) {
fCachedBlob = blob;
fBad = false;
@@ -37,6 +39,8 @@ PEFLoader::PEFLoader(const VoidPtr blob) : fCachedBlob(nullptr) {
MUST_PASS(fCachedBlob);
}
+/// @brief PEF loader constructor.
+/// @param path
PEFLoader::PEFLoader(const char *path) : fCachedBlob(nullptr), fBad(false) {
OwnPtr<FileStream<char>> file;
@@ -73,6 +77,7 @@ PEFLoader::PEFLoader(const char *path) : fCachedBlob(nullptr), fBad(false) {
}
}
+/// @brief PEF destructor.
PEFLoader::~PEFLoader() {
if (fCachedBlob) ke_delete_ke_heap(fCachedBlob);
}
@@ -89,11 +94,11 @@ VoidPtr PEFLoader::FindSymbol(const char *name, Int32 kind) {
switch (kind) {
case kPefCode: {
- errOrSym = StringBuilder::Construct(".text$");
+ errOrSym = StringBuilder::Construct(".code64$");
break;
}
case kPefData: {
- errOrSym = StringBuilder::Construct(".data$");
+ errOrSym = StringBuilder::Construct(".data64$");
break;
}
case kPefZero: {
@@ -126,6 +131,8 @@ VoidPtr PEFLoader::FindSymbol(const char *name, Int32 kind) {
return nullptr;
}
+/// @brief Finds the executable entrypoint.
+/// @return
ErrorOr<VoidPtr> PEFLoader::FindStart() {
if (auto sym = this->FindSymbol(kPefStart, kPefCode); sym)
return ErrorOr<VoidPtr>(sym);
@@ -133,8 +140,12 @@ ErrorOr<VoidPtr> PEFLoader::FindStart() {
return ErrorOr<VoidPtr>(H_EXEC_ERROR);
}
+/// @brief Tells if the executable is loaded or not.
+/// @return
bool PEFLoader::IsLoaded() noexcept { return !fBad && fCachedBlob; }
+#define kPefAppnameCommandHdr "PefAppName"
+
namespace Utils {
bool execute_from_image(PEFLoader &exec) noexcept {
auto errOrStart = exec.FindStart();
@@ -144,6 +155,9 @@ bool execute_from_image(PEFLoader &exec) noexcept {
ProcessHeader proc(errOrStart.Leak().Leak());
Ref<ProcessHeader> refProc = proc;
+ proc.Kind = ProcessHeader::kUserKind;
+ rt_copy_memory(exec.FindSymbol(kPefAppnameCommandHdr, kPefData), proc.Name, rt_string_len((const Char*)exec.FindSymbol(kPefAppnameCommandHdr, kPefData)));
+
return ProcessScheduler::Shared().Leak().Add(refProc);
}
} // namespace Utils
diff --git a/Private/Source/ProcessScheduler.cxx b/Private/Source/ProcessScheduler.cxx
index c29b4c89..88e0e074 100644
--- a/Private/Source/ProcessScheduler.cxx
+++ b/Private/Source/ProcessScheduler.cxx
@@ -146,6 +146,7 @@ void ProcessHeader::Exit(Int32 exit_code) {
SizeT ProcessScheduler::Add(Ref<ProcessHeader> &process) {
if (!process) return -1;
+ if (!mTeam.AsArray().Count() > kSchedProcessLimitPerTeam) return -kErrorOutOfTeamSlot;
if (process.Leak().Ring != (Int32)ProcessSelector::kRingKernel) return -1;
@@ -237,7 +238,7 @@ bool ProcessHelper::CanBeScheduled(Ref<ProcessHeader> &process) {
return false;
if (process.Leak().GetStatus() == ProcessStatus::kStarting) {
- if (process.Leak().PTime < static_cast<Int>(kMinMicroTime)) {
+ if (process.Leak().PTime < static_cast<Int>(kSchedMinMicroTime)) {
process.Leak().Status = ProcessStatus::kRunning;
process.Leak().Affinity = AffinityKind::kHartStandard;
@@ -247,7 +248,7 @@ bool ProcessHelper::CanBeScheduled(Ref<ProcessHeader> &process) {
++process.Leak().PTime;
}
- return process.Leak().PTime > static_cast<Int>(kMinMicroTime);
+ return process.Leak().PTime > static_cast<Int>(kSchedMinMicroTime);
}
/**
diff --git a/Private/Source/RuntimeMain.cxx b/Private/Source/RuntimeMain.cxx
index 3ae1d428..5bbee3b2 100644
--- a/Private/Source/RuntimeMain.cxx
+++ b/Private/Source/RuntimeMain.cxx
@@ -25,6 +25,8 @@ EXTERN_C void RuntimeMain(void) {
NewOS::FilesystemManagerInterface::Mount(newFS);
+ while (NewOS::ProcessScheduler::Shared().Leak().Run() > 0);
+
///! we're done, unmount.
delete newFS;
} \ No newline at end of file
diff --git a/Private/Source/UserHeap.cxx b/Private/Source/UserHeap.cxx
index dbec5728..1747b3fa 100644
--- a/Private/Source/UserHeap.cxx
+++ b/Private/Source/UserHeap.cxx
@@ -8,7 +8,7 @@
#include <KernelKit/UserHeap.hpp>
#include <KernelKit/ProcessScheduler.hpp>
-#define kHeapHeaderPaddingSz 16
+#define kHeapHeaderPaddingSz (16U)
/// @file UserHeap.cxx
/// @brief User Heap Manager, Process heap allocator.
@@ -38,7 +38,7 @@ class HeapManager final {
STATIC SizeT& Count() { return s_NumPools; }
STATIC Ref<Pmm>& Leak() { return s_Pmm; }
STATIC Boolean& IsEnabled() { return s_PoolsAreEnabled; }
- STATIC Array<Ref<PTEWrapper>, kUserHeapMaxSz>& The() { return s_Pool; }
+ STATIC MutableArray<Ref<PTEWrapper>>& The() { return s_Pool; }
private:
STATIC Size s_NumPools;
@@ -46,7 +46,7 @@ class HeapManager final {
private:
STATIC Boolean s_PoolsAreEnabled;
- STATIC Array<Ref<PTEWrapper>, kUserHeapMaxSz> s_Pool;
+ STATIC MutableArray<Ref<PTEWrapper>> s_Pool;
};
//! declare fields
@@ -54,7 +54,7 @@ class HeapManager final {
SizeT HeapManager::s_NumPools = 0UL;
Ref<Pmm> HeapManager::s_Pmm;
Boolean HeapManager::s_PoolsAreEnabled = true;
-Array<Ref<PTEWrapper>, kUserHeapMaxSz> HeapManager::s_Pool;
+MutableArray<Ref<PTEWrapper>> HeapManager::s_Pool;
STATIC VoidPtr ke_find_unused_heap(Int flags);
STATIC Void ke_free_heap_internal(VoidPtr vaddr);
@@ -67,7 +67,7 @@ STATIC Boolean ke_check_and_free_heap(const SizeT& index, VoidPtr ptr);
STATIC VoidPtr ke_find_unused_heap(Int flags) {
for (SizeT index = 0; index < kUserHeapMaxSz; ++index) {
if (HeapManager::The()[index] &&
- !HeapManager::The()[index].Leak().Leak().Leak().Present()) {
+ !HeapManager::The()[index].Leak().Leak().Present()) {
HeapManager::Leak().Leak().TogglePresent(
HeapManager::The()[index].Leak().Leak(), true);
kcout << "[ke_find_unused_heap] Done, trying to make a pool now...\r\n";
@@ -75,7 +75,6 @@ STATIC VoidPtr ke_find_unused_heap(Int flags) {
return ke_make_heap((VoidPtr)HeapManager::The()[index]
.Leak()
.Leak()
- .Leak()
.VirtualAddress(),
flags);
}
@@ -143,7 +142,7 @@ STATIC Boolean ke_check_and_free_heap(const SizeT& index, VoidPtr ptr) {
// ErrorOr<>::operator Boolean
/// if (address matches)
/// -> Free heap.
- if (HeapManager::The()[index].Leak().Leak().Leak().VirtualAddress() ==
+ if (HeapManager::The()[index].Leak().Leak().VirtualAddress() ==
(UIntPtr)ptr) {
HeapManager::Leak().Leak().FreePage(
HeapManager::The()[index].Leak().Leak());