Skip to content

Commit 91cbf1f

Browse files
committed
Add bitmask field to CSR label lookup
1 parent ebd07fa commit 91cbf1f

File tree

5 files changed

+113
-91
lines changed

5 files changed

+113
-91
lines changed

python/src/mlogv32/preprocessor/filters.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ def hex_filter(n: int):
8585
return hex(n)
8686

8787

88+
@make_jinja_exceptions_suck_a_bit_less
89+
@register_filter("bin")
90+
def bin_filter(n: int, bits: int | None = None):
91+
if bits:
92+
return f"{n:#0{bits + 2}b}"
93+
return bin(n)
94+
95+
8896
@make_jinja_exceptions_suck_a_bit_less
8997
@register_filter()
9098
def namespace_dict(namespace: Namespace):

python/src/mlogv32/preprocessor/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class Instruction(BaseModel):
5959
class CSR(BaseModel):
6060
read: CSRLocation
6161
write: CSRLocation | None = None
62+
mask: int = Field(default=0xFFFF_FFFF, ge=0, le=0xFFFF_FFFF)
6263
args: Iterable[Any] | None = None
6364

6465
@field_validator("instructions", mode="after")

src/cpu/controller.mlog.jinja

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,11 @@ init_labels__loop{{ns.loop}}:
139139
#% for name, csr in csrs.items()
140140
#% set read_label = 'csr_read_' ~ csr.read
141141
#% set write_label = 'csr_write_' ~ csr.write if csr.write is not none else 'ILLEGAL_OP'
142-
#% set value = labels[read_label] * 1000 + labels[write_label]
142+
#% set value = csr.mask * 1_000_000 + labels[write_label] * 1000 + labels[read_label]
143143
# {{ name }}
144144
# read: {{ read_label }} ({{ labels[read_label] }})
145145
# write: {{ write_label }} ({{ labels[write_label] }})
146+
# mask: {{ csr.mask|bin(32) }}
146147
write {{value}} {{CSR_LABELS}} "{{ name|csr }}"
147148
#% endfor
148149

src/cpu/cpu.yaml

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,23 @@ csrs:
193193
sstatus:
194194
read: LABEL
195195
write: LABEL
196+
# MXR -
197+
# SUM -
198+
# SPP -
199+
# SPIE -
200+
# SIE -
201+
mask: 0b00000000000011000000000100100010
196202
sie:
197203
read: LABEL
198204
write: LABEL
205+
# SEIE -
206+
# STIE -
207+
# SSIE -
208+
mask: 0b00000000000000000000001000100010
199209
stvec:
200210
read: csrs
201-
write: csrs_align_4B
211+
write: csrs
212+
mask: &align_4B 0xfffffffc
202213
scounteren:
203214
read: csrs
204215
write: csrs
@@ -225,7 +236,8 @@ csrs:
225236
write: csrs
226237
sepc:
227238
read: csrs
228-
write: csrs_align_4B
239+
write: csrs
240+
mask: *align_4B
229241
scause:
230242
read: csrs
231243
write: csrs
@@ -235,6 +247,8 @@ csrs:
235247
sip:
236248
read: LABEL
237249
write: LABEL
250+
# SSIP -
251+
mask: 0b00000000000000000000000000000010
238252

239253
# protection and translation
240254
satp:
@@ -259,21 +273,37 @@ csrs:
259273
mstatus:
260274
read: LABEL
261275
write: LABEL
276+
# state - ---- --
277+
# WPRI -------- - - -
278+
# UBE -
279+
mask: 0b00000000011111100001100110101010
262280
misa:
263281
read: csrs
264282
write: readonly
265283
medeleg:
266284
read: csrs
267-
write: LABEL
285+
write: csrs
286+
# custom --------
287+
# reserved ---- -- - -
288+
# M-call -
289+
mask: 0b00000000000011001011001111111111
268290
mideleg:
269291
read: csrs
270-
write: LABEL
292+
write: csrs
293+
# MEI -
294+
# SEI -
295+
# MTI -
296+
# STI -
297+
# MSI -
298+
# SSI -
299+
mask: 0b00000000000000000000101010101010
271300
mie:
272301
read: LABEL
273302
write: LABEL
274303
mtvec:
275304
read: csrs
276-
write: csrs_align_4B
305+
write: csrs
306+
mask: *align_4B
277307
mcounteren:
278308
read: csrs
279309
write: csrs
@@ -290,7 +320,8 @@ csrs:
290320
write: csrs
291321
mepc:
292322
read: csrs
293-
write: csrs_align_4B
323+
write: csrs
324+
mask: *align_4B
294325
mcause:
295326
read: csrs
296327
write: csrs
@@ -300,6 +331,9 @@ csrs:
300331
mip:
301332
read: LABEL
302333
write: LABEL
334+
# SEIP -
335+
# SSIP -
336+
mask: 0b00000000000000000000001000000010
303337

304338
# configuration
305339
menvcfg:

0 commit comments

Comments
 (0)