os/kernelhwsrv/kernel/eka/memmodel/emul/win32/minit.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // e32\memmodel\emul\win32\minit.cpp
    15 // 
    16 //
    17 
    18 #include "memmodel.h"
    19 #include <emulator.h>
    20 #include <property.h>
    21 
    22 _LIT8(KKernelFullPathName,"EKern.exe");
    23 _LIT8(KLitRamAlloc,"RamAlloc");
    24 
    25 void M::Init1()
    26 	{
    27 	__KTRACE_OPT2(KBOOT,KMMU,Kern::Printf("M::Init1"));
    28 	
    29 	SAddressInfo ainfo;
    30 	Emul::TheAsic->AddressInfo(ainfo);
    31 
    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;
    40 
    41 	K::SupervisorThreadStackSize=0x1000;	// 4K
    42 
    43 	K::MachineConfig=(TMachineConfig*)A::MachineConfiguration().Ptr();
    44 
    45 	K::MaxMemCopyInOneGo=KDefaultMaxMemCopyInOneGo;
    46 	__KTRACE_OPT(KBOOT,Kern::Printf("K::MaxMemCopyInOneGo=0x%x",K::MaxMemCopyInOneGo));
    47 
    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);
    54 	
    55 	MM::Init1();
    56 	}
    57 
    58 void M::Init2()
    59 	{
    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));
    63 	}
    64 
    65 void M::Init3()
    66 	{
    67 	__KTRACE_OPT2(KBOOT,KMMU,Kern::Printf("M::Init3"));
    68 	}
    69 
    70 // kernel heap construction
    71 
    72 void P::KernelInfo(TProcessCreateInfo& aInfo, TAny*& aStack, TAny*& aHeap)
    73 	{
    74 	memclr(&aInfo.iUids, sizeof(TProcessCreateInfo)-sizeof(aInfo.iFileName));
    75 	aInfo.iFileName=KKernelFullPathName;
    76 	aInfo.iRootNameOffset=0;
    77 	aInfo.iRootNameLength=9;
    78 	aInfo.iExtOffset=5;
    79 	aInfo.iAttr=ECodeSegAttKernel|ECodeSegAttFixed;
    80 
    81 	aStack=NULL;
    82 	aHeap=(TAny*)MM::KernelHeapAddress;
    83 
    84 #ifdef _UNICODE
    85 	TUint16 nameW[KMaxFileName+1];
    86 	int index;
    87 	for(index=0;index<aInfo.iFileName.Length();index++)
    88 		nameW[index] = (TUint16)aInfo.iFileName[index];
    89 	nameW[index] = 0;
    90 	Emulator::RImageFile pefile;
    91 	TInt r = pefile.Open((LPCTSTR)nameW);
    92 #else
    93 	TFileName name=aInfo.iFileName;
    94 	name.Append('\0');
    95 	Emulator::RImageFile pefile;
    96 	TInt r = pefile.Open((LPCTSTR)name.Ptr());
    97 #endif
    98 	if (r == KErrNone)
    99 		{
   100 		pefile.GetInfo(aInfo);
   101 		pefile.Close();
   102 		}
   103 	__ASSERT_ALWAYS(r==KErrNone, FAULT());
   104 	aInfo.iHeapSizeMin = KKernelHeapSizeMin;
   105 	aInfo.iHeapSizeMax = KKernelHeapSizeMax;
   106 	aInfo.iDataRunAddress = (TLinAddr)MM::KernelHeapAddress;
   107 	aInfo.iStackSize = 0;
   108 	}
   109 
   110 TInt M::InitSvHeapChunk(DChunk* aChunk, TInt aSize)
   111 	{
   112 	DWin32Chunk* pC=(DWin32Chunk*)aChunk;
   113 	aSize = MM::RoundToPageSize(aSize);
   114 	pC->iSize = 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();
   122 	return KErrNone;
   123 	}
   124 
   125 void RHeapK::Mutate(TInt aOffset, TInt aMaxLength)
   126 //
   127 // Used by the kernel to mutate a fixed heap into a chunk heap.
   128 //
   129 	{
   130 	iMinLength += aOffset;
   131 	iMaxLength = aMaxLength + aOffset;
   132 	iOffset = aOffset;
   133 	iChunkHandle = (TInt)K::HeapInfo.iChunk;
   134 	iPageSize = M::PageSizeInBytes();
   135 	iGrowBy = iPageSize;
   136 	iFlags &= ~(RAllocator::ESingleThreaded|RAllocator::EFixedSize);
   137 	}
   138 
   139 //
   140 
   141 TInt M::InitSvStackChunk()
   142 	{
   143 	return KErrNone;
   144 	}
   145