/src/MigTD/deps/td-shim/td-payload/src/lib.rs
Line | Count | Source |
1 | | // Copyright (c) 2022 Intel Corporation |
2 | | // Copyright (c) 2022 Alibaba Cloud |
3 | | // |
4 | | // SPDX-License-Identifier: BSD-2-Clause-Patent |
5 | | |
6 | | #![cfg_attr(not(test), no_std)] |
7 | | #![cfg_attr(not(test), no_main)] |
8 | | |
9 | | use console::CONSOLE; |
10 | | use core::fmt::{Arguments, Write}; |
11 | | |
12 | | extern crate alloc; |
13 | | |
14 | | pub mod acpi; |
15 | | pub mod arch; |
16 | | pub mod console; |
17 | | pub mod hob; |
18 | | pub mod mm; |
19 | | |
20 | | /// The entry point of Payload |
21 | | /// |
22 | | /// For the x86_64-unknown-uefi target, the entry point name is 'efi_main' |
23 | | /// For the x86_64-unknown-none target, the entry point name is '_start' |
24 | | #[no_mangle] |
25 | | #[cfg(all(not(test), feature = "start"))] |
26 | | #[cfg_attr(target_os = "uefi", export_name = "efi_main")] |
27 | | pub extern "C" fn _start(hob: u64, _payload: u64) -> ! { |
28 | | use mm::layout::RuntimeLayout; |
29 | | extern "C" { |
30 | | fn main(); |
31 | | } |
32 | | |
33 | | let layout = RuntimeLayout::default(); |
34 | | |
35 | | arch::init::pre_init( |
36 | | hob, |
37 | | &layout, |
38 | | #[cfg(not(feature = "no-shared-mem"))] |
39 | | false, |
40 | | ); |
41 | | arch::init::init(&layout, main); |
42 | | } |
43 | | |
44 | 0 | pub fn console(args: Arguments) { |
45 | 0 | CONSOLE |
46 | 0 | .lock() |
47 | 0 | .write_fmt(args) |
48 | 0 | .expect("Failed to write console"); |
49 | 0 | } |
50 | | |
51 | | #[macro_export] |
52 | | macro_rules! print { |
53 | | ($($arg:tt)*) => ($crate::console(format_args!($($arg)*))); |
54 | | } |
55 | | |
56 | | #[macro_export] |
57 | | macro_rules! println { |
58 | | ($($arg:tt)*) => ($crate::print!("{}\n", format_args!($($arg)*))); |
59 | | } |
60 | | |
61 | | #[derive(Debug)] |
62 | | pub enum Error { |
63 | | ParseHob, |
64 | | GetMemoryMap, |
65 | | GetAcpiTable, |
66 | | SetupMemoryLayout, |
67 | | SetupPageTable, |
68 | | } |