285 ExecuteInSupervisorModeVector = UserSvr::ExecuteInSupervisorMode; |
285 ExecuteInSupervisorModeVector = UserSvr::ExecuteInSupervisorMode; |
286 gExecutesInSupervisorMode = ETrue; |
286 gExecutesInSupervisorMode = ETrue; |
287 } |
287 } |
288 } |
288 } |
289 |
289 |
290 // A version that will work in user or supervisor mode |
290 /** |
291 void MyPrintf(const char* aFmt, ...) |
291 It would be nice to be able to print debug information from the various functions |
292 { |
292 supervisor-mode functions below. Unfortunately, we can't call RDebug::Printf() or |
|
293 any of its relatives in supervisor mode, and of course we can't call the equivalent |
|
294 kernel functions even when we're already in supervisor mode, because the entry |
|
295 points aren't visible. |
|
296 |
|
297 So this function just wraps and guards the call to RDebug, so we won't call it |
|
298 in SVC mode. The outcome is that trace messages are only generated if using the |
|
299 flexible memory model, where the code doesn't actually run in SVC mode anyway. |
|
300 */ |
|
301 void svPrintf(const char* aFmt, ...) |
|
302 { |
|
303 if (gExecutesInSupervisorMode) |
|
304 return; |
|
305 |
293 VA_LIST list; |
306 VA_LIST list; |
294 VA_START(list, aFmt); |
307 VA_START(list, aFmt); |
295 TPtrC8 fmt((const TText8*)aFmt); |
308 TPtrC8 fmt((const TText8*)aFmt); |
296 TBuf8<0x100> buf; |
309 TBuf8<0x100> buf; |
297 buf.AppendFormatList(fmt, list); |
310 buf.AppendFormatList(fmt, list); |
377 TInt svRelocateExports(TAny* aPtr) |
390 TInt svRelocateExports(TAny* aPtr) |
378 { |
391 { |
379 E32Image& exporter = *(E32Image*)aPtr; |
392 E32Image& exporter = *(E32Image*)aPtr; |
380 |
393 |
381 // Dump everything potentially useful that we know about the exporter ... |
394 // Dump everything potentially useful that we know about the exporter ... |
382 __LDRTRACE(MyPrintf("RelocateExports: paged? %d, iRomImageHeader@%08x, iHeader@%08x", |
395 __LDRTRACE(svPrintf("RelocateExports: paged? %d, iRomImageHeader@%08x, iHeader@%08x", |
383 exporter.iUseCodePaging, exporter.iRomImageHeader, exporter.iHeader)); |
396 exporter.iUseCodePaging, exporter.iRomImageHeader, exporter.iHeader)); |
384 __LDRTRACE(MyPrintf(" iCodeLoadAddress %08x, iCodeRunAddress %08x, iCodeSize %x iTextSize %x", |
397 __LDRTRACE(svPrintf(" iCodeLoadAddress %08x, iCodeRunAddress %08x, iCodeSize %x iTextSize %x", |
385 exporter.iCodeLoadAddress, exporter.iCodeRunAddress, |
398 exporter.iCodeLoadAddress, exporter.iCodeRunAddress, |
386 exporter.iCodeSize, exporter.iTextSize)) |
399 exporter.iCodeSize, exporter.iTextSize)) |
387 __LDRTRACE(MyPrintf(" iDataLoadAddress %08x, iDataRunAddress %08x, iDataSize %x iBssSize %x iTotalDataSize %x", |
400 __LDRTRACE(svPrintf(" iDataLoadAddress %08x, iDataRunAddress %08x, iDataSize %x iBssSize %x iTotalDataSize %x", |
388 exporter.iDataLoadAddress, exporter.iDataRunAddress, |
401 exporter.iDataLoadAddress, exporter.iDataRunAddress, |
389 exporter.iDataSize, exporter.iBssSize, exporter.iTotalDataSize)); |
402 exporter.iDataSize, exporter.iBssSize, exporter.iTotalDataSize)); |
390 __LDRTRACE(MyPrintf(" iCodeDelta, %x iDataDelta %x, iExportDirEntryDelta %x", |
403 __LDRTRACE(svPrintf(" iCodeDelta, %x iDataDelta %x, iExportDirEntryDelta %x", |
391 exporter.iCodeDelta, exporter.iDataDelta, exporter.iExportDirEntryDelta)); |
404 exporter.iCodeDelta, exporter.iDataDelta, exporter.iExportDirEntryDelta)); |
392 |
405 |
393 // It turns out that very little of the exporter info is useful! For |
406 // It turns out that very little of the exporter info is useful! For |
394 // example, the required code and data deltas are NOT those provided |
407 // example, the required code and data deltas are NOT those provided |
395 // by the exporter, nor are the load addresses relevant ... :( |
408 // by the exporter, nor are the load addresses relevant ... :( |
469 { |
482 { |
470 SFixupImportAddressesInfo& info = *(SFixupImportAddressesInfo*)aPtr; |
483 SFixupImportAddressesInfo& info = *(SFixupImportAddressesInfo*)aPtr; |
471 E32Image& exporter = *info.iExporter; |
484 E32Image& exporter = *info.iExporter; |
472 |
485 |
473 #ifdef _DEBUG |
486 #ifdef _DEBUG |
474 __LDRTRACE(MyPrintf(">svFixupImportAddresses %d imports, code@%08x, fixup@%08x exporter@%08x", |
487 __LDRTRACE(svPrintf(">svFixupImportAddresses %d imports, code@%08x, fixup@%08x exporter@%08x", |
475 info.iNumImports, info.iCodeLoadAddress, info.iFixup64, info.iExporter)); |
488 info.iNumImports, info.iCodeLoadAddress, info.iFixup64, info.iExporter)); |
476 |
489 |
477 // Dump everything potentially useful that we know about the exporter ... |
490 // Dump everything potentially useful that we know about the exporter ... |
478 __LDRTRACE(MyPrintf("%S: paged? %d, iRomImageHeader@%08x, iHeader@%08x", |
491 __LDRTRACE(svPrintf("%S: paged? %d, iRomImageHeader@%08x, iHeader@%08x", |
479 &exporter.iFileName, exporter.iUseCodePaging, |
492 &exporter.iFileName, exporter.iUseCodePaging, |
480 exporter.iRomImageHeader, exporter.iHeader)); |
493 exporter.iRomImageHeader, exporter.iHeader)); |
481 __LDRTRACE(MyPrintf("iCodeLoadAddress %08x, iCodeRunAddress %08x, iCodeSize %x iTextSize %x", |
494 __LDRTRACE(svPrintf("iCodeLoadAddress %08x, iCodeRunAddress %08x, iCodeSize %x iTextSize %x", |
482 exporter.iCodeLoadAddress, exporter.iCodeRunAddress, |
495 exporter.iCodeLoadAddress, exporter.iCodeRunAddress, |
483 exporter.iCodeSize, exporter.iTextSize)) |
496 exporter.iCodeSize, exporter.iTextSize)) |
484 __LDRTRACE(MyPrintf("iDataLoadAddress %08x, iDataRunAddress %08x, iDataSize %x iBssSize %x iTotalDataSize %x", |
497 __LDRTRACE(svPrintf("iDataLoadAddress %08x, iDataRunAddress %08x, iDataSize %x iBssSize %x iTotalDataSize %x", |
485 exporter.iDataLoadAddress, exporter.iDataRunAddress, |
498 exporter.iDataLoadAddress, exporter.iDataRunAddress, |
486 exporter.iDataSize, exporter.iBssSize, exporter.iTotalDataSize)); |
499 exporter.iDataSize, exporter.iBssSize, exporter.iTotalDataSize)); |
487 __LDRTRACE(MyPrintf("iCodeDelta, %x iDataDelta %x, iExportDirEntryDelta %x", |
500 __LDRTRACE(svPrintf("iCodeDelta, %x iDataDelta %x, iExportDirEntryDelta %x", |
488 exporter.iCodeDelta, exporter.iDataDelta, exporter.iExportDirEntryDelta)); |
501 exporter.iCodeDelta, exporter.iDataDelta, exporter.iExportDirEntryDelta)); |
489 |
502 |
490 if (exporter.iRomImageHeader) |
503 if (exporter.iRomImageHeader) |
491 { |
504 { |
492 const TRomImageHeader& rh = *exporter.iRomImageHeader; |
505 const TRomImageHeader& rh = *exporter.iRomImageHeader; |
493 __LDRTRACE(MyPrintf("ROM: iCodeAddress %08x, iCodeSize %x, iTextSize %x", |
506 __LDRTRACE(svPrintf("ROM: iCodeAddress %08x, iCodeSize %x, iTextSize %x", |
494 rh.iCodeAddress, rh.iCodeSize, rh.iTextSize)); |
507 rh.iCodeAddress, rh.iCodeSize, rh.iTextSize)); |
495 __LDRTRACE(MyPrintf("ROM: iDataAddress %08x, iDataSize %x, iBssSize %x", |
508 __LDRTRACE(svPrintf("ROM: iDataAddress %08x, iDataSize %x, iBssSize %x", |
496 rh.iDataAddress, rh.iDataSize, rh.iBssSize)); |
509 rh.iDataAddress, rh.iDataSize, rh.iBssSize)); |
497 __LDRTRACE(MyPrintf("ROM: iDataBssLinearBase %08x, iTotalDataSize %x", |
510 __LDRTRACE(svPrintf("ROM: iDataBssLinearBase %08x, iTotalDataSize %x", |
498 rh.iDataBssLinearBase, rh.iTotalDataSize)); |
511 rh.iDataBssLinearBase, rh.iTotalDataSize)); |
499 } |
512 } |
500 |
513 |
501 if (exporter.iHeader) |
514 if (exporter.iHeader) |
502 { |
515 { |
503 const E32ImageHeader& ih = *exporter.iHeader; |
516 const E32ImageHeader& ih = *exporter.iHeader; |
504 __LDRTRACE(MyPrintf("HEAD: iCodeBase %08x, iCodeSize %x, iTextSize %x", |
517 __LDRTRACE(svPrintf("HEAD: iCodeBase %08x, iCodeSize %x, iTextSize %x", |
505 ih.iCodeBase, ih.iCodeSize, ih.iTextSize)); |
518 ih.iCodeBase, ih.iCodeSize, ih.iTextSize)); |
506 __LDRTRACE(MyPrintf("HEAD: iDataBase %08x, iDataSize %x, iBssSize %x", |
519 __LDRTRACE(svPrintf("HEAD: iDataBase %08x, iDataSize %x, iBssSize %x", |
507 ih.iDataBase, ih.iDataSize, ih.iBssSize)); |
520 ih.iDataBase, ih.iDataSize, ih.iBssSize)); |
508 } |
521 } |
509 #endif // _DEBUG |
522 #endif // _DEBUG |
510 |
523 |
511 // 'exportDir' points to the address of the 0th ordinal (symbol name data); |
524 // 'exportDir' points to the address of the 0th ordinal (symbol name data); |
571 { |
584 { |
572 SFixupImportAddressesInfo& info = *(SFixupImportAddressesInfo*)aPtr; |
585 SFixupImportAddressesInfo& info = *(SFixupImportAddressesInfo*)aPtr; |
573 E32Image& exporter = *info.iExporter; |
586 E32Image& exporter = *info.iExporter; |
574 |
587 |
575 #ifdef _DEBUG |
588 #ifdef _DEBUG |
576 __LDRTRACE(MyPrintf(">svElfDerivedFixupImportAddresses %d imports, code@%08x, fixup@%08x exporter@%08x", |
589 __LDRTRACE(svPrintf(">svElfDerivedFixupImportAddresses %d imports, code@%08x, fixup@%08x exporter@%08x", |
577 info.iNumImports, info.iCodeLoadAddress, info.iFixup64, info.iExporter)); |
590 info.iNumImports, info.iCodeLoadAddress, info.iFixup64, info.iExporter)); |
578 |
591 |
579 // Dump everything potentially useful that we know about the exporter ... |
592 // Dump everything potentially useful that we know about the exporter ... |
580 __LDRTRACE(MyPrintf("%S: paged? %d, iRomImageHeader@%08x, iHeader@%08x", |
593 __LDRTRACE(svPrintf("%S: paged? %d, iRomImageHeader@%08x, iHeader@%08x", |
581 &exporter.iFileName, exporter.iUseCodePaging, |
594 &exporter.iFileName, exporter.iUseCodePaging, |
582 exporter.iRomImageHeader, exporter.iHeader)); |
595 exporter.iRomImageHeader, exporter.iHeader)); |
583 __LDRTRACE(MyPrintf("iCodeLoadAddress %08x, iCodeRunAddress %08x, iCodeSize %x iTextSize %x", |
596 __LDRTRACE(svPrintf("iCodeLoadAddress %08x, iCodeRunAddress %08x, iCodeSize %x iTextSize %x", |
584 exporter.iCodeLoadAddress, exporter.iCodeRunAddress, |
597 exporter.iCodeLoadAddress, exporter.iCodeRunAddress, |
585 exporter.iCodeSize, exporter.iTextSize)) |
598 exporter.iCodeSize, exporter.iTextSize)) |
586 __LDRTRACE(MyPrintf("iDataLoadAddress %08x, iDataRunAddress %08x, iDataSize %x iBssSize %x iTotalDataSize %x", |
599 __LDRTRACE(svPrintf("iDataLoadAddress %08x, iDataRunAddress %08x, iDataSize %x iBssSize %x iTotalDataSize %x", |
587 exporter.iDataLoadAddress, exporter.iDataRunAddress, |
600 exporter.iDataLoadAddress, exporter.iDataRunAddress, |
588 exporter.iDataSize, exporter.iBssSize, exporter.iTotalDataSize)); |
601 exporter.iDataSize, exporter.iBssSize, exporter.iTotalDataSize)); |
589 __LDRTRACE(MyPrintf("iCodeDelta, %x iDataDelta %x, iExportDirEntryDelta %x", |
602 __LDRTRACE(svPrintf("iCodeDelta, %x iDataDelta %x, iExportDirEntryDelta %x", |
590 exporter.iCodeDelta, exporter.iDataDelta, exporter.iExportDirEntryDelta)); |
603 exporter.iCodeDelta, exporter.iDataDelta, exporter.iExportDirEntryDelta)); |
591 |
604 |
592 if (exporter.iRomImageHeader) |
605 if (exporter.iRomImageHeader) |
593 { |
606 { |
594 const TRomImageHeader& rh = *exporter.iRomImageHeader; |
607 const TRomImageHeader& rh = *exporter.iRomImageHeader; |
595 __LDRTRACE(MyPrintf("ROM: iCodeAddress %08x, iCodeSize %x, iTextSize %x", |
608 __LDRTRACE(svPrintf("ROM: iCodeAddress %08x, iCodeSize %x, iTextSize %x", |
596 rh.iCodeAddress, rh.iCodeSize, rh.iTextSize)); |
609 rh.iCodeAddress, rh.iCodeSize, rh.iTextSize)); |
597 __LDRTRACE(MyPrintf("ROM: iDataAddress %08x, iDataSize %x, iBssSize %x", |
610 __LDRTRACE(svPrintf("ROM: iDataAddress %08x, iDataSize %x, iBssSize %x", |
598 rh.iDataAddress, rh.iDataSize, rh.iBssSize)); |
611 rh.iDataAddress, rh.iDataSize, rh.iBssSize)); |
599 __LDRTRACE(MyPrintf("ROM: iDataBssLinearBase %08x, iTotalDataSize %x", |
612 __LDRTRACE(svPrintf("ROM: iDataBssLinearBase %08x, iTotalDataSize %x", |
600 rh.iDataBssLinearBase, rh.iTotalDataSize)); |
613 rh.iDataBssLinearBase, rh.iTotalDataSize)); |
601 } |
614 } |
602 |
615 |
603 if (exporter.iHeader) |
616 if (exporter.iHeader) |
604 { |
617 { |
605 const E32ImageHeader& ih = *exporter.iHeader; |
618 const E32ImageHeader& ih = *exporter.iHeader; |
606 __LDRTRACE(MyPrintf("HEAD: iCodeBase %08x, iCodeSize %x, iTextSize %x", |
619 __LDRTRACE(svPrintf("HEAD: iCodeBase %08x, iCodeSize %x, iTextSize %x", |
607 ih.iCodeBase, ih.iCodeSize, ih.iTextSize)); |
620 ih.iCodeBase, ih.iCodeSize, ih.iTextSize)); |
608 __LDRTRACE(MyPrintf("HEAD: iDataBase %08x, iDataSize %x, iBssSize %x", |
621 __LDRTRACE(svPrintf("HEAD: iDataBase %08x, iDataSize %x, iBssSize %x", |
609 ih.iDataBase, ih.iDataSize, ih.iBssSize)); |
622 ih.iDataBase, ih.iDataSize, ih.iBssSize)); |
610 } |
623 } |
611 #endif // _DEBUG |
624 #endif // _DEBUG |
612 |
625 |
613 // Here we calculate the bounds of each section of the exporter, as |
626 // Here we calculate the bounds of each section of the exporter, as |
698 else |
711 else |
699 sectionDelta = dirDelta; // unknown - assume nonpaged? |
712 sectionDelta = dirDelta; // unknown - assume nonpaged? |
700 newValue = expAddr + sectionDelta + adjustment; |
713 newValue = expAddr + sectionDelta + adjustment; |
701 } |
714 } |
702 |
715 |
703 __LDRTRACE(MyPrintf("svElfDerivedFixupImportAddresses: import[%d] (%08x:%08x) is export[%d] %08x+%08x => %08x", |
716 __LDRTRACE(svPrintf("svElfDerivedFixupImportAddresses: import[%d] (%08x:%08x) is export[%d] %08x+%08x => %08x", |
704 iol - info.iImportOffsetList, codePtr, importInfo, ordinal, expAddr, adjustment, newValue)); |
717 iol - info.iImportOffsetList, codePtr, importInfo, ordinal, expAddr, adjustment, newValue)); |
705 |
718 |
706 // In non-paged code, we can simply replace the ordinals in the IAT with the |
719 // In non-paged code, we can simply replace the ordinals in the IAT with the |
707 // object addresses to which they refer once and for all. However, in a code |
720 // object addresses to which they refer once and for all. However, in a code |
708 // paging system, the IAT may be thrown away and later reloaded from the code |
721 // paging system, the IAT may be thrown away and later reloaded from the code |