IBNOS
Classes | Macros | Functions
paging.c File Reference
#include <memory/paging.h>
#include <memory/physmem.h>
#include <interrupt/interrupt.h>
#include <process/process.h>
#include <process/thread.h>
#include <console/console.h>
#include <util/list.h>
#include <util/util.h>
Include dependency graph for paging.c:

Go to the source code of this file.

Classes

struct  bootMapEntry
 

Macros

#define MAX_BOOT_ENTRIES   1024
 
#define KERNEL_DIR_ENTRY   (PAGETABLE_COUNT - 1)
 
#define KERNEL_DIR_ADDR   (((KERNEL_DIR_ENTRY << PAGETABLE_BITS) | KERNEL_DIR_ENTRY) << PAGE_BITS)
 
#define KERNEL_PAGE_ADDR   (KERNEL_DIR_ENTRY << (PAGETABLE_BITS + PAGE_BITS))
 
#define PAGING_AVAIL_NOTPRESENT_RESERVED   1 /* frame == 0, denies allocation for everyone with lower privileges */
 
#define PAGING_AVAIL_NOTPRESENT_ON_ACCESS_CREATE   2 /* frame == 0, creates a new page on access with rw = 1 */
 
#define PAGING_AVAIL_NOTPRESENT_OUTPAGED   3 /* frame points to some external device where the page is located */
 
#define PAGING_AVAIL_PRESENT_SHARED   1 /* shared, will not be duplicated when forking */
 
#define PAGING_AVAIL_PRESENT_NO_FORK   2 /* doesn't copy this block while forking */
 
#define PAGING_AVAIL_PRESENT_ON_WRITE_DUPLICATE   3 /* readwrite=0, copy (and release) the physical frame pointed to by frame */
 

Functions

uint32_t __getCR0 ()
 
 asm (".text\align 4\ "__getCR0:\" " movl %cr0, %eax\" " ret\")
 
uint32_t __setCR0 (uint32_t value)
 
 asm (".text\align 4\ "__setCR0:\" " movl 4(%esp), %eax\" " movl %eax, %cr0\" " ret\")
 
uint32_t __getCR3 ()
 
 asm (".text\align 4\ "__getCR3:\" " movl %cr3, %eax\" " ret\")
 
uint32_t __setCR3 (uint32_t value)
 
 asm (".text\align 4\ "__setCR3:\" " movl 4(%esp), %eax\" " movl %eax, %cr3\" " ret\")
 
uint32_t interrupt_0x0E (UNUSED uint32_t interrupt, uint32_t error, struct thread *t)
 Page fault handler. More...
 
void pagingInsertBootMap (uint32_t startIndex, uint32_t stopIndex)
 Appends a specific range of physical pages to the bootmap. More...
 
void pagingDumpBootMap ()
 Dumps a list of all entries in the boot map. More...
 
void pagingInit ()
 Initializes paging. More...
 
void pagingDumpPageTable (struct process *p)
 Dumps information about the page table of a specific process. More...
 
void pagingReserveArea (struct process *p, void *addr, uint32_t length, bool user)
 Marks the memory in a specific memory area as reserved. More...
 
void * pagingSearchArea (struct process *p, uint32_t length)
 Searches for a consecutive area of length free pages in a process. More...
 
void * pagingTrySearchArea (struct process *p, uint32_t length)
 Searches for a consecutive area of length free pages in a process. More...
 
void * pagingAllocatePhysMem (struct process *p, uint32_t length, bool rw, bool user)
 Allocates several pages of physical memory in a process. More...
 
void * pagingAllocatePhysMemUnpageable (struct process *p, uint32_t length, bool rw, bool user)
 Allocates several pages of unpageable physical memory in a process. More...
 
void * pagingTryAllocatePhysMem (struct process *p, uint32_t length, bool rw, bool user)
 Tries to allocates several pages of physical memory in a process. More...
 
void * pagingAllocatePhysMemFixed (struct process *p, void *addr, uint32_t length, bool rw, bool user)
 Allocates several pages of physical memory at a fixed virtual address in a process. More...
 
void * pagingAllocatePhysMemFixedUnpageable (struct process *p, void *addr, uint32_t length, bool rw, bool user)
 Allocates several pages of unpageable physical memory at a fixed virtual address in a process. More...
 
void * pagingTryAllocatePhysMemFixed (struct process *p, void *addr, uint32_t length, bool rw, bool user)
 Allocates several pages of unpageable physical memory at a fixed virtual address in a process. More...
 
void * pagingReAllocatePhysMem (struct process *p, void *addr, uint32_t old_length, uint32_t new_length, bool rw, bool user)
 Reallocates a specific range of virtual memory in a process. More...
 
void pagingReleasePhysMem (struct process *p, void *addr, uint32_t length)
 Releases several pages of physical memory in a process. More...
 
bool pagingTryReleasePhysMem (struct process *p, void *addr, uint32_t length)
 Releases several pages of physical memory of a process. More...
 
uint32_t pagingGetPhysMem (struct process *p, void *addr)
 Returns the physical page index for a virtual address. More...
 
void * pagingMapRemoteMemory (struct process *dst_p, struct process *src_p, void *dst_addr, void *src_addr, uint32_t length, bool rw, bool user)
 Maps some virtual memory from one process to another one. More...
 
void pagingAllocProcessPageTable (struct process *p)
 Allocates the page directory and page table for a specific process. More...
 
void pagingForkProcessPageTable (struct process *destination, struct process *source)
 Duplicate a page table and assigns it to a destination process. More...
 
void pagingReleaseProcessPageTable (struct process *p)
 Releases the page directory and page table of a specific process. More...
 
void pagingFillProcessInfo (struct process *p, struct processInfo *info)
 Fills out all memory related fields in the processInfo structure. More...
 
void * pagingTryMapUserMem (struct process *src_p, void *src_addr, uint32_t length, bool rw)
 Maps some virtual memory of a usermode process into the kernel. More...
 
bool pagingTryReleaseUserMem (struct process *p, void *addr, uint32_t length)
 Releases several pages of physical memory of a process. More...
 

Macro Definition Documentation

◆ KERNEL_DIR_ADDR

#define KERNEL_DIR_ADDR   (((KERNEL_DIR_ENTRY << PAGETABLE_BITS) | KERNEL_DIR_ENTRY) << PAGE_BITS)

Definition at line 48 of file paging.c.

◆ KERNEL_DIR_ENTRY

#define KERNEL_DIR_ENTRY   (PAGETABLE_COUNT - 1)

Definition at line 47 of file paging.c.

◆ KERNEL_PAGE_ADDR

#define KERNEL_PAGE_ADDR   (KERNEL_DIR_ENTRY << (PAGETABLE_BITS + PAGE_BITS))

Definition at line 49 of file paging.c.

◆ MAX_BOOT_ENTRIES

#define MAX_BOOT_ENTRIES   1024

Definition at line 43 of file paging.c.

◆ PAGING_AVAIL_NOTPRESENT_ON_ACCESS_CREATE

#define PAGING_AVAIL_NOTPRESENT_ON_ACCESS_CREATE   2 /* frame == 0, creates a new page on access with rw = 1 */

Definition at line 69 of file paging.c.

◆ PAGING_AVAIL_NOTPRESENT_OUTPAGED

#define PAGING_AVAIL_NOTPRESENT_OUTPAGED   3 /* frame points to some external device where the page is located */

Definition at line 70 of file paging.c.

◆ PAGING_AVAIL_NOTPRESENT_RESERVED

#define PAGING_AVAIL_NOTPRESENT_RESERVED   1 /* frame == 0, denies allocation for everyone with lower privileges */

Definition at line 68 of file paging.c.

◆ PAGING_AVAIL_PRESENT_NO_FORK

#define PAGING_AVAIL_PRESENT_NO_FORK   2 /* doesn't copy this block while forking */

Definition at line 74 of file paging.c.

◆ PAGING_AVAIL_PRESENT_ON_WRITE_DUPLICATE

#define PAGING_AVAIL_PRESENT_ON_WRITE_DUPLICATE   3 /* readwrite=0, copy (and release) the physical frame pointed to by frame */

Definition at line 75 of file paging.c.

◆ PAGING_AVAIL_PRESENT_SHARED

#define PAGING_AVAIL_PRESENT_SHARED   1 /* shared, will not be duplicated when forking */

Definition at line 73 of file paging.c.

Function Documentation

◆ __getCR0()

uint32_t __getCR0 ( )

◆ __getCR3()

uint32_t __getCR3 ( )

◆ __setCR0()

uint32_t __setCR0 ( uint32_t  value)

◆ __setCR3()

uint32_t __setCR3 ( uint32_t  value)

◆ asm() [1/4]

asm ( ".text\ign 4\__getCR0:\ " movl %  cr0,
%eax\" " ret\"   
)

◆ asm() [2/4]

asm ( ".text\lign 4\"__setCR0:\" " movl   4%esp,
%eax\" " movl %  eax,
%cr0\" " ret\"   
)

◆ asm() [3/4]

asm ( ".text\ign 4\__getCR3:\ " movl %  cr3,
%eax\" " ret\"   
)

◆ asm() [4/4]

asm ( ".text\lign 4\"__setCR3:\" " movl   4%esp,
%eax\" " movl %  eax,
%cr3\" " ret\"   
)

◆ interrupt_0x0E()

uint32_t interrupt_0x0E ( UNUSED uint32_t  interrupt,
uint32_t  error,
struct thread t 
)

Page fault handler.

Whenever the kernel or a usermode application tries to access a virtual memory address which is not present in the page table (or where access is denied) a page fault is triggered. If the situation can be resolved (for example loading the missing page from the harddrive or duplicating the read-only page, then INTERRUPT_CONTINUE_EXECUTION is returned. Otherwise the handler cannot resolve the problem. This is critical for kernel errors because the kernel is unable to proceed. For usermode applications the corresponding process will be killed - at some later point we will probably add some additional mechanisms such that usermode applications can also try to resolve this error on their own by defining an exception handler function at program start.

Parameters
interruptAlways 0x0E
errorError code containing information about the type of access
tThe thread in which the page fault occured
Returns
INTERRUPT_CONTINUE_EXECUTION on success, otherwise INTERRUPT_UNHANDLED

Definition at line 298 of file paging.c.