author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 04 Oct 2010 02:35:35 +0300 | |
changeset 281 | 13fbfa31d2ba |
parent 266 | 0008ccd16016 |
permissions | -rw-r--r-- |
266
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1 |
// Copyright (c) 2004-2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 2 |
// All rights reserved. |
3 |
// This component and the accompanying materials are made available |
|
4 |
// under the terms of the License "ARM EABI LICENCE.txt" |
|
5 |
// which accompanies this distribution, and is available |
|
6 |
// in kernel/eka/compsupp. |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// e32/compsupp/symaehabi/symbian_support.cpp |
|
266
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
15 |
// |
0 | 16 |
// |
17 |
||
18 |
/* Environment: */ |
|
19 |
#include "unwind_env.h" |
|
20 |
/* Language-independent unwinder declarations: */ |
|
21 |
#include "unwinder.h" |
|
22 |
||
23 |
/* Symbian specific support */ |
|
24 |
#include "symbian_support.h" |
|
25 |
||
26 |
#include <e32def.h> |
|
27 |
#include <e32def_private.h> |
|
28 |
#include <e32rom.h> |
|
29 |
#include <e32svr.h> |
|
30 |
#include <e32debug.h> |
|
31 |
||
32 |
static void __default_terminate_handler(void) |
|
33 |
{ |
|
34 |
abort(); |
|
35 |
} |
|
36 |
||
37 |
#define NAMES __ARM |
|
38 |
namespace NAMES { void default_unexpected_handler(void); } |
|
39 |
||
40 |
EXPORT_C TCppRTExceptionsGlobals::TCppRTExceptionsGlobals() |
|
41 |
{ |
|
42 |
buffer.inuse = false; |
|
266
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
43 |
buffer.em_buf2_p = NULL; |
0 | 44 |
thread_globals.uncaughtExceptions = 0; |
45 |
thread_globals.unexpectedHandler = NAMES::default_unexpected_handler; |
|
46 |
thread_globals.terminateHandler = __default_terminate_handler; |
|
47 |
thread_globals.implementation_ever_called_terminate = false; |
|
48 |
thread_globals.call_hook = NULL; |
|
49 |
thread_globals.caughtExceptions = NULL; |
|
50 |
thread_globals.propagatingExceptions = NULL; |
|
51 |
thread_globals.emergency_buffer = &buffer; |
|
52 |
Dll::SetTls(this); |
|
53 |
} |
|
266
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
54 |
|
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
55 |
EXPORT_C void TCppRTExceptionsGlobals::Init2ndEmergencyBuffer() |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
56 |
{ |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
57 |
ASSERT(buffer.em_buf2_p == NULL); |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
58 |
|
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
59 |
TEmergencyBuffer2* p = (TEmergencyBuffer2*) User::Alloc( sizeof(TEmergencyBuffer2) ); |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
60 |
if (!p) |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
61 |
abort(); |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
62 |
p->Init(); |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
63 |
buffer.em_buf2_p = p; |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
64 |
} |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
65 |
|
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
66 |
EXPORT_C void TCppRTExceptionsGlobals::Kill2ndEmergencyBuffer() |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
67 |
{ |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
68 |
ASSERT(buffer.em_buf2_p); |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
69 |
|
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
70 |
User::Free(buffer.em_buf2_p); |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
71 |
} |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
72 |
|
0 | 73 |
#if __ARMCC_VERSION < 220000 |
266
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
74 |
extern "C" |
0 | 75 |
{ |
76 |
/* |
|
77 |
we have to dummy up the following for 2.1. The names changed in the def file |
|
78 |
since in 2.2 catch handlers should be able to deal with imported RTTI |
|
79 |
||
80 |
_ZTI15XLeaveException @ 206 NONAME ; Typeinfo for XLeaveException |
|
81 |
_ZTV15XLeaveException @ 207 NONAME ; vtable for XLeaveException |
|
82 |
_ZN15XLeaveException16ForceKeyFunctionEv @ 208 NONAME ; the key function for XLeaveException |
|
83 |
*/ |
|
84 |
||
85 |
EXPORT_C void _ZTI15XLeaveException() |
|
86 |
{ |
|
87 |
// reserve a DEF file slot for key function |
|
88 |
} |
|
89 |
||
90 |
EXPORT_C void _ZTV15XLeaveException() |
|
91 |
{ |
|
92 |
// reserve a DEF file slot for vtable |
|
93 |
} |
|
94 |
||
95 |
EXPORT_C void _ZN15XLeaveException16ForceKeyFunctionEv() |
|
96 |
{ |
|
97 |
// reserve a DEF file slot for RTTI |
|
98 |
} |
|
99 |
} |
|
100 |
||
266
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
101 |
#else |
0 | 102 |
// This is the key function that forces the class impedimenta to be get exported in RVCT 2.2 and later. |
103 |
EXPORT_C void XLeaveException::ForceKeyFunction(){} |
|
104 |
#endif |
|
105 |
||
106 |
#if 0 |
|
107 |
#pragma push |
|
108 |
#pragma arm |
|
109 |
// If the strings were word aligned we could do something like this. |
|
110 |
// We could even do this if we checked the alignment of the strings. |
|
111 |
// Unfortunately the chances of them both being word aligned are |
|
112 |
// sufficiently slim (1/16) that the test for alignment will be carried out |
|
113 |
// most of time for no good purpose. |
|
114 |
static inline int typenameeq(const char* n1, const char* n2) |
|
115 |
{ |
|
116 |
if (n1 == n2) |
|
117 |
return 1; |
|
118 |
int* i1 = (int*)n1; |
|
119 |
int* i2 = (int*)n2; |
|
120 |
int w1=0; |
|
121 |
int w2=0; |
|
122 |
int x1, x2; |
|
123 |
for (int i = 0, w1=i1[i], w2=i2[i]; w1 == w2; i++, w1=i1[i], w2=i2[i]) |
|
124 |
{ |
|
125 |
// they're the same but they might contain the terminator |
|
126 |
if (!(w1 & 0xffffff00)) |
|
127 |
return 1; |
|
128 |
if (!(w1 & 0xffff00ff)) |
|
129 |
return 1; |
|
130 |
if (!(w1 & 0xff00ffff)) |
|
131 |
return 1; |
|
132 |
if (!(w1 & 0x00ffffff)) |
|
133 |
return 1; |
|
134 |
} |
|
135 |
// they're not the same but they might contain the terminator in the same place |
|
136 |
x1 = w1 & 0x000000ff; |
|
137 |
x2 = w2 & 0x000000ff; |
|
138 |
if (!x1 && !x2) |
|
139 |
return 1; |
|
140 |
if (x1 != x2) |
|
141 |
return 0; |
|
142 |
||
143 |
x1 = w1 & 0x0000ff00; |
|
144 |
x2 = w2 & 0x0000ff00; |
|
145 |
if (!x1 && !x2) |
|
146 |
return 1; |
|
147 |
if (x1 != x2) |
|
148 |
return 0; |
|
149 |
||
150 |
x1 = w1 & 0x00ff0000; |
|
151 |
x2 = w2 & 0x00ff0000; |
|
152 |
if (!x1 && !x2) |
|
153 |
return 1; |
|
154 |
if (x1 != x2) |
|
155 |
return 0; |
|
156 |
||
157 |
x1 = w1 & 0xff000000; |
|
158 |
x2 = w2 & 0xff000000; |
|
159 |
if (!x1 && !x2) |
|
160 |
return 1; |
|
161 |
if (x1 != x2) |
|
162 |
return 0; |
|
163 |
||
164 |
// just to keep the compiler quiet |
|
165 |
return 0; |
|
166 |
} |
|
167 |
#pragma pop |
|
168 |
#endif |
|
169 |
||
170 |
extern "C" { |
|
171 |
||
172 |
IMPORT_C void abort(); |
|
173 |
||
174 |
TRomExceptionSearchTable * GetROMExceptionSearchTable(void) |
|
175 |
{ |
|
176 |
return (TRomExceptionSearchTable *)((TRomHeader *)UserSvr::RomHeaderAddress())->iRomExceptionSearchTable; |
|
177 |
} |
|
178 |
||
179 |
TExceptionDescriptor* SearchEST(uint32_t addr, TRomExceptionSearchTable* aESTp) |
|
180 |
{ |
|
181 |
uint32_t l = 0; |
|
182 |
uint32_t nelems = aESTp->iNumEntries; |
|
183 |
uint32_t r = nelems; |
|
184 |
uint32_t m = 0; |
|
185 |
uint32_t val; |
|
186 |
uint32_t* base = (uint32_t*)&aESTp->iEntries[0]; |
|
187 |
while (r > l) |
|
188 |
{ |
|
189 |
m = (l + r) >> 1; |
|
190 |
val = base[m]; |
|
191 |
if (val > addr) |
|
192 |
r = m; |
|
193 |
else |
|
194 |
l = m + 1; |
|
195 |
} |
|
196 |
val = base[l-1]; |
|
197 |
if (addr >= val && addr < base[l]) /* relies on presence of fencepost at the end */ |
|
198 |
{ |
|
199 |
const TRomImageHeader* rih = (const TRomImageHeader*)val; |
|
200 |
return (TExceptionDescriptor*)rih[-1].iExceptionDescriptor; |
|
201 |
} |
|
202 |
return 0; |
|
203 |
} |
|
204 |
||
205 |
||
206 |
TExceptionDescriptor * GetRAMLoadedExceptionDescriptor(uint32_t addr) |
|
207 |
{ |
|
208 |
TLinAddr aEDp = UserSvr::ExceptionDescriptor(addr); |
|
209 |
||
210 |
SYMBIAN_EH_SUPPORT_PRINTF("UserSvr::ExceptionDescriptor for %08x returned %08x\n", addr, aEDp); |
|
211 |
||
212 |
return (TExceptionDescriptor *)(aEDp & 0xfffffffe); |
|
213 |
} |
|
214 |
||
215 |
void InitialiseSymbianSpecificUnwinderCache(uint32_t addr, _Unwind_Control_Block * ucbp) |
|
216 |
{ |
|
217 |
SET_ROM_EST(ucbp, GetROMExceptionSearchTable()); |
|
218 |
if (!ReLoadExceptionDescriptor(addr, ucbp)) |
|
219 |
{ |
|
220 |
SYMBIAN_EH_SUPPORT_PRINTF("EH ERROR: no exception descriptor for address 0x%08x\n", addr); |
|
221 |
abort(); |
|
222 |
} |
|
223 |
} |
|
224 |
||
225 |
TExceptionDescriptor * ReLoadExceptionDescriptor(uint32_t addr, _Unwind_Control_Block * ucbp) |
|
226 |
{ |
|
227 |
/* Check to see if address is in range covered by ROM EST. If |
|
228 |
it is find the exception descriptor for the address, |
|
229 |
checking that the address is in the range covered by the |
|
230 |
descriptor. Otherwise it comes from a RAM loaded |
|
231 |
executable so get the kernel to find the exception |
|
232 |
descriptor for us. |
|
233 |
*/ |
|
234 |
TRomExceptionSearchTable * aESTp = GET_ROM_EST(ucbp); |
|
235 |
TExceptionDescriptor * aEDp = NULL; |
|
236 |
if (aESTp && addr >= aESTp->iEntries[0] && addr < GET_EST_FENCEPOST(aESTp)) |
|
237 |
{ |
|
238 |
aEDp = SearchEST(addr, aESTp); |
|
239 |
goto jobdone; |
|
240 |
} |
|
241 |
aEDp = GetRAMLoadedExceptionDescriptor(addr); |
|
242 |
if (!aEDp) |
|
243 |
{ |
|
244 |
// look in extension ROM if there is one |
|
245 |
TUint main_start = UserSvr::RomHeaderAddress(); |
|
246 |
TUint main_end = main_start + ((TRomHeader*)main_start)->iUncompressedSize; |
|
266
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
247 |
|
0 | 248 |
TUint rda = UserSvr::RomRootDirectoryAddress(); |
266
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
249 |
|
0 | 250 |
// Assume rom starts on multiple of 4k |
251 |
if (rda > main_end) |
|
252 |
{ |
|
253 |
// ASSUMPTIONS HERE |
|
254 |
// 1. root directory is past the end of the main ROM so there must be an extension ROM |
|
255 |
// 2. the ROM file system in the extension ROM is at the beginning of the ROM (similar to the |
|
256 |
// main ROM) |
|
257 |
// 3. the extension ROM is mapped starting at a megabyte boundary |
|
258 |
// Thus the address of the extension ROM header may be obtained by rounding the root directory |
|
259 |
// address down to the next megabyte boundary. |
|
266
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
260 |
|
0 | 261 |
TUint ext_start = rda &~ 0x000fffffu; |
262 |
TRomExceptionSearchTable* extrom_exctab = (TRomExceptionSearchTable*)(((TExtensionRomHeader*)ext_start)->iRomExceptionSearchTable); |
|
263 |
if (extrom_exctab && addr >= extrom_exctab->iEntries[0] && addr < GET_EST_FENCEPOST(extrom_exctab)) |
|
264 |
aEDp = SearchEST(addr, extrom_exctab); |
|
265 |
} |
|
266 |
} |
|
267 |
||
268 |
jobdone: |
|
269 |
SYMBIAN_EH_SUPPORT_PRINTF("ReLoadExceptionDescriptor: Exception descriptor for address 0x%08x = 0x%08x\n\r", addr, aEDp); |
|
270 |
||
271 |
if (aEDp && ADDRESS_IN_EXCEPTION_DESCRIPTOR_RANGE(addr, aEDp)) |
|
272 |
return SET_EXCEPTION_DESCRIPTOR(ucbp, aEDp); |
|
273 |
else |
|
274 |
return NULL; |
|
275 |
} |
|
276 |
||
277 |
||
278 |
const __EIT_entry* SearchEITV1(uint32_t return_address_offset, const __EIT_entry* base, unsigned int nelems) |
|
279 |
{ |
|
280 |
uint32_t l = 0; |
|
281 |
uint32_t r = nelems; |
|
282 |
uint32_t m=0; |
|
283 |
uint32_t val; |
|
284 |
while (r>l) |
|
285 |
{ |
|
286 |
m = (l + r) >> 1; |
|
287 |
val = base[m].fnoffset; |
|
288 |
if (val > return_address_offset) |
|
289 |
r = m; |
|
290 |
else |
|
291 |
l = m + 1; |
|
292 |
} |
|
293 |
#ifdef _DEBUG |
|
294 |
val = base[l-1].fnoffset; |
|
295 |
SYMBIAN_EH_SUPPORT_PRINTF("SearchEITV1: Located IDX with fnoffset = %08x\n\r", val); |
|
296 |
#endif |
|
297 |
return base + l - 1; |
|
298 |
} |
|
299 |
||
300 |
/* R_ARM_PREL31 is a place-relative 31-bit signed relocation. The |
|
301 |
* routine takes the address of a location that was relocated by |
|
302 |
* R_ARM_PREL31, and returns an absolute address. |
|
303 |
*/ |
|
304 |
static FORCEINLINE uint32_t __ARM_resolve_prel31(void *p) |
|
305 |
{ |
|
306 |
return (uint32_t)((((*(int32_t *)p) << 1) >> 1) + (int32_t)p); |
|
307 |
} |
|
308 |
||
309 |
__EIT_entry* SearchEITV2(uint32_t return_address, const __EIT_entry* base, unsigned int nelems) |
|
310 |
{ |
|
311 |
uint32_t l = 0; |
|
312 |
uint32_t r = nelems; |
|
313 |
uint32_t m=0; |
|
314 |
uint32_t val; |
|
315 |
while (r>l) |
|
316 |
{ |
|
317 |
m = (l + r) >> 1; |
|
318 |
val = __ARM_resolve_prel31((void *)&base[m].fnoffset); |
|
319 |
if (val > return_address) |
|
320 |
r = m; |
|
321 |
else |
|
322 |
l = m + 1; |
|
323 |
} |
|
324 |
#ifdef _DEBUG |
|
325 |
val = __ARM_resolve_prel31((void *)&base[l-1].fnoffset); |
|
326 |
SYMBIAN_EH_SUPPORT_PRINTF("SearchEITV2: Located IDX with fn address = %08x\n\r", val); |
|
327 |
#endif |
|
328 |
return ((__EIT_entry *)base) + l - 1; |
|
329 |
} |
|
330 |
||
331 |
||
332 |
#ifdef _DEBUG |
|
333 |
class TestOverflowTruncate8 : public TDes8Overflow |
|
334 |
{ |
|
335 |
public: |
|
336 |
virtual void Overflow(TDes8& /*aDes*/) {} |
|
337 |
}; |
|
266
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
338 |
|
0 | 339 |
#endif |
340 |
||
341 |
void DebugPrintf(const char * aFmt, ...) |
|
342 |
{ |
|
343 |
#ifdef _DEBUG |
|
344 |
TestOverflowTruncate8 overflow; |
|
345 |
VA_LIST list; |
|
346 |
VA_START(list,aFmt); |
|
347 |
TPtrC8 fmt((const TUint8 *)aFmt); |
|
348 |
TBuf8<0x100> buf; |
|
349 |
buf.AppendFormatList(fmt,list,&overflow); |
|
350 |
TBuf<0x100> buf2; |
|
351 |
buf2.Copy(buf); |
|
352 |
if (buf2[buf2.Length()-1]=='\n') buf2.Append('\r'); |
|
353 |
RDebug::RawPrint(buf2); |
|
354 |
#else |
|
355 |
(void)aFmt; |
|
266
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
356 |
#endif |
0 | 357 |
} |
358 |
||
359 |
} // extern "C" |