# paging.h File Reference

`#include <ubixos/types.h>`
`#include <sys/sysproto.h>`
`#include <sys/thread.h>`

Include dependency graph for paging.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Defines

#define | btoc(x) (((vm_offset_t)(x)+PAGE_MASK)>>PAGE_SHIFT)
#define | ctob(x) ((x)<<PAGE_SHIFT)
#define | KERNEL_PAGE_DEFAULT (PAGE_PRESENT|PAGE_WRITE)
#define | PAGE_COW 0x00000200
#define | PAGE_DEFAULT (PAGE_PRESENT|PAGE_WRITE|PAGE_USER)
#define | PAGE_MASK (PAGE_SIZE-1)
#define | PAGE_PRESENT 0x00000001
#define | PAGE_SHIFT 12
#define | PAGE_SIZE (1<<PAGE_SHIFT)
#define | PAGE_STACK 0x00000400
#define | PAGE_USER 0x00000004
#define | PAGE_WIRED 0x00000600
#define | PAGE_WRITE 0x00000002
#define | pageEntries (pageSize/4)
#define | pageLength 0x00000400
#define | pageSize 4096
#define | parentPageDirAddr 0x100000
#define | round_page(x) (((x) + PAGE_MASK) & ~PAGE_MASK)
#define | tablesBaseAddress 0xBFC00000
#define | trunc_page(x) ((x) & ~PAGE_MASK)
#define | VM_TASK 1
#define | VM_THRD 0

## Functions

void | _vmm_pageFault ()
int | mmap (struct thread *, struct mmap_args *)
int | munmap (struct thread *, struct munmap_args *)
int | obreak (struct thread *, struct obreak_args *)
void * | vmm_getFreeMallocPage (uInt16 count)
uInt32 | vmm_getPhysicalAddr (uInt32)
void | vmm_pageFault (uInt32, uInt32, uInt32)
int | vmm_pagingInit ()
int | vmm_remapPage (uInt32, uInt32, uInt16)
int | vmm_setPageAttributes (uInt32, uInt16)
int | vmmClearVirtualPage (uInt32 pageAddr)
void * | vmmCopyVirtualSpace (pidType)
void * | vmmCreateVirtualSpace (pidType)
void * | vmmGetFreeKernelPage (pidType pid, uInt16 count)
void * | vmmGetFreePage (pidType)
void * | vmmGetFreeVirtualPage (pidType, int, int)
void * | vmmMapFromTask (pidType, void *, uInt32)
void | vmmUnmapPage (uInt32, int)
void | vmmUnmapPages (void *, uInt32)

## Variables

uInt32 * | kernelPageDirectory

## Define Documentation

#define btoc | ( | x |  | ) | (((vm_offset_t)(x)+PAGE_MASK)>>PAGE_SHIFT)

Definition at line 62 of file paging.h.

Referenced by obreak(), and vmmGetFreeVirtualPage().

#define ctob | ( | x |  | ) | ((x)<<PAGE_SHIFT)

Definition at line 61 of file paging.h.

Referenced by obreak(), and vmmGetFreeVirtualPage().

#define KERNEL_PAGE_DEFAULT (PAGE_PRESENT|PAGE_WRITE)

Definition at line 53 of file paging.h.

Referenced by execFile(), vmm_getFreeMallocPage(), vmm_pagingInit(), vmm_remapPage(), vmmGetFreeKernelPage(), vmmGetFreePage(), and vmmMapFromTask().

#define PAGE_COW 0x00000200

Definition at line 46 of file paging.h.

Referenced by vmm_cleanVirtualSpace(), vmm_pageFault(), vmm_remapPage(), vmmCopyVirtualSpace(), vmmFreeProcessPages(), and vmmGetFreeVirtualPage().

#define PAGE_DEFAULT (PAGE_PRESENT|PAGE_WRITE|PAGE_USER)

Definition at line 52 of file paging.h.

Referenced by elf_loadfile(), execFile(), kmod_load(), ldEnable(), obreak(), sys_exec(), sysExec(), vmm_pageFault(), vmm_remapPage(), vmmCopyVirtualSpace(), vmmCreateVirtualSpace(), and vmmGetFreeVirtualPage().

#define PAGE_MASK (PAGE_SIZE-1)

Definition at line 57 of file paging.h.

#define PAGE_PRESENT 0x00000001

Definition at line 49 of file paging.h.

Referenced by elf_loadfile(), execFile(), sys_exec(), sysExec(), vmm_cleanVirtualSpace(), vmm_remapPage(), and vmmGetFreeVirtualPage().

#define PAGE_SHIFT 12

Definition at line 55 of file paging.h.

Referenced by sys_exec(), and sysExec().

#define PAGE_SIZE (1<<PAGE_SHIFT)

Definition at line 56 of file paging.h.

Referenced by sysExec().

#define PAGE_STACK 0x00000400

Definition at line 47 of file paging.h.

Referenced by execFile(), vmm_cleanVirtualSpace(), vmm_remapPage(), and vmmCopyVirtualSpace().

#define PAGE_USER 0x00000004

Definition at line 51 of file paging.h.

Referenced by elf_loadfile(), execFile(), sys_exec(), and sysExec().

#define PAGE_WIRED 0x00000600

Definition at line 48 of file paging.h.

#define PAGE_WRITE 0x00000002

Definition at line 50 of file paging.h.

#define pageEntries (pageSize/4)

Definition at line 42 of file paging.h.

Referenced by vmm_pageFault(), vmm_pagingInit(), vmm_remapPage(), vmmClearVirtualPage(), vmmCopyVirtualSpace(), vmmCreateVirtualSpace(), vmmFreeProcessPages(), and vmmGetFreeVirtualPage().

#define pageLength 0x00000400

Definition at line 40 of file paging.h.

#define pageSize 4096

Definition at line 41 of file paging.h.

#define parentPageDirAddr 0x100000

Definition at line 44 of file paging.h.

Referenced by vmm_cleanVirtualSpace(), vmm_pageFault(), vmm_remapPage(), vmmCopyVirtualSpace(), vmmCreateVirtualSpace(), vmmFreeProcessPages(), and vmmGetFreeVirtualPage().

#define round_page | ( | x |  | ) | (((x) + PAGE_MASK) & ~PAGE_MASK)

Definition at line 60 of file paging.h.

Referenced by obreak(), sys_exec(), and sysExec().

#define tablesBaseAddress 0xBFC00000

Definition at line 43 of file paging.h.

Referenced by vmm_cleanVirtualSpace(), vmm_getFreeMallocPage(), vmm_getPhysicalAddr(), vmm_pageFault(), vmm_remapPage(), vmm_setPageAttributes(), vmmCopyVirtualSpace(), vmmCreateVirtualSpace(), vmmFreeProcessPages(), vmmGetFreeKernelPage(), vmmGetFreePage(), vmmGetFreeVirtualPage(), vmmMapFromTask(), vmmUnmapPage(), and vmmUnmapPages().

#define trunc_page | ( | x |  | ) | ((x) & ~PAGE_MASK)

Definition at line 59 of file paging.h.

Referenced by sys_exec(), and sysExec().

#define VM_TASK 1

Definition at line 38 of file paging.h.

Referenced by mmap(), sysExec(), sysGetFreePage(), and vmmGetFreeVirtualPage().

#define VM_THRD 0

Definition at line 37 of file paging.h.

Referenced by sysGetFreePage(), and vmmGetFreeVirtualPage().

## Function Documentation

void _vmm_pageFault | ( |  | ) |

int mmap | ( | struct thread * | ,
|  | struct mmap_args * |  |
| ) |  |  |

Definition at line 453 of file paging.c.

References _current, mmap_args::addr, mmap_args::fd, mmap_args::flags, taskStruct::id, kprintf(), mmap_args::len, mmap_args::pad, mmap_args::pos, mmap_args::prot, thread::td_retval, VM_TASK, vmmGetFreeVirtualPage(), and x1000.

Here is the call graph for this function:

int munmap | ( | struct thread * | ,
|  | struct munmap_args * |  |
| ) |  |  |

Definition at line 516 of file paging.c.

References kprintf().

Here is the call graph for this function:

int obreak | ( | struct thread * | ,
|  | struct obreak_args * |  |
| ) |  |  |

Definition at line 478 of file paging.c.

References _current, btoc, ctob, taskStruct::id, K_PANIC, kprintf(), obreak_args::nsize, PAGE_DEFAULT, round_page, thread::vm_daddr, thread::vm_dsize, vmm_remapPage(), and vmmFindFreePage().

Here is the call graph for this function:

void* vmm_getFreeMallocPage | ( | uInt16 | count | ) |

Definition at line 401 of file paging.c.

References fkpSpinLock, K_PANIC, KERNEL_PAGE_DEFAULT, spinLock(), spinUnlock(), sysID, tablesBaseAddress, vmm_remapPage(), vmmClearVirtualPage(), vmmFindFreePage(), and x1000.

Referenced by getEmptyDesc().

Here is the call graph for this function:

uInt32 vmm_getPhysicalAddr | ( | uInt32 | pageAddr | ) |

Function: void *vmmGetPhysicalAddr(); Description: Returns The Physical Address Of The Virtual Page Notes:

Definition at line 40 of file getphysicaladdr.c.

References tablesBaseAddress, and x1000.

Referenced by vmm_pageFault(), vmmCopyVirtualSpace(), and vmmCreateVirtualSpace().

void vmm_pageFault | ( | uInt32 | ,
|  | uInt32 | ,
|  | uInt32 |  |
| ) |  |  |

Definition at line 53 of file pagefault.c.

References _current, adjustCowCounter(), endTask(), taskStruct::id, kpanic(), kprintf(), PAGE_COW, PAGE_DEFAULT, pageEntries, pageFaultSpinLock, parentPageDirAddr, spinLock(), spinUnlock(), tablesBaseAddress, taskStruct::td, thread::vm_daddr, thread::vm_dsize, vmm_getPhysicalAddr(), vmmFindFreePage(), vmmGetFreeVirtualPage(), vmmUnmapPage(), x1, and x1000.

Here is the call graph for this function:

int vmm_pagingInit | ( |  | ) |

Definition at line 59 of file paging.c.

References _vmm_pageFault, K_PANIC, KERNEL_PAGE_DEFAULT, kernelPageDirectory, kprintf(), memset(), numPages, pageEntries, sysID, vmm_remapPage(), vmmFindFreePage(), vmmMemoryMap, vmmMemoryMapAddr, x1, and x1000.

Referenced by vmm_init().

Here is the call graph for this function:

int vmm_remapPage | ( | uInt32 | ,
|  | uInt32 | ,
|  | uInt16 |  |
| ) |  |  |

Definition at line 160 of file paging.c.

References _current, freePage(), taskStruct::id, K_PANIC, KERNEL_PAGE_DEFAULT, kprintf(), PAGE_COW, PAGE_DEFAULT, PAGE_PRESENT, PAGE_STACK, pageEntries, parentPageDirAddr, rmpSpinLock, spinLock(), spinUnlock(), tablesBaseAddress, vmmFindFreePage(), and x1000.

Referenced by elf_loadfile(), execFile(), kmod_load(), ldEnable(), obreak(), sys_exec(), sysExec(), vmm_getFreeMallocPage(), vmm_pagingInit(), vmmGetFreeKernelPage(), vmmGetFreePage(), vmmGetFreeVirtualPage(), and vmmMapFromTask().

Here is the call graph for this function:

int vmm_setPageAttributes | ( | uInt32 | ,
|  | uInt16 |  |
| ) |  |  |

Definition at line 41 of file setpageattributes.c.

References kpanic(), tablesBaseAddress, and x1000.

Referenced by elf_loadfile(), execFile(), sys_exec(), and sysExec().

Here is the call graph for this function:

int vmmClearVirtualPage | ( | uInt32 | pageAddr | ) |

Definition at line 314 of file paging.c.

References pageEntries.

Referenced by vmm_getFreeMallocPage(), vmmGetFreeKernelPage(), vmmGetFreePage(), and vmmGetFreeVirtualPage().

void* vmmCopyVirtualSpace | ( | pidType |  | ) |

Definition at line 53 of file copyvirtualspace.c.

References adjustCowCounter(), cvsSpinLock, kpanic(), memset(), PAGE_COW, PAGE_DEFAULT, PAGE_STACK, pageEntries, parentPageDirAddr, spinLock(), spinUnlock(), tablesBaseAddress, vmm_getPhysicalAddr(), vmmGetFreeKernelPage(), vmmUnmapPage(), x1, and x1000.

Referenced by fork_copyProcess().

Here is the call graph for this function:

void* vmmCreateVirtualSpace | ( | pidType |  | ) |

Definition at line 81 of file createvirtualspace.c.

References PAGE_DEFAULT, pageEntries, parentPageDirAddr, tablesBaseAddress, vmm_getPhysicalAddr(), vmmGetFreePage(), and vmmUnmapPage().

Referenced by execFile().

Here is the call graph for this function:

void* vmmGetFreeKernelPage | ( | pidType | pid,
|  | uInt16 | count |
| ) |  |  |

Definition at line 253 of file paging.c.

References fkpSpinLock, K_PANIC, KERNEL_PAGE_DEFAULT, spinLock(), spinUnlock(), tablesBaseAddress, vmm_remapPage(), vmmClearVirtualPage(), and vmmFindFreePage().

Referenced by vmmCopyVirtualSpace().

Here is the call graph for this function:

void* vmmGetFreePage | ( | pidType |  | ) |

Definition at line 48 of file getfreepage.c.

References KERNEL_PAGE_DEFAULT, kpanic(), spinLock(), spinUnlock(), tablesBaseAddress, vmm_remapPage(), vmmClearVirtualPage(), vmmFindFreePage(), vmmGFPlock, and x1000.

Referenced by vmmCreateVirtualSpace().

Here is the call graph for this function:

void* vmmGetFreeVirtualPage | ( | pidType | ,
|  | int | ,
|  | int |  |
| ) |  |  |

Definition at line 47 of file getfreevirtualpage.c.

References _current, btoc, ctob, fvpSpinLock, taskStruct::id, K_PANIC, kpanic(), kprintf(), taskStruct::oInfo, PAGE_COW, PAGE_DEFAULT, PAGE_PRESENT, pageEntries, parentPageDirAddr, spinLock(), spinUnlock(), tablesBaseAddress, taskStruct::td, thread::vm_daddr, thread::vm_dsize, VM_TASK, VM_THRD, vmm_remapPage(), vmmClearVirtualPage(), vmmFindFreePage(), osInfo::vmStart, x1, and x1000.

Referenced by mmap(), sysExec(), sysGetFreePage(), and vmm_pageFault().

Here is the call graph for this function:

void* vmmMapFromTask | ( | pidType | ,
|  | void * | ,
|  | uInt32 |  |
| ) |  |  |

Definition at line 332 of file paging.c.

References _current, tssStruct::cr3, K_PANIC, KERNEL_PAGE_DEFAULT, taskStruct::oInfo, schedFindTask(), tablesBaseAddress, taskStruct::tss, vmm_remapPage(), vmmUnmapPage(), osInfo::vmStart, and x1000.

Here is the call graph for this function:

void vmmUnmapPage | ( | uInt32 | ,
|  | int |  |
| ) |  |  |

Definition at line 50 of file unmappage.c.

References tablesBaseAddress, and x1000.

Referenced by vmm_pageFault(), vmmCopyVirtualSpace(), vmmCreateVirtualSpace(), and vmmMapFromTask().

void vmmUnmapPages | ( | void * | ,
|  | uInt32 |  |
| ) |  |  |

Definition at line 101 of file unmappage.c.

References tablesBaseAddress.

## Variable Documentation

uInt32* kernelPageDirectory

Definition at line 40 of file paging.c.

Referenced by _int8(), execFile(), execThread(), idt_init(), and vmm_pagingInit().