about summary refs log tree commit diff stats
path: root/baremetal
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2021-01-24 22:25:10 -0800
committerKartik Agaram <vc@akkartik.com>2021-01-24 22:25:10 -0800
commit0373ace5e025243a88a5619f2d3af2473e997ed8 (patch)
treee9a51acb6db28ef7b1df689997282e9f276a8112 /baremetal
parent5d5b9b2e9bbbe388f73a0fda4b622596d30e5352 (diff)
downloadmu-0373ace5e025243a88a5619f2d3af2473e997ed8.tar.gz
7564
Diffstat (limited to 'baremetal')
-rw-r--r--baremetal/boot.hex34
1 files changed, 16 insertions, 18 deletions
diff --git a/baremetal/boot.hex b/baremetal/boot.hex
index fda3c287..45b4f4d8 100644
--- a/baremetal/boot.hex
+++ b/baremetal/boot.hex
@@ -59,6 +59,7 @@
 #     see baremetal/120allocate.subx
 #   stack grows down from 0x00070000
 #     see below
+# Consult https://wiki.osdev.org/Memory_Map_(x86) before modifying any of this.
 
 ## 16-bit entry point
 
@@ -81,17 +82,15 @@
   8e e0  # fs <- ax
   8e e8  # gs <- ax
 
-  # We don't read or write the stack before we get to 32-bit mode, but we
-  # still need to move the stack in case BIOS initializes it in some low
-  # address that we want to write code into.
-  #
-  # We'll grow the stack downward from somewhere in 0x0007xxxx;
-  # consult https://wiki.osdev.org/Memory_Map_(x86) when modifying this
+  # initialize stack to 0x00070000
+  # We don't read or write the stack before we get to 32-bit mode, but BIOS
+  # calls do. We need to move the stack in case BIOS initializes it to some
+  # low address that we want to write code into.
   b8 00 70  # ax <- 0x7000
   8e d0  # ss <- ax
-  # Not bothering initializing sp register. Que sera sera.
+  bc 00 00  # sp <- 0x0000
 
-# 11:
+# 14:
   # disk read #1: load remaining sectors from first two tracks of disk into addresses [0x7e00, 0x17800)
   b4 02  # ah <- 2  # read sectors from disk
   # dl comes conveniently initialized at boot time with the index of the device being booted
@@ -102,12 +101,11 @@
   # address to write sectors to = es:bx = 0x7e00, contiguous with boot segment
   bb 00 00  # bx <- 0
   8e c3  # es <- bx
-# 20:
   bb 00 7e  # bx <- 0x7e00 [label]
   cd 13  # int 13h, BIOS disk service
-  0f 82 a6 00  # jump-if-carry disk_error [label]
+  0f 82 a3 00  # jump-if-carry disk_error [label]
 
-# 29:
+# 2c:
   # undo the A20 hack: https://en.wikipedia.org/wiki/A20_line
   # this is from https://github.com/mit-pdos/xv6-public/blob/master/bootasm.S
   # seta20.1:
@@ -118,7 +116,7 @@
   b0 d1  # al <- 0xd1
   e6 64  # port 0x64 <- al
 
-# 33:
+# 36:
   # seta20.2:
   e4 64  # al <- port 0x64
   a8 02  # set zf if bit 1 (second-least significant) is not set
@@ -127,7 +125,7 @@
   b0 df  # al <- 0xdf
   e6 64  # port 0x64 <- al
 
-# 3d:
+# 40:
   # adjust video mode
   b4 4f  # ah <- 4f (VBE)
   b0 02  # al <- 02 (set video mode)
@@ -136,7 +134,7 @@
             # fallback mode: 0x0101 (640x480x256)
   cd 10  # int 10h, Vesa BIOS extensions
 
-# 46:
+# 49:
   # load information for the (hopefully) current video mode
   # mostly just for the address to the linear frame buffer
   b4 4f  # ah <- 4f (VBE)
@@ -145,7 +143,7 @@
   bf 00 7f  # di <- 0x7f00 (video mode info) [label]
   cd 10
 
-# 52:
+# 55:
   # switch to 32-bit mode
   0f 01 16  # lgdt 00/mod/indirect 010/subop 110/rm/use-disp16
     f8 7c  # *gdt_descriptor [label]
@@ -155,8 +153,8 @@
   ea 00 7d 08 00  # far jump to initialize_32bit_mode after setting cs to the record at offset 8 in the gdt (gdt_code) [label]
 
 # padding
-# 66:
-                  00 00 00 00 00 00 00 00 00 00
+# 69:
+                           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
@@ -227,7 +225,7 @@ e9 fd ff  # loop forever
   8e e8  # gs <- ax
 
 # 10e:
-  bc 00 00 07 00  # esp <- 0x00070000 (wasting earlier stack above)
+  bc 00 00 07 00  # esp <- 0x00070000
 
 # 113:
   # load interrupt handlers