diff options
Diffstat (limited to 'dev/crt/src/hal')
| -rw-r--r-- | dev/crt/src/hal/x86/base_alloc.cxx | 55 | ||||
| -rw-r--r-- | dev/crt/src/hal/x86/exit.cxx | 19 |
2 files changed, 74 insertions, 0 deletions
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;
+}
|
