Skip to content

Conversation

@compnerd
Copy link
Owner

@compnerd compnerd commented Mar 1, 2022

This adds the rv{32,64,128} skeleton in place so that we can start adding the
necessary architectural support.

@compnerd compnerd force-pushed the compnerd/riscv64 branch 7 times, most recently from 8fd2cd8 to a629114 Compare March 8, 2022 23:17
@compnerd compnerd force-pushed the compnerd/riscv64 branch 10 times, most recently from deeeab9 to d21dbb4 Compare March 17, 2022 21:32
@compnerd
Copy link
Owner Author

compnerd commented Mar 22, 2022

Why do you need to shift right just to shift back left if you are doing the and to pull of the relevant bits? Also you do this operation a lot... wondering if you could encapsulate it in an inline function?

Ah, good question! It seems silly but it is because I'm terrible at arithmetic, but the compiler is stupidly good at it. This means that I can just cross-reference the documentation saying that these bits correspond to this bit of the address. The compiler will collapse that down anyway.

Nit: More clear name than RISCVnnn? Isn't exactly clear what it represents.

I don't have a better name. This was something that I replicated from RISCV itself! They use that in the ABI documentation.

Nit: For the "non-obvious" alternate abbreviations, it would be worthwhile to have comments describing what they are. The return address/stack pointer, might be obvious -- but thread pointer, saved register, function argument might not be.

I think that you addressed this subsequently:

Nit: For the alternate-names, it would be useful to have a link to a reference where these are defined.

These names are from the RISCV specification. I can add a link to the specification, but not sure if its valuable (and we don't have similar links for the X86 or ARM specifications).

Should bit-size be 32 for RV32F, and 64 for RV32D?

That is part of the TODO mentioned in the build changes: this currently assumes RVnnnG. That implies f, d, and d = 64 bit as per the specification if I understand it correctly.

CMakeLists.txt Outdated

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: More clear name than RISCVnnn? Isn't exactly clear what it represents.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took this name from one of the RISCV docs (ELF psABI?). The "nnn" is a placeholder for digits indicating the bitness.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: For the alternate-names, it would be useful to have a link to a reference where these are defined.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is effectively determined by GDB as the canonical source of information. The same applies to all the definitions for the other architectures. I think that adding that to developer documentation might be a good idea, but would be out of scope for this change IMO.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: For the "non-obvious" alternate abbreviations, it would be worthwhile to have comments describing what they are. The return address/stack pointer, might be obvious -- but thread pointer, saved register, function argument might not be.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH, I don't even know if there is an explanation for the names. These are determined by GDB's expectations.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should bit-size be 32 for RV32F, and 64 for RV32D?

"We use the term FLEN to describe the width of the floating-point registers in the RISC-V ISA, and FLEN=32 for the F single-precision floating-point extension."

"The D extension widens the 32 floating-point registers, f0–f31, to 64 bits (FLEN=64 in Fig-
ure 11.1). The f registers can now hold either 32-bit or 64-bit floating-point values as described
below in Section 12.2."

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one of the tradeoffs I made. If you look at the CMakeLIsts.txt change, there is a TODO there to determine the detail of the FPU more accurately. This currently assumes RVnnnG which implies f,d. AIUI, f = 32-bit, d = 64-bit, and q = 128-bit register width. GDB expects that a single width is used, which matches uintptr_t (due to the G expectation).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to shift right just to shift back left if you are doing the and to pull of the relevant bits?
Also you do this operation a lot... wondering if you could encapsulate it in an inline function?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question! I am terrible with arithmetic but the compiler is good! It can flatten this out, but in its current form it matches the specification almost verbatim. I have less to think about this way.

Screen Shot 2022-03-22 at 12 34 13 PM

Add support for RISCV64G (and partial support for RISCV32G and RISCV128G).  This
has been tested to work with RV64G in qemu and LLDB from LLVM main.
@compnerd compnerd merged commit 115fc18 into main Mar 22, 2022
@compnerd compnerd deleted the compnerd/riscv64 branch March 22, 2022 21:59
compnerd added a commit that referenced this pull request Mar 22, 2022
Replace the bit-extraction operations with a helper template type `bits` which
takes two template parameters to indicate the bits to extract.  This improves
the readability and maintainability of the RISCV disassembler.  The idea itself
was something that was suggested by @dmlockhart in #47.  This noticably improves
the ability to cross-reference the RISCV ISA specification.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants