www.ShoppingPodder.com

Leading Computer Shopping,
News and information


Part of the Identityscape.com network...

getxfactor.com jmoodmusic.com smartbusinesschoices.com mintdepot.com lowfaresalways.com evangelicalview.com shoppingpodder.com soproudlywehail.com webnews.ws currenthumor.com

 

 

Setting ARM CPSR to C variable
   Shopping Podder - the Best of Computer Postings! Forum Index -> Computer Architecture - Embedded  
View previous topic :: View next topic  
Author Message
Luken8r
Guest






PostPosted: Tue Nov 18, 2008 9:38 pm    Post subject: Setting ARM CPSR to C variable Reply with quote

Im using the TI Code Composer suite with an ARM 7 and Im looking for a way
to get the CPSR back into a C variable. I was looking through the
documentation that came with the compiler and it didnt have quite what I
was looking for. What Im need to do is get the state of the interrupt
disable bit. I need to use this bit as a condition variable for something
like:

===

if (interrupts enabled){
do this
}

===

the inline asm syntax is just

===
asm("assembly");
===

The problem is, Im not sure how to associate some C variable to the asm
code to pass the CPSR back to the C code flow. Ive used other compilers in
the past that have an option to pass arguments to the asm code like

===
_asm("tfr b, ccr",foo);
===


which passes the condition code register (for an HC12) to the var foo, but
this compiler does not have that capability.

I first tried

===

volatile ui32_t cpsrstat;

asm(" .global _cpsrstat"); // cpsrstat defined in C code
asm("_cpsrstat .set r0"); // set variable to r0
asm(" mrs r0,cpsr"); // move CPSR to r0

===

With this Im getting an illegal mnemonic error at the MRS instruction. Am
I barking up the wrong tree here?
Back to top
Anthony Fremont
Guest






PostPosted: Tue Nov 18, 2008 10:28 pm    Post subject: Re: Setting ARM CPSR to C variable Reply with quote

Luken8r wrote:
Quote:
Im using the TI Code Composer suite with an ARM 7 and Im looking for
a way to get the CPSR back into a C variable.

This is how you do it in GCC just in case it helps. I didn't write it, but
I can confirm that it does work.

static inline unsigned asm_get_cpsr(void)
{
unsigned long retval;
asm volatile (" mrs %0, cpsr" : "=r" (retval) : /* no inputs */ );
return retval;
}
Back to top
Not Really Me
Guest






PostPosted: Wed Nov 19, 2008 9:14 pm    Post subject: Re: Setting ARM CPSR to C variable Reply with quote

Anthony Fremont wrote:
Quote:
Luken8r wrote:
Im using the TI Code Composer suite with an ARM 7 and Im looking for
a way to get the CPSR back into a C variable.

This is how you do it in GCC just in case it helps. I didn't write
it, but I can confirm that it does work.

static inline unsigned asm_get_cpsr(void)
{
unsigned long retval;
asm volatile (" mrs %0, cpsr" : "=r" (retval) : /* no inputs */ );
return retval;
}

I did not get to see if this compiles, but this should work.

static inline unsigned asm_get_cpsr(void)
{
unsigned long retval;
__asm (" mrs r0, cpsr" );
__asm (" mrs retval, r0" );
return retval;
}

or slightly shorter, directly in an asm function in a C module:

asm_get_cpsr: .asmfunc
mrs r0,cpsr ; get cpsr
mov pc, lr ; return to caller
.endasmfunc

Scott
Back to top
Display posts from previous:   
   Shopping Podder - the Best of Computer Postings! Forum Index -> Computer Architecture - Embedded  
Page 1 of 1
All times are GMT

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum