Ignore:
Timestamp:
2007-10-30T22:54:11Z (18 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4d21cf8
Parents:
b2a0f6dd
Message:

Unify implementations of TLS variant I and variant II alloc_tls() and
free_tls_arch().

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/libc/arch/arm32/include/tls.h

    rb2a0f6dd rfa23560  
    11/*
    2  * Copyright (c) 2006 Ondrej Palkovsky
     2 * Copyright (c) 2007 Pavel Jancik
     3 * Copyright (c) 2007 Michal Kebrt
    34 * All rights reserved.
    45 *
     
    2728 */
    2829
    29 /** @addtogroup libcsparc64 sparc64
    30  * @ingroup lc
     30/** @addtogroup libcarm32
    3131 * @{
    3232 */
    3333/** @file
    34  *
    3534 */
    3635
    37 #include <thread.h>
    38 #include <malloc.h>
    39 #include <align.h>
     36#ifndef LIBC_arm32_TLS_H_
     37#define LIBC_arm32_TLS_H_
    4038
    41 /*
    42  * sparc64 uses thread-local storage data structures, variant II, as described
    43  * in:
    44  *      Drepper U.: ELF Handling For Thread-Local Storage, 2005
     39#include <sys/types.h>
     40
     41#define CONFIG_TLS_VARIANT_1
     42
     43/** Offsets for accessing __thread variables are shifted 8 bytes higher. */
     44#define ARM_TP_OFFSET  (-8)
     45
     46/** TCB (Thread Control Block) struct.
     47 *
     48 *  TLS starts just after this struct.
    4549 */
     50typedef struct {
     51        /** Fibril data. */
     52        void *fibril_data;
     53} tcb_t;
    4654
    47 /** Allocate TLS variant II data structures for a thread.
     55
     56/** Sets TLS address to the r9 register.
    4857 *
    49  * Only static model is supported.
    50  *
    51  * @param data Pointer to pointer to thread local data. This is actually an
    52  *      output argument.
    53  * @param size Size of thread local data.
    54  * @return Pointer to TCB structure.
     58 *  @param tcb          TCB (TLS starts behind)
    5559 */
    56 tcb_t * __alloc_tls(void **data, size_t size)
     60static inline void __tcb_set(tcb_t *tcb)
    5761{
    58         tcb_t *tcb;
    59        
    60         size = ALIGN_UP(size, &_tls_alignment);
    61         *data = memalign(&_tls_alignment, sizeof(tcb_t) + size);
    62 
    63         tcb = (tcb_t *) (*data + size);
    64         tcb->self = tcb;
    65 
    66         return tcb;
     62        void *tls = (void *) tcb;
     63        tls += sizeof(tcb_t) + ARM_TP_OFFSET;
     64        asm volatile (
     65                "mov r9, %0"
     66                :
     67                : "r" (tls)
     68        );
    6769}
    6870
    69 /** Free TLS variant II data structures of a thread.
     71
     72/** Returns TCB address.
    7073 *
    71  * Only static model is supported.
     74 * @return              TCB address (starts before TLS which address is stored
     75 *                      in r9 register).
     76 */
     77static inline tcb_t *__tcb_get(void)
     78{
     79        void *ret;
     80        asm volatile (
     81                "mov %0, r9"
     82                : "=r"(ret)
     83        );
     84        return (tcb_t *) (ret - ARM_TP_OFFSET - sizeof(tcb_t));
     85}
     86
     87
     88/** Returns TLS address stored.
    7289 *
    73  * @param tcb Pointer to TCB structure.
    74  * @param size Size of thread local data.
     90 *  Implemented in assembly.
     91 *
     92 *  @return             TLS address stored in r9 register
    7593 */
    76 void __free_tls_arch(tcb_t *tcb, size_t size)
    77 {
    78         size = ALIGN_UP(size, &_tls_alignment);
    79         void *start = ((void *) tcb) - size;
    80         free(start);
    81 }
     94extern uintptr_t __aeabi_read_tp(void);
     95
     96#endif
    8297
    8398/** @}
Note: See TracChangeset for help on using the changeset viewer.