Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef __ASM_SH_PTRACE_H |
| 2 | #define __ASM_SH_PTRACE_H |
| 3 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | /* |
| 5 | * Copyright (C) 1999, 2000 Niibe Yutaka |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | |
Paul Mundt | 934135c | 2008-09-12 19:52:36 +0900 | [diff] [blame] | 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 | |
Paul Mundt | 3bc24a1 | 2008-05-19 13:40:12 +0900 | [diff] [blame] | 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 | |
Paul Mundt | 934135c | 2008-09-12 19:52:36 +0900 | [diff] [blame] | 19 | #define PTRACE_GETDSPREGS 55 /* DSP registers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #define PTRACE_SETDSPREGS 56 |
| 21 | |
Paul Mundt | b0f3ae0 | 2010-02-12 15:40:00 +0900 | [diff] [blame] | 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 */ |
Kieran Bingham | be6514c | 2009-05-08 15:48:15 +0100 | [diff] [blame] | 25 | #define PT_TEXT_LEN 252 |
| 26 | |
Paul Mundt | da28c59 | 2010-06-14 16:02:47 +0900 | [diff] [blame] | 27 | #if defined(__SH5__) || defined(CONFIG_CPU_SH5) |
| 28 | #include "ptrace_64.h" |
| 29 | #else |
| 30 | #include "ptrace_32.h" |
| 31 | #endif |
| 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #ifdef __KERNEL__ |
Paul Mundt | da28c59 | 2010-06-14 16:02:47 +0900 | [diff] [blame] | 34 | |
| 35 | #include <linux/stringify.h> |
| 36 | #include <linux/stddef.h> |
| 37 | #include <linux/thread_info.h> |
Paul Mundt | 33f242e | 2007-11-09 16:57:27 +0900 | [diff] [blame] | 38 | #include <asm/addrspace.h> |
Paul Mundt | b0f3ae0 | 2010-02-12 15:40:00 +0900 | [diff] [blame] | 39 | #include <asm/page.h> |
| 40 | #include <asm/system.h> |
Paul Mundt | 33f242e | 2007-11-09 16:57:27 +0900 | [diff] [blame] | 41 | |
| 42 | #define user_mode(regs) (((regs)->sr & 0x40000000)==0) |
Roel Kluin | eac676e | 2011-01-01 18:36:36 +0000 | [diff] [blame] | 43 | #define kernel_stack_pointer(_regs) ((unsigned long)(_regs)->regs[15]) |
Paul Mundt | db7eba2 | 2011-05-31 14:39:49 +0900 | [diff] [blame] | 44 | |
| 45 | #define GET_FP(regs) ((regs)->regs[14]) |
| 46 | #define GET_USP(regs) ((regs)->regs[15]) |
Paul Mundt | 33f242e | 2007-11-09 16:57:27 +0900 | [diff] [blame] | 47 | |
Paul Mundt | c459dbf | 2008-07-30 19:09:31 +0900 | [diff] [blame] | 48 | #define arch_has_single_step() (1) |
Paul Mundt | c459dbf | 2008-07-30 19:09:31 +0900 | [diff] [blame] | 49 | |
Paul Mundt | eaaaeef | 2010-06-14 15:16:53 +0900 | [diff] [blame] | 50 | /* |
| 51 | * kprobe-based event tracer support |
| 52 | */ |
Paul Mundt | eaaaeef | 2010-06-14 15:16:53 +0900 | [diff] [blame] | 53 | struct pt_regs_offset { |
| 54 | const char *name; |
| 55 | int offset; |
| 56 | }; |
| 57 | |
| 58 | #define REG_OFFSET_NAME(r) {.name = #r, .offset = offsetof(struct pt_regs, r)} |
| 59 | #define REGS_OFFSET_NAME(num) \ |
| 60 | {.name = __stringify(r##num), .offset = offsetof(struct pt_regs, regs[num])} |
Paul Mundt | da28c59 | 2010-06-14 16:02:47 +0900 | [diff] [blame] | 61 | #define TREGS_OFFSET_NAME(num) \ |
| 62 | {.name = __stringify(tr##num), .offset = offsetof(struct pt_regs, tregs[num])} |
Paul Mundt | eaaaeef | 2010-06-14 15:16:53 +0900 | [diff] [blame] | 63 | #define REG_OFFSET_END {.name = NULL, .offset = 0} |
| 64 | |
| 65 | /* Query offset/name of register from its name/offset */ |
| 66 | extern int regs_query_register_offset(const char *name); |
| 67 | extern const char *regs_query_register_name(unsigned int offset); |
| 68 | |
| 69 | extern const struct pt_regs_offset regoffset_table[]; |
| 70 | |
| 71 | /** |
| 72 | * regs_get_register() - get register value from its offset |
| 73 | * @regs: pt_regs from which register value is gotten. |
| 74 | * @offset: offset number of the register. |
| 75 | * |
| 76 | * regs_get_register returns the value of a register. The @offset is the |
| 77 | * offset of the register in struct pt_regs address which specified by @regs. |
| 78 | * If @offset is bigger than MAX_REG_OFFSET, this returns 0. |
| 79 | */ |
| 80 | static inline unsigned long regs_get_register(struct pt_regs *regs, |
| 81 | unsigned int offset) |
| 82 | { |
| 83 | if (unlikely(offset > MAX_REG_OFFSET)) |
| 84 | return 0; |
| 85 | return *(unsigned long *)((unsigned long)regs + offset); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * regs_within_kernel_stack() - check the address in the stack |
| 90 | * @regs: pt_regs which contains kernel stack pointer. |
| 91 | * @addr: address which is checked. |
| 92 | * |
| 93 | * regs_within_kernel_stack() checks @addr is within the kernel stack page(s). |
| 94 | * If @addr is within the kernel stack, it returns true. If not, returns false. |
| 95 | */ |
| 96 | static inline int regs_within_kernel_stack(struct pt_regs *regs, |
| 97 | unsigned long addr) |
| 98 | { |
| 99 | return ((addr & ~(THREAD_SIZE - 1)) == |
| 100 | (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1))); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * regs_get_kernel_stack_nth() - get Nth entry of the stack |
| 105 | * @regs: pt_regs which contains kernel stack pointer. |
| 106 | * @n: stack entry number. |
| 107 | * |
| 108 | * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which |
| 109 | * is specified by @regs. If the @n th entry is NOT in the kernel stack, |
| 110 | * this returns 0. |
| 111 | */ |
| 112 | static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, |
| 113 | unsigned int n) |
| 114 | { |
| 115 | unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs); |
| 116 | addr += n; |
| 117 | if (regs_within_kernel_stack(regs, (unsigned long)addr)) |
| 118 | return *addr; |
| 119 | else |
| 120 | return 0; |
| 121 | } |
| 122 | |
Paul Mundt | 34d0b5a | 2009-12-28 17:53:47 +0900 | [diff] [blame] | 123 | struct perf_event; |
| 124 | struct perf_sample_data; |
| 125 | |
Paul Gortmaker | c84b51e | 2011-07-31 21:36:35 +0000 | [diff] [blame^] | 126 | extern void ptrace_triggered(struct perf_event *bp, |
Paul Mundt | 34d0b5a | 2009-12-28 17:53:47 +0900 | [diff] [blame] | 127 | struct perf_sample_data *data, struct pt_regs *regs); |
| 128 | |
Al Viro | 3cf0f4e | 2006-01-12 01:05:44 -0800 | [diff] [blame] | 129 | #define task_pt_regs(task) \ |
Magnus Damm | 4f099eb | 2009-02-23 07:16:34 +0000 | [diff] [blame] | 130 | ((struct pt_regs *) (task_stack_page(task) + THREAD_SIZE) - 1) |
Al Viro | 3cf0f4e | 2006-01-12 01:05:44 -0800 | [diff] [blame] | 131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | static inline unsigned long profile_pc(struct pt_regs *regs) |
| 133 | { |
Paul Mundt | db7eba2 | 2011-05-31 14:39:49 +0900 | [diff] [blame] | 134 | unsigned long pc = regs->pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
Paul Mundt | 9edef28 | 2010-02-17 16:28:00 +0900 | [diff] [blame] | 136 | if (virt_addr_uncached(pc)) |
| 137 | return CAC_ADDR(pc); |
Paul Mundt | 33f242e | 2007-11-09 16:57:27 +0900 | [diff] [blame] | 138 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | return pc; |
| 140 | } |
Mike Frysinger | 3cea45c | 2011-05-26 16:25:44 -0700 | [diff] [blame] | 141 | #define profile_pc profile_pc |
| 142 | |
| 143 | #include <asm-generic/ptrace.h> |
Paul Mundt | 33f242e | 2007-11-09 16:57:27 +0900 | [diff] [blame] | 144 | #endif /* __KERNEL__ */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
| 146 | #endif /* __ASM_SH_PTRACE_H */ |