source: soft/giet_vm/giet_common/vmem.h @ 534

Last change on this file since 534 was 534, checked in by alain, 9 years ago

Simplify the _v2p_translate function prototype.

  • Property svn:executable set to *
File size: 4.1 KB
Line 
1///////////////////////////////////////////////////////////////////////////////////
2// File     : vmem.h
3// Date     : 01/07/2012
4// Author   : alain greiner
5// Copyright (c) UPMC-LIP6
6///////////////////////////////////////////////////////////////////////////////////
7// The vmem.c and vmem.h files are part ot the GIET-VM nano kernel.
8// They define  the data structures implementing the page tables,
9// and the function used for VPN to PPN translation.
10///////////////////////////////////////////////////////////////////////////////////
11// The virtual address format is 32 bits: structures in 3 fields:
12//             |  11  |  9   |   12   |
13//             | IX1  | IX2  | OFFSET |
14// - The IX1 field is the index in the first level page table
15// - The IX2 field is the index in the second level page table
16// - The |IX1|IX2\ concatenation defines the VPN (Virtual Page Number)
17///////////////////////////////////////////////////////////////////////////////////
18
19#ifndef _VMEM_H_
20#define _VMEM_H_
21
22/////////////////////////////////////////////////////////////////////////////////////
23// Page Table sizes definition
24/////////////////////////////////////////////////////////////////////////////////////
25
26#define PT1_SIZE    8192
27#define PT2_SIZE    4096
28
29#define VPN_MASK    0xFFFFF000
30#define BPN_MASK    0xFFE00000
31
32/////////////////////////////////////////////////////////////////////////////////////
33// PTE flags masks definition
34/////////////////////////////////////////////////////////////////////////////////////
35
36#define PTE_V  0x80000000
37#define PTE_T  0x40000000
38#define PTE_L  0x20000000
39#define PTE_R  0x10000000
40#define PTE_C  0x08000000
41#define PTE_W  0x04000000
42#define PTE_X  0x02000000
43#define PTE_U  0x01000000
44#define PTE_G  0x00800000
45#define PTE_D  0x00400000
46
47///////////////////////////////////////////////////////////////////////////////////
48// MMU error codes definition
49///////////////////////////////////////////////////////////////////////////////////
50
51#define MMU_ERR_PT1_UNMAPPED         0x001 // Page fault on Table1 (invalid PTE)
52#define MMU_ERR_PT2_UNMAPPED         0x002 // Page fault on Table 2 (invalid PTE)
53#define MMU_ERR_PRIVILEGE_VIOLATION  0x004 // Protected access in user mode
54#define MMU_ERR_WRITE_VIOLATION      0x008 // Write access to a non write page
55#define MMU_ERR_EXEC_VIOLATION       0x010 // Exec access to a non exec page
56#define MMU_ERR_UNDEFINED_XTN        0x020 // Undefined external access address
57#define MMU_ERR_PT1_ILLEGAL_ACCESS   0x040 // Bus Error in Table1 access
58#define MMU_ERR_PT2_ILLEGAL_ACCESS   0x080 // Bus Error in Table2 access
59#define MMU_ERR_CACHE_ILLEGAL_ACCESS 0x100 // Bus Error during the cache access
60
61///////////////////////////////////////////////////////////////////////////////////
62// Page table structure definition
63///////////////////////////////////////////////////////////////////////////////////
64
65typedef struct PageTable
66{
67    unsigned int pt1[PT1_SIZE / 4];    // PT1 (index is ix1)
68    unsigned int pt2[1][PT2_SIZE / 4]; // PT2s (index is 2*ix2)
69} page_table_t;
70
71///////////////////////////////////////////////////////////////////////////////////
72// functions prototypes
73///////////////////////////////////////////////////////////////////////////////////
74
75///////////////////////////////////////////////////////////////////////////////////
76// This function makes a "virtual" to "physical" address translation,
77// using the page table of the calling task.
78// The MMU is supposed to be activated.
79// It supports both small (4 Kbytes) & big (2 Mbytes) pages.
80// The page flags are written in the flags buffer.
81// It uses the address extension mechanism for physical addressing.
82// Returns the physical address if success, exit if PTE1 or PTE2 unmapped.
83///////////////////////////////////////////////////////////////////////////////////
84unsigned long long _v2p_translate( unsigned int  vaddr,
85                                   unsigned int* flags );
86
87#endif
88
89// Local Variables:
90// tab-width: 4
91// c-basic-offset: 4
92// c-file-offsets:((innamespace . 0)(inline-open . 0))
93// indent-tabs-mode: nil
94// End:
95// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
96
Note: See TracBrowser for help on using the repository browser.