Skip to content

Commit

Permalink
小修改
Browse files Browse the repository at this point in the history
  • Loading branch information
copi143 committed Dec 19, 2024
1 parent 627dff4 commit 258635c
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/kernel/cpu/start.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -47,5 +47,5 @@ jmp RING0_CS:.next
section .bss
stack:
resb 0x1000
resb 4096
stack_end:
2 changes: 1 addition & 1 deletion src/kernel/cpu/x86.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/kernel/drivers/general/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}
1 change: 1 addition & 0 deletions src/kernel/drivers/input/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
13 changes: 13 additions & 0 deletions src/kernel/exec/elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -35,6 +45,7 @@ u32 load_elf(Elf32_Ehdr *hdr) {
load_segment(phdr, (void *)hdr);
phdr++;
}
print_section_names(hdr);
return hdr->e_entry;
}

Expand All @@ -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);
}
7 changes: 4 additions & 3 deletions src/kernel/init/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();

Expand All @@ -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();
}

0 comments on commit 258635c

Please sign in to comment.