Update contrib.
1 // Copyright (c) 1996-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 // e32\memmodel\emul\win32\minit.cpp
22 _LIT8(KKernelFullPathName,"EKern.exe");
23 _LIT8(KLitRamAlloc,"RamAlloc");
27 __KTRACE_OPT2(KBOOT,KMMU,Kern::Printf("M::Init1"));
30 Emul::TheAsic->AddressInfo(ainfo);
32 MM::RamChunkSize = KRamChunkSize;
33 MM::RamChunkShift = KRamChunkShift;
34 MM::RamPageSize = KRamPageSize;
35 MM::RamPageShift = KRamPageShift;
36 MM::FreeMemory = ainfo.iTotalRamSize;
37 TheSuperPage().iTotalRamSize = ainfo.iTotalRamSize;
38 K::MaxFreeRam = ainfo.iTotalRamSize;
39 PP::RamDriveMaxSize = ainfo.iRamDriveMaxSize;
41 K::SupervisorThreadStackSize=0x1000; // 4K
43 K::MachineConfig=(TMachineConfig*)A::MachineConfiguration().Ptr();
45 K::MaxMemCopyInOneGo=KDefaultMaxMemCopyInOneGo;
46 __KTRACE_OPT(KBOOT,Kern::Printf("K::MaxMemCopyInOneGo=0x%x",K::MaxMemCopyInOneGo));
48 LPVOID kheap = VirtualAlloc(NULL, KKernelHeapSizeMax, MEM_RESERVE, PAGE_READWRITE);
49 __ASSERT_ALWAYS(kheap, MM::Panic(MM::EKernelHeapReserveFailed));
50 kheap = VirtualAlloc(kheap, KKernelHeapSizeMin, MEM_COMMIT, PAGE_READWRITE);
51 __ASSERT_ALWAYS(kheap, MM::Panic(MM::EKernelHeapCommitFailed));
52 MM::KernelHeapAddress = kheap;
53 K::MemModelAttributes = (TUint32)(EMemModelTypeEmul|EMemModelAttrNonExProt|EMemModelAttrWriteProt|EMemModelAttrVA);
60 __KTRACE_OPT2(KBOOT,KMMU,Kern::Printf("M::Init2"));
61 TInt r=K::MutexCreate((DMutex*&)MM::RamAllocatorMutex, KLitRamAlloc, NULL, EFalse, KMutexOrdRamAlloc);
62 __ASSERT_ALWAYS(r==KErrNone, MM::Panic(MM::ERamAllocMutexCreateFailed));
67 __KTRACE_OPT2(KBOOT,KMMU,Kern::Printf("M::Init3"));
70 // kernel heap construction
72 void P::KernelInfo(TProcessCreateInfo& aInfo, TAny*& aStack, TAny*& aHeap)
74 memclr(&aInfo.iUids, sizeof(TProcessCreateInfo)-sizeof(aInfo.iFileName));
75 aInfo.iFileName=KKernelFullPathName;
76 aInfo.iRootNameOffset=0;
77 aInfo.iRootNameLength=9;
79 aInfo.iAttr=ECodeSegAttKernel|ECodeSegAttFixed;
82 aHeap=(TAny*)MM::KernelHeapAddress;
85 TUint16 nameW[KMaxFileName+1];
87 for(index=0;index<aInfo.iFileName.Length();index++)
88 nameW[index] = (TUint16)aInfo.iFileName[index];
90 Emulator::RImageFile pefile;
91 TInt r = pefile.Open((LPCTSTR)nameW);
93 TFileName name=aInfo.iFileName;
95 Emulator::RImageFile pefile;
96 TInt r = pefile.Open((LPCTSTR)name.Ptr());
100 pefile.GetInfo(aInfo);
103 __ASSERT_ALWAYS(r==KErrNone, FAULT());
104 aInfo.iHeapSizeMin = KKernelHeapSizeMin;
105 aInfo.iHeapSizeMax = KKernelHeapSizeMax;
106 aInfo.iDataRunAddress = (TLinAddr)MM::KernelHeapAddress;
107 aInfo.iStackSize = 0;
110 TInt M::InitSvHeapChunk(DChunk* aChunk, TInt aSize)
112 DWin32Chunk* pC=(DWin32Chunk*)aChunk;
113 aSize = MM::RoundToPageSize(aSize);
115 pC->iBase = (TUint8*)K::Allocator;
116 // mark the kernel heap pages as allocated
117 MM::FreeMemory -= aSize;
118 __KTRACE_OPT(KBOOT,Kern::Printf("Created SvHeap chunk, addr %08X, init size %08X max size %08X",pC->Base(),aSize,pC->MaxSize()));
119 K::HeapInfo.iChunk = aChunk;
120 K::HeapInfo.iBase = pC->iBase;
121 K::HeapInfo.iMaxSize = pC->MaxSize();
125 void RHeapK::Mutate(TInt aOffset, TInt aMaxLength)
127 // Used by the kernel to mutate a fixed heap into a chunk heap.
130 iMinLength += aOffset;
131 iMaxLength = aMaxLength + aOffset;
133 iChunkHandle = (TInt)K::HeapInfo.iChunk;
134 iPageSize = M::PageSizeInBytes();
136 iFlags &= ~(RAllocator::ESingleThreaded|RAllocator::EFixedSize);
141 TInt M::InitSvStackChunk()