-void
-__do_reserved_memory(int unlock)
-{
- multiboot_memory_map_t* mmaps = _k_init_mb_info->mmap_addr;
- size_t map_size =
- _k_init_mb_info->mmap_length / sizeof(multiboot_memory_map_t);
- // v_mapping mapping;
- for (unsigned int i = 0; i < map_size; i++) {
- multiboot_memory_map_t mmap = mmaps[i];
- uint8_t* pa = PG_ALIGN(mmap.addr_low);
- if (mmap.type == MULTIBOOT_MEMORY_AVAILABLE || pa <= MEM_4MB) {
- // Don't fuck up our kernel code or any free area!
- continue;
- }
- size_t pg_num = CEIL(mmap.len_low, PG_SIZE_BITS);
- size_t j = 0;
- if (!unlock) {
- for (; j < pg_num; j++) {
- uintptr_t _pa = pa + (j << PG_SIZE_BITS);
- if (_pa >= KERNEL_MM_BASE) {
- // Don't fuck up our kernel space!
- break;
- }
- vmm_set_mapping(PD_REFERENCED, _pa, _pa, PG_PREM_R, VMAP_NULL);
- }
- // Save the progress for later unmapping.
- mmaps[i].len_low = j * PG_SIZE;
- } else {
- for (; j < pg_num; j++) {
- uintptr_t _pa = pa + (j << PG_SIZE_BITS);
- vmm_del_mapping(PD_REFERENCED, _pa);
- }
- }
- }