mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Compare commits
114 Commits
8708b54756
...
post-02
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
83e6c0bc00 | ||
|
|
2b11ad8397 | ||
|
|
fa51f3adbf | ||
|
|
94d14d8d62 | ||
|
|
d9fa84edd6 | ||
|
|
9684f75819 | ||
|
|
d6cc562907 | ||
|
|
b44d8ab7fc | ||
|
|
c551fec1ce | ||
|
|
16bbb8f972 | ||
|
|
430e2143f8 | ||
|
|
86ffa24e8e | ||
|
|
c27eb1da9c | ||
|
|
a90a8bea67 | ||
|
|
688a21e4ed | ||
|
|
2265ddecad | ||
|
|
38604da92f | ||
|
|
c6990cb52d | ||
|
|
2bc4490404 | ||
|
|
7959b77ebd | ||
|
|
bebad6d5a9 | ||
|
|
b99c3f6d1d | ||
|
|
66c1792034 | ||
|
|
6393247a3b | ||
|
|
faa8d15cb7 | ||
|
|
26f1f5b896 | ||
|
|
1f49e2e9fe | ||
|
|
021762cf30 | ||
|
|
d8f280315f | ||
|
|
066c278277 | ||
|
|
96844f6519 | ||
|
|
1b86d7fd62 | ||
|
|
d658949f5b | ||
|
|
0e52ccbebb | ||
|
|
4e38e7ddf8 | ||
|
|
49dce7ada7 | ||
|
|
c42cee8d89 | ||
|
|
ebb9f0b8a7 | ||
|
|
cde3c8f955 | ||
|
|
4a4d704384 | ||
|
|
71d8a438f7 | ||
|
|
3a77cbe794 | ||
|
|
6f9cfce6f9 | ||
|
|
4bbaae24a4 | ||
|
|
44d7654ef6 | ||
|
|
f135aefae8 | ||
|
|
ffaac76876 | ||
|
|
5ae9f62f4d | ||
|
|
da0ee38f09 | ||
|
|
263e852dcc | ||
|
|
614e5b0e86 | ||
|
|
9ee42e0f5f | ||
|
|
c4672096d4 | ||
|
|
ffe1b6abd0 | ||
|
|
16ffe80fd5 | ||
|
|
07d8a22a53 | ||
|
|
b1bf0873ce | ||
|
|
46264d08ca | ||
|
|
fea4fa9c67 | ||
|
|
ddbe317099 | ||
|
|
0cc02f02c5 | ||
|
|
58629ea208 | ||
|
|
1c4ca04a2f | ||
|
|
60856aac6b | ||
|
|
7de138aa04 | ||
|
|
9e40f377db | ||
|
|
6b23fa3d28 | ||
|
|
99a7231d52 | ||
|
|
621364bd1b | ||
|
|
818bfb9646 | ||
|
|
ffd1bda509 | ||
|
|
bb8923cf56 | ||
|
|
dbe0802c6d | ||
|
|
9e1e3926fa | ||
|
|
7b00599bf8 | ||
|
|
72aa3a4580 | ||
|
|
5d7c4678de | ||
|
|
7197d8b18a | ||
|
|
e86c95bd24 | ||
|
|
47bcca33b3 | ||
|
|
5ed27923e8 | ||
|
|
b59720f6e1 | ||
|
|
63b97fe1f8 | ||
|
|
528bbd4e9f | ||
|
|
06d1c9ff81 | ||
|
|
c1064ad316 | ||
|
|
3c2a5ef0f6 | ||
|
|
64e7ea7b1a | ||
|
|
eee4718115 | ||
|
|
9237c875f3 | ||
|
|
62b89cd80f | ||
|
|
e1034aa9ac | ||
|
|
577c6b8cfc | ||
|
|
f308628db2 | ||
|
|
ab16203ed7 | ||
|
|
63f8f3a6eb | ||
|
|
013e6f2add | ||
|
|
d5cb74ac8b | ||
|
|
3bf2c66acc | ||
|
|
0e6ffc1a4f | ||
|
|
57484164ab | ||
|
|
1ca8cec4e6 | ||
|
|
2d5d6ee850 | ||
|
|
c9ce9d5735 | ||
|
|
f013172dd7 | ||
|
|
858a2f94c6 | ||
|
|
2ce4af4a65 | ||
|
|
8d730050d3 | ||
|
|
752a7ed84e | ||
|
|
59f9fe1e69 | ||
|
|
f4fd0e264a | ||
|
|
bbc19e132c | ||
|
|
f9ffee92c7 | ||
|
|
fd08b1a123 |
9
.cargo/config.toml
Normal file
9
.cargo/config.toml
Normal 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"
|
||||
21
.github/workflows/code.yml
vendored
21
.github/workflows/code.yml
vendored
@@ -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
11
Cargo.lock
generated
@@ -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"
|
||||
|
||||
12
Cargo.toml
12
Cargo.toml
@@ -2,12 +2,12 @@
|
||||
name = "blog_os"
|
||||
version = "0.1.0"
|
||||
authors = ["Philipp Oppermann <dev@phil-opp.com>"]
|
||||
edition = "2018"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
bootloader = "0.9"
|
||||
|
||||
[profile.dev]
|
||||
panic = "abort"
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
[[bin]]
|
||||
name = "blog_os"
|
||||
test = false
|
||||
bench = false
|
||||
|
||||
50
README.md
50
README.md
@@ -1,25 +1,61 @@
|
||||
# Blog OS (A Freestanding Rust Binary)
|
||||
# Blog OS (A Minimal Rust Kernel)
|
||||
|
||||
[](https://github.com/phil-opp/blog_os/actions?query=workflow%3A%22Code%22+branch%3Apost-01)
|
||||
[](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
1
rust-toolchain
Normal file
@@ -0,0 +1 @@
|
||||
nightly
|
||||
13
src/main.rs
13
src/main.rs
@@ -3,8 +3,19 @@
|
||||
|
||||
use core::panic::PanicInfo;
|
||||
|
||||
#[no_mangle]
|
||||
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
16
x86_64-blog_os.json
Normal 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"
|
||||
}
|
||||
Reference in New Issue
Block a user