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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
global int_syscall_handler
[extern task_fork]
[extern syscall_exit]
[extern syscall_write]
[extern syscall_read]
[extern syscall_readdir]
[extern syscall_execve]
[extern syscall_open]
[extern syscall_close]
[extern syscall_fstat]
[extern syscall_isatty]
[extern syscall_lseek]
[extern syscall_sbrk]
[extern syscall_stat]
[extern syscall_lstat]
[extern syscall_fork]
[extern syscall_unhandled]
[bits 32]
pid: dd 0x0
int_syscall_handler:
cmp eax, 72
je call_fork
cli
push ebx
push ecx
push edx
cmp eax, 60
je call_exit
cmp eax, 61
je call_write
cmp eax, 62
je call_read
cmp eax, 63
je call_readdir
cmp eax, 64
je call_execve
cmp eax, 65
je call_open
cmp eax, 66
je call_close
cmp eax, 67
je call_fstat
cmp eax, 68
je call_isatty
cmp eax, 69
je call_lseek
cmp eax, 70
je call_sbrk
cmp eax, 74
je call_stat
cmp eax, 79
je call_lstat
push eax
jmp call_unhandled
done:
mov ebx,eax
mov al, 0x20 ;Port number AND command number to Acknowledge IRQ
out 0x20, al ;Acknowledge IRQ, so we keep getting interrupts
mov eax,ebx
done_blocking:
pop ebx
pop ecx
pop edx
mov ebx,eax
sti
iret ;Interrupt-Return
call_fork:
cli
pusha ;Push all standard registers
mov ebx, esp ;save current stack pointer in esp
mov esp, 0x7000 ;now put the stack outside of virtual memory in kernel space!
push ebx ;Push pointer to all the stuff we just pushed
call task_fork ;Call C code
mov [pid],eax
mov esp, ebx ;Replace the stack with what the C code gave us
mov al, 0x20 ;Port number AND command number to Acknowledge IRQ
out 0x20, al ;Acknowledge IRQ, so we keep getting interrupts
popa ;Put the standard registers back
mov ebx,[pid]
sti
iretd ;Interrupt-Return
;;;;
call_stat:
call syscall_stat
jmp done
call_lstat:
call syscall_lstat
jmp done
call_write:
call syscall_write
jmp done
call_open:
call syscall_open
jmp done
call_readdir:
call syscall_readdir
jmp done
call_close:
call syscall_close
jmp done
call_fstat:
call syscall_fstat
jmp done
call_isatty:
call syscall_isatty
jmp done
call_lseek:
call syscall_lseek
jmp done
call_sbrk:
call syscall_sbrk
jmp done
call_exit:
call syscall_exit
jmp done
call_unhandled:
call syscall_unhandled
jmp done ;this should never be called, since unhandled causes kernel panic
;;; THIS CALLS NEED REENABLE INTERRUPTS BEFORE calling workers
;; TODO: redesign this shit!
call_read:
mov al, 0x20 ;Port number AND command number to Acknowledge IRQ
out 0x20, al ;Acknowledge IRQ, so we keep getting interrupts
sti
call syscall_read
jmp done_blocking
call_execve:
mov al, 0x20 ;Port number AND command number to Acknowledge IRQ
out 0x20, al ;Acknowledge IRQ, so we keep getting interrupts
sti
call syscall_execve
jmp done_blocking
|