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