Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
triazo
/
kernel
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
3
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e64790c4
authored
Sep 28, 2015
by
triazo
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add C functions to construct paging structures
parent
490cafc1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
0 deletions
src/mem.c
src/mem.h
src/mem.c
0 → 100644
View file @
e64790c4
/*
mem.c is the main file for dealing with virtual memory and paging.
*/
#include "mem.h"
// page_directory is currently defined once and should not be touched
// later. It must be page aligned for the MMU to read properly
uint32_t
page_directory
[
1024
]
__attribute__
((
aligned
(
4096
)));
// page_table_one is the first page table, and at the beginning the
// only page table in the page directory
uint32_t
page_table_one
[
1024
]
__attribute__
((
aligned
(
4096
)));
uint32_t
*
initiate_directory
()
{
// set each entry to not present
int
i
;
for
(
i
=
0
;
i
<
1024
;
i
++
)
{
// This sets the following flags to the pages:
// Supervisor: Only kernel-mode can access them
// Write Enabled: It can be both read from and written to
// (this is the 2 bit)
// Not Present: The page table is not present
page_directory
[
i
]
=
0x00000002
;
}
return
page_directory
;
}
void
initiate_page_table
(
uint32_t
*
page_dir
)
{
// 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.
unsigned
int
i
;
//we will fill all 1024 entries in the table, mapping 4 megabytes
for
(
i
=
0
;
i
<
1024
;
i
++
)
{
// As the address is page aligned, it will always leave 12 bits zeroed.
// Those bits are used by the attributes:
// -> supervisor level, read/write, present.
page_table_one
[
i
]
=
(
i
*
0x1000
)
|
3
;
}
// attributes: supervisor level, read/write, present
page_dir
[
0
]
=
((
unsigned
int
)
page_table_one
)
|
3
;
}
src/mem.h
0 → 100644
View file @
e64790c4
/*
mem.h
*/
#pragma once
#include <stdint.h>
// Defined in the file mem.c
uint32_t
*
initiate_directory
();
void
initiate_page_table
(
uint32_t
*
page_dir
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment