xref: /openbmc/qemu/include/semihosting/console.h (revision 4e245a9e)
1 /*
2  * Semihosting Console
3  *
4  * Copyright (c) 2019 Linaro Ltd
5  *
6  * SPDX-License-Identifier: GPL-2.0-or-later
7  */
8 
9 #ifndef SEMIHOST_CONSOLE_H
10 #define SEMIHOST_CONSOLE_H
11 
12 #include "cpu.h"
13 
14 /**
15  * qemu_semihosting_console_read:
16  * @cs: CPUState
17  * @buf: host buffer
18  * @len: buffer size
19  *
20  * Receive at least one character from debug console.  As this call may
21  * block if no data is available we suspend the CPU and will re-execute the
22  * instruction when data is there. Therefore two conditions must be met:
23  *
24  *   - CPUState is synchronized before calling this function
25  *   - pc is only updated once the character is successfully returned
26  *
27  * Returns: number of characters read, OR cpu_loop_exit!
28  */
29 int qemu_semihosting_console_read(CPUState *cs, void *buf, int len);
30 
31 /**
32  * qemu_semihosting_console_write:
33  * @buf: host buffer
34  * @len: buffer size
35  *
36  * Write len bytes from buf to the debug console.
37  *
38  * Returns: number of bytes written -- this should only ever be short
39  * on some sort of i/o error.
40  */
41 int qemu_semihosting_console_write(void *buf, int len);
42 
43 /**
44  * qemu_semihosting_log_out:
45  * @s: pointer to string
46  * @len: length of string
47  *
48  * Send a string to the debug output. Unlike console_out these strings
49  * can't be sent to a remote gdb instance as they don't exist in guest
50  * memory.
51  *
52  * Returns: number of bytes written
53  */
54 int qemu_semihosting_log_out(const char *s, int len);
55 
56 /*
57  * qemu_semihosting_console_block_until_ready:
58  * @cs: CPUState
59  *
60  * If no data is available we suspend the CPU and will re-execute the
61  * instruction when data is available.
62  */
63 void qemu_semihosting_console_block_until_ready(CPUState *cs);
64 
65 /**
66  * qemu_semihosting_console_ready:
67  *
68  * Return true if characters are available for read; does not block.
69  */
70 bool qemu_semihosting_console_ready(void);
71 
72 #endif /* SEMIHOST_CONSOLE_H */
73