os/kernelhwsrv/kernel/eka/memmodel/emul/win32/zrom.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 1998-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\zrom.cpp
    15 // Emulator implementation of the ROM related parts of the system
    16 // 
    17 //
    18 
    19 #include "plat_priv.h"
    20 #include <property.h>
    21 #include <emulator.h>
    22 #include "memmodel.h"
    23 
    24 const char* KVariantDllName="ecust.dll";
    25 
    26 TInt P::DefaultInitialTime()
    27 	{
    28 //
    29 // Not used on emulator
    30 //
    31 	return KErrGeneral;
    32 	}
    33 
    34 TInt P::InitSystemTime()
    35 	{
    36 //
    37 //  Initialise system time
    38 //	Return the initial time in seconds from 00:00:00 01-01-2000
    39 //
    40 	TUint dummy;
    41 	K::SetSystemTimeAndOffset(0, 0, 0, dummy, ETimeSetOffset|ETimeSetNoTimeUpdate);
    42 
    43 	__KTRACE_OPT(KBOOT,Kern::Printf("Use Host time to set system time"));
    44     TInt seconds;
    45 	A::SystemTimeInSecondsFrom2000(seconds);
    46 	return seconds;
    47 	}
    48 
    49 
    50 void P::CreateVariant()
    51 	{
    52 	__KTRACE_OPT(KBOOT,Kern::Printf("CreateVariant"));
    53 	HINSTANCE var = LoadLibraryA(KVariantDllName);
    54 	if (var)
    55 		{
    56 		TLibraryEntry entryPoint=(TLibraryEntry)Emulator::GetProcAddress(var, "_E32Dll");
    57 		if (entryPoint)
    58 			{
    59 			__KTRACE_OPT(KBOOT,Kern::Printf("Found variant"));
    60 			// Call the entry point (global constructors)
    61 			__KTRACE_OPT(KBOOT,Kern::Printf("Calling entrypoint %08x",entryPoint));
    62 			TInt r=entryPoint(KModuleEntryReasonVariantInit0);
    63 			__KTRACE_OPT(KBOOT,Kern::Printf("Entrypoint returned %d",r));
    64 			if (r<0)
    65 				Kern::Fault("VariantEntry",r);
    66 
    67 			// Initialise and create the variant object
    68 			r=A::CreateVariant(var, r);
    69 			if (r<0)
    70 				Kern::Fault("VariantInit",r);
    71 			__KTRACE_OPT(KBOOT,Kern::Printf("Variant installed"));
    72 
    73 			BTrace::Init0(); // we have to do this after variant has initialised the SuperPage
    74 			return;
    75 			}
    76 		}
    77 	Kern::Fault("NoVariant",0);
    78 	}
    79 
    80 
    81 TInt StartExtension(const char* aExtension)
    82 	{
    83 	HINSTANCE ext;
    84  	HMODULE mh;
    85  	if (*aExtension == '?')
    86  		{
    87  		ext = LoadLibraryA(++aExtension);
    88  		if (!ext)
    89  			{
    90  			__KTRACE_OPT(KBOOT, Kern::Printf("Optional extension \"%s\" not found", aExtension));
    91  			return KErrNone;
    92  			}
    93  		}
    94  	else
    95  		{
    96  		ext = LoadLibraryA(aExtension);
    97  		if (!ext)
    98  			return KErrNotFound;
    99  		}		
   100  	mh = GetModuleHandleA(aExtension);	
   101 	TLibraryEntry entryPoint=(TLibraryEntry)Emulator::GetProcAddress(ext, "_E32Dll");
   102 	if (!entryPoint)
   103 		return KErrArgument;
   104 	TInt r=entryPoint(KModuleEntryReasonExtensionInit0);
   105 	if (r!=KErrNone)
   106 		{
   107 		__KTRACE_OPT(KBOOT,Kern::Printf("Extension %s already started", aExtension));
   108 		return KErrNone;
   109 		}
   110 	DCodeSeg::Wait();
   111 	r=MM::RegisterModule(mh);
   112 	DCodeSeg::Signal();
   113 	if (r!=KErrNone)
   114 		return r;
   115 	__KTRACE_OPT(KBOOT,Kern::Printf("Calling entrypoint of %s extension ", aExtension));
   116 	return entryPoint(KModuleEntryReasonExtensionInit1);
   117 	}
   118 
   119 
   120 void P::StartExtensions()
   121 	{
   122 	HMODULE mh = GetModuleHandleA(KVariantDllName);
   123 	TInt r = MM::RegisterModule(mh);
   124 	const char* extension = NULL;
   125 	if (r==KErrNone)
   126 		extension = Property::GetString("Extension");
   127 	if (extension)
   128 		{
   129 		for (;;)
   130 			{
   131 			char name[128];
   132 			const char* end = strchr(extension, ';');
   133 			if (!end)
   134 				break;
   135 			strncpy(name, extension, end-extension);
   136 			name[end-extension] = '\0';
   137 			if (strchr(name, '.') == NULL)
   138 				strcat(name, ".dll");
   139 			r = StartExtension(name);
   140 			if (r != KErrNone)
   141 				break;
   142 			extension = end+1;
   143 			}
   144 		if (r==KErrNone)
   145 			r = StartExtension(extension);
   146 		}
   147 	if (r != KErrNone)
   148 		K::Fault(K::EStartExtensionsFailed);
   149 	}