Implement syscalls, hello world from userspace
This commit is contained in:
27
kernel/syscall/syscall.c
Normal file
27
kernel/syscall/syscall.c
Normal file
@ -0,0 +1,27 @@
|
||||
#include <stdint.h>
|
||||
#include "syscall.h"
|
||||
#include "errors.h"
|
||||
#include "dlmalloc/malloc.h"
|
||||
#include "kprintf.h"
|
||||
#include "proc/proc.h"
|
||||
|
||||
int32_t SYSCALL2(sys_debugprint, string1, len) {
|
||||
char *buf = dlmalloc(len);
|
||||
if (buf == NULL) {
|
||||
return E_NOMEMORY;
|
||||
}
|
||||
ksnprintf(buf, len, "%s", string1);
|
||||
kprintf("%s\n", buf);
|
||||
dlfree(buf);
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t SYSCALL0(sys_quitproc) {
|
||||
proc_killself();
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
SyscallFn SYSCALL_TABLE[SYSCALLS_MAX] = {
|
||||
[SYS_DEBUGPRINT] = &sys_debugprint,
|
||||
[SYS_QUITPROC] = &sys_quitproc,
|
||||
};
|
81
kernel/syscall/syscall.h
Normal file
81
kernel/syscall/syscall.h
Normal file
@ -0,0 +1,81 @@
|
||||
#ifndef SYSCALL_SYSCALL_H_
|
||||
#define SYSCALL_SYSCALL_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "compiler/attr.h"
|
||||
|
||||
#define SYSCALLS_MAX 0xff
|
||||
|
||||
#define SYSCALL0(name) \
|
||||
name(UNUSED uint64_t _1, \
|
||||
UNUSED uint64_t _2, \
|
||||
UNUSED uint64_t _3, \
|
||||
UNUSED uint64_t _4, \
|
||||
UNUSED uint64_t _5, \
|
||||
UNUSED uint64_t _6 \
|
||||
)
|
||||
|
||||
#define SYSCALL1(name, arg1) \
|
||||
name(uint64_t arg1, \
|
||||
UNUSED uint64_t _2, \
|
||||
UNUSED uint64_t _3, \
|
||||
UNUSED uint64_t _4, \
|
||||
UNUSED uint64_t _5, \
|
||||
UNUSED uint64_t _6 \
|
||||
)
|
||||
|
||||
#define SYSCALL2(name, arg1, arg2) \
|
||||
name(uint64_t arg1, \
|
||||
uint64_t arg2, \
|
||||
UNUSED uint64_t _3, \
|
||||
UNUSED uint64_t _4, \
|
||||
UNUSED uint64_t _5, \
|
||||
UNUSED uint64_t _6 \
|
||||
)
|
||||
|
||||
#define SYSCALL3(name, arg1, arg2, arg3) \
|
||||
name(uint64_t arg1, \
|
||||
uint64_t arg2, \
|
||||
uint64_t arg3, \
|
||||
UNUSED uint64_t _4, \
|
||||
UNUSED uint64_t _5, \
|
||||
UNUSED uint64_t _6 \
|
||||
)
|
||||
|
||||
#define SYSCALL4(name, arg1, arg2, arg3, arg4) \
|
||||
name(uint64_t arg1, \
|
||||
uint64_t arg2, \
|
||||
uint64_t arg3, \
|
||||
uint64_t arg4, \
|
||||
UNUSED uint64_t _5, \
|
||||
UNUSED uint64_t _6 \
|
||||
)
|
||||
|
||||
#define SYSCALL5(name, arg1, arg2, arg3, arg4, arg5) \
|
||||
name(uint64_t arg1, \
|
||||
uint64_t arg2, \
|
||||
uint64_t arg3, \
|
||||
uint64_t arg4, \
|
||||
uint64_t arg5, \
|
||||
UNUSED uint64_t _6 \
|
||||
)
|
||||
|
||||
#define SYSCALL6(name, arg1, arg2, arg3, arg4, arg5, arg6) \
|
||||
name(uint64_t arg1, \
|
||||
uint64_t arg2, \
|
||||
uint64_t arg3, \
|
||||
uint64_t arg4, \
|
||||
uint64_t arg5, \
|
||||
uint64_t arg6 \
|
||||
)
|
||||
|
||||
enum {
|
||||
SYS_DEBUGPRINT = 1,
|
||||
SYS_QUITPROC = 2,
|
||||
};
|
||||
|
||||
typedef int32_t (*SyscallFn)(uint64_t, uint64_t, uint64_t, uint64_t, uint64_t, uint64_t);
|
||||
|
||||
extern SyscallFn SYSCALL_TABLE[SYSCALLS_MAX];
|
||||
|
||||
#endif // SYSCALL_SYSCALL_H_
|
Reference in New Issue
Block a user