On a fresh built SAM9261 Port and a new .NetMF Hello World Project we want
to run the following code:
public static void Main()
{
Double dblvar = 3.3d;
float fltvar = 4.4f;
while (true)
{
Debug.Print("Double: " + dblvar.ToString() + ", Float: " +
fltvar.ToString());
Thread.Sleep(1000);
}
}
and get the following result on the debug console:
Double: 3.63395408954883248e-313, Float: 4.400000096
The code runs fine on the emulator so the problem has to be in the port. Has
anyone else encountered this problem?
We could also use float values but for some reason there is no float.Parse
function.
Where could we look for clues on how to solve this issue?
greetings, Martin
we had a similar problem in the past and it had to do with un-aligned stack
access.
Align the StackTop and StackBottom global variables in your scatterfile (xml
file under the solutions directory) to the 8 bytes boundary.
Regards
Lorenzo
thanks for the quick reply!
Stack_Bottom and Stack_Top are defined as:
<Set Name="Stack_Bottom" Value="0x00326000"/>
<Set Name="Stack_Top" Value="0x00327FF8"/>
the size of the Stack is defined further down as Size="%Stack_Top -
Stack_Bottom% + 4"/>
I´ve changed the Top to 0x0023 8000 and played around with the size by
adding zero or 8.
but none of these changes helped me. i´ve tried some debug messages in
tinybooter and they print out okay, i guess the same goes for tinyCLR but
haven´t testet a output of doubles there.
We had a similar issue with .net Longs and aligning the TinyCLR stack to an
8 byte boundry as Lorenzo suggested did fix it.
-Armand
I´ve tried to change the base adress of Stack_Top to 0x0032 8000 which looks
pretty byte aligned to me.
i´ve also added the Align option in the ExecRegion definition altough i´m
not sure if this will change anything:
<ExecRegion Name="ER_STACK_BOTTOM" Align="0x08" Base="%Stack_Bottom%">
<FileMapping Name="*" Options="(SectionForStackBottom)" />
</ExecRegion>
<ExecRegion Name="ER_STACK_TOP" Align="0x08" Base="%Stack_Top%">
<FileMapping Name="*" Options="(SectionForStackTop)" />
</ExecRegion>
am i missing something here?
operator double() const
{
/*
* These loops
were added to defeat a compiler
* optimization
in GCC 4.2 in the '-O2' or higher
* optimization
mode. It was not properly copying
* the data to
the returned value.
*/
double ret_val;
char* tmp = (char*)&ret_val;
char* src =
(char*)&_L;
for(int i = 0; i
< 4; i++)
{
tmp
[i] = src[i];
}
src = (char*)&_H;
for(int i = 0; i
< 4; i++)
{
tmp
[i+4] = src[i];
}
return ret_val;
}
...
R8& operator=( const double num )
{
/* See comments
for double() operator */
char* src =
(char*)#
char* tmp =
(char*)&_L;
for(int i = 0; i
< 4; i++)
{
tmp
[i] = src[i];
}
tmp = (char*)&_H;
for(int i = 0; i
< 4; i++)
{
tmp
[i] = src[i+4];
}
return *this;
}
This solved the problems for me. Hope it helps you as well.
Andreas, AUG Elektronik GmbH