public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* m68k structure return register
@ 2007-06-20  9:25 Vladimir Prus
  2007-09-19 12:46 ` Vladimir Prus
  0 siblings, 1 reply; 7+ messages in thread
From: Vladimir Prus @ 2007-06-20  9:25 UTC (permalink / raw)
  To: gdb


Hello,
it appears that the way gdb expects code to
return structure values on m68k is not exactly
consistent with how gcc actually passes them.

Basically, for function returning structures,
caller should pass an address of memory where
structure should be returned, using either register a0,
or register a1. Which register is used for what target
is precisely where confusion lies.

In gcc/config/m68k there are three definitions:

m68k.h:#define M68K_STRUCT_VALUE_REGNUM A1_REG
m68kelf.h:#define M68K_STRUCT_VALUE_REGNUM A0_REG
netbsd-elf.h:#define M68K_STRUCT_VALUE_REGNUM A0_REG

This, together with config.gcc, gives me the following table
of what register is used for what target.

        1. m68k-*-aout*                                 a1
        2. m68k-*-coff*                                 a1
        3. m68k-*-elf*                                  a0
        4. m68k*-*-netbsdelf*                           a0
        5. m68k*-*-openbsd*                             a1
        6. m68k-*-uclinuxoldabi*                        a0
        7. m68k-*-uclinux*                              a1
        8. m68k-*-linux*                                a1
        9. m68k-*-rtems*                                a0

Here's a breakdown of how those targets map to gdb's .mt files in
config/m68k:

Group I -- monitor.mt -- just m68k-tdep.c

        1. m68k-*-aout*                                 a1
        2. m68k-*-coff*                                 a1
        3. m68k-*-elf*                                  a0
        6. m68k-*-uclinuxoldabi*                        a0
        7. m68k-*-uclinux*                              a1
        9. m68k-*-rtems*                                a0

In gdb, all target here use the register set in m68k_gdbarch_init -- 
currently A1, which register is wrong for half of targets. I'll get to this
group shortly.

Group II -- nbsd.mt/obsd.mt -- m68k-tdep.c + m68kbsd-tdep.c

        4. m68k*-*-netbsdelf*                           a0
        5. m68k*-*-openbsd*                             a1
        
In this group. netbsd has osabi sniffer that sets a0. openbsd
just gets whatever  m68k_gdbarch_init sets -- currently a1.

Group III -- linux.mt -- m68k-tdep.c + m68klinux-tdep.c

        8. m68k-*-linux*                                a1

Here, there's osabi sniffer that causes a1 to be used.

The problem is therefore, group I. Notably, for m68k-elf gcc uses
a0, whereas gdb assumes a1. And for m68k-elf, we cannot set
any osabi sniffer. I think that nowdays m68k-elf is probably the most
important target in that group.

I would suggest the following:

1. Change gdb's default to use a0 register, so that bare-metal works.
2. If possible, add osabi sniffers to uclinux, openbsdb and rtems, that
will cause gdb to use a1. 

Does this sound reasonable, and if so, anybody knows how I can
implement osabi sniffers listed in (2)? I've being told osabi sniffer for
uclinux might be impossible, and I don't know much about either openbsd
or rtems.

Thanks,
Volodya

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

* Re: m68k structure return register
  2007-06-20  9:25 m68k structure return register Vladimir Prus
@ 2007-09-19 12:46 ` Vladimir Prus
  2007-09-19 14:06   ` Daniel Jacobowitz
  0 siblings, 1 reply; 7+ messages in thread
From: Vladimir Prus @ 2007-09-19 12:46 UTC (permalink / raw)
  To: gdb

On Wednesday 20 June 2007 13:25:06 Vladimir Prus wrote:

Does anybody object to the course of action I've proposed
in the below email? If not, I'll send a patch.

- Volodya

> Hello,
> it appears that the way gdb expects code to
> return structure values on m68k is not exactly
> consistent with how gcc actually passes them.
> 
> Basically, for function returning structures,
> caller should pass an address of memory where
> structure should be returned, using either register a0,
> or register a1. Which register is used for what target
> is precisely where confusion lies.
> 
> In gcc/config/m68k there are three definitions:
> 
> m68k.h:#define M68K_STRUCT_VALUE_REGNUM A1_REG
> m68kelf.h:#define M68K_STRUCT_VALUE_REGNUM A0_REG
> netbsd-elf.h:#define M68K_STRUCT_VALUE_REGNUM A0_REG
> 
> This, together with config.gcc, gives me the following table
> of what register is used for what target.
> 
>         1. m68k-*-aout*                                 a1
>         2. m68k-*-coff*                                 a1
>         3. m68k-*-elf*                                  a0
>         4. m68k*-*-netbsdelf*                           a0
>         5. m68k*-*-openbsd*                             a1
>         6. m68k-*-uclinuxoldabi*                        a0
>         7. m68k-*-uclinux*                              a1
>         8. m68k-*-linux*                                a1
>         9. m68k-*-rtems*                                a0
> 
> Here's a breakdown of how those targets map to gdb's .mt files in
> config/m68k:
> 
> Group I -- monitor.mt -- just m68k-tdep.c
> 
>         1. m68k-*-aout*                                 a1
>         2. m68k-*-coff*                                 a1
>         3. m68k-*-elf*                                  a0
>         6. m68k-*-uclinuxoldabi*                        a0
>         7. m68k-*-uclinux*                              a1
>         9. m68k-*-rtems*                                a0
> 
> In gdb, all target here use the register set in m68k_gdbarch_init -- 
> currently A1, which register is wrong for half of targets. I'll get to this
> group shortly.
> 
> Group II -- nbsd.mt/obsd.mt -- m68k-tdep.c + m68kbsd-tdep.c
> 
>         4. m68k*-*-netbsdelf*                           a0
>         5. m68k*-*-openbsd*                             a1
>         
> In this group. netbsd has osabi sniffer that sets a0. openbsd
> just gets whatever  m68k_gdbarch_init sets -- currently a1.
> 
> Group III -- linux.mt -- m68k-tdep.c + m68klinux-tdep.c
> 
>         8. m68k-*-linux*                                a1
> 
> Here, there's osabi sniffer that causes a1 to be used.
> 
> The problem is therefore, group I. Notably, for m68k-elf gcc uses
> a0, whereas gdb assumes a1. And for m68k-elf, we cannot set
> any osabi sniffer. I think that nowdays m68k-elf is probably the most
> important target in that group.
> 
> I would suggest the following:
> 
> 1. Change gdb's default to use a0 register, so that bare-metal works.
> 2. If possible, add osabi sniffers to uclinux, openbsdb and rtems, that
> will cause gdb to use a1. 
> 
> Does this sound reasonable, and if so, anybody knows how I can
> implement osabi sniffers listed in (2)? I've being told osabi sniffer for
> uclinux might be impossible, and I don't know much about either openbsd
> or rtems.
> 
> Thanks,
> Volodya

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

* Re: m68k structure return register
  2007-09-19 12:46 ` Vladimir Prus
@ 2007-09-19 14:06   ` Daniel Jacobowitz
  2007-09-20  9:06     ` Ralf Corsepius
  2007-09-30 20:40     ` Vladimir Prus
  0 siblings, 2 replies; 7+ messages in thread
From: Daniel Jacobowitz @ 2007-09-19 14:06 UTC (permalink / raw)
  To: Vladimir Prus; +Cc: gdb

On Wed, Sep 19, 2007 at 12:24:27PM +0400, Vladimir Prus wrote:
> > Group I -- monitor.mt -- just m68k-tdep.c
> > 
> >         1. m68k-*-aout*                                 a1
> >         2. m68k-*-coff*                                 a1
> >         3. m68k-*-elf*                                  a0
> >         6. m68k-*-uclinuxoldabi*                        a0
> >         7. m68k-*-uclinux*                              a1
> >         9. m68k-*-rtems*                                a0
> > 
> > In gdb, all target here use the register set in m68k_gdbarch_init -- 
> > currently A1, which register is wrong for half of targets. I'll get to this
> > group shortly.

Which of these are ELF?  I know RTEMS is; I suspect both uclinuxoldabi
and uclinux are.  You can differentiate based on ELF-ness in
m68k_gdbarch_init.  Lots of other targets do that too.  Then you can
set the default to a1 for non-ELF and a0 for ELF, and that will fix
m68k-elf and m68k-rtems without breaking m68k-aout or m68k-coff.

m68k-uclinux and m68k-uclinuxoldabi are harder.  Do you know how old
m68k-uclinuxoldabi is, and whether we need to support it in GDB?
If not, you can treat it just like m68k-linux.  It is likely that
the Linux OS/ABI sniffer will already accept uClinux binaries.

> > The problem is therefore, group I. Notably, for m68k-elf gcc uses
> > a0, whereas gdb assumes a1. And for m68k-elf, we cannot set
> > any osabi sniffer. I think that nowdays m68k-elf is probably the most
> > important target in that group.
> > 
> > I would suggest the following:
> > 
> > 1. Change gdb's default to use a0 register, so that bare-metal works.
> > 2. If possible, add osabi sniffers to uclinux, openbsdb and rtems, that
> > will cause gdb to use a1. 

OpenBSD is easy.  Shouldn't RTEMS use a0, from your tables above?

-- 
Daniel Jacobowitz
CodeSourcery

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

* Re: m68k structure return register
  2007-09-19 14:06   ` Daniel Jacobowitz
@ 2007-09-20  9:06     ` Ralf Corsepius
  2007-09-30 20:40     ` Vladimir Prus
  1 sibling, 0 replies; 7+ messages in thread
From: Ralf Corsepius @ 2007-09-20  9:06 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: Vladimir Prus, gdb, Chris Johns

On Wed, 2007-09-19 at 09:31 -0400, Daniel Jacobowitz wrote:
> On Wed, Sep 19, 2007 at 12:24:27PM +0400, Vladimir Prus wrote:
> > > Group I -- monitor.mt -- just m68k-tdep.c
> > > 
> > >         1. m68k-*-aout*                                 a1
> > >         2. m68k-*-coff*                                 a1
> > >         3. m68k-*-elf*                                  a0
> > >         6. m68k-*-uclinuxoldabi*                        a0
> > >         7. m68k-*-uclinux*                              a1
> > >         9. m68k-*-rtems*                                a0
> > > 
> > > In gdb, all target here use the register set in m68k_gdbarch_init -- 
> > > currently A1, which register is wrong for half of targets. I'll get to this
> > > group shortly.
> 
> Which of these are ELF?  I know RTEMS is;
Correct.

> > > The problem is therefore, group I. Notably, for m68k-elf gcc uses
> > > a0, whereas gdb assumes a1. And for m68k-elf, we cannot set
> > > any osabi sniffer. I think that nowdays m68k-elf is probably the most
> > > important target in that group.
> > > 
> > > I would suggest the following:
> > > 
> > > 1. Change gdb's default to use a0 register, so that bare-metal works.
> > > 2. If possible, add osabi sniffers to uclinux, openbsdb and rtems, that
> > > will cause gdb to use a1. 
> 
> OpenBSD is easy.  Shouldn't RTEMS use a0, from your tables above?
Also correct.

Ralf


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

* Re: m68k structure return register
  2007-09-19 14:06   ` Daniel Jacobowitz
  2007-09-20  9:06     ` Ralf Corsepius
@ 2007-09-30 20:40     ` Vladimir Prus
       [not found]       ` <20070930204008.GA15765@caradoc.them.org>
  1 sibling, 1 reply; 7+ messages in thread
From: Vladimir Prus @ 2007-09-30 20:40 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb

On Wednesday 19 September 2007 17:31:36 Daniel Jacobowitz wrote:
> On Wed, Sep 19, 2007 at 12:24:27PM +0400, Vladimir Prus wrote:
> > > Group I -- monitor.mt -- just m68k-tdep.c
> > > 
> > >         1. m68k-*-aout*                                 a1
> > >         2. m68k-*-coff*                                 a1
> > >         3. m68k-*-elf*                                  a0
> > >         6. m68k-*-uclinuxoldabi*                        a0
> > >         7. m68k-*-uclinux*                              a1
> > >         9. m68k-*-rtems*                                a0
> > > 
> > > In gdb, all target here use the register set in m68k_gdbarch_init -- 
> > > currently A1, which register is wrong for half of targets. I'll get to this
> > > group shortly.
> 
> Which of these are ELF?  I know RTEMS is; I suspect both uclinuxoldabi
> and uclinux are.  You can differentiate based on ELF-ness in
> m68k_gdbarch_init.  Lots of other targets do that too.  Then you can
> set the default to a1 for non-ELF and a0 for ELF, and that will fix
> m68k-elf and m68k-rtems without breaking m68k-aout or m68k-coff.

Yeah, that's better.

> m68k-uclinux and m68k-uclinuxoldabi are harder.  Do you know how old
> m68k-uclinuxoldabi is, and whether we need to support it in GDB?

No.

> If not, you can treat it just like m68k-linux.  It is likely that
> the Linux OS/ABI sniffer will already accept uClinux binaries.

It does not seem so. The debuggable .gdb ELF binary does not have the
.note.ABI-tag section so the linux sniffer won't catch it. Is there
anything else I can check for?

- Volodya

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

* Re: m68k structure return register
       [not found]       ` <20070930204008.GA15765@caradoc.them.org>
@ 2007-10-05 12:31         ` Vladimir Prus
  2007-10-05 20:36           ` Daniel Jacobowitz
  0 siblings, 1 reply; 7+ messages in thread
From: Vladimir Prus @ 2007-10-05 12:31 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb

On Monday 01 October 2007 00:40:08 Daniel Jacobowitz wrote:
> On Sun, Sep 30, 2007 at 10:13:04PM +0400, Vladimir Prus wrote:
> > > If not, you can treat it just like m68k-linux.  It is likely that
> > > the Linux OS/ABI sniffer will already accept uClinux binaries.
> > 
> > It does not seem so. The debuggable .gdb ELF binary does not have the
> > .note.ABI-tag section so the linux sniffer won't catch it. Is there
> > anything else I can check for?
> 
> Not that I know of :-(

Ok, so we can made structure return register right for all
targets, except for uclinux.
Or we can keep it as it us today -- wrong for bare-metal,
rtems and unclinuxoldabi.
Which one seems better?

- Volodya

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

* Re: m68k structure return register
  2007-10-05 12:31         ` Vladimir Prus
@ 2007-10-05 20:36           ` Daniel Jacobowitz
  0 siblings, 0 replies; 7+ messages in thread
From: Daniel Jacobowitz @ 2007-10-05 20:36 UTC (permalink / raw)
  To: Vladimir Prus; +Cc: gdb

On Fri, Oct 05, 2007 at 04:31:29PM +0400, Vladimir Prus wrote:
> Ok, so we can made structure return register right for all
> targets, except for uclinux.
> Or we can keep it as it us today -- wrong for bare-metal,
> rtems and unclinuxoldabi.
> Which one seems better?

I stumbled on another option today.  Take a look at target_is_uclinux
in m68klinux-tdep.c.

This is a property of the target, not reflected in the gdbarch,
unfortunately.  So we don't know it when we're initializing a
gdbarch and we can't record the result with the gdbarch.  We
might have to put a function pointer in the tdep structure
which returns the right register to use.

-- 
Daniel Jacobowitz
CodeSourcery

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

end of thread, other threads:[~2007-10-05 20:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-20  9:25 m68k structure return register Vladimir Prus
2007-09-19 12:46 ` Vladimir Prus
2007-09-19 14:06   ` Daniel Jacobowitz
2007-09-20  9:06     ` Ralf Corsepius
2007-09-30 20:40     ` Vladimir Prus
     [not found]       ` <20070930204008.GA15765@caradoc.them.org>
2007-10-05 12:31         ` Vladimir Prus
2007-10-05 20:36           ` Daniel Jacobowitz

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