.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
--- /dev/null
+/*
+ * ------------------------------------------------------------------------
+ * 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
#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;"
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...");
}
{
code = .;
*(.text)
- *(.ring3.text);
*(.sysexit) /* last */
}
etext = .;