1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) 1999, 2000 Niibe Yutaka
5 #ifndef __ASM_SH_PTRACE_H
6 #define __ASM_SH_PTRACE_H
9 #include <linux/stringify.h>
10 #include <linux/stddef.h>
11 #include <linux/thread_info.h>
12 #include <asm/addrspace.h>
14 #include <uapi/asm/ptrace.h>
16 #define user_mode(regs) (((regs)->sr & 0x40000000)==0)
17 #define kernel_stack_pointer(_regs) ((unsigned long)(_regs)->regs[15])
19 #define GET_FP(regs) ((regs)->regs[14])
20 #define GET_USP(regs) ((regs)->regs[15])
22 #define arch_has_single_step() (1)
25 * kprobe-based event tracer support
27 struct pt_regs_offset
{
32 #define REG_OFFSET_NAME(r) {.name = #r, .offset = offsetof(struct pt_regs, r)}
33 #define REGS_OFFSET_NAME(num) \
34 {.name = __stringify(r##num), .offset = offsetof(struct pt_regs, regs[num])}
35 #define TREGS_OFFSET_NAME(num) \
36 {.name = __stringify(tr##num), .offset = offsetof(struct pt_regs, tregs[num])}
37 #define REG_OFFSET_END {.name = NULL, .offset = 0}
39 /* Query offset/name of register from its name/offset */
40 extern int regs_query_register_offset(const char *name
);
41 extern const char *regs_query_register_name(unsigned int offset
);
43 extern const struct pt_regs_offset regoffset_table
[];
46 * regs_get_register() - get register value from its offset
47 * @regs: pt_regs from which register value is gotten.
48 * @offset: offset number of the register.
50 * regs_get_register returns the value of a register. The @offset is the
51 * offset of the register in struct pt_regs address which specified by @regs.
52 * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
54 static inline unsigned long regs_get_register(struct pt_regs
*regs
,
57 if (unlikely(offset
> MAX_REG_OFFSET
))
59 return *(unsigned long *)((unsigned long)regs
+ offset
);
63 * regs_within_kernel_stack() - check the address in the stack
64 * @regs: pt_regs which contains kernel stack pointer.
65 * @addr: address which is checked.
67 * regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
68 * If @addr is within the kernel stack, it returns true. If not, returns false.
70 static inline int regs_within_kernel_stack(struct pt_regs
*regs
,
73 return ((addr
& ~(THREAD_SIZE
- 1)) ==
74 (kernel_stack_pointer(regs
) & ~(THREAD_SIZE
- 1)));
78 * regs_get_kernel_stack_nth() - get Nth entry of the stack
79 * @regs: pt_regs which contains kernel stack pointer.
80 * @n: stack entry number.
82 * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
83 * is specified by @regs. If the @n th entry is NOT in the kernel stack,
86 static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs
*regs
,
89 unsigned long *addr
= (unsigned long *)kernel_stack_pointer(regs
);
91 if (regs_within_kernel_stack(regs
, (unsigned long)addr
))
98 struct perf_sample_data
;
100 extern void ptrace_triggered(struct perf_event
*bp
,
101 struct perf_sample_data
*data
, struct pt_regs
*regs
);
103 #define task_pt_regs(task) \
104 ((struct pt_regs *) (task_stack_page(task) + THREAD_SIZE) - 1)
106 static inline unsigned long profile_pc(struct pt_regs
*regs
)
108 unsigned long pc
= regs
->pc
;
110 if (virt_addr_uncached(pc
))
115 #define profile_pc profile_pc
117 #include <asm-generic/ptrace.h>
118 #endif /* __ASM_SH_PTRACE_H */