Changeset d6f9fff in mainline for kernel/arch/ia32/include


Ignore:
Timestamp:
2016-04-27T12:39:14Z (10 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:
kernel/arch/ia32/include/arch
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/ia32/include/arch/asm.h

    r8a36bc1e rd6f9fff  
    439439        asm volatile (
    440440                "ltr %[sel]"
     441                :: [sel] "r" (sel)
     442        );
     443}
     444
     445/** Load GS from descriptor table.
     446 *
     447 * @param sel Selector specifying descriptor of the GS segment.
     448 *
     449 */
     450NO_TRACE static inline void gs_load(uint16_t sel)
     451{
     452        asm volatile (
     453                "mov %[sel], %%gs"
    441454                :: [sel] "r" (sel)
    442455        );
  • kernel/arch/ia32/include/arch/context_struct.ag

    r8a36bc1e rd6f9fff  
    6666                },
    6767                {
     68                        name : tp,
     69                        type : uint32_t
     70                },
     71
     72                {
    6873                        name : ipl,
    6974                        type : ipl_t
  • kernel/arch/ia32/include/arch/pm.h

    r8a36bc1e rd6f9fff  
    4545#define UDATA_DES  4
    4646#define TSS_DES    5
    47 #define TLS_DES    6  /* Pointer to Thread-Local-Storage data */
     47#define VREG_DES   6  /* Virtual registers */
    4848
    4949#ifdef CONFIG_FB
     
    169169
    170170extern void tss_initialize(tss_t *t);
    171 extern void set_tls_desc(uintptr_t tls);
    172171
    173172#endif /* __ASM__ */
  • kernel/arch/ia32/include/arch/proc/thread.h

    r8a36bc1e rd6f9fff  
    3939
    4040typedef struct {
    41         sysarg_t tls;
    4241} thread_arch_t;
    4342
Note: See TracChangeset for help on using the changeset viewer.