Skip to content

Commit dd3dadf

Browse files
authored
Merge pull request #104 from rust-osdev/test-with-builtin-target
Add an example kernel that uses the built-in `x86_64-unknown-none` target
2 parents 9b4837b + fa148bc commit dd3dadf

File tree

7 files changed

+91
-0
lines changed

7 files changed

+91
-0
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ jobs:
9090
- name: "Print QEMU Version"
9191
run: qemu-system-x86_64 --version
9292

93+
- name: 'Build kernel with built-in target (no json-target-spec config)'
94+
run: cargo bootimage --target x86_64-unknown-none
95+
working-directory: example-kernel-built-in-target
96+
9397
- name: 'Build "basic" Kernel'
9498
run: cargo bootimage --target ../x86_64-bootimage-example-kernels.json
9599
working-directory: example-kernels/basic
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[unstable]
2+
build-std = ["core", "compiler_builtins"]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target/

example-kernel-built-in-target/Cargo.lock

Lines changed: 53 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "example-kernel-built-in-target"
3+
version = "0.1.0"
4+
edition = "2018"
5+
6+
[dependencies]
7+
bootloader = "0.9.7"
8+
x86_64 = "0.14.1"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nightly
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#![no_std]
2+
#![no_main]
3+
4+
use core::panic::PanicInfo;
5+
6+
#[panic_handler]
7+
fn panic(_info: &PanicInfo) -> ! {
8+
loop {}
9+
}
10+
11+
#[no_mangle]
12+
pub extern "C" fn _start() -> ! {
13+
unsafe { exit_qemu(); }
14+
loop {}
15+
}
16+
17+
unsafe fn exit_qemu() {
18+
use x86_64::instructions::port::Port;
19+
20+
let mut port = Port::<u32>::new(0xf4);
21+
port.write(51); // exit code is (51 << 1) | 1 = 103
22+
}

0 commit comments

Comments
 (0)