.section .text.panic

// Hangs, possibly printing an error message. Only to be used for unrecoverable
// errors.
.global panic
panic:
	ldr x2, =panic.caller
	str lr, [x2]
	ldr x2, =panic.function
	ldr x29, [x2]
	bl platform.debug_println
	br x29

// Panics with a message of "TODO".
.global todo
todo:
	adr x0, todo.msg
	mov x1, todo.msg.len
	b panic

// Hangs. Only to be used for unrecoverable errors. In general, prefer to call
// `panic`.
.global hang
hang:
	bl platform.idle
	b hang

.section .data.panic

.global panic.function
panic.function:
	.quad hang

.section .rodata.panic

todo.msg: .ascii "TODO"
.set todo.msg.len, . - todo.msg

.section .bss.panic

.align 8
panic.caller: .skip 8

// vim: set ft=arm64asm :