Try loading code at runtime
This commit is contained in:
@@ -6,4 +6,4 @@ build-std = ["core", "compiler_builtins", "alloc"]
|
||||
build-std-features = ["compiler-builtins-mem"]
|
||||
|
||||
[target.riscv64]
|
||||
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 = "qemu-system-riscv64 -machine virt -device bochs-display -bios none -m 512M -device loader,file=/home/julien/ensimag/TPs/kernel/disk.img,addr=0x90000000 -s -S -kernel"
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,3 +4,4 @@
|
||||
Cargo.lock
|
||||
|
||||
disk.img
|
||||
out.mem
|
||||
|
||||
14
Cargo.toml
14
Cargo.toml
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "kernel-rust"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
[workspace]
|
||||
resolver = "3"
|
||||
members = ["kernel", "test_pic"]
|
||||
default-members = ["kernel"]
|
||||
|
||||
[profile.dev]
|
||||
panic = "abort"
|
||||
@@ -10,9 +10,3 @@ opt-level = 0
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
debug = true
|
||||
|
||||
[dependencies]
|
||||
embedded-alloc = "0.7"
|
||||
kernel-macros = { path = "kernel-macros" }
|
||||
log = "0.4"
|
||||
critical-section = { version = "1", features = ["restore-state-bool"] }
|
||||
|
||||
6
bffs/Cargo.toml
Normal file
6
bffs/Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "bffs"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
3
bffs/src/lib.rs
Normal file
3
bffs/src/lib.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
#![no_std]
|
||||
|
||||
const MAGIC_NUMBER: usize = 0xBFF5;
|
||||
115
kernel.svg
115
kernel.svg
@@ -1,115 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
width="1000"
|
||||
height="1000"
|
||||
viewBox="0 0 264.58333 264.58333"
|
||||
version="1.1"
|
||||
id="svg1"
|
||||
inkscape:version="1.4.3 (0d15f75042, 2025-12-25)"
|
||||
sodipodi:docname="kernel.svg"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg">
|
||||
<sodipodi:namedview
|
||||
id="namedview1"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#000000"
|
||||
borderopacity="0.25"
|
||||
inkscape:showpageshadow="2"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:deskcolor="#d1d1d1"
|
||||
inkscape:document-units="px"
|
||||
showguides="true"
|
||||
showgrid="false"
|
||||
inkscape:zoom="1.1688587"
|
||||
inkscape:cx="148.00762"
|
||||
inkscape:cy="533.85408"
|
||||
inkscape:window-width="1916"
|
||||
inkscape:window-height="1026"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="0"
|
||||
inkscape:window-maximized="0"
|
||||
inkscape:current-layer="layer1">
|
||||
<inkscape:grid
|
||||
id="grid3"
|
||||
units="px"
|
||||
originx="0"
|
||||
originy="0"
|
||||
spacingx="0.26458333"
|
||||
spacingy="0.26458333"
|
||||
empcolor="#0099e5"
|
||||
empopacity="0.30196078"
|
||||
color="#0099e5"
|
||||
opacity="0.14901961"
|
||||
empspacing="5"
|
||||
enabled="true"
|
||||
visible="false" />
|
||||
</sodipodi:namedview>
|
||||
<defs
|
||||
id="defs1" />
|
||||
<g
|
||||
inkscape:groupmode="layer"
|
||||
id="layer3"
|
||||
inkscape:label="User Mode" />
|
||||
<g
|
||||
inkscape:groupmode="layer"
|
||||
id="layer2"
|
||||
inkscape:label="Supervisor Mode" />
|
||||
<g
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
inkscape:label="Machine Mode">
|
||||
<path
|
||||
style="fill:none;fill-opacity:1;stroke:#05668d;stroke-width:1.05833332;stroke-linejoin:round;stroke-opacity:1;stroke-dasharray:none"
|
||||
d="M 0,88.106249 H 264.58333"
|
||||
id="path3"
|
||||
sodipodi:nodetypes="cc" />
|
||||
<path
|
||||
style="fill:none;fill-opacity:1;stroke:#05668d;stroke-width:1.05833332;stroke-linejoin:round;stroke-opacity:1;stroke-dasharray:none"
|
||||
d="M 0,176.2125 H 264.58332"
|
||||
id="path3-3"
|
||||
sodipodi:nodetypes="cc" />
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:7.05556px;font-family:'Open Sans';-inkscape-font-specification:'Open Sans, Bold';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;writing-mode:lr-tb;direction:ltr;fill:#05668d;fill-opacity:1;stroke:none;stroke-width:1.05833;stroke-linejoin:round;stroke-dasharray:none;stroke-opacity:1"
|
||||
x="0.68901867"
|
||||
y="6.6834888"
|
||||
id="text3"><tspan
|
||||
sodipodi:role="line"
|
||||
id="tspan3"
|
||||
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:7.05556px;font-family:'Open Sans';-inkscape-font-specification:'Open Sans, Bold';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#05668d;fill-opacity:1;stroke:none;stroke-width:1.05833"
|
||||
x="0.68901867"
|
||||
y="6.6834888">Machine</tspan><tspan
|
||||
sodipodi:role="line"
|
||||
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:7.05556px;font-family:'Open Sans';-inkscape-font-specification:'Open Sans, Bold';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#05668d;fill-opacity:1;stroke:none;stroke-width:1.05833"
|
||||
x="0.68901867"
|
||||
y="15.502938"
|
||||
id="tspan5" /></text>
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:7.05556px;font-family:'Open Sans';-inkscape-font-specification:'Open Sans, Bold';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;writing-mode:lr-tb;direction:ltr;fill:#05668d;fill-opacity:1;stroke:none;stroke-width:1.05833;stroke-linejoin:round;stroke-dasharray:none;stroke-opacity:1"
|
||||
x="0.99907744"
|
||||
y="94.789734"
|
||||
id="text3-5"><tspan
|
||||
sodipodi:role="line"
|
||||
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:7.05556px;font-family:'Open Sans';-inkscape-font-specification:'Open Sans, Bold';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#05668d;fill-opacity:1;stroke:none;stroke-width:1.05833"
|
||||
x="0.99907744"
|
||||
y="94.789734"
|
||||
id="tspan4">Supervisor</tspan></text>
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:7.05556px;font-family:'Open Sans';-inkscape-font-specification:'Open Sans, Bold';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;writing-mode:lr-tb;direction:ltr;fill:#05668d;fill-opacity:1;stroke:none;stroke-width:1.05833;stroke-linejoin:round;stroke-dasharray:none;stroke-opacity:1"
|
||||
x="0.99907744"
|
||||
y="182.89598"
|
||||
id="text3-5-8"><tspan
|
||||
sodipodi:role="line"
|
||||
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:7.05556px;font-family:'Open Sans';-inkscape-font-specification:'Open Sans, Bold';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#05668d;fill-opacity:1;stroke:none;stroke-width:1.05833"
|
||||
x="0.99907744"
|
||||
y="182.89598"
|
||||
id="tspan6">User</tspan></text>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 5.7 KiB |
11
kernel/Cargo.toml
Normal file
11
kernel/Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "kernel-rust"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
embedded-alloc = "0.7"
|
||||
kernel-macros = { path = "../kernel-macros" }
|
||||
log = "0.4"
|
||||
critical-section = { version = "1", features = ["restore-state-bool"] }
|
||||
bffs = { path = "../bffs" }
|
||||
@@ -108,6 +108,9 @@ unsafe extern "C" fn supervisor_trap_handler(
|
||||
str::from_raw_parts(a1 as *const u8, a2 as usize)
|
||||
})
|
||||
}
|
||||
SysCall::WriteIntTemp => {
|
||||
info!("Print from user space int : {}, {:x}", a1, a1)
|
||||
}
|
||||
SysCall::Unimplemented => {
|
||||
unimplemented!("Syscall {syscall_u64} is not implemented")
|
||||
}
|
||||
@@ -62,7 +62,7 @@ pub extern "C" fn supervisor_mode_entry() {
|
||||
create_process(test, "proc1");
|
||||
create_process(proc2, "proc2");
|
||||
|
||||
MemoryDisk::new();
|
||||
// MemoryDisk::new();
|
||||
|
||||
enable_supervisor_interrupt();
|
||||
idle();
|
||||
@@ -3,6 +3,7 @@ use core::time::Duration;
|
||||
#[repr(u64)]
|
||||
pub enum SysCall {
|
||||
NanoSleep = 101,
|
||||
WriteIntTemp = 998,
|
||||
WriteTemp = 999,
|
||||
Unimplemented = 1 << 31,
|
||||
}
|
||||
@@ -11,6 +12,7 @@ impl From<u64> for SysCall {
|
||||
fn from(value: u64) -> Self {
|
||||
match value {
|
||||
101 => SysCall::NanoSleep,
|
||||
998 => SysCall::WriteIntTemp,
|
||||
999 => SysCall::WriteTemp,
|
||||
_ => SysCall::Unimplemented,
|
||||
}
|
||||
@@ -89,3 +91,8 @@ pub fn write_string_temp(content: &'static str) {
|
||||
);
|
||||
}
|
||||
}
|
||||
pub fn write_int_temp(content: u64) {
|
||||
unsafe {
|
||||
syscall!(SysCall::WriteIntTemp, content);
|
||||
}
|
||||
}
|
||||
26
kernel/src/user.rs
Normal file
26
kernel/src/user.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
use core::{arch::asm, time::Duration};
|
||||
|
||||
use log::info;
|
||||
|
||||
use crate::syscall::{sleep, write_int_temp, write_string_temp};
|
||||
|
||||
#[repr(align(32))]
|
||||
struct Alignement([u8; 132]);
|
||||
|
||||
static PROG: Alignement = Alignement(*include_bytes!("../../out.mem"));
|
||||
|
||||
pub fn test() {
|
||||
write_int_temp(PROG.0.as_ptr() as u64);
|
||||
unsafe { core::mem::transmute::<*const u8, extern "C" fn()>(PROG.0.as_ptr())() }
|
||||
loop {
|
||||
write_string_temp("test");
|
||||
sleep(Duration::new(2, 0));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn proc2() {
|
||||
loop {
|
||||
write_string_temp("proc2");
|
||||
sleep(Duration::new(3, 0));
|
||||
}
|
||||
}
|
||||
17
src/user.rs
17
src/user.rs
@@ -1,17 +0,0 @@
|
||||
use core::time::Duration;
|
||||
|
||||
use crate::syscall::{sleep, write_string_temp};
|
||||
|
||||
pub fn test() {
|
||||
loop {
|
||||
write_string_temp("test");
|
||||
sleep(Duration::new(2, 0));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn proc2() {
|
||||
loop {
|
||||
write_string_temp("proc2");
|
||||
sleep(Duration::new(3, 0));
|
||||
}
|
||||
}
|
||||
6
test_pic/Cargo.toml
Normal file
6
test_pic/Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "test_pic"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
3
test_pic/build.rs
Normal file
3
test_pic/build.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
println!("cargo::rustc-link-arg=-Tilm.ld");
|
||||
}
|
||||
24
test_pic/src/main.rs
Normal file
24
test_pic/src/main.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use core::arch::global_asm;
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(_panic_info: &core::panic::PanicInfo) -> ! {
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn entry() {
|
||||
let test = "Hello from user mode";
|
||||
unsafe {
|
||||
core::arch::asm!(
|
||||
"ecall",
|
||||
in("a0") 999,
|
||||
in("a1") test.as_ptr(),
|
||||
in("a2") test.len(),
|
||||
clobber_abi("system")
|
||||
);
|
||||
}
|
||||
loop {}
|
||||
}
|
||||
Reference in New Issue
Block a user