问题:不能在shell上输入浮点数,例如计算一个浮点数据的log,在shell上操作总是不正确。
答复:这是一个很老的问题,windriver有一个案例可以参考。
Problem Description
When trying to print of a floating point value from the shell on any hawdware architecture that passes floating point values in floating point registers, the result is not correct.
The target-resident shell does not contain any logic to support writing to floating point registers, and assumes that all parameters are of type int. Note that in vxWorks, pointers and int's are the same size (32-bits) and use the same registers, so passing pointers works fine.
The host-based shell uses the WDB agent to pass arguments to the target. When calling a function, the WDB_FUNC_CALL service is invoked. The WDB_FUNC_CALL services only passes integer parameters to target routines. Floats are currently passed by packing them into integers and passing them as ints. This works OK for architectures
that pass floats and ints the same way (68k, x86, sparc), but fails if
there is a different parameter passing mechanism for floats (Power PC,
MIPS, PA-risc).
Problem Solution
Calling printf from a compiled module works as desired. If you need to print floating point values from the shell, you can compile and download the following function:
void printfloat( float *pf )
{
printf( "%f\n", *pf );
}
Then from the shell, call:
> printFloat &fp_value
This passes the address of the floating-point value to printFloat (which always works) and the compiled code de-references the value and passes it to printf correctly based on processor architecture.
阅读(1209) | 评论(0) | 转发(0) |