]> git.ameliathe1st.gay Git - voyage-au-centre-des-fichiers.git/commitdiff
Encapsulated running the first process into a function
authorAmelia Coutard <eliottulio.coutard@gmail.com>
Tue, 14 Mar 2023 15:48:24 +0000 (16:48 +0100)
committerAmelia Coutard <eliottulio.coutard@gmail.com>
Tue, 14 Mar 2023 15:48:24 +0000 (16:48 +0100)
kernel/src/kernel.cpp
kernel/src/ring3.cpp
kernel/src/ring3.hpp

index 244eb1c9ec539aa7fe1290948f7c6dc09db611e6..014be9ae9e8dc1de2fd16a7a491badfde4e05f1d 100644 (file)
@@ -183,11 +183,6 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr<const multiboot2::info_s
        os::print("Enabling syscalls.\n");
        os::enable_syscalls();
 
-       os::current_pid = 1;
-       os::get_process(os::current_pid) = test_module_process;
-
-       os::print("Loading test_module virtual memory map.\n");
-       os::paging::load_pml4t(os::get_process(os::current_pid).PML4T);
        os::print("Moving to ring 3.\n");
-       os::ftl_to_userspace((void*)os::get_process(os::current_pid).rip, (std::byte*)os::get_process(os::current_pid).rsp);
+       os::run_first_process(test_module_process);
 }
index aed5e3a953c57b93851998d1aa29d8831e1c7c45..c0f58bd27176428ebbd3219aa98c3d92d0dbdc17 100644 (file)
 #include "serial.hpp"
 #include "paging.hpp"
 
+void os::run_first_process(os::process& process) {
+       os::current_pid = 1;
+       os::get_process(os::current_pid) = process;
+       os::paging::load_pml4t(process.PML4T);
+       os::ftl_to_userspace((void*)process.rip, (std::byte*)process.rsp);
+}
+
 void os::set_ring0_stack(os::tss& tss, std::uint64_t stack) {
        tss.rsp0 = stack;
 }
index ab77686d952bbb6348c299737c20ccfb36d0d33b..18cb4cb97a4e4c292a5fd2c7950b800d8690360c 100644 (file)
@@ -37,7 +37,10 @@ struct __attribute__((packed)) tss {
        std::uint16_t iopb;
 };
 
+struct process;
+
 extern "C" void ftl_to_userspace(void* program, std::byte* stack);
+void run_first_process(process& process);
 extern "C" void load_tss();
 extern "C" void syscall_64bit_handler();
 
@@ -69,11 +72,17 @@ inline process& get_process(std::uint64_t pid) {
        os::assert(1 <= pid && pid <= 2048, "Invalid pid: {}.\n", pid);
        return ((process*)0xFFFF'C000'0000'0000)[pid - 1];
 }
+inline bool process_exists(std::uint64_t pid) {
+       return 1 <= pid && pid <= 2048 && get_process(pid).rsp != 0;
+}
 inline port& get_port(std::uint64_t pid, std::uint64_t port) {
        os::assert(1 <= pid && pid <= 2048, "Invalid pid: {}.\n", pid);
        os::assert(1 <= port && port <= 4096, "Invalid port: {}.\n", pid);
        return ((os::port*)0xFFFF'C000'0001'0000)[(pid - 1) * 4096 + (port - 1)];
 }
+inline bool port_exists(std::uint64_t pid, std::uint64_t port) {
+       return process_exists(pid) && 1 <= port && port <= 4096 && get_port(pid, port).other_pid != 0;
+}
 
 extern std::uint64_t current_pid;