diff options
| author | Amlal <amlal@el-mahrouss-logic.com> | 2024-09-11 20:39:17 +0200 |
|---|---|---|
| committer | Amlal <amlal@el-mahrouss-logic.com> | 2024-09-11 20:39:17 +0200 |
| commit | bf11afdba8486d5b15445d55427a5e97385348fd (patch) | |
| tree | af1370219334b2126655fa59b69b8d48ae63d63d /dev | |
| parent | 8b6cc0cbe5e19e8114a65785e24bbcf4d22e0d2f (diff) | |
REWORK: Reworking Paging API on AMD64.
Signed-off-by: Amlal <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'dev')
| -rw-r--r-- | dev/ZBA/Sources/HEL/AMD64/BootMain.cxx | 31 | ||||
| -rw-r--r-- | dev/ZBA/amd64-efi.make | 2 | ||||
| -rw-r--r-- | dev/ZKA/FirmwareKit/Handover.hxx | 2 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx | 50 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalCommAPI.cxx | 115 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalHALComm.cxx | 239 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalKernelMain.cxx | 15 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/Processor.hxx | 2 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/ARM64/HalKernelMain.cxx | 2 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/ARM64/Processor.hxx | 2 | ||||
| -rw-r--r-- | dev/ZKA/Sources/ExeMain.cxx | 166 |
11 files changed, 173 insertions, 453 deletions
diff --git a/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx b/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx index 7e85296f..2e20c5d3 100644 --- a/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx +++ b/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx @@ -121,12 +121,12 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, // draw background color. // ------------------------------------------ // - handover_hdr->f_GOP.f_The = kGop->Mode->FrameBufferBase; - handover_hdr->f_GOP.f_Width = kGop->Mode->Info->VerticalResolution; - handover_hdr->f_GOP.f_Height = kGop->Mode->Info->HorizontalResolution; + handover_hdr->f_GOP.f_The = kGop->Mode->FrameBufferBase; + handover_hdr->f_GOP.f_Width = kGop->Mode->Info->VerticalResolution; + handover_hdr->f_GOP.f_Height = kGop->Mode->Info->HorizontalResolution; handover_hdr->f_GOP.f_PixelPerLine = kGop->Mode->Info->PixelsPerScanLine; - handover_hdr->f_GOP.f_PixelFormat = kGop->Mode->Info->PixelFormat; - handover_hdr->f_GOP.f_Size = kGop->Mode->FrameBufferSize; + handover_hdr->f_GOP.f_PixelFormat = kGop->Mode->Info->PixelFormat; + handover_hdr->f_GOP.f_Size = kGop->Mode->FrameBufferSize; // ------------------------------------------- // // Grab MP services, extended to runtime. // @@ -194,7 +194,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, for (; Descriptor[lookIndex].Kind != EfiMemoryType::EfiConventionalMemory; ++lookIndex) { - ; + ZKA_UNUSED(0); } cDefaultMemoryMap = lookIndex; @@ -213,7 +213,8 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, handover_hdr->f_FirmwareSpecific[HEL::kHandoverSpecificMemoryEfi] = (UIntPtr)Descriptor; - handover_hdr->f_BitMapStart = (VoidPtr)Descriptor[cDefaultMemoryMap].VirtualStart; + handover_hdr->f_BitMapStart = + (VoidPtr)Descriptor[cDefaultMemoryMap].VirtualStart; handover_hdr->f_BitMapSize = kHandoverBitMapSz; /* # of pages */ @@ -244,7 +245,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, handover_hdr->f_FirmwareVendorLen = BStrLen(SystemTable->FirmwareVendor); - handover_hdr->f_Magic = kHandoverMagic; + handover_hdr->f_Magic = kHandoverMagic; handover_hdr->f_Version = kHandoverVersion; // Provide fimware vendor name. @@ -290,14 +291,14 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, chimeWav.Blob() && urbanistTTF.Blob()) { - handover_hdr->f_StartupChime = chimeWav.Blob(); - handover_hdr->f_ChimeSz = chimeWav.Size(); - handover_hdr->f_StartupImage = readerSysDrv.Blob(); - handover_hdr->f_StartupSz = readerSysDrv.Size(); - handover_hdr->f_KernelImage = readerKernel.Blob(); - handover_hdr->f_KernelSz = readerKernel.Size(); + handover_hdr->f_StartupChime = chimeWav.Blob(); + handover_hdr->f_ChimeSz = chimeWav.Size(); + handover_hdr->f_StartupImage = readerSysDrv.Blob(); + handover_hdr->f_StartupSz = readerSysDrv.Size(); + handover_hdr->f_KernelImage = readerKernel.Blob(); + handover_hdr->f_KernelSz = readerKernel.Size(); handover_hdr->f_TTFallbackFont = urbanistTTF.Blob(); - handover_hdr->f_FontSz = urbanistTTF.Size(); + handover_hdr->f_FontSz = urbanistTTF.Size(); } else { diff --git a/dev/ZBA/amd64-efi.make b/dev/ZBA/amd64-efi.make index 5d5071e0..7695e240 100644 --- a/dev/ZBA/amd64-efi.make +++ b/dev/ZBA/amd64-efi.make @@ -36,7 +36,7 @@ EMU_FLAGS=-net none -m 8G -M q35 \ file=fat:rw:Sources/Root/,index=2,format=raw \ -drive id=disk_2,file=$(IMG_2),if=none \ -device ahci,id=ahci \ - -device ide-hd,drive=disk_2,bus=ahci.0 -d int + -device ide-hd,drive=disk_2,bus=ahci.0 -d int -no-shutdown -no-reboot LD_FLAGS=-e Main --subsystem=10 diff --git a/dev/ZKA/FirmwareKit/Handover.hxx b/dev/ZKA/FirmwareKit/Handover.hxx index 3332c463..a89cfa1e 100644 --- a/dev/ZKA/FirmwareKit/Handover.hxx +++ b/dev/ZKA/FirmwareKit/Handover.hxx @@ -25,7 +25,7 @@ #define kHandoverVersion 0x0116 /* Initial bitmap size. */ -#define kHandoverBitMapSz gib_cast(64) +#define kHandoverBitMapSz gib_cast(3) #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 57565b5b..22f93cba 100644 --- a/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx +++ b/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx @@ -27,7 +27,8 @@ namespace Kernel { Bool FreeBitMap(VoidPtr page_ptr) { - if (!page_ptr) return No; + if (!page_ptr) + return No; UIntPtr* ptr_bit_set = reinterpret_cast<UIntPtr*>(page_ptr); @@ -47,7 +48,9 @@ namespace Kernel ptr_bit_set[0] = cBitMpMagic; ptr_bit_set[2] = No; - mm_map_page(page_ptr, ~eFlagsPresent); + mm_map_page(ptr_bit_set, ~eFlagsPresent); + mm_map_page(ptr_bit_set, ~eFlagsRw); + mm_map_page(ptr_bit_set, ~eFlagsUser); return Yes; } @@ -80,15 +83,6 @@ namespace Kernel kcout << "Size of pointer (TIB): " << number(TIB(ptr_bit_set[1])) << endl; kcout << "Address Of BMP: " << hex_number((UIntPtr)ptr_bit_set) << endl; - if (rw) - mm_map_page(base_ptr, eFlagsRw | eFlagsPresent); - else if (user && rw) - mm_map_page(base_ptr, eFlagsUser | eFlagsRw | eFlagsPresent); - else if (user) - mm_map_page(base_ptr, eFlagsUser | eFlagsPresent); - else - mm_map_page(base_ptr, eFlagsPresent); - return (VoidPtr)ptr_bit_set; } } @@ -109,15 +103,6 @@ namespace Kernel kcout << "Size of pointer (TIB): " << number(TIB(ptr_bit_set[1])) << endl; kcout << "Address Of BMP: " << hex_number((UIntPtr)ptr_bit_set) << endl; - if (rw) - mm_map_page(base_ptr, eFlagsRw | eFlagsPresent); - else if (user && rw) - mm_map_page(base_ptr, eFlagsUser | eFlagsRw | eFlagsPresent); - else if (user) - mm_map_page(base_ptr, eFlagsUser | eFlagsPresent); - else - mm_map_page(base_ptr, eFlagsPresent); - return (VoidPtr)ptr_bit_set; } @@ -138,9 +123,21 @@ namespace Kernel VoidPtr ptr_new = nullptr; Detail::IBitMapAllocator traits; - ptr_new = traits.FindBitMap(kKernelVirtualStart, size, rw, user); + ptr_new = traits.FindBitMap(kKernelBitMpStart, size, rw, user); + + if (!ptr_new) + return nullptr; - return ((UIntPtr*)ptr_new); + if (rw) + mm_map_page(ptr_new, eFlagsRw | eFlagsPresent); + else if (user && rw) + mm_map_page(ptr_new, eFlagsUser | eFlagsRw | eFlagsPresent); + else if (user) + mm_map_page(ptr_new, eFlagsUser | eFlagsPresent); + else + mm_map_page(ptr_new, eFlagsPresent); + + return (UIntPtr*)ptr_new; } auto mm_free_bitmap(VoidPtr page_ptr) -> Bool @@ -149,7 +146,14 @@ namespace Kernel return No; Detail::IBitMapAllocator traits; - return traits.FreeBitMap(page_ptr); + Bool ret = traits.FreeBitMap(page_ptr); + + if (ret) + { + mm_map_page(page_ptr, ~eFlagsPresent); + } + + return ret; } } // namespace HAL } // namespace Kernel diff --git a/dev/ZKA/HALKit/AMD64/HalCommAPI.cxx b/dev/ZKA/HALKit/AMD64/HalCommAPI.cxx new file mode 100644 index 00000000..ff313f47 --- /dev/null +++ b/dev/ZKA/HALKit/AMD64/HalCommAPI.cxx @@ -0,0 +1,115 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + + File: HalProcessor.cxx + Purpose: Platform processor routines. + +------------------------------------------- */ + +#include <HALKit/AMD64/Processor.hxx> + +/** + * @file HalProcessorMgr.cxx + * @brief CPU Processor managers. + */ + +#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. + /// @param virt_addr 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 manip. + EXTERN_C Int32 mm_map_page(VoidPtr virt_addr, UInt32 flags) + { + return 0; + } + + Void Out8(UInt16 port, UInt8 value) + { + asm volatile("outb %%al, %1" + : + : "a"(value), "Nd"(port) + : "memory"); + } + + Void Out16(UInt16 port, UInt16 value) + { + asm volatile("outw %%ax, %1" + : + : "a"(value), "Nd"(port) + : "memory"); + } + + Void Out32(UInt16 port, UInt32 value) + { + asm volatile("outl %%eax, %1" + : + : "a"(value), "Nd"(port) + : "memory"); + } + + UInt8 In8(UInt16 port) + { + UInt8 value = 0UL; + asm volatile("inb %1, %%al" + : "=a"(value) + : "Nd"(port) + : "memory"); + + return value; + } + + UInt16 In16(UInt16 port) + { + UInt16 value = 0UL; + asm volatile("inw %1, %%ax" + : "=a"(value) + : "Nd"(port) + : "memory"); + + return value; + } + + UInt32 In32(UInt16 port) + { + UInt32 value = 0UL; + asm volatile("inl %1, %%eax" + : "=a"(value) + : "Nd"(port) + : "memory"); + + return value; + } + + Void rt_halt() + { + asm volatile("hlt"); + } + + Void rt_cli() + { + asm volatile("cli"); + } + + Void rt_sti() + { + asm volatile("sti"); + } + + Void rt_cld() + { + asm volatile("cld"); + } + + Void rt_std() + { + asm volatile("std"); + } +} // namespace Kernel::HAL diff --git a/dev/ZKA/HALKit/AMD64/HalHALComm.cxx b/dev/ZKA/HALKit/AMD64/HalHALComm.cxx deleted file mode 100644 index d19441c8..00000000 --- a/dev/ZKA/HALKit/AMD64/HalHALComm.cxx +++ /dev/null @@ -1,239 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - - File: HalProcessor.cxx - Purpose: Platform processor routines. - -------------------------------------------- */ - -#include <HALKit/AMD64/Processor.hxx> - -/** - * @file HalProcessorMgr.cxx - * @brief CPU Processor managers. - */ - -#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 -{ - namespace MM - { - UInt8 cPageBitMp[cBmpPgSz] = {0}; // Bitmap to track free/used pages - - Void pg_set_used(Int64 page_index) - { - cPageBitMp[page_index / 8] |= (1 << (page_index % 8)); - } - - Void pg_set_free(Int64 page_index) - { - cPageBitMp[page_index / 8] &= ~(1 << (page_index % 8)); - } - - Int32 pg_is_free(Int64 page_index) - { - return !(cPageBitMp[page_index / 8] & (1 << (page_index % 8))); - } - - VoidPtr pg_allocate() - { - for (SizeT i = 0; i < cTotalPages; i++) - { - if (pg_is_free(i)) - { - pg_set_used(i); - kcout << "Page has been allocated at index: " << number(i) << endl; - - return (VoidPtr)((UIntPtr)kKernelPageStart + (i * cPageSz)); // Return physical address of the page - } - } - - return nullptr; // No free page found - } - - Void pg_delete(void* addr) - { - Int64 page_index = (UIntPtr)addr / cPageSz; - kcout << "Page has been freed at: " << number(page_index) << endl; - - pg_set_free(page_index); - } - - } // namespace MM - - /// @brief Maps or allocates a page from virt_addr. - /// @param virt_addr 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 manip. - EXTERN_C Int32 mm_map_page(VoidPtr p_virt_addr, UInt32 flags) - { - rt_cli(); - - const auto cPageMask = 0xFFFF; - - volatile UIntPtr* pml4_base = (volatile UIntPtr*)(hal_read_cr3()); - - UIntPtr virt_addr = (UIntPtr)p_virt_addr; - - UInt16 pml4_index = (virt_addr >> 39) & 0x1FF; - UInt16 pdpt_index = (virt_addr >> 30) & 0x1FF; - UInt16 pd_index = (virt_addr >> 21) & 0x1FF; - UInt16 pt_index = (virt_addr >> 12) & 0x1FF; - UInt16 offset = virt_addr & 0xFFF; - - const auto cIndexAlign = kPageAlign; - - // Now get pml4_entry - volatile UIntPtr* pml4_entry = (volatile UInt64*)((pml4_base[pml4_index])); - - if (!(*pml4_entry & eFlagsPresent)) - { - auto pml_addr = MM::pg_allocate(); - *pml4_entry = (UIntPtr)pml_addr | (eFlagsPresent | eFlagsRw) & 0xFFF; - } - - volatile UIntPtr* pdpt_entry = (volatile UIntPtr*)(pml4_entry[pdpt_index]); - - if (!(*pdpt_entry & eFlagsPresent)) - { - auto pdpt_addr = MM::pg_allocate(); - *pdpt_entry = (UIntPtr)pdpt_addr | (eFlagsPresent | eFlagsRw) & 0xFFF; - } - - volatile UIntPtr* pd_entry = (volatile UIntPtr*)(pdpt_entry[pd_index]); - - if (!(*pd_entry & eFlagsPresent)) - { - auto pd_addr = MM::pg_allocate(); - *pd_entry = (UIntPtr)pd_addr | (eFlagsPresent | eFlagsRw) & 0xFFF; - } - - volatile UIntPtr* pt_entry = (volatile UIntPtr*)(pd_entry[pd_index]); - - if (!(pt_entry[pt_index] & eFlagsPresent)) - { - PTE* page_frame = (PTE*)pt_entry[pt_index]; - - if (page_frame->PhysicalAddress == 0) - { - auto pt_addr = MM::pg_allocate(); - pt_entry[pt_index] = (UIntPtr)pt_addr | eFlagsPresent | (flags & 0xFFF); - } - else - { - pt_entry[pt_index] = page_frame->PhysicalAddress | eFlagsPresent | (flags & 0xFFF); - } - - kcout << (page_frame->Present ? "Page Present." : "Page Not Present.") << endl; - kcout << (page_frame->Wr ? "Page W/R." : "Page Not W/R.") << endl; - kcout << (page_frame->User ? "Page User." : "Page Not User.") << endl; - - kcout << "Physical Address: " << hex_number(page_frame->PhysicalAddress) << endl; - - hal_flush_tlb(); - } - else - { - PTE* page_frame = (PTE*)pt_entry[pt_index]; - - pt_entry[pt_index] = page_frame->PhysicalAddress | (flags & 0xFFF); - - kcout << (page_frame->Present ? "Page Present." : "Page Not Present.") << endl; - kcout << (page_frame->Wr ? "Page W/R." : "Page Not W/R.") << endl; - kcout << (page_frame->User ? "Page User." : "Page Not User.") << endl; - - kcout << "Physical Address: " << hex_number(page_frame->PhysicalAddress) << endl; - } - - rt_sti(); - return 0; - } - - Void Out8(UInt16 port, UInt8 value) - { - asm volatile("outb %%al, %1" - : - : "a"(value), "Nd"(port) - : "memory"); - } - - Void Out16(UInt16 port, UInt16 value) - { - asm volatile("outw %%ax, %1" - : - : "a"(value), "Nd"(port) - : "memory"); - } - - Void Out32(UInt16 port, UInt32 value) - { - asm volatile("outl %%eax, %1" - : - : "a"(value), "Nd"(port) - : "memory"); - } - - UInt8 In8(UInt16 port) - { - UInt8 value = 0UL; - asm volatile("inb %1, %%al" - : "=a"(value) - : "Nd"(port) - : "memory"); - - return value; - } - - UInt16 In16(UInt16 port) - { - UInt16 value = 0UL; - asm volatile("inw %1, %%ax" - : "=a"(value) - : "Nd"(port) - : "memory"); - - return value; - } - - UInt32 In32(UInt16 port) - { - UInt32 value = 0UL; - asm volatile("inl %1, %%eax" - : "=a"(value) - : "Nd"(port) - : "memory"); - - return value; - } - - Void rt_halt() - { - asm volatile("hlt"); - } - - Void rt_cli() - { - asm volatile("cli"); - } - - Void rt_sti() - { - asm volatile("sti"); - } - - Void rt_cld() - { - asm volatile("cld"); - } - - Void rt_std() - { - asm volatile("std"); - } -} // namespace Kernel::HAL diff --git a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx index 9b9e0ac1..fd2ca470 100644 --- a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx +++ b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx @@ -19,6 +19,7 @@ #include <NetworkKit/IPC.hxx> #include <CFKit/Property.hxx> #include <Modules/CoreCG/TextRenderer.hxx> +#include <Modules/CoreCG/WindowRenderer.hxx> struct HEAP_ALLOC_INFO final { @@ -67,6 +68,8 @@ 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) { @@ -77,7 +80,7 @@ EXTERN_C void hal_init_platform( kKernelBitMpSize = kHandoverHeader->f_BitMapSize; // get virtual address start (for the heap) - kKernelVirtualStart = reinterpret_cast<Kernel::VoidPtr>( + kKernelBitMpStart = reinterpret_cast<Kernel::VoidPtr>( reinterpret_cast<Kernel::UIntPtr>(kHandoverHeader->f_BitMapStart)); // get physical address start. @@ -120,11 +123,13 @@ EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept if (kHandoverHeader->f_HardwareTables.f_MultiProcessingEnabled) Kernel::HAL::mp_get_cores(kHandoverHeader->f_HardwareTables.f_VendorPtr); - auto fs = Kernel::mm_new_class<Kernel::NeFileSystemMgr>(); + Kernel::NeFileSystemMgr::Mount(Kernel::mm_new_class<Kernel::NeFileSystemMgr>()); + + CG::CGDrawBackground(); - Kernel::NeFileSystemMgr::Mount(fs); + Kernel::HAL::mm_map_page(mp_user_switch_proc, Kernel::HAL::eFlagsRw | Kernel::HAL::eFlagsUser | Kernel::HAL::eFlagsPresent); - ke_dll_entrypoint(); + mp_do_user_switch(); - Kernel::ke_stop(RUNTIME_CHECK_FAILED); + Kernel::ke_stop(RUNTIME_CHECK_BOOTSTRAP); } diff --git a/dev/ZKA/HALKit/AMD64/Processor.hxx b/dev/ZKA/HALKit/AMD64/Processor.hxx index 42f4e287..ce9983c7 100644 --- a/dev/ZKA/HALKit/AMD64/Processor.hxx +++ b/dev/ZKA/HALKit/AMD64/Processor.hxx @@ -292,7 +292,7 @@ EXTERN_C Kernel::Void hal_load_gdt(Kernel::HAL::RegisterGDT ptr); #define kKernelIdtSize (0x100) #define kKernelInterruptId 0x32 -inline Kernel::VoidPtr kKernelVirtualStart = nullptr; +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 1bfaa879..229787e1 100644 --- a/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx +++ b/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx @@ -80,7 +80,7 @@ Kernel::Void hal_real_init(Kernel::Void) noexcept kKernelBitMpSize = kHandoverHeader->f_BitMapSize; // get virtual address start (for the heap) - kKernelVirtualStart = reinterpret_cast<Kernel::VoidPtr>( + kKernelBitMpStart = reinterpret_cast<Kernel::VoidPtr>( reinterpret_cast<Kernel::UIntPtr>(kHandoverHeader->f_BitMapStart)); // get physical address start. diff --git a/dev/ZKA/HALKit/ARM64/Processor.hxx b/dev/ZKA/HALKit/ARM64/Processor.hxx index 4c46f294..41456880 100644 --- a/dev/ZKA/HALKit/ARM64/Processor.hxx +++ b/dev/ZKA/HALKit/ARM64/Processor.hxx @@ -42,7 +42,7 @@ namespace Kernel::HAL typedef StackFrame* StackFramePtr; } // namespace Kernel::HAL -inline Kernel::VoidPtr kKernelVirtualStart = nullptr; +inline Kernel::VoidPtr kKernelBitMpStart = nullptr; inline Kernel::UIntPtr kKernelBitMpSize = 0UL; inline Kernel::VoidPtr kKernelPhysicalStart = nullptr; diff --git a/dev/ZKA/Sources/ExeMain.cxx b/dev/ZKA/Sources/ExeMain.cxx deleted file mode 100644 index a3fdfaa0..00000000 --- a/dev/ZKA/Sources/ExeMain.cxx +++ /dev/null @@ -1,166 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies - - File: Main.cxx - Purpose: Main entrypoint of Kernel. - -------------------------------------------- */ - -#include <KernelKit/PE.hxx> -#include <ArchKit/ArchKit.hxx> -#include <CompilerKit/Detail.hxx> -#include <FirmwareKit/Handover.hxx> -#include <KernelKit/FileMgr.hxx> -#include <KernelKit/Framebuffer.hxx> -#include <KernelKit/Heap.hxx> -#include <KernelKit/PEF.hxx> -#include <KernelKit/PEFCodeMgr.hxx> -#include <KernelKit/UserProcessScheduler.hxx> -#include <NewKit/Json.hxx> -#include <NewKit/KernelCheck.hxx> -#include <NewKit/String.hxx> -#include <NewKit/Utils.hxx> -#include <KernelKit/PEFCodeMgr.hxx> -#include <KernelKit/CodeMgr.hxx> -#include <CFKit/Property.hxx> -#include <Modules/CoreCG/WindowRenderer.hxx> -#include <KernelKit/Timer.hxx> - -/***********************************************************************************/ -/* Returns Kernel's version. */ -/***********************************************************************************/ - -EXTERN Kernel::Property cKernelVersion; - -/***********************************************************************************/ -/* This is an external C symbol, to draw the mouse. */ -/***********************************************************************************/ - -STATIC CG::UI_WINDOW_STRUCT* cKernelWnd = nullptr; - -namespace Kernel::Detail -{ - /// @brief Filesystem auto formatter, additional checks are also done by the class. - class FilesystemInstaller final - { - Kernel::NeFileSystemMgr* fNeFS{nullptr}; - - public: - /// @brief wizard constructor. - explicit FilesystemInstaller() - { - if (Kernel::IFilesystemMgr::GetMounted()) - { - CG::CGDrawStringToWnd(cKernelWnd, "NeFS IFS already mounted by HAL (A:)", 10, 10, RGB(0, 0, 0)); - fNeFS = reinterpret_cast<Kernel::NeFileSystemMgr*>(Kernel::IFilesystemMgr::GetMounted()); - } - else - { - // Mounts a NeFS from main drive. - fNeFS = Kernel::mm_new_class<Kernel::NeFileSystemMgr>(); - - Kernel::IFilesystemMgr::Mount(fNeFS); - - CG::CGDrawStringToWnd(cKernelWnd, "Mounted NeFS IFS (A:)", 10, 10, RGB(0, 0, 0)); - } - - const Kernel::SizeT cDirCount = 9UL; - - const Kernel::Char* cDirStr[cDirCount] = { - "\\Boot\\", "\\System\\", "\\Support\\", "\\Applications\\", - "\\Users\\", "\\Library\\", "\\Mount\\", "\\Store\\", "\\Applications\\Store\\"}; - - if (fNeFS->GetParser()) - { - for (Kernel::SizeT dirIndx = 0UL; dirIndx < cDirCount; ++dirIndx) - { - auto catalogDir = fNeFS->GetParser()->GetCatalog(cDirStr[dirIndx]); - - if (catalogDir) - { - CG::CGDrawStringToWnd(cKernelWnd, "Directory already exists: ", 10 + (10 * (dirIndx + 1)), 10, RGB(0, 0, 0)); - CG::CGDrawStringToWnd(cKernelWnd, catalogDir->Name, 10 + (10 * (dirIndx + 1)), 10 + (FONT_SIZE_X * rt_string_len("Directory already exists: ")), RGB(0, 0, 0)); - - delete catalogDir; - continue; - } - - catalogDir = fNeFS->GetParser()->CreateCatalog(cDirStr[dirIndx], 0, - kNeFSCatalogKindDir); - - CG::CGDrawStringToWnd(cKernelWnd, "Directory has been created: ", 10 + (10 * (dirIndx + 1)), 10, RGB(0, 0, 0)); - CG::CGDrawStringToWnd(cKernelWnd, catalogDir->Name, 10 + (10 * (dirIndx + 1)), 10 + (FONT_SIZE_X * rt_string_len("Directory has been created: ")), RGB(0, 0, 0)); - - NFS_FORK_STRUCT theFork{ 0 }; - - rt_copy_memory(catalogDir->Name, theFork.CatalogName, rt_string_len(catalogDir->Name)); - rt_copy_memory(catalogDir->Name, theFork.ForkName, rt_string_len(catalogDir->Name)); - - theFork.DataSize = kNeFSForkDataSz; - theFork.Kind = kNeFSDataForkKind; - theFork.ResourceId = 0; - - fNeFS->GetParser()->CreateFork(catalogDir, theFork); - - auto data_len = 4096; - Char data[4096] = R"({ "FolderKind": "System", "Owner": "ZKA USER\\SUPER", "Important": true })"; - - fNeFS->GetParser()->WriteCatalog(catalogDir, false, data, data_len, theFork.ForkName); - - delete catalogDir; - } - } - } - - ~FilesystemInstaller() = default; - - ZKA_COPY_DEFAULT(FilesystemInstaller); - - /// @brief Grab the disk's NeFS reference. - /// @return NeFileSystemMgr the filesystem interface - Kernel::NeFileSystemMgr* Leak() - { - return fNeFS; - } - }; -} // namespace Kernel::Detail - -namespace Kernel -{ - EXTERN UserProcessScheduler* cProcessScheduler; -} - -/// @brief Application entrypoint. -/// @param Void -/// @return Void -EXTERN_C Kernel::Void ke_dll_entrypoint(Kernel::Void) -{ - Kernel::cProcessScheduler = nullptr; - - CG::CGDrawBackground(); - - cKernelWnd = nullptr; - cKernelWnd = CG::CGCreateWindow(CG::cWndFlagWindow, "ZKA Operating System Kernel Log", "Window", 20, 20, CG::UIAccessibilty::The().Height() - 20, CG::UIAccessibilty::The().Width() - 20); - - cKernelWnd->w_sub_type = 0; - cKernelWnd->w_x = 10; - cKernelWnd->w_y = 10; - - cKernelWnd->w_needs_repaint = Yes; - - CG::CGDrawWindowList(&cKernelWnd, 1); - - /// Now run Kernel loop, until no process are running. - Kernel::Detail::FilesystemInstaller(); // automatic filesystem creation. - - cKernelWnd->w_sub_type = CG::cWndFlagCloseControlSelect; - cKernelWnd->w_needs_repaint = Yes; - - CG::CGDrawWindowList(&cKernelWnd, 1); - - CG::CGDrawStringToWnd(cKernelWnd, "Running: ", 10, 10, RGB(0, 0, 0)); - CG::CGDrawStringToWnd(cKernelWnd, kSysProcess, 10, 10 + (FONT_SIZE_X * Kernel::rt_string_len("Running: ")), RGB(0, 0, 0)); - - mp_do_user_switch(); -} |
