U-boot-1.1.6-2008R1到vdsp5(bf561)的移植记录(10):__xchg

 
  
在u-boot-1.1.6-2008R1/include/asm/system.h中有这样一个函数:
static inline unsigned long __xchg(unsigned long x, volatile void *ptr,
                      int size)
{
     unsigned long tmp = 0;
     unsigned long flags = 0;
 
     local_irq_save(flags);
 
     switch (size) {
     case 1:
         __asm__ __volatile__
              ("%0 = b%2 (z);/n/t"
               "b%2 = %1;/n/t"
               : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
         break;
     case 2:
         __asm__ __volatile__
              ("%0 = w%2 (z);/n/t"
               "w%2 = %1;/n/t"
               : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
         break;
     case 4:
         __asm__ __volatile__
              ("%0 = %2;/n/t"
               "%2 = %1;/n/t"
               : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
         break;
     }
     local_irq_restore(flags);
     return tmp;
}
这个函数使用了内嵌汇编,移植时有几个问题:
1、%0=b%2(z),类似这样的语句,在VDSP下一解释就变成了
r0 = bp0(r0和p0的使用可能与实际值不同)
当然是明显的语法错误,所以应该修改为
%0 = b[%2] (z)
2、”m”,在VDSP中不支持”m”,由于此处需要使用P指针,所以相应地改为”a”或者”p”。
3、 (*__xg(ptr)) 直接用(ptr)就OK了。
这样,经过修改后的函数就成了:
static inline unsigned long __xchg(unsigned long x, volatile void *ptr,
                      int size)
{
     unsigned long tmp = 0;
     unsigned long flags = 0;
 
     local_irq_save(flags);
 
     switch (size) {
     case 1:
         __asm__ __volatile__
              ("%0 = b[%2] (z);/n/t"
               "b[%2] = %1;/n/t"
               : "=&d" (tmp) : "d" (x), "a" (ptr) : "memory");
         break;
     case 2:
         __asm__ __volatile__
              ("%0 = w[%2] (z);/n/t"
              "w[%2] = %1;/n/t"
               : "=&d" (tmp) : "d" (x), "a" (ptr) : "memory");
         break;
     case 4:
         __asm__ __volatile__
              ("%0 = %2;/n/t"
               "%2 = %1;/n/t"
               : "=&d" (tmp) : "d" (x), "a" (ptr) : "memory");
         break;
     }
     local_irq_restore(flags);
     return tmp;
}
不过经过这样修改之后,VDSP会给出一个警告:
[Warning ea5506] "C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/acc0ab0f1fc000/acc0ab0f1fc001.s":124 Memory load instruction use may trigger hardware anomaly 05-00-0227. See appropriate Blackfin anomaly lists for more information.
查了一下 anomaly 05-00-0227,是这样解释的
Enables workaround for anomaly 05-00-0257: “An interrupt or exception during short hardware loops may cause the instruction fetch unit to malfunction.” When enabled, the compiler saves and restores LC0 and LC1 in interrupt handlers.
The compiler defines the macro __WORKAROUND_SHORT_LOOP_EXCEPTIONS_257 at the compile, assembly, and link build stages when this workaround is enabled.
暂时还不太明白这其中的意思,不过比较了一下gcc生成的代码和VDSP生成的代码,两者是一样的,所以暂时搁置一下这个问题。
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

嵌云阁主

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值