-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preliminary SMP support #46
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ad8ead1
Preliminary allow PLIC to support 32 sources to 32 contexts
ranvd 392820c
Preliminary implement CLINT to multi-hart system
ranvd 2fc2cd4
Adapt Linux kernel configurations for SMP-awareness
ranvd 73dab78
Preliminary SMP support
ranvd 6669da7
Change argument for smp option setting
ranvd 7f0d5ba
Fix mmu-type error on device tree generation
ranvd 2d9d54f
Rename `scripts/dtsi-gen.py` to `scripts/gen-hart-dts.py`
ranvd d3c57d5
Rename `minimal.dtsi` to `riscv-harts.dtsi`
ranvd 03e0113
Replace "else if" with "if" in `clint.c`
ranvd 0d95894
Enhance comment informative
ranvd 9f3003c
Rename `hart_number` to `hart_count`
ranvd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,95 @@ | ||
#include <stdint.h> | ||
#include "device.h" | ||
#include "riscv.h" | ||
#include "riscv_private.h" | ||
|
||
void clint_update_interrupts(hart_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; | ||
} | ||
|
||
if (addr < 0xBFF8) { | ||
addr -= 0x4000; | ||
*value = | ||
(uint32_t) (clint->mtimecmp[addr >> 3] >> (32 & -!!(addr & 0b100))); | ||
return true; | ||
} | ||
|
||
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; | ||
} | ||
|
||
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; | ||
} | ||
|
||
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(hart_t *vm, | ||
clint_state_t *clint, | ||
uint32_t addr, | ||
uint8_t width, | ||
uint32_t *value) | ||
{ | ||
if (!clint_reg_read(clint, addr, value)) | ||
vm_set_exception(vm, RV_EXC_LOAD_FAULT, vm->exc_val); | ||
*value = (*value) >> (RV_MEM_SW - width); | ||
return; | ||
} | ||
|
||
void clint_write(hart_t *vm, | ||
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(vm, RV_EXC_STORE_FAULT, vm->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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specify
const
qualifier when possible. i.e.,const clint_state_t *clint
.