Skip to content

Commit

Permalink
Add Hello World
Browse files Browse the repository at this point in the history
  • Loading branch information
lemolatoon committed Nov 6, 2022
1 parent a54b1ca commit 03c9e47
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/disk.img
27 changes: 27 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
PROFILE=debug

.PHONY: FORCE

bootloader/target/x86_64-unknown-uefi/$(PROFILE)/bootloader.efi: FORCE
cd bootloader && \
cargo build

disk.img: bootloader/target/x86_64-unknown-uefi/$(PROFILE)/bootloader.efi
# qemu-img create [-f format] [-o options] filename [size][preallocation]
# mkfs.fat [-n VOLUME-NAME] [-s SECTORS-PER-CLUSTER] [-f NUMBER-OF-FATS] [-R NUMBER-OF-RESERVED-SECTORS] [-F FAT-SIZE]
# ref.) `man mkfs.fat`
# mount [-o options] device dir
# loop -> mount as loop device
qemu-img create -f raw disk.img 200M && \
mkfs.fat -n "lemola_osv2" -s 2 -f 2 -R 32 -F 32 disk.img && \
mkdir -p mnt && \
sudo mount -o loop disk.img mnt && \
sudo mkdir -p mnt/EFI/BOOT && \
sudo cp bootloader/target/x86_64-unknown-uefi/$(PROFILE)/bootloader.efi mnt/EFI/BOOT/BOOTX64.EFI && \
sudo umount mnt

run: disk.img
qemu-system-x86_64 \
-drive if=pflash,file=ovmf/OVMF_CODE.fd \
-drive if=pflash,file=ovmf/lemola_os_ovmf_vars.fd \
-hda disk.img
11 changes: 11 additions & 0 deletions bootloader/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@
#![no_std]
#![feature(abi_efiapi)]

use core::arch::asm;

use uefi::prelude::*;
use uefi_services::println;

#[entry]
fn main(_handle: Handle, mut system_table: SystemTable<Boot>) -> Status {
uefi_services::init(&mut system_table).unwrap();

println!("Hello from uefi.rs");

loop {
unsafe {
asm!("hlt");
}
}

Status::SUCCESS
}
Binary file added ovmf/OVMF_CODE.fd
Binary file not shown.
Binary file added ovmf/lemola_os_ovmf_vars.fd
Binary file not shown.
13 changes: 13 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# only for ubuntu

# NOTE* install rust before run this

sudo apt-get install qemu-kvm -y
sudo apt-get install ovmf -y

# setup ovmf files by yourself

# cp /usr/share/OVMF/OVMF_VARS.fd ./ovmf/lemola_os_ovmf_vars.fd
# cp /usr/share/OVMF/OVMF_CODE.fd ./ovmf/OVMF_CODE.fd

0 comments on commit 03c9e47

Please sign in to comment.