Skip to content

Commit

Permalink
feat: support new polyhal
Browse files Browse the repository at this point in the history
  • Loading branch information
yfblock committed Aug 3, 2024
1 parent 7525ad4 commit 73fc87e
Show file tree
Hide file tree
Showing 24 changed files with 99 additions and 78 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ packets.pcap
kernel/*.lds
qemu.log
kernel/src/drivers.rs
graph.png
graph.png
tools/iso/example
13 changes: 3 additions & 10 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
{
"rust-analyzer.checkOnSave.allTargets": false,
"rust-analyzer.checkOnSave.extraArgs": [
// "--target",
// "riscv64imac-unknown-none-elf"
// "x86_64-unknown-none"
],
"files.associations": {
"*.in": "cpp",
"fcntl.h": "c"
}
"rust-analyzer.check.allTargets": false,
"rust-analyzer.check.extraArgs": [],
"rust-analyzer.procMacro.enable": true
}
29 changes: 16 additions & 13 deletions Cargo.lock

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

12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ ifeq ($(ROOT_FS), fat32)
sudo mount $(FS_IMG) mount/ -o uid=1000,gid=1000
sudo rm -rf mount/*
else ifeq ($(ROOT_FS), ext4_rs)
mkfs.ext4 $(FS_IMG)
mkfs.ext4 -b 4096 $(FS_IMG)
mkdir mount/ -p
sudo mount $(FS_IMG) mount/
else
Expand Down Expand Up @@ -161,4 +161,12 @@ gdb:
addr2line:
addr2line -sfipe $(KERNEL_ELF) | rustfilt

.PHONY: all run build clean gdb justbuild

iso: build
cp $(KERNEL_ELF) tools/iso/example
grub-mkrescue -o bootable.iso tools/iso

boot-iso: iso
qemu-system-x86_64 -cdrom bootable.iso -serial stdio

.PHONY: all run build clean gdb justbuild iso boot-iso
7 changes: 6 additions & 1 deletion byteos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ global:
configs:
board: "qemu"
# Available are fat32, ext4 and ext4_rs.
root_fs: "fat32"
# root_fs: "fat32"
root_fs: "ext4_rs"
env:
HEAP_SIZE: "0x0180_0000"
MOUNT_IMG_PATH: "mount.img"
Expand All @@ -22,6 +23,10 @@ bin:
target: "x86_64-unknown-none"
configs:
driver: "kvirtio,kgoldfish-rtc,ns16550a"
x86_64-generic:
target: "x86_64-unknown-none"
configs:
driver: "kramdisk,kgoldfish-rtc,ns16550a"
aarch64-qemu:
target: "aarch64-unknown-none-softfloat"
configs:
Expand Down
2 changes: 1 addition & 1 deletion kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ logging = { git = "https://github.com/Byte-OS/logging.git", features = []}
log = "0.4"
devices = { git = "https://github.com/Byte-OS/devices.git" }
hal = { git = "https://github.com/Byte-OS/hal.git" }
polyhal = { git = "https://github.com/Byte-OS/polyhal.git" }
polyhal = { git = "https://github.com/Byte-OS/polyhal.git", features = ["trap"]}
fs = { git = "https://github.com/Byte-OS/fs.git" }
fdt = "0.1.5"
executor = { git = "https://github.com/Byte-OS/executor.git" }
Expand Down
17 changes: 1 addition & 16 deletions kernel/linker.lds.S
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,8 @@ SECTIONS
*(.sigtrx .sigtrx.*)
}

_load_end = .;

. = ALIGN(4K);
_percpu_start = .;
.percpu 0x0 : AT(_percpu_start) {
_percpu_load_start = .;
*(.percpu .percpu.*)
_percpu_load_end = .;
. = ALIGN(64);
_percpu_size_aligned = .;

. = _percpu_load_start + _percpu_size_aligned * %SMP%;
}
. = _percpu_start + SIZEOF(.percpu);
_percpu_end = .;

.bss ALIGN(4K): {
_load_end = .;
*(.bss.stack)
_sbss = .;
*(.bss .bss.*)
Expand Down
14 changes: 9 additions & 5 deletions kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ mod user;

use core::sync::atomic::{AtomicBool, Ordering};

use devices::{self, get_int_device};
use devices::{self, get_int_device, VIRT_ADDR_START};
use executor::current_task;
use frame_allocator::{self, frame_alloc_persist, frame_unalloc};
use polyhal::addr::{PhysPage, VirtPage};
use polyhal::common::{get_fdt, get_mem_areas, PageAlloc};
use polyhal::irq::IRQ;
use polyhal::{get_mem_areas, PageAlloc, TrapFrame, TrapFrameArgs, TrapType, VIRT_ADDR_START};
use polyhal::trap::TrapType;
use polyhal::trapframe::{TrapFrame, TrapFrameArgs};
use tasks::UserTask;
use user::user_cow_int;
use vfscore::OpenFlags;
Expand Down Expand Up @@ -155,7 +157,7 @@ fn main(hart_id: usize) {
// initialize logging module
logging::init(option_env!("LOG"));

polyhal::init(&PageAllocImpl);
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);
Expand All @@ -170,7 +172,7 @@ fn main(hart_id: usize) {

devices::prepare_drivers();

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

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

// initialize filesystem
fs::init();
Expand Down Expand Up @@ -221,6 +224,7 @@ fn main(hart_id: usize) {

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

Expand Down
10 changes: 8 additions & 2 deletions kernel/src/panic.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
use polyhal::{hart_id, shutdown};
// use backtrace::backtrace;
use core::panic::PanicInfo;

use polyhal::instruction::Instruction;

#[inline]
fn hart_id() -> usize {
0
}

// 程序遇到错误
#[panic_handler]
fn panic_handler(info: &PanicInfo) -> ! {
Expand All @@ -21,5 +27,5 @@ fn panic_handler(info: &PanicInfo) -> ! {
// backtrace();
println!("!TEST FINISH!");
// loop {}
shutdown()
Instruction::shutdown()
}
2 changes: 1 addition & 1 deletion kernel/src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::{cmp, net::SocketAddrV4};
use alloc::{sync::Arc, vec::Vec};
use fs::INodeInterface;
use lose_net_stack::net_trait::SocketInterface;
use polyhal::debug::DebugConsole;
use polyhal::debug_console::DebugConsole;
use sync::Mutex;
use vfscore::{Metadata, PollEvent, VfsResult};

Expand Down
4 changes: 2 additions & 2 deletions kernel/src/syscall/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use fs::VfsError;
use hal::TimeVal;
use num_derive::FromPrimitive;
use polyhal::addr::VirtAddr;
use polyhal::pagetable::MappingFlags;
use polyhal::TrapFrame;
use polyhal::trapframe::TrapFrame;
use polyhal::MappingFlags;
use signal::SigProcMask;

#[repr(i32)]
Expand Down
4 changes: 2 additions & 2 deletions kernel/src/syscall/mm.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use core::ops::Add;

use devices::PAGE_SIZE;
use frame_allocator::ceil_div;
use log::debug;
use polyhal::addr::{VirtAddr, VirtPage};
use polyhal::PAGE_SIZE;
use polyhal::USER_VADDR_END;
use polyhal::pagetable::USER_VADDR_END;

use crate::syscall::consts::from_vfs;
use crate::syscall::consts::MSyncFlags;
Expand Down
4 changes: 2 additions & 2 deletions kernel/src/syscall/shm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use core::ops::Add;

use crate::tasks::{MapedSharedMemory, SharedMemory, SHARED_MEMORY};
use alloc::{sync::Arc, vec::Vec};
use devices::PAGE_SIZE;
use frame_allocator::{ceil_div, frame_alloc_much, FrameTracker};
use log::debug;
use polyhal::addr::{VirtAddr, VirtPage};
use polyhal::{pagetable::MappingFlags, PAGE_SIZE};
use polyhal::{addr::{VirtAddr, VirtPage}, MappingFlags};

use crate::user::UserTaskContainer;

Expand Down
2 changes: 1 addition & 1 deletion kernel/src/syscall/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl UserTaskContainer {
pub async fn sys_arch_prctl(&self, code: usize, addr: usize) -> SysResult {
use crate::syscall::consts::{ArchPrctlCode, LinuxError};
use num_traits::FromPrimitive;
use polyhal::TrapFrameArgs;
use polyhal::trapframe::TrapFrameArgs;

let arch_prctl_code = FromPrimitive::from_usize(code).ok_or(LinuxError::EINVAL)?;
debug!(
Expand Down
3 changes: 2 additions & 1 deletion kernel/src/syscall/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use alloc::{
{boxed::Box, sync::Arc},
};
use async_recursion::async_recursion;
use devices::PAGE_SIZE;
use polyhal::{trapframe::TrapFrameArgs, MappingFlags, Time, VirtPage};
use core::cmp;
use executor::{select, thread, tid2task, yield_now, AsyncTask};
use frame_allocator::{ceil_div, frame_alloc_much, FrameTracker};
Expand All @@ -25,7 +27,6 @@ use fs::TimeSpec;
use hal::{current_nsec, TimeVal};
use log::{debug, warn};
use num_traits::FromPrimitive;
use polyhal::{addr::VirtPage, pagetable::MappingFlags, time::Time, TrapFrameArgs, PAGE_SIZE};
use signal::SignalFlags;
use sync::Mutex;
use vfscore::OpenFlags;
Expand Down
4 changes: 2 additions & 2 deletions kernel/src/tasks/elf.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use alloc::{collections::BTreeMap, string::String, sync::Arc, vec::Vec};
use devices::PAGE_SIZE;
use executor::AsyncTask;
use log::warn;
use polyhal::addr::VirtPage;
use polyhal::{TrapFrame, TrapFrameArgs, PAGE_SIZE};
use polyhal::{addr::VirtPage, trapframe::{TrapFrame, TrapFrameArgs}};
use xmas_elf::{
program::Type,
sections::SectionData,
Expand Down
4 changes: 2 additions & 2 deletions kernel/src/tasks/initproc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use fs::{
};
use log::debug;
use logging::get_char;
use polyhal::{debug::DebugConsole, hart_id, shutdown};
use polyhal::{debug_console::DebugConsole, instruction::Instruction};
use vfscore::INodeInterface;

use crate::tasks::add_user_task;
Expand Down Expand Up @@ -407,6 +407,6 @@ pub async fn initproc() {
})
.is_none()
{
shutdown();
Instruction::shutdown();
}
}
4 changes: 2 additions & 2 deletions kernel/src/tasks/memset.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use alloc::{sync::Arc, vec::Vec};
use devices::PAGE_SIZE;
use core::{
cmp::min,
fmt::Debug,
ops::{Deref, DerefMut},
};
use frame_allocator::FrameTracker;
use fs::File;
use polyhal::addr::VirtPage;
use polyhal::{pagetable::PageTable, PAGE_SIZE};
use polyhal::{addr::VirtPage, PageTable};

/// Memory set for storing the memory and its map relation.
#[derive(Debug)]
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/tasks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use alloc::{sync::Arc, vec::Vec};
use devices::get_net_device;
use executor::{current_task, thread, yield_now, AsyncTask, TaskId, DEFAULT_EXECUTOR};
use hal::{ITimerVal, TimeVal};
use polyhal::get_cpu_num;
use polyhal::common::get_cpu_num;

use crate::syscall::{exec_with_process, NET_SERVER};
use crate::user::entry::user_entry;
Expand Down
Loading

0 comments on commit 73fc87e

Please sign in to comment.