Skip to content

Commit 4176770

Browse files
committed
Gate timers and MSI on an enabled CLINT.
1 parent 97b659f commit 4176770

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

model/core/interrupt_regs.sail

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,17 +208,23 @@ function read_mip(read_type : XipReadType) -> Minterrupts =
208208
function update_mip() -> unit = {
209209
let old_mip = mip.bits;
210210

211-
// This updates `mip` for any timer interrupts that may now have fired,
212-
// and for any machine-level software interrupts arising from the
213-
// CLINT.
211+
// This updates `mip` for any timer interrupts that may now have
212+
// fired, and for any machine-level software interrupts arising from
213+
// the CLINT. Currently, the only timer support is from the CLINT;
214+
// so without a CLINT, no non-virtual timer interrupts can fire.
215+
// This may need to change when we support other or multiple
216+
// interrupt controllers.
217+
218+
let platform_has_timer = plat_have_clint;
219+
214220
let cur_mtime = get_mtime();
215221
let hart_mtimecmp = get_hart_mtimecmp();
216222

217223
mip[MSI] = get_machine_software_interrupt_pending();
218-
mip[MTI] = bool_to_bit(hart_mtimecmp <=_u cur_mtime);
224+
mip[MTI] = bool_to_bit(platform_has_timer & (hart_mtimecmp <=_u cur_mtime));
219225

220226
if currentlyEnabled(Ext_Sstc) & menvcfg[STCE] == 0b1 then {
221-
mip[STI] = bool_to_bit(stimecmp <=_u cur_mtime);
227+
mip[STI] = bool_to_bit(platform_has_timer & (stimecmp <=_u cur_mtime));
222228
};
223229

224230
if currentlyEnabled(Ext_H) then {
@@ -240,7 +246,7 @@ function update_mip() -> unit = {
240246
var VSTI : bits(1) = hvip[VSTI];
241247

242248
if currentlyEnabled(Ext_Sstc) & read_henvcfg()[STCE] == 0b1 then {
243-
VSTI = VSTI | bool_to_bit(vstimecmp <=_u (cur_mtime + htimedelta));
249+
VSTI = VSTI | bool_to_bit(platform_has_timer & (vstimecmp <=_u (cur_mtime + htimedelta)));
244250
};
245251
mip[VSTI] = VSTI;
246252
};

model/sys/platform.sail

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,14 @@ private register mtimecmp : bits(64)
7373
// number of cycles from the system clock.
7474
private register mtime : bits(64)
7575

76-
function get_mtime() -> bits(64) = mtime
76+
function get_mtime() -> bits(64) =
77+
if plat_have_clint then mtime else zeros()
7778

78-
function get_hart_mtimecmp() -> bits(64) = mtimecmp
79+
function get_hart_mtimecmp() -> bits(64) =
80+
if plat_have_clint then mtimecmp else zeros()
7981

8082
function get_machine_software_interrupt_pending() -> bits(1) =
81-
msip[0]
83+
if plat_have_clint then msip[0] else 0b0
8284

8385
// CLINT memory-mapped IO
8486

0 commit comments

Comments
 (0)