From ccb0fcb78c0d22ebaeb9aa37f1941b0d44c98038 Mon Sep 17 00:00:00 2001 From: Fabian Imhof Date: Sun, 4 May 2025 11:07:48 +0000 Subject: move user-mode code into own namespace and linker section --- arch/x86_64/src/user/main.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 arch/x86_64/src/user/main.cpp (limited to 'arch/x86_64/src/user/main.cpp') diff --git a/arch/x86_64/src/user/main.cpp b/arch/x86_64/src/user/main.cpp new file mode 100644 index 0000000..6d8eea7 --- /dev/null +++ b/arch/x86_64/src/user/main.cpp @@ -0,0 +1,36 @@ +#include "arch/user/main.hpp" + +#include "arch/context_switching/syscall/main.hpp" + +// TODO: Disallow this import +#include "arch/video/vga/text.hpp" + +namespace teachos::arch::user +{ + + [[gnu::section(".user_text")]] + auto main() -> void + { + // TODO: Remove or replace this wall of text + // RFLAGS is saved into R11, RIP of the next instruction into RCX + // Required for SYSRETURN to know where to return too. + // Additional state needs to be saved by calling convention: + + // Syscall Number: RAX, Return Value: RAX (0 indicating no error, and -1 indicating an error, use as a boolean) + // Argument in this order (max 6. no argument on stack): RDI, RSI, RDX, R10, R8, R9 + // Not used registers: RBX, RSP, R12, R13, R14 + + // Actual Source: https://man7.org/linux/man-pages/man2/syscall.2.html More cleare documentation: + // https://sys.readthedocs.io/en/latest/doc/05_calling_system_calls.html + + const char syscall_message[68] = "Successfully entered user mode and wrote to VGA buffer via syscall!"; + auto error = context_switching::syscall::syscall(context_switching::syscall::WRITE, + {reinterpret_cast(&syscall_message)}); + + if (!error) + { + video::vga::text::write("Successfully made a SYSCALL and returned with SYSRETQ!", + video::vga::text::common_attributes::green_on_black); + } + } +} // namespace teachos::arch::user \ No newline at end of file -- cgit v1.2.3