Skip to content

Commit a43277c

Browse files
author
pascalgouedo
authored
Merge pull request #987 from pascalgouedo/dev_dd_pgo_doc
Added HWloop CSRs save/restore
2 parents 1f744c6 + a33cec0 commit a43277c

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

docs/source/corev_hw_loop.rst

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ At the end of the loop, the register %[i] contains 300 and the register %[j] con
142142

143143
.. _hwloop-exceptions_handlers:
144144

145-
Hardware loops impact on application, exceptions handlers and debugger
146-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
145+
Hardware loops impact on application, exception handlers and debug program
146+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
147147

148148
Application and ebreak/ecall exception handlers
149149
-----------------------------------------------
150150

151-
When an ebreak or an ecall instruction is used in an application, special care should be given for those instruction handlers in case they are placed as the last instruction of an HWLoop.
151+
When an ebreak or an ecall instruction is used in an application, special care should be given for their respective exception handler in case those instructions are the last one of an HWLoop.
152152
Those handlers should manage MEPC and lpcountX CSRs updates because an hw loop early-exit could happen if not done.
153153

154154
At the end of the handlers after restoring the context/CSRs, a piece of smart code should be added with following highest to lowest order of priority:
@@ -167,9 +167,7 @@ Interrupt handlers
167167
------------------
168168

169169
When an interrupt is happening on the last HWLoop instruction, its execution is cancelled, its address is saved in MEPC and its execution will be resumed when returning from interrupt handler.
170-
There is nothing special to be done in those interrupt handlers with respect to MEPC and lpcountX updates, they will be correctly managed by design when executing this last HWLoop instruction after interrupt handler execution.
171-
172-
Moreover since hardware loop could be used in interrupt routine, the registers have to be saved (resp. restored) at the beginning (resp. end) of the interrupt routine together with the general purpose registers.
170+
There is nothing special to be done in those interrupt handlers with respect to MEPC and lpcountX updates (except HWloop CSRs save/restore mentioned below), they will be correctly managed by design when executing this last HWLoop instruction after interrupt handler execution.
173171

174172
Illegal instruction exception handler
175173
-------------------------------------
@@ -179,11 +177,17 @@ Depending if an application is going to resume or not after Illegal instruction
179177
Debugger
180178
--------
181179

182-
If ebreak is used to enter in Debug Mode (:ref:`ebreak_scenario_2`) and put at the last instruction location of an HWLoop (not very likely to happen), same management than above should be done but on DPC rather than on MEPC.
180+
If ebreak is used to enter in Debug Mode (:ref:`ebreak_scenario_2`) and put at the last instruction location of an HWLoop, same management than above should be done but on DPC rather than on MEPC.
183181

184182
When ebreak instruction is used as Software Breakpoint by a debugger when in debug mode and is placed at the last instruction location of an HWLoop in instruction memory, no special management is foreseen.
185183
When executing the Software Breakpoint/ebreak instruction, control is given back to the debugger which will manage the different cases.
186184
For instance in Single-Step case, original instruction is put back in instruction memory, a Single-Step command is executed on this last instruction (with desgin updating PC and lpcountX to correct values) and Software Breakpoint/ebreak is put back by the debugger in memory.
187185

188-
When ecall instruction is used by a debugger to execute System Calls and is placed at the last instruction location of an HWLoop in instruction memory, debugger ecall handler in debug rom should do the same than described above for application case.
186+
When ecall instruction is used by a debugger to execute System Calls and is placed at the last instruction location of an HWLoop in instruction memory, debugger ecall handler in debug program should do the same than described above for application case.
187+
188+
HWloop CSRs save and restore
189+
----------------------------
190+
191+
As synchronous/asynchronous exception or a debug event happening during HWloop execution is interrupting the normal HWloop execution, special care should be given to HWloop CSRs in case any exception handler or debug program is going to use HWloop feature (or even just call functions using them like memmove, memcpy...).
189192

193+
So HWloop CSRs save/restore should be added together with the general purpose registers to exception handlers or debug program.

0 commit comments

Comments
 (0)