summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/init.h1
-rw-r--r--api/memory.h28
-rw-r--r--api/syscall.h21
-rw-r--r--arch/x86_64/debug/console.c39
-rw-r--r--arch/x86_64/hal/paging.c18
-rw-r--r--arch/x86_64/hal/serial_com.c16
-rw-r--r--arch/x86_64/hal/serial_com.h3
-rw-r--r--arch/x86_64/proc/process.c2
-rw-r--r--boot/limine/memorymap.c7
-rw-r--r--compile_commands.json331
-rw-r--r--config.mk2
-rw-r--r--debug/console.c116
-rw-r--r--debug/console.h14
-rw-r--r--doc/syscall.md45
-rw-r--r--hal/memory.h8
-rw-r--r--hal/obj.c23
-rw-r--r--hal/obj.h1
-rw-r--r--lib/printf.c5
-rw-r--r--panic/panic.c5
-rw-r--r--sys/syscall_pagedir.c95
20 files changed, 602 insertions, 178 deletions
diff --git a/api/init.h b/api/init.h
index 107ebef..1d6cf4b 100644
--- a/api/init.h
+++ b/api/init.h
@@ -12,7 +12,6 @@ enum {
INIT_ROOTDIR_HWMEMORY_I,
INIT_ROOTDIR_MODULES_I,
INIT_ROOTDIR_INTERRUPTS_I,
- INIT_ROOTDIR_INITRD_I,
INIT_ROOTDIR_MESSAGE_I,
_INIT_ROOTDIR_LAST_I
};
diff --git a/api/memory.h b/api/memory.h
new file mode 100644
index 0000000..d4096e2
--- /dev/null
+++ b/api/memory.h
@@ -0,0 +1,28 @@
+#ifndef _JOVE_API_MEMORY_H
+#define _JOVE_API_MEMORY_H 1
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#define JOVE_USERMEMORY_LIMIT 0x00007FFFFFFFFFFFULL
+
+typedef uintptr_t virtaddr_t;
+typedef uintptr_t physaddr_t;
+
+typedef virtaddr_t virt_frame_t;
+typedef physaddr_t phys_frame_t;
+
+struct pagedir_mapping_flags
+{
+ bool present;
+ bool writeable;
+ bool executable;
+};
+
+struct pagedir_mapping
+{
+ phys_frame_t pfn;
+ struct pagedir_mapping_flags flags;
+};
+
+#endif
diff --git a/api/syscall.h b/api/syscall.h
index 4a5d3e4..a52fa5e 100644
--- a/api/syscall.h
+++ b/api/syscall.h
@@ -3,9 +3,11 @@
#include <stddef.h>
#include <stdint.h>
+#include <stdbool.h>
#include "process.h"
#include "obj.h"
+#include "memory.h"
/* General syscall behavior:
* If the message passed is not a JOVE_OBJ_MESSAGE type, the kernel will return EBADOBJ.
@@ -106,6 +108,8 @@ struct syscall_objdir_link
enum
{
_SYSCALL_PAGEDIR_NONE = 0,
+ SYSCALL_PAGEDIR_GET_MAPPING,
+ SYSCALL_PAGEDIR_TRANSFER,
SYSCALL_PAGEDIR_MAP_FRAME,
SYSCALL_PAGEDIR_MAP_TABLE,
SYSCALL_PAGEDIR_MAP_SHMEM,
@@ -114,6 +118,8 @@ enum
SYSCALL_PAGEDIR_UNMAP_SHMEM,
};
+#define SYSCALL_PERM_PAGEDIR_GET_MAPPING (JOVE_PERM_READ)
+#define SYSCALL_PERM_PAGEDIR_TRANSFER (JOVE_PERM_READ | JOVE_PERM_WRITE)
#define SYSCALL_PERM_PAGEDIR_MAP_FRAME (JOVE_PERM_READ | JOVE_PERM_WRITE)
#define SYSCALL_PERM_PAGEDIR_MAP_TABLE (JOVE_PERM_READ | JOVE_PERM_WRITE)
#define SYSCALL_PERM_PAGEDIR_MAP_SHMEM (JOVE_PERM_READ | JOVE_PERM_WRITE)
@@ -121,17 +127,20 @@ enum
#define SYSCALL_PERM_PAGEDIR_UNMAP_TABLE (JOVE_PERM_READ | JOVE_PERM_WRITE)
#define SYSCALL_PERM_PAGEDIR_UNMAP_SHMEM (JOVE_PERM_READ | JOVE_PERM_WRITE)
-struct syscall_pagedir_flags
+#define SYSCALL_PERM_PAGEDIR_TRANSFER_TGT (SYSCALL_PERM_PAGEDIR_TRANSFER)
+
+struct syscall_pagedir_transfer
{
- uint8_t writeable : 1;
- uint8_t executable : 1;
- uint8_t flg_unused : 6;
+ virtaddr_t subject_address;
+ virtaddr_t target_address;
+ objpath_part_t target_path_length;
+ objpath_part_t target_path[];
};
struct syscall_pagedir_map
{
uintptr_t virtual_address;
- struct syscall_pagedir_flags page_flags;
+ struct pagedir_mapping_flags flags;
objpath_part_t untyped_pathlen;
objpath_part_t untyped_path[];
};
@@ -140,7 +149,7 @@ struct syscall_pagedir_map_shmem
{
uintptr_t virtual_address;
unsigned short page_offset;
- struct syscall_pagedir_flags page_flags;
+ struct pagedir_mapping_flags flags;
objpath_part_t shmem_pathlen;
objpath_part_t shmem_path[];
};
diff --git a/arch/x86_64/debug/console.c b/arch/x86_64/debug/console.c
new file mode 100644
index 0000000..b73e980
--- /dev/null
+++ b/arch/x86_64/debug/console.c
@@ -0,0 +1,39 @@
+#ifdef DEBUG_CONSOLE
+#include "debug/console.h"
+#include "lib/printf.h"
+#include "../hal/serial_com.h"
+
+static char
+s_console_getc(void)
+{
+#ifdef DEBUG_SERIAL
+ char c = serial_com_getc(SERIAL_COM1);
+#endif
+ serial_com_putc(SERIAL_COM1, c);
+ return c;
+}
+
+int
+debug_console_readinput(char *buf, size_t len)
+{
+ serial_com_putc(SERIAL_COM1, '>');
+ char readc;
+ int readw = 0;
+ while((readc = s_console_getc()) != 0xD) {
+ if(readw > len) break;
+ buf[readw++] = readc;
+ }
+ buf[readw] = 0;
+ return readw;
+}
+
+void debug_console_start(void)
+{
+ char input_buffer[128];
+ while(1) {
+ debug_console_readinput(input_buffer, 128);
+ debug_console_parsecmd(input_buffer);
+ }
+}
+
+#endif
diff --git a/arch/x86_64/hal/paging.c b/arch/x86_64/hal/paging.c
index d5bcee3..35d39e2 100644
--- a/arch/x86_64/hal/paging.c
+++ b/arch/x86_64/hal/paging.c
@@ -162,6 +162,16 @@ inline bool pagedir_mapping_is_present(virtaddr_t *mapping)
return ((page_t*)mapping)->p;
}
+inline bool pagedir_mapping_is_writeable(virtaddr_t *mapping)
+{
+ return ((page_t*)mapping)->rw;
+}
+
+inline bool pagedir_mapping_is_executable(virtaddr_t *mapping)
+{
+ return ((page_t*)mapping)->xd;
+}
+
inline void pagedir_mapping_set_pfn(virtaddr_t *mapping, size_t pfn)
{
((page_t*)mapping)->pfn = pfn;
@@ -205,7 +215,7 @@ int pagedir_map_frame(page_t *pml4,
int pagedir_map_frame_type(page_t *pml4,
uintptr_t pptr, uintptr_t vptr,
- struct syscall_pagedir_flags flg, int type)
+ struct pagedir_mapping_flags flg, int type)
{
uintmax_t real_flg = PAGE_USER | (type << PAGE_SHL_TYPE);
if(flg.writeable) {
@@ -219,7 +229,7 @@ int pagedir_map_frame_type(page_t *pml4,
int pagedir_map_untyped_frame(
jove_owned_obj_t *tgt, jove_perm_obj_t *untyped,
- uintptr_t vptr, struct syscall_pagedir_flags flg)
+ uintptr_t vptr, struct pagedir_mapping_flags flg)
{
page_t *pml4 = obj_deref(tgt);
@@ -260,7 +270,7 @@ int pagedir_map_table(page_t *pml4,
target_table = &pml2[pml2i];
goto map_table;
}
- return EHASMAP;
+ return -EHASMAP;
map_table:
memset(frame_ident, 0, 0x1000);
@@ -288,7 +298,7 @@ int pagedir_map_untyped_table(
int pagedir_map_shmem_frame(
jove_owned_obj_t *tgt, jove_perm_obj_t *shmem, uint8_t page_offset,
- uintptr_t vptr, struct syscall_pagedir_flags flg)
+ uintptr_t vptr, struct pagedir_mapping_flags flg)
{
page_t *pml4 = obj_deref(tgt);
diff --git a/arch/x86_64/hal/serial_com.c b/arch/x86_64/hal/serial_com.c
index c571057..ec39d21 100644
--- a/arch/x86_64/hal/serial_com.c
+++ b/arch/x86_64/hal/serial_com.c
@@ -10,26 +10,26 @@ serial_com_recv(uint16_t port)
return inb(SERIAL_COM_LSR(port)) & 1;
}
-static char
-serial_com_getc(uint16_t port)
-{
- while(serial_com_recv(port) == 0);
- return inb(port);
-}
-
static int
serial_com_put_ready(uint16_t port)
{
return inb(SERIAL_COM_LSR(port)) & 0x20;
}
-static void
+void
serial_com_putc(uint16_t port, char c)
{
while(serial_com_put_ready(port) == 0);
outb(port, c);
}
+char
+serial_com_getc(uint16_t port)
+{
+ while(serial_com_recv(port) == 0);
+ return inb(port);
+}
+
int
serial_com_init_port(
uint16_t port,
diff --git a/arch/x86_64/hal/serial_com.h b/arch/x86_64/hal/serial_com.h
index cf0badc..3850a7b 100644
--- a/arch/x86_64/hal/serial_com.h
+++ b/arch/x86_64/hal/serial_com.h
@@ -23,6 +23,9 @@
void serial_com_init(void);
+char serial_com_getc(uint16_t port);
+void serial_com_putc(uint16_t port, char c);
+
int serial_com_write(uint16_t port, const char *s, size_t len);
#endif
diff --git a/arch/x86_64/proc/process.c b/arch/x86_64/proc/process.c
index b10d538..638303c 100644
--- a/arch/x86_64/proc/process.c
+++ b/arch/x86_64/proc/process.c
@@ -17,7 +17,7 @@ PAGEALIGN char _init_pcb_bytes[0x1000] = { 0 };
int
_pcb_new_arch(pcb_t *pcb)
{
- return 0;
+ return pcb->header.pid;
}
void
diff --git a/boot/limine/memorymap.c b/boot/limine/memorymap.c
index 7ce1da8..8fa0279 100644
--- a/boot/limine/memorymap.c
+++ b/boot/limine/memorymap.c
@@ -35,6 +35,11 @@ mem_setup_regions(void)
obj_settype(region_objdir_obj, JOVE_OBJ_OBJDIR);
obj_setvalue(region_objdir_obj, (uintptr_t)&s_region_objdir);
obj_release(region_objdir_obj);
+
+ jove_owned_obj_t *hwmem_objdir_obj = objdir_getlocal(_rootdir_obj, INIT_ROOTDIR_HWMEMORY_I);
+ obj_settype(hwmem_objdir_obj, JOVE_OBJ_OBJDIR);
+ obj_setvalue(hwmem_objdir_obj, (uintptr_t)&s_hwmemory_objdir);
+ obj_release(hwmem_objdir_obj);
}
if(_limine_memmap_resp == NULL) {
@@ -85,7 +90,7 @@ mem_setup_regions(void)
jove_owned_obj_t *hwmem_obj = obj_take(&s_hwmemory_objdir.entries[hwmem_i++]);
obj_settype(hwmem_obj, JOVE_OBJ_SHMEMORY);
- obj_setvalue(hwmem_obj, entry->base | (entry->length >> 12));
+ obj_setvalue(hwmem_obj, base | pages);
obj_release(hwmem_obj);
hw_pages -= 4096;
diff --git a/compile_commands.json b/compile_commands.json
index 9454f3c..2ec111f 100644
--- a/compile_commands.json
+++ b/compile_commands.json
@@ -13,6 +13,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -41,6 +44,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -69,6 +75,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -97,6 +106,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -112,34 +124,6 @@
"output": "boot/cmdline.o"
},
{
- "file": "boot/initrd.c",
- "arguments": [
- "x86_64-jove-gcc",
- "-ffreestanding",
- "-fno-pie",
- "-fno-pic",
- "-g",
- "-MD",
- "-mno-sse",
- "-D__x86_64__",
- "-D__limine__",
- "-Iinclude",
- "-I.",
- "-march=x86-64",
- "-m64",
- "-mno-red-zone",
- "-mno-mmx",
- "-mcmodel=kernel",
- "-mfsgsbase",
- "-c",
- "boot/initrd.c",
- "-o",
- "boot/initrd.o"
- ],
- "directory": "/home/jon/prg/jove/kernel",
- "output": "boot/initrd.o"
- },
- {
"file": "lib/bitmap.c",
"arguments": [
"x86_64-jove-gcc",
@@ -153,6 +137,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -181,6 +168,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -209,6 +199,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -237,6 +230,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -265,6 +261,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -293,6 +292,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -321,6 +323,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -336,7 +341,7 @@
"output": "lib/tar.o"
},
{
- "file": "lib/virtterm.c",
+ "file": "hal/region.c",
"arguments": [
"x86_64-jove-gcc",
"-ffreestanding",
@@ -349,6 +354,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -356,15 +364,15 @@
"-mcmodel=kernel",
"-mfsgsbase",
"-c",
- "lib/virtterm.c",
+ "hal/region.c",
"-o",
- "lib/virtterm.o"
+ "hal/region.o"
],
"directory": "/home/jon/prg/jove/kernel",
- "output": "lib/virtterm.o"
+ "output": "hal/region.o"
},
{
- "file": "hal/region.c",
+ "file": "hal/shmem.c",
"arguments": [
"x86_64-jove-gcc",
"-ffreestanding",
@@ -377,6 +385,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -384,15 +395,15 @@
"-mcmodel=kernel",
"-mfsgsbase",
"-c",
- "hal/region.c",
+ "hal/shmem.c",
"-o",
- "hal/region.o"
+ "hal/shmem.o"
],
"directory": "/home/jon/prg/jove/kernel",
- "output": "hal/region.o"
+ "output": "hal/shmem.o"
},
{
- "file": "hal/shmem.c",
+ "file": "hal/untyped.c",
"arguments": [
"x86_64-jove-gcc",
"-ffreestanding",
@@ -405,6 +416,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -412,15 +426,15 @@
"-mcmodel=kernel",
"-mfsgsbase",
"-c",
- "hal/shmem.c",
+ "hal/untyped.c",
"-o",
- "hal/shmem.o"
+ "hal/untyped.o"
],
"directory": "/home/jon/prg/jove/kernel",
- "output": "hal/shmem.o"
+ "output": "hal/untyped.o"
},
{
- "file": "hal/untyped.c",
+ "file": "proc/init.c",
"arguments": [
"x86_64-jove-gcc",
"-ffreestanding",
@@ -433,6 +447,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -440,15 +457,15 @@
"-mcmodel=kernel",
"-mfsgsbase",
"-c",
- "hal/untyped.c",
+ "proc/init.c",
"-o",
- "hal/untyped.o"
+ "proc/init.o"
],
"directory": "/home/jon/prg/jove/kernel",
- "output": "hal/untyped.o"
+ "output": "proc/init.o"
},
{
- "file": "proc/init.c",
+ "file": "proc/ipc.c",
"arguments": [
"x86_64-jove-gcc",
"-ffreestanding",
@@ -461,6 +478,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -468,12 +488,12 @@
"-mcmodel=kernel",
"-mfsgsbase",
"-c",
- "proc/init.c",
+ "proc/ipc.c",
"-o",
- "proc/init.o"
+ "proc/ipc.o"
],
"directory": "/home/jon/prg/jove/kernel",
- "output": "proc/init.o"
+ "output": "proc/ipc.o"
},
{
"file": "proc/process.c",
@@ -489,6 +509,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -517,6 +540,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -545,6 +571,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -573,6 +602,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -601,6 +633,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -629,6 +664,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -657,6 +695,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -685,6 +726,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -700,34 +744,6 @@
"output": "sys/syscall.o"
},
{
- "file": "sys/syscall_initrd_file.c",
- "arguments": [
- "x86_64-jove-gcc",
- "-ffreestanding",
- "-fno-pie",
- "-fno-pic",
- "-g",
- "-MD",
- "-mno-sse",
- "-D__x86_64__",
- "-D__limine__",
- "-Iinclude",
- "-I.",
- "-march=x86-64",
- "-m64",
- "-mno-red-zone",
- "-mno-mmx",
- "-mcmodel=kernel",
- "-mfsgsbase",
- "-c",
- "sys/syscall_initrd_file.c",
- "-o",
- "sys/syscall_initrd_file.o"
- ],
- "directory": "/home/jon/prg/jove/kernel",
- "output": "sys/syscall_initrd_file.o"
- },
- {
"file": "sys/syscall_message.c",
"arguments": [
"x86_64-jove-gcc",
@@ -741,6 +757,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -769,6 +788,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -797,6 +819,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -825,6 +850,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -853,6 +881,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -881,6 +912,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -896,34 +930,6 @@
"output": "sys/syscall_untyped.o"
},
{
- "file": "sys/syscall_vtt.c",
- "arguments": [
- "x86_64-jove-gcc",
- "-ffreestanding",
- "-fno-pie",
- "-fno-pic",
- "-g",
- "-MD",
- "-mno-sse",
- "-D__x86_64__",
- "-D__limine__",
- "-Iinclude",
- "-I.",
- "-march=x86-64",
- "-m64",
- "-mno-red-zone",
- "-mno-mmx",
- "-mcmodel=kernel",
- "-mfsgsbase",
- "-c",
- "sys/syscall_vtt.c",
- "-o",
- "sys/syscall_vtt.o"
- ],
- "directory": "/home/jon/prg/jove/kernel",
- "output": "sys/syscall_vtt.o"
- },
- {
"file": "panic/panic.c",
"arguments": [
"x86_64-jove-gcc",
@@ -937,6 +943,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -952,7 +961,7 @@
"output": "panic/panic.o"
},
{
- "file": "boot/limine/framebuffer.c",
+ "file": "debug/debug.c",
"arguments": [
"x86_64-jove-gcc",
"-ffreestanding",
@@ -965,6 +974,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -972,12 +984,12 @@
"-mcmodel=kernel",
"-mfsgsbase",
"-c",
- "boot/limine/framebuffer.c",
+ "debug/debug.c",
"-o",
- "boot/limine/framebuffer.o"
+ "debug/debug.o"
],
"directory": "/home/jon/prg/jove/kernel",
- "output": "boot/limine/framebuffer.o"
+ "output": "debug/debug.o"
},
{
"file": "boot/limine/memorymap.c",
@@ -993,6 +1005,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -1008,7 +1023,7 @@
"output": "boot/limine/memorymap.o"
},
{
- "file": "boot/limine/start.c",
+ "file": "boot/limine/modules.c",
"arguments": [
"x86_64-jove-gcc",
"-ffreestanding",
@@ -1021,6 +1036,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -1028,15 +1046,15 @@
"-mcmodel=kernel",
"-mfsgsbase",
"-c",
- "boot/limine/start.c",
+ "boot/limine/modules.c",
"-o",
- "boot/limine/start.o"
+ "boot/limine/modules.o"
],
"directory": "/home/jon/prg/jove/kernel",
- "output": "boot/limine/start.o"
+ "output": "boot/limine/modules.o"
},
{
- "file": "arch/x86_64/lib/printf.c",
+ "file": "boot/limine/start.c",
"arguments": [
"x86_64-jove-gcc",
"-ffreestanding",
@@ -1049,6 +1067,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -1056,12 +1077,12 @@
"-mcmodel=kernel",
"-mfsgsbase",
"-c",
- "arch/x86_64/lib/printf.c",
+ "boot/limine/start.c",
"-o",
- "arch/x86_64/lib/printf.o"
+ "boot/limine/start.o"
],
"directory": "/home/jon/prg/jove/kernel",
- "output": "arch/x86_64/lib/printf.o"
+ "output": "boot/limine/start.o"
},
{
"file": "arch/x86_64/hal/gdt.c",
@@ -1077,6 +1098,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -1105,6 +1129,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -1133,6 +1160,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -1161,6 +1191,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -1189,6 +1222,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -1217,6 +1253,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -1245,6 +1284,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -1273,6 +1315,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -1301,6 +1346,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -1329,6 +1377,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -1357,6 +1408,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -1385,6 +1439,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -1400,34 +1457,6 @@
"output": "arch/x86_64/sys/syscall.o"
},
{
- "file": "arch/x86_64/sys/syscall_serial.c",
- "arguments": [
- "x86_64-jove-gcc",
- "-ffreestanding",
- "-fno-pie",
- "-fno-pic",
- "-g",
- "-MD",
- "-mno-sse",
- "-D__x86_64__",
- "-D__limine__",
- "-Iinclude",
- "-I.",
- "-march=x86-64",
- "-m64",
- "-mno-red-zone",
- "-mno-mmx",
- "-mcmodel=kernel",
- "-mfsgsbase",
- "-c",
- "arch/x86_64/sys/syscall_serial.c",
- "-o",
- "arch/x86_64/sys/syscall_serial.o"
- ],
- "directory": "/home/jon/prg/jove/kernel",
- "output": "arch/x86_64/sys/syscall_serial.o"
- },
- {
"file": "arch/x86_64/panic/panic.c",
"arguments": [
"x86_64-jove-gcc",
@@ -1441,6 +1470,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -1456,7 +1488,7 @@
"output": "arch/x86_64/panic/panic.o"
},
{
- "file": "arch/x86_64/boot/limine/framebuffer.c",
+ "file": "arch/x86_64/debug/console.c",
"arguments": [
"x86_64-jove-gcc",
"-ffreestanding",
@@ -1469,6 +1501,9 @@
"-D__limine__",
"-Iinclude",
"-I.",
+ "-DDEBUG_SERIAL",
+ "-DDEBUG_CONSOLE",
+ "-DDEBUG_IPC",
"-march=x86-64",
"-m64",
"-mno-red-zone",
@@ -1476,11 +1511,11 @@
"-mcmodel=kernel",
"-mfsgsbase",
"-c",
- "arch/x86_64/boot/limine/framebuffer.c",
+ "arch/x86_64/debug/console.c",
"-o",
- "arch/x86_64/boot/limine/framebuffer.o"
+ "arch/x86_64/debug/console.o"
],
"directory": "/home/jon/prg/jove/kernel",
- "output": "arch/x86_64/boot/limine/framebuffer.o"
+ "output": "arch/x86_64/debug/console.o"
}
] \ No newline at end of file
diff --git a/config.mk b/config.mk
index 65efef2..b2b8569 100644
--- a/config.mk
+++ b/config.mk
@@ -1,4 +1,4 @@
-DBGFLAGS := SERIAL IPC
+DBGFLAGS := SERIAL CONSOLE IPC
CDIRS := boot lib hal proc sys api panic debug
diff --git a/debug/console.c b/debug/console.c
new file mode 100644
index 0000000..cb8aeb3
--- /dev/null
+++ b/debug/console.c
@@ -0,0 +1,116 @@
+#ifdef DEBUG_CONSOLE
+#include "debug/console.h"
+#include "lib/string.h"
+#include "lib/printf.h"
+#include "api/process.h"
+#include "proc/process.h"
+#include "sys/objdir.h"
+
+struct con_command {
+ char *name;
+ void (*func)(int, char*[]);
+};
+
+#define MAX_ARGS 8
+static int
+s_tokenize_buffer(char *buffer, char *argv[])
+{
+ int argc = 1;
+
+ //Populate the arguments buffer.
+ argv[0] = buffer;
+ for(char *s = buffer; *s; s++) {
+ if(*s == ' ') {
+ *s = 0;
+ argv[argc++] = s + 1;
+ }
+ }
+ return argc;
+}
+
+static int
+atoi(const char *cstr)
+{
+ int ret = 0;
+ for(const char *c = cstr; *c; c++) {
+ if(*c < '0' || *c > '9') return ret;
+ ret *= 10;
+ ret += *c - '0';
+ }
+ return ret;
+}
+
+static void
+s_command_dir_printdir(jove_obj_t *dir)
+{
+ jove_objdir_t *objdir = obj_deref((jove_owned_obj_t*)dir);
+ for(size_t i = 0; i < OBJDIR_ENTRIES; i++) {
+ jove_owned_obj_t *entry = (jove_owned_obj_t*)&objdir->entries[i];
+ if(obj_gettype(entry) == JOVE_OBJ_NONE) continue;
+ kprintf("%3i %16s %p\n", i, obj_gettypename(entry), obj_getvalue(entry));
+ }
+}
+
+static void
+s_command_dir(int argc, char *argv[])
+{
+ pid_t target_pid = 1;
+ if(argc > 1) {
+ if(argc > 2) {
+ kprintf("Too many arguments for 'dir': expected 2, got %i\n", argc);
+ return;
+ }
+ target_pid = atoi(argv[1]);
+ }
+ pcb_t *pcb = pcb_frompid(target_pid);
+ if(pcb == NULL) {
+ kprintf("Invalid PCB: '%i'\n", pcb);
+ return;
+ }
+ kprintf("Root directory for PID %i\n", target_pid);
+
+ jove_obj_t *rootdir = pcb_getrootdir(pcb);
+
+ while(1) {
+ s_command_dir_printdir(rootdir);
+read_input:
+ debug_console_readinput(argv[0], 128);
+ argc = s_tokenize_buffer(argv[0], argv);
+
+ if(strncmp(argv[0], "x", 1) == 0) return;
+ int traversi = atoi(argv[0]);
+
+ if(traversi > OBJDIR_ENTRIES) {
+ kprintf("Bad entry index: %i", traversi);
+ goto read_input;
+ }
+ if(obj_gettype(objdir_getlocal(rootdir, traversi)) != JOVE_OBJ_OBJDIR) {
+ kprintf("Bad subdirectory index: %i is not an objdir\n", traversi);
+ goto read_input;
+ }
+ rootdir = obj_release(objdir_getlocal(rootdir, traversi));
+ kprintf("\nSubdirectory %i\n", traversi);
+ }
+}
+
+static struct con_command s_console_commands[] = {
+ { "dir", s_command_dir }
+};
+static size_t s_console_commands_count = sizeof(s_console_commands) / sizeof(struct con_command);
+
+void debug_console_parsecmd(char *buffer)
+{
+ char *argv[MAX_ARGS];
+ int argc = s_tokenize_buffer(buffer, argv);
+
+ for(size_t i = 0; i < s_console_commands_count; i++) {
+ struct con_command *command = &s_console_commands[i];
+ if(strncmp(command->name, argv[0], 128) == 0) {
+ command->func(argc, argv);
+ return;
+ }
+ }
+ kprintf("Unknown command %s\n", argv[0]);
+}
+
+#endif
diff --git a/debug/console.h b/debug/console.h
new file mode 100644
index 0000000..616a255
--- /dev/null
+++ b/debug/console.h
@@ -0,0 +1,14 @@
+#ifndef _JOVE_DEBUG_CONSOLE_H
+#define _JOVE_DEBUG_CONSOLE_H 1
+
+#ifdef DEBUG_CONSOLE
+#include <stddef.h>
+
+__attribute__((noreturn)) void debug_console_start(void);
+
+int debug_console_readinput(char *buffer, size_t bufferw);
+void debug_console_parsecmd(char *buffer);
+
+#endif
+
+#endif
diff --git a/doc/syscall.md b/doc/syscall.md
index 6d7583f..aa2fd1f 100644
--- a/doc/syscall.md
+++ b/doc/syscall.md
@@ -220,6 +220,9 @@ Successful links return 0.
| Syscall | Target Permissions | Subject Permissions | Subject Conditional Permissions |
|-----------------------------|:-------------------------------:|:-------------------------------------------------:|:-------------------------------:|
+| SYSCALL_PAGEDIR_GET_MAPPING | JOVE_PERM_READ, JOVE_PERM_WRITE | |
+ |
+| SYSCALL_PAGEDIR_TRANSFER | JOVE_PERM_READ, JOVE_PERM_WRITE | JOVE_PERM_READ, JOVE_PERM_WRITE | |
| SYSCALL_PAGEDIR_MAP_FRAME | JOVE_PERM_READ, JOVE_PERM_WRITE | JOVE_PERM_MUTATE | JOVE_PERM_READ, JOVE_PERM_WRITE |
| SYSCALL_PAGEDIR_MAP_TABLE | JOVE_PERM_READ, JOVE_PERM_WRITE | JOVE_PERM_READ, JOVE_PERM_WRITE, JOVE_PERM_MUTATE | |
| SYSCALL_PAGEDIR_MAP_SHMEM | JOVE_PERM_READ, JOVE_PERM_WRITE | JOVE_PERM_READ | JOVE_PERM_WRITE |
@@ -228,6 +231,48 @@ Successful links return 0.
| SYSCALL_PAGEDIR_UNMAP_SHMEM | JOVE_PERM_READ, JOVE_PERM_WRITE | | |
+#### SYSCALL_PAGEDIR_GET_MAPPING
+
+Returns the mapping information for the given virtual address in a machine-agnostic format.
+
+| Data | Virtual address |
+|--------------|-----------------|
+| Size (bytes) | sizeof(void*) |
+
+If the virtual address exceeds `JOVE_USERMEMORY_LIMIT`, the kernel will return `-EOOB`.
+
+If the page directory does not contain a page table for the given address, the kernel will return `-ENOMAP`.
+
+Successful calls populate the message buffer with the mapping information and returns `0`.
+
+| Data | Mapping information |
+|--------------|----------------------------------------|
+| Size (bytes) | sizeof(struct syscall_pagedir_mapping) |
+
+
+#### SYSCALL_PAGEDIR_TRANSFER
+
+Moves a page mapping from one page directory to another.
+
+In the target pagedir: the entry data is cleared.
+
+In the subject pagedir: the entry data is replaced by the target entry data.
+
+| Data | Target Address | Subject Address | Subject Path Length | Subject Path |
+|--------------|----------------|-----------------|------------------------|----------------------------------------------|
+| Size (bytes) | sizeof(void*) | sizeof(void*) | sizeof(objpath_part_t) | sizeof(objpath_part_t) * subject_path_length |
+
+If the subject path does not point to a `JOVE_OBJ_PAGEDIR` object, the kernel will return `-EBADOBJ`.
+
+If the target/subject address exceeds `JOVE_USERMEMORY_LIMIT`, the kernel will return `-EOOB`.
+
+If the target directory does not have a page table for the target address, the kernel will return `-ENOMAP`.
+
+If the subject directory does not have a page table for the subject address, the kernel will return `-ENOMAP`.
+
+If the subject mapping is marked as present, the kernel will return `-EHASMAP`.
+
+
#### SYSCALL_PAGEDIR_MAP_FRAME
Attempts to map a given untyped memory span to the given virtual address with passed permissions.
diff --git a/hal/memory.h b/hal/memory.h
index a8fdc86..2af275b 100644
--- a/hal/memory.h
+++ b/hal/memory.h
@@ -8,8 +8,6 @@
#include <stdbool.h>
#include <stdatomic.h>
-typedef uintptr_t physaddr_t;
-typedef uintptr_t virtaddr_t;
typedef unsigned short shmem_off_t;
/**Represents a region of alloc-able memory.
@@ -83,6 +81,8 @@ virtaddr_t *pagedir_get_mapping(
size_t pagedir_mapping_get_pfn(virtaddr_t *mapping);
virtaddr_t pagedir_ident_from_mapping(virtaddr_t *mapping);
bool pagedir_mapping_is_present(virtaddr_t *mapping);
+bool pagedir_mapping_is_writeable(virtaddr_t *mapping);
+bool pagedir_mapping_is_executable(virtaddr_t *mapping);
void pagedir_mapping_set_pfn(virtaddr_t *mapping, size_t pfn);
void pagedir_mapping_set_present(virtaddr_t *mapping, bool present);
@@ -92,13 +92,13 @@ void pagedir_mapping_set_type(virtaddr_t *mapping, int type);
int pagedir_map_untyped_frame(
jove_owned_obj_t *tgt, jove_perm_obj_t *untyped_obj,
- virtaddr_t vptr, struct syscall_pagedir_flags flg);
+ virtaddr_t vptr, struct pagedir_mapping_flags flags);
int pagedir_map_untyped_table(
jove_owned_obj_t *tgt, jove_perm_obj_t *untyped_obj,
virtaddr_t vptr);
int pagedir_map_shmem_frame(
jove_owned_obj_t *tgt, jove_perm_obj_t *shmem_obj, uint8_t page_offset,
- virtaddr_t vptr, struct syscall_pagedir_flags flg);
+ virtaddr_t vptr, struct pagedir_mapping_flags flags);
int pagedir_unmap_untyped_frame(
jove_owned_obj_t *tgt, jove_owned_obj_t *dst, uintptr_t vptr);
diff --git a/hal/obj.c b/hal/obj.c
new file mode 100644
index 0000000..5d1b9d7
--- /dev/null
+++ b/hal/obj.c
@@ -0,0 +1,23 @@
+#include "obj.h"
+
+static const char *s_typenames[] = {
+ [JOVE_OBJ_NONE] = "NONE",
+ [JOVE_OBJ_UNTYPED] = "UNTYPED",
+ [JOVE_OBJ_OBJDIR] = "OBJDIR",
+ [JOVE_OBJ_PAGEDIR] = "PAGEDIR",
+ [JOVE_OBJ_PROCESSOR] = "PROCESSOR",
+ [JOVE_OBJ_REGION] = "REGION",
+ [JOVE_OBJ_SHMEMORY] = "SHMEMORY",
+ [JOVE_OBJ_INT_HANDLE] = "INT_HANDLES",
+ [JOVE_OBJ_PCB] = "PCB",
+ [JOVE_OBJ_MESSAGE] = "MESSAGE",
+ [JOVE_OBJ_LINK] = "LINK"
+};
+
+const char*
+obj_gettypename(jove_owned_obj_t *obj)
+{
+ uint8_t type = obj_gettype(obj);
+ if(type > JOVE_OBJ_LINK) return "UNKNOWN";
+ return s_typenames[type];
+}
diff --git a/hal/obj.h b/hal/obj.h
index 180b830..f19cf2c 100644
--- a/hal/obj.h
+++ b/hal/obj.h
@@ -23,6 +23,7 @@ void *obj_deref(jove_owned_obj_t *obj);
/*Getters and setters for accessing the type field of the kernel object. */
uint8_t obj_gettype(jove_owned_obj_t *obj);
uint8_t obj_peektype(jove_obj_t obj);
+const char *obj_gettypename(jove_owned_obj_t *obj);
void obj_settype(jove_owned_obj_t *obj, uint8_t type);
/*Getters and setters for accessing the value field of the kernel object. */
diff --git a/lib/printf.c b/lib/printf.c
index 7fa681e..302f227 100644
--- a/lib/printf.c
+++ b/lib/printf.c
@@ -71,7 +71,9 @@ s_convert_string(char *str, size_t size, va_list ap, size_t stri, struct print_f
const char *strarg = va_arg(ap, const char*);
if((uintptr_t)strarg < 0xFFFF800000000000ULL) return stri;
- int arglen = flags.precision == 0 ? strlen(strarg) : flags.precision;
+ int arglen = strlen(strarg);
+ if(flags.precision > 0 && flags.precision < arglen) arglen = flags.precision;
+
int minlen = flags.fieldw;
char padc = flags.flg_zeropad ? '0' : ' ';
@@ -98,7 +100,6 @@ s_convert_int(char *str, size_t size, va_list ap, size_t stri,
case 4: value = (uintmax_t)va_arg(ap, unsigned int); break;
case 8: value = (uintmax_t)va_arg(ap, uintmax_t); break;
}
- size_t pad_stri = stri;
int advance = convert_as_int(num_buf, 64, 0, value, flags.radix, flags.unsign);
if(flags.flg_alt) {
diff --git a/panic/panic.c b/panic/panic.c
index 5bde05b..3b00f42 100644
--- a/panic/panic.c
+++ b/panic/panic.c
@@ -1,4 +1,5 @@
#include "panic.h"
+#include "debug/console.h"
#include "lib/printf.h"
int _kernel_panic_unlock = 0;
@@ -14,7 +15,11 @@ __panic_reason(const char *fmt, va_list ap)
void
__panic_end(void)
{
+#ifdef DEBUG_CONSOLE
+ debug_console_start();
+#else
hcf();
+#endif
}
void
diff --git a/sys/syscall_pagedir.c b/sys/syscall_pagedir.c
index 6e773bf..2b81dfa 100644
--- a/sys/syscall_pagedir.c
+++ b/sys/syscall_pagedir.c
@@ -1,3 +1,4 @@
+#include "api/memory.h"
#include "api/syscall.h"
#include "hal/memory.h"
#include "jove.h"
@@ -58,6 +59,86 @@ s_syscall_pagedir_get_untyped(
}
static int
+s_syscall_pagedir_get_mapping(
+ jove_owned_obj_t *pagedir,
+ size_t bytes_left,
+ void *payload_data)
+{
+ size_t bytes_needed = sizeof(struct pagedir_mapping);
+ CHECK_TOOSMALL(bytes_needed, bytes_left, "Message too small for payload");
+
+ virtaddr_t vptr = *((virtaddr_t*)payload_data);
+ if(vptr > JOVE_USERMEMORY_LIMIT) {
+ klogf("Virtual address %p is out of bounds!\n", vptr);
+ return -EOOB;
+ }
+
+ virtaddr_t *mapping = pagedir_get_mapping(pagedir, vptr);
+ if(mapping == NULL) return -errno;
+
+ struct pagedir_mapping *payload = payload_data;
+
+ payload->pfn = pagedir_mapping_get_pfn(mapping);
+ payload->flags.present = pagedir_mapping_is_present(mapping);
+ payload->flags.writeable = pagedir_mapping_is_writeable(mapping);
+ payload->flags.executable = pagedir_mapping_is_executable(mapping);
+ return 0;
+}
+
+static int
+s_syscall_pagedir_transfer(
+ lockstack_t *lockstack,
+ jove_obj_t *rootdir,
+ jove_owned_obj_t *pagedir,
+ size_t bytes_left,
+ void *payload_data)
+{
+ //Verify the message is big enough for the payload.
+ size_t bytes_needed = sizeof(struct syscall_pagedir_transfer);
+ CHECK_TOOSMALL(bytes_needed, bytes_left, "Message too small for payload");
+
+ //Verify the payload is big enough for the target path.
+ struct syscall_pagedir_transfer *payload = payload_data;
+ bytes_needed += sizeof(objpath_part_t) * payload->target_path_length;
+ CHECK_TOOSMALL(bytes_needed, bytes_left, "Message too small for target path");
+
+ //Verify the target object is a pagedir with the correct permissions.
+ jove_perm_obj_t target = link_traverse_objdir(rootdir, payload->target_path_length, payload->target_path);
+ CHECK_OBJEXISTS(target.obj, "Target path does not point to a valid object");
+ lockstack_push(lockstack, target.obj);
+
+ CHECK_OBJTYPE(target.obj, JOVE_OBJ_PAGEDIR, "Target object is not a JOVE_OBJ_PAGEDIR");
+ CHECK_OBJPERM(target, SYSCALL_PERM_PAGEDIR_TRANSFER_TGT, "Not allowed to transfer to target");
+
+ //Verify subject has a mapping at the given address.
+ virtaddr_t *subject_mapping = pagedir_get_mapping(pagedir, payload->subject_address);
+ if(subject_mapping == NULL) {
+ klogf("Subject page directory does not have tables for %p\n", payload->subject_address);
+ return -errno;
+ }
+
+ //Verify target has a mapping at the given address.
+ virtaddr_t *target_mapping = pagedir_get_mapping(target.obj, payload->target_address);
+ if(target_mapping == NULL) {
+ klogf("Target page directory does not have tables for %p\n", payload->target_address);
+ return -errno;
+ }
+
+ //Verify target mapping is not marked present.
+ if(pagedir_mapping_is_present(target_mapping)) {
+ klogf("Target page at %p is marked as present\n", payload->target_address);
+ return -EBUSY;
+ }
+
+ //Move the mapping over and return.
+ *target_mapping = *subject_mapping;
+ *subject_mapping = 0;
+
+ pagedir_invlpg(payload->subject_address);
+ return 0;
+}
+
+static int
s_syscall_pagedir_unmap(
lockstack_t *lockstack,
jove_obj_t *objdir,
@@ -111,7 +192,7 @@ s_syscall_pagedir_map_frame(
}
struct syscall_pagedir_map *payload = payload_data;
- sysret = pagedir_map_untyped_frame(pagedir, &untyped, payload->virtual_address, payload->page_flags);
+ sysret = pagedir_map_untyped_frame(pagedir, &untyped, payload->virtual_address, payload->flags);
if(sysret == 0)
obj_settype(untyped.obj, JOVE_OBJ_NONE);
@@ -186,7 +267,7 @@ s_syscall_pagedir_map_shmem(
}
return pagedir_map_shmem_frame(pagedir, &shmem, payload->page_offset,
- payload->virtual_address, payload->page_flags);
+ payload->virtual_address, payload->flags);
}
static int
@@ -234,6 +315,16 @@ _syscall_handle_pagedir(syscall_context_t *ctx)
void *payload = ctx->payload;
switch(header->callid) {
+ case SYSCALL_PAGEDIR_GET_MAPPING:
+ if(target->permissions & SYSCALL_PERM_PAGEDIR_GET_MAPPING)
+ return s_syscall_pagedir_get_mapping(target->obj, bytes_left, payload);
+ return -EPERM;
+
+ case SYSCALL_PAGEDIR_TRANSFER:
+ if(target->permissions & SYSCALL_PERM_PAGEDIR_TRANSFER)
+ return s_syscall_pagedir_transfer(
+ lockstack, objdir, target->obj, bytes_left, payload);
+
case SYSCALL_PAGEDIR_MAP_FRAME:
if(target->permissions & SYSCALL_PERM_PAGEDIR_MAP_FRAME)
return s_syscall_pagedir_map_frame(lockstack, objdir, target->obj, bytes_left, payload);