diff --git a/kernel/kernel.c b/kernel/kernel.c index 261651f..c2688d5 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -42,7 +42,7 @@ void kernel_main(uint32_t magic, uint32_t addr) { "mov $1, %eax\n" "int $0x80" ); - pmm_init(mem_size, bitmap); + pmm_init(mem_size, &bitmap); for (size_t i = 0; i < 15; i++) { if (region[i].type > 5) region[i].type = MULTIBOOT_MEMORY_AVAILABLE; @@ -55,6 +55,8 @@ void kernel_main(uint32_t magic, uint32_t addr) { } pmm_deinit_region(0x10000, &end_kernel_virt - &start_kernel_virt); vmm_init(); + void* caca = pmm_alloc_block(); + printf("new alloc: %p\n", caca); asm volatile("sti\n\t"); uint32_t cr0; asm volatile("mov %%cr0, %0" : "=r" (cr0)); diff --git a/memory/pmm/pmm.c b/memory/pmm/pmm.c index a8ef769..17ae2aa 100644 --- a/memory/pmm/pmm.c +++ b/memory/pmm/pmm.c @@ -18,16 +18,17 @@ int mmap_test(int bit) { } int mmap_find_first_free() { - for (size_t i = 0; i < _memory_max_blocks / 32; i++) { + for (size_t i = 0; i < _memory_max_blocks - _memory_used_blocks; i++) { if (_memory_map[i] != 0xFFFFFFFF) { - for (size_t j = 0; j < 32; i++) { - int bit = 1 << j; + for (size_t j = 0; j < 32; j++) { + uint32_t bit = 1 << j; if (!(_memory_map[i] & bit)) { return i * 32 + j; } } } } + return (-1); } int mmap_find_first_free_s (size_t size) { @@ -40,13 +41,12 @@ int mmap_find_first_free_s (size_t size) { for (size_t i = 0; i < _memory_max_blocks - _memory_used_blocks; i++) if (_memory_map[i] != 0xffffffff) - for (int j=0; j<32; j++) { //! test each bit in the dword + for (uint32_t j=0; j<32; j++) { //! test each bit in the dword - int bit = 1<