Repos / kernel.git / commitdiff
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 16e3653)
raw | patch | inline | side by side (parent: 16e3653)
| author | zhaoyanbai <zhaoyanbai@126.com> | |
| Thu, 1 Jan 2026 04:22:41 +0000 (12:22 +0800) | ||
| committer | zhaoyanbai <zhaoyanbai@126.com> | |
| Thu, 1 Jan 2026 04:22:41 +0000 (12:22 +0800) |
| boot/boot.h | patch | blob | history | |
| boot/multiboot.S | patch | blob | history | |
| include/system.h | patch | blob | history | |
| kernel/task_root.c | patch | blob | history | |
| scripts/link.ld | patch | blob | history |
diff --git a/boot/boot.h b/boot/boot.h
--- a/boot/boot.h
+++ b/boot/boot.h
#pragma once
-#include "multiboot2.h"
+#include <multiboot2.h>
+#include <types.h>
#define BOOT_INIT_PAGETBL_CNT 2 // 8MB
-#ifndef ASM
-#include <types.h>
-
#define E820_RAM 1
#define E820_RESERVED 2
#define E820_ACPI 3
extern struct boot_params boot_params;
extern bootmem_data_t bootmem_data;
-
-#endif
diff --git a/boot/multiboot.S b/boot/multiboot.S
--- a/boot/multiboot.S
+++ b/boot/multiboot.S
*
*--------------------------------------------------------------------------
*/
-#define ASM
-
-#include "boot.h"
-#include "task.h"
.global kernel_entry
.global main
.extern check_kernel
.extern init_system_info
.extern setup_kernel
-.extern root_task
.extern root_task_entry
+.extern get_root_task_stack_top
.extern kernel_virtual_addr_start
-#define MULTIBOOT_STACK_SIZE 0x4000
+#define MULTIBOOT_STACK_SIZE 0x200
.section .kernel_entry_text
kernel_entry:
jmp 4f
4:
# 准备切保护模式
-
# 此时esp的地址还需要再调整一下
addl $kernel_virtual_addr_start, %esp
-
-
.extern p_entry_vaddr
ljmp $0x08, $p_entry_vaddr
.align 4
.global p_entry # 为了让链接器计算出 p_entry_vaddr
+ # 因为编译器不支持 ljmp $0x08, $p_entry + kernel_virtual_addr_start 这种写法
p_entry:
leal check_kernel, %eax
call *%eax
- movl $root_task + TASK_SIZE, %esp
+ leal get_root_task_stack_top, %eax
+ call *%eax
+ movl %eax, %esp
+
leal init_system_info, %eax
call *%eax;
diff --git a/include/system.h b/include/system.h
--- a/include/system.h
+++ b/include/system.h
void* kzalloc(size_t size, gfp_t gfpflags);
void kfree(void* addr);
-#define panic(msg, ...) \
- do { \
- asm("cli;"); \
- printl(MPL_DEBUG, "PANIC:" msg " file:%s function:%s line:%d\n", ##__VA_ARGS__, __FILE__, __FUNCTION__, \
- __LINE__); \
- printk("PANIC:" msg " file:%s function:%s line:%d\n", ##__VA_ARGS__, __FILE__, __FUNCTION__, __LINE__); \
- while (1) { \
- asm("hlt"); \
- } \
+#define panic(msg, ...) \
+ do { \
+ asm("cli;"); \
+ printl(MPL_DEBUG, "PANIC:" msg " %s %s %d\n", ##__VA_ARGS__, __FILE__, __FUNCTION__, __LINE__); \
+ printk("PANIC:" msg " %s %s %d\n", ##__VA_ARGS__, __FILE__, __FUNCTION__, __LINE__); \
+ asm("hlt"); \
} while (0);
extern char etext, edata, end;
diff --git a/kernel/task_root.c b/kernel/task_root.c
--- a/kernel/task_root.c
+++ b/kernel/task_root.c
asm("hlt;");
}
}
+
+uint32_t get_root_task_stack_top() {
+ return (uint32_t)((uint8_t*)&root_task + TASK_SIZE);
+}
diff --git a/scripts/link.ld b/scripts/link.ld
--- a/scripts/link.ld
+++ b/scripts/link.ld
*(.multiboot2_header)
boot/multiboot.S.o(.text)
*unpaged_*.o(.text)
+ p_entry_vaddr = p_entry + kernel_virtual_addr_start;
}
eunpagged_text = .;