mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-15 08:16:47 +00:00
fix the logic to start the first process
This commit is contained in:
parent
128ffa0bff
commit
6e11ee39da
@ -6,7 +6,7 @@
|
|||||||
#![feature(const_btree_new)]
|
#![feature(const_btree_new)]
|
||||||
#![feature(cstr_from_bytes_until_nul)]
|
#![feature(cstr_from_bytes_until_nul)]
|
||||||
|
|
||||||
use kxos_frame::println;
|
use kxos_frame::{println, info, task::Task};
|
||||||
use process::Process;
|
use process::Process;
|
||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
@ -20,15 +20,26 @@ pub fn init() {
|
|||||||
process::fifo_scheduler::init();
|
process::fifo_scheduler::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_first_kernel_task() {
|
pub fn init_task() {
|
||||||
Process::spawn_kernel_task(|| {
|
println!("[kernel] Hello world from init task!");
|
||||||
println!("hello world from kernel");
|
|
||||||
|
let process = Process::spawn_kernel_task(|| {
|
||||||
|
println!("[kernel] Hello world from kernel!");
|
||||||
});
|
});
|
||||||
|
info!("spawn kernel process, pid = {}", process.pid());
|
||||||
|
|
||||||
|
let elf_file_content = read_elf_content();
|
||||||
|
let process = Process::spawn_from_elf(elf_file_content);
|
||||||
|
info!("spwan user process, pid = {}", process.pid());
|
||||||
|
|
||||||
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_first_process() {
|
/// first process never return
|
||||||
|
pub fn run_first_process() -> ! {
|
||||||
let elf_file_content = read_elf_content();
|
let elf_file_content = read_elf_content();
|
||||||
Process::spawn_from_elf(elf_file_content);
|
Task::spawn(init_task, None::<u8>, None).expect("Spawn first task failed");
|
||||||
|
unreachable!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_elf_content() -> &'static [u8] {
|
fn read_elf_content() -> &'static [u8] {
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use alloc::sync::Arc;
|
|
||||||
use kxos_frame::vm::{Vaddr, VmPerm, VmSpace};
|
use kxos_frame::vm::{Vaddr, VmPerm, VmSpace};
|
||||||
|
|
||||||
use super::vm_page::VmPageRange;
|
use super::vm_page::VmPageRange;
|
||||||
@ -8,9 +7,8 @@ pub const USER_STACK_SIZE: usize = 0x1000 * 16; // 64KB
|
|||||||
|
|
||||||
pub struct UserStack {
|
pub struct UserStack {
|
||||||
/// The low address of user stack
|
/// The low address of user stack
|
||||||
pub stack_base: Vaddr,
|
stack_base: Vaddr,
|
||||||
stack_size: usize,
|
stack_size: usize,
|
||||||
vm_space: Option<Arc<VmSpace>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UserStack {
|
impl UserStack {
|
||||||
@ -19,7 +17,6 @@ impl UserStack {
|
|||||||
Self {
|
Self {
|
||||||
stack_base,
|
stack_base,
|
||||||
stack_size,
|
stack_size,
|
||||||
vm_space: None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,7 +25,6 @@ impl UserStack {
|
|||||||
Self {
|
Self {
|
||||||
stack_base: USER_STACK_BASE,
|
stack_base: USER_STACK_BASE,
|
||||||
stack_size: USER_STACK_SIZE,
|
stack_size: USER_STACK_SIZE,
|
||||||
vm_space: None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ use core::sync::atomic::{AtomicUsize, Ordering};
|
|||||||
|
|
||||||
use alloc::sync::Arc;
|
use alloc::sync::Arc;
|
||||||
// use kxos_frame::{sync::SpinLock, task::Task, user::UserSpace};
|
// use kxos_frame::{sync::SpinLock, task::Task, user::UserSpace};
|
||||||
use kxos_frame::{debug, task::Task};
|
use kxos_frame::task::Task;
|
||||||
|
|
||||||
use self::task::spawn_user_task_from_elf;
|
use self::task::spawn_user_task_from_elf;
|
||||||
|
|
||||||
@ -39,8 +39,7 @@ impl Process {
|
|||||||
F: Fn() + Send + Sync + 'static,
|
F: Fn() + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
let pid = new_pid();
|
let pid = new_pid();
|
||||||
debug!("pid = {}", pid);
|
let task = Task::spawn(task_fn, pid, None).expect("spawn kernel task failed");
|
||||||
let task = Task::spawn(task_fn, None::<u8>, None).expect("spawn kernel task failed");
|
|
||||||
let exit_code = 0;
|
let exit_code = 0;
|
||||||
Self {
|
Self {
|
||||||
pid,
|
pid,
|
||||||
@ -48,6 +47,10 @@ impl Process {
|
|||||||
exit_code,
|
exit_code,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn pid(&self) -> usize {
|
||||||
|
self.pid
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// create a new pid for new process
|
/// create a new pid for new process
|
||||||
|
@ -25,6 +25,7 @@ pub fn spawn_user_task_from_elf(elf_file_content: &[u8]) -> Arc<Task> {
|
|||||||
let cur = Task::current();
|
let cur = Task::current();
|
||||||
let user_space = cur.user_space().expect("user task should have user space");
|
let user_space = cur.user_space().expect("user task should have user space");
|
||||||
let mut user_mode = UserMode::new(user_space);
|
let mut user_mode = UserMode::new(user_space);
|
||||||
|
debug!("in user task");
|
||||||
loop {
|
loop {
|
||||||
let user_event = user_mode.execute();
|
let user_event = user_mode.execute();
|
||||||
debug!("return from user mode");
|
debug!("return from user mode");
|
||||||
|
@ -12,10 +12,8 @@ print_message:
|
|||||||
mov $1, %rax # syscall number of write
|
mov $1, %rax # syscall number of write
|
||||||
mov $1, %rdi # stdout
|
mov $1, %rdi # stdout
|
||||||
mov $message, %rsi # address of message
|
mov $message, %rsi # address of message
|
||||||
mov $message, %r11
|
mov $message_end, %rdx
|
||||||
mov $message_end, %r12
|
sub %rsi, %rdx # calculate message len
|
||||||
sub %r11, %r12 # calculate message len
|
|
||||||
mov %r12, %rdx # number of bytes
|
|
||||||
syscall
|
syscall
|
||||||
ret
|
ret
|
||||||
.section .rodata
|
.section .rodata
|
||||||
|
@ -20,8 +20,6 @@ fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
|
|||||||
|
|
||||||
kxos_std::init();
|
kxos_std::init();
|
||||||
kxos_std::run_first_process();
|
kxos_std::run_first_process();
|
||||||
|
|
||||||
loop {}
|
|
||||||
}
|
}
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
#[panic_handler]
|
#[panic_handler]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user