add specs and dev log

This commit is contained in:
Michael Zhang 2024-12-16 11:02:41 -05:00
parent f9fba69adb
commit ca0913baff
16 changed files with 97 additions and 12 deletions

View file

@ -1,7 +1,12 @@
{
<<<<<<< HEAD
"rust-analyzer.cargo.allTargets": false,
"rust-analyzer.cargo.extraArgs": [
"--target",
"riscv64gc-unknown-none-elf"
]
}
=======
"rust-analyzer.cargo.allTargets": false
}
>>>>>>> 85bbe77 (add specs and dev log)

13
.vscode/tasks.json vendored Normal file
View file

@ -0,0 +1,13 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "process",
"command": ["${workspaceFolder}/scripts/start.sh"],
"args": [
"${workspaceFolder}/target/riscv64gc-unknown-none-elf/debug/kernel"
],
"label": "run kernel"
}
]
}

5
Cargo.lock generated
View file

@ -13,11 +13,16 @@ dependencies = [
"syn",
]
[[package]]
name = "ir"
version = "0.1.0"
[[package]]
name = "kernel"
version = "0.1.0"
dependencies = [
"contracts",
"ir",
]
[[package]]

View file

@ -3,6 +3,9 @@ name = "kernel"
version = "0.1.0"
edition = "2021"
[workspace]
members = ["crates/*"]
[profile.dev]
panic = "abort"
@ -11,5 +14,4 @@ panic = "abort"
[dependencies]
contracts = "0.6.3"
[features]
ir = { path = "crates/ir" }

1
crates/ir/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

6
crates/ir/Cargo.toml Normal file
View file

@ -0,0 +1,6 @@
[package]
name = "ir"
version = "0.1.0"
edition = "2021"
[dependencies]

13
crates/ir/src/lib.rs Normal file
View file

@ -0,0 +1,13 @@
#![no_std]
pub struct Module {}
pub struct Function {}
pub struct BasicBlock {}
pub enum Instruction {
Arithmetic(Arithmetic),
}
pub enum Arithmetic {}

25
development.md Normal file
View file

@ -0,0 +1,25 @@
# Development Log
### 2024-12-16
- Timer reference: https://popovicu.com/posts/risc-v-interrupts-with-timer-example/
- Another great general OS reference for RISC-V: https://osblog.stephenmarz.com/
- Looks like OpenSBI abstracts away UART and some other things, and has a bunch of extensions for managing the hardware. One thing you can do with this is create interrupts. I'm going to try to do this.
- The goal of setting up the interrupts is to go for a green-thread architecture.
### 2024-12-06
- I want to set up some kind of timer-based multitasking.
- https://github.com/marf/xv6-scheduling
### 2024-12-05
- Linker script annoying bug that didn't put .text at the exact address specified. It kept putting .rodata.\* first, so I just added an explicit entry for that to put it later
- The way the OS communicates with the QEMU terminal using UART
### 2024-12-04
- QEMU can automatically create a FAT filesystem on the fly https://qemu-project.gitlab.io/qemu/system/qemu-block-drivers.html#virtual-fat-disk-images
- https://www.qemu.org/2020/07/03/anatomy-of-a-boot/
- https://xiayingp.gitbook.io/build_a_os Learning resource
- Rust version of xv6: https://github.com/Jaic1/xv6-riscv-rust

Binary file not shown.

BIN
riscv-specs/riscv-abi.pdf Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

2
rustfmt.toml Normal file
View file

@ -0,0 +1,2 @@
tab_spaces = 2
max_width = 80

View file

@ -5,6 +5,8 @@ set -x
KERNEL=$1
shift
cargo build
qemu-system-riscv64 \
-nographic \
-machine virt \

View file

@ -2,6 +2,7 @@
#![no_main]
mod riscv;
mod sbi;
mod timer;
use core::{arch::global_asm, panic::PanicInfo, ptr};
@ -12,7 +13,7 @@ global_asm!(include_str!("asm/entry.S"));
#[panic_handler]
fn panic_handler(_: &PanicInfo) -> ! {
loop {}
loop {}
}
const UART0: usize = 0x10000000;
@ -20,13 +21,11 @@ static HELLO: &[u8] = b"meow\n";
#[no_mangle]
pub unsafe extern "C" fn start() -> ! {
timer_init();
timer_init();
for c in HELLO.iter() {
while ptr::read_volatile((UART0 + 5) as *const u8) & (1 << 5) == 0 {}
ptr::write_volatile((UART0 + 0) as *mut u8, *c);
}
for c in HELLO.iter() {
while ptr::read_volatile((UART0 + 5) as *const u8) & (1 << 5) == 0 {}
ptr::write_volatile((UART0 + 0) as *mut u8, *c);
}
loop {}
loop {}
}

12
src/sbi.rs Normal file
View file

@ -0,0 +1,12 @@
//! SBI -- Supervisor Binary Interface
//!
//! Docs: https://github.com/riscv-non-isa/riscv-sbi-doc
//!
//! QEMU implements this interface.
// https://github.com/popovicu/risc-v-sbi-timer/blob/main/timer.c
use core::arch::asm;
// Implementation from https://jborza.com/post/2021-04-04-riscv-supervisor-mode/
fn enter_supervisor_mode() {}