about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-04-17 19:49:50 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-04-17 19:49:50 -0700
commit18e8ee4e16d5a7a1b68a66eb02387e00fb4b55cf (patch)
tree43aa78b8e32242489957092fbb6aa99dccdd3801
parent31a2c8aac6e32773c593bf5fc89bfe5ae6469fca (diff)
downloadmu-18e8ee4e16d5a7a1b68a66eb02387e00fb4b55cf.tar.gz
start flushing the ATA disk cache
"Make sure to do a Cache Flush (ATA command 0xE7) after each write command
completes."
  https://wiki.osdev.org/index.php?title=ATA_PIO_Mode&oldid=25664#Writing_28_bit_LBA
-rw-r--r--boot.subx18
1 files changed, 18 insertions, 0 deletions
diff --git a/boot.subx b/boot.subx
index c19ab02a..0b840d58 100644
--- a/boot.subx
+++ b/boot.subx
@@ -1047,6 +1047,7 @@ $store-sectors:store-sector:
       eb/jump loop/disp8
     }
   }
+  (flush-ata-cache *(ebp+8))
 $store-sectors:end:
   # . restore registers
   5b/pop-to-ebx
@@ -1325,6 +1326,23 @@ $wait-400ns:end:
   5d/pop-to-ebp
   c3/return
 
+# Flush cache isn't in ATA 3, but it shows up by the ATA 5 spec:
+#   http://hddguru.com/download/documentation/ATA-ATAPI-standard-5/ATA-ATAPI-5.pdf
+flush-ata-cache:  # disk: (addr disk)
+  # . prologue
+  55/push-ebp
+  89/<- %ebp 4/r32/esp
+  #
+  (ata-drive-select *(ebp+8) 0)
+  (ata-command *(ebp+8) 0xe7)  # flush cache
+  (while-ata-busy *(ebp+8))
+  (until-ata-ready-for-data *(ebp+8))
+$flush-ata-cache:end:
+  # . epilogue
+  89/<- %esp 5/r32/ebp
+  5d/pop-to-ebp
+  c3/return
+
 # }}}
 
 ## Controlling a PS/2 mouse