blob: c7b7e1ed194af05fd626d1985c01be090a58339c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __ASM_SH_PTRACE_H
2#define __ASM_SH_PTRACE_H
3
Linus Torvalds1da177e2005-04-16 15:20:36 -07004/*
5 * Copyright (C) 1999, 2000 Niibe Yutaka
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007
Paul Mundt934135c2008-09-12 19:52:36 +09008#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 Mundt3bc24a12008-05-19 13:40:12 +090014#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 Mundt934135c2008-09-12 19:52:36 +090019#define PTRACE_GETDSPREGS 55 /* DSP registers */
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#define PTRACE_SETDSPREGS 56
21
Paul Mundtb0f3ae02010-02-12 15:40:00 +090022#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 Binghambe6514c2009-05-08 15:48:15 +010025#define PT_TEXT_LEN 252
26
Paul Mundtda28c592010-06-14 16:02:47 +090027#if defined(__SH5__) || defined(CONFIG_CPU_SH5)
28#include "ptrace_64.h"
29#else
30#include "ptrace_32.h"
31#endif
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#ifdef __KERNEL__
Paul Mundtda28c592010-06-14 16:02:47 +090034
35#include <linux/stringify.h>
36#include <linux/stddef.h>
37#include <linux/thread_info.h>
Paul Mundt33f242e2007-11-09 16:57:27 +090038#include <asm/addrspace.h>
Paul Mundtb0f3ae02010-02-12 15:40:00 +090039#include <asm/page.h>
Paul Mundt33f242e2007-11-09 16:57:27 +090040
41#define user_mode(regs) (((regs)->sr & 0x40000000)==0)
Roel Kluineac676e2011-01-01 18:36:36 +000042#define kernel_stack_pointer(_regs) ((unsigned long)(_regs)->regs[15])
Paul Mundtdb7eba22011-05-31 14:39:49 +090043
44#define GET_FP(regs) ((regs)->regs[14])
45#define GET_USP(regs) ((regs)->regs[15])
Paul Mundt33f242e2007-11-09 16:57:27 +090046
Paul Mundtc459dbf2008-07-30 19:09:31 +090047#define arch_has_single_step() (1)
Paul Mundtc459dbf2008-07-30 19:09:31 +090048
Paul Mundteaaaeef2010-06-14 15:16:53 +090049/*
50 * kprobe-based event tracer support
51 */
Paul Mundteaaaeef2010-06-14 15:16:53 +090052struct pt_regs_offset {
53 const char *name;
54 int offset;
55};
56
57#define REG_OFFSET_NAME(r) {.name = #r, .offset = offsetof(struct pt_regs, r)}
58#define REGS_OFFSET_NAME(num) \
59 {.name = __stringify(r##num), .offset = offsetof(struct pt_regs, regs[num])}
Paul Mundtda28c592010-06-14 16:02:47 +090060#define TREGS_OFFSET_NAME(num) \
61 {.name = __stringify(tr##num), .offset = offsetof(struct pt_regs, tregs[num])}
Paul Mundteaaaeef2010-06-14 15:16:53 +090062#define REG_OFFSET_END {.name = NULL, .offset = 0}
63
64/* Query offset/name of register from its name/offset */
65extern int regs_query_register_offset(const char *name);
66extern const char *regs_query_register_name(unsigned int offset);
67
68extern const struct pt_regs_offset regoffset_table[];
69
70/**
71 * regs_get_register() - get register value from its offset
72 * @regs: pt_regs from which register value is gotten.
73 * @offset: offset number of the register.
74 *
75 * regs_get_register returns the value of a register. The @offset is the
76 * offset of the register in struct pt_regs address which specified by @regs.
77 * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
78 */
79static inline unsigned long regs_get_register(struct pt_regs *regs,
80 unsigned int offset)
81{
82 if (unlikely(offset > MAX_REG_OFFSET))
83 return 0;
84 return *(unsigned long *)((unsigned long)regs + offset);
85}
86
87/**
88 * regs_within_kernel_stack() - check the address in the stack
89 * @regs: pt_regs which contains kernel stack pointer.
90 * @addr: address which is checked.
91 *
92 * regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
93 * If @addr is within the kernel stack, it returns true. If not, returns false.
94 */
95static inline int regs_within_kernel_stack(struct pt_regs *regs,
96 unsigned long addr)
97{
98 return ((addr & ~(THREAD_SIZE - 1)) ==
99 (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1)));
100}
101
102/**
103 * regs_get_kernel_stack_nth() - get Nth entry of the stack
104 * @regs: pt_regs which contains kernel stack pointer.
105 * @n: stack entry number.
106 *
107 * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
108 * is specified by @regs. If the @n th entry is NOT in the kernel stack,
109 * this returns 0.
110 */
111static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
112 unsigned int n)
113{
114 unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
115 addr += n;
116 if (regs_within_kernel_stack(regs, (unsigned long)addr))
117 return *addr;
118 else
119 return 0;
120}
121
Paul Mundt34d0b5a2009-12-28 17:53:47 +0900122struct perf_event;
123struct perf_sample_data;
124
Paul Gortmakerc84b51e2011-07-31 21:36:35 +0000125extern void ptrace_triggered(struct perf_event *bp,
Paul Mundt34d0b5a2009-12-28 17:53:47 +0900126 struct perf_sample_data *data, struct pt_regs *regs);
127
Al Viro3cf0f4e2006-01-12 01:05:44 -0800128#define task_pt_regs(task) \
Magnus Damm4f099eb2009-02-23 07:16:34 +0000129 ((struct pt_regs *) (task_stack_page(task) + THREAD_SIZE) - 1)
Al Viro3cf0f4e2006-01-12 01:05:44 -0800130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131static inline unsigned long profile_pc(struct pt_regs *regs)
132{
Paul Mundtdb7eba22011-05-31 14:39:49 +0900133 unsigned long pc = regs->pc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Paul Mundt9edef282010-02-17 16:28:00 +0900135 if (virt_addr_uncached(pc))
136 return CAC_ADDR(pc);
Paul Mundt33f242e2007-11-09 16:57:27 +0900137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 return pc;
139}
Mike Frysinger3cea45c2011-05-26 16:25:44 -0700140#define profile_pc profile_pc
141
142#include <asm-generic/ptrace.h>
Paul Mundt33f242e2007-11-09 16:57:27 +0900143#endif /* __KERNEL__ */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
145#endif /* __ASM_SH_PTRACE_H */