procinit in rust
This commit is contained in:
parent
089e6d2cc1
commit
320180764f
@ -7,13 +7,9 @@
|
|||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
struct proc proc[NPROC];
|
struct proc proc[NPROC];
|
||||||
|
|
||||||
struct proc *initproc;
|
struct proc *initproc;
|
||||||
|
|
||||||
extern void forkret(void);
|
extern void forkret(void);
|
||||||
|
|
||||||
extern char trampoline[]; // trampoline.S
|
|
||||||
|
|
||||||
// helps ensure that wakeups of wait()ing
|
// helps ensure that wakeups of wait()ing
|
||||||
// parents are not lost. helps obey the
|
// parents are not lost. helps obey the
|
||||||
// memory model when using p->parent.
|
// memory model when using p->parent.
|
||||||
@ -37,34 +33,8 @@ proc_mapstacks(pagetable_t kpgtbl)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize the proc table.
|
|
||||||
void
|
|
||||||
procinit(void)
|
|
||||||
{
|
|
||||||
struct proc *p;
|
|
||||||
|
|
||||||
initlock(&wait_lock, "wait_lock");
|
|
||||||
for(p = proc; p < &proc[NPROC]; p++) {
|
|
||||||
initlock(&p->lock, "proc");
|
|
||||||
p->state = UNUSED;
|
|
||||||
p->kstack = KSTACK((int) (p - proc));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Look in the process table for an UNUSED proc.
|
|
||||||
// If found, initialize state required to run in the kernel,
|
|
||||||
// and return with p->lock held.
|
|
||||||
// If there are no free procs, or a memory allocation fails, return 0.
|
|
||||||
struct proc *allocproc(void);
|
struct proc *allocproc(void);
|
||||||
|
|
||||||
// Create a user page table for a given process, with no user memory,
|
|
||||||
// but with trampoline and trapframe pages.
|
|
||||||
pagetable_t proc_pagetable(struct proc *p);
|
|
||||||
|
|
||||||
// Free a process's page table, and free the
|
|
||||||
// physical memory it refers to.
|
|
||||||
void proc_freepagetable(pagetable_t pagetable, uint64 sz);
|
|
||||||
|
|
||||||
// a user program that calls exec("/init")
|
// a user program that calls exec("/init")
|
||||||
// assembled from ../user/initcode.S
|
// assembled from ../user/initcode.S
|
||||||
// od -t xC ../user/initcode
|
// od -t xC ../user/initcode
|
||||||
@ -124,10 +94,6 @@ forkret(void)
|
|||||||
usertrapret();
|
usertrapret();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Atomically release lock and sleep on chan.
|
|
||||||
// Reacquires lock when awakened.
|
|
||||||
void sleep_lock(void *chan, struct spinlock *lk);
|
|
||||||
|
|
||||||
// Copy to either a user address, or kernel address,
|
// Copy to either a user address, or kernel address,
|
||||||
// depending on usr_dst.
|
// depending on usr_dst.
|
||||||
// Returns 0 on success, -1 on error.
|
// Returns 0 on success, -1 on error.
|
||||||
|
@ -29,8 +29,8 @@ pub mod mem {
|
|||||||
pub use super::riscv::{
|
pub use super::riscv::{
|
||||||
asm::sfence_vma as flush_cached_pages,
|
asm::sfence_vma as flush_cached_pages,
|
||||||
mem::{
|
mem::{
|
||||||
Pagetable, PagetableEntry, KERNEL_BASE, PAGE_SIZE, PHYSICAL_END, PTE_R, PTE_U, PTE_V,
|
kstack, Pagetable, PagetableEntry, KERNEL_BASE, PAGE_SIZE, PHYSICAL_END, PTE_R, PTE_U,
|
||||||
PTE_W, PTE_X, TRAMPOLINE, TRAPFRAME, VIRTUAL_MAX,
|
PTE_V, PTE_W, PTE_X, TRAMPOLINE, TRAPFRAME, VIRTUAL_MAX,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ use super::{
|
|||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
arch::{
|
arch::{
|
||||||
mem::{Pagetable, PAGE_SIZE, PTE_R, PTE_W, PTE_X, TRAMPOLINE, TRAPFRAME},
|
mem::{kstack, Pagetable, PAGE_SIZE, PTE_R, PTE_W, PTE_X, TRAMPOLINE, TRAPFRAME},
|
||||||
trap::InterruptBlocker,
|
trap::InterruptBlocker,
|
||||||
virtual_memory::{
|
virtual_memory::{
|
||||||
copyout, mappages, uvmalloc, uvmcopy, uvmcreate, uvmdealloc, uvmfree, uvmunmap,
|
copyout, mappages, uvmalloc, uvmcopy, uvmcreate, uvmdealloc, uvmfree, uvmunmap,
|
||||||
@ -35,8 +35,6 @@ use core::{
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
pub static mut proc: [Process; crate::NPROC];
|
pub static mut proc: [Process; crate::NPROC];
|
||||||
pub static mut initproc: *mut Process;
|
pub static mut initproc: *mut Process;
|
||||||
pub static mut nextpid: i32;
|
|
||||||
pub static mut pid_lock: Spinlock;
|
|
||||||
/// Helps ensure that wakeups of wait()ing
|
/// Helps ensure that wakeups of wait()ing
|
||||||
/// parents are not lost. Helps obey the
|
/// parents are not lost. Helps obey the
|
||||||
/// memory model when using p->parent.
|
/// memory model when using p->parent.
|
||||||
@ -45,18 +43,24 @@ extern "C" {
|
|||||||
// trampoline.S
|
// trampoline.S
|
||||||
pub static mut trampoline: *mut c_char;
|
pub static mut trampoline: *mut c_char;
|
||||||
|
|
||||||
pub fn procinit();
|
|
||||||
pub fn userinit();
|
pub fn userinit();
|
||||||
pub fn forkret();
|
pub fn forkret();
|
||||||
// pub fn fork() -> i32;
|
|
||||||
// pub fn exit(status: i32) -> !;
|
|
||||||
pub fn wait(addr: u64) -> i32;
|
pub fn wait(addr: u64) -> i32;
|
||||||
// pub fn procdump();
|
|
||||||
pub fn proc_mapstacks(kpgtbl: Pagetable);
|
pub fn proc_mapstacks(kpgtbl: Pagetable);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub static NEXT_PID: AtomicI32 = AtomicI32::new(1);
|
pub static NEXT_PID: AtomicI32 = AtomicI32::new(1);
|
||||||
|
|
||||||
|
/// Initialize the proc table.
|
||||||
|
pub unsafe fn procinit() {
|
||||||
|
wait_lock = Spinlock::new();
|
||||||
|
for (i, p) in proc.iter_mut().enumerate() {
|
||||||
|
*p = Process::new();
|
||||||
|
p.state = ProcessState::Unused;
|
||||||
|
p.kernel_stack = kstack(i) as u64;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Copy, Clone, Debug, Default, PartialEq)]
|
#[derive(Copy, Clone, Debug, Default, PartialEq)]
|
||||||
pub enum ProcessState {
|
pub enum ProcessState {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user