Kernel/arm7 - Still working on it
[tpg/acess2.git] / Kernel / arch / arm7 / mm_virt.c
1 /*
2  * Acess2
3  * 
4  * ARM7 Virtual Memory Manager
5  * - arch/arm7/mm_virt.c
6  */
7 #include <mm_virt.h>
8
9 // === TYPES ===
10 typedef struct
11 {
12         tPAddr  PhysAddr;
13         Uint8   Size;
14         Uint8   Domain;
15 } tMM_PageInfo;
16
17 // === GLOBALS ===
18 Uint32  *gMM_KernelTable0 = (void*)MM_TABLE0KERN;
19 Uint32  *gMM_KernelTable1 = (void*)MM_TABLE1KERN;
20
21 // === CODE ===
22 int MM_InitialiseVirtual(void)
23 {
24 }
25
26 int MM_int_GetPageInfo(tVAddr VAddr, tMM_PageInfo *pi)
27 {
28         Uint32  *table0, table1;
29         Uint32  desc;
30
31         if(VAddr & 0x80000000 ) {
32                 table0 = MM_TABLE0KERN;
33                 table1 = MM_TABLE1KERN;
34         }
35         else {
36                 table0 = MM_TABLE0USER;
37                 table1 = MM_TABLE1USER;
38         }
39         VAddr & 0x7FFFFFFF;
40
41         desc = table0[ VAddr >> 20 ];
42
43         switch( (desc & 3) )
44         {
45         // 0: Unmapped
46         case 0:
47                 pi->PhysAddr = 0;
48                 pi->Size = 20;
49                 pi->Domain = 0;
50                 return 1;
51
52         // 1: Coarse page table
53         case 1:
54                 // Domain from top level table
55                 pi->Domain = (desc >> 5) & 7;
56                 // Get next level
57                 desc = table1[ VAddr >> 12 ];
58                 switch( desc & 3 )
59                 {
60                 // 0: Unmapped
61                 case 0: 
62                         pi->Size = 12;
63                         return 1;
64                 // 1: Large Page (64KiB)
65                 case 1:
66                         pi->Size = 16;
67                         pi->PhysAddr = desc & 0xFFFF0000;
68                         return 0;
69                 // 2/3: Small page
70                 case 2:
71                 case 3:
72                         pi->Size = 12;
73                         pi->PhysAddr = desc & 0xFFFFF000;
74                         pi->bExecutable = desc & 1;
75                         pi->bGlobal = !(desc >> 11);
76                         pi->bSharec = (desc >> 10) & 1;
77                         return 1;
78                 }
79                 return 1;
80         
81         // 2: Section (or Supersection)
82         case 2:
83                 if( desc & (1 << 18) ) {
84                         // Supersection
85                         pi->PhysAddr = desc & 0xFF000000;
86                         pi->PhysAddr |= ((desc >> 20) & 0xF) << 32;
87                         pi->PhysAddr |= ((desc >> 5) & 0x7) << 36;
88                         pi->Size = 24;
89                         pi->Domain = 0; // Superpages default to zero
90                         return 0;
91                 }
92                 
93                 // Section
94                 pi->PhysAddr = desc & 0xFFF80000;
95                 pi->Size = 20;
96                 pi->Domain = (desc >> 5) & 7;
97                 return 0;
98
99         // 3: Reserved (invalid)
100         case 3:
101                 pi->PhysAddr = 0;
102                 pi->Size = 20;
103                 pi->Domain = 0;
104                 return 2;
105         }
106 }
107
108 // --- Exports ---
109 tPAddr MM_GetPhysAddr(tVAddr VAddr)
110 {
111         tMM_PageInfo    pi;
112         if( MM_int_GetPageInfo(VAddr, &pi) )
113                 return 0;
114         return pi.PhysAddr;
115 }

UCC git Repository :: git.ucc.asn.au