wiki:kernel_vmem

Paged Virtual memory

The vmem.c and vmem.h files define the data structures and services functions that can be used by both the boot-loader and the kernel to implement the paged virtual memory.

The page table initialisation is statically done by the boot-loader. There is one page table for each vspace defined in the mapping. When the architecture is clusterised (X_WIDTH > 1 or Y_WIDTH > 1), for each vspace, there is one page table per cluster.

These functions can also be used by the kernel to dynamically map and unmap files to an application MMAP segment.

The virtual address format is 32 bits: structured in 3 fields:

11 9 12
IX1 IX2 OFFSET
  • The IX1 field is the index in the first level page table
  • The IX2 field is the index in the second level page table.
  • The |IX1|IX2| concatenation defines the VPN (Virtual Page Number).

Two page sizes are supported:

  • BPP : Big Physical Page / 2 Mbytes
  • SPP : Small Physical pages / 4 Kbytes

1) void _v2p_add_pte1( unsigned int vspace_id , unsigned int x , unsigned int y , unsigned int vpn , unsigned int flags , unsigned int ppn , unsigned int ident )

This function registers a new PTE1 entry (BPP) in the page table defined by the <vspace_id> argument, and the <x,y> coordinates. The value is defined by the <flags> and <ppn> arguments. It takes the lock protecting the target page table, and updates only the first level PT1. Exit if page table does not exist, or if the PTE1 already mapped.

2) void _v2p_add_pte2( unsigned int vspace_id , unsigned int x , unsigned int y , unsigned int vpn )

This function registers a new PTE2 entry (SPP) in the page table defined by the <vspace_id> argument, and the <x,y> coordinates. The value is defined by the <flags> and <ppn> arguments. It takes the lock protecting the target page table, and updates both the first level PT1 and the second level PT2. Exit if page table does not exist, or if the PTE1 already mapped, or if not enough PT2s.

3) void _v2p_del_pte1( unsigned int vspace_id , unsigned int x , unsigned int y , unsigned int vpn )

This function invalidates a PTE1 entry (BPP), or a PTN identified by the <vpn> argument, from the PT1 page table defined by the <vspace_id> argument, and the <x,y> coordinates. Exit if page table does not exist, or if PTE1 unmapped.

4) void _v2p_del_pte2( unsigned int vspace_id , unsigned int x , unsigned int y , unsigned int vpn )

This function invalidates a PTE2 entry (SPP) identified by the <vpn>, from the PT2 page table defined by the <vspace_id> argument, and the <x,y> coordinates. Exit if page table does not exist, or if PTE2 unmapped.

5) unsigned long long _v2p_translate( unsigned int vaddr , unsigned int* flags )

This function returns the physical address from the virtual address <vaddr>. The MMU is supposed to be activated, and it uses the page table defined by the CP0_PTPR register. It supports both small (4 Kbytes) & big (2 Mbytes) pages. The PTE1 or PTE2 flags are returned in the <flags> buffer. Exit if PTE1 or PTE2 unmapped.

Last modified 9 years ago Last modified on Jan 18, 2016, 4:47:22 PM