root / arm-semi.c @ 79f85c3a
History | View | Annotate | Download (14.1 kB)
1 | a4f81979 | bellard | /*
|
---|---|---|---|
2 | a4f81979 | bellard | * Arm "Angel" semihosting syscalls
|
3 | 5fafdf24 | ths | *
|
4 | 8e71621f | pbrook | * Copyright (c) 2005, 2007 CodeSourcery.
|
5 | 8e71621f | pbrook | * Written by Paul Brook.
|
6 | a4f81979 | bellard | *
|
7 | a4f81979 | bellard | * This program is free software; you can redistribute it and/or modify
|
8 | a4f81979 | bellard | * it under the terms of the GNU General Public License as published by
|
9 | a4f81979 | bellard | * the Free Software Foundation; either version 2 of the License, or
|
10 | a4f81979 | bellard | * (at your option) any later version.
|
11 | a4f81979 | bellard | *
|
12 | a4f81979 | bellard | * This program is distributed in the hope that it will be useful,
|
13 | a4f81979 | bellard | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 | a4f81979 | bellard | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 | a4f81979 | bellard | * GNU General Public License for more details.
|
16 | a4f81979 | bellard | *
|
17 | a4f81979 | bellard | * You should have received a copy of the GNU General Public License
|
18 | a4f81979 | bellard | * along with this program; if not, write to the Free Software
|
19 | a4f81979 | bellard | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
20 | a4f81979 | bellard | */
|
21 | a4f81979 | bellard | |
22 | a4f81979 | bellard | #include <sys/types.h> |
23 | a4f81979 | bellard | #include <sys/stat.h> |
24 | a4f81979 | bellard | #include <fcntl.h> |
25 | a4f81979 | bellard | #include <unistd.h> |
26 | a4f81979 | bellard | #include <stdlib.h> |
27 | a4f81979 | bellard | #include <stdio.h> |
28 | a4f81979 | bellard | #include <time.h> |
29 | a4f81979 | bellard | |
30 | 8e71621f | pbrook | #include "cpu.h" |
31 | 8e71621f | pbrook | #ifdef CONFIG_USER_ONLY
|
32 | a4f81979 | bellard | #include "qemu.h" |
33 | a4f81979 | bellard | |
34 | a4f81979 | bellard | #define ARM_ANGEL_HEAP_SIZE (128 * 1024 * 1024) |
35 | 8e71621f | pbrook | #else
|
36 | 87ecb68b | pbrook | #include "qemu-common.h" |
37 | 87ecb68b | pbrook | #include "sysemu.h" |
38 | 87ecb68b | pbrook | #include "gdbstub.h" |
39 | 8e71621f | pbrook | #endif
|
40 | a4f81979 | bellard | |
41 | a4f81979 | bellard | #define SYS_OPEN 0x01 |
42 | a4f81979 | bellard | #define SYS_CLOSE 0x02 |
43 | a4f81979 | bellard | #define SYS_WRITEC 0x03 |
44 | a4f81979 | bellard | #define SYS_WRITE0 0x04 |
45 | a4f81979 | bellard | #define SYS_WRITE 0x05 |
46 | a4f81979 | bellard | #define SYS_READ 0x06 |
47 | a4f81979 | bellard | #define SYS_READC 0x07 |
48 | a4f81979 | bellard | #define SYS_ISTTY 0x09 |
49 | a4f81979 | bellard | #define SYS_SEEK 0x0a |
50 | a4f81979 | bellard | #define SYS_FLEN 0x0c |
51 | a4f81979 | bellard | #define SYS_TMPNAM 0x0d |
52 | a4f81979 | bellard | #define SYS_REMOVE 0x0e |
53 | a4f81979 | bellard | #define SYS_RENAME 0x0f |
54 | a4f81979 | bellard | #define SYS_CLOCK 0x10 |
55 | a4f81979 | bellard | #define SYS_TIME 0x11 |
56 | a4f81979 | bellard | #define SYS_SYSTEM 0x12 |
57 | a4f81979 | bellard | #define SYS_ERRNO 0x13 |
58 | a4f81979 | bellard | #define SYS_GET_CMDLINE 0x15 |
59 | a4f81979 | bellard | #define SYS_HEAPINFO 0x16 |
60 | a4f81979 | bellard | #define SYS_EXIT 0x18 |
61 | a4f81979 | bellard | |
62 | a4f81979 | bellard | #ifndef O_BINARY
|
63 | a4f81979 | bellard | #define O_BINARY 0 |
64 | a4f81979 | bellard | #endif
|
65 | a4f81979 | bellard | |
66 | a2d1ebaf | pbrook | #define GDB_O_RDONLY 0x000 |
67 | a2d1ebaf | pbrook | #define GDB_O_WRONLY 0x001 |
68 | a2d1ebaf | pbrook | #define GDB_O_RDWR 0x002 |
69 | a2d1ebaf | pbrook | #define GDB_O_APPEND 0x008 |
70 | a2d1ebaf | pbrook | #define GDB_O_CREAT 0x200 |
71 | a2d1ebaf | pbrook | #define GDB_O_TRUNC 0x400 |
72 | a2d1ebaf | pbrook | #define GDB_O_BINARY 0 |
73 | a2d1ebaf | pbrook | |
74 | a2d1ebaf | pbrook | static int gdb_open_modeflags[12] = { |
75 | a2d1ebaf | pbrook | GDB_O_RDONLY, |
76 | a2d1ebaf | pbrook | GDB_O_RDONLY | GDB_O_BINARY, |
77 | a2d1ebaf | pbrook | GDB_O_RDWR, |
78 | a2d1ebaf | pbrook | GDB_O_RDWR | GDB_O_BINARY, |
79 | a2d1ebaf | pbrook | GDB_O_WRONLY | GDB_O_CREAT | GDB_O_TRUNC, |
80 | a2d1ebaf | pbrook | GDB_O_WRONLY | GDB_O_CREAT | GDB_O_TRUNC | GDB_O_BINARY, |
81 | a2d1ebaf | pbrook | GDB_O_RDWR | GDB_O_CREAT | GDB_O_TRUNC, |
82 | a2d1ebaf | pbrook | GDB_O_RDWR | GDB_O_CREAT | GDB_O_TRUNC | GDB_O_BINARY, |
83 | a2d1ebaf | pbrook | GDB_O_WRONLY | GDB_O_CREAT | GDB_O_APPEND, |
84 | a2d1ebaf | pbrook | GDB_O_WRONLY | GDB_O_CREAT | GDB_O_APPEND | GDB_O_BINARY, |
85 | a2d1ebaf | pbrook | GDB_O_RDWR | GDB_O_CREAT | GDB_O_APPEND, |
86 | a2d1ebaf | pbrook | GDB_O_RDWR | GDB_O_CREAT | GDB_O_APPEND | GDB_O_BINARY |
87 | a2d1ebaf | pbrook | }; |
88 | a2d1ebaf | pbrook | |
89 | a2d1ebaf | pbrook | static int open_modeflags[12] = { |
90 | a4f81979 | bellard | O_RDONLY, |
91 | a4f81979 | bellard | O_RDONLY | O_BINARY, |
92 | a4f81979 | bellard | O_RDWR, |
93 | a4f81979 | bellard | O_RDWR | O_BINARY, |
94 | a4f81979 | bellard | O_WRONLY | O_CREAT | O_TRUNC, |
95 | a4f81979 | bellard | O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, |
96 | a4f81979 | bellard | O_RDWR | O_CREAT | O_TRUNC, |
97 | a4f81979 | bellard | O_RDWR | O_CREAT | O_TRUNC | O_BINARY, |
98 | a4f81979 | bellard | O_WRONLY | O_CREAT | O_APPEND, |
99 | a4f81979 | bellard | O_WRONLY | O_CREAT | O_APPEND | O_BINARY, |
100 | a4f81979 | bellard | O_RDWR | O_CREAT | O_APPEND, |
101 | a4f81979 | bellard | O_RDWR | O_CREAT | O_APPEND | O_BINARY |
102 | a4f81979 | bellard | }; |
103 | a4f81979 | bellard | |
104 | 8e71621f | pbrook | #ifdef CONFIG_USER_ONLY
|
105 | a4f81979 | bellard | static inline uint32_t set_swi_errno(TaskState *ts, uint32_t code) |
106 | a4f81979 | bellard | { |
107 | 8e71621f | pbrook | if (code == (uint32_t)-1) |
108 | 8e71621f | pbrook | ts->swi_errno = errno; |
109 | 8e71621f | pbrook | return code;
|
110 | 8e71621f | pbrook | } |
111 | 8e71621f | pbrook | #else
|
112 | 8e71621f | pbrook | static inline uint32_t set_swi_errno(CPUState *env, uint32_t code) |
113 | 8e71621f | pbrook | { |
114 | 8e71621f | pbrook | return code;
|
115 | 8e71621f | pbrook | } |
116 | 8e71621f | pbrook | |
117 | a87295e8 | pbrook | #include "softmmu-semi.h" |
118 | 8e71621f | pbrook | #endif
|
119 | a4f81979 | bellard | |
120 | a2d1ebaf | pbrook | static target_ulong arm_semi_syscall_len;
|
121 | a2d1ebaf | pbrook | |
122 | 33d9cc8a | pbrook | #if !defined(CONFIG_USER_ONLY)
|
123 | 33d9cc8a | pbrook | static target_ulong syscall_err;
|
124 | 33d9cc8a | pbrook | #endif
|
125 | 33d9cc8a | pbrook | |
126 | a2d1ebaf | pbrook | static void arm_semi_cb(CPUState *env, target_ulong ret, target_ulong err) |
127 | a2d1ebaf | pbrook | { |
128 | a2d1ebaf | pbrook | #ifdef CONFIG_USER_ONLY
|
129 | a2d1ebaf | pbrook | TaskState *ts = env->opaque; |
130 | a2d1ebaf | pbrook | #endif
|
131 | 33d9cc8a | pbrook | |
132 | a2d1ebaf | pbrook | if (ret == (target_ulong)-1) { |
133 | a2d1ebaf | pbrook | #ifdef CONFIG_USER_ONLY
|
134 | a2d1ebaf | pbrook | ts->swi_errno = err; |
135 | 33d9cc8a | pbrook | #else
|
136 | 33d9cc8a | pbrook | syscall_err = err; |
137 | a2d1ebaf | pbrook | #endif
|
138 | a2d1ebaf | pbrook | env->regs[0] = ret;
|
139 | a2d1ebaf | pbrook | } else {
|
140 | a2d1ebaf | pbrook | /* Fixup syscalls that use nonstardard return conventions. */
|
141 | a2d1ebaf | pbrook | switch (env->regs[0]) { |
142 | a2d1ebaf | pbrook | case SYS_WRITE:
|
143 | a2d1ebaf | pbrook | case SYS_READ:
|
144 | a2d1ebaf | pbrook | env->regs[0] = arm_semi_syscall_len - ret;
|
145 | a2d1ebaf | pbrook | break;
|
146 | a2d1ebaf | pbrook | case SYS_SEEK:
|
147 | a2d1ebaf | pbrook | env->regs[0] = 0; |
148 | a2d1ebaf | pbrook | break;
|
149 | a2d1ebaf | pbrook | default:
|
150 | a2d1ebaf | pbrook | env->regs[0] = ret;
|
151 | a2d1ebaf | pbrook | break;
|
152 | a2d1ebaf | pbrook | } |
153 | a2d1ebaf | pbrook | } |
154 | a2d1ebaf | pbrook | } |
155 | a2d1ebaf | pbrook | |
156 | 33d9cc8a | pbrook | static void arm_semi_flen_cb(CPUState *env, target_ulong ret, target_ulong err) |
157 | 33d9cc8a | pbrook | { |
158 | 33d9cc8a | pbrook | /* The size is always stored in big-endian order, extract
|
159 | 33d9cc8a | pbrook | the value. We assume the size always fit in 32 bits. */
|
160 | 33d9cc8a | pbrook | uint32_t size; |
161 | 33d9cc8a | pbrook | cpu_memory_rw_debug(env, env->regs[13]-64+32, (uint8_t *)&size, 4, 0); |
162 | 33d9cc8a | pbrook | env->regs[0] = be32_to_cpu(size);
|
163 | 33d9cc8a | pbrook | #ifdef CONFIG_USER_ONLY
|
164 | 33d9cc8a | pbrook | ((TaskState *)env->opaque)->swi_errno = err; |
165 | 33d9cc8a | pbrook | #else
|
166 | 33d9cc8a | pbrook | syscall_err = err; |
167 | 33d9cc8a | pbrook | #endif
|
168 | 33d9cc8a | pbrook | } |
169 | 33d9cc8a | pbrook | |
170 | 2f619698 | bellard | #define ARG(n) \
|
171 | 2f619698 | bellard | ({ \ |
172 | 2f619698 | bellard | target_ulong __arg; \ |
173 | 2f619698 | bellard | /* FIXME - handle get_user() failure */ \
|
174 | 2f619698 | bellard | get_user_ual(__arg, args + (n) * 4); \
|
175 | 2f619698 | bellard | __arg; \ |
176 | 2f619698 | bellard | }) |
177 | 2f619698 | bellard | #define SET_ARG(n, val) put_user_ual(val, args + (n) * 4) |
178 | a4f81979 | bellard | uint32_t do_arm_semihosting(CPUState *env) |
179 | a4f81979 | bellard | { |
180 | 53a5960a | pbrook | target_ulong args; |
181 | a4f81979 | bellard | char * s;
|
182 | a4f81979 | bellard | int nr;
|
183 | a4f81979 | bellard | uint32_t ret; |
184 | 8e71621f | pbrook | uint32_t len; |
185 | 8e71621f | pbrook | #ifdef CONFIG_USER_ONLY
|
186 | a4f81979 | bellard | TaskState *ts = env->opaque; |
187 | 8e71621f | pbrook | #else
|
188 | 8e71621f | pbrook | CPUState *ts = env; |
189 | 8e71621f | pbrook | #endif
|
190 | a4f81979 | bellard | |
191 | a4f81979 | bellard | nr = env->regs[0];
|
192 | 53a5960a | pbrook | args = env->regs[1];
|
193 | a4f81979 | bellard | switch (nr) {
|
194 | a4f81979 | bellard | case SYS_OPEN:
|
195 | 579a97f7 | bellard | if (!(s = lock_user_string(ARG(0)))) |
196 | 579a97f7 | bellard | /* FIXME - should this error code be -TARGET_EFAULT ? */
|
197 | 579a97f7 | bellard | return (uint32_t)-1; |
198 | a4f81979 | bellard | if (ARG(1) >= 12) |
199 | 579a97f7 | bellard | return (uint32_t)-1; |
200 | a4f81979 | bellard | if (strcmp(s, ":tt") == 0) { |
201 | a4f81979 | bellard | if (ARG(1) < 4) |
202 | a4f81979 | bellard | return STDIN_FILENO;
|
203 | a4f81979 | bellard | else
|
204 | a4f81979 | bellard | return STDOUT_FILENO;
|
205 | a4f81979 | bellard | } |
206 | a2d1ebaf | pbrook | if (use_gdb_syscalls()) {
|
207 | 5fafdf24 | ths | gdb_do_syscall(arm_semi_cb, "open,%s,%x,1a4", ARG(0), |
208 | 33d9cc8a | pbrook | (int)ARG(2)+1, gdb_open_modeflags[ARG(1)]); |
209 | a2d1ebaf | pbrook | return env->regs[0]; |
210 | a2d1ebaf | pbrook | } else {
|
211 | a2d1ebaf | pbrook | ret = set_swi_errno(ts, open(s, open_modeflags[ARG(1)], 0644)); |
212 | a2d1ebaf | pbrook | } |
213 | 8e71621f | pbrook | unlock_user(s, ARG(0), 0); |
214 | 8e71621f | pbrook | return ret;
|
215 | a4f81979 | bellard | case SYS_CLOSE:
|
216 | a2d1ebaf | pbrook | if (use_gdb_syscalls()) {
|
217 | a2d1ebaf | pbrook | gdb_do_syscall(arm_semi_cb, "close,%x", ARG(0)); |
218 | a2d1ebaf | pbrook | return env->regs[0]; |
219 | a2d1ebaf | pbrook | } else {
|
220 | a2d1ebaf | pbrook | return set_swi_errno(ts, close(ARG(0))); |
221 | a2d1ebaf | pbrook | } |
222 | a4f81979 | bellard | case SYS_WRITEC:
|
223 | 53a5960a | pbrook | { |
224 | 2f619698 | bellard | char c;
|
225 | 2f619698 | bellard | |
226 | 2f619698 | bellard | if (get_user_u8(c, args))
|
227 | 2f619698 | bellard | /* FIXME - should this error code be -TARGET_EFAULT ? */
|
228 | 2f619698 | bellard | return (uint32_t)-1; |
229 | 53a5960a | pbrook | /* Write to debug console. stderr is near enough. */
|
230 | a2d1ebaf | pbrook | if (use_gdb_syscalls()) {
|
231 | a2d1ebaf | pbrook | gdb_do_syscall(arm_semi_cb, "write,2,%x,1", args);
|
232 | a2d1ebaf | pbrook | return env->regs[0]; |
233 | a2d1ebaf | pbrook | } else {
|
234 | a2d1ebaf | pbrook | return write(STDERR_FILENO, &c, 1); |
235 | a2d1ebaf | pbrook | } |
236 | 53a5960a | pbrook | } |
237 | a4f81979 | bellard | case SYS_WRITE0:
|
238 | 579a97f7 | bellard | if (!(s = lock_user_string(args)))
|
239 | 579a97f7 | bellard | /* FIXME - should this error code be -TARGET_EFAULT ? */
|
240 | 579a97f7 | bellard | return (uint32_t)-1; |
241 | a2d1ebaf | pbrook | len = strlen(s); |
242 | a2d1ebaf | pbrook | if (use_gdb_syscalls()) {
|
243 | a2d1ebaf | pbrook | gdb_do_syscall(arm_semi_cb, "write,2,%x,%x\n", args, len);
|
244 | a2d1ebaf | pbrook | ret = env->regs[0];
|
245 | a2d1ebaf | pbrook | } else {
|
246 | a2d1ebaf | pbrook | ret = write(STDERR_FILENO, s, len); |
247 | a2d1ebaf | pbrook | } |
248 | 53a5960a | pbrook | unlock_user(s, args, 0);
|
249 | 53a5960a | pbrook | return ret;
|
250 | a4f81979 | bellard | case SYS_WRITE:
|
251 | 8e71621f | pbrook | len = ARG(2);
|
252 | a2d1ebaf | pbrook | if (use_gdb_syscalls()) {
|
253 | a2d1ebaf | pbrook | arm_semi_syscall_len = len; |
254 | a2d1ebaf | pbrook | gdb_do_syscall(arm_semi_cb, "write,%x,%x,%x", ARG(0), ARG(1), len); |
255 | a2d1ebaf | pbrook | return env->regs[0]; |
256 | a2d1ebaf | pbrook | } else {
|
257 | 579a97f7 | bellard | if (!(s = lock_user(VERIFY_READ, ARG(1), len, 1))) |
258 | 579a97f7 | bellard | /* FIXME - should this error code be -TARGET_EFAULT ? */
|
259 | 579a97f7 | bellard | return (uint32_t)-1; |
260 | a2d1ebaf | pbrook | ret = set_swi_errno(ts, write(ARG(0), s, len));
|
261 | a2d1ebaf | pbrook | unlock_user(s, ARG(1), 0); |
262 | a2d1ebaf | pbrook | if (ret == (uint32_t)-1) |
263 | a2d1ebaf | pbrook | return -1; |
264 | a2d1ebaf | pbrook | return len - ret;
|
265 | a2d1ebaf | pbrook | } |
266 | a4f81979 | bellard | case SYS_READ:
|
267 | 8e71621f | pbrook | len = ARG(2);
|
268 | a2d1ebaf | pbrook | if (use_gdb_syscalls()) {
|
269 | a2d1ebaf | pbrook | arm_semi_syscall_len = len; |
270 | a2d1ebaf | pbrook | gdb_do_syscall(arm_semi_cb, "read,%x,%x,%x", ARG(0), ARG(1), len); |
271 | a2d1ebaf | pbrook | return env->regs[0]; |
272 | a2d1ebaf | pbrook | } else {
|
273 | 579a97f7 | bellard | if (!(s = lock_user(VERIFY_WRITE, ARG(1), len, 0))) |
274 | 579a97f7 | bellard | /* FIXME - should this error code be -TARGET_EFAULT ? */
|
275 | 579a97f7 | bellard | return (uint32_t)-1; |
276 | a2d1ebaf | pbrook | do
|
277 | a2d1ebaf | pbrook | ret = set_swi_errno(ts, read(ARG(0), s, len));
|
278 | a2d1ebaf | pbrook | while (ret == -1 && errno == EINTR); |
279 | a2d1ebaf | pbrook | unlock_user(s, ARG(1), len);
|
280 | a2d1ebaf | pbrook | if (ret == (uint32_t)-1) |
281 | a2d1ebaf | pbrook | return -1; |
282 | a2d1ebaf | pbrook | return len - ret;
|
283 | a2d1ebaf | pbrook | } |
284 | a4f81979 | bellard | case SYS_READC:
|
285 | a4f81979 | bellard | /* XXX: Read from debug cosole. Not implemented. */
|
286 | a4f81979 | bellard | return 0; |
287 | a4f81979 | bellard | case SYS_ISTTY:
|
288 | a2d1ebaf | pbrook | if (use_gdb_syscalls()) {
|
289 | a2d1ebaf | pbrook | gdb_do_syscall(arm_semi_cb, "isatty,%x", ARG(0)); |
290 | a2d1ebaf | pbrook | return env->regs[0]; |
291 | a2d1ebaf | pbrook | } else {
|
292 | a2d1ebaf | pbrook | return isatty(ARG(0)); |
293 | a2d1ebaf | pbrook | } |
294 | a4f81979 | bellard | case SYS_SEEK:
|
295 | a2d1ebaf | pbrook | if (use_gdb_syscalls()) {
|
296 | 33d9cc8a | pbrook | gdb_do_syscall(arm_semi_cb, "lseek,%x,%x,0", ARG(0), ARG(1)); |
297 | a2d1ebaf | pbrook | return env->regs[0]; |
298 | a2d1ebaf | pbrook | } else {
|
299 | a2d1ebaf | pbrook | ret = set_swi_errno(ts, lseek(ARG(0), ARG(1), SEEK_SET)); |
300 | a2d1ebaf | pbrook | if (ret == (uint32_t)-1) |
301 | a2d1ebaf | pbrook | return -1; |
302 | a2d1ebaf | pbrook | return 0; |
303 | a2d1ebaf | pbrook | } |
304 | a4f81979 | bellard | case SYS_FLEN:
|
305 | a2d1ebaf | pbrook | if (use_gdb_syscalls()) {
|
306 | 5fafdf24 | ths | gdb_do_syscall(arm_semi_flen_cb, "fstat,%x,%x",
|
307 | 33d9cc8a | pbrook | ARG(0), env->regs[13]-64); |
308 | 33d9cc8a | pbrook | return env->regs[0]; |
309 | a2d1ebaf | pbrook | } else {
|
310 | a4f81979 | bellard | struct stat buf;
|
311 | a4f81979 | bellard | ret = set_swi_errno(ts, fstat(ARG(0), &buf));
|
312 | a4f81979 | bellard | if (ret == (uint32_t)-1) |
313 | a4f81979 | bellard | return -1; |
314 | a4f81979 | bellard | return buf.st_size;
|
315 | a4f81979 | bellard | } |
316 | a4f81979 | bellard | case SYS_TMPNAM:
|
317 | a4f81979 | bellard | /* XXX: Not implemented. */
|
318 | a4f81979 | bellard | return -1; |
319 | a4f81979 | bellard | case SYS_REMOVE:
|
320 | a2d1ebaf | pbrook | if (use_gdb_syscalls()) {
|
321 | 33d9cc8a | pbrook | gdb_do_syscall(arm_semi_cb, "unlink,%s", ARG(0), (int)ARG(1)+1); |
322 | a2d1ebaf | pbrook | ret = env->regs[0];
|
323 | a2d1ebaf | pbrook | } else {
|
324 | 579a97f7 | bellard | if (!(s = lock_user_string(ARG(0)))) |
325 | 579a97f7 | bellard | /* FIXME - should this error code be -TARGET_EFAULT ? */
|
326 | 579a97f7 | bellard | return (uint32_t)-1; |
327 | a2d1ebaf | pbrook | ret = set_swi_errno(ts, remove(s)); |
328 | a2d1ebaf | pbrook | unlock_user(s, ARG(0), 0); |
329 | a2d1ebaf | pbrook | } |
330 | 8e71621f | pbrook | return ret;
|
331 | a4f81979 | bellard | case SYS_RENAME:
|
332 | a2d1ebaf | pbrook | if (use_gdb_syscalls()) {
|
333 | a2d1ebaf | pbrook | gdb_do_syscall(arm_semi_cb, "rename,%s,%s",
|
334 | 33d9cc8a | pbrook | ARG(0), (int)ARG(1)+1, ARG(2), (int)ARG(3)+1); |
335 | a2d1ebaf | pbrook | return env->regs[0]; |
336 | a2d1ebaf | pbrook | } else {
|
337 | 8e71621f | pbrook | char *s2;
|
338 | 8e71621f | pbrook | s = lock_user_string(ARG(0));
|
339 | 8e71621f | pbrook | s2 = lock_user_string(ARG(2));
|
340 | 579a97f7 | bellard | if (!s || !s2)
|
341 | 579a97f7 | bellard | /* FIXME - should this error code be -TARGET_EFAULT ? */
|
342 | 579a97f7 | bellard | ret = (uint32_t)-1;
|
343 | 579a97f7 | bellard | else
|
344 | 579a97f7 | bellard | ret = set_swi_errno(ts, rename(s, s2)); |
345 | 579a97f7 | bellard | if (s2)
|
346 | 579a97f7 | bellard | unlock_user(s2, ARG(2), 0); |
347 | 579a97f7 | bellard | if (s)
|
348 | 579a97f7 | bellard | unlock_user(s, ARG(0), 0); |
349 | 8e71621f | pbrook | return ret;
|
350 | 8e71621f | pbrook | } |
351 | a4f81979 | bellard | case SYS_CLOCK:
|
352 | a4f81979 | bellard | return clock() / (CLOCKS_PER_SEC / 100); |
353 | a4f81979 | bellard | case SYS_TIME:
|
354 | a4f81979 | bellard | return set_swi_errno(ts, time(NULL)); |
355 | a4f81979 | bellard | case SYS_SYSTEM:
|
356 | a2d1ebaf | pbrook | if (use_gdb_syscalls()) {
|
357 | 33d9cc8a | pbrook | gdb_do_syscall(arm_semi_cb, "system,%s", ARG(0), (int)ARG(1)+1); |
358 | a2d1ebaf | pbrook | return env->regs[0]; |
359 | a2d1ebaf | pbrook | } else {
|
360 | 579a97f7 | bellard | if (!(s = lock_user_string(ARG(0)))) |
361 | 579a97f7 | bellard | /* FIXME - should this error code be -TARGET_EFAULT ? */
|
362 | 579a97f7 | bellard | return (uint32_t)-1; |
363 | a2d1ebaf | pbrook | ret = set_swi_errno(ts, system(s)); |
364 | a2d1ebaf | pbrook | unlock_user(s, ARG(0), 0); |
365 | a982b531 | ths | return ret;
|
366 | a2d1ebaf | pbrook | } |
367 | a4f81979 | bellard | case SYS_ERRNO:
|
368 | 8e71621f | pbrook | #ifdef CONFIG_USER_ONLY
|
369 | a4f81979 | bellard | return ts->swi_errno;
|
370 | 8e71621f | pbrook | #else
|
371 | 33d9cc8a | pbrook | return syscall_err;
|
372 | 8e71621f | pbrook | #endif
|
373 | a4f81979 | bellard | case SYS_GET_CMDLINE:
|
374 | 8e71621f | pbrook | #ifdef CONFIG_USER_ONLY
|
375 | 38d0662a | pbrook | /* Build a commandline from the original argv. */
|
376 | 38d0662a | pbrook | { |
377 | 38d0662a | pbrook | char **arg = ts->info->host_argv;
|
378 | 38d0662a | pbrook | int len = ARG(1); |
379 | 38d0662a | pbrook | /* lock the buffer on the ARM side */
|
380 | 579a97f7 | bellard | char *cmdline_buffer = (char*)lock_user(VERIFY_WRITE, ARG(0), len, 0); |
381 | 579a97f7 | bellard | |
382 | 579a97f7 | bellard | if (!cmdline_buffer)
|
383 | 579a97f7 | bellard | /* FIXME - should this error code be -TARGET_EFAULT ? */
|
384 | 579a97f7 | bellard | return (uint32_t)-1; |
385 | 38d0662a | pbrook | |
386 | 38d0662a | pbrook | s = cmdline_buffer; |
387 | 38d0662a | pbrook | while (*arg && len > 2) { |
388 | 38d0662a | pbrook | int n = strlen(*arg);
|
389 | 38d0662a | pbrook | |
390 | 38d0662a | pbrook | if (s != cmdline_buffer) {
|
391 | 38d0662a | pbrook | *(s++) = ' ';
|
392 | 38d0662a | pbrook | len--; |
393 | 38d0662a | pbrook | } |
394 | 38d0662a | pbrook | if (n >= len)
|
395 | 38d0662a | pbrook | n = len - 1;
|
396 | 38d0662a | pbrook | memcpy(s, *arg, n); |
397 | 38d0662a | pbrook | s += n; |
398 | 38d0662a | pbrook | len -= n; |
399 | 38d0662a | pbrook | arg++; |
400 | 38d0662a | pbrook | } |
401 | 38d0662a | pbrook | /* Null terminate the string. */
|
402 | 38d0662a | pbrook | *s = 0;
|
403 | 38d0662a | pbrook | len = s - cmdline_buffer; |
404 | 38d0662a | pbrook | |
405 | 38d0662a | pbrook | /* Unlock the buffer on the ARM side. */
|
406 | 38d0662a | pbrook | unlock_user(cmdline_buffer, ARG(0), len);
|
407 | 38d0662a | pbrook | |
408 | 38d0662a | pbrook | /* Adjust the commandline length argument. */
|
409 | 38d0662a | pbrook | SET_ARG(1, len);
|
410 | 38d0662a | pbrook | |
411 | 38d0662a | pbrook | /* Return success if commandline fit into buffer. */
|
412 | 38d0662a | pbrook | return *arg ? -1 : 0; |
413 | 38d0662a | pbrook | } |
414 | 8e71621f | pbrook | #else
|
415 | 8e71621f | pbrook | return -1; |
416 | 8e71621f | pbrook | #endif
|
417 | a4f81979 | bellard | case SYS_HEAPINFO:
|
418 | a4f81979 | bellard | { |
419 | a4f81979 | bellard | uint32_t *ptr; |
420 | a4f81979 | bellard | uint32_t limit; |
421 | a4f81979 | bellard | |
422 | 8e71621f | pbrook | #ifdef CONFIG_USER_ONLY
|
423 | 8e71621f | pbrook | /* Some C libraries assume the heap immediately follows .bss, so
|
424 | a4f81979 | bellard | allocate it using sbrk. */
|
425 | a4f81979 | bellard | if (!ts->heap_limit) {
|
426 | a4f81979 | bellard | long ret;
|
427 | a4f81979 | bellard | |
428 | 53a5960a | pbrook | ts->heap_base = do_brk(0);
|
429 | a4f81979 | bellard | limit = ts->heap_base + ARM_ANGEL_HEAP_SIZE; |
430 | a4f81979 | bellard | /* Try a big heap, and reduce the size if that fails. */
|
431 | a4f81979 | bellard | for (;;) {
|
432 | 53a5960a | pbrook | ret = do_brk(limit); |
433 | a4f81979 | bellard | if (ret != -1) |
434 | a4f81979 | bellard | break;
|
435 | a4f81979 | bellard | limit = (ts->heap_base >> 1) + (limit >> 1); |
436 | a4f81979 | bellard | } |
437 | a4f81979 | bellard | ts->heap_limit = limit; |
438 | a4f81979 | bellard | } |
439 | 3b46e624 | ths | |
440 | 579a97f7 | bellard | if (!(ptr = lock_user(VERIFY_WRITE, ARG(0), 16, 0))) |
441 | 579a97f7 | bellard | /* FIXME - should this error code be -TARGET_EFAULT ? */
|
442 | 579a97f7 | bellard | return (uint32_t)-1; |
443 | a4f81979 | bellard | ptr[0] = tswap32(ts->heap_base);
|
444 | a4f81979 | bellard | ptr[1] = tswap32(ts->heap_limit);
|
445 | a4f81979 | bellard | ptr[2] = tswap32(ts->stack_base);
|
446 | a4f81979 | bellard | ptr[3] = tswap32(0); /* Stack limit. */ |
447 | 8e71621f | pbrook | unlock_user(ptr, ARG(0), 16); |
448 | 8e71621f | pbrook | #else
|
449 | 8e71621f | pbrook | limit = ram_size; |
450 | 579a97f7 | bellard | if (!(ptr = lock_user(VERIFY_WRITE, ARG(0), 16, 0))) |
451 | 579a97f7 | bellard | /* FIXME - should this error code be -TARGET_EFAULT ? */
|
452 | 579a97f7 | bellard | return (uint32_t)-1; |
453 | 8e71621f | pbrook | /* TODO: Make this use the limit of the loaded application. */
|
454 | 8e71621f | pbrook | ptr[0] = tswap32(limit / 2); |
455 | 8e71621f | pbrook | ptr[1] = tswap32(limit);
|
456 | 8e71621f | pbrook | ptr[2] = tswap32(limit); /* Stack base */ |
457 | 8e71621f | pbrook | ptr[3] = tswap32(0); /* Stack limit. */ |
458 | 8e71621f | pbrook | unlock_user(ptr, ARG(0), 16); |
459 | 8e71621f | pbrook | #endif
|
460 | a4f81979 | bellard | return 0; |
461 | a4f81979 | bellard | } |
462 | a4f81979 | bellard | case SYS_EXIT:
|
463 | a4f81979 | bellard | exit(0);
|
464 | a4f81979 | bellard | default:
|
465 | a4f81979 | bellard | fprintf(stderr, "qemu: Unsupported SemiHosting SWI 0x%02x\n", nr);
|
466 | a4f81979 | bellard | cpu_dump_state(env, stderr, fprintf, 0);
|
467 | a4f81979 | bellard | abort(); |
468 | a4f81979 | bellard | } |
469 | a4f81979 | bellard | } |