forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/arch/hexagon/kernel/ptrace.c
....@@ -1,21 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Ptrace support for Hexagon
34 *
45 * Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License version 2 and
8
- * only version 2 as published by the Free Software Foundation.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program; if not, write to the Free Software
17
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18
- * 02110-1301, USA.
196 */
207
218 #include <linux/kernel.h>
....@@ -48,16 +35,9 @@
4835
4936 static int genregs_get(struct task_struct *target,
5037 const struct user_regset *regset,
51
- unsigned int pos, unsigned int count,
52
- void *kbuf, void __user *ubuf)
38
+ struct membuf to)
5339 {
54
- int ret;
55
- unsigned int dummy;
5640 struct pt_regs *regs = task_pt_regs(target);
57
-
58
-
59
- if (!regs)
60
- return -EIO;
6141
6242 /* The general idea here is that the copyout must happen in
6343 * exactly the same order in which the userspace expects these
....@@ -65,41 +45,28 @@
6545 * sequence in the kernel, so everything past the 32 gprs
6646 * happens one at a time.
6747 */
68
- ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
69
- &regs->r00, 0, 32*sizeof(unsigned long));
70
-
71
-#define ONEXT(KPT_REG, USR_REG) \
72
- if (!ret) \
73
- ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, \
74
- KPT_REG, offsetof(struct user_regs_struct, USR_REG), \
75
- offsetof(struct user_regs_struct, USR_REG) + \
76
- sizeof(unsigned long));
77
-
48
+ membuf_write(&to, &regs->r00, 32*sizeof(unsigned long));
7849 /* Must be exactly same sequence as struct user_regs_struct */
79
- ONEXT(&regs->sa0, sa0);
80
- ONEXT(&regs->lc0, lc0);
81
- ONEXT(&regs->sa1, sa1);
82
- ONEXT(&regs->lc1, lc1);
83
- ONEXT(&regs->m0, m0);
84
- ONEXT(&regs->m1, m1);
85
- ONEXT(&regs->usr, usr);
86
- ONEXT(&regs->preds, p3_0);
87
- ONEXT(&regs->gp, gp);
88
- ONEXT(&regs->ugp, ugp);
89
- ONEXT(&pt_elr(regs), pc);
90
- dummy = pt_cause(regs);
91
- ONEXT(&dummy, cause);
92
- ONEXT(&pt_badva(regs), badva);
50
+ membuf_store(&to, regs->sa0);
51
+ membuf_store(&to, regs->lc0);
52
+ membuf_store(&to, regs->sa1);
53
+ membuf_store(&to, regs->lc1);
54
+ membuf_store(&to, regs->m0);
55
+ membuf_store(&to, regs->m1);
56
+ membuf_store(&to, regs->usr);
57
+ membuf_store(&to, regs->preds);
58
+ membuf_store(&to, regs->gp);
59
+ membuf_store(&to, regs->ugp);
60
+ membuf_store(&to, pt_elr(regs)); // pc
61
+ membuf_store(&to, (unsigned long)pt_cause(regs)); // cause
62
+ membuf_store(&to, pt_badva(regs)); // badva
9363 #if CONFIG_HEXAGON_ARCH_VERSION >=4
94
- ONEXT(&regs->cs0, cs0);
95
- ONEXT(&regs->cs1, cs1);
64
+ membuf_store(&to, regs->cs0);
65
+ membuf_store(&to, regs->cs1);
66
+ return membuf_zero(&to, sizeof(unsigned long));
67
+#else
68
+ return membuf_zero(&to, 3 * sizeof(unsigned long));
9669 #endif
97
-
98
- /* Pad the rest with zeros, if needed */
99
- if (!ret)
100
- ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
101
- offsetof(struct user_regs_struct, pad1), -1);
102
- return ret;
10370 }
10471
10572 static int genregs_set(struct task_struct *target,
....@@ -172,7 +139,7 @@
172139 .n = ELF_NGREG,
173140 .size = sizeof(unsigned long),
174141 .align = sizeof(unsigned long),
175
- .get = genregs_get,
142
+ .regset_get = genregs_get,
176143 .set = genregs_set,
177144 },
178145 };