Chinaunix首页 | 论坛 | 博客
  • 博客访问: 562123
  • 博文数量: 169
  • 博客积分: 2656
  • 博客等级: 少校
  • 技术积分: 1685
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-30 13:03
文章分类

全部博文(169)

文章存档

2011年(1)

2010年(135)

2009年(33)

我的朋友

分类: 嵌入式

2010-05-14 13:24:36

问题:不能在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.
阅读(1117) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~