aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmulatedSeasons <89668582+EmulatedSeasons@users.noreply.github.com>2024-05-05 03:36:30 -0400
committerEmulatedSeasons <89668582+EmulatedSeasons@users.noreply.github.com>2024-05-06 02:27:20 -0400
commit982baec992d48343e455bf6e32ca96fbdcddda01 (patch)
treef5ac833e239d56871b997f9027db00d96cbbb667
parent4aa74dbe2a35a45668b33d688f17b680c2232572 (diff)
liminefied x86_64 boot
-rw-r--r--.gitignore1
-rw-r--r--kernel/arch/x86_64/crti.asm12
-rw-r--r--kernel/arch/x86_64/crtn.asm9
-rw-r--r--kernel/arch/x86_64/limine.cpp68
-rw-r--r--kernel/kernel.cpp12
5 files changed, 75 insertions, 27 deletions
diff --git a/.gitignore b/.gitignore
index be76e0b..ce75dcb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,7 @@
# directories that have to exist but shouldn't be added to git
sysroot/
build/
+isodir/
# compiled files files
*.bin
diff --git a/kernel/arch/x86_64/crti.asm b/kernel/arch/x86_64/crti.asm
deleted file mode 100644
index 73ac499..0000000
--- a/kernel/arch/x86_64/crti.asm
+++ /dev/null
@@ -1,12 +0,0 @@
-; x86 crti.asm
-section .init
-global _init:function
-_init:
- push rbp
- mov rbp, rsp
-
-section .fini
-global _fini:function
-_fini:
- push rbp
- mov rbp, rsp \ No newline at end of file
diff --git a/kernel/arch/x86_64/crtn.asm b/kernel/arch/x86_64/crtn.asm
deleted file mode 100644
index 322b3a2..0000000
--- a/kernel/arch/x86_64/crtn.asm
+++ /dev/null
@@ -1,9 +0,0 @@
-; x86 crtn.asm
-
-section .init
- pop rbp
- ret
-
-section .fini
- pop rbp
- ret \ No newline at end of file
diff --git a/kernel/arch/x86_64/limine.cpp b/kernel/arch/x86_64/limine.cpp
new file mode 100644
index 0000000..84f8642
--- /dev/null
+++ b/kernel/arch/x86_64/limine.cpp
@@ -0,0 +1,68 @@
+#include <cstddef>
+#include <stdint.h>
+#include <stddef.h>
+#include "limine.h"
+
+namespace {
+__attribute__((used, section(".requests")))
+volatile LIMINE_BASE_REVISION(2);
+}
+
+namespace {
+__attribute__((used, section(".requests")))
+volatile limine_framebuffer_request framebuffer_request = {
+ .id = LIMINE_FRAMEBUFFER_REQUEST,
+ .revision = 0,
+ .response = nullptr
+};
+}
+
+namespace {
+__attribute__((used, section(".requests_start_marker")))
+volatile LIMINE_REQUESTS_START_MARKER;
+
+__attribute__((used, section(".requests_end_marker")))
+volatile LIMINE_REQUESTS_END_MARKER;
+}
+
+namespace {
+void hcf() {
+ asm("cli");
+ for (;;) {
+ asm("hlt");
+ }
+}
+}
+
+extern void (*__init_array[])();
+extern void (*__init_array_end[])();
+
+
+extern "C" void _start() {
+ if (!LIMINE_BASE_REVISION_SUPPORTED) {
+ hcf();
+ }
+
+ // initialize global constructors
+ for (size_t i = 0; &__init_array[i] != __init_array_end; i++) {
+ __init_array[i]();
+ }
+
+ // Ensure we got a framebuffer.
+ if (framebuffer_request.response == nullptr
+ || framebuffer_request.response->framebuffer_count < 1) {
+ hcf();
+ }
+
+ // Fetch the first framebuffer.
+ limine_framebuffer *framebuffer = framebuffer_request.response->framebuffers[0];
+
+ // Note: we assume the framebuffer model is RGB with 32-bit pixels.
+ for (std::size_t i = 0; i < 100; i++) {
+ volatile uint32_t *fb_ptr = static_cast<volatile uint32_t *>(framebuffer->address);
+ fb_ptr[i * (framebuffer->pitch / 4) + i] = 0xffffff;
+ }
+
+ // We're done, just hang...
+ hcf();
+} \ No newline at end of file
diff --git a/kernel/kernel.cpp b/kernel/kernel.cpp
index a877be2..f8f36b5 100644
--- a/kernel/kernel.cpp
+++ b/kernel/kernel.cpp
@@ -3,9 +3,9 @@
#include <stdint.h>
#include <stdio.h>
-#include <arch/i386/tmtty.h>
-#include <arch/i386/ps2_controller.h>
-#include <dev/ps2kbd.h>
+//#include <arch/i386/tmtty.h>
+//#include <arch/i386/ps2_controller.h>
+//#include <dev/ps2kbd.h>
// linker symbols
unsigned int _kernel_begin;
@@ -19,7 +19,7 @@ extern "C" void kernel_main(void) {
//initialize_ps2_controller();
//keyboard_init();
- printf("Hello world!\n");
- printf("a%db\n", 1);
- printf("_begin: %x, _end: %x", &_kernel_begin, &_kernel_end);
+ //printf("Hello world!\n");
+ //printf("a%db\n", 1);
+ //printf("_begin: %x, _end: %x", &_kernel_begin, &_kernel_end);
}