no graphic support and fix task spawn bug

This commit is contained in:
Yuke Peng
2022-09-06 05:20:43 -07:00
parent 128ffa0bff
commit 33f4bd86ed
7 changed files with 47 additions and 17 deletions

View File

@ -4,7 +4,16 @@ use std::{
process::{Command, ExitStatus}, process::{Command, ExitStatus},
time::Duration, time::Duration,
}; };
const RUN_ARGS: &[&str] = &["--no-reboot", "-s"]; const RUN_ARGS: &[&str] = &[
"--no-reboot",
"-s",
"-device",
"isa-debug-exit,iobase=0xf4,iosize=0x04",
"-serial",
"stdio",
"-display",
"none",
];
const TEST_ARGS: &[&str] = &[ const TEST_ARGS: &[&str] = &[
"-device", "-device",
"isa-debug-exit,iobase=0xf4,iosize=0x04", "isa-debug-exit,iobase=0xf4,iosize=0x04",

View File

@ -20,3 +20,9 @@ uart_16550 = "0.2.0"
[dependencies.lazy_static] [dependencies.lazy_static]
version = "1.0" version = "1.0"
features = ["spin_no_std"] features = ["spin_no_std"]
[features]
default = ["serial_print"]
serial_print = []

View File

@ -127,15 +127,15 @@ impl fmt::Write for Writer {
/// Like the `print!` macro in the standard library, but prints to the VGA text buffer. /// Like the `print!` macro in the standard library, but prints to the VGA text buffer.
#[macro_export] #[macro_export]
macro_rules! print { macro_rules! screen_print {
($($arg:tt)*) => ($crate::device::framebuffer::_print(format_args!($($arg)*))); ($($arg:tt)*) => ($crate::device::framebuffer::_print(format_args!($($arg)*)));
} }
/// Like the `println!` macro in the standard library, but prints to the VGA text buffer. /// Like the `println!` macro in the standard library, but prints to the VGA text buffer.
#[macro_export] #[macro_export]
macro_rules! println { macro_rules! screen_println {
() => ($crate::print!("\n")); () => ($crate::screen_print!("\n"));
($($arg:tt)*) => ($crate::print!("{}\n", format_args!($($arg)*))); ($($arg:tt)*) => ($crate::screen_print!("{}\n", format_args!($($arg)*)));
} }
/// Prints the given formatted string to the VGA text buffer /// Prints the given formatted string to the VGA text buffer

View File

@ -42,6 +42,16 @@ use trap::{IrqCallbackHandle, IrqLine, TrapFrame};
static mut IRQ_CALLBACK_LIST: Vec<IrqCallbackHandle> = Vec::new(); static mut IRQ_CALLBACK_LIST: Vec<IrqCallbackHandle> = Vec::new();
#[cfg(not(feature = "serial_print"))]
pub use crate::screen_print as print;
#[cfg(not(feature = "serial_print"))]
pub use crate::screen_println as println;
#[cfg(feature = "serial_print")]
pub use crate::serial_print as print;
#[cfg(feature = "serial_print")]
pub use crate::serial_println as println;
pub fn init(boot_info: &'static mut BootInfo) { pub fn init(boot_info: &'static mut BootInfo) {
let siz = boot_info.framebuffer.as_ref().unwrap() as *const FrameBuffer as usize; let siz = boot_info.framebuffer.as_ref().unwrap() as *const FrameBuffer as usize;
device::init(boot_info.framebuffer.as_mut().unwrap()); device::init(boot_info.framebuffer.as_mut().unwrap());

View File

@ -3,7 +3,7 @@ use core::fmt::Arguments;
/// Print log message /// Print log message
/// This function should *NOT* be directly called. /// This function should *NOT* be directly called.
/// Instead, print logs with macros. /// Instead, print logs with macros.
#[cfg(not(test))] #[cfg(not(feature = "serial_print"))]
#[doc(hidden)] #[doc(hidden)]
pub fn log_print(args: Arguments) { pub fn log_print(args: Arguments) {
use crate::device::framebuffer::WRITER; use crate::device::framebuffer::WRITER;
@ -18,16 +18,18 @@ pub fn log_print(args: Arguments) {
/// Print log message /// Print log message
/// This function should *NOT* be directly called. /// This function should *NOT* be directly called.
/// Instead, print logs with macros. /// Instead, print logs with macros.
#[cfg(test)] #[cfg(feature = "serial_print")]
#[doc(hidden)] #[doc(hidden)]
pub fn log_print(args: Arguments) { pub fn log_print(args: Arguments) {
use crate::device::serial::SERIAL; use crate::device::serial::SERIAL;
use core::fmt::Write; use core::fmt::Write;
use x86_64::instructions::interrupts;
interrupts::without_interrupts(|| {
SERIAL SERIAL
.lock() .lock()
.write_fmt(args) .write_fmt(args)
.expect("Printing to serial failed"); .expect("Printing to serial failed");
});
} }
/// This macro should not be directly called. /// This macro should not be directly called.

View File

@ -50,14 +50,18 @@ pub(crate) fn get_idle_task_cx_ptr() -> *mut TaskContext {
} }
/// call this function to switch to other task by using GLOBAL_SCHEDULER /// call this function to switch to other task by using GLOBAL_SCHEDULER
pub fn schedule() {
switch_to_task(fetch_task().expect("no more task found"));
}
/// call this function to switch to other task
/// ///
/// if current task is none, then it will use the default task context and it will not return to this function again /// if current task is none, then it will use the default task context and it will not return to this function again
/// ///
/// if current task status is exit, then it will not add to the scheduler /// if current task status is exit, then it will not add to the scheduler
/// ///
/// before context switch, current task will switch to the next task /// before context switch, current task will switch to the next task
pub fn schedule() { pub fn switch_to_task(next_task: Arc<Task>) {
let next_task = fetch_task().expect("no more task found");
let current_task_option = current_task(); let current_task_option = current_task();
let next_task_cx_ptr = &next_task.inner_ctx() as *const TaskContext; let next_task_cx_ptr = &next_task.inner_ctx() as *const TaskContext;
let current_task: Arc<Task>; let current_task: Arc<Task>;

View File

@ -5,6 +5,7 @@ use lazy_static::lazy_static;
use crate::cell::Cell; use crate::cell::Cell;
use crate::config::{KERNEL_STACK_SIZE, PAGE_SIZE}; use crate::config::{KERNEL_STACK_SIZE, PAGE_SIZE};
use crate::task::processor::switch_to_task;
use crate::trap::{CalleeRegs, SyscallFrame, TrapFrame}; use crate::trap::{CalleeRegs, SyscallFrame, TrapFrame};
use crate::user::{syscall_switch_to_user_space, trap_switch_to_user_space, UserSpace}; use crate::user::{syscall_switch_to_user_space, trap_switch_to_user_space, UserSpace};
use crate::vm::{VmAllocOptions, VmFrameVec}; use crate::vm::{VmAllocOptions, VmFrameVec};
@ -177,9 +178,7 @@ impl Task {
- size_of::<SyscallFrame>(); - size_of::<SyscallFrame>();
let arc_self = Arc::new(result); let arc_self = Arc::new(result);
add_task(arc_self.clone()); switch_to_task(arc_self.clone());
schedule();
Ok(arc_self) Ok(arc_self)
} }