-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kernel.syscall.d
52 lines (45 loc) · 1.06 KB
/
kernel.syscall.d
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
// Copyright (C) 2021 Mateus de Lima Oliveira
module kernel.syscall;
import kernel.isr;
import kernel.tty;
import kernel.common : panic;
import kernel.paging : alloc_frame, getPage, currentDirectory;
import leaf.syscall;
extern(C)
static string toString(uint reg, int len) @trusted
{
char *p = cast(char *) reg;
char[] ret;
ret = p[0..len];
return cast(string) ret;
}
alias size_t = uint;
alias off_t = uint;
extern(C)
static void *mmap(void *addr, size_t length, int prot, int flags,
int fd, off_t offset)
{
for (void *p = addr; length > 0; p += 4096) {
alloc_frame(getPage(cast(uint) p, 1, currentDirectory), 0, 1);
length -= 4096; /* FIXME: underflow. */
}
return null;
}
extern(C)
void SyscallHandler(ISRRegisters regs) @system
{
//printk("syscall\n");
switch(regs.eax) {
case SyscallID.SYS_PRINT:
printk(toString(regs.ebx, regs.ecx));
break;
case SyscallID.SYS_MMAP:
printk("mmap\n");
mmap(cast(void *) regs.ebx, cast(size_t) regs.ecx, 0, 0, 0, 0);
printk("mmap done\n");
break;
default:
printk("Unhandled syscall.");
panic();
}
}