|
| 1 | +use core::mem; |
1 | 2 |
|
2 | 3 | /// Physical entry point into the kernel. |
3 | 4 | /// |
|
7 | 8 | /// Ignored otherwise. |
8 | 9 | pub const XEN_ELFNOTE_PHYS32_ENTRY: u32 = 18; |
9 | 10 |
|
| 11 | +// #[macro_export] |
| 12 | +// macro_rules! phys32_entry { |
| 13 | +// ($phys32_entry:expr) => { |
| 14 | +// const _: unsafe extern "C" fn() = $phys32_entry; |
| 15 | + |
| 16 | +// core::arch::global_asm!( |
| 17 | +// ".pushsection .note.Xen, \"a\", @note", |
| 18 | +// ".balign 4", |
| 19 | +// ".Ln_namesz: .long .Ldesc - .Lname", |
| 20 | +// ".Ln_descsz: .long .Lend - .Ldesc", |
| 21 | +// ".Ln_type: .long {ty}", |
| 22 | +// ".Lname: .asciz \"Xen\"", |
| 23 | +// ".balign 4", |
| 24 | +// ".Ldesc: .long {desc}", |
| 25 | +// ".Lend: .balign 4", |
| 26 | +// ".popsection", |
| 27 | +// ty = const $crate::elfnote::XEN_ELFNOTE_PHYS32_ENTRY, |
| 28 | +// desc = sym $phys32_entry, |
| 29 | +// ); |
| 30 | +// }; |
| 31 | +// } |
| 32 | + |
| 33 | +#[repr(C, packed(4))] |
| 34 | +struct Nhdr32 { |
| 35 | + n_namesz: u32, |
| 36 | + n_descsz: u32, |
| 37 | + n_type: u32, |
| 38 | +} |
| 39 | + |
| 40 | +#[doc(hidden)] |
| 41 | +#[repr(C, packed(4))] |
| 42 | +pub struct Elfnote<N, D> { |
| 43 | + header: Nhdr32, |
| 44 | + name: N, |
| 45 | + desc: D, |
| 46 | +} |
| 47 | + |
| 48 | +impl<N, D> Elfnote<N, D> { |
| 49 | + pub const fn new(n_type: u32, name: N, desc: D) -> Self { |
| 50 | + Self { |
| 51 | + header: Nhdr32 { |
| 52 | + n_namesz: mem::size_of::<N>() as u32, |
| 53 | + n_descsz: mem::size_of::<D>() as u32, |
| 54 | + n_type, |
| 55 | + }, |
| 56 | + name, |
| 57 | + desc, |
| 58 | + } |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +impl Elfnote<[u8; 4], unsafe extern "C" fn()> { |
| 63 | + #[doc(hidden)] |
| 64 | + pub const fn phys32_entry(phys32_entry: unsafe extern "C" fn()) -> Self { |
| 65 | + Self::new(XEN_ELFNOTE_PHYS32_ENTRY, *b"Xen\0", phys32_entry) |
| 66 | + } |
| 67 | +} |
| 68 | + |
10 | 69 | #[macro_export] |
11 | 70 | macro_rules! phys32_entry { |
12 | 71 | ($phys32_entry:expr) => { |
13 | | - const _: unsafe extern "C" fn() = $phys32_entry; |
14 | | - |
15 | | - core::arch::global_asm!( |
16 | | - ".pushsection .note.Xen, \"a\", @note", |
17 | | - ".balign 4", |
18 | | - ".Ln_namesz: .long .Ldesc - .Lname", |
19 | | - ".Ln_descsz: .long .Lend - .Ldesc", |
20 | | - ".Ln_type: .long {ty}", |
21 | | - ".Lname: .asciz \"Xen\"", |
22 | | - ".balign 4", |
23 | | - ".Ldesc: .long {desc}", |
24 | | - ".Lend: .balign 4", |
25 | | - ".popsection", |
26 | | - ty = const $crate::elfnote::XEN_ELFNOTE_PHYS32_ENTRY, |
27 | | - desc = sym $phys32_entry, |
28 | | - ); |
| 72 | + #[used] |
| 73 | + #[unsafe(link_section = ".note.Xen")] |
| 74 | + static XEN_ELFNOTE: $crate::elfnote::Elfnote<[u8; 4], unsafe extern "C" fn()> = |
| 75 | + $crate::elfnote::Elfnote::phys32_entry($phys32_entry); |
29 | 76 | }; |
30 | 77 | } |
0 commit comments