16b5fe137SPhilippe Mathieu-Daudé /* 26b5fe137SPhilippe Mathieu-Daudé * Semihosting Console 36b5fe137SPhilippe Mathieu-Daudé * 46b5fe137SPhilippe Mathieu-Daudé * Copyright (c) 2019 Linaro Ltd 56b5fe137SPhilippe Mathieu-Daudé * 66b5fe137SPhilippe Mathieu-Daudé * SPDX-License-Identifier: GPL-2.0-or-later 76b5fe137SPhilippe Mathieu-Daudé */ 86b5fe137SPhilippe Mathieu-Daudé 96b5fe137SPhilippe Mathieu-Daudé #ifndef SEMIHOST_CONSOLE_H 106b5fe137SPhilippe Mathieu-Daudé #define SEMIHOST_CONSOLE_H 116b5fe137SPhilippe Mathieu-Daudé 126b5fe137SPhilippe Mathieu-Daudé #include "cpu.h" 136b5fe137SPhilippe Mathieu-Daudé 146b5fe137SPhilippe Mathieu-Daudé /** 15e7fb6f32SRichard Henderson * qemu_semihosting_console_read: 163367d452SRichard Henderson * @cs: CPUState 17e7fb6f32SRichard Henderson * @buf: host buffer 18e7fb6f32SRichard Henderson * @len: buffer size 196b5fe137SPhilippe Mathieu-Daudé * 20e7fb6f32SRichard Henderson * Receive at least one character from debug console. As this call may 21e7fb6f32SRichard Henderson * block if no data is available we suspend the CPU and will re-execute the 22675f702fSRichard Henderson * instruction when data is there. Therefore two conditions must be met: 23675f702fSRichard Henderson * 246b5fe137SPhilippe Mathieu-Daudé * - CPUState is synchronized before calling this function 256b5fe137SPhilippe Mathieu-Daudé * - pc is only updated once the character is successfully returned 266b5fe137SPhilippe Mathieu-Daudé * 27e7fb6f32SRichard Henderson * Returns: number of characters read, OR cpu_loop_exit! 286b5fe137SPhilippe Mathieu-Daudé */ 29e7fb6f32SRichard Henderson int qemu_semihosting_console_read(CPUState *cs, void *buf, int len); 306b5fe137SPhilippe Mathieu-Daudé 316b5fe137SPhilippe Mathieu-Daudé /** 32cd66f20fSRichard Henderson * qemu_semihosting_console_write: 33cd66f20fSRichard Henderson * @buf: host buffer 34cd66f20fSRichard Henderson * @len: buffer size 35cd66f20fSRichard Henderson * 36cd66f20fSRichard Henderson * Write len bytes from buf to the debug console. 37cd66f20fSRichard Henderson * 38cd66f20fSRichard Henderson * Returns: number of bytes written -- this should only ever be short 39cd66f20fSRichard Henderson * on some sort of i/o error. 40cd66f20fSRichard Henderson */ 41cd66f20fSRichard Henderson int qemu_semihosting_console_write(void *buf, int len); 42cd66f20fSRichard Henderson 431b9177f7SRichard Henderson /* 441b9177f7SRichard Henderson * qemu_semihosting_console_block_until_ready: 451b9177f7SRichard Henderson * @cs: CPUState 461b9177f7SRichard Henderson * 471b9177f7SRichard Henderson * If no data is available we suspend the CPU and will re-execute the 481b9177f7SRichard Henderson * instruction when data is available. 491b9177f7SRichard Henderson */ 501b9177f7SRichard Henderson void qemu_semihosting_console_block_until_ready(CPUState *cs); 511b9177f7SRichard Henderson 521b9177f7SRichard Henderson /** 531b9177f7SRichard Henderson * qemu_semihosting_console_ready: 541b9177f7SRichard Henderson * 551b9177f7SRichard Henderson * Return true if characters are available for read; does not block. 561b9177f7SRichard Henderson */ 571b9177f7SRichard Henderson bool qemu_semihosting_console_ready(void); 581b9177f7SRichard Henderson 596b5fe137SPhilippe Mathieu-Daudé #endif /* SEMIHOST_CONSOLE_H */ 60