From bb84cb145bdcb8c5e18aacc4665c193534655a4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Kokosi=C5=84ski?= Date: Thu, 13 Jun 2024 19:46:13 +0200 Subject: [PATCH] wip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Filip KokosiƄski --- c-test-arith/Makefile | 1 + c-test-arith/main.c | 33 +++++++++++++++++++++++++++++++++ pdp1-gcc | 2 +- tests/test.exp | 15 ++++++++------- 4 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 c-test-arith/Makefile create mode 100644 c-test-arith/main.c diff --git a/c-test-arith/Makefile b/c-test-arith/Makefile new file mode 100644 index 0000000..49d1aab --- /dev/null +++ b/c-test-arith/Makefile @@ -0,0 +1 @@ +include ../common/common.mk diff --git a/c-test-arith/main.c b/c-test-arith/main.c new file mode 100644 index 0000000..e7bf177 --- /dev/null +++ b/c-test-arith/main.c @@ -0,0 +1,33 @@ +static void putc(int); + +int x; +int y; +int z; + +void _start(void) +{ + /* TODO: handle sp/fp init better -- separate crt0.S? */ + asm ("law 03000"); + asm ("dac 209"); + asm ("law 04000"); + asm ("dac 208"); + + x = 21; + y = 37; + + z = x << 3; + if (z == 168) + putc(027); + + z = y >> 3; + if (z == 4) + putc(027); + + asm ("hlt"); + __builtin_unreachable(); +} + +static void putc(int c) { + asm ("lio %0" : : "r"(c)); + asm ("tyo"); +} diff --git a/pdp1-gcc b/pdp1-gcc index 0be8d83..7c13560 160000 --- a/pdp1-gcc +++ b/pdp1-gcc @@ -1 +1 @@ -Subproject commit 0be8d834a47ef2b399cdb453a68e6134b4fa2637 +Subproject commit 7c13560b6e7af5c9afd65482440a5c14b89efbfe diff --git a/tests/test.exp b/tests/test.exp index 2eaddc4..f1fccf5 100644 --- a/tests/test.exp +++ b/tests/test.exp @@ -4,19 +4,19 @@ proc run_test { demo_name expected_output } { spawn "pdp1" send "attach ptr $demo_name/main.rim\n" expect { - "PTR: creating new file" { fail "Didn't find the RIM tape file\n" } - "sim>" { pass "Successfully loaded the RIM tape file\n" } - default { fail "Test failed unexpectedly\n" } + "PTR: creating new file" { fail "$demo_name: Didn't find the RIM tape file\n" } + "sim>" { pass "$demo_name: Successfully loaded the RIM tape file\n" } + default { fail "$demo_name: Test failed unexpectedly\n" } } send "boot ptr\n" expect { - "$expected_output" { pass "Encountered expected output\n" } - default { fail "Didn't encounter expected output\n" } + "$expected_output" { pass "$demo_name: Encountered expected output\n" } + default { fail "$demo_name: Didn't encounter expected output\n" } } expect { - -re "HALT instruction,.*" { pass "Program finished running normally\n" } - default { fail "Program halted unexpectedly\n" } + -re "HALT instruction,.*" { pass "$demo_name: Program finished running normally\n" } + default { fail "$demo_name: Program halted unexpectedly\n" } } send "quit\n" @@ -29,3 +29,4 @@ run_test "c-print-struct" "xyz" run_test "c-print-array" "xyzxyzxyzxyz" run_test "c-print-for-loop" "xxxxyxxx" run_test "c-test-comparison" "aceg" +run_test "c-test-arith" "xx"