ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

mmu.h
Go to the documentation of this file.
00001 #ifndef PPCMMU_H
00002 #define PPCMMU_H
00003 
00004 #include <string.h>
00005 
00006 /* PPC MMU object --
00007  * Always called from kernel mode, maps the first 16 megabytes and uses 16
00008  * bytes per page between 0x30000 and 16 megs.  Maximum memory size is 3 gig.
00009  *
00010  * Physical Memory Map:
00011  * 0x00300 -- Data Miss
00012  * 0x00400 -- Code Miss
00013  * 0x10000 -- MMU ucode
00014  * 0x20000 -- PTEG
00015  * 0x30000 -- Full map
00016  *
00017  * Actions:
00018  *
00019  * 1** -- MMU Related
00020  *
00021  * 100 -- Initialize
00022  *  -- No arguments
00023  * 101 -- Map page
00024  *  r4 -- virtual address
00025  *  r5 -- ppc_map_info_t
00026  * 102 -- Erase page
00027  *  r4 -- virtual address
00028  * 103 -- Set segment VSID
00029  *  r4 -- Start seg
00030  *  r5 -- End seg
00031  *  r6 -- Vsid
00032  * 104 -- Set trap callback
00033  *  r4 -- Trap number
00034  *  r5 -- Callback address (VA)
00035  * 105 -- Query page
00036  *  r4 -- Page addr
00037  *  r5 -- Address of info struct
00038  * 106 -- Unit Test
00039  * 107 -- Turn on paging
00040  * 108 -- Unmap process
00041  * 109 -- Get lowest unallocated page
00042  * 10a -- Alloc vsid
00043  * 10b -- Revoke vsid
00044  * 10c -- Allocate a page and return it
00045  * 10d -- Return from trap callback
00046  * 10e -- Dump Map
00047  *
00048  * 2** -- Debug Stub and Interrupt Vectoring
00049  *
00050  * 200 -- GDB Initialize
00051  *  r4 -- Device type
00052  *  r4 -- Serial port addr
00053  * 201 -- GDB Enter
00054  *  r4 -- Signal number
00055  */
00056 
00057 #define MMUCODE 0x10000
00058 #define HTABORG 0x20000
00059 #define HTABSIZ 0x10000
00060 #define PAGETAB 0x30000
00061 
00062 #define PpcHashedPTE ((ppc_pteg_t*)(HTABORG))
00063 #define PpcPageTable ((ppc_map_t*)(PAGETAB))
00064 
00065 #define PPC_PAGE_ADDR(x) ((x) << 12)
00066 #define PPC_PAGE_NUMBER(x) ((x) >> 12)
00067 #define PPC_VSID_MASK 0xffffff
00068 #define PPC_PAGE_MASK 0xfff
00069 
00070 #define MMU_NONE   0
00071 #define MMU_KR     8
00072 #define MMU_KW     4
00073 #define MMU_UR     2
00074 #define MMU_UW     1
00075 #define MMU_ALL_R  10
00076 #define MMU_KRW    12
00077 #define MMU_KRW_UR 14
00078 #define MMU_ALL_RW 15
00079 
00080 #define MMU_PAGE_ACCESS 0x40000000
00081 #define MMU_PAGE_DIRTY  0x80000000
00082 
00083 #define MMU_KMASK  12
00084 #define MMU_UMASK   3
00085 
00086 extern char _binary_mmucode_start[], _binary_mmucode_end[];
00087 
00088 /* thanks geist */
00089 typedef unsigned long paddr_t;
00090 typedef unsigned long vaddr_t;
00091 
00092 typedef struct _ppc_pte_t {
00093     unsigned long pteh, ptel;
00094 } ppc_pte_t;
00095 
00096 typedef struct _ppc_pteg_t {
00097     ppc_pte_t block[8];
00098 } ppc_pteg_t;
00099 
00100 typedef struct _ppc_map_t {
00101     ppc_pte_t pte;
00102     unsigned long proc;
00103     vaddr_t addr;
00104 } ppc_map_t;
00105 
00106 typedef struct _ppc_map_info_t {
00107     unsigned long flags, proc;
00108     vaddr_t addr;
00109     paddr_t phys;
00110 } ppc_map_info_t;
00111 
00112 typedef struct _ppc_trap_frame_t {
00113     unsigned long gpr[32];
00114     unsigned long long fpr[32];
00115     unsigned long srr0, srr1, cr, lr, ctr, dsisr, dar, xer;
00116 } ppc_trap_frame_t;
00117 
00118 typedef int (*MmuTrapHandler)(int trapid, ppc_trap_frame_t *trap);
00119 
00120 #include "mmuutil.h"
00121 
00122 static inline int PPCMMU(int action, void *arg1, void *arg2, void *arg3)
00123 {
00124     /* Set Bat0 to mmu object address */
00125     int i, batu, batl, usebat[2] = { 0, 1 }, gotbat = 0, pc, mask;
00126     volatile int ret;
00127     int (*mmumain)(int action, void *arg1, void *arg2, void *arg3) = (void *)MMUCODE;
00128     __asm__("bl 1f\n\t"
00129         "\n1:\n\t"
00130         "mflr %0\n\t" : "=r" (pc));
00131 
00132     for(i = 0, gotbat = 0; i < 4; i++)
00133     {
00134         /* Use the space above the trap handlers to store the old bats */
00135         GetBat(i, 0, &batu, &batl);
00136 
00137         SetPhys(0xf000 + i * 16, batu);
00138         SetPhys(0xf004 + i * 16, batl);
00139 
00140     GetBat(i, 1, &batu, &batl);
00141 
00142         SetPhys(0xf008 + i * 16, batu);
00143         SetPhys(0xf00c + i * 16, batl);
00144 
00145     if (gotbat < 2)
00146         {
00147             if(batu & 0xffc)
00148             {
00149                 mask = ~(0x1ffff | ((batu & 0xffc)>>2)<<17);
00150                 if(!(batu & 2) || ((batu & mask) != (pc & mask)))
00151                     usebat[gotbat++] = i;
00152             } else {
00153                 mask = ~(0x1ffff | (batl << 17));
00154                 if(!(batl & 0x40) || ((batu & mask) != (pc & mask)))
00155                     usebat[gotbat++] = i;
00156             }
00157         }
00158     }
00159 
00160     batu = 0xff;
00161     batl = 0x7f;
00162     SetBat(usebat[0], 0, batu, batl);
00163     SetBat(usebat[0], 1, batu, batl);
00164     batu += 8192 * 1024;
00165     batl += 8192 * 1024;
00166     SetBat(usebat[1], 0, batu, batl);
00167     SetBat(usebat[1], 1, batu, batl);
00168 
00169     ret = mmumain(action, arg1, arg2, arg3);
00170 
00171     return ret;
00172 }
00173 
00174 /* Expand this only if used ... That makes dependence on libmmu_code.a depend
00175  * on whether MmuInit is called in a clean way.
00176  */
00177 #define MmuInit() _MmuInit(&_binary_mmucode_start, &_binary_mmucode_end)
00178 
00179 /* Copy in the mmu code and call init
00180  * This bootstrap should only be called the first time (i.e. in the bootloader
00181  * or the early boot code).  Part of the purpose of this library is to
00182  * eliminate the need to do a complex mmu handoff between boot stages.
00183  */
00184 static inline void _MmuInit(void *_start, void *_end)
00185 {
00186     int target = MMUCODE, copy;
00187     int *start = (int *)_start;
00188     while(start < (int *)_end)
00189     {
00190         memcpy(&copy, start++, sizeof(int));
00191     SetPhys(target, copy);
00192     target += sizeof(int);
00193     }
00194     PPCMMU(0x100, 0, 0, 0);
00195 }
00196 
00197 static inline int MmuMapPage(ppc_map_info_t *info, int count)
00198 {
00199     return PPCMMU(0x101, info, (void *)count, 0);
00200 }
00201 
00202 static inline void MmuUnmapPage(ppc_map_info_t *info, int count)
00203 {
00204     PPCMMU(0x102, info, (void *)count, 0);
00205 }
00206 
00207 static inline void MmuSetVsid(int start, int end, int vsid)
00208 {
00209     PPCMMU(0x103, (void *)start, (void *)end, (void *)vsid);
00210 }
00211 
00212 static inline MmuTrapHandler MmuSetTrapHandler(int trap, MmuTrapHandler cb)
00213 {
00214     return (MmuTrapHandler)PPCMMU(0x104, (void *)trap, (void *)cb, 0);
00215 }
00216 
00217 static inline void MmuInqPage(ppc_map_info_t *info, int count)
00218 {
00219     PPCMMU(0x105, info, (void *)count, 0);
00220 }
00221 
00222 static inline int MmuUnitTest()
00223 {
00224     return PPCMMU(0x106, 0, 0, 0);
00225 }
00226 
00227 static inline int MmuTurnOn(void *fun, void *arg)
00228 {
00229     return PPCMMU(0x107, fun, arg, 0);
00230 }
00231 
00232 static inline void MmuSetMemorySize(paddr_t size)
00233 {
00234     PPCMMU(0x108, (void *)size, 0, 0);
00235 }
00236 
00237 static inline paddr_t MmuGetFirstPage()
00238 {
00239     return (paddr_t)PPCMMU(0x109, 0, 0, 0);
00240 }
00241 
00242 static inline void *MmuAllocVsid(int vsid, int mask)
00243 {
00244     return (void *)PPCMMU(0x10a, (void *)vsid, (void *)mask, 0);
00245 }
00246 
00247 static inline void MmuRevokeVsid(int vsid, int mask)
00248 {
00249     PPCMMU(0x10b, (void *)vsid, (void *)mask, 0);
00250 }
00251 
00252 static inline paddr_t MmuGetPage()
00253 {
00254     return PPCMMU(0x10c, 0,0,0);
00255 }
00256 
00257 static inline void MmuCallbackRet()
00258 {
00259     PPCMMU(0x10d, 0,0,0);
00260 }
00261 
00262 static inline void MmuDumpMap()
00263 {
00264     PPCMMU(0x10e, 0,0,0);
00265 }
00266 
00267 static inline void MmuDbgInit(int deviceType, int devicePort)
00268 {
00269     PPCMMU(0x200, (void *)deviceType, (void *)devicePort, 0);
00270 }
00271 
00272 static inline void MmuDbgEnter(int signal)
00273 {
00274     PPCMMU(0x201, (void *)signal, 0, 0);
00275 }
00276 
00277 #endif/*PPCMMU_H*/

Generated on Fri May 25 2012 04:31:45 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.