summaryrefslogtreecommitdiffstats
path: root/arch/x86_64
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2026-10-16 16:42:22 -0400
committerJon Santmyer <jon@jonsantmyer.com>2026-10-16 16:42:22 -0400
commitd8aca3ff2501f9a77e22e5afb7a30380aed205af (patch)
treea27db1749a35aea07317406f170a2d9b2a799ce7 /arch/x86_64
parent548506392b789f58b1556a6ffca917441e1d89fd (diff)
downloadjove-kernel-d8aca3ff2501f9a77e22e5afb7a30380aed205af.tar.gz
jove-kernel-d8aca3ff2501f9a77e22e5afb7a30380aed205af.tar.bz2
jove-kernel-d8aca3ff2501f9a77e22e5afb7a30380aed205af.zip
remove explicit framebuffer in kernel. reduce locking in syscalls
Diffstat (limited to 'arch/x86_64')
-rw-r--r--arch/x86_64/boot/limine/framebuffer.c51
-rw-r--r--arch/x86_64/debug/debug.c10
-rw-r--r--arch/x86_64/debug/printf.c20
-rw-r--r--arch/x86_64/hal/gdt.c2
-rw-r--r--arch/x86_64/hal/idt.c3
-rw-r--r--arch/x86_64/hal/serial_com.c26
-rw-r--r--arch/x86_64/hal/serial_com.h8
-rw-r--r--arch/x86_64/hal/smp.c9
-rw-r--r--arch/x86_64/lib/printf.c25
-rw-r--r--arch/x86_64/main.c18
-rw-r--r--arch/x86_64/proc/init.c15
-rw-r--r--arch/x86_64/proc/scheduler.c9
-rw-r--r--arch/x86_64/sys/syscall.c6
-rw-r--r--arch/x86_64/sys/syscall_serial.c33
14 files changed, 73 insertions, 162 deletions
diff --git a/arch/x86_64/boot/limine/framebuffer.c b/arch/x86_64/boot/limine/framebuffer.c
deleted file mode 100644
index 637a7fc..0000000
--- a/arch/x86_64/boot/limine/framebuffer.c
+++ /dev/null
@@ -1,51 +0,0 @@
-#include "arch/x86_64/hal/paging.h"
-#include "jove.h"
-#include "config.h"
-#include "hal/framebuffer.h"
-#include "lib/string.h"
-#include "lib/printf.h"
-
-/*We don't know the size of the framebuffer until runtime, but at the same
- * time we don't want to dynamically allocate from physical memory. In this
- * case we allocate memory for the maximum supported framebuffer at compile
- * time and only use what we need at runtime.*/
-#define FRAMEBUFFER_MAX_BYTES (FRAMEBUFFER_MAX_WIDTH * FRAMEBUFFER_MAX_WIDTH * 4)
-#define FRAMEBUFFER_MAX_PAGES ((FRAMEBUFFER_MAX_BYTES + 4095) / 0x1000)
-#define FRAMEBUFFER_MAX_HUGEPAGES ((FRAMEBUFFER_MAX_PAGES + 511) / 512)
-#define FRAMEBUFFER_MAX_GIANTPAGES ((FRAMEBUFFER_MAX_HUGEPAGES + 511) / 512)
-
-PAGEALIGN static page_t fb_pages[FRAMEBUFFER_MAX_GIANTPAGES + FRAMEBUFFER_MAX_HUGEPAGES][512];
-
-extern page_t _kernel_pml4[512];
-
-void*
-fb_remap(uintptr_t fb_address,
- size_t fb_bytes)
-{
- fb_address &= ~IDENT_VIRT_BASE;
- size_t fb_numpages = (fb_bytes + 4095) >> 12;
-
- if(fb_numpages > FRAMEBUFFER_MAX_PAGES) {
- kprintf("Framebuffer is too big! Please recompile the kernel with a bigger framebuffer allowance!");
- return NULL;
- }
-
- uintptr_t vptr = IDENT_VIRT_BASE | (511ULL << PMLI_SHL(3));
- size_t last_table = 0;
- for(size_t page = 0; page < fb_numpages; page++) {
- uintptr_t frame = fb_address + (page << 12);
- uintptr_t frame_virt = vptr + (page << 12);
-
- int tblres = 0;
- do {
- uintptr_t tbl_frame = KPTR_TOPHYS(&fb_pages[last_table++]);
- tblres = pagedir_map_table(_kernel_pml4, tbl_frame, frame_virt);
- if(tblres == EHASMAP) last_table--;
- } while(tblres == 0);
-
- pagedir_map_frame(_kernel_pml4, frame, frame_virt,
- PAGE_GLOBAL | PAGE_WRITEABLE | PAGE_XD);
- }
-
- return (void*)vptr;
-}
diff --git a/arch/x86_64/debug/debug.c b/arch/x86_64/debug/debug.c
new file mode 100644
index 0000000..5b2c918
--- /dev/null
+++ b/arch/x86_64/debug/debug.c
@@ -0,0 +1,10 @@
+#include "debug/debug.h"
+#include "arch/x86_64/hal/serial_com.h"
+
+void _debug_init_arch(void)
+{
+ #ifdef DEBUG_SERIAL
+ _debug_has_output = true;
+ serial_com_init();
+ #endif
+}
diff --git a/arch/x86_64/debug/printf.c b/arch/x86_64/debug/printf.c
new file mode 100644
index 0000000..13737b9
--- /dev/null
+++ b/arch/x86_64/debug/printf.c
@@ -0,0 +1,20 @@
+#include "lib/printf.h"
+#include "../hal/serial_com.h"
+#include "api/error.h"
+#include "debug/debug.h"
+
+int
+kvprintf(const char *fmt, va_list ap)
+{
+ if(!_debug_has_output) return -EBADCALL;
+
+ char buffer[256] = { 0 };
+ int r = vsnprintf(buffer, 256, fmt, ap);
+ int wlen = (r > 256 ? 256 : r);
+
+#ifdef DEBUG_SERIAL
+ serial_com_write(SERIAL_COM1, buffer, wlen);
+#endif
+
+ return r;
+}
diff --git a/arch/x86_64/hal/gdt.c b/arch/x86_64/hal/gdt.c
index fc7aa8b..8bfe942 100644
--- a/arch/x86_64/hal/gdt.c
+++ b/arch/x86_64/hal/gdt.c
@@ -63,7 +63,7 @@ gdt_setup(processor_t *processor)
load_gdt(&gdtr);
uintptr_t tss_base = (uintptr_t)&processor->tss;
- size_t tss_limit = sizeof(struct tss);
+ size_t tss_limit = sizeof(struct tss) + 0x2000;
struct gdt_entry *tss_lo = &processor->gdt[GDT_TSS_LO];
struct gdt_entry *tss_hi = &processor->gdt[GDT_TSS_HI];
diff --git a/arch/x86_64/hal/idt.c b/arch/x86_64/hal/idt.c
index ff7a8a0..7b8bd52 100644
--- a/arch/x86_64/hal/idt.c
+++ b/arch/x86_64/hal/idt.c
@@ -20,8 +20,7 @@ struct int_user_handle __int_user_handles[IDT_ENTRIES];
static struct int_stackframe*
s_int_handle_stub(struct int_stackframe* frame)
{
- kprintf("Unhandled interrupt %i at %p\n", frame->int_num, frame->int_rip);
- hcf();
+ kpanic_istate(frame, "Unhandled interrupt %i at %p\n", frame->int_num, frame->int_rip);
}
struct int_stackframe*
diff --git a/arch/x86_64/hal/serial_com.c b/arch/x86_64/hal/serial_com.c
index 372a433..c571057 100644
--- a/arch/x86_64/hal/serial_com.c
+++ b/arch/x86_64/hal/serial_com.c
@@ -1,10 +1,8 @@
+#ifdef DEBUG_SERIAL
+
#include "serial_com.h"
#include "port.h"
#include "jove.h"
-#include "hal/obj.h"
-#include "proc/init.h"
-#include "lib/printf.h"
-#include "sys/objdir.h"
static int
serial_com_recv(uint16_t port)
@@ -67,27 +65,15 @@ serial_com_init(void)
if(serial_com_init_port(SERIAL_COM1, 3)) {
return;
}
-
- {
- jove_owned_obj_t *com_obj = objdir_getlocal(_rootdir_obj, INIT_ROOTDIR_SERIAL_COM_I);
- obj_settype(com_obj, JOVE_OBJ_SERIAL_COM);
- obj_setvalue(com_obj, SERIAL_COM1);
- obj_release(com_obj);
- }
-
- kprintf("Initialized COM1 on port %X for obj %X\n", SERIAL_COM1, INIT_ROOTDIR_SERIAL_COM_I);
}
int
-serial_com_write(
- jove_owned_obj_t *obj,
- const char *s, size_t len)
+serial_com_write(uint16_t port, const char *s, size_t len)
{
- if(obj_gettype(obj) != JOVE_OBJ_SERIAL_COM) {
- reterr(EBADOBJ);
- }
for(size_t i = 0; i < len; i++) {
- serial_com_putc((uint16_t)obj_getvalue(obj), s[i]);
+ serial_com_putc(port, s[i]);
}
return len;
}
+
+#endif
diff --git a/arch/x86_64/hal/serial_com.h b/arch/x86_64/hal/serial_com.h
index 2dbb0cd..cf0badc 100644
--- a/arch/x86_64/hal/serial_com.h
+++ b/arch/x86_64/hal/serial_com.h
@@ -2,7 +2,7 @@
#define _JOVE_SERIAL_COM_H 1
#include <stdint.h>
-#include "obj.h"
+#include <stddef.h>
#define SERIAL_COM1 0x3F8
@@ -19,8 +19,12 @@
#define SERIAL_COM_DLAB_BAUD_LO(com) (com)
#define SERIAL_COM_DLAB_BAUD_HI(com) (com + 1)
+#ifdef DEBUG_SERIAL
+
void serial_com_init(void);
-int serial_com_write(jove_owned_obj_t *obj, const char *s, size_t len);
+int serial_com_write(uint16_t port, const char *s, size_t len);
+
+#endif
#endif
diff --git a/arch/x86_64/hal/smp.c b/arch/x86_64/hal/smp.c
index 7d94340..931a89f 100644
--- a/arch/x86_64/hal/smp.c
+++ b/arch/x86_64/hal/smp.c
@@ -45,15 +45,14 @@ smp_init_bsp(void)
processor_t *bsp = &s_processors[0];
{
- jove_owned_obj_t *processor_objdir_obj = objdir_getlocal(_rootdir_obj, INIT_ROOTDIR_PROCESSORS_I);
- obj_settype(processor_objdir_obj, JOVE_OBJ_OBJDIR);
- obj_setvalue(processor_objdir_obj, (uintptr_t)&s_processor_objdir);
+ jove_owned_obj_t *processor_objdir = objdir_getlocal(_rootdir_obj, INIT_ROOTDIR_PROCESSORS_I);
+ obj_settype(processor_objdir, JOVE_OBJ_OBJDIR);
+ obj_setvalue(processor_objdir, (uintptr_t)&s_processor_objdir);
+ jove_obj_t *processor_objdir_obj = obj_release(processor_objdir);
jove_owned_obj_t *bsp_obj = objdir_getlocal(processor_objdir_obj, 0);
init_processor(bsp, bsp_obj);
-
obj_release(bsp_obj);
- obj_release(processor_objdir_obj);
}
idt_init();
diff --git a/arch/x86_64/lib/printf.c b/arch/x86_64/lib/printf.c
deleted file mode 100644
index db47f6b..0000000
--- a/arch/x86_64/lib/printf.c
+++ /dev/null
@@ -1,25 +0,0 @@
-#include "../hal/serial_com.h"
-#include "lib/printf.h"
-#include "lib/virtterm.h"
-#include "proc/init.h"
-#include "sys/objdir.h"
-
-int
-kvprintf(const char *fmt, va_list ap)
-{
- char buffer[256] = { 0 };
- int r = vsnprintf(buffer, 256, fmt, ap);
- int wlen = (r > 256 ? 256 : r);
-
- {
- jove_owned_obj_t *serial_obj = objdir_getlocal(_rootdir_obj, INIT_ROOTDIR_SERIAL_COM_I);
- serial_com_write(serial_obj, buffer, wlen);
- obj_release(serial_obj);
-
- jove_owned_obj_t *vt_obj = objdir_getlocal(_rootdir_obj, INIT_ROOTDIR_VIRTTERM_I);
- vt_write(vt_obj, buffer, wlen);
- obj_release(vt_obj);
- }
-
- return r;
-}
diff --git a/arch/x86_64/main.c b/arch/x86_64/main.c
index 4a40707..4317c46 100644
--- a/arch/x86_64/main.c
+++ b/arch/x86_64/main.c
@@ -3,17 +3,15 @@
#include "proc/init.h"
#include "lib/string.h"
#include "lib/printf.h"
-#include "lib/virtterm.h"
#include "panic/panic.h"
#include "../../hal/obj.h"
#include "hal/msr.h"
#include "hal/serial_com.h"
#include "hal/smp.h"
#include "hal/memory.h"
-#include "hal/framebuffer.h"
#include "proc/process.h"
-#include "boot/initrd.h"
-#include "boot/cmdline.h"
+#include "boot/boot.h"
+#include "debug/debug.h"
int errno = 0;
@@ -27,22 +25,20 @@ static void kernel_process_entry(void);
void
kernel_entry(void)
{
+ debug_init();
+
memset(&_rootdir, 0, 0x1000);
obj_take(_rootdir_obj);
obj_settype(_rootdir_obj, JOVE_OBJ_OBJDIR);
obj_setvalue(_rootdir_obj, (uintptr_t)&_rootdir);
+ obj_release(_rootdir_obj);
msr_enable_sse();
- obj_settype(_rootdir_obj, JOVE_OBJ_OBJDIR);
- serial_com_init();
-
smp_init_bsp();
- mem_setup_regions();
- initrd_setup();
- fb_init();
- vt_init();
+ mem_setup_modules();
+ mem_setup_regions();
cmdline_print();
diff --git a/arch/x86_64/proc/init.c b/arch/x86_64/proc/init.c
index 8003a6d..6c5c36e 100644
--- a/arch/x86_64/proc/init.c
+++ b/arch/x86_64/proc/init.c
@@ -11,8 +11,7 @@
#include "lib/printf.h"
#include "arch/x86_64/lib/elf.h"
#include "arch/x86_64/hal/paging.h"
-#include "boot/cmdline.h"
-#include "boot/initrd.h"
+#include "boot/boot.h"
static int
elf_is_valid(struct elf_header *ehdr)
@@ -52,15 +51,13 @@ init_setup(void)
kpanic("Kernel commandline is missing 'init' arg.\n");
}
- jove_owned_obj_t *initrd_obj = objdir_getlocal(_rootdir_obj, INIT_ROOTDIR_INITRD_I);
- jove_owned_obj_t *init_obj = initrd_seek(initrd_obj, init_path);
- if(init_obj == NULL) {
- kpanic("init: Cannot find file '%s' in initrd.\n", init_path);
+ jove_owned_obj_t *init_obj = boot_getmodule(init_path);
+ if(init_obj == 0) {
+ kpanic("Unable to get module %s : %s\n", init_path, errstr(errno));
}
- obj_release(initrd_obj);
- void *init_data = initrd_file_data(init_obj);
- obj_release(init_obj);
+ void *init_data = shmem_deref(init_obj);
+ kprintf("Found init at %p\n", init_data);
struct elf_header *init_ehdr = init_data;
if(init_ehdr == NULL) {
diff --git a/arch/x86_64/proc/scheduler.c b/arch/x86_64/proc/scheduler.c
index 49a0c4d..6c748c7 100644
--- a/arch/x86_64/proc/scheduler.c
+++ b/arch/x86_64/proc/scheduler.c
@@ -1,5 +1,7 @@
#include "proc/scheduler.h"
#include "arch/x86_64/hal/gdt.h"
+#include "arch/x86_64/hal/obj.h"
+#include "lib/printf.h"
#include "lib/string.h"
#include "process.h"
#include "../hal/smp.h"
@@ -12,10 +14,15 @@ _scheduler_switch_pcb_arch(pcb_t *target)
proc->syscall_page = target->interrupt_page;
proc->interrupt_page = target->interrupt_page;
+ proc->tss.rsp[0] = __interrupt_stack + 0xFF8;
+
if(target->iopb) {
proc->tss.iopb = sizeof(struct tss);
jove_owned_obj_t *iopb_obj = obj_take(target->iopb);
- memcpy(proc->iopb, obj_deref(iopb_obj), sizeof(proc->iopb));
+ if(obj_gettype(iopb_obj) != JOVE_OBJ_IOPB) {
+ memcpy(proc->iopb, obj_deref(iopb_obj), sizeof(proc->iopb));
+ }
+ obj_release(iopb_obj);
}else{
proc->tss.iopb = 0xff;
}
diff --git a/arch/x86_64/sys/syscall.c b/arch/x86_64/sys/syscall.c
index 1e06e61..2a5ce08 100644
--- a/arch/x86_64/sys/syscall.c
+++ b/arch/x86_64/sys/syscall.c
@@ -6,7 +6,7 @@
#include "syscall.h"
syscall_handle_t s_arch_handles[128] = {
- [JOVE_OBJ_SERIAL_COM-0x80] = _syscall_handle_serial
+ NULL
};
int
@@ -50,5 +50,7 @@ void _syscall_entry(void)
sysretq"
::
[pcb] "i"(offsetof(processor_t, pcb)),
- [ksp] "i"(offsetof(struct pcb_header, ksp)));
+ [ksp] "i"(offsetof(struct pcb_header, ksp))
+ : "memory");
}
+
diff --git a/arch/x86_64/sys/syscall_serial.c b/arch/x86_64/sys/syscall_serial.c
deleted file mode 100644
index 786a78b..0000000
--- a/arch/x86_64/sys/syscall_serial.c
+++ /dev/null
@@ -1,33 +0,0 @@
-#include "jove.h"
-#include "lib/printf.h"
-#include "sys/syscall.h"
-#include "syscall.h"
-#include "arch/x86_64/hal/serial_com.h"
-
-static int
-s_syscall_serial_write(
- jove_owned_obj_t *serial_com,
- size_t payload_bytes,
- void *payload_data)
-{
- size_t bytes_needed = sizeof(struct syscall_generic_write);
- CHECK_TOOSMALL(bytes_needed, payload_bytes, "Message is too small for this syscall!");
-
- struct syscall_generic_write *payload = payload_data;
- bytes_needed += payload->len * 2;
- CHECK_TOOSMALL(bytes_needed, payload_bytes, "Message is too small for write buffer!");
-
- return serial_com_write(serial_com, payload->data, payload->len);
-}
-
-int
-_syscall_handle_serial(syscall_context_t *ctx)
-{
- switch(ctx->header->callid) {
- case SYSCALL_SERIAL_COM_WRITE:
- return s_syscall_serial_write(ctx->target.obj, ctx->bytes_left, ctx->payload);
- default:
- kprintf("syscall_serial: serial com object does not support syscall %i\n", ctx->header->callid);
- return -EBADCALL;
- }
-}