blob: 2506c7db76b70ef83db681e14f49cee27ccb5933 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (C) 1999, 2000 Niibe Yutaka
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 */
David Howells0a9426d2012-10-09 09:47:37 +01004#ifndef __ASM_SH_PTRACE_H
5#define __ASM_SH_PTRACE_H
Linus Torvalds1da177e2005-04-16 15:20:36 -07006
Paul Mundtda28c592010-06-14 16:02:47 +09007
8#include <linux/stringify.h>
9#include <linux/stddef.h>
10#include <linux/thread_info.h>
Paul Mundt33f242e2007-11-09 16:57:27 +090011#include <asm/addrspace.h>
Paul Mundtb0f3ae02010-02-12 15:40:00 +090012#include <asm/page.h>
David Howells0a9426d2012-10-09 09:47:37 +010013#include <uapi/asm/ptrace.h>
Paul Mundt33f242e2007-11-09 16:57:27 +090014
15#define user_mode(regs) (((regs)->sr & 0x40000000)==0)
Roel Kluineac676e2011-01-01 18:36:36 +000016#define kernel_stack_pointer(_regs) ((unsigned long)(_regs)->regs[15])
Paul Mundtdb7eba22011-05-31 14:39:49 +090017
18#define GET_FP(regs) ((regs)->regs[14])
19#define GET_USP(regs) ((regs)->regs[15])
Paul Mundt33f242e2007-11-09 16:57:27 +090020
Paul Mundtc459dbf2008-07-30 19:09:31 +090021#define arch_has_single_step() (1)
Paul Mundtc459dbf2008-07-30 19:09:31 +090022
Paul Mundteaaaeef32010-06-14 15:16:53 +090023/*
24 * kprobe-based event tracer support
25 */
Paul Mundteaaaeef32010-06-14 15:16:53 +090026struct 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 Mundtda28c592010-06-14 16:02:47 +090034#define TREGS_OFFSET_NAME(num) \
35 {.name = __stringify(tr##num), .offset = offsetof(struct pt_regs, tregs[num])}
Paul Mundteaaaeef32010-06-14 15:16:53 +090036#define REG_OFFSET_END {.name = NULL, .offset = 0}
37
38/* Query offset/name of register from its name/offset */
39extern int regs_query_register_offset(const char *name);
40extern const char *regs_query_register_name(unsigned int offset);
41
42extern 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 */
53static 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 */
69static 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 */
85static 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 Mundt34d0b5a2009-12-28 17:53:47 +090096struct perf_event;
97struct perf_sample_data;
98
Paul Gortmakerc84b51e2011-07-31 21:36:35 +000099extern void ptrace_triggered(struct perf_event *bp,
Paul Mundt34d0b5a2009-12-28 17:53:47 +0900100 struct perf_sample_data *data, struct pt_regs *regs);
101
Al Viro3cf0f4e2006-01-12 01:05:44 -0800102#define task_pt_regs(task) \
Magnus Damm4f099eb2009-02-23 07:16:34 +0000103 ((struct pt_regs *) (task_stack_page(task) + THREAD_SIZE) - 1)
Al Viro3cf0f4e2006-01-12 01:05:44 -0800104
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105static inline unsigned long profile_pc(struct pt_regs *regs)
106{
Paul Mundtdb7eba22011-05-31 14:39:49 +0900107 unsigned long pc = regs->pc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Paul Mundt9edef282010-02-17 16:28:00 +0900109 if (virt_addr_uncached(pc))
110 return CAC_ADDR(pc);
Paul Mundt33f242e2007-11-09 16:57:27 +0900111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 return pc;
113}
Mike Frysinger3cea45c2011-05-26 16:25:44 -0700114#define profile_pc profile_pc
115
116#include <asm-generic/ptrace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117#endif /* __ASM_SH_PTRACE_H */