Update contrib.
1 // Copyright (c) 1995-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\epoc\direct\mcodeseg.cpp
19 #include <kernel/cache.h>
21 DCodeSeg* M::NewCodeSeg(TCodeSegCreateInfo&)
23 __KTRACE_OPT(KDLL,Kern::Printf("M::NewCodeSeg"));
24 return new DMemModelCodeSeg;
28 DEpocCodeSegMemory* DEpocCodeSegMemory::New(DEpocCodeSeg* aCodeSeg)
30 return new DMemModelCodeSegMemory(aCodeSeg);
34 DMemModelCodeSegMemory::DMemModelCodeSegMemory(DEpocCodeSeg* aCodeSeg)
35 : DEpocCodeSegMemory(aCodeSeg)
40 DMemModelCodeSeg::DMemModelCodeSeg()
45 DMemModelCodeSeg::~DMemModelCodeSeg()
50 __KTRACE_OPT(KDLL,Kern::Printf("DMemModelCodeSeg::Destruct %C", this));
53 SRamCodeInfo& ri=RamInfo();
56 TInt code_size=MM::RoundToBlockSize(ri.iCodeSize+ri.iDataSize);
57 MM::FreeRegion(ri.iCodeLoadAddr, code_size);
61 TInt data_size=MM::RoundToBlockSize(ri.iDataSize+ri.iBssSize);
62 MM::FreeRegion(iDataAlloc, data_size);
65 Kern::Free(iKernelData);
66 DEpocCodeSeg::Destruct();
69 TInt DMemModelCodeSeg::DoCreateRam(TCodeSegCreateInfo& aInfo, DProcess* aProcess)
71 __KTRACE_OPT(KDLL,Kern::Printf("DMemModelCodeSeg::DoCreateRam %C proc %O", this, aProcess));
72 DMemModelProcess* p=(DMemModelProcess*)aProcess;
73 TBool kernel=( (iAttr&(ECodeSegAttKernel|ECodeSegAttGlobal)) == ECodeSegAttKernel );
74 SRamCodeInfo& ri=RamInfo();
75 iSize = MM::RoundToBlockSize(ri.iCodeSize+ri.iDataSize);
76 TInt total_data_size=ri.iDataSize+ri.iBssSize;
77 TInt r=MM::AllocRegion(ri.iCodeLoadAddr, iSize);
80 ri.iCodeRunAddr=ri.iCodeLoadAddr;
82 ri.iDataLoadAddr=ri.iCodeLoadAddr+ri.iCodeSize;
87 iKernelData=Kern::Alloc(total_data_size);
90 ri.iDataRunAddr=(TLinAddr)iKernelData;
94 if (total_data_size && p)
96 if (total_data_size && !IsExe())
98 TInt data_alloc_size=MM::RoundToBlockSize(total_data_size);
99 TInt r=MM::AllocRegion(iDataAlloc, data_alloc_size);
102 ri.iDataRunAddr=iDataAlloc;
107 TInt DMemModelCodeSeg::DoCreateXIP(DProcess* aProcess)
109 __KTRACE_OPT(KDLL,Kern::Printf("DMemModelCodeSeg::DoCreateXIP %C proc %O", this, aProcess));
110 DMemModelProcess* p=(DMemModelProcess*)aProcess;
112 TBool kernel=( (iAttr&(ECodeSegAttKernel|ECodeSegAttGlobal)) == ECodeSegAttKernel );
113 const TRomImageHeader& rih=RomInfo();
114 if (!kernel && aProcess)
116 // XIP images with static data are specific to a single process
117 if (rih.iFlags&KRomImageFlagDataPresent)
123 TInt DMemModelCodeSeg::Loaded(TCodeSegCreateInfo& aInfo)
127 // Clean DCache for specified area, Invalidate ICache/BTB for specified area
128 TLinAddr code_base=RamInfo().iCodeRunAddr;
129 Cache::IMB_Range(code_base, RamInfo().iCodeSize);
131 return DEpocCodeSeg::Loaded(aInfo);
134 void DMemModelCodeSeg::ReadExportDir(TUint32* aDest)
136 __KTRACE_OPT(KDLL,Kern::Printf("DMemModelCodeSeg::ReadExportDir %08x",aDest));
139 SRamCodeInfo& ri=RamInfo();
140 TInt size=(ri.iExportDirCount+1)*sizeof(TLinAddr);
141 kumemput32(aDest, (const TUint32*)(ri.iExportDir-sizeof(TUint32)), size);
145 TBool DMemModelCodeSeg::OpenCheck(DProcess* aProcess)
147 return FindCheck(aProcess);
150 TBool DMemModelCodeSeg::FindCheck(DProcess* aProcess)
152 __KTRACE_OPT(KDLL,Kern::Printf("CSEG:%08x Compat? proc=%O",this,aProcess));
154 return !iAttachProcess; // can't reuse same code segment for a new instance of the process
155 DMemModelProcess& p=*(DMemModelProcess*)aProcess;
156 DCodeSeg* pPSeg=p.CodeSeg();
157 if (iAttachProcess && iAttachProcess!=aProcess)
159 if (iExeCodeSeg && iExeCodeSeg!=pPSeg)
161 __ASSERT_DEBUG( (iAttachProcess || !(iMark & EMarkDataPresent)), MM::Panic(MM::ECodeSegCheckInconsistent));