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