xref: /relibc/src/crti/src/lib.rs (revision ae7cee26a661c02341332a200ddf03223a6fb362)
1 //! crti
2 
3 #![no_std]
4 #![feature(global_asm)]
5 #![feature(linkage)]
6 
7 // https://wiki.osdev.org/Creating_a_C_Library#crtbegin.o.2C_crtend.o.2C_crti.o.2C_and_crtn.o
8 #[cfg(target_arch = "x86_64")]
9 global_asm!(
10     r#"
11     .section .init
12     .global _init
13     _init:
14         push rbp
15         mov rbp, rsp
16         // Created a new stack frame and updated the stack pointer
17         // Body will be filled in by gcc and ended by crtn.o
18 
19     .section .fini
20     .global _fini
21     _fini:
22         push rbp
23         mov rbp, rsp
24         // Created a new stack frame and updated the stack pointer
25         // Body will be filled in by gcc and ended by crtn.o
26 "#
27 );
28 // https://git.musl-libc.org/cgit/musl/tree/crt/aarch64/crti.s
29 #[cfg(target_arch = "aarch64")]
30 global_asm!(
31     r#"
32     .section .init
33     .global _init
34     .type _init,%function
35     _init:
36         stp x29,x30,[sp,-16]!
37         mov x29,sp
38         // stp: "stores two doublewords from the first and second argument to memory addressed by addr"
39         // Body will be filled in by gcc and ended by crtn.o
40 
41     .section .fini
42     .global _fini
43     .type _fini,%function
44     _fini:
45         stp x29,x30,[sp,-16]!
46         mov x29,sp
47         // stp: "stores two doublewords from the first and second argument to memory addressed by addr"
48         // Body will be filled in by gcc and ended by crtn.o
49 "#
50 );
51 
52 #[linkage = "weak"]
53 #[no_mangle]
54 extern "C" fn relibc_panic(pi: &::core::panic::PanicInfo) -> ! {
55     loop {}
56 }
57 
58 #[panic_handler]
59 #[linkage = "weak"]
60 #[no_mangle]
61 pub unsafe extern "C" fn rust_begin_unwind(pi: &::core::panic::PanicInfo) -> ! {
62     relibc_panic(pi)
63 }
64