tools/elf4rom/src/dwarfdefs.h
changeset 34 92d87f2e53c2
equal deleted inserted replaced
33:1af5c1be89f8 34:92d87f2e53c2
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 *
       
     5 * This program is free software: you can redistribute it and/or modify
       
     6 * it under the terms of the GNU Lesser General Public License as published by
       
     7 * the Free Software Foundation, either version 3 of the License, or
       
     8 * (at your option) any later version.
       
     9 *
       
    10 * This program is distributed in the hope that it will be useful,
       
    11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    13 * GNU Lesser General Public License for more details.
       
    14 * 
       
    15 * You should have received a copy of the GNU Lesser General Public License
       
    16 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
       
    17 */
       
    18 
       
    19 #ifndef DWARFDEFS_H_
       
    20 #define DWARFDEFS_H_
       
    21 
       
    22 //#include <libdwarf.h>
       
    23 /* to identify a cie */
       
    24 
       
    25 
       
    26 #define DW_CIE_ID 		~(0x0)
       
    27 #define DW_CIE_VERSION		1 /* DWARF2 */
       
    28 #define DW_CIE_VERSION3		3 /* DWARF3 */
       
    29 #define ABBREV_HASH_TABLE_SIZE	10
       
    30 
       
    31 typedef int                 Dwarf_Bool;     /* boolean type */
       
    32 //
       
    33 // Copyright (c) 2008 Symbian Software Ltd. All rights reserved.
       
    34 //
       
    35 
       
    36 typedef unsigned long long  Dwarf_Off;      /* 8 byte file offset */
       
    37 typedef unsigned long long  Dwarf_Unsigned; /* 8 byte unsigned value*/
       
    38 typedef unsigned short      Dwarf_Half;     /* 2 byte unsigned value */
       
    39 typedef unsigned char       Dwarf_Small;    /* 1 byte unsigned value */
       
    40 typedef signed   long long  Dwarf_Signed;   /* 8 byte signed value */
       
    41 typedef unsigned long long  Dwarf_Addr;     /* target memory address */
       
    42 
       
    43 typedef void*		Dwarf_Ptr;          /* host machine pointer */
       
    44 
       
    45 typedef unsigned long Dwarf_Word;
       
    46 typedef signed long Dwarf_Sword;
       
    47 
       
    48 typedef signed char Dwarf_Sbyte;
       
    49 typedef unsigned char Dwarf_Ubyte;
       
    50 typedef signed short Dwarf_Shalf;
       
    51 typedef Dwarf_Ubyte *Dwarf_Byte_Ptr;
       
    52 
       
    53 /* these 2 are fixed sizes which must not vary with the
       
    54 ** ILP32/LP64 model. Between these two, stay at 32 bit.
       
    55 */
       
    56 typedef unsigned int Dwarf_ufixed;
       
    57 typedef int Dwarf_sfixed;
       
    58 
       
    59 /*
       
    60         In various places the code mistakenly associates
       
    61         forms 8 bytes long with Dwarf_Signed or Dwarf_Unsigned
       
    62 	This is not a very portable assumption.
       
    63         The following should be used instead for 64 bit integers.
       
    64 */
       
    65 typedef unsigned long long Dwarf_ufixed64;
       
    66 typedef long long Dwarf_sfixed64;
       
    67 
       
    68 char * GetDwarfTag(Dwarf_Unsigned aTag);
       
    69 char * GetDwarfAttr(Dwarf_Half attr);
       
    70 char * GetDwarfForm(Dwarf_Half form);
       
    71 
       
    72 #define READ_UNALIGNED2(aPtr)ReadUnaligned2(aPtr)
       
    73 static inline Dwarf_Word ReadUnaligned2(Dwarf_Byte_Ptr aPtr){
       
    74 	Dwarf_Byte_Ptr p = aPtr;
       
    75 	return p[0] | (p[1] << 8); 
       
    76 }
       
    77 #define READ_UNALIGNED4(aPtr)ReadUnaligned4(aPtr)
       
    78 static inline Dwarf_Word ReadUnaligned4(Dwarf_Byte_Ptr aPtr){
       
    79 	Dwarf_Byte_Ptr p = aPtr;
       
    80 	return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24); 
       
    81 }
       
    82 #define WRITE_UNALIGNED2(aPtr, val)WriteUnaligned2(aPtr, val)
       
    83 static inline void WriteUnaligned2(Dwarf_Byte_Ptr aPtr, Dwarf_Word val){
       
    84 	Dwarf_Byte_Ptr p = aPtr;
       
    85 	p[0] = val & 0xff;
       
    86 	p[1] = (val >> 8) & 0xff;
       
    87 }
       
    88 
       
    89 #define WRITE_UNALIGNED4(aPtr, val)WriteUnaligned4(aPtr, val)
       
    90 static inline void WriteUnaligned4(Dwarf_Byte_Ptr aPtr, Dwarf_Word val){
       
    91 	Dwarf_Byte_Ptr p = aPtr;
       
    92 	p[0] = val & 0xff;
       
    93 	p[1] = (val >> 8) & 0xff;
       
    94 	p[2] = (val >> 16) & 0xff;
       
    95 	p[3] = (val >> 24) & 0xff;
       
    96 }
       
    97 
       
    98 #include <iostream>
       
    99 static inline Dwarf_Word GetValue(Dwarf_Byte_Ptr start, size_t size){
       
   100 	switch (size){
       
   101 	default:
       
   102 	case 0: {
       
   103 		std::cerr << "Error: size of " << size << " not allowed\n";
       
   104 		exit(EXIT_FAILURE);
       
   105 		}
       
   106 	case 2:
       
   107 		return READ_UNALIGNED2(start);
       
   108 	case 4:
       
   109 		return READ_UNALIGNED4(start);
       
   110 	case 8: {
       
   111 		std::cerr << "Error: 64 bit values not support yet\n";
       
   112 		exit(EXIT_FAILURE);		
       
   113 		}
       
   114 	}	
       
   115 }
       
   116 
       
   117 static inline void WriteValue(Dwarf_Byte_Ptr start, Dwarf_Word val, size_t size){
       
   118 	switch (size){
       
   119 	default:
       
   120 	case 0: {
       
   121 		std::cerr << "Error: size of " << size << " not allowed\n";
       
   122 		exit(EXIT_FAILURE);
       
   123 		}
       
   124 	case 2:
       
   125 		WRITE_UNALIGNED2(start, val);
       
   126 		break;
       
   127 	case 4:
       
   128 		WRITE_UNALIGNED4(start, val);
       
   129 		break;
       
   130 	case 8: {
       
   131 		std::cerr << "Error: 64 bit values not support yet\n";
       
   132 		exit(EXIT_FAILURE);		
       
   133 		}
       
   134 	}
       
   135 	
       
   136 }
       
   137 
       
   138 // TODO: for the moment just say 4 - we are dealing with 32 bit ARM for the foreseeable future
       
   139 // in the future we need to figure out where to get this from...
       
   140 #define ENCODED_POINTER_SIZE 4
       
   141 
       
   142 #endif /*DWARFDEFS_H_*/