-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LibDisassembly: RISC-V disassembly 4-2/4-5: Disassemble extensions FD (floating-point), A (atomic) and Zicsr (CSRs) #25836
base: master
Are you sure you want to change the base?
Conversation
Note that CSR pretty-printing is not yet implemented, since we aim to establish shared CSR utilities in AK in the near future.
Again, no point in splitting these two since the orthagonal instruction set makes supporting both in common abstractions convenient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My ketchup, you already have the mustard
(Also not sure why I reviewed the commits in reverse)
auto is_sc = (raw_parts.funct7 & (1 << 2)) > 0; | ||
return adopt_own(*new (nothrow) LoadReserveStoreConditional(is_sc ? LoadReserveStoreConditional::Operation::StoreConditional : LoadReserveStoreConditional::Operation::LoadReserve, is_acquire, is_release, width, raw_parts.rs1, raw_parts.rs2, raw_parts.rd)); | ||
} | ||
case 0b00001: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am once again asking you to make this the enum values you are eventually/essentially assigning, so this becomes a cast-or-rejection pattern
(Seems like this did not make the cut for the the arithmetic instructions in G?)
|
||
auto operation = FloatArithmeticInstruction::Operation::Add; | ||
switch (raw_parts.funct7 & ~0b11) { | ||
case 0b0000000: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as in A
ErrorOr<void> format(FormatBuilder& builder, Disassembly::RISCV64::CSRInstruction::Operation op) | ||
{ | ||
auto op_name = ""sv; | ||
switch (op) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe sprinkle some using
/using enum
s in the formatters
The namespace lookup chains assume alarming proportions
auto is_immediate = (raw_parts.funct3 & 0b100) > 0; | ||
auto operation = CSRInstruction::Operation::ReadWrite; | ||
|
||
switch (raw_parts.funct3 & 0b11) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add
case 0b00:
VERIFY_NOT_REACHED();
here (just to be safe)? SYSTEM instructions with funct3 == 0 shouldn't be CSR instructions afaict.
@@ -172,6 +172,26 @@ String InstructionFetchFence::mnemonic() const | |||
return "fence.i"_string; | |||
} | |||
|
|||
String CSRImmediateInstruction::to_string(DisplayStyle display_style, u32, Optional<SymbolProvider const&>) const | |||
{ | |||
return MUST(String::formatted("{:10} {}, {}, {:d}", mnemonic(), format_register(destination_register(), display_style), immediate(), csr())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CSR immediate instructions are written as csrrwi rd, csr, uimm
.
Also, CSR addresses are typically formatted as hex.
|
||
String CSRRegisterInstruction::to_string(DisplayStyle display_style, u32, Optional<SymbolProvider const&>) const | ||
{ | ||
return MUST(String::formatted("{:10} {}, {}, {:d}", mnemonic(), format_register(destination_register(), display_style), format_register(source_register(), display_style), csr())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CSR register instructions are written as csrrw rd, csr, rs
.
Also, CSR addresses are typically formatted as hex.
@@ -147,6 +271,16 @@ String MemoryLoad::mnemonic() const | |||
return MUST(String::formatted("l{}", m_width)); | |||
} | |||
|
|||
String FloatMemoryLoad::to_string(DisplayStyle display_style, u32, Optional<SymbolProvider const&>) const | |||
{ | |||
return MUST(String::formatted("fl{:8} {}, {:#03x}({})", memory_width(), format_register(destination_register(), display_style), immediate(), format_register(base(), display_style))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You use mnemonic()
in the format string everywhere except here and in FloatMemoryStore::to_string
.
RoundingMode m_rounding_mode; | ||
}; | ||
|
||
class FloatRTypeInstruction : public FloatComputationInstruction { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you not derive from this class in some of the R-Type F/D instruction implementations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tbh I think the inheritance hierarchy is a bit overengineered in general.
(not a blocker though)
@@ -352,4 +352,25 @@ String Fence::mnemonic() const | |||
VERIFY_NOT_REACHED(); | |||
} | |||
|
|||
String AtomicMemoryOperation::to_string(DisplayStyle display_style, u32, Optional<SymbolProvider const&>) const | |||
{ | |||
return MUST(String::formatted("{:10} {}, {}, {}", mnemonic(), format_register(destination_register(), display_style), format_register(source_register_1(), display_style), format_register(source_register_2(), display_style))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
amo{} rd, rs2, (rs1)
is the correct syntax, not amo{} rd, rs1, rs2
.
|
||
String LoadReserveStoreConditional::to_string(DisplayStyle display_style, u32, Optional<SymbolProvider const&>) const | ||
{ | ||
return MUST(String::formatted("{:10} {}, {} ({})", mnemonic(), format_register(destination_register(), display_style), format_register(source_register_2(), display_style), format_register(source_register_1(), display_style))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lr
only has one source operand: rs1 as the address.
|
||
String AtomicMemoryOperation::mnemonic() const | ||
{ | ||
return MUST(String::formatted("amo{}.{}{}{}", m_operation, MemoryAccessMode { width(), Signedness::Signed }, is_acquire() ? ".aq"sv : ""sv, is_release() ? ".rl"sv : ""sv)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.aqrl
is the correct syntax for both acquire and release.
String LoadReserveStoreConditional::mnemonic() const | ||
{ | ||
auto operation = m_operation == Operation::LoadReserve ? "lr"sv : "sc"sv; | ||
return MUST(String::formatted("{}.{}{}{}", operation, MemoryAccessMode { width(), Signedness::Signed }, is_acquire() ? ".aq"sv : ""sv, is_release() ? ".rl"sv : ""sv)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
class LoadReserveStoreConditional : public AtomicOperation { | ||
public: | ||
enum class Operation : bool { | ||
LoadReserve, | ||
StoreConditional, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/LoadReserve/LoadReserved
This second PR in the collection deals with all the remaining non-priviledged extensions we need right now. I encourage anyone with three years of free time to tackle V :3
LibDisassembly: Add RISC-V Zicsr extension decoding
Note that CSR pretty-printing is not yet implemented, since we aim to establish shared CSR utilities in AK in the near future.
LibDisassembly: Add RISC-V FD extension decoding
Again, no point in splitting these two since the orthagonal instruction set makes supporting both in common abstractions convenient.
LibDisassembly: Add RISC-V A extension decoding