-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path0001-Build-strace-for-RISC-V.patch
239 lines (234 loc) · 7.04 KB
/
0001-Build-strace-for-RISC-V.patch
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
From e6d4b3e29991b8694640518d6a9e12dfde3676d3 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <[email protected]>
Date: Tue, 20 Jan 2015 23:31:22 -0800
Subject: [PATCH] Build strace for RISC-V
The original port of strace was done by Palmer Dabbelt
(eecs.berkeley.edu), based on strace 4.9.
Signed-off-by: Richard W.M. Jones <[email protected]>
---
Makefile.am | 13 +++++++++++++
clone.c | 2 +-
configure.ac | 5 +++++
defs.h | 2 ++
linux/riscv/arch_regs.c | 3 +++
linux/riscv/errnoent1.h | 2 ++
linux/riscv/get_error.c | 10 ++++++++++
linux/riscv/get_scno.c | 7 +++++++
linux/riscv/get_syscall_args.c | 12 ++++++++++++
linux/riscv/ioctls_arch0.h | 1 +
linux/riscv/ioctls_arch1.h | 1 +
linux/riscv/ioctls_inc0.h | 1 +
linux/riscv/ioctls_inc1.h | 1 +
linux/riscv/signalent1.h | 2 ++
linux/riscv/stat32.h | 1 +
linux/riscv/syscallent.h | 1 +
linux/riscv/syscallent1.h | 1 +
17 files changed, 64 insertions(+), 1 deletion(-)
create mode 100644 linux/riscv/arch_regs.c
create mode 100644 linux/riscv/errnoent1.h
create mode 100644 linux/riscv/get_error.c
create mode 100644 linux/riscv/get_scno.c
create mode 100644 linux/riscv/get_syscall_args.c
create mode 100644 linux/riscv/ioctls_arch0.h
create mode 100644 linux/riscv/ioctls_arch1.h
create mode 100644 linux/riscv/ioctls_inc0.h
create mode 100644 linux/riscv/ioctls_inc1.h
create mode 100644 linux/riscv/signalent1.h
create mode 100644 linux/riscv/stat32.h
create mode 100644 linux/riscv/syscallent.h
create mode 100644 linux/riscv/syscallent1.h
diff --git a/Makefile.am b/Makefile.am
index 3125a57..32d2092 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -499,6 +499,19 @@ EXTRA_DIST = \
linux/powerpc64/syscallent1.h \
linux/powerpc64/userent.h \
linux/ptp_clock.h \
+ linux/riscv/arch_regs.c \
+ linux/riscv/errnoent1.h \
+ linux/riscv/get_error.c \
+ linux/riscv/get_scno.c \
+ linux/riscv/get_syscall_args.c \
+ linux/riscv/ioctls_arch0.h \
+ linux/riscv/ioctls_arch1.h \
+ linux/riscv/ioctls_inc0.h \
+ linux/riscv/ioctls_inc1.h \
+ linux/riscv/signalent1.h \
+ linux/riscv/stat32.h \
+ linux/riscv/syscallent.h \
+ linux/riscv/syscallent1.h \
linux/s390/arch_regs.c \
linux/s390/arch_regs.h \
linux/s390/arch_sigreturn.c \
diff --git a/clone.c b/clone.c
index 0138631..604a695 100644
--- a/clone.c
+++ b/clone.c
@@ -59,7 +59,7 @@
# define ARG_PTID 2
# define ARG_CTID ((current_personality != 1) ? 3 : 4)
# define ARG_TLS ((current_personality != 1) ? 4 : 3)
-#elif defined ALPHA || defined TILE || defined OR1K
+#elif defined ALPHA || defined TILE || defined OR1K || defined RISCV
# define ARG_FLAGS 0
# define ARG_STACK 1
# define ARG_PTID 2
diff --git a/configure.ac b/configure.ac
index 0800f1f..bbd4110 100644
--- a/configure.ac
+++ b/configure.ac
@@ -187,6 +187,11 @@ xtensa*)
AC_DEFINE([XTENSA], 1, [Define for the Xtensa architecture])
;;
+riscv*)
+ arch=riscv
+ AC_DEFINE([RISCV], 1, [Define for the RISC-V architecture])
+ ;;
+
*)
AC_MSG_RESULT([NO!])
AC_MSG_ERROR([architecture $host_cpu is not supported by strace])
diff --git a/defs.h b/defs.h
index 6f2a844..070f2b3 100644
--- a/defs.h
+++ b/defs.h
@@ -156,6 +156,7 @@ extern char *stpcpy(char *dst, const char *src);
# define PERSONALITY2_WORDSIZE 4
#elif defined AARCH64 \
|| defined POWERPC64 \
+ || defined RISCV \
|| defined SPARC64 \
|| defined TILE \
|| defined X32
@@ -357,6 +358,7 @@ extern const struct xlat whence_codes[];
|| defined(BFIN) \
|| defined(M68K) \
|| defined(MICROBLAZE) \
+ || defined(RISCV) \
|| defined(S390) \
|| defined(SH) || defined(SH64) \
|| defined(SPARC) || defined(SPARC64) \
diff --git a/linux/riscv/arch_regs.c b/linux/riscv/arch_regs.c
new file mode 100644
index 0000000..40be17d
--- /dev/null
+++ b/linux/riscv/arch_regs.c
@@ -0,0 +1,3 @@
+static struct user_regs_struct riscv_regs;
+#define ARCH_REGS_FOR_GETREGSET riscv_regs
+#define ARCH_PC_REG riscv_regs.pc
diff --git a/linux/riscv/errnoent1.h b/linux/riscv/errnoent1.h
new file mode 100644
index 0000000..2a5c728
--- /dev/null
+++ b/linux/riscv/errnoent1.h
@@ -0,0 +1,2 @@
+/* RISC-V rv32 and rv64 */
+#include "../errnoent.h"
diff --git a/linux/riscv/get_error.c b/linux/riscv/get_error.c
new file mode 100644
index 0000000..be640d0
--- /dev/null
+++ b/linux/riscv/get_error.c
@@ -0,0 +1,10 @@
+static void
+get_error(struct tcb *tcp, const bool check_errno)
+{
+ if (check_errno && is_negated_errno(riscv_regs.a0)) {
+ tcp->u_rval = -1;
+ tcp->u_error = -riscv_regs.a0;
+ } else {
+ tcp->u_rval = riscv_regs.a0;
+ }
+}
diff --git a/linux/riscv/get_scno.c b/linux/riscv/get_scno.c
new file mode 100644
index 0000000..0ca1ed3
--- /dev/null
+++ b/linux/riscv/get_scno.c
@@ -0,0 +1,7 @@
+/* Return codes: 1 - ok, 0 - ignore, other - error. */
+static int
+arch_get_scno(struct tcb *tcp)
+{
+ tcp->scno = riscv_regs.a7;
+ return 1;
+}
diff --git a/linux/riscv/get_syscall_args.c b/linux/riscv/get_syscall_args.c
new file mode 100644
index 0000000..746e085
--- /dev/null
+++ b/linux/riscv/get_syscall_args.c
@@ -0,0 +1,12 @@
+/* Return -1 on error or 1 on success (never 0!). */
+static int
+get_syscall_args(struct tcb *tcp)
+{
+ tcp->u_arg[0] = riscv_regs.a0;
+ tcp->u_arg[1] = riscv_regs.a1;
+ tcp->u_arg[2] = riscv_regs.a2;
+ tcp->u_arg[3] = riscv_regs.a3;
+ tcp->u_arg[4] = riscv_regs.a4;
+ tcp->u_arg[5] = riscv_regs.a5;
+ return 1;
+}
diff --git a/linux/riscv/ioctls_arch0.h b/linux/riscv/ioctls_arch0.h
new file mode 100644
index 0000000..9c039fc
--- /dev/null
+++ b/linux/riscv/ioctls_arch0.h
@@ -0,0 +1 @@
+/* Generated by ioctls_gen.sh from definitions found in $linux/arch/riscv/include/ tree. */
diff --git a/linux/riscv/ioctls_arch1.h b/linux/riscv/ioctls_arch1.h
new file mode 100644
index 0000000..41d00f9
--- /dev/null
+++ b/linux/riscv/ioctls_arch1.h
@@ -0,0 +1 @@
+#include "ioctls_arch0.h"
diff --git a/linux/riscv/ioctls_inc0.h b/linux/riscv/ioctls_inc0.h
new file mode 100644
index 0000000..f9939fa
--- /dev/null
+++ b/linux/riscv/ioctls_inc0.h
@@ -0,0 +1 @@
+#include "64/ioctls_inc.h"
diff --git a/linux/riscv/ioctls_inc1.h b/linux/riscv/ioctls_inc1.h
new file mode 100644
index 0000000..4aecf98
--- /dev/null
+++ b/linux/riscv/ioctls_inc1.h
@@ -0,0 +1 @@
+#include "32/ioctls_inc.h"
diff --git a/linux/riscv/signalent1.h b/linux/riscv/signalent1.h
new file mode 100644
index 0000000..39891b8
--- /dev/null
+++ b/linux/riscv/signalent1.h
@@ -0,0 +1,2 @@
+/* RISC-V rv32 and rv64 */
+#include "../signalent.h"
diff --git a/linux/riscv/stat32.h b/linux/riscv/stat32.h
new file mode 100644
index 0000000..b6fedf6
--- /dev/null
+++ b/linux/riscv/stat32.h
@@ -0,0 +1 @@
+/* no 32-bit stat */
diff --git a/linux/riscv/syscallent.h b/linux/riscv/syscallent.h
new file mode 100644
index 0000000..7c416ef
--- /dev/null
+++ b/linux/riscv/syscallent.h
@@ -0,0 +1 @@
+#include "64/syscallent.h"
diff --git a/linux/riscv/syscallent1.h b/linux/riscv/syscallent1.h
new file mode 100644
index 0000000..22eff67
--- /dev/null
+++ b/linux/riscv/syscallent1.h
@@ -0,0 +1 @@
+#include "32/syscallent.h"
--
2.7.4