summaryrefslogtreecommitdiff
path: root/kernel/sys.c
blob: f21e35ac065e6737aba2a8c0288654f2c0da3c3f (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <errno.h>
#include <kernel/con.h>
#include <kernel/kernel.h>
#include <kernel/sched.h>
#include <kernel/serial.h>
#include <kernel/tty.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>

int sys_alarm(unsigned int seconds) {
  if(!seconds) {
    ctask->alarm = 0;
    return 0;
  }

  ctask->alarm = ticks + (seconds * 100);
}

int sys_ctty(int ctty) {
  ctask->ctty = ctty;

  return 0;
}

pid_t sys_getpid(void) {
  return ctask->pid;
}

void *sys_getpdir(void) {
  uint32_t pdir;

  __asm__ ("mov %%cr3, %%eax" : "=a" (pdir));

  return (void*) pdir;
}

void sys_panic(void) {
  panic();
}

int sys_pause(void) {
  ctask->state = TSTATE_INTERRUPTIBLE;
  reschedule();
  return -1;
}

void *sys_signal(int sig, void (*func)(int)) {
  if(sig < 0 || sig >= NRSIG)
    return NULL;

  /* SIGKILL and SIGSTOP cannot be caught */
  if(sig == SIGKILL || sig == SIGSTOP)
    return NULL;

  ctask->sig_handlers[sig] = func;

  return func;
}

time_t sys_time(void) {
  return ticks / 100;
}

int sys_dummy(void) {
  return -ENOSYS;
}