1
0
mirror of https://github.com/taigrr/gopher-os synced 2025-01-18 04:43:13 -08:00
gopher-os/kernel/panic.go

25 lines
654 B
Go

package kernel
import (
"github.com/achilleasa/gopher-os/kernel/cpu"
"github.com/achilleasa/gopher-os/kernel/kfmt/early"
)
var (
// cpuHaltFn is mocked by tests and is automatically inlined by the compiler.
cpuHaltFn = cpu.Halt
)
// Panic outputs the supplied error (if not nil) to the console and halts the
// CPU. Calls to Panic never return.
func Panic(err *Error) {
early.Printf("\n-----------------------------------\n")
if err != nil {
early.Printf("[%s] unrecoverable error: %s\n", err.Module, err.Message)
}
early.Printf("*** kernel panic: system halted ***")
early.Printf("\n-----------------------------------\n")
cpuHaltFn()
}