Skip to content

Commit a2636d6

Browse files
committed
vm/c-debugger: Quash registers on syscall
This makes the debugger reset registers to bogus values on all syscalls. The last few tests that were not working under it are now fixed. The entire bootstrap process now preserves registers when making syscalls. This will make it possible to implement syscalls as ordinary functions in the Onramp OS. It also makes it possible to proxy syscalls by child processes in the libc.
1 parent bbfa378 commit a2636d6

File tree

11 files changed

+41
-35
lines changed

11 files changed

+41
-35
lines changed

core/libc/0-oo/src/stdio.oo

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,10 @@
370370
7E 00 &__fopen_not_append ; jz 0 &__fopen_not_append
371371

372372
; mode is append. seek to the end
373-
70 81 00 FF ; add r1 0 -1 ; mov r1 -1
374-
70 82 00 FF ; add r2 0 -1 ; mov r2 -1
373+
; TODO probably remove this, I don't think append is used in bootstrapping.
374+
70 81 00 02 ; add r1 0 2 ; mov r1 2
375+
70 82 00 00 ; add r2 0 0 ; mov r2 0
376+
70 83 00 00 ; add r3 0 0 ; mov r3 0
375377
7F 07 00 00 ; sys fseek 0 0
376378
;78 82 8D F4 ; ldw r2 rfp -12
377379
;79 80 82 04 ; stw 0 r2 4 ; position in file

platform/vm/c-debugger/src/vm.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,12 @@ static void vm_sys(vm_t* vm, uint8_t syscall_number, uint8_t arg1, uint8_t arg2)
923923
}
924924

925925
vm->registers[0] = ret;
926+
927+
// We quash all other caller-preserved registers to ensure that programs do
928+
// not depend on register preservation.
929+
for (size_t i = 1; i <= 0xB; ++i) {
930+
vm->registers[i] = 0xDEADDEAD;
931+
}
926932
}
927933

928934
#if 0

test/as/0-basic/tests/hello-world.oo

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,13 @@
33

44

55

6-
7-
8-
96
=main
10-
7C80<__process_info_table
11-
7C80>__process_info_table
12-
78808E80
13-
14-
15-
70898000
167

178

18-
708A8910
19-
78808A00
9+
7C89<__process_info_table
10+
7C89>__process_info_table
11+
78898E89
12+
78808910
2013

2114

2215
7C81<hello_world
@@ -26,8 +19,10 @@
2619
7F060000
2720

2821

29-
708A8908
30-
788A8A00
22+
7C89<__process_info_table
23+
7C89>__process_info_table
24+
78898E89
25+
788A8908
3126

3227

3328
70800000

test/as/0-basic/tests/hello-world.os

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,14 @@
22
; Copyright (c) 2023-2024 Fraser Heavy Software
33
; This test case is part of the Onramp compiler project.
44

5-
; TODO this was written before we were linking against libc, hack to workaround it
6-
;=_start
7-
; ; format indicator
8-
; "~Onr~amp~ "
5+
; TODO this was written before we were linking against libc. it makes direct syscalls.
96
=main
10-
ims r0 <__process_info_table
11-
ims r0 >__process_info_table
12-
ldw r0 rpp r0
13-
14-
; store process info table in r9
15-
add r9 r0 '00
167

178
; get the output file descriptor
18-
add ra r9 '10
19-
ldw r0 ra '00
9+
ims r9 <__process_info_table
10+
ims r9 >__process_info_table
11+
ldw r9 rpp r9
12+
ldw r0 r9 '10
2013

2114
; write(stdout, "Hello world!", 12)
2215
ims r1 <hello_world
@@ -26,8 +19,10 @@ ldw r0 rpp r0
2619
sys fwrite '00 '00
2720

2821
; get the exit address
29-
add ra r9 '08
30-
ldw ra ra '00
22+
ims r9 <__process_info_table
23+
ims r9 >__process_info_table
24+
ldw r9 rpp r9
25+
ldw ra r9 '08
3126

3227
; exit(0)
3328
add r0 '00 '00 ; set exit parameter to 0 (success)
4 Bytes
Binary file not shown.

test/ld/1-omc/programs/eight-queens.oo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
78 8D 00 8C ; ldw rfp 0 rsp ; pop rfp
5454
70 8C 8C 04 ; add rsp rsp 4 ; ^^^
5555
70 80 00 00 ; add r0 0 0 ; zero r0
56-
78 8F 89 08 ; ldw rip r9 8 ; ret
56+
78 8F 00 8C ; ldw rip 0 rsp ; ret
5757

5858

5959

test/vm/files/fseek.skip

Whitespace-only changes.

test/vm/files/ftell.skip

Whitespace-only changes.

test/vm/io/hello.oe.ohx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
7E 61 6D 70 ; jz 97 28781
99
7E 20 20 20 ; jz 32 8224
1010

11-
; store process info vector in r9
12-
70 89 80 00 ; add r9 r0 0
11+
; push process info vector
12+
71 8C 8C 04 ; sub rsp rsp 4
13+
79 80 8C 00 ; stw r0 rsp 0
1314

1415
; get the output file descriptor
15-
70 8A 89 10 ; add ra r9 16 (output stream handle)
16+
70 8A 80 10 ; add ra r0 16 (output stream handle)
1617
78 80 8A 00 ; ldw r0 ra 0
1718

1819
; output("Hello world!")
@@ -21,6 +22,7 @@
2122
7F 06 00 00 ; sys write 0 0
2223

2324
; get the exit address
25+
78 89 8C 00 ; ldw r9 rsp 0
2426
70 8A 89 08 ; add ra r9 8 (exit address)
2527
78 8A 8A 00 ; ldw ra ra 0
2628

@@ -29,7 +31,6 @@
2931
70 8F 8A 00 ; add rip ra 0 ; jump to exit address
3032

3133
; padding
32-
00 00 00 00 00 00 00 00
3334
00 00 00 00
3435

3536
@0x40 =hello_world

test/vm/run.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
# If a corresponding .env file exists, the contents are passed as environment
2525
# variables to the program. Otherwise, the program inherits the current
2626
# environment.
27+
#
28+
# If a corresponding .skip file exists, the test is skipped.
2729

2830
if [ "$1" == "" ]; then
2931
echo "Need command to test."
@@ -49,6 +51,12 @@ echo "Running vm tests on: $COMMAND"
4951
for HEXNAME in $(find $(dirname $0)/* -name '*.oe.ohx'); do
5052
THIS_ERROR=0
5153
BASENAME=$(echo $HEXNAME|sed 's/\.oe\.ohx$//')
54+
55+
if [ -e $BASENAME.skip ]; then
56+
echo "Skipping $BASENAME"
57+
continue
58+
fi
59+
5260
echo "Testing $BASENAME"
5361

5462
ARGS=

test/vm/testdata/hello.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)