aboutsummaryrefslogtreecommitdiffstats
path: root/arch/c6x
diff options
context:
space:
mode:
authorAurelien Jacquiot <a-jacquiot@ti.com>2011-10-04 11:13:21 -0400
committerMark Salter <msalter@redhat.com>2011-10-06 19:48:17 -0400
commit52679b2d735492bce02503bafb333da87fae22c2 (patch)
tree62675c1cf17721a70ffb39ffb186a9ef92f7d0f0 /arch/c6x
parent64236ac1444eecca4b7b51270879d58bd291c8c2 (diff)
C6X: ptrace support
Original port to early 2.6 kernel using TI COFF toolchain. Brought up to date by Mark Salter <msalter@redhat.com> Signed-off-by: Aurelien Jacquiot <a-jacquiot@ti.com> Signed-off-by: Mark Salter <msalter@redhat.com> Acked-by: Arnd Bergmann <arnd@arndb.de>
Diffstat (limited to 'arch/c6x')
-rw-r--r--arch/c6x/include/asm/ptrace.h174
-rw-r--r--arch/c6x/kernel/ptrace.c187
2 files changed, 361 insertions, 0 deletions
diff --git a/arch/c6x/include/asm/ptrace.h b/arch/c6x/include/asm/ptrace.h
new file mode 100644
index 000000000000..21e8d7931fe7
--- /dev/null
+++ b/arch/c6x/include/asm/ptrace.h
@@ -0,0 +1,174 @@
1/*
2 * Copyright (C) 2004, 2006, 2009, 2010 Texas Instruments Incorporated
3 * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com)
4 *
5 * Updated for 2.6.34: Mark Salter <msalter@redhat.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#ifndef _ASM_C6X_PTRACE_H
12#define _ASM_C6X_PTRACE_H
13
14#define BKPT_OPCODE 0x56454314 /* illegal opcode */
15
16#ifdef _BIG_ENDIAN
17#define PT_LO(odd, even) odd
18#define PT_HI(odd, even) even
19#else
20#define PT_LO(odd, even) even
21#define PT_HI(odd, even) odd
22#endif
23
24#define PT_A4_ORG PT_LO(1, 0)
25#define PT_TSR PT_HI(1, 0)
26#define PT_ILC PT_LO(3, 2)
27#define PT_RILC PT_HI(3, 2)
28#define PT_CSR PT_LO(5, 4)
29#define PT_PC PT_HI(5, 4)
30#define PT_B16 PT_LO(7, 6)
31#define PT_B17 PT_HI(7, 6)
32#define PT_B18 PT_LO(9, 8)
33#define PT_B19 PT_HI(9, 8)
34#define PT_B20 PT_LO(11, 10)
35#define PT_B21 PT_HI(11, 10)
36#define PT_B22 PT_LO(13, 12)
37#define PT_B23 PT_HI(13, 12)
38#define PT_B24 PT_LO(15, 14)
39#define PT_B25 PT_HI(15, 14)
40#define PT_B26 PT_LO(17, 16)
41#define PT_B27 PT_HI(17, 16)
42#define PT_B28 PT_LO(19, 18)
43#define PT_B29 PT_HI(19, 18)
44#define PT_B30 PT_LO(21, 20)
45#define PT_B31 PT_HI(21, 20)
46#define PT_B0 PT_LO(23, 22)
47#define PT_B1 PT_HI(23, 22)
48#define PT_B2 PT_LO(25, 24)
49#define PT_B3 PT_HI(25, 24)
50#define PT_B4 PT_LO(27, 26)
51#define PT_B5 PT_HI(27, 26)
52#define PT_B6 PT_LO(29, 28)
53#define PT_B7 PT_HI(29, 28)
54#define PT_B8 PT_LO(31, 30)
55#define PT_B9 PT_HI(31, 30)
56#define PT_B10 PT_LO(33, 32)
57#define PT_B11 PT_HI(33, 32)
58#define PT_B12 PT_LO(35, 34)
59#define PT_B13 PT_HI(35, 34)
60#define PT_A16 PT_LO(37, 36)
61#define PT_A17 PT_HI(37, 36)
62#define PT_A18 PT_LO(39, 38)
63#define PT_A19 PT_HI(39, 38)
64#define PT_A20 PT_LO(41, 40)
65#define PT_A21 PT_HI(41, 40)
66#define PT_A22 PT_LO(43, 42)
67#define PT_A23 PT_HI(43, 42)
68#define PT_A24 PT_LO(45, 44)
69#define PT_A25 PT_HI(45, 44)
70#define PT_A26 PT_LO(47, 46)
71#define PT_A27 PT_HI(47, 46)
72#define PT_A28 PT_LO(49, 48)
73#define PT_A29 PT_HI(49, 48)
74#define PT_A30 PT_LO(51, 50)
75#define PT_A31 PT_HI(51, 50)
76#define PT_A0 PT_LO(53, 52)
77#define PT_A1 PT_HI(53, 52)
78#define PT_A2 PT_LO(55, 54)
79#define PT_A3 PT_HI(55, 54)
80#define PT_A4 PT_LO(57, 56)
81#define PT_A5 PT_HI(57, 56)
82#define PT_A6 PT_LO(59, 58)
83#define PT_A7 PT_HI(59, 58)
84#define PT_A8 PT_LO(61, 60)
85#define PT_A9 PT_HI(61, 60)
86#define PT_A10 PT_LO(63, 62)
87#define PT_A11 PT_HI(63, 62)
88#define PT_A12 PT_LO(65, 64)
89#define PT_A13 PT_HI(65, 64)
90#define PT_A14 PT_LO(67, 66)
91#define PT_A15 PT_HI(67, 66)
92#define PT_B14 PT_LO(69, 68)
93#define PT_B15 PT_HI(69, 68)
94
95#define NR_PTREGS 70
96
97#define PT_DP PT_B14 /* Data Segment Pointer (B14) */
98#define PT_SP PT_B15 /* Stack Pointer (B15) */
99
100#ifndef __ASSEMBLY__
101
102#ifdef _BIG_ENDIAN
103#define REG_PAIR(odd, even) unsigned long odd; unsigned long even
104#else
105#define REG_PAIR(odd, even) unsigned long even; unsigned long odd
106#endif
107
108/*
109 * this struct defines the way the registers are stored on the
110 * stack during a system call. fields defined with REG_PAIR
111 * are saved and restored using double-word memory operations
112 * which means the word ordering of the pair depends on endianess.
113 */
114struct pt_regs {
115 REG_PAIR(tsr, orig_a4);
116 REG_PAIR(rilc, ilc);
117 REG_PAIR(pc, csr);
118
119 REG_PAIR(b17, b16);
120 REG_PAIR(b19, b18);
121 REG_PAIR(b21, b20);
122 REG_PAIR(b23, b22);
123 REG_PAIR(b25, b24);
124 REG_PAIR(b27, b26);
125 REG_PAIR(b29, b28);
126 REG_PAIR(b31, b30);
127
128 REG_PAIR(b1, b0);
129 REG_PAIR(b3, b2);
130 REG_PAIR(b5, b4);
131 REG_PAIR(b7, b6);
132 REG_PAIR(b9, b8);
133 REG_PAIR(b11, b10);
134 REG_PAIR(b13, b12);
135
136 REG_PAIR(a17, a16);
137 REG_PAIR(a19, a18);
138 REG_PAIR(a21, a20);
139 REG_PAIR(a23, a22);
140 REG_PAIR(a25, a24);
141 REG_PAIR(a27, a26);
142 REG_PAIR(a29, a28);
143 REG_PAIR(a31, a30);
144
145 REG_PAIR(a1, a0);
146 REG_PAIR(a3, a2);
147 REG_PAIR(a5, a4);
148 REG_PAIR(a7, a6);
149 REG_PAIR(a9, a8);
150 REG_PAIR(a11, a10);
151 REG_PAIR(a13, a12);
152
153 REG_PAIR(a15, a14);
154 REG_PAIR(sp, dp);
155};
156
157#ifdef __KERNEL__
158
159#include <linux/linkage.h>
160
161#define user_mode(regs) ((((regs)->tsr) & 0x40) != 0)
162
163#define instruction_pointer(regs) ((regs)->pc)
164#define profile_pc(regs) instruction_pointer(regs)
165#define user_stack_pointer(regs) ((regs)->sp)
166
167extern void show_regs(struct pt_regs *);
168
169extern asmlinkage unsigned long syscall_trace_entry(struct pt_regs *regs);
170extern asmlinkage void syscall_trace_exit(struct pt_regs *regs);
171
172#endif /* __KERNEL__ */
173#endif /* __ASSEMBLY__ */
174#endif /* _ASM_C6X_PTRACE_H */
diff --git a/arch/c6x/kernel/ptrace.c b/arch/c6x/kernel/ptrace.c
new file mode 100644
index 000000000000..3c494e84444d
--- /dev/null
+++ b/arch/c6x/kernel/ptrace.c
@@ -0,0 +1,187 @@
1/*
2 * Port on Texas Instruments TMS320C6x architecture
3 *
4 * Copyright (C) 2004, 2006, 2009, 2010, 2011 Texas Instruments Incorporated
5 * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com)
6 *
7 * Updated for 2.6.34: Mark Salter <msalter@redhat.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13#include <linux/ptrace.h>
14#include <linux/tracehook.h>
15#include <linux/regset.h>
16#include <linux/elf.h>
17
18#include <asm/cacheflush.h>
19
20#define PT_REG_SIZE (sizeof(struct pt_regs))
21
22/*
23 * Called by kernel/ptrace.c when detaching.
24 */
25void ptrace_disable(struct task_struct *child)
26{
27 /* nothing to do */
28}
29
30/*
31 * Get a register number from live pt_regs for the specified task.
32 */
33static inline long get_reg(struct task_struct *task, int regno)
34{
35 long *addr = (long *)task_pt_regs(task);
36
37 if (regno == PT_TSR || regno == PT_CSR)
38 return 0;
39
40 return addr[regno];
41}
42
43/*
44 * Write contents of register REGNO in task TASK.
45 */
46static inline int put_reg(struct task_struct *task,
47 int regno,
48 unsigned long data)
49{
50 unsigned long *addr = (unsigned long *)task_pt_regs(task);
51
52 if (regno != PT_TSR && regno != PT_CSR)
53 addr[regno] = data;
54
55 return 0;
56}
57
58/* regset get/set implementations */
59
60static int gpr_get(struct task_struct *target,
61 const struct user_regset *regset,
62 unsigned int pos, unsigned int count,
63 void *kbuf, void __user *ubuf)
64{
65 struct pt_regs *regs = task_pt_regs(target);
66
67 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
68 regs,
69 0, sizeof(*regs));
70}
71
72static int gpr_set(struct task_struct *target,
73 const struct user_regset *regset,
74 unsigned int pos, unsigned int count,
75 const void *kbuf, const void __user *ubuf)
76{
77 int ret;
78 struct pt_regs *regs = task_pt_regs(target);
79
80 /* Don't copyin TSR or CSR */
81 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
82 &regs,
83 0, PT_TSR * sizeof(long));
84 if (ret)
85 return ret;
86
87 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
88 PT_TSR * sizeof(long),
89 (PT_TSR + 1) * sizeof(long));
90 if (ret)
91 return ret;
92
93 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
94 &regs,
95 (PT_TSR + 1) * sizeof(long),
96 PT_CSR * sizeof(long));
97 if (ret)
98 return ret;
99
100 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
101 PT_CSR * sizeof(long),
102 (PT_CSR + 1) * sizeof(long));
103 if (ret)
104 return ret;
105
106 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
107 &regs,
108 (PT_CSR + 1) * sizeof(long), -1);
109 return ret;
110}
111
112enum c6x_regset {
113 REGSET_GPR,
114};
115
116static const struct user_regset c6x_regsets[] = {
117 [REGSET_GPR] = {
118 .core_note_type = NT_PRSTATUS,
119 .n = ELF_NGREG,
120 .size = sizeof(u32),
121 .align = sizeof(u32),
122 .get = gpr_get,
123 .set = gpr_set
124 },
125};
126
127static const struct user_regset_view user_c6x_native_view = {
128 .name = "tic6x",
129 .e_machine = EM_TI_C6000,
130 .regsets = c6x_regsets,
131 .n = ARRAY_SIZE(c6x_regsets),
132};
133
134const struct user_regset_view *task_user_regset_view(struct task_struct *task)
135{
136 return &user_c6x_native_view;
137}
138
139/*
140 * Perform ptrace request
141 */
142long arch_ptrace(struct task_struct *child, long request,
143 unsigned long addr, unsigned long data)
144{
145 int ret = 0;
146
147 switch (request) {
148 /*
149 * write the word at location addr.
150 */
151 case PTRACE_POKETEXT:
152 ret = generic_ptrace_pokedata(child, addr, data);
153 if (ret == 0 && request == PTRACE_POKETEXT)
154 flush_icache_range(addr, addr + 4);
155 break;
156 default:
157 ret = ptrace_request(child, request, addr, data);
158 break;
159 }
160
161 return ret;
162}
163
164/*
165 * handle tracing of system call entry
166 * - return the revised system call number or ULONG_MAX to cause ENOSYS
167 */
168asmlinkage unsigned long syscall_trace_entry(struct pt_regs *regs)
169{
170 if (tracehook_report_syscall_entry(regs))
171 /* tracing decided this syscall should not happen, so
172 * We'll return a bogus call number to get an ENOSYS
173 * error, but leave the original number in
174 * regs->orig_a4
175 */
176 return ULONG_MAX;
177
178 return regs->b0;
179}
180
181/*
182 * handle tracing of system call exit
183 */
184asmlinkage void syscall_trace_exit(struct pt_regs *regs)
185{
186 tracehook_report_syscall_exit(regs, 0);
187}