diff --git a/.cargo/config.toml b/.cargo/config.toml index 9b4e124..f378733 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,6 +1,9 @@ [build] target = "x86_64_plain_os.json" +[target.'cfg(target_os = "none")'] +runner = "bootimage runner" + [unstable] # enable implementations for memset, memcpy and memcmp etc. build-std-features = ["compiler-builtins-mem"] diff --git a/Cargo.lock b/Cargo.lock index a083e15..22b0362 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "bootloader" +version = "0.9.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de78decc37247c7cfac5dbf3495c7298c6ac97cb355161caa7e15969c6648e6c" + [[package]] name = "plain_os" version = "0.1.0" +dependencies = [ + "bootloader", +] diff --git a/Cargo.toml b/Cargo.toml index 1be67dc..ee7c812 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,3 +14,4 @@ panic = "abort" # disable stack unwinding on panic panic = "abort" # disable stack unwinding on panic [dependencies] +bootloader = "0.9" diff --git a/README.md b/README.md new file mode 100644 index 0000000..51aba56 --- /dev/null +++ b/README.md @@ -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 +``` + diff --git a/src/main.rs b/src/main.rs index c388797..5cec221 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,15 +3,26 @@ use core::panic::PanicInfo; +static HELLO: &[u8] = b"Hello World!"; + /// This function defines the panic handler #[panic_handler] fn panic(_info: &PanicInfo) -> ! { loop{} } +// this function is the entry point, since the linker looks for a function +// named `_start` by default #[no_mangle] pub extern "C" fn _start() -> ! { - // this function is the entry point, since the linker looks for a function - // named `_start` by default + 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 {} }