aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/user/main.cpp
blob: 1d56d2ec8a339a9ec7b6b90b4d0db78619e40bce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#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

    char constexpr syscall_message[] = "Successfully entered user mode and wrote to VGA buffer via syscall!";
    auto const error = context_switching::syscall::syscall(context_switching::syscall::type::WRITE,
                                                           {reinterpret_cast<uint64_t>(&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