Lines Matching +full:cs +full:- +full:2

3  *  semihosting syscalls design. This includes Arm and RISC-V processors
10 * Adapted for systems other than ARM, including RISC-V, by Keith Packard
14 * the Free Software Foundation; either version 2 of the License, or
27 * https://github.com/ARM-software/abi-aa/blob/main/semihosting/semihosting.rst
29 * RISC-V Semihosting is documented in:
30 * RISC-V Semihosting
31 * https://github.com/riscv/riscv-semihosting-spec/blob/main/riscv-semihosting-spec.adoc
40 #include "semihosting/common-semi.h"
130 if (!mr->ram || mr->readonly) { in find_ram_cb()
134 if (size > info->ramsize) { in find_ram_cb()
135 info->rambase = int128_get64(start); in find_ram_cb()
136 info->ramsize = size; in find_ram_cb()
143 static LayoutInfo common_semi_find_bases(CPUState *cs) in common_semi_find_bases() argument
150 fv = address_space_to_flatview(cs->as); in common_semi_find_bases()
169 #include "common-semi-target.h"
179 * error indication (0 on success, non-0 for error) which the caller
202 * The semihosting API has no concept of its errno being thread-safe,
204 * real-hardware set of debug functionality. For QEMU, we make the
205 * errno be per-thread in linux-user mode; in system-mode it is a simple
214 static inline uint32_t get_swi_errno(CPUState *cs) in get_swi_errno() argument
217 TaskState *ts = get_task_state(cs); in get_swi_errno()
219 return ts->swi_errno; in get_swi_errno()
225 static void common_semi_cb(CPUState *cs, uint64_t ret, int err) in common_semi_cb() argument
229 TaskState *ts = get_task_state(cs); in common_semi_cb()
230 ts->swi_errno = err; in common_semi_cb()
235 common_semi_set_ret(cs, ret); in common_semi_cb()
242 static void common_semi_dead_cb(CPUState *cs, uint64_t ret, int err) in common_semi_dead_cb() argument
244 common_semi_set_ret(cs, 0xdeadbeef); in common_semi_dead_cb()
251 static void common_semi_rw_cb(CPUState *cs, uint64_t ret, int err) in common_semi_rw_cb() argument
254 CPUArchState *env G_GNUC_UNUSED = cpu_env(cs); in common_semi_rw_cb()
255 target_ulong args = common_semi_arg(cs, 1); in common_semi_rw_cb()
257 GET_ARG(2); in common_semi_rw_cb()
263 common_semi_set_ret(cs, arg2 - ret); in common_semi_rw_cb()
270 static void common_semi_istty_cb(CPUState *cs, uint64_t ret, int err) in common_semi_istty_cb() argument
273 ret = (err == ENOTTY ? 0 : -1); in common_semi_istty_cb()
275 common_semi_cb(cs, ret, err); in common_semi_istty_cb()
281 static void common_semi_seek_cb(CPUState *cs, uint64_t ret, int err) in common_semi_seek_cb() argument
286 common_semi_cb(cs, ret, err); in common_semi_seek_cb()
292 * is defined by GDB's remote protocol and is not target-specific.)
295 static target_ulong common_semi_flen_buf(CPUState *cs) in common_semi_flen_buf() argument
297 target_ulong sp = common_semi_stack_bottom(cs); in common_semi_flen_buf()
298 return sp - 64; in common_semi_flen_buf()
302 common_semi_flen_fstat_cb(CPUState *cs, uint64_t ret, int err) in common_semi_flen_fstat_cb() argument
305 /* The size is always stored in big-endian order, extract the value. */ in common_semi_flen_fstat_cb()
307 if (cpu_memory_rw_debug(cs, common_semi_flen_buf(cs) + in common_semi_flen_fstat_cb()
310 ret = -1, err = EFAULT; in common_semi_flen_fstat_cb()
314 ret = -1, err = EOVERFLOW; in common_semi_flen_fstat_cb()
318 common_semi_cb(cs, ret, err); in common_semi_flen_fstat_cb()
322 common_semi_readc_cb(CPUState *cs, uint64_t ret, int err) in common_semi_readc_cb() argument
325 CPUArchState *env G_GNUC_UNUSED = cpu_env(cs); in common_semi_readc_cb()
328 if (get_user_u8(ch, common_semi_stack_bottom(cs) - 1)) { in common_semi_readc_cb()
329 ret = -1, err = EFAULT; in common_semi_readc_cb()
334 common_semi_cb(cs, ret, err); in common_semi_readc_cb()
362 void do_common_semihosting(CPUState *cs) in do_common_semihosting() argument
364 CPUArchState *env = cpu_env(cs); in do_common_semihosting()
372 nr = common_semi_arg(cs, 0) & 0xffffffffU; in do_common_semihosting()
373 args = common_semi_arg(cs, 1); in do_common_semihosting()
383 GET_ARG(2); in do_common_semihosting()
390 common_semi_cb(cs, -1, EINVAL); in do_common_semihosting()
410 } else if (strcmp(s, ":semihosting-features") == 0) { in do_common_semihosting()
413 ret = -1; in do_common_semihosting()
422 semihost_sys_open(cs, common_semi_cb, arg0, arg2 + 1, in do_common_semihosting()
427 common_semi_cb(cs, ret, err); in do_common_semihosting()
433 semihost_sys_close(cs, common_semi_cb, arg0); in do_common_semihosting()
439 * which means this is wrong for a big-endian guest. in do_common_semihosting()
441 semihost_sys_write_gf(cs, common_semi_dead_cb, in do_common_semihosting()
449 common_semi_dead_cb(cs, -1, EFAULT); in do_common_semihosting()
451 semihost_sys_write_gf(cs, common_semi_dead_cb, in do_common_semihosting()
460 GET_ARG(2); in do_common_semihosting()
461 semihost_sys_write(cs, common_semi_rw_cb, arg0, arg1, arg2); in do_common_semihosting()
467 GET_ARG(2); in do_common_semihosting()
468 semihost_sys_read(cs, common_semi_rw_cb, arg0, arg1, arg2); in do_common_semihosting()
472 semihost_sys_read_gf(cs, common_semi_readc_cb, &console_in_gf, in do_common_semihosting()
473 common_semi_stack_bottom(cs) - 1, 1); in do_common_semihosting()
478 common_semi_set_ret(cs, (target_long)arg0 < 0); in do_common_semihosting()
483 semihost_sys_isatty(cs, common_semi_istty_cb, arg0); in do_common_semihosting()
489 semihost_sys_lseek(cs, common_semi_seek_cb, arg0, arg1, GDB_SEEK_SET); in do_common_semihosting()
494 semihost_sys_flen(cs, common_semi_flen_fstat_cb, common_semi_cb, in do_common_semihosting()
495 arg0, common_semi_flen_buf(cs)); in do_common_semihosting()
505 GET_ARG(2); in do_common_semihosting()
506 len = asprintf(&s, "%s/qemu-%x%02x", g_get_tmp_dir(), in do_common_semihosting()
509 common_semi_set_ret(cs, -1); in do_common_semihosting()
518 common_semi_set_ret(cs, -1); in do_common_semihosting()
529 common_semi_set_ret(cs, 0); in do_common_semihosting()
536 semihost_sys_remove(cs, common_semi_cb, arg0, arg1 + 1); in do_common_semihosting()
542 GET_ARG(2); in do_common_semihosting()
544 semihost_sys_rename(cs, common_semi_cb, arg0, arg1 + 1, arg2, arg3 + 1); in do_common_semihosting()
548 common_semi_set_ret(cs, clock() / (CLOCKS_PER_SEC / 100)); in do_common_semihosting()
553 common_semi_cb(cs, ul_ret, ul_ret == -1 ? errno : 0); in do_common_semihosting()
559 semihost_sys_system(cs, common_semi_cb, arg0, arg1 + 1); in do_common_semihosting()
563 common_semi_set_ret(cs, get_swi_errno(cs)); in do_common_semihosting()
568 /* Build a command-line from the original argv. in do_common_semihosting()
577 * * arg0, pointer to null-terminated string of the in do_common_semihosting()
589 TaskState *ts = get_task_state(cs); in do_common_semihosting()
604 output_size = ts->info->env_strings - ts->info->arg_strings; in do_common_semihosting()
607 * We special-case the "empty command line" case (argc==0). in do_common_semihosting()
615 /* Not enough space to store command-line arguments. */ in do_common_semihosting()
616 common_semi_cb(cs, -1, E2BIG); in do_common_semihosting()
620 /* Adjust the command-line length. */ in do_common_semihosting()
621 if (SET_ARG(1, output_size - 1)) { in do_common_semihosting()
632 /* Copy the command-line arguments. */ in do_common_semihosting()
637 /* Empty command-line. */ in do_common_semihosting()
642 if (copy_from_user(output_buffer, ts->info->arg_strings, in do_common_semihosting()
649 for (i = 0; i < output_size - 1; i++) { in do_common_semihosting()
658 common_semi_cb(cs, status, 0); in do_common_semihosting()
667 TaskState *ts = get_task_state(cs); in do_common_semihosting()
670 LayoutInfo info = common_semi_find_bases(cs); in do_common_semihosting()
680 if (!ts->heap_limit) { in do_common_semihosting()
683 ts->heap_base = do_brk(0); in do_common_semihosting()
684 limit = ts->heap_base + COMMON_SEMI_HEAP_SIZE; in do_common_semihosting()
691 limit = (ts->heap_base >> 1) + (limit >> 1); in do_common_semihosting()
693 ts->heap_limit = limit; in do_common_semihosting()
696 retvals[0] = ts->heap_base; in do_common_semihosting()
697 retvals[1] = ts->heap_limit; in do_common_semihosting()
698 retvals[2] = ts->stack_base; in do_common_semihosting()
703 retvals[2] = info.heaplimit; /* Stack base */ in do_common_semihosting()
721 common_semi_set_ret(cs, 0); in do_common_semihosting()
730 if (common_semi_sys_exit_extended(cs, nr)) { in do_common_semihosting()
733 * so the application-exit type can return a subcode which in do_common_semihosting()
735 * SYS_EXIT_EXTENDED is an a new-in-v2.0 optional function in do_common_semihosting()
760 elapsed = get_clock() - clock_start; in do_common_semihosting()
771 common_semi_set_ret(cs, 0); in do_common_semihosting()
776 common_semi_set_ret(cs, 1000000000); in do_common_semihosting()
781 * Clean the D-cache and invalidate the I-cache for the specified in do_common_semihosting()
786 common_semi_set_ret(cs, 0); in do_common_semihosting()
792 cpu_dump_state(cs, stderr, 0); in do_common_semihosting()
796 common_semi_cb(cs, -1, EFAULT); in do_common_semihosting()