summaryrefslogtreecommitdiff
path: root/arch/nds32/kernel/ptrace.c
blob: eaaf7a999b202f2a772c28a6ea20dab914fb82ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// SPDX-License-Identifier: GPL-2.0
// Copyright (C) 2005-2017 Andes Technology Corporation

#include <linux/ptrace.h>
#include <linux/regset.h>
#include <linux/tracehook.h>
#include <linux/elf.h>
#include <linux/sched/task_stack.h>

enum nds32_regset {
	REGSET_GPR,
};

static int gpr_get(struct task_struct *target,
		   const struct user_regset *regset,
		   unsigned int pos, unsigned int count,
		   void *kbuf, void __user * ubuf)
{
	struct user_pt_regs *uregs = &task_pt_regs(target)->user_regs;
	return user_regset_copyout(&pos, &count, &kbuf, &ubuf, uregs, 0, -1);
}

static int gpr_set(struct task_struct *target, const struct user_regset *regset,
		   unsigned int pos, unsigned int count,
		   const void *kbuf, const void __user * ubuf)
{
	int err;
	struct user_pt_regs newregs = task_pt_regs(target)->user_regs;

	err = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &newregs, 0, -1);
	if (err)
		return err;

	task_pt_regs(target)->user_regs = newregs;
	return 0;
}

static const struct user_regset nds32_regsets[] = {
	[REGSET_GPR] = {
			.core_note_type = NT_PRSTATUS,
			.n = sizeof(struct user_pt_regs) / sizeof(u32),
			.size = sizeof(elf_greg_t),
			.align = sizeof(elf_greg_t),
			.get = gpr_get,
			.set = gpr_set}
};

static const struct user_regset_view nds32_user_view = {
	.name = "nds32",
	.e_machine = EM_NDS32,
	.regsets = nds32_regsets,
	.n = ARRAY_SIZE(nds32_regsets)
};

const struct user_regset_view *task_user_regset_view(struct task_struct *task)
{
	return &nds32_user_view;
}

void ptrace_disable(struct task_struct *child)
{
	user_disable_single_step(child);
}

/* do_ptrace()
 *
 * Provide ptrace defined service.
 */
long arch_ptrace(struct task_struct *child, long request, unsigned long addr,
		 unsigned long data)
{
	int ret = -EIO;

	switch (request) {
	default:
		ret = ptrace_request(child, request, addr, data);
		break;
	}

	return ret;
}

void user_enable_single_step(struct task_struct *child)
{
	struct pt_regs *regs;
	regs = task_pt_regs(child);
	regs->ipsw |= PSW_mskHSS;
	set_tsk_thread_flag(child, TIF_SINGLESTEP);
}

void user_disable_single_step(struct task_struct *child)
{
	struct pt_regs *regs;
	regs = task_pt_regs(child);
	regs->ipsw &= ~PSW_mskHSS;
	clear_tsk_thread_flag(child, TIF_SINGLESTEP);
}

/* sys_trace()
 *
 * syscall trace handler.
 */

asmlinkage int syscall_trace_enter(struct pt_regs *regs)
{
	if (test_thread_flag(TIF_SYSCALL_TRACE)) {
		if (tracehook_report_syscall_entry(regs))
			forget_syscall(regs);
	}
	return regs->syscallno;
}

asmlinkage void syscall_trace_leave(struct pt_regs *regs)
{
	int step = test_thread_flag(TIF_SINGLESTEP);
	if (step || test_thread_flag(TIF_SYSCALL_TRACE))
		tracehook_report_syscall_exit(regs, step);

}