This commit is contained in:
2026-02-26 11:52:40 +01:00
parent 4dc05c4151
commit 79b75dc75b
8 changed files with 33 additions and 19 deletions

View File

@@ -9,4 +9,4 @@ build-std-features = ["compiler-builtins-mem"]
rustflags = [
"-C", "link-arg=-Tilm.ld",
]
runner = "qemu-system-riscv64 -machine virt -device bochs-display -bios none -m 512M -device loader,file=/home/julien/ensimag/TPs/kernel/disk.img,addr=0x90000000 -kernel"
runner = "just runner"

View File

@@ -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 *0x800dd1d8
# add-symbol-file target/riscv64/debug/test_pic 0x800dd1d8
# break machine_mode_entry
break *0x800bf000
add-symbol-file target/riscv64/debug/test_pic 0x800bf000
c

View File

@@ -1,18 +1,20 @@
release := ""
cargo_flags := if release != "" { "--release" } else { "" }
bin_path := if release != "" { "target/riscv64/release" } else { "target/riscv64/debug" }
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
@# 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
build_user_prog prog:
RUSTFLAGS="-C relocation-model=pic -C link-arg=-Tuser.ld" cargo b {{ cargo_flags }} --package {{ prog }}
riscv64-elf-objcopy -O binary {{ "target/riscv64/debug" / prog }} {{ "mnt/usr/bin" / prog }}
# cp {{ bin_path / prog }} {{ "mnt/usr/bin" / prog }}
riscv64-elf-objcopy -O binary {{ bin_path / prog }} {{ "mnt/usr/bin" / prog }}
build: mount_filesystem (map_dir "user" "build_user_prog")
cargo b {{ cargo_flags }}
@@ -25,3 +27,15 @@ map_dir dir recipe:
@for file in `ls {{ dir }}`; do \
just cargo_flags="{{ cargo_flags }}" {{ recipe }} $file ; \
done
qemu := "qemu-system-riscv64 -machine virt -device bochs-display -bios none -m 512M -device loader,file=disk.img,addr=0x90000000"
gdb: build
{{ qemu }} -s -S -kernel {{ bin_path / "kernel-rust" }}&
gf2
runner args:
{{ qemu }} -kernel {{ args }}
clean:
cargo clean

View File

@@ -79,9 +79,9 @@ impl Read for Disk {
return Ok(0);
}
let size = usize::min(buf.len(), (self.size - self.pos) as usize);
for i in 0..size {
(0..size).for_each(|i| {
buf[i] = unsafe { *DISK_ADDR.byte_add(i + self.pos as usize) };
}
});
self.pos += size as u64;
Ok(size)
}

View File

@@ -11,9 +11,11 @@
iter_map_windows,
str_from_raw_parts,
macro_metavar_expr,
macro_metavar_expr_concat
macro_metavar_expr_concat,
ptr_metadata
)]
use alloc::string::String;
use embedded_alloc::LlffHeap as Heap;
use log::info;
@@ -42,7 +44,7 @@ mod uart;
mod user;
mod vga;
pub const HEAP_SIZE: usize = 1024 * 1024; // 1Mo RAM
pub const HEAP_SIZE: usize = 1024 * 1024 * 32; // 32Mo RAM
#[global_allocator]
static HEAP: Heap = Heap::empty();

View File

@@ -16,7 +16,7 @@ use shared::syscall::exit;
use crate::{
fs::FILE_SYSTEM,
println,
scheduler::{ACTIVE_PID, PROCESS_COUNT, PROCESS_TABLE, scheduler_without_ret},
scheduler::{scheduler_without_ret, ACTIVE_PID, PROCESS_COUNT, PROCESS_TABLE},
time::elapsed_time_since_startup,
};
@@ -134,12 +134,9 @@ pub fn create_process_from_file<'a, T: Into<Path<'a>>>(path: T) -> i64 {
println!("Loading binary at address: {:x?}", content.as_ptr());
// SAFETY: Convert raw bytes into an executable function.
// The binary must be valid RISC-V machine code.
// Fallback: treat the file as a raw binary blob and execute in-place
let entry_point =
unsafe { core::mem::transmute::<*const u8, extern "C" fn()>(Vec::leak(content).as_ptr()) };
// Create a wrapper for the entry point function
let wrapper = Box::leak(Box::new(move || {
entry_point();
}));

View File

@@ -5,11 +5,11 @@ OUTPUT_ARCH(riscv)
ENTRY(_start)
MEMORY {
RAM (wxa) : ORIGIN = 0x800dd1d8, LENGTH = 128M
RAM (wxa) : ORIGIN = 0x0, LENGTH = 128M
}
SECTIONS {
. = 0x800dd1d8;
. = 0x0;
.text : {
KEEP(*(.text._start))

View File

@@ -15,6 +15,7 @@ fn main() {
test.push('C');
}
let mut b = String::from("test");
b.write_str("string: uaeuieuei");
// (&mut b as &mut dyn Write).write_str("string: uaeuieuei");
syscall::write_string_temp(&b);
// write(&mut b, Arguments::from_str_nonconst("string: uaeuieuei"));