Provide elf2e32 with an option to select either RVCT assembler or GNU assembler output for the --dump option
--- a/e32tools/elf2e32/source/filedump.cpp Fri Jun 04 13:19:09 2010 +0100
+++ b/e32tools/elf2e32/source/filedump.cpp Sun Jun 13 16:27:09 2010 +0100
@@ -9,6 +9,7 @@
// Nokia Corporation - initial contribution.
//
// Contributors:
+// Mike Kinghan, mikek@symbian.org, for Symbian Foundation, 2010
//
// Description:
// FileDump Operations of elf2e32 tool to dump E32Image and generate ASM File.
@@ -23,7 +24,9 @@
#include "h_utl.h"
#include "deffile.h"
#include "errorhandler.h"
-#include <stdio.h>
+#include <cstdio>
+#include <cassert>
+
/**
Constructor for class FileDump
@param aParameterListInterface - Instance of class ParameterListInterface
@@ -63,7 +66,7 @@
if(!iParameterListInterface->DefInput())
throw ParameterParserError(NOREQUIREDOPTIONERROR,"--definput");
- GenerateAsmFile(iParameterListInterface->E32ImageOutput());
+ GenerateAsmFile();
}
else
{
@@ -71,7 +74,7 @@
throw ParameterParserError(NOREQUIREDOPTIONERROR,"--e32input");
if(iParameterListInterface->DumpOptions() & EDumpAsm )
throw InvalidArgumentError(INVALIDARGUMENTERROR,iParameterListInterface->FileDumpSubOptions() ,"--dump");
- DumpE32Image(iParameterListInterface->E32Input());
+ DumpE32Image();
}
return 0;
}
@@ -83,11 +86,34 @@
@internalComponent
@released
*/
-int FileDump::GenerateAsmFile(const char* afileName)//DumpAsm
+int FileDump::GenerateAsmFile() //DumpAsm
+{
+ EAsmDialect asmDialect = iParameterListInterface->AsmDialect();
+ switch(asmDialect)
+ {
+ case EGas:
+ return GenerateGasAsmFile();
+ case EArmas:
+ return GenerateArmasAsmFile();
+ default:
+ assert(false);
+ }
+ return 0;
+}
+
+/**
+Function to generate an RVCT armas ASM File.
+@param afileName - ASM File name
+@return 0 on success, otherwise throw error
+@internalComponent
+@released
+*/
+int FileDump::GenerateArmasAsmFile()
{
DefFile *iDefFile = new DefFile();
SymbolList *aSymList;
aSymList = iDefFile->ReadDefFile(iParameterListInterface->DefInput());
+ char const *afileName = iParameterListInterface->E32ImageOutput();
FILE *fptr;
@@ -155,14 +181,89 @@
}
/**
+Function to generate a GNU as ASM File.
+@param afileName - ASM File name
+@return 0 on success, otherwise throw error
+@internalComponent
+@released
+*/
+int FileDump::GenerateGasAsmFile()
+{
+ DefFile *iDefFile = new DefFile();
+ SymbolList *aSymList;
+ aSymList = iDefFile->ReadDefFile(iParameterListInterface->DefInput());
+ char const *afileName = iParameterListInterface->E32ImageOutput();
+
+ FILE *fptr;
+
+ if((fptr=fopen(afileName,"w"))==NULL)
+ {
+ throw FileError(FILEOPENERROR,(char*)afileName);
+ }
+ else
+ {
+ SymbolList::iterator aItr = aSymList->begin();
+ SymbolList::iterator last = aSymList->end();
+ Symbol *aSym;
+
+ while( aItr != last)
+ {
+ aSym = *aItr;
+
+ if(aSym->Absent())
+ {
+ aItr++;
+ continue;
+ }
+
+ fputs("\t.extern ",fptr);
+ fputs(aSym->SymbolName(),fptr);
+ fputs("\n",fptr);
+ aItr++;
+ }
+
+ // Create a directive section that instructs the linker to make all listed
+ // symbols visible.
+
+ fputs("\t.text\n\n",fptr);
+
+ fputs("\t.ascii \"#<SYMEDIT>#\\n\"\n", fptr);
+
+ aItr = aSymList->begin();
+ while (aItr != last)
+ {
+ aSym = *aItr;
+
+ if ( aSym->Absent() )
+ {
+ aItr++;
+ continue;
+ }
+
+ // Example:
+ // DCB "EXPORT __ARM_ll_mlass\n"
+ fputs("\t.ascii \"EXPORT ",fptr);
+ fputs(aSym->SymbolName(),fptr);
+ fputs("\\n\"\n", fptr);
+
+ aItr++;
+ }
+ fclose(fptr);
+ }
+ return 0;
+}
+
+
+/**
Function to Dump E32 Image.
@param afileName - E32 Image File name
@return 1 on success, otherwise throw error
@internalComponent
@released
*/
-int FileDump::DumpE32Image(const char* afileName)
+int FileDump::DumpE32Image()
{
+ char const *afileName = iParameterListInterface->E32Input();
E32ImageFile *aE32Imagefile=new E32ImageFile();
TInt result = aE32Imagefile->Open(afileName);
--- a/e32tools/elf2e32/source/filedump.h Fri Jun 04 13:19:09 2010 +0100
+++ b/e32tools/elf2e32/source/filedump.h Sun Jun 13 16:27:09 2010 +0100
@@ -9,6 +9,7 @@
// Nokia Corporation - initial contribution.
//
// Contributors:
+// Mike Kinghan, mikek@symbian.org, for Symbian Foundation, 2010
//
// Description:
// FileDump Class for elf2e32 tool
@@ -35,8 +36,10 @@
~FileDump();
int Execute();
private:
- int DumpE32Image(const char * fileName);
- int GenerateAsmFile(const char* afileName);//DumpAsm
+ int DumpE32Image();
+ int GenerateAsmFile();//DumpAsm
+ int GenerateArmasAsmFile();
+ int GenerateGasAsmFile();
};
#endif
--- a/e32tools/elf2e32/source/parameterlistinterface.h Fri Jun 04 13:19:09 2010 +0100
+++ b/e32tools/elf2e32/source/parameterlistinterface.h Sun Jun 13 16:27:09 2010 +0100
@@ -9,6 +9,7 @@
// Nokia Corporation - initial contribution.
//
// Contributors:
+// Mike Kinghan, mikek@symbian.org, for Symbian Foundation, 2010
//
// Description:
// Implementation of the Header file for the ParameterListInterface of the elf2e32 tool
@@ -43,6 +44,12 @@
EStdExe
};
+enum EAsmDialect // Which dialect of arm assembly to write for the --dump option
+{
+ EArmas, // RVCT armas
+ EGas // GNU as
+};
+
typedef unsigned int UINT;
using std::vector;
@@ -278,6 +285,7 @@
virtual bool SymNamedLookup() = 0;
virtual bool IsDebuggable() = 0;
virtual bool IsSmpSafe() = 0;
+ virtual EAsmDialect AsmDialect() = 0;
};
--- a/e32tools/elf2e32/source/parametermanager.cpp Fri Jun 04 13:19:09 2010 +0100
+++ b/e32tools/elf2e32/source/parametermanager.cpp Sun Jun 13 16:27:09 2010 +0100
@@ -9,6 +9,7 @@
// Nokia Corporation - initial contribution.
//
// Contributors:
+// Mike Kinghan, mikek@symbian.org, for Symbian Foundation, 2010
//
// Description:
// Implementation of the Class ParameterManager for the elf2e32 tool
@@ -24,7 +25,7 @@
#include "pl_common.h"
#include "parametermanager.h"
#include "errorhandler.h"
-#include <iostream>
+#include <iostream>
#include <cstdlib>
#include "h_utl.h"
@@ -111,7 +112,8 @@
iCustomDllTarget(false),
iSymNamedLookup(false),
iDebuggable(false),
- iSmpSafe(false)
+ iSmpSafe(false),
+ iAsmDialect(EGas)
{
iArgumentCount = aArgc;
ParamList temp(aArgv, aArgv+aArgc);
@@ -430,6 +432,12 @@
(void*)ParameterManager::ParseSmpSafe,
"SMP Safe",
},
+ {
+ "asm",
+ (void*)ParameterManager::ParseAsmDialect,
+ "Dialect of arm assembly to write for the --dump option. "
+ "Either \"gas\" (GNU as: default) or \"armas\" (RVCT as)",
+ },
{
"help",
(void *)ParameterManager::ParamHelp,
@@ -1509,6 +1517,21 @@
}
/**
+This function indicates the asm assembly dialect that will be written for the
+--dump option, as determined by the specified or default value of the --asm
+option.
+
+@internalComponent
+@released
+
+@return EArmas if --asm=armas was passed, else EGas
+*/
+EAsmDialect ParameterManager::AsmDialect()
+{
+ return iAsmDialect;
+}
+
+/**
This function extracts the filename from the absolute path that is given as input.
@internalComponent
@@ -2847,6 +2870,23 @@
aPM->SetSmpSafe(true);
}
+DEFINE_PARAM_PARSER(ParameterManager::ParseAsmDialect)
+{
+ INITIALISE_PARAM_PARSER;
+ if (!strcmp(aValue,"gas"))
+ {
+ aPM->SetAsmDialect(EGas);
+ }
+ else if (!strcmp(aValue,"armas"))
+ {
+ aPM->SetSmpSafe(EArmas);
+ }
+ else
+ {
+ throw InvalidArgumentError(INVALIDARGUMENTERROR, aValue, "--asm");
+ }
+}
+
static const ParameterManager::TargetTypeDesc DefaultTargetTypes[] =
{
{ "DLL", EDll },
@@ -3729,3 +3769,18 @@
{
iSmpSafe = aVal;
}
+
+/**
+This function sets iAsmDialect if --asm is passed in.
+
+@internalComponent
+@released
+
+@param aVal
+A member of enum EAsmDialect
+*/
+void ParameterManager::SetAsmDialect(EAsmDialect aAsmDialect)
+{
+ iAsmDialect = aAsmDialect;
+}
+
--- a/e32tools/elf2e32/source/parametermanager.h Fri Jun 04 13:19:09 2010 +0100
+++ b/e32tools/elf2e32/source/parametermanager.h Sun Jun 13 16:27:09 2010 +0100
@@ -9,6 +9,7 @@
// Nokia Corporation - initial contribution.
//
// Contributors:
+// Mike Kinghan, mikek@symbian.org, for Symbian Foundation, 2010
//
// Description:
// Implementation of the Header file for Class ParameterManager of the elf2e32 tool
@@ -144,6 +145,7 @@
DECLARE_PARAM_PARSER(ParseSymNamedLookup);
DECLARE_PARAM_PARSER(ParseDebuggable);
DECLARE_PARAM_PARSER(ParseSmpSafe);
+ DECLARE_PARAM_PARSER(ParseAsmDialect);
ParameterManager(int aArgc, char** aArgv);
virtual ~ParameterManager();
@@ -195,6 +197,7 @@
void SetSymNamedLookup(bool aVal);
void SetDebuggable(bool aVal);
void SetSmpSafe(bool aVal);
+ void SetAsmDialect(EAsmDialect aAsmDialect);
int NumOptions();
int NumShortOptions();
@@ -279,6 +282,7 @@
bool SymNamedLookup();
bool IsDebuggable();
bool IsSmpSafe();
+ EAsmDialect AsmDialect();
private:
/** The number of command line arguments passed into the program */
@@ -445,6 +449,7 @@
bool iSymNamedLookup;
bool iDebuggable;
bool iSmpSafe;
+ EAsmDialect iAsmDialect;
};