• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 1999, 2000  Niibe Yutaka
3  */
4 #ifndef __ASM_SH_PTRACE_H
5 #define __ASM_SH_PTRACE_H
6 
7 
8 #include <linux/stringify.h>
9 #include <linux/stddef.h>
10 #include <linux/thread_info.h>
11 #include <asm/addrspace.h>
12 #include <asm/page.h>
13 #include <uapi/asm/ptrace.h>
14 
15 #define user_mode(regs)			(((regs)->sr & 0x40000000)==0)
16 #define kernel_stack_pointer(_regs)	((unsigned long)(_regs)->regs[15])
17 
18 #define GET_FP(regs)	((regs)->regs[14])
19 #define GET_USP(regs)	((regs)->regs[15])
20 
21 #define arch_has_single_step()	(1)
22 
23 /*
24  * kprobe-based event tracer support
25  */
26 struct pt_regs_offset {
27 	const char *name;
28 	int offset;
29 };
30 
31 #define REG_OFFSET_NAME(r) {.name = #r, .offset = offsetof(struct pt_regs, r)}
32 #define REGS_OFFSET_NAME(num)	\
33 	{.name = __stringify(r##num), .offset = offsetof(struct pt_regs, regs[num])}
34 #define TREGS_OFFSET_NAME(num)	\
35 	{.name = __stringify(tr##num), .offset = offsetof(struct pt_regs, tregs[num])}
36 #define REG_OFFSET_END {.name = NULL, .offset = 0}
37 
38 /* Query offset/name of register from its name/offset */
39 extern int regs_query_register_offset(const char *name);
40 extern const char *regs_query_register_name(unsigned int offset);
41 
42 extern const struct pt_regs_offset regoffset_table[];
43 
44 /**
45  * regs_get_register() - get register value from its offset
46  * @regs:	pt_regs from which register value is gotten.
47  * @offset:	offset number of the register.
48  *
49  * regs_get_register returns the value of a register. The @offset is the
50  * offset of the register in struct pt_regs address which specified by @regs.
51  * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
52  */
regs_get_register(struct pt_regs * regs,unsigned int offset)53 static inline unsigned long regs_get_register(struct pt_regs *regs,
54 					      unsigned int offset)
55 {
56 	if (unlikely(offset > MAX_REG_OFFSET))
57 		return 0;
58 	return *(unsigned long *)((unsigned long)regs + offset);
59 }
60 
61 /**
62  * regs_within_kernel_stack() - check the address in the stack
63  * @regs:	pt_regs which contains kernel stack pointer.
64  * @addr:	address which is checked.
65  *
66  * regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
67  * If @addr is within the kernel stack, it returns true. If not, returns false.
68  */
regs_within_kernel_stack(struct pt_regs * regs,unsigned long addr)69 static inline int regs_within_kernel_stack(struct pt_regs *regs,
70 					   unsigned long addr)
71 {
72 	return ((addr & ~(THREAD_SIZE - 1))  ==
73 		(kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1)));
74 }
75 
76 /**
77  * regs_get_kernel_stack_nth() - get Nth entry of the stack
78  * @regs:	pt_regs which contains kernel stack pointer.
79  * @n:		stack entry number.
80  *
81  * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
82  * is specified by @regs. If the @n th entry is NOT in the kernel stack,
83  * this returns 0.
84  */
regs_get_kernel_stack_nth(struct pt_regs * regs,unsigned int n)85 static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
86 						      unsigned int n)
87 {
88 	unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
89 	addr += n;
90 	if (regs_within_kernel_stack(regs, (unsigned long)addr))
91 		return *addr;
92 	else
93 		return 0;
94 }
95 
96 struct perf_event;
97 struct perf_sample_data;
98 
99 extern void ptrace_triggered(struct perf_event *bp,
100 		      struct perf_sample_data *data, struct pt_regs *regs);
101 
102 #define task_pt_regs(task) \
103 	((struct pt_regs *) (task_stack_page(task) + THREAD_SIZE) - 1)
104 
profile_pc(struct pt_regs * regs)105 static inline unsigned long profile_pc(struct pt_regs *regs)
106 {
107 	unsigned long pc = regs->pc;
108 
109 	if (virt_addr_uncached(pc))
110 		return CAC_ADDR(pc);
111 
112 	return pc;
113 }
114 #define profile_pc profile_pc
115 
116 #include <asm-generic/ptrace.h>
117 #endif /* __ASM_SH_PTRACE_H */
118