GitOS
Operating system exercise
Loading...
Searching...
No Matches
paging.h File Reference
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  paging_chunk
 

Macros

#define PAGING_CACHE_DISABLED   0b00010000
 
#define PAGING_WRITE_THROUGH   0b00001000
 
#define PAGING_ACCESS_FROM_ALL   0b00000100
 
#define PAGING_IS_WRITEABLE   0b00000010
 
#define PAGING_IS_PRESENT   0b00000001
 
#define PAGING_TOTAL_ENTRIES_PER_TABLE   1024
 
#define PAGING_PAGE_SIZE   4096
 

Functions

struct paging_chunkpaging_new_directory (uint8_t flags)
 Allocates and creates new page directory with specified flags.
 
void paging_free_directory (struct paging_chunk *chunk)
 Frees all entries and page directory itself.
 
void paging_switch (struct paging_chunk *chunk)
 Switches to given page directory pointer.
 
void paging_enable ()
 
uint32_t * paging_get_directory (struct paging_chunk *chunk)
 Returns directory entry pointer for given chunk.
 
int paging_map_to (struct paging_chunk *chunk, void *virtual_address, void *physical_address, void *physical_end, int flags)
 Maps virtual address to physical in page directory.
 
void * paging_align_address (void *ptr)
 Aligns pointer to page size.
 
void * paging_align_address_to_lower_page (void *ptr)
 
int paging_set_page (uint32_t *directory, void *virtual_address, uint32_t value)
 Sets page table entry.
 
uint32_t paging_get_page (uint32_t *directory, void *virtual_address)
 

Macro Definition Documentation

◆ PAGING_ACCESS_FROM_ALL

#define PAGING_ACCESS_FROM_ALL   0b00000100

◆ PAGING_CACHE_DISABLED

#define PAGING_CACHE_DISABLED   0b00010000

◆ PAGING_IS_PRESENT

#define PAGING_IS_PRESENT   0b00000001

◆ PAGING_IS_WRITEABLE

#define PAGING_IS_WRITEABLE   0b00000010

◆ PAGING_PAGE_SIZE

#define PAGING_PAGE_SIZE   4096

◆ PAGING_TOTAL_ENTRIES_PER_TABLE

#define PAGING_TOTAL_ENTRIES_PER_TABLE   1024

◆ PAGING_WRITE_THROUGH

#define PAGING_WRITE_THROUGH   0b00001000

Function Documentation

◆ paging_align_address()

void * paging_align_address ( void *  ptr)

Aligns pointer to page size.

Parameters
ptr
Returns
void*

References PAGING_PAGE_SIZE.

◆ paging_align_address_to_lower_page()

void * paging_align_address_to_lower_page ( void *  ptr)

References PAGING_PAGE_SIZE.

◆ paging_enable()

void paging_enable ( )

◆ paging_free_directory()

void paging_free_directory ( struct paging_chunk chunk)

Frees all entries and page directory itself.

Parameters
chunkPage directory to free

References paging_chunk::directory_entry, and kfree().

◆ paging_get_directory()

uint32_t * paging_get_directory ( struct paging_chunk chunk)

Returns directory entry pointer for given chunk.

Parameters
chunkChunk
Returns
uint32_t* Page directory pointer

References paging_chunk::directory_entry.

◆ paging_get_page()

uint32_t paging_get_page ( uint32_t *  directory,
void *  virtual_address 
)

References EINVARG.

◆ paging_map_to()

int paging_map_to ( struct paging_chunk chunk,
void *  virtual_address,
void *  physical_address,
void *  physical_end,
int  flags 
)

Maps virtual address to physical in page directory.

Parameters
chunkPaging chunk
physical_addressPhysical address start
physical_endPhysical address end
flagsPage directory entry flags
Returns
int Error code

References EINVARG, flags, paging_map_range(), and PAGING_PAGE_SIZE.

◆ paging_new_directory()

struct paging_chunk * paging_new_directory ( uint8_t  flags)

Allocates and creates new page directory with specified flags.

Parameters
flagsFlags for each page table
Returns
paging_chunk* Pointer to new paging chunk

References paging_chunk::directory_entry, flags, kzalloc(), offset, PAGING_IS_WRITEABLE, PAGING_PAGE_SIZE, and PAGING_TOTAL_ENTRIES_PER_TABLE.

◆ paging_set_page()

int paging_set_page ( uint32_t *  directory,
void *  virtual_address,
uint32_t  value 
)

Sets page table entry.

Parameters
directoryPage directory pointer
virtual_addressVirtual address
valueValue for page table entry
Returns
int Status

References EINVARG.

◆ paging_switch()

void paging_switch ( struct paging_chunk chunk)

Switches to given page directory pointer.

Parameters
chunkPage directory pointer

References paging_chunk::directory_entry.