e32tools/elf2e32/source/filedump.cpp
author Ross Qin <ross.qin@nokia.com>
Tue, 02 Nov 2010 09:31:04 +0800
changeset 671 ff8ff850b0cf
parent 666 76dc8e3e7f2e
permissions -rw-r--r--
fix the Serious problem with ROFS on-disk format
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
     1
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
     2
// All rights reserved.
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
     3
// This component and the accompanying materials are made available
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
     4
// under the terms of "Eclipse Public License v1.0"
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
     5
// which accompanies this distribution, and is available
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
     7
//
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
     8
// Initial Contributors:
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
     9
// Nokia Corporation - initial contribution.
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    10
//
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    11
// Contributors:
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    12
//
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    13
// Description:
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    14
// FileDump Operations of elf2e32 tool to dump E32Image and generate ASM File.
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    15
// @internalComponent
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    16
// @released
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    17
// 
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    18
//
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    19
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    20
#include "pl_common.h"
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    21
#include "filedump.h"
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    22
#include "e32imagefile.h"
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    23
#include "h_utl.h"
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    24
#include "deffile.h"
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    25
#include "errorhandler.h"
666
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
    26
#include <cstdio>
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
    27
#include <cassert>
0
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    28
/**
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    29
Constructor for class FileDump
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    30
@param aParameterListInterface - Instance of class ParameterListInterface
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    31
@internalComponent
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    32
@released
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    33
*/
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    34
FileDump::FileDump(ParameterListInterface* aParameterListInterface) : UseCaseBase(aParameterListInterface)
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    35
{
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    36
}
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    37
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    38
/**
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    39
Destructor for class FileDump
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    40
@internalComponent
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    41
@released
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    42
*/
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    43
FileDump::~FileDump()
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    44
{
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    45
}
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    46
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    47
/**
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    48
Execute Function for the File Dump. It dumps E32 image or generate ASM file based on the
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    49
file dump options
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    50
@return 0 on success, otherwise throw error 
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    51
@internalComponent
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    52
@released
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    53
*/
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    54
int FileDump::Execute()
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    55
{
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    56
	if(iParameterListInterface->FileDumpOption() && iParameterListInterface->E32OutOption() && iParameterListInterface->DefFileInOption()) //DumpAsm
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    57
	{
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    58
		if(!(iParameterListInterface->DumpOptions() & EDumpAsm))
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    59
			throw InvalidArgumentError(INVALIDARGUMENTERROR,(!iParameterListInterface->FileDumpSubOptions()?"":iParameterListInterface->FileDumpSubOptions()) ,"--dump");
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    60
		if(iParameterListInterface->DumpOptions() & 31)
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    61
			throw InvalidArgumentError(INVALIDARGUMENTERROR,(!iParameterListInterface->FileDumpSubOptions()?"":iParameterListInterface->FileDumpSubOptions()),"--dump");
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    62
		if(!iParameterListInterface->E32ImageOutput())
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    63
			throw ParameterParserError(NOREQUIREDOPTIONERROR,"--output");
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    64
		if(!iParameterListInterface->DefInput())
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    65
			throw ParameterParserError(NOREQUIREDOPTIONERROR,"--definput");
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    66
666
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
    67
		GenerateAsmFile();
0
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    68
	}
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    69
	else
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    70
	{
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    71
		if(!iParameterListInterface->E32Input())
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    72
			throw ParameterParserError(NOREQUIREDOPTIONERROR,"--e32input");
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    73
		if(iParameterListInterface->DumpOptions() & EDumpAsm )
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    74
			throw InvalidArgumentError(INVALIDARGUMENTERROR,iParameterListInterface->FileDumpSubOptions() ,"--dump");
666
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
    75
		DumpE32Image();
0
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    76
	}
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    77
	return 0;
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    78
}
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    79
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    80
/**
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    81
Function to generate ASM File.
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    82
@param afileName - ASM File name
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    83
@return 0 on success, otherwise throw error 
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    84
@internalComponent
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    85
@released
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
    86
*/
666
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
    87
int FileDump::GenerateAsmFile() //DumpAsm
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
    88
{
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
    89
	EAsmDialect asmDialect = iParameterListInterface->AsmDialect();
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
    90
	switch(asmDialect)
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
    91
	{
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
    92
	case EGas:
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
    93
		return GenerateGasAsmFile();
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
    94
	case EArmas:
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
    95
		return GenerateArmasAsmFile();
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
    96
	default:
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
    97
		assert(false);
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
    98
	}
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
    99
	return 0;
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   100
}
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   101
int FileDump::GenerateArmasAsmFile()
0
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   102
{
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   103
	DefFile *iDefFile = new DefFile();
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   104
	SymbolList *aSymList;
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   105
	aSymList = iDefFile->ReadDefFile(iParameterListInterface->DefInput());
666
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   106
	char const *afileName = iParameterListInterface->E32ImageOutput(); 
0
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   107
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   108
	FILE *fptr;
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   109
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   110
	if((fptr=fopen(afileName,"w"))==NULL)
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   111
	{
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   112
		throw FileError(FILEOPENERROR,(char*)afileName);
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   113
	}
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   114
	else
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   115
	{
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   116
		SymbolList::iterator aItr = aSymList->begin();
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   117
		SymbolList::iterator last = aSymList->end();
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   118
		Symbol *aSym;
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   119
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   120
		while( aItr != last)
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   121
		{
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   122
			aSym = *aItr;
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   123
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   124
			if(aSym->Absent())
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   125
			{
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   126
				aItr++;
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   127
				continue;
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   128
			}
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   129
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   130
			fputs("\tIMPORT ",fptr);
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   131
			fputs(aSym->SymbolName(),fptr);
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   132
			//Set the visibility of the symbols as default."DYNAMIC" option is
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   133
			//added to remove STV_HIDDEN visibility warnings generated by every 
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   134
			//export during kernel build 
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   135
			fputs(" [DYNAMIC]", fptr);
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   136
			fputs("\n",fptr);
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   137
			aItr++;
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   138
		}
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   139
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   140
        // Create a directive section that instructs the linker to make all listed
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   141
        // symbols visible.
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   142
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   143
        fputs("\n AREA |.directive|, READONLY, NOALLOC\n\n",fptr);
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   144
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   145
        fputs("\tDCB \"#<SYMEDIT>#\\n\"\n", fptr);
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   146
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   147
		aItr = aSymList->begin();
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   148
		while (aItr != last)
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   149
		{
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   150
			aSym = *aItr;
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   151
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   152
			if ( aSym->Absent() )
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   153
			{
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   154
				aItr++;
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   155
				continue;
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   156
			}
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   157
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   158
            // Example:
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   159
            //  DCB "EXPORT __ARM_ll_mlass\n"
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   160
			fputs("\tDCB \"EXPORT ",fptr);
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   161
			fputs(aSym->SymbolName(),fptr);
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   162
			fputs("\\n\"\n", fptr);
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   163
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   164
			aItr++;
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   165
		}
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   166
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   167
		fputs("\n END\n",fptr);
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   168
		fclose(fptr);
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   169
	}
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   170
	return 0;
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   171
}
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   172
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   173
/**
666
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   174
Function to generate a GNU as ASM File.
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   175
@param afileName - ASM File name
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   176
@return 0 on success, otherwise throw error 
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   177
@internalComponent
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   178
@released*/
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   179
int FileDump::GenerateGasAsmFile()
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   180
{
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   181
	DefFile *iDefFile = new DefFile();
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   182
	SymbolList *aSymList;
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   183
	aSymList = iDefFile->ReadDefFile(iParameterListInterface->DefInput());
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   184
	char const *afileName = iParameterListInterface->E32ImageOutput(); 
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   185
	FILE *fptr;
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   186
	if((fptr=fopen(afileName,"w"))==NULL)
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   187
	{
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   188
		throw FileError(FILEOPENERROR,(char*)afileName);
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   189
	}
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   190
	else
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   191
	{
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   192
		SymbolList::iterator aItr = aSymList->begin();
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   193
		SymbolList::iterator last = aSymList->end();
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   194
		Symbol *aSym;
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   195
		while( aItr != last)
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   196
		{
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   197
			aSym = *aItr;
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   198
			if(aSym->Absent())
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   199
			{
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   200
				aItr++;
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   201
				continue;
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   202
			}
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   203
			fputs("\t.global ",fptr);
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   204
			fputs(aSym->SymbolName(),fptr);
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   205
			fputs("\n",fptr);
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   206
			aItr++;
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   207
		}
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   208
		fclose(fptr);
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   209
	}
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   210
	return 0;
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   211
}
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   212
/**
0
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   213
Function to Dump E32 Image.
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   214
@param afileName - E32 Image File name
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   215
@return 1 on success, otherwise throw error 
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   216
@internalComponent
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   217
@released
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   218
*/
666
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   219
int FileDump::DumpE32Image()
0
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   220
{
666
76dc8e3e7f2e sync from svn
Zheng Shen <zheng.shen@nokia.com>
parents: 590
diff changeset
   221
	char const *afileName = iParameterListInterface->E32Input(); 
0
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   222
	E32ImageFile *aE32Imagefile=new E32ImageFile();
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   223
	TInt result = aE32Imagefile->Open(afileName);
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   224
	
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   225
	if (result > 0)
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   226
		return 1;
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   227
	else if (result == KErrCorrupt || result == KErrNotSupported)
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   228
	{
590
360bd6b35136 buildrom v3.24.0, rombuild v2.17.3, rofsbuild v2.10.4, resource compiler v8.4.001, image check v1.4.0, elftools v2.3, elf2e32 v2.3
jjkang
parents: 0
diff changeset
   229
		throw InvalidE32ImageError(INVALIDE32IMAGEERROR, (char*)afileName);
0
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   230
	}
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   231
	else if (result != 0)
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   232
	{
590
360bd6b35136 buildrom v3.24.0, rombuild v2.17.3, rofsbuild v2.10.4, resource compiler v8.4.001, image check v1.4.0, elftools v2.3, elf2e32 v2.3
jjkang
parents: 0
diff changeset
   233
		throw FileError(FILEREADERROR, (char*)afileName);
0
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   234
	}
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   235
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   236
	int dumpOptions=iParameterListInterface->DumpOptions();
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   237
	
590
360bd6b35136 buildrom v3.24.0, rombuild v2.17.3, rofsbuild v2.10.4, resource compiler v8.4.001, image check v1.4.0, elftools v2.3, elf2e32 v2.3
jjkang
parents: 0
diff changeset
   238
	aE32Imagefile->Dump(afileName, dumpOptions);
0
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   239
	delete aE32Imagefile;
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   240
	return KErrNone;
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   241
}
044383f39525 Convert Build package from SFL to EPL
Alex Gilkes <alex.gilkes@nokia.com>
parents:
diff changeset
   242