进入用户模式(系统调用存在page fault的bug)

This commit is contained in:
fslongjin
2022-04-11 10:32:39 +08:00
parent c09c6d4e66
commit dacc29310f
9 changed files with 96 additions and 79 deletions

View File

@ -104,13 +104,15 @@ Err_Code:
//
//
ENTRY(system_call)
// sysenter
sti;
hlt
subq $0x38, %rsp
cld;
pushq %rax
movq %es, %rax
pushq %rax
@ -137,6 +139,7 @@ ENTRY(system_call)
// rspsystem_call_function
movq %rsp, %rdi
callq system_call_function
@ -145,33 +148,29 @@ ENTRY(system_call)
ENTRY(ret_from_system_call)
movq %rax, 0x80(%rsp) // raxrax
popq %r15
popq %r14
popq %r13
popq %r12
popq %r11
popq %r10
popq %r9
popq %r8
popq %rbx
popq %rcx
popq %rdx
popq %rsi
popq %rdi
popq %rbp
popq %rax // popds
movq %rax, %ds
popq %rax
movq %rax, %es
popq %rax
addq $0x38, %rsp
.byte 0x48
sysexit
popq %r15
popq %r14
popq %r13
popq %r12
popq %r11
popq %r10
popq %r9
popq %r8
popq %rbx
popq %rcx
popq %rdx
popq %rsi
popq %rdi
popq %rbp
popq %rax
movq %rax, %ds
popq %rax
movq %rax, %es
popq %rax
addq $0x38, %rsp
.byte 0x48
sysexit
// 0 #DE

View File

@ -168,7 +168,7 @@ void do_stack_segment_fault(struct pt_regs *regs, unsigned long error_code)
// 13 #GP 通用保护性异常
void do_general_protection(struct pt_regs *regs, unsigned long error_code)
{
hlt();
kerror("do_general_protection(13),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, regs->rsp, regs->rip);
if (error_code & 0x01)
printk_color(RED, BLACK, "The exception occurred during delivery of an event external to the program,such as an interrupt or an earlier exception.\n");
@ -192,7 +192,7 @@ void do_general_protection(struct pt_regs *regs, unsigned long error_code)
// 14 #PF 页故障
void do_page_fault(struct pt_regs *regs, unsigned long error_code)
{
hlt();
unsigned long cr2 = 0;
__asm__ __volatile__("movq %%cr2, %0":"=r"(cr2)::"memory");