about summary refs log tree commit diff stats
path: root/ex3.hex
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-03-03 22:09:50 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-03-03 22:21:03 -0800
commit71e4f3812982dba2efb471283d310224e8db363e (patch)
treeea111a1acb8b8845dbda39c0e1b4bac1d198143b /ex3.hex
parentc6b928be29ac8cdb4e4d6e1eaa20420ff03e5a4c (diff)
downloadmu-71e4f3812982dba2efb471283d310224e8db363e.tar.gz
7842 - new directory organization
Baremetal is now the default build target and therefore has its sources
at the top-level. Baremetal programs build using the phase-2 Mu toolchain
that requires a Linux kernel. This phase-2 codebase which used to be at
the top-level is now under the linux/ directory. Finally, the phase-2 toolchain,
while self-hosting, has a way to bootstrap from a C implementation, which
is now stored in linux/bootstrap. The bootstrap C implementation uses some
literate programming tools that are now in linux/bootstrap/tools.

So the whole thing has gotten inverted. Each directory should build one
artifact and include the main sources (along with standard library). Tools
used for building it are relegated to sub-directories, even though those
tools are often useful in their own right, and have had lots of interesting
programs written using them.

A couple of things have gotten dropped in this process:
  - I had old ways to run on just a Linux kernel, or with a Soso kernel.
    No more.
  - I had some old tooling for running a single test at the cursor. I haven't
    used that lately. Maybe I'll bring it back one day.

The reorg isn't done yet. Still to do:
  - redo documentation everywhere. All the README files, all other markdown,
    particularly vocabulary.md.
  - clean up how-to-run comments at the start of programs everywhere
  - rethink what to do with the html/ directory. Do we even want to keep
    supporting it?

In spite of these shortcomings, all the scripts at the top-level, linux/
and linux/bootstrap are working. The names of the scripts also feel reasonable.
This is a good milestone to take stock at.
Diffstat (limited to 'ex3.hex')
-rw-r--r--ex3.hex58
1 files changed, 58 insertions, 0 deletions
diff --git a/ex3.hex b/ex3.hex
new file mode 100644
index 00000000..d3639948
--- /dev/null
+++ b/ex3.hex
@@ -0,0 +1,58 @@
+# Draw pixels in response to keyboard events, starting from the top-left
+# and in raster order.
+#
+# To run, first prepare a realistically sized disk image:
+#   dd if=/dev/zero of=disk.img count=20160  # 512-byte sectors, so 10MB
+# Load the program on the disk image:
+#   cat baremetal/boot.hex baremetal/ex3.hex  |./bootstrap run apps/hex  > a.bin
+#   dd if=a.bin of=disk.img conv=notrunc
+# To run:
+#   qemu-system-i386 disk.img
+# Or:
+#   bochs -f baremetal/boot.bochsrc  # boot.bochsrc loads disk.img
+
+# main:  (address 0x9000)
+
+# eax <- LFB
+8b  # copy *rm32 to r32
+  05  # 00/mod/indirect 000/r32/eax 101/rm32/use-disp32
+  28 81 00 00 # disp32 [label]
+
+# var read index/ecx: byte = 0
+31 c9  # ecx <- xor ecx;  11/direct 001/r32/ecx 001/rm32/ecx
+
+# $loop:
+  # CL = *read index
+  8a  # copy m8 at r32 to r8
+    0d  # 00/mod/indirect 001/r8/cl 101/rm32/use-disp32
+    cc 7d 00 00  # disp32 [label]
+  # CL = *(keyboard buffer + ecx)
+  8a  # copy m8 at r32 to r8
+    89  # 10/mod/*+disp32 001/r8/cl 001/rm32/ecx
+    d0 7d 00 00  # disp32 [label]
+  # if (CL == 0) loop (spin loop)
+  80
+    f9  # 11/mod/direct 111/subop/compare 001/rm8/CL
+    00  # imm8
+  74 ef  # loop -17 [label]
+# offset 0x19:
+  # otherwise increment read index
+  fe  # increment byte
+    05  # 00/mod/indirect 000/subop/increment 101/rm32/use-disp32
+    cc 7d 00 00  # disp32 [label]
+  # clear top nibble of index (keyboard buffer is circular)
+  80  # and byte
+    25  # 00/mod/indirect 100/subop/and 101/rm32/use-disp32
+    cc 7d 00 00  # disp32 [label]
+    0f  # imm8
+  # print a pixel in fluorescent green
+  c6  # copy imm8 to m8 at rm32
+    00  # 00/mod/indirect 000/subop 000/rm32/eax
+    31  # imm32
+  40  # increment eax
+  eb dc # loop -36 [label]
+
+# $break:
+e9 fb ff ff ff  # hang indefinitely
+
+# vim:ft=subx