Skip to content
This repository was archived by the owner on Jun 5, 2019. It is now read-only.

Fixes issues with endian macros (in GCC) #483

Closed
wants to merge 8 commits into from
10 changes: 5 additions & 5 deletions Application/TinyBooter/Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ bool Loader_Engine::ProcessPayload( WP_Message* msg )
LOADER_ENGINE_SETFLAG( this, c_LoaderEngineFlag_ValidConnection );

//--//
#if defined(BIG_ENDIAN)
#if defined(NETMF_TARGET_BIG_ENDIAN)
SwapEndian( msg, msg->m_payload, msg->m_header.m_size, false );
#endif
size_t num;
Expand Down Expand Up @@ -1120,7 +1120,7 @@ bool Loader_Engine::TransmitMessage( const WP_Message* msg, bool fQueue )
UINT32 payloadSize;
UINT32 flags;

#if !defined(BIG_ENDIAN)
#if !defined(NETMF_TARGET_BIG_ENDIAN)
payloadSize = msg->m_header.m_size;
flags = msg->m_header.m_flags;
#else
Expand Down Expand Up @@ -1178,7 +1178,7 @@ void Loader_Engine::ReplyToCommand( WP_Message* msg, bool fSuccess, bool fCritic

msgReply.Initialize( &m_controller );

#if defined(BIG_ENDIAN)
#if defined(NETMF_TARGET_BIG_ENDIAN)
SwapEndian( msg, ptr, size, true );
#endif
msgReply.PrepareReply( msg->m_header, flags, size, (UINT8*)ptr );
Expand All @@ -1203,7 +1203,7 @@ bool Loader_Engine::Monitor_Ping( WP_Message* msg )
CLR_DBG_Commands::Monitor_Ping::Reply cmdReply;
cmdReply.m_source = CLR_DBG_Commands::Monitor_Ping::c_Ping_Source_TinyBooter;

#if defined(BIG_ENDIAN)
#if defined(NETMF_TARGET_BIG_ENDIAN)
cmdReply.m_dbg_flags = CLR_DBG_Commands::Monitor_Ping::c_Ping_DbgFlag_BigEndian;
#endif

Expand Down Expand Up @@ -1587,7 +1587,7 @@ bool Loader_Engine::Monitor_FlashSectorMap( WP_Message* msg )
return true;
}

#if defined(BIG_ENDIAN)
#if defined(NETMF_TARGET_BIG_ENDIAN)

UINT32 Loader_Engine::SwapEndianPattern( UINT8* &buffer, UINT32 size, UINT32 count )
{
Expand Down
2 changes: 1 addition & 1 deletion Application/TinyBooter/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ struct Loader_Engine
bool Monitor_SignatureKeyUpdate( WP_Message* msg );
bool EnumerateAndLaunch ( );

#if defined(BIG_ENDIAN)
#if defined(NETMF_TARGET_BIG_ENDIAN)
public:
void SwapDebuggingValue ( UINT8* &msg, UINT32 size );
void SwapEndian ( WP_Message* msg, void* ptr, int size, bool fReply );
Expand Down
8 changes: 4 additions & 4 deletions CLR/Core/CLR_RT_HeapBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ HRESULT CLR_RT_HeapBlock::LoadFromReference( CLR_RT_HeapBlock& ref )
else if(size == 1) { first = ((CLR_UINT8 *)src)[ 0 ]; }
else { first = ((CLR_UINT16*)src)[ 0 ]; }

#if !defined(BIG_ENDIAN)
#if !defined(NETMF_TARGET_BIG_ENDIAN)
((CLR_UINT32*)&NumericByRef())[ 0 ] = first;
((CLR_UINT32*)&NumericByRef())[ 1 ] = second;
#else
Expand All @@ -403,7 +403,7 @@ HRESULT CLR_RT_HeapBlock::LoadFromReference( CLR_RT_HeapBlock& ref )
((CLR_UINT32*)&NumericByRef())[ 0 ] = second;
((CLR_UINT32*)&NumericByRef())[ 1 ] = first;
}
#endif //BIG_ENDIAN
#endif //NETMF_TARGET_BIG_ENDIAN

TINYCLR_SET_AND_LEAVE(S_OK);
}
Expand Down Expand Up @@ -531,7 +531,7 @@ HRESULT CLR_RT_HeapBlock::StoreToReference( CLR_RT_HeapBlock& ref, int size )
}
}

#if !defined(BIG_ENDIAN)
#if !defined(NETMF_TARGET_BIG_ENDIAN)
CLR_UINT32 first = ((CLR_UINT32*)&obj->NumericByRef())[ 0 ];
CLR_UINT32 second = ((CLR_UINT32*)&obj->NumericByRef())[ 1 ];
#else
Expand All @@ -548,7 +548,7 @@ HRESULT CLR_RT_HeapBlock::StoreToReference( CLR_RT_HeapBlock& ref, int size )
first = ((CLR_UINT32*)&obj->NumericByRef())[ 1 ];
second = ((CLR_UINT32*)&obj->NumericByRef())[ 0 ];
}
#endif //BIG_ENDIAN
#endif //NETMF_TARGET_BIG_ENDIAN

if (sizeArray == 4) { ((CLR_UINT32*)dst)[ 0 ] = (CLR_UINT32)first; }
else if(sizeArray == 8) { ((CLR_UINT32*)dst)[ 0 ] = (CLR_UINT32)first; ((CLR_UINT32*)dst)[ 1 ] = (CLR_UINT32)second; }
Expand Down
2 changes: 1 addition & 1 deletion CLR/Core/CLR_RT_HeapBlock_Array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ HRESULT CLR_RT_HeapBlock_Array::IndexOf( CLR_RT_HeapBlock_Array* array, CLR_RT_H

while(true)
{
#if !defined(BIG_ENDIAN)
#if !defined(NETMF_TARGET_BIG_ENDIAN)
if(memcmp( data, &matchPtr->NumericByRef(), sizeElem ) == 0)
{
index = pos;
Expand Down
2 changes: 1 addition & 1 deletion CLR/Core/Execution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3067,7 +3067,7 @@ void CLR_RT_ExecutionEngine::StopOnBreakpoint( CLR_DBG_Commands::Debugging_Execu

if(m_breakpointsActiveNum == 1)
{
#if defined(BIG_ENDIAN)
#if defined(NETMF_TARGET_BIG_ENDIAN)
static CLR_DBG_Commands::Debugging_Execution_BreakpointDef s_breakpoint;
CLR_UINT8* data;

Expand Down
2 changes: 1 addition & 1 deletion CLR/Core/Serialization/BinaryFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1635,7 +1635,7 @@ HRESULT CLR_RT_BinaryFormatter::State::AdvanceToTheNextElement()
{
TINYCLR_CHECK_HRESULT(m_parent->ReadBits( val, bits ));

#if !defined(BIG_ENDIAN)
#if !defined(NETMF_TARGET_BIG_ENDIAN)
memcpy( ptr, &val, size );
#else
memcpy( ptr, ((unsigned char*)&val)+(sizeof(val)-size), size );
Expand Down
2 changes: 1 addition & 1 deletion CLR/Core/Streams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ HRESULT CLR_RT_HeapBlock_MemoryStream::ReadBits( CLR_UINT64& res, CLR_UINT32 bit

CLR_UINT32* ptr = (CLR_UINT32*)&res;

#if !defined(BIG_ENDIAN)
#if !defined(NETMF_TARGET_BIG_ENDIAN)
if(bits > 32) { TINYCLR_CHECK_HRESULT(ReadBits( ptr[ 1 ], bits - 32 )); bits = 32; }
else { ptr[ 1 ] = 0; }

Expand Down
4 changes: 2 additions & 2 deletions CLR/Core/TypeSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@ bool CLR_RECORD_ASSEMBLY::GoodHeader() const
NATIVE_PROFILE_CLR_CORE();
CLR_RECORD_ASSEMBLY header = *this; header.headerCRC = 0;

#if !defined(BIG_ENDIAN)
#if !defined(NETMF_TARGET_BIG_ENDIAN)
if ( (header.flags & CLR_RECORD_ASSEMBLY::c_Flags_BigEndian) == CLR_RECORD_ASSEMBLY::c_Flags_BigEndian)
#else
if ( (header.flags & CLR_RECORD_ASSEMBLY::c_Flags_BigEndian) != CLR_RECORD_ASSEMBLY::c_Flags_BigEndian)
Expand Down Expand Up @@ -4430,7 +4430,7 @@ HRESULT CLR_RT_AttributeParser::Next( Value*& res )
CLR_UINT32 size = (dtl.m_sizeInBits + 7) / 8;

// FIXME GJS - the numeric values, what is their endiannes??? In the MSTV code there is a BIG endian fix but it looks like it will not work, so was it ever used?
#if !defined(BIG_ENDIAN)
#if !defined(NETMF_TARGET_BIG_ENDIAN)
memcpy( &m_lastValue.m_value.NumericByRef(), m_blob, size ); m_blob += size;
#else
switch(size)
Expand Down
4 changes: 2 additions & 2 deletions CLR/Debugger/Debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ bool CLR_DBG_Debugger::Monitor_Ping( WP_Message* msg, void* owner )

cmdReply.m_source = CLR_DBG_Commands::Monitor_Ping::c_Ping_Source_TinyCLR;

#if !defined(BIG_ENDIAN)
#if !defined(NETMF_TARGET_BIG_ENDIAN)
cmdReply.m_dbg_flags = CLR_EE_DBG_IS(State_ProgramExited) != 0 ? CLR_DBG_Commands::Monitor_Ping::c_Ping_DbgFlag_AppExit : 0;
#else
cmdReply.m_dbg_flags = CLR_DBG_Commands::Monitor_Ping::c_Ping_DbgFlag_BigEndian;
Expand Down Expand Up @@ -1432,7 +1432,7 @@ static bool FillValues( CLR_RT_HeapBlock* ptr, CLR_DBG_Commands::Debugging_Value
// Primitives or optimized value types.
//

#if !defined(BIG_ENDIAN)
#if !defined(NETMF_TARGET_BIG_ENDIAN)
memcpy( dst->m_builtinValue, (void*)&ptr->NumericByRefConst().u1, 8 );
#else
{
Expand Down
2 changes: 1 addition & 1 deletion CLR/Include/TinyCLR_Messaging.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ struct CLR_Messaging
static bool Messaging_Send__Reply ( WP_Message* msg, void* owner );
static bool Messaging_Reply ( WP_Message* msg, void* owner );
static bool Messaging_Reply__Reply ( WP_Message* msg, void* owner );
#if defined(BIG_ENDIAN)
#if defined(NETMF_TARGET_BIG_ENDIAN)
public:
static void SwapDebuggingValue ( UINT8* &msg, UINT32 size );
static void SwapEndian ( WP_Message* msg, void* ptr, int size, bool fReply );
Expand Down
4 changes: 2 additions & 2 deletions CLR/Include/TinyCLR_PlatformDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <CLR_Defines.h>

#ifdef _WIN32
#define LITTLE_ENDIAN
#define NETMF_TARGET_LITTLE_ENDIAN
#endif

////////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -32,7 +32,7 @@
#endif

#if !defined(PLATFORM_WINDOWS_EMULATOR) && !defined(PLATFORM_WINCE)
#if !defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN)
#if !defined(NETMF_TARGET_LITTLE_ENDIAN) && !defined(NETMF_TARGET_BIG_ENDIAN)
#error ENDIANNESS NOT DEFINED
#endif
#endif
Expand Down
30 changes: 15 additions & 15 deletions CLR/Include/TinyCLR_Runtime__HeapBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#endif

////////////////////////////////////////////////////////////////////////////////////////////////////
#if !defined(BIG_ENDIAN)
#if !defined(NETMF_TARGET_BIG_ENDIAN)

#define CLR_RT_HEAPBLOCK_RAW_ID( dataType, flags, size ) ( (dataType & 0x000000FF) | ((flags & 0x000000FF) << 8) | ((size & 0x0000FFFF) << 16))
#define CLR_RT_HEAPBLOCK_ASSIGN_INTEGER32_SIGNED( dataType, num ) { m_id.raw = CLR_RT_HEAPBLOCK_RAW_ID( dataType, 0, 1 ); m_data.numeric.s4 = (CLR_INT32)num; }
Expand All @@ -23,7 +23,7 @@
#define CLR_RT_HEAPBLOCK_ASSIGN_FLOAT32(dataType,num) { m_id.raw = CLR_RT_HEAPBLOCK_RAW_ID( dataType, 0, 1 ); m_data.numeric.r4 = num; }
#define CLR_RT_HEAPBLOCK_ASSIGN_FLOAT64(dataType,num) { m_id.raw = CLR_RT_HEAPBLOCK_RAW_ID( dataType, 0, 1 ); m_data.numeric.r8 = num; }

#else // BIG_ENDIAN
#else // NETMF_TARGET_BIG_ENDIAN

#define CLR_RT_HEAPBLOCK_RAW_ID( dataType, flags, size ) ( (size & 0x0000FFFF) | ((flags & 0x000000FF) << 16) | ((dataType & 0x000000FF) << 24))
#define CLR_RT_HEAPBLOCK_ASSIGN_INTEGER32_SIGNED( dataType, num ) { m_id.raw = CLR_RT_HEAPBLOCK_RAW_ID( dataType, 0, 1 ); m_data.numeric.padS4 = 0; m_data.numeric.s4 = (CLR_INT32)num; }
Expand All @@ -35,7 +35,7 @@
#define CLR_RT_HEAPBLOCK_ASSIGN_FLOAT32( dataType, num ) { m_id.raw = CLR_RT_HEAPBLOCK_RAW_ID( dataType, 0, 1 ); m_data.numeric.padR4 = 0; m_data.numeric.r4 = num; }
#define CLR_RT_HEAPBLOCK_ASSIGN_FLOAT64( dataType, num ) { m_id.raw = CLR_RT_HEAPBLOCK_RAW_ID( dataType, 0, 1 ); m_data.numeric.r8 = num; }

#endif // BIG_ENDIAN
#endif // NETMF_TARGET_BIG_ENDIAN

////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -147,7 +147,7 @@ struct CLR_RT_HeapBlock

union Numeric
{
#if !defined(BIG_ENDIAN)
#if !defined(NETMF_TARGET_BIG_ENDIAN)
CLR_UINT8 u1;
CLR_UINT16 u2;
CLR_UINT32 u4;
Expand All @@ -158,7 +158,7 @@ struct CLR_RT_HeapBlock
#endif
struct U8
{
#if !defined(BIG_ENDIAN)
#if !defined(NETMF_TARGET_BIG_ENDIAN)
CLR_UINT32 _L;
CLR_UINT32 _H;
//--//
Expand Down Expand Up @@ -293,7 +293,7 @@ struct CLR_RT_HeapBlock

} u8;
//
#if !defined(BIG_ENDIAN)
#if !defined(NETMF_TARGET_BIG_ENDIAN)
CLR_INT8 s1;
CLR_INT16 s2;
CLR_INT32 s4;
Expand All @@ -304,7 +304,7 @@ struct CLR_RT_HeapBlock
#endif
struct S8
{
#if !defined(BIG_ENDIAN)
#if !defined(NETMF_TARGET_BIG_ENDIAN)
CLR_UINT32 _L;
CLR_UINT32 _H;
//--//
Expand Down Expand Up @@ -445,14 +445,14 @@ struct CLR_RT_HeapBlock

#if !defined(TINYCLR_EMULATED_FLOATINGPOINT)

#if !defined(BIG_ENDIAN)
#if !defined(NETMF_TARGET_BIG_ENDIAN)
float r4;
#else
struct { CLR_UINT32 padR4; float r4; };
#endif
struct R8
{
#if !defined(BIG_ENDIAN)
#if !defined(NETMF_TARGET_BIG_ENDIAN)
CLR_UINT32 _L;
CLR_UINT32 _H;
#else
Expand All @@ -464,7 +464,7 @@ struct CLR_RT_HeapBlock
{
double ret_val;

#if !defined(BIG_ENDIAN)
#if !defined(NETMF_TARGET_BIG_ENDIAN)
#if defined(__GNUC__)
///
/// This code fixes an optimization problem with the gcc compiler.
Expand Down Expand Up @@ -525,7 +525,7 @@ struct CLR_RT_HeapBlock

R8& operator=( const double num )
{
#if !defined(BIG_ENDIAN)
#if !defined(NETMF_TARGET_BIG_ENDIAN)
#if defined(__GNUC__)
///
/// This code fixes an optimization problem with the gcc compiler.
Expand Down Expand Up @@ -649,7 +649,7 @@ struct CLR_RT_HeapBlock
#else
/// not using floating point lib, emulated one

#if defined(BIG_ENDIAN)
#if defined(NETMF_TARGET_BIG_ENDIAN)
CLR_UINT32 padR4;
#endif

Expand Down Expand Up @@ -705,7 +705,7 @@ struct CLR_RT_HeapBlock

struct R8
{
#if !defined(BIG_ENDIAN)
#if !defined(NETMF_TARGET_BIG_ENDIAN)
CLR_UINT32 _L;
CLR_UINT32 _H;
//--//
Expand Down Expand Up @@ -833,7 +833,7 @@ struct CLR_RT_HeapBlock
// MemLE: DDCCBBAA
// So for LE DD,Addr 00 is the low byte.
// For BE it is certainly not true, hence this check will not work. Will Interop? FIXME GJS - verify interop
#if !defined(BIG_ENDIAN)
#if !defined(NETMF_TARGET_BIG_ENDIAN)
CT_ASSERT_UNIQUE_NAME( offsetof( Numeric, s1 ) == 0, s1 )
CT_ASSERT_UNIQUE_NAME( offsetof( Numeric, s2 ) == 0, s2 )
CT_ASSERT_UNIQUE_NAME( offsetof( Numeric, s4 ) == 0, s4 )
Expand Down Expand Up @@ -1078,7 +1078,7 @@ struct CLR_RT_HeapBlock
}

//--//
#if !defined(BIG_ENDIAN)
#if !defined(NETMF_TARGET_BIG_ENDIAN)
const CLR_RT_HeapBlock_AtomicData& DataByRefConst() const { return m_data; }
#else
const CLR_RT_HeapBlock_AtomicData& DataByRefConst() const
Expand Down
Loading