Skip to content

Commit 00b3adf

Browse files
committed
Merge #385
385: First bits of the second edition r=phil-opp a=phil-opp This PR adds the first two posts for the second edition, “A Freestanding Rust Binary” and “A Minimal Rust Kernel”. The largest changes in comparison to the first edition are: - Instead of GRUB, we use our own [bootloader](https://github.com/rust-osdev/bootloader) (written in Rust) and our [bootimage](https://github.com/rust-osdev/bootimage) tool. This removes the dependencies on GRUB and `nasm`. Note that both tools are still experimental and might contain bugs. - Support for Windows and Mac: Without GRUB, there's nothing preventing us from building on Windows or Mac OS anymore! We added additional CI jobs at travis and appveyor to ensure that the project always builds on all three platforms. (At the moment, users still need to install LLD, but with the [LLVM 6 update of rustc](rust-lang/rust#47828) we should have a builtin LLD soon.) - No assembly in the main posts. Instead, we're creating a `no_std` _executable_ and relying on our custom bootloader to perform the initial page mapping and the switch to long mode. - No linker script: Our bootloader loads the kernel in a clean address space, so we can just use the default executable layout and don't need a linker script. (This also means that users that want a higher half kernel just need to update the mapping in their linker script. However, I'm not sure if it's a good idea to add this to the blog. Maybe later, when we begin to run user programs.) These changes only land in “beta mode” with this PR, which means that they're not linked from the front page yet. We will do that in a follow up PR.
2 parents 3f4a4bf + b2285f7 commit 00b3adf

File tree

62 files changed

+1386
-1981
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1386
-1981
lines changed

.appveyor.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
branches:
2+
except:
3+
# Used by bors
4+
- staging.tmp
5+
6+
# Appveyor configuration template for Rust using rustup for Rust installation
7+
# https://github.com/starkat99/appveyor-rust
8+
9+
## Operating System (VM environment) ##
10+
11+
# Rust needs at least Visual Studio 2013 Appveyor OS for MSVC targets.
12+
os: Visual Studio 2015
13+
14+
## Build Matrix ##
15+
environment:
16+
matrix:
17+
18+
### MSVC Toolchains ###
19+
# Nightly 64-bit MSVC
20+
- channel: nightly
21+
target: x86_64-pc-windows-msvc
22+
MSYS_BITS: 64
23+
# Nightly 32-bit MSVC
24+
- channel: nightly
25+
target: i686-pc-windows-msvc
26+
MSYS_BITS: 32
27+
28+
### GNU Toolchains ###
29+
# Nightly 64-bit GNU
30+
- channel: nightly
31+
target: x86_64-pc-windows-gnu
32+
MSYS_BITS: 64
33+
# Nightly 32-bit GNU
34+
- channel: nightly
35+
target: i686-pc-windows-gnu
36+
MSYS_BITS: 32
37+
38+
cache:
39+
- '%USERPROFILE%\.cargo\bin'
40+
- '%USERPROFILE%\.cargo\config'
41+
- '%USERPROFILE%\.cargo\env'
42+
- '%USERPROFILE%\.cargo\.crates.toml'
43+
- '%USERPROFILE%\.xargo'
44+
- target
45+
46+
## Install Script ##
47+
48+
# This is the most important part of the Appveyor configuration. This installs the version of Rust
49+
# specified by the 'channel' and 'target' environment variables from the build matrix. This uses
50+
# rustup to install Rust.
51+
#
52+
# For simple configurations, instead of using the build matrix, you can simply set the
53+
# default-toolchain and default-host manually here.
54+
install:
55+
- appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
56+
- rustup-init -yv --default-toolchain %channel% --default-host %target%
57+
- set PATH=%PATH%;%USERPROFILE%\.cargo\bin
58+
- rustc -vV
59+
- cargo -vV
60+
61+
## Build Script ##
62+
63+
# 'cargo test' takes care of building for us, so disable Appveyor's build stage. This prevents
64+
# the "directory does not contain a project or solution file" error.
65+
build: false
66+
67+
before_test:
68+
- mkdir bin
69+
- mklink "bin\ld.exe" "C:\Program Files\LLVM\bin\lld.exe"
70+
- set PATH=%CD%\bin;C:\msys64\mingw%MSYS_BITS%\bin;C:\msys64\usr\bin;%PATH%
71+
- rustup component add rust-src
72+
- set RUST_BACKTRACE=1
73+
- if not exist %USERPROFILE%\.cargo\bin\cargo-install-update.exe cargo install cargo-update
74+
- if not exist %USERPROFILE%\.cargo\bin\xargo.exe cargo install xargo
75+
- if not exist %USERPROFILE%\.cargo\bin\bootimage.exe cargo install bootimage
76+
- cargo install-update -a
77+
78+
# Uses 'cargo test' to run tests and build. Alternatively, the project may call compiled programs
79+
# directly or perform other testing commands. Rust will automatically be placed in the PATH
80+
# environment variable.
81+
test_script:
82+
- bootimage --target x86_64-blog_os

.travis.yml

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,53 @@
11
language: rust
22

3+
sudo: false
4+
5+
notifications:
6+
email:
7+
on_success: never
8+
on_failure: change
9+
10+
branches:
11+
except:
12+
# Used by bors
13+
- staging.tmp
14+
315
rust:
416
- nightly
517

18+
os:
19+
- linux
20+
- osx
21+
22+
addons:
23+
apt:
24+
sources:
25+
- llvm-toolchain-trusty-5.0
26+
packages:
27+
- lld-5.0
28+
629
cache:
730
directories:
8-
- $HOME/.cargo
9-
- $HOME/.xargo
10-
- $TRAVIS_BUILD_DIR/target
31+
- $HOME/.cargo
32+
- $HOME/.xargo
33+
- $TRAVIS_BUILD_DIR/target
34+
35+
before_install:
36+
- |
37+
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
38+
set -e
39+
LLVM_URL="https://releases.llvm.org/5.0.1/clang+llvm-5.0.1-x86_64-apple-darwin.tar.xz"
40+
travis_retry wget -O llvm.tar.xz -nv ${LLVM_URL}
41+
tar -xJ -f llvm.tar.xz
42+
export PATH="`pwd`/clang+llvm-5.0.1-final-x86_64-apple-darwin/bin:$PATH"
43+
fi
1144
1245
before_script:
1346
- rustup component add rust-src
1447
- (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update)
1548
- (test -x $HOME/.cargo/bin/xargo || cargo install xargo)
49+
- (test -x $HOME/.cargo/bin/bootimage || cargo install bootimage)
1650
- cargo install-update -a
1751

18-
sudo: false
19-
20-
notifications:
21-
email:
22-
on_success: never
23-
on_failure: change
24-
25-
addons:
26-
apt:
27-
packages:
28-
- nasm
29-
3052
script:
31-
- make
53+
- bootimage --target x86_64-blog_os

Cargo.toml

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
[package]
22
authors = ["Philipp Oppermann <[email protected]>"]
33
name = "blog_os"
4-
version = "0.1.0"
4+
version = "0.2.0"
55

66
[dependencies]
7-
bit_field = "0.7.0"
8-
bitflags = "0.9.1"
9-
multiboot2 = "0.1.0"
10-
once = "0.3.2"
11-
rlibc = "1.0"
12-
spin = "0.4.5"
13-
volatile = "0.1.0"
14-
x86_64 = "0.1.2"
15-
linked_list_allocator = "0.4.2"
167

17-
[dependencies.lazy_static]
18-
features = ["spin_no_std"]
19-
version = "0.2.1"
8+
# the profile used for `cargo build`
9+
[profile.dev]
10+
panic = "abort" # disable stack unwinding on panic
2011

21-
[lib]
22-
crate-type = ["staticlib"]
12+
# the profile used for `cargo build --release`
13+
[profile.release]
14+
panic = "abort" # disable stack unwinding on panic

Makefile

Lines changed: 0 additions & 82 deletions
This file was deleted.

Xargo.toml

Lines changed: 0 additions & 2 deletions
This file was deleted.

blog/content/extra/naked-exceptions/01-catching-exceptions/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title = "Catching Exceptions"
33
order = 1
44
path = "catching-exceptions"
5-
date = "2016-05-28"
5+
date = 2016-05-28
66
[extra]
77
updated = "2016-06-25"
88
+++

blog/content/extra/naked-exceptions/02-better-exception-messages/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title = "Better Exception Messages"
33
order = 2
44
path = "better-exception-messages"
5-
date = "2016-08-03"
5+
date = 2016-08-03
66
[extra]
77
updated = "2016-11-01"
88
+++

blog/content/extra/naked-exceptions/03-returning-from-exceptions/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title = "Returning from Exceptions"
33
order = 3
44
path = "returning-from-exceptions"
5-
date = "2016-09-21"
5+
date = 2016-09-21
66
[extra]
77
updated = "2016-11-01"
88
+++

blog/content/first-edition/_index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
+++
2+
title = "First Edition"
3+
template = "index.html"
4+
+++

blog/content/posts/01-multiboot-kernel/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title = "A minimal x86 kernel"
33
order = 1
44
path = "multiboot-kernel/"
5-
date = "2015-08-18"
5+
date = 2015-08-18
66
+++
77

88
This post explains how to create a minimal x86 operating system kernel. In fact, it will just boot and print `OK` to the screen. In subsequent blog posts we will extend it using the [Rust] programming language.

blog/content/posts/02-entering-longmode/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title = "Entering Long Mode"
33
order = 2
44
path = "entering-longmode"
5-
date = "2015-08-25"
5+
date = 2015-08-25
66
[extra]
77
updated = "2015-10-29"
88
+++

blog/content/posts/03-set-up-rust/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title = "Set Up Rust"
33
order = 3
44
path = "set-up-rust"
5-
date = "2015-09-02"
5+
date = 2015-09-02
66
[extra]
77
updated = "2017-04-12"
88
+++

blog/content/posts/04-printing-to-screen/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title = "Printing to Screen"
33
order = 4
44
path = "printing-to-screen"
5-
date = "2015-10-23"
5+
date = 2015-10-23
66
[extra]
77
updated = "2016-10-31"
88
+++

blog/content/posts/05-allocating-frames/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title = "Allocating Frames"
33
order = 5
44
path = "allocating-frames"
5-
date = "2015-11-15"
5+
date = 2015-11-15
66
+++
77

88
In this post we create an allocator that provides free physical frames for a future paging module. To get the required information about available and used memory we use the Multiboot information structure. Additionally, we improve the `panic` handler to print the corresponding message and source line.

blog/content/posts/06-page-tables/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title = "Page Tables"
33
order = 6
44
path = "page-tables"
5-
date = "2015-12-09"
5+
date = 2015-12-09
66
+++
77

88
In this post we will create a paging module, which allows us to access and modify the 4-level page table. We will explore recursive page table mapping and use some Rust features to make it safe. Finally we will create functions to translate virtual addresses and to map and unmap pages.

blog/content/posts/07-remap-the-kernel/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title = "Remap the Kernel"
33
order = 7
44
path = "remap-the-kernel"
5-
date = "2016-01-01"
5+
date = 2016-01-01
66
[extra]
77
updated = "2016-03-06"
88
+++

blog/content/posts/08-kernel-heap/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title = "Kernel Heap"
33
order = 8
44
path = "kernel-heap"
5-
date = "2016-04-11"
5+
date = 2016-04-11
66
updated = "2017-11-19"
77
+++
88

blog/content/posts/09-handling-exceptions/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title = "Handling Exceptions"
33
order = 9
44
path = "handling-exceptions"
5-
date = "2017-03-26"
5+
date = 2017-03-26
66
+++
77

88
In this post, we start exploring CPU exceptions. Exceptions occur in various erroneous situations, for example when accessing an invalid memory address or when dividing by zero. To catch them, we have to set up an _interrupt descriptor table_ that provides handler functions. At the end of this post, our kernel will be able to catch [breakpoint exceptions] and to resume normal execution afterwards.

blog/content/posts/10-double-faults/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title = "Double Faults"
33
order = 10
44
path = "double-faults"
5-
date = "2017-01-02"
5+
date = 2017-01-02
66
+++
77

88
In this post we explore double faults in detail. We also set up an _Interrupt Stack Table_ to catch double faults on a separate kernel stack. This way, we can completely prevent triple faults, even on kernel stack overflow.

blog/content/second-edition/_index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
+++
2+
title = "Second Edition"
3+
template = "second-edition/index.html"
4+
+++

0 commit comments

Comments
 (0)