forked from jackmiller1/ece391-kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterrupts.S
More file actions
executable file
·92 lines (76 loc) · 2.3 KB
/
Copy pathinterrupts.S
File metadata and controls
executable file
·92 lines (76 loc) · 2.3 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
# interrupts.S - Assembly Wrapper for Interrupt Handlers
# This piece of code takes care of the interrupt handler
# and calls the appropriate function to handle the interrupt
#define ASM 1
#include "x86_desc.h"
.global system_call_handler
#define HANDLER(name,send_to_fn) \
.GLOBL name ;\
name: ;\
pushal ;\
pushfl ;\
call send_to_fn ;\
popfl ;\
popal ;\
iret ;\
# keyboard_handler: interrupt handler for keyboard interrupts
HANDLER(keyboard_handler, keyboard_interrupt_handler);
# clock_handler: interrupt handler for rtc interrupts
HANDLER(rtc_handler, rtc_interrupt_handler);
# pit handler: interrupt handler for pit interrupts
HANDLER(pit_handler, PIT_interrupt_and_schedule);
#-------------------------------------------------------------------#
#System Call Handler
#Save Registers -> Push Arguments -> Check Validity ->
# Load Call -> Make Call -> Restore Registers -> Interrupt Return.
#SYSTEM CALL JUMP TABLE - ONLY 1 - 6 ("execute" -> "close") FOR CHECKPT 2
system_call_jump_table:
.long 0x0, halt, execute, read, write, open, close, getargs, vidmap
# Main Syscall Handler
system_call_handler:
# Save all registers and flags except for eax, the return value
cli
pushl %es
pushl %ds
pushl %ebx
pushl %ecx
pushl %edx
pushl %esi
pushl %edi
pushl %ebp
pushfl
# Pushing arguments - need to save all registers according to Appendix B.
pushl %ebp #Pushed "to avoid leaking information to the user programs"
pushl %edi #Pushed "to avoid leaking information to the user programs"
pushl %esi #Pushed "to avoid leaking information to the user programs"
pushl %edx #Argument 3
pushl %ecx #Argument 2
pushl %ebx #Argument 1
#Check to see if our System Call Number (stored in %EAX) is within bounds (Chkpt 3 - 1:6)
cmpl $1, %eax
jl invalid
cmpl $8, %eax
jg invalid
# Call the correct system call according to the jumptable
sti
call *system_call_jump_table(,%eax,4)
cli
jmp restore
invalid:
movl $-1, %eax
restore:
# Popping arguments - 6 Registers * 4 Bytes = 24
addl $24, %esp
# Restore all regs, except for eax, and flags
popfl
popl %ebp
popl %edi
popl %esi
popl %edx
popl %ecx
popl %ebx
popl %ds
popl %es
sti
# Return from interrupt
iret