From 258635c33b0b82cc1f422ea90e619c0e294405e9 Mon Sep 17 00:00:00 2001 From: copi143 Date: Thu, 19 Dec 2024 18:19:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/kernel/cpu/start.asm | 4 ++-- src/kernel/cpu/x86.asm | 2 +- src/kernel/drivers/general/timer.c | 4 ++-- src/kernel/drivers/input/keyboard.c | 1 + src/kernel/exec/elf.c | 13 +++++++++++++ src/kernel/init/init.c | 7 ++++--- 6 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/kernel/cpu/start.asm b/src/kernel/cpu/start.asm index ded8fa8c..6e4c3a67 100755 --- a/src/kernel/cpu/start.asm +++ b/src/kernel/cpu/start.asm @@ -5,7 +5,7 @@ ; ; Copyright (C) 2024~ plos - clan ; - bits 32 + [bits 32] magic equ 0xe85250d6 i386 equ 0 length equ header_end - header_start @@ -47,5 +47,5 @@ jmp RING0_CS:.next section .bss stack: - resb 0x1000 + resb 4096 stack_end: diff --git a/src/kernel/cpu/x86.asm b/src/kernel/cpu/x86.asm index 62e49fd7..964ad928 100755 --- a/src/kernel/cpu/x86.asm +++ b/src/kernel/cpu/x86.asm @@ -63,7 +63,7 @@ asm_task_start: ; void asm_task_start(task_t current, task_t next) mov cr3, eax popa sti ; 这边必须 sti - ret + ret ; 注意 sti 指令的实现,sti ret 会在返回之后才设置 IF 位 global entering_v86 entering_v86: ; extern void entering_v86(u32 ss, u32 esp, u32 cs, u32 eip); diff --git a/src/kernel/drivers/general/timer.c b/src/kernel/drivers/general/timer.c index 1191192e..33f90c77 100755 --- a/src/kernel/drivers/general/timer.c +++ b/src/kernel/drivers/general/timer.c @@ -18,6 +18,7 @@ void init_pit() { inthandler_set(0x20, inthandler20); asm_out8(PIT_CTRL, 0x34); pit_set(1193182 / PIT_FREQ); + irq_enable(0); } #define NANOSEC_IN_SEC 1000000000 @@ -44,6 +45,5 @@ __attr(fastcall) void inthandler20(i32 id, regs32 *regs) { kenel_debugger_tick(); - extern task_t task_current; - if (task_current) task_tick(); + if (current_task->tid >= 0) task_tick(); } diff --git a/src/kernel/drivers/input/keyboard.c b/src/kernel/drivers/input/keyboard.c index 05e1af1f..cc43a31b 100755 --- a/src/kernel/drivers/input/keyboard.c +++ b/src/kernel/drivers/input/keyboard.c @@ -38,6 +38,7 @@ void init_keyboard() { asm_out8(PORT_KEYCMD, KEYCMD_WRITE_MODE); wait_KBC_sendready(); asm_out8(PORT_KEYDAT, KBC_MODE); + irq_enable(1); } int getch() { diff --git a/src/kernel/exec/elf.c b/src/kernel/exec/elf.c index d8c4beeb..d28ccbbd 100755 --- a/src/kernel/exec/elf.c +++ b/src/kernel/exec/elf.c @@ -4,6 +4,16 @@ bool elf32_is_validate(Elf32_Ehdr *hdr) { return *(u32 *)hdr->e_ident == ELF_MAGIC; } +void print_section_names(Elf32_Ehdr *hdr) { + Elf32_Shdr *shdr = (Elf32_Shdr *)((u32)hdr + hdr->e_shoff); + char *strtab = (char *)hdr + shdr[hdr->e_shstrndx].sh_offset; + + klogd("Section Headers:"); + for (int i = 0; i < hdr->e_shnum; i++) { + klogd(" [%2d] %s", i, strtab + shdr[i].sh_name); + } +} + u32 elf32_get_max_vaddr(Elf32_Ehdr *hdr) { Elf32_Phdr *phdr = (Elf32_Phdr *)((u32)hdr + hdr->e_phoff); u32 max = 0; @@ -35,6 +45,7 @@ u32 load_elf(Elf32_Ehdr *hdr) { load_segment(phdr, (void *)hdr); phdr++; } + print_section_names(hdr); return hdr->e_entry; } @@ -49,4 +60,6 @@ void elf32_load_data(Elf32_Ehdr *elfhdr, u8 *ptr) { ptr[shdr->sh_addr + i] = p[shdr->sh_offset + i]; } } + + print_section_names(elfhdr); } diff --git a/src/kernel/init/init.c b/src/kernel/init/init.c index 14df22f5..b33d34c5 100755 --- a/src/kernel/init/init.c +++ b/src/kernel/init/init.c @@ -15,6 +15,8 @@ void *pci_addr_base; void init_serial(); +#define KERNEL_HEAP_SIZE (128 * 1024 * 1024) + void sysinit() { total_mem_size = memtest(0x00400000, 0xbfffffff); init_page(); @@ -32,10 +34,8 @@ void sysinit() { init_pit(); asm_sti; - irq_enable(0); - irq_enable(1); - memory_init(page_alloc(128 * 1024 * 1024), 128 * 1024 * 1024); + memory_init(page_alloc(KERNEL_HEAP_SIZE), KERNEL_HEAP_SIZE); vbe_init(); @@ -62,5 +62,6 @@ void sysinit() { info("the memory test has been passed! Your PC has %dMiB memory", total_mem_size / (1024 * 1024)); } + init_keyboard(); }