about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-03-15 21:46:53 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-03-15 21:46:53 -0700
commit7119d79b8a9a4023414f7664a011e40fafb44dfd (patch)
tree23bf14e1498c6c833f7e68b4272ffb01ec638bee
parentfd224d83f511c8cb0e8a70393d6f1c47dd88d1f1 (diff)
downloadmu-7119d79b8a9a4023414f7664a011e40fafb44dfd.tar.gz
snapshot: write to disk using BIOS
Requires the following commands:
  dd if=/dev/zero of=data.img count=20160
  ./translate life.mu
  qemu-system-i386 -hda disk.img -hdb data.img

Before running Qemu, data.img will contain all 0s.
After quitting Qemu, data.img will contain the first 512 bytes of disk.img.
-rw-r--r--boot.bochsrc1
-rw-r--r--boot.subx14
2 files changed, 15 insertions, 0 deletions
diff --git a/boot.bochsrc b/boot.bochsrc
index a1c8a4bc..360cbe40 100644
--- a/boot.bochsrc
+++ b/boot.bochsrc
@@ -10,6 +10,7 @@
 display_library: sdl2
 
 ata0-master: type=disk, path="disk.img", mode=flat, cylinders=20, heads=16, spt=63  # 10MB, 512 bytes per sector
+ata1-master: type=disk, path="data.img", mode=flat, cylinders=20, heads=16, spt=63  # 10MB, 512 bytes per sector
 boot: disk
 # PS/2 mouse requires black magic that I don't know how to explain.
 log: -
diff --git a/boot.subx b/boot.subx
index 412940d6..7f278c33 100644
--- a/boot.subx
+++ b/boot.subx
@@ -109,6 +109,20 @@
   bb/copy-to-bx 0/imm16
   8e/->seg 3/mod/direct 3/rm32/bx 0/r32/es
 
+  # write 1 sector of disk to disk 1
+  b4/copy-to-ah 3/imm8  # write sectors to disk
+  b2/copy-to-dl 0x81/imm8  # disk 1
+  b5/copy-to-ch 0/imm8  # cylinder 0
+  b6/copy-to-dh 0/imm8  # track 0
+  b1/copy-to-cl 1/imm8  # first sector, 1-based
+  b0/copy-to-al 1/imm8  # number of sectors to write
+  # address to read sectors from = es:bx = 0x7c00, contiguous with boot segment
+  bb/copy-to-bx 0/imm16
+  8e/->seg 3/mod/direct 3/rm32/bx 0/r32/es
+  bb/copy-to-bx 0x7c00/imm16
+  cd/syscall 0x13/imm8/bios-disk-services
+  0f 82/jump-if-carry disk_error/disp16
+
   # adjust video mode
   b4/copy-to-ah 0x4f/imm8  # VBE commands
   b0/copy-to-al 2/imm8  # set video mode