Repos / kernel.git / commitdiff
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ce414a1)
raw | patch | inline | side by side (parent: ce414a1)
| author | zhaoyanbai <zhaoyanbai@126.com> | |
| Wed, 3 Nov 2021 11:59:58 +0000 (19:59 +0800) | ||
| committer | zhaoyanbai <zhaoyanbai@126.com> | |
| Wed, 3 Nov 2021 11:59:58 +0000 (19:59 +0800) |
| include/page.h | patch | blob | history | |
| kernel/exec.c | patch | blob | history | |
| kernel/fork.c | patch | blob | history | |
| kernel/init.c | patch | blob | history | |
| kernel/sched.c | patch | blob | history | |
| mm/mm.c | patch | blob | history | |
| mm/page.c | patch | blob | history |
diff --git a/include/page.h b/include/page.h
--- a/include/page.h
+++ b/include/page.h
#define MAX_ORDER (11)
-#define LOAD_CR3(pde) asm("movl %%edx, %%cr3" ::"d"(va2pa(pde)))
+#define LoadCR3(cr3) asm volatile ("movl %%edx, %%cr3"::"d"(cr3))
typedef unsigned int gfp_t;
diff --git a/kernel/exec.c b/kernel/exec.c
--- a/kernel/exec.c
+++ b/kernel/exec.c
unsigned int npde = get_npd(vaddr);
unsigned int npte = get_npt(vaddr);
- pde_t *page_dir = (pde_t *)current->cr3;
+ pde_t *page_dir = (pde_t *)pa2va(current->cr3);
pte_t *page_table = (pte_t *)PAGE_ALIGN(page_dir[npde]);
if (page_table == 0) {
diff --git a/kernel/fork.c b/kernel/fork.c
--- a/kernel/fork.c
+++ b/kernel/fork.c
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];
diff --git a/kernel/init.c b/kernel/init.c
--- a/kernel/init.c
+++ b/kernel/init.c
}
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
diff --git a/kernel/sched.c b/kernel/sched.c
--- a/kernel/sched.c
+++ b/kernel/sched.c
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);
}
--- a/mm/mm.c
+++ b/mm/mm.c
// paging for user space
set_page_shared(sysexit);
- LOAD_CR3(init_pgd);
+ LoadCR3(va2pa(init_pgd));
}
void init_mm() {
diff --git a/mm/page.c b/mm/page.c
--- a/mm/page.c
+++ b/mm/page.c
#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]);