riscv: print exception PC and code
This can be useful for debugging critical bugs in code. I haven't added human-readable exceptions (such as "illegal instruction" or "stack overflow") yet, they can be added when they happen in practice (to avoid increasing code size too much).
Этот коммит содержится в:
родитель
b9cdfd9e9a
коммит
b258f3424b
1 изменённых файлов: 18 добавлений и 2 удалений
|
@ -69,8 +69,10 @@ func handleInterrupt() {
|
||||||
riscv.MIE.ClearBits(1 << 7) // MTIE bit
|
riscv.MIE.ClearBits(1 << 7) // MTIE bit
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// TODO: handle exceptions in a similar was as HardFault is handled on
|
// Topmost bit is clear, so it is an exception of some sort.
|
||||||
// Cortex-M (by printing an error message with instruction address).
|
// We could implement support for unsupported instructions here (such as
|
||||||
|
// misaligned loads). However, for now we'll just print a fatal error.
|
||||||
|
handleException(code)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,3 +153,17 @@ func sleepTicks(d timeUnit) {
|
||||||
riscv.Asm("wfi")
|
riscv.Asm("wfi")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handleException is called from the interrupt handler for any exception.
|
||||||
|
// Exceptions can be things like illegal instructions, invalid memory
|
||||||
|
// read/write, and similar issues.
|
||||||
|
func handleException(code uint) {
|
||||||
|
// For a list of exception codes, see:
|
||||||
|
// https://content.riscv.org/wp-content/uploads/2019/08/riscv-privileged-20190608-1.pdf#page=49
|
||||||
|
print("fatal error: exception with mcause=")
|
||||||
|
print(code)
|
||||||
|
print(" pc=")
|
||||||
|
print(riscv.MEPC.Get())
|
||||||
|
println()
|
||||||
|
abort()
|
||||||
|
}
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче