1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kernel/eka/memmodel/emul/win32/zrom.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,149 @@
1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32\memmodel\emul\win32\zrom.cpp
1.18 +// Emulator implementation of the ROM related parts of the system
1.19 +//
1.20 +//
1.21 +
1.22 +#include "plat_priv.h"
1.23 +#include <property.h>
1.24 +#include <emulator.h>
1.25 +#include "memmodel.h"
1.26 +
1.27 +const char* KVariantDllName="ecust.dll";
1.28 +
1.29 +TInt P::DefaultInitialTime()
1.30 + {
1.31 +//
1.32 +// Not used on emulator
1.33 +//
1.34 + return KErrGeneral;
1.35 + }
1.36 +
1.37 +TInt P::InitSystemTime()
1.38 + {
1.39 +//
1.40 +// Initialise system time
1.41 +// Return the initial time in seconds from 00:00:00 01-01-2000
1.42 +//
1.43 + TUint dummy;
1.44 + K::SetSystemTimeAndOffset(0, 0, 0, dummy, ETimeSetOffset|ETimeSetNoTimeUpdate);
1.45 +
1.46 + __KTRACE_OPT(KBOOT,Kern::Printf("Use Host time to set system time"));
1.47 + TInt seconds;
1.48 + A::SystemTimeInSecondsFrom2000(seconds);
1.49 + return seconds;
1.50 + }
1.51 +
1.52 +
1.53 +void P::CreateVariant()
1.54 + {
1.55 + __KTRACE_OPT(KBOOT,Kern::Printf("CreateVariant"));
1.56 + HINSTANCE var = LoadLibraryA(KVariantDllName);
1.57 + if (var)
1.58 + {
1.59 + TLibraryEntry entryPoint=(TLibraryEntry)Emulator::GetProcAddress(var, "_E32Dll");
1.60 + if (entryPoint)
1.61 + {
1.62 + __KTRACE_OPT(KBOOT,Kern::Printf("Found variant"));
1.63 + // Call the entry point (global constructors)
1.64 + __KTRACE_OPT(KBOOT,Kern::Printf("Calling entrypoint %08x",entryPoint));
1.65 + TInt r=entryPoint(KModuleEntryReasonVariantInit0);
1.66 + __KTRACE_OPT(KBOOT,Kern::Printf("Entrypoint returned %d",r));
1.67 + if (r<0)
1.68 + Kern::Fault("VariantEntry",r);
1.69 +
1.70 + // Initialise and create the variant object
1.71 + r=A::CreateVariant(var, r);
1.72 + if (r<0)
1.73 + Kern::Fault("VariantInit",r);
1.74 + __KTRACE_OPT(KBOOT,Kern::Printf("Variant installed"));
1.75 +
1.76 + BTrace::Init0(); // we have to do this after variant has initialised the SuperPage
1.77 + return;
1.78 + }
1.79 + }
1.80 + Kern::Fault("NoVariant",0);
1.81 + }
1.82 +
1.83 +
1.84 +TInt StartExtension(const char* aExtension)
1.85 + {
1.86 + HINSTANCE ext;
1.87 + HMODULE mh;
1.88 + if (*aExtension == '?')
1.89 + {
1.90 + ext = LoadLibraryA(++aExtension);
1.91 + if (!ext)
1.92 + {
1.93 + __KTRACE_OPT(KBOOT, Kern::Printf("Optional extension \"%s\" not found", aExtension));
1.94 + return KErrNone;
1.95 + }
1.96 + }
1.97 + else
1.98 + {
1.99 + ext = LoadLibraryA(aExtension);
1.100 + if (!ext)
1.101 + return KErrNotFound;
1.102 + }
1.103 + mh = GetModuleHandleA(aExtension);
1.104 + TLibraryEntry entryPoint=(TLibraryEntry)Emulator::GetProcAddress(ext, "_E32Dll");
1.105 + if (!entryPoint)
1.106 + return KErrArgument;
1.107 + TInt r=entryPoint(KModuleEntryReasonExtensionInit0);
1.108 + if (r!=KErrNone)
1.109 + {
1.110 + __KTRACE_OPT(KBOOT,Kern::Printf("Extension %s already started", aExtension));
1.111 + return KErrNone;
1.112 + }
1.113 + DCodeSeg::Wait();
1.114 + r=MM::RegisterModule(mh);
1.115 + DCodeSeg::Signal();
1.116 + if (r!=KErrNone)
1.117 + return r;
1.118 + __KTRACE_OPT(KBOOT,Kern::Printf("Calling entrypoint of %s extension ", aExtension));
1.119 + return entryPoint(KModuleEntryReasonExtensionInit1);
1.120 + }
1.121 +
1.122 +
1.123 +void P::StartExtensions()
1.124 + {
1.125 + HMODULE mh = GetModuleHandleA(KVariantDllName);
1.126 + TInt r = MM::RegisterModule(mh);
1.127 + const char* extension = NULL;
1.128 + if (r==KErrNone)
1.129 + extension = Property::GetString("Extension");
1.130 + if (extension)
1.131 + {
1.132 + for (;;)
1.133 + {
1.134 + char name[128];
1.135 + const char* end = strchr(extension, ';');
1.136 + if (!end)
1.137 + break;
1.138 + strncpy(name, extension, end-extension);
1.139 + name[end-extension] = '\0';
1.140 + if (strchr(name, '.') == NULL)
1.141 + strcat(name, ".dll");
1.142 + r = StartExtension(name);
1.143 + if (r != KErrNone)
1.144 + break;
1.145 + extension = end+1;
1.146 + }
1.147 + if (r==KErrNone)
1.148 + r = StartExtension(extension);
1.149 + }
1.150 + if (r != KErrNone)
1.151 + K::Fault(K::EStartExtensionsFailed);
1.152 + }