Set up allocations

This commit is contained in:
Philipp Oppermann
2021-03-24 13:32:19 +01:00
parent e0b5cf89ba
commit 9d78913a37
2 changed files with 25 additions and 2 deletions

View File

@@ -10,4 +10,4 @@ edition = "2018"
members = ["disk_image"] members = ["disk_image"]
[dependencies] [dependencies]
uefi = "0.8.0" uefi = { version = "0.8.0", features = ["alloc"] }

View File

@@ -1,8 +1,12 @@
#![feature(abi_efiapi)] #![feature(abi_efiapi)]
#![feature(alloc_error_handler)]
#![no_std] #![no_std]
#![no_main] #![no_main]
use core::panic::PanicInfo; extern crate alloc;
use alloc::vec::Vec;
use core::{alloc::Layout, fmt::Write, panic::PanicInfo};
use uefi::prelude::entry; use uefi::prelude::entry;
#[entry] #[entry]
@@ -10,6 +14,20 @@ fn efi_main(
image: uefi::Handle, image: uefi::Handle,
system_table: uefi::table::SystemTable<uefi::table::Boot>, system_table: uefi::table::SystemTable<uefi::table::Boot>,
) -> uefi::Status { ) -> uefi::Status {
let stdout = system_table.stdout();
stdout.clear().unwrap().unwrap();
writeln!(stdout, "Hello World!").unwrap();
unsafe {
uefi::alloc::init(system_table.boot_services());
}
writeln!(stdout, "alloc").unwrap();
let mut v: Vec<u32> = Vec::new();
v.push(1);
v.push(2);
writeln!(stdout, "v = {:?}", v).unwrap();
loop {} loop {}
} }
@@ -17,3 +35,8 @@ fn efi_main(
fn panic(_info: &PanicInfo) -> ! { fn panic(_info: &PanicInfo) -> ! {
loop {} loop {}
} }
#[alloc_error_handler]
fn alloc_error(_layout: Layout) -> ! {
panic!("out of memory")
}