about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-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