Compare commits

...

110 Commits

Author SHA1 Message Date
Philipp Oppermann
83e6c0bc00 Merge pull request #1436 from phil-opp/post-02-fix-target
Fix: `target-pointer-width` field now expects an integer
2025-09-03 17:56:38 +02:00
Philipp Oppermann
2b11ad8397 Fix: target-pointer-width field now expects an integer 2025-09-03 17:53:14 +02:00
Philipp Oppermann
fa51f3adbf Update to latest bootloader version 2025-09-03 17:52:56 +02:00
Philipp Oppermann
94d14d8d62 Run cargo update for bootloader crate 2025-08-18 09:42:41 +02:00
Philipp Oppermann
d9fa84edd6 Merge pull request #1425 from phil-opp/post-02-fix-target
Fix: `target-c-int-width` field now expects an integer
2025-08-07 13:09:35 +02:00
Philipp Oppermann
9684f75819 Merge branch 'post-01' into post-02 2025-08-07 13:07:09 +02:00
Philipp Oppermann
d6cc562907 Fix: target-c-int-width field now expects an integer 2025-08-07 12:25:03 +02:00
Philipp Oppermann
16bbb8f972 Merge branch 'post-01' into post-02 2025-03-27 15:07:24 +01:00
Philipp Oppermann
c27eb1da9c Run cargo update for bootloader crate 2025-03-24 11:08:41 +01:00
Philipp Oppermann
a90a8bea67 Run cargo update for bootloader crate 2025-02-10 12:35:16 +01:00
Philipp Oppermann
688a21e4ed Set rustc-abi: x86-softfloat in target JSON
This additional field is required by the Rust compiler since https://github.com/rust-lang/rust/pull/136146 .
2025-02-10 11:16:14 +01:00
Philipp Oppermann
2265ddecad Run cargo update 2024-04-30 15:37:30 +02:00
Philipp Oppermann
38604da92f Update bootloader version to v0.9.27 in Cargo.lock 2024-02-16 15:59:13 +01:00
Philipp Oppermann
c6990cb52d Don't specify patch version in Cargo.toml
Avoids confusion for people that don't know that cargo always chooses the latest patch version.
2024-02-16 13:21:21 +01:00
Philipp Oppermann
2bc4490404 Update bootloader version to v0.9.26 in Cargo.lock 2024-02-16 13:13:31 +01:00
Philipp Oppermann
7959b77ebd Update data layout for LLVM 18
Fixes build on latest rustc nightly.
2024-02-16 12:38:32 +01:00
Philipp Oppermann
bebad6d5a9 Update bootloader version in Cargo.lock 2024-02-16 12:36:31 +01:00
Philipp Oppermann
b99c3f6d1d Use latest data layout for custom target 2024-01-28 11:44:35 +01:00
Philipp Oppermann
66c1792034 Update bootloader version in Cargo.lock 2024-01-28 11:44:23 +01:00
Philipp Oppermann
6393247a3b Update bootloader version in Cargo.lock 2022-09-25 11:29:38 +02:00
Philipp Oppermann
faa8d15cb7 Run cargo update for bootloader crate 2022-01-18 10:05:56 +01:00
Philipp Oppermann
26f1f5b896 Run cargo update for bootloader crate 2021-12-22 09:27:00 +01:00
Philipp Oppermann
1f49e2e9fe Merge branch 'post-01' into post-02 2021-05-21 19:53:49 +02:00
Philipp Oppermann
021762cf30 Run cargo update for bootloader 2021-05-20 14:32:27 +02:00
Philipp Oppermann
d8f280315f Run cargo update for bootloader crate 2021-05-17 11:28:54 +02:00
Philipp Oppermann
066c278277 Merge branch 'post-01' into post-02 2021-03-10 09:23:02 +01:00
Philipp Oppermann
96844f6519 Merge branch 'post-01' into post-02 2021-03-10 09:15:58 +01:00
Philipp Oppermann
1b86d7fd62 Merge branch 'post-01' into post-02 2021-03-10 09:13:39 +01:00
Philipp Oppermann
d658949f5b Run cargo update for bootloader crate 2021-03-10 08:53:21 +01:00
Philipp Oppermann
0e52ccbebb Run cargo update for bootloader crate 2021-02-02 10:51:03 +01:00
Rob Gries
4e38e7ddf8 Remove rlibc and use compiler-builtins-mem feature (#865) 2020-10-02 23:14:25 +02:00
Philipp Oppermann
49dce7ada7 cargo update the bootloadercrate to fix nightly breakage 2020-09-29 12:19:48 +02:00
Philipp Oppermann
c42cee8d89 Update bootloader to 0.9.10 2020-09-24 10:09:57 +02:00
Philipp Oppermann
ebb9f0b8a7 Run cargo update 2020-09-24 09:07:45 +02:00
Philipp Oppermann
cde3c8f955 Merge branch 'post-01' into post-02 2020-08-16 18:03:09 +02:00
Philipp Oppermann
4a4d704384 Add note about minimum required nightly version 2020-07-17 15:57:32 +02:00
Philipp Oppermann
71d8a438f7 Update Readme for new build-std build instructions 2020-07-17 11:48:27 +02:00
Philipp Oppermann
3a77cbe794 Merge branch 'post-01' into post-02 2020-07-17 11:44:17 +02:00
Philipp Oppermann
6f9cfce6f9 Don't deny clippy warnings 2020-07-17 11:27:18 +02:00
Philipp Oppermann
4bbaae24a4 Merge pull request #835 from phil-opp/post-02-Zbuild-std
Migrate post-02 code from cargo-xbuild to `-Zbuild-std`
2020-07-17 11:13:11 +02:00
Philipp Oppermann
44d7654ef6 Add toml extension to .cargo/config and use table format for unstable 2020-07-17 10:57:04 +02:00
Philipp Oppermann
f135aefae8 Update to bootloader 0.9.8 2020-07-17 10:52:21 +02:00
Philipp Oppermann
ffaac76876 Use latest release of bootimage on CI 2020-07-17 10:52:08 +02:00
Philipp Oppermann
5ae9f62f4d Adjust job names on CI to match existing names 2020-07-16 17:15:03 +02:00
Philipp Oppermann
da0ee38f09 Add names for all CI operations 2020-07-16 17:10:50 +02:00
Philipp Oppermann
263e852dcc Use functionality of toolchain action for installing rustup components 2020-07-16 17:04:02 +02:00
Philipp Oppermann
614e5b0e86 Install rustup components after checking out the repo
so that the components are installed for the nightly toolchain.
2020-07-16 16:36:19 +02:00
Philipp Oppermann
9ee42e0f5f Install Zbuild-std branch of bootimage 2020-07-16 16:32:50 +02:00
Philipp Oppermann
c4672096d4 Install rust-src component for cargo check 2020-07-16 16:31:52 +02:00
Philipp Oppermann
ffe1b6abd0 Rewrite CI script with using actions-rs actions
This gives use support for github's scoped annotations when there are errors or warnings.
2020-07-16 16:21:37 +02:00
Philipp Oppermann
16ffe80fd5 Add dependency on rlibc 2020-07-16 15:39:07 +02:00
Philipp Oppermann
07d8a22a53 Use -Zbuildstd instead of cargo-xbuild 2020-07-16 15:37:09 +02:00
Philipp Oppermann
b1bf0873ce Update bootloader to v0.9.3 2020-05-20 14:03:59 +02:00
Philipp Oppermann
46264d08ca Run cargo update 2020-02-26 12:43:51 +01:00
Philipp Oppermann
fea4fa9c67 Update Github Actions badge for post-02 2019-12-12 09:28:05 +01:00
Philipp Oppermann
ddbe317099 Merge branch 'post-01' into post-02 2019-12-12 09:27:30 +01:00
Philipp Oppermann
0cc02f02c5 Merge branch 'post-01' into post-02 2019-12-12 09:23:30 +01:00
Philipp Oppermann
58629ea208 Merge branch 'post-01' into post-02 2019-12-10 16:55:26 +01:00
Philipp Oppermann
1c4ca04a2f Update post-02 to new lockfile format 2019-11-28 14:03:59 +01:00
Philipp Oppermann
60856aac6b Merge branch 'post-01' into post-02 2019-11-28 14:03:19 +01:00
Philipp Oppermann
7de138aa04 Merge branch 'post-01' into post-02 2019-11-22 15:57:18 +01:00
Philipp Oppermann
9e40f377db Merge branch 'post-01' into post-02 2019-10-08 19:44:38 +02:00
Philipp Oppermann
6b23fa3d28 Run cargo update 2019-09-25 13:18:32 +02:00
Philipp Oppermann
99a7231d52 Remove profile.{dev, release}.panic keys from Cargo.toml 2019-09-13 17:42:06 +02:00
Philipp Oppermann
621364bd1b Merge branch 'post-01' into post-02 2019-09-13 10:53:50 +02:00
Philipp Oppermann
818bfb9646 Merge branch 'post-01' into post-02 2019-09-11 11:21:15 +02:00
Philipp Oppermann
ffd1bda509 Update bootloader to version 0.8.0 2019-09-11 10:55:49 +02:00
Philipp Oppermann
bb8923cf56 Merge branch 'post-01' into post-02 2019-09-11 10:32:57 +02:00
Philipp Oppermann
dbe0802c6d Merge branch 'post-01' into post-02 2019-09-11 10:12:46 +02:00
Philipp Oppermann
9e1e3926fa Merge branch 'post-01' into post-02 2019-09-11 10:09:29 +02:00
Philipp Oppermann
7b00599bf8 Merge pull request #662 from phil-opp/post-02-actions
Set up GitHub Actions for post-02 branch
2019-09-11 09:45:20 +02:00
Philipp Oppermann
72aa3a4580 Update github actions script for post-02 2019-09-10 23:50:14 +02:00
Philipp Oppermann
5d7c4678de Merge branch 'post-01' into post-02-actions 2019-09-10 23:50:08 +02:00
Philipp Oppermann
7197d8b18a Remove old package.metadata.bootimage configuration key 2019-09-10 10:20:42 +02:00
Philipp Oppermann
e86c95bd24 Run cargo update 2019-07-22 10:24:54 +02:00
Philipp Oppermann
47bcca33b3 Run cargo update 2019-07-18 10:14:57 +02:00
Philipp Oppermann
5ed27923e8 Update to bootloader 0.6.4 2019-07-18 10:14:39 +02:00
Philipp Oppermann
b59720f6e1 Update Readme for new runner 2019-04-26 11:27:36 +02:00
Philipp Oppermann
63b97fe1f8 Update bootloader to version 0.6.0 2019-04-26 11:23:32 +02:00
Philipp Oppermann
528bbd4e9f Add a cargo xbuild check on CI 2019-04-25 14:28:43 +02:00
Philipp Oppermann
06d1c9ff81 Update CI scripts to use cargo bootimage 2019-04-25 14:17:27 +02:00
Philipp Oppermann
c1064ad316 Add a .cargo/config file 2019-04-25 13:18:28 +02:00
Philipp Oppermann
3c2a5ef0f6 Merge branch 'post-01' into post-02 2019-04-25 11:08:11 +02:00
Philipp Oppermann
64e7ea7b1a Merge branch 'post-01' into post-02 2019-04-11 15:32:06 +02:00
Philipp Oppermann
eee4718115 Add llvm-tools-preview also in travis and appveyor scripts 2019-04-06 17:35:11 +02:00
Philipp Oppermann
9237c875f3 Run cargo update 2019-04-06 16:53:52 +02:00
Philipp Oppermann
62b89cd80f Install llvm-tools-preview rustup component 2019-04-06 16:37:43 +02:00
Philipp Oppermann
e1034aa9ac Update Cargo.lock 2019-04-06 15:34:23 +02:00
Philipp Oppermann
577c6b8cfc Update to bootloader 0.5.1 2019-04-06 15:33:13 +02:00
Philipp Oppermann
f308628db2 Merge branch 'post-01' into post-02 2019-04-03 10:45:28 +02:00
Philipp Oppermann
ab16203ed7 Update bootloader to version 0.4.0 2019-03-14 11:13:28 +01:00
Philipp Oppermann
63f8f3a6eb Merge branch 'post-01' into post-02 2019-02-25 16:34:15 +01:00
Philipp Oppermann
013e6f2add Merge branch 'post-01' into post-02 2019-02-07 18:46:31 +01:00
Philipp Oppermann
d5cb74ac8b We still need nighly Rust for the second and later posts 2019-02-07 16:14:58 +01:00
Philipp Oppermann
3bf2c66acc Merge branch 'post-01' into post-02 2019-02-07 16:11:46 +01:00
Philipp Oppermann
0e6ffc1a4f Merge branch 'post-01' into post-02 2019-02-05 15:23:48 +01:00
Philipp Oppermann
57484164ab Expand azure pipelines script for second post 2019-02-05 14:55:22 +01:00
Philipp Oppermann
1ca8cec4e6 Merge branch 'post-01' into post-02 2019-02-05 14:53:53 +01:00
Philipp Oppermann
2d5d6ee850 Merge branch 'post-01' into post-02 2019-02-05 10:46:08 +01:00
Philipp Oppermann
c9ce9d5735 Merge branch 'post-01' into post-02 2019-01-29 12:16:54 +01:00
Philipp Oppermann
f013172dd7 Update Readme for A Minimal Rust Kernel post 2019-01-27 17:06:41 +01:00
Philipp Oppermann
858a2f94c6 Merge branch 'post-01' into post-02 2019-01-27 17:06:09 +01:00
Philipp Oppermann
2ce4af4a65 Merge branch 'post-01' into post-02 2019-01-27 16:33:54 +01:00
Philipp Oppermann
8d730050d3 Update CI scripts for second post 2019-01-27 15:27:16 +01:00
Philipp Oppermann
752a7ed84e Merge branch 'z_post_01' into z_post_02 2019-01-27 15:22:55 +01:00
Philipp Oppermann
59f9fe1e69 Update Cargo.lock 2019-01-25 12:44:36 +01:00
Philipp Oppermann
f4fd0e264a Add default target for bootimage 2019-01-25 12:44:27 +01:00
Philipp Oppermann
bbc19e132c Add bootloader dependency 2019-01-25 12:42:48 +01:00
Philipp Oppermann
f9ffee92c7 Print Hello World! to screen 2019-01-25 12:42:21 +01:00
Philipp Oppermann
fd08b1a123 Add target specification file 2019-01-25 12:40:20 +01:00
8 changed files with 99 additions and 27 deletions

9
.cargo/config.toml Normal file
View File

@@ -0,0 +1,9 @@
[unstable]
build-std = ["core", "compiler_builtins"]
build-std-features = ["compiler-builtins-mem"]
[build]
target = "x86_64-blog_os.json"
[target.'cfg(target_os = "none")']
runner = "bootimage runner"

View File

@@ -56,21 +56,16 @@ jobs:
with:
profile: minimal
toolchain: nightly
- name: Install bootimage
run: cargo install bootimage --debug
- name: Checkout Repository
uses: actions/checkout@v2
- name: Add thumbv7em-none-eabihf Target
run: rustup target add thumbv7em-none-eabihf
- name: Build for thumbv7em-none-eabihf
run: cargo build --target thumbv7em-none-eabihf
- name: Build for Linux
if: runner.os == 'Linux'
run: cargo rustc -- -C link-arg=-nostartfiles
- name: Build for macOS
if: runner.os == 'macOS'
run: cargo rustc -- -C link-args="-e __start -static -nostartfiles"
- name: Build for Windows
if: runner.os == 'Windows'
run: cargo rustc -- -C link-args="/ENTRY:_start /SUBSYSTEM:console"
- name: Install Rustup Components
run: rustup component add rust-src llvm-tools-preview
- name: Run `cargo bootimage`
uses: actions-rs/cargo@v1
with:
command: bootimage
check_formatting:
name: Check Formatting

11
Cargo.lock generated
View File

@@ -1,7 +1,16 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
version = 4
[[package]]
name = "blog_os"
version = "0.1.0"
dependencies = [
"bootloader",
]
[[package]]
name = "bootloader"
version = "0.9.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7bdfddac270bbdd45903296bc1caf29a7fdce6b326aaf0bbab7f04c5f98b7447"

View File

@@ -5,12 +5,7 @@ authors = ["Philipp Oppermann <dev@phil-opp.com>"]
edition = "2024"
[dependencies]
[profile.dev]
panic = "abort"
[profile.release]
panic = "abort"
bootloader = "0.9"
[[bin]]
name = "blog_os"

View File

@@ -1,25 +1,61 @@
# Blog OS (A Freestanding Rust Binary)
# Blog OS (A Minimal Rust Kernel)
[![Build Status](https://github.com/phil-opp/blog_os/workflows/Code/badge.svg?branch=post-01)](https://github.com/phil-opp/blog_os/actions?query=workflow%3A%22Code%22+branch%3Apost-01)
[![Build Status](https://github.com/phil-opp/blog_os/workflows/Code/badge.svg?branch=post-02)](https://github.com/phil-opp/blog_os/actions?query=workflow%3A%22Code%22+branch%3Apost-02)
This repository contains the source code for the [A Freestanding Rust Binary][post] post of the [Writing an OS in Rust](https://os.phil-opp.com) series.
This repository contains the source code for the [A Minimal Rust Kernel][post] post of the [Writing an OS in Rust](https://os.phil-opp.com) series.
[post]: https://os.phil-opp.com/freestanding-rust-binary/
[post]: https://os.phil-opp.com/minimal-rust-kernel/
**Check out the [master branch](https://github.com/phil-opp/blog_os) for more information.**
## Building
To build the project on Linux, run:
This project requires a nightly version of Rust because it uses some unstable features. At least nightly _2020-07-15_ is required for building. You might need to run `rustup update nightly --force` to update to the latest nightly even if some components such as `rustfmt` are missing it.
You can build the project by running:
```
cargo rustc -- -Clink-arg=-nostartfiles
cargo build
```
The entry point and the build command differ slightly on macOS and Windows. See the [post] for more information.
To create a bootable disk image from the compiled kernel, you need to install the [`bootimage`] tool:
[`bootimage`]: https://github.com/rust-osdev/bootimage
```
cargo install bootimage
```
After installing, you can create the bootable disk image by running:
```
cargo bootimage
```
This creates a bootable disk image in the `target/x86_64-blog_os/debug` directory.
Please file an issue if you have any problems.
## Running
You can run the disk image in [QEMU] through:
[QEMU]: https://www.qemu.org/
```
cargo run
```
[QEMU] and the [`bootimage`] tool need to be installed for this.
You can also write the image to an USB stick for booting it on a real machine. On Linux, the command for this is:
```
dd if=target/x86_64-blog_os/debug/bootimage-blog_os.bin of=/dev/sdX && sync
```
Where `sdX` is the device name of your USB stick. **Be careful** to choose the correct device name, because everything on that device is overwritten.
## License
Licensed under either of

1
rust-toolchain Normal file
View File

@@ -0,0 +1 @@
nightly

View File

@@ -3,8 +3,19 @@
use core::panic::PanicInfo;
static HELLO: &[u8] = b"Hello World!";
#[unsafe(no_mangle)]
pub extern "C" fn _start() -> ! {
let vga_buffer = 0xb8000 as *mut u8;
for (i, &byte) in HELLO.iter().enumerate() {
unsafe {
*vga_buffer.offset(i as isize * 2) = byte;
*vga_buffer.offset(i as isize * 2 + 1) = 0xb;
}
}
loop {}
}

16
x86_64-blog_os.json Normal file
View File

@@ -0,0 +1,16 @@
{
"llvm-target": "x86_64-unknown-none",
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128",
"arch": "x86_64",
"target-endian": "little",
"target-pointer-width": 64,
"target-c-int-width": 32,
"os": "none",
"executables": true,
"linker-flavor": "ld.lld",
"linker": "rust-lld",
"panic-strategy": "abort",
"disable-redzone": true,
"features": "-mmx,-sse,+soft-float",
"rustc-abi": "x86-softfloat"
}