summaryrefslogtreecommitdiff
path: root/src/kernel/task/syscall.cpp
blob: 7938e76aa9b4107a35bb2fbd6746b6243294290b (plain) (blame)
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
#include "syscall.h"
#include "task.h"
#include "timer.h"
#include <core/monitor.h>
#include <core/sys.h>

#define CALL0(name, scname) static void scname(registers* r) { r->eax = name(); }
#define CALL1(name, scname) static void scname(registers* r) { \
	r->eax = name(r->ecx); }
#define CALL2(name, scname) static void scname(registers* r) { \
	r->eax = name(r->ecx, r->edx); }
#define CALL3(name, scname) static void scname(registers* r) { \
	r->eax = name(r->ecx, r->edx, r->esi); }
#define CALL0V(name, scname) static void scname(registers* r) { name(); }
#define CALL1V(name, scname) static void scname(registers* r) { name(r->ecx); }
#define CALL2V(name, scname) static void scname(registers* r) { name(r->ecx, r->edx); }
#define CALL3V(name, scname) static void scname(registers* r) { name(r->ecx, r->edx, r->esi); }
#define CALL4V(name, scname) static void scname(registers* r) { name(r->ecx, r->edx, r->esi, r->edi); }

CALL0V(thread_exit, thread_exit_sc);
CALL0V(schedule, schedule_sc);
CALL1V(thread_sleep, thread_sleep_sc);
CALL1V(process_exit, process_exit_sc);
CALL1V(idt_waitIrq, irq_wait_sc);
CALL0(proc_priv, proc_priv_sc);
CALL1(process_sbrk, proc_sbrk_sc);
CALL1V(process_brk, proc_brk_sc);

static void printk_sc(registers *r) {
	monitor_write((char*)r->ecx);
}

static void thread_new_sc(registers* r) {
	cli();
	new thread(current_thread->process, (thread_entry)r->ecx, (void*)r->edx, (void*)r->esi);
	sti();
}

int_callback syscalls[NUMBER_OF_SYSCALLS] = {		// This must correspond to common/include/tce/syscalls.h
	0,
	thread_exit_sc,			//0
	schedule_sc,
	thread_sleep_sc,
	process_exit_sc,
	printk_sc,
	thread_new_sc,			//5
	irq_wait_sc,
	proc_priv_sc,
	proc_sbrk_sc,
	proc_brk_sc,
	0 };


/*	Called in idt_.asm on a system call (interrupt 64).
	Calls the correct syscall handler (if any). */
extern "C" void idt_syscallHandler(registers regs) {
	if (regs.eax == 0) {
		if (regs.ebx < NUMBER_OF_SYSCALLS && syscalls[regs.ebx] != 0) {
			syscalls[regs.ebx](&regs);
		}
	} else {
		monitor_write("Hello. Object calls not implemented.\n");
	}
}