From 9d78913a37481b697086c04d2e812a8de172a1aa Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Wed, 24 Mar 2021 13:32:19 +0100 Subject: [PATCH] Set up allocations --- Cargo.toml | 2 +- src/main.rs | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d0617bf4..7887f98a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,4 +10,4 @@ edition = "2018" members = ["disk_image"] [dependencies] -uefi = "0.8.0" +uefi = { version = "0.8.0", features = ["alloc"] } diff --git a/src/main.rs b/src/main.rs index 7b21c667..2e1e01cf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,12 @@ #![feature(abi_efiapi)] +#![feature(alloc_error_handler)] #![no_std] #![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; #[entry] @@ -10,6 +14,20 @@ fn efi_main( image: uefi::Handle, system_table: uefi::table::SystemTable, ) -> 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 = Vec::new(); + v.push(1); + v.push(2); + writeln!(stdout, "v = {:?}", v).unwrap(); + loop {} } @@ -17,3 +35,8 @@ fn efi_main( fn panic(_info: &PanicInfo) -> ! { loop {} } + +#[alloc_error_handler] +fn alloc_error(_layout: Layout) -> ! { + panic!("out of memory") +}