-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuart.cc
42 lines (34 loc) · 898 Bytes
/
uart.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "local-include/uart.h"
#include <cstdlib>
// 预置的输入字符串
static const char *uart_input_ptr = " " // 占位空格字符
"busybox | head -n4\n"
"ls\n"
"./hello\n";
static inline bool input_available() {
return *uart_input_ptr != '\0';
}
// 0x1000表示mmio区域大小
UART::UART(paddr_t addr): Device(addr, 0x1000) { }
UART::~UART() { }
void UART::write(paddr_t addr, int len, word_t data) {
if (addr == 0) {
putchar(data & 0xff);
fflush(stdout);
}
}
word_t UART::read(paddr_t addr, int len) {
if (addr == 0) {
if (input_available()) {
return *uart_input_ptr++;
} else {
return 0xff;
}
} else if (addr == 5) {
return 0x60 | input_available();
}
return 0;
}
word_t UART::get_ip() {
return input_available();
}