8000 New linker script and multi-core support by Disasm · Pull Request #31 · rust-embedded/riscv-rt · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Nov 28, 2023. It is now read-only.

New linker script and multi-core support #31

Merged
merged 26 commits into from
Jul 2, 2019
Merged

New linker script and multi-core support #31

merged 26 commits into from
Jul 2, 2019

Conversation

Disasm
Copy link
Member
@Disasm Disasm commented May 22, 2019
  • Linker script was reworked. Now it uses region aliases to relocate sections. This approach makes it possible to build firmware for both FLASH+RAM and RAM-only targets. Memory definitions now supposed to be present in their corresponding crates (e.g. RAM definition in PAC crate, FLASH definition in board support crate).
  • Multi-core support was introduced. Cores are parked with _mp_hook function and then awakened in platform-dependent way.
  • Documentation was updated to reflect new features.
  • New crate version: 0.6.0

Depends on: rust-embedded/riscv#28
Closes: #26

@Disasm Disasm requested a review from a team as a code owner May 22, 2019 21:56
@Disasm Disasm added S-blocked Status: marked as blocked ❌ on something else such as an RFC or other implementation work. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 22, 2019
@@ -71,6 +71,10 @@ _start:
// Set frame pointer
add s0, sp, zero

// Set trap handler
la t0, _start_trap
csrw mtvec, t0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beware that not all targets support Privileged Architecture CSRs.
I wanted to submit a PR gating the mtvec::write in src/lib.rs. It's not gonna be possible to conditionally compile an '.S'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it. Both riscv and riscv-rt depend on running with privileged support, so there is no easy way to support picorv32 and complex cores like FU540. Seems like it's better to have separate picorv32-rt library.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, makes sense. I'll just fork off this repo then after this PR lands

@@ -253,9 +250,6 @@ pub unsafe extern "C" fn start_rust() -> ! {

// TODO: Enable FPU when available

// Set mtvec to _start_trap
mtvec::write(&_start_trap as *const _ as usize, mtvec::TrapMode::Direct);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this single line allowed me to run Rust on https://github.com/cliffordwolf/picorv32.

@Disasm
Copy link
Member Author
Disasm commented May 26, 2019

@bradjc Could you review this?

@laanwj
Copy link
Contributor
laanwj commented Jun 3, 2019

Nice.

@Disasm
Copy link
Member Author
Disasm commented Jul 1, 2019

@laanwj Do you have any suggestions or we can merge it?

@Disasm Disasm removed the S-blocked Status: marked as blocked ❌ on something else such as an RFC or other implementation work. label Jul 1, 2019
@Disasm
Copy link
Member Author
Disasm commented Jul 1, 2019

bors try

bors bot added a commit that referenced this pull request Jul 1, 2019
@bors
Copy link
Contributor
bors bot commented Jul 1, 2019

try

Build failed

@laanwj
Copy link
Contributor
laanwj commented Jul 2, 2019

@laanwj Do you have any suggestions or we can merge it?

I haven't tried the code, but the changes look good to me. I made similar (but more hacky) changes to succesfully test multi-core on K210. Mainly: set the trap handler for all cores, then enable MIE and MSOFT so that the other core can be woken up using an IPI:

+    // Set trap handler
+    la t0, _start_trap
+    csrw mtvec, t0
+    // Enable software interrupts
+    csrs mstatus, 8
+    csrs mie, 8

Then to invoke the trap handler on the other core:

    writeln!(stdout, "Generate IPI for core 1 !").unwrap();
    unsafe {
        (*pac::CLINT::ptr()).msip[1].write(|w| w.bits(1));
    }

It looks like mp_hook would handle specific things such as enabling cross-core software interrupts, and parking the non-main cores until that.

So looks good for merge to me.

Copy link
Contributor
@laanwj laanwj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@laanwj laanwj mentioned this pull request Jul 2, 2019
@Disasm
Copy link
Member Author
Disasm commented Jul 2, 2019

@laanwj I thought about handling other cores with a trap handler, but refused to go this way. One of the reasons is that we should decide which core is the main one upon startup. I wanted to avoid this, because I know at least one case where choosing core 0 as the main one may not work: when you white a firmware for the RV64G cores on FU540. They are numbered 1..4, so you need a different way to choose this "main" core. Linux performs a "hart lottery" to choose it. However, this approach requires atomics, and I tried to avoid enforcing their presence.

@Disasm
Copy link
Member Author
Disasm commented Jul 2, 2019

bors r=laanwj
@laanwj Thank you for reviewing this!

bors bot added a commit that referenced this pull request Jul 2, 2019
31: New linker script and multi-core support r=laanwj a=Disasm

* Linker script was reworked. Now it uses region aliases to relocate sections. This approach makes it possible to build firmware for both FLASH+RAM and RAM-only targets. Memory definitions now supposed to be present in their corresponding crates (e.g. RAM definition in PAC crate, FLASH definition in board support crate).
* Multi-core support was introduced. Cores are parked with `_mp_hook` function and then awakened in platform-dependent way.
* Documentation was updated to reflect new features.
* New crate version: 0.6.0

Depends on: rust-embedded/riscv#28
Closes: #26

Co-authored-by: Vadim Kaushan <admin@disasm.info>
@bors
Copy link
Contributor
bors bot commented Jul 2, 2019

Build succeeded

@bors bors bot merged commit 9f118f1 into master Jul 2, 2019
@bors bors bot deleted the next branch July 2, 2019 09:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement multi-core support
3 participants
0