From: Kalai Rajah N <kalairajah@gmail.com>
To: "gcc-help@gcc.gnu.org" <gcc-help@gcc.gnu.org>
Subject: Thumb inline assembly
Date: Mon, 10 Jun 2013 21:41:00 -0000 [thread overview]
Message-ID: <CAPTDLfFZp2Z_arQO0iRRFFQMxuj1=AC6zxgv4Q=F2GVxY23qVA@mail.gmail.com> (raw)
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
next reply other threads:[~2013-06-10 21:41 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-10 21:41 Kalai Rajah N [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAPTDLfFZp2Z_arQO0iRRFFQMxuj1=AC6zxgv4Q=F2GVxY23qVA@mail.gmail.com' \
--to=kalairajah@gmail.com \
--cc=gcc-help@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).