diff --git a/.cargo/config.toml b/.cargo/config.toml index 638fd35..450058d 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,5 +1,6 @@ -[build] -target = "x86_64-rustboot.json" # target OS specifications - [unstable] build-std = ["core", "compiler_builtins"] # recompile these +build-std-features = ["compiler-builtins-mem"] + +[build] +target = "x86_64-rustboot.json" # target OS specifications diff --git a/Cargo.toml b/Cargo.toml index ae63927..c6cfebd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,15 @@ name = "rustboot" version = "0.1.0" edition = "2024" -authors = ["mtgmonkey"] +authors = [ "mtgmonkey" ] + +# quit QEMU +[package.metadata.bootimage] +test-args = [ "device", "isa-debug-exit,iobase=0xf4,iosize=0x04", +"-serial", "stdio", +"-display", "none" ] +test-success-exit-code = 33 # (0x10 << 1) | 1 +test-timeout = 30 # in seconds [lib] crate-type = ["staticlib"] # library that contains all dependencies @@ -17,8 +25,8 @@ x86_64 = "0.15" version = "1.5" features = ["spin_no_std"] -#[profile.dev] -#panic = "abort" +[profile.dev] +panic = "abort" -#[profile.release] -#panic = "abort" +[profile.release] +panic = "abort" diff --git a/Cargo.toml.0 b/Cargo.toml.0 deleted file mode 100644 index 0e541a6..0000000 --- a/Cargo.toml.0 +++ /dev/null @@ -1,35 +0,0 @@ -[package] -name = "rustos" -version = "0.1.0" -edition = "2024" -authors = [ "mtgmonkey" ] - -# Special debug shutdown device in QEMU -[package.metadata.bootimage] -test-args = ["-device", "isa-debug-exit,iobase=0xf4,iosize=0x04", -"-serial", "stdio", -"-display", "none"] -test-success-exit-code = 33 # (0x10 << 1) | 1 -test-timeout = 30 # in seconds - -[dependencies] -bootloader = { version = "0.9", features = ["map_physical_memory"] } -linked_list_allocator = "0.9.0" -pc-keyboard = "0.7.0" -pic8259 = "0.10.1" -spin = "0.5.2" -uart_16550 = "0.2.0" -volatile = "0.2.6" -x86_64 = "0.14.2" - -[dependencies.lazy_static] -version = "1.0" -features = ["spin_no_std"] - -[[test]] -name = "should_panic" -harness = false - -[[test]] -name = "stack_overflow" -harness = false diff --git a/Makefile b/Makefile deleted file mode 100644 index a9d257e..0000000 --- a/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -all: - mkdir temp - nasm -f elf64 src/multiboot_header.asm -o temp/multiboot_header.asm.o - nasm -f elf64 src/long_mode_init.asm -o temp/long_mode_init.asm.o - nasm -f elf64 src/boot.asm -o temp/boot.asm.o - echo "Run 'RUST_TARGET_PATH=(pwd)" - cargo update --verbose - cargo build --target x86_64-rustboot - ld -n -o temp/kernel.bin --gc-sections -T linker.ld temp/multiboot_header.asm.o temp/long_mode_init.asm.o temp/boot.asm.o target/x86_64-rustboot/debug/librustboot.a - mkdir isofiles - mkdir isofiles/boot - mkdir isofiles/boot/grub - cp temp/kernel.bin isofiles/boot/kernel.bin - cp src/grub.cfg isofiles/boot/grub/grub.cfg - rm -rf temp - grub-mkrescue -o build/os.iso isofiles 2> /dev/null - rm -rf isofiles - -clean: - rm -rf temp - rm -rf isofiles - -run: - qemu-system-x86_64 -cdrom build/os.iso diff --git a/build/os.iso b/build/os.iso index 1e6e8cf..1168be6 100644 Binary files a/build/os.iso and b/build/os.iso differ diff --git a/flake.nix b/flake.nix index 4bf7d7c..8060117 100644 --- a/flake.nix +++ b/flake.nix @@ -1,13 +1,14 @@ { - description = "Rust shells"; - + description = "Rustup"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; rust-overlay.url = "github:oxalica/rust-overlay"; }; - outputs = inputs @ {...}: let additionalPackages = [ + pkgs.cowsay + pkgs.just + pkgs.nasm pkgs.qemu pkgs.xorriso ]; @@ -15,7 +16,6 @@ system = "x86_64-linux"; overlays = [(import inputs.rust-overlay)]; }; - rustup = { package = pkgs.rustup; path = "${pkgs.rustup}/lib/rustlib.src/rust/library"; @@ -23,12 +23,18 @@ in { devShell.x86_64-linux = pkgs.mkShell { packages = [ - rustup.package additionalPackages + rustup.package ]; - env = { - RUST_SRC_PATH = rustup.path; - }; + shellHook = '' + echo "Run 'exit' if you don't see something cowsaid." && + export RUST_SRC_PATH=rustup.path && + rustup default nightly && + rustup component add rust-src && + rustup component add rust-analyzer && + export PS1='\h@\[\e[30;48;5;202;1m\]rustboot\[\e[0m\]|\w\\$ ' && + cowsay "Welcome to rust-boot! Run 'just' to build and 'just run' to launch QEMU!" + ''; }; }; } diff --git a/justfile b/justfile index bac7dac..b97b18a 100644 --- a/justfile +++ b/justfile @@ -1,24 +1,34 @@ -all: - mkdir temp - nasm -f elf64 src/multiboot_header.asm -o temp/multiboot_header.asm.o - nasm -f elf64 src/long_mode_init.asm -o temp/long_mode_init.asm.o - nasm -f elf64 src/boot.asm -o temp/boot.asm.o - cargo update --verbose +all: setup asm rust link image clean + +setup: + mkdir temp + +asm: + nasm -f elf64 src/asm/multiboot_header.asm -o temp/multiboot_header.asm.o + nasm -f elf64 src/asm/long_mode_init.asm -o temp/long_mode_init.asm.o + nasm -f elf64 src/asm/boot.asm -o temp/boot.asm.o + +rust: cargo build - ld -n -o temp/kernel.bin --gc-sections -T linker.ld temp/multiboot_header.asm.o temp/long_mode_init.asm.o temp/boot.asm.o target/x86_64-rustboot/debug/librustboot.a + +link: + ld -n -o temp/kernel.bin --gc-sections -T link-cfg/linker.ld temp/multiboot_header.asm.o temp/long_mode_init.asm.o temp/boot.asm.o target/x86_64-rustboot/debug/librustboot.a + +image: mkdir isofiles mkdir isofiles/boot mkdir isofiles/boot/grub cp temp/kernel.bin isofiles/boot/kernel.bin - cp src/grub.cfg isofiles/boot/grub/grub.cfg - rm -rf temp + cp link-cfg/grub.cfg isofiles/boot/grub/grub.cfg grub-mkrescue -o build/os.iso isofiles 2> /dev/null - rm -rf isofiles clean: rm -rf temp rm -rf isofiles - rm -rf target + +scrub: clean + cargo clean + cargo update --verbose run: qemu-system-x86_64 -cdrom build/os.iso diff --git a/src/grub.cfg b/link-cfg/grub.cfg similarity index 100% rename from src/grub.cfg rename to link-cfg/grub.cfg diff --git a/linker.ld b/link-cfg/linker.ld similarity index 100% rename from linker.ld rename to link-cfg/linker.ld diff --git a/src/boot.asm b/src/asm/boot.asm similarity index 100% rename from src/boot.asm rename to src/asm/boot.asm diff --git a/src/long_mode_init.asm b/src/asm/long_mode_init.asm similarity index 100% rename from src/long_mode_init.asm rename to src/asm/long_mode_init.asm diff --git a/src/multiboot_header.asm b/src/asm/multiboot_header.asm similarity index 100% rename from src/multiboot_header.asm rename to src/asm/multiboot_header.asm