root / arm-semi.c @ 36bb244b
History | View | Annotate | Download (13.3 kB)
1 | a4f81979 | bellard | /*
|
---|---|---|---|
2 | a4f81979 | bellard | * Arm "Angel" semihosting syscalls
|
3 | a4f81979 | bellard | *
|
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 | 8e71621f | pbrook | static uint32_t softmmu_tget32(CPUState *env, uint32_t addr)
|
116 | 8e71621f | pbrook | { |
117 | 8e71621f | pbrook | uint32_t val; |
118 | 8e71621f | pbrook | |
119 | 8e71621f | pbrook | cpu_memory_rw_debug(env, addr, (uint8_t *)&val, 4, 0); |
120 | 8e71621f | pbrook | return tswap32(val);
|
121 | a4f81979 | bellard | } |
122 | 8e71621f | pbrook | static uint32_t softmmu_tget8(CPUState *env, uint32_t addr)
|
123 | 8e71621f | pbrook | { |
124 | 8e71621f | pbrook | uint8_t val; |
125 | 8e71621f | pbrook | |
126 | 8e71621f | pbrook | cpu_memory_rw_debug(env, addr, &val, 1, 0); |
127 | 8e71621f | pbrook | return val;
|
128 | 8e71621f | pbrook | } |
129 | 8e71621f | pbrook | #define tget32(p) softmmu_tget32(env, p)
|
130 | 8e71621f | pbrook | #define tget8(p) softmmu_tget8(env, p)
|
131 | 8e71621f | pbrook | |
132 | 8e71621f | pbrook | static void *softmmu_lock_user(CPUState *env, uint32_t addr, uint32_t len, |
133 | 8e71621f | pbrook | int copy)
|
134 | 8e71621f | pbrook | { |
135 | 8e71621f | pbrook | char *p;
|
136 | 8e71621f | pbrook | /* TODO: Make this something that isn't fixed size. */
|
137 | 8e71621f | pbrook | p = malloc(len); |
138 | 8e71621f | pbrook | if (copy)
|
139 | 8e71621f | pbrook | cpu_memory_rw_debug(env, addr, p, len, 0);
|
140 | 8e71621f | pbrook | return p;
|
141 | 8e71621f | pbrook | } |
142 | 8e71621f | pbrook | #define lock_user(p, len, copy) softmmu_lock_user(env, p, len, copy)
|
143 | 8e71621f | pbrook | static char *softmmu_lock_user_string(CPUState *env, uint32_t addr) |
144 | 8e71621f | pbrook | { |
145 | 8e71621f | pbrook | char *p;
|
146 | 8e71621f | pbrook | char *s;
|
147 | 8e71621f | pbrook | uint8_t c; |
148 | 8e71621f | pbrook | /* TODO: Make this something that isn't fixed size. */
|
149 | 8e71621f | pbrook | s = p = malloc(1024);
|
150 | 8e71621f | pbrook | do {
|
151 | 8e71621f | pbrook | cpu_memory_rw_debug(env, addr, &c, 1, 0); |
152 | 8e71621f | pbrook | addr++; |
153 | 8e71621f | pbrook | *(p++) = c; |
154 | 8e71621f | pbrook | } while (c);
|
155 | 8e71621f | pbrook | return s;
|
156 | 8e71621f | pbrook | } |
157 | 8e71621f | pbrook | #define lock_user_string(p) softmmu_lock_user_string(env, p)
|
158 | 8e71621f | pbrook | static void softmmu_unlock_user(CPUState *env, void *p, target_ulong addr, |
159 | 8e71621f | pbrook | target_ulong len) |
160 | 8e71621f | pbrook | { |
161 | 8e71621f | pbrook | if (len)
|
162 | 8e71621f | pbrook | cpu_memory_rw_debug(env, addr, p, len, 1);
|
163 | 8e71621f | pbrook | free(p); |
164 | 8e71621f | pbrook | } |
165 | 8e71621f | pbrook | #define unlock_user(s, args, len) softmmu_unlock_user(env, s, args, len)
|
166 | 8e71621f | pbrook | #endif
|
167 | a4f81979 | bellard | |
168 | a2d1ebaf | pbrook | static target_ulong arm_semi_syscall_len;
|
169 | a2d1ebaf | pbrook | |
170 | a2d1ebaf | pbrook | static void arm_semi_cb(CPUState *env, target_ulong ret, target_ulong err) |
171 | a2d1ebaf | pbrook | { |
172 | a2d1ebaf | pbrook | #ifdef CONFIG_USER_ONLY
|
173 | a2d1ebaf | pbrook | TaskState *ts = env->opaque; |
174 | a2d1ebaf | pbrook | #endif
|
175 | a2d1ebaf | pbrook | if (ret == (target_ulong)-1) { |
176 | a2d1ebaf | pbrook | #ifdef CONFIG_USER_ONLY
|
177 | a2d1ebaf | pbrook | ts->swi_errno = err; |
178 | a2d1ebaf | pbrook | #endif
|
179 | a2d1ebaf | pbrook | env->regs[0] = ret;
|
180 | a2d1ebaf | pbrook | } else {
|
181 | a2d1ebaf | pbrook | /* Fixup syscalls that use nonstardard return conventions. */
|
182 | a2d1ebaf | pbrook | switch (env->regs[0]) { |
183 | a2d1ebaf | pbrook | case SYS_WRITE:
|
184 | a2d1ebaf | pbrook | case SYS_READ:
|
185 | a2d1ebaf | pbrook | env->regs[0] = arm_semi_syscall_len - ret;
|
186 | a2d1ebaf | pbrook | break;
|
187 | a2d1ebaf | pbrook | case SYS_SEEK:
|
188 | a2d1ebaf | pbrook | env->regs[0] = 0; |
189 | a2d1ebaf | pbrook | break;
|
190 | a2d1ebaf | pbrook | default:
|
191 | a2d1ebaf | pbrook | env->regs[0] = ret;
|
192 | a2d1ebaf | pbrook | break;
|
193 | a2d1ebaf | pbrook | } |
194 | a2d1ebaf | pbrook | } |
195 | a2d1ebaf | pbrook | } |
196 | a2d1ebaf | pbrook | |
197 | 38d0662a | pbrook | #define ARG(n) tget32(args + (n) * 4) |
198 | 38d0662a | pbrook | #define SET_ARG(n, val) tput32(args + (n) * 4,val) |
199 | a4f81979 | bellard | uint32_t do_arm_semihosting(CPUState *env) |
200 | a4f81979 | bellard | { |
201 | 53a5960a | pbrook | target_ulong args; |
202 | a4f81979 | bellard | char * s;
|
203 | a4f81979 | bellard | int nr;
|
204 | a4f81979 | bellard | uint32_t ret; |
205 | 8e71621f | pbrook | uint32_t len; |
206 | 8e71621f | pbrook | #ifdef CONFIG_USER_ONLY
|
207 | a4f81979 | bellard | TaskState *ts = env->opaque; |
208 | 8e71621f | pbrook | #else
|
209 | 8e71621f | pbrook | CPUState *ts = env; |
210 | 8e71621f | pbrook | #endif
|
211 | a4f81979 | bellard | |
212 | a4f81979 | bellard | nr = env->regs[0];
|
213 | 53a5960a | pbrook | args = env->regs[1];
|
214 | a4f81979 | bellard | switch (nr) {
|
215 | a4f81979 | bellard | case SYS_OPEN:
|
216 | 8e71621f | pbrook | s = lock_user_string(ARG(0));
|
217 | a4f81979 | bellard | if (ARG(1) >= 12) |
218 | a4f81979 | bellard | return (uint32_t)-1; |
219 | a4f81979 | bellard | if (strcmp(s, ":tt") == 0) { |
220 | a4f81979 | bellard | if (ARG(1) < 4) |
221 | a4f81979 | bellard | return STDIN_FILENO;
|
222 | a4f81979 | bellard | else
|
223 | a4f81979 | bellard | return STDOUT_FILENO;
|
224 | a4f81979 | bellard | } |
225 | a2d1ebaf | pbrook | if (use_gdb_syscalls()) {
|
226 | a2d1ebaf | pbrook | gdb_do_syscall(arm_semi_cb, "open,%s,%x,1a4", ARG(0), (int)ARG(2), |
227 | a2d1ebaf | pbrook | gdb_open_modeflags[ARG(1)]);
|
228 | a2d1ebaf | pbrook | return env->regs[0]; |
229 | a2d1ebaf | pbrook | } else {
|
230 | a2d1ebaf | pbrook | ret = set_swi_errno(ts, open(s, open_modeflags[ARG(1)], 0644)); |
231 | a2d1ebaf | pbrook | } |
232 | 8e71621f | pbrook | unlock_user(s, ARG(0), 0); |
233 | 8e71621f | pbrook | return ret;
|
234 | a4f81979 | bellard | case SYS_CLOSE:
|
235 | a2d1ebaf | pbrook | if (use_gdb_syscalls()) {
|
236 | a2d1ebaf | pbrook | gdb_do_syscall(arm_semi_cb, "close,%x", ARG(0)); |
237 | a2d1ebaf | pbrook | return env->regs[0]; |
238 | a2d1ebaf | pbrook | } else {
|
239 | a2d1ebaf | pbrook | return set_swi_errno(ts, close(ARG(0))); |
240 | a2d1ebaf | pbrook | } |
241 | a4f81979 | bellard | case SYS_WRITEC:
|
242 | 53a5960a | pbrook | { |
243 | 53a5960a | pbrook | char c = tget8(args);
|
244 | 53a5960a | pbrook | /* Write to debug console. stderr is near enough. */
|
245 | a2d1ebaf | pbrook | if (use_gdb_syscalls()) {
|
246 | a2d1ebaf | pbrook | gdb_do_syscall(arm_semi_cb, "write,2,%x,1", args);
|
247 | a2d1ebaf | pbrook | return env->regs[0]; |
248 | a2d1ebaf | pbrook | } else {
|
249 | a2d1ebaf | pbrook | return write(STDERR_FILENO, &c, 1); |
250 | a2d1ebaf | pbrook | } |
251 | 53a5960a | pbrook | } |
252 | a4f81979 | bellard | case SYS_WRITE0:
|
253 | 53a5960a | pbrook | s = lock_user_string(args); |
254 | a2d1ebaf | pbrook | len = strlen(s); |
255 | a2d1ebaf | pbrook | if (use_gdb_syscalls()) {
|
256 | a2d1ebaf | pbrook | gdb_do_syscall(arm_semi_cb, "write,2,%x,%x\n", args, len);
|
257 | a2d1ebaf | pbrook | ret = env->regs[0];
|
258 | a2d1ebaf | pbrook | } else {
|
259 | a2d1ebaf | pbrook | ret = write(STDERR_FILENO, s, len); |
260 | a2d1ebaf | pbrook | } |
261 | 53a5960a | pbrook | unlock_user(s, args, 0);
|
262 | 53a5960a | pbrook | return ret;
|
263 | a4f81979 | bellard | case SYS_WRITE:
|
264 | 8e71621f | pbrook | len = ARG(2);
|
265 | a2d1ebaf | pbrook | if (use_gdb_syscalls()) {
|
266 | a2d1ebaf | pbrook | arm_semi_syscall_len = len; |
267 | a2d1ebaf | pbrook | gdb_do_syscall(arm_semi_cb, "write,%x,%x,%x", ARG(0), ARG(1), len); |
268 | a2d1ebaf | pbrook | return env->regs[0]; |
269 | a2d1ebaf | pbrook | } else {
|
270 | a2d1ebaf | pbrook | s = lock_user(ARG(1), len, 1); |
271 | a2d1ebaf | pbrook | ret = set_swi_errno(ts, write(ARG(0), s, len));
|
272 | a2d1ebaf | pbrook | unlock_user(s, ARG(1), 0); |
273 | a2d1ebaf | pbrook | if (ret == (uint32_t)-1) |
274 | a2d1ebaf | pbrook | return -1; |
275 | a2d1ebaf | pbrook | return len - ret;
|
276 | a2d1ebaf | pbrook | } |
277 | a4f81979 | bellard | case SYS_READ:
|
278 | 8e71621f | pbrook | len = ARG(2);
|
279 | a2d1ebaf | pbrook | if (use_gdb_syscalls()) {
|
280 | a2d1ebaf | pbrook | arm_semi_syscall_len = len; |
281 | a2d1ebaf | pbrook | gdb_do_syscall(arm_semi_cb, "read,%x,%x,%x", ARG(0), ARG(1), len); |
282 | a2d1ebaf | pbrook | return env->regs[0]; |
283 | a2d1ebaf | pbrook | } else {
|
284 | a2d1ebaf | pbrook | s = lock_user(ARG(1), len, 0); |
285 | a2d1ebaf | pbrook | do
|
286 | a2d1ebaf | pbrook | ret = set_swi_errno(ts, read(ARG(0), s, len));
|
287 | a2d1ebaf | pbrook | while (ret == -1 && errno == EINTR); |
288 | a2d1ebaf | pbrook | unlock_user(s, ARG(1), len);
|
289 | a2d1ebaf | pbrook | if (ret == (uint32_t)-1) |
290 | a2d1ebaf | pbrook | return -1; |
291 | a2d1ebaf | pbrook | return len - ret;
|
292 | a2d1ebaf | pbrook | } |
293 | a4f81979 | bellard | case SYS_READC:
|
294 | a4f81979 | bellard | /* XXX: Read from debug cosole. Not implemented. */
|
295 | a4f81979 | bellard | return 0; |
296 | a4f81979 | bellard | case SYS_ISTTY:
|
297 | a2d1ebaf | pbrook | if (use_gdb_syscalls()) {
|
298 | a2d1ebaf | pbrook | gdb_do_syscall(arm_semi_cb, "isatty,%x", ARG(0)); |
299 | a2d1ebaf | pbrook | return env->regs[0]; |
300 | a2d1ebaf | pbrook | } else {
|
301 | a2d1ebaf | pbrook | return isatty(ARG(0)); |
302 | a2d1ebaf | pbrook | } |
303 | a4f81979 | bellard | case SYS_SEEK:
|
304 | a2d1ebaf | pbrook | if (use_gdb_syscalls()) {
|
305 | a2d1ebaf | pbrook | gdb_do_syscall(arm_semi_cb, "fseek,%x,%x,0", ARG(0), ARG(1)); |
306 | a2d1ebaf | pbrook | return env->regs[0]; |
307 | a2d1ebaf | pbrook | } else {
|
308 | a2d1ebaf | pbrook | ret = set_swi_errno(ts, lseek(ARG(0), ARG(1), SEEK_SET)); |
309 | a2d1ebaf | pbrook | if (ret == (uint32_t)-1) |
310 | a2d1ebaf | pbrook | return -1; |
311 | a2d1ebaf | pbrook | return 0; |
312 | a2d1ebaf | pbrook | } |
313 | a4f81979 | bellard | case SYS_FLEN:
|
314 | a2d1ebaf | pbrook | if (use_gdb_syscalls()) {
|
315 | a2d1ebaf | pbrook | /* TODO: Use stat syscall. */
|
316 | a2d1ebaf | pbrook | return -1; |
317 | a2d1ebaf | pbrook | } else {
|
318 | a4f81979 | bellard | struct stat buf;
|
319 | a4f81979 | bellard | ret = set_swi_errno(ts, fstat(ARG(0), &buf));
|
320 | a4f81979 | bellard | if (ret == (uint32_t)-1) |
321 | a4f81979 | bellard | return -1; |
322 | a4f81979 | bellard | return buf.st_size;
|
323 | a4f81979 | bellard | } |
324 | a4f81979 | bellard | case SYS_TMPNAM:
|
325 | a4f81979 | bellard | /* XXX: Not implemented. */
|
326 | a4f81979 | bellard | return -1; |
327 | a4f81979 | bellard | case SYS_REMOVE:
|
328 | a2d1ebaf | pbrook | if (use_gdb_syscalls()) {
|
329 | a2d1ebaf | pbrook | gdb_do_syscall(arm_semi_cb, "unlink,%s", ARG(0), (int)ARG(1)); |
330 | a2d1ebaf | pbrook | ret = env->regs[0];
|
331 | a2d1ebaf | pbrook | } else {
|
332 | a2d1ebaf | pbrook | s = lock_user_string(ARG(0));
|
333 | a2d1ebaf | pbrook | ret = set_swi_errno(ts, remove(s)); |
334 | a2d1ebaf | pbrook | unlock_user(s, ARG(0), 0); |
335 | a2d1ebaf | pbrook | } |
336 | 8e71621f | pbrook | return ret;
|
337 | a4f81979 | bellard | case SYS_RENAME:
|
338 | a2d1ebaf | pbrook | if (use_gdb_syscalls()) {
|
339 | a2d1ebaf | pbrook | gdb_do_syscall(arm_semi_cb, "rename,%s,%s",
|
340 | a2d1ebaf | pbrook | ARG(0), (int)ARG(1), ARG(2), (int)ARG(3)); |
341 | a2d1ebaf | pbrook | return env->regs[0]; |
342 | a2d1ebaf | pbrook | } else {
|
343 | 8e71621f | pbrook | char *s2;
|
344 | 8e71621f | pbrook | s = lock_user_string(ARG(0));
|
345 | 8e71621f | pbrook | s2 = lock_user_string(ARG(2));
|
346 | 8e71621f | pbrook | ret = set_swi_errno(ts, rename(s, s2)); |
347 | 8e71621f | pbrook | unlock_user(s2, ARG(2), 0); |
348 | 8e71621f | pbrook | unlock_user(s, ARG(0), 0); |
349 | 8e71621f | pbrook | return ret;
|
350 | 8e71621f | pbrook | } |
351 | a4f81979 | bellard | case SYS_CLOCK:
|
352 | a4f81979 | bellard | return clock() / (CLOCKS_PER_SEC / 100); |
353 | a4f81979 | bellard | case SYS_TIME:
|
354 | a4f81979 | bellard | return set_swi_errno(ts, time(NULL)); |
355 | a4f81979 | bellard | case SYS_SYSTEM:
|
356 | a2d1ebaf | pbrook | if (use_gdb_syscalls()) {
|
357 | a2d1ebaf | pbrook | gdb_do_syscall(arm_semi_cb, "system,%s", ARG(0), (int)ARG(1)); |
358 | a2d1ebaf | pbrook | return env->regs[0]; |
359 | a2d1ebaf | pbrook | } else {
|
360 | a2d1ebaf | pbrook | s = lock_user_string(ARG(0));
|
361 | a2d1ebaf | pbrook | ret = set_swi_errno(ts, system(s)); |
362 | a2d1ebaf | pbrook | unlock_user(s, ARG(0), 0); |
363 | a2d1ebaf | pbrook | } |
364 | a4f81979 | bellard | case SYS_ERRNO:
|
365 | 8e71621f | pbrook | #ifdef CONFIG_USER_ONLY
|
366 | a4f81979 | bellard | return ts->swi_errno;
|
367 | 8e71621f | pbrook | #else
|
368 | 8e71621f | pbrook | return 0; |
369 | 8e71621f | pbrook | #endif
|
370 | a4f81979 | bellard | case SYS_GET_CMDLINE:
|
371 | 8e71621f | pbrook | #ifdef CONFIG_USER_ONLY
|
372 | 38d0662a | pbrook | /* Build a commandline from the original argv. */
|
373 | 38d0662a | pbrook | { |
374 | 38d0662a | pbrook | char **arg = ts->info->host_argv;
|
375 | 38d0662a | pbrook | int len = ARG(1); |
376 | 38d0662a | pbrook | /* lock the buffer on the ARM side */
|
377 | 38d0662a | pbrook | char *cmdline_buffer = (char*)lock_user(ARG(0), len, 0); |
378 | 38d0662a | pbrook | |
379 | 38d0662a | pbrook | s = cmdline_buffer; |
380 | 38d0662a | pbrook | while (*arg && len > 2) { |
381 | 38d0662a | pbrook | int n = strlen(*arg);
|
382 | 38d0662a | pbrook | |
383 | 38d0662a | pbrook | if (s != cmdline_buffer) {
|
384 | 38d0662a | pbrook | *(s++) = ' ';
|
385 | 38d0662a | pbrook | len--; |
386 | 38d0662a | pbrook | } |
387 | 38d0662a | pbrook | if (n >= len)
|
388 | 38d0662a | pbrook | n = len - 1;
|
389 | 38d0662a | pbrook | memcpy(s, *arg, n); |
390 | 38d0662a | pbrook | s += n; |
391 | 38d0662a | pbrook | len -= n; |
392 | 38d0662a | pbrook | arg++; |
393 | 38d0662a | pbrook | } |
394 | 38d0662a | pbrook | /* Null terminate the string. */
|
395 | 38d0662a | pbrook | *s = 0;
|
396 | 38d0662a | pbrook | len = s - cmdline_buffer; |
397 | 38d0662a | pbrook | |
398 | 38d0662a | pbrook | /* Unlock the buffer on the ARM side. */
|
399 | 38d0662a | pbrook | unlock_user(cmdline_buffer, ARG(0), len);
|
400 | 38d0662a | pbrook | |
401 | 38d0662a | pbrook | /* Adjust the commandline length argument. */
|
402 | 38d0662a | pbrook | SET_ARG(1, len);
|
403 | 38d0662a | pbrook | |
404 | 38d0662a | pbrook | /* Return success if commandline fit into buffer. */
|
405 | 38d0662a | pbrook | return *arg ? -1 : 0; |
406 | 38d0662a | pbrook | } |
407 | 8e71621f | pbrook | #else
|
408 | 8e71621f | pbrook | return -1; |
409 | 8e71621f | pbrook | #endif
|
410 | a4f81979 | bellard | case SYS_HEAPINFO:
|
411 | a4f81979 | bellard | { |
412 | a4f81979 | bellard | uint32_t *ptr; |
413 | a4f81979 | bellard | uint32_t limit; |
414 | a4f81979 | bellard | |
415 | 8e71621f | pbrook | #ifdef CONFIG_USER_ONLY
|
416 | 8e71621f | pbrook | /* Some C libraries assume the heap immediately follows .bss, so
|
417 | a4f81979 | bellard | allocate it using sbrk. */
|
418 | a4f81979 | bellard | if (!ts->heap_limit) {
|
419 | a4f81979 | bellard | long ret;
|
420 | a4f81979 | bellard | |
421 | 53a5960a | pbrook | ts->heap_base = do_brk(0);
|
422 | a4f81979 | bellard | limit = ts->heap_base + ARM_ANGEL_HEAP_SIZE; |
423 | a4f81979 | bellard | /* Try a big heap, and reduce the size if that fails. */
|
424 | a4f81979 | bellard | for (;;) {
|
425 | 53a5960a | pbrook | ret = do_brk(limit); |
426 | a4f81979 | bellard | if (ret != -1) |
427 | a4f81979 | bellard | break;
|
428 | a4f81979 | bellard | limit = (ts->heap_base >> 1) + (limit >> 1); |
429 | a4f81979 | bellard | } |
430 | a4f81979 | bellard | ts->heap_limit = limit; |
431 | a4f81979 | bellard | } |
432 | a4f81979 | bellard | |
433 | 8e71621f | pbrook | ptr = lock_user(ARG(0), 16, 0); |
434 | a4f81979 | bellard | ptr[0] = tswap32(ts->heap_base);
|
435 | a4f81979 | bellard | ptr[1] = tswap32(ts->heap_limit);
|
436 | a4f81979 | bellard | ptr[2] = tswap32(ts->stack_base);
|
437 | a4f81979 | bellard | ptr[3] = tswap32(0); /* Stack limit. */ |
438 | 8e71621f | pbrook | unlock_user(ptr, ARG(0), 16); |
439 | 8e71621f | pbrook | #else
|
440 | 8e71621f | pbrook | limit = ram_size; |
441 | 8e71621f | pbrook | ptr = lock_user(ARG(0), 16, 0); |
442 | 8e71621f | pbrook | /* TODO: Make this use the limit of the loaded application. */
|
443 | 8e71621f | pbrook | ptr[0] = tswap32(limit / 2); |
444 | 8e71621f | pbrook | ptr[1] = tswap32(limit);
|
445 | 8e71621f | pbrook | ptr[2] = tswap32(limit); /* Stack base */ |
446 | 8e71621f | pbrook | ptr[3] = tswap32(0); /* Stack limit. */ |
447 | 8e71621f | pbrook | unlock_user(ptr, ARG(0), 16); |
448 | 8e71621f | pbrook | #endif
|
449 | a4f81979 | bellard | return 0; |
450 | a4f81979 | bellard | } |
451 | a4f81979 | bellard | case SYS_EXIT:
|
452 | a4f81979 | bellard | exit(0);
|
453 | a4f81979 | bellard | default:
|
454 | a4f81979 | bellard | fprintf(stderr, "qemu: Unsupported SemiHosting SWI 0x%02x\n", nr);
|
455 | a4f81979 | bellard | cpu_dump_state(env, stderr, fprintf, 0);
|
456 | a4f81979 | bellard | abort(); |
457 | a4f81979 | bellard | } |
458 | a4f81979 | bellard | } |