Initial commit

This commit is contained in:
xqtc161 2024-06-18 12:36:23 +02:00
commit f0da866ed7
11 changed files with 477 additions and 0 deletions

5
.cargo/config.toml Normal file
View file

@ -0,0 +1,5 @@
# [source.crates-io]
# replace-with = "vendored-sources"
#
# [source.vendored-sources]
# directory = "vendor"

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

188
Cargo.lock generated Normal file
View file

@ -0,0 +1,188 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "autocfg"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
[[package]]
name = "bitflags"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1"
[[package]]
name = "bowotloader"
version = "0.1.0"
dependencies = [
"bitflags",
"multiboot",
"multiboot2",
"spin",
"talc",
]
[[package]]
name = "derive_more"
version = "0.99.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.66",
]
[[package]]
name = "lock_api"
version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17"
dependencies = [
"autocfg",
"scopeguard",
]
[[package]]
name = "log"
version = "0.4.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c"
[[package]]
name = "multiboot"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f87ad3b7b7bcf5da525c22221e3eb3a020cd68b2d55ae62f629c15e8bc3bd56e"
dependencies = [
"paste",
]
[[package]]
name = "multiboot2"
version = "0.20.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad7ef048d4783355163fd0c874aac3db54b919dc6a86dc29bb13f67308b114b0"
dependencies = [
"bitflags",
"derive_more",
"log",
"ptr_meta",
"uefi-raw",
]
[[package]]
name = "paste"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
[[package]]
name = "proc-macro2"
version = "1.0.85"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23"
dependencies = [
"unicode-ident",
]
[[package]]
name = "ptr_meta"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bcada80daa06c42ed5f48c9a043865edea5dc44cbf9ac009fda3b89526e28607"
dependencies = [
"ptr_meta_derive",
]
[[package]]
name = "ptr_meta_derive"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bca9224df2e20e7c5548aeb5f110a0f3b77ef05f8585139b7148b59056168ed2"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "quote"
version = "1.0.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"
dependencies = [
"proc-macro2",
]
[[package]]
name = "scopeguard"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "spin"
version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
dependencies = [
"lock_api",
]
[[package]]
name = "syn"
version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "syn"
version = "2.0.66"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "talc"
version = "4.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04be12ec299aadd63a0bf781d893e4b6139d33cdca6dcd6f6be31f849cedcac8"
dependencies = [
"lock_api",
]
[[package]]
name = "uefi-raw"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efa8716f52e8cab8bcedfd5052388a0f263b69fe5cc2561548dc6a530678333c"
dependencies = [
"bitflags",
"ptr_meta",
"uguid",
]
[[package]]
name = "uguid"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab14ea9660d240e7865ce9d54ecdbd1cd9fa5802ae6f4512f093c7907e921533"
[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"

13
Cargo.toml Normal file
View file

@ -0,0 +1,13 @@
[package]
name = "bowotloader"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
talc = "4.4.1"
spin = "0.9.8"
multiboot = "0.8.0"
multiboot2 = "0.20.2"
bitflags = "2.5.0"

18
Dockerfile Normal file
View file

@ -0,0 +1,18 @@
FROM debian:bullseye@sha256:2c7a92a41cb814c00e7d455b2bc0c90ccdb9a4ced2ffdc10e562c7a84a186032
RUN apt-get update && apt-get install -y openssh-server gcc make dpkg-dev curl
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain nightly --profile default -y
# RUN /root/.cargo/rustup default nightly
# RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-host x86_64-unknown-linux-gnu --default-toolchain nightly --profile default -y
RUN /root/.cargo/bin/rustup target add x86_64-unknown-none
RUN /root/.cargo/bin/rustup component add rust-src --target nightly-x86_64-unknown-none
WORKDIR /root
# RUN /root/.cargo/bin/cargo init
COPY Cargo.toml /root/Cargo.toml
COPY ./src/ /root/src
# COPY ./conf/ /root/conf
# COPY ./.cargo /root/.cargo
# RUN RUSTFLAGS='-Zlocation-detail=none' /root/.cargo/bin/cargo +nightly build -Zbuild-std --target x86_64-unknown-none --release
RUN /root/.cargo/bin/cargo +nightly build --target x86_64-unknown-none --release
WORKDIR /wd
RUN echo "[+] Building..."
ENTRYPOINT ["/bin/bash", "-c", "/root/.cargo/bin/cargo +nightly build --target x86_64-unknown-none --release"]

12
build.nu Normal file
View file

@ -0,0 +1,12 @@
def compile [] {
print "[*] Running rustc..."
do {
print "[*] Starting container..."
print $"[*] Docker output for (pwd|path basename)"
docker build --network=host -t (pwd|path basename) .
docker run -it --network=host -v $"(pwd):/wd" (pwd|path basename)
}
print "[+] Built succesfully"
}
compile

113
flake.lock Normal file
View file

@ -0,0 +1,113 @@
{
"nodes": {
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1709336216,
"narHash": "sha256-Dt/wOWeW6Sqm11Yh+2+t0dfEWxoMxGBvv3JpIocFl9E=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "f7b3c975cf067e56e7cda6cb098ebe3fb4d74ca2",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1710272261,
"narHash": "sha256-g0bDwXFmTE7uGDOs9HcJsfLFhH7fOsASbAuOzDC+fhQ=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "0ad13a6833440b8e238947e47bea7f11071dc2b2",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-lib": {
"locked": {
"dir": "lib",
"lastModified": 1709237383,
"narHash": "sha256-cy6ArO4k5qTx+l5o+0mL9f5fa86tYUX3ozE1S+Txlds=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "1536926ef5621b09bba54035ae2bb6d806d72ac8",
"type": "github"
},
"original": {
"dir": "lib",
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1708475490,
"narHash": "sha256-g1v0TsWBQPX97ziznfJdWhgMyMGtoBFs102xSYO4syU=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "0e74ca98a74bc7270d28838369593635a5db3260",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs",
"systems": "systems",
"treefmt-nix": "treefmt-nix"
}
},
"systems": {
"flake": false,
"locked": {
"lastModified": 1,
"narHash": "sha256-8wkkYGr1dPSnX9oVMX8D6dTOROXKOYpBTKfriA0sEBI=",
"path": "/nix/store/y7l8hkx9725h2069vx2jy8n63hr9pjsv-source/flake.systems.nix",
"type": "path"
},
"original": {
"path": "/nix/store/y7l8hkx9725h2069vx2jy8n63hr9pjsv-source/flake.systems.nix",
"type": "path"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1710278050,
"narHash": "sha256-Oc6BP7soXqb8itlHI8UKkdf3V9GeJpa1S39SR5+HJys=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "35791f76524086ab4b785a33e4abbedfda64bd22",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

81
flake.nix Normal file
View file

@ -0,0 +1,81 @@
# Nix flake for reproducible builds & development environments.
# TL;DR:
# either `curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install`
# or https://github.com/DeterminateSystems/nix-installer
# and then `nix build` or `nix develop`
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
#systems.url = "github:nix-systems/default";
# Dev tools
treefmt-nix.url = "github:numtide/treefmt-nix";
};
inputs.systems.url = "./flake.systems.nix";
inputs.systems.flake = false;
outputs = inputs:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = import inputs.systems;
imports = [
inputs.treefmt-nix.flakeModule
];
perSystem = { config, self', pkgs, lib, system, ... }:
let
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
nonRustDeps = [
pkgs.libiconv
pkgs.pkg-config
pkgs.openssl
];
rust-toolchain = pkgs.symlinkJoin {
name = "rust-toolchain";
paths = [ pkgs.rustc pkgs.cargo pkgs.cargo-watch pkgs.rustPlatform.rustcSrc ];
};
in
{
# Rust package
packages.default = pkgs.rustPlatform.buildRustPackage {
inherit (cargoToml.package) name version;
nativeBuildInputs = nonRustDeps;
buildInputs = nonRustDeps;
src = ./.;
cargoLock.lockFile = ./Cargo.lock;
};
# Rust dev environment
devShells.default = pkgs.mkShell {
inputsFrom = [
config.treefmt.build.devShell
];
shellHook = ''
# For rust-analyzer 'hover' tooltips to work.
export RUST_SRC_PATH=${pkgs.rustPlatform.rustLibSrc}
echo $RUST_SRC_PATH
echo
echo "Run 'just <recipe>' to get started"
just
'';
buildInputs = nonRustDeps;
nativeBuildInputs = with pkgs; [
just
rust-toolchain
];
RUST_BACKTRACE = 1;
};
# Add your auto-formatters here.
# cf. https://numtide.github.io/treefmt/
treefmt.config = {
projectRootFile = "flake.nix";
programs = {
nixpkgs-fmt.enable = true;
rustfmt.enable = true;
};
};
};
};
}

4
flake.systems.nix Normal file
View file

@ -0,0 +1,4 @@
[
"x86_64-linux"
"aarch64-linux"
]

14
justfile Normal file
View file

@ -0,0 +1,14 @@
default:
@just --list
# Auto-format the source tree
fmt:
treefmt
# Run 'cargo run' on the project
run *ARGS:
cargo run {{ARGS}}
# Run 'cargo watch' to run the project (auto-recompiles)
watch *ARGS:
cargo watch -x "run -- {{ARGS}}"

28
src/main.rs Normal file
View file

@ -0,0 +1,28 @@
#![no_std]
#![no_main]
use core::alloc::GlobalAlloc;
use core::panic::PanicInfo;
use multiboot;
use multiboot2;
use spin::*;
use talc::*;
static mut START_ARENA: [u8; 10000] = [0; 10000];
#[global_allocator]
static ALLOCATOR: Talck<spin::Mutex<()>, ClaimOnOom> =
Talc::new(unsafe { ClaimOnOom::new(Span::from_const_array(core::ptr::addr_of!(START_ARENA))) })
.lock();
fn main() {}
pub fn kernel_entry(mbi_magic: u32, mbi_ptr: u32) {
if mbi_magic == multiboot2::MAGIC {
} else if mbi_magic == multiboot::header::MULTIBOOT_HEADER_MAGIC {
};
}
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
loop {}
}