From: Amelia Coutard Date: Mon, 6 Mar 2023 19:14:57 +0000 (+0100) Subject: Added syscall to show userspace vmemory, to make debugging the kernel easier X-Git-Url: https://git.ameliathe1st.gay/?a=commitdiff_plain;h=9570b8a28831eee92f551fe6cf36588f309dd3f6;p=voyage-au-centre-des-fichiers.git Added syscall to show userspace vmemory, to make debugging the kernel easier --- diff --git a/kernel/src/ring3.S b/kernel/src/ring3.S index 527fe1b..2b6a783 100644 --- a/kernel/src/ring3.S +++ b/kernel/src/ring3.S @@ -44,4 +44,5 @@ incorrect_syscall: syscalls_call_table: .quad syscall_print .quad syscall_println -.set syscall_n, 2 + .quad syscall_print_low_mmap +.set syscall_n, 3 diff --git a/kernel/src/ring3.cpp b/kernel/src/ring3.cpp index 9cddf88..589e38e 100644 --- a/kernel/src/ring3.cpp +++ b/kernel/src/ring3.cpp @@ -14,6 +14,7 @@ #include "ring3.hpp" #include "utils.hpp" #include "serial.hpp" +#include "paging.hpp" void os::set_ring0_stack(os::tss& tss, std::uint64_t stack) { tss.rsp0 = stack; @@ -33,15 +34,31 @@ void os::enable_syscalls() { os::set_msr(0xC0000084, 0x00000000); // syscall flag mask, we don't want to change the flags for now. } -extern "C" void syscall_print(char v) { +extern "C" void os::syscall_print(char v) { os::printc(v); } -extern "C" void syscall_println(char v) { +extern "C" void os::syscall_println(char v) { os::printc(v); os::printc('\n'); } -extern "C" void syscall_rax_error_handler() { +extern "C" os::paging::PML4T PML4T; +extern "C" void os::syscall_print_low_mmap() { + os::paging::on_all_pages(PML4T, [](os::paging::page* vaddr, os::phys_ptr paddr, std::size_t page_size_in_bytes) { + if (std::size_t(vaddr) < 128ul * 1024 * 1024 * 1024 * 1024) { // Lower half: + if (std::size_t(vaddr) < 0x10'0000'0000) { + os::print("segments:"); + } else if (std::size_t(vaddr) < 0x7FFF'FFFF'0000) { + os::print("heap: "); + } else { + os::print("stack: "); + } + os::print(" {} -> {} (0x{}B)\n", std::size_t(vaddr), paddr.get_phys_addr(), page_size_in_bytes); + } + }); +} + +extern "C" void os::syscall_rax_error_handler() { os::assert(false, "Incorrect %rax for syscall."); } diff --git a/kernel/src/ring3.hpp b/kernel/src/ring3.hpp index 54077c9..eab7646 100644 --- a/kernel/src/ring3.hpp +++ b/kernel/src/ring3.hpp @@ -41,6 +41,7 @@ extern "C" void syscall_64bit_handler(); extern "C" void syscall_print(char c); extern "C" void syscall_println(char c); +extern "C" void syscall_print_low_mmap(); extern "C" void syscall_rax_error_handler(); void set_ring0_stack(tss& tss, std::uint64_t stack); diff --git a/test_module/src/test.S b/test_module/src/test.S index 65e8156..968868e 100644 --- a/test_module/src/test.S +++ b/test_module/src/test.S @@ -18,3 +18,9 @@ print: mov $0, %rax syscall ret + +.globl check_mem +check_mem: + mov $2, %rax + syscall + ret diff --git a/test_module/src/test.cpp b/test_module/src/test.cpp index ef01f00..4f6294d 100644 --- a/test_module/src/test.cpp +++ b/test_module/src/test.cpp @@ -14,6 +14,7 @@ #include extern "C" void print(char c); +extern "C" void check_mem(); void printstr(const char* str) { for (size_t i = 0; str[i] != '\0'; i++) { @@ -26,5 +27,8 @@ extern "C" void _start() { for (size_t i = 0; i < 16; i++) { printstr(str); } + printstr("Mem:\n"); + check_mem(); + printstr("Done.\n"); while (true) {} }