From e66dbd7725c0e62f1cf6f39ce3229b1d81ad5c24 Mon Sep 17 00:00:00 2001 From: acevest Date: Wed, 3 Nov 2021 17:10:01 +0800 Subject: [PATCH] =?utf8?q?=E5=87=86=E5=A4=87=E9=99=8D=E7=BA=A7=E5=88=B0rin?= =?utf8?q?g3?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- kernel/init.c | 30 ++++++++++++++++++++---------- kernel/syscall.S | 33 +-------------------------------- 2 files changed, 21 insertions(+), 42 deletions(-) diff --git a/kernel/init.c b/kernel/init.c index 7f1bcf8..cb9f1e1 100644 --- a/kernel/init.c +++ b/kernel/init.c @@ -22,15 +22,25 @@ char __initdata kernel_init_stack[KRNL_INIT_STACK_SIZE] __attribute__((__aligned int debug_wait_queue_get(); -extern void *ring3; -extern void *ring3_stack_top; +// #define __ring3section__ __attribute__((__section__(".ring3"))) + +// char __attribute__((__section__(".ring3.data"))) ring3_stack[PAGE_SIZE] = {0}; +// void __ring3section__ ring3_entry() { +// while (1) { +// systest(); +// } +// } + void user_task_entry() { - printk("user_task_entry: %08x %08x\n", ring3_stack_top, &ring3_stack_top); -#if 0 - asm("sti;sysexit;"::"d"(&ring3), "c"(&ring3_stack_top)); -#else - sysc_exec("/bin/shell", 0); -#endif + // printk("user_task_entry: %08x\n", ring3_entry); + + // 现在要准备返回用户态 + // eip --> edx + // esp --> ecx + // asm("sysexit;" ::"d"(ring3_entry), "c"(ring3_stack + PAGE_SIZE)); + while (1) { + asm("hlt;"); + } } void init_task_entry() { @@ -56,7 +66,6 @@ void init_task_entry() { } } -extern void ret_from_fork_krnl(); void kernel_task(char *name, void *entry) { pt_regs_t regs; @@ -67,6 +76,7 @@ void kernel_task(char *name, void *entry) { // 创建内核任务的时候就直接指定其在fork后走的路径 // 就不用走sysexit那个路径了 + extern void ret_from_fork_krnl(); regs.eip = (unsigned long)ret_from_fork_krnl; regs.cs = SELECTOR_KRNL_CS; regs.ds = SELECTOR_KRNL_DS; @@ -85,7 +95,7 @@ void root_task_entry() { kernel_task("init", init_task_entry); kernel_task("test", init_task_entry); - // kernel_task(user_task_entry); + kernel_task("user", user_task_entry); int cnt = 0; while (1) { diff --git a/kernel/syscall.S b/kernel/syscall.S index 21f8b43..0a6f290 100644 --- a/kernel/syscall.S +++ b/kernel/syscall.S @@ -108,35 +108,4 @@ sysexit: popl %ebp; popl %edx; popl %ecx; - ret - -.global ring3 -.global ring3_stack_top -ring3: - nop; - nop; - - #movl $(ring3_stack+100), %esp - - movl $11, %eax; - - pushl $1f; - pushl %ecx; - pushl %edx; - pushl %ebp; - movl %esp,%ebp; - sysenter; - 1: - - nop; - nop; - - jmp ring3 - -ring3_stack: - .long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 - .long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 - .long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 - .long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 -ring3_stack_top: - .long 0x12345678 + ret \ No newline at end of file -- 2.44.0