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 <termios.h>
17
18int qemu_semihosting_console_outs(CPUArchState *env, target_ulong addr)
19{
20 int len = target_strlen(addr);
21 void *s;
22 if (len < 0){
23 qemu_log_mask(LOG_GUEST_ERROR,
24 "%s: passed inaccessible address " TARGET_FMT_lx,
25 __func__, addr);
26 return 0;
27 }
28 s = lock_user(VERIFY_READ, addr, (long)(len + 1), 1);
29 g_assert(s);
30 len = write(STDERR_FILENO, s, len);
31 unlock_user(s, addr, 0);
32 return len;
33}
34
35void qemu_semihosting_console_outc(CPUArchState *env, target_ulong addr)
36{
37 char c;
38
39 if (get_user_u8(c, addr)) {
40 qemu_log_mask(LOG_GUEST_ERROR,
41 "%s: passed inaccessible address " TARGET_FMT_lx,
42 __func__, addr);
43 } else {
44 if (write(STDERR_FILENO, &c, 1) != 1) {
45 qemu_log_mask(LOG_UNIMP, "%s: unexpected write to stdout failure",
46 __func__);
47 }
48 }
49}
50
51
52
53
54
55
56
57
58target_ulong qemu_semihosting_console_inc(CPUArchState *env)
59{
60 uint8_t c;
61 struct termios old_tio, new_tio;
62
63
64 tcgetattr(STDIN_FILENO, &old_tio);
65 new_tio = old_tio;
66 new_tio.c_lflag &= (~ICANON & ~ECHO);
67 tcsetattr(STDIN_FILENO, TCSANOW, &new_tio);
68
69 c = getchar();
70
71
72 tcsetattr(STDIN_FILENO, TCSANOW, &old_tio);
73
74 return (target_ulong) c;
75}
76