summaryrefslogtreecommitdiff
path: root/src/asm.cpp
diff options
context:
space:
mode:
authorJacob McDonnell <jacob@jacobmcdonnell.com>2026-03-15 21:51:55 -0400
committerJacob McDonnell <jacob@jacobmcdonnell.com>2026-03-15 21:51:55 -0400
commit2999bd3b9466617938f2f7ceb689cfbe33b46cd9 (patch)
tree538c285c82ca0980a3192dbac08009da5128d742 /src/asm.cpp
parent7025f30be3b6cccf9f419daec9f0b7aeeaa2d6d3 (diff)
feat: Initial mapping of registers and instructions
Mapping of registers from register names to numbers. As well, the inital mapping of instructions to their opcodes has been added. There are bit fields for each type of instruction, and a tagged union of all the instruction types.
Diffstat (limited to 'src/asm.cpp')
-rw-r--r--src/asm.cpp143
1 files changed, 143 insertions, 0 deletions
diff --git a/src/asm.cpp b/src/asm.cpp
new file mode 100644
index 0000000..d79f086
--- /dev/null
+++ b/src/asm.cpp
@@ -0,0 +1,143 @@
+#include <cstdint>
+#include <map>
+#include <string>
+#include "asm.hpp"
+
+namespace {
+std::map<std::string, instruction_t> instructions = {
+ {"lb", {}},
+ {"lh", {}},
+ {"lw", {}},
+ {"ld", {}},
+ {"lbu", {}},
+ {"lhu", {}},
+ {"lwu", {}},
+ {"sb", {}},
+ {"sh", {}},
+ {"sw", {}},
+ {"sd", {}},
+ {"li", {}},
+ {"lui", {}},
+ {"auipc", {}},
+ {"mv", {}},
+ {"sext.b", {}},
+ {"sext.h", {}},
+ {"sext.w", {}},
+ {"zext.b", {}},
+ {"zext.h", {}},
+ {"zext.w", {}},
+ {"rev8", {}},
+ {"czero.eqz", {}},
+ {"czero.nez", {}},
+ {"addi", {}},
+ {"add", {}},
+ {"sh1add", {}},
+ {"sh2add", {}},
+ {"sh3add", {}},
+ {"add.wu", {}},
+ {"sh1add.wu", {}},
+ {"sh2add.wu", {}},
+ {"sh3add.wu", {}},
+ {"addiw", {}},
+ {"addw", {}},
+ {"sub", {}},
+ {"subw", {}},
+ {"neg", {}},
+ {"negw", {}},
+ {"mul", {}},
+ {"mulw", {}},
+ {"mulh", {}},
+ {"mulhu", {}},
+ {"mulhsu", {}},
+ {"div", {}},
+ {"divu", {}},
+ {"rem", {}},
+ {"remu", {}},
+ {"min", {}},
+ {"max", {}},
+ {"minu", {}},
+ {"maxu", {}},
+ {"seqz", {}},
+ {"snez", {}},
+ {"slti", {}},
+ {"slt", {}},
+ {"sltiu", {}},
+ {"sltu", {}},
+ {"bexti", {}},
+ {"bext", {}},
+ {"andi", {}},
+ {"and", {}},
+ {"andn", {}},
+ {"bclri", {}},
+ {"bclr", {}},
+ {"ori", {}},
+ {"or", {}},
+ {"orn", {}},
+ {"bseti", {}},
+ {"bset", {}},
+ {"xori", {}},
+ {"xor", {}},
+ {"xnor", {}},
+ {"binvi", {}},
+ {"binv", {}},
+ {"not", {}},
+ {"orc.b", {}},
+ {"slli", {}},
+ {"sll", {}},
+ {"slliw", {}},
+ {"sllw", {}},
+ {"slli.wu", {}},
+ {"srli", {}},
+ {"srl", {}},
+ {"srliw", {}},
+ {"srlw", {}},
+ {"srai", {}},
+ {"sra", {}},
+ {"sraiw", {}},
+ {"sraw", {}},
+ {"rori", {}},
+ {"ror", {}},
+ {"rol", {}},
+ {"roriw", {}},
+ {"rorw", {}},
+ {"rolw", {}},
+ {"clz", {}},
+ {"clzw", {}},
+ {"ctz", {}},
+ {"ctzw", {}},
+ {"cpop", {}},
+ {"cpopw", {}},
+ {"j", {}},
+ {"jal", {}},
+ {"jr", {}},
+ {"jalr", {}},
+ {"call", {}},
+ {"tail", {}},
+ {"ret", {}},
+ {"beq", {}},
+ {"bne", {}},
+ {"blt", {}},
+ {"bgt", {}},
+ {"bge", {}},
+ {"ble", {}},
+ {"bltu", {}},
+ {"bgtu", {}},
+ {"bgeu", {}},
+ {"bleu", {}},
+ {"nop", {}},
+ {"ecall", {}},
+ {"ebreak", {}},
+};
+
+std::map<std::string, uint8_t> registers = {
+ {"x0", 0}, {"x1", 1}, {"x2", 2}, {"x3", 3}, {"x4", 4}, {"x5", 5}, {"x6", 6}, {"x7", 7}, {"x8", 8},
+ {"x9", 9}, {"x10", 10}, {"x11", 11}, {"x12", 12}, {"x13", 13}, {"x14", 14}, {"x15", 15}, {"x16", 16}, {"x17", 17},
+ {"x18", 18}, {"x19", 19}, {"x20", 20}, {"x21", 21}, {"x22", 22}, {"x23", 23}, {"x24", 24}, {"x25", 25}, {"x26", 26},
+ {"x27", 27}, {"x28", 28}, {"x29", 29}, {"x30", 30}, {"x31", 31}, {"zero", 0}, {"ra", 1}, {"sp", 2}, {"gp", 3},
+ {"tp", 4}, {"t0", 5}, {"t1", 6}, {"t2", 7}, {"s0", 8}, {"fp", 8}, {"s1", 9}, {"a0", 10}, {"a1", 11},
+ {"a2", 12}, {"a3", 13}, {"a4", 14}, {"a5", 15}, {"a6", 16}, {"a7", 17}, {"s2", 18}, {"s3", 19}, {"s4", 20},
+ {"s5", 21}, {"s6", 22}, {"s7", 23}, {"s8", 24}, {"s9", 25}, {"s10", 26}, {"s11", 27}, {"t3", 28}, {"t4", 29},
+ {"t5", 30}, {"t6", 31},
+};
+} // namespace
+