4 * Linux architectural port borrowing liberally from similar works of
5 * others. All original copyrights apply as per the original source
8 * Modifications for the OpenRISC architecture:
9 * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>
10 * Copyright (C) 2005 Gyorgy Jeney <nog@bsemi.com>
11 * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version
16 * 2 of the License, or (at your option) any later version.
19 #include <linux/kernel.h>
20 #include <linux/sched.h>
21 #include <linux/string.h>
24 #include <linux/errno.h>
25 #include <linux/ptrace.h>
26 #include <linux/audit.h>
27 #include <linux/regset.h>
28 #include <linux/tracehook.h>
29 #include <linux/elf.h>
31 #include <asm/thread_info.h>
32 #include <asm/segment.h>
34 #include <asm/pgtable.h>
37 * Copy the thread state to a regset that can be interpreted by userspace.
39 * It doesn't matter what our internal pt_regs structure looks like. The
40 * important thing is that we export a consistent view of the thread state
41 * to userspace. As such, we need to make sure that the regset remains
42 * ABI compatible as defined by the struct user_regs_struct:
44 * (Each item is a 32-bit word)
45 * r0 = 0 (exported for clarity)
47 * PC (Program counter)
48 * SR (Supervision register)
50 static int genregs_get(struct task_struct *target,
51 const struct user_regset *regset,
52 unsigned int pos, unsigned int count,
53 void *kbuf, void __user * ubuf)
55 const struct pt_regs *regs = task_pt_regs(target);
59 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf, 0, 4);
62 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
63 regs->gpr+1, 4, 4*32);
65 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
66 ®s->pc, 4*32, 4*33);
68 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
69 ®s->sr, 4*33, 4*34);
71 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
78 * Set the thread state from a regset passed in via ptrace
80 static int genregs_set(struct task_struct *target,
81 const struct user_regset *regset,
82 unsigned int pos, unsigned int count,
83 const void *kbuf, const void __user * ubuf)
85 struct pt_regs *regs = task_pt_regs(target);
89 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf, 0, 4);
92 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
93 regs->gpr+1, 4, 4*32);
96 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
97 ®s->pc, 4*32, 4*33);
99 * Skip SR and padding... userspace isn't allowed to changes bits in
100 * the Supervision register
103 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
110 * Define the register sets available on OpenRISC under Linux
116 static const struct user_regset or1k_regsets[] = {
118 .core_note_type = NT_PRSTATUS,
120 .size = sizeof(long),
121 .align = sizeof(long),
127 static const struct user_regset_view user_or1k_native_view = {
129 .e_machine = EM_OPENRISC,
130 .regsets = or1k_regsets,
131 .n = ARRAY_SIZE(or1k_regsets),
134 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
136 return &user_or1k_native_view;
140 * does not yet catch signals sent when the child dies.
141 * in exit.c or in signal.c.
146 * Called by kernel/ptrace.c when detaching..
148 * Make sure the single step bit is not set.
150 void ptrace_disable(struct task_struct *child)
152 pr_debug("ptrace_disable(): TODO\n");
154 user_disable_single_step(child);
155 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
158 long arch_ptrace(struct task_struct *child, long request, unsigned long addr,
165 ret = ptrace_request(child, request, addr, data);
173 * Notification of system call entry/exit
174 * - triggered by current->work.syscall_trace
176 asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
180 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
181 tracehook_report_syscall_entry(regs))
183 * Tracing decided this syscall should not happen.
184 * We'll return a bogus call number to get an ENOSYS
185 * error, but leave the original number in <something>.
189 audit_syscall_entry(regs->gpr[11], regs->gpr[3], regs->gpr[4],
190 regs->gpr[5], regs->gpr[6]);
192 return ret ? : regs->gpr[11];
195 asmlinkage void do_syscall_trace_leave(struct pt_regs *regs)
199 audit_syscall_exit(regs);
201 step = test_thread_flag(TIF_SINGLESTEP);
202 if (step || test_thread_flag(TIF_SYSCALL_TRACE))
203 tracehook_report_syscall_exit(regs, step);