Changeset fa23560 in mainline for uspace/lib/libc/arch/arm32/include/tls.h
- Timestamp:
- 2007-10-30T22:54:11Z (18 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4d21cf8
- Parents:
- b2a0f6dd
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libc/arch/arm32/include/tls.h
rb2a0f6dd rfa23560 1 1 /* 2 * Copyright (c) 2006 Ondrej Palkovsky 2 * Copyright (c) 2007 Pavel Jancik 3 * Copyright (c) 2007 Michal Kebrt 3 4 * All rights reserved. 4 5 * … … 27 28 */ 28 29 29 /** @addtogroup libcsparc64 sparc64 30 * @ingroup lc 30 /** @addtogroup libcarm32 31 31 * @{ 32 32 */ 33 33 /** @file 34 *35 34 */ 36 35 37 #include <thread.h> 38 #include <malloc.h> 39 #include <align.h> 36 #ifndef LIBC_arm32_TLS_H_ 37 #define LIBC_arm32_TLS_H_ 40 38 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. 45 49 */ 50 typedef struct { 51 /** Fibril data. */ 52 void *fibril_data; 53 } tcb_t; 46 54 47 /** Allocate TLS variant II data structures for a thread. 55 56 /** Sets TLS address to the r9 register. 48 57 * 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) 55 59 */ 56 tcb_t * __alloc_tls(void **data, size_t size)60 static inline void __tcb_set(tcb_t *tcb) 57 61 { 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 ); 67 69 } 68 70 69 /** Free TLS variant II data structures of a thread. 71 72 /** Returns TCB address. 70 73 * 71 * Only static model is supported. 74 * @return TCB address (starts before TLS which address is stored 75 * in r9 register). 76 */ 77 static 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. 72 89 * 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 75 93 */ 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 } 94 extern uintptr_t __aeabi_read_tp(void); 95 96 #endif 82 97 83 98 /** @}
Note:
See TracChangeset
for help on using the changeset viewer.