commit - 14e785cef4f55c4cdaddd9bd6d98e4fa076d351f
commit + f0641b653b40f7b88979351e4bc56a32816ef84e
blob - dd689e20d4964ff3c5f13cea619551d57872c0e8
blob + c2068da3cd85736b579c59c2db99a0c031bf4e85
--- rvvm/rvhart.c
+++ rvvm/rvhart.c
uint64_t next_pc = h->pc + RV_STEP_SIZE;
switch (i.opcode) {
- // TODO: Implement execution logic.
+ case 0x13:
+ switch (i.funct3) {
+ case 0x0: // ADDI
+ h->rfile[i.rd] = h->rfile[i.rs1] + i.imm;
+ break;
+ case 0x4: // XORI
+ h->rfile[i.rd] = h-rfile[i.rs1] ^ i.imm;
+ break;
+ case 0x6: // ORI
+ h->rfile[i.rd] = h->rfile[i.rs1] | i.imm;
+ break;
+ case 0x7: // ANDI
+ h->rfile[i.rd] = h->rfile[i.rs1] & i.imm;
+ break;
+ default:
+ err(1, "rv_execute(): unknown funct3 %x for OP-IMM", i.funct3);
+ }
+ break;
+ case 0x33:
+ switch (i.funct3) {
+ case 0x0:
+ if (i.funct7 == 0x20)
+ h->rfile[i.rd] = h->rfile[i.rs1] - h->rfile[i.rs2];
+ else
+ h->rfile[i.rd] = h->rfile[i.rs1] + h->rfile[i.rs2];
+ break;
+ case 0x7:
+ h->rfile[i.rd] = h->rfile[i.rs1] & h->rfile[i.rs2];
+ break;
+ default:
+ err(1, "rv_execute(): unknown funct3 %x for OP", i.funct3);
+ }
+ break;
+ case 0x37: // LUI
+ h->rfile[i.rd] = i.imm;
+ break;
default:
err(1, "rv_execute(): unknown opcode %x", i.opcode);
}
word = (uint32_t)rv_ram_read(m, h->pc);
i = rv_decode(word);
- rv_execute(h, i);
+ rv_execute(h, m, i);
}
blob - 224142c566e514d83c4b78b582b8dd318f01ad59
blob + 26ebe47523c7b52e09d66de178471ee5652bbfbb
--- rvvm/rvram.c
+++ rvvm/rvram.c
#include <string.h>
#include "rvram.h"
+
+uint64_t
+rv_ram_read(struct rv_ram *m, uint64_t addr)
+{
+ uint64_t offset = addr - m->base_addr;
+ return (uint64_t)(*(uint32_t *)&m->data[offset]);
+}
blob - 9d787bc887285367dc41570fc57e4ba1825021aa
blob + a049c1b3924f3e2d4c44bb988b84751fce8789bb
--- rvvm/rvram.h
+++ rvvm/rvram.h
#include <stdint.h>
struct rv_ram {
- // ...
+ uint8_t *data;
+ uint64_t base_addr;
+ size_t size;
};
#endif