ReactOS  0.4.14-dev-323-g6fe6a88
mmu.h
Go to the documentation of this file.
1 #ifndef PPCMMU_H
2 #define PPCMMU_H
3 
4 #include <string.h>
5 
6 /* PPC MMU object --
7  * Always called from kernel mode, maps the first 16 megabytes and uses 16
8  * bytes per page between 0x30000 and 16 megs. Maximum memory size is 3 gig.
9  *
10  * Physical Memory Map:
11  * 0x00300 -- Data Miss
12  * 0x00400 -- Code Miss
13  * 0x10000 -- MMU ucode
14  * 0x20000 -- PTEG
15  * 0x30000 -- Full map
16  *
17  * Actions:
18  *
19  * 1** -- MMU Related
20  *
21  * 100 -- Initialize
22  * -- No arguments
23  * 101 -- Map page
24  * r4 -- virtual address
25  * r5 -- ppc_map_info_t
26  * 102 -- Erase page
27  * r4 -- virtual address
28  * 103 -- Set segment VSID
29  * r4 -- Start seg
30  * r5 -- End seg
31  * r6 -- Vsid
32  * 104 -- Set trap callback
33  * r4 -- Trap number
34  * r5 -- Callback address (VA)
35  * 105 -- Query page
36  * r4 -- Page addr
37  * r5 -- Address of info struct
38  * 106 -- Unit Test
39  * 107 -- Turn on paging
40  * 108 -- Unmap process
41  * 109 -- Get lowest unallocated page
42  * 10a -- Alloc vsid
43  * 10b -- Revoke vsid
44  * 10c -- Allocate a page and return it
45  * 10d -- Return from trap callback
46  * 10e -- Dump Map
47  *
48  * 2** -- Debug Stub and Interrupt Vectoring
49  *
50  * 200 -- GDB Initialize
51  * r4 -- Device type
52  * r4 -- Serial port addr
53  * 201 -- GDB Enter
54  * r4 -- Signal number
55  */
56 
57 #define MMUCODE 0x10000
58 #define HTABORG 0x20000
59 #define HTABSIZ 0x10000
60 #define PAGETAB 0x30000
61 
62 #define PpcHashedPTE ((ppc_pteg_t*)(HTABORG))
63 #define PpcPageTable ((ppc_map_t*)(PAGETAB))
64 
65 #define PPC_PAGE_ADDR(x) ((x) << 12)
66 #define PPC_PAGE_NUMBER(x) ((x) >> 12)
67 #define PPC_VSID_MASK 0xffffff
68 #define PPC_PAGE_MASK 0xfff
69 
70 #define MMU_NONE 0
71 #define MMU_KR 8
72 #define MMU_KW 4
73 #define MMU_UR 2
74 #define MMU_UW 1
75 #define MMU_ALL_R 10
76 #define MMU_KRW 12
77 #define MMU_KRW_UR 14
78 #define MMU_ALL_RW 15
79 
80 #define MMU_PAGE_ACCESS 0x40000000
81 #define MMU_PAGE_DIRTY 0x80000000
82 
83 #define MMU_KMASK 12
84 #define MMU_UMASK 3
85 
87 
88 /* thanks geist */
89 typedef unsigned long paddr_t;
90 typedef unsigned long vaddr_t;
91 
92 typedef struct _ppc_pte_t {
93  unsigned long pteh, ptel;
94 } ppc_pte_t;
95 
96 typedef struct _ppc_pteg_t {
98 } ppc_pteg_t;
99 
100 typedef struct _ppc_map_t {
102  unsigned long proc;
104 } ppc_map_t;
105 
106 typedef struct _ppc_map_info_t {
107  unsigned long flags, proc;
111 
112 typedef struct _ppc_trap_frame_t {
113  unsigned long gpr[32];
114  unsigned long long fpr[32];
115  unsigned long srr0, srr1, cr, lr, ctr, dsisr, dar, xer;
117 
118 typedef int (*MmuTrapHandler)(int trapid, ppc_trap_frame_t *trap);
119 
120 #include "mmuutil.h"
121 
122 static inline int PPCMMU(int action, void *arg1, void *arg2, void *arg3)
123 {
124  /* Set Bat0 to mmu object address */
125  int i, batu, batl, usebat[2] = { 0, 1 }, gotbat = 0, pc, mask;
126  volatile int ret;
127  int (*mmumain)(int action, void *arg1, void *arg2, void *arg3) = (void *)MMUCODE;
128  __asm__("bl 1f\n\t"
129  "\n1:\n\t"
130  "mflr %0\n\t" : "=r" (pc));
131 
132  for(i = 0, gotbat = 0; i < 4; i++)
133  {
134  /* Use the space above the trap handlers to store the old bats */
135  GetBat(i, 0, &batu, &batl);
136 
137  SetPhys(0xf000 + i * 16, batu);
138  SetPhys(0xf004 + i * 16, batl);
139 
140  GetBat(i, 1, &batu, &batl);
141 
142  SetPhys(0xf008 + i * 16, batu);
143  SetPhys(0xf00c + i * 16, batl);
144 
145  if (gotbat < 2)
146  {
147  if(batu & 0xffc)
148  {
149  mask = ~(0x1ffff | ((batu & 0xffc)>>2)<<17);
150  if(!(batu & 2) || ((batu & mask) != (pc & mask)))
151  usebat[gotbat++] = i;
152  } else {
153  mask = ~(0x1ffff | (batl << 17));
154  if(!(batl & 0x40) || ((batu & mask) != (pc & mask)))
155  usebat[gotbat++] = i;
156  }
157  }
158  }
159 
160  batu = 0xff;
161  batl = 0x7f;
162  SetBat(usebat[0], 0, batu, batl);
163  SetBat(usebat[0], 1, batu, batl);
164  batu += 8192 * 1024;
165  batl += 8192 * 1024;
166  SetBat(usebat[1], 0, batu, batl);
167  SetBat(usebat[1], 1, batu, batl);
168 
169  ret = mmumain(action, arg1, arg2, arg3);
170 
171  return ret;
172 }
173 
174 /* Expand this only if used ... That makes dependence on libmmu_code.a depend
175  * on whether MmuInit is called in a clean way.
176  */
177 #define MmuInit() _MmuInit(&_binary_mmucode_start, &_binary_mmucode_end)
178 
179 /* Copy in the mmu code and call init
180  * This bootstrap should only be called the first time (i.e. in the bootloader
181  * or the early boot code). Part of the purpose of this library is to
182  * eliminate the need to do a complex mmu handoff between boot stages.
183  */
184 static inline void _MmuInit(void *_start, void *_end)
185 {
186  int target = MMUCODE, copy;
187  int *start = (int *)_start;
188  while(start < (int *)_end)
189  {
190  memcpy(&copy, start++, sizeof(int));
191  SetPhys(target, copy);
192  target += sizeof(int);
193  }
194  PPCMMU(0x100, 0, 0, 0);
195 }
196 
197 static inline int MmuMapPage(ppc_map_info_t *info, int count)
198 {
199  return PPCMMU(0x101, info, (void *)count, 0);
200 }
201 
202 static inline void MmuUnmapPage(ppc_map_info_t *info, int count)
203 {
204  PPCMMU(0x102, info, (void *)count, 0);
205 }
206 
207 static inline void MmuSetVsid(int start, int end, int vsid)
208 {
209  PPCMMU(0x103, (void *)start, (void *)end, (void *)vsid);
210 }
211 
213 {
214  return (MmuTrapHandler)PPCMMU(0x104, (void *)trap, (void *)cb, 0);
215 }
216 
217 static inline void MmuInqPage(ppc_map_info_t *info, int count)
218 {
219  PPCMMU(0x105, info, (void *)count, 0);
220 }
221 
222 static inline int MmuUnitTest()
223 {
224  return PPCMMU(0x106, 0, 0, 0);
225 }
226 
227 static inline int MmuTurnOn(void *fun, void *arg)
228 {
229  return PPCMMU(0x107, fun, arg, 0);
230 }
231 
232 static inline void MmuSetMemorySize(paddr_t size)
233 {
234  PPCMMU(0x108, (void *)size, 0, 0);
235 }
236 
237 static inline paddr_t MmuGetFirstPage()
238 {
239  return (paddr_t)PPCMMU(0x109, 0, 0, 0);
240 }
241 
242 static inline void *MmuAllocVsid(int vsid, int mask)
243 {
244  return (void *)PPCMMU(0x10a, (void *)vsid, (void *)mask, 0);
245 }
246 
247 static inline void MmuRevokeVsid(int vsid, int mask)
248 {
249  PPCMMU(0x10b, (void *)vsid, (void *)mask, 0);
250 }
251 
252 static inline paddr_t MmuGetPage()
253 {
254  return PPCMMU(0x10c, 0,0,0);
255 }
256 
257 static inline void MmuCallbackRet()
258 {
259  PPCMMU(0x10d, 0,0,0);
260 }
261 
262 static inline void MmuDumpMap()
263 {
264  PPCMMU(0x10e, 0,0,0);
265 }
266 
267 static inline void MmuDbgInit(int deviceType, int devicePort)
268 {
269  PPCMMU(0x200, (void *)deviceType, (void *)devicePort, 0);
270 }
271 
272 static inline void MmuDbgEnter(int signal)
273 {
274  PPCMMU(0x201, (void *)signal, 0, 0);
275 }
276 
277 #endif/*PPCMMU_H*/
unsigned long cr
Definition: mmu.h:115
static void MmuCallbackRet()
Definition: mmu.h:257
struct _ppc_pte_t ppc_pte_t
unsigned long proc
Definition: mmu.h:107
static int MmuUnitTest()
Definition: mmu.h:222
Definition: mmu.h:92
static void MmuDbgInit(int deviceType, int devicePort)
Definition: mmu.h:267
vaddr_t addr
Definition: mmu.h:108
ppc_pte_t pte
Definition: mmu.h:101
char _binary_mmucode_start[]
unsigned long proc
Definition: mmu.h:102
GLuint GLuint GLsizei count
Definition: gl.h:1545
unsigned long flags
Definition: mmu.h:107
unsigned long srr1
Definition: mmu.h:115
int _start[]
static void _MmuInit(void *_start, void *_end)
Definition: mmu.h:184
static void MmuRevokeVsid(int vsid, int mask)
Definition: mmu.h:247
unsigned long long fpr[32]
Definition: mmu.h:114
GLuint GLuint end
Definition: gl.h:1545
int(* MmuTrapHandler)(int trapid, ppc_trap_frame_t *trap)
Definition: mmu.h:118
unsigned long paddr_t
Definition: mmu.h:89
void SetBat(int bat, int inst, int batHi, int batLo)
Definition: mmu.c:236
GLuint GLuint GLuint GLuint GLuint GLuint GLuint arg2
Definition: glext.h:9514
static MmuTrapHandler MmuSetTrapHandler(int trap, MmuTrapHandler cb)
Definition: mmu.h:212
char _binary_mmucode_end[]
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLenum GLint GLuint mask
Definition: glext.h:6028
unsigned long dsisr
Definition: mmu.h:115
__asm__("\t.globl GetPhys\n" "GetPhys:\t\n" "mflr 0\n\t" "stwu 0,-16(1)\n\t" "mfmsr 5\n\t" "andi. 6,5,0xffef\n\t" "mtmsr 6\n\t" "isync\n\t" "sync\n\t" "lwz 3,0(3)\n\t" "mtmsr 5\n\t" "isync\n\t" "sync\n\t" "lwz 0,0(1)\n\t" "addi 1,1,16\n\t" "mtlr 0\n\t" "blr")
GLuint GLuint GLuint GLuint arg1
Definition: glext.h:9513
unsigned long vaddr_t
Definition: mmu.h:90
struct _ppc_map_info_t ppc_map_info_t
struct _ppc_trap_frame_t ppc_trap_frame_t
vaddr_t addr
Definition: mmu.h:103
static void MmuSetMemorySize(paddr_t size)
Definition: mmu.h:232
void GetBat(int bat, int inst, int *batHi, int *batLo)
Definition: mmu.c:191
static void MmuUnmapPage(ppc_map_info_t *info, int count)
Definition: mmu.h:202
unsigned long dar
Definition: mmu.h:115
unsigned long srr0
Definition: mmu.h:115
GLuint GLuint GLuint GLuint GLuint GLuint GLuint GLuint GLuint GLuint arg3
Definition: glext.h:9515
unsigned long xer
Definition: mmu.h:115
int _end[]
GLsizeiptr size
Definition: glext.h:5919
static int PPCMMU(int action, void *arg1, void *arg2, void *arg3)
Definition: mmu.h:122
static void * MmuAllocVsid(int vsid, int mask)
Definition: mmu.h:242
unsigned long lr
Definition: mmu.h:115
unsigned long pteh
Definition: mmu.h:93
struct _ppc_pteg_t ppc_pteg_t
int ret
int signal
Definition: xcptfil.c:12
unsigned long ptel
Definition: mmu.h:93
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
struct _ppc_map_t ppc_map_t
unsigned long ctr
Definition: mmu.h:115
static int MmuMapPage(ppc_map_info_t *info, int count)
Definition: mmu.h:197
static void MmuInqPage(ppc_map_info_t *info, int count)
Definition: mmu.h:217
const WCHAR * action
Definition: action.c:7783
unsigned long gpr[32]
Definition: mmu.h:113
GLuint start
Definition: gl.h:1545
INT copy(TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], INT append, DWORD lpdwFlags, BOOL bTouch)
Definition: copy.c:51
#define MMUCODE
Definition: mmu.h:57
static HMODULE MODULEINFO DWORD cb
Definition: module.c:32
static int MmuTurnOn(void *fun, void *arg)
Definition: mmu.h:227
static paddr_t MmuGetPage()
Definition: mmu.h:252
static void MmuSetVsid(int start, int end, int vsid)
Definition: mmu.h:207
static void MmuDumpMap()
Definition: mmu.h:262
GLenum target
Definition: glext.h:7315
paddr_t phys
Definition: mmu.h:109
static void MmuDbgEnter(int signal)
Definition: mmu.h:272
ppc_pte_t block[8]
Definition: mmu.h:97
void SetPhys(ULONG Addr, ULONG Data)
static paddr_t MmuGetFirstPage()
Definition: mmu.h:237
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31