Thumb inline assembly
Kalai Rajah N
kalairajah@gmail.com
Mon Jun 10 21:41:00 GMT 2013
Hi,
I'm trying to do a simple register read through ARM inline assembly.
If I embed the asm in the function directly, it works ...
eg:
#define BAD 0xBAADBAAD
#define GOOD 0x600D600D
#define RESET 0x00000000
#define NVIC_ISER0 0xE000E100
volatile int nvic_iser_status = 0xFFFFFFFF;
function () {
...
asm volatile(
"ldr r2, =8 /* number of register */ \n\t"
"ldr r1, =%0 /* load the nvic_iser* register */ \n\t"
"read_nvic_iser:\n\t"
"sub r2, r2, #1\n\t"
"ldr r0, [r1]\n\t"
"add r1, r1, #4 /* go to the next register */ \n\t"
"cmp r0, %1\n\t"
"beq read_nvic_iser_ok\n\t"
"ldr r3, =%2\n\t"
"str r3, [%4] /* update status flag */\n\t"
"read_nvic_iser_ok:\n\t"
"cmp r2, #0\n\t"
"bne read_nvic_iser\n\t"
"ldr r3, =%3\n\t"
"str r3, [%4] /* update status flag */\n\t"
:
: "i" (NVIC_ISER0), "i" (RESET), "i" (BAD), "i" (GOOD), "r" (&nvic_iser_status)
: "r0", "r1", "r2", "r3"
);
..
}
But, if I want to call the asm through another function, I get errors ..
eg: function (){
...
reg_read(NVIC_ISER0, RESET, nvic_iser_status)
..
}
reg_read(int addr, int reset, int status){
asm volatile(
"ldr r2, =8 /* number of register */ \n\t"
"ldr r1, =%0 /* load the nvic_iser* register */ \n\t"
"read_reg:\n\t"
"sub r2, r2, #1\n\t"
"ldr r0, [r1]\n\t"
"add r1, r1, #4 /* go to the next register */ \n\t"
"cmp r0, %1\n\t"
"beq read_reg_ok\n\t"
"ldr r3, =%2\n\t"
"str r3, [%4] /* update status flag */\n\t"
"read_reg_ok:\n\t"
"cmp r2, #0\n\t"
"bne read_reg\n\t"
"ldr r3, =%3\n\t"
"str r3, [%4] /* update status flag */\n\t"
:
: "r" (addr), "r" (reset), "r" (BAD), "r" (GOOD), "r" (status)
: "r0", "r1", "r2", "r3"
//:
);
}
I see the following errors:
/tmp/ccYu7aUS.ltrans0.ltrans.o: In function `read_reg_ok':
ccYu7aUS.ltrans0.o:(.text.check_reset_value.4010+0x60): undefined
reference to `r6'
ccYu7aUS.ltrans0.o:(.text.check_reset_value.4010+0x64): undefined
reference to `r4'
ccYu7aUS.ltrans0.o:(.text.check_reset_value.4010+0x68): undefined
reference to `r5'
collect2: error: ld returned 1 exit status
What am I doing wrong?
thanks,
Kalai
More information about the Gcc-help
mailing list