diff options
Diffstat (limited to 'dev')
| -rw-r--r-- | dev/crt/base_exception.hxx | 7 | ||||
| -rw-r--r-- | dev/crt/crtx64.json (renamed from dev/crt/crt.json) | 4 | ||||
| -rw-r--r-- | dev/crt/defines.hxx | 1 | ||||
| -rw-r--r-- | dev/crt/src/hal/x86/base_alloc.cxx | 55 | ||||
| -rw-r--r-- | dev/crt/src/hal/x86/exit.cxx | 19 | ||||
| -rw-r--r-- | dev/crt/src/new+delete.cxx | 52 | ||||
| -rw-r--r-- | dev/zba/amd64-efi.make | 2 |
7 files changed, 84 insertions, 56 deletions
diff --git a/dev/crt/base_exception.hxx b/dev/crt/base_exception.hxx index e73ac11b..e4ee3487 100644 --- a/dev/crt/base_exception.hxx +++ b/dev/crt/base_exception.hxx @@ -9,7 +9,6 @@ #include <crt/defines.hxx> #include <crt/exit.hxx> -/// @brief Standard C++ namespace namespace std { inline void __throw_general(void) @@ -23,6 +22,12 @@ namespace std __builtin_unreachable(); // prevent from continuing. } + inline void __throw_bad_alloc(void) + { + __throw_general(); + __builtin_unreachable(); // prevent from continuing. + } + inline void __throw_bad_array_new_length(void) { __throw_general(); diff --git a/dev/crt/crt.json b/dev/crt/crtx64.json index fbd54bf8..3e321e5d 100644 --- a/dev/crt/crt.json +++ b/dev/crt/crtx64.json @@ -2,8 +2,8 @@ "compiler_path": "x86_64-w64-mingw32-g++", "compiler_std": "c++20", "headers_path": ["../", "./"], - "sources_path": ["src/*.cxx"], - "output_name": "crt.dll", + "sources_path": ["src/*.cxx", "src/hal/x86/*.cxx"], + "output_name": "crtx64.dll", "compiler_flags": [ "-ffreestanding", "-shared", diff --git a/dev/crt/defines.hxx b/dev/crt/defines.hxx index 5636c337..73422165 100644 --- a/dev/crt/defines.hxx +++ b/dev/crt/defines.hxx @@ -79,6 +79,7 @@ typedef union double_cast { #endif // ifdef __STD_CXX__ +/// @brief Standard C++ namespace. namespace std { /// @brief Forward object. diff --git a/dev/crt/src/hal/x86/base_alloc.cxx b/dev/crt/src/hal/x86/base_alloc.cxx new file mode 100644 index 00000000..effb6c94 --- /dev/null +++ b/dev/crt/src/hal/x86/base_alloc.cxx @@ -0,0 +1,55 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include <crt/base_alloc.hxx> +#include <crt/base_exception.hxx> + +#define kAllocSyscallId "mov $10, %%r9\n\t" +#define kFreeSyscallId "mov $11, %%r9\n\t" + +void* operator new(size_t length) +{ + void* ptr = nullptr; + + // do syscall according to PEF convention. + asm("mov %0, %%r8\n\t" kAllocSyscallId + "syscall" + : "=r"(ptr)); + + if (!ptr) + std::__throw_bad_alloc(); + + return ptr; +} + +void* operator new[](size_t length) +{ + ptr_type ptr = nullptr; + + // do syscall according to PEF convention. + asm("mov %0, %%r8\n\t" kAllocSyscallId + "syscall" + : "=r"(ptr)); + + if (!ptr) + std::__throw_bad_alloc(); + + return ptr; +} + +void operator delete(void* ptr) noexcept +{ + asm("mov %0, %%r8\n\t" kFreeSyscallId + "syscall" + : "=r"(ptr)); +} + +void operator delete[](void* ptr) noexcept +{ + asm("mov %0, %%r8\n\t" kFreeSyscallId + "syscall" + : "=r"(ptr)); +} diff --git a/dev/crt/src/hal/x86/exit.cxx b/dev/crt/src/hal/x86/exit.cxx new file mode 100644 index 00000000..d593adf9 --- /dev/null +++ b/dev/crt/src/hal/x86/exit.cxx @@ -0,0 +1,19 @@ +/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <crt/exit.hxx>
+
+#define kAllocSyscallId "mov $12, %%r9\n\t"
+
+/// @note Just here for building.
+extern "C" int exit(int code)
+{
+ asm("mov 0, %%r8\n\t" kAllocSyscallId
+ "syscall"
+ : "=r"(code));
+
+ return 1;
+}
diff --git a/dev/crt/src/new+delete.cxx b/dev/crt/src/new+delete.cxx deleted file mode 100644 index 1241bf66..00000000 --- a/dev/crt/src/new+delete.cxx +++ /dev/null @@ -1,52 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include <crt/base_alloc.hxx> - -#define kAllocSyscallId "mov $10, %%r9\n\t" -#define kFreeSyscallId "mov $11, %%r9\n\t" - -void* operator new(size_t length) -{ - void* ptr = nullptr; - - // do syscall according to PEF convention. - asm ("mov %0, %%r8\n\t" - kAllocSyscallId - "syscall" - : "=r" (ptr)); - - return ptr; -} - -void* operator new[](size_t length) -{ - ptr_type ptr = nullptr; - - // do syscall according to PEF convention. - asm ("mov %0, %%r8\n\t" - kAllocSyscallId - "syscall" - : "=r" (ptr)); - - return ptr; -} - -void operator delete(void* ptr) noexcept -{ - asm ("mov %0, %%r8\n\t" - kFreeSyscallId - "syscall" - : "=r" (ptr)); -} - -void operator delete[](void* ptr) noexcept -{ - asm ("mov %0, %%r8\n\t" - kFreeSyscallId - "syscall" - : "=r" (ptr)); -} diff --git a/dev/zba/amd64-efi.make b/dev/zba/amd64-efi.make index 7bf3ceaa..e1a212ef 100644 --- a/dev/zba/amd64-efi.make +++ b/dev/zba/amd64-efi.make @@ -55,7 +55,7 @@ BOOT_LOADER=newosldr.exe KERNEL=minoskrnl.exe DDK=ddk.dll SCI=sci.dll -CRT=crt.dll +CRT=crtx64.dll SYS_CHK=syschk.sys STARTUP=startup.sys |
