Skip to content

Instantly share code, notes, and snippets.

@mikerowehl
Last active September 4, 2020 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikerowehl/ffaad752adc98a6286c6297d0a63c44b to your computer and use it in GitHub Desktop.
Save mikerowehl/ffaad752adc98a6286c6297d0a63c44b to your computer and use it in GitHub Desktop.
Compiling boot sector from assembly and C++ using a Docker cross-compile toolchain
# Assuming you have boot4.asm, kmain.cpp, and linker.ld from
# http://3zanders.co.uk/2017/10/18/writing-a-bootloader3/
# already in your working directory and you have nasm and qemu
# installed locally
nasm -f elf32 boot4.asm -o boot4.o
docker run --rm dockcross/linux-x86 > ./dockcross
chmod +x dockcross
./dockcross g++ -m32 kmain.cpp boot4.o -o kernel.bin -nostdlib \
-ffreestanding -std=c++11 -mno-red-zone -fno-exceptions \
-nostdlib -fno-rtti -Wall -Wextra -Werror -fno-pie -T linker.ld
qemu-system-x86_64 kernel.bin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment