summaryrefslogtreecommitdiff
path: root/kernel/syscall.cpp
blob: 3aa410597b1c612b3bc6c827f84d91bc24123919 (plain) (blame)
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
36
#include <hilbert/kernel/application.hpp>
#include <hilbert/kernel/framebuffer.hpp>
#include <hilbert/kernel/syscall.hpp>
#include <hilbert/kernel/paging.hpp>

namespace hilbert::kernel::syscall {

  syscall_handler handlers[256];

  void init_syscalls() {
    for (int i = 0; i < 256; ++i)
      handlers[i] = 0;
  }

  void add_syscall(uint64_t rax, syscall_handler handler) {
    handlers[rax] = handler;
  }

}

using namespace hilbert::kernel::syscall;

extern "C" void do_syscall(
  uint64_t &rax, uint64_t &rdi, uint64_t &rsi, uint64_t &rdx
) {

  if (rax < 256 && handlers[rax] != 0)
    handlers[rax](rax, rdi, rsi, rdx);
  else {
    rax = 0;
    rdi = 0;
    rsi = 0;
    rdx = 0;
  }

}