diff --git a/tests/asm/include/common.S b/tests/asm/include/common.S index 25622de..3275877 100644 --- a/tests/asm/include/common.S +++ b/tests/asm/include/common.S @@ -5,6 +5,7 @@ #define NR_write 4 #define NR_rt_sigaction 174 #define NR_rt_sigreturn 173 +#define NR_access_hw_stacks 254 #define SCRATCH_REG0 %g23 #define SCRATCH_REG1 %g22 @@ -165,6 +166,38 @@ } .endm +#define READ_CHAIN_STACK 0 +#define READ_PROCEDURE_STACK 1 +#define WRITE_PROCEDURE_STACK 2 +#define GET_CHAIN_STACK_OFFSET 3 +#define GET_CHAIN_STACK_SIZE 4 +#define GET_PROCEDURE_STACK_SIZE 5 +#define READ_CHAIN_STACK_EX 6 +#define READ_PROCEDURE_STACK_EX 7 +#define WRITE_PROCEDURE_STACK_EX 8 +#define WRITE_CHAIN_STACK_EX 9 + + .macro sys_access_hw_stacks mode, frame_addr=0, buf_addr=0, buf_size=0, size_addr=0 + { + setwd wsz=8, nfx=1 + sdisp %ctpr1, 0x3 + } + { + addd,0 0, NR_access_hw_stacks, %r8 + addd,1 0, \mode, %r9 + } + { + nop 2 + addd,0 0, \frame_addr, %r10 + addd,1 0, \buf_addr, %r11 + } + { + addd,0 0, \buf_size, %r12 + addd,1 0, \size_addr, %r13 + call %ctpr1, wbs=4 + } + .endm + #define assert_(PRED, MSG) \ ibranch local(ok) ? PRED; \ write("assert at " __FILE__ ":" str(__LINE__) ":\n" \ @@ -225,8 +258,11 @@ set_exit_code 1; \ local(ok): -#define assert_ne_i32(LEFT, RIGHT, MSG) assert_ne(cmpesb, LEFT, RIGHT, MSG) -#define assert_ne_i64(LEFT, RIGHT, MSG) assert_ne(cmpedb, LEFT, RIGHT, MSG) +#define assert_ne_i32(LEFT, RIGHT) assert_ne(cmpesb, LEFT, RIGHT, "") +#define assert_ne_i64(LEFT, RIGHT) assert_ne(cmpedb, LEFT, RIGHT, "") + +#define assert_ne_i32m(LEFT, RIGHT, MSG) assert_ne(cmpesb, LEFT, RIGHT, MSG) +#define assert_ne_i64m(LEFT, RIGHT, MSG) assert_ne(cmpedb, LEFT, RIGHT, MSG) #define test_helper(OP, CMP, S1, S2, EXPECTED) \ { \ diff --git a/tests/asm/meson.build b/tests/asm/meson.build index fef21d4..d48d10a 100644 --- a/tests/asm/meson.build +++ b/tests/asm/meson.build @@ -164,6 +164,14 @@ asm_tests = { 'dam-1': {}, 'dam-2': {}, }, + 'syscall': { + 'get-ps-size-1': {}, + 'get-pcs-size-1': {}, + 'get-pcs-offset-1': {}, + 'read-ps-ex-1': {}, + 'read-ps-ex-unaligned-1': { 'should_fail': true }, + 'write-ps-ex-1': {}, + }, } foreach suite, tests : asm_tests diff --git a/tests/asm/syscall/get-pcs-offset-1.S b/tests/asm/syscall/get-pcs-offset-1.S new file mode 100644 index 0000000..eb96a36 --- /dev/null +++ b/tests/asm/syscall/get-pcs-offset-1.S @@ -0,0 +1,22 @@ +#include "test_start.S" + + setwd wsz=8, nfx=1 + rrd,0 %pcsp.lo, %g16 + rrd,0 %pcsp.hi, %g17 + { + andd,0 %g16, (1ULL << 48) - 1, %g16 + andd,1 %g17, (1ULL << 32) - 1, %g17 + } + addd,0 %g16, %g17, %g16 + std,2 %g16, [ frame ] + sys_access_hw_stacks GET_CHAIN_STACK_OFFSET, frame, 0, 0, offset + assert_eq_i64(%r8, 0) + +#include "test_end.S" + + .data + .balign 8 +frame: + .quad 0 +offset: + .quad 0 diff --git a/tests/asm/syscall/get-pcs-size-1.S b/tests/asm/syscall/get-pcs-size-1.S new file mode 100644 index 0000000..5cdf431 --- /dev/null +++ b/tests/asm/syscall/get-pcs-size-1.S @@ -0,0 +1,15 @@ +#include "test_start.S" + + setwd wsz=8, nfx=1 + sys_access_hw_stacks GET_CHAIN_STACK_SIZE, 0, 0, 0, size + assert_eq_i64(%r8, 0) + ldd,0 [ size ], %g16 + assert_ne_i64(%g16, 0) + +#include "test_end.S" + + .data + .balign 8 + .byte 0 +size: + .quad 0 diff --git a/tests/asm/syscall/get-ps-size-1.S b/tests/asm/syscall/get-ps-size-1.S new file mode 100644 index 0000000..61b0192 --- /dev/null +++ b/tests/asm/syscall/get-ps-size-1.S @@ -0,0 +1,15 @@ +#include "test_start.S" + + setwd wsz=8, nfx=1 + sys_access_hw_stacks GET_PROCEDURE_STACK_SIZE, 0, 0, 0, size + assert_eq_i64(%r8, 0) + ldd,0 [ size ], %g16 + assert_ne_i64(%g16, 0) + +#include "test_end.S" + + .data + .balign 8 + .byte 0 +size: + .quad 0 diff --git a/tests/asm/syscall/read-ps-ex-1.S b/tests/asm/syscall/read-ps-ex-1.S new file mode 100644 index 0000000..330fdf4 --- /dev/null +++ b/tests/asm/syscall/read-ps-ex-1.S @@ -0,0 +1,46 @@ +#include "test_start.S" + + { + setwd wsz=8, nfx=1 + disp %ctpr1, 0f + } + { + addd,0 0, 0xdeadbeef, %r8 + addd,1 0, 8, %r9 + call %ctpr1, wbs=4 + } + +#include "test_end.S" + +0: + { + setwd wsz=8, nfx=1 + disp %ctpr1, 0b + } + { + cmpedb,0 %r1, 0, %pred0 + addd,1 0, 0xdeadbeef, %r8 + subd,2 %r1, 1, %r9 + } + call %ctpr1, wbs=4 ? ~%pred0 + ibranch 0f ? ~%pred0 + + sys_access_hw_stacks GET_PROCEDURE_STACK_SIZE, 0, 0, 0, size + ldd,0 [ size ], %g16 + subd,0 %g16, 128, %g16 + std,2 %g16, [ frame ] + sys_access_hw_stacks READ_PROCEDURE_STACK_EX, frame, buf, 128 + ldd,0 0, buf, %g16 + assert_eq_i64(%g16, 0xdeadbeef) +0: + return %ctpr3 + ct %ctpr3 + + .data + .balign 8 +buf: + .fill 64, 1, 0 +size: + .quad 0 +frame: + .quad 0 diff --git a/tests/asm/syscall/read-ps-ex-unaligned-1.S b/tests/asm/syscall/read-ps-ex-unaligned-1.S new file mode 100644 index 0000000..c16303a --- /dev/null +++ b/tests/asm/syscall/read-ps-ex-unaligned-1.S @@ -0,0 +1,47 @@ +#include "test_start.S" + + { + setwd wsz=8, nfx=1 + disp %ctpr1, 0f + } + { + addd,0 0, 0xdeadbeef, %r8 + addd,1 0, 8, %r9 + call %ctpr1, wbs=4 + } + +#include "test_end.S" + +0: + { + setwd wsz=8, nfx=1 + disp %ctpr1, 0b + } + { + cmpedb,0 %r1, 0, %pred0 + addd,1 0, 0xdeadbeef, %r8 + subd,2 %r1, 1, %r9 + } + call %ctpr1, wbs=4 ? ~%pred0 + ibranch 0f ? ~%pred0 + + sys_access_hw_stacks GET_PROCEDURE_STACK_SIZE, 0, 0, 0, size + ldd,0 [ size ], %g16 + subd,0 %g16, 128, %g16 + std,2 %g16, [ frame ] + sys_access_hw_stacks READ_PROCEDURE_STACK_EX, frame, buf, 128 + ldd,0 0, buf, %g16 + assert_eq_i64(%g16, 0xdeadbeef) +0: + return %ctpr3 + ct %ctpr3 + + .data + .balign 8 + .byte 0 +buf: + .fill 64, 1, 0 +size: + .quad 0 +frame: + .quad 0 diff --git a/tests/asm/syscall/write-ps-ex-1.S b/tests/asm/syscall/write-ps-ex-1.S new file mode 100644 index 0000000..d168935 --- /dev/null +++ b/tests/asm/syscall/write-ps-ex-1.S @@ -0,0 +1,33 @@ +#include "test_start.S" + + { + setwd wsz=8, nfx=1 + disp %ctpr1, 0f + } + { + addd,0 0, 0, %r0 + call %ctpr1, wbs=4 + } + assert_eq_i64(%r0, 0xdeadbeef) + +#include "test_end.S" + +0: + setwd wsz=8, nfx=1 + sys_access_hw_stacks GET_PROCEDURE_STACK_SIZE, 0, 0, 0, size + ldd,0 [ size ], %g16 + subd,0 %g16, 256, %g16 + std,2 %g16, [ frame ] + sys_access_hw_stacks WRITE_PROCEDURE_STACK_EX, frame, buf, 8 + assert_eq_i64(%r8, 0) + return %ctpr3 + ct %ctpr3 + + .data + .balign 8 +buf: + .quad 0xdeadbeef +size: + .quad 0 +frame: + .quad 0