root / m68k-semi.c @ 5439779e
History | View | Annotate | Download (12.3 kB)
1 | a87295e8 | pbrook | /*
|
---|---|---|---|
2 | a87295e8 | pbrook | * m68k/ColdFire Semihosting syscall interface
|
3 | 5fafdf24 | ths | *
|
4 | a87295e8 | pbrook | * Copyright (c) 2005-2007 CodeSourcery.
|
5 | a87295e8 | pbrook | *
|
6 | a87295e8 | pbrook | * This program is free software; you can redistribute it and/or modify
|
7 | a87295e8 | pbrook | * it under the terms of the GNU General Public License as published by
|
8 | a87295e8 | pbrook | * the Free Software Foundation; either version 2 of the License, or
|
9 | a87295e8 | pbrook | * (at your option) any later version.
|
10 | a87295e8 | pbrook | *
|
11 | a87295e8 | pbrook | * This program is distributed in the hope that it will be useful,
|
12 | a87295e8 | pbrook | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | a87295e8 | pbrook | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | a87295e8 | pbrook | * GNU General Public License for more details.
|
15 | a87295e8 | pbrook | *
|
16 | a87295e8 | pbrook | * You should have received a copy of the GNU General Public License
|
17 | a87295e8 | pbrook | * along with this program; if not, write to the Free Software
|
18 | a87295e8 | pbrook | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
19 | a87295e8 | pbrook | */
|
20 | a87295e8 | pbrook | |
21 | a87295e8 | pbrook | #include <sys/types.h> |
22 | a87295e8 | pbrook | #include <sys/stat.h> |
23 | a87295e8 | pbrook | #include <errno.h> |
24 | a87295e8 | pbrook | #include <fcntl.h> |
25 | a87295e8 | pbrook | #include <unistd.h> |
26 | a87295e8 | pbrook | #include <stdlib.h> |
27 | a87295e8 | pbrook | #include <stdio.h> |
28 | a87295e8 | pbrook | #include <sys/time.h> |
29 | a87295e8 | pbrook | #include <time.h> |
30 | a87295e8 | pbrook | |
31 | a87295e8 | pbrook | #include "cpu.h" |
32 | a87295e8 | pbrook | #if defined(CONFIG_USER_ONLY)
|
33 | a87295e8 | pbrook | #include "qemu.h" |
34 | a87295e8 | pbrook | #define SEMIHOSTING_HEAP_SIZE (128 * 1024 * 1024) |
35 | a87295e8 | pbrook | #else
|
36 | 87ecb68b | pbrook | #include "qemu-common.h" |
37 | 87ecb68b | pbrook | #include "sysemu.h" |
38 | 87ecb68b | pbrook | #include "gdbstub.h" |
39 | a87295e8 | pbrook | #include "softmmu-semi.h" |
40 | a87295e8 | pbrook | #endif
|
41 | a87295e8 | pbrook | |
42 | a87295e8 | pbrook | #define HOSTED_EXIT 0 |
43 | a87295e8 | pbrook | #define HOSTED_INIT_SIM 1 |
44 | a87295e8 | pbrook | #define HOSTED_OPEN 2 |
45 | a87295e8 | pbrook | #define HOSTED_CLOSE 3 |
46 | a87295e8 | pbrook | #define HOSTED_READ 4 |
47 | a87295e8 | pbrook | #define HOSTED_WRITE 5 |
48 | a87295e8 | pbrook | #define HOSTED_LSEEK 6 |
49 | a87295e8 | pbrook | #define HOSTED_RENAME 7 |
50 | a87295e8 | pbrook | #define HOSTED_UNLINK 8 |
51 | a87295e8 | pbrook | #define HOSTED_STAT 9 |
52 | a87295e8 | pbrook | #define HOSTED_FSTAT 10 |
53 | a87295e8 | pbrook | #define HOSTED_GETTIMEOFDAY 11 |
54 | a87295e8 | pbrook | #define HOSTED_ISATTY 12 |
55 | a87295e8 | pbrook | #define HOSTED_SYSTEM 13 |
56 | a87295e8 | pbrook | |
57 | a87295e8 | pbrook | typedef uint32_t gdb_mode_t;
|
58 | a87295e8 | pbrook | typedef uint32_t gdb_time_t;
|
59 | a87295e8 | pbrook | |
60 | a87295e8 | pbrook | struct m68k_gdb_stat {
|
61 | a87295e8 | pbrook | uint32_t gdb_st_dev; /* device */
|
62 | a87295e8 | pbrook | uint32_t gdb_st_ino; /* inode */
|
63 | a87295e8 | pbrook | gdb_mode_t gdb_st_mode; /* protection */
|
64 | a87295e8 | pbrook | uint32_t gdb_st_nlink; /* number of hard links */
|
65 | a87295e8 | pbrook | uint32_t gdb_st_uid; /* user ID of owner */
|
66 | a87295e8 | pbrook | uint32_t gdb_st_gid; /* group ID of owner */
|
67 | a87295e8 | pbrook | uint32_t gdb_st_rdev; /* device type (if inode device) */
|
68 | a87295e8 | pbrook | uint64_t gdb_st_size; /* total size, in bytes */
|
69 | a87295e8 | pbrook | uint64_t gdb_st_blksize; /* blocksize for filesystem I/O */
|
70 | a87295e8 | pbrook | uint64_t gdb_st_blocks; /* number of blocks allocated */
|
71 | a87295e8 | pbrook | gdb_time_t gdb_st_atime; /* time of last access */
|
72 | a87295e8 | pbrook | gdb_time_t gdb_st_mtime; /* time of last modification */
|
73 | a87295e8 | pbrook | gdb_time_t gdb_st_ctime; /* time of last change */
|
74 | a87295e8 | pbrook | } __attribute__((packed)); |
75 | a87295e8 | pbrook | |
76 | a87295e8 | pbrook | struct gdb_timeval {
|
77 | a87295e8 | pbrook | gdb_time_t tv_sec; /* second */
|
78 | a87295e8 | pbrook | uint64_t tv_usec; /* microsecond */
|
79 | a87295e8 | pbrook | } __attribute__((packed)); |
80 | a87295e8 | pbrook | |
81 | a87295e8 | pbrook | #define GDB_O_RDONLY 0x0 |
82 | a87295e8 | pbrook | #define GDB_O_WRONLY 0x1 |
83 | a87295e8 | pbrook | #define GDB_O_RDWR 0x2 |
84 | a87295e8 | pbrook | #define GDB_O_APPEND 0x8 |
85 | a87295e8 | pbrook | #define GDB_O_CREAT 0x200 |
86 | a87295e8 | pbrook | #define GDB_O_TRUNC 0x400 |
87 | a87295e8 | pbrook | #define GDB_O_EXCL 0x800 |
88 | a87295e8 | pbrook | |
89 | a87295e8 | pbrook | static int translate_openflags(int flags) |
90 | a87295e8 | pbrook | { |
91 | a87295e8 | pbrook | int hf;
|
92 | a87295e8 | pbrook | |
93 | a87295e8 | pbrook | if (flags & GDB_O_WRONLY)
|
94 | a87295e8 | pbrook | hf = O_WRONLY; |
95 | a87295e8 | pbrook | else if (flags & GDB_O_RDWR) |
96 | a87295e8 | pbrook | hf = O_RDWR; |
97 | a87295e8 | pbrook | else
|
98 | a87295e8 | pbrook | hf = O_RDONLY; |
99 | a87295e8 | pbrook | |
100 | a87295e8 | pbrook | if (flags & GDB_O_APPEND) hf |= O_APPEND;
|
101 | a87295e8 | pbrook | if (flags & GDB_O_CREAT) hf |= O_CREAT;
|
102 | a87295e8 | pbrook | if (flags & GDB_O_TRUNC) hf |= O_TRUNC;
|
103 | a87295e8 | pbrook | if (flags & GDB_O_EXCL) hf |= O_EXCL;
|
104 | a87295e8 | pbrook | |
105 | a87295e8 | pbrook | return hf;
|
106 | a87295e8 | pbrook | } |
107 | a87295e8 | pbrook | |
108 | a87295e8 | pbrook | static void translate_stat(CPUState *env, target_ulong addr, struct stat *s) |
109 | a87295e8 | pbrook | { |
110 | a87295e8 | pbrook | struct m68k_gdb_stat *p;
|
111 | a87295e8 | pbrook | |
112 | 579a97f7 | bellard | if (!(p = lock_user(VERIFY_WRITE, addr, sizeof(struct m68k_gdb_stat), 0))) |
113 | 579a97f7 | bellard | /* FIXME - should this return an error code? */
|
114 | 579a97f7 | bellard | return;
|
115 | a87295e8 | pbrook | p->gdb_st_dev = cpu_to_be32(s->st_dev); |
116 | a87295e8 | pbrook | p->gdb_st_ino = cpu_to_be32(s->st_ino); |
117 | a87295e8 | pbrook | p->gdb_st_mode = cpu_to_be32(s->st_mode); |
118 | a87295e8 | pbrook | p->gdb_st_nlink = cpu_to_be32(s->st_nlink); |
119 | a87295e8 | pbrook | p->gdb_st_uid = cpu_to_be32(s->st_uid); |
120 | a87295e8 | pbrook | p->gdb_st_gid = cpu_to_be32(s->st_gid); |
121 | a87295e8 | pbrook | p->gdb_st_rdev = cpu_to_be32(s->st_rdev); |
122 | a87295e8 | pbrook | p->gdb_st_size = cpu_to_be64(s->st_size); |
123 | 29b3a662 | pbrook | #ifdef _WIN32
|
124 | 29b3a662 | pbrook | /* Windows stat is missing some fields. */
|
125 | 29b3a662 | pbrook | p->gdb_st_blksize = 0;
|
126 | 29b3a662 | pbrook | p->gdb_st_blocks = 0;
|
127 | 29b3a662 | pbrook | #else
|
128 | a87295e8 | pbrook | p->gdb_st_blksize = cpu_to_be64(s->st_blksize); |
129 | a87295e8 | pbrook | p->gdb_st_blocks = cpu_to_be64(s->st_blocks); |
130 | 29b3a662 | pbrook | #endif
|
131 | a87295e8 | pbrook | p->gdb_st_atime = cpu_to_be32(s->st_atime); |
132 | a87295e8 | pbrook | p->gdb_st_mtime = cpu_to_be32(s->st_mtime); |
133 | a87295e8 | pbrook | p->gdb_st_ctime = cpu_to_be32(s->st_ctime); |
134 | a87295e8 | pbrook | unlock_user(p, addr, sizeof(struct m68k_gdb_stat)); |
135 | a87295e8 | pbrook | } |
136 | a87295e8 | pbrook | |
137 | a87295e8 | pbrook | static int m68k_semi_is_fseek; |
138 | a87295e8 | pbrook | |
139 | a87295e8 | pbrook | static void m68k_semi_cb(CPUState *env, target_ulong ret, target_ulong err) |
140 | a87295e8 | pbrook | { |
141 | a87295e8 | pbrook | target_ulong args; |
142 | a87295e8 | pbrook | |
143 | a87295e8 | pbrook | args = env->dregs[1];
|
144 | a87295e8 | pbrook | if (m68k_semi_is_fseek) {
|
145 | a87295e8 | pbrook | /* FIXME: We've already lost the high bits of the fseek
|
146 | a87295e8 | pbrook | return value. */
|
147 | 2f619698 | bellard | /* FIXME - handle put_user() failure */
|
148 | 2f619698 | bellard | put_user_u32(0, args);
|
149 | a87295e8 | pbrook | args += 4;
|
150 | a87295e8 | pbrook | m68k_semi_is_fseek = 0;
|
151 | a87295e8 | pbrook | } |
152 | 2f619698 | bellard | /* FIXME - handle put_user() failure */
|
153 | 2f619698 | bellard | put_user_u32(ret, args); |
154 | 2f619698 | bellard | put_user_u32(errno, args + 4);
|
155 | a87295e8 | pbrook | } |
156 | a87295e8 | pbrook | |
157 | 2f619698 | bellard | #define ARG(n) \
|
158 | 2f619698 | bellard | ({ \ |
159 | 2f619698 | bellard | target_ulong __arg; \ |
160 | 2f619698 | bellard | /* FIXME - handle get_user() failure */ \
|
161 | 2f619698 | bellard | get_user_ual(__arg, args + (n) * 4); \
|
162 | 2f619698 | bellard | __arg; \ |
163 | 2f619698 | bellard | }) |
164 | a87295e8 | pbrook | #define PARG(x) ((unsigned long)ARG(x)) |
165 | a87295e8 | pbrook | void do_m68k_semihosting(CPUM68KState *env, int nr) |
166 | a87295e8 | pbrook | { |
167 | a87295e8 | pbrook | uint32_t args; |
168 | a87295e8 | pbrook | void *p;
|
169 | a87295e8 | pbrook | void *q;
|
170 | a87295e8 | pbrook | uint32_t len; |
171 | a87295e8 | pbrook | uint32_t result; |
172 | a87295e8 | pbrook | |
173 | a87295e8 | pbrook | args = env->dregs[1];
|
174 | a87295e8 | pbrook | switch (nr) {
|
175 | a87295e8 | pbrook | case HOSTED_EXIT:
|
176 | a87295e8 | pbrook | exit(env->dregs[0]);
|
177 | a87295e8 | pbrook | case HOSTED_OPEN:
|
178 | a87295e8 | pbrook | if (use_gdb_syscalls()) {
|
179 | a87295e8 | pbrook | gdb_do_syscall(m68k_semi_cb, "open,%s,%x,%x", ARG(0), (int)ARG(1), |
180 | a87295e8 | pbrook | ARG(2), ARG(3)); |
181 | a87295e8 | pbrook | return;
|
182 | a87295e8 | pbrook | } else {
|
183 | 579a97f7 | bellard | if (!(p = lock_user_string(ARG(0)))) { |
184 | 579a97f7 | bellard | /* FIXME - check error code? */
|
185 | 579a97f7 | bellard | result = -1;
|
186 | 579a97f7 | bellard | } else {
|
187 | 579a97f7 | bellard | result = open(p, translate_openflags(ARG(2)), ARG(3)); |
188 | 579a97f7 | bellard | unlock_user(p, ARG(0), 0); |
189 | 579a97f7 | bellard | } |
190 | a87295e8 | pbrook | } |
191 | a87295e8 | pbrook | break;
|
192 | a87295e8 | pbrook | case HOSTED_CLOSE:
|
193 | a87295e8 | pbrook | { |
194 | a87295e8 | pbrook | /* Ignore attempts to close stdin/out/err. */
|
195 | a87295e8 | pbrook | int fd = ARG(0); |
196 | a87295e8 | pbrook | if (fd > 2) { |
197 | a87295e8 | pbrook | if (use_gdb_syscalls()) {
|
198 | a87295e8 | pbrook | gdb_do_syscall(m68k_semi_cb, "close,%x", ARG(0)); |
199 | a87295e8 | pbrook | return;
|
200 | a87295e8 | pbrook | } else {
|
201 | a87295e8 | pbrook | result = close(fd); |
202 | a87295e8 | pbrook | } |
203 | a87295e8 | pbrook | } else {
|
204 | a87295e8 | pbrook | result = 0;
|
205 | a87295e8 | pbrook | } |
206 | a87295e8 | pbrook | break;
|
207 | a87295e8 | pbrook | } |
208 | a87295e8 | pbrook | case HOSTED_READ:
|
209 | a87295e8 | pbrook | len = ARG(2);
|
210 | a87295e8 | pbrook | if (use_gdb_syscalls()) {
|
211 | a87295e8 | pbrook | gdb_do_syscall(m68k_semi_cb, "read,%x,%x,%x",
|
212 | a87295e8 | pbrook | ARG(0), ARG(1), len); |
213 | a87295e8 | pbrook | return;
|
214 | a87295e8 | pbrook | } else {
|
215 | 579a97f7 | bellard | if (!(p = lock_user(VERIFY_WRITE, ARG(1), len, 0))) { |
216 | 579a97f7 | bellard | /* FIXME - check error code? */
|
217 | 579a97f7 | bellard | result = -1;
|
218 | 579a97f7 | bellard | } else {
|
219 | 579a97f7 | bellard | result = read(ARG(0), p, len);
|
220 | 579a97f7 | bellard | unlock_user(p, ARG(1), len);
|
221 | 579a97f7 | bellard | } |
222 | a87295e8 | pbrook | } |
223 | a87295e8 | pbrook | break;
|
224 | a87295e8 | pbrook | case HOSTED_WRITE:
|
225 | a87295e8 | pbrook | len = ARG(2);
|
226 | a87295e8 | pbrook | if (use_gdb_syscalls()) {
|
227 | a87295e8 | pbrook | gdb_do_syscall(m68k_semi_cb, "write,%x,%x,%x",
|
228 | a87295e8 | pbrook | ARG(0), ARG(1), len); |
229 | a87295e8 | pbrook | return;
|
230 | a87295e8 | pbrook | } else {
|
231 | 579a97f7 | bellard | if (!(p = lock_user(VERIFY_READ, ARG(1), len, 1))) { |
232 | 579a97f7 | bellard | /* FIXME - check error code? */
|
233 | 579a97f7 | bellard | result = -1;
|
234 | 579a97f7 | bellard | } else {
|
235 | 579a97f7 | bellard | result = write(ARG(0), p, len);
|
236 | 579a97f7 | bellard | unlock_user(p, ARG(0), 0); |
237 | 579a97f7 | bellard | } |
238 | a87295e8 | pbrook | } |
239 | a87295e8 | pbrook | break;
|
240 | a87295e8 | pbrook | case HOSTED_LSEEK:
|
241 | a87295e8 | pbrook | { |
242 | a87295e8 | pbrook | uint64_t off; |
243 | a87295e8 | pbrook | off = (uint32_t)ARG(2) | ((uint64_t)ARG(1) << 32); |
244 | a87295e8 | pbrook | if (use_gdb_syscalls()) {
|
245 | a87295e8 | pbrook | m68k_semi_is_fseek = 1;
|
246 | a87295e8 | pbrook | gdb_do_syscall(m68k_semi_cb, "fseek,%x,%lx,%x",
|
247 | a87295e8 | pbrook | ARG(0), off, ARG(3)); |
248 | a87295e8 | pbrook | } else {
|
249 | a87295e8 | pbrook | off = lseek(ARG(0), off, ARG(3)); |
250 | 2f619698 | bellard | /* FIXME - handle put_user() failure */
|
251 | 2f619698 | bellard | put_user_u32(off >> 32, args);
|
252 | 2f619698 | bellard | put_user_u32(off, args + 4);
|
253 | 2f619698 | bellard | put_user_u32(errno, args + 8);
|
254 | a87295e8 | pbrook | } |
255 | a87295e8 | pbrook | return;
|
256 | a87295e8 | pbrook | } |
257 | a87295e8 | pbrook | case HOSTED_RENAME:
|
258 | a87295e8 | pbrook | if (use_gdb_syscalls()) {
|
259 | 5fafdf24 | ths | gdb_do_syscall(m68k_semi_cb, "rename,%s,%s",
|
260 | a87295e8 | pbrook | ARG(0), (int)ARG(1), ARG(2), (int)ARG(3)); |
261 | a87295e8 | pbrook | return;
|
262 | a87295e8 | pbrook | } else {
|
263 | a87295e8 | pbrook | p = lock_user_string(ARG(0));
|
264 | a87295e8 | pbrook | q = lock_user_string(ARG(2));
|
265 | 579a97f7 | bellard | if (!p || !q) {
|
266 | 579a97f7 | bellard | /* FIXME - check error code? */
|
267 | 579a97f7 | bellard | result = -1;
|
268 | 579a97f7 | bellard | } else {
|
269 | 579a97f7 | bellard | result = rename(p, q); |
270 | 579a97f7 | bellard | } |
271 | a87295e8 | pbrook | unlock_user(p, ARG(0), 0); |
272 | a87295e8 | pbrook | unlock_user(q, ARG(2), 0); |
273 | a87295e8 | pbrook | } |
274 | a87295e8 | pbrook | break;
|
275 | a87295e8 | pbrook | case HOSTED_UNLINK:
|
276 | a87295e8 | pbrook | if (use_gdb_syscalls()) {
|
277 | a87295e8 | pbrook | gdb_do_syscall(m68k_semi_cb, "unlink,%s",
|
278 | a87295e8 | pbrook | ARG(0), (int)ARG(1)); |
279 | a87295e8 | pbrook | return;
|
280 | a87295e8 | pbrook | } else {
|
281 | 579a97f7 | bellard | if (!(p = lock_user_string(ARG(0)))) { |
282 | 579a97f7 | bellard | /* FIXME - check error code? */
|
283 | 579a97f7 | bellard | result = -1;
|
284 | 579a97f7 | bellard | } else {
|
285 | 579a97f7 | bellard | result = unlink(p); |
286 | 579a97f7 | bellard | unlock_user(p, ARG(0), 0); |
287 | 579a97f7 | bellard | } |
288 | a87295e8 | pbrook | } |
289 | a87295e8 | pbrook | break;
|
290 | a87295e8 | pbrook | case HOSTED_STAT:
|
291 | a87295e8 | pbrook | if (use_gdb_syscalls()) {
|
292 | a87295e8 | pbrook | gdb_do_syscall(m68k_semi_cb, "stat,%s,%x",
|
293 | a87295e8 | pbrook | ARG(0), (int)ARG(1), ARG(2)); |
294 | a87295e8 | pbrook | return;
|
295 | a87295e8 | pbrook | } else {
|
296 | a87295e8 | pbrook | struct stat s;
|
297 | 579a97f7 | bellard | if (!(p = lock_user_string(ARG(0)))) { |
298 | 579a97f7 | bellard | /* FIXME - check error code? */
|
299 | 579a97f7 | bellard | result = -1;
|
300 | 579a97f7 | bellard | } else {
|
301 | 579a97f7 | bellard | result = stat(p, &s); |
302 | 579a97f7 | bellard | unlock_user(p, ARG(0), 0); |
303 | 579a97f7 | bellard | } |
304 | a87295e8 | pbrook | if (result == 0) { |
305 | a87295e8 | pbrook | translate_stat(env, ARG(2), &s);
|
306 | a87295e8 | pbrook | } |
307 | a87295e8 | pbrook | } |
308 | a87295e8 | pbrook | break;
|
309 | a87295e8 | pbrook | case HOSTED_FSTAT:
|
310 | a87295e8 | pbrook | if (use_gdb_syscalls()) {
|
311 | a87295e8 | pbrook | gdb_do_syscall(m68k_semi_cb, "fstat,%x,%x",
|
312 | a87295e8 | pbrook | ARG(0), ARG(1)); |
313 | a87295e8 | pbrook | return;
|
314 | a87295e8 | pbrook | } else {
|
315 | a87295e8 | pbrook | struct stat s;
|
316 | a87295e8 | pbrook | result = fstat(ARG(0), &s);
|
317 | a87295e8 | pbrook | if (result == 0) { |
318 | a87295e8 | pbrook | translate_stat(env, ARG(1), &s);
|
319 | a87295e8 | pbrook | } |
320 | a87295e8 | pbrook | } |
321 | a87295e8 | pbrook | break;
|
322 | a87295e8 | pbrook | case HOSTED_GETTIMEOFDAY:
|
323 | a87295e8 | pbrook | if (use_gdb_syscalls()) {
|
324 | a87295e8 | pbrook | gdb_do_syscall(m68k_semi_cb, "gettimeofday,%x,%x",
|
325 | a87295e8 | pbrook | ARG(0), ARG(1)); |
326 | a87295e8 | pbrook | return;
|
327 | a87295e8 | pbrook | } else {
|
328 | 29b3a662 | pbrook | qemu_timeval tv; |
329 | a87295e8 | pbrook | struct gdb_timeval *p;
|
330 | 29b3a662 | pbrook | result = qemu_gettimeofday(&tv); |
331 | a87295e8 | pbrook | if (result != 0) { |
332 | 579a97f7 | bellard | if (!(p = lock_user(VERIFY_WRITE,
|
333 | 579a97f7 | bellard | ARG(0), sizeof(struct gdb_timeval), 0))) { |
334 | 579a97f7 | bellard | /* FIXME - check error code? */
|
335 | 579a97f7 | bellard | result = -1;
|
336 | 579a97f7 | bellard | } else {
|
337 | 579a97f7 | bellard | p->tv_sec = cpu_to_be32(tv.tv_sec); |
338 | 579a97f7 | bellard | p->tv_usec = cpu_to_be64(tv.tv_usec); |
339 | 579a97f7 | bellard | unlock_user(p, ARG(0), sizeof(struct gdb_timeval)); |
340 | 579a97f7 | bellard | } |
341 | a87295e8 | pbrook | } |
342 | a87295e8 | pbrook | } |
343 | a87295e8 | pbrook | break;
|
344 | a87295e8 | pbrook | case HOSTED_ISATTY:
|
345 | a87295e8 | pbrook | if (use_gdb_syscalls()) {
|
346 | a87295e8 | pbrook | gdb_do_syscall(m68k_semi_cb, "isatty,%x", ARG(0)); |
347 | a87295e8 | pbrook | return;
|
348 | a87295e8 | pbrook | } else {
|
349 | a87295e8 | pbrook | result = isatty(ARG(0));
|
350 | a87295e8 | pbrook | } |
351 | a87295e8 | pbrook | break;
|
352 | a87295e8 | pbrook | case HOSTED_SYSTEM:
|
353 | a87295e8 | pbrook | if (use_gdb_syscalls()) {
|
354 | a87295e8 | pbrook | gdb_do_syscall(m68k_semi_cb, "system,%s",
|
355 | a87295e8 | pbrook | ARG(0), (int)ARG(1)); |
356 | a87295e8 | pbrook | return;
|
357 | a87295e8 | pbrook | } else {
|
358 | 579a97f7 | bellard | if (!(p = lock_user_string(ARG(0)))) { |
359 | 579a97f7 | bellard | /* FIXME - check error code? */
|
360 | 579a97f7 | bellard | result = -1;
|
361 | 579a97f7 | bellard | } else {
|
362 | 579a97f7 | bellard | result = system(p); |
363 | 579a97f7 | bellard | unlock_user(p, ARG(0), 0); |
364 | 579a97f7 | bellard | } |
365 | a87295e8 | pbrook | } |
366 | a87295e8 | pbrook | break;
|
367 | a87295e8 | pbrook | case HOSTED_INIT_SIM:
|
368 | a87295e8 | pbrook | #if defined(CONFIG_USER_ONLY)
|
369 | a87295e8 | pbrook | { |
370 | a87295e8 | pbrook | TaskState *ts = env->opaque; |
371 | a87295e8 | pbrook | /* Allocate the heap using sbrk. */
|
372 | a87295e8 | pbrook | if (!ts->heap_limit) {
|
373 | a87295e8 | pbrook | long ret;
|
374 | a87295e8 | pbrook | uint32_t size; |
375 | a87295e8 | pbrook | uint32_t base; |
376 | a87295e8 | pbrook | |
377 | a87295e8 | pbrook | base = do_brk(0);
|
378 | a87295e8 | pbrook | size = SEMIHOSTING_HEAP_SIZE; |
379 | a87295e8 | pbrook | /* Try a big heap, and reduce the size if that fails. */
|
380 | a87295e8 | pbrook | for (;;) {
|
381 | a87295e8 | pbrook | ret = do_brk(base + size); |
382 | a87295e8 | pbrook | if (ret != -1) |
383 | a87295e8 | pbrook | break;
|
384 | a87295e8 | pbrook | size >>= 1;
|
385 | a87295e8 | pbrook | } |
386 | a87295e8 | pbrook | ts->heap_limit = base + size; |
387 | a87295e8 | pbrook | } |
388 | a87295e8 | pbrook | /* This call may happen before we have writable memory, so return
|
389 | a87295e8 | pbrook | values directly in registers. */
|
390 | a87295e8 | pbrook | env->dregs[1] = ts->heap_limit;
|
391 | a87295e8 | pbrook | env->aregs[7] = ts->stack_base;
|
392 | a87295e8 | pbrook | } |
393 | a87295e8 | pbrook | #else
|
394 | a87295e8 | pbrook | /* FIXME: This is wrong for boards where RAM does not start at
|
395 | a87295e8 | pbrook | address zero. */
|
396 | a87295e8 | pbrook | env->dregs[1] = ram_size;
|
397 | a87295e8 | pbrook | env->aregs[7] = ram_size;
|
398 | a87295e8 | pbrook | #endif
|
399 | a87295e8 | pbrook | return;
|
400 | a87295e8 | pbrook | default:
|
401 | a87295e8 | pbrook | cpu_abort(env, "Unsupported semihosting syscall %d\n", nr);
|
402 | a87295e8 | pbrook | result = 0;
|
403 | a87295e8 | pbrook | } |
404 | 2f619698 | bellard | /* FIXME - handle put_user() failure */
|
405 | 2f619698 | bellard | put_user_u32(result, args); |
406 | 2f619698 | bellard | put_user_u32(errno, args + 4);
|
407 | a87295e8 | pbrook | } |