diff --git a/Tests/isa/CPrograms/main.c b/Tests/isa/CPrograms/main.c new file mode 100644 index 0000000..57bbe57 --- /dev/null +++ b/Tests/isa/CPrograms/main.c @@ -0,0 +1,18 @@ +#include +#include + +int main(void) { + void *__capability csp; + + // Set address + csp = (void *__capability)0x80001000; + + // Set bounds + csp = cheri_bounds_set(csp, 8); + // Increment offset + // csp = cheri_offset_increment(csp, 10); + + uint64_t val = *(uint64_t *__capability)csp; + + return 0; +} \ No newline at end of file diff --git a/Tests/isa/CPrograms/start.S b/Tests/isa/CPrograms/start.S new file mode 100644 index 0000000..4fd3e87 --- /dev/null +++ b/Tests/isa/CPrograms/start.S @@ -0,0 +1,40 @@ + .section .text + .globl _start + .align 4 +_start: + # cspecialr c1, pcc + + # Use csetaddr to build a stack capability + # li t0, 0x80001000 # fixed top-of-stack address + # csetaddr csp, ct0, t0 + + # bound it to 8 bytes (size of dword) + # li t2, 8 + # csetbounds csp, csp, t2 + # li t5, 4 + # cincoffsetimm csp, csp, 10 + + # Read bounds + # cgetbase t3, csp + # ld t0, 0(csp) + # derive capability from PCC + # csetaddr c1, ct0, t0 + + cspecialr ca0, pcc # Get the root data capability + li t0, 0x80002000 # Set top of stack address + csetaddr csp, ca0, t0 # Set address + li t1, -2048 # 2KB size + csetbounds csp, csp, t1 # Restrict bounds so main can't wander + + # Call main + # sw ra, 12(sp) + call main + + # a0 contains return value + mv t1, a0 + + # la t0, tohost + # Signal success + la t0, 0 + li t1, 1 + sd t1, 0(t0) \ No newline at end of file diff --git a/Tests/isa/build-assembler.sh b/Tests/isa/build-assembler.sh index b7870b2..e671298 100644 --- a/Tests/isa/build-assembler.sh +++ b/Tests/isa/build-assembler.sh @@ -1,8 +1,14 @@ # Send assembler file to remote machine to run -scp cheri.S home:/home/akilan/cheri/output/sdk/bin/ +scp Cprograms/start.S home:/home/akilan/cheri/output/sdk/bin/ +scp Cprograms/main.c home:/home/akilan/cheri/output/sdk/bin/ # Run compiled instruction remotely -ssh home 'cd /home/akilan/cheri/output/sdk/bin/ && ./clang --target=riscv64-unknown-elf -march=rv64gcxcheri -mabi=l64pc128 -nostdlib -nostartfiles -Wl,-Ttext=0x80000000 -o testC cheri.S' +# ssh home 'cd /home/akilan/cheri/output/sdk/bin/ && ./clang --target=riscv64-unknown-elf -march=rv64gcxcheri -mabi=l64pc128 -nostdlib -nostartfiles -Wl,-Ttext=0x80000000 -o testC start.S main.c' + +ssh home 'cd /home/akilan/cheri/output/sdk/bin/ && ./clang --target=riscv64-unknown-elf -march=rv64gcxcheri -mabi=lp64d -nostdlib -nostartfiles -Wl,-Ttext=0x80000000 -o testC start.S main.c' + +# Disassembly ouput +ssh home 'cd /home/akilan/cheri/output/sdk/bin/ && ./llvm-objdump -d testC' # Copy file back for testing scp home:/home/akilan/cheri/output/sdk/bin/testC . diff --git a/Tests/isa/cheri.S b/Tests/isa/cheri.S index 8db85d9..de84290 100644 --- a/Tests/isa/cheri.S +++ b/Tests/isa/cheri.S @@ -14,12 +14,6 @@ _start: # li t5, 4 cincoffsetimm csp, csp, 10 - # seal the bounded capability - # cspecialr ct1, 4 - # li t2, 12 - # csetaddr ct1, ct1, t2 - # ccseal c2, csp, t2 - # Read bounds cgetbase t3, csp ld t0, 0(csp) @@ -30,30 +24,3 @@ _start: li t1, 1 csd t1, 0(c1) -halt: - wfi - j halt - -.globl exit -exit: - j exit - - .section .bss - .align 16 -stack_bottom: - .space 2048 -stack_top: # address = 0x80001000 (for csetaddr) - -# -------------------------------------------------- -# Data section (NO .bss) -# -------------------------------------------------- - -# .section .data -# .align 3 - -# .globl tohost -# .globl fromhost -# tohost: -# .dword 0 -#fromhost: -# .dword 0 \ No newline at end of file diff --git a/Tests/isa/cheri.c b/Tests/isa/cheri.c new file mode 100644 index 0000000..fda1db2 --- /dev/null +++ b/Tests/isa/cheri.c @@ -0,0 +1,20 @@ +#include +#include + +int main() { + void *__capability csp; + + // Set address + csp = (void *__capability)0x80001000; + + // Set bounds + csp = cheri_bounds_set(csp, 8); + + // Increment offset + csp = cheri_offset_increment(csp, 10); + + uint64_t val = *(uint64_t *__capability)csp; + + while (1) {} + return 0; +} \ No newline at end of file diff --git a/Tests/isa/testC b/Tests/isa/testC index 95d69ae..2a216ab 100755 Binary files a/Tests/isa/testC and b/Tests/isa/testC differ