OpenCores
URL https://opencores.org/ocsvn/forwardcom/forwardcom/trunk

Subversion Repositories forwardcom

[/] [forwardcom/] [bintools/] [maindef.h] - Blame information for rev 160

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 37 Agner
/****************************  maindef.h   **********************************
2
* Author:        Agner Fog
3
* Date created:  2017-04-17
4
* Last modified: 2021-07-10
5
* Version:       1.11
6
* Project:       Binary tools for ForwardCom instruction set
7
* Module:        maindef.h
8
* Original location: https://github.com/forwardcom/binutils
9
* License: GPL-3.0. https://www.gnu.org/licenses/#GPL
10
* Copyright 2016-2021 by Agner Fog
11
*
12
* Description:
13
* Header file for type definitions and other main definitions.
14
*****************************************************************************/
15
#pragma once 
16
 
17
// Program version
18
#define FORWARDCOM_VERSION         1
19
#define FORWARDCOM_SUBVERSION      11
20
 
21
 
22
// Get high part of a 64-bit integer
23
static inline uint32_t highDWord (uint64_t x) {
24
   return (uint32_t)(x >> 32);
25
}
26
 
27
// Check if compiling on big-endian machine 
28
// (__BIG_ENDIAN__ may not be defined even on big endian systems, so this check is not 
29
// sufficient. A further check is done in CheckEndianness() in main.cpp)
30
#if defined(__BIG_ENDIAN__) && (__BIG_ENDIAN__ != 4321)
31
   #error This machine has big-endian memory organization. Program will not work
32
#endif
33
 
34
// Max file name length
35
const int MAXFILENAMELENGTH =       256;
36
 
37
// File types 
38
const int FILETYPE_ELF =              3;         // x86 ELF file
39
const int FILETYPE_FWC =           0x10;         // ForwardCom ELF file
40
const int FILETYPE_FWC_EXE =       0x11;         // Executable ForwardCom ELF file
41
const int FILETYPE_FWC_LIB =       0x20;         // ForwardCom library file
42
const int FILETYPE_FWC_HEX =       0x40;         // Executable code in hexadecimal format for loader ROM
43
const int FILETYPE_ASM =          0x100;         // Disassembly output
44
const int FILETYPE_LIBRARY =     0x1000;         // UNIX-style library/archive
45
 
46
 
47
// Define constants for symbol scope
48
const int S_LOCAL =    0;                        // Local symbol. Accessed only internally
49
const int S_PUBLIC =   1;                        // Public symbol. Visible from other modules
50
const int S_EXTERNAL = 2;                        // External symbol. Defined in another module
51
 
52
 
53
// Macro to calculate the size of an array
54
#define TableSize(x) ((int)(sizeof(x)/sizeof(x[0])))
55
 
56
// template to zero all elements of an object
57
template <typename T>
58
void zeroAllMembers(T & x) {
59
    memset(&x, 0, sizeof(T));
60
}
61
 
62
// Structures and functions used for lookup tables:
63
 
64
// Structure of integers and char *, used for tables of text strings
65
struct SIntTxt {
66
   uint32_t a;
67
   const char * b;
68
};
69
 
70
// Translate integer value to text string by looking up in table of SIntTxt.
71
// Parameters: p = table, n = length of table, x = value to find in table
72
static inline char const * lookupText(SIntTxt const * p, int n, uint32_t x) {
73
   for (int i=0; i<n; i++, p++) {
74
      if (p->a == x) return p->b;
75
   }
76
   // Not found
77
   static char utext[32];
78
   sprintf(utext, "unknown(0x%X)", x);
79
   return utext;
80
}
81
 
82
// Macro to get length of text list and call LookupText
83
#define Lookup(list,x)  lookupText(list, sizeof(list)/sizeof(list[0]), x)
84
 
85
// Bit scan reverse. Returns floor(log2(x)), 0 if x = 0
86
uint32_t bitScanReverse(uint64_t x);
87
 
88
// // Bit scan forward. Returns index to the lowest set bit, 0 if x = 0
89
uint32_t bitScanForward(uint64_t x);
90
 
91
// Convert 32 bit time stamp to string
92
const char * timestring(uint32_t t);
93
 
94
// Convert half precision floating point number to single precision
95
float half2float(uint32_t half, bool supportSubnormal = true);
96
 
97
// Convert floating point number to half precision
98
uint16_t float2half(float x, bool supportSubnormal = true);
99
uint16_t double2half(double x, bool supportSubnormal = true);

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.