diff --git a/.gitignore b/.gitignore index 32fa216..8a4757c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ -userland/root_fs/mnt/ target/ .gdb_history !*/.gitkeep __pycache__/ debug.log +/disk/ +/limine/ +/disk.img diff --git a/ableos/.cargo/config.toml b/ableos/.cargo/config.toml index b747c1c..7b397ba 100644 --- a/ableos/.cargo/config.toml +++ b/ableos/.cargo/config.toml @@ -8,7 +8,6 @@ build-std-features = ["compiler-builtins-mem"] [target.'cfg(target_arch = "x86_64")'] rustflags = ["-C", "target-feature=+rdrand"] -runner = "bootimage runner" [target.riscv64gc-unknown-none-elf] rustflags = "-C link-arg=-Tableos/src/arch/riscv/virt.lds" diff --git a/ableos/Cargo.toml b/ableos/Cargo.toml index 5c0639f..9536237 100644 --- a/ableos/Cargo.toml +++ b/ableos/Cargo.toml @@ -8,52 +8,6 @@ version = "0.1.1" panic = "abort" [package.metadata.bootimage] -run-command = [ - "qemu-system-x86_64", - - "-device", - "piix4-ide,id=ide", - - "-drive", - "file={},format=raw,if=none,id=disk", - - "-device", - "ide-hd,drive=disk,bus=ide.0" -] -run-args = [ - # "--nodefaults", - "-cpu", - "Broadwell-v3", - "-m", - "4G", - "-serial", - "stdio", - "-smp", - "cores=2", - - - "-soundhw", - "pcspk", - - - # "-device", - # "VGA", - # "-device", - # "virtio-gpu-pci", - - "-device", - "vmware-svga", - - "-device", - "sb16", - - - # "-machine", "pcspk-audiodev=0", - - # "-qmp", - # "unix:../qmp-sock,server,nowait", -] - test-args = [ "-device", "isa-debug-exit,iobase=0xf4,iosize=0x04", diff --git a/base/README.md b/base/README.md new file mode 100644 index 0000000..c251711 --- /dev/null +++ b/base/README.md @@ -0,0 +1,4 @@ +# Base Root Filesystem + +This is the base root filesystem for ableOS. It's used by tepbuild while +building the disk image. diff --git a/base/boot/limine.cfg b/base/boot/limine.cfg new file mode 100644 index 0000000..2229358 --- /dev/null +++ b/base/boot/limine.cfg @@ -0,0 +1,17 @@ +${ABLEOS_KERNEL}=boot:///boot/kernel +# TODO: Make a boot background image for ableOS +# ${WALLPAPER_PATH}=boot:///boot/bg.bmp + +DEFAULT_ENTRY=1 +TIMEOUT=3 +VERBOSE=yes + +# Terminal related settings +# TERM_WALLPAPER=${WALLPAPER_PATH} +TERM_BACKDROP=008080 + +:ableOS + COMMENT=Default ableOS boot entry. + PROTOCOL=limine + KERNEL_PATH=${ABLEOS_KERNEL} + KERNEL_CMDLINE= diff --git a/base/home/able/bins/aos_test.wasm b/base/home/able/bins/aos_test.wasm new file mode 100755 index 0000000..b9350d9 Binary files /dev/null and b/base/home/able/bins/aos_test.wasm differ diff --git a/base/home/able/bins/weealloc_test.wasm b/base/home/able/bins/weealloc_test.wasm new file mode 100755 index 0000000..7af3a9f Binary files /dev/null and b/base/home/able/bins/weealloc_test.wasm differ diff --git a/base/home/able/configs/qwerty.keymap b/base/home/able/configs/qwerty.keymap new file mode 100644 index 0000000..95db614 --- /dev/null +++ b/base/home/able/configs/qwerty.keymap @@ -0,0 +1,252 @@ +# Able doesn't have a full keyboard +0-NONE +1- +2- +3-BACKSPACE +4- +5- +6- +7- +8- +9-TAB +10- +11- +12- +13-ENTER +14- +15- +16-SHIFT +17-CONTROL +18-ALT +19-PAUSE +20-CAPS_LOCK +21- +22- +23- +24- +25- +26- +27- +28- +29- +30- +31- +32-SPACE +33-PAGE_UP +34-PAGE_DOWN +35-END +36-HOME +37-ARROW_LEFT +38-ARROW_UP +39-ARROW_RIGHT +40-ARROW_DOWN +41- +42- +43- +44- +45-INSERT +46-DELETE +47- +48-0 +49-1 +50-2 +51-3 +52-4 +53-5 +54-6 +55-7 +56-8 +57-9 +58- +59-SEMICOLON +60- +61-EQUAL +62- +63- +64- +65-a +66-b +67-c +68-d +69-e +70-f +71-g +72-h +73-i +74-j +75-k +76-l +77-m +78-n +79-o +80-p +81-q +82-r +83-s +84-t +85-u +86-v +87-w +88-x +89-y +90-z +91- +92- +93- +94- +95- +96- +97- +98- +99- +100- +101- +102- +103- +106- +107- +108- +109- +110- +111- +112-FUNCTION_1 +113-FUNCTION_2 +114-FUNCTION_3 +115-FUNCTION_4 +116-FUNCTION_5 +117-FUNCTION_6 +118-FUNCTION_7 +119-FUNCTION_8 +120-FUNCTION_9 +121-FUNCTION_10 +122-FUNCTION_11 +123-FUNCTION_12 +124- +125- +126- +127- +128- +129- +130- +131- +132- +134- +135- +136- +137- +138- +139- +140- +141- +142- +143- +145-SCROLL_LOCK +146- +147- +148- +149- +150- +151- +152- +153- +154- +155- +156- +157- +158- +159- +160- +161- +162- +163- +164- +165- +166- +167- +168- +169- +170- +171- +172- +173-MINUS +174- +175- +176- +177- +178- +179- +180- +181- +182- +183- +184- +185- +186- +187- +188-COMMA +189- +190-PERIOD +191-FORWARD_SLASH +192-GRAVE +193- +194- +195- +196- +197- +198- +199- +200- +201- +202- +203- +204- +205- +206- +207- +208- +209- +210- +211- +212- +213- +214- +215- +216- +218- +219-BRACKET_LEFT +220-BACK_SLASH +221-BRACKET_RIGHT +222-QUOTE +223- +224- +225- +226- +227- +228- +229- +230- +231- +232- +233- +234- +235- +236- +237- +238- +239- +240- +241- +242- +243- +244- +245- +246- +247- +248- +249- +250- +251- +252- +253- +254- +255- diff --git a/base/home/able/kernel.md b/base/home/able/kernel.md new file mode 100644 index 0000000..b4b1e54 --- /dev/null +++ b/base/home/able/kernel.md @@ -0,0 +1,4 @@ +Hi there :>$RED$ +hi +$GREEN$ +hi 3 diff --git a/base/home/able/layout.txt b/base/home/able/layout.txt new file mode 100644 index 0000000..73c3402 --- /dev/null +++ b/base/home/able/layout.txt @@ -0,0 +1,14 @@ +boot/ +├─ kernel.img +home/ +├─ able/ +│ ├─ bins/ +│ ├─ config/ +│ │ ├─ able_edit/ +│ │ │ ├─ config.toml +│ ├─ irl_pic.png +│ ├─ password.txt +system/ +├─ bins/ +├─ configs/ +│ ├─ kernel.toml \ No newline at end of file diff --git a/repbuild/src/main.rs b/repbuild/src/main.rs index bc4d571..990e469 100644 --- a/repbuild/src/main.rs +++ b/repbuild/src/main.rs @@ -5,7 +5,7 @@ * SPDX-License-Identifier: MPL-2.0 */ -use std::{fs, process::Command}; +use std::{fs::{self, File}, process::Command}; use colored::*; @@ -15,6 +15,7 @@ struct Options { } enum Subcommand { + BuildImage, Doc, Help, Run, @@ -27,6 +28,7 @@ enum Subcommand { impl Subcommand { fn from_str>(str: S) -> Subcommand { match str.as_ref() { + "build-image" => Subcommand::BuildImage, "doc" => Subcommand::Doc, "help" => Subcommand::Help, "run" | "r" => Subcommand::Run, @@ -48,6 +50,142 @@ fn main() { let options = options(); match options.subcommand { + Subcommand::BuildImage => { + let machine_text = options.arguments.get(0).cloned().unwrap_or_default(); + + match machine(machine_text) { + MachineType::X86_64 => { + // Cleanup + // NOTE: we are not unwrapping these, as we don't want this to fail if they + // don't exist yet, probably not the best idea tho. + // FIXME: figure out a better way to ignore errors about these not existing + #[allow(unused_must_use)] + { + fs::remove_dir_all("./limine"); + fs::remove_dir_all("./disk"); + fs::remove_file("./disk.img"); + } + + // Build ableOS in release mode + Command::new("cargo") + .args(["build", "--release"]) + .current_dir(fs::canonicalize("./ableos").unwrap()) + .status() + .unwrap(); + + // Create disk directory + fs::create_dir("./disk").unwrap(); + + // Clone limine 3.X binaries + Command::new("git") + .arg("clone") + .arg("https://github.com/limine-bootloader/limine.git") + .arg("--branch=v3.0-branch-binary") + .arg("--depth=1") + .status() + .unwrap(); + + println!("{}", "Building limine".bold()); + Command::new("make") + .args(["-C", "limine"]) + .status() + .unwrap(); + + println!("{}", "Allocating new disk image".bold()); + Command::new("dd") + .args(["if=/dev/zero", "of=disk.img", "count=1", "bs=256MiB"]) + .status() + .unwrap(); + + println!("{}", "Partitioning disk image".bold()); + Command::new("sudo") + .args(["sfdisk", "disk.img"]) + .stdin(File::open("./sfdisk-config").unwrap()) + .status() + .unwrap(); + + // Setup loopback device for disk.img, with partitions + // FIXME: don't assume that /dev/loop0 is empty + Command::new("sudo") + .arg("losetup") + .args(["-P", "/dev/loop0", "disk.img"]) + .status() + .unwrap(); + + println!("{}", "Creating ext2 filesystem on /dev/loop0p1".bold()); + Command::new("sudo") + .arg("mkfs.ext2") + .arg("/dev/loop0p1") + .status() + .unwrap(); + + println!("{}", "Mounting filesystem".bold()); + Command::new("sudo") + .arg("mount") + .args(["/dev/loop0p1", "./disk"]) + .status() + .unwrap(); + + // copy ./base/* over to ./disk + Command::new("sudo") + .args(["sh", "-c"]) + .arg("cp -r ./base/* ./disk") + .status() + .unwrap(); + + // copy ./limine/limine.sys over to ./disk/boot + Command::new("sudo") + .arg("cp") + .args(["./limine/limine.sys", "./disk/boot"]) + .status() + .unwrap(); + + // copy the kernel over to ./disk/boot/kernel + Command::new("sudo") + .arg("cp") + .arg("./target/x86_64-ableos/release/ableos") + .arg("./disk/boot/kernel") + .status() + .unwrap(); + + // TODO: build the userspace programs and copy them over + + // unmount the fs + Command::new("sudo") + .arg("umount") + .arg("./disk") + .status() + .unwrap(); + + // remove the loopback device + Command::new("sudo") + .arg("losetup") + .args(["-d", "/dev/loop0"]) + .status() + .unwrap(); + + println!("{}", "Deploying limine".bold()); + Command::new("./limine/limine-deploy") + .arg("./disk.img") + .status() + .unwrap(); + } + MachineType::Unknown(unknown) => { + eprintln!( + "{}: unknown machine type `{}`", + "error".red().bold(), + unknown.bold(), + ); + eprintln!("expected one of x86_64, riscv64 or aarch64"); + } + _ => { + eprintln!( + "{}: build-image not implemented for this machine type", + "error".red().bold(), + ); + } + } + } Subcommand::Test => { Command::new("cargo") .args(["test", "--target=json_targets/x86_64-ableos.json"]) @@ -100,18 +238,137 @@ fn main() { match machine(machine_text) { MachineType::X86_64 if debug => { + // Build ableOS Command::new("cargo") - .args(["run", "--", "-S", "-gdb", "tcp:9000"]) + .arg("build") .current_dir(fs::canonicalize("./ableos").unwrap()) .status() .unwrap(); + + // Setup loopback device for disk.img, with partitions + // FIXME: don't do ths if running without changes + Command::new("sudo") + .arg("losetup") + .args(["-P", "/dev/loop0", "disk.img"]) + .status() + .unwrap(); + + // mount the root fs to ./disk + Command::new("sudo") + .arg("mount") + .args(["/dev/loop0p1", "./disk"]) + .status() + .unwrap(); + + // copy the kernel over to ./disk/boot/kernel + Command::new("sudo") + .arg("cp") + .arg("./target/x86_64-ableos/debug/ableos") + .arg("./disk/boot/kernel") + .status() + .unwrap(); + + // unmount the root fs + Command::new("sudo") + .arg("umount") + .arg("./disk") + .status() + .unwrap(); + + // remove loopback device + Command::new("sudo") + .arg("losetup") + .args(["-d", "/dev/loop0"]) + .status() + .unwrap(); + + // run qemu with "-S", "-gdb", "tcp:9000" + Command::new("qemu-system-x86_64") + .args(["-device", "piix4-ide,id=ide"]) + .arg("-drive") + .arg("file=./disk.img,format=raw,if=none,id=disk") + .args(["-device", "ide-hd,drive=disk,bus=ide.0"]) + // .arg("--nodefaults") + .args(["-cpu", "Broadwell-v3"]) + .args(["-m", "4G"]) + .args(["-serial", "stdio"]) + .args(["-smp", "cores=2"]) + .args(["-soundhw", "pcspk"]) + // .args(["-device", "VGA"]) + // .args(["-device", "virtio-gpu-pci"]) + .args(["-device", "vmware-svga"]) + .args(["-device", "sb16"]) + // .args(["-machine", "pcspk-audiodev=0"]) + // .args(["-qmp", "unix:../qmp-sock,server,nowait"]) + .args(["-S", "-gdb", "tcp:9000"]) + .status() + .unwrap(); } MachineType::X86_64 => { + // Build ableOS Command::new("cargo") - .args(["run", "--release"]) + .args(["build", "--release"]) .current_dir(fs::canonicalize("./ableos").unwrap()) .status() .unwrap(); + + // Setup loopback device for disk.img, with partitions + // FIXME: don't do ths if running without changes + Command::new("sudo") + .arg("losetup") + .args(["-P", "/dev/loop0", "disk.img"]) + .status() + .unwrap(); + + // mount the root fs to ./disk + Command::new("sudo") + .arg("mount") + .args(["/dev/loop0p1", "./disk"]) + .status() + .unwrap(); + + // copy the kernel over to ./disk/boot/kernel + Command::new("sudo") + .arg("cp") + .arg("./target/x86_64-ableos/release/ableos") + .arg("./disk/boot/kernel") + .status() + .unwrap(); + + // unmount the root fs + Command::new("sudo") + .arg("umount") + .arg("./disk") + .status() + .unwrap(); + + // remove loopback device + Command::new("sudo") + .arg("losetup") + .args(["-d", "/dev/loop0"]) + .status() + .unwrap(); + + // run qemu + Command::new("qemu-system-x86_64") + .args(["-device", "piix4-ide,id=ide"]) + .arg("-drive") + .arg("file=./disk.img,format=raw,if=none,id=disk") + .args(["-device", "ide-hd,drive=disk,bus=ide.0"]) + // .arg("--nodefaults") + .args(["-cpu", "Broadwell-v3"]) + .args(["-m", "4G"]) + .args(["-serial", "stdio"]) + .args(["-smp", "cores=2"]) + .args(["-soundhw", "pcspk"]) + // .args(["-device", "VGA"]) + // .args(["-device", "virtio-gpu-pci"]) + .args(["-device", "vmware-svga"]) + .args(["-device", "sb16"]) + // .args(["-machine", "pcspk-audiodev=0"]) + // .args(["-qmp", "unix:../qmp-sock,server,nowait"]) + .status() + .unwrap(); } MachineType::RiscV64 if debug => { eprintln!( diff --git a/sfdisk-config b/sfdisk-config new file mode 100644 index 0000000..8785fdb --- /dev/null +++ b/sfdisk-config @@ -0,0 +1 @@ +,,,-