-
Notifications
You must be signed in to change notification settings - Fork 100
Hart enumeration algorithm (Sec 3.3) is impractical and conflicts with hart state definitions (Sec 3.4) #1176
Description
I would like to propose a discussion on the hart enumeration algorithm in Section 3.3 "Selecting Harts". The current mandatory (must) algorithm appears to be impractical and based on a premise that conflicts with other parts of the specification.
The specification currently requires debuggers to stop scanning for harts as soon as they find one that is nonexistent:
"...a debugger must ... selects each hart starting from 0 until either
anynonexistentindmstatusis 1, or the highest index... is reached."
This requirement creates several significant problems:
1. The Algorithm Conflicts with Real-World Practice
This algorithm assumes the debugger has zero knowledge of the target. In reality, debuggers (or their users) almost always know the target's configuration (i.e., NUM_HARTS) beforehand. This information is typically provided via a debugger configuration script (e.g., an OpenOCD .cfg file). A mandatory scan is unnecessary when the hart count is already known.
2. Redundancy with confstrptr
The confstrptr mechanism (Section 3.14.9) is provided for configuration discovery. If this is available, the "scan-until-nonexistent" algorithm is completely redundant.
3. Contradictory Definitions for "Holes" (Section 3.4)
The definitions in Section 3.4 "Hart DM States" are contradictory regarding permanently disabled harts ("holes"):
nonexistentis defined as "if they will never be part of this hardware platform". This perfectly describes a "hole".- However, the spec also states that "holes... must show up as unavailable".
- This forces implementations to use the semantically incorrect
unavailablestatus (which implies the hart "might... become available") for something that is trulynonexistent.
4. The Algorithm Prevents Flexible Implementations
Because of the mandatory "Stop-at-Nonexistent" rule, implementations cannot use the more logical nonexistent status for "holes". If an implementation did report a "hole" (e.g., hart 2) as nonexistent, a spec-compliant debugger would incorrectly stop its scan and fail to find existing harts at higher indices (e.g., hart 3).
Proposal:
The specification should be updated to align with real-world use and logical definitions.
- Allow
nonexistentHarts as "Holes": Implementations should be allowed to have existing harts at indices above anonexistenthart. - Change the Enumeration Algorithm (Section 3.3):
- Remove the "Stop-at-Nonexistent" Rule. The algorithm should not require debuggers to stop at the first
nonexistenthart. - The primary method for enumeration should be reading
confstrptr(Sec 3.14.9) or using user-provided configuration (which is the common case). - The full scan (up to the maximum
HARTSELLEN) should be only a fallback, andnonexistentshould not halt it.
- Remove the "Stop-at-Nonexistent" Rule. The algorithm should not require debuggers to stop at the first
- Clarify Definitions (Section 3.4):
nonexistentshould be defined as any hart that is permanently disabled (including "holes").unavailableshould be defined only as any hart that might genuinely become available later (e.g., powered down, in reset).
This approach provides a more logical definition of hart states, aligns with realistic debugging practices, and gives implementers the flexibility needed for modern hardware (like binned devices).