.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/vector.ras
raw
| 1 | //! Complete vector state across machine traps, nested timers and user switches. |
| 2 | // Machine completion device address and result values. |
| 3 | .constant VECTOR_TEST_FINISH 0x10001000; |
| 4 | .constant VECTOR_TEST_PASS 0x5555; |
| 5 | .constant VECTOR_TEST_FAIL 0x13333; |
| 6 | // Vector state enable bits in mstatus. |
| 7 | .constant VECTOR_TEST_VS 0x600; |
| 8 | // Bytes in the complete integer and vector trap frame. |
| 9 | .constant VECTOR_TEST_FRAME 1344; |
| 10 | // Hart zero timer compare register. |
| 11 | .constant VECTOR_TEST_COMPARE 0x02004000; |
| 12 | |
| 13 | .text; |
| 14 | li %s0 0x80020000; |
| 15 | sd %sp 0(%s0); |
| 16 | li %t0 16384; |
| 17 | sub %t0 %sp %t0; |
| 18 | sd %t0 8(%s0); |
| 19 | sd %zero 16(%s0); |
| 20 | la %t0 @handler; |
| 21 | sd %t0 24(%s0); |
| 22 | sd %zero 64(%s0); |
| 23 | mv %a0 %s0; |
| 24 | call @kernel::trap::install; |
| 25 | li %t0 VECTOR_TEST_VS; |
| 26 | csrs mstatus %t0; |
| 27 | call @pattern; |
| 28 | li %t0 0x80026000; |
| 29 | call @store; |
| 30 | call @configure; |
| 31 | ecall; |
| 32 | call @check; |
| 33 | // Enter a user context with the same known vector contents. |
| 34 | call @configure; |
| 35 | la %t0 @user; |
| 36 | csrw mepc %t0; |
| 37 | li %t0 VECTOR_TEST_VS; |
| 38 | csrw mstatus %t0; |
| 39 | li %sp 0x80023000; |
| 40 | mret; |
| 41 | @user |
| 42 | ecall; |
| 43 | call @check; |
| 44 | li %a7 1; |
| 45 | ecall; |
| 46 | j @fail; |
| 47 | @peer |
| 48 | call @clobber; |
| 49 | ecall; |
| 50 | j @fail; |
| 51 | |
| 52 | // Fill all vector lanes and registers with group-specific values. |
| 53 | @pattern |
| 54 | li %t0 64; |
| 55 | vsetvli %zero %t0 e32 m8 ta ma; |
| 56 | vid.v %v0; |
| 57 | vadd.vi %v8 %v0 1; |
| 58 | vadd.vi %v16 %v0 2; |
| 59 | vadd.vi %v24 %v0 3; |
| 60 | ret; |
| 61 | |
| 62 | // Store every vector register at t0 with vstart cleared. |
| 63 | @store |
| 64 | csrw vstart %zero; |
| 65 | vs8r.v %v0 (%t0); |
| 66 | addi %t0 %t0 256; |
| 67 | vs8r.v %v8 (%t0); |
| 68 | addi %t0 %t0 256; |
| 69 | vs8r.v %v16 (%t0); |
| 70 | addi %t0 %t0 256; |
| 71 | vs8r.v %v24 (%t0); |
| 72 | ret; |
| 73 | |
| 74 | // Configure a partial vector, a restart index and fixed-point state. |
| 75 | @configure |
| 76 | vsetivli %zero 3 e32 m2 ta ma; |
| 77 | li %t0 5; |
| 78 | csrw vcsr %t0; |
| 79 | li %t0 2; |
| 80 | csrw vstart %t0; |
| 81 | ret; |
| 82 | |
| 83 | // Check CSRs and every byte, including vector tails. |
| 84 | @check |
| 85 | csrr %t0 vstart; |
| 86 | li %t1 2; |
| 87 | bne %t0 %t1 @fail; |
| 88 | csrw vstart %zero; |
| 89 | csrr %t0 vl; |
| 90 | li %t1 3; |
| 91 | bne %t0 %t1 @fail; |
| 92 | csrr %t0 vtype; |
| 93 | li %t1 209; |
| 94 | bne %t0 %t1 @fail; |
| 95 | csrr %t0 vcsr; |
| 96 | li %t1 5; |
| 97 | bne %t0 %t1 @fail; |
| 98 | mv %t6 %ra; |
| 99 | li %t0 0x80027000; |
| 100 | call @store; |
| 101 | mv %ra %t6; |
| 102 | li %t0 0x80026000; |
| 103 | li %t1 0x80027000; |
| 104 | li %t2 128; |
| 105 | @compare |
| 106 | ld %t3 0(%t0); |
| 107 | ld %t4 0(%t1); |
| 108 | bne %t3 %t4 @fail; |
| 109 | addi %t0 %t0 8; |
| 110 | addi %t1 %t1 8; |
| 111 | addi %t2 %t2 -1; |
| 112 | bnez %t2 @compare; |
| 113 | ret; |
| 114 | |
| 115 | // Replace all live vector data and configuration. |
| 116 | @clobber |
| 117 | csrw vstart %zero; |
| 118 | li %t0 64; |
| 119 | vsetvli %zero %t0 e32 m8 ta ma; |
| 120 | vmv.v.i %v0 -1; |
| 121 | vmv.v.i %v8 -1; |
| 122 | vmv.v.i %v16 -1; |
| 123 | vmv.v.i %v24 -1; |
| 124 | csrw vcsr %zero; |
| 125 | ret; |
| 126 | |
| 127 | // A timer interrupts an outer handler while vector state is live. |
| 128 | @handler |
| 129 | ld %t0 272(%a0); |
| 130 | blt %t0 %zero @timer; |
| 131 | ld %t0 64(%s0); |
| 132 | beqz %t0 @machine; |
| 133 | li %t1 2; |
| 134 | beq %t0 %t1 @switchPeer; |
| 135 | li %t1 3; |
| 136 | beq %t0 %t1 @switchUser; |
| 137 | li %t0 VECTOR_TEST_FINISH; |
| 138 | li %t1 VECTOR_TEST_PASS; |
| 139 | sw %t1 0(%t0); |
| 140 | @machine |
| 141 | li %t0 1; |
| 142 | sd %t0 64(%s0); |
| 143 | addi %sp %sp -16; |
| 144 | sd %ra 0(%sp); |
| 145 | sd %a0 8(%sp); |
| 146 | call @pattern; |
| 147 | call @configure; |
| 148 | li %t0 VECTOR_TEST_COMPARE; |
| 149 | sd %zero 0(%t0); |
| 150 | li %t0 128; |
| 151 | csrw mie %t0; |
| 152 | csrsi mstatus 8; |
| 153 | @await |
| 154 | ld %t0 64(%s0); |
| 155 | li %t1 2; |
| 156 | bne %t0 %t1 @await; |
| 157 | csrci mstatus 8; |
| 158 | csrw mie %zero; |
| 159 | call @check; |
| 160 | call @clobber; |
| 161 | ld %ra 0(%sp); |
| 162 | ld %a0 8(%sp); |
| 163 | addi %sp %sp 16; |
| 164 | j @advance; |
| 165 | @timer |
| 166 | li %t0 VECTOR_TEST_COMPARE; |
| 167 | li %t1 -1; |
| 168 | sd %t1 0(%t0); |
| 169 | mv %t5 %ra; |
| 170 | call @clobber; |
| 171 | mv %ra %t5; |
| 172 | li %t0 2; |
| 173 | sd %t0 64(%s0); |
| 174 | ret; |
| 175 | @switchPeer |
| 176 | // Save the first context and initialize a separate zero vector context. |
| 177 | li %t0 0x80024000; |
| 178 | mv %t1 %a0; |
| 179 | li %t2 VECTOR_TEST_FRAME / 8; |
| 180 | @saveFrame |
| 181 | ld %t3 0(%t1); |
| 182 | sd %t3 0(%t0); |
| 183 | addi %t0 %t0 8; |
| 184 | addi %t1 %t1 8; |
| 185 | addi %t2 %t2 -1; |
| 186 | bnez %t2 @saveFrame; |
| 187 | addi %t0 %a0 288; |
| 188 | li %t1 132; |
| 189 | @clearVector |
| 190 | sd %zero 0(%t0); |
| 191 | addi %t0 %t0 8; |
| 192 | addi %t1 %t1 -1; |
| 193 | bnez %t1 @clearVector; |
| 194 | la %t0 @peer; |
| 195 | sd %t0 256(%a0); |
| 196 | li %t0 3; |
| 197 | sd %t0 64(%s0); |
| 198 | ret; |
| 199 | @switchUser |
| 200 | li %t0 0x80024000; |
| 201 | mv %t1 %a0; |
| 202 | li %t2 VECTOR_TEST_FRAME / 8; |
| 203 | @restoreFrame |
| 204 | ld %t3 0(%t0); |
| 205 | sd %t3 0(%t1); |
| 206 | addi %t0 %t0 8; |
| 207 | addi %t1 %t1 8; |
| 208 | addi %t2 %t2 -1; |
| 209 | bnez %t2 @restoreFrame; |
| 210 | li %t0 4; |
| 211 | sd %t0 64(%s0); |
| 212 | @advance |
| 213 | ld %t0 256(%a0); |
| 214 | addi %t0 %t0 4; |
| 215 | sd %t0 256(%a0); |
| 216 | ret; |
| 217 | @fail |
| 218 | li %t0 VECTOR_TEST_FINISH; |
| 219 | li %t1 VECTOR_TEST_FAIL; |
| 220 | sw %t1 0(%t0); |
| 221 | ebreak; |