mu/mu-init-test.subx
Kartik Agaram c48ce3c8bf 6153 - switch 'main' to use Mu strings
At the SubX level we have to put up with null-terminated kernel strings
for commandline args. But so far we haven't done much with them. Rather
than try to support them we'll just convert them transparently to standard
length-prefixed strings.

In the process I realized that it's not quite right to treat the combination
of argc and argv as an array of kernel strings. Argc counts the number
of elements, whereas the length of an array is usually denominated in bytes.
2020-03-15 21:03:12 -07:00

38 lines
940 B
Plaintext

# Just a test stub for mu-init.subx
#
# Try it out like this:
# $ ./translate_subx init.linux [0-9]*.subx mu-init.subx mu-init-test.subx
# $ ./a.elf # should run all tests
main: # args: (addr array (addr array byte)) -> 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 4/imm32
7e/jump-if-<= break/disp8
# if (argv[1] != "test") break
(string-equal? *(esi+8) "test") # => eax
3d/compare-eax-and 0/imm32
74/jump-if-= 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