public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Thumb inline assembly
@ 2013-06-10 21:41 Kalai Rajah N
  2013-06-10 22:51 ` Ian Lance Taylor
  0 siblings, 1 reply; 11+ messages in thread
From: Kalai Rajah N @ 2013-06-10 21:41 UTC (permalink / raw)
  To: gcc-help

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2013-06-11 18:27 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-10 21:41 Thumb inline assembly Kalai Rajah N
2013-06-10 22:51 ` Ian Lance Taylor
2013-06-10 23:19   ` Kalai Rajah N
2013-06-10 23:59     ` Ian Lance Taylor
2013-06-11  0:06       ` Kalai Rajah N
2013-06-11  0:13         ` Ian Lance Taylor
     [not found]           ` <CAPTDLfH--WkreVXSDb7nt6KsKP+vBH3q_eoJX7yvqm=O8QzF0A@mail.gmail.com>
2013-06-11  0:20             ` Fwd: " Kalai Rajah N
2013-06-11  0:31               ` Ian Lance Taylor
2013-06-11  0:41                 ` Kalai Rajah N
2013-06-11  1:01                   ` Ian Lance Taylor
2013-06-11 18:27                     ` Kalai Rajah N

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).