Skip to content

Commit 436100b

Browse files
committed
Finish implementing accumulator tracking
1 parent 4088578 commit 436100b

File tree

11 files changed

+304
-175
lines changed

11 files changed

+304
-175
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ The MLOGSYS instruction is used for simple system controls, including `printchar
125125

126126
The `mlogsys.icache` instruction uses register _rs1_ as the number of bytes to decode. This can be generated by using a linker script to find the end address of the `.text` section and load it using `li`. The actual number of bytes decoded will be the smallest of _rs1_, the size of the icache, and the size of ROM.
127127

128+
FIXME: `printflush` and `drawflush` are broken with subframe :(
129+
128130
| funct12 | rs1 | name |
129131
| ------- | ------- | --------------------- |
130132
| 0 | length | Initialize ROM icache |

coremark/mlogv32/ee_printf.c

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -660,22 +660,43 @@ ee_vsprintf(char *buf, const char *fmt, va_list args)
660660
return str - buf;
661661
}
662662

663-
static unsigned int print_x = 7;
664-
static unsigned int print_y = 508;
663+
typedef struct {
664+
unsigned char rhr_thr[4];
665+
unsigned char ier[4];
666+
unsigned char isr_fcr[4];
667+
unsigned char lcr[4];
668+
unsigned char mcr[4];
669+
unsigned char lsr[4];
670+
unsigned char msr[4];
671+
unsigned char spr[4];
672+
} uart_mmio_t;
673+
674+
#define UART0_BASE ((volatile uart_mmio_t*)(0xf0000010))
675+
676+
#define UART_FIFO_CAPACITY 253
677+
678+
static unsigned int uart0_fifo_size = 0;
665679

666680
void
667681
uart_send_char(char c)
668682
{
669-
MLOGSYS_printchar(c);
683+
volatile uart_mmio_t* uart0 = UART0_BASE;
684+
685+
if (uart0_fifo_size >= UART_FIFO_CAPACITY) {
686+
while ((uart0->lsr[0] & 0b1100000) != 0b1100000) {}
687+
uart0_fifo_size = 0;
688+
}
689+
690+
uart0->rhr_thr[0] = c;
691+
uart0_fifo_size += 1;
670692
}
671693

672694
void init_printf() {
673-
print_x = 7;
674-
print_y = 508;
675-
MLOGDRAW_reset();
676-
MLOGDRAW_clear(0, 0, 0);
677-
MLOGDRAW_color(255, 255, 255, 255);
678-
MLOGSYS_drawflush();
695+
volatile uart_mmio_t* uart0 = UART0_BASE;
696+
uart0->isr_fcr[0] = 0b00000111;
697+
while (uart0->lsr[0] & 0b1) {
698+
uart0->isr_fcr[0] = 0b00000111;
699+
}
679700
}
680701

681702
int
@@ -685,33 +706,16 @@ ee_printf(const char *fmt, ...)
685706
va_list args;
686707
int n = 0;
687708

688-
int old_print_x = print_x;
689-
int old_print_y = print_y;
690-
691709
va_start(args, fmt);
692710
ee_vsprintf(buf, fmt, args);
693711
va_end(args);
694712
p = buf;
695713
while (*p)
696714
{
697-
if (*p == '\n') {
698-
print_x = 7;
699-
print_y -= 13;
700-
} else {
701-
print_x += 7;
702-
if (print_x > 504) {
703-
uart_send_char('\n');
704-
print_x = 7;
705-
print_y -= 13;
706-
}
707-
}
708715
uart_send_char(*p);
709716
n++;
710717
p++;
711718
}
712719

713-
MLOGDRAW_print(old_print_x, old_print_y);
714-
MLOGSYS_drawflush();
715-
716720
return n;
717721
}

mod/src/main/kotlin/gay/object/mlogv32/ProcessorAccess.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,13 @@ class ProcessorAccess(
4040
uartFifoModulo: Int,
4141
uart0: MemoryBuild,
4242
uart1: MemoryBuild,
43+
uart2: MemoryBuild,
44+
uart3: MemoryBuild,
4345
) {
4446
val uart0 = UartAccess(uart0, uartFifoModulo - 1)
4547
val uart1 = UartAccess(uart1, uartFifoModulo - 1)
48+
val uart2 = UartAccess(uart2, uartFifoModulo - 1)
49+
val uart3 = UartAccess(uart3, uartFifoModulo - 1)
4650

4751
val romEnd = ROM_START + romSize.toUInt()
4852
val ramEnd = RAM_START + ramSize.toUInt()
@@ -261,6 +265,8 @@ class ProcessorAccess(
261265
uartFifoModulo = positiveIntVar(build, "UART_FIFO_MODULO") ?: return null,
262266
uart0 = buildVar<MemoryBuild>(build, "bank1") ?: return null,
263267
uart1 = buildVar<MemoryBuild>(build, "bank2") ?: return null,
268+
uart2 = buildVar<MemoryBuild>(build, "bank3") ?: return null,
269+
uart3 = buildVar<MemoryBuild>(build, "bank4") ?: return null,
264270
)
265271
}
266272

@@ -383,6 +389,8 @@ data class WaitRequest(
383389
enum class UartDevice {
384390
uart0,
385391
uart1,
392+
uart2,
393+
uart3,
386394
}
387395

388396
@Serializable
@@ -396,6 +404,8 @@ data class SerialRequest(
396404
val uart = when (device) {
397405
UartDevice.uart0 -> processor.uart0
398406
UartDevice.uart1 -> processor.uart1
407+
UartDevice.uart2 -> processor.uart2
408+
UartDevice.uart3 -> processor.uart3
399409
}
400410
while (true) {
401411
if (rx.isClosedForRead || tx.isClosedForWrite) {
@@ -476,9 +486,9 @@ data object StatusRequest : Request() {
476486
mepc = processor.getCSR(0x341),
477487
mcause = processor.getCSR(0x342),
478488
mtval = processor.getCSR(0x343),
479-
mstatus = processor.getCSR(0x300),
480-
mip = processor.getCSR(0x344),
481-
mie = processor.getCSR(0x304),
489+
mstatus = processor.build.executor.optionalVar("csr_mstatus")?.numu() ?: 0u,
490+
mip = processor.build.executor.optionalVar("csr_mip")?.numu() ?: 0u,
491+
mie = processor.build.executor.optionalVar("csr_mie")?.numu() ?: 0u,
482492
)
483493
}
484494
}

python/src/mlogv32/preprocessor/app.py

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -123,37 +123,34 @@ def build(
123123
for y in lenrange(0, 16):
124124
schem.add_block(simple_block(BEContent.TILE_LOGIC_DISPLAY, x, y))
125125

126-
display_link = ProcessorLink(0, 0, "display1")
126+
display_link = ProcessorLink(0, 0, "")
127127

128128
schem.add_schem(lookups_schem, 0, 16)
129-
lookup_links = [
130-
ProcessorLink(x=i % 4, y=16 + i // 4, name=f"processor{i + 1}")
131-
for i in range(16)
132-
]
129+
lookup_links = [ProcessorLink(x=i % 4, y=16 + i // 4, name="") for i in range(16)]
133130

134131
add_label(schem, 4, 19, right="UART0, UART2", down="LABELS")
135132
schem.add_block(simple_block(Content.WORLD_CELL, 4, 18))
136133
schem.add_block(simple_block(Content.WORLD_CELL, 4, 17))
137134
add_label(schem, 4, 16, up="COSTS", right="UART1, UART3")
138135

139-
labels_link = ProcessorLink(4, 18, "cell1")
140-
costs_link = ProcessorLink(4, 17, "cell2")
136+
labels_link = ProcessorLink(4, 18, "")
137+
costs_link = ProcessorLink(4, 17, "")
141138

142139
uart_links = list[ProcessorLink]()
143140
for x in lenrange(5, 4, 2):
144141
for y in lenrange(18, -4, -2):
145142
schem.add_block(simple_block(Content.MEMORY_BANK, x, y))
146-
uart_links.append(ProcessorLink(x, y, f"bank{len(uart_links) + 1}"))
143+
uart_links.append(ProcessorLink(x, y, ""))
147144

148145
schem.add_block(simple_block(Content.MEMORY_CELL, 9, 19))
149146
schem.add_schem(ram_schem, 9, 18)
150147
schem.add_schem(ram_schem, 9, 17)
151148
schem.add_block(Block(Content.MICRO_PROCESSOR, 9, 16, ProcessorConfig("", []), 0))
152149

153-
registers_link = ProcessorLink(9, 19, "cell3")
154-
csrs_link = ProcessorLink(9, 18, "processor17")
155-
incr_link = ProcessorLink(9, 17, "processor18")
156-
config_link = ProcessorLink(9, 16, "processor19")
150+
registers_link = ProcessorLink(9, 19, "")
151+
csrs_link = ProcessorLink(9, 18, "")
152+
incr_link = ProcessorLink(9, 17, "")
153+
config_link = ProcessorLink(9, 16, "")
157154

158155
add_with_label(
159156
schem,
@@ -180,10 +177,10 @@ def build(
180177
right="SINGLE_STEP_SWITCH",
181178
)
182179

183-
error_output_link = ProcessorLink(11, 19, "message1")
184-
power_switch_link = ProcessorLink(11, 18, "switch2")
185-
pause_switch_link = ProcessorLink(11, 17, "switch3")
186-
single_step_switch_link = ProcessorLink(11, 16, "switch1")
180+
error_output_link = ProcessorLink(11, 19, "")
181+
power_switch_link = ProcessorLink(11, 18, "")
182+
pause_switch_link = ProcessorLink(11, 17, "")
183+
single_step_switch_link = ProcessorLink(11, 16, "")
187184

188185
# hack
189186
if cpu_only:
@@ -199,15 +196,16 @@ def build(
199196
links=relative_links(
200197
*lookup_links,
201198
*uart_links,
199+
registers_link,
202200
labels_link,
203201
costs_link,
204202
csrs_link,
205203
incr_link,
206204
config_link,
207205
error_output_link,
208-
single_step_switch_link,
209206
power_switch_link,
210207
pause_switch_link,
208+
single_step_switch_link,
211209
display_link,
212210
x=16,
213211
y=0,
@@ -217,7 +215,7 @@ def build(
217215
)
218216
)
219217

220-
controller_link = ProcessorLink(16, 0, "processor20")
218+
controller_link = ProcessorLink(16, 0, "")
221219

222220
for x in lenrange(16, width):
223221
for y in lenrange(0, height):
@@ -235,9 +233,9 @@ def build(
235233
links=relative_links(
236234
*lookup_links,
237235
*uart_links,
236+
registers_link,
238237
labels_link,
239238
costs_link,
240-
registers_link,
241239
csrs_link,
242240
incr_link,
243241
config_link,
@@ -253,8 +251,6 @@ def build(
253251
)
254252
)
255253

256-
schem.set_tag("name", "mlogv32")
257-
258254
if output:
259255
schem.write_file(str(output))
260256
else:

python/src/mlogv32/preprocessor/models.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
from contextlib import contextmanager
44
from contextvars import ContextVar
55
from pathlib import Path
6-
from typing import Annotated
6+
from typing import Annotated, Any
77

88
import yaml
9-
from pydantic import AfterValidator, BaseModel, Field
9+
from pydantic import AfterValidator, BaseModel, Field, field_validator
1010

1111
_relative_path_root_var = ContextVar[Path]("_relative_path_root_var")
1212

@@ -42,6 +42,13 @@ class Instruction(BaseModel):
4242
label: str
4343
cost: int = Field(ge=0)
4444

45+
@field_validator("cost", mode="before")
46+
@classmethod
47+
def _resolve_cost_math(cls, value: Any):
48+
if isinstance(value, str):
49+
return eval(value) # CURSED
50+
return value
51+
4552
@classmethod
4653
def load(cls, path: str | Path):
4754
path = Path(path).resolve()

riscof/mlogv32/riscof_mlogv32.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ def runTests(self, testlist: dict[str, Any]):
123123
# we will iterate over each entry in the testlist. Each entry node will be refered to by the
124124
# variable testname.
125125
for testname in testlist:
126+
logger.info(f"Building test: {testname}")
127+
126128
# for each testname we get all its fields (as described by the testlist format)
127129
testentry = testlist[testname]
128130

@@ -219,7 +221,7 @@ def runTests(self, testlist: dict[str, Any]):
219221
f"{begin_signature=:#x} {end_signature=:#x} {signature_length=}"
220222
)
221223

222-
logger.info(f"Starting test: {testname}")
224+
logger.info(f"Running test: {testname}")
223225

224226
processor.stop()
225227
processor.flash(binary_file_host)

src/config/configs.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ defaults:
77

88
configs:
99
riscv-arch-test:
10-
MEMORY_X_OFFSET: -11
11-
MEMORY_Y_OFFSET: -26
10+
MEMORY_X_OFFSET: -9
11+
MEMORY_Y_OFFSET: -40
1212
MEMORY_WIDTH: 32
1313
ROM_ROWS: 9
1414
RAM_ROWS: 9

0 commit comments

Comments
 (0)