sel4_runtime_common/start/
mod.rs1use core::arch::global_asm;
8
9mod with_stack_init;
10
11#[macro_export]
12macro_rules! declare_entrypoint {
13 {
14 $f:ident($( $i:ident: $t:ty ),* $(,)?)
15 } => {
16 $crate::declare_entrypoint! {
17 $f($($i: $t,)*)
18 global_init if true
19 }
20 };
21 {
22 $f:ident($( $i:ident: $t:ty ),* $(,)?)
23 global_init if $global_init_cond:expr
24 } => {
25 const _: () = {
26 #[unsafe(no_mangle)]
27 unsafe extern "C" fn __sel4_runtime_common__rust_entrypoint($($i: $t,)*) -> ! {
28 $crate::_private::_run_entrypoint($global_init_cond, || {
29 $f($($i,)*)
30 });
31 }
32 };
33
34 $crate::_private::global_asm! {
35 r#"
36 .extern __sel4_runtime_common__call_rust_entrypoint
37
38 .section .text
39
40 .global _start
41 _start:
42 "#,
43 #[cfg(any(target_arch = "aarch64", target_arch = "arm"))]
44 r#"
45 b __sel4_runtime_common__call_rust_entrypoint
46 "#,
47 #[cfg(any(target_arch = "riscv64", target_arch = "riscv32"))]
48 r#"
49 j __sel4_runtime_common__call_rust_entrypoint
50 "#,
51 #[cfg(target_arch = "x86_64")]
52 r#"
53 jmp __sel4_runtime_common__call_rust_entrypoint
54 "#,
55 }
56 };
57}
58
59global_asm! {
60 r#"
61 .extern __sel4_runtime_common__rust_entrypoint
62
63 .section .text.__sel4_runtime_common__call_rust_entrypoint, "ax", %progbits
64
65 .global __sel4_runtime_common__call_rust_entrypoint
66 __sel4_runtime_common__call_rust_entrypoint:
67 "#,
68 #[cfg(any(target_arch = "aarch64", target_arch = "arm"))]
69 r#"
70 bl __sel4_runtime_common__rust_entrypoint
71 1: b 1b
72 "#,
73 #[cfg(any(target_arch = "riscv64", target_arch = "riscv32"))]
74 r#"
75 .option push
76 .option norelax
77 1: auipc gp, %pcrel_hi(__global_pointer$)
78 addi gp, gp, %pcrel_lo(1b)
79 .option pop
80 jal __sel4_runtime_common__rust_entrypoint
81 1: j 1b
82 "#,
83 #[cfg(target_arch = "x86_64")]
84 r#"
85 call __sel4_runtime_common__rust_entrypoint
86 1: jmp 1b
87 "#,
88}