mirror of
https://github.com/tailix/kernel.git
synced 2024-10-30 12:03:52 -04:00
Add mapping func
This commit is contained in:
parent
6dc84eba38
commit
be3fb904d8
1 changed files with 34 additions and 29 deletions
|
@ -1,10 +1,11 @@
|
|||
#include "paging.h"
|
||||
|
||||
#include "panic.h"
|
||||
|
||||
#include <kernaux/libc.h>
|
||||
#include <kernaux/stdlib.h>
|
||||
|
||||
static void mapping(struct Paging *paging, uint32_t virt, uint32_t phys);
|
||||
|
||||
void paging_load(struct Paging *const paging)
|
||||
{
|
||||
uint32_t page_dir_phys = (uint32_t)&paging->page_dir;
|
||||
|
@ -49,17 +50,8 @@ void paging_clear(struct Paging *const paging)
|
|||
void paging_identity(struct Paging *const paging)
|
||||
{
|
||||
for (size_t i = 0; i < PAGE_DIR_LENGTH; ++i) {
|
||||
paging->page_dir[i].addr = PAGE_DIR_ADDR(i * PAGE_BIG_SIZE);
|
||||
|
||||
paging->page_dir[i].available1 = 0;
|
||||
paging->page_dir[i].page_size = 1;
|
||||
paging->page_dir[i].available0 = 0;
|
||||
paging->page_dir[i].accessed = 0;
|
||||
paging->page_dir[i].cache_disabled = 1;
|
||||
paging->page_dir[i].write_through = 1;
|
||||
paging->page_dir[i].user = 1;
|
||||
paging->page_dir[i].writable = 1;
|
||||
paging->page_dir[i].present = 1;
|
||||
const size_t addr = i * PAGE_BIG_SIZE;
|
||||
mapping(paging, addr, addr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,27 +62,40 @@ void paging_mapkernel(
|
|||
assert(!(kinfo->kernel_phys_base % PAGE_BIG_SIZE), "Kernel physical address is not aligned.");
|
||||
assert(!(kinfo->kernel_virt_base % PAGE_BIG_SIZE), "Kernel virtual address is not aligned.");
|
||||
|
||||
size_t pde = kinfo->kernel_virt_base / PAGE_BIG_SIZE;
|
||||
|
||||
size_t phys = kinfo->kernel_phys_base;
|
||||
size_t virt = kinfo->kernel_virt_base;
|
||||
size_t mapped = 0;
|
||||
size_t kern_phys = kinfo->kernel_phys_base;
|
||||
|
||||
while (mapped < kinfo->kernel_size) {
|
||||
paging->page_dir[pde].addr = PAGE_DIR_ADDR(kern_phys);
|
||||
|
||||
paging->page_dir[pde].available1 = 0;
|
||||
paging->page_dir[pde].page_size = 1;
|
||||
paging->page_dir[pde].available0 = 0;
|
||||
paging->page_dir[pde].accessed = 0;
|
||||
paging->page_dir[pde].cache_disabled = 0;
|
||||
paging->page_dir[pde].write_through = 0;
|
||||
paging->page_dir[pde].user = 0;
|
||||
paging->page_dir[pde].writable = 1;
|
||||
paging->page_dir[pde].present = 1;
|
||||
mapping(paging, virt, phys);
|
||||
|
||||
phys += PAGE_BIG_SIZE;
|
||||
virt += PAGE_BIG_SIZE;
|
||||
mapped += PAGE_BIG_SIZE;
|
||||
kern_phys += PAGE_BIG_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
++pde;
|
||||
void mapping(
|
||||
struct Paging *const paging,
|
||||
const uint32_t virt,
|
||||
const uint32_t phys
|
||||
) {
|
||||
KERNAUX_NOTNULL_RETURN(paging);
|
||||
|
||||
const size_t pde_index = virt / PAGE_BIG_SIZE;
|
||||
struct KernAux_Arch_I386_PDE *const pde = &paging->page_dir[pde_index];
|
||||
|
||||
if (!pde->present) {
|
||||
pde->addr = PAGE_DIR_ADDR(phys);
|
||||
|
||||
pde->available1 = 0;
|
||||
pde->page_size = 1;
|
||||
pde->available0 = 0;
|
||||
pde->accessed = 0;
|
||||
pde->cache_disabled = 0;
|
||||
pde->write_through = 0;
|
||||
pde->user = 0;
|
||||
pde->writable = 1;
|
||||
pde->present = 1;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue