diff --git a/_config.yml b/_config.yml index 56830454..6a76e7e0 100644 --- a/_config.yml +++ b/_config.yml @@ -11,6 +11,10 @@ tagline: "rust, kernels, and more" paginate: 10 baseurl: "" +markdown: redcarpet +redcarpet: + extensions: ["no_intra_emphasis", "fenced_code_blocks", "autolink", "tables", "with_toc_data", "superscript", "footnotes"] + # Assets # # We specify the directory for Jekyll so we can use @imports. @@ -33,3 +37,4 @@ navigation_pages: Archive: '/archive' contact: '/contact' + diff --git a/_posts/2015-07-22-rust-os-boot.md b/_posts/2015-07-22-rust-os-boot.md index a9b3e07e..e54e4982 100644 --- a/_posts/2015-07-22-rust-os-boot.md +++ b/_posts/2015-07-22-rust-os-boot.md @@ -1,27 +1,63 @@ --- layout: post -title: "[DRAFT] Rust OS Part 1: Booting" -related_posts: +title: '[DRAFT] Rust OS Part 1: Booting' +related_posts: null --- +## Multiboot +Fortunately there is a bootloader standard: the [Multiboot Specification][multiboot]. So our kernel just needs to indicate that it supports Multiboot and every Multiboot-compliant bootloader can boot it. We will use the [GRUB 2] bootloader together with the Multiboot 2 specification ([PDF][Multiboot 2]). -Fortunately there is a bootloader standard: the [Multiboot -Specification][multiboot]. So our kernel just needs to indicate that it supports -Multiboot and every Multiboot-compliant bootloader can boot it. We will use the [GRUB 2] bootloader together with the [Multiboot 2] specification. So let's begin! +To indicate our Multiboot 2 support to the bootloader, our kernel must contain a _Multiboot Header_, which has the following format: -To indicate our Multiboot 2 support to the bootloader, our kernel must contain a *Multiboot Header*, which has the following format: +Field | Type | Value +------------- | --------------- | ---------------------------------------- +magic number | u32 | 0xE85250D6 +architecture | u32 | 0 for i386, 4 for MIPS +header length | u32 | total header size, including tags +checksum | u32 | -(magic + architecture + header length) +tags | variable | +end tag | (u16, u16, u32) | (0, 0, 8) -Field | Size in byte -------|----- -magic number | 4 +Converted to x86 assembly it looks like this (Intel syntax): -Offset | Type | Field Name --------|------|----------- -0 | u32 | magic -4 | u32 | architecture -8 | u32 | header_length -12 | u32 | checksum -16-XX | | tags +```nasm +header_start: + dd 0xe85250d6 ; magic number (multiboot 2) + dd 0 ; architecture 0 (protected mode i386) + dd header_end - header_start ; header length + ; checksum + dd 0x100000000 - (0xe85250d6 + 0 + (header_end - header_start)) + + ; insert optional multiboot tags here + + ; required end tag + dw 0 ; type + dw 0 ; flags + dd 8 ; size +header_end: +``` + +If you don't know x86 assembly, here is some quick guide: + +- `header_start` and `header_end` are _labels_ that mark a memory location. We use them to calculate the header length easily +- `dd` stands for `define double` (32bit) and `dw` stands for `define word` (16bit) +- the additional `0x100000000` in the checksum calculation is a small hack[^fn-checksum_hack] to avoid a compiler warning + +We can already compile it using `nasm`. As it produces a flat binary by default, the resulting file contains just our 24 bytes (in little endian if you work on a x86 machine): + +``` +> nasm boot.asm +> hexdump -x boot +0000000 50d6 e852 0000 0000 0018 0000 af12 17ad +0000010 0000 0000 0008 0000 +0000018 +``` + + +## Booting + + +[^fn-checksum_hack]: The formula from the table, `-(magic + architecture + header length)`, creates a negative value that doesn't fit into 32bit. By subtracting from `0x100000000` instead, we keep the value positive without changing its truncated value. Without the additional sign bit(s) the result fits into 32bit and the compiler is happy. [multiboot]: https://en.wikipedia.org/wiki/Multiboot_Specification -[GRUB 2]: http://wiki.osdev.org/GRUB_2 -[Multiboot 2]: http://nongnu.askapache.com/grub/phcoder/multiboot.pdf +[grub 2]: http://wiki.osdev.org/GRUB_2 +[multiboot 2]: http://nongnu.askapache.com/grub/phcoder/multiboot.pdf diff --git a/_sass/_layout.scss b/_sass/_layout.scss index 2a272698..661b1007 100644 --- a/_sass/_layout.scss +++ b/_sass/_layout.scss @@ -3,7 +3,7 @@ // Styles for managing the structural hierarchy of the site. .container { - max-width: 38rem; + max-width: 45rem; padding-left: 1.5rem; padding-right: 1.5rem; margin-left: auto;