This commit is contained in:
Kartik Agaram 2021-01-24 22:25:10 -08:00
parent 5d5b9b2e9b
commit 0373ace5e0
1 changed files with 16 additions and 18 deletions

View File

@ -59,6 +59,7 @@
# see baremetal/120allocate.subx # see baremetal/120allocate.subx
# stack grows down from 0x00070000 # stack grows down from 0x00070000
# see below # see below
# Consult https://wiki.osdev.org/Memory_Map_(x86) before modifying any of this.
## 16-bit entry point ## 16-bit entry point
@ -81,17 +82,15 @@
8e e0 # fs <- ax 8e e0 # fs <- ax
8e e8 # gs <- ax 8e e8 # gs <- ax
# We don't read or write the stack before we get to 32-bit mode, but we # initialize stack to 0x00070000
# still need to move the stack in case BIOS initializes it in some low # We don't read or write the stack before we get to 32-bit mode, but BIOS
# address that we want to write code into. # calls do. We need to move the stack in case BIOS initializes it to 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
b8 00 70 # ax <- 0x7000 b8 00 70 # ax <- 0x7000
8e d0 # ss <- ax 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) # disk read #1: load remaining sectors from first two tracks of disk into addresses [0x7e00, 0x17800)
b4 02 # ah <- 2 # read sectors from disk b4 02 # ah <- 2 # read sectors from disk
# dl comes conveniently initialized at boot time with the index of the device being booted # 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 # address to write sectors to = es:bx = 0x7e00, contiguous with boot segment
bb 00 00 # bx <- 0 bb 00 00 # bx <- 0
8e c3 # es <- bx 8e c3 # es <- bx
# 20:
bb 00 7e # bx <- 0x7e00 [label] bb 00 7e # bx <- 0x7e00 [label]
cd 13 # int 13h, BIOS disk service 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 # 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 # this is from https://github.com/mit-pdos/xv6-public/blob/master/bootasm.S
# seta20.1: # seta20.1:
@ -118,7 +116,7 @@
b0 d1 # al <- 0xd1 b0 d1 # al <- 0xd1
e6 64 # port 0x64 <- al e6 64 # port 0x64 <- al
# 33: # 36:
# seta20.2: # seta20.2:
e4 64 # al <- port 0x64 e4 64 # al <- port 0x64
a8 02 # set zf if bit 1 (second-least significant) is not set a8 02 # set zf if bit 1 (second-least significant) is not set
@ -127,7 +125,7 @@
b0 df # al <- 0xdf b0 df # al <- 0xdf
e6 64 # port 0x64 <- al e6 64 # port 0x64 <- al
# 3d: # 40:
# adjust video mode # adjust video mode
b4 4f # ah <- 4f (VBE) b4 4f # ah <- 4f (VBE)
b0 02 # al <- 02 (set video mode) b0 02 # al <- 02 (set video mode)
@ -136,7 +134,7 @@
# fallback mode: 0x0101 (640x480x256) # fallback mode: 0x0101 (640x480x256)
cd 10 # int 10h, Vesa BIOS extensions cd 10 # int 10h, Vesa BIOS extensions
# 46: # 49:
# load information for the (hopefully) current video mode # load information for the (hopefully) current video mode
# mostly just for the address to the linear frame buffer # mostly just for the address to the linear frame buffer
b4 4f # ah <- 4f (VBE) b4 4f # ah <- 4f (VBE)
@ -145,7 +143,7 @@
bf 00 7f # di <- 0x7f00 (video mode info) [label] bf 00 7f # di <- 0x7f00 (video mode info) [label]
cd 10 cd 10
# 52: # 55:
# switch to 32-bit mode # switch to 32-bit mode
0f 01 16 # lgdt 00/mod/indirect 010/subop 110/rm/use-disp16 0f 01 16 # lgdt 00/mod/indirect 010/subop 110/rm/use-disp16
f8 7c # *gdt_descriptor [label] 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] 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 # padding
# 66: # 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 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
@ -227,7 +225,7 @@ e9 fd ff # loop forever
8e e8 # gs <- ax 8e e8 # gs <- ax
# 10e: # 10e:
bc 00 00 07 00 # esp <- 0x00070000 (wasting earlier stack above) bc 00 00 07 00 # esp <- 0x00070000
# 113: # 113:
# load interrupt handlers # load interrupt handlers