Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1615433
  • 博文数量: 197
  • 博客积分: 10046
  • 博客等级: 上将
  • 技术积分: 1983
  • 用 户 组: 普通用户
  • 注册时间: 2006-08-07 12:36
个人简介

在外企做服务器开发, 目前是项目经理, 管理两个server开发的项目。不做嵌入式好久了。

文章分类
文章存档

2011年(2)

2010年(6)

2009年(18)

2008年(30)

2007年(100)

2006年(41)

分类: LINUX

2007-12-18 21:40:08

 
 
*( (unsigned short *)block_base_address) = (unsigned short)(0x20);
*( (unsigned short *)block_base_address) = (unsigned short)(0xd0);


请问 , 编译器会把上面两条命令优化成一条执行吗?
我用MultiICE 仿真器调试, 仅仅会执行 *( (unsigned short *)block_base_address) = (unsigned short)(0xd0); 这句, 而 上面那句恰恰是最关键的。


我的编译选项: -Os 和 -O都试验过了, nor flash 擦除都没有正常工作。



我用的编译器是 eldk4.0里面arm-linux-gcc


[root@bobzhanglinux u-boot-1.2.0-ixdk0015]# arm-linux-gcc -v
Reading specs from /opt/eldk-4.1/usr/bin/../lib/gcc/arm-linux/4.0.0/specs
Target: arm-linux
Configured with: /opt/eldk/build/arm-2007-01-21/work/usr/src/denx/BUILD/crosstool-0.35/build/gcc-4.0.0-glibc-2.3.5-eldk/arm-linux/gcc-4.0.0/configure --target=arm-linux --host=i686-host_pc-linux-gnu --prefix=/var/tmp/eldk.bMi2nK/usr/crosstool/gcc-4.0.0-glibc-2.3.5-eldk/arm-linux --with-headers=/var/tmp/eldk.bMi2nK/usr/crosstool/gcc-4.0.0-glibc-2.3.5-eldk/arm-linux/arm-linux/include --with-local-prefix=/var/tmp/eldk.bMi2nK/usr/crosstool/gcc-4.0.0-glibc-2.3.5-eldk/arm-linux/arm-linux --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-languages=c,c++ --enable-shared --enable-c99 --enable-long-long --enable-__cxa_atexit
Thread model: posix
gcc version 4.0.0 (DENX ELDK 4.1 4.0.0)

+++++++++++++++++
 
经过试验:

我发现
-g -Os
-g -O2
-g -O 都优化了代码 , 两行变成一行了。

倒是 -g 后面什么都不加 , 就没有优化了。 两行还是两行。

我想请问 对于 gcc -g main.c -o main.o 默认是编译选项呢?


另外, 对于 u-boot 默认就是 -g -Os , 我不想因为一个c文件 而影响其他的文件, gcc 可否有什么扩展语法, 专门 来禁止优化 下面这两句
*( (unsigned short *)block_base_address) = (unsigned short)(0x20);
*( (unsigned short *)block_base_address) = (unsigned short)(0xd0);
这样的代码, 或者有别的什么办法吗?

----------------------------
我这两行代码是用来擦除nor flash的sector的,

*( (unsigned short *)block_base_address) = (unsigned short)(0x20);
*( (unsigned short *)block_base_address) = (unsigned short)(0xd0);
是标准的做法 , 用armcc 编译,运行就没有问题 。

另外, 我想到个办法:
在两句之间加上其他的语句,
比如:*( (unsigned short *)block_base_address) = (unsigned short)(0x20);
//其他的无关的语句:
printf(“%#04lx\n",*( (unsigned short *)block_base_address) );
*( (unsigned short *)block_base_address) = (unsigned short)(0xd0);

但是这样根据datasheet 还能工作了吗?




阅读(2821) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~