Merge tag 'powerpc-4.12-1' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc...
[sfrench/cifs-2.6.git] / arch / c6x / kernel / ptrace.c
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 #include <linux/sched/task_stack.h>
18
19 #include <asm/cacheflush.h>
20
21 #define PT_REG_SIZE       (sizeof(struct pt_regs))
22
23 /*
24  * Called by kernel/ptrace.c when detaching.
25  */
26 void ptrace_disable(struct task_struct *child)
27 {
28         /* nothing to do */
29 }
30
31 /*
32  * Get a register number from live pt_regs for the specified task.
33  */
34 static inline long get_reg(struct task_struct *task, int regno)
35 {
36         long *addr = (long *)task_pt_regs(task);
37
38         if (regno == PT_TSR || regno == PT_CSR)
39                 return 0;
40
41         return addr[regno];
42 }
43
44 /*
45  * Write contents of register REGNO in task TASK.
46  */
47 static inline int put_reg(struct task_struct *task,
48                           int regno,
49                           unsigned long data)
50 {
51         unsigned long *addr = (unsigned long *)task_pt_regs(task);
52
53         if (regno != PT_TSR && regno != PT_CSR)
54                 addr[regno] = data;
55
56         return 0;
57 }
58
59 /* regset get/set implementations */
60
61 static int gpr_get(struct task_struct *target,
62                    const struct user_regset *regset,
63                    unsigned int pos, unsigned int count,
64                    void *kbuf, void __user *ubuf)
65 {
66         struct pt_regs *regs = task_pt_regs(target);
67
68         return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
69                                    regs,
70                                    0, sizeof(*regs));
71 }
72
73 enum c6x_regset {
74         REGSET_GPR,
75 };
76
77 static const struct user_regset c6x_regsets[] = {
78         [REGSET_GPR] = {
79                 .core_note_type = NT_PRSTATUS,
80                 .n = ELF_NGREG,
81                 .size = sizeof(u32),
82                 .align = sizeof(u32),
83                 .get = gpr_get,
84         },
85 };
86
87 static const struct user_regset_view user_c6x_native_view = {
88         .name           = "tic6x",
89         .e_machine      = EM_TI_C6000,
90         .regsets        = c6x_regsets,
91         .n              = ARRAY_SIZE(c6x_regsets),
92 };
93
94 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
95 {
96         return &user_c6x_native_view;
97 }
98
99 /*
100  * Perform ptrace request
101  */
102 long arch_ptrace(struct task_struct *child, long request,
103                  unsigned long addr, unsigned long data)
104 {
105         int ret = 0;
106
107         switch (request) {
108                 /*
109                  * write the word at location addr.
110                  */
111         case PTRACE_POKETEXT:
112                 ret = generic_ptrace_pokedata(child, addr, data);
113                 if (ret == 0 && request == PTRACE_POKETEXT)
114                         flush_icache_range(addr, addr + 4);
115                 break;
116         default:
117                 ret = ptrace_request(child, request, addr, data);
118                 break;
119         }
120
121         return ret;
122 }
123
124 /*
125  * handle tracing of system call entry
126  * - return the revised system call number or ULONG_MAX to cause ENOSYS
127  */
128 asmlinkage unsigned long syscall_trace_entry(struct pt_regs *regs)
129 {
130         if (tracehook_report_syscall_entry(regs))
131                 /* tracing decided this syscall should not happen, so
132                  * We'll return a bogus call number to get an ENOSYS
133                  * error, but leave the original number in
134                  * regs->orig_a4
135                  */
136                 return ULONG_MAX;
137
138         return regs->b0;
139 }
140
141 /*
142  * handle tracing of system call exit
143  */
144 asmlinkage void syscall_trace_exit(struct pt_regs *regs)
145 {
146         tracehook_report_syscall_exit(regs, 0);
147 }