aboutsummaryrefslogtreecommitdiff
path: root/pk
diff options
context:
space:
mode:
authorAndrew Waterman <waterman@cs.berkeley.edu>2016-03-03 16:55:04 -0800
committerAndrew Waterman <waterman@cs.berkeley.edu>2016-03-03 16:55:04 -0800
commit82dcccf73c7be17415a7e84fc872c9627ee275fc (patch)
tree9856dcbda210fb378ed256d9b17dd4eb20717583 /pk
parent3dd00b900cf087b0f39d2626c957b228cafed52a (diff)
downloadriscv-pk-82dcccf73c7be17415a7e84fc872c9627ee275fc.zip
riscv-pk-82dcccf73c7be17415a7e84fc872c9627ee275fc.tar.gz
riscv-pk-82dcccf73c7be17415a7e84fc872c9627ee275fc.tar.bz2
Don't request KB interrupt til first call to sbi_console_getchar
Diffstat (limited to 'pk')
-rw-r--r--pk/minit.c2
-rw-r--r--pk/mtrap.c11
-rw-r--r--pk/mtrap.h2
3 files changed, 6 insertions, 9 deletions
diff --git a/pk/minit.c b/pk/minit.c
index bf151e8..741445b 100644
--- a/pk/minit.c
+++ b/pk/minit.c
@@ -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);
}
diff --git a/pk/mtrap.c b/pk/mtrap.c
index 4e45b80..a6a2fdb 100644
--- a/pk/mtrap.c
+++ b/pk/mtrap.c
@@ -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()
diff --git a/pk/mtrap.h b/pk/mtrap.h
index 5d2154f..7b2a181 100644
--- a/pk/mtrap.h
+++ b/pk/mtrap.h
@@ -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() ({ \