we can now disassemble riscv64-linux-musl-gcc hello world!
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -3,3 +3,5 @@
|
|||||||
/chip8
|
/chip8
|
||||||
/mos6502
|
/mos6502
|
||||||
/riscv64
|
/riscv64
|
||||||
|
/riscv64-linux-musl-cross
|
||||||
|
/dump
|
||||||
158
riscv64.cc
158
riscv64.cc
@@ -86,6 +86,7 @@ enum Op {
|
|||||||
C_SUB,
|
C_SUB,
|
||||||
C_SUBW,
|
C_SUBW,
|
||||||
C_SW,
|
C_SW,
|
||||||
|
C_SWSP,
|
||||||
C_XOR,
|
C_XOR,
|
||||||
DIV,
|
DIV,
|
||||||
DIVU,
|
DIVU,
|
||||||
@@ -187,106 +188,57 @@ struct OpDef {
|
|||||||
Format format;
|
Format format;
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr std::array<OpDef, 100> OP_TABLE = {{
|
static constexpr std::array<OpDef, 101> OP_TABLE = {{
|
||||||
{"???", Format::NONE},
|
{"???", Format::NONE}, {"add", Format::R},
|
||||||
{"add", Format::R},
|
{"addi", Format::I}, {"addiw", Format::I},
|
||||||
{"addi", Format::I},
|
{"addw", Format::R}, {"amoswap.d", Format::R_ATOMIC},
|
||||||
{"addiw", Format::I},
|
{"and", Format::R}, {"andi", Format::I},
|
||||||
{"addw", Format::R},
|
{"auipc", Format::U}, {"beq", Format::B},
|
||||||
{"amoswap.d", Format::R_ATOMIC},
|
{"bge", Format::B}, {"bgeu", Format::B},
|
||||||
{"and", Format::R},
|
{"blt", Format::B}, {"bltu", Format::B},
|
||||||
{"andi", Format::I},
|
{"bne", Format::B}, {"c.add", Format::CR},
|
||||||
{"auipc", Format::U},
|
{"c.addi", Format::CI}, {"c.addiw", Format::CI},
|
||||||
{"beq", Format::B},
|
{"c.addi16sp", Format::CI}, {"c.addi4spn", Format::CI},
|
||||||
{"bge", Format::B},
|
{"c.addw", Format::CI}, {"c.and", Format::CR},
|
||||||
{"bgeu", Format::B},
|
{"c.andi", Format::CI}, {"c.beqz", Format::B},
|
||||||
{"blt", Format::B},
|
{"c.bnez", Format::B}, {"c.ebreak", Format::CR},
|
||||||
{"bltu", Format::B},
|
{"c.fldsp", Format::CSS}, {"c.j", Format::CJ},
|
||||||
{"bne", Format::B},
|
{"c.jalr", Format::CR1}, {"c.jr", Format::CR1},
|
||||||
{"c.add", Format::CR},
|
{"c.ld", Format::CL}, {"c.ldsp", Format::CL},
|
||||||
{"c.addi", Format::CI},
|
{"c.li", Format::CI}, {"c.lui", Format::CI},
|
||||||
{"c.addiw", Format::CI},
|
{"c.lw", Format::CL}, {"c.mv", Format::CR},
|
||||||
{"c.addi16sp", Format::CI},
|
{"c.or", Format::CR}, {"c.sd", Format::S},
|
||||||
{"c.addi4spn", Format::CI},
|
{"c.sdsp", Format::CSS}, {"c.slli", Format::CI},
|
||||||
{"c.addw", Format::CI},
|
{"c.srai", Format::CI}, {"c.srli", Format::CI},
|
||||||
{"c.and", Format::CR},
|
{"c.sub", Format::CR}, {"c.subw", Format::CR},
|
||||||
{"c.andi", Format::CI},
|
{"c.sw", Format::S}, {"c.swsp", Format::CSS},
|
||||||
{"c.beqz", Format::B},
|
{"c.xor", Format::CR}, {"div", Format::R},
|
||||||
{"c.bnez", Format::B},
|
{"divu", Format::R}, {"divuw", Format::R},
|
||||||
{"c.ebreak", Format::CR},
|
{"divw", Format::R}, {"ecall", Format::NONE},
|
||||||
{"c.fldsp", Format::CSS},
|
{"fence", Format::NONE}, {"fence.tso", Format::NONE},
|
||||||
{"c.j", Format::CJ},
|
{"jal", Format::J}, {"jalr", Format::I},
|
||||||
{"c.jalr", Format::CR1},
|
{"lb", Format::I_LOAD}, {"lbu", Format::I_LOAD},
|
||||||
{"c.jr", Format::CR1},
|
{"ld", Format::I_LOAD}, {"lh", Format::I_LOAD},
|
||||||
{"c.ld", Format::CL},
|
{"lhu", Format::I_LOAD}, {"lr.d", Format::R_ATOMIC_LR},
|
||||||
{"c.ldsp", Format::CL},
|
{"lui", Format::U}, {"lw", Format::I_LOAD},
|
||||||
{"c.li", Format::CI},
|
{"lwu", Format::I_LOAD}, {"mul", Format::R},
|
||||||
{"c.lui", Format::CI},
|
{"mulh", Format::R}, {"mulhu", Format::R},
|
||||||
{"c.lw", Format::CL},
|
{"mulw", Format::R}, {"or", Format::R},
|
||||||
{"c.mv", Format::CR},
|
{"ori", Format::I}, {"pause", Format::NONE},
|
||||||
{"c.or", Format::CR},
|
{"rem", Format::R}, {"remu", Format::R},
|
||||||
{"c.sd", Format::S},
|
{"remuw", Format::R}, {"remw", Format::R},
|
||||||
{"c.sdsp", Format::CSS},
|
{"sb", Format::S}, {"sc.d", Format::R_ATOMIC},
|
||||||
{"c.slli", Format::CI},
|
{"sd", Format::S}, {"sh", Format::S},
|
||||||
{"c.srai", Format::CI},
|
{"sll", Format::R}, {"slli", Format::I_SHIFT},
|
||||||
{"c.srli", Format::CI},
|
{"slliw", Format::I_SHIFT}, {"sllw", Format::R},
|
||||||
{"c.sub", Format::CR},
|
{"slt", Format::R}, {"slti", Format::I},
|
||||||
{"c.subw", Format::CR},
|
{"sltiu", Format::I}, {"sltu", Format::R},
|
||||||
{"c.sw", Format::S},
|
{"sra", Format::R}, {"srai", Format::I_SHIFT},
|
||||||
{"c.xor", Format::CR},
|
{"sraiw", Format::I_SHIFT}, {"sraw", Format::R},
|
||||||
{"div", Format::R},
|
{"srl", Format::R}, {"srli", Format::I_SHIFT},
|
||||||
{"divu", Format::R},
|
{"srliw", Format::I_SHIFT}, {"srlw", Format::R},
|
||||||
{"divuw", Format::R},
|
{"sub", Format::R}, {"subw", Format::R},
|
||||||
{"divw", Format::R},
|
{"sw", Format::S}, {"xor", Format::R},
|
||||||
{"ecall", Format::NONE},
|
|
||||||
{"fence", Format::NONE},
|
|
||||||
{"fence.tso", Format::NONE},
|
|
||||||
{"jal", Format::J},
|
|
||||||
{"jalr", Format::I},
|
|
||||||
{"lb", Format::I_LOAD},
|
|
||||||
{"lbu", Format::I_LOAD},
|
|
||||||
{"ld", Format::I_LOAD},
|
|
||||||
{"lh", Format::I_LOAD},
|
|
||||||
{"lhu", Format::I_LOAD},
|
|
||||||
{"lr.d", Format::R_ATOMIC_LR},
|
|
||||||
{"lui", Format::U},
|
|
||||||
{"lw", Format::I_LOAD},
|
|
||||||
{"lwu", Format::I_LOAD},
|
|
||||||
{"mul", Format::R},
|
|
||||||
{"mulh", Format::R},
|
|
||||||
{"mulhu", Format::R},
|
|
||||||
{"mulw", Format::R},
|
|
||||||
{"or", Format::R},
|
|
||||||
{"ori", Format::I},
|
|
||||||
{"pause", Format::NONE},
|
|
||||||
{"rem", Format::R},
|
|
||||||
{"remu", Format::R},
|
|
||||||
{"remuw", Format::R},
|
|
||||||
{"remw", Format::R},
|
|
||||||
{"sb", Format::S},
|
|
||||||
{"sc.d", Format::R_ATOMIC},
|
|
||||||
{"sd", Format::S},
|
|
||||||
{"sh", Format::S},
|
|
||||||
{"sll", Format::R},
|
|
||||||
{"slli", Format::I_SHIFT},
|
|
||||||
{"slliw", Format::I_SHIFT},
|
|
||||||
{"sllw", Format::R},
|
|
||||||
{"slt", Format::R},
|
|
||||||
{"slti", Format::I},
|
|
||||||
{"sltiu", Format::I},
|
|
||||||
{"sltu", Format::R},
|
|
||||||
{"sra", Format::R},
|
|
||||||
{"srai", Format::I_SHIFT},
|
|
||||||
{"sraiw", Format::I_SHIFT},
|
|
||||||
{"sraw", Format::R},
|
|
||||||
{"srl", Format::R},
|
|
||||||
{"srli", Format::I_SHIFT},
|
|
||||||
{"srliw", Format::I_SHIFT},
|
|
||||||
{"srlw", Format::R},
|
|
||||||
{"sub", Format::R},
|
|
||||||
{"subw", Format::R},
|
|
||||||
{"sw", Format::S},
|
|
||||||
{"xor", Format::R},
|
|
||||||
{"xori", Format::I},
|
{"xori", Format::I},
|
||||||
}};
|
}};
|
||||||
|
|
||||||
@@ -1091,6 +1043,12 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}; break;
|
}; break;
|
||||||
|
case 0b110: {
|
||||||
|
i.rs2 = (raw >> 2) & 0b11111;
|
||||||
|
i.rs1 = 2;
|
||||||
|
i.imm = (((raw >> 9) & 0b1111) << 2) | (((raw >> 7) & 0b11) << 6);
|
||||||
|
i.op = Op::C_SWSP;
|
||||||
|
}; break;
|
||||||
case 0b111: {
|
case 0b111: {
|
||||||
i.rs2 = (raw >> 2) & 0b11111;
|
i.rs2 = (raw >> 2) & 0b11111;
|
||||||
i.imm = (((raw >> 10) & 0b111) << 3) | (((raw >> 7) & 0b111) << 6);
|
i.imm = (((raw >> 10) & 0b111) << 3) | (((raw >> 7) & 0b111) << 6);
|
||||||
|
|||||||
Reference in New Issue
Block a user