This commit is contained in:
Kartik Agaram 2020-03-06 18:07:39 -08:00
parent 5c26afb1de
commit 4c19dd3968
28 changed files with 70 additions and 70 deletions

View File

@ -7,13 +7,13 @@
# because we don't know if they refer to the line above or the line below.
#
# To run:
# $ ./subx translate init.linux 0*.subx apps/subx-params.subx apps/assort.subx -o apps/assort
# $ ./bootstrap translate init.linux 0*.subx apps/subx-params.subx apps/assort.subx -o apps/assort
# $ cat x
# == code
# abc
# == code
# def
# $ cat x |./subx run apps/assort
# $ cat x |./bootstrap run apps/assort
# == code
# abc
# def

View File

@ -3,8 +3,8 @@
# except that we support hex digits.
#
# To run:
# $ ./subx translate init.linux 0*.subx apps/crenshaw2-1.subx -o apps/crenshaw2-1
# $ echo '3' |./subx run apps/crenshaw2-1
# $ ./bootstrap translate init.linux 0*.subx apps/crenshaw2-1.subx -o apps/crenshaw2-1
# $ echo '3' |./bootstrap run apps/crenshaw2-1
# Expected output:
# # syscall(exit, 3)
# bb/copy-to-ebx 3/imm32
@ -12,14 +12,14 @@
# cd/syscall 0x80/imm8
#
# To run the generated output:
# $ echo '3' |./subx run apps/crenshaw2-1 > z1.subx
# $ ./subx translate init.linux z1.subx -o z1
# $ ./subx run z1
# $ echo '3' |./bootstrap run apps/crenshaw2-1 > z1.subx
# $ ./bootstrap translate init.linux z1.subx -o z1
# $ ./bootstrap run z1
# $ echo $?
# 3
#
# Stdin must contain just a single hex digit. Other input will print an error:
# $ echo 'xyz' |./subx run apps/crenshaw2-1
# $ echo 'xyz' |./bootstrap run apps/crenshaw2-1
# Error: integer expected
#
# Names in this file sometimes follow Crenshaw's original rather than my usual

View File

@ -3,8 +3,8 @@
# except that we support hex numbers of multiple digits.
#
# To run:
# $ ./subx translate init.linux 0*.subx apps/crenshaw2-1b.subx -o apps/crenshaw2-1b
# $ echo '1a' |./subx run apps/crenshaw2-1b
# $ ./bootstrap translate init.linux 0*.subx apps/crenshaw2-1b.subx -o apps/crenshaw2-1b
# $ echo '1a' |./bootstrap run apps/crenshaw2-1b
# Expected output:
# # syscall(exit, 1a)
# bb/copy-to-ebx 3/imm32
@ -12,14 +12,14 @@
# cd/syscall 0x80/imm8
#
# To run the generated output:
# $ echo '1a' |./subx run apps/crenshaw2-1b > z1.subx
# $ ./subx translate init.linux z1.subx -o z1
# $ ./subx run z1
# $ echo '1a' |./bootstrap run apps/crenshaw2-1b > z1.subx
# $ ./bootstrap translate init.linux z1.subx -o z1
# $ ./bootstrap run z1
# $ echo $?
# 26 # 0x1a in decimal
#
# Stdin must contain just a single hex digit. Other input will print an error:
# $ echo 'xyz' |./subx run apps/crenshaw2-1b
# $ echo 'xyz' |./bootstrap run apps/crenshaw2-1b
# Error: integer expected
#
# Names in this file sometimes follow Crenshaw's original rather than my usual

View File

@ -2,11 +2,11 @@
# Replace them with references to new variables in the data segment.
#
# To run:
# $ ./subx translate init.linux 0*.subx apps/subx-params.subx apps/dquotes.subx -o apps/dquotes
# $ ./bootstrap translate init.linux 0*.subx apps/subx-params.subx apps/dquotes.subx -o apps/dquotes
# $ cat x
# == code
# ab "cd ef"/imm32
# $ cat x |./subx run apps/dquotes
# $ cat x |./bootstrap run apps/dquotes
# == code
# ab __string1/imm32
# == data

View File

@ -2,8 +2,8 @@
# Just return 42.
#
# To run:
# $ ./subx translate init.linux examples/ex1.2.subx -o examples/ex1
# $ ./subx run examples/ex1
# $ ./bootstrap translate init.linux apps/ex1.2.subx -o apps/ex1
# $ ./bootstrap run apps/ex1
# Expected result:
# $ echo $?
# 42

View File

@ -1,8 +1,8 @@
# String comparison: return 1 iff the two args passed in at the commandline are equal.
#
# To run:
# $ ./subx translate init.linux examples/ex10.subx -o examples/ex10
# $ ./subx run examples/ex10 abc abd
# $ ./bootstrap translate init.linux apps/ex10.subx -o apps/ex10
# $ ./bootstrap run apps/ex10 abc abd
# Expected result:
# $ echo $?
# 0 # false

View File

@ -6,8 +6,8 @@
# a null-terminated 'kernel string' with a length-prefixed 'SubX string'.
#
# To run:
# $ ./subx translate init.linux examples/ex11.subx -o examples/ex11
# $ ./subx run examples/ex11 # runs a series of tests
# $ ./bootstrap translate init.linux apps/ex11.subx -o apps/ex11
# $ ./bootstrap run apps/ex11 # runs a series of tests
# ...... # all tests pass
#
# (We can't yet run the tests when given a "test" commandline argument,

View File

@ -2,8 +2,8 @@
# Create a new segment using mmap, save the address, write to it.
#
# To run:
# $ ./subx translate init.linux examples/ex12.subx -o examples/ex12
# $ ./subx run examples/ex12
# $ ./bootstrap translate init.linux apps/ex12.subx -o apps/ex12
# $ ./bootstrap run apps/ex12
# You shouldn't get a segmentation fault.
== code

View File

@ -1,8 +1,8 @@
# Compare 3 and 3.
#
# To run:
# $ ./subx translate init.linux examples/ex13.subx -o examples/ex13
# $ ./subx run examples/ex13
# $ ./bootstrap translate init.linux apps/ex13.subx -o apps/ex13
# $ ./bootstrap run apps/ex13
# Expected result:
# $ echo $?
# 1

View File

@ -1,8 +1,8 @@
# Add 1 and 1, and return the result in the exit code.
#
# To run:
# $ ./subx translate init.linux examples/ex2.subx -o examples/ex2
# $ ./subx run examples/ex2
# $ ./bootstrap translate init.linux apps/ex2.subx -o apps/ex2
# $ ./bootstrap run apps/ex2
# Expected result:
# $ echo $?
# 2

View File

@ -1,8 +1,8 @@
# Add the first 10 numbers, and return the result in the exit code.
#
# To run:
# $ ./subx translate init.linux examples/ex3.subx -o examples/ex3
# $ ./subx run examples/ex3
# $ ./bootstrap translate init.linux apps/ex3.subx -o apps/ex3
# $ ./bootstrap run apps/ex3
# Expected result:
# $ echo $?
# 55

View File

@ -1,8 +1,8 @@
# Read a character from stdin, save it to a global, write it to stdout.
#
# To run:
# $ ./subx translate init.linux examples/ex4.subx -o examples/ex4
# $ ./subx run examples/ex4
# $ ./bootstrap translate init.linux apps/ex4.subx -o apps/ex4
# $ ./bootstrap run apps/ex4
== data

View File

@ -1,8 +1,8 @@
# Read a character from stdin, save it to a local on the stack, write it to stdout.
#
# To run:
# $ ./subx translate init.linux examples/ex5.subx -o examples/ex5
# $ ./subx run examples/ex5
# $ ./bootstrap translate init.linux apps/ex5.subx -o apps/ex5
# $ ./bootstrap run apps/ex5
== code
# instruction effective address register displacement immediate

View File

@ -1,8 +1,8 @@
# Print out a (global variable) string to stdout.
#
# To run:
# $ ./subx translate init.linux examples/ex6.subx -o examples/ex6
# $ ./subx run examples/ex6
# $ ./bootstrap translate init.linux apps/ex6.subx -o apps/ex6
# $ ./bootstrap run apps/ex6
# Hello, world!
== code

View File

@ -5,8 +5,8 @@
# the character read.
#
# To run:
# $ ./subx translate init.linux examples/ex7.subx -o examples/ex7
# $ ./subx run examples/ex7
# $ ./bootstrap translate init.linux apps/ex7.subx -o apps/ex7
# $ ./bootstrap run apps/ex7
# Expected result:
# $ echo $?
# 97

View File

@ -1,8 +1,8 @@
# Example reading commandline arguments: compute length of first arg.
#
# To run:
# $ ./subx translate init.linux examples/ex8.subx -o examples/ex8
# $ ./subx run examples/ex8 abc de fghi
# $ ./bootstrap translate init.linux apps/ex8.subx -o apps/ex8
# $ ./bootstrap run apps/ex8 abc de fghi
# Expected result:
# $ echo $?
# 3 # length of 'abc'

View File

@ -4,8 +4,8 @@
# letter of second arg.
#
# To run:
# $ ./subx translate init.linux examples/ex9.subx -o examples/ex9
# $ ./subx run examples/ex9 z x
# $ ./bootstrap translate init.linux apps/ex9.subx -o apps/ex9
# $ ./bootstrap run apps/ex9 z x
# Expected result:
# $ echo $?
# 2

View File

@ -1,14 +1,14 @@
## compute the factorial of 5, and return the result in the exit code
#
# To run:
# $ ./subx translate init.linux 0*.subx apps/factorial.subx -o apps/factorial
# $ ./subx run apps/factorial
# $ ./bootstrap translate init.linux 0*.subx apps/factorial.subx -o apps/factorial
# $ ./bootstrap run apps/factorial
# Expected result:
# $ echo $?
# 120
#
# You can also run the automated test suite:
# $ ./subx run apps/factorial test
# $ ./bootstrap run apps/factorial test
# Expected output:
# ........
# Every '.' indicates a passing test. Failing tests get a 'F'.

View File

@ -5,13 +5,13 @@
#
# To run:
# $ ./translate_subx init.linux 0*.subx apps/factorial.subx -o apps/factorial
# $ ./subx run apps/factorial
# $ ./bootstrap run apps/factorial
# Expected result:
# $ echo $?
# 120
#
# You can also run the automated test suite:
# $ ./subx run apps/factorial test
# $ ./bootstrap run apps/factorial test
# Expected output:
# ........
# Every '.' indicates a passing test. Failing tests get a 'F'.

View File

@ -6,13 +6,13 @@
#
# To run:
# $ ./translate_subx init.linux 0*.subx apps/factorial.subx -o apps/factorial
# $ ./subx run apps/factorial
# $ ./bootstrap run apps/factorial
# Expected result:
# $ echo $?
# 120
#
# You can also run the automated test suite:
# $ ./subx run apps/factorial test
# $ ./bootstrap run apps/factorial test
# Expected output:
# ........
# Every '.' indicates a passing test. Failing tests get a 'F'.

View File

@ -7,13 +7,13 @@
#
# To run:
# $ ./translate_subx init.linux 0*.subx apps/factorial.subx -o apps/factorial
# $ ./subx run apps/factorial
# $ ./bootstrap run apps/factorial
# Expected result:
# $ echo $?
# 120
#
# You can also run the automated test suite:
# $ ./subx run apps/factorial test
# $ ./bootstrap run apps/factorial test
# Expected output:
# ........
# Every '.' indicates a passing test. Failing tests get a 'F'.

View File

@ -13,8 +13,8 @@
# offset 4: address
#
# To run:
# $ ./subx translate init.linux 0*.subx apps/handle.subx -o apps/handle
# $ ./subx run apps/handle
# $ ./bootstrap translate init.linux 0*.subx apps/handle.subx -o apps/handle
# $ ./bootstrap run apps/handle
# Expected result is a successful lookup followed by a hard abort:
# lookup succeeded
# lookup failed

View File

@ -3,8 +3,8 @@
# comments between '#' and newline.
#
# To run:
# $ ./subx translate init.linux 0*.subx apps/subx-params.subx apps/hex.subx -o apps/hex
# $ echo '80 81 82 # comment' |./subx run apps/hex |xxd -
# $ ./bootstrap translate init.linux 0*.subx apps/subx-params.subx apps/hex.subx -o apps/hex
# $ echo '80 81 82 # comment' |./bootstrap run apps/hex |xxd -
# Expected output:
# 00000000: 8081 82
#

View File

@ -3,8 +3,8 @@
# uses are left untouched.
#
# To run:
# $ ./subx translate init.linux 0*.subx apps/subx-params.subx apps/pack.subx -o apps/pack
# $ echo '05/add-to-eax 0x20/imm32' |./subx run apps/pack
# $ ./bootstrap translate init.linux 0*.subx apps/subx-params.subx apps/pack.subx -o apps/pack
# $ echo '05/add-to-eax 0x20/imm32' |./bootstrap run apps/pack
# Expected output:
# 05 20 00 00 00 # 05/add-to-eax 0x20/imm32
# The original instruction gets included as a comment at the end of each

View File

@ -1,8 +1,8 @@
# Repeatedly read 32-bit numbers from /dev/random, print them to stdout.
#
# To run:
# $ ./subx translate init.linux 0*.subx apps/random.subx -o apps/random
# $ ./subx run apps/random
# $ ./bootstrap translate init.linux 0*.subx apps/random.subx -o apps/random
# $ ./bootstrap run apps/random
== code 0x09000000
# instruction effective address register displacement immediate

View File

@ -2,36 +2,36 @@
# other related arguments.
#
# To run:
# $ ./subx translate init.linux 0*.subx apps/subx-params.subx apps/sigils.subx -o apps/sigils
# $ ./bootstrap translate init.linux 0*.subx apps/subx-params.subx apps/sigils.subx -o apps/sigils
#
# We currently support the following notations:
#
# 1.
# $ echo '%eax' | ./subx run apps/sigils
# $ echo '%eax' | ./bootstrap run apps/sigils
# 3/mod 0/rm32
#
# 2.
# $ echo '*eax' | ./subx run apps/sigils
# $ echo '*eax' | ./bootstrap run apps/sigils
# 0/mod 0/rm32
#
# 3.
# $ echo '*(eax+4)' | ./subx run apps/sigils
# $ echo '*(eax+4)' | ./bootstrap run apps/sigils
# 2/mod 0/rm32 4/disp32
#
# 4.
# $ echo '*(eax+ecx)' | ./subx run apps/sigils
# $ echo '*(eax+ecx)' | ./bootstrap run apps/sigils
# 0/mod 4/rm32 0/base 1/index 0/scale
#
# 5.
# $ echo '*(eax+ecx+4)' | ./subx run apps/sigils
# $ echo '*(eax+ecx+4)' | ./bootstrap run apps/sigils
# 2/mod 4/rm32 0/base 1/index 0/scale 4/disp32
#
# 6.
# $ echo '*(eax+ecx<<2+4)' | ./subx run apps/sigils
# $ echo '*(eax+ecx<<2+4)' | ./bootstrap run apps/sigils
# 2/mod 4/rm32 0/base 1/index 2/scale 4/disp32
#
# 7.
# $ echo '*Foo' | ./subx run apps/sigils
# $ echo '*Foo' | ./bootstrap run apps/sigils
# 0/mod 5/rm32/.disp32 Foo/disp32
#
# Addition isn't commutative here. Template must always be (base+index<<scale+disp),

View File

@ -5,7 +5,7 @@
# b) add segment headers with addresses and offsets correctly filled in
#
# To build:
# $ ./subx translate init.linux 0*.subx apps/subx-params.subx apps/survey.subx -o apps/survey
# $ ./bootstrap translate init.linux 0*.subx apps/subx-params.subx apps/survey.subx -o apps/survey
#
# The expected input is a stream of bytes with segment headers, comments and
# some interspersed labels.
@ -23,7 +23,7 @@
# The output is the stream of bytes without segment headers or label definitions,
# and with label references replaced with numeric values/displacements.
#
# $ cat x |./subx run apps/survey
# $ cat x |./bootstrap run apps/survey
# ...ELF header bytes...
# # ELF header above will specify that code segment begins at this offset
# aa bb nn # some computed address

View File

@ -2,7 +2,7 @@
# all functions starting with 'test-'.
#
# To build:
# $ ./subx translate init.linux 0*.subx apps/subx-params.subx apps/tests.subx -o apps/tests
# $ ./bootstrap translate init.linux 0*.subx apps/subx-params.subx apps/tests.subx -o apps/tests
== code
# instruction effective address register displacement immediate