1 /* Copyright 2013-2014 IBM Corp.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 * implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef __STACKFRAME_H
18 #define __STACKFRAME_H
19
20 #include <mem-map.h>
21
22 #define STACK_ENTRY_OPAL_API 0 /* OPAL call */
23 #define STACK_ENTRY_HMI 0x0e60 /* Hypervisor maintenance */
24 #define STACK_ENTRY_RESET 0x0100 /* System reset */
25 #define STACK_ENTRY_SOFTPATCH 0x1500 /* Soft patch (denorm emulation) */
26
27 /* Safety/ABI gap at top of stack */
28 #define STACK_TOP_GAP 0x100
29
30 /* Remaining stack space (gap included) */
31 #define NORMAL_STACK_SIZE STACK_SIZE
32
33 /* Offset to get to normal CPU stacks */
34 #define CPU_STACKS_OFFSET (CPU_STACKS_BASE + \
35 NORMAL_STACK_SIZE - STACK_TOP_GAP)
36
37 /* Gap below the stack. If our stack checker sees the stack below that
38 * gap, it will flag a stack overflow
39 */
40 #define STACK_SAFETY_GAP 512
41
42 /* Warning threshold, if stack goes below that on mcount, print a
43 * warning.
44 */
45 #define STACK_WARNING_GAP 2048
46
47 #ifndef __ASSEMBLY__
48
49 #include <stdint.h>
50
51 /* This is the struct used to save GPRs etc.. on OPAL entry
52 * and from some exceptions. It is not always entirely populated
53 * depending on the entry type
54 */
55 struct stack_frame {
56 /* Standard 112-byte stack frame header (the minimum size required,
57 * using an 8-doubleword param save area). The callee (in C) may use
58 * lrsave; we declare these here so we don't get our own save area
59 * overwritten */
60 uint64_t backchain;
61 uint64_t crsave;
62 uint64_t lrsave;
63 uint64_t compiler_dw;
64 uint64_t linker_dw;
65 uint64_t tocsave;
66 uint64_t paramsave[8];
67
68 /* Space for stack-local vars used by asm. At present we only use
69 * one doubleword. */
70 uint64_t locals[1];
71
72 /* Entry type */
73 uint64_t type;
74
75 /* GPR save area
76 *
77 * We don't necessarily save everything in here
78 */
79 uint64_t gpr[32];
80
81 /* Other SPR saved
82 *
83 * Only for some exceptions.
84 */
85 uint32_t cr;
86 uint32_t xer;
87 uint64_t ctr;
88 uint64_t lr;
89 uint64_t pc;
90 uint64_t cfar;
91 uint64_t srr0;
92 uint64_t srr1;
93 uint64_t hsrr0;
94 uint64_t hsrr1;
95 } __attribute__((aligned(16)));
96
97 /* Backtrace */
98 struct bt_entry {
99 unsigned long sp;
100 unsigned long pc;
101 };
102
103 /* Boot stack top */
104 extern void *boot_stack_top;
105
106 /* Create a backtrace */
107 extern void __backtrace(struct bt_entry *entries, unsigned int *count);
108
109 /* Convert a backtrace to ASCII */
110 extern void __print_backtrace(unsigned int pir, struct bt_entry *entries,
111 unsigned int count, char *out_buf,
112 unsigned int *len, bool symbols);
113
114 /* For use by debug code, create and print backtrace, uses a static buffer */
115 extern void backtrace(void);
116
117 #ifdef STACK_CHECK_ENABLED
118 extern void check_stacks(void);
119 #else
check_stacks(void)120 static inline void check_stacks(void) { }
121 #endif
122
123 #endif /* __ASSEMBLY__ */
124 #endif /* __STACKFRAME_H */
125
126