|
1 // Copyright (c) 2007-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 "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 // For the Winscw Emulator only, selects between NGA and Non-NGA version of wsgraphicdrawer. |
|
15 // The default is the non-GCE based version. |
|
16 // To select the NGA version do one of: |
|
17 // 1. Add a line to the epoc.ini file in \epoc32\data like this: |
|
18 // symbian_graphics_use_gce ON |
|
19 // or |
|
20 // 2. Start epoc.exe with these parameters, (the "--" IS necessary): |
|
21 // -Dsymbian_graphics_use_gce=ON -- |
|
22 // or |
|
23 // 3. epoc.exe can be told to switch to a different initialisation file than epoc.ini, with the -M parameter. |
|
24 // Progress chaining to the real Wserv is logged in epocwind.out. |
|
25 // |
|
26 // |
|
27 |
|
28 |
|
29 |
|
30 #include <emulator.h> |
|
31 |
|
32 #include <e32svr.h> |
|
33 #include <u32hal.h> |
|
34 |
|
35 |
|
36 extern "C" { |
|
37 |
|
38 #include "wsgraphicdrawer_stubs.h" |
|
39 |
|
40 FARPROC vector[MAX_ORDINAL+1]; |
|
41 |
|
42 |
|
43 void Stop(char* aErrorMessage) |
|
44 { |
|
45 int err = GetLastError(); |
|
46 RDebug::Printf("%S, (last error = %i)", aErrorMessage, err); |
|
47 _asm int 3; |
|
48 } |
|
49 |
|
50 void fill_vector(HINSTANCE aDll) |
|
51 { |
|
52 int i; |
|
53 FARPROC address = NULL; |
|
54 for (i=1;i<=MAX_ORDINAL;i++) |
|
55 { |
|
56 address = GetProcAddress(aDll, (LPCSTR)i); |
|
57 if (address == NULL) |
|
58 { |
|
59 Stop("... has too few exported functions"); |
|
60 } |
|
61 vector[i] = address; |
|
62 } |
|
63 |
|
64 address = GetProcAddress(aDll, (LPCSTR)i); |
|
65 if (address != NULL) |
|
66 { |
|
67 Stop("... has too many exported functions"); |
|
68 } |
|
69 vector[0] = (FARPROC)1; // initialised |
|
70 } |
|
71 |
|
72 // redirects DLL calls to GCE or non-GCE implementation |
|
73 void init_vector() |
|
74 { |
|
75 // ask HAL which configuration to use |
|
76 TBool nga = EFalse; |
|
77 UserSvr::HalFunction(EHalGroupEmulator, EEmulatorHalBoolProperty, (TAny*)"symbian_graphics_use_gce", &nga); |
|
78 const char* library = nga ? "wsgraphicdrawer_nga.dll" : "wsgraphicdrawer_nonnga.dll"; |
|
79 |
|
80 RDebug::Printf("Redirecting wsgraphicdrawer.dll to \"%s\" ...\n", library); |
|
81 |
|
82 Emulator::Escape(); // prevent deadlock between EKA2 scheduler and MS kernel |
|
83 // try to load selected DLL |
|
84 HINSTANCE instance = LoadLibraryA(library); |
|
85 Emulator::Reenter(); |
|
86 |
|
87 if (instance == NULL) |
|
88 { |
|
89 Stop("... unable to load"); |
|
90 } |
|
91 else |
|
92 { |
|
93 fill_vector(instance); |
|
94 RDebug::Printf("... DLL loaded successfully"); |
|
95 } |
|
96 } |
|
97 |
|
98 __declspec(naked) void common_dispatch() |
|
99 { |
|
100 _asm cmp dword ptr vector,0 // initialised? |
|
101 _asm je do_init_vector |
|
102 call_though_vector: |
|
103 _asm jmp [vector+eax*4] |
|
104 |
|
105 do_init_vector: |
|
106 _asm push eax |
|
107 _asm push ecx |
|
108 _asm push edx |
|
109 _asm call init_vector |
|
110 _asm pop edx |
|
111 _asm pop ecx |
|
112 _asm pop eax |
|
113 _asm jmp call_though_vector |
|
114 } |
|
115 |
|
116 } |