1 /* SPDX-License-Identifier: GPL-2.0 */
5 #include <linux/thread_info.h>
6 #include <linux/sched.h>
7 #include <asm/ptrace.h>
10 /* SP must be STACK_BIAS adjusted already. */
11 static inline bool kstack_valid(struct thread_info
*tp
, unsigned long sp
)
13 unsigned long base
= (unsigned long) tp
;
15 /* Stack pointer must be 16-byte aligned. */
19 if (sp
>= (base
+ sizeof(struct thread_info
)) &&
20 sp
<= (base
+ THREAD_SIZE
- sizeof(struct sparc_stackf
)))
23 if (hardirq_stack
[tp
->cpu
]) {
24 base
= (unsigned long) hardirq_stack
[tp
->cpu
];
26 sp
<= (base
+ THREAD_SIZE
- sizeof(struct sparc_stackf
)))
28 base
= (unsigned long) softirq_stack
[tp
->cpu
];
30 sp
<= (base
+ THREAD_SIZE
- sizeof(struct sparc_stackf
)))
36 /* Does "regs" point to a valid pt_regs trap frame? */
37 static inline bool kstack_is_trap_frame(struct thread_info
*tp
, struct pt_regs
*regs
)
39 unsigned long base
= (unsigned long) tp
;
40 unsigned long addr
= (unsigned long) regs
;
43 addr
<= (base
+ THREAD_SIZE
- sizeof(*regs
)))
46 if (hardirq_stack
[tp
->cpu
]) {
47 base
= (unsigned long) hardirq_stack
[tp
->cpu
];
49 addr
<= (base
+ THREAD_SIZE
- sizeof(*regs
)))
51 base
= (unsigned long) softirq_stack
[tp
->cpu
];
53 addr
<= (base
+ THREAD_SIZE
- sizeof(*regs
)))
59 if ((regs
->magic
& ~0x1ff) == PT_REGS_MAGIC
)
65 static inline __attribute__((always_inline
)) void *set_hardirq_stack(void)
67 void *orig_sp
, *sp
= hardirq_stack
[smp_processor_id()];
69 __asm__
__volatile__("mov %%sp, %0" : "=r" (orig_sp
));
71 orig_sp
> (sp
+ THREAD_SIZE
)) {
72 sp
+= THREAD_SIZE
- 192 - STACK_BIAS
;
73 __asm__
__volatile__("mov %0, %%sp" : : "r" (sp
));
79 static inline __attribute__((always_inline
)) void restore_hardirq_stack(void *orig_sp
)
81 __asm__
__volatile__("mov %0, %%sp" : : "r" (orig_sp
));
84 #endif /* _KSTACK_H */