public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* MSP430 in gcc4.9 ... enable interrupts?
@ 2014-02-14 10:12 Brian Drummond
  2014-02-14 19:17 ` DJ Delorie
  0 siblings, 1 reply; 6+ messages in thread
From: Brian Drummond @ 2014-02-14 10:12 UTC (permalink / raw)
  To: gcc

I have built a crosscompiler for the MSP430, using a gcc4.9 snapshot
(gcc-4.9-20140112) and the compiler seems OK and builds a simple
"blinky" LED flashing example.

But my slightly larger example, originally built using Peter Bigot's
mspgcc backend, no longer compiles ... 

mspgcc had a number of intrinsic functions, such as __nop(), __eint()
and __dint() respectively. Calling these would execute a nop, enable and
disable interrupts respectively. 

Others such as __bis_status_register(), __bic_status_register() would
manipulate system status, low power modes etc.

Now in the MSP430 port for gcc4.9, these intrinsic functions have gone. 

Perusing the config/msp430 source files, e.g. config/msp430/msp430.md I
can see evidence that the _functionality_ is still there, e.g.

(define_insn "enable_interrupts"
  [(unspec_volatile [(const_int 0)] UNS_EINT)]
  ""
  "EINT"
  )
...
(define_insn "bis_SR"
  [(unspec_volatile [(match_operand 0 "nonmemory_operand" "ir")]
UNS_BIS_SR)]
  ""
  "BIS.W\t%0, %O0(SP)"
  )

... but how do I access it? In other words, what C code fragment would
cause the "enable_interrupts" instruction to be emitted, and generate
"EINT" in the assembler or object output?

- Brian


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

* Re: MSP430 in gcc4.9 ... enable interrupts?
  2014-02-14 10:12 MSP430 in gcc4.9 ... enable interrupts? Brian Drummond
@ 2014-02-14 19:17 ` DJ Delorie
  2014-02-14 20:53   ` Brian Drummond
  2014-02-16 14:26   ` David Brown
  0 siblings, 2 replies; 6+ messages in thread
From: DJ Delorie @ 2014-02-14 19:17 UTC (permalink / raw)
  To: brian; +Cc: gcc


The constructs in the *.md files are for the compiler's internal use
(i.e. there are function attributes that trigger those).  You don't
need compiler support for these opcodes at the user level; the right
way is to implement those builtins as inline assembler in a common
header file:

static inline __attribute__((always_inline))
void __nop()
{
  asm volatile ("NOP");
}

static inline __attribute__((always_inline))
void __eint()
{
  asm volatile ("EINT");
}


Or more simply:

#define __eint() asm("EINT")
#define __nop() asm("NOP")


For opcodes with parameters, you use a more complex form of inline
assembler:

static inline __attribute__((always_inline))
void BIC_SR(const int x)
{
  asm volatile ("BIC.W %0,R2" :: "i" (x));
}

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

* Re: MSP430 in gcc4.9 ... enable interrupts?
  2014-02-14 19:17 ` DJ Delorie
@ 2014-02-14 20:53   ` Brian Drummond
  2014-02-16 14:26   ` David Brown
  1 sibling, 0 replies; 6+ messages in thread
From: Brian Drummond @ 2014-02-14 20:53 UTC (permalink / raw)
  To: gcc

On Fri, 2014-02-14 at 14:17 -0500, DJ Delorie wrote:
> The constructs in the *.md files are for the compiler's internal use
> (i.e. there are function attributes that trigger those).  You don't
> need compiler support for these opcodes at the user level; the right
> way is to implement those builtins as inline assembler 

> static inline __attribute__((always_inline))
> void __nop()
> {
>   asm volatile ("NOP");
> }

Thanks for the answer. I thought I was missing something, but apparently
not. Now it's clear that inline assembler is the official way, I can
adapt that approach to my situation. 

- Brian

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

* Re: MSP430 in gcc4.9 ... enable interrupts?
  2014-02-14 19:17 ` DJ Delorie
  2014-02-14 20:53   ` Brian Drummond
@ 2014-02-16 14:26   ` David Brown
  2014-02-17 23:12     ` DJ Delorie
  1 sibling, 1 reply; 6+ messages in thread
From: David Brown @ 2014-02-16 14:26 UTC (permalink / raw)
  To: DJ Delorie, brian; +Cc: gcc

On 14/02/14 20:17, DJ Delorie wrote:
> The constructs in the *.md files are for the compiler's internal use
> (i.e. there are function attributes that trigger those).  You don't
> need compiler support for these opcodes at the user level; the right
> way is to implement those builtins as inline assembler in a common
> header file:
>
> static inline __attribute__((always_inline))
> void __nop()
> {
>    asm volatile ("NOP");
> }
>
> static inline __attribute__((always_inline))
> void __eint()
> {
>    asm volatile ("EINT");
> }
>
>
> Or more simply:
>
> #define __eint() asm("EINT")
> #define __nop() asm("NOP")
>
>
> For opcodes with parameters, you use a more complex form of inline
> assembler:
>
> static inline __attribute__((always_inline))
> void BIC_SR(const int x)
> {
>    asm volatile ("BIC.W %0,R2" :: "i" (x));
> }
>

I presume these will be part of the headers for the library distributed 
for msp430 gcc by TI/Redhat?  (I know that's a bit off-topic for the gcc 
list, but it is relevant to msp430 gcc users who don't want to have to 
learn inline assembly.)  I certainly think that's the right way to 
handle this sort of thing - if it can be just as efficiently put in 
headers using inline assembly, then maintenance is easier than putting 
it into gcc itself.

When you say that the interrupt control in the compiler is for function 
attributes, is that for the "critical" attribute that exists in the old 
msp430 port (which disables interrupts for the duration of the 
function)?  I don't see it mentioned in the current gcc documentation, 
but I haven't tried the code itself.  It was certainly a nice idea - and 
one that I would love to see supported on a range of gcc ports rather 
than just the msp430.

David


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

* Re: MSP430 in gcc4.9 ... enable interrupts?
  2014-02-16 14:26   ` David Brown
@ 2014-02-17 23:12     ` DJ Delorie
  2014-02-18  8:01       ` David Brown
  0 siblings, 1 reply; 6+ messages in thread
From: DJ Delorie @ 2014-02-17 23:12 UTC (permalink / raw)
  To: David Brown; +Cc: brian, gcc


> I presume these will be part of the headers for the library
> distributed for msp430 gcc by TI/Redhat?

I can't speak for TI's or Red Hat's plans.  GNU's typical non-custom
embedded runtime is newlib/libgloss, which usually doesn't have that
much in the way of chip-specific headers or library functions.

> is that for the "critical" attribute that exists in the old msp430
> port (which disables interrupts for the duration of the function)?

Yes, for things like that.  They're documented under "Function
Attributes" in the "Extensions to the C Language Family" chapter of
the current GCC manual.

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

* Re: MSP430 in gcc4.9 ... enable interrupts?
  2014-02-17 23:12     ` DJ Delorie
@ 2014-02-18  8:01       ` David Brown
  0 siblings, 0 replies; 6+ messages in thread
From: David Brown @ 2014-02-18  8:01 UTC (permalink / raw)
  To: DJ Delorie; +Cc: brian, gcc

On 18/02/14 00:12, DJ Delorie wrote:
>> I presume these will be part of the headers for the library
>> distributed for msp430 gcc by TI/Redhat?
> 
> I can't speak for TI's or Red Hat's plans.  GNU's typical non-custom
> embedded runtime is newlib/libgloss, which usually doesn't have that
> much in the way of chip-specific headers or library functions.

Fair enough.  I don't know if Red Hat will be distributing anything
themselves, but I'm confident that TI will distribute chip-specific
headers with pre-built msp430 gcc packages (their aim, after all, is to
get more people to buy msp430 chips - and making the tools as easy and
powerful as possible is part of that).  I was just wondering where these
headers would fit in.

> 
>> is that for the "critical" attribute that exists in the old msp430
>> port (which disables interrupts for the duration of the function)?
> 
> Yes, for things like that.  They're documented under "Function
> Attributes" in the "Extensions to the C Language Family" chapter of
> the current GCC manual.
> 

Ah yes, I missed it when I first looked - the documentation makes
"critical" look like an option to the "interrupt" attribute, rather than
a stand-alone attribute.  It seems to me a rather strange idea to have
both "interrupt" and "critical" on the same function - an "interrupt"
function is inherently "critical" (and "reentrant") in that interrupts
are disabled before it enters, and restored or re-enabled on exit.  It
would make a difference on processors like ARMs with several interrupt
levels, but not on an msp430 with its single level.

David

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

end of thread, other threads:[~2014-02-18  8:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-14 10:12 MSP430 in gcc4.9 ... enable interrupts? Brian Drummond
2014-02-14 19:17 ` DJ Delorie
2014-02-14 20:53   ` Brian Drummond
2014-02-16 14:26   ` David Brown
2014-02-17 23:12     ` DJ Delorie
2014-02-18  8:01       ` David Brown

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).