MAINTAINERS: Remove deleted platform efm32
[linux-2.6-microblaze.git] / arch / c6x / kernel / ptrace.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  *  Port on Texas Instruments TMS320C6x architecture
4  *
5  *  Copyright (C) 2004, 2006, 2009, 2010, 2011 Texas Instruments Incorporated
6  *  Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com)
7  *
8  *  Updated for 2.6.34: Mark Salter <msalter@redhat.com>
9  */
10 #include <linux/ptrace.h>
11 #include <linux/tracehook.h>
12 #include <linux/regset.h>
13 #include <linux/elf.h>
14 #include <linux/sched/task_stack.h>
15
16 #include <asm/cacheflush.h>
17
18 #define PT_REG_SIZE       (sizeof(struct pt_regs))
19
20 /*
21  * Called by kernel/ptrace.c when detaching.
22  */
23 void ptrace_disable(struct task_struct *child)
24 {
25         /* nothing to do */
26 }
27
28 /*
29  * Get a register number from live pt_regs for the specified task.
30  */
31 static inline long get_reg(struct task_struct *task, int regno)
32 {
33         long *addr = (long *)task_pt_regs(task);
34
35         if (regno == PT_TSR || regno == PT_CSR)
36                 return 0;
37
38         return addr[regno];
39 }
40
41 /*
42  * Write contents of register REGNO in task TASK.
43  */
44 static inline int put_reg(struct task_struct *task,
45                           int regno,
46                           unsigned long data)
47 {
48         unsigned long *addr = (unsigned long *)task_pt_regs(task);
49
50         if (regno != PT_TSR && regno != PT_CSR)
51                 addr[regno] = data;
52
53         return 0;
54 }
55
56 /* regset get/set implementations */
57
58 static int gpr_get(struct task_struct *target,
59                    const struct user_regset *regset,
60                    struct membuf to)
61 {
62         return membuf_write(&to, task_pt_regs(target), sizeof(struct pt_regs));
63 }
64
65 enum c6x_regset {
66         REGSET_GPR,
67 };
68
69 static const struct user_regset c6x_regsets[] = {
70         [REGSET_GPR] = {
71                 .core_note_type = NT_PRSTATUS,
72                 .n = ELF_NGREG,
73                 .size = sizeof(u32),
74                 .align = sizeof(u32),
75                 .regset_get = gpr_get,
76         },
77 };
78
79 static const struct user_regset_view user_c6x_native_view = {
80         .name           = "tic6x",
81         .e_machine      = EM_TI_C6000,
82         .regsets        = c6x_regsets,
83         .n              = ARRAY_SIZE(c6x_regsets),
84 };
85
86 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
87 {
88         return &user_c6x_native_view;
89 }
90
91 /*
92  * Perform ptrace request
93  */
94 long arch_ptrace(struct task_struct *child, long request,
95                  unsigned long addr, unsigned long data)
96 {
97         int ret = 0;
98
99         switch (request) {
100                 /*
101                  * write the word at location addr.
102                  */
103         case PTRACE_POKETEXT:
104                 ret = generic_ptrace_pokedata(child, addr, data);
105                 if (ret == 0 && request == PTRACE_POKETEXT)
106                         flush_icache_range(addr, addr + 4);
107                 break;
108         default:
109                 ret = ptrace_request(child, request, addr, data);
110                 break;
111         }
112
113         return ret;
114 }
115
116 /*
117  * handle tracing of system call entry
118  * - return the revised system call number or ULONG_MAX to cause ENOSYS
119  */
120 asmlinkage unsigned long syscall_trace_entry(struct pt_regs *regs)
121 {
122         if (tracehook_report_syscall_entry(regs))
123                 /* tracing decided this syscall should not happen, so
124                  * We'll return a bogus call number to get an ENOSYS
125                  * error, but leave the original number in
126                  * regs->orig_a4
127                  */
128                 return ULONG_MAX;
129
130         return regs->b0;
131 }
132
133 /*
134  * handle tracing of system call exit
135  */
136 asmlinkage void syscall_trace_exit(struct pt_regs *regs)
137 {
138         tracehook_report_syscall_exit(regs, 0);
139 }