summaryrefslogtreecommitdiff
path: root/src/kernel/task/syscall.cpp
blob: 9e7c0892fa2acef2a9a0cb4e2a2fb9c97e2a8990 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "syscall.h"
#include "task.h"
#include "timer.h"
#include <ui/vt.h>
#include <core/sys.h>
#include <vfs/node.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->ebx); }
#define CALL2(name, scname) static void scname(registers* r) { \
	r->eax = name(r->ebx, r->ecx); }
#define CALL3(name, scname) static void scname(registers* r) { \
	r->eax = name(r->ebx, r->ecx, r->edx); }
#define CALL4(name, scname) static void scname(registers* r) { \
	r->eax = name(r->ebx, 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->ebx); }
#define CALL2V(name, scname) static void scname(registers* r) { name(r->ebx, r->ecx); }
#define CALL3V(name, scname) static void scname(registers* r) { name(r->ebx, r->ecx, r->edx); }
#define CALL4V(name, scname) static void scname(registers* r) { name(r->ebx, r->ecx, r->edx, r->esi); }

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);
CALL2(process_waitpid, waitpid_sc);

CALL1V(close, close_sc);

static void printk_sc(registers *r) {
	ke_vt->writeStr((char*)r->ebx);
}

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

static void run_sc(registers *r) {
	r->eax = process_run((char*)r->ebx, (char**)r->ecx, (int)r->edx);
}

static void open_sc(registers *r) {
	r->eax = open((char*)r->ebx, r->ecx);
}

static void open_relative_sc(registers *r) {
	r->eax = open_relative(r->ebx, (char*)r->ecx, r->edx);
}

static void stat_sc(registers *r) {
	r->eax = stat((char*)r->ebx, (file_info*)r->ecx);
}

static void stat_relative_sc(registers *r) {
	r->eax = stat_relative(r->ebx, (char*)r->ecx, (file_info*)r->edx);
}

static void statf_sc(registers *r) {
	r->eax = statf(r->ebx, (file_info*)r->ecx);
}

static void read_sc(registers *r) {
	r->eax = read(r->ebx, r->ecx, r->edx, (char*)r->esi);
}

static void write_sc(registers *r) {
	r->eax = write(r->ebx, r->ecx, r->edx, (char*)r->esi);
}

static void link_sc(registers *r) {
	r->eax = link((char*)r->ebx, (char*)r->ecx, r->edx);
}


int_callback syscalls[NUMBER_OF_SYSCALLS] = {		// This must correspond to common/include/tce/syscalls.h
	0,						// 0
	thread_exit_sc,	
	schedule_sc,
	thread_sleep_sc,
	process_exit_sc,
	printk_sc,				//5
	thread_new_sc,
	irq_wait_sc,
	proc_priv_sc,
	0,
	proc_sbrk_sc,			//10
	proc_brk_sc,
	0,
	0,
	run_sc,
	waitpid_sc,				//15
	0,
	0,
	0,
	0,
	open_sc,				//20
	open_relative_sc,
	stat_sc,
	stat_relative_sc,
	statf_sc,
	close_sc,				//25
	read_sc,
	write_sc,
	link_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 < NUMBER_OF_SYSCALLS && syscalls[regs.eax] != 0) {
		syscalls[regs.eax](&regs);
	}
}