summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-06-24 21:58:41 +0200
committerAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-06-24 22:06:03 +0200
commita1362d5f0c53ba38a164223822e0ee543acbf3ac (patch)
tree474701d6a58f783a2bae4a4b503cf71bd8ed7c00
parentbc5c006f4262d7c7a6e92d2d1fccad9e7a295517 (diff)
IMP: Kernel init macro to jump into kernel procedure.
- New NAPI power management syscalls, shutdown; reboot. (no more is needed, handover that to hardware) Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
-rw-r--r--Comm/newstd.hxx8
-rw-r--r--Kernel/HALKit/AMD64/HalKernelMain.cxx69
2 files changed, 54 insertions, 23 deletions
diff --git a/Comm/newstd.hxx b/Comm/newstd.hxx
index 7362f8e9..8590176e 100644
--- a/Comm/newstd.hxx
+++ b/Comm/newstd.hxx
@@ -48,24 +48,24 @@ typedef __INT8_TYPE__ SInt8;
class NUser final
{
public:
- // THOSE REQUIRES PERMISSIONS FROM THE USER. ///
+ // THOSE REQUIRES PERMISSIONS FROM THE USER. //
static UInt0 Poweroff();
static UInt0 Reboot();
static Bool IsWokeup();
- // THOSE DOESNT REQUIRE PERMISSIONS FROM THE USER. ///
+ // THOSE DOESNT REQUIRE PERMISSIONS FROM THE USER. //
static UInt0 Terminate();
static Bool Exit(OSType code);
static UInt0* New(long long sz);
static UInt0 Delete(void* ptr);
- // ASK FOR ELEVATION ///
+ // ASK FOR ELEVATION //
static Bool RaiseUAC();
- // THOSE MAY REQUIRE PERMISSIONS FROM THE USER. ///
+ // THOSE MAY REQUIRE PERMISSIONS FROM THE USER. //
static OSType Open(const char* path);
static UInt0 Close(OSType fd);
diff --git a/Kernel/HALKit/AMD64/HalKernelMain.cxx b/Kernel/HALKit/AMD64/HalKernelMain.cxx
index 0381e4ab..a37a6e32 100644
--- a/Kernel/HALKit/AMD64/HalKernelMain.cxx
+++ b/Kernel/HALKit/AMD64/HalKernelMain.cxx
@@ -17,6 +17,11 @@
#include <Modules/CoreCG/Accessibility.hxx>
#include <KernelKit/CodeManager.hpp>
+#define KERNEL_INIT(X) X; \
+ NewOS::ke_stop(RUNTIME_CHECK_BOOTSTRAP);
+
+
+
/// @brief This symbol is the kernel main symbol.
EXTERN_C void KeMain();
@@ -45,11 +50,11 @@ struct PACKED ProcessExitInfo final
namespace NewOS::HAL
{
/// @brief Gets the system cores using the MADT.
- /// @param rsdPtr the RSD PTR.
+ /// @param rsdPtr The 'RSD PTR' data structure.
extern void hal_system_get_cores(NewOS::voidPtr rsdPtr);
} // namespace NewOS::HAL
-/* GDT constant. */
+/* GDT. */
STATIC NewOS::HAL::Detail::NewOSGDT cGdt = {
{0, 0, 0, 0x00, 0x00, 0}, // null entry
{0, 0, 0, 0x9a, 0xaf, 0}, // kernel code
@@ -78,32 +83,32 @@ EXTERN_C void hal_init_platform(
kKernelPhysicalStart = HandoverHeader->f_PhysicalStart;
+ // Load memory descriptors.
+
NewOS::HAL::RegisterGDT gdtBase;
gdtBase.Base = reinterpret_cast<NewOS::UIntPtr>(&cGdt);
gdtBase.Limit = sizeof(NewOS::HAL::Detail::NewOSGDT) - 1;
- NewOS::HAL::GDTLoader gdt;
- gdt.Load(gdtBase);
+ CONST NewOS::HAL::GDTLoader cGDT;
+ cGDT.Load(gdtBase);
- /// Load IDT.
+ // Load IDT now.
NewOS::HAL::Register64 idtBase;
idtBase.Base = (NewOS::UIntPtr)kInterruptVectorTable;
idtBase.Limit = 0;
- NewOS::HAL::IDTLoader idt;
- idt.Load(idtBase);
+ CONST NewOS::HAL::IDTLoader cIDT;
+ cIDT.Load(idtBase);
- /**
- register basic syscalls.
- */
+ // register the basic NAPI syscalls.
- constexpr auto cSerialAlertInterrupt = 0x10; // 16
- constexpr auto cTlsInterrupt = 0x11; // 17
- constexpr auto cTlsInstallInterrupt = 0x12; // 18
- constexpr auto cNewInterrupt = 0x13; // 19
- constexpr auto cDeleteInterrupt = 0x14; // 20
+ constexpr auto cSerialAlertInterrupt = 0x10;
+ constexpr auto cTlsInterrupt = 0x11;
+ constexpr auto cTlsInstallInterrupt = 0x12;
+ constexpr auto cNewInterrupt = 0x13;
+ constexpr auto cDeleteInterrupt = 0x14;
constexpr auto cExitInterrupt = 0x15;
constexpr auto cLastExitInterrupt = 0x16;
constexpr auto cCatalogOpen = 0x17;
@@ -112,10 +117,15 @@ EXTERN_C void hal_init_platform(
constexpr auto cCatalogClose = 0x20;
constexpr auto cCatalogRemove = 0x21;
constexpr auto cCatalogCreate = 0x22;
+ constexpr auto cRebootInterrupt = 0x23;
+ constexpr auto cShutdownInterrupt = 0x24;
+ constexpr auto cLPCSendMsg = 0x25;
+ constexpr auto cLPCOpenMsg = 0x26;
+ constexpr auto cLPCCloseMsg = 0x27;
kSyscalls[cSerialAlertInterrupt].Leak().Leak()->fProc = [](NewOS::VoidPtr rdx) -> void {
const char* msg = (const char*)rdx;
- NewOS::kcout << "newoskrnl: " << msg << "\r";
+ NewOS::kcout << "NAPI: " << msg << "\r";
};
kSyscalls[cTlsInterrupt].Leak().Leak()->fProc = [](NewOS::VoidPtr rdx) -> void {
@@ -125,6 +135,8 @@ EXTERN_C void hal_init_platform(
kSyscalls[cNewInterrupt].Leak().Leak()->fProc = [](NewOS::VoidPtr rdx) -> void {
/// get HAC struct.
HeapAllocInfo* rdxInf = reinterpret_cast<HeapAllocInfo*>(rdx);
+
+ if (!rdxInf) return;
/// assign the fThe field with the pointer.
rdxInf->fThe = NewOS::ProcessScheduler::The().Leak().TheCurrent().Leak().New(rdxInf->fTheSz);
@@ -134,12 +146,16 @@ EXTERN_C void hal_init_platform(
/// get HAC struct.
HeapAllocInfo* rdxInf = reinterpret_cast<HeapAllocInfo*>(rdx);
+ if (!rdxInf) return;
+
/// delete ptr with sz in mind.
NewOS::ProcessScheduler::The().Leak().TheCurrent().Leak().Delete(rdxInf->fThe, rdxInf->fTheSz);
};
kSyscalls[cTlsInstallInterrupt].Leak().Leak()->fProc = [](NewOS::VoidPtr rdx) -> void {
ProcessBlockInfo* rdxPb = reinterpret_cast<ProcessBlockInfo*>(rdx);
+
+ if (!rdxPb) return;
/// install the process's fTIB and fPIB.
rt_install_tib(rdxPb->fTIB, rdxPb->fPIB);
@@ -147,6 +163,8 @@ EXTERN_C void hal_init_platform(
kSyscalls[cExitInterrupt].Leak().Leak()->fProc = [](NewOS::VoidPtr rdx) -> void {
ProcessExitInfo* rdxEi = reinterpret_cast<ProcessExitInfo*>(rdx);
+
+ if (!rdxEi) return;
NewOS::kcout << "newoskrnl: " << rdxEi->fReason << "\r";
NewOS::ProcessScheduler::The().Leak().TheCurrent().Leak().Exit(rdxEi->fCode);
@@ -154,9 +172,22 @@ EXTERN_C void hal_init_platform(
kSyscalls[cLastExitInterrupt].Leak().Leak()->fProc = [](NewOS::VoidPtr rdx) -> void {
ProcessExitInfo* rdxEi = reinterpret_cast<ProcessExitInfo*>(rdx);
+
+ if (!rdxEi) return;
+
rdxEi->fCode = NewOS::rt_get_exit_code();
};
+ kSyscalls[cRebootInterrupt].Leak().Leak()->fProc = [](NewOS::VoidPtr rdx) -> void {
+ NewOS::ACPIFactoryInterface acpi;
+ acpi.Reboot();
+ };
+
+ kSyscalls[cShutdownInterrupt].Leak().Leak()->fProc = [](NewOS::VoidPtr rdx) -> void {
+ NewOS::ACPIFactoryInterface acpi;
+ acpi.Shutdown();
+ };
+
kSyscalls[cSerialAlertInterrupt].Leak().Leak()->fHooked = true;
kSyscalls[cTlsInterrupt].Leak().Leak()->fHooked = true;
kSyscalls[cTlsInstallInterrupt].Leak().Leak()->fHooked = true;
@@ -164,11 +195,11 @@ EXTERN_C void hal_init_platform(
kSyscalls[cNewInterrupt].Leak().Leak()->fHooked = true;
kSyscalls[cExitInterrupt].Leak().Leak()->fHooked = true;
kSyscalls[cLastExitInterrupt].Leak().Leak()->fHooked = true;
+ kSyscalls[cShutdownInterrupt].Leak().Leak()->fHooked = true;
+ kSyscalls[cRebootInterrupt].Leak().Leak()->fHooked = true;
NewOS::UIAccessibilty::The().Show("RCM", NewOS::UIAccessibilty::The().Width(), NewOS::UIAccessibilty::The().Height());
NewOS::HAL::hal_system_get_cores(kHandoverHeader->f_HardwareTables.f_RsdPtr);
- KeMain();
-
- NewOS::ke_stop(RUNTIME_CHECK_BOOTSTRAP);
+ KERNEL_INIT(KeMain());
}