- Change Log
- Copyright and license information
- Contributors
- 1. Introduction
- 2. Trace Protocols and Trace Control
- 3. Trace System Overview
- 4. Trace Control Interface Overview
- 5. Versioning of Components
- 6. Trace Encoder Control Interface
- 7. Trace RAM Sink
- 8. Trace Funnel
- 9. Trace PIB Sink
- 10. Trace ATB Bridge
- 11. Additional Material
Warning
|
This document is in the Frozen state
Change is extremely unlikely. A high threshold will be used, and a change will only occur because of some truly critical issue being identified during the public review cycle. Any other desired or needed changes can be the subject of a follow-on new extension. |
This specification is licensed under the Creative Commons Attribution 4.0 International License (CC-BY 4.0). The full license text is available at creativecommons.org/licenses/by/4.0/
Copyright 2019-2024 by RISC-V International.
Key contributors to RISC-V Trace Control Interface specification in alphabetical order:
Bruce Ableidinger (SiFive) ⇒ Initial SiFive donation, reviews
Robert Chyla (IAR, SiFive, MIPS) ⇒ Most topics, editing, publishing
Ernie Edgar (SiFive) ⇒ Initial SiFive donation, reviews
Jay Gamoneda (NXP) ⇒ Reviews, editing and updating after ARC review
Markus Goehrle (Lauterbach) ⇒ Reviews, updates
Iain Robertson (UltraSoC, Siemens) ⇒ E-Trace compatibility, filtering chapter, reviews
Ved Shanbhogue (Rivos) ⇒ Detailed Architecture Review Committee notes
Nino Vidovic (Segger) ⇒ Reviews
This document presents a standardized control interface for RISC-V trace infrastructure (such as trace encoders, trace funnels, trace sinks, …) for the Efficient Trace for RISC-V Version 2.0 Specification and for the RISC-V N-Trace (Nexus-based Trace) Specification Version 1.0.0. Standardized control interface allows trace control software development tools to be used interchangeably with any RISC-V device implementing processor and/or data trace.
Instruction Trace is a system that collects a history of processor execution, along with other events. The trace system may be set up and controlled using a register-based interface. Hart execution activity appears on the Ingress Port and feeds into a Trace Encoder where it is compressed and formatted into trace messages. The Trace Encoder transmits trace messages to a Trace Sink. In multi-core systems, each hart has its own Trace Encoder, and typically all will connect to a Trace Funnel that aggregates the trace data from multiple sources and sends the data to a single destination.
This specification does not define the hardware interconnection between the hart and Trace Encoder, as this is defined in the Efficient Trace for RISC-V Specification Version 2.0. This document also does not define the hardware interconnection between the Trace Encoder and Trace Funnel, or between the Trace Encoder/Funnel and Trace Sink.
This specification allows a wide range of implementations including low-gate-count minimal instruction trace and systems with only instrumentation trace. Implementation choices include whether to support instruction trace, data trace, instrumentation trace, timestamps, external triggers, various trace sink types, and various optimization tradeoffs between gate count, features, and bandwidth requirements.
Trace Encoder (TE for short) - Hardware module that accepts execution information from a hart and generates a stream of trace messages/packets.
Trace Message/Packet - Depending on protocol different names can be used, but it means the same. It is considered as a continuous sequence of (usually bytes) describing program and/or data flow and other events.
Trace Funnel - Hardware module that combines trace streams from multiple trace sources (Trace Encoders and/or other Trace Funnels) into a single output stream of trace messages/packets.
Trace Sink - Hardware module that accepts a stream of trace messages/packets and records them into the memory or forwards them onward in some format.
Trace Decoder - Software program that takes a recorded trace (from a Trace Sink) and produces a readable execution history.
RO - Denotes read-only bit/field - it does not mean it will return the same value each time when read.
RW - Denotes read-write bit/field - value being read may not be the same as what was written as some fields may change their values because of other reasons.
RW1C - Denotes bit/field, which can be read but you must write 1 to clear it (writing 0 will be ignored). It is used for sticky status bits to assure that these are cleared by deliberate action (write 1).
WARL - Denotes Write any, read legal bit/field/register. If a non-legal value is written, the written value is converted to a value that is supported. That value should deterministically depend on the illegal written value and the architectural state of the trace sub-system.
W1 - Denotes write-only bit, which performs an action when 1 is written to it.
SD - Reset value of a field/register is system dependent - these fields should always have the same values at trace component reset. In many cases this may be the only value supported.
Undef - This field/register may not reset. Trace tool must write correct value before enabling the trace component.
ATB - Advanced Trace Bus, a protocol described in ARM document AMBA ATB Protocol Specification. This is one of alternative methods to send the trace (in addition to native Trace Sinks defined in this specification).
PIB - Pin Interface Block, a parallel or serial off-chip trace port feeding into a trace probe.
?? - Used in names refer to identical fields/registers in different components. For example tr??Active
may mean trTeActive
or trTsActive
.
There are two standard RISC-V trace protocols which will utilize this RISC-V Trace Control Interface:
-
RISC-V N-Trace (Nexus-based Trace) Specification
-
Version 1.0 to be ratified together with this specification.
-
-
Efficient Trace for RISC-V Specification
-
Version 2.0 (ratified May 5-th 2022).
-
This specification together with details provided in any of above documents should be considered as a complete guideline for any standard RISC-V trace implementation.
Trace is controlled by set of 32-bit memory-mapped registers.
Not all trace protocols and components must support all registers, bits, fields and options. This document includes a chapter Minimal Implementation which describes the smallest possible set of registers and fields, but each message protocol supported by this standard must clarify the exact meaning of supported registers/fields and bits as some of them define.
This section briefly describes features of the Trace Encoder and other trace components as background for understanding some of the control interface register fields.
By monitoring the Ingress Port, the Trace Encoder determines when a program flow discontinuity has occurred and whether the discontinuity is inferable or non-inferable. An inferable discontinuity is one for which the Trace Decoder can statically determine the destination, such as a direct branch instruction in which the destination or offset is included in the opcode. Non-inferable discontinuities include all other types such as interrupts, exceptions, and indirect jump instructions.
Branch Trace Messaging is the simplest, baseline form of instruction trace. Each program counter discontinuity results in one trace message, either a Direct or Indirect Branch Message. Linear instructions (or sequences of linear instructions) do not directly generate any trace messages/packets but overflow of counters (or exceptions) may generate corresponding packets/messages - these messages are infrequent and will not affect trace compression.
Indirect Branch Messages normally contain a compressed address to reduce bandwidth. The Trace Encoder emits a Branch With Sync Message containing the complete instruction address under certain conditions. This message type is a variant of the Direct or Indirect Branch Message and includes a full address and a field indicating the reason for the Sync.
Both the Efficient Trace for RISC-V (E-Trace) Specification and the RISC-V N-Trace (Nexus-based Trace) specification define systems of messages intended to improve compression by reporting only whether conditional branches are taken by encoding each branch outcome in a single taken/not-taken bit. The destinations of non-inferable jumps and calls are reported as compressed addresses. Much better optimized compression can be achieved, but an encoder implementation will typically require more hardware.
Several other optimizations are possible to improve trace compression. These are optional for any Trace Encoder and there should be a way to disable optimizations in case the trace system is used with code that does not follow recommended API rules. Examples of optimizations are a Return-address stack, Branch repetition, Statically inferable jump, and Branch prediction.
The Trace Encoder transmits completed messages to a Trace Sink. This specification defines a number of different sink types, all optional, and allows an implementation to define other sink types. A Trace Encoder must have at least one sink or funnel attached to it.
Note
|
Trace messages/packets are sequences of bytes. In case of wider sink width, some padding/idle bytes (or additional formatting) may be added by the sink. N-Trace format allows any number of idle bytes between messages. |
The Trace Encoder packs trace messages into fixed-width trace words (usually bytes). These are then stored in a dedicated RAM, typically located on-chip, in a circular-buffer fashion. When the RAM has filled, it may optionally be stopped, or it may wrap and overwrite earlier trace data.
The Trace Encoder packs trace messages into fixed-width trace words (usually bytes). These are then stored in a range of system memory reserved for trace using a DMA-type bus controller in a circular-buffer fashion. When the memory range has been filled, it may optionally be stopped, or it may wrap and overwrite earlier trace data. This type of sink may also be used to transmit trace off-chip through, for example, a PCIe or USB port.
The ATB Bridge allows sending RISC-V trace to Arm CoreSight infrastructure (instead of RISC-V compliant sink defined in this document) as an ATB initiator. ATB Bridge is not needed for RISC-V only systems.
ATB width is byte aligned (8, 16, 32, 64, 128) which allows transport of trace messages/packets defined as sequence of bytes.
The Trace Encoder may send trace messages to a Trace Funnel. The Funnel aggregates the trace from each of its inputs (either RISC-V Trace Encoder or another Trace Funnel) and sends the combined trace stream to its designated Trace Sink or ATB Bridge, which is one or more of the sink types above.
Note
|
It is assumed that each input to the funnel (Trace Encoder or another Trace Funnel) has a unique message source ID defined (trTeSrcID field in the trTeControl register).
|
The Trace Control interface consists of a set of 32-bit registers. The control interface can be used to set up and control a trace session, retrieve collected trace, and control any trace system components.
Each Trace Component is controlled by a set of 32-bit registers occupying up to 4KB of an address space. Base address of each trace component must be aligned on the 4KB boundary.
Each hart being traced must have its own separate Trace Encoder control component. A system with multiple harts must allow generating messages with a field indicating which hart is responsible for that message.
This specification defines the following trace components (N in at the end of symbol name denotes 0-based index of the component)
Component Name | Component Type (value=symbol) | Base Address (symbol #N) |
---|---|---|
Trace Encoder |
0x1=TRCOMP_ENCODER |
trBaseEncoderN |
Trace Funnel |
0x8=TRCOMP_FUNNEL |
trBaseFunnelN |
Trace RAM Sink |
0x9=TRCOMP_RAMSINK |
trBaseRamSinkN |
Trace PIB Sink |
0xA=TRCOMP_PIBSINK |
trBasePibSinkN |
Trace ATB Bridge |
0xE=TRCOMP_ATBBRIDGE |
trBaseAtbBridgeN |
Note
|
This specification does NOT address the discovery of base addresses of trace components. These base addresses (symbols in above table) must be specified as part of trace tool configuration. Connections between different trace components must be also defined. Future versions of this specification may allow a single base address to be sufficient to access and discover all trace components in the system. |
Different components must be connected via internal busses and/or FIFO buffers. This specification does not define this interconnect logic, but the following rules must be followed:
-
Each component sending a trace message/packet must assure the entire packet can be accepted by the destination component (or pushed into the FIFO buffer).
-
Sending a partial packet is NEVER allowed as it will not be possible to process and decode such a trace.
-
-
If a component cannot send an entire message/packet it must wait until it is possible to do so.
-
Tracing is typically required to be non-intrusive, and if the Trace Encoder cannot keep up with the hart it should drop the packet and wait for the receiver to be ready.
-
Once trace is allowed to resume it must issue an instruction trace synchronization message/packet so the decoder will be aware that some (unknown) amount of trace has been lost.
-
It is advisable to drain the trace pipeline to some hysteresis level before resuming - otherwise a lot of short chunks of trace may be produced.
-
-
Optionally the Trace Encoder may be configured to stall the hart to avoid trace data loss.
-
To prevent trace overflows the following techniques can be used:
-
Add a FIFO capable of holding several trace messages/packets to mitigate bursts of trace data.
-
Use wider internal busses to provide more bandwidth.
-
Make sure funnels and sinks provide the same or more bandwidth than encoders.
-
Use triggers to create trace windows/ranges to limit amount of trace data - especially in multi-core configurations.
-
Input | Output | Description |
---|---|---|
Ingress Port |
Trace Encoder |
Ingress Port (from hart) providing raw trace to be encoded |
Trace Encoder |
Trace RAM Sink |
Single hart tracing to RAM buffer |
Trace Encoder |
Trace PIB Sink |
Single hart tracing via pins |
Trace Encoder |
Trace ATB Bridge |
Single hart tracing to Arm ATB infrastructure |
Trace Encoder |
Trace Funnel |
Sending trace from single hart to Trace Funnel (to be combined from other RISC-V trace) |
Trace Funnel |
Trace Funnel |
Sending combined trace from multiple harts to higher level Trace Funnel (to be combined from other RISC-V trace) |
Trace Funnel |
Trace RAM Sink |
Sending combined trace from multiple harts to RAM buffer |
Trace Funnel |
Trace PIB Sink |
Sending combined trace from multiple harts via pins |
Trace Funnel |
Trace ATB Bridge |
Sending combined trace from multiple harts to Arm ATB infrastructure |
Trace ATB Bridge |
Arm ATB bus |
Sending trace to ATB (to combine RISC-V trace with other Arm components on the system) |
Note
|
Sending RISC-V trace to Arm CoreSight infrastructure is allowed (via ATB Bridge), but this specification does not specify how to transport trace data from other Arm CoreSight components in the system using RISC-V Trace sub-system. One of possible ways of doing so would be to create a custom trace component, configure it to encapsulate it as custom N-Trace trace messages and connect it as input to one of trace funnels. |
+----------------+ | Single Hart | | +----------+ +---------+ +------------+ | | Trace | | Trace | | Trace Sink | | | Ingress =====>| Encoder |---->| or | | | Port | | | | ATB Bridge | | +----------+ +---------+ +------------+ | | +----------------+
+-----------+ +---------+ | Hart with | | Trace | | Ingress |==>| Encoder |---+ | Port | | | | +-----------+ +---------+ | | +-----------+ +---------+ | +--------+ +-------------+ | Hart with | | Trace | +-->| Trace | | Trace Sink | | Ingress |==>| Encoder |------>| Funnel |---->| or | | Port | | | +-->| | | ATB Bridge | +-----------+ +---------+ | +--------+ +-------------+ | +-----------+ +---------+ | | Hart with | | Trace | | | Ingress |==>| Encoder |---+ | Port | | | +-----------+ +---------+
+-------------------------+ | 3 Harts with 3 Encoders | | and local Funnel |---+ | (see above) | | +-------------------------+ | | +--------+ +-------------+ +-->| Trace | | Trace Sink | | Funnel |---->| or | +-->| (top) | | ATB Bridge | | +--------+ +-------------+ +-------------------------+ | | 3 Harts with 3 Encoders | | | and local Funnel |---+ | (see above) | +-------------------------+
+-------------------------+ | 3 Harts with 3 Encoders | | and local Funnel |---+ | (see above) | | +-------------------------+ | | +-----------+ +---------+ | +--------+ +-------------+ | Hart #4 | | Trace | +-->| Trace | | Trace Sink | | |==>| Encoder |------>| Funnel |---->| or | | | | #4 |---+ | (top) | | ATB Bridge | +-----------+ +---------+ | +--------+ +-------------+ | v +----------------+ | Trace RAM Sink | | (in SRAM mode) | +----------------+
Note
|
Trace data from Trace Encoder #4 may be combined with trace from other 3 Trace Encoders. But it may be also sent to dedicated Trace RAM Sink - in such a case corresponding input to Trace Funnel (top) should be disabled. |
For the access method to the trace control registers, it makes a difference whether these registers shall be accessed by an external debug/trace tool, or by an internal debugger running on the chip.
Trace control register access by an external debugger (this is the most common use case):
-
External debuggers must be able to access all trace control registers independent of whether the traced harts are running or halted. That is why for external debuggers, the recommended access method for memory-mapped control registers is memory accesses through the RISC-V debug module using SBA (System Bus Access) as defined in the RISC-V Debug Specification.
Trace control register access by an internal debugger:
-
Through loads and stores performed by one or more harts in the system. Mapping the control interface into physical memory accessible from a hart allows that hart to manage a trace session independently from an external debugger. A hart may act as an internal debugger or may act in cooperation with an external debugger. Two possible use models are collecting crash information in the field and modifying trace collection parameters during execution. If a system has physical memory protection (PMP), a range can be configured to restrict access to the trace system from hart(s).
Note
|
Additional control path(s) may also be implemented, such as extra JTAG registers or devices, a dedicated DMI debug bus or message-passing network. Such an access (which is NOT based on System Bus) may require custom implementation by trace probe vendors as this specification only mandates probe vendors to provide access via SBA commands. |
Each block of 32-bit registers (for each component) has the following layout:
Address Offset | Register Name | Compliance | Description |
---|---|---|---|
0x000 |
tr??Control |
Required |
Main control register for this trace component |
0x004 |
tr??Impl |
Required |
Trace Implementation information for this trace component |
0x008 - 0x00F |
extra controls |
Optional |
Extra controls for this trace component (named differently) |
0x010 - 0xDFF |
— |
Optional |
Additional registers (specific for the type of a component). All not used registers are reserved and should read as 0 and ignore writes. |
0xE00 - 0xFFF |
— |
Optional |
Registers reserved for implementation/vendor specific details. May allow identification of components on a system bus. |
Warning
|
Each component has a tr??Active bit in the tr??Control register. Accesses to other registers are unspecified when the tr??Active bit is 0.
|
Each trace component has a tr??Impl
register (at address offset 0x4) allowing trace component version and trace component type to be identified. This register allows debug tools to confirm the component type and potentially adjust tool behavior by looking at component versions.
Note
|
Each component may have a different version. Initial version of this specification defines all components to specify component version as 1.0 (major=1, minor=0). |
Registers in the 4KB range that are not implemented are reserved and read as 0 and ignore writes.
Most trace control registers are optional. Some WARL fields may be hard coded to any value (including 0). It allows different implementations to provide different functionality.
Both N-Trace and E-Trace encoders are controlled by the same set of bits/fields in the same trTe???
registers - as almost every register, field, bit is optional this provides good flexibility in implementation.
All other trace components are shared between different trace encoders (N-Trace and E-Trace).
Address Offset | Register Name | Compliance | Description |
---|---|---|---|
0x000 |
trTeControl |
Required |
Trace Encoder control register |
0x004 |
trTeImpl |
Required |
Trace Encoder implementation information |
0x008 |
trTeInstFeatures |
Optional |
Extra instruction trace encoder features and trace source IDs |
0x00C |
trTeInstFilters |
Optional |
Mask of filters to qualify an instruction trace |
Data trace control (trTeData??) |
|||
0x010 |
trTeDataControl |
Optional |
Data trace control and features |
0x014 - 0x018 |
— |
Reserved |
Reserved for data trace related future standard extension |
0x01C |
trTeDataFilters |
Optional |
Mask of filters to qualify data trace |
Reserved |
|||
0x020 - 0x03F |
— |
Reserved |
Reserved for future standard extension |
Timestamp control (trTs??) |
|||
0x040 |
trTsControl |
Optional |
Timestamp control register |
0x044 |
— |
Reserved |
Reserved for future timestamp related standard extension |
0x048 |
trTsCounterLow |
Optional |
Lower 32 bits of timestamp counter |
0x04C |
trTsCounterHigh |
Optional |
Upper bits of timestamp counter |
Trigger control (trTeTrig??) |
|||
0x050 |
trTeTrigDbgControl |
Optional |
Debug Triggers control register |
0x054 |
trTeTrigExtInControl |
Optional |
External Triggers Input control register |
0x058 |
trTeTrigExtOutControl |
Optional |
External Triggers Output control register |
Reserved |
|||
0x060 - 0x3FF |
— |
Reserved |
Reserved for future standard extension |
Filters & comparators (trTeFilter??, trTeComp??) |
|||
0x400 - 0x5FF |
trTeFilter?? |
Optional |
Trace Encoder Filter Registers |
0x600 - 0x7FF |
trTeComp?? |
Optional |
Trace Encoder Comparator Registers |
Address Offset | Register Name | Compliance | Description |
---|---|---|---|
0x000 |
trRamControl |
Required |
RAM Sink control register |
0x004 |
trRamImpl |
Required |
RAM Sink Implementation information |
0x008 - 0x00F |
— |
Reserved |
Reserved for more control registers |
0x010 |
trRamStartLow |
Required |
Lower 32 bits of start address of circular trace buffer |
0x014 |
trRamStartHigh |
Optional |
Upper bits of start address of circular trace buffer |
0x018 |
trRamLimitLow |
Required |
Lower 32 bits of end address of circular trace buffer |
0x01C |
trRamLimitHigh |
Optional |
Upper bits of end address of circular trace buffer |
0x020 |
trRamWPLow |
Required |
Lower 32 bits of current write location for trace data in circular buffer |
0x024 |
trRamWPHigh |
Optional |
Upper bits of current write location for trace data in circular buffer |
0x028 |
trRamRPLow |
Optional |
Lower 32 bits of access pointer for trace readback |
0x02C |
trRamRPHigh |
Optional |
Upper bits of access pointer for trace readback |
0x030 - 0x03F |
— |
Reserved |
Reserved for more control registers |
0x040 |
trRamData |
Optional |
Read/write access to SRAM trace memory (32-bit data) |
Address Offset | Register Name | Compliance | Description |
---|---|---|---|
0x000 |
trPibControl |
Required |
Trace PIB Sink control register |
0x004 |
trPibImpl |
Required |
Trace PIB Sink Implementation information |
Address Offset | Register Name | Compliance | Description |
---|---|---|---|
0x000 |
trFunnelControl |
Required |
Trace Funnel control register |
0x004 |
trFunnelImpl |
Required |
Trace Funnel Implementation information |
0x008 |
trFunnelDisInput |
Optional |
Disable individual funnel inputs |
0x00C - 0x03F |
— |
Reserved |
Reserved for more control registers |
Timestamp control (trTs??) |
|||
0x040 |
trTsControl |
Optional |
Timestamp control register |
0x044 |
— |
Reserved |
Reserved for extra timestamp control |
0x048 |
trTsCounterLow |
Optional |
Lower 32 bits of timestamp counter |
0x04C |
trTsCounterHigh |
Optional |
Upper bits of timestamp counter |
Note
|
Funnels may optionally be a source of timestamp and/or forward timestamp to Trace Encoders in the system. This way several Trace Encoders may share timestamp and trace from several harts may be time-correlated. |
Each component has a tr??Impl
register, which includes two 4-bit tr??VerMinor
and tr??VerMajor
fields. These fields are guaranteed to be present in all future revisions of a standard, so trace tools will be able to discover a component version and act accordingly.
-
Value 0 as
tr??VerMajor
is NOT allowed (due to compatibility reasons). -
Different components may report different versions (as some components may be updated more often than others).
-
The major version
tr??VerMajor
field is incremented when the modification breaks backward compatibility. -
The minor version
tr??VerMinor
field is incremented when the modification maintains backward compatibility (for example adding a new field) - for that reason software should always write 0 to reserved bits in registers. -
Version 15.x is reserved for non-compatible version encoding.
-
Version n.15 should be used as experimental (in development) implementation.
Software tools must report the version number as two decimal numbers major.minor - initial version of this specification is defined as 1.0.
Note
|
Trace software should handle versions as follows (let’s assume hypothetical version 2.3 was defined as current version in moment of release of trace software)
Displayed messages should report component name, component base address and current and supported version numbers. It is suggested to display the full hexadecimal value of |
Many features of the Trace Encoder (TE for short) are optional. In most cases, optional features are enabled using a WARL (write any, read legal) register field. A debugger can determine if optional feature is present by writing to the register field and reading back the result.
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
0 |
trTeActive |
Primary activate/reset bit for the TE. When 0, the TE may have clocks gated off or be powered down, and other register locations may be inaccessible. Hardware may take an arbitrarily long time to process power-up and power-down and will indicate completion when the read value of this bit matches what was written. See Reset and Discovery chapter for more details. |
RW |
0 |
1 |
trTeEnable |
1: Trace Encoder is enabled. Allows |
RW |
0 |
2 |
trTeInstTracing |
1: Instruction trace is being generated. Written from a trace tool (after a write to |
RW |
|
3 |
trTeEmpty |
Reads as 1 when all generated trace have been emitted. |
RO |
1 |
6:4 |
trTeInstMode |
Instruction trace generation mode |
WARL |
|
8:7 |
— |
Reserved |
— |
0 |
9 |
trTeContext |
Enable sending trace messages/fields with scontext/mcontext values and/or privilege levels. |
WARL |
|
10 |
— |
Reserved |
— |
0 |
11 |
trTeInstTrigEnable |
1: Allows |
WARL |
|
12 |
trTeInstStallOrOverflow |
Set to 1 by hardware when trace buffer overflow (also known as trace lost) occurs, or when the TE requests a hart stall. Clears to 0 at TE reset or when the trace is enabled ( |
RW1C |
|
13 |
trTeInstStallEna |
0: If TE cannot send a message, the message is dropped. The protocol dependent overflow instruction trace synchronization message/packet is generated when the trace is restarted, so the decoder will know that trace is lost and must reset any internal decoder state. |
WARL |
|
14 |
— |
Reserved |
— |
0 |
15 |
trTeInhibitSrc |
0: Messages/packets generated by the trace encoder include a message source field if the
source width held in |
WARL |
|
17:16 |
trTeInstSyncMode |
Select the periodic instruction trace synchronization message/packet generation mechanism. At least one non-zero mechanism must be implemented. |
WARL |
|
19:18 |
— |
Reserved |
— |
0 |
23:20 |
trTeInstSyncMax |
The maximum interval (in units determined by |
WARL |
|
26:24 |
trTeFormat |
Trace recording/protocol format: |
WARL |
|
31:27 |
— |
Reserved |
— |
0 |
Note
|
Writing to this register while trace is enabled may unintentionally change a value of trTeInstTracing bit because that bit may dynamically change by triggers.
|
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
3:0 |
trTeVerMajor |
Trace Encoder Component Major Version. Value 1 means the component is compliant with this document. Value 0 means pre-ratified/initial version - see 'Pre-ratified/Initial Interface Version' chapter at the end. |
RO |
1 |
7:4 |
trTeVerMinor |
Trace Encoder Component Minor Version. Value 0 means the component is compliant with this document. |
RO |
0 |
11:8 |
trTeCompType |
Trace Encoder Component Type (Trace Encoder) |
RO |
0x1 |
15:12 |
— |
Reserved for future versions of this standard |
— |
0 |
19:16 |
trTeProtocolMajor |
Trace Protocol Major Version. As specified by specification governing |
RO |
|
23:20 |
trTeProtocolMinor |
Trace Protocol Minor Version. As specified by specification governing |
RO |
|
31:24 |
— |
Reserved for vendor specific implementation details |
— |
Note
|
trTeProtocol?? fields are separated from trTeVer?? as we may have the same control interface, but protocol itself may be extended with new packets/ messages/ fields.
|
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
0 |
trTeInstNoAddrDiff |
When set, trace messages/packets always carry a full address. |
WARL |
|
1 |
trTeInstNoTrapAddr |
When set, do not include trap handler address in trap messages/packets. |
WARL |
|
2 |
trTeInstEnSequentialJump |
When set, treat sequentially inferrable jumps as inferable PC discontinuities. |
WARL |
|
3 |
trTeInstEnImplicitReturn |
When set, treat returns as inferable PC discontinuities when returning from a recent call on a stack. Field |
WARL |
|
4 |
trTeInstEnBranchPrediction |
When set, Branch Predictor based compression is enabled. |
WARL |
|
5 |
trTeInstEnJumpTargetCache |
When set, Jump Target Cache based compression is enabled. |
WARL |
|
7:6 |
trTeInstImplicitReturnMode |
Defines how the decoder is handling stack of return addresses (if enabled by |
WARL |
|
8 |
trTeInstEnRepeatedHistory |
Enable repeated branch history/map detection when set. |
WARL |
|
9 |
trTeInstEnAllJumps |
Enable emitting of trace message or add history/map bit for direct unconditional/inferable control flow changes (jumps or calls). Normally these instructions do not generate any trace as the decoder can determine the next instruction. Trace will not compress well but timestamp accuracy will be better - may be used when profiling loops. |
WARL |
|
10 |
trTeInstExtendAddrMSB |
When set, allow extended handing of MSB address bits. Encoding details are trace protocol dependent. |
WARL |
|
15:11 |
— |
Reserved for additional instruction trace control/status bits |
— |
0 |
27:16 |
trTeSrcID |
Trace source ID assigned to this trace encoder. If |
WARL |
|
31:28 |
trTeSrcBits |
The number of bits in the trace source field (0..12), unless disabled by |
WARL |
Note
|
Applicability of different trTeInst?? fields for each trace encoding protocol is described in a document which defines the protocol (and not all fields are applicable to all protocols).
|
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
15:0 |
trTeInstFilters |
Determine which filters defined in Trace Encoder Filter Registers chapter qualify an instruction trace. If bit n is a 1 then instructions will be traced when filter n matches. If all bits are 0, all instructions are traced. |
WARL |
|
31:16 |
— |
Reserved |
— |
0 |
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
0 |
trTeDataImplemented |
Read as 1 if data trace is implemented. |
RO |
|
1 |
trTeDataTracing |
1: Data trace is being generated. Written from a trace tool or controlled by triggers. When |
WARL |
|
2 |
trTeDataTrigEnable |
Global enable/disable for data trace triggers |
WARL |
|
3 |
trTeDataStallOrOverflow |
Set to 1 by hardware when data trace causes trace buffer overflow, or when the TE requests a hart stall due to data trace. Clears to 0 at TE reset or when the trace is enabled ( |
RW1C |
|
4 |
trTeDataStallEna |
0: If TE cannot send data trace messages, an overflow message is generated when the trace is restarted. |
WARL |
|
5 |
trTeDataDrop |
Written to 1 by hardware when the data trace packet was dropped (if enabled). Clears to 0 at TE reset or when the trace is enabled ( |
RW1C |
|
6 |
trTeDataDropEna |
1: Allow temporary suppression of data trace (at some watermark level) to prevent trace overflow or stall. This way instruction trace will have higher priority. |
WARL |
|
15:7 |
— |
Reserved for additional data trace control/status bits. |
— |
0 |
16 |
trTeDataNoValue |
When set, omit data values from data trace packets. |
WARL |
|
17 |
trTeDataNoAddr |
When set, omit data address from data trace packets. |
WARL |
|
19:18 |
trTeDataAddrCompress |
Data trace address compression selection: |
WARL |
|
31:20 |
— |
Reserved |
— |
0 |
Note
|
Writing to this register while trace is enabled may unintentionally change a value of trTeDataTracing bit because that bit may dynamically change by triggers.
|
Note
|
Applicability of different trTeData?? fields for each trace encoding protocol is described in a document which defines the protocol (and not all fields are applicable to all protocols).
|
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
15:0 |
trTeDataFilters |
Determine which filters defined in Trace Encoder Filter Registers chapter qualify data trace. If bit n is a 1 then data accessed will be traced when filter n matches. If all bits are 0, all data accesses are traced. |
WARL |
|
31:16 |
— |
Reserved |
— |
0 |
Timestamp Unit is an optional sub-component present in either Trace Encoder or Trace Funnel. An implementation may choose from several modes of timestamps:
-
Internal System - fixed clock in a system (such as bus clock) is used to increment the timestamp counter (for both Trace Encoders and Trace Funnels)
-
Internal Core - core clock is used to increment the timestamp counter (only for Trace Encoders)
-
Shared - shares timestamp with another Trace Encoder or Trace Funnel
-
External - accepts a binary timestamp value from an outside source such as ARM CoreSight™ trace (for both Trace Encoders and Trace Funnels)
Implementations may have no timestamp, one timestamp mode, or more than one mode. The WARL field trTsMode
is used to determine the system capability and to set the desired timestamp mode.
The width of the timestamp is implementation dependent, typically 40 or 48 bits (40-bit timestamp will overflow every 4.7 minutes assuming 1GHz timestamp clock).
In a system with Funnels, typically all the Funnels are built with a Timestamp Unit. The top-level Funnel is the source of the timestamp (Internal System or External) and all the Encoders and other Funnels have a Shared timestamp. This assures that all timestamps in the system are the same and trace from different harts may be time-correlated. To perform the forwarding function, the mid-level Funnels must be programmed with trFunnelActive
= 1 (which is natural as all trace messages must pass through that funnel).
An Internal System or Core timestamp unit may include a timestamp clock pre-scaler divider, which can extend the range of a narrower timestamp and uses less power but has less resolution.
In a system with an Internal Core timestamp counter (implemented in Trace Encoder associated with a hart) an optional control bit is provided to stop the counter when the hart is halted by a debugger.
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
0 |
trTsActive |
Primary activate/reset bit for timestamp unit.
This must either be RW or, if separated reset for timestamp component is not implemented, a read-only copy of the corresponding |
WARL |
SD |
1 |
trTsCount |
Internal System or Core timestamp only. |
WARL |
|
2 |
trTsReset |
Internal System or Core timestamp only. |
W1 |
— |
3 |
trTsRunInDebug |
Internal Core timestamp only. |
WARL |
|
6:4 |
trTsMode |
Mode used by Timestamp unit: |
WARL |
|
7 |
— |
Reserved |
— |
0 |
9:8 |
trTsPrescale |
Internal System or Core timestamp only. |
WARL |
|
14:10 |
— |
Reserved |
— |
0 |
15 |
trTsEnable |
Enable for timestamp field in trace messages/packets (for Trace Encoder only). |
WARL |
|
23:16 |
Vendor-specific bits to control what message/packet types include timestamp fields. |
WARL |
||
29:24 |
trTsWidth |
Width of timestamp in bits (0..63) |
RO |
|
31:30 |
— |
Reserved |
— |
0 |
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
31:0 |
trTsCounterLow |
Lower 32 bits of timestamp counter. |
RO |
0 |
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
31:0 |
trTsCounterHigh |
Upper bits of timestamp counter, zero-extended. |
RO |
0 |
Debug module triggers are signals from the hart that a trigger was hit, but the action associated with that trigger is a trace-related action. Action identifiers 2-5 are reserved for trace actions in the RISC-V Debug Specification, where triggers are defined. Actions 2-4 are defined by the Efficient Trace for RISC-V (E-Trace) Specification. The desired action is written to the action
field of the Match Control mcontrol
CSR (0x7a1). As not all harts may support all trace actions, the debugger should read back the mcontrol
CSR after setting the desired trace action to verify that the option exists.
Trigger Action (from debug spec) | Effect |
---|---|
0 |
Breakpoint exception (as defined in RISC-V Debug Specification) |
1 |
Debug exception (as defined in RISC-V Debug Specification) |
2 |
Trace-on action |
3 |
Trace-off action |
4 |
Trace-notify action |
5 |
Vendor-specific trace action (optional) |
If there are vendor-specific features that require control, the trTeTrigDbgControl
register is used.
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
31:0 |
trTeTrigDbgControl |
Vendor-specific trigger setup |
WARL |
The TE may be configured with up to 8 external trigger inputs for controlling trace. These are in addition to the external triggers present in the Debug Module when Halt Groups are implemented. The specific hardware signals comprising an external trigger are implementation dependent.
External Trigger Outputs may also be present. A trigger out may be generated by trace starting, trace stopping, a watchpoint, or by other system-specific events.
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
3:0 |
trTeTrigExtInAction0 |
Select action to perform when external trigger input #0 fires. If external trigger input #0 does not exist, then its action is fixed at 0. |
WARL |
|
31:4 |
trTeTrigExtInActionN |
Select actions (as defined for bits 3-0) for external trigger input #N (1..7). If an external trigger input does not exist, then its action is fixed at 0. |
WARL |
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
3:0 |
trTeTrigExtOutEvent0 |
Bitmap to select which event(s) cause external trigger #0 output to fire. If external trigger output #0 does not exist, then all bits are fixed at 0. Bits 2 and 3 may be fixed at 0 if the corresponding feature is not implemented. |
WARL |
|
31:4 |
trTeTrigExtOutEventN |
Select events for external trigger output #N (1..7). If an external trigger output does not exist, then its event bits are fixed at 0 |
WARL |
It is implementation dependent what happens when triggers (from debug module or external) with conflicting actions occur simultaneously (signaled at the same ingress port cycle) or if triggers occur too frequently. It is recommended that tracing starts from the oldest instruction retired in the cycle that Trace-on is asserted, and stops following the newest instruction retired in the cycle that Trace-off is asserted.
All registers with offsets 0x400 .. 0x7FC are designated for additional trace encoder filter options (context, addresses, modes, etc.).
Trace encoder filters are an optional feature that can be used to control the generated trace in various ways.
The registers below divide the filter logic into filters and comparators to provide maximum flexibility at low cost. The number of filters and comparators depends on the system. Each filter unit can specify filtering against instruction and optionally against data trace inputs from the hart. When filter i is implemented, the registers trTeFilteriControl
and trTeInstFilters
must be implemented to enable it. And to apply filter i to the data trace, the trTeDataFilters
register must also be present. And if a match bit in the trTeFilteriControl
register can be set to 1 (= enabling a filter option), the corresponding register from the bit’s description must have a correct value already set as otherwise the trigger may fire unintentionally. Each of the mentioned comparator units is a pair of comparators (primary and secondary, or P and S), so a limited range can be matched with a single comparator unit if needed.
Each enabled filter define independent condition where trace is enabled - if several filters are enabled they act as logical OR
. Several conditions for single filter act as logical AND
.
Note
|
Filter and comparator registers refer to values of some signals (as priv, itype, ecause, dtype, dsize, …) available on Trace Ingress Port. See E-Trace specification for details of encoding of these values. |
Address Offset | Register Name | Compliance | Description |
---|---|---|---|
0x400 + 0x20*i |
trTeFilteriControl |
Optional |
Filter i control |
0x404 + 0x20*i |
trTeFilteriMatchInst |
Optional |
Filter i instruction match control |
0x408 + 0x20*i |
trTeFilteriMatchEcauseLow |
Optional |
Filter i Ecause match control (bits 31:0) |
0x40C + 0x20*i |
trTeFilteriMatchEcauseHigh |
Optional |
Filter i Ecause match control (bits 63:32) |
0x410 + 0x20*i |
trTeFilteriMatchValueImpdef |
Optional |
Filter i impdef value |
0x414 + 0x20*i |
trTeFilteriMatchMaskImpdef |
Optional |
Filter i impdef mask |
0x418 + 0x20*i |
trTeFilteriMatchData |
Optional |
Filter i Data trace match control |
0x41C + 0x20*i |
— |
Optional |
Reserved |
Address Offset | Register Name | Compliance | Description |
---|---|---|---|
0x600 + 0x20*j |
trTeCompjControl |
Optional |
Comparator j control |
0x604 + 0x20*j |
— |
Optional |
Reserved |
0x608 + 0x20*j |
— |
Optional |
Reserved |
0x60c + 0x20*j |
— |
Optional |
Reserved |
0x610 + 0x20*j |
trTeCompjPmatchLow |
Optional |
Comparator j primary match (bits 31:0) |
0x614 + 0x20*j |
trTeCompjPmatchHigh |
Optional |
Comparator j primary match (bits 63:32) |
0x618 + 0x20*j |
trTeCompjSmatchLow |
Optional |
Comparator j secondary match (bits 31:0) |
0x61C + 0x20*j |
trTeCompjSmatchHigh |
Optional |
Comparator j secondary match (bits 63:32) |
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
0 |
trTeFilterEnable |
Overall filter enable for filter #i |
WARL |
|
1 |
trTeFilterMatchPrivilege |
When set, match privilege levels specified by |
WARL |
|
2 |
trTeFilterMatchEcause |
When set, start matching from exception cause codes specified by |
WARL |
|
3 |
trTeFilterMatchInterrupt |
When set, start matching from either an interrupt or exception as specified by
|
WARL |
|
4 |
trTeFilterMatchComp1 |
When set, the output of the comparator selected by |
WARL |
|
7:5 |
trTeFilterComp1 |
Specifies the comparator unit to use for the 1st comparison. |
WARL |
|
8 |
trTeFilterMatchComp2 |
When set, the output of the comparator selected by |
WARL |
|
11:9 |
trTeFilterComp2 |
Specifies the comparator unit to use for the 2nd comparison. |
WARL |
|
12 |
trTeFilterMatchComp3 |
When set, the output of the comparator selected by |
WARL |
|
15:13 |
trTeFilterComp3 |
Specifies the comparator unit to use for the 3rd comparison. |
WARL |
|
16 |
trTeFilterMatchImpdef |
When set, match impdef values as specified by |
WARL |
|
23:17 |
— |
Reserved |
— |
0 |
24 |
trTeFilterMatchDtype |
When set, match dtype values as specified by |
WARL |
|
25 |
trTeFilterMatchDsize |
When set, match dsize values as specified by |
WARL |
|
31:26 |
— |
Reserved |
— |
0 |
Note
|
Handling of trTeFilterMatchEcause and trTeFilterMatchInterrupt should include a count of nested traps. The size of the counter is implementation dependent. If the number of nested traps exceeds the number that can be counted, the counter will saturate, meaning that the filtering will turn off prematurely.
|
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
7:0 |
trTeFilterMatchChoicePrivilege |
When |
WARL |
|
8 |
trTeFilterMatchValueInterrupt |
When |
WARL |
|
31:9 |
— |
Reserved |
— |
0 |
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
31:0 |
trTeFilterMatchChoiceEcauseLow |
When |
WARL |
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
31:0 |
trTeFilterMatchChoiceEcauseHigh |
Stores bits 63:32 to allow matching of higher ecause codes. If bit N is 1, then match if the ecause is N+32. |
WARL |
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
31:0 |
trTeFilterMatchValueImpdef |
When |
WARL |
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
31:0 |
trTeFilterMatchMaskImpdef |
When |
WARL |
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
15:0 |
trTeFilterMatchChoiceDtype |
When |
WARL |
|
23:16 |
trTeFilterMatchChoiceDsize |
When |
WARL |
|
31:24 |
— |
Reserved |
— |
0 |
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
1:0 |
trTeCompPInput |
Determines which input to compare against the primary comparator. |
WARL |
|
3:2 |
trTeCompSInput |
Determines which input to compare against the secondary comparator. Same encoding as |
WARL |
|
6:4 |
trTeCompPFunction |
Selects the primary comparator function. Primary result is true if input selected via |
WARL |
|
7 |
— |
Reserved |
— |
0 |
10:8 |
trTeCompSFunction |
Selects the secondary comparator function. Secondary result is true if input selected via |
WARL |
|
11 |
— |
Reserved |
— |
0 |
13:12 |
trTeCompMatchMode |
Selects the match condition used to assert the overall comparator output |
WARL |
|
14 |
trTeCompPNotify |
Generate a trace packet explicitly reporting the address
of the final instruction in a block that causes a
primary match. This is also known as a watchpoint.
Requires |
WARL |
|
15 |
trTeCompSNotify |
Generate a trace packet explicitly reporting the address
of the final instruction in a block that causes a
secondary match. This is also known as a watchpoint.
Requires |
WARL |
|
31:16 |
— |
Reserved |
— |
0 |
Important
|
Comparisions are performed as unsigned numbers. Only bits from an input signal (as defined by trTeCompPInput and/or trTeCompSInput fields), should be compared. Additional most significant bits from the trTeCompjPMatchLow/High registers must be ignored.
|
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
31:0 |
trTeCompPMatchLow |
The match value for the primary comparator (bits 31:0). |
WARL |
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
31:0 |
trTeCompPMatchHigh |
The match value for the primary comparator (bits 63:32). |
WARL |
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
31:0 |
trTeCompSMatchLow |
The match value for the secondary comparator (bits 31:0). |
WARL |
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
31:0 |
trTeCompSMatchHigh |
The match value for the secondary comparator (bits 63:32). |
WARL |
Trace RAM Sink may be instantiated or configured to support storing trace into dedicated SRAM or system memory. SRAM mode is using dedicated local memory inside of RAM sink, while system memory mode (SMEM mode) is accessing memory via system bus (care should be taken to not overwrite application code or data - it is usually done by reserving part of system memory for trace). Dedicated SRAM memory must be read via dedicated trRamData
register, while memory in SMEM mode should be read as any other memory on system bus - for example using SBA (System Bus Access) access mode as defined in the RISC-V Debug Specification.
Trace data is placed in memory in LSB order (first byte of trace packet/data is placed on LSB).
Be aware that in case trace memory wraps around some protocols may require additional synchronization data - it is usually done by periodically generating a sequence of alignment synchronization bytes which cannot be part of any valid packet. Specification of each trace protocol must define it.
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
0 |
trRamActive |
Primary activate/reset bit for Trace RAM Sink. When 0, the Trace RAM Sink may have clocks gated off or be powered down, and other register locations may be inaccessible. Hardware may take an arbitrarily long time to process power-up and power-down and will indicate completion when the read value of this bit matches what was written. See Reset and Discovery chapter for more details. |
RW |
0 |
1 |
trRamEnable |
1: Trace RAM Sink enabled. Setting |
RW |
0 |
2 |
— |
Reserved |
— |
0 |
3 |
trRamEmpty |
Reads 1 when Trace RAM Sink internal buffers are empty, which means that all trace data is flushed. |
RO |
1 |
4 |
trRamMode |
0: This RAM Sink will operate in SRAM mode |
WARL |
|
7:5 |
— |
Reserved |
— |
0 |
8 |
trRamStopOnWrap |
1: Disable storing trace to RAM ( |
WARL |
|
10:9 |
trRamMemFormat |
0: Memory is formatted as plain bytes |
WARL |
|
11 |
— |
Reserved |
— |
0 |
14:12 |
trRamAsyncFreq |
0: Alignment synchronization (Async) packets disabled (may be the only choice for some protocols) |
WARL |
|
31:15 |
— |
Reserved |
— |
0 |
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
3:0 |
trRamVerMajor |
Trace RAM Sink Component Major Version. Value 1 means the component is compliant with this document. |
RO |
1 |
7:4 |
trRamVerMinor |
Trace RAM Sink Component Minor Version. Value 0 means the component is compliant with this document. |
RO |
0 |
11:8 |
trRamCompType |
Trace RAM Sink Component Type (RAM Sink) |
RO |
0x9 |
12 |
trRamHasSRAM |
This RAM Sink supports SRAM mode |
RO |
|
13 |
trRamHasSMEM |
This RAM Sink supports SMEM (System Memory) mode |
RO |
|
23:14 |
— |
Reserved for future versions of this standard |
— |
0 |
31:24 |
— |
Reserved for vendor specific implementation details |
— |
Note
|
Single RAM Sink may support both SRAM and SMEM modes, but not both may be enabled at the same time. It is also possible to have more than one RAM Sink in a system. |
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
1:0 |
— |
Always 0 (two LSB of 32-bit address) |
RO |
0 |
31:2 |
trRamStartLow |
Byte address of start of trace sink circular buffer. It is always aligned on at least a 32-bit/4-byte boundary. An SRAM sink will usually have |
WARL |
Undef or fixed to 0 |
For a bus with an address larger than 32-bit, corresponding High
registers define the MSB part of such a larger address.
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
31:0 |
trRamStartHigh |
High order bits (63:32) of |
WARL |
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
1:0 |
— |
Always 0 (two LSB of 32-bit address) |
RO |
0 |
31:2 |
trRamLimitLow |
Highest absolute 32-bit part of address of trace circular buffer. The |
WARL |
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
31:0 |
trRamLimitHigh |
High order bits (63:32) of |
WARL |
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
0 |
trRamWrap |
Set to 1 by hardware when |
WARL |
|
1 |
— |
Always 0 (bit B1 of 32-bit address) |
RO |
0 |
31:2 |
trRamWPLow |
Absolute 32-bit part of address in trace sink memory where next trace message will be written. Fixed to a natural boundary. After a trace word write occurs while |
WARL |
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
31:0 |
trRamWPHigh |
High order bits (63:32) of |
WARL |
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
1:0 |
— |
Always 0 (two LSB of 32-bit address) |
RO |
0 |
31:2 |
trRamRPLow |
Absolute 32-bit part of address in trace circular memory buffer visible through |
WARL |
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
31:0 |
trRamRPHigh |
High order bits (63:32) of |
WARL |
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
31:0 |
trRamData |
Read (and optional write) value for trace sink memory access. SRAM is always accessed by 32-bit words through this path regardless of the actual width of the sink memory. Required for SRAM mode and optional for SMEM mode. |
R or RW |
Note
|
When trace capture was wrapped around (trRamWrap = 1) beginning of trace is not available and oldest packets/messages in the trace buffer (starting at address in trRamWP ) will most likely not be complete. Trace decoders must look for the start of a message. Also when trace is stopped on wrap around, the very last message recorded in trace memory may not be complete.
|
The table below shows typical Trace RAM Sink configurations. Implementing other configurations is not suggested as trace tools may not support it without adjustments.
Mode | trRamStart | trRamLimit | trRamWP | trRamRP | trRamData |
---|---|---|---|---|---|
SRAM |
0 |
Hard coded to max size (2^M - A) at reset, but can be possibly trimmed |
Required |
Required |
Required |
SMEM Generic |
Any (2^N aligned) |
Any ( |
Required |
Not implemented |
Not implemented |
SMEM Fixed |
Fixed (2^N aligned) |
Fixed to max size at reset ( |
Required |
Not implemented |
Not implemented |
Note
|
Value A means alignment which depends on memory access width. If we have memory access width of 32-bits, A=4 and value of trRamLimit register should be 0x…FC. Some implementations may impose bigger alignment of trace data (to allow more efficient transfer rates) for SMEM mode. For SRAM mode A must be 4 as access to trace via trRamData is always 32-bits wide.
|
Trace tool should start interacting with Trace RAM Sink by releasing RAM Sink from reset by setting trRamActive
= 1 and waiting for this bit to be set. After that it should verify trRamEmpty
= 1, read trRamImpl
and verify trRamCompType
and trRamVer??
fields. Values of trRamHasSRAM/SMEM
fields will provide main types of RAM Sink being implemented.
Later trRamMode
should be set (depending on desired RAM Sink mode). It is important to set this field first as other registers may behave differently for SRAM and SMEM modes.
In SRAM mode, the trace memory is dedicated for trace storage and trRamStart??
registers should not be settable (usually both not implemented and return 0). trRamLimitLow
register may be either hardcoded (to reflect physical SRAM size) or writable (allowing trimming RAM size allowing faster wrap-around or sharing the same memory with some other components in the system). The trRamLimitHigh
register should not be implemented as it is not practical to have more than 4GB of dedicated on-chip RAM storage.
Detection of valid ranges of each trRamStart??
and trRamLimit??
registers should be performed by writing 0 and 0xFFFFFFFF.
After setting 0, the lowest possible value must be set. After setting 0xFFFFFFFF the highest possible value must be set. If the highest value for trRamStartHigh
or trRamLimitHigh
is 0, it means the register is NOT implemented.
Some implementations may provide different limits for different start addresses, so the trace tool should always set trRamStart??
registers first - this option can be used when a particular implementation has two different RAM regions (each with different physical memory size).
Not every value may be settable in trRamStart/Limit
registers. Value written may be trimmed (for example aligned on a particular 2^N boundary) and a trace tool should verify values being written. In case accepted values are different from what was provided by the user, a message should be printed which may allow the user to adjust (possbly suboptimal) settings.
Registers trRamStart??
and trRamLimit??
are usually set at the beginning of a debug/trace session and never changed.
Important
|
In SMEM mode (trRamMode = 1) trace tool should never set trRamStart?? and trRamLimit?? registers outside of range provided by the user as otherwise raw trace being written to memory may corrupt running code and/or data or stack. This type of errors may be very difficult to diagnose as in complex system code (or data) being overwritten by trace may be used way, way later after actual corruption was made.
|
Having both trRamStart/Limit??
registers set, the tool should try to set trRamRP??
to the same value as trRamLimit??
. If it is settable, it means that the trRamData
register should be used to read the trace. Otherwise collected trace must be read using normal, physical memory accesses (in range defined by trRamStart/Limit??
registers).
Before enabling RAM Trace Sink (by setting trRamEnable
= 1) the trace tool should set trRamWP??
registers (usually to the same values as in trRamStart??
register). Enabling trace must NOT change any of trRamStart/Size/WP/RP??
registers. Just after the trace is enabled trRamWP??
may change because of trace being added to trace memory.
After trace is enabled and active (trRamEnable
= 1 or trRamEmpty
= 0), the trace tool should NOT write any of trRamStart/Limit/WP??
registers.
Setting trRamRP
and reading trRamData
may be attempted while trace is active, but support for reading SRAM trace while trace is active may not always be implemented. In such a case write to trRamRP
must be ignored and trRamData
read must not advance trRamRP
. Reading the trace in the SMEM mode via normal memory reads is always allowed.
Note
|
Even if reading trace (while trace is active) is implemented, circular trace buffer may be overwritten even several times, so values being read by trRamData will be of no use. However, when trace is started/stopped by infrequent triggers, reading SRAM trace may be useful. Also, the very last packet in memory may be incomplete as the last trace word may be buffered inside (and trRamEmpty = 0 will be observed).
|
Note
|
Trace RAM Sink may implement writing trace by writing to trRamData , but this mode is usable only for testing, so will most likely not be implemented. Trace tool is not required to support writing to the trRamData register.
|
The Trace Funnel combines messages/packets from multiple sources into a single trace stream. It is implementation dependent how many incoming messages/packets are accepted before it is switching to another input source and in what order. But a continuous stream of messages/packets at one input cannot cause other inputs to not be handled. Suggested implementation would be to process just a single message/packet from each input in a round-robin fashion.
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
0 |
trFunnelActive |
Primary activate/reset bit for trace funnel. When 0, the Trace Funnel may have clocks gated off or be powered down, and other register locations may be inaccessible. Hardware may take an arbitrarily long time to process power-up and power-down and will indicate completion when the read value of this bit matches what was written. See Reset and Discovery chapter for more details. |
RW |
0 |
1 |
trFunnelEnable |
1: Trace Funnel enabled. Setting |
RW |
0 |
2 |
— |
Reserved |
— |
0 |
3 |
trFunnelEmpty |
Reads 1 when Trace Funnel internal buffers are empty |
RO |
1 |
31:4 |
— |
Reserved |
— |
0 |
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
3:0 |
trFunnelVerMajor |
Trace Funnel Component Major Version. Value 1 means the component is compliant with this document. |
RO |
1 |
7:4 |
trFunnelVerMinor |
Trace Funnel Component Minor Version. Value 0 means the component is compliant with this document. |
RO |
0 |
11:8 |
trFunnelCompType |
Trace Funnel Component Type (Trace Funnel) |
RO |
0x8 |
23:12 |
— |
Reserved for future versions of this standard |
— |
0 |
31:24 |
— |
Reserved for vendor specific implementation details |
— |
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
15:0 |
trFunnelDisInput |
1: Funnel input #n (bit position in register) is disabled. Incoming messages are read from diabled input but discarded. |
WARL |
|
31:16 |
— |
Reserved |
— |
0 |
Note
|
trFunnelDisInput register is optional. When not implemented (or never set) it will read as 0, which means that all inputs are always enabled. When implemented, it can be set to 0xFFFF to detect which inputs may be disabled in that trace funnel. Disabling inputs is needed when a single trace encoder may provide output to more than one possible active destination/sink. This register can be also used by trace tools to easily configure a trace in complex systems. Without the ability to disable individual funnel inputs, the trace tool must assure all trace sources which should not be traced are disabled.
|
Trace data may be sent to chip pins through an interface called the Pin Interface Block (PIB). This interface typically operates at a few hundred MHz and can sometimes be higher with careful constraints and board layout or by using LVDS or other high-speed signal protocol. PIB may consist of just one signal and in this configuration may be called SWT (Serial-Wire Trace). Alternative configurations include a trace clock (TRC_CLK) and 1/2/4/8/16 parallel trace data signals (TRC_DATA) timed to that trace clock. WARL register fields are used to determine specific PIB capabilities.
The modes and behavior described here are intended to be compatible with trace probes available in the market.
PIB Register Interface
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
0 |
trPibActive |
Primary activate/reset bit for PIB Sink component. When 0, the PIB Sink may have clocks gated off or be powered down, and other register locations may be inaccessible. Hardware may take an arbitrarily long time to process power-up and power-down and will indicate completion when the read value of this bit matches what was written. See Reset and Discovery chapter for more details. |
RW |
0 |
1 |
trPibEnable |
0: PIB does not accept input but holds output(s) at idle state defined by pibMode. |
RW |
0 |
2 |
— |
Reserved |
— |
0 |
3 |
trPibEmpty |
Reads 1 when PIB internal buffers are empty. |
RO |
1 |
7:4 |
trPibMode |
Select mode for output pins. Allowed values are described in the |
WARL |
|
8 |
trPibClkCenter |
In parallel modes, adjust TRC_CLK timing to the center of the bit period. This can be set only if |
WARL |
|
9 |
trPibCalibrate |
Set this to 1 to generate a repeating calibration pattern to help tune a probe’s signal delays, bit rate, etc. In this mode input to the sink is not consumed. The calibration pattern is described below. |
WARL |
|
11:10 |
— |
Reserved |
— |
0 |
14:12 |
trPibAsyncFreq |
0: Alignment synchronization (Async) packets disabled (may be the only choice for some protocols) |
WARL |
|
15 |
— |
Reserved |
— |
0 |
31:16 |
trPibDivider |
Timebase selection for the PIB module. The input clock is divided by |
WARL |
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
3:0 |
trPibVerMajor |
Trace PIB Sink Component Major Version. Value 1 means the component is compliant with this document. |
RO |
1 |
7:4 |
trPibVerMinor |
Trace PIB Sink Component Minor Version. Value 0 means the component is compliant with this document. |
RO |
0 |
11:8 |
trPibCompType |
Trace PIB Sink Component Type (PIB Sink) |
RO |
0xA |
23:12 |
— |
Reserved for future versions of this standard |
— |
0 |
31:24 |
— |
Reserved for vendor specific implementation details |
— |
Software can determine what modes are available by attempting to write each mode setting to the WARL field trPibMode
and reading back to see if the value was accepted.
Mode | trPibMode | trPibClkCenter | Bit rate |
---|---|---|---|
Off |
0 |
X |
— |
SWT Manchester |
4 |
X |
1/2 |
SWT UART |
5 |
X |
1 |
TRC_CLK + 1 TRC_DATA |
8 |
0 |
1 |
TRC_CLK + 2 TRC_DATA |
9 |
0 |
1 |
TRC_CLK + 4 TRC_DATA |
10 |
0 |
1 |
TRC_CLK + 8 TRC_DATA |
11 |
0 |
1 |
TRC_CLK + 16 TRC_DATA |
12 |
0 |
1 |
TRC_CLK + 1 TRC_DATA |
8 |
1 |
1/2 |
TRC_CLK + 2 TRC_DATA |
9 |
1 |
1/2 |
TRC_CLK + 4 TRC_DATA |
10 |
1 |
1/2 |
TRC_CLK + 8 TRC_DATA |
11 |
1 |
1/2 |
TRC_CLK + 16 TRC_DATA |
12 |
1 |
1/2 |
Since the PIB supports many different modes, it is necessary to follow a particular programming sequence:
-
Activate the PIB by setting
trPibActive
. -
Set the
trPibMode
,trPibDivider
,trPibClkCenter
, andtrPibCalibrate
fields. This will set the TRC_DATA outputs to the quiescent state (whether that is high or low depends ontrPibMode
) and start TRC_CLK running. -
Activate the receiving device, such as a trace probe. Allow time for PLL to sync up, if using a PLL with a parallel PIB mode.
-
Set
trPibEnable
. This enables the PIB to generate output either immediately (calibration mode) or when the Trace Encoder or Trace Funnel begins sending trace messages/packets.
-
Trace messages/packets are considered as sequences of bytes and are always transmitted with least significant bits/bytes first.
-
In 16-bit mode (
trPibMode
== 12) the byte transmitted on bits #0-#7 is considered first and most significant bits#8-#15 are transmitting second byte. -
Idle sequences (no message/packet to be sent) are transmitted between messages.
-
Idle sequence depends on trace protocol and must allow detection of the start of first byte of message/packet following the idle sequence.
-
Idle sequences may be different and should be defined by trace protocols.
-
Traditionally, off-chip trace has used this protocol. There are several parallel data signals (TRC_DATA0..15) and one continuously-running trace clock (TRC_CLK). The data rate of parallel signals can be much higher than either of the serial-wire protocols.
This protocol is oriented to send full, variable length trace messages/packets rather than fixed-width trace words.
When a message start is detected, this sample and possibly the next few (depending on the width of TRC_DATA) are collected until a complete byte has been received. Bytes are transmitted least significant bit first, with TRC_DATA[0] representing the least significant bit in each beat of data. The receiver continues collecting bytes until a complete message has been received. The criteria for this depends on the trace format. After the last byte of a message, the data signals may then go to their idle state or a new message may begin in the next trace clock edge.
The trace clock, TRC_CLK, normally has edges coincident with the TRC_DATA edges. Typically, a trace probe will delay trace data or use a PLL to recover a sampling clock that is twice the frequency of TRC_CLK and shifted 90 degrees so that its rising edges occur near the center of each bit period. If the PIB implementation supports it, the debugger can set trPibClkCenter
to change the timing of TRC_CLK so that there is a TRC_CLK edge at the center of each bit period on TRC_DATA. Note that this option cuts the data rate in half relative to normal parallel mode and still requires the probe to sample TRC_DATA on both edges of TRC_CLK.
This example shows 8-bit parallel mode with trPibClkCenter
= 0 transmitting a 5-byte message/packet followed by a 2-byte message/packet.
And an example showing 8-bit parallel mode transmitting a 4-byte packet with trPibClkCenter
= 1
In this mode, the PIB outputs complete trace messages encapsulated between a start bit and a stop bit. Each bit period is divided into 2 phases and the sequential values of the TRC_DATA[0] pin during those 2 phases denote the bit value. Bits of the message are transmitted LSB first. The idle state of TRC_DATA[0] is low in this mode.
Bit | Phase 1 | Phase 2 |
---|---|---|
start |
1 |
0 |
logic 0 |
0 |
1 |
logic 1 |
1 |
0 |
stop/idle |
0 |
0 |
In UART protocol, the PIB outputs bytes of a trace message encapsulated in a 10-bit packet consisting of a low start bit, 8 data bits, LSB first, and a high stop bit. Another packet may begin immediately following the stop bit or there may be an idle period between packets. When no data is being sent, TRC_DATA[0] is high in this mode.
In optional calibration mode, the PIB transmits a repeating pattern. Probes can use this to automatically tune input delays due to skew on different PIB signal lines and to adjust to the transmitter’s data rate (trPibDivider
and trPibClkCenter
). Calibration patterns for each mode are listed below.
Mode | Calibration Bytes | Wire Sequence |
---|---|---|
UART, Manchester |
AA 55 00 FF |
alternating 1/0, then all 0, then all 1 |
1-bit parallel |
AA 55 00 FF |
alternating 1/0, then all 0, then all 1 |
2-bit parallel |
66 66 CC 33 |
2, 1, 2, 1, 2, 1, 2, 1, 0, 3, 0, 3, 3, 0, 3, 0 |
4-bit parallel |
5A 5A F0 0F |
A, 5, A, 5, 0, F, F, 0 |
8-bit parallel |
AA 55 00 FF |
AA, 55, 00, FF |
16-bit parallel |
AA AA 55 55 00 00 FF FF |
AAAA, 5555, 0000, FFFF |
Note
|
Calibration mode may be used even by probes which do not support calibration of trace just to assure trace routing on PCB is correct and PIB is correctly enabled. It may be also possible to use calibration mode to check trace signal routing from SoC using scope or logic analyzer. |
Some SoCs may have an Advanced Trace Bus (ATB) infrastructure to manage trace produced by other components. In such systems, it may be desired to route entire RISC-V trace stream to the ATB through an ATB Bridge. This module manages the interface to ATB, generating ATB trace records that encapsulate RISC-V trace produced by the Trace Encoder[s] and/or Trace Funnel[s]. There is a control register that includes trace on/off control and a field allowing software to set the ID to be used on the ATB bus. This ID allows software to extract entire RISC-V trace from the combined trace. This interface is compatible with AMBA 4 ATB v1.1.
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
0 |
trAtbBridgeActive |
Primary activate/reset for the ATB Bridge. When 0, the ATB Bridge may have clocks gated off or be powered down, and other register locations may be inaccessible. Hardware may take an arbitrarily long time to process power-up and power-down and will indicate completion when the read value of this bit matches what was written. See Reset and Discovery chapter for more details. |
RW |
0 |
1 |
trAtbBridgeEnable |
1: ATB Bridge enabled. Setting |
RW |
0 |
2 |
— |
Reserved |
— |
0 |
3 |
trAtbBridgeEmpty |
Reads 1 when ATB Bridge internal buffers are empty |
RO |
1 |
7:4 |
— |
Reserved |
— |
0 |
14:8 |
trAtbBridgeID |
ID of this node on ATB. Values of 0x00 and 0x70-0x7F are reserved by the ATB specification and should not be used. |
RW |
|
31:15 |
— |
Reserved |
— |
0 |
Bit | Field | Description | RW | Reset |
---|---|---|---|---|
3:0 |
trAtbBridgeVerMajor |
ATB Bridge Component Major Version. Value 1 means the component is compliant with this document. |
RO |
1 |
7:4 |
trAtbBridgeVerMinor |
ATB Bridge Component Minor Version. Value 0 means the component is compliant with this document. |
RO |
0 |
11:8 |
trAtbBridgeCompType |
ATB Bridge Component Type (ATB Bridge) |
RO |
0xE |
14:12 |
trAtbBridgeAsyncFreq |
0: Alignment synchronization (Async) packets disabled (may be the only choice for some protocols) |
WARL |
|
23:15 |
— |
Reserved for future versions of this standard |
— |
0 |
31:24 |
— |
Reserved for vendor specific implementation details |
— |
An implementation determines the data widths of the connection from the Trace Encoder or Trace Funnel and of the ATB port.
ATB Bridge may optionally insert ATB alignment synchronization packets (controlled by trAtbBridgeAsyncFreq
field) allowing trace decoding software to detect ATB packet boundaries. Not all protocols may require it.
This (non-normative) chapter gives an of what needs to be done to put together complete RISC-V trace implementation without getting familiar with every detail of every register.
Minimal General Registers/Fields
These requirements are applicable to the entire trace sub-system.
-
One
Trace Encoder
per hart being traced is required. -
At least one of Trace RAM or Trace PIB sinks or Trace ATB Bridge is required as the final destination of an encoded RISC-V trace.
-
Implementations providing custom transport only are NOT considered fully compliant with this specification as custom trace tools will be needed.
-
-
Each trace component in a system is required to implement
tr??Control
andtr??Impl
registers.-
tr??Active
bit must be settable to 0 or 1, although reset itself is NOT required. -
tr??Enable
bit must be settable to 0 or 1 and must support flushing (if applicable) when changed from 1 to 0. -
tr??Empty
bit must read as 0 when the trace component has some trace data internally buffered (if trace component it not buffering any trace data, this bit may be hard coded to 1). -
tr??VerMajor
,tr??VerMinor
andtr??CompType
must be implemented.
-
Minimal Trace Encoder Register/Fields
-
Bit
trTeInstTracing
must be implemented (to start/stop instruction trace output from Trace Encoder). -
One of
trTeInstMode
= 3 (Baseline instruction trace) or 6 (Optimized instruction trace) must be implemented (can be a hard coded value). -
At least one of the non-0 values of
trTeInstSyncMode
must be settable (or hard coded). -
Field
trTeFormat
must correspond to implemented trace protocol (0 for E-Trace or 1 for N-Trace). -
Fields
trTeProtocolMajor
andtrTeProtocolMinor
must return versions of implemented protocol. -
All other registers/fields/bits may be tied to 0.
Minimal Trace RAM Sink Register/Fields
SRAM mode only:
-
Bit
trRamHasSRAM
must be tied to 1 andtrRamMode
must be tied to 0. -
Bit
trRamWrap
must be implemented. -
Register
trRamLimitLow
must be implemented but can be hard coded to value '2^M-4' (address 0x..FC). -
Register
trRamWPLow
must at least accept a write of 0. -
Register
trRamRPLow
must accept any 32-bit aligned value in inclusive range < 0 ..trRamLimitLow
>.-
If width of access to SRAM is wider than 32-bits any 32-bit aligned value of
trRamRP
must be allowed and reads must be buffered.
-
-
Register
trRamData
may be implemented for reading only. -
All other registers/fields/bits may be tied to 0.
SMEM mode only:
-
Bit
trRamHasSMEM
must be tied to 1 andtrRamMode
must be tied to 1. -
Bit
trRamWrap
must be implemented. -
Register
trRamStart
must be implemented but can be hard coded to value '2^N' (address 0x..00). -
Register
trRamLimit
must be implemented but can be hard coded to value '2^N + 2^M-4' (address 0x..FC). -
Registers
trRamWP
must accept any 32-bit aligned value in inclusive range <trRamStart
..trRamLimit
>. -
All other registers/fields/bits may be tied to 0.
Minimal Trace PIB Sink Register/Fields
It is hard to define required mode as it depends on SoC bandwidth requirements and capabilities, but some general guidance may be provided.
-
4-bit mode is supported by most (if not all) trace probes and less expensive MIPI20 connectors can be used.
-
1-bit and 2-bit modes should be only used when there are critical constraints on the number of MCU pins. Not all trace probes may support these modes.
-
-
Serial mode should be only considered when either limited trace is required, or cores run slowly. Not all trace probes may support this mode and max allowed speeds may vary.
-
Manchester encoding is self-synchronizing and may provide a more reliable trace. However UART mode may provide better bandwidth. It is suggested to support both.
-
-
8-bit and 16-bit modes will provide better bandwidth, but require a more expensive Mictor connector and only more advanced trace probe models may support it.
-
It is suggested to provide as fast as possible trace logic clock, and allow a trace tool to set the divider in the
trPibDivider
field. -
For TRC_CLK frequencies higher than 50MHz, it is suggested to provide a calibration mode.
-
If possible, implement
trPibClkCenter
for better flexibility.
-
Minimal ATB Bridge Register/Fields
-
Field
trAtbBridgeID
must be settable by trace tool (hard coded ID may not be handled by all trace tools).
This chapter describes what trace tools should do to reset and discover trace features.
Important
|
Trace tools must be provided with base addresses of all trace components. |
Only the tr??Active
and the tr??Enable
bits are reset to 0 on power-up.
These tr??Active
bits act as independent resets for the respected trace components:
-
trTeActive
- reset for Trace Encoder component (this will disable encoder from single hart) -
trFunnelActive
- reset for Trace Funnel component -
trPibActive
- reset for PIB component (resets Pin Interface Block only) -
trRamActive
- reset for RAM component (resets RAM Sink only) -
trAtbBridgeActive
- resets ATB Bridge component (resets ATB Bridge interface) -
trTsActive
- resets the Timestamp Unit sub-component (resets timestamp generation logic)
When component is held in reset (tr??Active
is 0), then tr??Enable
bit must be reset to 0 as well (what makes component disabled).
Releasing components from reset (by setting tr??Active
to 1) may take time - debug tools should monitor (with reasonable timeout) if the appropriate bit changed from 0 to 1.
As not all fields/registers are affected by reset (defined as Undef), the trace tools must initialize (usually, a write of a value 0) several registers to assure that trace component is in a predictable state.
Note
|
|
Reset and Discovery should be performed as follows:
-
Reset the component by setting
tr??Active
= 0.-
This should be done by writing a value 0x0 to
tr??Control
register.
-
-
Read-back and wait until
tr??Active
= 0 is read, which means that a component reached a reset state. -
Release a component from reset by setting
tr??Active
= 1.-
This should be done by writing a value 0x1 to
tr??Control
register. This write will reset most of other enable/mode bits in this register and all WARL and read-only fields will be set to defaults.
-
-
Read-back and wait until
tr??Active
= 1 is read, which means that a component was released from reset.-
In this moment
tr??Enable
is set to 0 and the component is not yet enabled. -
Component clock should be enabled to allow programming of other registers.
-
-
Optionally save
tr??Control
register as it holds all reset values of all fields. It may be cached/shadowed, and trace tool may execute faster write-only (instead a read-modify-write) operations. -
Handle
tr??VerMinor/Major
as described in 'Versioning of Components' chapter.-
If
tr??VerMajor
is 0 (for Trace Encoder component) either handle it as pre-ratified/initial version 0 or generate fatal error with an appropriate error message.
-
-
Read
tr??Impl
and comparetr??ComType
field with expected value. -
Set some WARL fields and read back to discover supported component configuration - make sure the component is NOT enabled (by setting
tr??Enable
to 1) by mistake. -
Configure some initial values in all needed registers/fields. Optionally Read-back to assure these are set properly.
The table below is showing what registers needs to be written to have each trace component in identical, predictable state.
Component | Register | Write | Notes |
---|---|---|---|
Trace Encoder |
trTeControl |
0x1 |
Release from reset and set all defaults. |
trTeInstFeatures |
0x0 |
Force minimal sub-set of features. |
|
trTeInstFilters |
0x0 |
Disable all filters. |
|
trTeDataControl |
0x0 |
Disable data trace. |
|
trTeDataFilters |
0x0 |
Disable filters for data trace. |
|
trTeTrigDbgControl |
0x0 |
Disable all triggers from Debug module. |
|
trTeTrigExtInControl |
0x0 |
Disable all external trigger inputs. |
|
trTeTrigExtOutControl |
0x0 |
Do not general any external trigger outputs. |
|
trTsControl |
0x0 |
Keep timestamp unit in reset. |
|
Trace Funnel |
trFunnelControl |
0x1 |
Release from reset and set all defaults. |
trFunnelDisInput |
0x0 |
Make sure all inputs are enabled. |
|
trTsControl |
0x0 |
Keep timestamp unit in reset. |
|
Trace RAM Sink |
trRamControl |
0x1 |
Release from reset and set all defaults. |
Trace PIB Sink |
trPibControl |
0x1 |
Release from reset and set all defaults. |
Trace ATB Bridge |
trAtbBridgeControl |
0x1 |
Release from reset and set all defaults. |
As we are dealing with several independent components, it is important to assure that the component which is in reset (or powered down) is keeping its outputs on safe values, so garbage trace data is not emitted.
In general, it is safer to power-up and enable components starting from sinks/bridges, followed by Trace Funnels and Trace Encoders as last. Each implementation should test this sequence to assure trace tools are working seamlessly.
Important
|
Pre-release version of this specification specified that most of fields and registers were reset. It was suggested (by Architecture Review Committee) that reset logic is made minimal to follow RISC-V ISA style. Older implementations (which reset more bits) are still compatible with a ratified version. These implementations do not have to change as it is perfectly OK to reset more fields and registers. |
Enabling should work as follows:
-
Release all needed components from reset by setting
tr??Active
= 1 as described above. -
Set desired mode and verify if that mode is set (regardless of discovery results).
-
For RAM Sink:
-
Setup needed addresses (if possible and desired) as these may not reset.
-
-
For PIB Sink:
-
Calibrate PIB (if possible and desired).
-
Start physical trace capture (trace probe dependent).
-
-
Configure RAM Sink/PIB Sink/ATB Bridge in appropriate mode.
-
Verify if a particular mode is set.
-
-
Set main enable for RAM Sink/PIB Sink/ATB Bridge component by setting
tr??Enable
= 1.-
Read back and wait for confirmation (
tr??Enable
= 1).
-
-
Enable Trace Funnel[s] in the same way.
-
Configure and Enable Trace Encoder[s] in the same way (last should be writing
trTeEnable
= 1 followed by reading to verify that it is set).-
The
trTeInstMode
WARL field should be set to 6 - it may revert to different mode.
-
-
Either manually set
trTeInstTracing=1
and/ortrTeDataTracing=1
bits or set triggers to start the trace. -
Start hart[s] to be traced (hart could be already running as well - in this case trace will be generated in the moment when
trTeInstTracing
ortrTeDataTracing
bit is set). -
Periodically read
trTeControl
for status of trace (as it may stop by itself due to triggers).-
If RAM Sink was configured with
trRamStopOnWrap
= 1, readtrRamEnable
to see if RAM capture was stopped.
-
Note
|
Discovery may not be necessary to enable and test the trace during development of SoC. However, a discovery must be possible and should be tested by SoC designer - this is necessary for trace tools to work with that SoC without any customization. |
Note
|
Trace tools may verify a particular setting once per session, so subsequent starts of trace may be faster. |
Note
|
Trace tools should provide configuration settings allowing more verbose logging mode during discovery and initialization, so potential compatibility issues may be solved. |
Disabling the trace should work as follows:
-
It is essential to disable the trace from encoders associated with stopped harts as entering debug mode is NOT flushing any trace pipelines.
-
Disable and flush trace starting from Trace Encoders, then Trace Funnels and finally Trace Sinks or Trace Bridges.
-
Set
tr??Enable
= 0 and wait fortr??Enable
= 0 andtr??Empty
= 1 for each trace component. -
It is important to do it in that order as otherwise data may be lost.
-
-
Stop physical capture if PIB sink was enabled (trace probe dependent).
-
Read the trace.
-
For RAM Trace Sink read
trRamWP
- depending ontrRamWrap
bit, you may read trace from two ranges. -
For RAM Trace Sink in SRAM mode, set
trRamRP
and readtrRamData
multiple times. -
For RAM Trace Sink in SMEM mode, read trace from system memory using memory read.
-
For PIB Trace Sink read trace from trace probe.
-
For ATB Bridge, read trace using Coresight components (ETB/TMC/TPIU).
-
Decoding trace
-
Decoder (in most cases) must have access to code which is running on device either by reading it from device or from a file containing the code (binary/hex/srec/ELF).
-
The trace collected by trace probes can be read and decoded while a trace is being captured (this is called trace streaming mode).
-
There is no guarantee that the last trace packet is completed until the trace is properly flushed and disabled.
-
-
Decoding of the trace should never affect code being traced.
The value of trTeVerMajor
as 0 means this is the pre-ratified/initial version of this trace control interface.
Initially this specification was kept highly compatible, but after the decision to split all components into 4K regions it was very hard to track and list all changes and appropriate chapter was removed.
The migration path from 'ver 0' (for both IP providers and tool vendors) should not be hard as the main concepts remain unchanged.
Original donation from SiFive (which describes implementation of pre-ratified/initial version 0) can be found here: RISC-V-Trace-Control-Interface-Proposed-20200612.pdf
Important
|
Not all trace tools may support pre-ratified/initial version 0. But all such tools should reject a version 0 with a very clear message. |