]> Zhao Yanbai Git Server - kernel.git/commitdiff
把ring3的代码拆分到汇编文件里
authoracevest <zhaoyanbai@126.com>
Tue, 30 Dec 2025 14:59:06 +0000 (22:59 +0800)
committeracevest <zhaoyanbai@126.com>
Tue, 30 Dec 2025 14:59:06 +0000 (22:59 +0800)
boot/multiboot2_header.c
kernel/ring3.S [new file with mode: 0644]
kernel/task_user.c
mm/mm.c
scripts/link.ld

index 85b7618f82fdfa4163fd0437517247cdf165eeba..18b6639a384bb909ce9cbf49509f9a41b456145d 100644 (file)
@@ -44,8 +44,8 @@ const multiboot2_bin_header_t multiboot2_elf_header = {
         .type = MULTIBOOT_HEADER_TAG_FRAMEBUFFER,
         .flags = MULTIBOOT_HEADER_TAG_OPTIONAL,
         .size = sizeof(struct multiboot_header_tag_framebuffer),
-        .width = 1280,
-        .height = 800,
+        .width = 1024,
+        .height = 768,
         .depth = 32,
     },
 #endif
diff --git a/kernel/ring3.S b/kernel/ring3.S
new file mode 100644 (file)
index 0000000..dcab140
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * ------------------------------------------------------------------------
+ *   File Name: ring3.S
+ *      Author: Zhao Yanbai
+ *              2025-12-30 22:12:25 Tuesday CST
+ * Description: none
+ * ------------------------------------------------------------------------
+ */
+
+.global ring3_entrys
+# a allocatable 可分配,表示这个节在程序运行时需要加载到内存中
+# x executable  可执行,表示这个节包含可执行的代码
+# w writable    可写,通常用于数据节
+# r read-only   只读
+# M mergeable   可合并相同内容
+# S strings     包含以null结尾的字符串
+# G group       属于某个节组
+#
+# @progbits     包含了程序数据  目标文件中实际包含数据/代码,如.text、.data节
+# @nobits       不包含程序数据  目标文件中不占空间,运行时分配零初始化内存,如.bss节
+.section .ring3.entry, "aw", @progbits
+#.type ring3_entry, @function
+.align 0x1000
+ring3_entrys:
+    nop;
+    nop;
+    nop
+    pushal
+    movl $5, %eax
+    call get_eip
+    get_eip:
+    popl %edi
+    addl $8,%edi
+    movl %esp, %ebp;
+    sysenter;
+    popal
+    nop
+    nop
+    jmp ring3_entrys
index 835c069d7a0caee4fae3f7e9918d95572dfbcb94..e90d5133d518a68d24bf12e529bec49fb23aa6a1 100644 (file)
 #include <system.h>
 #include <types.h>
 
-#define RING3_ENTRY __attribute__((__section__(".ring3.entry")))
-void RING3_ENTRY __attribute__((__aligned__(PAGE_SIZE))) ring3_entry() {
-    while (1) {
-        int __sysc_ret__ = 0;
-
-        // EDI = 用户态返回地址
-        // EBP = 用户态栈
-        asm volatile(
-            "nop;"
-            "nop;"
-            "pusha;"
-            "call get_eip;"
-            "get_eip:"
-            "popl %%edi;" // 获得EIP的值,注意此时EIP的位置为这条pop指令的地址
-                          // 反汇编后计算了一下需要加8个字节才能跳到sysenter下一个指令
-            "addl $8, %%edi;"
-            "movl %%esp, %%ebp;"
-            "sysenter;"
-            "popa;"
-            "nop;"
-            "nop;"
-            :"=a"(__sysc_ret__)
-            :"a"(SYSC_WAIT)
-        );
-    }
-}
-
 void flush_tlb() {
     asm volatile("movl %%cr3, %%eax;"
                 "movl %%eax, %%cr3;"
diff --git a/mm/mm.c b/mm/mm.c
index 128a3ad595cd9a7b1df45832b3c3e6d4f63e1d76..0eda2da76d9b7354da670fcc10dcd6369c020c17 100644 (file)
--- a/mm/mm.c
+++ b/mm/mm.c
@@ -109,7 +109,7 @@ void init_paging() {
     unsigned long vram_phys_addr = system.vbe_phys_addr;
     printk("vram_phys_addr: 0x%x\n", vram_phys_addr);
     for (int pde_inx = 0; pde_inx < get_npde(VRAM_VADDR_SIZE); pde_inx++) {
-        pgtb_addr = (unsigned long *)(alloc_from_bootmem(PAGE_SIZE, "vrampaging"));
+        unsigned long *pgtb_addr = (unsigned long *)(alloc_from_bootmem(PAGE_SIZE, "vrampaging"));
         if (0 == pgtb_addr) {
             panic("no pages for paging...");
         }
index 693ba4d3720463628890798127b7d664b44d6f1c..1a55db4d0ced29ac9664fca86cb3c3758f1379aa 100644 (file)
@@ -67,7 +67,6 @@ SECTIONS
     {
         code = .;
         *(.text)
-        *(.ring3.text);
         *(.sysexit) /* last */
     }
     etext = .;