summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--dev/ZBAKit/Modules/NetBoot/build.json2
-rw-r--r--dev/ZBAKit/Modules/SysChk/build.json2
-rw-r--r--dev/ZKAKit/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc5
-rw-r--r--dev/ZKAKit/HALKit/AMD64/HalDescriptorLoader.cc2
-rw-r--r--dev/ZKAKit/HALKit/AMD64/HalKernelMain.cc14
-rw-r--r--dev/ZKAKit/HALKit/AMD64/HalPagingMgrAMD64.cc28
-rw-r--r--dev/ZKAKit/HALKit/ARM64/HalKernelMain.cc2
-rw-r--r--dev/ZKAKit/HALKit/ARM64/HalPagingMgrARM64.cc (renamed from dev/ZKAKit/HALKit/ARM64/HalPagingMgr.cc)0
-rw-r--r--dev/ZKAKit/NewKit/Array.h10
-rw-r--r--dev/ZKAKit/src/Heap.cc58
-rw-r--r--dev/ZKAKit/src/UserProcessScheduler.cc24
-rw-r--r--zka-dev.files2
12 files changed, 75 insertions, 74 deletions
diff --git a/dev/ZBAKit/Modules/NetBoot/build.json b/dev/ZBAKit/Modules/NetBoot/build.json
index dfa39ac5..0f86ed86 100644
--- a/dev/ZBAKit/Modules/NetBoot/build.json
+++ b/dev/ZBAKit/Modules/NetBoot/build.json
@@ -1,7 +1,7 @@
{
"compiler_path": "x86_64-w64-mingw32-g++",
"compiler_std": "c++20",
- "headers_path": ["../", "../../", "../../../zka", "../../../", "./"],
+ "headers_path": ["../", "../../", "../../../ZKAKit", "../../../", "./"],
"sources_path": [".cc", "*.S"],
"output_name": "netboot.sys",
"compiler_flags": [
diff --git a/dev/ZBAKit/Modules/SysChk/build.json b/dev/ZBAKit/Modules/SysChk/build.json
index 299b0acf..524fc0ff 100644
--- a/dev/ZBAKit/Modules/SysChk/build.json
+++ b/dev/ZBAKit/Modules/SysChk/build.json
@@ -1,7 +1,7 @@
{
"compiler_path": "x86_64-w64-mingw32-g++",
"compiler_std": "c++20",
- "headers_path": ["../", "../../", "../../../zka", "../../../", "./"],
+ "headers_path": ["../", "../../", "../../../ZKAKit", "../../../", "./"],
"sources_path": ["*.cc", "*.S"],
"output_name": "syschk.sys",
"compiler_flags": [
diff --git a/dev/ZKAKit/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc b/dev/ZKAKit/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc
index cb323ed8..ded862dd 100644
--- a/dev/ZKAKit/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc
+++ b/dev/ZKAKit/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc
@@ -8,11 +8,6 @@
#include <KernelKit/UserProcessScheduler.h>
#include <NewKit/KString.h>
-namespace Kernel
-{
- EXTERN UserProcessScheduler* kProcessScheduler;
-}
-
/// @brief Handle GPF fault.
/// @param rsp
EXTERN_C void idt_handle_gpf(Kernel::UIntPtr rsp)
diff --git a/dev/ZKAKit/HALKit/AMD64/HalDescriptorLoader.cc b/dev/ZKAKit/HALKit/AMD64/HalDescriptorLoader.cc
index b04fb0b0..f28d23a5 100644
--- a/dev/ZKAKit/HALKit/AMD64/HalDescriptorLoader.cc
+++ b/dev/ZKAKit/HALKit/AMD64/HalDescriptorLoader.cc
@@ -7,7 +7,7 @@
#include <ArchKit/ArchKit.h>
#include <HALKit/AMD64/Processor.h>
-#define kPITDefaultTicks (1000U)
+#define kPITDefaultTicks (100U)
namespace Kernel::HAL
{
diff --git a/dev/ZKAKit/HALKit/AMD64/HalKernelMain.cc b/dev/ZKAKit/HALKit/AMD64/HalKernelMain.cc
index 58b7acbf..14cf4dae 100644
--- a/dev/ZKAKit/HALKit/AMD64/HalKernelMain.cc
+++ b/dev/ZKAKit/HALKit/AMD64/HalKernelMain.cc
@@ -17,6 +17,18 @@ EXTERN_C Kernel::VoidPtr kInterruptVectorTable[];
EXTERN_C Kernel::VoidPtr mp_user_switch_proc;
EXTERN_C Kernel::Char mp_user_switch_proc_stack_begin[];
+EXTERN_C Kernel::MainKind __CTOR_LIST__[];
+EXTERN_C Kernel::MainKind __DTOR_LIST__[];
+
+STATIC Kernel::Void hal_init_cxx_ctors()
+{
+ for (Kernel::SizeT index = 0UL; __CTOR_LIST__[index] != __DTOR_LIST__[0]; ++index)
+ {
+ Kernel::MainKind ctor = (Kernel::MainKind)__CTOR_LIST__[index];
+ ctor();
+ }
+}
+
/// @brief Kernel init procedure.
EXTERN_C void hal_init_platform(
Kernel::HEL::HANDOVER_INFO_HEADER* HandoverHeader)
@@ -29,6 +41,8 @@ EXTERN_C void hal_init_platform(
return;
}
+ hal_init_cxx_ctors();
+
/************************************** */
/* INITIALIZE BIT MAP. */
/************************************** */
diff --git a/dev/ZKAKit/HALKit/AMD64/HalPagingMgrAMD64.cc b/dev/ZKAKit/HALKit/AMD64/HalPagingMgrAMD64.cc
index a94fe442..53553a13 100644
--- a/dev/ZKAKit/HALKit/AMD64/HalPagingMgrAMD64.cc
+++ b/dev/ZKAKit/HALKit/AMD64/HalPagingMgrAMD64.cc
@@ -14,7 +14,9 @@ namespace Kernel::HAL
{
typedef UInt32 PageTableIndex;
+ /***********************************************************************************/
/// \brief Page store type.
+ /***********************************************************************************/
struct ZKA_PAGE_STORE final
{
struct
@@ -24,7 +26,7 @@ namespace Kernel::HAL
VoidPtr fVAddr{nullptr};
} fInternalStore;
- Bool fStoreOp{No}; // Store operation in progress.
+ Bool fStoreOp{No}; // Store operation is in progress.
bool IsValidPage(PTE* pte)
{
@@ -48,7 +50,10 @@ namespace Kernel::HAL
}
};
+ /***********************************************************************************/
/// \brief Retrieve the page status of a PTE.
+ /// \param pte Page Table Entry pointer.
+ /***********************************************************************************/
STATIC Void mmi_page_status(PTE* pte)
{
kcout << (pte->Present ? "Present" : "Not Present") << endl;
@@ -57,13 +62,15 @@ namespace Kernel::HAL
kcout << (pte->User ? "User" : "Not User") << endl;
}
- STATIC Int32 mmi_map_page_table_entry(VoidPtr virtual_address, UInt32 flags, PTE* pt_entry);
+ STATIC Int32 mmi_map_page_table_entry(VoidPtr virtual_address, UInt32 flags, ZKA_PTE* pt_entry, ZKA_PDE* pd_entry);
+ /***********************************************************************************/
/// @brief Maps or allocates a page from virtual_address.
/// @param virtual_address a valid virtual address.
/// @param phys_addr point to physical address.
/// @param flags the flags to put on the page.
/// @return Status code of page manipulation process.
+ /***********************************************************************************/
EXTERN_C Int32 mm_map_page(VoidPtr virtual_address, UInt32 flags)
{
if (!virtual_address ||
@@ -84,15 +91,12 @@ namespace Kernel::HAL
UInt64 pd_index = ((UIntPtr)virtual_address >> 21) & cPmlIndexMask;
UInt64 pt_index = ((UIntPtr)virtual_address >> 12) & cPmlIndexMask;
- while (page_store.fStoreOp)
- ;
-
page_store.fStoreOp = Yes;
if (page_store.fInternalStore.fVAddr == virtual_address)
{
page_store.fStoreOp = No;
- return mmi_map_page_table_entry(page_store.fInternalStore.fVAddr, flags, page_store.fInternalStore.fPte);
+ return mmi_map_page_table_entry(page_store.fInternalStore.fVAddr, flags, page_store.fInternalStore.fPte, page_store.fInternalStore.fPde);
}
const auto cPmlEntrySize = 8;
@@ -114,15 +118,19 @@ namespace Kernel::HAL
UInt64 pt_entry = (pt_base + pt_index * cPmlEntrySize);
// Lastly, grab the pte entry.
- ZKA_PDE* pte_struct = reinterpret_cast<ZKA_PDE*>(pt_base);
+ ZKA_PDE* pde_struct = reinterpret_cast<ZKA_PDE*>(pt_base);
- return mmi_map_page_table_entry(virtual_address, flags, pte_struct->fEntries[pt_entry]);
+ return mmi_map_page_table_entry(virtual_address, flags, pde_struct->fEntries[pt_entry], pde_struct);
}
+ /***********************************************************************************/
/// @brief Maps flags for a specific pte.
/// @internal Internal function.
- STATIC Int32 mmi_map_page_table_entry(VoidPtr virtual_address, UInt32 flags, PTE* pt_entry)
+ /***********************************************************************************/
+ STATIC Int32 mmi_map_page_table_entry(VoidPtr virtual_address, UInt32 flags, ZKA_PTE* pt_entry, ZKA_PDE* pd_entry)
{
+ if (!pt_entry) return -1;
+
pt_entry->Present = true;
if (flags & kMMFlagsWr)
@@ -148,7 +156,7 @@ namespace Kernel::HAL
// Update Internal store.
- page_store.fInternalStore.fPde = nullptr;
+ page_store.fInternalStore.fPde = pd_entry;
page_store.fInternalStore.fPte = pt_entry;
page_store.fInternalStore.fVAddr = virtual_address;
diff --git a/dev/ZKAKit/HALKit/ARM64/HalKernelMain.cc b/dev/ZKAKit/HALKit/ARM64/HalKernelMain.cc
index 6039791e..81e14bf6 100644
--- a/dev/ZKAKit/HALKit/ARM64/HalKernelMain.cc
+++ b/dev/ZKAKit/HALKit/ARM64/HalKernelMain.cc
@@ -46,7 +46,5 @@ EXTERN_C void hal_init_platform(
Kernel::NeFileSystemMgr::Mount(new Kernel::NeFileSystemMgr());
-
-
while (Yes);
}
diff --git a/dev/ZKAKit/HALKit/ARM64/HalPagingMgr.cc b/dev/ZKAKit/HALKit/ARM64/HalPagingMgrARM64.cc
index 5b262cf9..5b262cf9 100644
--- a/dev/ZKAKit/HALKit/ARM64/HalPagingMgr.cc
+++ b/dev/ZKAKit/HALKit/ARM64/HalPagingMgrARM64.cc
diff --git a/dev/ZKAKit/NewKit/Array.h b/dev/ZKAKit/NewKit/Array.h
index 9c143bdd..6caa5b2d 100644
--- a/dev/ZKAKit/NewKit/Array.h
+++ b/dev/ZKAKit/NewKit/Array.h
@@ -16,15 +16,7 @@ namespace Kernel
class Array final
{
public:
- explicit Array()
- {
- for (SizeT i = 0; i < N; i++)
- {
- if (!fArray[i])
- fArray[i] = T();
- }
- }
-
+ explicit Array() = default;
~Array() = default;
Array& operator=(const Array&) = default;
diff --git a/dev/ZKAKit/src/Heap.cc b/dev/ZKAKit/src/Heap.cc
index 15b532e8..01c35096 100644
--- a/dev/ZKAKit/src/Heap.cc
+++ b/dev/ZKAKit/src/Heap.cc
@@ -88,8 +88,6 @@ namespace Kernel
typedef HEAP_INFORMATION_BLOCK* HEAP_INFORMATION_BLOCK_PTR;
} // namespace Detail
- Detail::HEAP_INFORMATION_BLOCK_PTR kLatestAllocation = nullptr;
-
/// @brief Declare a new size for ptr_heap.
/// @param ptr_heap the pointer.
/// @return Newly allocated heap header.
@@ -141,7 +139,7 @@ namespace Kernel
auto result = reinterpret_cast<VoidPtr>(heap_info_ptr->fHeapPtr);
- kLatestAllocation = heap_info_ptr;
+ kcout << "Created Heap address: " << hex_number(reinterpret_cast<UIntPtr>(heap_info_ptr)) << endl;
return result;
}
@@ -154,14 +152,16 @@ namespace Kernel
if (Detail::mm_check_heap_address(heap_ptr) == No)
return -kErrorHeapNotPresent;
- Detail::HEAP_INFORMATION_BLOCK_PTR heap_blk =
+ Detail::HEAP_INFORMATION_BLOCK_PTR heap_info_ptr =
reinterpret_cast<Detail::HEAP_INFORMATION_BLOCK_PTR>(
(UIntPtr)heap_ptr - sizeof(Detail::HEAP_INFORMATION_BLOCK));
if (!heap_ptr)
return -kErrorHeapNotPresent;
- heap_blk->fPage = true;
+ heap_info_ptr->fPage = true;
+
+ kcout << "Created Page address: " << hex_number(reinterpret_cast<UIntPtr>(heap_info_ptr)) << endl;
return kErrorSuccess;
}
@@ -174,46 +174,46 @@ namespace Kernel
if (Detail::mm_check_heap_address(heap_ptr) == No)
return -kErrorHeapNotPresent;
- Detail::HEAP_INFORMATION_BLOCK_PTR heap_blk =
+ Detail::HEAP_INFORMATION_BLOCK_PTR heap_info_ptr =
reinterpret_cast<Detail::HEAP_INFORMATION_BLOCK_PTR>(
(UIntPtr)(heap_ptr) - sizeof(Detail::HEAP_INFORMATION_BLOCK));
- if (heap_blk && heap_blk->fMagic == kKernelHeapMagic)
+ if (heap_info_ptr && heap_info_ptr->fMagic == kKernelHeapMagic)
{
- if (!heap_blk->fPresent)
+ if (!heap_info_ptr->fPresent)
{
return -kErrorHeapNotPresent;
}
- if (heap_blk->fCRC32 != 0)
+ if (heap_info_ptr->fCRC32 != 0)
{
- if (heap_blk->fCRC32 !=
- ke_calculate_crc32((Char*)heap_blk->fHeapPtr,
- heap_blk->fHeapSize))
+ if (heap_info_ptr->fCRC32 !=
+ ke_calculate_crc32((Char*)heap_info_ptr->fHeapPtr,
+ heap_info_ptr->fHeapSize))
{
- if (!heap_blk->fUser)
+ if (!heap_info_ptr->fUser)
{
ke_stop(RUNTIME_CHECK_POINTER);
}
}
}
- heap_blk->fHeapSize = 0UL;
- heap_blk->fPresent = No;
- heap_blk->fHeapPtr = 0;
- heap_blk->fCRC32 = 0;
- heap_blk->fWr = No;
- heap_blk->fUser = No;
- heap_blk->fMagic = 0;
+ heap_info_ptr->fHeapSize = 0UL;
+ heap_info_ptr->fPresent = No;
+ heap_info_ptr->fHeapPtr = 0;
+ heap_info_ptr->fCRC32 = 0;
+ heap_info_ptr->fWr = No;
+ heap_info_ptr->fUser = No;
+ heap_info_ptr->fMagic = 0;
- PTEWrapper pageWrapper(No, No, No, reinterpret_cast<UIntPtr>(heap_blk) - sizeof(Detail::HEAP_INFORMATION_BLOCK));
+ PTEWrapper pageWrapper(No, No, No, reinterpret_cast<UIntPtr>(heap_info_ptr) - sizeof(Detail::HEAP_INFORMATION_BLOCK));
Ref<PTEWrapper> pteAddress{pageWrapper};
- kcout << "Freeing pointer address: " << hex_number(reinterpret_cast<UIntPtr>(heap_blk) - sizeof(Detail::HEAP_INFORMATION_BLOCK)) << endl;
-
PageMgr heap_mgr;
heap_mgr.Free(pteAddress);
+ kcout << "Freed Heap address: " << hex_number(reinterpret_cast<UIntPtr>(heap_info_ptr)) << endl;
+
return kErrorSuccess;
}
@@ -227,11 +227,11 @@ namespace Kernel
{
if (heap_ptr)
{
- Detail::HEAP_INFORMATION_BLOCK_PTR heap_blk =
+ Detail::HEAP_INFORMATION_BLOCK_PTR heap_info_ptr =
reinterpret_cast<Detail::HEAP_INFORMATION_BLOCK_PTR>(
(UIntPtr)(heap_ptr) - sizeof(Detail::HEAP_INFORMATION_BLOCK));
- if (heap_blk && heap_blk->fPresent && heap_blk->fMagic == kKernelHeapMagic)
+ if (heap_info_ptr && heap_info_ptr->fPresent && heap_info_ptr->fMagic == kKernelHeapMagic)
{
return Yes;
}
@@ -247,14 +247,14 @@ namespace Kernel
{
if (heap_ptr)
{
- Detail::HEAP_INFORMATION_BLOCK_PTR heap_blk =
+ Detail::HEAP_INFORMATION_BLOCK_PTR heap_info_ptr =
reinterpret_cast<Detail::HEAP_INFORMATION_BLOCK_PTR>(
(UIntPtr)heap_ptr - sizeof(Detail::HEAP_INFORMATION_BLOCK));
- if (heap_ptr && heap_blk->fPresent && kKernelHeapMagic == heap_blk->fMagic)
+ if (heap_ptr && heap_info_ptr->fPresent && kKernelHeapMagic == heap_info_ptr->fMagic)
{
- heap_blk->fCRC32 =
- ke_calculate_crc32((Char*)heap_blk->fHeapPtr, heap_blk->fHeapSize);
+ heap_info_ptr->fCRC32 =
+ ke_calculate_crc32((Char*)heap_info_ptr->fHeapPtr, heap_info_ptr->fHeapSize);
return Yes;
}
diff --git a/dev/ZKAKit/src/UserProcessScheduler.cc b/dev/ZKAKit/src/UserProcessScheduler.cc
index dfa04537..61f6ba7b 100644
--- a/dev/ZKAKit/src/UserProcessScheduler.cc
+++ b/dev/ZKAKit/src/UserProcessScheduler.cc
@@ -320,7 +320,7 @@ namespace Kernel
return -kErrorInvalidData;
#ifdef __ZKA_AMD64__
- process.VMRegister = reinterpret_cast<UIntPtr>(HAL::mm_alloc_bitmap(Yes, Yes, sizeof(PDE), Yes));
+ process.VMRegister = reinterpret_cast<UIntPtr>(mm_new_heap(sizeof(PDE), No, Yes));
#endif // __ZKA_AMD64__
process.StackFrame = reinterpret_cast<HAL::StackFramePtr>(mm_new_heap(sizeof(HAL::StackFrame), Yes, Yes));
@@ -339,16 +339,13 @@ namespace Kernel
if (!process.Image)
{
- if (process.Kind != UserProcess::kExectuableDLLKind)
- {
- process.Crash();
- return -kErrorProcessFault;
- }
+ process.Crash();
+ return -kErrorProcessFault;
}
// Get preferred stack size by app.
- const auto cMaxStackSize = process.StackSize;
- process.StackReserve = reinterpret_cast<UInt8*>(mm_new_heap(sizeof(UInt8) * cMaxStackSize, Yes, Yes));
+ const auto kMaxStackSize = process.StackSize;
+ process.StackReserve = reinterpret_cast<UInt8*>(mm_new_heap(sizeof(UInt8) * kMaxStackSize, Yes, Yes));
if (!process.StackReserve)
{
@@ -424,12 +421,14 @@ namespace Kernel
SizeT process_index = 0; //! we store this guy to tell the scheduler how many
//! things we have scheduled.
- if (mTeam.mProcessAmount < 1)
+ if (mTeam.mProcessAmount == 0)
{
kcout << "UserProcessScheduler::Run(): This team doesn't have any process!\r";
return 0;
}
+ kcout << "UserProcessScheduler::Run(): This team has process # " << number(mTeam.mProcessAmount) << endl;
+
for (; process_index < mTeam.AsArray().Capacity(); ++process_index)
{
auto& process = mTeam.AsArray()[process_index];
@@ -500,12 +499,7 @@ namespace Kernel
process.Status == ProcessStatusKind::kDead)
return No;
- if (process.Status == ProcessStatusKind::kStarting &&
- process.Image)
- return Yes;
-
- if (!process.Image &&
- process.Kind == UserProcess::kExectuableKind)
+ if (!process.Image)
return No;
return process.PTime < 1 && process.Status == ProcessStatusKind::kRunning;
diff --git a/zka-dev.files b/zka-dev.files
index 88bf2e46..09980727 100644
--- a/zka-dev.files
+++ b/zka-dev.files
@@ -152,7 +152,7 @@ dev/ZKAKit/HALKit/ARM64/HalCoreMPScheduler.cc
dev/ZKAKit/HALKit/ARM64/HalDebugOutput.cc
dev/ZKAKit/HALKit/ARM64/HalKernelMain.cc
dev/ZKAKit/HALKit/ARM64/HalPageInternal.S
-dev/ZKAKit/HALKit/ARM64/HalPagingMgr.cc
+dev/ZKAKit/HALKit/ARM64/HalPagingMgrARM64.cc
dev/ZKAKit/HALKit/ARM64/HalSchedulerCoreARM64.cc
dev/ZKAKit/HALKit/ARM64/HalTimer.cc
dev/ZKAKit/HALKit/ARM64/Paging.h