summaryrefslogtreecommitdiffhomepage
path: root/dev
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-12-01 18:41:41 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-12-01 18:41:41 +0100
commitf83e7bddcf24433adbfc9214e0f8f8139f8b6362 (patch)
tree0447eddc2ebff291f96286847c238b4f907515b1 /dev
parentc62790f8f773a2f10464d2b1e0e286f2b3156712 (diff)
FIX: Fixing ARM64 execution when booting from bootloader.
FIX: Now works both for ARM64 and AMD64 EFI backends. TODO: The ACB backend needs to be done too. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev')
-rw-r--r--dev/Modules/ATA/ATA.h2
-rw-r--r--dev/ZBAKit/BootKit/Support.h14
-rw-r--r--dev/ZBAKit/arm64-efi.make2
-rw-r--r--dev/ZBAKit/src/HEL/ARM64/BootAPI.S12
-rw-r--r--dev/ZBAKit/src/HEL/ARM64/BootMain.cc14
-rw-r--r--dev/ZKAKit/HALKit/ARM64/HalKernelMain.cc5
-rw-r--r--dev/ZKAKit/HALKit/ARM64/HalSchedulerCoreARM64.cc2
-rw-r--r--dev/ZKAKit/HintKit/CompilerHint.h2
-rw-r--r--dev/ZKAKit/KernelKit/IDLLObject.h2
-rw-r--r--dev/ZKAKit/KernelKit/IPEFDLLObject.h2
-rw-r--r--dev/ZKAKit/KernelKit/PEFCodeMgr.h4
-rw-r--r--dev/ZKAKit/KernelKit/ThreadLocalStorage.h11
-rw-r--r--dev/ZKAKit/KernelKit/ThreadLocalStorage.inl21
-rw-r--r--dev/ZKAKit/KernelKit/UserProcessScheduler.h4
-rw-r--r--dev/ZKAKit/KernelKit/UserProcessScheduler.inl40
-rw-r--r--dev/ZKAKit/amd64-efi.make2
-rw-r--r--dev/ZKAKit/src/CxxAbi-ARM64.cc15
-rw-r--r--dev/ZKAKit/src/IPEFDLLObject.cc3
-rw-r--r--dev/ZKAKit/src/UserProcessScheduler.cc37
-rw-r--r--dev/ZKAKit/src/Utils.cc7
20 files changed, 135 insertions, 66 deletions
diff --git a/dev/Modules/ATA/ATA.h b/dev/Modules/ATA/ATA.h
index b9309752..f03b6b1d 100644
--- a/dev/Modules/ATA/ATA.h
+++ b/dev/Modules/ATA/ATA.h
@@ -134,7 +134,7 @@ enum
#if defined(__ATA_PIO__) || defined(__ATA_DMA__)
-Kernel::Boolean drv_std_init(Kernel::UInt16 _Input bus, Kernel::UInt8 _Input drive, Kernel::UInt16& _Output out_bus, Kernel::UInt8& _Output out_master);
+Kernel::Boolean drv_std_init(Kernel::UInt16 in_bus, Kernel::UInt8 drive, Kernel::UInt16& out_bus, Kernel::UInt8& out_master);
Kernel::Boolean drv_std_detected(Kernel::Void);
diff --git a/dev/ZBAKit/BootKit/Support.h b/dev/ZBAKit/BootKit/Support.h
index 1ee1dc47..2c1db6f4 100644
--- a/dev/ZBAKit/BootKit/Support.h
+++ b/dev/ZBAKit/BootKit/Support.h
@@ -6,13 +6,11 @@
#pragma once
-#include <cstddef>
-
/// @file Support.h
/// @brief Purpose of this file is to help port libs into the bootloader.
-#define cLongMax ((long)(~0UL >> 1))
-#define cLongMin (~cLongMax)
+#define kLongMax ((long)(~0UL >> 1))
+#define kLongMin (~kLongMax)
#ifdef __NEWOSLDR__
@@ -65,7 +63,7 @@ inline long StringToLong(const char* nptr, char** endptr, int base)
const char *p = nptr, *endp;
bool is_neg = 0, overflow = 0;
- /* Need unsigned so (-cLongMin) can fit in these: */
+ /* Need unsigned so (-kLongMin) can fit in these: */
unsigned long n = 0UL, cutoff;
int cutlim;
@@ -124,8 +122,8 @@ inline long StringToLong(const char* nptr, char** endptr, int base)
base = 10;
}
- cutoff = (is_neg) ? -(cLongMin / base) : cLongMax / base;
- cutlim = (is_neg) ? -(cLongMin % base) : cLongMax % base;
+ cutoff = (is_neg) ? -(kLongMin / base) : kLongMax / base;
+ cutlim = (is_neg) ? -(kLongMin % base) : kLongMax % base;
while (1)
{
@@ -160,7 +158,7 @@ inline long StringToLong(const char* nptr, char** endptr, int base)
if (overflow)
{
- return ((is_neg) ? cLongMin : cLongMax);
+ return ((is_neg) ? kLongMin : kLongMax);
}
return (long)((is_neg) ? -n : n);
diff --git a/dev/ZBAKit/arm64-efi.make b/dev/ZBAKit/arm64-efi.make
index db805848..12aae5f8 100644
--- a/dev/ZBAKit/arm64-efi.make
+++ b/dev/ZBAKit/arm64-efi.make
@@ -46,7 +46,7 @@ REM_FLAG=-f
FLAG_ASM=-f win64
FLAG_GNU=-fshort-wchar -c -ffreestanding -MMD -mno-red-zone -D__ZKA_ARM64__ -fno-rtti -fno-exceptions -I./ \
-target aarch64-unknown-windows \
- -std=c++20 -D__FSKIT_USE_NEFS__ -D__STANDALONE__ -D__MINOSKRNL__ -D__NEWOSLDR__ -D__HAVE_ZKA_APIS__ -D__ZKA__ -I../ -I../zka
+ -std=c++20 -D__FSKIT_USE_NEFS__ -D__STANDALONE__ -D__MINOSKRNL__ -D__NEWOSLDR__ -D__HAVE_ZKA_APIS__ -D__ZKA__ -I../ -I../ZKAKit
BOOT_LOADER=zbaosldr.exe
KERNEL=minoskrnl.exe
diff --git a/dev/ZBAKit/src/HEL/ARM64/BootAPI.S b/dev/ZBAKit/src/HEL/ARM64/BootAPI.S
new file mode 100644
index 00000000..9a53dfc9
--- /dev/null
+++ b/dev/ZBAKit/src/HEL/ARM64/BootAPI.S
@@ -0,0 +1,12 @@
+.global rt_jump_to_address
+
+.text
+
+/**
+ @brief this function setups a stack and then jumps to
+ a function */
+rt_jump_to_address:
+ mov x19, x0
+ mov sp, x2
+ br x19
+
diff --git a/dev/ZBAKit/src/HEL/ARM64/BootMain.cc b/dev/ZBAKit/src/HEL/ARM64/BootMain.cc
index 1d3d9150..99e321ee 100644
--- a/dev/ZBAKit/src/HEL/ARM64/BootMain.cc
+++ b/dev/ZBAKit/src/HEL/ARM64/BootMain.cc
@@ -9,12 +9,12 @@
#include <BootKit/Thread.h>
#include <BootKit/BootKit.h>
-#ifndef cExpectedWidth
-#define cExpectedWidth 844
+#ifndef kExpectedWidth
+#define kExpectedWidth 844
#endif
-#ifndef cExpectedHeight
-#define cExpectedHeight 390
+#ifndef kExpectedHeight
+#define kExpectedHeight 390
#endif
EXTERN EfiBootServices* BS;
@@ -52,8 +52,8 @@ EFI_EXTERN_C EFI_API Int32 Main(EfiHandlePtr ImageHandle,
writer.Write(infoPtr->VerticalResolution);
writer.Write("\r");
- if (infoPtr->HorizontalResolution == cExpectedWidth &&
- infoPtr->VerticalResolution == cExpectedHeight)
+ if (infoPtr->HorizontalResolution == kExpectedWidth &&
+ infoPtr->VerticalResolution == kExpectedHeight)
{
kGop->SetMode(kGop, i);
break;
@@ -69,7 +69,7 @@ EFI_EXTERN_C EFI_API Int32 Main(EfiHandlePtr ImageHandle,
auto kernel_thread = Boot::BThread(reader_kernel.Blob());
if (kernel_thread.IsValid())
- kernel_thread.Start(nullptr);
+ kernel_thread.Start(nullptr, YES);
}
CANT_REACH();
diff --git a/dev/ZKAKit/HALKit/ARM64/HalKernelMain.cc b/dev/ZKAKit/HALKit/ARM64/HalKernelMain.cc
index 1d901e48..6d89dfc4 100644
--- a/dev/ZKAKit/HALKit/ARM64/HalKernelMain.cc
+++ b/dev/ZKAKit/HALKit/ARM64/HalKernelMain.cc
@@ -44,8 +44,5 @@ EXTERN_C void hal_init_platform(
kKernelBitMpStart = reinterpret_cast<Kernel::VoidPtr>(
reinterpret_cast<Kernel::UIntPtr>(kHandoverHeader->f_BitMapStart));
- Kernel::NeFileSystemMgr::Mount(new Kernel::NeFileSystemMgr());
-
- while (Yes)
- ;
+ Kernel::ke_stop(RUNTIME_CHECK_BOOTSTRAP);
}
diff --git a/dev/ZKAKit/HALKit/ARM64/HalSchedulerCoreARM64.cc b/dev/ZKAKit/HALKit/ARM64/HalSchedulerCoreARM64.cc
index 4c620ab9..55619d54 100644
--- a/dev/ZKAKit/HALKit/ARM64/HalSchedulerCoreARM64.cc
+++ b/dev/ZKAKit/HALKit/ARM64/HalSchedulerCoreARM64.cc
@@ -35,6 +35,6 @@ namespace Kernel
/// hooks and hangs thread to prevent code from executing.
Void mp_hang_thread(HAL::StackFrame* stack)
{
- ZKA_UNUSUED(stack);
+ ZKA_UNUSED(stack);
}
} // namespace Kernel
diff --git a/dev/ZKAKit/HintKit/CompilerHint.h b/dev/ZKAKit/HintKit/CompilerHint.h
index 415e4776..f484a261 100644
--- a/dev/ZKAKit/HintKit/CompilerHint.h
+++ b/dev/ZKAKit/HintKit/CompilerHint.h
@@ -7,7 +7,9 @@
#ifndef __HINTKIT_COMPILER_HINT_H__
#define __HINTKIT_COMPILER_HINT_H__
+#ifdef __TK__
#pragma compiler(hint_manifest)
+#endif
#define _Input
#define _Output
diff --git a/dev/ZKAKit/KernelKit/IDLLObject.h b/dev/ZKAKit/KernelKit/IDLLObject.h
index bd1aa5d0..e14e335f 100644
--- a/dev/ZKAKit/KernelKit/IDLLObject.h
+++ b/dev/ZKAKit/KernelKit/IDLLObject.h
@@ -12,6 +12,8 @@
#include <NewKit/Defines.h>
#include <CompilerKit/CompilerKit.h>
+#define ZKA_DLL_OBJECT : public IDLLObject
+
namespace Kernel
{
/// @brief DLL class object. A handle to a shared library.
diff --git a/dev/ZKAKit/KernelKit/IPEFDLLObject.h b/dev/ZKAKit/KernelKit/IPEFDLLObject.h
index 9447a98f..03dcd53f 100644
--- a/dev/ZKAKit/KernelKit/IPEFDLLObject.h
+++ b/dev/ZKAKit/KernelKit/IPEFDLLObject.h
@@ -22,7 +22,7 @@ namespace Kernel
* @brief Shared Library class
* Load library from this class
*/
- class IPEFDLLObject final : public IDLLObject
+ class IPEFDLLObject final ZKA_DLL_OBJECT
{
public:
explicit IPEFDLLObject() = default;
diff --git a/dev/ZKAKit/KernelKit/PEFCodeMgr.h b/dev/ZKAKit/KernelKit/PEFCodeMgr.h
index 5474e4b6..c42701ce 100644
--- a/dev/ZKAKit/KernelKit/PEFCodeMgr.h
+++ b/dev/ZKAKit/KernelKit/PEFCodeMgr.h
@@ -12,6 +12,10 @@
#include <NewKit/KString.h>
#include <KernelKit/FileMgr.h>
+#ifndef INC_PROCESS_SCHEDULER_H
+#include <KernelKit/UserProcessScheduler.h>
+#endif
+
#define kPefApplicationMime "application/vnd-zka-executable"
namespace Kernel
diff --git a/dev/ZKAKit/KernelKit/ThreadLocalStorage.h b/dev/ZKAKit/KernelKit/ThreadLocalStorage.h
index 93e0a9a4..2c0a8810 100644
--- a/dev/ZKAKit/KernelKit/ThreadLocalStorage.h
+++ b/dev/ZKAKit/KernelKit/ThreadLocalStorage.h
@@ -8,6 +8,7 @@
#define KERNELKIT_TLS_H
#include <NewKit/Defines.h>
+#include <NewKit/ErrorOr.h>
///! @brief Thread Local Storage for minoskrnl.
@@ -38,6 +39,16 @@ T* tls_new_ptr(void) noexcept;
template <typename T>
Kernel::Boolean tls_delete_ptr(T* ptr) noexcept;
+//! @brief Delete process pointer.
+//! @param obj The pointer to delete.
+template <typename T>
+inline Kernel::Bool tls_delete_ptr(Kernel::ErrorOr<T> obj) noexcept;
+
+//! @brief Delete process pointer.
+//! @param obj The pointer to delete.
+template <typename T>
+inline Kernel::Bool tls_delete_ptr(Kernel::ErrorOr<T*> obj) noexcept;
+
template <typename T, typename... Args>
T* tls_new_class(Args&&... args);
diff --git a/dev/ZKAKit/KernelKit/ThreadLocalStorage.inl b/dev/ZKAKit/KernelKit/ThreadLocalStorage.inl
index d9850c01..3683bc4b 100644
--- a/dev/ZKAKit/KernelKit/ThreadLocalStorage.inl
+++ b/dev/ZKAKit/KernelKit/ThreadLocalStorage.inl
@@ -7,6 +7,7 @@
//! @file ThreadLocalStorage.inl
//! @brief Allocate resources from the process's heap storage.
+#include "NewKit/ErrorOr.h"
#ifndef INC_PROCESS_SCHEDULER_H
#include <KernelKit/UserProcessScheduler.h>
#endif
@@ -40,7 +41,25 @@ inline Kernel::Bool tls_delete_ptr(T* obj) noexcept
auto ref_process = UserProcessScheduler::The().GetCurrentProcess();
MUST_PASS(ref_process);
- return ref_process.Leak().Delete(obj, sizeof(T));
+ ErrorOr<T*> obj_wrapped{obj};
+
+ return ref_process.Leak().Delete(obj_wrapped, sizeof(T));
+}
+
+//! @brief Delete process pointer.
+//! @param obj The pointer to delete.
+template <typename T>
+inline Kernel::Bool tls_delete_ptr(Kernel::ErrorOr<T> obj) noexcept
+{
+ return tls_delete_ptr(obj.Leak());
+}
+
+//! @brief Delete process pointer.
+//! @param obj The pointer to delete.
+template <typename T>
+inline Kernel::Bool tls_delete_ptr(Kernel::ErrorOr<T*> obj) noexcept
+{
+ return tls_delete_ptr(obj->Leak());
}
/// @brief Allocate a C++ class, and then call the constructor of it.
diff --git a/dev/ZKAKit/KernelKit/UserProcessScheduler.h b/dev/ZKAKit/KernelKit/UserProcessScheduler.h
index a3a6c8bd..c1559085 100644
--- a/dev/ZKAKit/KernelKit/UserProcessScheduler.h
+++ b/dev/ZKAKit/KernelKit/UserProcessScheduler.h
@@ -219,7 +219,8 @@ namespace Kernel
///! @brief TLS free.
///! @param ptr the pointer to free.
///! @param sz the size of it.
- Boolean Delete(ErrorOr<VoidPtr> ptr, const SizeT& sz);
+ template <typename T>
+ Boolean Delete(ErrorOr<T*> ptr, const SizeT& sz);
///! @brief Wakes up threads.
Void Wake(const Bool wakeup = false);
@@ -324,6 +325,7 @@ namespace Kernel
} // namespace Kernel
#include <KernelKit/ThreadLocalStorage.h>
+#include <KernelKit/UserProcessScheduler.inl>
////////////////////////////////////////////////////
diff --git a/dev/ZKAKit/KernelKit/UserProcessScheduler.inl b/dev/ZKAKit/KernelKit/UserProcessScheduler.inl
new file mode 100644
index 00000000..b99fafbf
--- /dev/null
+++ b/dev/ZKAKit/KernelKit/UserProcessScheduler.inl
@@ -0,0 +1,40 @@
+namespace Kernel
+{
+ /***********************************************************************************/
+ /** @brief Free pointer from usage. */
+ /***********************************************************************************/
+
+ template <typename T>
+ Boolean UserProcess::Delete(ErrorOr<T*> ptr, const SizeT& sz)
+ {
+ if (!ptr ||
+ sz == 0)
+ return No;
+
+ UserProcessHeapList* entry = this->MemoryHeap;
+
+ while (entry != nullptr)
+ {
+ if (entry->MemoryEntry == ptr.Leak().Leak())
+ {
+#ifdef __ZKA_AMD64__
+ auto pd = hal_read_cr3();
+ hal_write_cr3(this->VMRegister);
+
+ auto ret = mm_delete_heap(entry->MemoryEntry);
+
+ hal_write_cr3(pd);
+
+ return ret;
+#else
+ Bool ret = mm_delete_heap(ptr.Leak().Leak());
+ return ret;
+#endif
+ }
+
+ entry = entry->MemoryNext;
+ }
+
+ return No;
+ }
+} // namespace Kernel \ No newline at end of file
diff --git a/dev/ZKAKit/amd64-efi.make b/dev/ZKAKit/amd64-efi.make
index 296abbb9..97ce96de 100644
--- a/dev/ZKAKit/amd64-efi.make
+++ b/dev/ZKAKit/amd64-efi.make
@@ -7,7 +7,7 @@ CC = x86_64-w64-mingw32-g++
LD = x86_64-w64-mingw32-ld
CCFLAGS = -fshort-wchar -c -D__ZKA_AMD64__ -mno-red-zone -fno-rtti -fno-exceptions \
-std=c++20 -D__ZKA_SUPPORT_NX__ -O0 -I../Vendor -D__FSKIT_INCLUDES_NEFS__ \
- -D__MINOSKRNL__ -D__HAVE_ZKA_APIS__ -D__FREESTANDING__ -D__ZKA__ -I./ -I../ -I../zba -Wall
+ -D__MINOSKRNL__ -D__HAVE_ZKA_APIS__ -D__FREESTANDING__ -D__ZKA__ -I./ -I../ -I../zba
ASM = nasm
diff --git a/dev/ZKAKit/src/CxxAbi-ARM64.cc b/dev/ZKAKit/src/CxxAbi-ARM64.cc
index 91ca0fe2..68a3acdc 100644
--- a/dev/ZKAKit/src/CxxAbi-ARM64.cc
+++ b/dev/ZKAKit/src/CxxAbi-ARM64.cc
@@ -87,4 +87,19 @@ EXTERN_C Kernel::Void _purecall(void* self)
kcout << ", has unimplemented virtual functions.\r";
}
+EXTERN_C Kernel::Void _Init_thread_footer(Kernel::Int* thread_obj)
+{
+ ZKA_UNUSED(thread_obj);
+}
+
+EXTERN_C Kernel::Void _Init_thread_epoch(Kernel::Void)
+{
+}
+
+EXTERN_C Kernel::Void _Init_thread_header(Kernel::Int* thread_obj)
+{
+}
+
+EXTERN_C Kernel::Int _tls_index = 0UL;
+
#endif // ifdef __ZKA_ARM64__
diff --git a/dev/ZKAKit/src/IPEFDLLObject.cc b/dev/ZKAKit/src/IPEFDLLObject.cc
index 89b613ac..3eb102b5 100644
--- a/dev/ZKAKit/src/IPEFDLLObject.cc
+++ b/dev/ZKAKit/src/IPEFDLLObject.cc
@@ -7,6 +7,7 @@
* ========================================================
*/
+#include "KernelKit/IDLLObject.h"
#include <KernelKit/DebugOutput.h>
#include <KernelKit/PEF.h>
#include <KernelKit/IPEFDLLObject.h>
@@ -55,6 +56,7 @@ EXTERN_C IDLL rtl_init_dll(UserProcess* header)
{
tls_delete_class(dll_obj);
header->Crash();
+
return nullptr;
}
@@ -65,6 +67,7 @@ EXTERN_C IDLL rtl_init_dll(UserProcess* header)
{
tls_delete_class(dll_obj);
header->Crash();
+
return nullptr;
}
diff --git a/dev/ZKAKit/src/UserProcessScheduler.cc b/dev/ZKAKit/src/UserProcessScheduler.cc
index 7f303d7c..e9cd1c54 100644
--- a/dev/ZKAKit/src/UserProcessScheduler.cc
+++ b/dev/ZKAKit/src/UserProcessScheduler.cc
@@ -156,43 +156,6 @@ namespace Kernel
}
/***********************************************************************************/
- /** @brief Free pointer from usage. */
- /***********************************************************************************/
-
- Boolean UserProcess::Delete(ErrorOr<VoidPtr> ptr, const SizeT& sz)
- {
- if (!ptr ||
- sz == 0)
- return No;
-
- UserProcessHeapList* entry = this->MemoryHeap;
-
- while (entry != nullptr)
- {
- if (entry->MemoryEntry == ptr.Leak().Leak())
- {
-#ifdef __ZKA_AMD64__
- auto pd = hal_read_cr3();
- hal_write_cr3(this->VMRegister);
-
- auto ret = mm_delete_heap(entry->MemoryEntry);
-
- hal_write_cr3(pd);
-
- return ret;
-#else
- Bool ret = mm_delete_heap(ptr);
- return ret;
-#endif
- }
-
- entry = entry->MemoryNext;
- }
-
- return No;
- }
-
- /***********************************************************************************/
/// @brief Gets the name of the current process.
/***********************************************************************************/
diff --git a/dev/ZKAKit/src/Utils.cc b/dev/ZKAKit/src/Utils.cc
index 412e4a45..d6657680 100644
--- a/dev/ZKAKit/src/Utils.cc
+++ b/dev/ZKAKit/src/Utils.cc
@@ -211,12 +211,13 @@ namespace Kernel
}
} // namespace Kernel
-EXTERN_C void* memset(void* dst, int c, __SIZE_TYPE__ len)
+EXTERN_C void* memset(void* dst, int c, long long unsigned int len)
{
return Kernel::rt_set_memory(dst, c, len);
}
-EXTERN_C __UINT32_TYPE__ memcpy(void* dst, void* src, __SIZE_TYPE__ len)
+EXTERN_C void* memcpy(void* dst, const void* src, long long unsigned int len)
{
- return Kernel::rt_copy_memory(src, dst, len);
+ Kernel::rt_copy_memory(const_cast<void*>(src), dst, len);
+ return dst;
}