xref: /optee_os/core/arch/riscv/kernel/unwind_rv.c (revision 2e5a3b0d63ddd51c4795a01a5bde2157dc0ddbf6)
1 // SPDX-License-Identifier: BSD-2-Clause
2 /*-
3  * Copyright (c) 2023 Andes Technology Corporation
4  * Copyright (c) 2015 Linaro Limited
5  * Copyright (c) 2015 The FreeBSD Foundation
6  */
7 
8 #include <kernel/linker.h>
9 #include <kernel/thread.h>
10 #include <kernel/unwind.h>
11 #include <riscv.h>
12 #include <unw/unwind.h>
13 
14 #if defined(CFG_UNWIND) && (TRACE_LEVEL > 0)
print_kernel_stack(void)15 void print_kernel_stack(void)
16 {
17 	struct unwind_state_riscv state = { };
18 	vaddr_t stack_start = 0;
19 	vaddr_t stack_end = 0;
20 
21 	state.pc = read_pc();
22 	state.fp = read_fp();
23 
24 	trace_printf_helper_raw(TRACE_ERROR, true,
25 				"TEE load address @ %#"PRIxVA, VCORE_START_VA);
26 	get_stack_hard_limits(&stack_start, &stack_end);
27 	print_stack_riscv(&state, stack_start, stack_end - stack_start);
28 }
29 #endif
30