-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathentry.S
115 lines (105 loc) · 3 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* entry.S - Entry point to system mode from user mode
*/
#include <asm.h>
#include <segment.h>
#include <errno.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(syscall_handler_sysenter)
push $__USER_DS
push %ebp
pushfl
push $__USER_CS
//Guardamos @ret
push 4(%ebp)
SAVE_ALL
cmpl $0, %eax
jl sysenter_err
cmpl $MAX_SYSCALL, %eax
jg sysenter_err
call *sys_call_table(,%eax,0x04)
jmp sysenter_fin
sysenter_err:
movl $-ENOSYS, %eax
sysenter_fin:
//guardar el valor de ret del write en la pila de usuario
movl %eax, 0x18(%esp)
RESTORE_ALL
//metemos @ret en edx y en ecx stack pointer al top de la pila user
movl (%esp),%edx
movl 12(%esp),%ecx
sti
sysexit
ENTRY(keyboard_handler)
call update_ticks_user
SAVE_ALL
EOI
call keyboard_routine
RESTORE_ALL
call update_ticks_sys
iret
ENTRY(clock_handler)
call update_ticks_user
SAVE_ALL
EOI
call clock_routine
RESTORE_ALL
call update_ticks_sys
iret