Skip to content

Commit 23e88bf

Browse files
aykevldeadprogram
authored andcommitted
arm: allow nesting in DisableInterrupts and EnableInterrupts
This finally fixes a TODO left in the code.
1 parent 6389e45 commit 23e88bf

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/device/arm/arm.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,22 +191,21 @@ func SetPriority(irq uint32, priority uint32) {
191191
NVIC.IPR[regnum].Set((uint32(NVIC.IPR[regnum].Get()) &^ mask) | priority)
192192
}
193193

194-
// DisableInterrupts disables all interrupts, and returns the old state.
195-
//
196-
// TODO: it doesn't actually return the old state, meaning that it cannot be
197-
// nested.
194+
// DisableInterrupts disables all interrupts, and returns the old interrupt
195+
// state.
198196
func DisableInterrupts() uintptr {
199-
Asm("cpsid if")
200-
return 0
197+
return AsmFull(`
198+
mrs {}, PRIMASK
199+
cpsid if
200+
`, nil)
201201
}
202202

203203
// EnableInterrupts enables all interrupts again. The value passed in must be
204204
// the mask returned by DisableInterrupts.
205-
//
206-
// TODO: it doesn't actually use the old state, meaning that it cannot be
207-
// nested.
208205
func EnableInterrupts(mask uintptr) {
209-
Asm("cpsie if")
206+
AsmFull("msr PRIMASK, {mask}", map[string]interface{}{
207+
"mask": mask,
208+
})
210209
}
211210

212211
// SystemReset performs a hard system reset.

0 commit comments

Comments
 (0)