memcpy(tsk, current, sizeof(task_union));
- tsk->cr3 = (unsigned long)alloc_one_page(0);
+ tsk->cr3 = va2pa((unsigned long)alloc_one_page(0));
assert(tsk->cr3 != 0);
unsigned int i, j;
- pde_t *pde_src = (pde_t *)current->cr3;
- pde_t *pde_dst = (pde_t *)tsk->cr3;
+ pde_t *pde_src = (pde_t *)pa2va(current->cr3);
+ pde_t *pde_dst = (pde_t *)pa2va(tsk->cr3);
- memcpy((void *)tsk->cr3, (void *)current->cr3, PAGE_SIZE);
+ memcpy((void *)pa2va(tsk->cr3), (void *)pa2va(current->cr3), PAGE_SIZE);
for (i = 0; i < PAGE_PDE_CNT; ++i) {
unsigned long spde = (unsigned long)pde_src[i];
}
void user_task_entry() {
- // printk("user_task_entry: %08x\n", ring3_entry);
-
- unsigned long ring3_text_page = va2pa(alloc_one_page(0));
- unsigned long ring3_data_page = va2pa(alloc_one_page(0));
- unsigned long ring3_bss_page = va2pa(alloc_one_page(0));
- unsigned long *pt_text_page = (unsigned long *)va2pa(alloc_one_page(0));
- unsigned long *pt_data_page = (unsigned long *)va2pa(alloc_one_page(0));
- unsigned long *pt_bss_page = (unsigned long *)va2pa(alloc_one_page(0));
- unsigned long *p = (unsigned long *)current->cr3;
-
- // text: 0x0800_0000
- // data: 0x2000_0000
- // bss: 0x3000_0000
- unsigned long text_at = 0x08000000;
- unsigned long data_at = 0x20000000;
- unsigned long bbs_at = 0x30000000;
-
- unsigned long flag = 0;
-
- flag |= PAGE_P;
- flag |= PAGE_US;
-
- p[text_at >> 22] = (unsigned long)pt_text_page | PAGE_P | PAGE_US;
- pt_text_page[0] = ring3_text_page;
- p[data_at >> 22] = (unsigned long)pt_data_page | PAGE_P | PAGE_WR | PAGE_US;
- pt_data_page[0] = ring3_data_page;
- p[bbs_at >> 22] = (unsigned long)pt_bss_page | PAGE_P | PAGE_WR | PAGE_US;
- pt_bss_page[0] = ring3_bss_page;
-
- LOAD_CR3(current->cr3);
+ // // printk("user_task_entry: %08x\n", ring3_entry);
+
+ // unsigned long ring3_text_page = va2pa(alloc_one_page(0));
+ // unsigned long ring3_data_page = va2pa(alloc_one_page(0));
+ // unsigned long ring3_bss_page = va2pa(alloc_one_page(0));
+ // unsigned long *pt_text_page = (unsigned long *)va2pa(alloc_one_page(0));
+ // unsigned long *pt_data_page = (unsigned long *)va2pa(alloc_one_page(0));
+ // unsigned long *pt_bss_page = (unsigned long *)va2pa(alloc_one_page(0));
+ // unsigned long *p = (unsigned long *)((current->cr3 - 0xC0000000));
+
+ // asm volatile("xchg %%bx, %%bx;mov %%eax, %%ebx;xchg %%bx, %%bx;"::"a"(p));
+
+ // // text: 0x0800_0000
+ // // data: 0x2000_0000
+ // // bss: 0x3000_0000
+ // unsigned long text_at = 0x08000000;
+ // unsigned long data_at = 0x20000000;
+ // unsigned long bbs_at = 0x30000000;
+
+ // unsigned long flag = 0;
+
+ // flag |= PAGE_P;
+ // flag |= PAGE_US;
+
+ // p[text_at >> 22] = (unsigned long)pt_text_page | PAGE_P | PAGE_US;
+ // pt_text_page[0] = ring3_text_page;
+ // p[data_at >> 22] = (unsigned long)pt_data_page | PAGE_P | PAGE_WR | PAGE_US;
+ // pt_data_page[0] = ring3_data_page;
+ // p[bbs_at >> 22] = (unsigned long)pt_bss_page | PAGE_P | PAGE_WR | PAGE_US;
+ // pt_bss_page[0] = ring3_bss_page;
+
+ // //
+ // asm("xchg %bx, %bx");
+ // LOAD_CR3((unsigned long)p);
// 现在要准备返回用户态
// eip --> edx
return pid;
}
-void load_cr3(task_union *tsk) { LOAD_CR3(tsk->cr3); }
+void load_cr3(task_union *tsk) { LoadCR3(tsk->cr3); }
extern pde_t __initdata init_pgd[PDECNT_PER_PAGE] __attribute__((__aligned__(PAGE_SIZE)));
// root_task.fps[i] = 0;
root_task.esp0 = ((unsigned long)&root_task) + sizeof(root_task);
- root_task.cr3 = (unsigned long)(init_pgd);
+ root_task.cr3 = va2pa((unsigned long)(init_pgd));
tss.esp0 = root_task.esp0;
inline task_union *get_next_tsk() { return 0; }
void switch_to() {
- LOAD_CR3(current->cr3);
+ LoadCR3(current->cr3);
tss.esp0 = current->esp0;
wrmsr(MSR_SYSENTER_ESP, current->esp0, 0);
}
#include <types.h>
void do_no_page(void *addr) {
- pde_t *page_dir = (pde_t *)current->cr3;
+ pde_t *page_dir = (pde_t *)pa2va(current->cr3);
pte_t *page_tbl = 0;
unsigned long page = alloc_one_page(0);
int npde = get_npd(addr);
int npte = get_npt(addr);
- pde_t *page_dir = (pde_t *)current->cr3;
+ pde_t *page_dir = (pde_t *)pa2va(current->cr3);
pte_t *page_tbl = pa2va(PAGE_ALIGN(page_dir[npde]));
unsigned long wp_pa_addr = PAGE_ALIGN(page_tbl[npte]);