Skip to content

Commit d25558f

Browse files
committed
feat: support multicore
1 parent ed76271 commit d25558f

File tree

9 files changed

+120
-32
lines changed

9 files changed

+120
-32
lines changed

.cargo/config.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 编译的目标平台
22
[build]
3-
target = 'riscv64imac-unknown-none-elf'
3+
target = 'riscv64gc-unknown-none-elf'
44
# target = 'x86_64-unknown-none'
55
# target = 'aarch64-unknown-none-softfloat'
66
# target = 'loongarch64-unknown-none'
@@ -10,6 +10,7 @@ rustflags = [
1010
'-Cforce-frame-pointers=yes',
1111
'-Clink-arg=-no-pie',
1212
'--cfg=board="qemu"',
13+
'--cfg=root_fs="ext4"',
1314
'-Zunstable-options',
1415
'-Ztls-model=local-exec',
1516
# '--cfg=driver="kvirtio,kgoldfish-rtc,ns16550a"',

Cargo.lock

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

Makefile

+19-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ QEMU_EXEC ?=
99
BUILD_ARGS :=
1010
GDB ?= gdb-multiarch
1111
MOUNT_IMG_PATH ?= $(shell pwd)/mount.img
12+
ROOT_FS := fat32
1213

1314
BUS := device
1415
ifeq ($(ARCH), x86_64)
@@ -19,7 +20,7 @@ ifeq ($(ARCH), x86_64)
1920
-cpu IvyBridge-v2
2021
BUS := pci
2122
else ifeq ($(ARCH), riscv64)
22-
TARGET := riscv64imac-unknown-none-elf
23+
TARGET := riscv64gc-unknown-none-elf
2324
QEMU_EXEC += qemu-system-$(ARCH) \
2425
-machine virt \
2526
-bios $(SBI) \
@@ -48,9 +49,9 @@ SBI := tools/opensbi-$(BOARD).bin
4849
features:=
4950
K210-SERIALPORT = /dev/ttyUSB0
5051
K210-BURNER = tools/k210/kflash.py
51-
QEMU_EXEC += -m 1G\
52+
QEMU_EXEC += -m 128M\
5253
-nographic \
53-
-smp 2 \
54+
-smp 1 \
5455
-D qemu.log -d in_asm,int,pcall,cpu_reset,guest_errors
5556

5657
ifeq ($(RELEASE), release)
@@ -85,15 +86,27 @@ offline:
8586
rust-objcopy --binary-architecture=riscv64 $(KERNEL_ELF) --strip-all -O binary os.bin
8687

8788
fs-img:
89+
ifeq ($(ROOT_FS), fat32)
8890
rm -f $(FS_IMG)
89-
dd if=/dev/zero of=$(FS_IMG) bs=1M count=64
91+
dd if=/dev/zero of=$(FS_IMG) bs=1M count=128
9092
mkfs.vfat -F 32 $(FS_IMG)
9193
mkdir mount/ -p
9294
sudo mount $(FS_IMG) mount/ -o uid=1000,gid=1000
93-
rm -rf mount/*
94-
-cp -rf tools/$(TESTCASE)/* mount/
95+
sudo rm -rf mount/*
96+
sudo cp -rf tools/$(TESTCASE)/* mount/
97+
sudo chmod 777 $(FS_IMG)
9598
sync
9699
sudo umount $(FS_IMG)
100+
else ifeq ($(ROOT_FS), ext4)
101+
rm -f $(FS_IMG)
102+
dd if=/dev/zero of=$(FS_IMG) bs=1M count=128
103+
mkfs.ext4 -F -O ^metadata_csum_seed $(FS_IMG)
104+
mkdir mount/ -p
105+
sudo mount $(FS_IMG) mount/
106+
sudo cp -rf tools/$(TESTCASE)/* mount/
107+
sync
108+
sudo umount $(FS_IMG)
109+
endif
97110

98111
build:
99112
# RUST_BACKTRACE=1 LOG=$(LOG) MOUNT_IMG_PATH=$(MOUNT_IMG_PATH) cargo build --target $(TARGET) $(BUILD_ARGS) --features "$(features)"

byteos.toml

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# build for riscv64-qemu
22
[bin.riscv64-qemu]
3-
target = "riscv64imac-unknown-none-elf"
3+
target = "riscv64gc-unknown-none-elf"
44
[bin.riscv64-qemu.configs]
55
board = "qemu"
66
driver = "kvirtio,kgoldfish-rtc,ns16550a"
7+
root_fs = "ext4"
78

89
[bin.riscv64-qemu.env]
910
HEAP_SIZE = "0x0180_0000"
@@ -15,9 +16,10 @@ target = "x86_64-unknown-none"
1516
[bin.x86_64-qemu.configs]
1617
board = "qemu"
1718
driver = "kvirtio,kgoldfish-rtc,ns16550a"
19+
root_fs = "ext4"
1820

1921
[bin.x86_64-qemu.env]
20-
HEAP_SIZE = "0x0200_0000"
22+
HEAP_SIZE = "0x0180_0000"
2123
MOUNT_IMG_PATH = "mount.img"
2224

2325
# build for aarch64-qemu
@@ -26,9 +28,10 @@ target = "aarch64-unknown-none-softfloat"
2628
[bin.aarch64-qemu.configs]
2729
board = "qemu"
2830
driver = "kvirtio,kgoldfish-rtc,ns16550a"
31+
root_fs = "fat32"
2932

3033
[bin.aarch64-qemu.env]
31-
HEAP_SIZE = "0x0200_0000"
34+
HEAP_SIZE = "0x0180_0000"
3235
MOUNT_IMG_PATH = "mount.img"
3336

3437
# build for loongarch64-qemu
@@ -38,8 +41,9 @@ build_std = true
3841
[bin.loongarch64-qemu.configs]
3942
board = "qemu"
4043
driver = "kramdisk"
44+
root_fs = "ext4"
4145

4246
[bin.loongarch64-qemu.env]
43-
HEAP_SIZE = "0x0200_0000"
47+
HEAP_SIZE = "0x0180_0000"
4448
CARGO_CFG_DRIVER = "kramdisk"
4549
MOUNT_IMG_PATH = "mount.img"

kernel/src/main.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ fn kernel_interrupt(cx_ref: &mut TrapFrame, trap_type: TrapType) {
6969
| TrapType::InstructionPageFault(addr)
7070
| TrapType::LoadPageFault(addr) => {
7171
if addr > VIRT_ADDR_START {
72-
panic!("kernel error: {:#x}", addr);
72+
panic!(
73+
"kernel page error: {:#x} sepc: {:#x}",
74+
addr,
75+
cx_ref[TrapFrameArgs::SEPC]
76+
);
7377
}
7478
// judge whether it is trigger by a user_task handler.
7579
if let Some(task) = current_task().downcast_arc::<UserTask>().ok() {

kernel/src/panic.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,17 @@ use core::panic::PanicInfo;
77
fn panic_handler(info: &PanicInfo) -> ! {
88
if let Some(location) = info.location() {
99
println!(
10-
"\x1b[1;31m[Core {}][{}:{}]panic: '{}'\x1b[0m",
10+
"\x1b[1;31m[Core {}] [{}:{}]\x1b[0m",
1111
hart_id(),
1212
location.file(),
1313
location.line(),
14-
info.message().unwrap()
15-
);
16-
} else {
17-
println!(
18-
"\x1b[1;31m[Core {}]panic: '{}'\x1b[0m",
19-
hart_id(),
20-
info.message().unwrap()
2114
);
2215
}
16+
println!(
17+
"\x1b[1;31m[Core {}] panic: '{}'\x1b[0m",
18+
hart_id(),
19+
info.message().unwrap()
20+
);
2321
// backtrace();
2422
println!("!TEST FINISH!");
2523
// loop {}

kernel/src/syscall/consts.rs

+3
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,9 @@ impl<T> UserRef<T> {
897897

898898
#[inline]
899899
pub fn slice_until_valid(&self, is_valid: fn(T) -> bool) -> &'static mut [T] {
900+
if self.addr.addr() == 0 {
901+
return &mut [];
902+
}
900903
self.addr.slice_until(is_valid)
901904
}
902905

kernel/src/syscall/fd.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl UserTaskContainer {
169169
let new_dir = to_node(&self.task, newdir_fd, new_path)?;
170170
if old_file_type == FileType::File {
171171
let new_file = new_dir
172-
.dentry_open(new_path, OpenFlags::empty())
172+
.dentry_open(new_path, OpenFlags::O_CREAT)
173173
.expect("can't find new file");
174174
// TODO: Check the file exists
175175
let file_size = old_file.metadata().map_err(from_vfs)?.size;

kernel/src/tasks/initproc.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ fn clear() {
5757

5858
async fn kill_all_tasks() {
5959
TASK_MAP.lock().values().into_iter().for_each(|task| {
60-
task.upgrade().inspect(|x| x.exit(100));
60+
task.upgrade().inspect(|x| {
61+
if x.get_task_type() == TaskType::MonolithicTask {
62+
x.exit(100)
63+
}
64+
});
6165
});
6266
}
6367

@@ -264,7 +268,7 @@ pub async fn initproc() {
264268
// command("./runtest.exe -w entry-static.exe pthread_cond_smasher").await;
265269

266270
// command("test-fscanf").await;
267-
// command("./runtest.exe -w entry-static.exe argv").await;
271+
// command("./runtest.exe -w entry-static.exe statvfs").await;
268272
// command("entry-static.exe fscanf").await;
269273
// command(" busybox sh").await;
270274
// command("./a.out").await;
@@ -279,14 +283,22 @@ pub async fn initproc() {
279283
// command("busybox sh busybox_testcode.sh").await;
280284

281285
// command("busybox echo run libctest_testcode.sh").await;
282-
// command("busybox sh libctest_testcode.sh").await;
286+
command("busybox sh libctest_testcode.sh").await;
287+
// command("ls").await;
288+
289+
// simple_shell().await;
290+
// command("busybox sh").await;
283291

284292
// command("busybox sh ./run-static.sh").await;
285293
// command("./runtest.exe -w entry-dynamic.exe pthread_robust_detach").await;
286294
// command("busybox echo 123").await;
287295
// command("qjs.static test.js").await;
288296
// command("qjs.static").await;
289297
// command("busybox sh").await;
298+
// command("busybox mkdir touch123").await;
299+
// command("busybox rm -r touch123").await;
300+
// command("busybox touch 123 >> touch123/123").await;
301+
// command("busybox cat touch123/123").await;
290302
// command("busybox echo run lua_testcode.sh").await;
291303
// command("busybox sh lua_testcode.sh").await;
292304

@@ -306,8 +318,8 @@ pub async fn initproc() {
306318
// command("busybox echo run lmbench_testcode.sh").await;
307319
// command("busybox sh lmbench_testcode.sh").await;
308320

309-
command("busybox echo run unixbench_testcode.sh").await;
310-
command("busybox sh unixbench_testcode.sh").await;
321+
// command("busybox echo run unixbench_testcode.sh").await;
322+
// command("busybox sh unixbench_testcode.sh").await;
311323

312324
// command("copy-file-range-test-1").await;
313325
// command("copy-file-range-test-2").await;

0 commit comments

Comments
 (0)