diff options
author | Andrew Waterman <waterman@cs.berkeley.edu> | 2016-03-03 16:55:04 -0800 |
---|---|---|
committer | Andrew Waterman <waterman@cs.berkeley.edu> | 2016-03-03 16:55:04 -0800 |
commit | 82dcccf73c7be17415a7e84fc872c9627ee275fc (patch) | |
tree | 9856dcbda210fb378ed256d9b17dd4eb20717583 | |
parent | 3dd00b900cf087b0f39d2626c957b228cafed52a (diff) | |
download | pk-82dcccf73c7be17415a7e84fc872c9627ee275fc.zip pk-82dcccf73c7be17415a7e84fc872c9627ee275fc.tar.gz pk-82dcccf73c7be17415a7e84fc872c9627ee275fc.tar.bz2 |
Don't request KB interrupt til first call to sbi_console_getchar
-rw-r--r-- | pk/minit.c | 2 | ||||
-rw-r--r-- | pk/mtrap.c | 11 | ||||
-rw-r--r-- | pk/mtrap.h | 2 |
3 files changed, 6 insertions, 9 deletions
@@ -76,7 +76,6 @@ void hls_init(uint32_t id, csr_t* csrs) hls_t* hls = OTHER_HLS(id); memset(hls, 0, sizeof(*hls)); hls->csrs = csrs; - hls->console_ibuf = -1; } static void hart_init() @@ -99,7 +98,6 @@ void init_first_hart() memory_init(); vm_init(); - request_htif_keyboard_interrupt(); boot_loader(args); } @@ -85,7 +85,7 @@ static uintptr_t mcall_hart_id() return read_const_csr(mhartid); } -void request_htif_keyboard_interrupt() +static void request_htif_keyboard_interrupt() { uintptr_t old_tohost = swap_csr(mtohost, TOHOST_CMD(1, 0, 0)); kassert(old_tohost == 0); @@ -96,9 +96,8 @@ void htif_interrupt() // we should only be interrupted by keypresses uintptr_t fromhost = swap_csr(mfromhost, 0); kassert(FROMHOST_DEV(fromhost) == 1 && FROMHOST_CMD(fromhost) == 0); - HLS()->console_ibuf = (uint8_t)FROMHOST_DATA(fromhost); + HLS()->console_ibuf = 1 + (uint8_t)FROMHOST_DATA(fromhost); set_csr(mip, MIP_SSIP); - request_htif_keyboard_interrupt(); } static void do_tohost_fromhost(uintptr_t dev, uintptr_t cmd, uintptr_t data) @@ -166,15 +165,17 @@ static void reset_ssip() clear_csr(mip, MIP_SSIP); mb(); - if (HLS()->sipi_pending || HLS()->console_ibuf >= 0) + if (HLS()->sipi_pending || HLS()->console_ibuf > 0) set_csr(mip, MIP_SSIP); } static uintptr_t mcall_console_getchar() { int ch = atomic_swap(&HLS()->console_ibuf, -1); + if (ch >= 0) + request_htif_keyboard_interrupt(); reset_ssip(); - return ch; + return ch - 1; } static uintptr_t mcall_clear_ipi() @@ -179,8 +179,6 @@ typedef struct { #define IPI_FENCE_I 0x2 #define IPI_SFENCE_VM 0x4 -void request_htif_keyboard_interrupt(); - void hls_init(uint32_t hart_id, csr_t* csrs); #define MACHINE_STACK_TOP() ({ \ |