summaryrefslogtreecommitdiffhomepage
path: root/dev/crt/src
diff options
context:
space:
mode:
Diffstat (limited to 'dev/crt/src')
-rw-r--r--dev/crt/src/alloca.cxx9
-rw-r--r--dev/crt/src/base_exception.cxx (renamed from dev/crt/src/crt_lib.cxx)4
-rw-r--r--dev/crt/src/new+delete.cxx52
3 files changed, 61 insertions, 4 deletions
diff --git a/dev/crt/src/alloca.cxx b/dev/crt/src/alloca.cxx
new file mode 100644
index 00000000..d2f684b3
--- /dev/null
+++ b/dev/crt/src/alloca.cxx
@@ -0,0 +1,9 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <crt/alloca.hxx>
+
+/// @note Just here for building.
diff --git a/dev/crt/src/crt_lib.cxx b/dev/crt/src/base_exception.cxx
index 530e40db..a8a43ac7 100644
--- a/dev/crt/src/crt_lib.cxx
+++ b/dev/crt/src/base_exception.cxx
@@ -4,10 +4,6 @@
------------------------------------------- */
-#include <crt/alloca.hxx>
-#include <crt/defines.hxx>
#include <crt/base_exception.hxx>
-#include <crt/math.hxx>
-#include <crt/base_alloc.hxx>
/// @note Just here for building.
diff --git a/dev/crt/src/new+delete.cxx b/dev/crt/src/new+delete.cxx
new file mode 100644
index 00000000..1241bf66
--- /dev/null
+++ b/dev/crt/src/new+delete.cxx
@@ -0,0 +1,52 @@
+/* -------------------------------------------
+
+ 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));
+}