1
2
3
4
5
6
7
8
9
10
11
12
13#include "qemu/osdep.h"
14#include "semihosting/console.h"
15#include "qemu.h"
16#include "user-internals.h"
17#include <termios.h>
18
19
20
21
22
23
24
25
26int qemu_semihosting_console_read(CPUState *cs, void *buf, int len)
27{
28 int ret;
29 struct termios old_tio, new_tio;
30
31
32 tcgetattr(STDIN_FILENO, &old_tio);
33 new_tio = old_tio;
34 new_tio.c_lflag &= (~ICANON & ~ECHO);
35 new_tio.c_cc[VMIN] = 1;
36 new_tio.c_cc[VTIME] = 0;
37 tcsetattr(STDIN_FILENO, TCSANOW, &new_tio);
38
39 ret = fread(buf, 1, len, stdin);
40
41
42 tcsetattr(STDIN_FILENO, TCSANOW, &old_tio);
43
44 return ret;
45}
46
47int qemu_semihosting_console_write(void *buf, int len)
48{
49 return fwrite(buf, 1, len, stderr);
50}
51