提交 80b2e870 编写于 作者: Z Zihao Yu

Merge branch 'rt-thread' into 'rv64'

Rt thread

See merge request projectn/nemu!13
......@@ -7,20 +7,51 @@
#define SERIAL_MMIO 0xa10003F8
#define CH_OFFSET 0
#define QUEUE_SIZE 1024
static char queue[QUEUE_SIZE] = {};
static int f = 0, r = 0;
static uint8_t *serial_ch_base = NULL;
static void serial_enqueue(char ch) {
int next = (r + 1) % QUEUE_SIZE;
if (next != f) {
// not full
queue[r] = ch;
r = next;
}
}
static void serial_ch_io_handler(uint32_t offset, int len, bool is_write) {
assert(offset == 0);
assert(is_write);
assert(len == 1);
char c = serial_ch_base[0];
/* We bind the serial port with the host stdout in NEMU. */
putc(c, stderr);
if (is_write) {
char c = serial_ch_base[0];
/* We bind the serial port with the host stdout in NEMU. */
putc(c, stderr);
} else {
if (f != r) {
serial_ch_base[0] = queue[f];
f = (f + 1) % QUEUE_SIZE;
} else {
serial_ch_base[0] = 0xff;
}
}
}
static void preset_input() {
char buf[128] = "memtrace\n";
int i;
for (i = 0; i < strlen(buf); i ++) {
serial_enqueue(buf[i]);
}
}
void init_serial() {
serial_ch_base = new_space(1);
add_pio_map("serial", SERIAL_PORT + CH_OFFSET, serial_ch_base, 1, serial_ch_io_handler);
add_mmio_map("serial", SERIAL_MMIO + CH_OFFSET, serial_ch_base, 1, serial_ch_io_handler);
preset_input();
}
......@@ -5,7 +5,7 @@
#define CSRS(f) \
f(mstatus , 0x300) f(mtvec , 0x305) f(mepc , 0x341) f(mcause , 0x342) \
f(mie , 0x304) f(satp , 0x180)
f(mie , 0x304) f(mhartid , 0xf14) f(satp , 0x180)
#define CSR_STRUCT_START(name) \
typedef union { \
......@@ -45,6 +45,9 @@ CSR_STRUCT_END(mcause)
CSR_STRUCT_START(mepc)
CSR_STRUCT_END(mepc)
CSR_STRUCT_START(mhartid)
CSR_STRUCT_END(mhartid)
CSR_STRUCT_START(mie)
uint64_t usie : 1;
uint64_t ssie : 1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册