blob: dd7f6db53e94dad9152b19f8626166c8499d3ad5 [file] [log] [blame]
Andrew Walbranb996b4a2022-04-22 15:15:41 +00001// Copyright 2022, The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Rust entry point.
16
17use crate::{console, power::shutdown};
18
19/// This is the entry point to the Rust code, called from the binary entry point in `entry.S`.
20#[no_mangle]
21extern "C" fn rust_entry() -> ! {
22 console::init();
23 unsafe {
24 main();
25 }
26 shutdown();
27}
28
29extern "Rust" {
30 /// Main function provided by the application using the `main!` macro.
31 fn main();
32}
33
34/// Marks the main function of the binary.
35///
36/// Example:
37///
38/// ```rust
39/// use vmbase::main;
40///
41/// main!(my_main);
42///
43/// fn my_main() {
44/// println!("Hello world");
45/// }
46/// ```
47#[macro_export]
48macro_rules! main {
49 ($name:path) => {
50 // Export a symbol with a name matching the extern declaration above.
51 #[export_name = "main"]
52 fn __main() {
53 // Ensure that the main function provided by the application has the correct type.
54 $name()
55 }
56 };
57}