Monitor: wide 132x64 screen showing everything at once

On the 132x64 screen the monitor shows PC and all integer registers, all
float registers (hex and decimal) with FCSR decoded, mstatus/mepc/mcause/
mtval/cycle/instret and the breakpoint, 24 rows of disassembly beside the
stack, and 14 rows of memory, with changed registers highlighted; the 80x32
layout is unchanged. R takes float register names. The CPU's trap CSRs
start at 0, so reading them before the first trap no longer hangs the
simulated bus. send-hex accepts the prompt on any row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
brad ArantandClaude Opus 5.5 committed 2026-12-02 00:00:43 -08:00
1 parent 1e44ce4383
commit 8b4af2f574
10 files changed
+3644 -3373

No files matched your search

+4 -1
View File
@@ -166,7 +166,10 @@ All in C (plus a little assembly), compiled with GCC:
ulp), since ulp), since
newlib's bring in its stdio and malloc. newlib's bring in its stdio and malloc.
- `monitor/` — the machine-code monitor: memory, registers (integer and - `monitor/` — the machine-code monitor: memory, registers (integer and
floating point), step, breakpoints, a RISC-V disassembler and a two-pass floating point), step, breakpoints; on the 132 × 64 screen it shows
everything at once (all the integer and float registers, the float values
in decimal, the CSRs, the disassembly, the stack and the memory, with the
registers a step changed highlighted), a RISC-V disassembler and a two-pass
assembler that both use GNU as syntax (`.org`, `.word`, `.string`, assembler that both use GNU as syntax (`.org`, `.word`, `.string`,
`%hi`/`%lo`, `#` comments; the disassembly reads like `objdump`'s), Intel `%hi`/`%lo`, `#` comments; the disassembly reads like `objdump`'s), Intel
HEX in and out. HEX in and out.
+61 -2
View File
@@ -1019,6 +1019,65 @@ graphics come back exactly as they were.
breakpoint. breakpoint.
- The stack column shows the words at SP upwards. - The stack column shows the words at SP upwards.
**The wide screen.** When the terminal is 132 × 64, as it is from power-up,
the monitor uses all of it and shows everything at once, with nothing to
switch between. It goes by the width when it is entered, so after `ESC[?3l`
(80 × 32) it draws the screen above. Its left half:
```
RISC-V MONITOR
REGISTERS
PC 000065B4 ZERO 00000000 RA 00005364 SP 00013EF0
GP 0000F8B8 TP 00000000 T0 0000000A T1 0000000A
T2 00009000 S0 0000000A S1 000000AE A0 000000AE
...
T6 0000000A
CONTROL AND STATUS
MSTATUS 00001880 MEPC 00012008 MTVAL 00000000
MCAUSE 00000003 EBREAK
CYCLE 000000000002C110 INSTRET 000000000002C27A
BREAKPOINT NONE
ADDR WORD INSTRUCTION
> 065B4 80CFF06F j 0x55c0
065B8 8F8FD0EF jal 0x36b0
...
```
and its right half:
```
STOPPED BY MONITOR COMMAND
FLOAT REGISTERS
FT0 00000000 0 FA6 00000000 0
...
FA0 42900000 7.200000E+01 FS10 00000000 0
FA1 C2F6E979 -1.234560E+02 FS11 00000000 0
...
FA5 C7000000 -3.276800E+04 FT11 00000000 0
FCSR 00000001 ROUNDING RNE FLAGS -- -- -- -- NX
STACK
13EF0 00000000
...
```
- **Registers:** the PC and all 32 integer registers by name, and all 32 float
registers by their ABI names, each as its bit pattern and as a number
(to 7 digits). FCSR is shown whole and split into its rounding mode and
its five flags (`NV` invalid, `DZ` divide by zero, `OF` overflow, `UF`
underflow, `NX` inexact), a letter pair for each that is set.
- **After a step,** or whenever the monitor comes back, the registers the
program changed since the monitor last showed them are in bright yellow.
- **Control and status:** `mstatus`, `mepc`, `mcause` (with what it means),
`mtval`, the `cycle` and `instret` counters, and the breakpoint.
- **Below them:** 24 rows of disassembly with the stack beside it, and 14 rows
of memory, always there. `F` has nothing to switch, so it just says so; `M`
and `D`, the arrow keys and Page Up and Page Down move the windows as on
the narrow screen, and `DIR` and `ASM`'s errors use the memory window until
`M`.
### Commands ### Commands
Type a command on the bottom line and press Enter. Numbers are in hex, with Type a command on the bottom line and press Enter. Numbers are in hex, with
@@ -1035,8 +1094,8 @@ or without `0x`.
| `D addr` | Show the disassembly from *addr* (`D` alone: from PC) | | `D addr` | Show the disassembly from *addr* (`D` alone: from PC) |
| `M addr` | Show memory from *addr* | | `M addr` | Show memory from *addr* |
| `E addr bytes…` | Write bytes into memory: `E 12000 13 05 10 04` | | `E addr bytes…` | Write bytes into memory: `E 12000 13 05 10 04` |
| `R reg=value` | Set PC or a register, by name or number: `R A0=1234`, `R X10=1234`; a float register as its bit pattern: `R F1=3FC00000` (1.5), or `R FCSR=0` | | `R reg=value` | Set PC or a register, by name or number: `R A0=1234`, `R X10=1234`; a float register as its bit pattern, by number or name: `R F1=3FC00000` (1.5), `R FA0=3FC00000`, or `R FCSR=0` |
| `F` | Show the float registers F0–F31 and FCSR, as bit patterns, in the memory window (`M` brings the memory back) | | `F` | On the 80 × 32 screen, show the float registers F0–F31 and FCSR, as bit patterns, in the memory window (`M` brings the memory back); the 132 × 64 screen always shows them |
| `SAVE "NAME" start end` | Save memory *start* to *end* (inclusive) to a file in flash | | `SAVE "NAME" start end` | Save memory *start* to *end* (inclusive) to a file in flash |
| `LOAD "NAME"` | Load a memory file back to where it was saved from | | `LOAD "NAME"` | Load a memory file back to where it was saved from |
| `LOAD "NAME" addr` | Load it at *addr* instead (A000 or above) | | `LOAD "NAME" addr` | Load it at *addr* instead (A000 or above) |
Binary file not shown.
+2 -2
View File
@@ -463,7 +463,7 @@ enum {
P_LI, P_LA, P_MV, P_NOT, P_NEG, P_SEQZ, P_SNEZ, P_SLTZ, P_SGTZ, P_J, P_JR, P_RET, P_LI, P_LA, P_MV, P_NOT, P_NEG, P_SEQZ, P_SNEZ, P_SLTZ, P_SGTZ, P_J, P_JR, P_RET,
P_CALL, P_BZ, P_BZS, P_BSW, P_CSRR, P_CSRW, P_CSRWI, P_FR, P_FS P_CALL, P_BZ, P_BZS, P_BSW, P_CSRR, P_CSRW, P_CSRWI, P_FR, P_FS
}; };
struct ins { char name[8]; u8 f; u32 base; }; struct ins { char name[7]; u8 f; u32 base; }; /* 12 bytes: a 7-letter name has no 0 */
static const struct ins itab[] = { static const struct ins itab[] = {
{ "ADD", F_R, 0x00000033 }, { "SUB", F_R, 0x40000033 }, { "SLL", F_R, 0x00001033 }, { "ADD", F_R, 0x00000033 }, { "SUB", F_R, 0x40000033 }, { "SLL", F_R, 0x00001033 },
{ "SLT", F_R, 0x00002033 }, { "SLTU", F_R, 0x00003033 }, { "XOR", F_R, 0x00004033 }, { "SLT", F_R, 0x00002033 }, { "SLTU", F_R, 0x00003033 }, { "XOR", F_R, 0x00004033 },
@@ -740,7 +740,7 @@ static void a_line(char *s)
return; return;
} }
for (m = 0; m < NINS; m++) for (m = 0; m < NINS; m++)
if (!strncmp(w, itab[m].name, 8)) break; if (!strncmp(w, itab[m].name, 7) && !w[7]) break;
if (m == NINS) { a_fail("UNKNOWN INSTRUCTION"); return; } if (m == NINS) { a_fail("UNKNOWN INSTRUCTION"); return; }
a_split(); a_split();
if (a_err) return; if (a_err) return;
Binary file not shown.
+197 -49
View File
@@ -411,26 +411,41 @@ int main(int argc, char **argv)
/* ------------------------------------------------------------- screen */ /* ------------------------------------------------------------- screen */
static void puts_(const char *s) { while (*s) putc_(*s++); } static void puts_(const char *s) { while (*s) putc_(*s++); }
static void esc_n(u8 n) /* 1 to 3 digits */
{
if (n >= 100) putc_('0' + n / 100);
if (n >= 10) putc_('0' + n / 10 % 10);
putc_('0' + n % 10);
}
static void at(u8 r, u8 c) /* r, c from 0 */ static void at(u8 r, u8 c) /* r, c from 0 */
{ {
char b[12], *p = b; putc_(27); putc_('[');
*p++ = 27; *p++ = '['; esc_n(r + 1); putc_(';'); esc_n(c + 1); putc_('H');
if (r >= 9) *p++ = '0' + (r + 1) / 10;
*p++ = '0' + (r + 1) % 10; *p++ = ';';
if (c >= 9) *p++ = '0' + (c + 1) / 10;
*p++ = '0' + (c + 1) % 10; *p++ = 'H'; *p = 0;
puts_(b);
} }
static void sgr(const char *s) { putc_(27); putc_('['); puts_(s); putc_('m'); } static void sgr(const char *s) { putc_(27); putc_('['); puts_(s); putc_('m'); }
static void flush_line(void) { *lp = 0; puts_(line); } static void flush_line(void) { *lp = 0; puts_(line); }
static void clr_eol(void) { puts_("\033[K"); } static void clr_eol(void) { puts_("\033[K"); }
/* --------------------------------------------------------------- state */ /* --------------------------------------------------------------- state */
#define REG_TOP 2 /* six rows of registers */ /* The screen's layout: 80x32 (narrow) or 132x64 (wide, everything at once),
#define DIS_ROWS 12 chosen from port 0 bit 2 when the monitor is entered. */
#define MEM_ROWS 6 #define REG_TOP 2 /* narrow: six rows of registers */
#define DIS_TOP 9 static u8 wide;
#define MEM_TOP 22 static u8 DIS_ROWS, MEM_ROWS, DIS_TOP, MEM_TOP, STK_COL, HELP_ROW, CMD_ROW, MSG_COL;
static void layout(void)
{
wide = con_stat & 4;
DIS_ROWS = wide ? 24 : 12;
MEM_ROWS = wide ? 14 : 6;
DIS_TOP = wide ? 22 : 9;
MEM_TOP = wide ? 48 : 22;
STK_COL = wide ? 66 : 54;
HELP_ROW = wide ? 62 : 28;
CMD_ROW = wide ? 63 : 29;
MSG_COL = wide ? 66 : 40;
}
static u32 px[32], pf[32]; /* the registers when last shown */
static u8 pv; /* ... saved */
static u32 dis_a; /* first line of the disassembly window */ static u32 dis_a; /* first line of the disassembly window */
static u32 mem_a; /* first line of the memory window */ static u32 mem_a; /* first line of the memory window */
@@ -454,9 +469,125 @@ static void s_rv(const char *n, u32 v)
s_str(n); s_ch(' '); s_h8(v); s_ch(' '); s_str(n); s_ch(' '); s_h8(v); s_ch(' ');
} }
/* a float's value in decimal, " 1.500000E+00", from its bits, without the
FPU (the monitor leaves it alone): 7 digits, the last may be 1 out */
static void s_fdec(u32 b)
{
u32 m = b & 0x7FFFFF, x;
i32 e = b >> 23 & 255, d = 0;
u8 k;
char g[11];
s_ch(b >> 31 ? '-' : ' ');
if (e == 255) { s_str(m ? "NAN" : "INF"); return; }
if (e) m |= 0x800000; else e = 1;
if (!m) { s_str("0"); return; }
x = m;
for (e -= 150; e > 0; e--) /* x * 2^e * 10^d, x kept large */
if (x < 0x80000000u) x <<= 1; else { x /= 10; d++; e++; }
for (; e < 0; e++)
if (x < 0x19999999u) { x *= 10; d--; e--; } else x >>= 1;
while (x >= 100000000u) { x = (x + (x >= 1000000000u ? 0 : 5)) / 10; d++; } /* 8 digits */
x = (x + 5) / 10; d++; /* 7, rounded */
if (x >= 10000000u) { x /= 10; d++; }
for (k = 0; k < 7; k++) { g[6 - k] = '0' + x % 10; x /= 10; }
d += 6;
s_ch(g[0]); s_ch('.');
for (k = 1; k < 7; k++) s_ch(g[k]);
s_ch('E'); s_ch(d < 0 ? '-' : '+');
if (d < 0) d = -d;
s_ch('0' + d / 10); s_ch('0' + d % 10);
}
static u32 csr_mepc(void) { u32 v; __asm__ volatile("csrr %0, mepc" : "=r"(v)); return v; }
static u32 csr_mstatus(void) { u32 v; __asm__ volatile("csrr %0, mstatus" : "=r"(v)); return v; }
static u32 csr_mcause(void) { u32 v; __asm__ volatile("csrr %0, mcause" : "=r"(v)); return v; }
static u32 csr_mtval(void) { u32 v; __asm__ volatile("csrr %0, mtval" : "=r"(v)); return v; }
static void s_cycle(void)
{
u32 h, l;
__asm__ volatile("csrr %0, cycleh; csrr %1, cycle" : "=r"(h), "=r"(l));
s_h8(h); s_h8(l);
}
static void s_instret(void)
{
u32 h, l;
__asm__ volatile("csrr %0, instreth; csrr %1, instret" : "=r"(h), "=r"(l));
s_h8(h); s_h8(l);
}
static const char *cause_text(u32 c);
/* the line built so far at r, c: highlighted when it changed */
static void w_put(u8 r, u8 c, u8 changed)
{
at(r, c);
if (changed) sgr("1;33");
flush_line();
if (changed) sgr("0");
}
static void w_head(u8 r, u8 c, const char *t) { at(r, c); sgr("36"); puts_(t); sgr("0"); }
/* 132x64: the integer registers, the float registers, the CSRs */
static void draw_wregs(void)
{
u8 k;
u32 v;
static const char fl[] = "NVDZOFUFNX";
w_head(2, 1, "REGISTERS");
for (k = 0; k < 33; k++) {
lp = line;
s_ch(' '); /* names of up to 4 letters (ZERO) */
s_rv(k ? regn[k - 1] : "PC", k ? u.x[k - 1] : u.pc);
w_put(3 + k / 4, 1 + (k & 3) * 15, k > 1 && pv && px[k - 1] != u.x[k - 1]);
}
w_head(2, 66, "FLOAT REGISTERS");
for (k = 0; k < 32; k++) {
char n[6];
lp = n; s_freg(k); *lp = 0;
if (!u.fs) { if (!k) { at(3, 66); puts_("THE FPU IS OFF (MSTATUS.FS = 0)"); } continue; }
lp = line;
if (n[3] == 0) s_ch(' '); /* FT0 and FT10 in line */
s_rv(n, u.f[k]);
s_fdec(u.f[k]);
w_put(3 + (k & 15), 66 + (k >> 4) * 33, pv && pf[k] != u.f[k]);
}
if (u.fs) {
lp = line;
s_str("FCSR "); s_h8(u.fcsr); s_str(" ROUNDING "); s_str(rmn[u.fcsr >> 5 & 7] ? rmn[u.fcsr >> 5 & 7] : "?");
s_str(" FLAGS");
for (k = 0; k < 5; k++) {
u8 on = u.fcsr >> (4 - k) & 1;
s_ch(' '); s_ch(on ? fl[2 * k] : '-'); s_ch(on ? fl[2 * k + 1] : '-');
}
at(19, 66); flush_line();
}
w_head(13, 1, "CONTROL AND STATUS");
lp = line;
/* u.status is saved only for a trap; an NMI leaves mstatus as it was */
s_str("MSTATUS "); s_h8(u.how ? u.status : csr_mstatus()); s_str(" MEPC "); s_h8(csr_mepc());
s_str(" MTVAL "); s_h8(csr_mtval());
at(14, 1); flush_line();
v = csr_mcause();
{
const char *ct = cause_text(v);
lp = line;
s_str("MCAUSE "); s_h8(v); s_ch(' '); s_str(ct);
}
while (lp < line + 58) s_ch(' ');
at(15, 1); flush_line();
lp = line;
s_str("CYCLE "); s_cycle(); s_str(" INSTRET "); s_instret();
at(16, 1); flush_line();
lp = line;
s_str("BREAKPOINT ");
if (bp_set) s_hex(bp, 5); else s_str("NONE ");
at(17, 1); flush_line();
}
static void draw_regs(void) static void draw_regs(void)
{ {
u8 r, i; u8 r, i;
if (wide) { draw_wregs(); return; }
for (r = 0; r < 6; r++) { for (r = 0; r < 6; r++) {
lp = line; lp = line;
for (i = 0; i < 6; i++) { for (i = 0; i < 6; i++) {
@@ -479,7 +610,7 @@ static void draw_dis(void)
s_hex(a, 5); s_str(" "); s_hex(a, 5); s_str(" ");
s_h8(rd32(a)); s_str(" "); s_h8(rd32(a)); s_str(" ");
disasm(a); disasm(a);
while (lp < line + 50) s_ch(' '); while (lp < line + STK_COL - 4) s_ch(' ');
at(DIS_TOP + r, 0); at(DIS_TOP + r, 0);
if (a == pc) sgr("1;33;44"); if (a == pc) sgr("1;33;44");
flush_line(); flush_line();
@@ -492,11 +623,11 @@ static void draw_stack(void)
{ {
u32 s = u.x[2]; u32 s = u.x[2];
u8 r; u8 r;
at(DIS_TOP - 1, 54); sgr("36"); puts_("STACK"); sgr("0"); at(DIS_TOP - 1, STK_COL); sgr("36"); puts_("STACK"); sgr("0");
for (r = 0; r < DIS_ROWS; r++) { for (r = 0; r < DIS_ROWS; r++) {
lp = line; lp = line;
s_hex(s, 5); s_str(" "); s_h8(rd32(s)); s_hex(s, 5); s_str(" "); s_h8(rd32(s));
at(DIS_TOP + r, 54); flush_line(); clr_eol(); at(DIS_TOP + r, STK_COL); flush_line(); clr_eol();
s += 4; s += 4;
} }
} }
@@ -526,7 +657,7 @@ static void draw_mem(void)
{ {
u32 a = mem_a; u32 a = mem_a;
u8 r, j, c; u8 r, j, c;
if (show_f) { draw_fregs(); return; } if (show_f && !wide) { draw_fregs(); return; }
at(MEM_TOP - 1, 0); sgr("36"); puts_(" MEMORY"); sgr("0"); clr_eol(); at(MEM_TOP - 1, 0); sgr("36"); puts_(" MEMORY"); sgr("0"); clr_eol();
for (r = 0; r < MEM_ROWS; r++) { for (r = 0; r < MEM_ROWS; r++) {
lp = line; lp = line;
@@ -539,22 +670,27 @@ static void draw_mem(void)
} }
} }
/* an mcause value in words (in t, so not while line is being built) */
static const char *cause_text(u32 c) /* uses lp: call before building a line */
{
static char t[16];
const char *r = t;
if (c >> 31) { lp = t; s_str("INTERRUPT "); s_udec(c & 31); *lp = 0; }
else switch (c) {
case 0: r = "MISALIGNED JUMP"; break;
case 2: r = "ILLEGAL INSTRUCTION"; break;
case 3: r = "EBREAK"; break;
case 4: r = "MISALIGNED LOAD"; break;
case 6: r = "MISALIGNED STORE"; break;
case 11: r = "ECALL"; break;
default: lp = t; s_str("TRAP "); s_udec(c); *lp = 0;
}
return r;
}
static const char *why_text(void) static const char *why_text(void)
{ {
static char t[32]; if (u.how) return cause_text(u.cause);
if (u.how) {
u32 c = u.cause;
if (c >> 31) { lp = t; s_str("INTERRUPT "); s_udec(c & 31); *lp = 0; return t; }
switch (c) {
case 0: return "MISALIGNED JUMP";
case 2: return "ILLEGAL INSTRUCTION";
case 3: return "EBREAK";
case 4: return "MISALIGNED LOAD";
case 6: return "MISALIGNED STORE";
case 11: return "ECALL";
default: lp = t; s_str("TRAP "); s_udec(c); *lp = 0; return t;
}
}
switch (why_in) { switch (why_in) {
case 1: return "PAUSE KEY"; case 1: return "PAUSE KEY";
case 2: return "MONITOR COMMAND"; case 2: return "MONITOR COMMAND";
@@ -567,23 +703,28 @@ static const char *why_text(void)
static void draw_all(void) static void draw_all(void)
{ {
u8 w = wide ? 132 : 80, n;
puts_("\033[2J"); puts_("\033[2J");
at(0, 0); sgr("1;37;44"); at(0, 0); sgr("1;37;44");
lp = line; {
s_str(" RISC-V MONITOR"); const char *wt = why_text();
while (lp < line + 50) s_ch(' '); lp = line;
s_str("STOPPED BY "); s_str(" RISC-V MONITOR");
s_str(why_text()); while (lp < line + (wide ? 66 : 50)) s_ch(' ');
while (lp < line + 80) s_ch(' '); s_str("STOPPED BY ");
s_str(wt);
}
*lp = 0; *lp = 0;
line[80] = 0; n = lp - line;
puts_(line); sgr("0"); puts_(line);
while (n++ < w) putc_(' ');
sgr("0");
draw_regs(); draw_regs();
at(DIS_TOP - 1, 0); sgr("36"); puts_(" ADDR WORD INSTRUCTION"); sgr("0"); at(DIS_TOP - 1, 0); sgr("36"); puts_(" ADDR WORD INSTRUCTION"); sgr("0");
draw_dis(); draw_dis();
draw_stack(); draw_stack();
draw_mem(); draw_mem();
at(28, 0); sgr("36"); at(HELP_ROW, 0); sgr("36");
puts_(" ENTER step O over G go X exit B bp D/M addr E edit R reg F fp ? help"); puts_(" ENTER step O over G go X exit B bp D/M addr E edit R reg F fp ? help");
sgr("0"); sgr("0");
} }
@@ -609,7 +750,7 @@ static u8 get_hex(u32 *v)
static void show_msg(void) static void show_msg(void)
{ {
at(29, 40); clr_eol(); at(CMD_ROW, MSG_COL); clr_eol();
if (msg) { sgr(msg_err ? "1;31" : "32"); puts_(msg); sgr("0"); } if (msg) { sgr(msg_err ? "1;31" : "32"); puts_(msg); sgr("0"); }
} }
@@ -619,9 +760,9 @@ static const char *prompt = "> ";
static u8 read_cmd(void) static u8 read_cmd(void)
{ {
u8 n = 0, c; u8 n = 0, c;
at(29, 0); puts_(prompt); clr_eol(); at(CMD_ROW, 0); puts_(prompt); clr_eol();
show_msg(); show_msg();
at(29, strlen(prompt)); at(CMD_ROW, strlen(prompt));
puts_("\033[?25h"); puts_("\033[?25h");
for (;;) { for (;;) {
c = getk(); c = getk();
@@ -1053,14 +1194,16 @@ static u8 set_reg(void)
u8 r; u8 r;
u32 v; u32 v;
skip_sp(); skip_sp();
if (cp[0] == 'F' && ((cp[1] >= '0' && cp[1] <= '9') || !memcmp(cp, "FCSR", 4))) { { /* F0-F31, FT0, FA0 ..., FCSR */
char n[6];
u8 k = 0;
while (k < 5 && cp[k] && cp[k] != '=' && cp[k] != ' ') { n[k] = cp[k]; k++; }
n[k] = 0;
r = !strcmp(n, "FCSR") ? 32 : a_fregname(n);
}
if (r != 0xFF) {
if (!u.fs) return 0; /* not saved: the FPU is off */ if (!u.fs) return 0; /* not saved: the FPU is off */
if (cp[1] == 'C') { cp += 4; r = 32; } while (*cp && *cp != '=' && *cp != ' ') cp++;
else {
r = *++cp - '0';
if (*++cp >= '0' && *cp <= '9') r = r * 10 + (*cp++ - '0');
if (r > 31) return 0;
}
skip_sp(); skip_sp();
if (*cp == '=') cp++; if (*cp == '=') cp++;
if (!get_hex(&v)) return 0; if (!get_hex(&v)) return 0;
@@ -1203,6 +1346,7 @@ static u8 command(void)
draw_all(); draw_all();
return 0; return 0;
case 'F': case 'F':
if (wide) { msg = "THE FLOAT REGISTERS ARE ALWAYS SHOWN"; return 0; }
show_f = 1; show_f = 1;
draw_mem(); draw_mem();
msg = "M TO SHOW MEMORY AGAIN"; msg = "M TO SHOW MEMORY AGAIN";
@@ -1243,6 +1387,7 @@ void mon_main(void)
} }
steps = 0; steps = 0;
go_after = 0; go_after = 0;
layout();
if (!dis_shows(u.pc)) dis_a = u.pc; if (!dis_shows(u.pc)) dis_a = u.pc;
puts_("\0337\033[?47h\033[?25l"); /* save the cursor, alternate screen */ puts_("\0337\033[?47h\033[?25l"); /* save the cursor, alternate screen */
@@ -1260,6 +1405,9 @@ void mon_main(void)
else if (k == 'Q') mem_a += 16 * MEM_ROWS; else if (k == 'Q') mem_a += 16 * MEM_ROWS;
if (k == 'U' || k == 'N') draw_dis(); else draw_mem(); if (k == 'U' || k == 'N') draw_dis(); else draw_mem();
} }
memcpy(px, u.x, sizeof px); /* to show what the program changes */
memcpy(pf, u.f, sizeof pf);
pv = 1;
puts_("\033[?25h\033[?47l\0338"); puts_("\033[?25h\033[?47l\0338");
} }
#endif #endif
+3313 -3313
View File
File diff suppressed because it is too large. Load diff
+4 -2
View File
@@ -247,11 +247,13 @@ module rv32_cpu #(
// ------------------------------------------------------------------ // ------------------------------------------------------------------
// CSRs // CSRs
reg mie_b, mpie_b; // mstatus reg mie_b, mpie_b; // mstatus
reg [31:0] mie_r, mtvec, mscratch, mepc, mcause, mtval; // 0 at power-up (no logic: the flip-flops' initial state), so the
// monitor shows 0 rather than whatever they held before the first trap
reg [31:0] mie_r = 0, mtvec = 0, mscratch = 0, mepc = 0, mcause = 0, mtval = 0;
reg [63:0] mcycle, minstret; reg [63:0] mcycle, minstret;
reg tsel, mte, mpte; reg tsel, mte, mpte;
reg nmie, stepped; reg nmie, stepped;
reg [31:0] mnscratch, mnepc, mncause; reg [31:0] mnscratch = 0, mnepc = 0, mncause = 0;
reg [1:0] t_m, t_x, t_s, t_l; reg [1:0] t_m, t_x, t_s, t_l;
reg [31:0] t_a0, t_a1; reg [31:0] t_a0, t_a1;
reg [31:0] irq_r; reg [31:0] irq_r;
+59 -1
View File
@@ -113,6 +113,14 @@ module tb_terminal;
end end
endfunction endfunction
function [9:0] cellattr(input integer rr, input integer cc); // its colours
reg [17:0] v;
begin
v = dut.screen.cell_at((dut.alt_scr ? 8448 : 0) + rr * 132 + cc);
cellattr = v[17:8];
end
endfunction
function [7:0] cellch(input integer rr, input integer cc); function [7:0] cellch(input integer rr, input integer cc);
reg [7:0] v; reg [7:0] v;
begin begin
@@ -381,6 +389,56 @@ module tb_terminal;
cellraw(8, 104), cellraw(8, 106), cellraw(9, 0)); cellraw(8, 104), cellraw(8, 106), cellraw(9, 0));
errors = errors + 1; errors = errors + 1;
end end
// ---- the monitor's wide layout: everything at once
uart_str("\025MONITOR\015");
wait_at(0, 66, "STOPPED BY MONITOR COMMAND");
wait_at(2, 1, "REGISTERS");
wait_at(3, 1, " PC ");
wait_at(3, 16, " ZERO 00000000");
wait_at(2, 66, "FLOAT REGISTERS");
wait_at(3, 66, " FT0 ");
wait_at(18, 99, "FT11 ");
wait_at(19, 66, "FCSR ");
wait_at(13, 1, "CONTROL AND STATUS");
wait_at(14, 1, "MSTATUS ");
wait_at(15, 1, "MCAUSE ");
wait_at(16, 1, "CYCLE ");
wait_at(17, 1, "BREAKPOINT NONE");
wait_at(21, 0, " ADDR WORD INSTRUCTION");
wait_at(22, 0, ">");
wait_at(21, 66, "STACK");
wait_at(47, 0, " MEMORY");
wait_at(48, 1, " ");
wait_at(62, 0, " ENTER step");
wait_at(63, 0, "> ");
// a float register, in hex and decimal, without asking for it (F)
// (each command redraws the whole screen: give it time before the next)
uart_str("R FA0=3FC00000\015");
wait_at(13, 66, " FA0 3FC00000 1.500000E+00");
#300_000_000;
uart_str("R FA1=C2F6E979\015");
wait_at(14, 66, " FA1 C2F6E979 -1.234560E+02");
#300_000_000;
// a step that changes A0 shows it highlighted (A1 beside it is not)
uart_str("A 12000\015"); #300_000_000;
uart_str("LI A0,66\015"); #300_000_000;
uart_str("\015"); #300_000_000;
uart_str("R PC=12000\015"); #300_000_000;
uart_str("\015");
wait_at(0, 66, "STOPPED BY STEP");
wait_at(5, 46, " A0 00000042");
wait_at(3, 6, "00012004");
// (ZERO is never highlighted, and LI leaves A1 alone)
if (cellattr(5, 52) != cellattr(3, 23) && cellattr(6, 7) == cellattr(3, 23))
$display("PASS a register a step changed is highlighted");
else begin
$display("FAIL highlight: A0 %h, A1 %h, ZERO %h", cellattr(5, 52), cellattr(6, 7), cellattr(3, 23));
errors = errors + 1;
end
// F says the float registers are already there; M is the memory
#300_000_000;
uart_str("F\015");
wait_at(63, 66, "THE FLOAT REGISTERS ARE ALWAYS SHOWN");
if (errors == 0) $display("ALL TESTS PASSED"); if (errors == 0) $display("ALL TESTS PASSED");
else $display("%0d TESTS FAILED", errors); else $display("%0d TESTS FAILED", errors);
$finish; $finish;
@@ -429,7 +487,7 @@ module tb_terminal;
"OUT 112,1:OUT 113,108:OUT 114,0:OUT 115,158:OUT 116,1:OUT 117,1\015"}); "OUT 112,1:OUT 113,108:OUT 114,0:OUT 115,158:OUT 116,1:OUT 117,1\015"});
uart_str({"FILL 0,200,319,239,4:OUT 112,2:OUT 113,54:OUT 114,1:OUT 115,230:", uart_str({"FILL 0,200,319,239,4:OUT 112,2:OUT 113,54:OUT 114,1:OUT 115,230:",
"OUT 116,2:OUT 117,3\015"}); "OUT 116,2:OUT 117,3\015"});
#40_000_000; #300_000_000;
@(posedge vs); @(posedge vs); @(posedge vs); @(posedge vs); @(posedge vs); @(posedge vs);
uart_str("LOCATE 30,1:PRINT INP(128);INP(129);INP(132)\015"); uart_str("LOCATE 30,1:PRINT INP(128);INP(129);INP(132)\015");
wait_row(29, " 3 0 4"); wait_row(29, " 3 0 4");
+4 -3
View File
@@ -74,9 +74,10 @@ def wait_for(pattern, timeout=10.0):
raise SystemExit("no answer from the board (waiting for %r); last output: %r" % (pattern, buf[-200:])) raise SystemExit("no answer from the board (waiting for %r); last output: %r" % (pattern, buf[-200:]))
# the monitor's command line, redrawn after each command; its message comes # the monitor's command line, redrawn after each command (row 30 on the 80x32
# after the prompt, and the cursor is turned back on last # screen, 64 on the 132x64 one); its message comes after the prompt, and the
PROMPT = rb"\x1b\[30;1H> .*?\x1b\[\?25h" # cursor is turned back on last
PROMPT = rb"\x1b\[\d+;1H> .*?\x1b\[\?25h"
send("\r") send("\r")
time.sleep(0.3) time.sleep(0.3)
if not a.no_date: # the file gets the PC's date if not a.no_date: # the file gets the PC's date