about summary refs log tree commit diff stats
path: root/baremetal
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2021-02-01 13:26:48 -0800
committerKartik Agaram <vc@akkartik.com>2021-02-01 13:26:48 -0800
commitcd83a22a599004e0087ef0a3d6e791537adfdbea (patch)
treead67959fe8a64137e0aa50d5e27b432b74922640 /baremetal
parent0167d5c5016010c27b7cc2396ad1dbc028917754 (diff)
downloadmu-cd83a22a599004e0087ef0a3d6e791537adfdbea.tar.gz
7682
Diffstat (limited to 'baremetal')
-rw-r--r--baremetal/boot.hex36
-rw-r--r--baremetal/boot0.hex16
2 files changed, 20 insertions, 32 deletions
diff --git a/baremetal/boot.hex b/baremetal/boot.hex
index 08f89fe5..b2156838 100644
--- a/baremetal/boot.hex
+++ b/baremetal/boot.hex
@@ -299,14 +299,12 @@ e9 fd ff  # loop forever
   # acknowledge interrupt
   b0 20  # al <- 0x20
   e6 20  # port 0x20 <- al
-  # read status into eax
   31 c0  # eax <- xor eax;  11/direct 000/r32/eax 000/rm32/eax
+  # check output buffer of 8042 keyboard controller (https://web.archive.org/web/20040604041507/http://panda.cs.ndsu.nodak.edu/~achapwes/PICmicro/keyboard/atkeyboard.html)
   e4 64  # al <- port 0x64
-  # if (status & 0x1) == 0, return
-  24 01  # al <- and 0x1
-  3c 00  # compare al, 0
-  74 89  # jump to epilogue if = [label]
-# 220:
+  a8 01  # set zf if bit 0 (least significant) is not set
+  74 89  # jump to epilogue if 0 bit is not set [label]
+# 21e:
   # - if keyboard buffer is full, return
   31 c9  # ecx <- xor ecx;  11/direct 001/r32/ecx 001/rm32/ecx
   # var index/ecx: byte
@@ -319,33 +317,29 @@ e9 fd ff  # loop forever
     30 80 00 00  # disp32 [label]
   # if (al != 0) return
   3c 00  # compare al, 0
-# 230:
   75 77  # jump to epilogue if != [label]
+# 230:
   # - read keycode
   e4 60  # al <- port 0x60
-# 234:
   # - key released
   # if (al == 0xaa) shift = false  # left shift is being lifted
   3c aa  # compare al, 0xaa
   75 0a  # jump to $1 if != [label]
-# 238:
   # *shift = 0
   c7  # copy imm32 to rm32
     05  # 00/mod/indirect 000/subop/copy 101/rm32/use-disp32
     10 80 00 00  # disp32 [label]
     00 00 00 00  # imm32
-# 242:
+# 240:
 # $1:
   # if (al == 0xb6) shift = false  # right shift is being lifted
   3c b6  # compare al, 0xb6
-# 244:
   75 0a  # jump to $1 if != [label]
   # *shift = 0
   c7  # copy imm32 to rm32
     05  # 00/mod/indirect 000/subop/copy 101/rm32/use-disp32
     10 80 00 00  # disp32 [label]
     00 00 00 00  # imm32
-# 250:
 # $2:
   # if (al & 0x80) a key is being lifted; return
   50  # push eax
@@ -353,7 +347,7 @@ e9 fd ff  # loop forever
   3c 00  # compare al, 0
   58  # pop to eax (without touching flags)
   75 51  # jump to epilogue if != [label]
-# 258:
+# 256:
   # - key pressed
   # if (al == 0x2a) shift = true, return  # left shift pressed
   3c 2a  # compare al, 0x2a
@@ -364,7 +358,7 @@ e9 fd ff  # loop forever
     10 80 00 00  # disp32 [label]
     01 00 00 00  # imm32
   eb 41 # jump to epilogue [label]
-# 268:
+# 266:
 # $3:
   # if (al == 0x36) shift = true, return  # right shift pressed
   3c 36  # compare al, 0x36
@@ -375,8 +369,8 @@ e9 fd ff  # loop forever
     10 80 00 00  # disp32 [label]
     01 00 00 00  # imm32
   eb 31 # jump to epilogue [label]
+# 276:
 # $4:
-# 278:
   # - convert key to character
   # if (shift) use keyboard normal map
   81  # operate on rm32 and imm32
@@ -384,35 +378,31 @@ e9 fd ff  # loop forever
     10 80 00 00  # disp32 = shift [label]
     00 00 00 00  # imm32
   74 08  # jump to $5 if = [label]
-# 284:
   # otherwise use keyboard shift map
   # al <- *(keyboard shift map + eax)
   8a  # copy m8 at rm32 to r8
     80  # 10/mod/*+disp32 000/r8/al 000/rm32/eax
     00 87 00 00  # disp32 [label]
   eb 06  # jump to $6 [label]
+# 28a:
 # $5:
-# 28c:
   # al <- *(keyboard normal map + eax)
   8a  # copy m8 at rm32 to r8
     80  # 10/mod/*+disp32 000/r8/al 000/rm32/eax
     00 86 00 00  # disp32 [label]
 # $6:
-# 292:
   # - if there's no character mapping, return
   3c 00  # compare al, 0
   74 13  # jump to epilogue if = [label]
-# 296:
+# 294:
   # - store al in keyboard buffer
   88  # copy r8 to m8 at r32
     81  # 10/mod/*+disp32 000/r8/al 001/rm32/ecx
     30 80 00 00  # disp32 [label]
-# 29c:
   # increment index
   fe  # increment byte
     05  # 00/mod/indirect 000/subop/increment 101/rm32/use-disp32
     28 80 00 00  # disp32 [label]
-# 2a2:
   # clear top nibble of index (keyboard buffer is circular)
   80  # and byte
     25  # 00/mod/indirect 100/subop/and 101/rm32/use-disp32
@@ -425,8 +415,8 @@ e9 fd ff  # loop forever
   cf  # iret
 
 # padding
-# 2ac:
-                                    00 00 00 00
+# 2aa:
+                              00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
diff --git a/baremetal/boot0.hex b/baremetal/boot0.hex
index 793b2b9f..adb320d1 100644
--- a/baremetal/boot0.hex
+++ b/baremetal/boot0.hex
@@ -1,8 +1,7 @@
 # A minimal bootable image that:
 #   - loads more sectors past the first boot sector (using BIOS primitives)
 #   - switches to 32-bit mode (giving up access to BIOS primitives)
-#   - sets up a handler for keyboard events
-#   - as an example program, prints '1' to the top-left position on screen (by writing to memory-mapped VGA memory) when the '1' key is typed
+#   - sets up a keyboard handler to print '1' at the top-left of screen when '1' is typed
 #
 # When it's ready to accept keys, it prints 'H' to the top-left of the screen.
 #
@@ -226,10 +225,10 @@ e9 fb ff ff ff  # loop forever
   # acknowledge interrupt
   b0 20  # al <- 0x20
   e6 20  # port 0x20 <- al
-  # read keyboard status (TODO: why bit 0? Doesn't line up with https://web.archive.org/web/20040604041507/http://panda.cs.ndsu.nodak.edu/~achapwes/PICmicro/keyboard/atkeyboard.html)
-#?   e4 64  # al <- port 0x64
-#?   a8 01  # set zf if bit 0 (least significant) is not set
-#?   74 11  # if bit 0 is not set, skip to epilogue
+  # check output buffer of 8042 keyboard controller (https://web.archive.org/web/20040604041507/http://panda.cs.ndsu.nodak.edu/~achapwes/PICmicro/keyboard/atkeyboard.html)
+  e4 64  # al <- port 0x64
+  a8 01  # set zf if bit 0 (least significant) is not set
+  74 11  # if bit 0 is not set, skip to epilogue
   # read keycode into eax
   31 c0  # eax <- xor eax;  11/direct 000/r32/eax 000/rm32/eax
   e4 60  # al <- port 0x60
@@ -248,9 +247,8 @@ e9 fb ff ff ff  # loop forever
   cf  # iret
 
 # padding
-# 14f
-                                             00
-00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# 155
+               00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
/a> ^
bd8c32cc ^







839d0c52 ^
bd8c32cc ^
839d0c52 ^
bd8c32cc ^


839d0c52 ^
bd8c32cc ^



839d0c52 ^
bd8c32cc ^
839d0c52 ^

bd8c32cc ^






839d0c52 ^


bd8c32cc ^







839d0c52 ^
bd8c32cc ^




839d0c52 ^
bd8c32cc ^



839d0c52 ^
bd8c32cc ^
839d0c52 ^
bd8c32cc ^







839d0c52 ^
bd8c32cc ^
839d0c52 ^
bd8c32cc ^







839d0c52 ^
bd8c32cc ^
839d0c52 ^
bd8c32cc ^







839d0c52 ^
bd8c32cc ^
839d0c52 ^
bd8c32cc ^







839d0c52 ^
bd8c32cc ^
839d0c52 ^
bd8c32cc ^







839d0c52 ^
bd8c32cc ^
839d0c52 ^
bd8c32cc ^







839d0c52 ^
bd8c32cc ^
839d0c52 ^
bd8c32cc ^







839d0c52 ^
bd8c32cc ^
839d0c52 ^
bd8c32cc ^







839d0c52 ^
bd8c32cc ^
839d0c52 ^
bd8c32cc ^







839d0c52 ^
bd8c32cc ^









839d0c52 ^
bd8c32cc ^

839d0c52 ^
bd8c32cc ^






839d0c52 ^
bd8c32cc ^
839d0c52 ^
bd8c32cc ^







839d0c52 ^
bd8c32cc ^
839d0c52 ^
bd8c32cc ^







839d0c52 ^
bd8c32cc ^









839d0c52 ^
bd8c32cc ^









839d0c52 ^
bd8c32cc ^









839d0c52 ^
bd8c32cc ^









839d0c52 ^
bd8c32cc ^














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