]>
Commit | Line | Data |
---|---|---|
a4f81979 FB |
1 | /* |
2 | * Arm "Angel" semihosting syscalls | |
5fafdf24 | 3 | * |
8e71621f PB |
4 | * Copyright (c) 2005, 2007 CodeSourcery. |
5 | * Written by Paul Brook. | |
a4f81979 FB |
6 | * |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
8167ee88 | 18 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
a4f81979 FB |
19 | */ |
20 | ||
21 | #include <sys/types.h> | |
22 | #include <sys/stat.h> | |
23 | #include <fcntl.h> | |
24 | #include <unistd.h> | |
25 | #include <stdlib.h> | |
26 | #include <stdio.h> | |
27 | #include <time.h> | |
28 | ||
8e71621f PB |
29 | #include "cpu.h" |
30 | #ifdef CONFIG_USER_ONLY | |
a4f81979 FB |
31 | #include "qemu.h" |
32 | ||
33 | #define ARM_ANGEL_HEAP_SIZE (128 * 1024 * 1024) | |
8e71621f | 34 | #else |
87ecb68b | 35 | #include "qemu-common.h" |
022c62cb | 36 | #include "exec/gdbstub.h" |
bd2be150 | 37 | #include "hw/arm/arm.h" |
8e71621f | 38 | #endif |
a4f81979 | 39 | |
3881725c SW |
40 | #define TARGET_SYS_OPEN 0x01 |
41 | #define TARGET_SYS_CLOSE 0x02 | |
42 | #define TARGET_SYS_WRITEC 0x03 | |
43 | #define TARGET_SYS_WRITE0 0x04 | |
44 | #define TARGET_SYS_WRITE 0x05 | |
45 | #define TARGET_SYS_READ 0x06 | |
46 | #define TARGET_SYS_READC 0x07 | |
47 | #define TARGET_SYS_ISTTY 0x09 | |
48 | #define TARGET_SYS_SEEK 0x0a | |
49 | #define TARGET_SYS_FLEN 0x0c | |
50 | #define TARGET_SYS_TMPNAM 0x0d | |
51 | #define TARGET_SYS_REMOVE 0x0e | |
52 | #define TARGET_SYS_RENAME 0x0f | |
53 | #define TARGET_SYS_CLOCK 0x10 | |
54 | #define TARGET_SYS_TIME 0x11 | |
55 | #define TARGET_SYS_SYSTEM 0x12 | |
56 | #define TARGET_SYS_ERRNO 0x13 | |
57 | #define TARGET_SYS_GET_CMDLINE 0x15 | |
58 | #define TARGET_SYS_HEAPINFO 0x16 | |
59 | #define TARGET_SYS_EXIT 0x18 | |
a4f81979 FB |
60 | |
61 | #ifndef O_BINARY | |
62 | #define O_BINARY 0 | |
63 | #endif | |
64 | ||
a2d1ebaf PB |
65 | #define GDB_O_RDONLY 0x000 |
66 | #define GDB_O_WRONLY 0x001 | |
67 | #define GDB_O_RDWR 0x002 | |
68 | #define GDB_O_APPEND 0x008 | |
69 | #define GDB_O_CREAT 0x200 | |
70 | #define GDB_O_TRUNC 0x400 | |
71 | #define GDB_O_BINARY 0 | |
72 | ||
73 | static int gdb_open_modeflags[12] = { | |
74 | GDB_O_RDONLY, | |
75 | GDB_O_RDONLY | GDB_O_BINARY, | |
76 | GDB_O_RDWR, | |
77 | GDB_O_RDWR | GDB_O_BINARY, | |
78 | GDB_O_WRONLY | GDB_O_CREAT | GDB_O_TRUNC, | |
79 | GDB_O_WRONLY | GDB_O_CREAT | GDB_O_TRUNC | GDB_O_BINARY, | |
80 | GDB_O_RDWR | GDB_O_CREAT | GDB_O_TRUNC, | |
81 | GDB_O_RDWR | GDB_O_CREAT | GDB_O_TRUNC | GDB_O_BINARY, | |
82 | GDB_O_WRONLY | GDB_O_CREAT | GDB_O_APPEND, | |
83 | GDB_O_WRONLY | GDB_O_CREAT | GDB_O_APPEND | GDB_O_BINARY, | |
84 | GDB_O_RDWR | GDB_O_CREAT | GDB_O_APPEND, | |
85 | GDB_O_RDWR | GDB_O_CREAT | GDB_O_APPEND | GDB_O_BINARY | |
86 | }; | |
87 | ||
88 | static int open_modeflags[12] = { | |
a4f81979 FB |
89 | O_RDONLY, |
90 | O_RDONLY | O_BINARY, | |
91 | O_RDWR, | |
92 | O_RDWR | O_BINARY, | |
93 | O_WRONLY | O_CREAT | O_TRUNC, | |
94 | O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, | |
95 | O_RDWR | O_CREAT | O_TRUNC, | |
96 | O_RDWR | O_CREAT | O_TRUNC | O_BINARY, | |
97 | O_WRONLY | O_CREAT | O_APPEND, | |
98 | O_WRONLY | O_CREAT | O_APPEND | O_BINARY, | |
99 | O_RDWR | O_CREAT | O_APPEND, | |
100 | O_RDWR | O_CREAT | O_APPEND | O_BINARY | |
101 | }; | |
102 | ||
8e71621f | 103 | #ifdef CONFIG_USER_ONLY |
a4f81979 FB |
104 | static inline uint32_t set_swi_errno(TaskState *ts, uint32_t code) |
105 | { | |
8e71621f PB |
106 | if (code == (uint32_t)-1) |
107 | ts->swi_errno = errno; | |
108 | return code; | |
109 | } | |
110 | #else | |
81926f47 | 111 | static inline uint32_t set_swi_errno(CPUARMState *env, uint32_t code) |
8e71621f PB |
112 | { |
113 | return code; | |
114 | } | |
115 | ||
022c62cb | 116 | #include "exec/softmmu-semi.h" |
8e71621f | 117 | #endif |
a4f81979 | 118 | |
a2d1ebaf PB |
119 | static target_ulong arm_semi_syscall_len; |
120 | ||
33d9cc8a PB |
121 | #if !defined(CONFIG_USER_ONLY) |
122 | static target_ulong syscall_err; | |
123 | #endif | |
124 | ||
81926f47 | 125 | static void arm_semi_cb(CPUARMState *env, target_ulong ret, target_ulong err) |
a2d1ebaf PB |
126 | { |
127 | #ifdef CONFIG_USER_ONLY | |
128 | TaskState *ts = env->opaque; | |
129 | #endif | |
33d9cc8a | 130 | |
a2d1ebaf PB |
131 | if (ret == (target_ulong)-1) { |
132 | #ifdef CONFIG_USER_ONLY | |
133 | ts->swi_errno = err; | |
33d9cc8a PB |
134 | #else |
135 | syscall_err = err; | |
a2d1ebaf PB |
136 | #endif |
137 | env->regs[0] = ret; | |
138 | } else { | |
139 | /* Fixup syscalls that use nonstardard return conventions. */ | |
140 | switch (env->regs[0]) { | |
3881725c SW |
141 | case TARGET_SYS_WRITE: |
142 | case TARGET_SYS_READ: | |
a2d1ebaf PB |
143 | env->regs[0] = arm_semi_syscall_len - ret; |
144 | break; | |
3881725c | 145 | case TARGET_SYS_SEEK: |
a2d1ebaf PB |
146 | env->regs[0] = 0; |
147 | break; | |
148 | default: | |
149 | env->regs[0] = ret; | |
150 | break; | |
151 | } | |
152 | } | |
153 | } | |
154 | ||
81926f47 | 155 | static void arm_semi_flen_cb(CPUARMState *env, target_ulong ret, target_ulong err) |
33d9cc8a PB |
156 | { |
157 | /* The size is always stored in big-endian order, extract | |
158 | the value. We assume the size always fit in 32 bits. */ | |
159 | uint32_t size; | |
160 | cpu_memory_rw_debug(env, env->regs[13]-64+32, (uint8_t *)&size, 4, 0); | |
161 | env->regs[0] = be32_to_cpu(size); | |
162 | #ifdef CONFIG_USER_ONLY | |
163 | ((TaskState *)env->opaque)->swi_errno = err; | |
164 | #else | |
165 | syscall_err = err; | |
166 | #endif | |
167 | } | |
168 | ||
f296c0d1 PM |
169 | /* Read the input value from the argument block; fail the semihosting |
170 | * call if the memory read fails. | |
171 | */ | |
172 | #define GET_ARG(n) do { \ | |
173 | if (get_user_ual(arg ## n, args + (n) * 4)) { \ | |
174 | return (uint32_t)-1; \ | |
175 | } \ | |
176 | } while (0) | |
177 | ||
2f619698 | 178 | #define SET_ARG(n, val) put_user_ual(val, args + (n) * 4) |
81926f47 | 179 | uint32_t do_arm_semihosting(CPUARMState *env) |
a4f81979 | 180 | { |
878096ee | 181 | ARMCPU *cpu = arm_env_get_cpu(env); |
53a5960a | 182 | target_ulong args; |
f296c0d1 | 183 | target_ulong arg0, arg1, arg2, arg3; |
a4f81979 FB |
184 | char * s; |
185 | int nr; | |
186 | uint32_t ret; | |
8e71621f PB |
187 | uint32_t len; |
188 | #ifdef CONFIG_USER_ONLY | |
a4f81979 | 189 | TaskState *ts = env->opaque; |
8e71621f | 190 | #else |
81926f47 | 191 | CPUARMState *ts = env; |
8e71621f | 192 | #endif |
a4f81979 FB |
193 | |
194 | nr = env->regs[0]; | |
53a5960a | 195 | args = env->regs[1]; |
a4f81979 | 196 | switch (nr) { |
3881725c | 197 | case TARGET_SYS_OPEN: |
f296c0d1 PM |
198 | GET_ARG(0); |
199 | GET_ARG(1); | |
200 | GET_ARG(2); | |
201 | s = lock_user_string(arg0); | |
202 | if (!s) { | |
579a97f7 FB |
203 | /* FIXME - should this error code be -TARGET_EFAULT ? */ |
204 | return (uint32_t)-1; | |
f296c0d1 PM |
205 | } |
206 | if (arg1 >= 12) { | |
207 | unlock_user(s, arg0, 0); | |
579a97f7 | 208 | return (uint32_t)-1; |
396bef4b | 209 | } |
a4f81979 | 210 | if (strcmp(s, ":tt") == 0) { |
f296c0d1 PM |
211 | int result_fileno = arg1 < 4 ? STDIN_FILENO : STDOUT_FILENO; |
212 | unlock_user(s, arg0, 0); | |
396bef4b | 213 | return result_fileno; |
a4f81979 | 214 | } |
a2d1ebaf | 215 | if (use_gdb_syscalls()) { |
f296c0d1 PM |
216 | gdb_do_syscall(arm_semi_cb, "open,%s,%x,1a4", arg0, |
217 | (int)arg2+1, gdb_open_modeflags[arg1]); | |
396bef4b | 218 | ret = env->regs[0]; |
a2d1ebaf | 219 | } else { |
f296c0d1 | 220 | ret = set_swi_errno(ts, open(s, open_modeflags[arg1], 0644)); |
a2d1ebaf | 221 | } |
f296c0d1 | 222 | unlock_user(s, arg0, 0); |
8e71621f | 223 | return ret; |
3881725c | 224 | case TARGET_SYS_CLOSE: |
f296c0d1 | 225 | GET_ARG(0); |
a2d1ebaf | 226 | if (use_gdb_syscalls()) { |
f296c0d1 | 227 | gdb_do_syscall(arm_semi_cb, "close,%x", arg0); |
a2d1ebaf PB |
228 | return env->regs[0]; |
229 | } else { | |
f296c0d1 | 230 | return set_swi_errno(ts, close(arg0)); |
a2d1ebaf | 231 | } |
3881725c | 232 | case TARGET_SYS_WRITEC: |
53a5960a | 233 | { |
2f619698 FB |
234 | char c; |
235 | ||
236 | if (get_user_u8(c, args)) | |
237 | /* FIXME - should this error code be -TARGET_EFAULT ? */ | |
238 | return (uint32_t)-1; | |
53a5960a | 239 | /* Write to debug console. stderr is near enough. */ |
a2d1ebaf PB |
240 | if (use_gdb_syscalls()) { |
241 | gdb_do_syscall(arm_semi_cb, "write,2,%x,1", args); | |
242 | return env->regs[0]; | |
243 | } else { | |
244 | return write(STDERR_FILENO, &c, 1); | |
245 | } | |
53a5960a | 246 | } |
3881725c | 247 | case TARGET_SYS_WRITE0: |
579a97f7 FB |
248 | if (!(s = lock_user_string(args))) |
249 | /* FIXME - should this error code be -TARGET_EFAULT ? */ | |
250 | return (uint32_t)-1; | |
a2d1ebaf PB |
251 | len = strlen(s); |
252 | if (use_gdb_syscalls()) { | |
253 | gdb_do_syscall(arm_semi_cb, "write,2,%x,%x\n", args, len); | |
254 | ret = env->regs[0]; | |
255 | } else { | |
256 | ret = write(STDERR_FILENO, s, len); | |
257 | } | |
53a5960a PB |
258 | unlock_user(s, args, 0); |
259 | return ret; | |
3881725c | 260 | case TARGET_SYS_WRITE: |
f296c0d1 PM |
261 | GET_ARG(0); |
262 | GET_ARG(1); | |
263 | GET_ARG(2); | |
264 | len = arg2; | |
a2d1ebaf PB |
265 | if (use_gdb_syscalls()) { |
266 | arm_semi_syscall_len = len; | |
f296c0d1 | 267 | gdb_do_syscall(arm_semi_cb, "write,%x,%x,%x", arg0, arg1, len); |
a2d1ebaf PB |
268 | return env->regs[0]; |
269 | } else { | |
f296c0d1 PM |
270 | s = lock_user(VERIFY_READ, arg1, len, 1); |
271 | if (!s) { | |
579a97f7 FB |
272 | /* FIXME - should this error code be -TARGET_EFAULT ? */ |
273 | return (uint32_t)-1; | |
f296c0d1 PM |
274 | } |
275 | ret = set_swi_errno(ts, write(arg0, s, len)); | |
276 | unlock_user(s, arg1, 0); | |
a2d1ebaf PB |
277 | if (ret == (uint32_t)-1) |
278 | return -1; | |
279 | return len - ret; | |
280 | } | |
3881725c | 281 | case TARGET_SYS_READ: |
f296c0d1 PM |
282 | GET_ARG(0); |
283 | GET_ARG(1); | |
284 | GET_ARG(2); | |
285 | len = arg2; | |
a2d1ebaf PB |
286 | if (use_gdb_syscalls()) { |
287 | arm_semi_syscall_len = len; | |
f296c0d1 | 288 | gdb_do_syscall(arm_semi_cb, "read,%x,%x,%x", arg0, arg1, len); |
a2d1ebaf PB |
289 | return env->regs[0]; |
290 | } else { | |
f296c0d1 PM |
291 | s = lock_user(VERIFY_WRITE, arg1, len, 0); |
292 | if (!s) { | |
579a97f7 FB |
293 | /* FIXME - should this error code be -TARGET_EFAULT ? */ |
294 | return (uint32_t)-1; | |
f296c0d1 PM |
295 | } |
296 | do { | |
297 | ret = set_swi_errno(ts, read(arg0, s, len)); | |
298 | } while (ret == -1 && errno == EINTR); | |
299 | unlock_user(s, arg1, len); | |
a2d1ebaf PB |
300 | if (ret == (uint32_t)-1) |
301 | return -1; | |
302 | return len - ret; | |
303 | } | |
3881725c | 304 | case TARGET_SYS_READC: |
b90372ad | 305 | /* XXX: Read from debug console. Not implemented. */ |
a4f81979 | 306 | return 0; |
3881725c | 307 | case TARGET_SYS_ISTTY: |
f296c0d1 | 308 | GET_ARG(0); |
a2d1ebaf | 309 | if (use_gdb_syscalls()) { |
f296c0d1 | 310 | gdb_do_syscall(arm_semi_cb, "isatty,%x", arg0); |
a2d1ebaf PB |
311 | return env->regs[0]; |
312 | } else { | |
f296c0d1 | 313 | return isatty(arg0); |
a2d1ebaf | 314 | } |
3881725c | 315 | case TARGET_SYS_SEEK: |
f296c0d1 PM |
316 | GET_ARG(0); |
317 | GET_ARG(1); | |
a2d1ebaf | 318 | if (use_gdb_syscalls()) { |
f296c0d1 | 319 | gdb_do_syscall(arm_semi_cb, "lseek,%x,%x,0", arg0, arg1); |
a2d1ebaf PB |
320 | return env->regs[0]; |
321 | } else { | |
f296c0d1 | 322 | ret = set_swi_errno(ts, lseek(arg0, arg1, SEEK_SET)); |
a2d1ebaf PB |
323 | if (ret == (uint32_t)-1) |
324 | return -1; | |
325 | return 0; | |
326 | } | |
3881725c | 327 | case TARGET_SYS_FLEN: |
f296c0d1 | 328 | GET_ARG(0); |
a2d1ebaf | 329 | if (use_gdb_syscalls()) { |
5fafdf24 | 330 | gdb_do_syscall(arm_semi_flen_cb, "fstat,%x,%x", |
f296c0d1 | 331 | arg0, env->regs[13]-64); |
33d9cc8a | 332 | return env->regs[0]; |
a2d1ebaf | 333 | } else { |
a4f81979 | 334 | struct stat buf; |
f296c0d1 | 335 | ret = set_swi_errno(ts, fstat(arg0, &buf)); |
a4f81979 FB |
336 | if (ret == (uint32_t)-1) |
337 | return -1; | |
338 | return buf.st_size; | |
339 | } | |
3881725c | 340 | case TARGET_SYS_TMPNAM: |
a4f81979 FB |
341 | /* XXX: Not implemented. */ |
342 | return -1; | |
3881725c | 343 | case TARGET_SYS_REMOVE: |
f296c0d1 PM |
344 | GET_ARG(0); |
345 | GET_ARG(1); | |
a2d1ebaf | 346 | if (use_gdb_syscalls()) { |
f296c0d1 | 347 | gdb_do_syscall(arm_semi_cb, "unlink,%s", arg0, (int)arg1+1); |
a2d1ebaf PB |
348 | ret = env->regs[0]; |
349 | } else { | |
f296c0d1 PM |
350 | s = lock_user_string(arg0); |
351 | if (!s) { | |
579a97f7 FB |
352 | /* FIXME - should this error code be -TARGET_EFAULT ? */ |
353 | return (uint32_t)-1; | |
f296c0d1 | 354 | } |
a2d1ebaf | 355 | ret = set_swi_errno(ts, remove(s)); |
f296c0d1 | 356 | unlock_user(s, arg0, 0); |
a2d1ebaf | 357 | } |
8e71621f | 358 | return ret; |
3881725c | 359 | case TARGET_SYS_RENAME: |
f296c0d1 PM |
360 | GET_ARG(0); |
361 | GET_ARG(1); | |
362 | GET_ARG(2); | |
363 | GET_ARG(3); | |
a2d1ebaf PB |
364 | if (use_gdb_syscalls()) { |
365 | gdb_do_syscall(arm_semi_cb, "rename,%s,%s", | |
f296c0d1 | 366 | arg0, (int)arg1+1, arg2, (int)arg3+1); |
a2d1ebaf PB |
367 | return env->regs[0]; |
368 | } else { | |
8e71621f | 369 | char *s2; |
f296c0d1 PM |
370 | s = lock_user_string(arg0); |
371 | s2 = lock_user_string(arg2); | |
579a97f7 FB |
372 | if (!s || !s2) |
373 | /* FIXME - should this error code be -TARGET_EFAULT ? */ | |
374 | ret = (uint32_t)-1; | |
375 | else | |
376 | ret = set_swi_errno(ts, rename(s, s2)); | |
377 | if (s2) | |
f296c0d1 | 378 | unlock_user(s2, arg2, 0); |
579a97f7 | 379 | if (s) |
f296c0d1 | 380 | unlock_user(s, arg0, 0); |
8e71621f PB |
381 | return ret; |
382 | } | |
3881725c | 383 | case TARGET_SYS_CLOCK: |
a4f81979 | 384 | return clock() / (CLOCKS_PER_SEC / 100); |
3881725c | 385 | case TARGET_SYS_TIME: |
a4f81979 | 386 | return set_swi_errno(ts, time(NULL)); |
3881725c | 387 | case TARGET_SYS_SYSTEM: |
f296c0d1 PM |
388 | GET_ARG(0); |
389 | GET_ARG(1); | |
a2d1ebaf | 390 | if (use_gdb_syscalls()) { |
f296c0d1 | 391 | gdb_do_syscall(arm_semi_cb, "system,%s", arg0, (int)arg1+1); |
a2d1ebaf PB |
392 | return env->regs[0]; |
393 | } else { | |
f296c0d1 PM |
394 | s = lock_user_string(arg0); |
395 | if (!s) { | |
579a97f7 FB |
396 | /* FIXME - should this error code be -TARGET_EFAULT ? */ |
397 | return (uint32_t)-1; | |
f296c0d1 | 398 | } |
a2d1ebaf | 399 | ret = set_swi_errno(ts, system(s)); |
f296c0d1 | 400 | unlock_user(s, arg0, 0); |
a982b531 | 401 | return ret; |
a2d1ebaf | 402 | } |
3881725c | 403 | case TARGET_SYS_ERRNO: |
8e71621f | 404 | #ifdef CONFIG_USER_ONLY |
a4f81979 | 405 | return ts->swi_errno; |
8e71621f | 406 | #else |
33d9cc8a | 407 | return syscall_err; |
8e71621f | 408 | #endif |
3881725c | 409 | case TARGET_SYS_GET_CMDLINE: |
38d0662a | 410 | { |
1c1b40c1 CV |
411 | /* Build a command-line from the original argv. |
412 | * | |
413 | * The inputs are: | |
f296c0d1 PM |
414 | * * arg0, pointer to a buffer of at least the size |
415 | * specified in arg1. | |
416 | * * arg1, size of the buffer pointed to by arg0 in | |
1c1b40c1 CV |
417 | * bytes. |
418 | * | |
419 | * The outputs are: | |
f296c0d1 | 420 | * * arg0, pointer to null-terminated string of the |
1c1b40c1 | 421 | * command line. |
f296c0d1 | 422 | * * arg1, length of the string pointed to by arg0. |
1c1b40c1 | 423 | */ |
579a97f7 | 424 | |
1c1b40c1 | 425 | char *output_buffer; |
f296c0d1 | 426 | size_t input_size; |
1c1b40c1 CV |
427 | size_t output_size; |
428 | int status = 0; | |
f296c0d1 PM |
429 | GET_ARG(0); |
430 | GET_ARG(1); | |
431 | input_size = arg1; | |
1c1b40c1 CV |
432 | /* Compute the size of the output string. */ |
433 | #if !defined(CONFIG_USER_ONLY) | |
434 | output_size = strlen(ts->boot_info->kernel_filename) | |
435 | + 1 /* Separating space. */ | |
436 | + strlen(ts->boot_info->kernel_cmdline) | |
437 | + 1; /* Terminating null byte. */ | |
438 | #else | |
439 | unsigned int i; | |
38d0662a | 440 | |
1c1b40c1 CV |
441 | output_size = ts->info->arg_end - ts->info->arg_start; |
442 | if (!output_size) { | |
2e8785ac WS |
443 | /* We special-case the "empty command line" case (argc==0). |
444 | Just provide the terminating 0. */ | |
1c1b40c1 CV |
445 | output_size = 1; |
446 | } | |
447 | #endif | |
38d0662a | 448 | |
1c1b40c1 CV |
449 | if (output_size > input_size) { |
450 | /* Not enough space to store command-line arguments. */ | |
451 | return -1; | |
38d0662a | 452 | } |
38d0662a | 453 | |
1c1b40c1 | 454 | /* Adjust the command-line length. */ |
f296c0d1 PM |
455 | if (SET_ARG(1, output_size - 1)) { |
456 | /* Couldn't write back to argument block */ | |
457 | return -1; | |
458 | } | |
38d0662a | 459 | |
1c1b40c1 | 460 | /* Lock the buffer on the ARM side. */ |
f296c0d1 | 461 | output_buffer = lock_user(VERIFY_WRITE, arg0, output_size, 0); |
1c1b40c1 CV |
462 | if (!output_buffer) { |
463 | return -1; | |
464 | } | |
38d0662a | 465 | |
1c1b40c1 CV |
466 | /* Copy the command-line arguments. */ |
467 | #if !defined(CONFIG_USER_ONLY) | |
468 | pstrcpy(output_buffer, output_size, ts->boot_info->kernel_filename); | |
469 | pstrcat(output_buffer, output_size, " "); | |
470 | pstrcat(output_buffer, output_size, ts->boot_info->kernel_cmdline); | |
471 | #else | |
472 | if (output_size == 1) { | |
473 | /* Empty command-line. */ | |
474 | output_buffer[0] = '\0'; | |
475 | goto out; | |
476 | } | |
2e8785ac | 477 | |
1c1b40c1 CV |
478 | if (copy_from_user(output_buffer, ts->info->arg_start, |
479 | output_size)) { | |
480 | status = -1; | |
481 | goto out; | |
2e8785ac WS |
482 | } |
483 | ||
1c1b40c1 CV |
484 | /* Separate arguments by white spaces. */ |
485 | for (i = 0; i < output_size - 1; i++) { | |
486 | if (output_buffer[i] == 0) { | |
487 | output_buffer[i] = ' '; | |
488 | } | |
489 | } | |
490 | out: | |
491 | #endif | |
492 | /* Unlock the buffer on the ARM side. */ | |
f296c0d1 | 493 | unlock_user(output_buffer, arg0, output_size); |
2e8785ac | 494 | |
1c1b40c1 | 495 | return status; |
38d0662a | 496 | } |
3881725c | 497 | case TARGET_SYS_HEAPINFO: |
a4f81979 FB |
498 | { |
499 | uint32_t *ptr; | |
500 | uint32_t limit; | |
f296c0d1 | 501 | GET_ARG(0); |
a4f81979 | 502 | |
8e71621f PB |
503 | #ifdef CONFIG_USER_ONLY |
504 | /* Some C libraries assume the heap immediately follows .bss, so | |
a4f81979 FB |
505 | allocate it using sbrk. */ |
506 | if (!ts->heap_limit) { | |
206ae74a | 507 | abi_ulong ret; |
a4f81979 | 508 | |
53a5960a | 509 | ts->heap_base = do_brk(0); |
a4f81979 FB |
510 | limit = ts->heap_base + ARM_ANGEL_HEAP_SIZE; |
511 | /* Try a big heap, and reduce the size if that fails. */ | |
512 | for (;;) { | |
53a5960a | 513 | ret = do_brk(limit); |
206ae74a | 514 | if (ret >= limit) { |
a4f81979 | 515 | break; |
206ae74a | 516 | } |
a4f81979 FB |
517 | limit = (ts->heap_base >> 1) + (limit >> 1); |
518 | } | |
519 | ts->heap_limit = limit; | |
520 | } | |
3b46e624 | 521 | |
f296c0d1 PM |
522 | ptr = lock_user(VERIFY_WRITE, arg0, 16, 0); |
523 | if (!ptr) { | |
579a97f7 FB |
524 | /* FIXME - should this error code be -TARGET_EFAULT ? */ |
525 | return (uint32_t)-1; | |
f296c0d1 | 526 | } |
a4f81979 FB |
527 | ptr[0] = tswap32(ts->heap_base); |
528 | ptr[1] = tswap32(ts->heap_limit); | |
529 | ptr[2] = tswap32(ts->stack_base); | |
530 | ptr[3] = tswap32(0); /* Stack limit. */ | |
f296c0d1 | 531 | unlock_user(ptr, arg0, 16); |
8e71621f PB |
532 | #else |
533 | limit = ram_size; | |
f296c0d1 PM |
534 | ptr = lock_user(VERIFY_WRITE, arg0, 16, 0); |
535 | if (!ptr) { | |
579a97f7 FB |
536 | /* FIXME - should this error code be -TARGET_EFAULT ? */ |
537 | return (uint32_t)-1; | |
f296c0d1 | 538 | } |
8e71621f PB |
539 | /* TODO: Make this use the limit of the loaded application. */ |
540 | ptr[0] = tswap32(limit / 2); | |
541 | ptr[1] = tswap32(limit); | |
542 | ptr[2] = tswap32(limit); /* Stack base */ | |
543 | ptr[3] = tswap32(0); /* Stack limit. */ | |
f296c0d1 | 544 | unlock_user(ptr, arg0, 16); |
8e71621f | 545 | #endif |
a4f81979 FB |
546 | return 0; |
547 | } | |
3881725c | 548 | case TARGET_SYS_EXIT: |
0e1c9c54 | 549 | gdb_exit(env, 0); |
a4f81979 FB |
550 | exit(0); |
551 | default: | |
552 | fprintf(stderr, "qemu: Unsupported SemiHosting SWI 0x%02x\n", nr); | |
878096ee | 553 | cpu_dump_state(CPU(cpu), stderr, fprintf, 0); |
a4f81979 FB |
554 | abort(); |
555 | } | |
556 | } |