summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/cxx/constructors.cxx18
-rw-r--r--kernel/cxx/gcc_required_functions.cxx1
-rw-r--r--kernel/cxx/icxxabi.cxx0
-rw-r--r--kernel/cxx/icxxabi.h0
-rw-r--r--kernel/entry.cxx49
-rw-r--r--kernel/ldscript69
6 files changed, 137 insertions, 0 deletions
diff --git a/kernel/cxx/constructors.cxx b/kernel/cxx/constructors.cxx
new file mode 100644
index 0000000..8c21453
--- /dev/null
+++ b/kernel/cxx/constructors.cxx
@@ -0,0 +1,18 @@
+extern void (*_ctors_start[0])(void), (*_ctors_end[0])(void);
+extern void (*_dtors_start[0])(void), (*_dtors_end[0])(void);
+
+void init (void)
+{
+ for (void (**ctor)(void) = _ctors_start; ctor != _ctors_end; ctor++)
+ {
+ (*ctor)();
+ }
+}
+
+void fini (void)
+{
+ for (void (**dtor)(void) = _dtors_start; dtor != _dtors_end; dtor++)
+ {
+ (*dtor)();
+ }
+}
diff --git a/kernel/cxx/gcc_required_functions.cxx b/kernel/cxx/gcc_required_functions.cxx
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/kernel/cxx/gcc_required_functions.cxx
@@ -0,0 +1 @@
+
diff --git a/kernel/cxx/icxxabi.cxx b/kernel/cxx/icxxabi.cxx
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/kernel/cxx/icxxabi.cxx
diff --git a/kernel/cxx/icxxabi.h b/kernel/cxx/icxxabi.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/kernel/cxx/icxxabi.h
diff --git a/kernel/entry.cxx b/kernel/entry.cxx
new file mode 100644
index 0000000..b5bc210
--- /dev/null
+++ b/kernel/entry.cxx
@@ -0,0 +1,49 @@
+#include "../vendor/limine/limine.h"
+#include <cstdint>
+
+__attribute__ ((used, section(".requests")))
+static volatile LIMINE_BASE_REVISION(3);
+
+__attribute__ ((used, section(".requests")))
+static volatile limine_framebuffer_request framebuffer_request = {
+ .id = LIMINE_FRAMEBUFFER_REQUEST,
+ .revision = 0,
+ .response = nullptr
+};
+
+__attribute__ ((used, section(".requests_start")))
+static volatile LIMINE_REQUESTS_START_MARKER;
+
+__attribute__ ((used, section(".requests_end")))
+static volatile LIMINE_REQUESTS_END_MARKER;
+
+static void hcf (void)
+{
+ for (;;)
+ {
+ asm ("hlt");
+ }
+}
+
+void init (void);
+
+extern "C" void _launch (void);
+void _launch (void)
+{
+ if (LIMINE_BASE_REVISION_SUPPORTED == false)
+ {
+ hcf();
+ }
+
+ struct limine_framebuffer *fb = framebuffer_request.response->framebuffers[0];
+ for (std::size_t i = 0; i < (fb->width - 1) * (fb->height - 1); i += 2)
+ {
+ volatile std::uint32_t *fbptr = static_cast<std::uint32_t *>(fb->address);
+ fbptr[i] = 0xffffff;
+ }
+
+ // Global C++ constructors
+ init();
+
+ hcf();
+}
diff --git a/kernel/ldscript b/kernel/ldscript
new file mode 100644
index 0000000..2f1e1f4
--- /dev/null
+++ b/kernel/ldscript
@@ -0,0 +1,69 @@
+ENTRY(_launch)
+
+PHDRS
+{
+ text PT_LOAD;
+ rodata PT_LOAD;
+ data PT_LOAD;
+ eh_frame PT_LOAD;
+ dynamic PT_LOAD;
+}
+
+SECTIONS
+{
+ /* Load in upper, you know the drill */
+ . = 0xFFFFFFFF80000000;
+
+ _kernel_start = .;
+
+ .text : {
+ *(.text .text.*)
+ } :text
+
+ . += CONSTANT(MAXPAGESIZE);
+
+ .rodata : {
+ *(.rodata, .rodata.*)
+ *(.srodata, .srodata.*)
+ } :rodata
+
+ .init_array : {
+ _ctors_start = .;
+ KEEP(*(SORT(.init_array.*)))
+ KEEP(*(.init_array))
+ _ctors_end = .;
+ } :rodata
+
+ .fini_array : {
+ _dtors_start = .;
+ KEEP(*(SORT(.fini_array)))
+ KEEP(*(.fini_array))
+ _dtors_end = .;
+ } :rodata
+
+ . += CONSTANT(MAXPAGESIZE);
+
+ .data : {
+ *(.data .data.*)
+ *(.sdata .sdata.*)
+
+ KEEP(*(.requests_start))
+ KEEP(*(.requests))
+ KEEP(*(.requests_end))
+ } :data
+
+ .dynamic : {
+ *(.dynamic)
+ } :data :dynamic
+
+ .bss : {
+ *(.bss .bss.*)
+ *(.sbss .sbss.*)
+ *(COMMON)
+ } :data
+
+ /DISCARD/ : {
+ *(.eh_frame*)
+ *(.note .note.*)
+ }
+}