Skip to content

Commit cd79501

Browse files
committed
Add config for 16x16 memory setup, generate memory sizes with ld K/M in config
1 parent 79e99cd commit cd79501

File tree

5 files changed

+46
-21
lines changed

5 files changed

+46
-21
lines changed

python/src/mlogv32/preprocessor/app.py

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

88
from mlogv32.preprocessor.extensions import CommentStatement
99

10-
from . import filters
10+
from .filters import FILTERS
1111

1212
app = Typer(
1313
pretty_exceptions_show_locals=False,
@@ -42,7 +42,7 @@ def configs(yaml_path: Path):
4242
template = env.get_template(data["template"])
4343

4444
for name, args in data["configs"].items():
45-
result = template.render(**data["defaults"], **args)
45+
result = template.render(**(data["defaults"] | args))
4646
(output_dir / name).with_suffix(".mlog").write_text(result, "utf-8")
4747

4848

@@ -59,11 +59,7 @@ def create_jinja_env(template_dir: Path):
5959
CommentStatement,
6060
],
6161
)
62-
env.filters |= { # pyright: ignore[reportAttributeAccessIssue]
63-
"ram_variable": filters.ram_variable,
64-
"quote": filters.quote,
65-
"csr": filters.csr,
66-
}
62+
env.filters |= FILTERS
6763
return env
6864

6965

python/src/mlogv32/preprocessor/filters.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@
55

66
from mlogv32.scripts.ram_proc import VariableFormat
77

8+
# https://sourceware.org/binutils/docs/ld/Constants.html#Constants
9+
MEMORY_K = 1024
10+
MEMORY_M = 1024 * 1024
11+
12+
FILTERS = dict[str, Callable[..., Any]]()
13+
14+
15+
def register_filter[**P, R](f: Callable[P, R]) -> Callable[P, R]:
16+
FILTERS[f.__name__] = f
17+
return f
18+
819

920
# from hexdoc.jinja.filters
1021
def make_jinja_exceptions_suck_a_bit_less[**P, R](f: Callable[P, R]) -> Callable[P, R]:
@@ -25,11 +36,13 @@ def wrapper(*args: P.args, **kwargs: P.kwargs):
2536

2637

2738
@make_jinja_exceptions_suck_a_bit_less
39+
@register_filter
2840
def ram_variable(index: int):
2941
return VariableFormat.min.get_variable(index)
3042

3143

3244
@make_jinja_exceptions_suck_a_bit_less
45+
@register_filter
3346
def csr(name: str | int):
3447
match name:
3548
case str():
@@ -41,10 +54,21 @@ def csr(name: str | int):
4154

4255

4356
@make_jinja_exceptions_suck_a_bit_less
57+
@register_filter
4458
def quote(value: Any):
4559
return f'"{value}"'
4660

4761

62+
@make_jinja_exceptions_suck_a_bit_less
63+
@register_filter
64+
def memory_size(size: int):
65+
if size % MEMORY_M == 0:
66+
return f"{size // MEMORY_M}M"
67+
if size % MEMORY_K == 0:
68+
return f"{size // MEMORY_K}K"
69+
return hex(size)
70+
71+
4872
CSRS: dict[str, int] = {
4973
# unprivileged
5074
"cycle": 0xC00,

rust/examples/webserver/memory.x

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
MEMORY {
2-
ROM (rx) : ORIGIN = 0x00000000, LENGTH = 0x80000
3-
RAM (rwx) : ORIGIN = 0x80000000, LENGTH = 0x980000 - 0x1000
4-
PANIC (rwx) : ORIGIN = 0x80000000 + 0x980000 - 0x1000, LENGTH = 0x1000
2+
ROM (rx) : ORIGIN = 0x00000000, LENGTH = 512K
3+
RAM (rwx) : ORIGIN = 0x80000000, LENGTH = 3M - 4K
4+
PANIC (rwx) : ORIGIN = ORIGIN(RAM) + LENGTH(RAM), LENGTH = 4K
55
MMIO (rw) : ORIGIN = 0xf0000000, LENGTH = 0x10000000
66
}
77

src/config/base.mlog.jinja

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@
99
set MEMORY_Y_OFFSET {{#MEMORY_Y_OFFSET}} # y offset from this proc to bottom left memory proc
1010
set MEMORY_WIDTH {{#MEMORY_WIDTH}} # physical width of the memory procs
1111

12-
set ROM_SIZE {{# '%#0x'|format(ROM_ROWS * MEMORY_WIDTH * 16384) }} # ROM size in bytes (rx)
13-
set RAM_SIZE {{# '%#0x'|format(RAM_ROWS * MEMORY_WIDTH * 16384) }} # RAM size in bytes (rwx)
14-
set ICACHE_SIZE {{# '%#0x'|format(ICACHE_ROWS * MEMORY_WIDTH * 16384) }} # icache size in bytes
12+
#%+ set ROM_SIZE = ROM_ROWS * MEMORY_WIDTH * 16384
13+
#% set RAM_SIZE = RAM_ROWS * MEMORY_WIDTH * 16384
14+
#% set ICACHE_SIZE = ICACHE_ROWS * MEMORY_WIDTH * 16384
15+
16+
set ROM_SIZE {{# '%#0x'|format(ROM_SIZE) }} # ROM size in bytes ({{ ROM_SIZE|memory_size }})
17+
set RAM_SIZE {{# '%#0x'|format(RAM_SIZE) }} # RAM size in bytes ({{ RAM_SIZE|memory_size }})
18+
set ICACHE_SIZE {{# '%#0x'|format(ICACHE_SIZE) }} # icache size in bytes ({{ ICACHE_SIZE|memory_size }})
1519

1620
set UART_FIFO_CAPACITY {{#UART_FIFO_CAPACITY}} # UART TX/RX FIFO capacity in bytes (max 253)
1721

src/config/configs.yaml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ template: base.mlog.jinja
33
defaults:
44
TARGET_IPT: 500000
55
BREAKPOINT_ADDRESS: '0x'
6+
UART_FIFO_CAPACITY: 253
67

78
configs:
89
riscv-arch-test:
@@ -12,12 +13,12 @@ configs:
1213
ROM_ROWS: 9
1314
RAM_ROWS: 9
1415
ICACHE_ROWS: 6
15-
UART_FIFO_CAPACITY: 253
16-
webserver:
16+
17+
micro:
18+
TARGET_IPT: 250000 # we're running two of these at once, so underclock it
1719
MEMORY_X_OFFSET: -9
18-
MEMORY_Y_OFFSET: -23
19-
MEMORY_WIDTH: 32
20-
ROM_ROWS: 1
21-
RAM_ROWS: 19
22-
ICACHE_ROWS: 1
23-
UART_FIFO_CAPACITY: 253
20+
MEMORY_Y_OFFSET: -32
21+
MEMORY_WIDTH: 16
22+
ROM_ROWS: 2
23+
RAM_ROWS: 12
24+
ICACHE_ROWS: 2

0 commit comments

Comments
 (0)