Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / arch / sh / include / asm / ptrace.h
blob9143c7babcbef7d5158e1f225f7f10da80e0d79f
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Copyright (C) 1999, 2000 Niibe Yutaka
4 */
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>
13 #include <asm/page.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 {
28 const char *name;
29 int 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[];
45 /**
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,
55 unsigned int offset)
57 if (unlikely(offset > MAX_REG_OFFSET))
58 return 0;
59 return *(unsigned long *)((unsigned long)regs + offset);
62 /**
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,
71 unsigned long addr)
73 return ((addr & ~(THREAD_SIZE - 1)) ==
74 (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1)));
77 /**
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,
84 * this returns 0.
86 static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
87 unsigned int n)
89 unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
90 addr += n;
91 if (regs_within_kernel_stack(regs, (unsigned long)addr))
92 return *addr;
93 else
94 return 0;
97 struct perf_event;
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))
111 return CAC_ADDR(pc);
113 return pc;
115 #define profile_pc profile_pc
117 #include <asm-generic/ptrace.h>
118 #endif /* __ASM_SH_PTRACE_H */