this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Init

roufpup 83ae6f3c

+269
+1
.envrc
··· 1 + use_nix
+3
.gitignore
··· 1 + OpenSBI/ 2 + .direnv/ 3 + target/
+18
.zed/settings.json
··· 1 + // Folder-specific settings 2 + // 3 + // For a full list of overridable settings, and general information on folder-specific settings, 4 + // see the documentation: https://zed.dev/docs/configuring-zed#settings-files 5 + { 6 + "lsp": { 7 + "rust-analyzer": { 8 + "initialization_options": { 9 + "cargo": { 10 + "target": "riscv64gc-unknown-linux-gnu", 11 + }, 12 + "check": { 13 + "allTargets": false, 14 + }, 15 + }, 16 + }, 17 + }, 18 + }
+15
kernel/.cargo/config.toml
··· 1 + [build] 2 + target = "riscv64gc-unknown-linux-gnu" 3 + 4 + [target.riscv64gc-unknown-linux-gnu] 5 + linker = "riscv64-unknown-linux-gnu-ld" 6 + rustflags = [ 7 + "-C", 8 + "link-arg=-static", 9 + "-C", 10 + "link-arg=-nostdlib", 11 + "-C", 12 + "relocation-model=static", 13 + "-C", 14 + "link-arg=-T./linker.ld", 15 + ]
+1
kernel/.gitignore
··· 1 + /target
+32
kernel/Cargo.lock
··· 1 + # This file is automatically @generated by Cargo. 2 + # It is not intended for manual editing. 3 + version = 4 4 + 5 + [[package]] 6 + name = "cc" 7 + version = "1.2.30" 8 + source = "registry+https://github.com/rust-lang/crates.io-index" 9 + checksum = "deec109607ca693028562ed836a5f1c4b8bd77755c4e132fc5ce11b0b6211ae7" 10 + dependencies = [ 11 + "shlex", 12 + ] 13 + 14 + [[package]] 15 + name = "fdt" 16 + version = "0.1.5" 17 + source = "registry+https://github.com/rust-lang/crates.io-index" 18 + checksum = "784a4df722dc6267a04af36895398f59d21d07dce47232adf31ec0ff2fa45e67" 19 + 20 + [[package]] 21 + name = "kernel" 22 + version = "0.1.0" 23 + dependencies = [ 24 + "cc", 25 + "fdt", 26 + ] 27 + 28 + [[package]] 29 + name = "shlex" 30 + version = "1.3.0" 31 + source = "registry+https://github.com/rust-lang/crates.io-index" 32 + checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
+19
kernel/Cargo.toml
··· 1 + [package] 2 + name = "kernel" 3 + version = "0.1.0" 4 + edition = "2024" 5 + test = false 6 + bench = false 7 + 8 + [dependencies] 9 + fdt = "0.1.5" 10 + 11 + [build-dependencies] 12 + cc = "1.2.30" 13 + 14 + 15 + [profile.dev] 16 + panic = "abort" 17 + 18 + [profile.release] 19 + panic = "abort"
+7
kernel/build.rs
··· 1 + fn main() { 2 + cc::Build::new() 3 + .file("src/kernel.s") 4 + .flag("-march=rv64gc") 5 + .compiler("riscv64-unknown-linux-gnu-gcc") 6 + .compile("boot"); 7 + }
+2
kernel/justfile
··· 1 + run: 2 + cargo build --release && qemu-system-riscv64 -nographic -machine virt -bios ../OpenSBI/build/platform/generic/firmware/fw_dynamic.elf -kernel ./target/riscv64gc-unknown-linux-gnu/release/kernel
+21
kernel/linker.ld
··· 1 + ENTRY(_start) 2 + 3 + SECTIONS { 4 + . = 0x00000000801ff000; 5 + .text : { 6 + *(.text*) 7 + } 8 + 9 + .rodata : { 10 + *(.rodata*) 11 + } 12 + 13 + .data : { 14 + *(.data*) 15 + } 16 + 17 + .bss : { 18 + *(.bss*) 19 + *(COMMON) 20 + } 21 + }
+3
kernel/rust-toolchain.toml
··· 1 + [toolchain] 2 + targets = ["riscv64gc-unknown-linux-gnu"] 3 + channel = "stable"
+17
kernel/src/kernel.s
··· 1 + .section .text 2 + .globl _start 3 + _start: 4 + # Set up stack pointer (adjust as you want) 5 + la sp, stack_top 6 + 7 + # Call rust_main (extern function) 8 + call rust_main 9 + 10 + # Infinite loop after kmain returns 11 + 1: j 1b 12 + 13 + .section .bss 14 + .align 12 # 2^12 = 4096 bytes stack alignment 15 + .space 0x4000 # 16KB stack 16 + 17 + stack_top:
+39
kernel/src/main.rs
··· 1 + #![no_std] 2 + #![no_main] 3 + 4 + use core::panic::PanicInfo; 5 + 6 + use fdt::Fdt; 7 + 8 + pub mod uart; 9 + 10 + // Debugging 11 + const CLINT: usize = 0x0200_0000; 12 + const MTIME: *const u64 = (CLINT + 0xBFF8) as *const u64; 13 + 14 + pub fn read_mtime() -> u64 { 15 + unsafe { core::ptr::read_volatile(MTIME) } 16 + } 17 + 18 + pub fn get_uart_address(device_tree: usize) { 19 + // fdt::node::Fdt:: 20 + } 21 + 22 + #[unsafe(no_mangle)] 23 + pub extern "C" fn rust_main(_hartid: usize, _dtb: usize) -> ! { 24 + uprintln!("Hello RiscV :3"); 25 + 26 + unsafe { 27 + let fdt = Fdt::from_ptr(_dtb as *const u8).ok().unwrap(); 28 + } 29 + 30 + #[allow(clippy::empty_loop)] 31 + loop {} 32 + } 33 + 34 + #[panic_handler] 35 + fn panic(_info: &PanicInfo) -> ! { 36 + uprintln!("Woopsie we panicked :<"); 37 + 38 + loop {} 39 + }
+50
kernel/src/uart.rs
··· 1 + use core::fmt::{self, Write}; 2 + 3 + const UART: usize = 0x1000_0000; 4 + const UART_STATUS: usize = UART + 0x5; 5 + const MASK: u8 = 1 << 5; 6 + 7 + pub struct Uart; 8 + 9 + impl Uart { 10 + pub fn write_byte(src: u8) { 11 + unsafe { 12 + let status = UART_STATUS as *mut u8; 13 + let reg = UART as *mut u8; 14 + 15 + while core::ptr::read_volatile(status) & MASK == 0 {} 16 + 17 + core::ptr::write_volatile(reg, src); 18 + } 19 + } 20 + 21 + pub fn print(args: fmt::Arguments) { 22 + Uart.write_fmt(args).ok(); 23 + } 24 + } 25 + 26 + impl Write for Uart { 27 + fn write_str(&mut self, s: &str) -> core::fmt::Result { 28 + for byte in s.as_bytes() { 29 + Self::write_byte(*byte); 30 + } 31 + Ok(()) 32 + } 33 + } 34 + 35 + #[macro_export] 36 + macro_rules! uprint { 37 + ($($arg:tt)*) => {{ 38 + $crate::uart::Uart::print(core::format_args!($($arg)*)); 39 + }}; 40 + } 41 + 42 + #[macro_export] 43 + macro_rules! uprintln { 44 + () => { 45 + $crate::uprint!("\n") 46 + }; 47 + ($($arg:tt)*) => {{ 48 + uprint!("{}\n", core::format_args!($($arg)*)); 49 + }} 50 + }
+41
shell.nix
··· 1 + let 2 + rust_overlay = import ( 3 + fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz" 4 + ); 5 + 6 + pkgs = import <nixpkgs> { 7 + overlays = [ 8 + rust_overlay 9 + (_: prev: { 10 + riscv-rust = prev.rust-bin.stable.latest.default.override { 11 + extensions = [ 12 + "rust-src" 13 + "rust-analyzer" 14 + "clippy" 15 + ]; 16 + targets = [ "riscv64gc-unknown-linux-gnu" ]; 17 + }; 18 + }) 19 + ]; 20 + }; 21 + 22 + riscv-toolchain = import <nixpkgs> { 23 + localSystem = "x86_64-linux"; 24 + crossSystem = { 25 + config = "riscv64-unknown-linux-gnu"; 26 + }; 27 + }; 28 + in 29 + pkgs.mkShell { 30 + nativeBuildInputs = with pkgs; [ 31 + git 32 + riscv-toolchain.buildPackages.gcc 33 + python312 34 + dtc 35 + riscv-rust 36 + ]; 37 + 38 + shellHook = '' 39 + echo "`git --version`" 40 + ''; 41 + }