/* Integer vector execution through the machine instruction dispatcher. */ #include #include #include "machine_internal.h" /* Write one instruction to machine RAM. */ static void instruction(u8 *ram, u32 ins) { for (u32 i = 0; i < 4; i++) ram[i] = ins >> (8 * i); } int main(void) { u8 ram[4096] = { 0 }; struct machine_config config = { 0 }; config.ram = ram; config.memory_size = sizeof(ram); config.hart_count = 1; config.text.base = MACHINE_RAM_BASE; config.text.size = 64; struct machine machine = { 0 }; machine.config = &config; struct machine_hart *h = &machine.harts[0]; h->privilege = 3; h->pc = MACHINE_RAM_BASE; instruction(ram, 0xc1027557); /* vsetivli a0,4,e32,m1,tu,mu */ machine_step(&machine, h); assert(h->mcause == CAUSE_ILLEGAL && h->vector.vl == 0); h->mstatus = 1ULL << 9; h->pc = MACHINE_RAM_BASE; machine_step(&machine, h); assert(h->vector.vl == 4 && h->regs[10] == 4); assert(((h->mstatus >> 9) & 3) == 3); instruction(ram, 0x5e03b457); /* vmv.v.i v8,7 */ h->pc = MACHINE_RAM_BASE; machine_step(&machine, h); assert(h->vector.reg[8][0] == 7); instruction(ram, 0x42802557); /* vmv.x.s a0,v8 */ h->pc = MACHINE_RAM_BASE; machine_step(&machine, h); assert(h->regs[10] == 7); instruction(ram, 0x02056407); /* vle32.v v8,(a0) */ h->regs[10] = MACHINE_RAM_BASE + 4092; h->pc = MACHINE_RAM_BASE; machine_step(&machine, h); assert(h->mcause == CAUSE_LOAD_FAULT && h->vector.vstart == 1); assert(h->mtval == MACHINE_RAM_BASE + 4096); return 0; }