xref: /openbmc/linux/arch/sh/include/asm/ptrace.h (revision 261a9af6)
1 #ifndef __ASM_SH_PTRACE_H
2 #define __ASM_SH_PTRACE_H
3 
4 /*
5  * Copyright (C) 1999, 2000  Niibe Yutaka
6  */
7 
8 #define PTRACE_GETREGS		12	/* General registers */
9 #define PTRACE_SETREGS		13
10 
11 #define PTRACE_GETFPREGS	14	/* FPU registers */
12 #define PTRACE_SETFPREGS	15
13 
14 #define PTRACE_GETFDPIC		31	/* get the ELF fdpic loadmap address */
15 
16 #define PTRACE_GETFDPIC_EXEC	0	/* [addr] request the executable loadmap */
17 #define PTRACE_GETFDPIC_INTERP	1	/* [addr] request the interpreter loadmap */
18 
19 #define	PTRACE_GETDSPREGS	55	/* DSP registers */
20 #define	PTRACE_SETDSPREGS	56
21 
22 #define PT_TEXT_END_ADDR	240
23 #define PT_TEXT_ADDR		244	/* &(struct user)->start_code */
24 #define PT_DATA_ADDR		248	/* &(struct user)->start_data */
25 #define PT_TEXT_LEN		252
26 
27 #if defined(__SH5__) || defined(CONFIG_CPU_SH5)
28 #include "ptrace_64.h"
29 #else
30 #include "ptrace_32.h"
31 #endif
32 
33 #ifdef __KERNEL__
34 
35 #include <linux/stringify.h>
36 #include <linux/stddef.h>
37 #include <linux/thread_info.h>
38 #include <asm/addrspace.h>
39 #include <asm/page.h>
40 #include <asm/system.h>
41 
42 #define user_mode(regs)			(((regs)->sr & 0x40000000)==0)
43 #define kernel_stack_pointer(_regs)	((unsigned long)(_regs)->regs[15])
44 
45 #define GET_FP(regs)	((regs)->regs[14])
46 #define GET_USP(regs)	((regs)->regs[15])
47 
48 extern void show_regs(struct pt_regs *);
49 
50 #define arch_has_single_step()	(1)
51 
52 /*
53  * kprobe-based event tracer support
54  */
55 struct pt_regs_offset {
56 	const char *name;
57 	int offset;
58 };
59 
60 #define REG_OFFSET_NAME(r) {.name = #r, .offset = offsetof(struct pt_regs, r)}
61 #define REGS_OFFSET_NAME(num)	\
62 	{.name = __stringify(r##num), .offset = offsetof(struct pt_regs, regs[num])}
63 #define TREGS_OFFSET_NAME(num)	\
64 	{.name = __stringify(tr##num), .offset = offsetof(struct pt_regs, tregs[num])}
65 #define REG_OFFSET_END {.name = NULL, .offset = 0}
66 
67 /* Query offset/name of register from its name/offset */
68 extern int regs_query_register_offset(const char *name);
69 extern const char *regs_query_register_name(unsigned int offset);
70 
71 extern const struct pt_regs_offset regoffset_table[];
72 
73 /**
74  * regs_get_register() - get register value from its offset
75  * @regs:	pt_regs from which register value is gotten.
76  * @offset:	offset number of the register.
77  *
78  * regs_get_register returns the value of a register. The @offset is the
79  * offset of the register in struct pt_regs address which specified by @regs.
80  * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
81  */
82 static inline unsigned long regs_get_register(struct pt_regs *regs,
83 					      unsigned int offset)
84 {
85 	if (unlikely(offset > MAX_REG_OFFSET))
86 		return 0;
87 	return *(unsigned long *)((unsigned long)regs + offset);
88 }
89 
90 /**
91  * regs_within_kernel_stack() - check the address in the stack
92  * @regs:	pt_regs which contains kernel stack pointer.
93  * @addr:	address which is checked.
94  *
95  * regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
96  * If @addr is within the kernel stack, it returns true. If not, returns false.
97  */
98 static inline int regs_within_kernel_stack(struct pt_regs *regs,
99 					   unsigned long addr)
100 {
101 	return ((addr & ~(THREAD_SIZE - 1))  ==
102 		(kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1)));
103 }
104 
105 /**
106  * regs_get_kernel_stack_nth() - get Nth entry of the stack
107  * @regs:	pt_regs which contains kernel stack pointer.
108  * @n:		stack entry number.
109  *
110  * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
111  * is specified by @regs. If the @n th entry is NOT in the kernel stack,
112  * this returns 0.
113  */
114 static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
115 						      unsigned int n)
116 {
117 	unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
118 	addr += n;
119 	if (regs_within_kernel_stack(regs, (unsigned long)addr))
120 		return *addr;
121 	else
122 		return 0;
123 }
124 
125 struct perf_event;
126 struct perf_sample_data;
127 
128 extern void ptrace_triggered(struct perf_event *bp, int nmi,
129 		      struct perf_sample_data *data, struct pt_regs *regs);
130 
131 #define task_pt_regs(task) \
132 	((struct pt_regs *) (task_stack_page(task) + THREAD_SIZE) - 1)
133 
134 static inline unsigned long profile_pc(struct pt_regs *regs)
135 {
136 	unsigned long pc = regs->pc;
137 
138 	if (virt_addr_uncached(pc))
139 		return CAC_ADDR(pc);
140 
141 	return pc;
142 }
143 #define profile_pc profile_pc
144 
145 #include <asm-generic/ptrace.h>
146 #endif /* __KERNEL__ */
147 
148 #endif /* __ASM_SH_PTRACE_H */
149