Commit Graph

9844 Commits

Author SHA1 Message Date
Evgeniy Naydanov a54d86f3d0 target/riscv: access registers via `reg->type`
* `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 alvais 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 <evgeniy.naydanov@syntacore.com>
2024-12-20 14:57:09 +03:00
Marek Vrbka 1c6b7fa2c9 target: Fix force-reading of registers and add flush capability
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 invalidates the register
cache after the flush.

For targets which implement the register cache should implement
the flush() callback in struct reg_arch_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 <marek.vrbka@codasip.com>
Signed-off-by: Jan Matyas <jan.matyas@codasip.com>
2024-12-20 14:56:56 +03:00
Evgeniy Naydanov 4b9fb1972f Merge up to 133dd9d669 from upstream
Change-Id: Iaaf234da839cbed61684f4615135c9a42213c56a
2024-12-18 12:41:19 +03:00
Evgeniy Naydanov cf9963ad81
Merge pull request #1181 from en-sc/en-sc/reg-invalidate
target/riscv: clean-up register invalidation
2024-12-11 16:40:20 +03:00
Evgeniy Naydanov de20c2ad5f target/riscv: clean-up register invalidation
* Registers were not invalidated if the hart became unavailable.
* Improved logging in the case register invalidation involves loss of
  information.

Change-Id: Icfb5e190dd6dcb1a97e4d314d802466cab7a01e4
Signed-off-by: Evgeniy Naydanov <evgeniy.naydanov@syntacore.com>
2024-12-10 15:25:22 +03:00
Farid Khaydari d5c2604418 target/riscv: replaced repeating ternary operator with variable
Replaced repeating ternary operator with variable

Signed-off-by: Farid Khaydari <f.khaydari@syntacore.com>
2024-12-10 13:40:08 +03:00
Farid Khaydari 4dcd80164a target/riscv: use buf_get_uXX instead of manual bit shift
Replaced manual bit shift with buf_get_u64/buf_get_u32

Signed-off-by: Farid Khaydari <f.khaydari@syntacore.com>
2024-12-04 22:56:05 +03:00
Anatoly Parshintsev c430c24330
Merge pull request #1167 from fk-sc/fk-sc/rwargs
target/riscv: pass memory access info in struct, move write_memory pointer
2024-12-04 21:04:56 +03:00
Anatoly Parshintsev ca80920157
Merge pull request #1176 from aap-sc/aap-sc/csr_as_hex_regression_fixup
fix incorrect parsing of names for custom csr registers
2024-11-29 18:26:19 +03:00
Farid Khaydari eb4e717a3b target/riscv: pass memory access info in struct, move write_memory pointer
This changes will allow to unite read_memory/write_memory fucntions
to one access function

(1) Replaced read/write functions arguments with one structure
(2) Unified read_memory/write_memory function pointers
    to be stored in same structure

Signed-off-by: Farid Khaydari <f.khaydari@syntacore.com>
2024-11-29 18:12:53 +03:00
Anatoly Parshintsev 0f0302b029
Merge pull request #1174 from fk-sc/fk-sc/checker-fix
target/riscv: fix memory access result type checker function return in case of assertion
2024-11-29 01:23:37 +03:00
Parshintsev Anatoly 109646c09d fix incorrect parsing of names for custom csr registers
this commit fixes a regression introduced in
ba8c1eef5a.

The regression was caused by removal of these lines:

```
-                       /* Register prefix: "csr_" or "custom_" */
-                       strcpy(name, reg_type);
-                       name[strlen(reg_type)] = '_';
```

causing all CSR names with custom names to be parsed as empty strings.
2024-11-27 22:08:20 +03:00
Evgeniy Naydanov eb1ecd7d10
Merge pull request #1170 from fk-sc/fk-sc/priv-mod
target/riscv: decrease modify_privilege function nesting level
2024-11-26 17:26:49 +03:00
Farid Khaydari c8ae081979 target/riscv: fix memory access result type checker function return in case of assertion
Fix memory access result type checker return in case of assertion

Signed-off-by: Farid Khaydari <f.khaydari@syntacore.com>
2024-11-26 12:56:36 +03:00
Anatoly Parshintsev 658766858d
Merge pull request #1162 from aap-sc/aap-sc/csr_as_hex
target/riscv: allow hexadecimal values to expose_csr-like commands
2024-11-25 23:00:32 +03:00
Henrik Mau 133dd9d669 target/xtensa: add maskisr command support for NX
Add maskisr command support to Xtensa NX targets allowing masking
of interrupts during single stepping.

Change-Id: I3835479de8015f1a2842afd1aeab24829e385031
Signed-off-by: Henrik Mau <henrik.mau@analog.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8575
Reviewed-by: Ian Thompson <ianst@cadence.com>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
2024-11-23 13:54:44 +00:00
Marc Schink 76e228f733 target/cortex_m: Use LOG_TARGET_xxx()
Use LOG_TARGET_xxx() for the remaining log messages.

Change-Id: If52e3935b57e4c39212ce6b5111ff65159de1373
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/8580
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-11-23 13:54:03 +00:00
Marc Schink c837beaf5d target/breakpoints: Use LOG_TARGET_ERROR()
Use LOG_TARGET_xxx() for the remaining log messages.

Change-Id: I4b86b206d17dead0662388e827204b40a7d29edd
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/8579
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-11-23 13:53:42 +00:00
Marc Schink 6973613175 rtos: Remove 'ERROR: ' prefix in error log
Remove the prefix since it is redundant. While at it, also
get rid of the useless exclamation mark.

Change-Id: I8707342c602cea735c5a423b37ebe40a3aafb137
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/8578
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-11-23 13:53:24 +00:00
Marc Schink f5036aff3a target/xtensa: Remove 'ERROR: ' prefix in error log
Remove the prefix since it is redundant.

Change-Id: I9c23c0479ba40be24e471309e720060cd03763ee
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/8577
Tested-by: jenkins
Reviewed-by: Ian Thompson <ianst@cadence.com>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-11-23 13:52:56 +00:00
R. Diez 9ff79fd61f enable the Bus Pirate adapter by default on most systems
Also convert the Bus Pirate to the common PROCESS_ADAPTERS logic.

Change-Id: Ifa8ebcee380c16d7e308ba7a75dbffdb74208285
Signed-off-by: R. Diez <rdiezmail-openocd@yahoo.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/8533
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: R. Diez <rdiez-2006@rd10.de>
Tested-by: jenkins
2024-11-23 13:49:42 +00:00
Antonio Borneo c582cfbf75 driver: stlink: get adapter speed through adapter_get_speed_khz()
The stlink driver, both in dapdirect and in HLA modes, pretends to
store locally the value of the adapter speed in order to use it
later-on during adapter initialization.
It doesn't work in dapdirect mode since the code to store locally
the value will not be executed until the adapter is already fully
initialized.

This cause an issue in dapdirect mode:
- due to the local value, still kept at -1, the adapter will be
  initialized to the lowest clock speed (5 KHz on stlink v2 in SWD
  mode);
- after the adapter initialization the framework will again set
  the speed with the value requested by the user.

Some target, like nRF51822, only accepts JTAG/SWD speed in a
defined range of frequencies. The initial speed of 5 KHz used by
dapdirect can be out of range, making the target debug port not
working.

The adapter framework already stores the value of speed and makes
it available through adapter_get_speed_khz().

Drop struct hl_interface_param::initial_interface_speed.
Let the code to use adapter_get_speed_khz().

Change-Id: Ie11bf0234574f2a9180d3d3a16efb78e08dfcd86
Reported-by: Andrzej Sierżęga <asier70@gmail.com>
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8574
Reviewed-by: Andrzej Sierżęga <asier70@gmail.com>
Tested-by: jenkins
2024-11-23 13:49:16 +00:00
Marc Schink 8c739a45a0 helper/jim-nvp.h: Rework 'isconfigure' variable
Change the variable name to 'is_configure' to be compatible with the
coding style and use 'bool' as data type.

Change-Id: I8609f9807c8bd14eaf6c93acf63fd51b55c9bbbb
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/8573
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-11-23 13:48:52 +00:00
Antonio Borneo 61fbcbeca8 semihosting: make local functions static
The functions:
- semihosting_opcode_to_str();
- semihosting_write_fields();
- semihosting_set_field();
are not referenced outside the file.

Make them static.

Change-Id: Ia8d35554673145fdfe0e501543eb18919863039f
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8551
Tested-by: jenkins
2024-11-23 13:48:25 +00:00
Antonio Borneo b04a58e3fc target: esirisc: make local functions static
The function esirisc_jtag_get_eid() is not used outside the file.
Make it static.

The function esirisc_jtag_disable_debug() is never used.
Make it static and mark it as unused.

Change-Id: I5c99cbf77cc9c527b6e18a3f67caa24f8551d09c
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8550
Tested-by: jenkins
2024-11-23 13:48:12 +00:00
Antonio Borneo df42faf51d target: aarch64: drop unused armv8_mmu_translate_va()
The function is not used.
Drop it!

Change-Id: I1625e03714b5a842f668098191c39cce34f815e8
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8549
Tested-by: jenkins
2024-11-23 13:47:55 +00:00
Antonio Borneo c5babec794 target: x86_32: make x86_32_common_read_io() static
The function is not referenced outside the file.
Make it static.

Change-Id: Ic2552c040b6b46c0334851a4fc0fdaa400e11e4c
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8548
Tested-by: jenkins
2024-11-23 13:47:33 +00:00
Antonio Borneo f3aeb3d676 target: dsp563xx: make dsp563xx_once_reg_read_ex() static
The function is not referenced outside the file.
Make it static.

Change-Id: Ifeccc5e38f3da4b4111422860bc1c1447d00f7fe
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8547
Tested-by: jenkins
2024-11-23 13:47:15 +00:00
Antonio Borneo a34d4b8cb4 pld: make get_pld_device_by_num() static
The function is not referenced outside the file.
Make it static.

Change-Id: I5f2a2c70085b9158df8806432bb9ed09bb256ab5
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8546
Tested-by: jenkins
2024-11-23 13:46:59 +00:00
Antonio Borneo 4da8f6d27a rtt: drop unused function rtt_started()
The function is not used.
Drop it!

Change-Id: I176c9d6ba077e36b762c14f9b877d5152992763c
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8545
Tested-by: jenkins
Reviewed-by: zapb <dev@zapb.de>
2024-11-23 13:46:35 +00:00
Antonio Borneo 644742b4b2 driver: mpsse: make local functions static
The functions:
- mpsse_divide_by_5_config();
- mpsse_purge();
- mpsse_rtck_config();
- mpsse_set_divisor();
are not referenced outside the file.

Make them static.

Change-Id: Id6930183a3ce26693b2113f622046168ba289df8
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8544
Tested-by: jenkins
2024-11-23 13:46:20 +00:00
Antonio Borneo f4ac0c7022 jtag: driver: make local functions static
The functions:
- interface_jtag_add_callback();
- interface_jtag_add_callback4();
are not referenced outside the file.

Make them static.

Change-Id: I84f738309d23c8d0b5329aa04436db750cf185e5
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8543
Tested-by: jenkins
2024-11-23 13:46:01 +00:00
Antonio Borneo f82664ff82 jtag: core: make local functions static
The functions:
- jtag_error_clear();
- jtag_tap_count();
are not referenced outside the file.

Make them static.

Change-Id: I00fcf06b1838b9f6c955c19772f1d41d486459e9
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8542
Tested-by: jenkins
2024-11-23 13:45:42 +00:00
Antonio Borneo 2465f18515 adapter: make adapter_config_khz() static
The function is not referenced outside the file.
Make it static.

Change-Id: I72e96624749ae4cc7f4566d737a88186e899616a
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8541
Tested-by: jenkins
2024-11-23 13:45:19 +00:00
Evgeniy Naydanov 1bf7efb2d5
Merge pull request #1144 from sunnyzhu-learning/resume-before-step-develop
target/riscv:Perform single step before resume if necessary
2024-11-21 12:37:59 +03:00
Farid Khaydari 8b7013028c target/riscv: decrease modify_privilege function nesting level
Restructured modify_privilege function to decrease nesting level

Signed-off-by: Farid Khaydari <f.khaydari@syntacore.com>
2024-11-21 00:04:15 +03:00
Parshintsev Anatoly ba8c1eef5a target/riscv: allow hexadecimal values to expose_csr-like commands
hexadecimal values are often used in the documentation. Forcing user to
convert CSRs addresses to decimal is unnecessary.
2024-11-19 22:28:57 +03:00
Evgeniy Naydanov f51900b4a2
Merge pull request #1165 from aap-sc/aap-sc/resume_debug_errors
target/riscv: detailed error messages for cases when resume operation fails
2024-11-18 13:17:25 +03:00
Evgeniy Naydanov 463d1b0866
Merge pull request #1157 from zqb-all/support-disable-auto-fence
target/riscv: support disable auto fence
2024-11-18 13:16:54 +03:00
Evgeniy Naydanov c53f9319c8
Merge pull request #1163 from en-sc/en-sc/from_upstream
Merge up to fd62626dff from  upstream
2024-11-18 13:16:18 +03:00
Jan Matyas d4a64e3f38 autoconf: Add support for code coverage
Add support for code coverage collection. This helps
developers to check if their test scenarios really exercised
all the OpenOCD functionality that they intended to test.

- Option --enable-gcov has been added to configure.ac
  which enables the coverage collection using Gcov. (Disabled
  by default.)

- The steps to collect and inspect the coverage have been
  described in HACKING file.

Change-Id: I259e401937a255e7ad7f155359a0b7787e4d0752
Signed-off-by: Jan Matyas <jan.matyas@codasip.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8521
Tested-by: jenkins
Reviewed-by: Evgeniy Naydanov <evgeniy.naydanov@syntacore.com>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-11-16 14:18:57 +00:00
Evgeniy Naydanov a2f5da3289
Merge pull request #1161 from en-sc/en-sc/deassert-reset
target/riscv: avoid updating `target` if `ackhavereset` fails
2024-11-14 13:23:42 +03:00
Parshintsev Anatoly faffae0493 target/riscv: detailed error messages for cases when resume operation fails
This change aims to provide more context in case if resume operation
fails. Before the change messages were quite confusing.
2024-11-14 12:23:47 +03:00
Evgeniy Naydanov f7ea8245e6
Merge pull request #1160 from zqb-all/reduce-log
[NFC] target/riscv: remove LOG_ERROR when COMMAND check ARGC fail
2024-11-12 17:45:57 +03:00
Evgeniy Naydanov cabb6000df Merge up to fd62626dff from upstream
Conflicts are related to `unsigned`->`unisgned int` cleanup:
* `src/jtag/drivers/ftdi.c` -- between
  6749c70a3a and
  a64dc23bf1.
* `src/rtos/hwthread.c` -- between
  ef3e61bebc and
  436e6f1770.
* `src/target/target.c` and `.h` -- between
  53ec10b61d and
  e72733d590.
* `src/target/riscv/*` -- due to
  957eb741a0 and
  fec3b22421.
  Resolved by:
    * Changing the return type of `riscv_batch_get_dmi_read_op()` to
      `uint32_t`.
    * Using RISC-V OpenOCD's version in other cases.

Change-Id: Ia6e2129c6fddb1dec26adcd936506af2539412ef
2024-11-12 17:25:33 +03:00
Evgeniy Naydanov fd62626dff target/breakpoints: fix types in `watchpoint_add_internal()`
There was a conflict:
1. commit 2cd8ebf44d ("breakpoints: use 64-bit type for watchpoint mask
   and value")
2. commit 0bf3373e80 ("target/breakpoints: Use 'unsigned int' for
   length")

The second commit was created erlier, but merged later so the types of
`mask` and `value` became `uint32_t` in `watchpoint_add_internal()`.

This created a bug:
`WATCHPOINT_IGNORE_DATA_VALUE_MASK` is defined as `(~(uint64_t)0)`.
Truncation to uint32_t makes it so the comparisons with the constant
don't work.

Change-Id: I19c414c351f52aff72a60330d83c29db7bbca375
Signed-off-by: Evgeniy Naydanov <evgeniy.naydanov@syntacore.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8500
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: Jan Matyas <jan.matyas@codasip.com>
Tested-by: jenkins
Reviewed-by: zapb <dev@zapb.de>
Reviewed-by: Karl Palsson <karlp@tweak.au>
2024-11-11 17:33:56 +00:00
zhusonghe 215ecdaedf target/riscv:Perform single step before resume if necessary
Two cases where single step is needed before resume:
1. ebreak used in software breakpoint;
2. a trigger that is taken just before the instruction
   that triggered it is retired.

Signed-off-by: Songhe Zhu <zhusonghe@eswincomputing.com> Co-developed-by: Fei Gao <gaofei@eswincomputing.com> Co-developed-by: xiatianyi <xiatianyi@eswincomputing.com>
2024-11-11 15:31:49 +08:00
Evgeniy Naydanov 784687d781 target/riscv: avoid updating `target` if `ackhavereset` fails
`target`'s `state` and `debug_reason` should not be updated in
`deassert_reset` if sending reset acknowledgment fails.

Change-Id: I86136fe829e7a7c6b69f718f0cf32322e40341b0
Signed-off-by: Evgeniy Naydanov <evgeniy.naydanov@syntacore.com>
2024-11-08 16:36:25 +03:00
Mark Zhuang e024f112e3 [NFC] target/riscv: remove LOG_ERROR when COMMAND check ARGC fail
Per current OpenOCD conventions, LOG_ERROR should not be printed
when ERROR_COMMAND_SYNTAX_ERROR is returned. OpenOCD will print
the command syntax to the user on its own.
2024-11-06 19:32:20 +08:00
Mark Zhuang 340e38a9ed target/riscv: support disable auto fence
Support disable automatic fence, it's useful for
debug some cache related issue.
2024-11-06 17:15:57 +08:00