在移植汇编代码时,VDSP中的分号造成了一些小困扰,但是相比之下,C中嵌入汇编引起的问题则要隐蔽得多,如cpu/blackfin/reset.c中的函数:
__attribute__ ((__l1_text__, __noreturn__))
void bfin_reset(void)
{
while (1) {
/* No idea why this is needed, but with out this, the ssync()
* after SWRST = 0x0 will hang indefinitely ...
*/
__builtin_bfin_ssync();
/* Initiate system software reset of peripherals */
bfin_write_SWRST(0x7);
/* Due to the way reset is handled in the hardware, we need
* to delay for 5 SCLKS. The only reliable way to do this is
* to calculate the CCLK/SCLK ratio and multiply 5. For now,
* we'll assume worse case which is a 1:15 ratio.
*/
asm(
"LSETUP (.Lreset_nops,.Lreset_nops) LC0 = %0/n"
".Lreset_nops: nop;"
:
: "a" (15 * 5)
: "LC0", "LB0", "LT0"
);
/* Clear system software reset */
bfin_write_SWRST(0);
__builtin_bfin_ssync();
/* Issue core reset */
asm("raise 1");
}
}
这里有两行的嵌入汇编,当在VDSP下编译时,它的提示信息为:
[Error ea5004] "C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/acc0a74df1e000/acc0a74df1e001.s":59 Syntax Error in :
.Lreset_nops: nop;
syntax error is at or near text '.Lreset_nops'.
Attempting error recovery by ignoring text until the ';'
[Error ea5004] "C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/acc0a74df1e000/acc0a74df1e001.s":79 Syntax Error in :
.LN7:
syntax error is at or near text '.LN7'.
Attempting error recovery by ignoring text until the ';'
Previous errors prevent assembly
第一个错误提示还好点,第二个提示就让人不知所云了。实际上,这两个错误都是由嵌入汇编中一个小小的分号引起的,修改后的代码如下:
__attribute__ ((__l1_text__, __noreturn__))
void bfin_reset(void)
{
while (1) {
/* No idea why this is needed, but with out this, the ssync()
* after SWRST = 0x0 will hang indefinitely ...
*/
__builtin_bfin_ssync();
/* Initiate system software reset of peripherals */
bfin_write_SWRST(0x7);
/* Due to the way reset is handled in the hardware, we need
* to delay for 5 SCLKS. The only reliable way to do this is
* to calculate the CCLK/SCLK ratio and multiply 5. For now,
* we'll assume worse case which is a 1:15 ratio.
*/
asm(
"LSETUP (.Lreset_nops,.Lreset_nops) LC0 = %0;/n"
".Lreset_nops: nop;"
:
: "a" (15 * 5)
: "LC0", "LB0", "LT0"
);
/* Clear system software reset */
bfin_write_SWRST(0);
__builtin_bfin_ssync();
/* Issue core reset */
asm("raise 1;");
}
}