.githooks/
riscv/
test/
jit_calls.c
5.5 KiB
jit_vector.c
15.8 KiB
vector.c
10.7 KiB
vector_machine.c
1.8 KiB
.clang-format
570 B
.gitignore
5 B
.gitsigners
112 B
AGENTS.md
227 B
LICENSE
1.1 KiB
Makefile
3.5 KiB
README
12.5 KiB
STYLE
781 B
abi_host.c
12.2 KiB
abi_linux.c
3.7 KiB
bitmanip.h
5.8 KiB
color.h
567 B
debug_map.c
5.1 KiB
debug_map.h
1.3 KiB
emulator.c
87.3 KiB
host.h
5.5 KiB
host_posix.c
11.2 KiB
hosted.h
5.7 KiB
image_native.c
4.6 KiB
image_rad0.c
2.7 KiB
image_raw.c
2.6 KiB
io.c
1.1 KiB
io.h
444 B
jit.c
99.2 KiB
jit.h
7.8 KiB
machine.c
4.4 KiB
machine.h
2.1 KiB
machine_cpu.c
13.6 KiB
machine_csr.c
4.6 KiB
machine_devices.c
10.8 KiB
machine_fdt.c
8.7 KiB
machine_internal.h
7.4 KiB
muldiv.h
1.0 KiB
profile.c
17.5 KiB
profile.h
1.4 KiB
riscv.c
755 B
riscv.h
4.3 KiB
types.h
1019 B
vector.c
54.0 KiB
vector.h
1.3 KiB
test/vector_machine.c
raw
| 1 | /* Integer vector execution through the machine instruction dispatcher. */ |
| 2 | #include <assert.h> |
| 3 | #include <string.h> |
| 4 | |
| 5 | #include "machine_internal.h" |
| 6 | |
| 7 | /* Write one instruction to machine RAM. */ |
| 8 | static void instruction(u8 *ram, u32 ins) { |
| 9 | for (u32 i = 0; i < 4; i++) |
| 10 | ram[i] = ins >> (8 * i); |
| 11 | } |
| 12 | |
| 13 | int main(void) { |
| 14 | u8 ram[4096] = { 0 }; |
| 15 | struct machine_config config = { 0 }; |
| 16 | config.ram = ram; |
| 17 | config.memory_size = sizeof(ram); |
| 18 | config.hart_count = 1; |
| 19 | config.text.base = MACHINE_RAM_BASE; |
| 20 | config.text.size = 64; |
| 21 | struct machine machine = { 0 }; |
| 22 | machine.config = &config; |
| 23 | struct machine_hart *h = &machine.harts[0]; |
| 24 | h->privilege = 3; |
| 25 | h->pc = MACHINE_RAM_BASE; |
| 26 | instruction(ram, 0xc1027557); /* vsetivli a0,4,e32,m1,tu,mu */ |
| 27 | machine_step(&machine, h); |
| 28 | assert(h->mcause == CAUSE_ILLEGAL && h->vector.vl == 0); |
| 29 | h->mstatus = 1ULL << 9; |
| 30 | h->pc = MACHINE_RAM_BASE; |
| 31 | machine_step(&machine, h); |
| 32 | assert(h->vector.vl == 4 && h->regs[10] == 4); |
| 33 | assert(((h->mstatus >> 9) & 3) == 3); |
| 34 | instruction(ram, 0x5e03b457); /* vmv.v.i v8,7 */ |
| 35 | h->pc = MACHINE_RAM_BASE; |
| 36 | machine_step(&machine, h); |
| 37 | assert(h->vector.reg[8][0] == 7); |
| 38 | instruction(ram, 0x42802557); /* vmv.x.s a0,v8 */ |
| 39 | h->pc = MACHINE_RAM_BASE; |
| 40 | machine_step(&machine, h); |
| 41 | assert(h->regs[10] == 7); |
| 42 | instruction(ram, 0x02056407); /* vle32.v v8,(a0) */ |
| 43 | h->regs[10] = MACHINE_RAM_BASE + 4092; |
| 44 | h->pc = MACHINE_RAM_BASE; |
| 45 | machine_step(&machine, h); |
| 46 | assert(h->mcause == CAUSE_LOAD_FAULT && h->vector.vstart == 1); |
| 47 | assert(h->mtval == MACHINE_RAM_BASE + 4096); |
| 48 | return 0; |
| 49 | } |