Skip to content
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

target/riscv: access registers via reg->type #1187

Open
wants to merge 2 commits into
base: riscv
Choose a base branch
from

Conversation

en-sc
Copy link
Collaborator

@en-sc en-sc commented Dec 20, 2024

  • int riscv_reg_get() and int riscv_reg_set() are implemented in
    terms of reg->type->get/set instead of the other way around. This
    makes it easier to support custom behavior for some registers.
  • Cacheability is determined by reg->type instead of
    riscv_reg_impl_gdb_regno_cacheable().
  • Issues with redirection of priv -> dcsr and pc -> dpc are
    addressed at the "topmost" level.
    • priv and pc are always invalid.
    • Fixed some issues, e.g. the first pc write printed-out an
      uninitialized value:
> reg pc 0
pc (/64): 0x000075da6b33db20

@en-sc
Copy link
Collaborator Author

en-sc commented Dec 20, 2024

Please note: this PR cherry-picks https://review.openocd.org/c/openocd/+/8070

@en-sc en-sc force-pushed the en-sc/ref-reg-get-set branch from 6387dd4 to a54d86f Compare December 20, 2024 11:57
Copy link
Collaborator

@JanMatCodasip JanMatCodasip left a comment

Choose a reason for hiding this comment

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

@en-sc Thank you for preparing this change.

I have not yet managed a proper review, but I have revived and rebased the underlying upstream patch.

My preference would be to have that upstream patch merged first, then import the change to riscv-openocd via a periodic merge from upstream, and then finally merge this PR. However, it is difficult to estimate when/if the upstream patch gets a review.

To anyone from the riscv-openocd audience: If you could help with the review in OpenOCD upstream, that would be very appreciated!

Copy link
Collaborator

@JanMatCodasip JanMatCodasip left a comment

Choose a reason for hiding this comment

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

Note: In the review I focused on the second commit only: target/riscv: access registers via reg->type. Any comments to the other underlying upstream commit should be posted directly to the upstream review.

Overall, I like this change very much. I have some concerns over get_pc() and set_pc(), and then trivial suggestions about comments and naming. Other than that, the code looks all right - thank you.

@aap-sc
Copy link
Collaborator

aap-sc commented Feb 4, 2025

@en-sc minor comment regarding commit description:

priv and pc are alvais invalid.

alvais -> always :)

@en-sc en-sc force-pushed the en-sc/ref-reg-get-set branch 3 times, most recently from d45da3c to 2b852d6 Compare February 14, 2025 12:57
Copy link
Collaborator

@JanMatCodasip JanMatCodasip left a comment

Choose a reason for hiding this comment

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

Due to the size (and importance) of this PR, I would like to go through it once more.

Anyway, it looks very good overall. Also thanks for addressing my suggestions so far.

@en-sc en-sc force-pushed the en-sc/ref-reg-get-set branch 2 times, most recently from ba03990 to 8ca5b54 Compare February 17, 2025 13:15
Copy link
Collaborator

@JanMatCodasip JanMatCodasip left a comment

Choose a reason for hiding this comment

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

Overall, this change looks fine.

I have posted few last minor comments and do not expect to have any more.

Also there is a merge conflict at the moment.

MarekVCodasip and others added 2 commits February 27, 2025 10:27
…pability

Cherrry-picked form https://review.openocd.org/c/openocd/+/8070/21

1) OpenOCD has the capability to 'force' a register read from the
target. This functionality however silently breaks the register
cache: During 'get_reg force' or 'reg <name> force',
reg->type->get() is called which will silently overwrite
dirty items in the register cache, causing a loss of unwritten
register values. This patch fixes that by adding a flush
callback for registers, and by using it when it is needed.

2) The register write commands did not have the 'force' flag;
this was present for register read commands only.
This patch adds it.

3) This patch also introduces the flush_reg_cache command. It
flushes all registers and can optionally invalidate the register
cache after the flush.

For targets which implement the register cache, the flush()
callback in struct reg_arch_type should be implemented (in
separate patches, by the maintainers of each of the target type).

This functionality is also useful for test purposes. Example:
 - In RISC-V, some registers are WARL (write any read legal)
   and this command allows to check this behavior.

We plan to implement the corresponding callback
in the RISC-V target.

Change-Id: I9537a5f05b46330f70aad17f77b2b80dedad068a
Signed-off-by: Marek Vrbka <[email protected]>
Signed-off-by: Jan Matyas <[email protected]>
* `int riscv_reg_get()` and `int riscv_reg_set()` are implemented in
  terms of `reg->type->get/set` instead of the other way around. This
  makes it easier to support custom behavior for some registers.
* Cacheability is determined by `reg->type` instead of
  `riscv_reg_impl_gdb_regno_cacheable()`.
* Issues with redirection of `priv` -> `dcsr` and `pc` -> `dpc` are
  addressed at the "topmost" level.
    - `priv` and `pc` are always invalid.
    - Fixed some issues, e.g. the first `pc` write printed-out an
      uninitialized value:
```
> reg pc 0
pc (/64): 0x000075da6b33db20
```

Change-Id: I514547f455d62b289fb5dee62753bf5d9aa3b8ae
Signed-off-by: Evgeniy Naydanov <[email protected]>
@en-sc en-sc force-pushed the en-sc/ref-reg-get-set branch from 8ca5b54 to 85654c1 Compare February 27, 2025 07:29
@en-sc en-sc requested a review from JanMatCodasip February 27, 2025 07:30
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.

4 participants