1 /* SPDX-License-Identifier: (BSD-2-Clause AND MIT-CMU) */
2 /*-
3  * Copyright (c) 2015-2019, Linaro Limited
4  * Copyright (c) 2000, 2001 Ben Harris
5  * Copyright (c) 1996 Scott K. Stevens
6  *
7  * Mach Operating System
8  * Copyright (c) 1991,1990 Carnegie Mellon University
9  * All Rights Reserved.
10  *
11  * Permission to use, copy, modify and distribute this software and its
12  * documentation is hereby granted, provided that both the copyright
13  * notice and this permission notice appear in all copies of the
14  * software, derivative works or modified versions, and any portions
15  * thereof, and that both notices appear in supporting documentation.
16  *
17  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
18  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
19  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
20  *
21  * Carnegie Mellon requests users of this software to return to
22  *
23  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
24  *  School of Computer Science
25  *  Carnegie Mellon University
26  *  Pittsburgh PA 15213-3890
27  *
28  * any improvements or extensions that they make and grant Carnegie the
29  * rights to redistribute these changes.
30  *
31  * $FreeBSD$
32  */
33 
34 #ifndef UNW_UNWIND_H
35 #define UNW_UNWIND_H
36 
37 #include <compiler.h>
38 #include <types_ext.h>
39 
40 /* The state of the unwind process (32-bit mode) */
41 struct unwind_state_arm32 {
42 	uint32_t registers[16];
43 	uint32_t start_pc;
44 	vaddr_t insn;
45 	unsigned int entries;
46 	unsigned int byte;
47 	uint16_t update_mask;
48 };
49 
50 #ifdef CFG_UNWIND
51 /*
52  * Unwind a 32-bit stack.
53  * @stack, @stack_size: the bottom of the stack and its size, respectively.
54  * Returns false when there is nothing more to unwind.
55  */
56 bool unwind_stack_arm32(struct unwind_state_arm32 *state,
57 			vaddr_t stack, size_t stack_size);
58 
59 void print_stack_arm32(struct unwind_state_arm32 *state,
60 		       vaddr_t stack, size_t stack_size);
61 #else
unwind_stack_arm32(struct unwind_state_arm32 * state __unused,vaddr_t stack __unused,size_t stack_size __unused)62 static inline bool unwind_stack_arm32(struct unwind_state_arm32 *state __unused,
63 				      vaddr_t stack __unused,
64 				      size_t stack_size __unused)
65 {
66 	return false;
67 }
68 
print_stack_arm32(struct unwind_state_arm32 * state __unused,vaddr_t stack __unused,size_t stack_size __unused)69 static inline void print_stack_arm32(struct unwind_state_arm32 *state __unused,
70 				     vaddr_t stack __unused,
71 				     size_t stack_size __unused)
72 {
73 }
74 #endif
75 
76 /*
77  * External helper function. Must be implemented by the caller of the 32-bit
78  * stack unwinding functions.
79  */
80 bool find_exidx(vaddr_t addr, vaddr_t *idx_start, vaddr_t *idx_end);
81 
82 /* The state of the unwind process (64-bit mode) */
83 struct unwind_state_arm64 {
84 	uint64_t fp;
85 	uint64_t sp;
86 	uint64_t pc;
87 };
88 
89 #if defined(ARM64) && defined(CFG_UNWIND)
90 /*
91  * Unwind a 64-bit stack.
92  * @stack, @stack_size: the bottom of the stack and its size, respectively.
93  * Returns false when there is nothing more to unwind.
94  */
95 bool unwind_stack_arm64(struct unwind_state_arm64 *state,
96 			vaddr_t stack, size_t stack_size);
97 
98 void print_stack_arm64(struct unwind_state_arm64 *state,
99 		       vaddr_t stack, size_t stack_size);
100 #else
unwind_stack_arm64(struct unwind_state_arm64 * state __unused,vaddr_t stack __unused,size_t stack_size __unused)101 static inline bool unwind_stack_arm64(struct unwind_state_arm64 *state __unused,
102 				      vaddr_t stack __unused,
103 				      size_t stack_size __unused)
104 {
105 	return false;
106 }
107 
print_stack_arm64(struct unwind_state_arm64 * state __unused,vaddr_t stack __unused,size_t stack_size __unused)108 static inline void print_stack_arm64(struct unwind_state_arm64 *state __unused,
109 				     vaddr_t stack __unused,
110 				     size_t stack_size __unused)
111 {
112 }
113 #endif
114 
115 /*
116  * External helper function optionally implemented by the caller of the 64-bit
117  * stack unwinding functions.
118  */
119 void ftrace_map_lr(uint64_t *lr);
120 
121 #endif /*UNW_UNWIND_H*/
122