public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* ColdFire and Thread-Local Storage
@ 2014-01-28 15:49 Sebastian Huber
  2014-01-28 19:15 ` Ian Lance Taylor
  0 siblings, 1 reply; 5+ messages in thread
From: Sebastian Huber @ 2014-01-28 15:49 UTC (permalink / raw)
  To: gcc-help

Hi,

it seems GCC uses this ColdFire TLS ABI:

https://lists.debian.org/debian-68k/2007/11/msg00071.html

Here we have a function

void *__m68k_read_tp(void)

which must return the thread pointer in register a0.

I have to implement this function.  Is there a way to instruct GCC to return 
the value in register a0 instead of d0 or do I have to use assembler to 
implement this function?

-- 
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber@embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.

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

* Re: ColdFire and Thread-Local Storage
  2014-01-28 15:49 ColdFire and Thread-Local Storage Sebastian Huber
@ 2014-01-28 19:15 ` Ian Lance Taylor
  2014-01-29  7:51   ` Sebastian Huber
  0 siblings, 1 reply; 5+ messages in thread
From: Ian Lance Taylor @ 2014-01-28 19:15 UTC (permalink / raw)
  To: Sebastian Huber; +Cc: gcc-help

On Tue, Jan 28, 2014 at 7:49 AM, Sebastian Huber
<sebastian.huber@embedded-brains.de> wrote:
>
> it seems GCC uses this ColdFire TLS ABI:
>
> https://lists.debian.org/debian-68k/2007/11/msg00071.html
>
> Here we have a function
>
> void *__m68k_read_tp(void)
>
> which must return the thread pointer in register a0.
>
> I have to implement this function.  Is there a way to instruct GCC to return
> the value in register a0 instead of d0 or do I have to use assembler to
> implement this function?

I believe that on m68k GNU/Linux a function that returns a pointer
will normally return the value in a0.

Ian

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

* Re: ColdFire and Thread-Local Storage
  2014-01-28 19:15 ` Ian Lance Taylor
@ 2014-01-29  7:51   ` Sebastian Huber
  2014-01-29 19:50     ` Norbert Lange
  0 siblings, 1 reply; 5+ messages in thread
From: Sebastian Huber @ 2014-01-29  7:51 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-help

On 2014-01-28 20:15, Ian Lance Taylor wrote:
> On Tue, Jan 28, 2014 at 7:49 AM, Sebastian Huber
> <sebastian.huber@embedded-brains.de> wrote:
>>
>> it seems GCC uses this ColdFire TLS ABI:
>>
>> https://lists.debian.org/debian-68k/2007/11/msg00071.html
>>
>> Here we have a function
>>
>> void *__m68k_read_tp(void)
>>
>> which must return the thread pointer in register a0.
>>
>> I have to implement this function.  Is there a way to instruct GCC to return
>> the value in register a0 instead of d0 or do I have to use assembler to
>> implement this function?
>
> I believe that on m68k GNU/Linux a function that returns a pointer
> will normally return the value in a0.
>
> Ian
>

The function

void *__m68k_read_tp(void)
{
   const Thread_Control *executing = _Thread_Get_executing();

   return (char *) executing->Start.tls_area +
     _TLS_Get_thread_control_block_area_size((uintptr_t) _TLS_Alignment)
     + 0x7000;
}

translates to

__m68k_read_tp:
         move.l #_TLS_Alignment,%d0
         moveq #8,%d1
         move.l _Per_CPU_Information+18,%a0
         cmp.l %d0,%d1
         jls .L2
         moveq #8,%d0
.L2:
         add.l #28672,%d0
         add.l 194(%a0),%d0
         rts

I use now:

void __m68k_read_tp(void)
{
   const Thread_Control *executing = _Thread_Get_executing();
   void *tp = (char *) executing->Start.tls_area +
     _TLS_Get_thread_control_block_area_size((uintptr_t) _TLS_Alignment)
     + 0x7000;

   __asm__ volatile (
     "move.l %0, %%a0"
     :
     : "d" (tp)
   );
}

-- 
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber@embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.

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

* Re: ColdFire and Thread-Local Storage
  2014-01-29  7:51   ` Sebastian Huber
@ 2014-01-29 19:50     ` Norbert Lange
  2014-01-30 10:43       ` Sebastian Huber
  0 siblings, 1 reply; 5+ messages in thread
From: Norbert Lange @ 2014-01-29 19:50 UTC (permalink / raw)
  To: gcc-help

Hello,

its been some time since I looked at the TLS conventions and I only done  
this on ARM.
But I would strongly advise you to implement the function in asm, on ARM  
you arent allowed to change any register except the one you return and I  
would bet its the same on other architectures.

Norbert

Am 29.01.2014, 08:51 Uhr, schrieb Sebastian Huber  
<sebastian.huber@embedded-brains.de>:

> On 2014-01-28 20:15, Ian Lance Taylor wrote:
>> On Tue, Jan 28, 2014 at 7:49 AM, Sebastian Huber
>> <sebastian.huber@embedded-brains.de> wrote:
>>>
>>> it seems GCC uses this ColdFire TLS ABI:
>>>
>>> https://lists.debian.org/debian-68k/2007/11/msg00071.html
>>>
>>> Here we have a function
>>>
>>> void *__m68k_read_tp(void)
>>>
>>> which must return the thread pointer in register a0.
>>>
>>> I have to implement this function.  Is there a way to instruct GCC to  
>>> return
>>> the value in register a0 instead of d0 or do I have to use assembler to
>>> implement this function?
>>
>> I believe that on m68k GNU/Linux a function that returns a pointer
>> will normally return the value in a0.
>>
>> Ian
>>
>
> The function
>
> void *__m68k_read_tp(void)
> {
>    const Thread_Control *executing = _Thread_Get_executing();
>
>    return (char *) executing->Start.tls_area +
>      _TLS_Get_thread_control_block_area_size((uintptr_t) _TLS_Alignment)
>      + 0x7000;
> }
>
> translates to
>
> __m68k_read_tp:
>          move.l #_TLS_Alignment,%d0
>          moveq #8,%d1
>          move.l _Per_CPU_Information+18,%a0
>          cmp.l %d0,%d1
>          jls .L2
>          moveq #8,%d0
> .L2:
>          add.l #28672,%d0
>          add.l 194(%a0),%d0
>          rts
>
> I use now:
>
> void __m68k_read_tp(void)
> {
>    const Thread_Control *executing = _Thread_Get_executing();
>    void *tp = (char *) executing->Start.tls_area +
>      _TLS_Get_thread_control_block_area_size((uintptr_t) _TLS_Alignment)
>      + 0x7000;
>
>    __asm__ volatile (
>      "move.l %0, %%a0"
>      :
>      : "d" (tp)
>    );
> }

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

* Re: ColdFire and Thread-Local Storage
  2014-01-29 19:50     ` Norbert Lange
@ 2014-01-30 10:43       ` Sebastian Huber
  0 siblings, 0 replies; 5+ messages in thread
From: Sebastian Huber @ 2014-01-30 10:43 UTC (permalink / raw)
  To: gcc-help

Hello Norbert,

thanks for the warning.

On 2014-01-29 20:50, Norbert Lange wrote:
> its been some time since I looked at the TLS conventions and I only done this
> on ARM.
> But I would strongly advise you to implement the function in asm, on ARM you
> arent allowed to change any register except the one you return and I would bet
> its the same on other architectures.

Yes, this is true for ARM, here __aeabi_read_tp() can clobber only r0.  On m68k 
the situation is different:

https://lists.debian.org/debian-68k/2007/11/msg00071.html

"This TLS ABI defines a function __m68k_read_tp, provided by libc.
This returns the thread pointer in register a0 (not d0) and may
clobber other call-clobbered registers.  The compiler will generate
calls to this function for the initial exec and local exec models."

-- 
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber@embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschÀftliche Mitteilung im Sinne des EHUG.

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

end of thread, other threads:[~2014-01-30 10:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-28 15:49 ColdFire and Thread-Local Storage Sebastian Huber
2014-01-28 19:15 ` Ian Lance Taylor
2014-01-29  7:51   ` Sebastian Huber
2014-01-29 19:50     ` Norbert Lange
2014-01-30 10:43       ` Sebastian Huber

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