add more comments and CHANGE Fn name: run_user_shell TO add_user_shell

master
chyyuu 6 years ago
parent c853eda9b3
commit 28dbfd66b9

@ -10,9 +10,9 @@ pub fn init() {
*flags |= EferFlags::SYSTEM_CALL_EXTENSIONS;
});
let mut star = Msr::new(0xC0000081);
let mut lstar = Msr::new(0xC0000082);
let mut sfmask = Msr::new(0xC0000084);
let mut star = Msr::new(0xC0000081); // legacy mode SYSCALL target
let mut lstar = Msr::new(0xC0000082); // long mode SYSCALL target
let mut sfmask = Msr::new(0xC0000084); // EFLAGS mask for syscall
// flags to clear on syscall
// copy from Linux 5.0

@ -40,26 +40,33 @@ pub extern "C" fn _start(boot_info: &'static BootInfo) -> ! {
memory::init(boot_info);
// Now heap is available
gdt::init();
// Init GDT
gdt::init();
//get local apic id of cpu
cpu::init();
// Use IOAPIC instead of PIC, use APIC Timer instead of PIT, init serial&keyboard in x86_64
driver::init();
// init pci/bus-based devices ,e.g. Intel 10Gb NIC, ...
crate::drivers::init();
// init cpu scheduler and process manager, and add user shell app in process manager
crate::process::init();
//wake up other CPUs
AP_CAN_INIT.store(true, Ordering::Relaxed);
//call the first main function in kernel.
crate::kmain();
}
/// The entry point for other processors
fn other_start() -> ! {
// Init trap handling.
idt::init();
// init gdt
gdt::init();
// init local apic
cpu::init();
// setup fast syscall in xv6-64
interrupt::fast_syscall::init();
//call the first main function in kernel.
crate::kmain();
}

@ -1,3 +1,17 @@
//! Define the FrameAllocator for physical memory
//! x86_64 -- 64GB
//! AARCH64/MIPS/RV -- 1GB
//! K210(rv64) -- 8MB
//! NOTICE:
//! type FrameAlloc = bitmap_allocator::BitAllocXXX
//! KSTACK_SIZE -- 16KB
//!
//! KERNEL_HEAP_SIZE:
//! x86-64 -- 32MB
//! AARCH64/RV64 -- 8MB
//! MIPS/RV32 -- 2MB
//! mipssim/malta(MIPS) -- 10MB
use super::HEAP_ALLOCATOR;
pub use crate::arch::paging::*;
use crate::consts::MEMORY_OFFSET;
@ -85,17 +99,17 @@ pub fn dealloc_frame(target: usize) {
}
pub struct KernelStack(usize);
const STACK_SIZE: usize = 0x4000;
const KSTACK_SIZE: usize = 0x4000; //16KB
impl KernelStack {
pub fn new() -> Self {
use alloc::alloc::{alloc, Layout};
let bottom =
unsafe { alloc(Layout::from_size_align(STACK_SIZE, STACK_SIZE).unwrap()) } as usize;
unsafe { alloc(Layout::from_size_align(KSTACK_SIZE, KSTACK_SIZE).unwrap())} as usize;
KernelStack(bottom)
}
pub fn top(&self) -> usize {
self.0 + STACK_SIZE
self.0 + KSTACK_SIZE
}
}
@ -105,7 +119,7 @@ impl Drop for KernelStack {
unsafe {
dealloc(
self.0 as _,
Layout::from_size_align(STACK_SIZE, STACK_SIZE).unwrap(),
Layout::from_size_align(KSTACK_SIZE, KSTACK_SIZE).unwrap(),
);
}
}

@ -20,7 +20,7 @@ pub fn init() {
}
}
crate::shell::run_user_shell();
crate::shell::add_user_shell();
info!("process: init end");
}

@ -8,7 +8,7 @@ use alloc::vec::Vec;
#[cfg(not(feature = "run_cmdline"))]
pub fn run_user_shell() {
pub fn add_user_shell() {
/// the busybox of alpine linux can not transfer env vars into child process
/// Now we use busybox from
/// https://raw.githubusercontent.com/docker-library/busybox/82bc0333a9ae148fbb4246bcbff1487b3fc0c510/musl/busybox.tar.xz -O busybox.tar.xz
@ -43,7 +43,7 @@ pub fn run_user_shell() {
}
#[cfg(feature = "run_cmdline")]
pub fn run_user_shell() {
pub fn add_user_shell() {
let cmdline = CMDLINE.read();
let inode = ROOT_INODE.lookup(&cmdline).unwrap();
let data = inode.read_as_vec().unwrap();

Loading…
Cancel
Save