Repository navigation
Expand file tree
/
Copy pathsyscall.c
More file actions
95 lines (75 loc) · 2 KB
/
Copy pathsyscall.c
File metadata and controls
95 lines (75 loc) · 2 KB
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
#include "syscall.h"
#include "isr.h"
#include "tfs.h"
#include "proc.h"
#include "auth.h"
extern uint32_t kern_restore_esp;
void syscall_handler(struct regs *r)
{
if(r->eax < 1 || r->eax > SYS_MAX)
return;
switch (r->eax) {
case SYS_COUT:
cursor_write((const char*)r->ebx);
break;
case SYS_GETCH: {
char c = getch();
r->eax = (uint32_t)c;
break;
}
case SYS_CUR_SET:
cursor_set(r->ebx);
break;
case SYS_CUR_GET:
r->eax = cursor_get();
break;
case SYS_TFS_LIST:
tfs_list();
break;
case SYS_TFS_READ:
r->eax = tfs_read((const char*)r->ebx, (char*)r->ecx, r->edx);
break;
case SYS_TFS_CREATE:
r->eax = tfs_create((const char*)r->ebx, (const char*)r->ecx, r->edx);
break;
case SYS_TFS_DELETE:
r->eax = tfs_delete((const char*)r->ebx);
break;
case SYS_EXIT:
in_ring3 = 0;
__asm__ volatile(
"movl %0, %%esp \n"
"movl %%esp, %%ebp \n"
"sti \n"
"xorl %%eax, %%eax \n"
"leave \n"
"ret \n"
: : "m"(kern_restore_esp)
);
__builtin_unreachable();
case SYS_HEX: {
char buf[12];
uint32_t val = r->ebx;
const char *hex = "0123456789ABCDEF";
int p = 0;
buf[p++] = '0';
buf[p++] = 'x';
for (int i = 7; i >= 0; i--)
buf[p++] = hex[(val >> (i * 4)) & 0xF];
buf[p++] = '\n';
buf[p] = '\0';
cursor_write(buf);
break;
}
case SYS_BACKSPACE:
cursor_backspace();
break;
case SYS_LOGIN:
r->eax = auth_login((const char*)r->ebx, (const char*)r->ecx);
break;
case SYS_EXEC:
r->eax = proc_load((const char*)r->ebx);
/* 成功则 proc_start → iret, 不返回; 失败返回 -1 */
break;
}
}