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},
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] = &[
"-device",
"isa-debug-exit,iobase=0xf4,iosize=0x04",

View File

@ -20,3 +20,9 @@ uart_16550 = "0.2.0"
[dependencies.lazy_static]
version = "1.0"
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.
#[macro_export]
macro_rules! print {
macro_rules! screen_print {
($($arg:tt)*) => ($crate::device::framebuffer::_print(format_args!($($arg)*)));
}
/// Like the `println!` macro in the standard library, but prints to the VGA text buffer.
#[macro_export]
macro_rules! println {
() => ($crate::print!("\n"));
($($arg:tt)*) => ($crate::print!("{}\n", format_args!($($arg)*)));
macro_rules! screen_println {
() => ($crate::screen_print!("\n"));
($($arg:tt)*) => ($crate::screen_print!("{}\n", format_args!($($arg)*)));
}
/// 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();
#[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) {
let siz = boot_info.framebuffer.as_ref().unwrap() as *const FrameBuffer as usize;
device::init(boot_info.framebuffer.as_mut().unwrap());

View File

@ -3,7 +3,7 @@ use core::fmt::Arguments;
/// Print log message
/// This function should *NOT* be directly called.
/// Instead, print logs with macros.
#[cfg(not(test))]
#[cfg(not(feature = "serial_print"))]
#[doc(hidden)]
pub fn log_print(args: Arguments) {
use crate::device::framebuffer::WRITER;
@ -18,16 +18,18 @@ pub fn log_print(args: Arguments) {
/// Print log message
/// This function should *NOT* be directly called.
/// Instead, print logs with macros.
#[cfg(test)]
#[cfg(feature = "serial_print")]
#[doc(hidden)]
pub fn log_print(args: Arguments) {
use crate::device::serial::SERIAL;
use core::fmt::Write;
SERIAL
.lock()
.write_fmt(args)
.expect("Printing to serial failed");
use x86_64::instructions::interrupts;
interrupts::without_interrupts(|| {
SERIAL
.lock()
.write_fmt(args)
.expect("Printing to serial failed");
});
}
/// 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
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 status is exit, then it will not add to the scheduler
///
/// before context switch, current task will switch to the next task
pub fn schedule() {
let next_task = fetch_task().expect("no more task found");
pub fn switch_to_task(next_task: Arc<Task>) {
let current_task_option = current_task();
let next_task_cx_ptr = &next_task.inner_ctx() as *const TaskContext;
let current_task: Arc<Task>;

View File

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