blob: b7500729c9f47a4342e72822032397a06a4b932c (
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
71
72
73
74
75
76
77
78
|
#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>
time_t sys_time(void) {
return ticks / 100;
}
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_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;
}
int sys_alarm(unsigned int seconds) {
if(!seconds) {
ctask->alarm = 0;
return 0;
}
ctask->alarm = ticks + (seconds * 100);
}
int sys_pause(void) {
ctask->state = TSTATE_INTERRUPTIBLE;
reschedule();
return -1;
}
int sys_ctty(int ctty) {
ctask->ctty = ctty;
return 0;
}
ssize_t sys_read(void *buf, size_t len) {
return tty_read(ctask->ctty, buf, len);
}
ssize_t sys_write(void *buf, size_t len) {
return tty_write(ctask->ctty, buf, len);
}
void sys_panic(void) {
panic();
}
int sys_dummy(void) {
return -ENOSYS;
}
|