GNU Linux-libre 4.4.288-gnu1
[releases.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
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  */
25 void 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  */
33 static 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  */
46 static 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
60 static 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
72 enum c6x_regset {
73         REGSET_GPR,
74 };
75
76 static const struct user_regset c6x_regsets[] = {
77         [REGSET_GPR] = {
78                 .core_note_type = NT_PRSTATUS,
79                 .n = ELF_NGREG,
80                 .size = sizeof(u32),
81                 .align = sizeof(u32),
82                 .get = gpr_get,
83         },
84 };
85
86 static const struct user_regset_view user_c6x_native_view = {
87         .name           = "tic6x",
88         .e_machine      = EM_TI_C6000,
89         .regsets        = c6x_regsets,
90         .n              = ARRAY_SIZE(c6x_regsets),
91 };
92
93 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
94 {
95         return &user_c6x_native_view;
96 }
97
98 /*
99  * Perform ptrace request
100  */
101 long arch_ptrace(struct task_struct *child, long request,
102                  unsigned long addr, unsigned long data)
103 {
104         int ret = 0;
105
106         switch (request) {
107                 /*
108                  * write the word at location addr.
109                  */
110         case PTRACE_POKETEXT:
111                 ret = generic_ptrace_pokedata(child, addr, data);
112                 if (ret == 0 && request == PTRACE_POKETEXT)
113                         flush_icache_range(addr, addr + 4);
114                 break;
115         default:
116                 ret = ptrace_request(child, request, addr, data);
117                 break;
118         }
119
120         return ret;
121 }
122
123 /*
124  * handle tracing of system call entry
125  * - return the revised system call number or ULONG_MAX to cause ENOSYS
126  */
127 asmlinkage unsigned long syscall_trace_entry(struct pt_regs *regs)
128 {
129         if (tracehook_report_syscall_entry(regs))
130                 /* tracing decided this syscall should not happen, so
131                  * We'll return a bogus call number to get an ENOSYS
132                  * error, but leave the original number in
133                  * regs->orig_a4
134                  */
135                 return ULONG_MAX;
136
137         return regs->b0;
138 }
139
140 /*
141  * handle tracing of system call exit
142  */
143 asmlinkage void syscall_trace_exit(struct pt_regs *regs)
144 {
145         tracehook_report_syscall_exit(regs, 0);
146 }