linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* halt/reset on assert?
@ 2011-04-02  0:22 Evan Lavelle
  0 siblings, 0 replies; 7+ messages in thread
From: Evan Lavelle @ 2011-04-02  0:22 UTC (permalink / raw)
  To: linuxppc-dev

I'd like to use an assert macro in a device driver for an MPC870 using 
ppcboot; something like:

#define MY_ASSERT(expr)                                         \
    do {                                                         \
       if(!(expr)) {                                             \
          printk(                                                \
             KERN_EMERG                                          \
             "assertion failure: %s, line %d\n",                 \
             __FILE__, __LINE__);                                \
          asm(--ppc halt/reset?)                                 \
       }                                                         \
    } while(0)

However, I've got no idea how to halt or reset the processor here. 
Anyone happen to know?

Thanks -

Evan

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

* Re: halt/reset on assert?
       [not found] <4D966C5C.9030409__15236.8285613649$1301704900$gmane$org@cyconix.com>
@ 2011-04-02  6:51 ` Andreas Schwab
  2011-04-02  6:53 ` Andreas Schwab
  1 sibling, 0 replies; 7+ messages in thread
From: Andreas Schwab @ 2011-04-02  6:51 UTC (permalink / raw)
  To: Evan Lavelle; +Cc: linuxppc-dev

Evan Lavelle <sa212+lppc@cyconix.com> writes:

> I'd like to use an assert macro in a device driver for an MPC870 using
> ppcboot; something like:
>
> #define MY_ASSERT(expr)                                         \
>    do {                                                         \
>       if(!(expr)) {                                             \
>          printk(                                                \
>             KERN_EMERG                                          \
>             "assertion failure: %s, line %d\n",                 \
>             __FILE__, __LINE__);                                \
>          asm(--ppc halt/reset?)                                 \
>       }                                                         \
>    } while(0)
>
> However, I've got no idea how to halt or reset the processor here. Anyone
> happen to know?

#define MY_ASSERT(expr) BUG(!(expr))

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

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

* Re: halt/reset on assert?
       [not found] <4D966C5C.9030409__15236.8285613649$1301704900$gmane$org@cyconix.com>
  2011-04-02  6:51 ` halt/reset on assert? Andreas Schwab
@ 2011-04-02  6:53 ` Andreas Schwab
  2011-04-06 13:01   ` Evan Lavelle
  1 sibling, 1 reply; 7+ messages in thread
From: Andreas Schwab @ 2011-04-02  6:53 UTC (permalink / raw)
  To: Evan Lavelle; +Cc: linuxppc-dev

Evan Lavelle <sa212+lppc@cyconix.com> writes:

> I'd like to use an assert macro in a device driver for an MPC870 using
> ppcboot; something like:
>
> #define MY_ASSERT(expr)                                         \
>    do {                                                         \
>       if(!(expr)) {                                             \
>          printk(                                                \
>             KERN_EMERG                                          \
>             "assertion failure: %s, line %d\n",                 \
>             __FILE__, __LINE__);                                \
>          asm(--ppc halt/reset?)                                 \
>       }                                                         \
>    } while(0)
>
> However, I've got no idea how to halt or reset the processor here. Anyone
> happen to know?

#define MY_ASSERT(expr) BUG_ON(!(expr))

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

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

* Re: halt/reset on assert?
  2011-04-02  6:53 ` Andreas Schwab
@ 2011-04-06 13:01   ` Evan Lavelle
  2011-04-07  7:55     ` Benjamin Herrenschmidt
  0 siblings, 1 reply; 7+ messages in thread
From: Evan Lavelle @ 2011-04-06 13:01 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: linuxppc-dev

Hi Andreas -

that's great; thanks. I'm on 2.4.4, which doesn't have BUG_ON. The right 
way for 2.4.4 turns out to be

#define MY_ASSERT(expr) if(!(expr)) BUG()

-Evan

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

* Re: halt/reset on assert?
  2011-04-06 13:01   ` Evan Lavelle
@ 2011-04-07  7:55     ` Benjamin Herrenschmidt
  2011-04-07 17:04       ` kevin diggs
  0 siblings, 1 reply; 7+ messages in thread
From: Benjamin Herrenschmidt @ 2011-04-07  7:55 UTC (permalink / raw)
  To: Evan Lavelle; +Cc: linuxppc-dev, Andreas Schwab

On Wed, 2011-04-06 at 14:01 +0100, Evan Lavelle wrote:
> #define MY_ASSERT(expr) if(!(expr)) BUG()

Make it

#define MY_ASSERT(expr) do { if .... } while(0)

To ensure it has proper single statement semantics in C.

Cheers,
Ben.

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

* Re: halt/reset on assert?
  2011-04-07  7:55     ` Benjamin Herrenschmidt
@ 2011-04-07 17:04       ` kevin diggs
  2011-04-07 21:48         ` Benjamin Herrenschmidt
  0 siblings, 1 reply; 7+ messages in thread
From: kevin diggs @ 2011-04-07 17:04 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: Andreas Schwab, linuxppc-dev, Evan Lavelle

On Thu, Apr 7, 2011 at 2:55 AM, Benjamin Herrenschmidt
<benh@kernel.crashing.org> wrote:
> On Wed, 2011-04-06 at 14:01 +0100, Evan Lavelle wrote:
>> #define MY_ASSERT(expr) if(!(expr)) BUG()
>
> Make it
>
> #define MY_ASSERT(expr) do { if .... } while(0)
>
> To ensure it has proper single statement semantics in C.
>
So THAT'S why they do this!!!!!! Now I just have to figure out what
'proper single statement semantics' means!

THANKS!!!

kevin

> Cheers,
> Ben.

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

* Re: halt/reset on assert?
  2011-04-07 17:04       ` kevin diggs
@ 2011-04-07 21:48         ` Benjamin Herrenschmidt
  0 siblings, 0 replies; 7+ messages in thread
From: Benjamin Herrenschmidt @ 2011-04-07 21:48 UTC (permalink / raw)
  To: kevin diggs; +Cc: Andreas Schwab, linuxppc-dev, Evan Lavelle

On Thu, 2011-04-07 at 12:04 -0500, kevin diggs wrote:
> On Thu, Apr 7, 2011 at 2:55 AM, Benjamin Herrenschmidt
> <benh@kernel.crashing.org> wrote:
> > On Wed, 2011-04-06 at 14:01 +0100, Evan Lavelle wrote:
> >> #define MY_ASSERT(expr) if(!(expr)) BUG()
> >
> > Make it
> >
> > #define MY_ASSERT(expr) do { if .... } while(0)
> >
> > To ensure it has proper single statement semantics in C.
> >
> So THAT'S why they do this!!!!!! Now I just have to figure out what
> 'proper single statement semantics' means!

Thing what happens without the do { ... } while(0) if you have code
that looks like:

	if (enable_debug)
		MY_ASSERT(foo);
	else
		something_else;

Ben.

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

end of thread, other threads:[~2011-04-07 21:48 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <4D966C5C.9030409__15236.8285613649$1301704900$gmane$org@cyconix.com>
2011-04-02  6:51 ` halt/reset on assert? Andreas Schwab
2011-04-02  6:53 ` Andreas Schwab
2011-04-06 13:01   ` Evan Lavelle
2011-04-07  7:55     ` Benjamin Herrenschmidt
2011-04-07 17:04       ` kevin diggs
2011-04-07 21:48         ` Benjamin Herrenschmidt
2011-04-02  0:22 Evan Lavelle

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 NNTP newsgroup(s).