feature: enable paging and load page directory
This commit is contained in:
parent
65a59534b4
commit
ddf3cfff68
29
headers/memory.h
Normal file
29
headers/memory.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define NOT_PRESENT (1 << 0)
|
||||||
|
#define RW (1 << 1)
|
||||||
|
#define SUPERVISOR (0 << 2)
|
||||||
|
#define INIT_FLAGS (NOT_PRESENT | RW | SUPERVISOR)
|
||||||
|
|
||||||
|
struct page_directory_entry {
|
||||||
|
uint32_t present : 1;
|
||||||
|
uint32_t rw : 1;
|
||||||
|
uint32_t user : 1;
|
||||||
|
uint32_t page_size : 1;
|
||||||
|
uint32_t unused : 8;
|
||||||
|
uint32_t frame : 20;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct page_table_entry {
|
||||||
|
uint32_t present : 1;
|
||||||
|
uint32_t rw : 1;
|
||||||
|
uint32_t user : 1;
|
||||||
|
uint32_t accessed : 1;
|
||||||
|
uint32_t dirty : 1;
|
||||||
|
uint32_t unused : 7;
|
||||||
|
uint32_t frame : 20;
|
||||||
|
};
|
||||||
|
|
||||||
|
void init_memory(void);
|
@ -1,8 +1,7 @@
|
|||||||
#include "gdt.h"
|
#include "gdt.h"
|
||||||
|
#include "memory.h"
|
||||||
#include "shell.h"
|
#include "shell.h"
|
||||||
#include "terminal.h"
|
#include "terminal.h"
|
||||||
/* #include "power.h" */
|
|
||||||
#include "gdt.h"
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
@ -21,9 +20,8 @@
|
|||||||
|
|
||||||
void kernel_main(void)
|
void kernel_main(void)
|
||||||
{
|
{
|
||||||
/* Initialize terminal interface */
|
|
||||||
terminal_initialize();
|
terminal_initialize();
|
||||||
|
|
||||||
init_gdt();
|
init_gdt();
|
||||||
|
init_memory();
|
||||||
shell_init();
|
shell_init();
|
||||||
}
|
}
|
||||||
|
12
src/memory/load_pd.s
Normal file
12
src/memory/load_pd.s
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
.intel_syntax noprefix
|
||||||
|
|
||||||
|
.text
|
||||||
|
.global load_page_directory
|
||||||
|
load_page_directory:
|
||||||
|
push ebp
|
||||||
|
mov ebp, esp
|
||||||
|
mov eax, [esp + 8]
|
||||||
|
mov cr3, eax
|
||||||
|
mov esp, ebp
|
||||||
|
pop ebp
|
||||||
|
ret
|
18
src/memory/memory.c
Normal file
18
src/memory/memory.c
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#include "memory.h"
|
||||||
|
#include "string.h"
|
||||||
|
|
||||||
|
extern void load_page_directory(uint32_t *);
|
||||||
|
extern void enable_paging(void);
|
||||||
|
|
||||||
|
uint32_t page_directory_entries[1024] __attribute__((aligned(4096)));
|
||||||
|
uint32_t page_table_entries[1024] __attribute__((aligned(4096)));
|
||||||
|
|
||||||
|
void init_memory(void)
|
||||||
|
{
|
||||||
|
memset(page_directory_entries, INIT_FLAGS, 1024);
|
||||||
|
for (int i = 0; i < 1024; i++)
|
||||||
|
page_table_entries[i] = (i << 12) | INIT_FLAGS;
|
||||||
|
page_directory_entries[0] = (uint32_t)page_table_entries | INIT_FLAGS;
|
||||||
|
load_page_directory(page_directory_entries);
|
||||||
|
enable_paging();
|
||||||
|
}
|
13
src/memory/paging.s
Normal file
13
src/memory/paging.s
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
.intel_syntax noprefix
|
||||||
|
|
||||||
|
.text
|
||||||
|
.global enable_paging
|
||||||
|
enable_paging:
|
||||||
|
push ebp
|
||||||
|
mov ebp, esp
|
||||||
|
mov eax, cr0
|
||||||
|
or eax, 0x80000000
|
||||||
|
mov cr0, eax
|
||||||
|
mov esp, ebp
|
||||||
|
pop ebp
|
||||||
|
ret
|
Loading…
Reference in New Issue
Block a user