-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow debug module to be at a base address other than 0 (#2649)
- Loading branch information
1 parent
d894612
commit 9699c48
Showing
8 changed files
with
238 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// See LICENSE.SiFive for license details. | ||
|
||
#include "riscv-pk/encoding.h" | ||
|
||
#ifndef CSR_DSCRATCH1 | ||
#define CSR_DSCRATCH1 (CSR_DSCRATCH + 1) | ||
#endif | ||
|
||
// These are implementation-specific addresses in the Debug Module, relative to entry | ||
#define HALTED -0x700 // 0x100 | ||
#define GOING -0x6FC // 0x104 | ||
#define RESUMING -0x6F8 // 0x108 | ||
#define EXCEPTION -0x6F4 // 0x10C | ||
|
||
// Region of memory where each hart has 1 byte to read. | ||
#define FLAGS -0x400 // 0x400 | ||
#define FLAG_GO 0 | ||
#define FLAG_RESUME 1 | ||
|
||
.option norvc | ||
.global entry | ||
.global exception | ||
|
||
// Entry location on ebreak, Halt, or Breakpoint | ||
// It is the same for all harts. They branch when | ||
// their GO or RESUME bit is set. | ||
|
||
// 0x800 | ||
entry: | ||
csrw CSR_DSCRATCH1, s1 // s1=s1, ds1=s1: Save s1 to use as base pointer | ||
j _entry | ||
|
||
// 0x808 | ||
exception: | ||
csrrw s1, CSR_DSCRATCH1, s1 // s1=base, ds1=s1 | ||
sw zero, EXCEPTION(s1) // Let debug module know you got an exception. | ||
|
||
_entry: | ||
// This fence is required because the execution may have written something | ||
// into the Abstract Data or Program Buffer registers. | ||
fence | ||
csrw CSR_DSCRATCH, s0 // Save s0 to allow signaling MHARTID | ||
la s1, entry // s1 = base (0x800 into debug region) | ||
|
||
// We continue to let the hart know that we are halted in order that | ||
// a DM which was reset is still made aware that a hart is halted. | ||
// We keep checking both whether there is something the debugger wants | ||
// us to do, or whether we should resume. | ||
entry_loop: | ||
csrr s0, CSR_MHARTID | ||
sw s0, HALTED(s1) | ||
add s0, s0, s1 // s0=base + hartid | ||
lbu s0, FLAGS(s0) // 1 byte flag per hart. Only one hart advances here. | ||
andi s0, s0, (1 << FLAG_GO) | (1 << FLAG_RESUME) | ||
beqz s0, entry_loop // Loop until either GO or RESUME is set. | ||
|
||
andi s0, s0, (1 << FLAG_GO) | ||
beqz s0, _resume // If GO is clear at this point, RESUME must be set. | ||
|
||
csrr s0, CSR_DSCRATCH // Restore s0 here | ||
|
||
//TODO: 0x48 is a hack for (icache-entry) constant | ||
jalr zero, 0x48(s1) // Rocket-Chip has a specific hack which is that jalr in | ||
// Debug Mode will flush the I-Cache. We need that so that the | ||
// remainder of the variable instructions will be what Debug Module | ||
// intends. | ||
icache: | ||
sw zero, GOING(s1) // When debug module sees this write, the GO flag is reset. | ||
csrrw s1, CSR_DSCRATCH1, s1 // s1=s1, ds1=base | ||
j whereto | ||
|
||
_resume: | ||
csrr s0, CSR_MHARTID | ||
sw s0, RESUMING(s1) // When Debug Module sees this write, the RESUME flag is reset. | ||
csrr s0, CSR_DSCRATCH // Restore s0 | ||
csrr s1, CSR_DSCRATCH1 // Restore s1 | ||
dret | ||
|
||
// END OF ACTUAL "ROM" CONTENTS. BELOW IS JUST FOR LINKER SCRIPT. | ||
|
||
.section .whereto | ||
whereto: | ||
nop | ||
// Variable "ROM" This is : jal x0 abstract, jal x0 program_buffer, | ||
// or jal x0 resume, as desired. | ||
// Debug Module state machine tracks what is 'desired'. | ||
// We don't need/want to use jalr here because all of the | ||
// Variable ROM contents are set by | ||
// Debug Module before setting the OK_GO byte. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/scala/devices/debug/DebugRomNonzeroContents.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// This file was auto-generated by 'make publish' in debug/ directory. | ||
|
||
package freechips.rocketchip.devices.debug | ||
|
||
object DebugRomNonzeroContents { | ||
|
||
def apply() : Array[Byte] = { Array ( | ||
0x73, 0x90, 0x34, 0x7b, 0x6f, 0x00, 0xc0, 0x00, 0xf3, 0x94, 0x34, 0x7b, | ||
0x23, 0xa6, 0x04, 0x90, 0x0f, 0x00, 0xf0, 0x0f, 0x73, 0x10, 0x24, 0x7b, | ||
0x97, 0x04, 0x00, 0x00, 0x93, 0x84, 0x84, 0xfe, 0x73, 0x24, 0x40, 0xf1, | ||
0x23, 0xa0, 0x84, 0x90, 0x33, 0x04, 0x94, 0x00, 0x03, 0x44, 0x04, 0xc0, | ||
0x13, 0x74, 0x34, 0x00, 0xe3, 0x06, 0x04, 0xfe, 0x13, 0x74, 0x14, 0x00, | ||
0x63, 0x0c, 0x04, 0x00, 0x73, 0x24, 0x20, 0x7b, 0x67, 0x80, 0x84, 0x04, | ||
0x23, 0xa2, 0x04, 0x90, 0xf3, 0x94, 0x34, 0x7b, 0x6f, 0xf0, 0x1f, 0xab, | ||
0x73, 0x24, 0x40, 0xf1, 0x23, 0xa4, 0x84, 0x90, 0x73, 0x24, 0x20, 0x7b, | ||
0xf3, 0x24, 0x30, 0x7b, 0x73, 0x00, 0x20, 0x7b | ||
).map(_.toByte) } | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.