create and switch to new stack
This commit is contained in:
parent
45d6fea05b
commit
908b5d1d5f
1 changed files with 19 additions and 1 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
#include "std.h"
|
#include "std.h"
|
||||||
#include "ram.h"
|
#include "ram.h"
|
||||||
|
#include "x86_64/address.h"
|
||||||
#include "x86_64/asm.h"
|
#include "x86_64/asm.h"
|
||||||
#include "x86_64/paging.h"
|
#include "x86_64/paging.h"
|
||||||
|
|
||||||
|
|
@ -494,13 +495,21 @@ void pt_create_minimal(void) {
|
||||||
|
|
||||||
// 16 GiB identity map with hugepages starting at low end of upper half of AS
|
// 16 GiB identity map with hugepages starting at low end of upper half of AS
|
||||||
unsigned int npages_in_gb = 1ull << 18;
|
unsigned int npages_in_gb = 1ull << 18;
|
||||||
|
unsigned int npages_idmap = 16 * npages_in_gb;
|
||||||
struct vpn vpn_idmap_start = vpn_from_aligned_va(va_from_value(1ull << 47));
|
struct vpn vpn_idmap_start = vpn_from_aligned_va(va_from_value(1ull << 47));
|
||||||
pt_map_range(vpn_idmap_start,
|
pt_map_range(vpn_idmap_start,
|
||||||
ppn_from_pagenum(0),
|
ppn_from_pagenum(0),
|
||||||
16 * npages_in_gb,
|
npages_idmap,
|
||||||
true, true, false,
|
true, true, false,
|
||||||
new_cr3);
|
new_cr3);
|
||||||
|
|
||||||
|
// new stack with 4 GiB size and guard pages around
|
||||||
|
// TODO one stack for each core
|
||||||
|
struct vpn stack_virt = vpn_from_pagenum(vpn_to_pagenum(vpn_idmap_start) + npages_idmap + 1);
|
||||||
|
struct ppn stack_phys;
|
||||||
|
ASSERT(ram_alloc_frame_zeroed(&stack_phys, RAM_PAGE_NORMAL));
|
||||||
|
pt_map_single(stack_virt, stack_phys, true, true, false, new_cr3);
|
||||||
|
|
||||||
#ifdef PT_CREATE_DEBUG
|
#ifdef PT_CREATE_DEBUG
|
||||||
uint64_t value = pa_to_value(pa_from_ppn(new_cr3));
|
uint64_t value = pa_to_value(pa_from_ppn(new_cr3));
|
||||||
printf("new cr3: %p\n", value);
|
printf("new cr3: %p\n", value);
|
||||||
|
|
@ -529,9 +538,18 @@ void pt_create_minimal(void) {
|
||||||
set_cr3(value);
|
set_cr3(value);
|
||||||
set_identity_mapping(vpn_idmap_start);
|
set_identity_mapping(vpn_idmap_start);
|
||||||
|
|
||||||
|
// stack switch
|
||||||
|
// it doesn't really make sense to copy stack contents because rbp and pointers
|
||||||
|
// to local variables will point to the wrong location.
|
||||||
|
// this means we won't leave this function for now.
|
||||||
|
uint64_t new_sp = va_to_canonical(va_from_vpn(stack_virt)) + 4096;
|
||||||
|
__asm__("mov %0,%%rsp" ::"r"(new_sp));
|
||||||
|
|
||||||
#ifdef PT_CREATE_DEBUG
|
#ifdef PT_CREATE_DEBUG
|
||||||
printf("hello from new page table!\n");
|
printf("hello from new page table!\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
PANIC("end of pt_create_minimal");
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- iterators ---
|
// --- iterators ---
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue