public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Unconditional trap
@ 2020-09-12 20:17 William Tambe
  2020-09-12 20:26 ` Marc Glisse
  2020-09-13 14:11 ` Segher Boessenkool
  0 siblings, 2 replies; 5+ messages in thread
From: William Tambe @ 2020-09-12 20:17 UTC (permalink / raw)
  To: gcc-help

I am currently using following for trap instruction:

(define_insn "trap"
  [(trap_if (const_int 1) (const_int 0))]
  ""
  "brk")

However it causes the compiler to generate a trap when address 0 is
used; in the example below, I have a function that prints characters
through the UART using address 0; but the resulting assembly generates
a function that traps instead.

#define UART_ADDR 0
void uart_print (char *s) {
        while (*s) {
                *(volatile char *)UART_ADDR = *s;
                ++s;
        }
}

How can one implement unconditional trap ?

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

* Re: Unconditional trap
  2020-09-12 20:17 Unconditional trap William Tambe
@ 2020-09-12 20:26 ` Marc Glisse
  2020-09-12 21:04   ` William Tambe
  2020-09-13 14:11 ` Segher Boessenkool
  1 sibling, 1 reply; 5+ messages in thread
From: Marc Glisse @ 2020-09-12 20:26 UTC (permalink / raw)
  To: William Tambe; +Cc: gcc-help

On Sat, 12 Sep 2020, William Tambe via Gcc-help wrote:

> However it causes the compiler to generate a trap when address 0 is
> used; in the example below, I have a function that prints characters
> through the UART using address 0; but the resulting assembly generates
> a function that traps instead.

Are you using -fno-delete-null-pointer-checks?

-- 
Marc Glisse

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

* Re: Unconditional trap
  2020-09-12 20:26 ` Marc Glisse
@ 2020-09-12 21:04   ` William Tambe
  2020-09-12 21:24     ` Marc Glisse
  0 siblings, 1 reply; 5+ messages in thread
From: William Tambe @ 2020-09-12 21:04 UTC (permalink / raw)
  To: gcc-help

On Sat, Sep 12, 2020 at 3:26 PM Marc Glisse <marc.glisse@inria.fr> wrote:
>
> On Sat, 12 Sep 2020, William Tambe via Gcc-help wrote:
>
> > However it causes the compiler to generate a trap when address 0 is
> > used; in the example below, I have a function that prints characters
> > through the UART using address 0; but the resulting assembly generates
> > a function that traps instead.
>
> Are you using -fno-delete-null-pointer-checks?

Using -fno-delete-null-pointer-checks helps.

Is there a way to make it permanent in the GCC source such that
providing that option is not needed ?

>
> --
> Marc Glisse

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

* Re: Unconditional trap
  2020-09-12 21:04   ` William Tambe
@ 2020-09-12 21:24     ` Marc Glisse
  0 siblings, 0 replies; 5+ messages in thread
From: Marc Glisse @ 2020-09-12 21:24 UTC (permalink / raw)
  To: William Tambe; +Cc: gcc-help

On Sat, 12 Sep 2020, William Tambe via Gcc-help wrote:

> Using -fno-delete-null-pointer-checks helps.
>
> Is there a way to make it permanent in the GCC source such that
> providing that option is not needed ?

$ grep -R delete-null-pointer-checks gcc/config
gcc/config/nios2/elf.h:/* Default -fdelete-null-pointer-checks to off, to prevent the compiler
gcc/config/cr16/cr16.c:  /* Disable -fdelete-null-pointer-checks option for CR16 target.

TARGET_OPTION_OVERRIDE seems to be the way if you want to disable it for 
some specific target. If you want to change the default for all targets, 
you could edit common.opt instead.

-- 
Marc Glisse

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

* Re: Unconditional trap
  2020-09-12 20:17 Unconditional trap William Tambe
  2020-09-12 20:26 ` Marc Glisse
@ 2020-09-13 14:11 ` Segher Boessenkool
  1 sibling, 0 replies; 5+ messages in thread
From: Segher Boessenkool @ 2020-09-13 14:11 UTC (permalink / raw)
  To: William Tambe; +Cc: gcc-help

Hi!

On Sat, Sep 12, 2020 at 03:17:03PM -0500, William Tambe via Gcc-help wrote:
> I am currently using following for trap instruction:
> 
> (define_insn "trap"
>   [(trap_if (const_int 1) (const_int 0))]
>   ""
>   "brk")

This looks fine.

> However it causes the compiler to generate a trap when address 0 is
> used; in the example below, I have a function that prints characters
> through the UART using address 0; but the resulting assembly generates
> a function that traps instead.
> 
> #define UART_ADDR 0
> void uart_print (char *s) {
>         while (*s) {
>                 *(volatile char *)UART_ADDR = *s;
>                 ++s;
>         }
> }
> 
> How can one implement unconditional trap ?

You should implement TARGET_ADDR_SPACE_ZERO_ADDRESS_VALID to make 0 a
valid address.


Segher

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

end of thread, other threads:[~2020-09-13 14:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-12 20:17 Unconditional trap William Tambe
2020-09-12 20:26 ` Marc Glisse
2020-09-12 21:04   ` William Tambe
2020-09-12 21:24     ` Marc Glisse
2020-09-13 14:11 ` Segher Boessenkool

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