-
Notifications
You must be signed in to change notification settings - Fork 2
/
interrupt_wrapper.S
199 lines (161 loc) · 3.15 KB
/
interrupt_wrapper.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
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
.text # The text section is used for keeping the actual code
.global rtc_wrapper, keybrd_wrapper, pit_wrapper, hd_read, hd_write, mouse_linkage
# saves all registers and flags before rtc_handler, restores all registers and flags after
rtc_wrapper:
pushal # push all registers
pushfl # push all flags
call rtc_handler
popfl # pop all flags
popal # pop all registers
iret
# saves all registers and flags before keyboard_handler, restores all registers and flags after
keybrd_wrapper:
pushal # push all registers
pushfl # push all flags
call keyboard_handler
popfl # pop all flags
popal # pop all registers
iret
pit_wrapper:
pushal
pushfl
call pit_handler
popfl
popal
iret
hd_read:
.intel_syntax noprefix
push ds
push es
push fs
push gs
push ss
push eax
push esi
push edi
push ebp
push edx
push ecx
push ebx
.att_syntax prefix
movw $0x0018, %dx
movw %dx, %ds
movw %dx, %es
movw %dx, %fs
movw %dx, %gs
movw %dx, %ss
.intel_syntax noprefix
mov dx,0x1F6
mov al,0xA0
out dx,al
mov dx,0x1F2 #Sector count port
mov al,1 #Read CH sectors
out dx,al
mov dx,0x1F3 #Sector number port
mov al,bl #BL is sector index
out dx,al
mov dx,0x1F4 #Cylinder low port
mov al,cl
out dx,al
mov dx,0x1F5 #Cylinder high port
mov al,ch
out dx,al
mov dx,0x1F7 #Command port
mov al,0x20 #Read with retry.
out dx,al
.still_going_read:
in al,dx
test al,8 #the sector buffer requires servicing.
jz .still_going_read #until the sector buffer is ready.
cld
mov dx,0x1F0
mov cx,256
rep insw #in to [EDI]
mov dx,0x1F7 #status port
in al,dx
pop ebx
pop ecx
pop edx
pop ebp
pop edi
pop esi
pop eax
pop ss
pop gs
pop fs
pop es
pop ds
ret
##########################################################
hd_write:
.intel_syntax noprefix
push ds
push es
push fs
push gs
push ss
push eax
push esi
push edi
push ebp
push edx
push ecx
push ebx
.att_syntax prefix
movw $0x18,%dx #set to kernel space ds
movw %dx,%ds
movw %dx,%es
movw %dx,%fs
movw %dx,%gs
movw %dx, %ss
.intel_syntax noprefix
mov dx,0x1F6
mov al,0xA0
out dx,al
mov dx,0x1F2 #Sector count port
mov al,1 #Read CH sectors
out dx,al
mov dx,0x1F3 #Sector number port
mov al,bl #BL is sector index
out dx,al
mov dx,0x1F4 #Cylinder low port
mov al,cl
out dx,al
mov dx,0x1F5 #Cylinder high port
mov al,ch
out dx,al
mov dx,0x1F7 #Command port
mov al,0x30 #Write with retry.
out dx,al
.still_going_write:
in al,dx
test al,8 #the sector buffer requires servicing.
jz .still_going_write #until the sector buffer is ready.
cld
mov dx,0x1F0
mov cx,256
rep outsw #out to [ESI]
mov dx,0x1F7 #Command port
in al,dx
pop ebx
pop ecx
pop edx
pop ebp
pop edi
pop esi
pop eax
pop ss
pop gs
pop fs
pop es
pop ds
ret
.att_syntax prefix
mouse_linkage:
pushal
pushf
cli
call mouse_handler
popfl
popal
iret