flat assembler
Message board for the users of flat assembler.

Index > OS Construction > BOOTBOOT Loader

Author
Thread Post new topic Reply to topic
bzt



Joined: 09 Nov 2018
Posts: 83
bzt 09 Nov 2018, 19:05
Hi All,

Not a OS, just a bootloader. I wanted to boot my micro-kernel on different machines and architectures with the simpliest interface possible.
Later I made my bootloader available for other OSes as well, and released the source under MIT license. You can give it a try, if you'd like.

The UEFI and the RPi versions are written in C, but the BIOS/Multiboot version is entirely coded with FASM only. It consist of two files:
- boot.bin (512 bytes): boot record, which works as MBR, VBR and a El Torito "no emulation" CDROM boot record out-of-the-box. Can load bootboot.bin from any filesystem, and supports RAID mirrors. It can be installed on a FAT volume too (does not interfere with the BPB).
- bootboot.bin (10k): the stage2 part. Can be loaded by boot.bin, by GRUB as a Multiboot kernel, but also works as a BIOS Expansion ROM (only tested with bochs and qemu, not in real EEPROM).

The source code is commented, you can use it for learning purposes (although sometimes you might find interesting things as it took me more than a year to implement all the following features in Assembly with lots of rewrites and bugfixes. The C sources are much cleaner, tbh. Gzip deflate was particularly a bitch to port.)

Notable features:
- Boots 64 bit kernels only (x86_64 long mode and ARM AArch64)
- Sets up virtual memory, mapping the kernel in higher half (at -2M, no protmode/longmode trampoline code or higher-half GDT trickery needed)
- Sets up video mode (VESA2.0+, GOP or VC) and maps LFB in higher half (at -64M)
- Initializes the serial debug console for your kernel (tested with VirtualBox, qemu and on real hardware. Very useful for debugging)
- Designed for micro-kernels, so loads an initrd, assumes kernel executable is inside
- Supported initrd formats: cpio (all variants), ustar (POSIX version), James Molloy's initrd format, SFS, and statically linked executables (like the Minix kernel)
- Supports Gzip deflate compressed initrd images
- GPT aware, can load initrd from a partition or from a file on a FAT16/32 partition, and also from ROM
- Kernel can be in ELF64 or in PE32+ format
- Environment info (screen dimension, arch independent memory map etc.) is passed in a simple structure at linker specified address
- Full documentation available in PDF

Suggestions, questions and testing results are welcome,
bzt
Post 09 Nov 2018, 19:05
View user's profile Send private message Reply with quote
bzt



Joined: 09 Nov 2018
Posts: 83
bzt 26 Nov 2018, 15:54
Hi All,

Added Linux x86 boot protocol too.

Currently the same bootboot.bin binary supports the following boot mechanisms without any modifications:
- loaded by boot.bin (as MBR, VBR and CDROM boot record, qemu -hda)
- Expansion ROM (for embedded systems, qemu -option-rom)
- Multiboot (GRUB or qemu -multiboot)
- Linux boot (GRUB, ISOLINUX, LoadLin, qemu -kernel etc.)

Cheers,
bzt
Post 26 Nov 2018, 15:54
View user's profile Send private message Reply with quote
bzt



Joined: 09 Nov 2018
Posts: 83
bzt 08 Feb 2019, 10:29
Hi All,

Added co-processor (SSE, Neon) and SMP support. With those, the feature set is now complete. The BOOTBOOT Protocol Specification is now frozen.

All cores are running the kernel simultaneously, so you may want to start your kernel with
Code:
_start:
mov eax, 1
cpuid
shr ebx, 24
cmp bx, word [bootboot.bspid]
jne .ap
; ... things to do on the bootstrap processor
.ap:
; ... things to do on an application processor 
    

With ARM things are easier as core ids are contiguous (no gaps) and BSP is always core 0:
Code:
_start:
mrs x0, mpidr_el1
and x0, x0, #3
cbnz x0, .ap
; ... things to do on the bootstrap processor
.ap:
; ... things to do on an application processor 
    
(Note: BOOTBOOT internally handles cores up to 65536, see bootboot.numcores field. If you want to take advantage of that, you'll have to use x2APIC, otherwise you're limited to 256 cores. The ARM version has fixed 4 cores.)

The environment and memory mapping is the same on all cores, except each core has it's own 1k stack. If 1k is not enough for your entire kernel, then you should set up a new stack in your _start() function.

Cheers,
bzt
Post 08 Feb 2019, 10:29
View user's profile Send private message Reply with quote
scippie



Joined: 26 Jan 2017
Posts: 11
scippie 08 Feb 2019, 13:31
Sounds impressive! I'll certainly take a look at your code!
Post 08 Feb 2019, 13:31
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.