Skip to content

Commit 2f5fa67

Browse files
committed
f
1 parent 08f4977 commit 2f5fa67

File tree

5 files changed

+78
-21
lines changed

5 files changed

+78
-21
lines changed

src/arch/x86_64/platform/multiboot/entry.s

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
.align 4
1313
.global _start
1414
_start:
15+
mov edi, ebx
1516
cli # avoid any interrupt
1617

1718
# Initialize stack pointer

src/arch/x86_64/platform/multiboot/mod.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use alloc::borrow::ToOwned;
2+
use xen_hvm::start_info::HvmStartInfo;
23
use core::ptr::write_bytes;
34
use core::sync::atomic::{AtomicPtr, Ordering};
45
use core::{mem, ptr, slice};
@@ -44,11 +45,12 @@ mod entry {
4445

4546
static MB_INFO: AtomicPtr<MultibootInfo> = AtomicPtr::new(ptr::null_mut());
4647

47-
unsafe extern "C" fn rust_start(mb_info: *mut MultibootInfo) -> ! {
48-
MB_INFO.store(mb_info, Ordering::Relaxed);
49-
unsafe {
50-
crate::os::loader_main();
51-
}
48+
unsafe extern "C" fn rust_start(start_info: &'static HvmStartInfo) -> ! {
49+
paging::map::<Size4KiB>(0x2000, 0x2000, 1, PageTableFlags::empty());
50+
dbg!(start_info);
51+
crate::log::init();
52+
crate::log_built_info();
53+
loop {}
5254
}
5355

5456
struct Mem;

xen-hvm/src/elfnote.rs

Lines changed: 63 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use core::mem;
12

23
/// Physical entry point into the kernel.
34
///
@@ -7,24 +8,70 @@
78
/// Ignored otherwise.
89
pub const XEN_ELFNOTE_PHYS32_ENTRY: u32 = 18;
910

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+
1069
#[macro_export]
1170
macro_rules! phys32_entry {
1271
($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);
2976
};
3077
}

xen-hvm/src/save.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//!
2+
//!
3+
//! [`xen/include/public/arch-x86/hvm/save.h`]: https://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=xen/include/public/arch-x86/hvm/save.h;h=9c4bfc7ebdac9e2baf2856d1293712eb8c30d526;hb=06af9ef22996cecc2024a2e6523cec77a655581e

xen-hvm/src/start_info.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ pub const XEN_HVM_START_MAGIC_VALUE: u32 = 0x336ec578;
8686
/// Address Map Interfaces" section of the ACPI Specification. Please refer to
8787
/// section 15 in version 6.2 of the ACPI spec: http://uefi.org/specifications
8888
#[doc(alias = "XEN_HVM_MEMMAP_TYPE")]
89+
#[derive(Debug)]
8990
#[repr(u32)]
9091
pub enum XenHvmMemmapType {
9192
#[doc(alias = "XEN_HVM_MEMMAP_TYPE_RAM")]
@@ -115,6 +116,7 @@ pub enum XenHvmMemmapType {
115116
/// The canonical definition of this layout is above, this is just a way to
116117
/// represent the layout described there using C types.
117118
#[doc(alias = "hvm_start_info")]
119+
#[derive(Debug)]
118120
#[repr(C)]
119121
pub struct HvmStartInfo {
120122
/// Contains the magic value 0x336ec578 "xEn3" with the 0x80 bit of the "E" set).
@@ -152,6 +154,7 @@ pub struct HvmStartInfo {
152154
}
153155

154156
#[doc(alias = "hvm_modlist_entry")]
157+
#[derive(Debug)]
155158
#[repr(C)]
156159
pub struct HvmModlistEntry {
157160
/// Physical address of the module.
@@ -166,6 +169,7 @@ pub struct HvmModlistEntry {
166169
}
167170

168171
#[doc(alias = "hvm_memmap_table_entry")]
172+
#[derive(Debug)]
169173
#[repr(C)]
170174
pub struct HvmMemmapTableEntry {
171175
/// Base address of the memory region

0 commit comments

Comments
 (0)