Skip to content

Commit 1eed1fa

Browse files
committed
dev: temp stasj
1 parent 59af83b commit 1eed1fa

File tree

7 files changed

+71
-26
lines changed

7 files changed

+71
-26
lines changed

Cargo.lock

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
[patch]
1+
[patch."https://github.com/Byte-OS/fs.git".fs]
2+
path = "crates/fs"
23

34
[profile.release]
45
debug = true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
use core::slice;
2+
3+
use alloc::vec::Vec;
4+
use fdt::Fdt;
5+
6+
use crate::components::{common::{CPU_ID, DTB_BIN, DTB_PTR, MEM_AREA}, consts::VIRT_ADDR_START};
7+
8+
9+
#[inline]
10+
pub fn wfi() {
11+
unsafe {
12+
riscv::register::sstatus::clear_sie();
13+
riscv::asm::wfi();
14+
riscv::register::sstatus::set_sie();
15+
}
16+
}
17+
18+
pub fn hart_id() -> usize {
19+
CPU_ID.read_current()
20+
}
21+
22+
pub fn arch_init() {
23+
let mut buffer = Vec::new();
24+
if let Ok(fdt) = unsafe { Fdt::from_ptr(*DTB_PTR as *const u8) } {
25+
unsafe {
26+
buffer.extend_from_slice(slice::from_raw_parts(
27+
*DTB_PTR as *const u8,
28+
fdt.total_size(),
29+
));
30+
}
31+
}
32+
DTB_BIN.init_by(buffer);
33+
let mut mem_area: Vec<(usize, usize)> = Vec::new();
34+
if let Ok(fdt) = Fdt::new(&DTB_BIN) {
35+
log::info!("There has {} CPU(s)", fdt.cpus().count());
36+
fdt.memory().regions().for_each(|x| {
37+
log::info!(
38+
"memory region {:#X} - {:#X}",
39+
x.starting_address as usize,
40+
x.starting_address as usize + x.size.unwrap()
41+
);
42+
mem_area.push((
43+
x.starting_address as usize | VIRT_ADDR_START,
44+
x.size.unwrap_or(0),
45+
));
46+
});
47+
} else {
48+
mem_area.push((0x8000_0000 | VIRT_ADDR_START, 0x1000_0000));
49+
}
50+
MEM_AREA.init_by(mem_area);
51+
}

kernel/src/main.rs

+3-17
Original file line numberDiff line numberDiff line change
@@ -154,24 +154,19 @@ fn main(hart_id: usize) {
154154
let str = include_str!("banner.txt");
155155
println!("{}", str);
156156

157-
// initialize logging module
158-
// logging::init(option_env!("LOG"));
159-
160157
polyhal::common::init(&PageAllocImpl);
161158
get_mem_areas().into_iter().for_each(|(start, size)| {
162159
info!("memory area: {:#x} - {:#x}", start, start + size);
163160
frame_allocator::add_frame_map(start, start + size);
164161
});
165162

166-
println!("run kernel @ hart {}", hart_id);
167-
163+
info!("run kernel @ hart {}", hart_id);
168164
info!("program size: {}KB", (end as usize - start as usize) / 1024);
169165

170-
// Boot all application core.
171-
// polyhal::multicore::MultiCore::boot_all();
172-
173166
devices::prepare_drivers();
174167

168+
log::debug!("device fdt: {}", get_fdt().is_some());
169+
175170
if let Some(fdt) = get_fdt() {
176171
for node in fdt.all_nodes() {
177172
devices::try_to_add_device(&node);
@@ -181,9 +176,6 @@ fn main(hart_id: usize) {
181176
// get devices and init
182177
devices::regist_devices_irq();
183178

184-
// TODO: test ebreak
185-
// Instruction::ebreak();
186-
187179
// initialize filesystem
188180
fs::init();
189181
{
@@ -218,22 +210,16 @@ fn main(hart_id: usize) {
218210
// crate::syscall::cache_task_template("libc.so").expect("can't cache task");
219211
// crate::syscall::cache_task_template("lmbench_all").expect("can't cache task");
220212

221-
// loop {
222-
// info!("3");
223-
// }
224-
225213
// init kernel threads and async executor
226214
tasks::init();
227215
log::info!("run tasks");
228-
// loop { arch::wfi() }
229216
tasks::run_tasks();
230217

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

235222
IRQ::int_enable();
236-
// loop { arch::wfi() }
237223
tasks::run_tasks();
238224
info!("shutdown ap core");
239225
}

kernel/src/tasks/initproc.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,9 @@ pub async fn initproc() {
283283
// command("busybox sh busybox_testcode.sh").await;
284284

285285
// command("busybox echo run libctest_testcode.sh").await;
286-
command("busybox sh libctest_testcode.sh").await;
286+
// command("busybox sh libctest_testcode.sh").await;
287+
// command("busybox sh").await;
288+
command("ls").await;
287289
// command("busybox echo Hello World!").await;
288290
// command("busybox sh").await;
289291
// command("hello").await;

scripts/cli-qemu.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ class QemuRunner {
66
arch: string;
77
bus: string = "device";
88
builder: KernelBuilder;
9+
memorySize: string = "1G";
10+
smp: string = "1";
11+
912

1013
constructor(options: CommandOptions<globalArgType>, builder: KernelBuilder) {
1114
this.arch = options.arch;
@@ -50,15 +53,16 @@ class QemuRunner {
5053
args: [
5154
...this.getQemuArchExec(),
5255
"-m",
53-
"1G",
56+
this.memorySize,
5457
"-nographic",
5558
"-smp",
56-
"1",
59+
this.smp,
60+
// Dump Debug information.
5761
"-D",
5862
"qemu.log",
5963
"-d",
6064
"in_asm,int,pcall,cpu_reset,guest_errors",
61-
65+
// Add virtio block device.
6266
"-drive",
6367
"file=mount.img,if=none,format=raw,id=x0",
6468
"-device",

scripts/kernel.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class KernelBuilder {
1616
this.elfPath = `${Deno.cwd()}/target/${targetMap[arch]}/release/kernel`;
1717
this.binPath = `${this.elfPath}.bin`;
1818

19-
this.rustflags = Deno.env.get('rustflags') || "";
19+
this.rustflags = Deno.env.get('RUSTFLAGS') || "";
2020
}
2121

2222
buildFlags() {
@@ -25,14 +25,16 @@ export class KernelBuilder {
2525
"-Clink-arg=-no-pie",
2626
"-Ztls-model=local-exec",
2727
`--cfg=root_fs="ext4_rs"`,
28-
'--cfg=board="qemu"'
28+
'--cfg=board="qemu"',
29+
`--cfg=driver="kvirtio,kgoldfish-rtc,ns16550a"`
2930
];
3031

31-
this.rustflags += rustflags.join(" ");
32+
this.rustflags += ' ' + rustflags.join(" ");
3233
}
3334

3435
async buildElf() {
3536
this.buildFlags();
37+
console.log(this.rustflags);
3638

3739
const buildProc = new Deno.Command("cargo", {
3840
args: [

0 commit comments

Comments
 (0)