bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Arm "Angel" semihosting syscalls |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3 | * |
pbrook | 8e71621 | 2007-01-20 17:12:09 +0000 | [diff] [blame] | 4 | * Copyright (c) 2005, 2007 CodeSourcery. |
| 5 | * Written by Paul Brook. |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 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 |
Blue Swirl | 8167ee8 | 2009-07-16 20:47:01 +0000 | [diff] [blame] | 18 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 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 | |
pbrook | 8e71621 | 2007-01-20 17:12:09 +0000 | [diff] [blame] | 29 | #include "cpu.h" |
| 30 | #ifdef CONFIG_USER_ONLY |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 31 | #include "qemu.h" |
| 32 | |
| 33 | #define ARM_ANGEL_HEAP_SIZE (128 * 1024 * 1024) |
pbrook | 8e71621 | 2007-01-20 17:12:09 +0000 | [diff] [blame] | 34 | #else |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 35 | #include "qemu-common.h" |
Paolo Bonzini | 022c62c | 2012-12-17 18:19:49 +0100 | [diff] [blame] | 36 | #include "exec/gdbstub.h" |
Peter Maydell | bd2be15 | 2013-04-09 15:26:55 +0100 | [diff] [blame] | 37 | #include "hw/arm/arm.h" |
pbrook | 8e71621 | 2007-01-20 17:12:09 +0000 | [diff] [blame] | 38 | #endif |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 39 | |
Stefan Weil | 3881725 | 2012-04-28 05:07:47 +0000 | [diff] [blame] | 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 |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 60 | |
| 61 | #ifndef O_BINARY |
| 62 | #define O_BINARY 0 |
| 63 | #endif |
| 64 | |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 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] = { |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 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 | |
pbrook | 8e71621 | 2007-01-20 17:12:09 +0000 | [diff] [blame] | 103 | #ifdef CONFIG_USER_ONLY |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 104 | static inline uint32_t set_swi_errno(TaskState *ts, uint32_t code) |
| 105 | { |
pbrook | 8e71621 | 2007-01-20 17:12:09 +0000 | [diff] [blame] | 106 | if (code == (uint32_t)-1) |
| 107 | ts->swi_errno = errno; |
| 108 | return code; |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 109 | } |
pbrook | 8e71621 | 2007-01-20 17:12:09 +0000 | [diff] [blame] | 110 | #else |
Andreas Färber | 81926f4 | 2012-03-14 01:38:23 +0100 | [diff] [blame] | 111 | static inline uint32_t set_swi_errno(CPUARMState *env, uint32_t code) |
pbrook | 8e71621 | 2007-01-20 17:12:09 +0000 | [diff] [blame] | 112 | { |
| 113 | return code; |
| 114 | } |
| 115 | |
Paolo Bonzini | 022c62c | 2012-12-17 18:19:49 +0100 | [diff] [blame] | 116 | #include "exec/softmmu-semi.h" |
pbrook | 8e71621 | 2007-01-20 17:12:09 +0000 | [diff] [blame] | 117 | #endif |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 118 | |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 119 | static target_ulong arm_semi_syscall_len; |
| 120 | |
pbrook | 33d9cc8 | 2007-06-09 14:44:00 +0000 | [diff] [blame] | 121 | #if !defined(CONFIG_USER_ONLY) |
| 122 | static target_ulong syscall_err; |
| 123 | #endif |
| 124 | |
Andreas Färber | 9e0c542 | 2013-06-27 17:45:01 +0200 | [diff] [blame] | 125 | static void arm_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 126 | { |
Andreas Färber | 9e0c542 | 2013-06-27 17:45:01 +0200 | [diff] [blame] | 127 | ARMCPU *cpu = ARM_CPU(cs); |
| 128 | CPUARMState *env = &cpu->env; |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 129 | #ifdef CONFIG_USER_ONLY |
| 130 | TaskState *ts = env->opaque; |
| 131 | #endif |
pbrook | 33d9cc8 | 2007-06-09 14:44:00 +0000 | [diff] [blame] | 132 | |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 133 | if (ret == (target_ulong)-1) { |
| 134 | #ifdef CONFIG_USER_ONLY |
| 135 | ts->swi_errno = err; |
pbrook | 33d9cc8 | 2007-06-09 14:44:00 +0000 | [diff] [blame] | 136 | #else |
| 137 | syscall_err = err; |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 138 | #endif |
| 139 | env->regs[0] = ret; |
| 140 | } else { |
| 141 | /* Fixup syscalls that use nonstardard return conventions. */ |
| 142 | switch (env->regs[0]) { |
Stefan Weil | 3881725 | 2012-04-28 05:07:47 +0000 | [diff] [blame] | 143 | case TARGET_SYS_WRITE: |
| 144 | case TARGET_SYS_READ: |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 145 | env->regs[0] = arm_semi_syscall_len - ret; |
| 146 | break; |
Stefan Weil | 3881725 | 2012-04-28 05:07:47 +0000 | [diff] [blame] | 147 | case TARGET_SYS_SEEK: |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 148 | env->regs[0] = 0; |
| 149 | break; |
| 150 | default: |
| 151 | env->regs[0] = ret; |
| 152 | break; |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | |
Andreas Färber | 9e0c542 | 2013-06-27 17:45:01 +0200 | [diff] [blame] | 157 | static void arm_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err) |
pbrook | 33d9cc8 | 2007-06-09 14:44:00 +0000 | [diff] [blame] | 158 | { |
Andreas Färber | 9e0c542 | 2013-06-27 17:45:01 +0200 | [diff] [blame] | 159 | ARMCPU *cpu = ARM_CPU(cs); |
| 160 | CPUARMState *env = &cpu->env; |
pbrook | 33d9cc8 | 2007-06-09 14:44:00 +0000 | [diff] [blame] | 161 | /* The size is always stored in big-endian order, extract |
| 162 | the value. We assume the size always fit in 32 bits. */ |
| 163 | uint32_t size; |
Andreas Färber | f17ec44 | 2013-06-29 19:40:58 +0200 | [diff] [blame] | 164 | cpu_memory_rw_debug(cs, env->regs[13]-64+32, (uint8_t *)&size, 4, 0); |
pbrook | 33d9cc8 | 2007-06-09 14:44:00 +0000 | [diff] [blame] | 165 | env->regs[0] = be32_to_cpu(size); |
| 166 | #ifdef CONFIG_USER_ONLY |
| 167 | ((TaskState *)env->opaque)->swi_errno = err; |
| 168 | #else |
| 169 | syscall_err = err; |
| 170 | #endif |
| 171 | } |
| 172 | |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 173 | /* Read the input value from the argument block; fail the semihosting |
| 174 | * call if the memory read fails. |
| 175 | */ |
| 176 | #define GET_ARG(n) do { \ |
| 177 | if (get_user_ual(arg ## n, args + (n) * 4)) { \ |
| 178 | return (uint32_t)-1; \ |
| 179 | } \ |
| 180 | } while (0) |
| 181 | |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 182 | #define SET_ARG(n, val) put_user_ual(val, args + (n) * 4) |
Andreas Färber | 81926f4 | 2012-03-14 01:38:23 +0100 | [diff] [blame] | 183 | uint32_t do_arm_semihosting(CPUARMState *env) |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 184 | { |
Andreas Färber | 878096e | 2013-05-27 01:33:50 +0200 | [diff] [blame] | 185 | ARMCPU *cpu = arm_env_get_cpu(env); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 186 | target_ulong args; |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 187 | target_ulong arg0, arg1, arg2, arg3; |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 188 | char * s; |
| 189 | int nr; |
| 190 | uint32_t ret; |
pbrook | 8e71621 | 2007-01-20 17:12:09 +0000 | [diff] [blame] | 191 | uint32_t len; |
| 192 | #ifdef CONFIG_USER_ONLY |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 193 | TaskState *ts = env->opaque; |
pbrook | 8e71621 | 2007-01-20 17:12:09 +0000 | [diff] [blame] | 194 | #else |
Andreas Färber | 81926f4 | 2012-03-14 01:38:23 +0100 | [diff] [blame] | 195 | CPUARMState *ts = env; |
pbrook | 8e71621 | 2007-01-20 17:12:09 +0000 | [diff] [blame] | 196 | #endif |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 197 | |
| 198 | nr = env->regs[0]; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 199 | args = env->regs[1]; |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 200 | switch (nr) { |
Stefan Weil | 3881725 | 2012-04-28 05:07:47 +0000 | [diff] [blame] | 201 | case TARGET_SYS_OPEN: |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 202 | GET_ARG(0); |
| 203 | GET_ARG(1); |
| 204 | GET_ARG(2); |
| 205 | s = lock_user_string(arg0); |
| 206 | if (!s) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 207 | /* FIXME - should this error code be -TARGET_EFAULT ? */ |
| 208 | return (uint32_t)-1; |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 209 | } |
| 210 | if (arg1 >= 12) { |
| 211 | unlock_user(s, arg0, 0); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 212 | return (uint32_t)-1; |
Jim Meyering | 396bef4 | 2012-08-22 13:55:55 +0200 | [diff] [blame] | 213 | } |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 214 | if (strcmp(s, ":tt") == 0) { |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 215 | int result_fileno = arg1 < 4 ? STDIN_FILENO : STDOUT_FILENO; |
| 216 | unlock_user(s, arg0, 0); |
Jim Meyering | 396bef4 | 2012-08-22 13:55:55 +0200 | [diff] [blame] | 217 | return result_fileno; |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 218 | } |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 219 | if (use_gdb_syscalls()) { |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 220 | gdb_do_syscall(arm_semi_cb, "open,%s,%x,1a4", arg0, |
| 221 | (int)arg2+1, gdb_open_modeflags[arg1]); |
Jim Meyering | 396bef4 | 2012-08-22 13:55:55 +0200 | [diff] [blame] | 222 | ret = env->regs[0]; |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 223 | } else { |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 224 | ret = set_swi_errno(ts, open(s, open_modeflags[arg1], 0644)); |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 225 | } |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 226 | unlock_user(s, arg0, 0); |
pbrook | 8e71621 | 2007-01-20 17:12:09 +0000 | [diff] [blame] | 227 | return ret; |
Stefan Weil | 3881725 | 2012-04-28 05:07:47 +0000 | [diff] [blame] | 228 | case TARGET_SYS_CLOSE: |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 229 | GET_ARG(0); |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 230 | if (use_gdb_syscalls()) { |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 231 | gdb_do_syscall(arm_semi_cb, "close,%x", arg0); |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 232 | return env->regs[0]; |
| 233 | } else { |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 234 | return set_swi_errno(ts, close(arg0)); |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 235 | } |
Stefan Weil | 3881725 | 2012-04-28 05:07:47 +0000 | [diff] [blame] | 236 | case TARGET_SYS_WRITEC: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 237 | { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 238 | char c; |
| 239 | |
| 240 | if (get_user_u8(c, args)) |
| 241 | /* FIXME - should this error code be -TARGET_EFAULT ? */ |
| 242 | return (uint32_t)-1; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 243 | /* Write to debug console. stderr is near enough. */ |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 244 | if (use_gdb_syscalls()) { |
| 245 | gdb_do_syscall(arm_semi_cb, "write,2,%x,1", args); |
| 246 | return env->regs[0]; |
| 247 | } else { |
| 248 | return write(STDERR_FILENO, &c, 1); |
| 249 | } |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 250 | } |
Stefan Weil | 3881725 | 2012-04-28 05:07:47 +0000 | [diff] [blame] | 251 | case TARGET_SYS_WRITE0: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 252 | if (!(s = lock_user_string(args))) |
| 253 | /* FIXME - should this error code be -TARGET_EFAULT ? */ |
| 254 | return (uint32_t)-1; |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 255 | len = strlen(s); |
| 256 | if (use_gdb_syscalls()) { |
| 257 | gdb_do_syscall(arm_semi_cb, "write,2,%x,%x\n", args, len); |
| 258 | ret = env->regs[0]; |
| 259 | } else { |
| 260 | ret = write(STDERR_FILENO, s, len); |
| 261 | } |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 262 | unlock_user(s, args, 0); |
| 263 | return ret; |
Stefan Weil | 3881725 | 2012-04-28 05:07:47 +0000 | [diff] [blame] | 264 | case TARGET_SYS_WRITE: |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 265 | GET_ARG(0); |
| 266 | GET_ARG(1); |
| 267 | GET_ARG(2); |
| 268 | len = arg2; |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 269 | if (use_gdb_syscalls()) { |
| 270 | arm_semi_syscall_len = len; |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 271 | gdb_do_syscall(arm_semi_cb, "write,%x,%x,%x", arg0, arg1, len); |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 272 | return env->regs[0]; |
| 273 | } else { |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 274 | s = lock_user(VERIFY_READ, arg1, len, 1); |
| 275 | if (!s) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 276 | /* FIXME - should this error code be -TARGET_EFAULT ? */ |
| 277 | return (uint32_t)-1; |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 278 | } |
| 279 | ret = set_swi_errno(ts, write(arg0, s, len)); |
| 280 | unlock_user(s, arg1, 0); |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 281 | if (ret == (uint32_t)-1) |
| 282 | return -1; |
| 283 | return len - ret; |
| 284 | } |
Stefan Weil | 3881725 | 2012-04-28 05:07:47 +0000 | [diff] [blame] | 285 | case TARGET_SYS_READ: |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 286 | GET_ARG(0); |
| 287 | GET_ARG(1); |
| 288 | GET_ARG(2); |
| 289 | len = arg2; |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 290 | if (use_gdb_syscalls()) { |
| 291 | arm_semi_syscall_len = len; |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 292 | gdb_do_syscall(arm_semi_cb, "read,%x,%x,%x", arg0, arg1, len); |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 293 | return env->regs[0]; |
| 294 | } else { |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 295 | s = lock_user(VERIFY_WRITE, arg1, len, 0); |
| 296 | if (!s) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 297 | /* FIXME - should this error code be -TARGET_EFAULT ? */ |
| 298 | return (uint32_t)-1; |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 299 | } |
| 300 | do { |
| 301 | ret = set_swi_errno(ts, read(arg0, s, len)); |
| 302 | } while (ret == -1 && errno == EINTR); |
| 303 | unlock_user(s, arg1, len); |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 304 | if (ret == (uint32_t)-1) |
| 305 | return -1; |
| 306 | return len - ret; |
| 307 | } |
Stefan Weil | 3881725 | 2012-04-28 05:07:47 +0000 | [diff] [blame] | 308 | case TARGET_SYS_READC: |
Peter Maydell | b90372a | 2012-08-06 17:42:18 +0100 | [diff] [blame] | 309 | /* XXX: Read from debug console. Not implemented. */ |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 310 | return 0; |
Stefan Weil | 3881725 | 2012-04-28 05:07:47 +0000 | [diff] [blame] | 311 | case TARGET_SYS_ISTTY: |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 312 | GET_ARG(0); |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 313 | if (use_gdb_syscalls()) { |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 314 | gdb_do_syscall(arm_semi_cb, "isatty,%x", arg0); |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 315 | return env->regs[0]; |
| 316 | } else { |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 317 | return isatty(arg0); |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 318 | } |
Stefan Weil | 3881725 | 2012-04-28 05:07:47 +0000 | [diff] [blame] | 319 | case TARGET_SYS_SEEK: |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 320 | GET_ARG(0); |
| 321 | GET_ARG(1); |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 322 | if (use_gdb_syscalls()) { |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 323 | gdb_do_syscall(arm_semi_cb, "lseek,%x,%x,0", arg0, arg1); |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 324 | return env->regs[0]; |
| 325 | } else { |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 326 | ret = set_swi_errno(ts, lseek(arg0, arg1, SEEK_SET)); |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 327 | if (ret == (uint32_t)-1) |
| 328 | return -1; |
| 329 | return 0; |
| 330 | } |
Stefan Weil | 3881725 | 2012-04-28 05:07:47 +0000 | [diff] [blame] | 331 | case TARGET_SYS_FLEN: |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 332 | GET_ARG(0); |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 333 | if (use_gdb_syscalls()) { |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 334 | gdb_do_syscall(arm_semi_flen_cb, "fstat,%x,%x", |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 335 | arg0, env->regs[13]-64); |
pbrook | 33d9cc8 | 2007-06-09 14:44:00 +0000 | [diff] [blame] | 336 | return env->regs[0]; |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 337 | } else { |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 338 | struct stat buf; |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 339 | ret = set_swi_errno(ts, fstat(arg0, &buf)); |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 340 | if (ret == (uint32_t)-1) |
| 341 | return -1; |
| 342 | return buf.st_size; |
| 343 | } |
Stefan Weil | 3881725 | 2012-04-28 05:07:47 +0000 | [diff] [blame] | 344 | case TARGET_SYS_TMPNAM: |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 345 | /* XXX: Not implemented. */ |
| 346 | return -1; |
Stefan Weil | 3881725 | 2012-04-28 05:07:47 +0000 | [diff] [blame] | 347 | case TARGET_SYS_REMOVE: |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 348 | GET_ARG(0); |
| 349 | GET_ARG(1); |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 350 | if (use_gdb_syscalls()) { |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 351 | gdb_do_syscall(arm_semi_cb, "unlink,%s", arg0, (int)arg1+1); |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 352 | ret = env->regs[0]; |
| 353 | } else { |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 354 | s = lock_user_string(arg0); |
| 355 | if (!s) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 356 | /* FIXME - should this error code be -TARGET_EFAULT ? */ |
| 357 | return (uint32_t)-1; |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 358 | } |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 359 | ret = set_swi_errno(ts, remove(s)); |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 360 | unlock_user(s, arg0, 0); |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 361 | } |
pbrook | 8e71621 | 2007-01-20 17:12:09 +0000 | [diff] [blame] | 362 | return ret; |
Stefan Weil | 3881725 | 2012-04-28 05:07:47 +0000 | [diff] [blame] | 363 | case TARGET_SYS_RENAME: |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 364 | GET_ARG(0); |
| 365 | GET_ARG(1); |
| 366 | GET_ARG(2); |
| 367 | GET_ARG(3); |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 368 | if (use_gdb_syscalls()) { |
| 369 | gdb_do_syscall(arm_semi_cb, "rename,%s,%s", |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 370 | arg0, (int)arg1+1, arg2, (int)arg3+1); |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 371 | return env->regs[0]; |
| 372 | } else { |
pbrook | 8e71621 | 2007-01-20 17:12:09 +0000 | [diff] [blame] | 373 | char *s2; |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 374 | s = lock_user_string(arg0); |
| 375 | s2 = lock_user_string(arg2); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 376 | if (!s || !s2) |
| 377 | /* FIXME - should this error code be -TARGET_EFAULT ? */ |
| 378 | ret = (uint32_t)-1; |
| 379 | else |
| 380 | ret = set_swi_errno(ts, rename(s, s2)); |
| 381 | if (s2) |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 382 | unlock_user(s2, arg2, 0); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 383 | if (s) |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 384 | unlock_user(s, arg0, 0); |
pbrook | 8e71621 | 2007-01-20 17:12:09 +0000 | [diff] [blame] | 385 | return ret; |
| 386 | } |
Stefan Weil | 3881725 | 2012-04-28 05:07:47 +0000 | [diff] [blame] | 387 | case TARGET_SYS_CLOCK: |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 388 | return clock() / (CLOCKS_PER_SEC / 100); |
Stefan Weil | 3881725 | 2012-04-28 05:07:47 +0000 | [diff] [blame] | 389 | case TARGET_SYS_TIME: |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 390 | return set_swi_errno(ts, time(NULL)); |
Stefan Weil | 3881725 | 2012-04-28 05:07:47 +0000 | [diff] [blame] | 391 | case TARGET_SYS_SYSTEM: |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 392 | GET_ARG(0); |
| 393 | GET_ARG(1); |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 394 | if (use_gdb_syscalls()) { |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 395 | gdb_do_syscall(arm_semi_cb, "system,%s", arg0, (int)arg1+1); |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 396 | return env->regs[0]; |
| 397 | } else { |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 398 | s = lock_user_string(arg0); |
| 399 | if (!s) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 400 | /* FIXME - should this error code be -TARGET_EFAULT ? */ |
| 401 | return (uint32_t)-1; |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 402 | } |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 403 | ret = set_swi_errno(ts, system(s)); |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 404 | unlock_user(s, arg0, 0); |
ths | a982b53 | 2008-07-01 16:40:04 +0000 | [diff] [blame] | 405 | return ret; |
pbrook | a2d1eba | 2007-01-28 03:10:55 +0000 | [diff] [blame] | 406 | } |
Stefan Weil | 3881725 | 2012-04-28 05:07:47 +0000 | [diff] [blame] | 407 | case TARGET_SYS_ERRNO: |
pbrook | 8e71621 | 2007-01-20 17:12:09 +0000 | [diff] [blame] | 408 | #ifdef CONFIG_USER_ONLY |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 409 | return ts->swi_errno; |
pbrook | 8e71621 | 2007-01-20 17:12:09 +0000 | [diff] [blame] | 410 | #else |
pbrook | 33d9cc8 | 2007-06-09 14:44:00 +0000 | [diff] [blame] | 411 | return syscall_err; |
pbrook | 8e71621 | 2007-01-20 17:12:09 +0000 | [diff] [blame] | 412 | #endif |
Stefan Weil | 3881725 | 2012-04-28 05:07:47 +0000 | [diff] [blame] | 413 | case TARGET_SYS_GET_CMDLINE: |
pbrook | 38d0662 | 2006-11-19 20:29:35 +0000 | [diff] [blame] | 414 | { |
Cédric VINCENT | 1c1b40c | 2011-06-29 12:49:41 +0200 | [diff] [blame] | 415 | /* Build a command-line from the original argv. |
| 416 | * |
| 417 | * The inputs are: |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 418 | * * arg0, pointer to a buffer of at least the size |
| 419 | * specified in arg1. |
| 420 | * * arg1, size of the buffer pointed to by arg0 in |
Cédric VINCENT | 1c1b40c | 2011-06-29 12:49:41 +0200 | [diff] [blame] | 421 | * bytes. |
| 422 | * |
| 423 | * The outputs are: |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 424 | * * arg0, pointer to null-terminated string of the |
Cédric VINCENT | 1c1b40c | 2011-06-29 12:49:41 +0200 | [diff] [blame] | 425 | * command line. |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 426 | * * arg1, length of the string pointed to by arg0. |
Cédric VINCENT | 1c1b40c | 2011-06-29 12:49:41 +0200 | [diff] [blame] | 427 | */ |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 428 | |
Cédric VINCENT | 1c1b40c | 2011-06-29 12:49:41 +0200 | [diff] [blame] | 429 | char *output_buffer; |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 430 | size_t input_size; |
Cédric VINCENT | 1c1b40c | 2011-06-29 12:49:41 +0200 | [diff] [blame] | 431 | size_t output_size; |
| 432 | int status = 0; |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 433 | GET_ARG(0); |
| 434 | GET_ARG(1); |
| 435 | input_size = arg1; |
Cédric VINCENT | 1c1b40c | 2011-06-29 12:49:41 +0200 | [diff] [blame] | 436 | /* Compute the size of the output string. */ |
| 437 | #if !defined(CONFIG_USER_ONLY) |
| 438 | output_size = strlen(ts->boot_info->kernel_filename) |
| 439 | + 1 /* Separating space. */ |
| 440 | + strlen(ts->boot_info->kernel_cmdline) |
| 441 | + 1; /* Terminating null byte. */ |
| 442 | #else |
Wolfgang Schildbach | 2e8785a | 2010-12-06 15:06:05 +0000 | [diff] [blame] | 443 | unsigned int i; |
pbrook | 38d0662 | 2006-11-19 20:29:35 +0000 | [diff] [blame] | 444 | |
Cédric VINCENT | 1c1b40c | 2011-06-29 12:49:41 +0200 | [diff] [blame] | 445 | output_size = ts->info->arg_end - ts->info->arg_start; |
| 446 | if (!output_size) { |
Wolfgang Schildbach | 2e8785a | 2010-12-06 15:06:05 +0000 | [diff] [blame] | 447 | /* We special-case the "empty command line" case (argc==0). |
| 448 | Just provide the terminating 0. */ |
Cédric VINCENT | 1c1b40c | 2011-06-29 12:49:41 +0200 | [diff] [blame] | 449 | output_size = 1; |
Wolfgang Schildbach | 2e8785a | 2010-12-06 15:06:05 +0000 | [diff] [blame] | 450 | } |
pbrook | 8e71621 | 2007-01-20 17:12:09 +0000 | [diff] [blame] | 451 | #endif |
Cédric VINCENT | 1c1b40c | 2011-06-29 12:49:41 +0200 | [diff] [blame] | 452 | |
| 453 | if (output_size > input_size) { |
| 454 | /* Not enough space to store command-line arguments. */ |
| 455 | return -1; |
| 456 | } |
| 457 | |
| 458 | /* Adjust the command-line length. */ |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 459 | if (SET_ARG(1, output_size - 1)) { |
| 460 | /* Couldn't write back to argument block */ |
| 461 | return -1; |
| 462 | } |
Cédric VINCENT | 1c1b40c | 2011-06-29 12:49:41 +0200 | [diff] [blame] | 463 | |
| 464 | /* Lock the buffer on the ARM side. */ |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 465 | output_buffer = lock_user(VERIFY_WRITE, arg0, output_size, 0); |
Cédric VINCENT | 1c1b40c | 2011-06-29 12:49:41 +0200 | [diff] [blame] | 466 | if (!output_buffer) { |
| 467 | return -1; |
| 468 | } |
| 469 | |
| 470 | /* Copy the command-line arguments. */ |
| 471 | #if !defined(CONFIG_USER_ONLY) |
| 472 | pstrcpy(output_buffer, output_size, ts->boot_info->kernel_filename); |
| 473 | pstrcat(output_buffer, output_size, " "); |
| 474 | pstrcat(output_buffer, output_size, ts->boot_info->kernel_cmdline); |
| 475 | #else |
| 476 | if (output_size == 1) { |
| 477 | /* Empty command-line. */ |
| 478 | output_buffer[0] = '\0'; |
| 479 | goto out; |
| 480 | } |
| 481 | |
| 482 | if (copy_from_user(output_buffer, ts->info->arg_start, |
| 483 | output_size)) { |
| 484 | status = -1; |
| 485 | goto out; |
| 486 | } |
| 487 | |
| 488 | /* Separate arguments by white spaces. */ |
| 489 | for (i = 0; i < output_size - 1; i++) { |
| 490 | if (output_buffer[i] == 0) { |
| 491 | output_buffer[i] = ' '; |
| 492 | } |
| 493 | } |
| 494 | out: |
| 495 | #endif |
| 496 | /* Unlock the buffer on the ARM side. */ |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 497 | unlock_user(output_buffer, arg0, output_size); |
Cédric VINCENT | 1c1b40c | 2011-06-29 12:49:41 +0200 | [diff] [blame] | 498 | |
| 499 | return status; |
| 500 | } |
Stefan Weil | 3881725 | 2012-04-28 05:07:47 +0000 | [diff] [blame] | 501 | case TARGET_SYS_HEAPINFO: |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 502 | { |
| 503 | uint32_t *ptr; |
| 504 | uint32_t limit; |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 505 | GET_ARG(0); |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 506 | |
pbrook | 8e71621 | 2007-01-20 17:12:09 +0000 | [diff] [blame] | 507 | #ifdef CONFIG_USER_ONLY |
| 508 | /* Some C libraries assume the heap immediately follows .bss, so |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 509 | allocate it using sbrk. */ |
| 510 | if (!ts->heap_limit) { |
Peter Maydell | 206ae74 | 2011-04-18 16:34:25 +0100 | [diff] [blame] | 511 | abi_ulong ret; |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 512 | |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 513 | ts->heap_base = do_brk(0); |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 514 | limit = ts->heap_base + ARM_ANGEL_HEAP_SIZE; |
| 515 | /* Try a big heap, and reduce the size if that fails. */ |
| 516 | for (;;) { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 517 | ret = do_brk(limit); |
Peter Maydell | 206ae74 | 2011-04-18 16:34:25 +0100 | [diff] [blame] | 518 | if (ret >= limit) { |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 519 | break; |
Peter Maydell | 206ae74 | 2011-04-18 16:34:25 +0100 | [diff] [blame] | 520 | } |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 521 | limit = (ts->heap_base >> 1) + (limit >> 1); |
| 522 | } |
| 523 | ts->heap_limit = limit; |
| 524 | } |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 525 | |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 526 | ptr = lock_user(VERIFY_WRITE, arg0, 16, 0); |
| 527 | if (!ptr) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 528 | /* FIXME - should this error code be -TARGET_EFAULT ? */ |
| 529 | return (uint32_t)-1; |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 530 | } |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 531 | ptr[0] = tswap32(ts->heap_base); |
| 532 | ptr[1] = tswap32(ts->heap_limit); |
| 533 | ptr[2] = tswap32(ts->stack_base); |
| 534 | ptr[3] = tswap32(0); /* Stack limit. */ |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 535 | unlock_user(ptr, arg0, 16); |
pbrook | 8e71621 | 2007-01-20 17:12:09 +0000 | [diff] [blame] | 536 | #else |
| 537 | limit = ram_size; |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 538 | ptr = lock_user(VERIFY_WRITE, arg0, 16, 0); |
| 539 | if (!ptr) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 540 | /* FIXME - should this error code be -TARGET_EFAULT ? */ |
| 541 | return (uint32_t)-1; |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 542 | } |
pbrook | 8e71621 | 2007-01-20 17:12:09 +0000 | [diff] [blame] | 543 | /* TODO: Make this use the limit of the loaded application. */ |
| 544 | ptr[0] = tswap32(limit / 2); |
| 545 | ptr[1] = tswap32(limit); |
| 546 | ptr[2] = tswap32(limit); /* Stack base */ |
| 547 | ptr[3] = tswap32(0); /* Stack limit. */ |
Peter Maydell | f296c0d | 2012-10-14 09:52:27 +0000 | [diff] [blame] | 548 | unlock_user(ptr, arg0, 16); |
pbrook | 8e71621 | 2007-01-20 17:12:09 +0000 | [diff] [blame] | 549 | #endif |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 550 | return 0; |
| 551 | } |
Stefan Weil | 3881725 | 2012-04-28 05:07:47 +0000 | [diff] [blame] | 552 | case TARGET_SYS_EXIT: |
Paul Brook | 0e1c9c5 | 2010-06-16 13:03:51 +0100 | [diff] [blame] | 553 | gdb_exit(env, 0); |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 554 | exit(0); |
| 555 | default: |
| 556 | fprintf(stderr, "qemu: Unsupported SemiHosting SWI 0x%02x\n", nr); |
Andreas Färber | 878096e | 2013-05-27 01:33:50 +0200 | [diff] [blame] | 557 | cpu_dump_state(CPU(cpu), stderr, fprintf, 0); |
bellard | a4f8197 | 2005-04-23 18:25:41 +0000 | [diff] [blame] | 558 | abort(); |
| 559 | } |
| 560 | } |