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
|
bits 32
global syscall_isr
global quit_isr
global yield_isr
global _start_user_mode
global kbd_isr
extern syscall_table
extern active_task
extern delete_task
extern advance_active_task
extern on_kbd_isr
extern make_sure_tasks
n_syscalls equ 0x9
section .text
syscall_isr:
cmp eax, n_syscalls
jge .bad
mov eax, dword [syscall_table + eax * 4]
push edi
push esi
push edx
push ecx
push ebx
call eax
add esp, 20
iret
.bad:
mov eax, -1
iret
quit_isr:
push dword [active_task]
call delete_task
call make_sure_tasks
mov dword [esp], yield_isr.return_to_task
jmp advance_active_task
yield_isr:
mov eax, dword [active_task]
mov dword [eax + 8], ebx
mov dword [eax + 12], ecx
mov dword [eax + 16], edx
mov dword [eax + 20], esi
mov dword [eax + 24], edi
mov dword [eax + 28], ebp
mov edx, dword [esp]
mov dword [eax], edx
mov edx, cr3
mov dword [eax + 4], edx
mov edx, dword [esp + 12]
mov dword [eax + 32], edx
call advance_active_task
.return_to_task:
mov eax, dword [active_task]
mov edx, dword [eax]
mov dword [esp], edx
mov edx, dword [eax + 4]
mov cr3, edx
mov edx, dword [eax + 32]
mov dword [esp + 12], edx
mov ebx, dword [eax + 8]
mov ecx, dword [eax + 12]
mov edx, dword [eax + 16]
mov esi, dword [eax + 20]
mov edi, dword [eax + 24]
mov ebp, dword [eax + 28]
_before_start_task:
iret
_start_user_mode:
mov ax, 0x2b
mov ds, ax
push dword 0x2b
sub esp, 4
push dword 0x00000200;interrupt flag
push dword 0x23
sub esp, 4
jmp yield_isr.return_to_task
kbd_isr:
push eax
push ecx
push edx
call on_kbd_isr
mov al, 0x20
out 0x0020, al
pop edx
pop ecx
pop eax
iret
|