API Documentation


Page Handling

group paging

Unnamed Group

typedef uint32_t optimsoc_pte_t

Page table entry

A page table entry is a 32 bit value as defined by the architecture specification.

typedef optimsoc_pte_t *optimsoc_page_table_t

Page table

A page table is an array of page table entries.

void _optimsoc_vmm_init(void)

Initialize virtual memory subsystem

Set the exception handlers for the memory management units.

optimsoc_page_table_t _optimsoc_vmm_create_page_table()

Allocate page table

Allocate a page table in memory and initialize all entries to 0.

Return

New allocated table

optimsoc_pte_t _optimsoc_vmm_lookup(optimsoc_page_dir_t directory, uint32_t vaddr)

Lookup virtual address in page directory

This is the lookup function that does the two level lookup for a virtual address and returns the page table entry. Call optimsoc_vmm_virt2phys if you need the physical address.

Return

Page table entry for virtual address

Parameters
  • directory: Directory to search

  • vaddr: Virtual address to lookup

void _optimsoc_set_dtlb(uint32_t vaddr, optimsoc_pte_t pte)

Set the DTLB entry

Parameters
  • vaddr: Virtual address to set

  • pte: Corresponding page table entry

void _optimsoc_set_itlb(uint32_t vaddr, optimsoc_pte_t pte)

Set the ITLB entry

Parameters
  • vaddr: Virtual address to set

  • pte: Corresponding page table entry

void _optimsoc_dtlb_miss(void)

DTLB miss handler

void _optimsoc_itlb_miss(void)

ITLB miss handler

void _optimsoc_dpage_fault(void)

DMMU fault handler

void _optimsoc_ipage_fault(void)

IMMU fault handler

Typedefs

typedef uint32_t *optimsoc_page_dir_t

Page directory

The page directory is the data structure for the memory lookup from virtual addresses to physical addresses. It can be shared by multiple threads and is assigned to a thread by calling optimsoc_thread_set_pagedir.

It should not be manipulated directly, but only by the functions provided. Mapping pages is thread-safe, but generally caution is necessary when calling the functions on two different cores concurrently when accessing the same virtual pages.

typedef void (*optimsoc_pfault_handler_fptr)(uint32_t vaddr)

Page fault handler type

The function pointer is used to define callback function for page faults when a page cannot be found in the page directory. The user code has to take appropriate actions then.

Parameters
  • vaddr: The virtual address of the fault

typedef void *(*page_alloc_fptr)()

Functions

optimsoc_page_dir_t optimsoc_vmm_create_page_dir(void)

Create a new page directory

This function allocates a new page directory. You can set it for a thread by calling optimsoc_thread_set_pagedir.

Return

Empty page dir

int optimsoc_vmm_map(optimsoc_page_dir_t directory, uint32_t vaddr, uint32_t paddr)

Map virtual page to physical page

This functions adds the entry of the virtual page of vaddr to the physical page of paddr.

Return

Success of operation

Parameters
  • directory: Directory to add page mapping to

  • vaddr: Virtual address of the page to map

  • paddr: Physical address of the page to map

int optimsoc_vmm_unmap(optimsoc_page_dir_t directory, uint32_t vaddr)

Remove a page from directory

Remove an entry from the page directory.

Return

Success of operation

Parameters
  • directory: Directory to remove page from

  • vaddr: Virtual address of page to map

int optimsoc_vmm_virt2phys(optimsoc_page_dir_t directory, uint32_t vaddr, uint32_t *paddr)

Virtual to physical mapping

Map a virtual address to the physical address.

Return

Success of operation

Parameters
  • directory: Directory for lookup

  • vaddr: Virtual address

  • [out] paddr: Physical address

int optimsoc_vmm_phys2virt(optimsoc_page_dir_t directory, uint32_t paddr, uint32_t *vaddr)

Physical to virtual mapping

Find virtual address for a physical address. This is a very time consuming operation, especially if the virtual address space is fully or sparsely populated. It also only finds the first mapping, but may be usefull to find and delete incorrect mappings.

Return

Success of operation

Parameters
  • directory: Directory for lookup

  • paddr: Physical address

  • [out] vaddr: Virtual address

void optimsoc_vmm_set_dfault_handler(optimsoc_pfault_handler_fptr handler)

Set handler for data page faults

Register the handler for fault exceptions from the data MMU.

Parameters
  • handler: Handler to register

void optimsoc_vmm_set_ifault_handler(optimsoc_pfault_handler_fptr handler)

Set handler for instruction page faults

Register the handler for fault exceptions from the instructions MMU.

Parameters
  • handler: Handler to register

void optimsoc_vmm_destroy_page_dir(optimsoc_page_dir_t dir)

Destroy a page directory

Destroy an entire page directory and free the memory.

Parameters
  • dir: Directory to destroy

optimsoc_page_dir_t optimsoc_vmm_dir_copy(uint32_t remote_tile, void *remote_addr, page_alloc_fptr page_alloc_fnc)