Skip to content

Commit

Permalink
feat: use latest polyhal and fmt code
Browse files Browse the repository at this point in the history
  • Loading branch information
yfblock committed Jun 4, 2024
1 parent fe410e0 commit 23f441e
Show file tree
Hide file tree
Showing 22 changed files with 60 additions and 56 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions byteos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ bin:
build_std: "core,alloc"
configs:
driver: "kramdisk"
loongarch64-2k1000:
target: "loongarch64-unknown-none"
build_std: "core,alloc"
configs:
driver: "kramdisk"
board: "2k1000"
6 changes: 5 additions & 1 deletion kernel/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ fn main() {

fn gen_linker_script(platform: &str) -> Result<()> {
let arch = env::var("CARGO_CFG_TARGET_ARCH").expect("can't find target");
let board = env::var("CARGO_CFG_BOARD").unwrap_or("qemu".to_string());
let fname = format!("linker_{}_{}.lds", arch, platform);
let (output_arch, kernel_base) = if arch == "x86_64" {
("i386:x86-64", "0xffffff8000200000")
Expand All @@ -54,7 +55,10 @@ fn gen_linker_script(platform: &str) -> Result<()> {
("aarch64", "0xffffff8040080000")
// ("aarch64", "0xffff000040080000")
} else if arch.contains("loongarch64") {
("loongarch64", "0x9000000090000000")
match board.as_str() {
"2k1000" => ("loongarch64", "0x9000000098000000"),
_ => ("loongarch64", "0x9000000090000000"),
}
} else {
(arch.as_str(), "0")
};
Expand Down
30 changes: 13 additions & 17 deletions kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,12 @@ mod user;

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

use polyhal::addr::{PhysPage, VirtPage};
use polyhal::{
disable_irq, enable_irq, get_mem_areas, PageAlloc, TrapFrame, TrapFrameArgs, TrapType,
VIRT_ADDR_START,
};
use devices::{self, get_int_device};
use executor::current_task;
use frame_allocator::{self, frame_alloc_persist, frame_unalloc};
use hal;
use polyhal::addr::{PhysPage, VirtPage};
use polyhal::irq::IRQ;
use polyhal::{get_mem_areas, PageAlloc, TrapFrame, TrapFrameArgs, TrapType, VIRT_ADDR_START};
use tasks::UserTask;
use user::user_cow_int;
use vfscore::OpenFlags;
Expand Down Expand Up @@ -139,9 +136,12 @@ fn kernel_interrupt(cx_ref: &mut TrapFrame, trap_type: TrapType) {
#[polyhal::arch_entry]
fn main(hart_id: usize) {
static BOOT_CORE_FLAGS: AtomicBool = AtomicBool::new(false);
disable_irq();
IRQ::int_disable();
// Ensure this is the first core
if BOOT_CORE_FLAGS.compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed).is_ok() {
if BOOT_CORE_FLAGS
.compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed)
.is_ok()
{
extern "C" {
fn start();
fn end();
Expand All @@ -157,6 +157,7 @@ fn main(hart_id: usize) {

polyhal::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 @@ -175,12 +176,11 @@ fn main(hart_id: usize) {
}
}

// initialize interrupt
hal::interrupt::init();

// get devices and init
devices::regist_devices_irq();

polyhal::instruction::Instruction::ebreak();

// initialize filesystem
fs::init();
{
Expand All @@ -204,7 +204,7 @@ fn main(hart_id: usize) {
}

// enable interrupts
enable_irq();
IRQ::int_enable();

// cache task with task templates
// crate::syscall::cache_task_template("/bin/busybox").expect("can't cache task");
Expand All @@ -228,11 +228,7 @@ fn main(hart_id: usize) {
} else {
println!("run kernel @ hart {}", hart_id);

// initialize interrupt
hal::interrupt::init();

// enable_irq();
enable_irq();
IRQ::int_enable();
// loop { arch::wfi() }
tasks::run_tasks();
info!("shutdown ap core");
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/socket.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use core::{cmp, net::SocketAddrV4};

use alloc::{sync::Arc, vec::Vec};
use polyhal::debug::DebugConsole;
use fs::INodeInterface;
use lose_net_stack::net_trait::SocketInterface;
use polyhal::debug::DebugConsole;
use sync::Mutex;
use vfscore::{Metadata, PollEvent, VfsResult};

Expand Down
6 changes: 3 additions & 3 deletions kernel/src/syscall/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
use core::fmt::{Debug, Display};
use core::marker::PhantomData;

use polyhal::addr::VirtAddr;
use polyhal::pagetable::MappingFlags;
use polyhal::TrapFrame;
use bitflags::bitflags;
use cfg_if::cfg_if;
use fs::VfsError;
use hal::TimeVal;
use num_derive::FromPrimitive;
use polyhal::addr::VirtAddr;
use polyhal::pagetable::MappingFlags;
use polyhal::TrapFrame;
use signal::SigProcMask;

#[repr(i32)]
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/syscall/fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use num_traits::FromPrimitive;
use vfscore::FileType;

use alloc::sync::Arc;
use polyhal::addr::VirtAddr;
use bit_field::BitArray;
use executor::yield_now;
use fs::pipe::create_pipe;
use fs::{OpenFlags, PollEvent, PollFd, SeekFrom, Stat, StatFS, StatMode, TimeSpec, UTIME_NOW};
use log::debug;
use polyhal::addr::VirtAddr;

use crate::epoll::{EpollEvent, EpollFile};
use crate::syscall::consts::{from_vfs, FcntlCmd, IoVec, AT_CWD};
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 frame_allocator::ceil_div;
use log::debug;
use polyhal::addr::{VirtAddr, VirtPage};
use polyhal::PAGE_SIZE;
use polyhal::USER_VADDR_END;
use frame_allocator::ceil_div;
use log::debug;

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 polyhal::addr::{VirtAddr, VirtPage};
use polyhal::{pagetable::MappingFlags, 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 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 @@ -149,8 +149,8 @@ impl UserTaskContainer {
#[cfg(target_arch = "x86_64")]
pub async fn sys_arch_prctl(&self, code: usize, addr: usize) -> SysResult {
use crate::syscall::consts::{ArchPrctlCode, LinuxError};
use arch::TrapFrameArgs;
use num_traits::FromPrimitive;
use polyhal::TrapFrameArgs;

let arch_prctl_code = FromPrimitive::from_usize(code).ok_or(LinuxError::EINVAL)?;
debug!(
Expand Down
7 changes: 1 addition & 6 deletions kernel/src/syscall/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ use alloc::{
vec::Vec,
{boxed::Box, sync::Arc},
};
use polyhal::{
addr::VirtPage,
pagetable::MappingFlags,
time::Time,
{TrapFrameArgs, PAGE_SIZE},
};
use async_recursion::async_recursion;
use core::cmp;
use executor::{select, thread, tid2task, yield_now, AsyncTask};
Expand All @@ -31,6 +25,7 @@ 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
2 changes: 1 addition & 1 deletion kernel/src/syscall/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use core::{
task::{Context, Poll},
};

use polyhal::time::Time;
use executor::select;
use fs::TimeSpec;
pub use hal::current_nsec;
use hal::{ITimerVal, TimeVal};
use log::{debug, warn};
use polyhal::time::Time;

use crate::{
tasks::{WaitHandleAbleSignal, TMS},
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/tasks/async_ops.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use core::{cmp, future::Future, pin::Pin, task::Poll};

use alloc::{sync::Arc, vec::Vec};
use polyhal::time::Time;
use executor::AsyncTask;
use polyhal::time::Time;
use sync::Mutex;

use crate::syscall::consts::LinuxError;
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 polyhal::addr::VirtPage;
use polyhal::{TrapFrame, TrapFrameArgs, PAGE_SIZE};
use executor::AsyncTask;
use log::warn;
use polyhal::addr::VirtPage;
use polyhal::{TrapFrame, TrapFrameArgs, PAGE_SIZE};
use xmas_elf::{
program::Type,
sections::SectionData,
Expand Down
5 changes: 4 additions & 1 deletion kernel/src/tasks/initproc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use alloc::{
string::{String, ToString},
vec::Vec,
};
use polyhal::{debug::DebugConsole, hart_id, shutdown};
use executor::{current_task, release_task, task::TaskType, tid2task, yield_now, TASK_MAP};
use frame_allocator::get_free_pages;
use fs::{
Expand All @@ -13,6 +12,7 @@ use fs::{
};
use log::debug;
use logging::get_char;
use polyhal::{debug::DebugConsole, hart_id, shutdown};
use vfscore::INodeInterface;

use crate::tasks::add_user_task;
Expand Down Expand Up @@ -284,6 +284,9 @@ pub async fn initproc() {

// command("busybox echo run libctest_testcode.sh").await;
command("busybox sh libctest_testcode.sh").await;
// command("busybox echo Hello World!").await;
// command("busybox sh").await;
// command("hello").await;
// command("ls").await;

// simple_shell().await;
Expand Down
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 polyhal::addr::VirtPage;
use polyhal::{pagetable::PageTable, 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};

/// 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
@@ -1,10 +1,10 @@
use alloc::string::String;
use alloc::sync::Weak;
use alloc::{sync::Arc, vec::Vec};
use polyhal::get_cpu_num;
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 crate::syscall::{exec_with_process, NET_SERVER};
use crate::user::entry::user_entry;
Expand Down
8 changes: 4 additions & 4 deletions kernel/src/tasks/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ use alloc::{
sync::{Arc, Weak},
vec::Vec,
};
use executor::{release_task, task::TaskType, task_id_alloc, AsyncTask, TaskId};
use frame_allocator::{ceil_div, frame_alloc_much};
use fs::File;
use log::debug;
use polyhal::{
addr::{PhysPage, VirtAddr, VirtPage},
pagetable::{MappingFlags, MappingSize, PageTableWrapper},
{TrapFrame, TrapFrameArgs, PAGE_SIZE},
};
use executor::{release_task, task::TaskType, task_id_alloc, AsyncTask, TaskId};
use frame_allocator::{ceil_div, frame_alloc_much};
use fs::File;
use log::debug;
use signal::{SigAction, SigProcMask, SignalFlags, REAL_TIME_SIGNAL_NUM};
use sync::{Mutex, MutexGuard, RwLock};
use vfscore::OpenFlags;
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/user/entry.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use alloc::boxed::Box;
use polyhal::{kernel_page_table, TrapFrame};
use async_recursion::async_recursion;
use executor::{yield_now, AsyncTask};
use futures_lite::future;
use hal::TimeVal;
use log::debug;
use polyhal::{kernel_page_table, TrapFrame};
use signal::SignalFlags;

use crate::tasks::{current_user_task, UserTaskControlFlow};
Expand Down
8 changes: 4 additions & 4 deletions kernel/src/user/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use ::signal::SignalFlags;
use alloc::sync::Arc;
use polyhal::addr::VirtPage;
use polyhal::{pagetable::MappingFlags, run_user_task, time::Time, TrapFrame, TrapFrameArgs};
use executor::{AsyncTask, TaskId};
use frame_allocator::frame_alloc;
use log::{debug, warn};
use polyhal::addr::VirtPage;
use polyhal::{pagetable::MappingFlags, run_user_task, time::Time, TrapFrame, TrapFrameArgs};

use crate::tasks::{MapTrack, MemType, UserTask};
use crate::{
Expand All @@ -24,11 +24,11 @@ pub struct UserTaskContainer {
/// Copy on write.
/// call this function when trigger store/instruction page fault.
/// copy page or remap page.
pub fn user_cow_int(task: Arc<UserTask>, _cx_ref: &mut TrapFrame, addr: usize) {
pub fn user_cow_int(task: Arc<UserTask>, cx_ref: &mut TrapFrame, addr: usize) {
let vpn = VirtPage::from_addr(addr);
warn!(
"store/instruction page fault @ {:#x} vaddr: {:#x} paddr: {:?} task_id: {}",
addr,
cx_ref[TrapFrameArgs::SEPC],
addr,
task.page_table.translate(addr.into()),
task.get_task_id()
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/user/signal.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use core::mem::size_of;

use polyhal::{TrapFrameArgs, SIG_RETURN_ADDR};
use executor::AsyncTask;
use log::debug;
use polyhal::{TrapFrameArgs, SIG_RETURN_ADDR};
use signal::SignalFlags;

use crate::syscall::consts::{SignalUserContext, UserRef};
Expand Down
Loading

0 comments on commit 23f441e

Please sign in to comment.