Commit 36eb51a1 by triazo

Give flags to the the paging structures

parent 21818eb9
Showing with 35 additions and 11 deletions
...@@ -3,16 +3,17 @@ ...@@ -3,16 +3,17 @@
*/ */
#include "mem.h" #include "mem.h"
#include "serial.h"
// page_directory is currently defined once and should not be touched // page_directory is currently defined once and should not be touched
// later. It must be page aligned for the MMU to read properly // later. It must be page aligned for the MMU to read properly
uint32_t page_directory[1024] __attribute__((aligned(4096))); page_directory_entry page_directory[1024] __attribute__((aligned(4096)));
// page_table_one is the first page table, and at the beginning the // page_table_one is the first page table, and at the beginning the
// only page table in the page directory // only page table in the page directory
uint32_t page_table_one[1024] __attribute__((aligned(4096))); page_table_entry page_table_one[1024] __attribute__((aligned(4096)));
uint32_t* initiate_directory() { page_directory_entry* initiate_directory() {
// set each entry to not present // set each entry to not present
int i; int i;
for(i = 0; i < 1024; i++) for(i = 0; i < 1024; i++)
...@@ -22,13 +23,14 @@ uint32_t* initiate_directory() { ...@@ -22,13 +23,14 @@ uint32_t* initiate_directory() {
// Write Enabled: It can be both read from and written to // Write Enabled: It can be both read from and written to
// (this is the 2 bit) // (this is the 2 bit)
// Not Present: The page table is not present // Not Present: The page table is not present
page_directory[i] = 0x00000002; page_directory[i] = 0;
page_directory[i] |= PAGE_WRITABLE;
} }
return page_directory; return page_directory;
} }
void initiate_page_table(uint32_t* page_dir) { void initiate_page_table(page_directory_entry* page_dir) {
// holds the physical address where we want to start mapping these pages to. // holds the physical address where we want to start mapping these pages to.
// in this case, we want to map these pages to the very beginning of memory. // in this case, we want to map these pages to the very beginning of memory.
unsigned int i; unsigned int i;
...@@ -39,9 +41,13 @@ void initiate_page_table(uint32_t* page_dir) { ...@@ -39,9 +41,13 @@ void initiate_page_table(uint32_t* page_dir) {
// As the address is page aligned, it will always leave 12 bits zeroed. // As the address is page aligned, it will always leave 12 bits zeroed.
// Those bits are used by the attributes: // Those bits are used by the attributes:
// -> supervisor level, read/write, present. // -> supervisor level, read/write, present.
page_table_one[i] = (i * 0x1000) | 3; page_table_one[i] = 0;
page_table_one[i] |= i << 12;
page_table_one[i] |= PAGE_WRITABLE | PAGE_PRESENT;
} }
// attributes: supervisor level, read/write, present // attributes: supervisor level, read/write, present
page_dir[0] = ((unsigned int)page_table_one) | 3; page_dir[0] = (uint32_t) page_table_one;
page_dir[0] |= PAGE_WRITABLE | PAGE_PRESENT;
} }
...@@ -2,13 +2,31 @@ ...@@ -2,13 +2,31 @@
mem.h mem.h
*/ */
#pragma once #ifndef _MEM_INC
#define _MEM_INT
#include <stdbool.h>
#include <stdint.h> #include <stdint.h>
// Flags for pages directory entries and table entries
#define PAGE_PRESENT 0x1
#define PAGE_WRITABLE 0x2
#define PAGE_USER 0x4
#define PAGE_WRITE_THROUGH 0x8
#define PAGE_CACHE_DISABLED 0x10
#define PAGE_ACCESSED 0x20
#define PAGE_DIRTY 0x80
#define PAGE_SIZE_FLAG 0x80
typedef uint32_t page_directory_entry;
typedef uint32_t page_table_entry;
// These two are defined in the assembly file paging.asm // These two are defined in the assembly file paging.asm
extern void loadPageDirectory(uint32_t*); extern void loadPageDirectory(page_directory_entry*);
extern void enablePaging(); extern void enablePaging();
// Defined in the file mem.c // Defined in the file mem.c
uint32_t* initiate_directory(); page_directory_entry* initiate_directory();
void initiate_page_table(uint32_t* page_dir); void initiate_page_table(page_directory_entry* page_dir);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment