-
Notifications
You must be signed in to change notification settings - Fork 8
/
vga.S
446 lines (418 loc) · 9.48 KB
/
vga.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
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
# a0 = PCI Config Entry for QEMU VGA
_setup_qemu_vga:
push ra
push a0
la a0, setup_qemu_vga
call _writeln
pop a0
# mode 13h
# code from https://gist.github.com/iamgreaser/15a0a81cd117d4efd1c47ce598c13c91
mv t0, a0
# Set up frame buffer
la t1, _vga_framebuffer
sw t1, 0x10(t0)
# Set up I/O
la t2, _vga_mmio
sw t2, 0x18(t0)
# Enable memory accesses for this device
lw a0, 0x04(t0)
ori a0, a0, 0x02
sw a0, 0x04(t0)
lw a0, 0x04(t0)
# Set up video mode somehow
li t3, 0x60 # Enable LFB, enable 8-bit DAC
sh t3, 0x508(t2)
# Set Mode 13h by hand
la a0, mode_13h_regs
addi a1, t2, 0x400-0xC0
la t3, 0xC0
1:
# Grab address
lbu a3, 0(a0)
beq a3, zero, 2f
add a2, a1, a3
# Grab index and data
lb a4, 1(a0)
lbu a5, 2(a0)
# Advance a0
addi a0, a0, 3
# If this is for the attribute controller,
# treat it specially.
blt a3, t3, 3f
# If this is an external register,
# also treat it specially.
blt a4, zero, 4f
# Normal case
sb a4, 0(a2)
sb a5, 1(a2)
j 1b
3:
# The attribute controller is a special case
lb zero, 0xDA(a1)
sb a4, 0(a2)
sb a5, 0(a2)
j 1b
4:
# External registers are also special
# but not as special as the attribute controller
sb a5, 0(a2)
j 1b
2:
# Set up a palette
li t3, 0
sb t3, 0x408(t2)
li t3, 0
li t4, 256*3
la a0, initial_palette
1:
lb t5, 0(a0)
sb t5, 0x409(t2)
addi a0, a0, 1
addi t3, t3, 1
bltu t3, t4, 1b
# Draw Purple Background
la t0, _vga_framebuffer
li t2, 0
_draw_loop:
add t3, t0, t2
li t1, 0xFFFFFFFFFFFFFFFF
sd t1, 0x0(t3)
li t1, 1
add t2, t1, t2
li t3, 0xFFFF
bne t2, t3,_draw_loop
pop ra
ret
mode_13h_regs:
# Miscellaneous Output Register:
# Just a single port.
# But bit 0 determines whether we use 3Dx or 3Bx.
# So we need to set this early.
.byte 0xC2, 0xFF, 0x63
# Sequencer:
# Disable reset here.
.byte 0xC4, 0x00, 0x00
# Attributes:
# - Read 3DA to reset flip-flop
# - Write 3C0 for address
# - Write 3C0 for data
.byte 0xC0, 0x00, 0x00
.byte 0xC0, 0x01, 0x02
.byte 0xC0, 0x02, 0x08
.byte 0xC0, 0x03, 0x0A
.byte 0xC0, 0x04, 0x20
.byte 0xC0, 0x05, 0x22
.byte 0xC0, 0x06, 0x28
.byte 0xC0, 0x07, 0x2A
.byte 0xC0, 0x08, 0x15
.byte 0xC0, 0x09, 0x17
.byte 0xC0, 0x0A, 0x1D
.byte 0xC0, 0x0B, 0x1F
.byte 0xC0, 0x0C, 0x35
.byte 0xC0, 0x0D, 0x37
.byte 0xC0, 0x0E, 0x3D
.byte 0xC0, 0x0F, 0x3F
.byte 0xC0, 0x30, 0x41
.byte 0xC0, 0x31, 0x00
.byte 0xC0, 0x32, 0x0F
.byte 0xC0, 0x33, 0x00
.byte 0xC0, 0x34, 0x00
# Graphics Mode
.byte 0xCE, 0x00, 0x00
.byte 0xCE, 0x01, 0x00
.byte 0xCE, 0x02, 0x00
.byte 0xCE, 0x03, 0x00
.byte 0xCE, 0x04, 0x00
.byte 0xCE, 0x05, 0x40
.byte 0xCE, 0x06, 0x05
.byte 0xCE, 0x07, 0x00
.byte 0xCE, 0x08, 0xFF
# CRTC
.byte 0xD4, 0x11, 0x0E # Do this to unprotect the registers
.byte 0xD4, 0x00, 0x5F
.byte 0xD4, 0x01, 0x4F
.byte 0xD4, 0x02, 0x50
.byte 0xD4, 0x03, 0x82
.byte 0xD4, 0x04, 0x54
.byte 0xD4, 0x05, 0x80
.byte 0xD4, 0x06, 0xBF
.byte 0xD4, 0x07, 0x1F
.byte 0xD4, 0x08, 0x00
.byte 0xD4, 0x09, 0x41
.byte 0xD4, 0x0A, 0x20
.byte 0xD4, 0x0B, 0x1F
.byte 0xD4, 0x0C, 0x00
.byte 0xD4, 0x0D, 0x00
.byte 0xD4, 0x0E, 0xFF
.byte 0xD4, 0x0F, 0xFF
.byte 0xD4, 0x10, 0x9C
.byte 0xD4, 0x11, 0x8E # Registers are now reprotected
.byte 0xD4, 0x12, 0x8F
.byte 0xD4, 0x13, 0x28
.byte 0xD4, 0x14, 0x40
.byte 0xD4, 0x15, 0x96
.byte 0xD4, 0x16, 0xB9
.byte 0xD4, 0x17, 0xA3
# Sequencer
.byte 0xC4, 0x01, 0x01
.byte 0xC4, 0x02, 0x0F
.byte 0xC4, 0x03, 0x00
.byte 0xC4, 0x04, 0x0E
.byte 0x00
initial_palette:
.byte 0x00, 0x00, 0x00
.byte 0x00, 0x00, 0x55
.byte 0x00, 0x00, 0xAA
.byte 0x00, 0x00, 0xFF
.byte 0x00, 0x55, 0x00
.byte 0x00, 0x55, 0x55
.byte 0x00, 0x55, 0xAA
.byte 0x00, 0x55, 0xFF
.byte 0x00, 0xAA, 0x00
.byte 0x00, 0xAA, 0x55
.byte 0x00, 0xAA, 0xAA
.byte 0x00, 0xAA, 0xFF
.byte 0x00, 0xFF, 0x00
.byte 0x00, 0xFF, 0x55
.byte 0x00, 0xFF, 0xAA
.byte 0x00, 0xFF, 0xFF
.byte 0x55, 0x00, 0x00
.byte 0x55, 0x00, 0x55
.byte 0x55, 0x00, 0xAA
.byte 0x55, 0x00, 0xFF
.byte 0x55, 0x55, 0x00
.byte 0x55, 0x55, 0x55
.byte 0x55, 0x55, 0xAA
.byte 0x55, 0x55, 0xFF
.byte 0x55, 0xAA, 0x00
.byte 0x55, 0xAA, 0x55
.byte 0x55, 0xAA, 0xAA
.byte 0x55, 0xAA, 0xFF
.byte 0x55, 0xFF, 0x00
.byte 0x55, 0xFF, 0x55
.byte 0x55, 0xFF, 0xAA
.byte 0x55, 0xFF, 0xFF
.byte 0xAA, 0x00, 0x00
.byte 0xAA, 0x00, 0x55
.byte 0xAA, 0x00, 0xAA
.byte 0xAA, 0x00, 0xFF
.byte 0xAA, 0x55, 0x00
.byte 0xAA, 0x55, 0x55
.byte 0xAA, 0x55, 0xAA
.byte 0xAA, 0x55, 0xFF
.byte 0xAA, 0xAA, 0x00
.byte 0xAA, 0xAA, 0x55
.byte 0xAA, 0xAA, 0xAA
.byte 0xAA, 0xAA, 0xFF
.byte 0xAA, 0xFF, 0x00
.byte 0xAA, 0xFF, 0x55
.byte 0xAA, 0xFF, 0xAA
.byte 0xAA, 0xFF, 0xFF
.byte 0xFF, 0x00, 0x00
.byte 0xFF, 0x00, 0x55
.byte 0xFF, 0x00, 0xAA
.byte 0xFF, 0x00, 0xFF
.byte 0xFF, 0x55, 0x00
.byte 0xFF, 0x55, 0x55
.byte 0xFF, 0x55, 0xAA
.byte 0xFF, 0x55, 0xFF
.byte 0xFF, 0xAA, 0x00
.byte 0xFF, 0xAA, 0x55
.byte 0xFF, 0xAA, 0xAA
.byte 0xFF, 0xAA, 0xFF
.byte 0xFF, 0xFF, 0x00
.byte 0xFF, 0xFF, 0x55
.byte 0xFF, 0xFF, 0xAA
.byte 0xFF, 0xFF, 0xFF
.byte 0x00, 0x00, 0x00
.byte 0x00, 0x00, 0x55
.byte 0x00, 0x00, 0xAA
.byte 0x00, 0x00, 0xFF
.byte 0x00, 0x55, 0x00
.byte 0x00, 0x55, 0x55
.byte 0x00, 0x55, 0xAA
.byte 0x00, 0x55, 0xFF
.byte 0x00, 0xAA, 0x00
.byte 0x00, 0xAA, 0x55
.byte 0x00, 0xAA, 0xAA
.byte 0x00, 0xAA, 0xFF
.byte 0x00, 0xFF, 0x00
.byte 0x00, 0xFF, 0x55
.byte 0x00, 0xFF, 0xAA
.byte 0x00, 0xFF, 0xFF
.byte 0x55, 0x00, 0x00
.byte 0x55, 0x00, 0x55
.byte 0x55, 0x00, 0xAA
.byte 0x55, 0x00, 0xFF
.byte 0x55, 0x55, 0x00
.byte 0x55, 0x55, 0x55
.byte 0x55, 0x55, 0xAA
.byte 0x55, 0x55, 0xFF
.byte 0x55, 0xAA, 0x00
.byte 0x55, 0xAA, 0x55
.byte 0x55, 0xAA, 0xAA
.byte 0x55, 0xAA, 0xFF
.byte 0x55, 0xFF, 0x00
.byte 0x55, 0xFF, 0x55
.byte 0x55, 0xFF, 0xAA
.byte 0x55, 0xFF, 0xFF
.byte 0xAA, 0x00, 0x00
.byte 0xAA, 0x00, 0x55
.byte 0xAA, 0x00, 0xAA
.byte 0xAA, 0x00, 0xFF
.byte 0xAA, 0x55, 0x00
.byte 0xAA, 0x55, 0x55
.byte 0xAA, 0x55, 0xAA
.byte 0xAA, 0x55, 0xFF
.byte 0xAA, 0xAA, 0x00
.byte 0xAA, 0xAA, 0x55
.byte 0xAA, 0xAA, 0xAA
.byte 0xAA, 0xAA, 0xFF
.byte 0xAA, 0xFF, 0x00
.byte 0xAA, 0xFF, 0x55
.byte 0xAA, 0xFF, 0xAA
.byte 0xAA, 0xFF, 0xFF
.byte 0xFF, 0x00, 0x00
.byte 0xFF, 0x00, 0x55
.byte 0xFF, 0x00, 0xAA
.byte 0xFF, 0x00, 0xFF
.byte 0xFF, 0x55, 0x00
.byte 0xFF, 0x55, 0x55
.byte 0xFF, 0x55, 0xAA
.byte 0xFF, 0x55, 0xFF
.byte 0xFF, 0xAA, 0x00
.byte 0xFF, 0xAA, 0x55
.byte 0xFF, 0xAA, 0xAA
.byte 0xFF, 0xAA, 0xFF
.byte 0xFF, 0xFF, 0x00
.byte 0xFF, 0xFF, 0x55
.byte 0xFF, 0xFF, 0xAA
.byte 0xFF, 0xFF, 0xFF
.byte 0x00, 0x00, 0x00
.byte 0x00, 0x00, 0x55
.byte 0x00, 0x00, 0xAA
.byte 0x00, 0x00, 0xFF
.byte 0x00, 0x55, 0x00
.byte 0x00, 0x55, 0x55
.byte 0x00, 0x55, 0xAA
.byte 0x00, 0x55, 0xFF
.byte 0x00, 0xAA, 0x00
.byte 0x00, 0xAA, 0x55
.byte 0x00, 0xAA, 0xAA
.byte 0x00, 0xAA, 0xFF
.byte 0x00, 0xFF, 0x00
.byte 0x00, 0xFF, 0x55
.byte 0x00, 0xFF, 0xAA
.byte 0x00, 0xFF, 0xFF
.byte 0x55, 0x00, 0x00
.byte 0x55, 0x00, 0x55
.byte 0x55, 0x00, 0xAA
.byte 0x55, 0x00, 0xFF
.byte 0x55, 0x55, 0x00
.byte 0x55, 0x55, 0x55
.byte 0x55, 0x55, 0xAA
.byte 0x55, 0x55, 0xFF
.byte 0x55, 0xAA, 0x00
.byte 0x55, 0xAA, 0x55
.byte 0x55, 0xAA, 0xAA
.byte 0x55, 0xAA, 0xFF
.byte 0x55, 0xFF, 0x00
.byte 0x55, 0xFF, 0x55
.byte 0x55, 0xFF, 0xAA
.byte 0x55, 0xFF, 0xFF
.byte 0xAA, 0x00, 0x00
.byte 0xAA, 0x00, 0x55
.byte 0xAA, 0x00, 0xAA
.byte 0xAA, 0x00, 0xFF
.byte 0xAA, 0x55, 0x00
.byte 0xAA, 0x55, 0x55
.byte 0xAA, 0x55, 0xAA
.byte 0xAA, 0x55, 0xFF
.byte 0xAA, 0xAA, 0x00
.byte 0xAA, 0xAA, 0x55
.byte 0xAA, 0xAA, 0xAA
.byte 0xAA, 0xAA, 0xFF
.byte 0xAA, 0xFF, 0x00
.byte 0xAA, 0xFF, 0x55
.byte 0xAA, 0xFF, 0xAA
.byte 0xAA, 0xFF, 0xFF
.byte 0xFF, 0x00, 0x00
.byte 0xFF, 0x00, 0x55
.byte 0xFF, 0x00, 0xAA
.byte 0xFF, 0x00, 0xFF
.byte 0xFF, 0x55, 0x00
.byte 0xFF, 0x55, 0x55
.byte 0xFF, 0x55, 0xAA
.byte 0xFF, 0x55, 0xFF
.byte 0xFF, 0xAA, 0x00
.byte 0xFF, 0xAA, 0x55
.byte 0xFF, 0xAA, 0xAA
.byte 0xFF, 0xAA, 0xFF
.byte 0xFF, 0xFF, 0x00
.byte 0xFF, 0xFF, 0x55
.byte 0xFF, 0xFF, 0xAA
.byte 0xFF, 0xFF, 0xFF
.byte 0x00, 0x00, 0x00
.byte 0x00, 0x00, 0x55
.byte 0x00, 0x00, 0xAA
.byte 0x00, 0x00, 0xFF
.byte 0x00, 0x55, 0x00
.byte 0x00, 0x55, 0x55
.byte 0x00, 0x55, 0xAA
.byte 0x00, 0x55, 0xFF
.byte 0x00, 0xAA, 0x00
.byte 0x00, 0xAA, 0x55
.byte 0x00, 0xAA, 0xAA
.byte 0x00, 0xAA, 0xFF
.byte 0x00, 0xFF, 0x00
.byte 0x00, 0xFF, 0x55
.byte 0x00, 0xFF, 0xAA
.byte 0x00, 0xFF, 0xFF
.byte 0x55, 0x00, 0x00
.byte 0x55, 0x00, 0x55
.byte 0x55, 0x00, 0xAA
.byte 0x55, 0x00, 0xFF
.byte 0x55, 0x55, 0x00
.byte 0x55, 0x55, 0x55
.byte 0x55, 0x55, 0xAA
.byte 0x55, 0x55, 0xFF
.byte 0x55, 0xAA, 0x00
.byte 0x55, 0xAA, 0x55
.byte 0x55, 0xAA, 0xAA
.byte 0x55, 0xAA, 0xFF
.byte 0x55, 0xFF, 0x00
.byte 0x55, 0xFF, 0x55
.byte 0x55, 0xFF, 0xAA
.byte 0x55, 0xFF, 0xFF
.byte 0xAA, 0x00, 0x00
.byte 0xAA, 0x00, 0x55
.byte 0xAA, 0x00, 0xAA
.byte 0xAA, 0x00, 0xFF
.byte 0xAA, 0x55, 0x00
.byte 0xAA, 0x55, 0x55
.byte 0xAA, 0x55, 0xAA
.byte 0xAA, 0x55, 0xFF
.byte 0xAA, 0xAA, 0x00
.byte 0xAA, 0xAA, 0x55
.byte 0xAA, 0xAA, 0xAA
.byte 0xAA, 0xAA, 0xFF
.byte 0xAA, 0xFF, 0x00
.byte 0xAA, 0xFF, 0x55
.byte 0xAA, 0xFF, 0xAA
.byte 0xAA, 0xFF, 0xFF
.byte 0xFF, 0x00, 0x00
.byte 0xFF, 0x00, 0x55
.byte 0xFF, 0x00, 0xAA
.byte 0xFF, 0x00, 0xFF
.byte 0xFF, 0x55, 0x00
.byte 0xFF, 0x55, 0x55
.byte 0xFF, 0x55, 0xAA
.byte 0xFF, 0x55, 0xFF
.byte 0xFF, 0xAA, 0x00
.byte 0xFF, 0xAA, 0x55
.byte 0xFF, 0xAA, 0xAA
.byte 0xFF, 0xAA, 0xFF
.byte 0xFF, 0xFF, 0x00
.byte 0xFF, 0xFF, 0x55
.byte 0xFF, 0xFF, 0xAA
.byte 0xFF, 0xFF, 0xFF