2 * m68k/ColdFire Semihosting syscall interface
4 * Copyright (c) 2005-2007 CodeSourcery.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include "qemu/osdep.h"
23 #include "gdbstub/syscalls.h"
24 #include "gdbstub/helpers.h"
25 #include "semihosting/syscalls.h"
26 #include "semihosting/softmmu-uaccess.h"
27 #include "hw/boards.h"
31 #define HOSTED_INIT_SIM 1
33 #define HOSTED_CLOSE 3
35 #define HOSTED_WRITE 5
36 #define HOSTED_LSEEK 6
37 #define HOSTED_RENAME 7
38 #define HOSTED_UNLINK 8
40 #define HOSTED_FSTAT 10
41 #define HOSTED_GETTIMEOFDAY 11
42 #define HOSTED_ISATTY 12
43 #define HOSTED_SYSTEM 13
45 static int host_to_gdb_errno(int err
)
47 #define E(X) case E##X: return GDB_E##X
74 static void m68k_semi_u32_cb(CPUState
*cs
, uint64_t ret
, int err
)
76 M68kCPU
*cpu
= M68K_CPU(cs
);
77 CPUM68KState
*env
= &cpu
->env
;
79 target_ulong args
= env
->dregs
[1];
80 if (put_user_u32(ret
, args
) ||
81 put_user_u32(host_to_gdb_errno(err
), args
+ 4)) {
83 * The m68k semihosting ABI does not provide any way to report this
84 * error to the guest, so the best we can do is log it in qemu.
85 * It is always a guest error not to pass us a valid argument block.
87 qemu_log_mask(LOG_GUEST_ERROR
, "m68k-semihosting: return value "
88 "discarded because argument block not writable\n");
92 static void m68k_semi_u64_cb(CPUState
*cs
, uint64_t ret
, int err
)
94 M68kCPU
*cpu
= M68K_CPU(cs
);
95 CPUM68KState
*env
= &cpu
->env
;
97 target_ulong args
= env
->dregs
[1];
98 if (put_user_u32(ret
>> 32, args
) ||
99 put_user_u32(ret
, args
+ 4) ||
100 put_user_u32(host_to_gdb_errno(err
), args
+ 8)) {
101 /* No way to report this via m68k semihosting ABI; just log it */
102 qemu_log_mask(LOG_GUEST_ERROR
, "m68k-semihosting: return value "
103 "discarded because argument block not writable\n");
108 * Read the input value from the argument block; fail the semihosting
109 * call if the memory read fails.
111 #define GET_ARG(n) do { \
112 if (get_user_ual(arg ## n, args + (n) * 4)) { \
117 #define GET_ARG64(n) do { \
118 if (get_user_ual(arg ## n, args + (n) * 4)) { \
124 void do_m68k_semihosting(CPUM68KState
*env
, int nr
)
126 CPUState
*cs
= env_cpu(env
);
128 target_ulong arg0
, arg1
, arg2
, arg3
;
130 args
= env
->dregs
[1];
133 gdb_exit(env
->dregs
[0]);
141 semihost_sys_open(cs
, m68k_semi_u32_cb
, arg0
, arg1
, arg2
, arg3
);
146 semihost_sys_close(cs
, m68k_semi_u32_cb
, arg0
);
153 semihost_sys_read(cs
, m68k_semi_u32_cb
, arg0
, arg1
, arg2
);
160 semihost_sys_write(cs
, m68k_semi_u32_cb
, arg0
, arg1
, arg2
);
168 semihost_sys_lseek(cs
, m68k_semi_u64_cb
, arg0
,
169 deposit64(arg2
, arg1
, 32, 32), arg3
);
177 semihost_sys_rename(cs
, m68k_semi_u32_cb
, arg0
, arg1
, arg2
, arg3
);
183 semihost_sys_remove(cs
, m68k_semi_u32_cb
, arg0
, arg1
);
190 semihost_sys_stat(cs
, m68k_semi_u32_cb
, arg0
, arg1
, arg2
);
196 semihost_sys_fstat(cs
, m68k_semi_u32_cb
, arg0
, arg1
);
199 case HOSTED_GETTIMEOFDAY
:
202 semihost_sys_gettimeofday(cs
, m68k_semi_u32_cb
, arg0
, arg1
);
207 semihost_sys_isatty(cs
, m68k_semi_u32_cb
, arg0
);
213 semihost_sys_system(cs
, m68k_semi_u32_cb
, arg0
, arg1
);
216 case HOSTED_INIT_SIM
:
218 * FIXME: This is wrong for boards where RAM does not start at
221 env
->dregs
[1] = current_machine
->ram_size
;
222 env
->aregs
[7] = current_machine
->ram_size
;
226 cpu_abort(env_cpu(env
), "Unsupported semihosting syscall %d\n", nr
);
229 m68k_semi_u32_cb(cs
, -1, EFAULT
);
232 m68k_semi_u64_cb(cs
, -1, EFAULT
);