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 static inline unsigned long instruction_pointer(struct pt_regs
*regs
)
23 static inline void instruction_pointer_set(struct pt_regs
*regs
,
29 static inline unsigned long frame_pointer(struct pt_regs
*regs
)
31 return regs
->regs
[14];
34 static inline unsigned long user_stack_pointer(struct pt_regs
*regs
)
36 return regs
->regs
[15];
39 static inline void user_stack_pointer_set(struct pt_regs
*regs
,
45 #define arch_has_single_step() (1)
48 * kprobe-based event tracer support
50 struct pt_regs_offset
{
55 #define REG_OFFSET_NAME(r) {.name = #r, .offset = offsetof(struct pt_regs, r)}
56 #define REGS_OFFSET_NAME(num) \
57 {.name = __stringify(r##num), .offset = offsetof(struct pt_regs, regs[num])}
58 #define TREGS_OFFSET_NAME(num) \
59 {.name = __stringify(tr##num), .offset = offsetof(struct pt_regs, tregs[num])}
60 #define REG_OFFSET_END {.name = NULL, .offset = 0}
62 /* Query offset/name of register from its name/offset */
63 extern int regs_query_register_offset(const char *name
);
64 extern const char *regs_query_register_name(unsigned int offset
);
66 extern const struct pt_regs_offset regoffset_table
[];
69 * regs_get_register() - get register value from its offset
70 * @regs: pt_regs from which register value is gotten.
71 * @offset: offset number of the register.
73 * regs_get_register returns the value of a register. The @offset is the
74 * offset of the register in struct pt_regs address which specified by @regs.
75 * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
77 static inline unsigned long regs_get_register(struct pt_regs
*regs
,
80 if (unlikely(offset
> MAX_REG_OFFSET
))
82 return *(unsigned long *)((unsigned long)regs
+ offset
);
86 * regs_within_kernel_stack() - check the address in the stack
87 * @regs: pt_regs which contains kernel stack pointer.
88 * @addr: address which is checked.
90 * regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
91 * If @addr is within the kernel stack, it returns true. If not, returns false.
93 static inline int regs_within_kernel_stack(struct pt_regs
*regs
,
96 return ((addr
& ~(THREAD_SIZE
- 1)) ==
97 (kernel_stack_pointer(regs
) & ~(THREAD_SIZE
- 1)));
101 * regs_get_kernel_stack_nth() - get Nth entry of the stack
102 * @regs: pt_regs which contains kernel stack pointer.
103 * @n: stack entry number.
105 * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
106 * is specified by @regs. If the @n th entry is NOT in the kernel stack,
109 static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs
*regs
,
112 unsigned long *addr
= (unsigned long *)kernel_stack_pointer(regs
);
114 if (regs_within_kernel_stack(regs
, (unsigned long)addr
))
121 struct perf_sample_data
;
123 extern void ptrace_triggered(struct perf_event
*bp
,
124 struct perf_sample_data
*data
, struct pt_regs
*regs
);
126 #define task_pt_regs(task) \
127 ((struct pt_regs *) (task_stack_page(task) + THREAD_SIZE) - 1)
129 static inline unsigned long profile_pc(struct pt_regs
*regs
)
131 unsigned long pc
= regs
->pc
;
133 if (virt_addr_uncached(pc
))
139 #endif /* __ASM_SH_PTRACE_H */