mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 22:37:49 +00:00
add multiboot section
This commit is contained in:
@@ -11,6 +11,10 @@ tagline: "rust, kernels, and more"
|
|||||||
paginate: 10
|
paginate: 10
|
||||||
baseurl: ""
|
baseurl: ""
|
||||||
|
|
||||||
|
markdown: redcarpet
|
||||||
|
redcarpet:
|
||||||
|
extensions: ["no_intra_emphasis", "fenced_code_blocks", "autolink", "tables", "with_toc_data", "superscript", "footnotes"]
|
||||||
|
|
||||||
# Assets
|
# Assets
|
||||||
#
|
#
|
||||||
# We specify the directory for Jekyll so we can use @imports.
|
# We specify the directory for Jekyll so we can use @imports.
|
||||||
@@ -33,3 +37,4 @@ navigation_pages:
|
|||||||
Archive: '/archive'
|
Archive: '/archive'
|
||||||
|
|
||||||
contact: '/contact'
|
contact: '/contact'
|
||||||
|
|
||||||
|
|||||||
@@ -1,27 +1,63 @@
|
|||||||
---
|
---
|
||||||
layout: post
|
layout: post
|
||||||
title: "[DRAFT] Rust OS Part 1: Booting"
|
title: '[DRAFT] Rust OS Part 1: Booting'
|
||||||
related_posts:
|
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
|
To indicate our Multiboot 2 support to the bootloader, our kernel must contain a _Multiboot Header_, which has the following format:
|
||||||
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:
|
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
|
Converted to x86 assembly it looks like this (Intel syntax):
|
||||||
------|-----
|
|
||||||
magic number | 4
|
|
||||||
|
|
||||||
Offset | Type | Field Name
|
```nasm
|
||||||
-------|------|-----------
|
header_start:
|
||||||
0 | u32 | magic
|
dd 0xe85250d6 ; magic number (multiboot 2)
|
||||||
4 | u32 | architecture
|
dd 0 ; architecture 0 (protected mode i386)
|
||||||
8 | u32 | header_length
|
dd header_end - header_start ; header length
|
||||||
12 | u32 | checksum
|
; checksum
|
||||||
16-XX | | tags
|
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
|
[multiboot]: https://en.wikipedia.org/wiki/Multiboot_Specification
|
||||||
[GRUB 2]: http://wiki.osdev.org/GRUB_2
|
[grub 2]: http://wiki.osdev.org/GRUB_2
|
||||||
[Multiboot 2]: http://nongnu.askapache.com/grub/phcoder/multiboot.pdf
|
[multiboot 2]: http://nongnu.askapache.com/grub/phcoder/multiboot.pdf
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
// Styles for managing the structural hierarchy of the site.
|
// Styles for managing the structural hierarchy of the site.
|
||||||
|
|
||||||
.container {
|
.container {
|
||||||
max-width: 38rem;
|
max-width: 45rem;
|
||||||
padding-left: 1.5rem;
|
padding-left: 1.5rem;
|
||||||
padding-right: 1.5rem;
|
padding-right: 1.5rem;
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
|
|||||||
Reference in New Issue
Block a user