summaryrefslogtreecommitdiffhomepage
path: root/dev
diff options
context:
space:
mode:
authorAmlal <amlal@nekernel.org>2025-08-17 08:16:29 +0200
committerAmlal <amlal@nekernel.org>2025-08-17 08:16:29 +0200
commit0fdc3eeb3afed04f9ffd36b4b2760dac61d1b098 (patch)
tree3e4887506ba7ce77fad55e59f7f643191d70cdf2 /dev
parentef8603be406c84f9bf8d777109d7c7a91e019139 (diff)
feat: kernel: (HALKit/KernelKit): Scheduler, and dylib improvements.
feat: ZXD: Define the ZXD format. TeX file for PEF and ZXD to be written soon. Signed-off-by: Amlal <amlal@nekernel.org>
Diffstat (limited to 'dev')
-rw-r--r--dev/kernel/HALKit/AMD64/HalSchedulerCorePrimitives.cc18
-rw-r--r--dev/kernel/HALKit/ARM64/HalSchedulerCorePrimitives.cc4
-rw-r--r--dev/kernel/KernelKit/IDylibObject.h2
-rw-r--r--dev/kernel/KernelKit/IPEFDylibObject.h14
-rw-r--r--dev/kernel/KernelKit/ZXD.h11
-rw-r--r--dev/kernel/src/ZXD.cc7
6 files changed, 34 insertions, 22 deletions
diff --git a/dev/kernel/HALKit/AMD64/HalSchedulerCorePrimitives.cc b/dev/kernel/HALKit/AMD64/HalSchedulerCorePrimitives.cc
index 1dbce4ac..c8f53aa9 100644
--- a/dev/kernel/HALKit/AMD64/HalSchedulerCorePrimitives.cc
+++ b/dev/kernel/HALKit/AMD64/HalSchedulerCorePrimitives.cc
@@ -13,7 +13,7 @@ namespace Kernel {
/// @param
/***********************************************************************************/
-EXTERN_C Void __zka_pure_call(USER_PROCESS* process) {
+EXTERN_C Void __ne_pure_call(USER_PROCESS* process) {
if (process) process->Crash();
}
@@ -25,23 +25,27 @@ EXTERN_C Void __zka_pure_call(USER_PROCESS* process) {
EXTERN_C Bool hal_check_task(HAL::StackFramePtr stack_ptr) {
if (!stack_ptr) return No;
- return stack_ptr->SP != 0 && stack_ptr->IP != 0;
+ return stack_ptr->SP > 0 && stack_ptr->IP > 0;
}
/// @brief Wakes up thread.
/// Wakes up thread from the hang state.
Void mp_wakeup_thread(HAL::StackFrame* stack) {
- NE_UNUSED(stack);
+ if (!hal_check_task(stack)) return;
+
+ // RIP is always in R15. R15 is reserved for the RIP.
+ stack->IP = stack->R15;
+
Kernel::UserProcessHelper::StartScheduling();
}
/// @brief makes the thread sleep on a loop.
/// hooks and hangs thread to prevent code from executing.
Void mp_hang_thread(HAL::StackFrame* stack) {
- NE_UNUSED(stack);
+ if (!hal_check_task(stack)) return;
- while (Yes) {
- /* Nothing to do, code is spinning */
- }
+ // Store IP in R15
+ stack->R15 = stack->IP;
+ stack->IP = 0UL;
}
} // namespace Kernel
diff --git a/dev/kernel/HALKit/ARM64/HalSchedulerCorePrimitives.cc b/dev/kernel/HALKit/ARM64/HalSchedulerCorePrimitives.cc
index 10f95e29..2d10fa89 100644
--- a/dev/kernel/HALKit/ARM64/HalSchedulerCorePrimitives.cc
+++ b/dev/kernel/HALKit/ARM64/HalSchedulerCorePrimitives.cc
@@ -10,10 +10,10 @@
namespace Kernel {
/***********************************************************************************/
/// @brief Unimplemented function (crashes by default)
-/// @param void
+/// @param process The process handle.
/***********************************************************************************/
-EXTERN_C Void __zka_pure_call(USER_PROCESS* process) {
+EXTERN_C Void __ne_pure_call(USER_PROCESS* process) {
if (process) process->Crash();
}
diff --git a/dev/kernel/KernelKit/IDylibObject.h b/dev/kernel/KernelKit/IDylibObject.h
index b673766c..3727e938 100644
--- a/dev/kernel/KernelKit/IDylibObject.h
+++ b/dev/kernel/KernelKit/IDylibObject.h
@@ -41,5 +41,5 @@ class IDylibObject {
};
/// @brief Pure implementation, missing method/function handler.
-EXTERN_C void __zka_pure_call(void);
+EXTERN_C void __ne_pure_call(void);
} // namespace Kernel
diff --git a/dev/kernel/KernelKit/IPEFDylibObject.h b/dev/kernel/KernelKit/IPEFDylibObject.h
index 66b4895d..5788138d 100644
--- a/dev/kernel/KernelKit/IPEFDylibObject.h
+++ b/dev/kernel/KernelKit/IPEFDylibObject.h
@@ -7,8 +7,8 @@
* ========================================================
*/
-#ifndef __KERNELKIT_SHARED_OBJECT_H__
-#define __KERNELKIT_SHARED_OBJECT_H__
+#ifndef __KERNELKIT_PEF_SHARED_OBJECT_H__
+#define __KERNELKIT_PEF_SHARED_OBJECT_H__
#include <KernelKit/IDylibObject.h>
#include <KernelKit/PEF.h>
@@ -38,7 +38,7 @@ class IPEFDylibObject final NE_DYLIB_OBJECT {
DylibTraits* Get() { return fMounted; }
public:
- void Mount(DylibTraits* to_mount) {
+ void Mount(DylibTraits* to_mount) noexcept {
if (!to_mount || !to_mount->ImageObject) return;
fMounted = to_mount;
@@ -53,19 +53,19 @@ class IPEFDylibObject final NE_DYLIB_OBJECT {
}
}
- void Unmount() {
+ void Unmount() noexcept {
if (fMounted) fMounted = nullptr;
};
template <typename SymbolType>
- SymbolType Load(const Char* symbol_name, SizeT len, Int32 kind) {
+ SymbolType Load(const Char* symbol_name, const SizeT& len, const UInt32& kind) {
if (symbol_name == nullptr || *symbol_name == 0) return nullptr;
if (len > kPathLen || len < 1) return nullptr;
auto ret = reinterpret_cast<SymbolType>(fLoader->FindSymbol(symbol_name, kind).Leak().Leak());
if (!ret) {
- if (kind == kPefCode) return (VoidPtr) &__zka_pure_call;
+ if (kind == kPefCode) return (VoidPtr) &__ne_pure_call;
return nullptr;
}
@@ -83,4 +83,4 @@ EXTERN_C IDylibRef rtl_init_dylib_pef(USER_PROCESS& header);
EXTERN_C Void rtl_fini_dylib_pef(USER_PROCESS& header, IDylibRef lib, Bool* successful);
} // namespace Kernel
-#endif /* ifndef __KERNELKIT_SHARED_OBJECT_H__ */
+#endif /* ifndef __KERNELKIT_PEF_SHARED_OBJECT_H__ */
diff --git a/dev/kernel/KernelKit/ZXD.h b/dev/kernel/KernelKit/ZXD.h
index 10af568b..f1c99a21 100644
--- a/dev/kernel/KernelKit/ZXD.h
+++ b/dev/kernel/KernelKit/ZXD.h
@@ -8,15 +8,16 @@
#include <NeKit/Defines.h>
-namespace ZXD {
-using namespace Kernel;
+#define kZXDMagicNumber (0x2010AF)
+#define kZXDVersion (0x0001)
+namespace Kernel {
struct ZXD_EXEC_HEADER;
struct ZXD_STUB_HEADER;
/// @brief ZXD executable header
/// @details This header is used to identify ZXD executable files.
-struct ZXD_EXEC_HEADER {
+struct PACKED ZXD_EXEC_HEADER {
UInt32 fMagic;
UInt32 fVersion;
UInt32 fFlags;
@@ -35,9 +36,9 @@ struct ZXD_EXEC_HEADER {
/// @brief ZXD stub header
/// @details This header is used to identify ZXD stub files. It contains the size of the stub, the
/// offset of the stub, and the CRC32 checksum of the stub.
-struct ZXD_STUB_HEADER {
+struct PACKED ZXD_STUB_HEADER {
UInt32 fStubSize;
UInt32 fStubOffset;
UInt32 fStubCRC32;
};
-} // namespace ZXD \ No newline at end of file
+} // namespace Kernel
diff --git a/dev/kernel/src/ZXD.cc b/dev/kernel/src/ZXD.cc
new file mode 100644
index 00000000..8ca6bbf7
--- /dev/null
+++ b/dev/kernel/src/ZXD.cc
@@ -0,0 +1,7 @@
+/* -------------------------------------------
+
+ Copyright (C) 2025, Amlal El Mahrouss, all rights reserved.
+
+------------------------------------------- */
+
+#include <KernelKit/ZXD.h>