Cleans library directory
This commit is contained in:
8
.gdbinit
8
.gdbinit
@@ -1,6 +1,6 @@
|
||||
file target/riscv64/debug/kernel-rust
|
||||
# file target/riscv64/debug/kernel-rust
|
||||
target remote localhost:1234
|
||||
break machine_mode_entry
|
||||
# break *0x800bf000
|
||||
# add-symbol-file target/riscv64/debug/test_pic 0x800bf000
|
||||
# break machine_mode_entry
|
||||
break *0x800cfdd8
|
||||
add-symbol-file target/riscv64/debug/test_pic 0x800cfdd8
|
||||
c
|
||||
|
||||
4
ilm.ld
4
ilm.ld
@@ -16,11 +16,11 @@ SECTIONS {
|
||||
*(.text .text.*)
|
||||
} > RAM
|
||||
|
||||
.rodata : {
|
||||
.rodata : ALIGN(8) {
|
||||
*(.rodata .rodata.*)
|
||||
} > RAM
|
||||
|
||||
.data : {
|
||||
.data : ALIGN(8) {
|
||||
*(.data .data.*)
|
||||
} > RAM
|
||||
|
||||
|
||||
54
justfile
54
justfile
@@ -2,39 +2,39 @@ release := ""
|
||||
qemu_flags := ""
|
||||
cargo_flags := "" + if release != "" { "--release" } else { "" }
|
||||
bin_path := if release != "" { "target/riscv64/release" } else { "target/riscv64/debug" }
|
||||
GDB := "gf2"
|
||||
|
||||
default: run
|
||||
|
||||
mount_filesystem:
|
||||
@# Add some permissions to be able to do next operations without sudo
|
||||
mountpoint -q mnt || sudo mount -o umask=0022,gid=$(id -g $USER),uid=$(id -u $USER) disk.img mnt
|
||||
|
||||
sync_filesystem:
|
||||
sync
|
||||
mountpoint -q mnt || sudo mount -o umask=0022,gid=$(id -g),uid=$(id -u) disk.img mnt
|
||||
|
||||
update-std:
|
||||
@cd library/std && just update-std
|
||||
@cd library/std && {{ just_executable() }} update-std
|
||||
|
||||
build-sysroot:
|
||||
@cd library/std && just build-sysroot
|
||||
@cd library/std && {{ just_executable() }} build-sysroot
|
||||
|
||||
build_user_prog prog:
|
||||
RUSTFLAGS="-C relocation-model=pic -C link-arg=-pie --sysroot {{ justfile_directory() / "sysroot" }}" cargo b {{ cargo_flags }} --package {{ prog }}
|
||||
riscv64-elf-strip {{ bin_path / prog }}
|
||||
cp {{ bin_path / prog }} {{ "mnt/usr/bin" / prog }}
|
||||
RUSTFLAGS="-Clink-arg=-Tuser.ld -C relocation-model=pic -C link-arg=-pie --sysroot {{ justfile_directory() / "sysroot" }}" \
|
||||
cargo b {{ cargo_flags }} --package {{ prog }}
|
||||
cp {{ bin_path / prog }} {{ bin_path / prog + "-stripped" }}
|
||||
if command -v riscv64-elf-strip >/dev/null 2>&1; then \
|
||||
riscv64-elf-strip {{ bin_path / prog + "-stripped" }}; \
|
||||
fi
|
||||
cp {{ bin_path / prog + "-stripped" }} {{ "mnt/usr/bin" / prog }}
|
||||
|
||||
build: mount_filesystem (map_dir "user" f"just release=\"{{release}}\" cargo_flags=\"{{cargo_flags}}\" build_user_prog")
|
||||
build: mount_filesystem
|
||||
@for file in `ls user`; do \
|
||||
{{ just_executable() }} release="{{ release }}" cargo_flags="{{ cargo_flags }}" build_user_prog $file ; \
|
||||
done
|
||||
RUSTFLAGS="-Clink-arg=-Tilm.ld --sysroot {{ justfile_directory() / "sysroot" }}" cargo b {{ cargo_flags }}
|
||||
just sync_filesystem
|
||||
sync
|
||||
|
||||
run: build (runner f"{{bin_path / "kernel-rust"}}")
|
||||
|
||||
map_dir dir recipe:
|
||||
@for file in `ls {{ dir }}`; do \
|
||||
{{ recipe }} $file ; \
|
||||
done
|
||||
|
||||
qemu := f"qemu-system-riscv64 \
|
||||
QEMU := f"qemu-system-riscv64 \
|
||||
-machine virt \
|
||||
-serial mon:stdio \
|
||||
-device bochs-display \
|
||||
@@ -47,17 +47,25 @@ qemu := f"qemu-system-riscv64 \
|
||||
# -d guest_errors,unimp,int"
|
||||
|
||||
perf: build
|
||||
{{ qemu }} -perfmap -kernel {{ bin_path / "kernel-rust" }}&
|
||||
{{ QEMU }} -perfmap -kernel {{ bin_path / "kernel-rust" }}&
|
||||
perf record --output=/tmp/perf.data --call-graph=dwarf -F 999 -p $(pidof qemu-system-riscv64) -- sleep 20; exit 0
|
||||
cd /tmp && hotspot perf.data
|
||||
|
||||
gdb: build
|
||||
{{ qemu }} -s -S -kernel {{ bin_path / "kernel-rust" }}&
|
||||
gf2
|
||||
dbg: build
|
||||
{{ QEMU }} -s -S -kernel {{ bin_path / "kernel-rust" }}&
|
||||
{{ GDB }}
|
||||
|
||||
dbg-user prog addr: build
|
||||
{{ QEMU }} -s -S -kernel {{ bin_path / "kernel-rust" }}&
|
||||
{{ GDB }} -nx \
|
||||
-ex "target remote localhost:1234" \
|
||||
-ex "break *{{ addr }}" \
|
||||
-ex "add-symbol-file target/riscv64/debug/{{ prog }} {{ addr }}" \
|
||||
-ex "c"
|
||||
|
||||
runner args:
|
||||
{{ qemu }} -kernel {{ args }}
|
||||
{{ QEMU }} -kernel {{ args }}
|
||||
|
||||
clean:
|
||||
cd library && just clean
|
||||
cd library && {{ just_executable() }} clean
|
||||
cargo clean
|
||||
|
||||
@@ -44,7 +44,7 @@ STD_FILES := "\
|
||||
sys/thread_local/no_threads.rs sys/thread_local/os.rs sys/time/mod.rs \
|
||||
sys/time/unsupported.rs sys/backtrace.rs sys/cmath.rs \
|
||||
sys/configure_builtins.rs sys/env_consts.rs sys/exit.rs sys/mod.rs thread"
|
||||
KEEP_FILES := "sys sys/pal sys/pal/survos.rs sys/alloc sys/alloc/survos.rs"
|
||||
KEEP_FILES := "survos.rs"
|
||||
|
||||
setup-std:
|
||||
@echo "🔗 Linking root directories..."
|
||||
@@ -74,8 +74,9 @@ patch-std:
|
||||
done
|
||||
|
||||
build-sysroot:
|
||||
cargo clean
|
||||
RUSTFLAGS="-Zforce-unstable-if-unmarked -C relocation-model=pic -C link-arg=-pie" \
|
||||
cargo build --package std --target ../riscv64.json --features compiler-builtins-mem
|
||||
cargo build --package std --target ../riscv64.json --features compiler-builtins-mem
|
||||
mkdir -p ../sysroot/lib/rustlib/riscv64/lib
|
||||
rm -rf ../sysroot/lib/rustlib/riscv64/lib/*
|
||||
cp target/riscv64/debug/deps/*.rlib ../sysroot/lib/rustlib/riscv64/lib
|
||||
@@ -83,11 +84,10 @@ build-sysroot:
|
||||
clean:
|
||||
cargo clean
|
||||
rm -rf ../sysroot/lib/rustlib/riscv64/lib/*
|
||||
@for item in $(find library/std/src); do \
|
||||
@for item in $(find std/src -type f); do \
|
||||
basename_item=$(basename "$item"); \
|
||||
keep=0; \
|
||||
for protected in {{ KEEP_FILES }}; do \
|
||||
echo $basename_item = $protected; \
|
||||
if [ "$basename_item" = "$protected" ]; then keep=1; break; fi; \
|
||||
done; \
|
||||
if [ "$keep" -eq 0 ]; then \
|
||||
|
||||
1
library/std/.gitignore
vendored
1
library/std/.gitignore
vendored
@@ -91,7 +91,6 @@ src/sys/mod.rs
|
||||
src/sys/time
|
||||
src/sys/time/mod.rs
|
||||
src/sys/time/unsupported.rs
|
||||
src/sys/stdio
|
||||
src/sys/stdio/mod.rs
|
||||
src/sys/stdio/unsupported.rs
|
||||
src/sys/cmath.rs
|
||||
|
||||
4
library/std/patches/sys/stdio/mod.sed
Normal file
4
library/std/patches/sys/stdio/mod.sed
Normal file
@@ -0,0 +1,4 @@
|
||||
47a \ target_os = "survos" => { \
|
||||
mod survos; \
|
||||
pub use self::survos::*; \
|
||||
}
|
||||
148
library/std/src/sys/stdio/survos.rs
Normal file
148
library/std/src/sys/stdio/survos.rs
Normal file
@@ -0,0 +1,148 @@
|
||||
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut};
|
||||
|
||||
#[path = "unsupported.rs"]
|
||||
mod unsupported;
|
||||
pub use self::unsupported::{STDIN_BUF_SIZE, Stderr, Stdin, is_ebadf, panic_output};
|
||||
|
||||
pub struct Stdout;
|
||||
// pub struct Stdin;
|
||||
|
||||
impl Stdout {
|
||||
pub const fn new() -> Self {
|
||||
Self
|
||||
}
|
||||
}
|
||||
// impl Stdin {
|
||||
// pub const fn new() -> Self {
|
||||
// Self
|
||||
// }
|
||||
// }
|
||||
|
||||
impl io::Write for Stdout {
|
||||
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
||||
unsafe { Ok(write(1, buf) as usize) }
|
||||
}
|
||||
|
||||
fn flush(&mut self) -> io::Result<()> {
|
||||
// todo!()
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
// impl io::Read for Stdin {
|
||||
// fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||||
// Ok(0)
|
||||
// // unsafe { Ok(read(0, buf) as usize) }
|
||||
// }
|
||||
// }
|
||||
|
||||
#[repr(u64)]
|
||||
pub enum SysCall {
|
||||
Read = 0,
|
||||
Write = 1,
|
||||
Open = 2,
|
||||
Close = 3,
|
||||
Seek = 8,
|
||||
Alloc = 40,
|
||||
Dealloc = 41,
|
||||
Spawn = 58,
|
||||
ExecVE = 59,
|
||||
Exit = 60,
|
||||
NanoSleep = 101,
|
||||
WriteIntTemp = 998,
|
||||
WriteTemp = 999,
|
||||
Unimplemented = 1 << 31,
|
||||
}
|
||||
|
||||
impl From<u64> for SysCall {
|
||||
fn from(value: u64) -> Self {
|
||||
match value {
|
||||
0 => SysCall::Read,
|
||||
1 => SysCall::Write,
|
||||
2 => SysCall::Open,
|
||||
3 => SysCall::Close,
|
||||
8 => SysCall::Seek,
|
||||
40 => SysCall::Alloc,
|
||||
41 => SysCall::Dealloc,
|
||||
58 => SysCall::Spawn,
|
||||
59 => SysCall::ExecVE,
|
||||
60 => SysCall::Exit,
|
||||
101 => SysCall::NanoSleep,
|
||||
998 => SysCall::WriteIntTemp,
|
||||
999 => SysCall::WriteTemp,
|
||||
_ => SysCall::Unimplemented,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
unsafe fn _syscall(
|
||||
syscall: SysCall,
|
||||
mut a1: u64,
|
||||
mut a2: u64,
|
||||
mut a3: u64,
|
||||
mut a4: u64,
|
||||
mut a5: u64,
|
||||
mut a6: u64,
|
||||
mut a7: u64,
|
||||
) -> (u64, u64, u64, u64, u64, u64, u64, u64) {
|
||||
let mut a0 = syscall as u64;
|
||||
unsafe {
|
||||
core::arch::asm!(
|
||||
"ecall",
|
||||
inlateout("a0") a0,
|
||||
inlateout("a1") a1,
|
||||
inlateout("a2") a2,
|
||||
inlateout("a3") a3,
|
||||
inlateout("a4") a4,
|
||||
inlateout("a5") a5,
|
||||
inlateout("a6") a6,
|
||||
inlateout("a7") a7,
|
||||
clobber_abi("system")
|
||||
);
|
||||
}
|
||||
(a0, a1, a2, a3, a4, a5, a6, a7)
|
||||
}
|
||||
|
||||
macro_rules! syscall {
|
||||
($syscall:expr, $a1:expr, $a2:expr, $a3:expr, $a4:expr, $a5:expr, $a6:expr, $a7:expr) => {
|
||||
_syscall($syscall, $a1, $a2, $a3, $a4, $a5, $a6, $a7)
|
||||
};
|
||||
($syscall:expr, $a1:expr, $a2:expr, $a3:expr, $a4:expr, $a5:expr, $a6:expr) => {
|
||||
syscall!($syscall, $a1, $a2, $a3, $a4, $a5, $a6, 0)
|
||||
};
|
||||
($syscall:expr, $a1:expr, $a2:expr, $a3:expr, $a4:expr, $a5:expr) => {
|
||||
syscall!($syscall, $a1, $a2, $a3, $a4, $a5, 0)
|
||||
};
|
||||
($syscall:expr, $a1:expr, $a2:expr, $a3:expr, $a4:expr) => {
|
||||
syscall!($syscall, $a1, $a2, $a3, $a4, 0)
|
||||
};
|
||||
($syscall:expr, $a1:expr, $a2:expr, $a3:expr) => {
|
||||
syscall!($syscall, $a1, $a2, $a3, 0)
|
||||
};
|
||||
($syscall:expr, $a1:expr, $a2:expr) => {
|
||||
syscall!($syscall, $a1, $a2, 0)
|
||||
};
|
||||
($syscall:expr, $a1:expr) => {
|
||||
syscall!($syscall, $a1, 0)
|
||||
};
|
||||
($syscall:expr) => {
|
||||
syscall!($syscall, 0)
|
||||
};
|
||||
}
|
||||
pub fn write(file_descriptor: u64, buf: &[u8]) -> u64 {
|
||||
unsafe {
|
||||
let ptr = buf.as_ptr();
|
||||
let size = buf.len();
|
||||
let (len, ..) = syscall!(SysCall::Write, file_descriptor, ptr as u64, size as u64);
|
||||
len
|
||||
}
|
||||
}
|
||||
pub fn read(file_descriptor: u64, buf: &mut [u8]) -> u64 {
|
||||
unsafe {
|
||||
let ptr = buf.as_ptr();
|
||||
let size = buf.len();
|
||||
let (len, ..) = syscall!(SysCall::Read, file_descriptor, ptr as u64, size as u64);
|
||||
len
|
||||
}
|
||||
}
|
||||
@@ -197,6 +197,7 @@ impl Scheduler {
|
||||
if ph.p_type == goblin::elf::program_header::PT_LOAD {
|
||||
let dst = unsafe { base.add((ph.p_vaddr - min_vaddr) as usize) };
|
||||
let src_off = ph.p_offset as usize;
|
||||
println!("off{:x?}", dst);
|
||||
let copy_len = ph.p_filesz as usize;
|
||||
if copy_len > 0 {
|
||||
unsafe {
|
||||
@@ -228,6 +229,16 @@ impl Scheduler {
|
||||
let where_off = (rela.r_offset - min_vaddr) as usize;
|
||||
let where_ptr = unsafe { base.add(where_off) } as *mut u64;
|
||||
let val = (base as u64).wrapping_add(rela.r_addend.unwrap() as u64);
|
||||
if rela.r_addend.unwrap() == 0x5bfb8 {
|
||||
println!(
|
||||
"Relocating GLOBAL_PANIC_COUNT: at {:p}, setting value to {:x}",
|
||||
where_ptr, val
|
||||
);
|
||||
assert!(
|
||||
val % 8 == 0,
|
||||
"DANGER: Address of GLOBAL_PANIC_COUNT is not 8-aligned!"
|
||||
);
|
||||
}
|
||||
unsafe { core::ptr::write_unaligned(where_ptr, val) };
|
||||
}
|
||||
_ => {}
|
||||
|
||||
@@ -57,7 +57,7 @@ impl VirtualFileSystem for MainFileSystem {
|
||||
}
|
||||
|
||||
pub static mut FILE_SYSTEM: LazyCell<MainFileSystem> = LazyCell::new(|| MainFileSystem {
|
||||
root: Box::new(Fat32FileSystem::new(Disk::new(1024 * 1024 * 16)).unwrap()),
|
||||
root: Box::new(Fat32FileSystem::new(Disk::new(1024 * 1024 * 64)).unwrap()),
|
||||
mounts: HashMap::new(),
|
||||
});
|
||||
|
||||
|
||||
@@ -39,12 +39,12 @@ impl Seek for NullNode {
|
||||
}
|
||||
|
||||
impl Write for NullNode {
|
||||
fn write(&mut self, _buf: &[u8]) -> Result<usize, Self::Error> {
|
||||
todo!()
|
||||
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
|
||||
Ok(buf.len())
|
||||
}
|
||||
|
||||
fn flush(&mut self) -> Result<(), Self::Error> {
|
||||
todo!()
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
35
user.ld
Normal file
35
user.ld
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* ld directives the for barmetal RISCV
|
||||
*/
|
||||
OUTPUT_ARCH(riscv)
|
||||
ENTRY(_start)
|
||||
|
||||
MEMORY {
|
||||
RAM (wxa) : ORIGIN = 0x0, LENGTH = 512M
|
||||
}
|
||||
|
||||
SECTIONS {
|
||||
. = 0x0;
|
||||
.text : {
|
||||
KEEP(*(.text._start))
|
||||
|
||||
*(.text .text.*)
|
||||
} > RAM
|
||||
|
||||
.rodata : ALIGN(8) {
|
||||
*(.rodata .rodata.*)
|
||||
} > RAM
|
||||
|
||||
.data : ALIGN(8) {
|
||||
*(.data .data.*)
|
||||
} > RAM
|
||||
|
||||
.bss : ALIGN(8) {
|
||||
__bss_start = .;
|
||||
*(.bss .bss.*)
|
||||
__bss_end = .;
|
||||
} > RAM
|
||||
|
||||
_heap_start = ALIGN(8);
|
||||
_heap_end = ORIGIN(RAM) + LENGTH(RAM);
|
||||
}
|
||||
@@ -4,6 +4,5 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
# std = { path = "../../crates/std" }
|
||||
# shared = { path = "../../crates/shared", features = ["user"] }
|
||||
# core = { path = "../../crates/std/crates/core" }
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// use std::io::_print;
|
||||
|
||||
fn main() {
|
||||
let a = std::env::args();
|
||||
for a in a {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#![allow(unused)]
|
||||
#![feature(panic_internals, core_intrinsics)]
|
||||
|
||||
use io::{Read, Write};
|
||||
use std::io::{Stdin, stdin};
|
||||
use io::{Read as Readio, Write};
|
||||
use shared::syscall;
|
||||
use std::io::{Read, Stdin, stdin};
|
||||
|
||||
fn main() {
|
||||
let mut input = String::new();
|
||||
@@ -13,10 +14,15 @@ fn main() {
|
||||
// syscall::sleep(Duration::from_secs_f64(2.0));
|
||||
syscall::close(0);
|
||||
let mut tty = syscall::open("/dev/tty0");
|
||||
syscall::close(1);
|
||||
let _ = syscall::open("/dev/tty0");
|
||||
println!("test from test_pic");
|
||||
tty.write(input.as_bytes()).unwrap();
|
||||
syscall::spawn("/usr/bin/shell");
|
||||
core::panicking::panic("explicit panic");
|
||||
loop {
|
||||
let mut test = [0; 2];
|
||||
// let len = stdin().read(&mut test);
|
||||
let len = tty.read(&mut test).unwrap();
|
||||
tty.write(str::from_utf8(&test[..len as usize]).unwrap().as_bytes())
|
||||
.unwrap();
|
||||
|
||||
Reference in New Issue
Block a user