Explorar o código

能进入用户态程序,但无法正确进行系统调用

fslongjin %!s(int64=3) %!d(string=hai) anos
pai
achega
c09c6d4e66

+ 1 - 1
kernel/exception/entry.S

@@ -106,7 +106,7 @@ Err_Code:
 ENTRY(system_call)
     // 由于sysenter指令会禁用中断,因此要在这里手动开启中断
     sti;
-    
+    hlt
     subq $0x38, %rsp
     
     cld;

+ 1 - 1
kernel/exception/trap.c

@@ -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");

+ 13 - 5
kernel/process/process.c

@@ -51,10 +51,18 @@ void user_level_function()
     // kinfo("Program (user_level_function) is runing...");
     // kinfo("Try to enter syscall id 15...");
     // enter_syscall(15, 0, 0, 0, 0, 0, 0, 0, 0);
-    hlt();
-    enter_syscall(SYS_PRINTF, (ul) "test_sys_printf\n", 0, 0, 0, 0, 0, 0, 0);
-
-    kinfo("Return from syscall id 15...");
+    
+    //enter_syscall(SYS_PRINTF, (ul) "test_sys_printf\n", 0, 0, 0, 0, 0, 0, 0);
+long ret = 0;
+//	color_printk(RED,BLACK,"user_level_function task is running\n");
+	char string[]="Hello World!\n";
+
+	__asm__	__volatile__	(	"leaq	sysexit_return_address(%%rip),	%%rdx	\n\t"
+					"movq	%%rsp,	%%rcx		\n\t"
+					"sysenter			\n\t"
+					"sysexit_return_address:	\n\t"
+					:"=a"(ret):"0"(1),"D"(string):"memory");
+    //kinfo("Return from syscall id 15...");
 
     while (1)
         ;
@@ -83,7 +91,7 @@ ul do_execve(struct pt_regs *regs)
     uint64_t addr = 0x800000UL;
     
     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);
     set_pml4t(tmp, mk_pml4t(virt_2_phys(virtual), PAGE_USER_PGT));
 

+ 1 - 1
kernel/sched/sched.c

@@ -107,6 +107,6 @@ void sched_init()
     memset(&sched_cfs_ready_queue, 0, sizeof(struct sched_queue_t));
     list_init(&sched_cfs_ready_queue.proc_queue.list);
     sched_cfs_ready_queue.count = 1; // 因为存在IDLE进程,因此为1
-    sched_cfs_ready_queue.cpu_exec_proc_jiffies = 4;
+    sched_cfs_ready_queue.cpu_exec_proc_jiffies = 10;
     sched_cfs_ready_queue.proc_queue.virtual_runtime = 0x7fffffffffffffff;
 }

+ 3 - 3
kernel/smp/smp.c

@@ -31,7 +31,7 @@ void smp_init()
     //*(uchar *)0x20000 = 0xf4; // 在内存的0x20000处写入HLT指令(AP处理器会执行物理地址0x20000的代码)
     // 将引导程序复制到物理地址0x20000处
     memcpy((unsigned char *)phys_2_virt(0x20000), _apu_boot_start, (unsigned long)&_apu_boot_end - (unsigned long)&_apu_boot_start);
-    
+
     // 设置多核IPI中断门
     for (int i = 200; i < 210; ++i)
         set_intr_gate(i, 2, SMP_interrupt_table[i - 200]);
@@ -73,7 +73,7 @@ void smp_init()
     
     // 由于ap处理器初始化过程需要用到0x00处的地址,因此初始化完毕后才取消内存地址的重映射
     //todo: 取消低0-2M的地址映射
-    for (int i = 1; i < 128; ++i)
+    for (int i = 0; i < 128; ++i)
     {
 
         *(ul *)(phys_2_virt(global_CR3) + i) = 0UL;
@@ -112,7 +112,7 @@ void smp_ap_start()
 
     sti();
     kdebug("IDT_addr = %#018lx", phys_2_virt(IDT_Table));
-
+    memset(current_pcb, 0, sizeof(struct process_control_block));
     spin_unlock(&multi_core_starting_lock);
     while (1) // 这里要循环hlt,原因是当收到中断后,核心会被唤醒,处理完中断之后不会自动hlt
         hlt();

+ 1 - 0
kernel/syscall/syscall.c

@@ -65,6 +65,7 @@ long enter_syscall(ul syscall_id, ul arg0, ul arg1, ul arg2, ul arg3, ul arg4, u
  */
 ul sys_printf(struct pt_regs *regs)
 {
+    while(1);
     if(regs->r9 == 0 &&regs->r10 == 0)
         printk((char*)regs->r8);
     else printk_color(regs->r9, regs->r10, (char*)regs->r8);