diff options
author | Kartik Agaram <vc@akkartik.com> | 2020-01-01 16:35:02 -0800 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2020-01-01 16:35:02 -0800 |
commit | 7ca19e4e1d3acb2c770c180156b813fb536a673e (patch) | |
tree | 35ad8c7dfd1a09326b747363a4a5ec61fe4484ac | |
parent | dafef4e30fcfb53e6546ce0f53859bf9f1420dd2 (diff) | |
download | mu-7ca19e4e1d3acb2c770c180156b813fb536a673e.tar.gz |
5850 - driver script for translating Mu programs
-rw-r--r-- | mu-init-test.subx | 37 | ||||
-rw-r--r-- | mu-init.subx | 25 | ||||
-rwxr-xr-x | translate_mu | 7 |
3 files changed, 69 insertions, 0 deletions
diff --git a/mu-init-test.subx b/mu-init-test.subx new file mode 100644 index 00000000..6b08b113 --- /dev/null +++ b/mu-init-test.subx @@ -0,0 +1,37 @@ +# Just a test stub for mu-init.subx +# +# Try it out like this: +# $ ./ntranslate init.linux 0*.subx mu-init.subx mu-init-test.subx +# $ ./a.elf # should run all tests + +main: # args : (address array kernel-string) -> result/ebx : int + # . prologue + 55/push-ebp + 89/<- %ebp 4/r32/esp + # . save registers + 50/push-eax + 56/push-esi + # esi = args + 8b/-> *(ebp+8) 6/r32/esi + { + # if (argc <= 1) break + 81 7/subop/compare *esi 1/imm32 + 7e/jump-if-lesser-or-equal break/disp8 + # if (argv[1] != "test") break + (kernel-string-equal? *(esi+8) "test") # => eax + 3d/compare-eax-and 0/imm32 + 74/jump-if-equal break/disp8 + # + (run-tests) + # return *Num-test-failures + 8b/-> *Num-test-failures 3/r32/ebx + eb/jump $main:end/disp8 + } +$main:end: + # . restore registers + 5e/pop-to-esi + 58/pop-to-eax + # . epilogue + 89/<- %esp 5/r32/ebp + 5d/pop-to-ebp + c3/return diff --git a/mu-init.subx b/mu-init.subx new file mode 100644 index 00000000..0c5d0293 --- /dev/null +++ b/mu-init.subx @@ -0,0 +1,25 @@ +# Initialize the minimal runtime for Mu programs. +# +# See translate_mu for how this file is used. +# +# Mu programs start at a function called 'main' with this signature: +# fn main args: (address array kernel-string) -> exit_status/ebx : int +# If your program doesn't need commandline arguments you can drop it: +# fn main -> exit_status/ebx : int +# +# Notice that the output must be in ebx, so that the exit() syscall can pick +# it up. + +== code + +Entry: + # we don't use ebp in Entry; just initialize it + bd/copy-to-ebp 0/imm32 + # var args/eax : (address array kernel-string) + 89/<- %eax 4/r32/esp + # initialize the heap + (new-segment *Heap-size Heap) + # run Mu program + (main %eax) + # exit + (syscall_exit) diff --git a/translate_mu b/translate_mu new file mode 100755 index 00000000..d3029433 --- /dev/null +++ b/translate_mu @@ -0,0 +1,7 @@ +#!/bin/sh + +set -e + +cat $* |apps/mu > a.subx + +./ntranslate init.linux 0*.subx mu-init.subx a.subx |