-
Notifications
You must be signed in to change notification settings - Fork 9
Use naked functions #22
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| // Copyright 2025 The aarch64-rt Authors. | ||
| // This project is dual-licensed under Apache 2.0 and MIT terms. | ||
| // See LICENSE-APACHE and LICENSE-MIT for details. | ||
|
|
||
| //! Entrypoint code | ||
|
|
||
| use core::arch::naked_asm; | ||
|
|
||
| /// This is a generic entry point for an image. It carries out the operations required to prepare the | ||
| /// loaded image to be run. Specifically, it zeroes the bss section using registers x25 and above, | ||
| /// prepares the stack, enables floating point, and sets up the exception vector. It preserves x0-x3 | ||
| /// for the Rust entry point, as these may contain boot parameters. | ||
| /// | ||
| /// # Safety | ||
| /// | ||
| /// This function is marked unsafe because it should never be called by anyone. The linker is | ||
| /// responsible for setting it as the entry function. | ||
| #[unsafe(naked)] | ||
| #[unsafe(link_section = ".init.entry")] | ||
| #[unsafe(export_name = "entry")] | ||
| unsafe extern "C" fn entry() -> ! { | ||
| naked_asm!( | ||
| ".macro adr_l, reg:req, sym:req", | ||
| r"adrp \reg, \sym", | ||
| r"add \reg, \reg, :lo12:\sym", | ||
| ".endm", | ||
| "bl enable_mmu", | ||
| // Disable trapping floating point access in EL1. | ||
| "mrs x30, cpacr_el1", | ||
| "orr x30, x30, #(0x3 << 20)", | ||
| "msr cpacr_el1, x30", | ||
| "isb", | ||
| // Zero out the bss section. | ||
| "adr_l x29, bss_begin", | ||
| "adr_l x30, bss_end", | ||
| "0:", | ||
| "cmp x29, x30", | ||
| "b.hs 1f", | ||
| "stp xzr, xzr, [x29], #16", | ||
| "b 0b", | ||
| "1:", | ||
| // Prepare the stack. | ||
| "adr_l x30, boot_stack_end", | ||
| "mov sp, x30", | ||
| // Call into Rust code. | ||
| "b {rust_entry}", | ||
| rust_entry = sym crate::rust_entry, | ||
| ) | ||
| } | ||
|
|
||
| /// An assembly entry point for secondary cores. | ||
| /// | ||
| /// It will enable the MMU, disable trapping of floating point instructions, initialise the | ||
| /// stack pointer to `stack_end` and then jump to the function pointer at the bottom of the | ||
| /// stack with the u64 value second on the stack as a parameter. | ||
| /// | ||
| /// # Safety | ||
| /// | ||
| /// This requires that an initial stack pointer value be passed in `x0`, and the stack must contain | ||
| /// the address of a Rust entry point to jump to and a parameter value to pass to it. | ||
| #[unsafe(naked)] | ||
| pub unsafe extern "C" fn secondary_entry(stack_end: *mut u64) -> ! { | ||
| naked_asm!( | ||
| "bl enable_mmu", | ||
| // Disable trapping floating point access in EL1. | ||
| "mrs x30, cpacr_el1", | ||
| "orr x30, x30, #(0x3 << 20)", | ||
| "msr cpacr_el1, x30", | ||
| "isb", | ||
| // Set the stack pointer which was passed. | ||
| "mov sp, x0", | ||
| // Load Rust entry point address and argument from the bottom of the stack into | ||
| // callee-saved registers. | ||
| "ldp x19, x20, [sp, #-16]", | ||
| // Set the exception vector. | ||
| "bl {set_exception_vector}", | ||
| // Pass argument to Rust entry point. | ||
| "mov x0, x19", | ||
| // Call into Rust code. | ||
| "br x20", | ||
| set_exception_vector = sym crate::set_exception_vector, | ||
| ) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,32 +15,28 @@ | |
| ))] | ||
| compile_error!("Only one `el` feature may be enabled at once."); | ||
|
|
||
| mod entry; | ||
| #[cfg(feature = "initial-pagetable")] | ||
| mod pagetable; | ||
|
|
||
| #[cfg(any(feature = "exceptions", feature = "psci"))] | ||
| use core::arch::asm; | ||
| use core::arch::global_asm; | ||
| pub use entry::secondary_entry; | ||
| #[cfg(feature = "initial-pagetable")] | ||
| pub use pagetable::{DEFAULT_MAIR, DEFAULT_SCTLR, DEFAULT_TCR, InitialPagetable}; | ||
|
|
||
| global_asm!(include_str!("entry.S")); | ||
|
|
||
| #[cfg(not(feature = "initial-pagetable"))] | ||
| global_asm!(include_str!("dummy_enable_mmu.S"),); | ||
| #[unsafe(naked)] | ||
| #[unsafe(link_section = ".init")] | ||
| #[unsafe(export_name = "enable_mmu")] | ||
| extern "C" fn enable_mmu() { | ||
| core::arch::naked_asm!("ret") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I left it in since I moved the entry code to its own module and this is the only |
||
| } | ||
|
|
||
| #[cfg(feature = "exceptions")] | ||
| global_asm!(include_str!("exceptions.S")); | ||
|
|
||
| unsafe extern "C" { | ||
| /// An assembly entry point for secondary cores. | ||
| /// | ||
| /// It will enable the MMU, disable trapping of floating point instructions, initialise the | ||
| /// stack pointer to `stack_end` and then jump to the function pointer at the bottom of the | ||
| /// stack with the u64 value second on the stack as a parameter. | ||
| pub unsafe fn secondary_entry(stack_end: *mut u64) -> !; | ||
| } | ||
|
|
||
| /// Sets the appropriate vbar to point to our `vector_table`, if the `exceptions` feature is | ||
| /// enabled. | ||
| #[unsafe(no_mangle)] | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.