summaryrefslogtreecommitdiff
path: root/Kernel/Syscall.h
blob: 5f225fc12d919ced5bc62def99e348f4dcbbae07 (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
#pragma once

#include <AK/Types.h>

#define DO_SYSCALL_A0(function) Syscall::invoke((dword)(function))
#define DO_SYSCALL_A1(function, arg1) Syscall::invoke((dword)(function), (dword)(arg1))
#define DO_SYSCALL_A2(function, arg1, arg2) Syscall::invoke((dword)(function), (dword)(arg1), (dword)(arg2))
#define DO_SYSCALL_A3(function, arg1, arg2, arg3) Syscall::invoke((dword)(function), (dword)(arg1), (dword)(arg2), (dword)arg3)

namespace Syscall {

enum Function {
    Spawn = 0x1981,
    Sleep = 0x1982,
    Yield = 0x1983,
    PutCharacter = 1984,
    PosixOpen = 0x1985,
    PosixClose = 0x1986,
    PosixRead = 0x1987,
    PosixSeek = 0x1988,
    PosixKill = 0x1989,
    PosixGetuid = 0x1990,
    PosixExit = 0x1991,
    PosixGetgid = 0x1992,
    PosixGetpid = 0x1993,
    PosixWaitpid = 0x1994,
    PosixMmap = 0x1995,
    PosixMunmap = 0x1996,
    GetDirEntries = 0x1997,
    PosixLstat = 0x1998,
    PosixGetcwd = 0x1999,
    PosixGettimeofday = 0x2000,
    PosixGethostname = 0x2001,
    GetArguments = 0x2002,
};

void initialize();

inline dword invoke(dword function)
{
    dword result;
    asm volatile("int $0x80":"=a"(result):"a"(function));
    return result;
}

inline dword invoke(dword function, dword arg1)
{
    dword result;
    asm volatile("int $0x80":"=a"(result):"a"(function),"d"(arg1));
    return result;
}

inline dword invoke(dword function, dword arg1, dword arg2)
{
    dword result;
    asm volatile("int $0x80":"=a"(result):"a"(function),"d"(arg1),"c"(arg2));
    return result;
}

inline dword invoke(dword function, dword arg1, dword arg2, dword arg3)
{
    dword result;
    asm volatile("int $0x80":"=a"(result):"a"(function),"d"(arg1),"c"(arg2),"b"(arg3));
    return result;
}

}