diff options
author | Andrew Waterman <waterman@cs.berkeley.edu> | 2016-05-05 17:07:04 -0700 |
---|---|---|
committer | Andrew Waterman <waterman@cs.berkeley.edu> | 2016-05-05 17:07:04 -0700 |
commit | 1bcab7872c6ae98ab86cdc1a3f567fd263e723d7 (patch) | |
tree | 064c07519643d791b76d2fc2a6157eef15df28e0 /machine | |
parent | 552bc9bf1b09dc33a38d01a9027862ee681072e4 (diff) | |
download | riscv-pk-1bcab7872c6ae98ab86cdc1a3f567fd263e723d7.zip riscv-pk-1bcab7872c6ae98ab86cdc1a3f567fd263e723d7.tar.gz riscv-pk-1bcab7872c6ae98ab86cdc1a3f567fd263e723d7.tar.bz2 |
Poll HTIF console on timer interrupt
Diffstat (limited to 'machine')
-rw-r--r-- | machine/mentry.S | 11 | ||||
-rw-r--r-- | machine/mtrap.c | 17 |
2 files changed, 20 insertions, 8 deletions
diff --git a/machine/mentry.S b/machine/mentry.S index 4895227..6bdc7e6 100644 --- a/machine/mentry.S +++ b/machine/mentry.S @@ -20,7 +20,9 @@ trap_table: .word bad_trap #define SOFTWARE_INTERRUPT_VECTOR 12 .word software_interrupt -#define TRAP_FROM_MACHINE_MODE_VECTOR 13 +#define TIMER_INTERRUPT_VECTOR 13 + .word timer_interrupt +#define TRAP_FROM_MACHINE_MODE_VECTOR 14 .word __trap_from_machine_mode .option norvc @@ -49,11 +51,8 @@ trap_vector: # Is it a machine timer interrupt? li a0, IRQ_M_TIMER * 2 bne a0, a1, 1f - # Yes. Post a supervisor timer interrupt. - li a0, MIP_MTIP - csrc mie, a0 - li a0, MIP_STIP - csrs mip, a0 + li a1, TIMER_INTERRUPT_VECTOR + j .Lhandle_trap_in_machine_mode .Lmret: # Go back whence we came. diff --git a/machine/mtrap.c b/machine/mtrap.c index 5c835cb..9560948 100644 --- a/machine/mtrap.c +++ b/machine/mtrap.c @@ -30,6 +30,8 @@ static void htif_interrupt() { // we should only be interrupted by keypresses uint64_t fh = fromhost; + if (!fh) + return; if (!(FROMHOST_DEV(fh) == 1 && FROMHOST_CMD(fh) == 0)) die("unexpected htif interrupt"); HLS()->console_ibuf = 1 + (uint8_t)FROMHOST_DATA(fh); @@ -40,8 +42,7 @@ static void htif_interrupt() static void do_tohost_fromhost(uintptr_t dev, uintptr_t cmd, uintptr_t data) { while (tohost) - if (fromhost) - htif_interrupt(); + htif_interrupt(); tohost = TOHOST_CMD(dev, cmd, data); while (1) { @@ -56,6 +57,18 @@ static void do_tohost_fromhost(uintptr_t dev, uintptr_t cmd, uintptr_t data) } } +uintptr_t timer_interrupt() +{ + // just send the timer interrupt to the supervisor + clear_csr(mie, MIP_MTIP); + set_csr(mip, MIP_STIP); + + // and poll the HTIF console + htif_interrupt(); + + return 0; +} + static uintptr_t mcall_console_putchar(uint8_t ch) { do_tohost_fromhost(1, 1, ch); |