1 /**************************** maindef.h **********************************
2 * Author: Agner Fog
3 * Date created: 2006-08-26
4 * Last modified: 2018-10-08
5 * Project: objconv
6 * Module: maindef.h
7 * Description:
8 * Header file for type definitions and other main definitions.
9 *
10 * Copyright 2006-2018 GNU General Public License http://www.gnu.org/licenses
11 *****************************************************************************/
12 #ifndef MAINDEF_H
13 #define MAINDEF_H
14
15 // Program version
16 #define OBJCONV_VERSION 2.52
17
18
19 // Integer type definitions with platform-independent sizes:
20 #include <limits.h>
21 #include <inttypes.h>
22 /*
23 #if defined(_I64_MAX)
24 // Microsoft compilers use __int64 etc
25 typedef char int8_t; // 8 bit signed integer
26 typedef unsigned char uint8_t; // 8 bit unsigned integer
27 typedef short int int16_t; // 16 bit signed integer
28 typedef unsigned short int uint16_t; // 16 bit unsigned integer
29 typedef int int32_t; // 32 bit signed integer
30 typedef unsigned int uint32_t; // 32 bit unsigned integer
31 typedef __int64 int64_t; // 64 bit signed integer
32 typedef unsigned __int64 uint64_t; // 64 bit unsigned integer
33
34 #elif defined(INT_MAX) && defined(LLONG_MAX) && INT_MAX==2147483647L && LLONG_MAX==9223372036854775807LL
35 // Compiler has int = 32 bit and long long = 64 bit
36 typedef char int8_t; // 8 bit signed integer
37 typedef unsigned char uint8_t; // 8 bit unsigned integer
38 typedef short int int16_t; // 16 bit signed integer
39 typedef unsigned short int uint16_t; // 16 bit unsigned integer
40 typedef int int32_t; // 32 bit signed integer
41 typedef unsigned int uint32_t; // 32 bit unsigned integer
42 typedef long long int64_t; // 64 bit signed integer
43 typedef unsigned long long uint64_t; // 64 bit unsigned integer
44
45 #else
46 // Compilers supporting C99 or C++0x or C++1x have inttypes.h defining these integer types
47 // This is the preferred solution:
48 #include <inttypes.h>
49 //typedef int8_t int8_t; // Gnu compiler can't convert int8_t to char
50 typedef char int8_t; // 8 bit signed integer
51 typedef uint8_t uint8_t; // 8 bit unsigned integer
52 typedef int16_t int16_t; // 16 bit signed integer
53 typedef uint16_t uint16_t; // 16 bit unsigned integer
54 typedef int32_t int32_t; // 32 bit signed integer
55 typedef uint32_t uint32_t; // 32 bit unsigned integer
56 typedef int64_t int64_t; // 64 bit signed integer
57 typedef uint64_t uint64_t; // 64 bit unsigned integer
58 #endif
59 */
60
61
62 // Get high part of a 64-bit integer
HighDWord(uint64_t x)63 static inline uint32_t HighDWord (uint64_t x) {
64 return (uint32_t)(x >> 32);
65 }
66
67 // Check if compiling for big-endian machine
68 // (__BIG_ENDIAN__ may not be defined even on big endian systems, so this check is not
69 // sufficient. A further check is done in CheckEndianness() in main.cpp)
70 #if defined(__BIG_ENDIAN__) && (__BIG_ENDIAN__ != 4321)
71 #error This machine has big-endian memory organization. Objconv program will not work
72 #endif
73
74 // Max file name length
75 #define MAXFILENAMELENGTH 256
76
77
78 // File types
79 #define FILETYPE_COFF 1 // Windows COFF/PE file
80 #define FILETYPE_OMF 2 // Windows OMF file
81 #define FILETYPE_ELF 3 // Linux or BSD ELF file
82 #define FILETYPE_MACHO_LE 4 // Mach-O file, little endian
83 #define FILETYPE_MACHO_BE 5 // Mach-O file, big endian
84 #define FILETYPE_DOS 6 // DOS file
85 #define FILETYPE_WIN3X 7 // Windows 3.x file
86 #define IMPORT_LIBRARY_MEMBER 0x10 // Member of import library, Windows
87 #define FILETYPE_MAC_UNIVBIN 0x11 // Macintosh universal binary
88 #define FILETYPE_MS_WPO 0x20 // Object file for whole program optimization, MS
89 #define FILETYPE_INTEL_WPO 0x21 // Object file for whole program optimization, Intel
90 #define FILETYPE_WIN_UNKNOWN 0x29 // Unknown subtype, Windows
91 #define FILETYPE_ASM 0x100 // Disassembly output
92 #define FILETYPE_LIBRARY 0x1000 // UNIX-style library/archive
93 #define FILETYPE_OMFLIBRARY 0x2000 // OMF-style library
94
95 // Library subtypes
96 #define LIBTYPE_OMF 0x01 // OMF library
97 #define LIBTYPE_SHORTNAMES 0x10 // Short member names only, compatible with all systems
98 #define LIBTYPE_WINDOWS 0x11 // Long member names in "//" member, terminated by 0
99 #define LIBTYPE_LINUX 0x12 // Long member names in "//" member, terminated by '/'+LF
100 #define LIBTYPE_BSD_MAC 0x13 // Long member name after header. Length indicated by #1/<length>
101
102 // Define constants for symbol scope
103 #define S_LOCAL 0 // Local symbol. Accessed only internally
104 #define S_PUBLIC 1 // Public symbol. Visible from other modules
105 #define S_EXTERNAL 2 // External symbol. Defined in another module
106
107
108 // Macro to calculate the size of an array
109 #define TableSize(x) ((int)(sizeof(x)/sizeof(x[0])))
110
111
112 // Structures and functions used for lookup tables:
113
114 // Structure of integers and char *, used for tables of text strings
115 struct SIntTxt {
116 uint32_t a;
117 const char * b;
118 };
119
120 // Translate integer value to text string by looking up in table of SIntTxt.
121 // Parameters: p = table, n = length of table, x = value to find in table
LookupText(SIntTxt const * p,int n,uint32_t x)122 static inline char const * LookupText(SIntTxt const * p, int n, uint32_t x) {
123 for (int i=0; i<n; i++, p++) {
124 if (p->a == x) return p->b;
125 }
126 // Not found
127 static char utext[32];
128 sprintf(utext, "unknown(0x%X)", x);
129 return utext;
130 }
131
132 // Macro to get length of text list and call LookupText
133 #define Lookup(list,x) LookupText(list, sizeof(list)/sizeof(list[0]), x)
134
135
136 // Function to convert powers of 2 to index
137 int FloorLog2(uint32_t x);
138
139 // Convert 32 bit time stamp to string
140 const char * timestring(uint32_t t);
141
142 #endif // #ifndef MAINDEF_H
143