Changeset 1a5eca4 in mainline for kernel/arch/amd64/src/context.S


Ignore:
Timestamp:
2016-04-27T19:36:56Z (8 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
af9dd1e
Parents:
d6f9fff
Message:

amd64: Make TLS settable from uspace

The TLS document[1] mandates that %fs[0] is the thread pointer on amd64.
That is good as it allows userspace-only TLS management for fibrils:
fibril_save/restore() simply manipulate the thread pointer in %fs:0 and
don't need to ask the kernel to modify %fs's base. The kernel treats
%fs: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 %fs 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 %fs:0 as the thread pointer
  • Make GCC generate code that always goes through %gs:0 to access TLS
  • Introduce kseg: a per-CPU area accessible from GS_KERNEL that holds the kernel stack, kernel FS base and a scratch space for syscall and int handlers to use

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

File:
1 edited

Legend:

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

    rd6f9fff r1a5eca4  
    2929#include <abi/asmtool.h>
    3030#include <arch/context_struct.h>
     31#include <arch/vreg.h>
    3132
    3233.text
     
    5051        movq %r14, CONTEXT_OFFSET_R14(%rdi)
    5152        movq %r15, CONTEXT_OFFSET_R15(%rdi)
     53
     54        movq vreg_ptr, %rsi
     55        movq %fs:VREG_TP(%rsi), %rsi
     56        movq %rsi, CONTEXT_OFFSET_TP(%rdi)
    5257       
    5358        xorl %eax, %eax       # context_save returns 1
     
    7277        movq CONTEXT_OFFSET_SP(%rdi), %rsp   # ctx->sp -> %rsp
    7378       
    74         movq CONTEXT_OFFSET_PC(%rdi), %rdx
    75        
     79        movq CONTEXT_OFFSET_PC(%rdi), %rdx
    7680        movq %rdx, (%rsp)
     81
     82        movq CONTEXT_OFFSET_TP(%rdi), %rcx
     83        movq vreg_ptr, %rsi
     84        movq %rcx, %fs:VREG_TP(%rsi)
    7785       
    7886        xorl %eax, %eax       # context_restore returns 0
Note: See TracChangeset for help on using the changeset viewer.