Update contrib.
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\mmu\t_pages.cpp
19 #include <e32std_private.h>
24 LOCAL_D TUint Read(TUint anAddr)
26 return Shadow.Read(anAddr);
29 TCpu Cpu = ECpuUnknown;
34 const TUint KXPbitM = 0x800000;
36 LOCAL_C void ProcessCBTEX(TDes& aDes, TUint aCb, TUint aTex)
39 const TPtrC KTEXCB[9] = {_L("StOr"),_L("ShDv"),_L("WTRA"),_L("WBRA"),_L("NoCa"),_L("Resv"),_L("ImpD"),_L("WBWA"),_L("NSDv")};
40 const TPtrC KCacheP[4] = {_L("NoCa"),_L("WBWA"),_L("WTRA"),_L("WBRA")};
43 TUint texCB = aCb | ((aTex&7) << 2);
45 if ((texCB<9) && (CpuArc>5))
46 aDes.Append(KTEXCB[texCB]);
47 else if ((aTex&4) && (CpuArc>5))
49 aDes.Append(KCacheP[aTex&3]);
50 aDes.Append(TChar('/'));
51 aDes.Append(KCacheP[aCb]);
58 aDes.Append(TChar('1'));
60 aDes.Append(TChar('0'));
63 aDes.Append(TChar('1'));
65 aDes.Append(TChar('0'));
68 aDes.Append(TChar('1'));
70 aDes.Append(TChar('0'));
72 else if (CpuSpecial == 2)
75 aDes.Append(TChar('X'));
77 aDes.Append(TChar('_'));
79 aDes.Append(TChar('?'));
84 aDes.Append(TChar('C'));
86 aDes.Append(TChar('_'));
88 aDes.Append(TChar('B'));
90 aDes.Append(TChar('_'));
95 LOCAL_C void ProcessXNnGS(TDes& aDes, TUint anGS, TUint aXN)
97 if ((ControlReg & KXPbitM))
99 aDes.Append(TChar(' '));
101 aDes.Append(_L("XN "));
103 aDes.Append(_L("__ "));
106 aDes.Append(_L("nG "));
108 aDes.Append(_L("__ "));
111 aDes.Append(TChar('S'));
113 aDes.Append(TChar('_'));
119 LOCAL_C void ProcessAP(TDes& aDes, TUint aAp)
121 const TPtrC KAccessP[7] = {_L(" RWNO"),_L(" RWRO"),_L(" RWRW"),_L(" Rsv0"),_L(" RONO"),_L(" RORO"),_L(" Rsv1")};
122 const TPtrC KAccZrP[4] = {_L(" NONO"), _L(" RONO"), _L(" RORO"), _L(" Rsv2")};
124 TUint access = aAp & 3;
125 TUint apx = (aAp >> 3) & 4;
127 if (((ControlReg & 0x300) !=0) && apx)
129 aDes.Append(_L(" Rsv3"));
133 if ((ControlReg & KXPbitM))
137 aDes.Append(KAccZrP[(ControlReg >> 8) & 3]);
139 aDes.Append(KAccessP[access-1]);
143 LOCAL_C void ProcessPteSE(TUint aPte, TUint anAddr)
155 TUint phys=aPte & 0xffff0000;
156 TUint ap0=(aPte>>4)&3;
157 TUint ap1=(aPte>>6)&3;
158 TUint ap2=(aPte>>8)&3;
159 TUint ap3=(aPte>>10)&3;
160 TUint tex=(aPte>>12)&0xf;
161 ProcessCBTEX(buf,aPte&0xc,tex);
166 RDebug::Print(_L("\t%08x Lpage: phys=%08x, %S"),anAddr,phys,&buf);
172 TUint phys=aPte & 0xfffff000;
173 TUint ap0=(aPte>>4)&3;
174 TUint ap1=(aPte>>6)&3;
175 TUint ap2=(aPte>>8)&3;
176 TUint ap3=(aPte>>10)&3;
177 ProcessCBTEX(buf,aPte&0xc,0);
182 RDebug::Print(_L("\t%08x Spage: phys=%08x, %S"),anAddr,phys,&buf);
187 // extended small page
188 TUint phys=aPte & 0xfffff000;
189 TUint ap=(aPte>>4)&3;
190 TUint tex=(aPte>>6)&0xf;
191 ProcessCBTEX(buf,aPte&0xc,tex);
193 RDebug::Print(_L("\t%08x XSpage: phys=%08x, %S"),anAddr,phys,&buf);
200 LOCAL_C void ProcessPteSD(TUint aPte, TUint anAddr)
206 TUint ap=(aPte>>4)&23;
208 if (aPte&2) // XS-Page
210 // extended small page
211 TUint phys=aPte & 0xfffff000;
212 TUint tex=(aPte>>6)&0x7;
213 ProcessCBTEX(buf,aPte&0xc,tex);
215 ProcessXNnGS(buf, (aPte>>10)&3, aPte &1);
216 RDebug::Print(_L("\t%08x XSpage: phys=%08x, %S"),anAddr,phys,&buf);
222 TUint phys=aPte & 0xffff0000;
223 TUint tex=(aPte>>12)&0x7;
224 ProcessCBTEX(buf,aPte&0xc,tex);
226 ProcessXNnGS(buf, (aPte>>10)&3, (aPte >> 15) &1);
227 RDebug::Print(_L("\t%08x Lpage: phys=%08x, %S"),anAddr,phys,&buf);
230 }// Else "Fault" - Not Present
235 LOCAL_C void ProcessPde(TUint aPde, TUint anAddr)
244 RDebug::Print(_L(" Not Present\n"));
249 TUint ptphys=aPde & 0xfffffc00;
250 TUint domain=(aPde>>5)&15;
251 TUint P=(aPde&0x200);
252 TUint ptpgphys=ptphys & 0xfffff000;
256 for (i=0; i<256; i++)
258 if ((Read(PageTables+i*4)&0xfffff000)==ptpgphys)
261 ptlin=PageTables+(i<<12)+(ptphys & 0xc00);
263 RDebug::Print(_L("WARNING Multiple page tables found! alt = %08x\n"), PageTables+(i<<12)+(ptphys & 0xc00));
268 RDebug::Print(_L("%08x page table: phys=%08x, domain %2d, %s, page table lin=%08x"),anAddr,ptphys,domain,P?L"ECC":L"No ECC",ptlin);
269 for (i=0; i<256; i++)
271 TUint addr=anAddr+(i<<12);
272 TUint pte=Read(ptlin+i*4);
274 if (ControlReg & KXPbitM)
275 ProcessPteSD(pte,addr);
277 ProcessPteSE(pte,addr);
281 RDebug::Print(_L("%08x page table: phys=%08x, domain %2d, %s, page table not found"),anAddr,ptphys,domain,P?L"ECC":L"No ECC");
288 TUint phys=aPde & 0xfff00000;
289 TUint perm=(aPde>>10)&0x23;
290 TUint P=(aPde&0x200);
291 TUint domain=(aPde>>5)&15;
292 ProcessCBTEX(buf,aPde&0xc,(aPde>>12)&0xf); // tex is bigger on xscale, but bit is masked off later.
294 ProcessXNnGS(buf, (aPde>>16)&3, (aPde>>4)&1);
296 if ((ControlReg & KXPbitM) && (aPde & 0x40000))
298 domain = (domain << 4) | ((aPde >> 20) &15);
299 RDebug::Print(_L("%08x Supersectn: phys=%08x, base %4d, %s, %S"),anAddr,phys,domain,P?L"ECC":L"No ECC",&buf);
303 RDebug::Print(_L("%08x section : phys=%08x, domain %2d, %s, %S"),anAddr,phys,domain,P?L"ECC":L"No ECC",&buf);
309 RDebug::Print(_L("PDE for %08x invalid, value %08x"),anAddr,aPde);
314 const TInt KNotInInvalid = -2;
315 TInt StartInvalid=KNotInInvalid;
316 TInt StartInvalidBase=0;
317 TInt EndInvalidBase=0;
319 void DisplayNotPresent(TInt aCurrentPd)
322 if (StartInvalid!=KNotInInvalid) // Display any Invalid ranges.
324 if (StartInvalid == aCurrentPd)
325 RDebug::Print(_L("\nPage Directory 0x%x: Base=0x%x - Not Present.\n"), StartInvalid, StartInvalidBase);
327 RDebug::Print(_L("\nPage Directorys 0x%x-0x%x: Bases=0x%x-0x%x - Not Present.\n"), StartInvalid, aCurrentPd, StartInvalidBase, EndInvalidBase);
329 StartInvalid=KNotInInvalid;
333 void ProcessPd(TUint aPd)
340 TInt err = Shadow.GetPdInfo(aPd, pdSize, pdBase, offset);
344 DisplayNotPresent(aPd);
346 if (aPd==KGlobalPageDirectory)
347 RDebug::Print(_L("Global Page Directory: Base=0x%x, Entries=0x%x, Start index=0x%x\n"), pdBase, pdSize, offset);
349 RDebug::Print(_L("\nPage Directory 0x%x: Base=0x%x, Entries=0x%x %x\n"), aPd, pdBase, pdSize, offset);
354 for (i=0; i<pdSize; i++)
356 TUint addr=(i+offset)<<20;
357 TUint pde=Read(pdBase+i*4);
358 ProcessPde(pde,addr);
362 RDebug::Print(_L("Cannot display pde for this CPU"));
365 { // Dont list all invalid PDs - there are too many.
366 if (StartInvalid==KNotInInvalid)
368 StartInvalidBase = pdBase;
373 EndInvalidBase=pdBase;
379 GLDEF_C TInt E32Main()
386 TInt r=User::LoadLogicalDevice(_L("D_SHADOW"));
387 if ((r!=KErrNone) && (r!=KErrAlreadyExists))
388 User::Panic(_L("T_PAGES0"),r);
391 User::Panic(_L("T_PAGES1"),r);
393 Shadow.GetMemoryArchitecture(Cpu, ControlReg);
398 mmuId=Shadow.MmuId();
399 TUint implementor= (mmuId>>24);
401 if (implementor==0x44)
404 switch ((mmuId>>12)&15)
407 if ((mmuId>>4)==0x4156030)
409 else if ((mmuId>>8)==0x415606)
415 TUint arc = (mmuId >>16) &15;
419 if ((implementor==0x69) && (arc==4))
425 if ((implementor==0x69) && (arc==5))
436 case 1:RDebug::Print(_L("\nCPU = ARMv%d (StrongArm), ControlRegister = 0x%x "),CpuArc, ControlReg);
438 case 2:RDebug::Print(_L("\nCPU = ARMv%d (XScale), ControlRegister = 0x%x "),CpuArc, ControlReg);
442 RDebug::Print(_L("\nCPU = ARMv%d, ControlRegister = 0x%x "),CpuArc, ControlReg);
444 RDebug::Print(_L("\nCPU = ARM (#%d), ControlRegister = 0x%x "),CpuArc, ControlReg);
447 RDebug::Print(_L("(MMU=%d, Alignment Checking=%d, Write Buffer=%d, System Protection=%d, "),
448 ControlReg & 1,(ControlReg>>1)&1,(ControlReg>>3)&1, (ControlReg>>8)&1);
450 if (ControlReg & KXPbitM)
451 RDebug::Print(_L("ROM Protection=%d, Subpages Disabled, Exception Endian=%d)\n"), (ControlReg>>9)&1, (ControlReg>>25)&1);
453 RDebug::Print(_L("ROM Protection=%d, Subpages Enabled, Exception Endian=%d)\n"), (ControlReg>>9)&1, (ControlReg>>25)&1);
455 RDebug::Print(_L("MMU ID=%08X"),mmuId);
459 cacheType=Shadow.CacheType();
460 RDebug::Print(_L("CACHE TYPE=%08X"),cacheType);
466 RDebug::Print(_L("\nCPU = x86\n"));
470 RDebug::Print(_L("\nCPU = Unknown, Flags = 0x%x\n"), ControlReg);
475 TMemModel memModel = Shadow.GetMemModelInfo(PageTables, numPages);
479 case EMemModelMoving: RDebug::Print(_L("Moving Memory Model.\n"));
481 case EMemModelMultiple : RDebug::Print(_L("Multiple Memory Model.\nMax number of PageDirectorys=0x%x.\n"), numPages);
483 case EMemModelFlexible : RDebug::Print(_L("Flexible Memory Model.\nMax number of PageDirectorys=0x%x.\n"), numPages);
486 RDebug::Print(_L("Unknown Memory Model.\n"));
490 ProcessPd(KGlobalPageDirectory);
495 for (i=0; i<numPages; i++)
499 DisplayNotPresent(numPages);
502 User::FreeLogicalDevice(_L("Shadow"));