Skip to content

Commit

Permalink
dev: temp stasj
Browse files Browse the repository at this point in the history
  • Loading branch information
yfblock committed Nov 7, 2024
1 parent 59af83b commit 1eed1fa
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 26 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[patch]
[patch."https://github.com/Byte-OS/fs.git".fs]
path = "crates/fs"

[profile.release]
debug = true
Expand Down
51 changes: 51 additions & 0 deletions crates/polyhal/src/components/arch/riscv64.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use core::slice;

use alloc::vec::Vec;
use fdt::Fdt;

use crate::components::{common::{CPU_ID, DTB_BIN, DTB_PTR, MEM_AREA}, consts::VIRT_ADDR_START};


#[inline]
pub fn wfi() {
unsafe {
riscv::register::sstatus::clear_sie();
riscv::asm::wfi();
riscv::register::sstatus::set_sie();
}
}

pub fn hart_id() -> usize {
CPU_ID.read_current()
}

pub fn arch_init() {
let mut buffer = Vec::new();
if let Ok(fdt) = unsafe { Fdt::from_ptr(*DTB_PTR as *const u8) } {
unsafe {
buffer.extend_from_slice(slice::from_raw_parts(
*DTB_PTR as *const u8,
fdt.total_size(),
));
}
}
DTB_BIN.init_by(buffer);
let mut mem_area: Vec<(usize, usize)> = Vec::new();
if let Ok(fdt) = Fdt::new(&DTB_BIN) {
log::info!("There has {} CPU(s)", fdt.cpus().count());
fdt.memory().regions().for_each(|x| {
log::info!(
"memory region {:#X} - {:#X}",
x.starting_address as usize,
x.starting_address as usize + x.size.unwrap()
);
mem_area.push((
x.starting_address as usize | VIRT_ADDR_START,
x.size.unwrap_or(0),
));
});
} else {
mem_area.push((0x8000_0000 | VIRT_ADDR_START, 0x1000_0000));
}
MEM_AREA.init_by(mem_area);
}
20 changes: 3 additions & 17 deletions kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,24 +154,19 @@ fn main(hart_id: usize) {
let str = include_str!("banner.txt");
println!("{}", str);

// initialize logging module
// logging::init(option_env!("LOG"));

polyhal::common::init(&PageAllocImpl);
get_mem_areas().into_iter().for_each(|(start, size)| {
info!("memory area: {:#x} - {:#x}", start, start + size);
frame_allocator::add_frame_map(start, start + size);
});

println!("run kernel @ hart {}", hart_id);

info!("run kernel @ hart {}", hart_id);
info!("program size: {}KB", (end as usize - start as usize) / 1024);

// Boot all application core.
// polyhal::multicore::MultiCore::boot_all();

devices::prepare_drivers();

log::debug!("device fdt: {}", get_fdt().is_some());

if let Some(fdt) = get_fdt() {
for node in fdt.all_nodes() {
devices::try_to_add_device(&node);
Expand All @@ -181,9 +176,6 @@ fn main(hart_id: usize) {
// get devices and init
devices::regist_devices_irq();

// TODO: test ebreak
// Instruction::ebreak();

// initialize filesystem
fs::init();
{
Expand Down Expand Up @@ -218,22 +210,16 @@ fn main(hart_id: usize) {
// crate::syscall::cache_task_template("libc.so").expect("can't cache task");
// crate::syscall::cache_task_template("lmbench_all").expect("can't cache task");

// loop {
// info!("3");
// }

// init kernel threads and async executor
tasks::init();
log::info!("run tasks");
// loop { arch::wfi() }
tasks::run_tasks();

println!("Task All Finished!");
} else {
println!("run kernel @ hart {}", hart_id);

IRQ::int_enable();
// loop { arch::wfi() }
tasks::run_tasks();
info!("shutdown ap core");
}
Expand Down
4 changes: 3 additions & 1 deletion kernel/src/tasks/initproc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@ pub async fn initproc() {
// command("busybox sh busybox_testcode.sh").await;

// command("busybox echo run libctest_testcode.sh").await;
command("busybox sh libctest_testcode.sh").await;
// command("busybox sh libctest_testcode.sh").await;
// command("busybox sh").await;
command("ls").await;
// command("busybox echo Hello World!").await;
// command("busybox sh").await;
// command("hello").await;
Expand Down
10 changes: 7 additions & 3 deletions scripts/cli-qemu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ class QemuRunner {
arch: string;
bus: string = "device";
builder: KernelBuilder;
memorySize: string = "1G";
smp: string = "1";


constructor(options: CommandOptions<globalArgType>, builder: KernelBuilder) {
this.arch = options.arch;
Expand Down Expand Up @@ -50,15 +53,16 @@ class QemuRunner {
args: [
...this.getQemuArchExec(),
"-m",
"1G",
this.memorySize,
"-nographic",
"-smp",
"1",
this.smp,
// Dump Debug information.
"-D",
"qemu.log",
"-d",
"in_asm,int,pcall,cpu_reset,guest_errors",

// Add virtio block device.
"-drive",
"file=mount.img,if=none,format=raw,id=x0",
"-device",
Expand Down
8 changes: 5 additions & 3 deletions scripts/kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class KernelBuilder {
this.elfPath = `${Deno.cwd()}/target/${targetMap[arch]}/release/kernel`;
this.binPath = `${this.elfPath}.bin`;

this.rustflags = Deno.env.get('rustflags') || "";
this.rustflags = Deno.env.get('RUSTFLAGS') || "";
}

buildFlags() {
Expand All @@ -25,14 +25,16 @@ export class KernelBuilder {
"-Clink-arg=-no-pie",
"-Ztls-model=local-exec",
`--cfg=root_fs="ext4_rs"`,
'--cfg=board="qemu"'
'--cfg=board="qemu"',
`--cfg=driver="kvirtio,kgoldfish-rtc,ns16550a"`
];

this.rustflags += rustflags.join(" ");
this.rustflags += ' ' + rustflags.join(" ");
}

async buildElf() {
this.buildFlags();
console.log(this.rustflags);

const buildProc = new Deno.Command("cargo", {
args: [
Expand Down

0 comments on commit 1eed1fa

Please sign in to comment.