Skip to content

Commit

Permalink
Hello world works!
Browse files Browse the repository at this point in the history
  • Loading branch information
eholk committed Nov 17, 2013
1 parent 42ddc2c commit f3ada16
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 8 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
boot.efi :
.phony: all
all :
rustc -O -c --lib boot.rs
x86_64-efi-pe-ld -g --oformat pei-x86-64 --dll --subsystem 10:1.0 --major-os-version 0 --heap 0,0 -nostdlib --stack 0x1000,0 -pie -Bsymbolic -nocombreloc -e efi_main boot.o -o boot.efi

71 changes: 64 additions & 7 deletions boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,72 @@ struct EFI_TABLE_HEADER {

struct EFI_SYSTEM_TABLE {
Hdr : EFI_TABLE_HEADER,
FirmwareVendor : *u16,
FirmwareRevision : u32,
ConsoleInHandle : EFI_HANDLE,
ConIn : *EFI_SIMPLE_TEXT_INPUT_PROTOCOL,
ConsoleOutHandle : EFI_HANDLE,
ConOut : *EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL,
// ... other stuff that we're ignoring for now.
}

#[no_mangle]
pub fn efi_main(_ImageHandle : EFI_HANDLE, _SystemTable : EFI_SYSTEM_TABLE) -> int {
loop {}
struct EFI_SIMPLE_TEXT_INPUT_PROTOCOL;

struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL {
Reset : EFI_TEXT_RESET,
OutputString : EFI_TEXT_STRING,
// ... and more stuff that we're ignoring.
}

type EFI_TEXT_RESET = *();

type EFI_TEXT_STRING = extern "win64" fn(*EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL,
*u16);

#[no_mangle]
pub fn __morestack() {
// Terrible things will happen if this is ever called.
loop {}
}
#[no_split_stack]
pub extern "win64" fn efi_main(_ImageHandle : EFI_HANDLE, SystemTable : *EFI_SYSTEM_TABLE) -> int {
unsafe {
let SystemTable = *SystemTable;
let vendor = SystemTable.FirmwareVendor;
let conout = SystemTable.ConOut;
let output = (*conout).OutputString;

let hello = ['H' as u16,
'e' as u16,
'l' as u16,
'l' as u16,
'o' as u16,
',' as u16,
' ' as u16,
'W' as u16,
'o' as u16,
'r' as u16,
'l' as u16,
'd' as u16,
'\r' as u16,
'\n' as u16,
0u16];
let (hello_ptr, _) = buf_ptr(hello);

output(conout, hello_ptr);

loop {
}
}
}

fn buf_ptr<T>(buf: &[T]) -> (*T, uint) {
unsafe { transmute(buf) }
}

//#[no_mangle]
//#[no_split_stack]
//pub fn __morestack() {
// // If this is called, something horrible probably happened...
//}

extern "rust-intrinsic" {
pub fn transmute<T,U>(val: T) -> U;
// pub fn size_of<T>() -> uint;
}

0 comments on commit f3ada16

Please sign in to comment.