proc_mapstacks

This commit is contained in:
Garen Tyler 2023-11-12 13:34:46 -07:00
parent 320180764f
commit c39b98dd02
Signed by: garentyler
GPG Key ID: D7A048C454CB7054
3 changed files with 12 additions and 21 deletions

View File

@ -16,23 +16,6 @@ extern void forkret(void);
// must be acquired before any p->lock.
struct spinlock wait_lock;
// Allocate a page for each process's kernel stack.
// Map it high in memory, followed by an invalid
// guard page.
void
proc_mapstacks(pagetable_t kpgtbl)
{
struct proc *p;
for(p = proc; p < &proc[NPROC]; p++) {
char *pa = kalloc();
if(pa == 0)
panic("kalloc");
uint64 va = KSTACK((int) (p - proc));
kvmmap(kpgtbl, va, (uint64)pa, PGSIZE, PTE_R | PTE_W);
}
}
struct proc *allocproc(void);
// a user program that calls exec("/init")

View File

@ -1,6 +1,6 @@
use super::{
asm,
mem::{make_satp, pte2pa},
mem::{make_satp, pte2pa, kstack},
plic::PLIC,
power::QEMU_POWER,
};
@ -17,7 +17,6 @@ use crate::{
kalloc::{kalloc, kfree},
memmove, memset,
},
proc::process::proc_mapstacks,
};
use core::ptr::{addr_of, addr_of_mut, null_mut};
@ -34,6 +33,9 @@ pub static mut KERNEL_PAGETABLE: Pagetable = null_mut();
/// Make a direct-map page table for the kernel.
pub unsafe fn kvmmake() -> Pagetable {
let pagetable = kalloc() as Pagetable;
if pagetable.is_null() {
panic!("kalloc");
}
memset(pagetable.cast(), 0, PAGE_SIZE as u32);
// QEMU test interface used for power management.
@ -105,7 +107,14 @@ pub unsafe fn kvmmake() -> Pagetable {
);
// Allocate and map a kernel stack for each process.
proc_mapstacks(pagetable);
for i in 0..crate::NPROC {
let page = kalloc();
if page.is_null() {
panic!("kalloc");
}
let virtual_addr = kstack(i) as u64;
kvmmap(pagetable, virtual_addr, page as u64, PAGE_SIZE as u64, PTE_R | PTE_W);
}
pagetable
}

View File

@ -46,7 +46,6 @@ extern "C" {
pub fn userinit();
pub fn forkret();
pub fn wait(addr: u64) -> i32;
pub fn proc_mapstacks(kpgtbl: Pagetable);
}
pub static NEXT_PID: AtomicI32 = AtomicI32::new(1);