Skip to content

Commit 4fad738

Browse files
committed
Clean up CPU templates
1 parent 62c9acf commit 4fad738

File tree

6 files changed

+94
-99
lines changed

6 files changed

+94
-99
lines changed

python/src/mlogv32/preprocessor/app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ def _render_template(
252252
[LocalVariables],
253253
force=True,
254254
VARIABLE_0_TO_PAGE_OFFSET="".join(variable_0_to_page_offset),
255+
**config.inputs,
255256
)
256257

257258
i = LocalVariablesEnv.of(worker_env).largest_local_variable
@@ -283,6 +284,7 @@ def _render_template(
283284
csrs=config.csrs,
284285
labels=worker_labels,
285286
VARIABLE_0_TO_PAGE_OFFSET="".join(variable_0_to_page_offset),
287+
**config.inputs,
286288
)
287289

288290
# preprocess other code snippets

python/src/mlogv32/preprocessor/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class BuildConfig(BaseModel):
3333
templates: Templates
3434
schematics: Schematics
3535
configs: RelativePath
36+
inputs: dict[str, Any]
3637
instructions: list[Instruction]
3738
csrs: dict[str, CSR]
3839

src/cpu/constants.jinja

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/cpu/controller.mlog.jinja

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#% from 'worker.mlog.jinja' import fetch_variables with context
22

3-
#% extends 'constants.jinja'
4-
#% block contents
5-
63
#% set REGISTERS = 'cell1'
74
#% set LABELS = 'cell2'
85

@@ -372,8 +369,7 @@ lookup_variable:
372369

373370
set @counter ret
374371

375-
#% endblock contents
376-
372+
#% if false
377373
# disable mlogls warnings
378374
# {% raw %}
379375
# common preprocessor constants
@@ -421,3 +417,4 @@ set _ csr_mie
421417
set _ csr_satp
422418
set _ csr_mideleg
423419
# {% endraw %}
420+
#% endif

src/cpu/cpu.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@ schematics:
1515

1616
configs: ../config/configs.yaml
1717

18+
inputs:
19+
LOOKUP_PROC_SIZE: 260 # number of variables per lookup proc
20+
ROM_BYTE_OFFSET: 174 # start character for ROM string byte data
21+
ROM_PROC_BYTES: 16384 # number of bytes per ROM proc
22+
RAM_PROC_BYTES: 16384 # number of bytes per RAM proc
23+
RAM_PROC_VARS: 4096 # number of variables per RAM proc
24+
25+
# ROM starts at 0x00000000, so we don't need a variable for it
26+
RAM_START: '0x80000000'
27+
MMIO_START: '0xf0000000'
28+
SYSCON: '0xfffffff0'
29+
30+
UART_RX_READ: 254
31+
UART_RX_WRITE: 255
32+
UART_TX_START: 256
33+
UART_TX_READ: 510
34+
UART_TX_WRITE: 511
35+
1836
instructions:
1937
# runtime handlers
2038
- label: BEQ

src/cpu/worker.mlog.jinja

Lines changed: 71 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,3 @@
1-
#% macro fetch_variables()
2-
read _rom prev_proc "_rom"
3-
read __etext prev_proc "__etext"
4-
read _address prev_proc "_address"
5-
read address prev_proc "address"
6-
read breakpoint_address prev_proc "breakpoint_address"
7-
read csr_mideleg prev_proc "csr_mideleg"
8-
read csr_mie prev_proc "csr_mie"
9-
read csr_minstret prev_proc "csr_minstret"
10-
read csr_mip prev_proc "csr_mip"
11-
read csr_mstatus prev_proc "csr_mstatus"
12-
read csr_mtime prev_proc "csr_mtime"
13-
read csr_mtimecmp prev_proc "csr_mtimecmp"
14-
read csr_mtimecmph prev_proc "csr_mtimecmph"
15-
read csr_mtimeh prev_proc "csr_mtimeh"
16-
read csr_satp prev_proc "csr_satp"
17-
read csr_stimecmp prev_proc "csr_stimecmp"
18-
read csr_stimecmph prev_proc "csr_stimecmph"
19-
read effective_privilege_mode prev_proc "effective_privilege_mode"
20-
read icache_ram prev_proc "icache_ram"
21-
read icache_var prev_proc "icache_var"
22-
read imm prev_proc "imm"
23-
read length prev_proc "length"
24-
read mcause prev_proc "mcause"
25-
read mtval prev_proc "mtval"
26-
read next_pc prev_proc "next_pc"
27-
read op_id prev_proc "op_id"
28-
read pc prev_proc "pc"
29-
read privilege_mode prev_proc "privilege_mode"
30-
read ram prev_proc "ram"
31-
read rd prev_proc "rd"
32-
read rd_id prev_proc "rd_id"
33-
read result prev_proc "result"
34-
read rs1 prev_proc "rs1"
35-
read rs1_id prev_proc "rs1_id"
36-
read rs2 prev_proc "rs2"
37-
read rs2_id prev_proc "rs2_id"
38-
read state prev_proc "state"
39-
read value prev_proc "value"
40-
read variable prev_proc "variable"
41-
42-
read ret prev_proc "ret"
43-
read ret2 prev_proc "ret2"
44-
read ret3 prev_proc "ret3"
45-
read ret4 prev_proc "ret4"
46-
47-
read nonlocal1 prev_proc "nonlocal1"
48-
read nonlocal2 prev_proc "nonlocal2"
49-
50-
#% do reset_locals()
51-
read {{local_variable()}} prev_proc "{{ local_variable(1) }}"
52-
read {{local_variable()}} prev_proc "{{ local_variable(2) }}"
53-
read {{local_variable()}} prev_proc "{{ local_variable(3) }}"
54-
read {{local_variable()}} prev_proc "{{ local_variable(4) }}"
55-
read {{local_variable()}} prev_proc "{{ local_variable(5) }}"
56-
read {{local_variable()}} prev_proc "{{ local_variable(6) }}"
57-
read {{local_variable()}} prev_proc "{{ local_variable(7) }}"
58-
read {{local_variable()}} prev_proc "{{ local_variable(8) }}"
59-
read {{local_variable()}} prev_proc "{{ local_variable(9) }}"
60-
#% endmacro
61-
62-
# {% macro start_assert_length(n) %}{{ n }}{{ '\n#directive start_assert_length ' }}{{ n }}{% endmacro %}
63-
64-
#%# hack: use extends so we don't need to individually import all of the constants
65-
#% extends 'constants.jinja'
66-
#% block contents
67-
681
#%# linked buildings
692

703
#% set UART_START_LINK = 16
@@ -100,12 +33,16 @@
10033
#% set labels.end_instruction = _labels_vals|last + 2
10134
#% set labels.end_instruction_trap = _labels_vals|last + 6
10235

36+
#%# macros
37+
38+
#% macro start_assert_length(n)
39+
#{- n
40+
#directive start_assert_length {{ n }}
41+
#%- endmacro
42+
10343
reset:
10444
setrate 1000
10545

106-
# define this variable FIRST so that we can read other variables over it
107-
# set _rom null
108-
10946
# load config
11047
read MEMORY_X {{CONFIG}} "MEMORY_X"
11148
read MEMORY_Y {{CONFIG}} "MEMORY_Y"
@@ -131,6 +68,67 @@ reset:
13168

13269
#directive start_fetch
13370

71+
#% macro fetch_variables()
72+
read _rom prev_proc "_rom"
73+
read __etext prev_proc "__etext"
74+
read _address prev_proc "_address"
75+
read address prev_proc "address"
76+
read breakpoint_address prev_proc "breakpoint_address"
77+
read csr_mideleg prev_proc "csr_mideleg"
78+
read csr_mie prev_proc "csr_mie"
79+
read csr_minstret prev_proc "csr_minstret"
80+
read csr_mip prev_proc "csr_mip"
81+
read csr_mstatus prev_proc "csr_mstatus"
82+
read csr_mtime prev_proc "csr_mtime"
83+
read csr_mtimecmp prev_proc "csr_mtimecmp"
84+
read csr_mtimecmph prev_proc "csr_mtimecmph"
85+
read csr_mtimeh prev_proc "csr_mtimeh"
86+
read csr_satp prev_proc "csr_satp"
87+
read csr_stimecmp prev_proc "csr_stimecmp"
88+
read csr_stimecmph prev_proc "csr_stimecmph"
89+
read effective_privilege_mode prev_proc "effective_privilege_mode"
90+
read icache_ram prev_proc "icache_ram"
91+
read icache_var prev_proc "icache_var"
92+
read imm prev_proc "imm"
93+
read length prev_proc "length"
94+
read mcause prev_proc "mcause"
95+
read mtval prev_proc "mtval"
96+
read next_pc prev_proc "next_pc"
97+
read op_id prev_proc "op_id"
98+
read pc prev_proc "pc"
99+
read privilege_mode prev_proc "privilege_mode"
100+
read ram prev_proc "ram"
101+
read rd prev_proc "rd"
102+
read rd_id prev_proc "rd_id"
103+
read result prev_proc "result"
104+
read rs1 prev_proc "rs1"
105+
read rs1_id prev_proc "rs1_id"
106+
read rs2 prev_proc "rs2"
107+
read rs2_id prev_proc "rs2_id"
108+
read state prev_proc "state"
109+
read value prev_proc "value"
110+
read variable prev_proc "variable"
111+
112+
read ret prev_proc "ret"
113+
read ret2 prev_proc "ret2"
114+
read ret3 prev_proc "ret3"
115+
read ret4 prev_proc "ret4"
116+
117+
read nonlocal1 prev_proc "nonlocal1"
118+
read nonlocal2 prev_proc "nonlocal2"
119+
120+
#% do reset_locals()
121+
read {{local_variable()}} prev_proc "{{ local_variable(1) }}"
122+
read {{local_variable()}} prev_proc "{{ local_variable(2) }}"
123+
read {{local_variable()}} prev_proc "{{ local_variable(3) }}"
124+
read {{local_variable()}} prev_proc "{{ local_variable(4) }}"
125+
read {{local_variable()}} prev_proc "{{ local_variable(5) }}"
126+
read {{local_variable()}} prev_proc "{{ local_variable(6) }}"
127+
read {{local_variable()}} prev_proc "{{ local_variable(7) }}"
128+
read {{local_variable()}} prev_proc "{{ local_variable(8) }}"
129+
read {{local_variable()}} prev_proc "{{ local_variable(9) }}"
130+
#% endmacro
131+
134132
#{ fetch_variables()
135133

136134
#directive end_fetch
@@ -2703,11 +2701,9 @@ MLOGSYS__decode_loop:
27032701

27042702
jump end_instruction always
27052703

2706-
#% endblock contents
2707-
2704+
#% if false
27082705
# disable mlogls warnings
2709-
# put this at the end of the file so it's not included in the output
2710-
# and so that if we go over the 1000 instruction limit, we can ignore the errors below this line
2706+
# put this at the end of the file so if we go over the 1000 instruction limit, we can ignore the errors below this line
27112707
# {% raw %}
27122708
# common preprocessor constants
27132709
set {{ null
@@ -2853,3 +2849,4 @@ jump csr_write_sstatus always
28532849
jump csr_write_stimecmp always
28542850
jump csr_write_stimecmph always
28552851
# {% endraw %}
2852+
#% endif

0 commit comments

Comments
 (0)