refactor
This commit is contained in:
+5
-2
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <common/utils.h>
|
||||
#include <kernel/alloc.h>
|
||||
#include <kernel/arch.h>
|
||||
#include <kernel/init.h>
|
||||
#include <kernel/panic.h>
|
||||
#include <kernel/print.h>
|
||||
@@ -141,7 +142,7 @@ void mem_init(struct phys_mem* map, size_t map_len, uintptr_t kernel_virt, phys_
|
||||
|
||||
const size_t num_pages = (map[i].length + pgsz - 1) / pgsz;
|
||||
const size_t metadata_size = num_pages * sizeof(struct page);
|
||||
const uintptr_t metadata_start_vaddr = arch_vm_pfndb_addr() + (map[i].address / pgsz * sizeof(struct page));
|
||||
const uintptr_t metadata_start_vaddr = arch_mem_pfndb_addr() + (map[i].address / pgsz * sizeof(struct page));
|
||||
const uintptr_t metadata_end_vaddr = metadata_start_vaddr + metadata_size;
|
||||
|
||||
// Find the page-aligned boundaries that contain this metadata.
|
||||
@@ -156,7 +157,7 @@ void mem_init(struct phys_mem* map, size_t map_len, uintptr_t kernel_virt, phys_
|
||||
pmap_map(&kernel_vas.pmap, vaddr + page, paddr, PTE_READ | PTE_WRITE, CACHE_NONE);
|
||||
}
|
||||
}
|
||||
vm_pfndb = (struct page*)arch_vm_pfndb_addr();
|
||||
vm_pfndb = (struct page*)arch_mem_pfndb_addr();
|
||||
|
||||
// We don't need the bootstrap allocator from this point on.
|
||||
// Initialize the real page allocator.
|
||||
@@ -164,5 +165,7 @@ void mem_init(struct phys_mem* map, size_t map_len, uintptr_t kernel_virt, phys_
|
||||
|
||||
slab_init();
|
||||
|
||||
// TODO: Free `__init` memory.
|
||||
|
||||
kprintf("Memory initialization complete\n");
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
kernel_sources += files(
|
||||
'init.c',
|
||||
'mmio.c',
|
||||
'pmap.c',
|
||||
'pmm.c',
|
||||
'slab.c',
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <kernel/mmio.h>
|
||||
#include <kernel/pmap.h>
|
||||
#include <kernel/vas.h>
|
||||
#include <kernel/virt.h>
|
||||
#include <bits/mem.h>
|
||||
|
||||
void* mmio_new(phys_t addr, size_t length) {
|
||||
void* ptr = vm_alloc(length);
|
||||
for (size_t i = 0; i < length; i += arch_mem_page_size()) {
|
||||
|
||||
if (pmap_map(&kernel_vas.pmap, (uintptr_t)ptr + i, addr + i, PTE_READ | PTE_WRITE, CACHE_MMIO)) {
|
||||
vm_free(ptr, length);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void mmio_free(void* ptr, size_t length) {
|
||||
// TODO
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <zinnia/status.h>
|
||||
#include <kernel/alloc.h>
|
||||
#include <kernel/arch.h>
|
||||
#include <kernel/pmap.h>
|
||||
#include <kernel/spin.h>
|
||||
#include <kernel/vas.h>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <common/compiler.h>
|
||||
#include <kernel/alloc.h>
|
||||
#include <kernel/arch.h>
|
||||
#include <kernel/panic.h>
|
||||
#include <kernel/print.h>
|
||||
#include <kernel/spin.h>
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <zinnia/status.h>
|
||||
#include <common/compiler.h>
|
||||
#include <kernel/alloc.h>
|
||||
#include <kernel/arch.h>
|
||||
#include <kernel/spin.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <kernel/bits/usercopy.h>
|
||||
#include <kernel/arch.h>
|
||||
#include <kernel/percpu.h>
|
||||
#include <kernel/usercopy.h>
|
||||
|
||||
@@ -11,7 +11,3 @@ bool usercopy_read(void* dst, const __user void* src, size_t len) {
|
||||
bool usercopy_write(__user void* dst, const void* src, size_t len) {
|
||||
return arch_usercopy_write(dst, src, len, &percpu_get()->sched.current->usercopy_region);
|
||||
}
|
||||
|
||||
bool usercopy_strlen(const __user char* str, size_t max, size_t* len) {
|
||||
return arch_usercopy_strlen(str, max, len, &percpu_get()->sched.current->usercopy_region);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <zinnia/status.h>
|
||||
#include <common/utils.h>
|
||||
#include <kernel/alloc.h>
|
||||
#include <kernel/arch.h>
|
||||
#include <kernel/vas.h>
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
+8
-3
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <common/utils.h>
|
||||
#include <kernel/alloc.h>
|
||||
#include <kernel/arch.h>
|
||||
#include <kernel/virt.h>
|
||||
#include <stdatomic.h>
|
||||
#include <stddef.h>
|
||||
@@ -12,17 +13,21 @@ struct page* vm_pfndb = nullptr;
|
||||
|
||||
static size_t mapping_offset = 0;
|
||||
|
||||
void* vm_alloc(size_t length) {
|
||||
uintptr_t vm_alloc(size_t length) {
|
||||
uintptr_t base = arch_mem_mapping_addr();
|
||||
size_t offset = atomic_fetch_add(&mapping_offset, ALIGN_UP(length, arch_mem_page_size()));
|
||||
|
||||
return (void*)(base + offset);
|
||||
return (base + offset);
|
||||
}
|
||||
|
||||
void vm_free(void* ptr, size_t length) {
|
||||
void vm_free(uintptr_t ptr, size_t length) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
uintptr_t vm_page_addr(struct page* page) {
|
||||
return (((uintptr_t)page - (uintptr_t)vm_pfndb) / sizeof(struct page)) * arch_mem_page_size();
|
||||
}
|
||||
|
||||
size_t mem_high_shift() {
|
||||
return arch_mem_level_bits() * arch_mem_num_levels() + arch_mem_page_bits();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <zinnia/status.h>
|
||||
#include <common/utils.h>
|
||||
#include <kernel/alloc.h>
|
||||
#include <kernel/arch.h>
|
||||
#include <kernel/list.h>
|
||||
#include <kernel/virt.h>
|
||||
#include <kernel/vmo.h>
|
||||
|
||||
Reference in New Issue
Block a user