| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (C) 1999, 2000  Niibe Yutaka | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2012-10-09 09:47:37 +01:00
										 |  |  | #ifndef __ASM_SH_PTRACE_H
 | 
					
						
							|  |  |  | #define __ASM_SH_PTRACE_H
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-14 16:02:47 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <linux/stringify.h>
 | 
					
						
							|  |  |  | #include <linux/stddef.h>
 | 
					
						
							|  |  |  | #include <linux/thread_info.h>
 | 
					
						
							| 
									
										
										
										
											2007-11-09 16:57:27 +09:00
										 |  |  | #include <asm/addrspace.h>
 | 
					
						
							| 
									
										
										
										
											2010-02-12 15:40:00 +09:00
										 |  |  | #include <asm/page.h>
 | 
					
						
							| 
									
										
										
										
											2012-10-09 09:47:37 +01:00
										 |  |  | #include <uapi/asm/ptrace.h>
 | 
					
						
							| 
									
										
										
										
											2007-11-09 16:57:27 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define user_mode(regs)			(((regs)->sr & 0x40000000)==0)
 | 
					
						
							| 
									
										
										
										
											2011-01-01 18:36:36 +00:00
										 |  |  | #define kernel_stack_pointer(_regs)	((unsigned long)(_regs)->regs[15])
 | 
					
						
							| 
									
										
										
										
											2011-05-31 14:39:49 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define GET_FP(regs)	((regs)->regs[14])
 | 
					
						
							|  |  |  | #define GET_USP(regs)	((regs)->regs[15])
 | 
					
						
							| 
									
										
										
										
											2007-11-09 16:57:27 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-14 15:16:53 +09:00
										 |  |  | #define arch_has_single_step()	(1)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-30 19:09:31 +09:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2010-06-14 15:16:53 +09:00
										 |  |  |  * kprobe-based event tracer support | 
					
						
							| 
									
										
										
										
											2008-07-30 19:09:31 +09:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2010-06-14 15:16:53 +09:00
										 |  |  | struct pt_regs_offset { | 
					
						
							|  |  |  | 	const char *name; | 
					
						
							|  |  |  | 	int offset; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define REG_OFFSET_NAME(r) {.name = #r, .offset = offsetof(struct pt_regs, r)}
 | 
					
						
							|  |  |  | #define REGS_OFFSET_NAME(num)	\
 | 
					
						
							|  |  |  | 	{.name = __stringify(r##num), .offset = offsetof(struct pt_regs, regs[num])} | 
					
						
							| 
									
										
										
										
											2010-06-14 16:02:47 +09:00
										 |  |  | #define TREGS_OFFSET_NAME(num)	\
 | 
					
						
							|  |  |  | 	{.name = __stringify(tr##num), .offset = offsetof(struct pt_regs, tregs[num])} | 
					
						
							| 
									
										
										
										
											2010-06-14 15:16:53 +09:00
										 |  |  | #define REG_OFFSET_END {.name = NULL, .offset = 0}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Query offset/name of register from its name/offset */ | 
					
						
							|  |  |  | extern int regs_query_register_offset(const char *name); | 
					
						
							|  |  |  | extern const char *regs_query_register_name(unsigned int offset); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | extern const struct pt_regs_offset regoffset_table[]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * regs_get_register() - get register value from its offset | 
					
						
							|  |  |  |  * @regs:	pt_regs from which register value is gotten. | 
					
						
							|  |  |  |  * @offset:	offset number of the register. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * regs_get_register returns the value of a register. The @offset is the | 
					
						
							|  |  |  |  * offset of the register in struct pt_regs address which specified by @regs. | 
					
						
							|  |  |  |  * If @offset is bigger than MAX_REG_OFFSET, this returns 0. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static inline unsigned long regs_get_register(struct pt_regs *regs, | 
					
						
							|  |  |  | 					      unsigned int offset) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (unlikely(offset > MAX_REG_OFFSET)) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	return *(unsigned long *)((unsigned long)regs + offset); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * regs_within_kernel_stack() - check the address in the stack | 
					
						
							|  |  |  |  * @regs:	pt_regs which contains kernel stack pointer. | 
					
						
							|  |  |  |  * @addr:	address which is checked. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * regs_within_kernel_stack() checks @addr is within the kernel stack page(s). | 
					
						
							|  |  |  |  * If @addr is within the kernel stack, it returns true. If not, returns false. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static inline int regs_within_kernel_stack(struct pt_regs *regs, | 
					
						
							|  |  |  | 					   unsigned long addr) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return ((addr & ~(THREAD_SIZE - 1))  == | 
					
						
							|  |  |  | 		(kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1))); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * regs_get_kernel_stack_nth() - get Nth entry of the stack | 
					
						
							|  |  |  |  * @regs:	pt_regs which contains kernel stack pointer. | 
					
						
							|  |  |  |  * @n:		stack entry number. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which | 
					
						
							|  |  |  |  * is specified by @regs. If the @n th entry is NOT in the kernel stack, | 
					
						
							|  |  |  |  * this returns 0. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, | 
					
						
							|  |  |  | 						      unsigned int n) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs); | 
					
						
							|  |  |  | 	addr += n; | 
					
						
							|  |  |  | 	if (regs_within_kernel_stack(regs, (unsigned long)addr)) | 
					
						
							|  |  |  | 		return *addr; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-07-30 19:09:31 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-28 17:53:47 +09:00
										 |  |  | struct perf_event; | 
					
						
							|  |  |  | struct perf_sample_data; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-31 21:36:35 +00:00
										 |  |  | extern void ptrace_triggered(struct perf_event *bp, | 
					
						
							| 
									
										
										
										
											2009-12-28 17:53:47 +09:00
										 |  |  | 		      struct perf_sample_data *data, struct pt_regs *regs); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-12 01:05:44 -08:00
										 |  |  | #define task_pt_regs(task) \
 | 
					
						
							| 
									
										
										
										
											2009-02-23 07:16:34 +00:00
										 |  |  | 	((struct pt_regs *) (task_stack_page(task) + THREAD_SIZE) - 1) | 
					
						
							| 
									
										
										
										
											2006-01-12 01:05:44 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | static inline unsigned long profile_pc(struct pt_regs *regs) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-05-31 14:39:49 +09:00
										 |  |  | 	unsigned long pc = regs->pc; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-17 16:28:00 +09:00
										 |  |  | 	if (virt_addr_uncached(pc)) | 
					
						
							|  |  |  | 		return CAC_ADDR(pc); | 
					
						
							| 
									
										
										
										
											2007-11-09 16:57:27 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	return pc; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-05-26 16:25:44 -07:00
										 |  |  | #define profile_pc profile_pc
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <asm-generic/ptrace.h>
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | #endif /* __ASM_SH_PTRACE_H */
 |