summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--dev/ZBA/Sources/HEL/AMD64/BootAPI.S9
-rw-r--r--dev/ZBA/Sources/HEL/AMD64/BootMain.cxx21
-rw-r--r--dev/ZKA/FirmwareKit/Handover.hxx5
-rw-r--r--dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx3
-rw-r--r--dev/ZKA/HALKit/AMD64/HalCommAPI.cxx13
-rw-r--r--dev/ZKA/HALKit/AMD64/HalKernelMain.cxx47
-rw-r--r--dev/ZKA/HALKit/AMD64/Paging.hxx12
-rw-r--r--dev/ZKA/HALKit/AMD64/Processor.hxx2
-rw-r--r--dev/ZKA/HALKit/ARM64/HalKernelMain.cxx53
-rw-r--r--dev/ZKA/amd64-efi.make2
10 files changed, 41 insertions, 126 deletions
diff --git a/dev/ZBA/Sources/HEL/AMD64/BootAPI.S b/dev/ZBA/Sources/HEL/AMD64/BootAPI.S
index 9db0961a..47f250f1 100644
--- a/dev/ZBA/Sources/HEL/AMD64/BootAPI.S
+++ b/dev/ZBA/Sources/HEL/AMD64/BootAPI.S
@@ -40,8 +40,13 @@ wait_gate2:
reset_wait:
jmp reset_wait
-.global write_cr3
+.global boot_write_cr3
+.global boot_read_cr3
-write_cr3:
+boot_read_cr3:
+ mov rax, rax
+ ret
+
+boot_write_cr3:
mov cr3, rcx
ret
diff --git a/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx b/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx
index 2e20c5d3..55d93c29 100644
--- a/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx
+++ b/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx
@@ -79,7 +79,10 @@ STATIC Bool CheckBootDevice(BootDeviceATA& ataDev)
return true;
}
-EXTERN_C Void write_cr3(VoidPtr new_cr3);
+EXTERN_C VoidPtr boot_read_cr3();
+EXTERN_C Void boot_write_cr3(VoidPtr new_cr3);
+
+EXTERN EfiBootServices* BS;
/// @brief Main EFI entrypoint.
/// @param ImageHandle Handle of this image.
@@ -135,8 +138,6 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
auto guid_mp = EfiGUID(EFI_MP_SERVICES_PROTOCOL_GUID);
EfiMpServicesProtocol* mp = nullptr;
- EXTERN EfiBootServices* BS;
-
BS->LocateProtocol(&guid_mp, nullptr, reinterpret_cast<VoidPtr*>(&mp));
handover_hdr->f_HardwareTables.f_MpPtr = reinterpret_cast<VoidPtr>(mp);
@@ -203,19 +204,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
// Update handover file specific table and phyiscal start field.
//-----------------------------------------------------------//
- handover_hdr->f_PageStart =
- (VoidPtr)Descriptor[cDefaultMemoryMap].PhysicalStart;
-
- handover_hdr->f_FirmwareSpecific[HEL::kHandoverSpecificAttrib] =
- Descriptor[cDefaultMemoryMap].Attribute;
- handover_hdr->f_FirmwareSpecific[HEL::kHandoverSpecificKind] =
- Descriptor[cDefaultMemoryMap].Kind;
- handover_hdr->f_FirmwareSpecific[HEL::kHandoverSpecificMemoryEfi] =
- (UIntPtr)Descriptor;
-
- handover_hdr->f_BitMapStart =
- (VoidPtr)Descriptor[cDefaultMemoryMap].VirtualStart;
-
+ handover_hdr->f_BitMapStart = reinterpret_cast<VoidPtr>(kHandoverBitMapStart); /* # of pages */
handover_hdr->f_BitMapSize = kHandoverBitMapSz; /* # of pages */
handover_hdr->f_FirmwareCustomTables[0] = (VoidPtr)BS;
diff --git a/dev/ZKA/FirmwareKit/Handover.hxx b/dev/ZKA/FirmwareKit/Handover.hxx
index a89cfa1e..8e021754 100644
--- a/dev/ZKA/FirmwareKit/Handover.hxx
+++ b/dev/ZKA/FirmwareKit/Handover.hxx
@@ -22,10 +22,11 @@
/* Handover macros. */
#define kHandoverMagic 0xBADCC
-#define kHandoverVersion 0x0116
+#define kHandoverVersion 0x0117
/* Initial bitmap size. */
-#define kHandoverBitMapSz gib_cast(3)
+#define kHandoverBitMapStart 0x100000000
+#define kHandoverBitMapSz gib_cast(4)
#define kHandoverStructSz sizeof(HEL::HANDOVER_INFO_HEADER)
namespace Kernel::HEL
diff --git a/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx b/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx
index 22f93cba..1d7d37c0 100644
--- a/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx
+++ b/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx
@@ -107,6 +107,9 @@ namespace Kernel
}
base_ptr = reinterpret_cast<VoidPtr>(reinterpret_cast<UIntPtr>(base_ptr) + (ptr_bit_set[0] != cBitMpMagic ? size : ptr_bit_set[1]));
+
+ if ((UIntPtr)base_ptr < (base + kHandoverHeader->f_BitMapSize))
+ return nullptr;
}
return nullptr;
diff --git a/dev/ZKA/HALKit/AMD64/HalCommAPI.cxx b/dev/ZKA/HALKit/AMD64/HalCommAPI.cxx
index ff313f47..087090b0 100644
--- a/dev/ZKA/HALKit/AMD64/HalCommAPI.cxx
+++ b/dev/ZKA/HALKit/AMD64/HalCommAPI.cxx
@@ -7,18 +7,14 @@
------------------------------------------- */
+#include <HALKit/AMD64/Paging.hxx>
#include <HALKit/AMD64/Processor.hxx>
/**
- * @file HalProcessorMgr.cxx
- * @brief CPU Processor managers.
+ * @file HalCommAPI.cxx
+ * @brief CPU Processor common API.
*/
-#define cPageSz kPageSize // 4KB pages
-#define cTotalPgMem gib_cast(16) // 16MB total memory
-#define cTotalPages (cTotalPgMem / cPageSz) // Total number of pages
-#define cBmpPgSz (cTotalPages / 8) // 1 bit per page in the bitmap
-
namespace Kernel::HAL
{
/// @brief Maps or allocates a page from virt_addr.
@@ -28,6 +24,9 @@ namespace Kernel::HAL
/// @return Status code of page manip.
EXTERN_C Int32 mm_map_page(VoidPtr virt_addr, UInt32 flags)
{
+ ZKA_UNUSED(virt_addr);
+ ZKA_UNUSED(flags);
+
return 0;
}
diff --git a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx
index fd2ca470..df3986a1 100644
--- a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx
+++ b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx
@@ -21,32 +21,6 @@
#include <Modules/CoreCG/TextRenderer.hxx>
#include <Modules/CoreCG/WindowRenderer.hxx>
-struct HEAP_ALLOC_INFO final
-{
- Kernel::VoidPtr fThe;
- Kernel::Size fTheSz;
-};
-
-struct CREATE_THREAD_INFO final
-{
- Kernel::MainKind fMain;
- Kernel::Char fName[kPefNameLen];
-};
-
-struct PROCESS_BLOCK_INFO final
-{
- THREAD_INFORMATION_BLOCK* fTIB;
- THREAD_INFORMATION_BLOCK* fGIB;
-};
-
-struct PROCESS_EXIT_INFO final
-{
- STATIC constexpr auto cReasonLen = 512;
-
- Kernel::Int64 fCode;
- Kernel::Char fReason[cReasonLen];
-};
-
namespace Kernel::HAL
{
/// @brief Gets the system cores using the MADT.
@@ -54,13 +28,7 @@ namespace Kernel::HAL
EXTERN void mp_get_cores(Kernel::voidPtr rsdPtr) noexcept;
} // namespace Kernel::HAL
-EXTERN_C Kernel::UInt8* mp_user_switch_proc;
-EXTERN_C Kernel::UInt8* mp_user_switch_proc_stack_end;
-EXTERN_C Kernel::VoidPtr mp_user_switch_proc_real;
-
EXTERN_C Kernel::VoidPtr kInterruptVectorTable[];
-EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept;
-EXTERN_C Kernel::Void ke_dll_entrypoint(Kernel::Void);
/// @brief Kernel init procedure.
EXTERN_C void hal_init_platform(
@@ -68,14 +36,14 @@ EXTERN_C void hal_init_platform(
{
kHandoverHeader = HandoverHeader;
- Kernel::HAL::mm_map_page(kHandoverHeader->f_PageStart, Kernel::HAL::eFlagsRw | Kernel::HAL::eFlagsPresent);
-
if (kHandoverHeader->f_Magic != kHandoverMagic &&
kHandoverHeader->f_Version != kHandoverVersion)
{
return;
}
+ CG::CGDrawBackground();
+
// get page size.
kKernelBitMpSize = kHandoverHeader->f_BitMapSize;
@@ -83,10 +51,6 @@ EXTERN_C void hal_init_platform(
kKernelBitMpStart = reinterpret_cast<Kernel::VoidPtr>(
reinterpret_cast<Kernel::UIntPtr>(kHandoverHeader->f_BitMapStart));
- // get physical address start.
- kKernelPageStart = reinterpret_cast<Kernel::VoidPtr>(
- reinterpret_cast<Kernel::UIntPtr>(kHandoverHeader->f_PageStart));
-
STATIC CONST auto cEntriesCount = 6;
/* GDT, mostly descriptors for user and kernel segments. */
@@ -104,11 +68,10 @@ EXTERN_C void hal_init_platform(
gdtBase.Base = reinterpret_cast<Kernel::UIntPtr>(cGdt);
gdtBase.Limit = (sizeof(Kernel::HAL::Detail::ZKA_GDT_ENTRY) * cEntriesCount) - 1;
+ //! GDT will load hal_read_init after it successfully loads the segments.
CONST Kernel::HAL::GDTLoader cGDT;
cGDT.Load(gdtBase);
- // Load IDT now.
-
Kernel::ke_stop(RUNTIME_CHECK_BOOTSTRAP);
}
@@ -125,10 +88,6 @@ EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept
Kernel::NeFileSystemMgr::Mount(Kernel::mm_new_class<Kernel::NeFileSystemMgr>());
- CG::CGDrawBackground();
-
- Kernel::HAL::mm_map_page(mp_user_switch_proc, Kernel::HAL::eFlagsRw | Kernel::HAL::eFlagsUser | Kernel::HAL::eFlagsPresent);
-
mp_do_user_switch();
Kernel::ke_stop(RUNTIME_CHECK_BOOTSTRAP);
diff --git a/dev/ZKA/HALKit/AMD64/Paging.hxx b/dev/ZKA/HALKit/AMD64/Paging.hxx
index 23ac68e1..a4744631 100644
--- a/dev/ZKA/HALKit/AMD64/Paging.hxx
+++ b/dev/ZKA/HALKit/AMD64/Paging.hxx
@@ -19,7 +19,7 @@
#endif //! kPageMax
#ifndef kPageAlign
-#define kPageAlign (0x1000)
+#define kPageAlign (0x08)
#endif //! kPageAlign
#ifndef kPageSize
@@ -41,7 +41,6 @@ EXTERN_C Kernel::VoidPtr hal_read_cr3(); // @brief Page table.
namespace Kernel::HAL
{
-
struct PACKED ZKA_PTE_GENERIC
{
Bool Present : 1;
@@ -100,9 +99,14 @@ namespace Kernel::HAL
}
} // namespace Detail
- struct ALIGN(0x08) ZKA_PDE final
+ struct ZKA_PDE final
+ {
+ ZKA_PTE* ALIGN(kPageAlign) fEntries[kPageMax];
+ };
+
+ struct ZKA_PDE_GENERIC final
{
- ZKA_PTE ALIGN(kPageAlign) fEntries[kPageMax];
+ ZKA_PTE_GENERIC* ALIGN(kPageAlign) fEntries[kPageMax];
};
auto mm_alloc_bitmap(Boolean rw, Boolean user, SizeT size) -> VoidPtr;
diff --git a/dev/ZKA/HALKit/AMD64/Processor.hxx b/dev/ZKA/HALKit/AMD64/Processor.hxx
index ce9983c7..40ea63f9 100644
--- a/dev/ZKA/HALKit/AMD64/Processor.hxx
+++ b/dev/ZKA/HALKit/AMD64/Processor.hxx
@@ -294,5 +294,3 @@ EXTERN_C Kernel::Void hal_load_gdt(Kernel::HAL::RegisterGDT ptr);
inline Kernel::VoidPtr kKernelBitMpStart = nullptr;
inline Kernel::UIntPtr kKernelBitMpSize = 0UL;
-
-inline Kernel::VoidPtr kKernelPageStart = nullptr;
diff --git a/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx b/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx
index 229787e1..a1b75ccf 100644
--- a/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx
+++ b/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx
@@ -20,31 +20,6 @@
#include <CFKit/Property.hxx>
#include <Modules/CoreCG/TextRenderer.hxx>
-Kernel::Property cKernelVersion;
-Kernel::User cUserSuper{Kernel::RingKind::kRingSuperUser, kSuperUser};
-
-EXTERN Kernel::Boolean kAllocationInProgress;
-
-struct HEAP_ALLOC_INFO final
-{
- Kernel::VoidPtr fThe;
- Kernel::Size fTheSz;
-};
-
-struct PROCESS_BLOCK_INFO final
-{
- THREAD_INFORMATION_BLOCK* fTIB;
- THREAD_INFORMATION_BLOCK* fGIB;
-};
-
-struct PROCESS_EXIT_INFO final
-{
- STATIC constexpr auto cReasonLen = 512;
-
- Kernel::Int64 fCode;
- Kernel::Char fReason[cReasonLen];
-};
-
namespace Kernel::HAL
{
/// @brief Gets the system cores using the MADT.
@@ -68,13 +43,7 @@ EXTERN_C void hal_init_platform(
return;
}
- hal_real_init();
-}
-
-Kernel::Void hal_real_init(Kernel::Void) noexcept
-{
- // reset kAllocationInProgress field to zero.
- kAllocationInProgress = false;
+ CG::CGDrawBackground();
// get page size.
kKernelBitMpSize = kHandoverHeader->f_BitMapSize;
@@ -83,29 +52,17 @@ Kernel::Void hal_real_init(Kernel::Void) noexcept
kKernelBitMpStart = reinterpret_cast<Kernel::VoidPtr>(
reinterpret_cast<Kernel::UIntPtr>(kHandoverHeader->f_BitMapStart));
- // get physical address start.
- kKernelPhysicalStart = reinterpret_cast<Kernel::VoidPtr>(
- reinterpret_cast<Kernel::UIntPtr>(kHandoverHeader->f_PhysicalStart));
-
if (kHandoverHeader->f_HardwareTables.f_MultiProcessingEnabled)
Kernel::HAL::mp_get_cores(kHandoverHeader->f_HardwareTables.f_VendorPtr);
- else
- Kernel::HAL::mp_get_cores(nullptr);
kcout << "Creating filesystem and such.\r";
- auto fs = new Kernel::NeFileSystemMgr();
-
- MUST_PASS(fs);
- MUST_PASS(fs->GetParser());
-
- Kernel::NeFileSystemMgr::Mount(fs);
-
- const auto cPassword = "ZKA_KERNEL_AUTHORITY";
+ if (kHandoverHeader->f_HardwareTables.f_MultiProcessingEnabled)
+ Kernel::HAL::mp_get_cores(kHandoverHeader->f_HardwareTables.f_VendorPtr);
- cUserSuper.TrySave(cPassword);
+ Kernel::NeFileSystemMgr::Mount(Kernel::mm_new_class<Kernel::NeFileSystemMgr>());
- ke_dll_entrypoint();
+ mp_do_user_switch();
Kernel::ke_stop(RUNTIME_CHECK_FAILED);
}
diff --git a/dev/ZKA/amd64-efi.make b/dev/ZKA/amd64-efi.make
index 80cb35b7..18e79e19 100644
--- a/dev/ZKA/amd64-efi.make
+++ b/dev/ZKA/amd64-efi.make
@@ -35,7 +35,7 @@ COPY = cp
ASMFLAGS = -f win64
# Kernel subsystem is 17 and entrypoint is hal_init_platform
-LDFLAGS = -e hal_init_platform --subsystem=17 --image-base 0x10000000
+LDFLAGS = -e hal_init_platform --subsystem=17 --image-base 0x4000000
LDOBJ = Objects/*.obj
# This file is the Kernel, responsible of task, memory, driver, sci, disk and device management.