Changeset 281b607 in mainline for arch/ia32


Ignore:
Timestamp:
2006-03-23T10:29:39Z (20 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a0bb10ef
Parents:
9aa72b4
Message:

Added basic kernel infrastructure for ThreadLocalStorage(TLS) for
ia32(complete),amd64(complete),mips32(missing emulation of rdhwr instruction).

Location:
arch/ia32
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • arch/ia32/include/pm.h

    r9aa72b4 r281b607  
    3131
    3232#define IDT_ITEMS 64
    33 #define GDT_ITEMS 6
     33#define GDT_ITEMS 7
    3434
    3535#define NULL_DES        0
     
    3939#define UDATA_DES       4
    4040#define TSS_DES         5
     41#define TLS_DES         6 /* Pointer to Thread-Local-Storage data */
    4142
    4243#define selector(des)   ((des)<<3)
     
    147148
    148149extern void tss_initialize(struct tss *t);
     150extern void set_tls_desc(__address tls);
    149151
    150152#endif /* __ASM__ */
  • arch/ia32/include/thread.h

    r9aa72b4 r281b607  
    3030#define __ia32_THREAD_H__
    3131
    32 #define ARCH_THREAD_DATA
     32#define ARCH_THREAD_DATA __native tls;
    3333
    3434#endif
  • arch/ia32/src/ia32.c

    r9aa72b4 r281b607  
    5252#include <interrupt.h>
    5353#include <arch/debugger.h>
     54#include <proc/thread.h>
     55#include <syscall/syscall.h>
    5456
    5557void arch_pre_mm_init(void)
     
    107109        }
    108110}
     111
     112/** Set Thread-local-storeage pointer
     113 *
     114 * TLS pointer is set in FS register. Unfortunately the 64-bit
     115 * part can be set only in CPL0 mode.
     116 *
     117 * The specs says, that on %fs:0 there is stored contents of %fs register,
     118 * we need not to go to CPL0 to read it.
     119 */
     120__native sys_tls_set(__native addr)
     121{
     122        THREAD->tls = addr;
     123        set_tls_desc(addr);
     124
     125        return 0;
     126}
  • arch/ia32/src/pm.c

    r9aa72b4 r281b607  
    4949 * mode, we use, for each privilege level, two segments spanning the
    5050 * whole memory. One is for code and one is for data.
     51 *
     52 * One is for GS register which holds pointer to the TLS thread
     53 * structure in it's base.
    5154 */
    5255struct descriptor gdt[GDT_ITEMS] = {
     
    6265        { 0xffff, 0, 0, AR_PRESENT | AR_DATA | AR_WRITABLE | DPL_USER, 0xf, 0, 0, 1, 1, 0 },
    6366        /* TSS descriptor - set up will be completed later */
    64         { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
     67        { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     68        { 0xffff, 0, 0, AR_PRESENT | AR_DATA | AR_WRITABLE | DPL_USER, 0xf, 0, 0, 1, 1, 0 }
    6569};
    6670
     
    215219        clean_AM_flag();          /* Disable alignment check */
    216220}
     221
     222void set_tls_desc(__address tls)
     223{
     224        struct ptr_16_32 cpugdtr;
     225        struct descriptor *gdt_p = (struct descriptor *) cpugdtr.base;
     226
     227        __asm__ volatile ("sgdt %0\n" : : "m" (cpugdtr));
     228
     229        gdt_setbase(&gdt_p[TLS_DES], tls);
     230        /* Reload gdt register to update GS in CPU */
     231        __asm__ volatile ("lgdt %0\n" : : "m" (cpugdtr));
     232}
  • arch/ia32/src/proc/scheduler.c

    r9aa72b4 r281b607  
    3333#include <arch/context.h>       /* SP_DELTA */
    3434#include <arch/debugger.h>
     35#include <arch/pm.h>
    3536
    3637void before_thread_runs_arch(void)
     
    3839        CPU->arch.tss->esp0 = (__address) &THREAD->kstack[THREAD_STACK_SIZE-SP_DELTA];
    3940        CPU->arch.tss->ss0 = selector(KDATA_DES);
     41
     42        /* Set up TLS in GS register */
     43        set_tls_desc(THREAD->tls);
    4044
    4145#ifdef CONFIG_DEBUG_AS_WATCHPOINT
  • arch/ia32/src/userspace.c

    r9aa72b4 r281b607  
    5656                "popfl\n"
    5757
     58                /* Set up GS register (TLS) */
     59                "movl %6, %%gs\n"
     60
    5861                "pushl %0\n"
    5962                "pushl %1\n"
     
    6669                : "i" (selector(UDATA_DES) | PL_USER), "r" (kernel_uarg->uspace_stack+THREAD_STACK_SIZE),
    6770                  "r" (ipl), "i" (selector(UTEXT_DES) | PL_USER), "r" (kernel_uarg->uspace_entry),
    68                   "r" (kernel_uarg->uspace_uarg)
     71                "r" (kernel_uarg->uspace_uarg),
     72                "r" (selector(TLS_DES))
    6973                : "eax");
    7074       
Note: See TracChangeset for help on using the changeset viewer.