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);
}
#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;
}
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();
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;