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.
sl@0
     1
// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32\memmodel\emul\win32\minit.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include "memmodel.h"
sl@0
    19
#include <emulator.h>
sl@0
    20
#include <property.h>
sl@0
    21
sl@0
    22
_LIT8(KKernelFullPathName,"EKern.exe");
sl@0
    23
_LIT8(KLitRamAlloc,"RamAlloc");
sl@0
    24
sl@0
    25
void M::Init1()
sl@0
    26
	{
sl@0
    27
	__KTRACE_OPT2(KBOOT,KMMU,Kern::Printf("M::Init1"));
sl@0
    28
	
sl@0
    29
	SAddressInfo ainfo;
sl@0
    30
	Emul::TheAsic->AddressInfo(ainfo);
sl@0
    31
sl@0
    32
	MM::RamChunkSize = KRamChunkSize;
sl@0
    33
	MM::RamChunkShift = KRamChunkShift;
sl@0
    34
	MM::RamPageSize = KRamPageSize;
sl@0
    35
	MM::RamPageShift = KRamPageShift;
sl@0
    36
	MM::FreeMemory = ainfo.iTotalRamSize;
sl@0
    37
	TheSuperPage().iTotalRamSize = ainfo.iTotalRamSize;
sl@0
    38
	K::MaxFreeRam = ainfo.iTotalRamSize;
sl@0
    39
	PP::RamDriveMaxSize = ainfo.iRamDriveMaxSize;
sl@0
    40
sl@0
    41
	K::SupervisorThreadStackSize=0x1000;	// 4K
sl@0
    42
sl@0
    43
	K::MachineConfig=(TMachineConfig*)A::MachineConfiguration().Ptr();
sl@0
    44
sl@0
    45
	K::MaxMemCopyInOneGo=KDefaultMaxMemCopyInOneGo;
sl@0
    46
	__KTRACE_OPT(KBOOT,Kern::Printf("K::MaxMemCopyInOneGo=0x%x",K::MaxMemCopyInOneGo));
sl@0
    47
sl@0
    48
	LPVOID kheap = VirtualAlloc(NULL, KKernelHeapSizeMax, MEM_RESERVE, PAGE_READWRITE);
sl@0
    49
	__ASSERT_ALWAYS(kheap, MM::Panic(MM::EKernelHeapReserveFailed));
sl@0
    50
	kheap = VirtualAlloc(kheap, KKernelHeapSizeMin, MEM_COMMIT, PAGE_READWRITE);
sl@0
    51
	__ASSERT_ALWAYS(kheap, MM::Panic(MM::EKernelHeapCommitFailed));
sl@0
    52
	MM::KernelHeapAddress = kheap;
sl@0
    53
	K::MemModelAttributes = (TUint32)(EMemModelTypeEmul|EMemModelAttrNonExProt|EMemModelAttrWriteProt|EMemModelAttrVA);
sl@0
    54
	
sl@0
    55
	MM::Init1();
sl@0
    56
	}
sl@0
    57
sl@0
    58
void M::Init2()
sl@0
    59
	{
sl@0
    60
	__KTRACE_OPT2(KBOOT,KMMU,Kern::Printf("M::Init2"));
sl@0
    61
	TInt r=K::MutexCreate((DMutex*&)MM::RamAllocatorMutex, KLitRamAlloc, NULL, EFalse, KMutexOrdRamAlloc);
sl@0
    62
	__ASSERT_ALWAYS(r==KErrNone, MM::Panic(MM::ERamAllocMutexCreateFailed));
sl@0
    63
	}
sl@0
    64
sl@0
    65
void M::Init3()
sl@0
    66
	{
sl@0
    67
	__KTRACE_OPT2(KBOOT,KMMU,Kern::Printf("M::Init3"));
sl@0
    68
	}
sl@0
    69
sl@0
    70
// kernel heap construction
sl@0
    71
sl@0
    72
void P::KernelInfo(TProcessCreateInfo& aInfo, TAny*& aStack, TAny*& aHeap)
sl@0
    73
	{
sl@0
    74
	memclr(&aInfo.iUids, sizeof(TProcessCreateInfo)-sizeof(aInfo.iFileName));
sl@0
    75
	aInfo.iFileName=KKernelFullPathName;
sl@0
    76
	aInfo.iRootNameOffset=0;
sl@0
    77
	aInfo.iRootNameLength=9;
sl@0
    78
	aInfo.iExtOffset=5;
sl@0
    79
	aInfo.iAttr=ECodeSegAttKernel|ECodeSegAttFixed;
sl@0
    80
sl@0
    81
	aStack=NULL;
sl@0
    82
	aHeap=(TAny*)MM::KernelHeapAddress;
sl@0
    83
sl@0
    84
#ifdef _UNICODE
sl@0
    85
	TUint16 nameW[KMaxFileName+1];
sl@0
    86
	int index;
sl@0
    87
	for(index=0;index<aInfo.iFileName.Length();index++)
sl@0
    88
		nameW[index] = (TUint16)aInfo.iFileName[index];
sl@0
    89
	nameW[index] = 0;
sl@0
    90
	Emulator::RImageFile pefile;
sl@0
    91
	TInt r = pefile.Open((LPCTSTR)nameW);
sl@0
    92
#else
sl@0
    93
	TFileName name=aInfo.iFileName;
sl@0
    94
	name.Append('\0');
sl@0
    95
	Emulator::RImageFile pefile;
sl@0
    96
	TInt r = pefile.Open((LPCTSTR)name.Ptr());
sl@0
    97
#endif
sl@0
    98
	if (r == KErrNone)
sl@0
    99
		{
sl@0
   100
		pefile.GetInfo(aInfo);
sl@0
   101
		pefile.Close();
sl@0
   102
		}
sl@0
   103
	__ASSERT_ALWAYS(r==KErrNone, FAULT());
sl@0
   104
	aInfo.iHeapSizeMin = KKernelHeapSizeMin;
sl@0
   105
	aInfo.iHeapSizeMax = KKernelHeapSizeMax;
sl@0
   106
	aInfo.iDataRunAddress = (TLinAddr)MM::KernelHeapAddress;
sl@0
   107
	aInfo.iStackSize = 0;
sl@0
   108
	}
sl@0
   109
sl@0
   110
TInt M::InitSvHeapChunk(DChunk* aChunk, TInt aSize)
sl@0
   111
	{
sl@0
   112
	DWin32Chunk* pC=(DWin32Chunk*)aChunk;
sl@0
   113
	aSize = MM::RoundToPageSize(aSize);
sl@0
   114
	pC->iSize = aSize;
sl@0
   115
	pC->iBase = (TUint8*)K::Allocator;
sl@0
   116
// mark the kernel heap pages as allocated
sl@0
   117
	MM::FreeMemory -= aSize;
sl@0
   118
	__KTRACE_OPT(KBOOT,Kern::Printf("Created SvHeap chunk, addr %08X, init size %08X max size %08X",pC->Base(),aSize,pC->MaxSize()));
sl@0
   119
	K::HeapInfo.iChunk = aChunk;
sl@0
   120
	K::HeapInfo.iBase = pC->iBase;
sl@0
   121
	K::HeapInfo.iMaxSize = pC->MaxSize();
sl@0
   122
	return KErrNone;
sl@0
   123
	}
sl@0
   124
sl@0
   125
void RHeapK::Mutate(TInt aOffset, TInt aMaxLength)
sl@0
   126
//
sl@0
   127
// Used by the kernel to mutate a fixed heap into a chunk heap.
sl@0
   128
//
sl@0
   129
	{
sl@0
   130
	iMinLength += aOffset;
sl@0
   131
	iMaxLength = aMaxLength + aOffset;
sl@0
   132
	iOffset = aOffset;
sl@0
   133
	iChunkHandle = (TInt)K::HeapInfo.iChunk;
sl@0
   134
	iPageSize = M::PageSizeInBytes();
sl@0
   135
	iGrowBy = iPageSize;
sl@0
   136
	iFlags &= ~(RAllocator::ESingleThreaded|RAllocator::EFixedSize);
sl@0
   137
	}
sl@0
   138
sl@0
   139
//
sl@0
   140
sl@0
   141
TInt M::InitSvStackChunk()
sl@0
   142
	{
sl@0
   143
	return KErrNone;
sl@0
   144
	}
sl@0
   145