Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

paging.h File Reference

Paging header. More...

#include <kernel/kernel_map.h>

Go to the source code of this file.

Data Structures

struct  PAGE_TABLE
 Page table structure. More...


Defines

#define PAGE_SIZE   4096U
 The page size.

#define P_PRESENT   0x01
 Page present flag.

#define P_WRITE   0x02
 Page writeable flag.

#define P_USER   0x04
 Page at user privilege level.

#define P_ACCESSED   0x20
 Page accessed flag.

#define P_DIRTY   0x40
 Page dirty flag (the page has been written).

#define P_ADDR_16MB   (0x1000000 / PAGE_SIZE)
 16MB expressed in pages.

#define P_ADDR_4GB   0x100000
 4GB expressed in pages.

#define PAGE_ALIGN_UP(addr)   (((addr) + PAGE_SIZE - 1) & -PAGE_SIZE)
 Rounds an address up to a page boundary.

#define PAGE_ALIGN(addr)   ((addr) & -PAGE_SIZE)
 Rounds an address down to a page boundary.

#define PAGE_DIR_ALIGN_UP(addr)   (((addr) & -(PAGE_SIZE*1024)) + PAGE_SIZE*1024)
 Rounds an address up to a page directory boundary.

#define PAGE_DIR_ALIGN(addr)   ((addr) & -(PAGE_SIZE*1024))
 Rounds an address down to a page directory boundary.

#define ADDR_TO_PAGE(addr)   (addr / PAGE_SIZE)
 Converts from address to page.

#define PAGE_TO_ADDR(p_addr)   (p_addr * PAGE_SIZE)
 Converts from page to address.

#define GET_PDBR()   (*ADDR_TO_PDE(PAGE_TABLE_MAP) & -PAGE_SIZE)
 Get current page directory base address.

#define ADDR_TO_PDE(addr)   (dword *)(PAGE_DIR_MAP + (((dword) (addr) / (1024 * 1024))&(~0x3)))
 Access to the page directory entry referred to the virtual address addr.

#define ADDR_TO_PTE(addr)   (dword *)(PAGE_TABLE_MAP + ((((dword) (addr) / 1024))&(~0x3)))
 Access to the page table entry referred to the virtual address addr.

#define PHYSICAL(addr)   (addr+PHYS_MEM_START)
 Access to an address into the mapped physical memory area.

#define flush_tlb_single(addr)   __asm__ __volatile__("invlpg %0": :"m" (*(char *) addr))
 Flush a single entry into the TLB cache (address translation).
Parameters:
addr  The virtual address of the page that must be invalidated.


#define flush_tlb_all()
 Flush every entry into the TLB cache (address translation).


Typedefs

typedef PAGE_TABLE page_table_t
 Page table structure.


Functions

void init_paging ()
 Initialize the paging mechanism.
Note:
This routine must be called once, when the system is initializing.
Warning:
This routine must be the first routine of the kernel initialization process!!!


dword pop_frame ()
 Pop a free frame from the free frames stack.
Exceptions:
NULL  Out-of-memory.
Note:
The function returns the address expressed in the page number format. This value will be multiplied by PAGE_SIZE to obtain the real physical address of the frame.


void push_frame (dword p_addr)
 Push a free frame into the free frames stack.
Parameters:
p_addr  The page number you want to push.
Note:
The value p_addr must be the page number!
If you know the physical address you have to divide this value to PAGE_SIZE.


bool map_page (dword vir_addr, dword phys_addr, word attribs)
 Map a physical address into a virtual address for the current address space.
Parameters:
vir_addr  The virtual address.
phys_addr  The physical address.
attribs  The attributes mask for this page.
Returns:


void unmap_page (dword vir_addr)
 Unmap a page, but doesn't destroy the physical frame.
Parameters:
vir_addr  The virtual address you want to unmap.


void delete_page (dword vir_addr)
 Unmap a page and destroy the physical frame where the address is mapped.
Parameters:
vir_addr  The virtual address you want to delete.


void * get_temp_page ()
 Get a free virtual page from the temporary memory area.
Returns:
The address of the temporary page or NULL if out of memory.


void free_temp_page (void *p, bool do_delete)
 Free a virtual temporary page allocated by get_temp_page().
Parameters:
p  The temporary page virtual address.
do_delete 
  • TRUE free the page and also the physical frame;
  • FALSE unmap the page only, do not free the physical frame.


dword vir_to_phys (dword vir_addr)
 Translate a virtual address into the physical address.
Parameters:
vir_addr  The virtual address to be translated.


int page_fault_handler (dword err_code, dword cr2)
 This is the page-fault handler. Every time a page-fault occurs, this routine must be invoked.
Parameters:
err_code  The error code from the CPU.
cr2  The address that caused the fault.
Returns:
  • 0 success;
  • < 0 otherwise.


void dump_dirty_pages ()
 Dump the dirty pages to stdout.

void dump_free_frames ()
 Dump the free frames to stdout.

void check_free_frames_integrity ()
 This process checks the free frames stack integrity.
Warning:
This is a process so it must end with auto_kill();.



Detailed Description

Paging header.

Author:
Andrea Righi <drizzt@inwind.it>
Date:
Last update: 2003-12-16
Note:
Copyright (©) 2003 Andrea Righi

Definition in file paging.h.


Define Documentation

#define ADDR_TO_PAGE addr       (addr / PAGE_SIZE)
 

Converts from address to page.

Definition at line 43 of file paging.h.

#define ADDR_TO_PDE addr       (dword *)(PAGE_DIR_MAP + (((dword) (addr) / (1024 * 1024))&(~0x3)))
 

Access to the page directory entry referred to the virtual address addr.

Definition at line 51 of file paging.h.

#define ADDR_TO_PTE addr       (dword *)(PAGE_TABLE_MAP + ((((dword) (addr) / 1024))&(~0x3)))
 

Access to the page table entry referred to the virtual address addr.

Definition at line 55 of file paging.h.

 
#define flush_tlb_all  
 

Value:

do {                                                            \
                unsigned int tmpreg;                                    \
                                                                        \
                __asm__ __volatile__(                                   \
                        "movl %%cr3, %0;  # flush TLB \n"               \
                        "movl %0, %%cr3;              \n"               \
                        : "=r" (tmpreg)                                 \
                        :: "memory");                                   \
        } while (0)
Flush every entry into the TLB cache (address translation).

Definition at line 73 of file paging.h.

#define flush_tlb_single addr       __asm__ __volatile__("invlpg %0": :"m" (*(char *) addr))
 

Flush a single entry into the TLB cache (address translation).

Parameters:
addr  The virtual address of the page that must be invalidated.

Definition at line 69 of file paging.h.

 
#define GET_PDBR      (*ADDR_TO_PDE(PAGE_TABLE_MAP) & -PAGE_SIZE)
 

Get current page directory base address.

Definition at line 47 of file paging.h.

#define P_ACCESSED   0x20
 

Page accessed flag.

Definition at line 24 of file paging.h.

#define P_ADDR_16MB   (0x1000000 / PAGE_SIZE)
 

16MB expressed in pages.

Definition at line 29 of file paging.h.

#define P_ADDR_4GB   0x100000
 

4GB expressed in pages.

Definition at line 31 of file paging.h.

#define P_DIRTY   0x40
 

Page dirty flag (the page has been written).

Definition at line 26 of file paging.h.

#define P_PRESENT   0x01
 

Page present flag.

Definition at line 18 of file paging.h.

#define P_USER   0x04
 

Page at user privilege level.

Definition at line 22 of file paging.h.

#define P_WRITE   0x02
 

Page writeable flag.

Definition at line 20 of file paging.h.

#define PAGE_ALIGN addr       ((addr) & -PAGE_SIZE)
 

Rounds an address down to a page boundary.

Definition at line 36 of file paging.h.

#define PAGE_ALIGN_UP addr       (((addr) + PAGE_SIZE - 1) & -PAGE_SIZE)
 

Rounds an address up to a page boundary.

Definition at line 34 of file paging.h.

#define PAGE_DIR_ALIGN addr       ((addr) & -(PAGE_SIZE*1024))
 

Rounds an address down to a page directory boundary.

Definition at line 40 of file paging.h.

#define PAGE_DIR_ALIGN_UP addr       (((addr) & -(PAGE_SIZE*1024)) + PAGE_SIZE*1024)
 

Rounds an address up to a page directory boundary.

Definition at line 38 of file paging.h.

#define PAGE_SIZE   4096U
 

The page size.

Definition at line 15 of file paging.h.

#define PAGE_TO_ADDR p_addr       (p_addr * PAGE_SIZE)
 

Converts from page to address.

Definition at line 45 of file paging.h.

#define PHYSICAL addr       (addr+PHYS_MEM_START)
 

Access to an address into the mapped physical memory area.

Definition at line 58 of file paging.h.


Typedef Documentation

typedef struct PAGE_TABLE page_table_t
 

Page table structure.


Generated on Fri Feb 20 15:32:19 2004 for Minirighi by doxygen1.2.18