Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 1999, 2000 Niibe Yutaka |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | */ |
David Howells | 0a9426d | 2012-10-09 09:47:37 +0100 | [diff] [blame] | 4 | #ifndef __ASM_SH_PTRACE_H |
| 5 | #define __ASM_SH_PTRACE_H |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | |
Paul Mundt | da28c59 | 2010-06-14 16:02:47 +0900 | [diff] [blame] | 7 | |
| 8 | #include <linux/stringify.h> |
| 9 | #include <linux/stddef.h> |
| 10 | #include <linux/thread_info.h> |
Paul Mundt | 33f242e | 2007-11-09 16:57:27 +0900 | [diff] [blame] | 11 | #include <asm/addrspace.h> |
Paul Mundt | b0f3ae0 | 2010-02-12 15:40:00 +0900 | [diff] [blame] | 12 | #include <asm/page.h> |
David Howells | 0a9426d | 2012-10-09 09:47:37 +0100 | [diff] [blame] | 13 | #include <uapi/asm/ptrace.h> |
Paul Mundt | 33f242e | 2007-11-09 16:57:27 +0900 | [diff] [blame] | 14 | |
| 15 | #define user_mode(regs) (((regs)->sr & 0x40000000)==0) |
Roel Kluin | eac676e | 2011-01-01 18:36:36 +0000 | [diff] [blame] | 16 | #define kernel_stack_pointer(_regs) ((unsigned long)(_regs)->regs[15]) |
Paul Mundt | db7eba2 | 2011-05-31 14:39:49 +0900 | [diff] [blame] | 17 | |
| 18 | #define GET_FP(regs) ((regs)->regs[14]) |
| 19 | #define GET_USP(regs) ((regs)->regs[15]) |
Paul Mundt | 33f242e | 2007-11-09 16:57:27 +0900 | [diff] [blame] | 20 | |
Paul Mundt | c459dbf | 2008-07-30 19:09:31 +0900 | [diff] [blame] | 21 | #define arch_has_single_step() (1) |
Paul Mundt | c459dbf | 2008-07-30 19:09:31 +0900 | [diff] [blame] | 22 | |
Paul Mundt | eaaaeef3 | 2010-06-14 15:16:53 +0900 | [diff] [blame] | 23 | /* |
| 24 | * kprobe-based event tracer support |
| 25 | */ |
Paul Mundt | eaaaeef3 | 2010-06-14 15:16:53 +0900 | [diff] [blame] | 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])} |
Paul Mundt | da28c59 | 2010-06-14 16:02:47 +0900 | [diff] [blame] | 34 | #define TREGS_OFFSET_NAME(num) \ |
| 35 | {.name = __stringify(tr##num), .offset = offsetof(struct pt_regs, tregs[num])} |
Paul Mundt | eaaaeef3 | 2010-06-14 15:16:53 +0900 | [diff] [blame] | 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 | */ |
| 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 | */ |
| 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 | */ |
| 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 | |
Paul Mundt | 34d0b5a | 2009-12-28 17:53:47 +0900 | [diff] [blame] | 96 | struct perf_event; |
| 97 | struct perf_sample_data; |
| 98 | |
Paul Gortmaker | c84b51e | 2011-07-31 21:36:35 +0000 | [diff] [blame] | 99 | extern void ptrace_triggered(struct perf_event *bp, |
Paul Mundt | 34d0b5a | 2009-12-28 17:53:47 +0900 | [diff] [blame] | 100 | struct perf_sample_data *data, struct pt_regs *regs); |
| 101 | |
Al Viro | 3cf0f4e | 2006-01-12 01:05:44 -0800 | [diff] [blame] | 102 | #define task_pt_regs(task) \ |
Magnus Damm | 4f099eb | 2009-02-23 07:16:34 +0000 | [diff] [blame] | 103 | ((struct pt_regs *) (task_stack_page(task) + THREAD_SIZE) - 1) |
Al Viro | 3cf0f4e | 2006-01-12 01:05:44 -0800 | [diff] [blame] | 104 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | static inline unsigned long profile_pc(struct pt_regs *regs) |
| 106 | { |
Paul Mundt | db7eba2 | 2011-05-31 14:39:49 +0900 | [diff] [blame] | 107 | unsigned long pc = regs->pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
Paul Mundt | 9edef28 | 2010-02-17 16:28:00 +0900 | [diff] [blame] | 109 | if (virt_addr_uncached(pc)) |
| 110 | return CAC_ADDR(pc); |
Paul Mundt | 33f242e | 2007-11-09 16:57:27 +0900 | [diff] [blame] | 111 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | return pc; |
| 113 | } |
Mike Frysinger | 3cea45c | 2011-05-26 16:25:44 -0700 | [diff] [blame] | 114 | #define profile_pc profile_pc |
| 115 | |
| 116 | #include <asm-generic/ptrace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | #endif /* __ASM_SH_PTRACE_H */ |