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