Hello, World!

This commit is contained in:
Felix Suchert 2022-03-27 18:41:22 +02:00
parent fa2420d5d9
commit 656d15e5d5
Signed by: feliix42
GPG key ID: 24363525EA0E8A99
5 changed files with 47 additions and 2 deletions

View file

@ -1,6 +1,9 @@
[build] [build]
target = "x86_64_plain_os.json" target = "x86_64_plain_os.json"
[target.'cfg(target_os = "none")']
runner = "bootimage runner"
[unstable] [unstable]
# enable implementations for memset, memcpy and memcmp etc. # enable implementations for memset, memcpy and memcmp etc.
build-std-features = ["compiler-builtins-mem"] build-std-features = ["compiler-builtins-mem"]

9
Cargo.lock generated
View file

@ -2,6 +2,15 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 3
[[package]]
name = "bootloader"
version = "0.9.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de78decc37247c7cfac5dbf3495c7298c6ac97cb355161caa7e15969c6648e6c"
[[package]] [[package]]
name = "plain_os" name = "plain_os"
version = "0.1.0" version = "0.1.0"
dependencies = [
"bootloader",
]

View file

@ -14,3 +14,4 @@ panic = "abort" # disable stack unwinding on panic
panic = "abort" # disable stack unwinding on panic panic = "abort" # disable stack unwinding on panic
[dependencies] [dependencies]
bootloader = "0.9"

21
README.md Normal file
View file

@ -0,0 +1,21 @@
# PlainOS, something that may operate your system
This may or may not do things in the future.
## Building
Building the project requires Rust Nightly and the `bootimage` tool since I've yet to upgrade my `bootloader` dependency:
```bash
rustup override set nightly
rustup component add rust-src --toolchain nightly # needed for building `core` from source
cargo install bootimage
rustup component add llvm-tools-preview
```
You'll need QEMU to run the kernel. To build the project and run it in `qemu`, run:
```bash
cargo run
```

View file

@ -3,15 +3,26 @@
use core::panic::PanicInfo; use core::panic::PanicInfo;
static HELLO: &[u8] = b"Hello World!";
/// This function defines the panic handler /// This function defines the panic handler
#[panic_handler] #[panic_handler]
fn panic(_info: &PanicInfo) -> ! { fn panic(_info: &PanicInfo) -> ! {
loop{} loop{}
} }
// this function is the entry point, since the linker looks for a function
// named `_start` by default
#[no_mangle] #[no_mangle]
pub extern "C" fn _start() -> ! { pub extern "C" fn _start() -> ! {
// this function is the entry point, since the linker looks for a function let vga_buffer = 0xb8000 as *mut u8;
// named `_start` by default
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 {} loop {}
} }