-
Notifications
You must be signed in to change notification settings - Fork 0
/
bits.asm
executable file
·274 lines (230 loc) · 2.8 KB
/
bits.asm
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
[bits 64]
global outb
global outw
global outd
global inb
global inw
global ind
global simple
global first
global snd
global intq
global irq1_ps2_port1
global irq1_ps2_port2
global testq
global disable_pic
global enable_ioapic_maybe
global enable_int
global disable_int
global readthemsrthing
global disable_local_apic
global io_wait
extern call_lua_int
extern wait_for_out_data
global a_irq4_handler
extern irq4_handler
simple:
mov rax, 0x87654321
ret
first:
mov rax, rdi
ret
snd:
mov rax, rsi
ret
outb:
push dx
mov dx, di
mov ax, si
out dx, al
pop dx
ret
outd:
push dx
mov dx, di
mov eax, esi
out dx, eax
pop dx
ret
outw:
push dx
mov dx, di
mov ax, si
out dx, ax
pop dx
ret
inb:
push dx
mov dx, di
in al, dx
pop dx
ret
ind:
push dx
mov dx, di
in eax, dx
pop dx
ret
inw:
push dx
mov dx, di
in ax, dx
pop dx
ret
intq:
push rax
mov al, [0xb8000]
inc al
mov [0xb8000], al
;mov [0x200000], al
; write to EOI
mov rax, 0xfee000b0
mov [rax], rax
pop rax
iretq
irq1_ps2_port1:
push rax
mov al, [0xb8000]
inc al
mov [0xb8000], al
in al, 0x60
;write eoi
mov al, 0x20
out 0x20, al
; write eoi to apic???
;mov rax, 0xfee000b0
;mov [rax], rax
pop rax
iretq
%macro pushforccall 0
push rax
;push rbx ; PRESERVED
push rcx
push rdx
;push rbp ; PRESERVED
push rdi
push rsi
push r8
push r9
push r10
push r11
;push r12
;push r13
;push r14
;push r15
%endmacro
%macro popforccall 0
;pop r15
;pop r14
;pop r13
;pop r12
pop r11
pop r10
pop r9
pop r8
pop rsi
pop rdi
;pop rbp
pop rdx
pop rcx
;pop rbx
pop rax
%endmacro
%macro lirq 1
pushforccall
mov rdi, %1
call call_lua_int
popforccall
iretq
%endmacro
%macro dlirq 1
global irq%1
irq%1: lirq 0x20 + %1
%endmacro
dlirq 0
dlirq 1
dlirq 2
dlirq 3
dlirq 4
dlirq 5
dlirq 6
dlirq 7
dlirq 8
dlirq 9
dlirq 10
dlirq 11
dlirq 12
dlirq 13
dlirq 14
dlirq 15
irq1_ps2_port2:
push rax
mov al, [0xb8000]
inc al
mov [0xb8000], al
in al, 0x60
; write slave eoi
mov al, 0x20
out 0xa0, al
; write master eoi
mov al, 0x20
out 0x20, al
pop rax
iretq
a_irq4_handler:
push rax
mov al, [0xb8002]
inc al
mov [0xb8002], al
call irq4_handler
; eoi
mov al, 0x20
out 0x20, al
; shouldnt need this (slave eoi)
out 0xa0, al
; ??? shouldnt need this
mov rax, 0xfee000b0
mov [rax], rax
pop rax
iretq
testq:
;int 80h
int 0x24
;int 0
ret
disable_pic:
mov al, 0xff
out 0xa1, al
out 0x21, al
ret
enable_ioapic_maybe:
mov al, 0x70
out 0x22, al
mov al, 0x01
out 0x23, al
ret
disable_int:
cli
ret
enable_int:
sti
ret
readthemsrthing:
mov ecx, 0x1b
rdmsr
mov [0x200000], edx
mov [0x200004], eax
ret
disable_local_apic:
mov ecx, 0x1b
rdmsr
and eax, 0xfffff7ff
wrmsr
ret
io_wait:
; apparently this is okay
push rax
mov al, 0
out 0x80, al
pop rax
ret