🎨 更改代码结构

This commit is contained in:
fslongjin 2022-04-14 16:53:11 +08:00
parent 777932704d
commit 53c553c730
2 changed files with 48 additions and 55 deletions

View File

@ -599,7 +599,6 @@ void mm_map_phys_addr_user(ul virt_addr_start, ul phys_addr_start, ul length, ul
// 页面写穿,禁止缓存 // 页面写穿,禁止缓存
set_pdt(tmp1, mk_pdt((ul)phys_addr_start + i, flags | PAGE_USER_PAGE)); set_pdt(tmp1, mk_pdt((ul)phys_addr_start + i, flags | PAGE_USER_PAGE));
kdebug("mk_pdt((ul)phys_addr_start + i, flags | PAGE_USER_PAGE) = %#018lx",mk_pdt((ul)phys_addr_start + i, flags | PAGE_USER_PAGE));
} }
flush_tlb(); flush_tlb();

View File

@ -8,7 +8,6 @@
#include <mm/slab.h> #include <mm/slab.h>
#include <sched/sched.h> #include <sched/sched.h>
extern void system_call(void); extern void system_call(void);
ul _stack_start; // initial proc的栈基地址虚拟地址 ul _stack_start; // initial proc的栈基地址虚拟地址
struct mm_struct initial_mm = {0}; struct mm_struct initial_mm = {0};
@ -58,8 +57,6 @@ void __switch_to(struct process_control_block *prev, struct process_control_bloc
color = WHITE; color = WHITE;
else else
color = YELLOW; color = YELLOW;
} }
/** /**
@ -129,7 +126,7 @@ ul do_execve(struct pt_regs *regs)
// mm_map_proc_page_table(get_CR3(), true, 0x800000, alloc_pages(ZONE_NORMAL, 1, PAGE_PGT_MAPPED)->addr_phys, PAGE_2M_SIZE, PAGE_USER_PAGE, true); // mm_map_proc_page_table(get_CR3(), true, 0x800000, alloc_pages(ZONE_NORMAL, 1, PAGE_PGT_MAPPED)->addr_phys, PAGE_2M_SIZE, PAGE_USER_PAGE, true);
uint64_t addr = 0x800000UL; uint64_t addr = 0x800000UL;
/*
unsigned long *tmp = phys_2_virt((unsigned long *)((unsigned long)get_CR3() & (~0xfffUL)) + ((addr >> PAGE_GDT_SHIFT) & 0x1ff)); unsigned long *tmp = phys_2_virt((unsigned long *)((unsigned long)get_CR3() & (~0xfffUL)) + ((addr >> PAGE_GDT_SHIFT) & 0x1ff));
unsigned long *virtual = kmalloc(PAGE_4K_SIZE, 0); unsigned long *virtual = kmalloc(PAGE_4K_SIZE, 0);
@ -144,16 +141,15 @@ ul do_execve(struct pt_regs *regs)
set_pdt(tmp, mk_pdt(p->addr_phys, PAGE_USER_PAGE)); set_pdt(tmp, mk_pdt(p->addr_phys, PAGE_USER_PAGE));
flush_tlb(); flush_tlb();
/*
mm_map_phys_addr_user(addr, alloc_pages(ZONE_NORMAL, 1, PAGE_PGT_MAPPED)->addr_phys, PAGE_2M_SIZE, PAGE_USER_PAGE);
*/ */
mm_map_phys_addr_user(addr, alloc_pages(ZONE_NORMAL, 1, PAGE_PGT_MAPPED)->addr_phys, PAGE_2M_SIZE, PAGE_USER_PAGE);
if (!(current_pcb->flags & PF_KTHREAD)) if (!(current_pcb->flags & PF_KTHREAD))
current_pcb->addr_limit = KERNEL_BASE_LINEAR_ADDR; current_pcb->addr_limit = KERNEL_BASE_LINEAR_ADDR;
// 将程序代码拷贝到对应的内存中 // 将程序代码拷贝到对应的内存中
memcpy((void *)0x800000, user_level_function, 1024); memcpy((void *)0x800000, user_level_function, 1024);
// kdebug("program copied!"); // kdebug("program copied!");
return 0; return 0;
} }
@ -385,8 +381,6 @@ unsigned long do_fork(struct pt_regs *regs, unsigned long clone_flags, unsigned
else else
kdebug("is kernel proc."); kdebug("is kernel proc.");
tsk->state = PROC_RUNNING; tsk->state = PROC_RUNNING;
sched_cfs_enqueue(tsk); sched_cfs_enqueue(tsk);