Giter VIP home page Giter VIP logo

Comments (8)

almindor avatar almindor commented on August 27, 2024

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.

SimonSapin avatar SimonSapin commented on August 27, 2024

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.

SimonSapin avatar SimonSapin commented on August 27, 2024

Never mind that last sentence, for this use case I’d need assembly anyway to access specific registers.

from riscv-rt.

Disasm avatar Disasm commented on August 27, 2024

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.

SimonSapin avatar SimonSapin commented on August 27, 2024

This is a very elegant solution, but doesn’t this require carrying these values somewhere all the way through initialization code?

from riscv-rt.

SimonSapin avatar SimonSapin commented on August 27, 2024

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) prints 0x0
  • _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.

Disasm avatar Disasm commented on August 27, 2024

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.

SimonSapin avatar SimonSapin commented on August 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.