Code Monkey home page Code Monkey logo

uefi-bootstrap's Introduction

OS DEV

This should be a very simple jumping off point to modern kernel development.

The idea behind this project is to provide an easy to understand, minimalist bootstrap that lowers the barrier to entry for any new comers.

Code works for both

  • x86_64
  • AArch64

run ./build.sh and you can boot the resulting example kernel on both x86_64 and AArch64

Crystal Kernel

This bootstrap is being used to load this hobby OS https://github.com/stakach/crystal-kernel

Getting started

Very easy to test and run on Windows with VirtualBox see Crystal Kernel for details on how to test and even step through debug your kernel on macOS.

  • Compile on Win Linux layer, macOS or Linux
  • Clang + LLVM toolchain
  • requires Zig lang

Building an EFI bootable executable

EFI expects the bootable file to be in COFF/PE32+ format

  • run ./build.sh to clean and build for all architectures

you can also do this manually

  1. run make -f makefile_x86_64
  2. this will output
    • bin/efi/boot/bootx64.efi
    • bin/kernelx64.elf
  3. you can inspect symbols in the object files using nm -C bin/uefi_bootstrap.obj (or kernelx64.elf)
    • anything with a U tag, i.e. U memcpy means memcpy needs to be defined in your project

Create a disk image for booting

Very simple to do this on Windows, for macOS see Crystal Kernel which builds disk images as part of the build script

  • Disk Management (diskmgmt.msc)
    • Action -> Create VHD
    • Initialize disk (GPT GUID Partition Table)
    • Format as FAT32
  • create the following folder:
    • /efi/boot
    • add bootstrap file as bootx64.efi
  • OR just copy the bin folder contents to the VHD

unmount the disk before booting it in VirtualBox unmount

Create a VM

  • Install VirtualBox
  • Create new VM
    • Type: Other
    • Version: Other/Unknown (64bit)
    • Don't add a HD
  • Edit Settings
    • System -> Check "Enable EFI"
    • Storage -> Add default IDE + select VHD image from above

Starting the VM will now boot the bootx64.efi file

unmount

Diving into the code

The process of booting should be fairly simple to follow along looking at uefi_bootstrap.zig The real trick with UEFI code is that

  • it needs to be in PE/COFF format (think Windows .exe files)
  • conform to a particular entrypoint format (-Wl,-entry:efi_main in the make file)

The bootstrap code likewise expects a few things of the kernel.elf file:

  • Segments need to be 4kb aligned - for paging support
  • the entry point takes no params and returns void
  • the boot_info structure is going to be stored at address 1MB
    • (no matter where the elf segments request to be loaded)

Take a look at kernel.ld to see how this is laid out. For instance I currently have the boot_info label in the text section. But I could probably swap around the text and data sections if I wanted boot_info as part of data or bss

Accessing the full address space

https://eli.thegreenplace.net/2012/01/03/understanding-the-x64-code-models

  • this flag is set in the makefile

uefi-bootstrap's People

Contributors

stakach avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

uefi-bootstrap's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.