From 3c87632b0cbc4e494747bb508ffd404e6bdc29c2 Mon Sep 17 00:00:00 2001 From: 0x35c Date: Fri, 8 Nov 2024 12:45:00 +0100 Subject: [PATCH] wip: change the C function set_mem_size to asm --- headers/memory.h | 2 +- src/boot.s | 8 +++++--- src/kernel.c | 7 ++++--- src/memory/memory.c | 2 +- src/set_mem_size.s | 27 +++++++++++++++++++++++++++ 5 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 src/set_mem_size.s diff --git a/headers/memory.h b/headers/memory.h index e13978c..4968a94 100644 --- a/headers/memory.h +++ b/headers/memory.h @@ -23,7 +23,7 @@ extern uint32_t _kernel_end; extern uint32_t boot_page_directory; extern uint32_t *page_directory; extern uint32_t page_table_default[1024]; -extern uint32_t mem_size; +extern uint64_t mem_size; uint32_t *virt_to_phys(uint32_t *virt_addr); void init_memory(void); diff --git a/src/boot.s b/src/boot.s index 3eeb36c..8215bf4 100644 --- a/src/boot.s +++ b/src/boot.s @@ -34,6 +34,7 @@ boot_page_table1: # The kernel entry point. .section .multiboot.text, "a" .global _start +.global end_mem .type _start, @function _start: # Physical address of boot_page_table1. @@ -89,6 +90,10 @@ _start: movl $(boot_page_directory - 0xC0000000), %ecx movl %ecx, %cr3 + jmp set_mem_size + +end_mem: + # Enable paging and the write-protect bit. movl %cr0, %ecx orl $0x80000000, %ecx @@ -113,9 +118,6 @@ _start: # Set up the stack. mov $stack_top, %esp - push %eax - push %ebx - # Enter the high-level kernel. call kernel_main diff --git a/src/kernel.c b/src/kernel.c index 7e96de6..a11fb10 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -31,7 +31,8 @@ * feeling qui me donnerait envie de continuer dans une relation "couple" sur le * long terme. Je sais pas trop comment le dire sans que ça te blesse, c'est pas * personnel ou quoi c'est cool quand on parle et tout mais juste je ne pense - * pas pouvoir faire marcher une relation comme celle là :( */ /* Voilà je voulais juste te le dire pour pas que tu te mettes quelque chose en + * pas pouvoir faire marcher une relation comme celle là :( */ +/* Voilà je voulais juste te le dire pour pas que tu te mettes quelque chose en * tête qui n'arrivera pas, je trouve ça plus correct */ static void set_mem_size(multiboot_info_t *mbd, uint32_t magic) @@ -54,14 +55,14 @@ static void set_mem_size(multiboot_info_t *mbd, uint32_t magic) } } -void kernel_main(multiboot_info_t *mbd, uint32_t magic) +void kernel_main(void) { terminal_initialize(); init_gdt(); init_idt(); init_memory(); load_drivers(); - set_mem_size(mbd, magic); + /* set_mem_size(mbd, magic); */ kprintf(KERN_ALERT "I see no way to confuse an array of 256 seg:off pairs with a " "complex 8*unknown quantity -byte descriptor table. -- Troy " diff --git a/src/memory/memory.c b/src/memory/memory.c index 3d31152..4e79a69 100644 --- a/src/memory/memory.c +++ b/src/memory/memory.c @@ -6,7 +6,7 @@ uint32_t *page_directory = &boot_page_directory; uint32_t page_table_default[1024] __attribute__((aligned(4096))); -uint32_t mem_size; +uint64_t mem_size; void init_memory(void) { diff --git a/src/set_mem_size.s b/src/set_mem_size.s new file mode 100644 index 0000000..dcd4c42 --- /dev/null +++ b/src/set_mem_size.s @@ -0,0 +1,27 @@ +.intel_syntax noprefix + +.section .text + .global set_mem_size + + set_mem_size: + xor ebx, ebx +.L1: + // loop condition + cmp ebx, [eax + 64] + jge end_mem + + // declare mmmt + mov ecx, [eax + 68] + add ecx, ebx + + // check if the mmmt->type is available (1) + cmp DWORD PTR [ecx + 20], 1 + jne .L2 + // add the size of the block + mov edx, [ecx + 12] + add DWORD PTR mem_size, edx + mov edx, [ecx + 16] + add DWORD PTR mem_size + 4, edx +.L2: + add ebx, 24 + jmp .L1