Changeset d6f9fff in mainline for uspace


Ignore:
Timestamp:
2016-04-27T12:39:14Z (9 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1a5eca4
Parents:
8a36bc1e
Message:

ia32: Make TLS settable from uspace

The TLS document[1] mandates that %gs[0] is the thread pointer on ia32.
That is good as it allows userspace-only TLS management for fibrils:
fibril_save/restore() simply manipulate the thread pointer in %gs:0 and
don't need to ask the kernel to modify %gs's base. The kernel treats
%gs:0 as another preserved register and preserves it across context
switches. GCC gets in the way a little bit because it by default assumes
that TLS is accessible from negative %gs offsets (which would
necessitate a kernel-assisted solution). Fortunately, there is a GCC
option to suppress this assumption.

  • Introduce the concept of virtual registers, with VREG_TP (thread pointer) being the first of them
  • Preserve VREG_TP in context_save/restore()
  • Stop using sys_tls_set() in favour of using %gs:0 as the thread pointer
  • Make GCC generate code that always goes through %gs:0 to access TLS

[1] Drepper, U.: ELF Handling For Thread-Local Storage

Location:
uspace/lib/c/arch/ia32
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/arch/ia32/Makefile.common

    r8a36bc1e rd6f9fff  
    2828
    2929ifeq ($(PROCESSOR),i486)
    30         GCC_CFLAGS += -march=i486 -fno-omit-frame-pointer
     30        GCC_CFLAGS += -march=i486 -mno-tls-direct-seg-refs -fno-omit-frame-pointer
    3131else
    32         GCC_CFLAGS += -march=pentium -fno-omit-frame-pointer
     32        GCC_CFLAGS += -march=pentium -mno-tls-direct-seg-refs -fno-omit-frame-pointer
    3333endif
    3434
  • uspace/lib/c/arch/ia32/include/libarch/tls.h

    r8a36bc1e rd6f9fff  
    4747static inline void __tcb_set(tcb_t *tcb)
    4848{
    49         __SYSCALL1(SYS_TLS_SET, (sysarg_t) tcb);
     49        asm volatile ("movl %0, %%gs:0" :: "r" (tcb));
    5050}
    5151
     
    5454        void *retval;
    5555       
    56         asm (
    57                 "movl %%gs:0, %0"
    58                 : "=r" (retval)
    59         );
     56        asm volatile ("movl %%gs:0, %0" : "=r" (retval));
    6057       
    6158        return retval;
  • uspace/lib/c/arch/ia32/src/fibril.S

    r8a36bc1e rd6f9fff  
    7777       
    7878        # set thread local storage
    79         pushl %edx
    8079        movl CONTEXT_OFFSET_TLS(%eax), %edx     # Set arg1 to TLS addr
    81         movl $1, %eax                           # Syscall SYS_TLS_SET
    82         int $0x30
    83         popl %edx
     80        movl %edx, %gs:0
    8481       
    8582        xorl %eax, %eax         # context_restore returns 0
Note: See TracChangeset for help on using the changeset viewer.