2 * Copyright (C) 2014 Altera Corporation
3 * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
5 * This file is subject to the terms and conditions of the GNU General
6 * Public License. See the file COPYING in the main directory of this
7 * archive for more details.
10 #include <linux/elf.h>
11 #include <linux/errno.h>
12 #include <linux/kernel.h>
14 #include <linux/ptrace.h>
15 #include <linux/regset.h>
16 #include <linux/sched.h>
17 #include <linux/sched/task_stack.h>
18 #include <linux/tracehook.h>
19 #include <linux/uaccess.h>
20 #include <linux/user.h>
22 static int genregs_get(struct task_struct
*target
,
23 const struct user_regset
*regset
,
26 const struct pt_regs
*regs
= task_pt_regs(target
);
27 const struct switch_stack
*sw
= (struct switch_stack
*)regs
- 1;
29 membuf_zero(&to
, 4); // R0
30 membuf_write(&to
, ®s
->r1
, 7 * 4); // R1..R7
31 membuf_write(&to
, ®s
->r8
, 8 * 4); // R8..R15
32 membuf_write(&to
, sw
, 8 * 4); // R16..R23
33 membuf_zero(&to
, 2 * 4); /* et and bt */
34 membuf_store(&to
, regs
->gp
);
35 membuf_store(&to
, regs
->sp
);
36 membuf_store(&to
, regs
->fp
);
37 membuf_store(&to
, regs
->ea
);
38 membuf_zero(&to
, 4); // PTR_BA
39 membuf_store(&to
, regs
->ra
);
40 membuf_store(&to
, regs
->ea
); /* use ea for PC */
41 return membuf_zero(&to
, (NUM_PTRACE_REG
- PTR_PC
) * 4);
45 * Set the thread state from a regset passed in via ptrace
47 static int genregs_set(struct task_struct
*target
,
48 const struct user_regset
*regset
,
49 unsigned int pos
, unsigned int count
,
50 const void *kbuf
, const void __user
*ubuf
)
52 struct pt_regs
*regs
= task_pt_regs(target
);
53 const struct switch_stack
*sw
= (struct switch_stack
*)regs
- 1;
56 #define REG_IGNORE_RANGE(START, END) \
58 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf, \
59 START * 4, (END * 4) + 4);
61 #define REG_IN_ONE(PTR, LOC) \
63 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, \
64 (void *)(PTR), LOC * 4, (LOC * 4) + 4);
66 #define REG_IN_RANGE(PTR, START, END) \
68 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, \
69 (void *)(PTR), START * 4, (END * 4) + 4);
71 REG_IGNORE_RANGE(PTR_R0
, PTR_R0
);
72 REG_IN_RANGE(®s
->r1
, PTR_R1
, PTR_R7
);
73 REG_IN_RANGE(®s
->r8
, PTR_R8
, PTR_R15
);
74 REG_IN_RANGE(sw
, PTR_R16
, PTR_R23
);
75 REG_IGNORE_RANGE(PTR_R24
, PTR_R25
); /* et and bt */
76 REG_IN_ONE(®s
->gp
, PTR_GP
);
77 REG_IN_ONE(®s
->sp
, PTR_SP
);
78 REG_IN_ONE(®s
->fp
, PTR_FP
);
79 REG_IN_ONE(®s
->ea
, PTR_EA
);
80 REG_IGNORE_RANGE(PTR_BA
, PTR_BA
);
81 REG_IN_ONE(®s
->ra
, PTR_RA
);
82 REG_IN_ONE(®s
->ea
, PTR_PC
); /* use ea for PC */
84 ret
= user_regset_copyin_ignore(&pos
, &count
, &kbuf
, &ubuf
,
91 * Define the register sets available on Nios2 under Linux
97 static const struct user_regset nios2_regsets
[] = {
99 .core_note_type
= NT_PRSTATUS
,
101 .size
= sizeof(unsigned long),
102 .align
= sizeof(unsigned long),
103 .regset_get
= genregs_get
,
108 static const struct user_regset_view nios2_user_view
= {
110 .e_machine
= ELF_ARCH
,
111 .ei_osabi
= ELF_OSABI
,
112 .regsets
= nios2_regsets
,
113 .n
= ARRAY_SIZE(nios2_regsets
)
116 const struct user_regset_view
*task_user_regset_view(struct task_struct
*task
)
118 return &nios2_user_view
;
121 void ptrace_disable(struct task_struct
*child
)
126 long arch_ptrace(struct task_struct
*child
, long request
, unsigned long addr
,
129 return ptrace_request(child
, request
, addr
, data
);
132 asmlinkage
int do_syscall_trace_enter(void)
136 if (test_thread_flag(TIF_SYSCALL_TRACE
))
137 ret
= tracehook_report_syscall_entry(task_pt_regs(current
));
142 asmlinkage
void do_syscall_trace_exit(void)
144 if (test_thread_flag(TIF_SYSCALL_TRACE
))
145 tracehook_report_syscall_exit(task_pt_regs(current
), 0);