Skip to content

Commit

Permalink
修正页表相关命名
Browse files Browse the repository at this point in the history
  • Loading branch information
copi143 committed Dec 19, 2024
1 parent 258635c commit dd468a7
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 97 deletions.
2 changes: 1 addition & 1 deletion include/kernel/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ typedef struct regs64 {
} regs64;

void v86_int(byte intnum, regs16 *regs); // 调用虚拟86模式中断
void init_page(); // 初始化分页
void init_paging(); // 初始化分页
void init_gdtidt(); // 初始化全局描述符表和中断描述符表
void init_error_inthandler(); // 初始化错误中断处理程序
void fpu_disable(); // 禁用浮点运算单元
Expand Down
2 changes: 1 addition & 1 deletion include/kernel/mtask.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ typedef void (*cb_keyboard_t)(u8 data, u32 task);

typedef struct __PACKED__ task {
stack_frame *esp;
u32 pde;
u32 cr3;
u32 user_mode;
u32 stack_bottom; // ring0 栈底
u32 running; // 已经占用了多少时间片
Expand Down
23 changes: 13 additions & 10 deletions include/kernel/page.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#pragma once
#include <define.h>

#define PAGE_P MASK(0)
#define PAGE_WRABLE MASK(1)
#define PAGE_USER MASK(2)
#define PAGE_WT MASK(3) // 使用直写而不是写回
#define PAGE_CD MASK(4) // 禁用缓存
#define PAGE_SHARED 1024 // 自定义的
#define PAGE_PRESENT MASK(0) // 存在
#define PAGE_WRABLE MASK(1) // 可写
#define PAGE_USER MASK(2) // 用户态
#define PAGE_WT MASK(3) // 使用直写而不是写回
#define PAGE_CD MASK(4) // 禁用缓存
#define PAGE_ACCESS MASK(5) // 访问位
#define PAGE_DIRTY MASK(6) // 脏页
#define PAGE_GLOBAL MASK(8) // 全局页
#define PAGE_SHARED MASK(10) // 自定义的

#define PDE_ADDRESS 0x400000
#define PTE_ADDRESS (PDE_ADDRESS + 0x1000)
#define PAGE_END (PTE_ADDRESS + 0x400000)
#define PD_ADDRESS 0x400000
#define PT_ADDRESS (PD_ADDRESS + 0x1000)
#define PAGE_END (PT_ADDRESS + 0x400000)
#define PAGE_MANNAGER PAGE_END

typedef struct __PACKED__ PageInfo {
Expand Down Expand Up @@ -54,7 +57,7 @@ void *page_alloc(size_t size);
void page_free(void *p, size_t size);
void task_free_all_pages(u32 tid);
void change_page_task_id(int task_id, void *p, u32 size);
u32 pde_clone(u32 addr);
u32 pd_clone(u32 addr);
void *page_malloc_one();
void *page_malloc_one_no_mark();
void page_link(u32 addr);
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/cpu/v86.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void v86_task() {
assert(p, "open /fatfs2/v86_service.bin failed");
vfs_read(p, code, 0, p->size);
// 映射页面
u32 pde = current_task->pde;
u32 pde = current_task->cr3;
page_link_addr_pde(0x2000, pde, (u32)code);
page_link_addr_pde(0x3000, pde, (u32)ptr);
page_link_addr_pde(0x0, pde, 0x0);
Expand Down
14 changes: 7 additions & 7 deletions src/kernel/exec/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ void task_app() {
current_task->alloc_size = (u32 *)malloc(4);
current_task->alloced = 1;
*(current_task->alloc_size) = 2 * 1024 * 1024;
u32 pde = current_task->pde;
u32 pde = current_task->cr3;
asm_cli;
asm_set_cr3(PDE_ADDRESS);
current_task->pde = PDE_ADDRESS;
klogd("P1 %08x", current_task->pde);
asm_set_cr3(PD_ADDRESS);
current_task->cr3 = PD_ADDRESS;
klogd("P1 %08x", current_task->cr3);
for (int i = DIDX(0x70000000) * 4; i < PAGE_SIZE; i += 4) {
u32 *pde_entry = (u32 *)(pde + i);

Expand All @@ -45,7 +45,7 @@ void task_app() {
*pde_entry = (u32)page_malloc_one_count_from_4gb();
memcpy((void *)(*pde_entry), (void *)old, PAGE_SIZE);
pages[IDX(old)].count--;
*pde_entry |= PAGE_USER | PAGE_P | PAGE_WRABLE;
*pde_entry |= PAGE_USER | PAGE_PRESENT | PAGE_WRABLE;
} else {
*pde_entry &= 0xfffff;
*pde_entry |= 7;
Expand All @@ -56,11 +56,11 @@ void task_app() {
u32 *pte_entry = (u32 *)(p + j);
if ((*pte_entry & PAGE_SHARED)) {
*pte_entry &= 0xfffff000;
*pte_entry |= PAGE_USER | PAGE_P;
*pte_entry |= PAGE_USER | PAGE_PRESENT;
}
}
}
current_task->pde = pde;
current_task->cr3 = pde;
asm_sti;
asm_set_cr3(pde);
klogd("go to task_to_usermode_elf");
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/init/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void init_serial();

void sysinit() {
total_mem_size = memtest(0x00400000, 0xbfffffff);
init_page();
init_paging();

cpuid_do_cache(); // 缓存 CPUID 信息

Expand Down
Loading

0 comments on commit dd468a7

Please sign in to comment.