Changeset d6f9fff in mainline for kernel/arch/ia32/src/context.S


Ignore:
Timestamp:
2016-04-27T12:39:14Z (8 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/ia32/src/context.S

    r8a36bc1e rd6f9fff  
    2929#include <abi/asmtool.h>
    3030#include <arch/context_struct.h>
     31#include <arch/vreg.h>
    3132
    3233.text
     
    4849        movl %edi, CONTEXT_OFFSET_EDI(%edx)     # %edi -> ctx->edi
    4950        movl %ebp, CONTEXT_OFFSET_EBP(%edx)     # %ebp -> ctx->ebp
     51
     52        mov vreg_ptr, %ecx
     53        movl %gs:VREG_TP(%ecx), %ecx
     54        movl %ecx, CONTEXT_OFFSET_TP(%edx)
    5055
    5156        xorl %eax, %eax         # context_save returns 1
     
    7277
    7378        movl %edx, 0(%esp)      # put saved pc on stack
     79
     80        mov vreg_ptr, %ecx
     81        movl CONTEXT_OFFSET_TP(%eax), %edx
     82        movl %edx, %gs:VREG_TP(%ecx)
     83
    7484        xorl %eax, %eax         # context_restore returns 0
    7585        ret
    76 FUNCTION_END(context_restore_arch)
Note: See TracChangeset for help on using the changeset viewer.