Skip to content

Commit e2a00a4

Browse files
committed
Add an example kernel that can be used to try the bootloader
1 parent 39cc62e commit e2a00a4

File tree

7 files changed

+130
-0
lines changed

7 files changed

+130
-0
lines changed

azure-pipelines.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,6 @@ steps:
106106
if [ $? -eq 123 ]; then (exit 0); else (exit 1); fi
107107
displayName: 'Test Bootloader'
108108

109+
- script: cargo xbuild
110+
workingDirectory: example-kernel
111+
displayName: 'Build Example Kernel'

example-kernel/.cargo/config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build]
2+
target = "x86_64-example-kernel.json"

example-kernel/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target/
2+
**/*.rs.bk

example-kernel/Cargo.lock

Lines changed: 69 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example-kernel/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "example-kernel"
3+
version = "0.1.0"
4+
authors = ["Philipp Oppermann <[email protected]>"]
5+
edition = "2018"
6+
7+
[dependencies]
8+
x86_64 = "0.3.4"

example-kernel/src/main.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#![no_std] // don't link the Rust standard library
2+
#![no_main] // disable all Rust-level entry points
3+
4+
use core::panic::PanicInfo;
5+
6+
static HELLO: &[u8] = b"Hello World!";
7+
8+
#[no_mangle] // don't mangle the name of this function
9+
pub extern "C" fn _start() -> ! {
10+
// this function is the entry point, since the linker looks for a function
11+
// named `_start` by default
12+
13+
let vga_buffer = 0xb8000 as *mut u8;
14+
15+
// print `HELLO` to the screen (see
16+
// https://os.phil-opp.com/minimal-rust-kernel/#printing-to-screen)
17+
for (i, &byte) in HELLO.iter().enumerate() {
18+
unsafe {
19+
*vga_buffer.offset(i as isize * 2) = byte;
20+
*vga_buffer.offset(i as isize * 2 + 1) = 0xb;
21+
}
22+
}
23+
24+
loop {}
25+
}
26+
27+
/// This function is called on panic.
28+
#[panic_handler]
29+
fn panic(_info: &PanicInfo) -> ! {
30+
loop {}
31+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"llvm-target": "x86_64-unknown-none",
3+
"data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
4+
"arch": "x86_64",
5+
"target-endian": "little",
6+
"target-pointer-width": "64",
7+
"target-c-int-width": "32",
8+
"os": "none",
9+
"executables": true,
10+
"linker-flavor": "ld.lld",
11+
"linker": "rust-lld",
12+
"panic-strategy": "abort",
13+
"disable-redzone": true,
14+
"features": "-mmx,-sse,+soft-float"
15+
}

0 commit comments

Comments
 (0)