-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preliminary implement CLINT to multi-hart system
Replace emu.timer with the CLINT device. This CLINT device preliminarily supports sending 4095 individual timer and software interrupts to different harts.
- Loading branch information
Showing
6 changed files
with
145 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ OBJS := \ | |
plic.o \ | ||
uart.o \ | ||
main.o \ | ||
clint.o \ | ||
$(OBJS_EXTRA) | ||
|
||
deps := $(OBJS:%.o=.%.o.d) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#include <stdint.h> | ||
#include "device.h" | ||
#include "riscv.h" | ||
#include "riscv_private.h" | ||
|
||
void clint_update_interrupts(vm_t *hart, clint_state_t *clint) | ||
{ | ||
if (clint->mtime > clint->mtimecmp[hart->mhartid]) | ||
hart->sip |= RV_INT_STI_BIT; | ||
else | ||
hart->sip &= ~RV_INT_STI_BIT; | ||
|
||
if (clint->msip[hart->mhartid]) { | ||
hart->sip |= RV_INT_SSI_BIT; | ||
} else | ||
hart->sip &= ~RV_INT_SSI_BIT; | ||
} | ||
|
||
static bool clint_reg_read(clint_state_t *clint, uint32_t addr, uint32_t *value) | ||
{ | ||
if (addr < 0x4000) { | ||
*value = clint->msip[addr >> 2]; | ||
return true; | ||
} else if (addr < 0xBFF8) { | ||
addr -= 0x4000; | ||
*value = | ||
(uint32_t) (clint->mtimecmp[addr >> 3] >> (32 & -!!(addr & 0b100))); | ||
return true; | ||
} else if (addr < 0xBFFF) { | ||
*value = clint->mtime >> (32 & -!!(addr & 0b100)); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
static bool clint_reg_write(clint_state_t *clint, uint32_t addr, uint32_t value) | ||
{ | ||
if (addr < 0x4000) { | ||
clint->msip[addr >> 2] = value; | ||
return true; | ||
} else if (addr < 0xBFF8) { | ||
addr -= 0x4000; | ||
int32_t upper = clint->mtimecmp[addr >> 3] >> 32; | ||
int32_t lowwer = clint->mtimecmp[addr >> 3]; | ||
if (addr & 0b100) | ||
upper = value; | ||
else | ||
lowwer = value; | ||
|
||
clint->mtimecmp[addr >> 3] = (uint64_t) upper << 32 | lowwer; | ||
return true; | ||
} else if (addr < 0xBFFF) { | ||
int32_t upper = clint->mtime >> 32; | ||
int32_t lowwer = clint->mtime; | ||
if (addr & 0b100) | ||
upper = value; | ||
else | ||
lowwer = value; | ||
|
||
clint->mtime = (uint64_t) upper << 32 | lowwer; | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
void clint_read(vm_t *hart, | ||
clint_state_t *clint, | ||
uint32_t addr, | ||
uint8_t width, | ||
uint32_t *value) | ||
{ | ||
if (!clint_reg_read(clint, addr, value)) | ||
vm_set_exception(hart, RV_EXC_LOAD_FAULT, hart->exc_val); | ||
*value = (*value) >> (RV_MEM_SW - width); | ||
return; | ||
} | ||
|
||
void clint_write(vm_t *hart, | ||
clint_state_t *clint, | ||
uint32_t addr, | ||
uint8_t width, | ||
uint32_t value) | ||
{ | ||
if (!clint_reg_write(clint, addr, value >> (RV_MEM_SW - width))) | ||
vm_set_exception(hart, RV_EXC_STORE_FAULT, hart->exc_val); | ||
return; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters