This commit is contained in:
parent
480daf408c
commit
c0607ecca8
2
400.mu
2
400.mu
|
@ -9,7 +9,7 @@ sig draw-cursor-on-real-screen g: grapheme
|
|||
sig read-key kbd: (addr keyboard) -> _/eax: byte
|
||||
|
||||
# disk
|
||||
sig load-sector-string-from-primary-bus-secondary-drive LBAlo: byte, LBAmid: byte, LBAhi: byte, out: (addr stream byte)
|
||||
sig load-first-sector-from-primary-bus-secondary-drive out: (addr stream byte)
|
||||
|
||||
# tests
|
||||
sig count-test-failure
|
||||
|
|
22
boot.subx
22
boot.subx
|
@ -916,17 +916,15 @@ Font:
|
|||
# offset 1800 (address 0x9400)
|
||||
== code 0x9400
|
||||
|
||||
# Use 28-bit PIO mode to transfer a string spanning at most one sector (512
|
||||
# bytes) of data.
|
||||
# Use 28-bit PIO mode to read the first sector (512 bytes) from an IDE (ATA)
|
||||
# disk drive.
|
||||
# Inspired by https://colorforth.github.io/ide.html
|
||||
#
|
||||
# Resources:
|
||||
# https://wiki.osdev.org/ATA_PIO_Mode
|
||||
# https://forum.osdev.org/viewtopic.php?f=1&p=167798
|
||||
# read-sector, according to https://www.scs.stanford.edu/11wi-cs140/pintos/specs/ata-3-std.pdf
|
||||
#
|
||||
# Currently assumes top 4 bits of the 28-bit LBA coordinate are 0.
|
||||
load-sector-string-from-primary-bus-secondary-drive: # LBAlo: byte, LBAmid: byte, LBAhi: byte, out: (addr stream byte)
|
||||
load-first-sector-from-primary-bus-secondary-drive: # out: (addr stream byte)
|
||||
# . prologue
|
||||
55/push-ebp
|
||||
89/<- %ebp 4/r32/esp
|
||||
|
@ -937,12 +935,12 @@ load-sector-string-from-primary-bus-secondary-drive: # LBAlo: byte, LBAmid: byt
|
|||
# check for drive
|
||||
(secondary-drive-exists?) # => eax
|
||||
3d/compare-eax-and 0/imm32/false
|
||||
0f 84/jump-if-= $load-sector-string-from-primary-bus-secondary-drive:end/disp32
|
||||
0f 84/jump-if-= $load-first-sector-from-primary-bus-secondary-drive:end/disp32
|
||||
# kick off read
|
||||
(ata-drive-select 0xf0) # primary bus, secondary drive; 4 LSBs contain 4 upper bits of LBA (here 0)
|
||||
(clear-ata-error)
|
||||
(ata-sector-count 1)
|
||||
(ata-lba *(ebp+8) *(ebp+0xc) *(ebp+0x10)) # lower 24 bits of LBA
|
||||
(ata-lba 0 0 0) # lower 24 bits of LBA, all 0
|
||||
(ata-command 0x20) # read sectors with retries
|
||||
# poll for results
|
||||
(poll-ata-primary-bus-primary-drive-regular-status-word)
|
||||
|
@ -954,20 +952,20 @@ load-sector-string-from-primary-bus-secondary-drive: # LBAlo: byte, LBAmid: byt
|
|||
74/jump-if-= break/disp8
|
||||
ed/read-port-dx-into-eax
|
||||
# write 4 bytes to stream one at a time
|
||||
(append-byte *(ebp+0x14) %eax)
|
||||
(append-byte *(ebp+8) %eax)
|
||||
49/decrement-ecx
|
||||
c1/shift 5/subop/right-padding-zeroes %eax 8/imm8
|
||||
(append-byte *(ebp+0x14) %eax)
|
||||
(append-byte *(ebp+8) %eax)
|
||||
49/decrement-ecx
|
||||
c1/shift 5/subop/right-padding-zeroes %eax 8/imm8
|
||||
(append-byte *(ebp+0x14) %eax)
|
||||
(append-byte *(ebp+8) %eax)
|
||||
49/decrement-ecx
|
||||
c1/shift 5/subop/right-padding-zeroes %eax 8/imm8
|
||||
(append-byte *(ebp+0x14) %eax)
|
||||
(append-byte *(ebp+8) %eax)
|
||||
49/decrement-ecx
|
||||
eb/jump loop/disp8
|
||||
}
|
||||
$load-sector-string-from-primary-bus-secondary-drive:end:
|
||||
$load-first-sector-from-primary-bus-secondary-drive:end:
|
||||
# . restore registers
|
||||
5a/pop-to-edx
|
||||
59/pop-to-ecx
|
||||
|
|
|
@ -28,7 +28,7 @@ fn load-sandbox-from-secondary-disk _self: (addr sandbox) {
|
|||
var self/esi: (addr sandbox) <- copy _self
|
||||
var s-storage: (stream byte 0x200)
|
||||
var s/ebx: (addr stream byte) <- address s-storage
|
||||
load-sector-string-from-primary-bus-secondary-drive 0/lbalo, 0/lbamid, 0/lbahi, s
|
||||
load-first-sector-from-primary-bus-secondary-drive s
|
||||
{
|
||||
var done?/eax: boolean <- stream-empty? s
|
||||
compare done?, 0/false
|
||||
|
|
Loading…
Reference in New Issue