-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentry.S
98 lines (89 loc) · 2.62 KB
/
entry.S
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
/*
* entry.S - Entry point to system mode from user mode
*/
#include <asm.h>
#include <segment.h>
/**************************************************/
/**** Save & Restore ******************************/
/** **/
/** When we change to privilege level 0 (kernel) **/
/** (through an interrupt, a system call, an **/
/** exception ...) we must save the state of the **/
/** currently running task (save). **/
/** **/
/** Stack layout in 'systemCall': **/
/** **/
/** 0(%esp) - %ebx \ **/
/** 4(%esp) - %ecx | **/
/** 8(%esp) - %edx | **/
/** C(%esp) - %esi | Register saved **/
/** 10(%esp) - %edi | by 'save' **/
/** 14(%esp) - %ebp | **/
/** 18(%esp) - %eax | **/
/** 1C(%esp) - %ds | **/
/** 20(%esp) - %es | **/
/** 24(%esp) - %fs | **/
/** 28(%esp) - %gs / **/
/** 2C(%esp) - %eip \ **/
/** 30(%esp) - %cs | **/
/** 34(%esp) - %eflags | Return context saved **/
/** 38(%esp) - %oldesp | by the processor. **/
/** 3C(%esp) - %oldss / **/
/** **/
/**************************************************/
#define SAVE_ALL \
pushl %gs; \
pushl %fs; \
pushl %es; \
pushl %ds; \
pushl %eax; \
pushl %ebp; \
pushl %edi; \
pushl %esi; \
pushl %edx; \
pushl %ecx; \
pushl %ebx; \
movl $__KERNEL_DS, %edx; \
movl %edx, %ds; \
movl %edx, %es;
#define RESTORE_ALL \
popl %ebx; \
popl %ecx; \
popl %edx; \
popl %esi; \
popl %edi; \
popl %ebp; \
popl %eax; \
popl %ds; \
popl %es; \
popl %fs; \
popl %gs;
#define EOI \
movb $0x20, %al; \
outb %al, $0x20;
ENTRY(keyboard_handler)
SAVE_ALL
EOI
call keyboard_routine
RESTORE_ALL
iret
ENTRY(clock_handler)
SAVE_ALL
EOI
call clock_routine
RESTORE_ALL
iret
ENTRY(system_call_handler)
SAVE_ALL
cmpl $0, %eax
jl err
cmpl $0x2D, %eax
jg err
call *sys_call_table(, %eax, 0x04)
jmp end
err:
call sys_ni_syscall
end:
movl %eax, 0x18(%esp)
RESTORE_ALL
iret