Comments (8)
We could provide something like this. I would feature-gate it since there's no "free real estate" to store it to. The place where this would be stored would also have to somehow be defined for this to work.
from riscv-rt.
Instead of specific behavior with an opt-in flag, could there be an optional hook for running code provided by another crate before the registers are reset? Are there constraints for code running this early? (For example, would it have to be assembly rather than Rust?)
from riscv-rt.
Never mind that last sentence, for this use case I’d need assembly anyway to access specific registers.
from riscv-rt.
Maybe we can pass all the a<n>
(or at least the first 3) register values to start_rust
and then to main
? This should be relatively cheap and universal (also compatible with multi-core hardware).
from riscv-rt.
This is a very elegant solution, but doesn’t this require carrying these values somewhere all the way through initialization code?
from riscv-rt.
An attempt at the "early hook" approach:
diff --git asm.S asm.S
index 910d359..0e7d7f8 100644
--- asm.S
+++ asm.S
@@ -42,7 +42,8 @@ _start:
.option pop
.endif
-_abs_start:
+.global _default_abs_start
+_default_abs_start:
.cfi_startproc
.cfi_undefined ra
diff --git link.x link.x
index e3b5ff4..93f2b8d 100644
--- link.x
+++ link.x
@@ -4,6 +4,7 @@ PROVIDE(_max_hart_id = 0);
PROVIDE(_hart_stack_size = 2K);
PROVIDE(_heap_size = 0);
+PROVIDE(_abs_start = _default_abs_start);
PROVIDE(UserSoft = DefaultHandler);
PROVIDE(SupervisorSoft = DefaultHandler);
PROVIDE(MachineSoft = DefaultHandler);
In the user crate:
extern "C" {
pub static DEVICE_TREE_PTR: *const u8;
}
core::arch::global_asm!(
r#"
.section init, "ax"
.global _abs_start
la t0, DEVICE_TREE_PTR
sw a1, 0(t0)
j _default_abs_start
.section data
.global DEVICE_TREE_PTR
DEVICE_TREE_PTR:
.4byte 0
"#
);
DEVICE_TREE_PTR
is not a Rust static because that would be overwritten by r0::init_data
.
But it looks like my symbol definitions in global_asm!
don’t work:
println!("{:p}", &device_tree::DEVICE_TREE_PTR as *const *const u8)
prints0x0
_start
jumps to_default_abs_start
, not my_abs_start
:
(gdb) break _start
Breakpoint 1 at 0x80000000: file asm.S, line 27.
(gdb) c
Continuing.
Breakpoint 1, _start () at asm.S:27
27 asm.S: No such file or directory.
(gdb) x/5i $pc
=> 0x80000000 <_start>: lui ra,0x80000
0x80000004 <_start+4>: jr 8(ra)
0x80000008 <_default_abs_start>: csrwi mie,0
0x8000000c <_default_abs_start+4>: csrwi mip,0
0x80000010 <_default_abs_start+8>: li ra,0
from riscv-rt.
This is a very elegant solution, but doesn’t this require carrying these values somewhere all the way through initialization code?
Yes, this will require additional code to save/restore registers, but I don't think that it will be a lot of code, especially for just 3 registers.
from riscv-rt.
An attempt at the "early hook" approach:
I’ve found the bug. Section names are .init
and .data
, not init
and data
😅
While passing arguments to main
would look nice, handling the different signatures seems like a headache. I’ve submitted #94
from riscv-rt.
Related Issues (20)
- Support for lld HOT 2
- Build on stable
- rust produces a 2.1G executable HOT 7
- build using -mcmodel = medany HOT 18
- Implement multi-core support
- Bizarre warning behavior around #[entry] macro and `&mut FnMut`
- LiteX/VexRiscv support HOT 4
- Execution start address varies. HOT 3
- Update r0 to 1.0 HOT 1
- Relocation R_RISCV_ALIGN linker error
- ELF output contains lots of zero data: linker script issue? HOT 4
- RAM init code violates pointer provenance and aliasing rules HOT 1
- Migration to GitHub Actions HOT 1
- sp may not be aligned to 16 bytes
- Lots of rust-lld errors HOT 3
- New crates.io release HOT 4
- Doesn't compile with the latest nightly toolchain. HOT 4
- Reimplement `r0`, since it is deprecated HOT 7
- asm: Startup code traps into an illegal instruction
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from riscv-rt.