.githooks/
compiler/
kernel/
lib/
scripts/
seed/
sublime/
test/
boot/
bootstrap/
compiler/
cycles/
dispatch/
format/
host/
integration/
kernel/
loader/
manifests/
mmio/
native/
packages/
runtime/
scheduling/
shared/
slots/
smp/
std/
sync/
termination/
tests/
trap/
machine.ras
7.2 KiB
reservations.ras
2.6 KiB
vector.ras
4.6 KiB
verify/
Makefile
9.2 KiB
kernel.rad
776 B
runner.rad
11.6 KiB
vim/
.gitignore
333 B
.gitsigners
224 B
AGENTS.md
8.3 KiB
CONTRIBUTING
2.1 KiB
LICENSE
1.1 KiB
Makefile
2.5 KiB
README
3.4 KiB
STYLE
3.2 KiB
std.lib
2.1 KiB
std.lib.test
1.1 KiB
test/trap/reservations.ras
raw
| 1 | //! Reservation isolation at trap entry, frame resume, and user context switches. |
| 2 | // Machine completion device address. |
| 3 | .constant RESERVATION_TEST_FINISH_ADDRESS 0x10001000; |
| 4 | // Successful machine completion value. |
| 5 | .constant RESERVATION_TEST_FINISH_PASS 0x5555; |
| 6 | // Failed machine completion value. |
| 7 | .constant RESERVATION_TEST_FINISH_FAIL 0x13333; |
| 8 | // Previous machine privilege field in mstatus. |
| 9 | .constant RESERVATION_TEST_MPP_MACHINE 0x1800; |
| 10 | // Machine environment call exception code. |
| 11 | .constant RESERVATION_TEST_MACHINE_CALL 11; |
| 12 | // User environment call exception code. |
| 13 | .constant RESERVATION_TEST_USER_CALL 8; |
| 14 | |
| 15 | .text; |
| 16 | li %s0 0x80020000; |
| 17 | sd %sp 0(%s0); |
| 18 | li %t0 4096; |
| 19 | sub %t0 %sp %t0; |
| 20 | sd %t0 8(%s0); |
| 21 | sd %zero 16(%s0); |
| 22 | la %t0 @handler; |
| 23 | sd %t0 24(%s0); |
| 24 | mv %a0 %s0; |
| 25 | call @kernel::trap::install; |
| 26 | addi %s1 %s0 80; |
| 27 | |
| 28 | // Enter the vector with a live reservation and the machine trap CSR state. |
| 29 | la %t0 @resumed; |
| 30 | csrw mepc %t0; |
| 31 | li %t0 RESERVATION_TEST_MACHINE_CALL; |
| 32 | csrw mcause %t0; |
| 33 | li %t0 RESERVATION_TEST_MPP_MACHINE; |
| 34 | csrw mstatus %t0; |
| 35 | lr.d %t0 (%s1); |
| 36 | j @kernel::trap::vector; |
| 37 | @resumed |
| 38 | sc.d %t0 %zero (%s1); |
| 39 | beqz %t0 @fail; |
| 40 | ld %t0 0(%s1); |
| 41 | bnez %t0 @fail; |
| 42 | li %t0 2; |
| 43 | sd %t0 88(%s0); |
| 44 | la %t0 @first; |
| 45 | csrw mepc %t0; |
| 46 | csrw mstatus %zero; |
| 47 | mret; |
| 48 | |
| 49 | // The first user context retains its loaded value across a peer's execution. |
| 50 | @first |
| 51 | lr.d %a2 (%s1); |
| 52 | ecall; |
| 53 | @firstResume |
| 54 | sc.d %a3 %a2 (%s1); |
| 55 | beqz %a3 @fail; |
| 56 | ld %t0 0(%s1); |
| 57 | li %t1 1; |
| 58 | bne %t0 %t1 @fail; |
| 59 | ecall; |
| 60 | j @fail; |
| 61 | |
| 62 | // The peer changes shared memory and reserves the same location before exit. |
| 63 | @peer |
| 64 | li %t0 1; |
| 65 | sd %t0 0(%s1); |
| 66 | lr.d %t0 (%s1); |
| 67 | ecall; |
| 68 | j @fail; |
| 69 | |
| 70 | // Inject a live return reservation after trap entry has completed. |
| 71 | @handler |
| 72 | ld %t0 88(%s0); |
| 73 | beqz %t0 @entryCheck; |
| 74 | ld %t1 272(%a0); |
| 75 | li %t2 RESERVATION_TEST_USER_CALL; |
| 76 | bne %t1 %t2 @fail; |
| 77 | li %t1 2; |
| 78 | beq %t0 %t1 @switchPeer; |
| 79 | li %t1 3; |
| 80 | beq %t0 %t1 @switchFirst; |
| 81 | li %t1 4; |
| 82 | bne %t0 %t1 @fail; |
| 83 | j @success; |
| 84 | @entryCheck |
| 85 | sc.d %t0 %zero (%s1); |
| 86 | beqz %t0 @fail; |
| 87 | li %t0 1; |
| 88 | sd %t0 88(%s0); |
| 89 | lr.d %t0 (%s1); |
| 90 | ret; |
| 91 | @switchPeer |
| 92 | li %t0 3; |
| 93 | sd %t0 88(%s0); |
| 94 | la %t0 @peer; |
| 95 | sd %t0 256(%a0); |
| 96 | ret; |
| 97 | @switchFirst |
| 98 | li %t0 4; |
| 99 | sd %t0 88(%s0); |
| 100 | la %t0 @firstResume; |
| 101 | sd %t0 256(%a0); |
| 102 | lr.d %t0 (%s1); |
| 103 | ret; |
| 104 | @success |
| 105 | li %t0 RESERVATION_TEST_FINISH_ADDRESS; |
| 106 | li %t1 RESERVATION_TEST_FINISH_PASS; |
| 107 | sw %t1 0(%t0); |
| 108 | @fail |
| 109 | li %t0 RESERVATION_TEST_FINISH_ADDRESS; |
| 110 | li %t1 RESERVATION_TEST_FINISH_FAIL; |
| 111 | sw %t1 0(%t0); |
| 112 | ebreak; |