Changeset deca0f5


Ignore:
Timestamp:
Apr 18, 2019, 2:59:09 PM (5 years ago)
Author:
tdelisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
8c3a0336
Parents:
3c06bba
Message:

x87 and SSE flags are now only saved by threads

Location:
libcfa/src/concurrency
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/CtxSwitch-i386.S

    r3c06bba rdeca0f5  
    5252        movl 4(%esp),%eax
    5353
    54         // Save floating & SSE control words on the stack.
    55 
    56         sub    $8,%esp
    57         stmxcsr 0(%esp)         // 4 bytes
    58         fnstcw  4(%esp)         // 2 bytes
    59 
    6054        // Save volatile registers on the stack.
    6155
     
    8680        popl %ebx
    8781
    88         // Load floating & SSE control words from the stack.
    89 
    90         fldcw   4(%esp)
    91         ldmxcsr 0(%esp)
    92         add    $8,%esp
    93 
    9482        // Return to thread.
    9583
  • libcfa/src/concurrency/CtxSwitch-x86_64.S

    r3c06bba rdeca0f5  
    4646CtxSwitch:
    4747
    48         // Save floating & SSE control words on the stack.
    49 
    50         subq   $8,%rsp
    51         stmxcsr 0(%rsp)         // 4 bytes
    52         fnstcw  4(%rsp)         // 2 bytes
    53 
    5448        // Save volatile registers on the stack.
    5549
     
    7872        popq %r15
    7973
    80         // Load floating & SSE control words from the stack.
    81 
    82         fldcw   4(%rsp)
    83         ldmxcsr 0(%rsp)
    84         addq   $8,%rsp
    85 
    8674        // Return to thread.
    8775
    8876        ret
    8977        .size  CtxSwitch, .-CtxSwitch
    90 
    91 
    92 //.text
    93 //      .align 2
    94 //.globl        CtxStore
    95 //CtxStore:
    96 //      // Save floating & SSE control words on the stack.
    97 //
    98 //      subq   $8,%rsp
    99 //      stmxcsr 0(%rsp)         // 4 bytes
    100 //      fnstcw  4(%rsp)         // 2 bytes
    101 //
    102 //      // Save volatile registers on the stack.
    103 //
    104 //      pushq %r15
    105 //      pushq %r14
    106 //      pushq %r13
    107 //      pushq %r12
    108 //      pushq %rbx
    109 //
    110 //      // Save old context in the "from" area.
    111 //
    112 //      movq %rsp,SP_OFFSET(%rdi)
    113 //      movq %rbp,FP_OFFSET(%rdi)
    114 //
    115 //      // Return to thread
    116 //
    117 //      ret
    118 //
    119 //.text
    120 //      .align 2
    121 //.globl        CtxRet
    122 //CtxRet:
    123 //      // Load new context from the "to" area.
    124 //
    125 //      movq SP_OFFSET(%rdi),%rsp
    126 //      movq FP_OFFSET(%rdi),%rbp
    127 //
    128 //      // Load volatile registers from the stack.
    129 //
    130 //      popq %rbx
    131 //      popq %r12
    132 //      popq %r13
    133 //      popq %r14
    134 //      popq %r15
    135 //
    136 //      // Load floating & SSE control words from the stack.
    137 //
    138 //      fldcw   4(%rsp)
    139 //      ldmxcsr 0(%rsp)
    140 //      addq   $8,%rsp
    141 //
    142 //      // Return to thread.
    143 //
    144 //      ret
    145 
    14678
    14779.text
  • libcfa/src/concurrency/invoke.c

    r3c06bba rdeca0f5  
    124124        struct FakeStack {
    125125            void *fixedRegisters[3];                    // fixed registers ebx, edi, esi (popped on 1st uSwitch, values unimportant)
    126             uint32_t mxcr;                        // SSE Status and Control bits (control bits are preserved across function calls)
    127             uint16_t fcw;                         // X97 FPU control word (preserved across function calls)
    128126            void *rturn;                          // where to go on return from uSwitch
    129127            void *dummyReturn;                          // fake return compiler would have pushed on call to uInvoke
     
    140138        fs->argument[0] = this;     // argument to invoke
    141139        fs->rturn = invoke;
    142         fs->mxcr = 0x1F80; //Vol. 2A 3-520
    143         fs->fcw = 0x037F;  //Vol. 1 8-7
    144140
    145141#elif defined( __x86_64 )
     
    147143        struct FakeStack {
    148144                void *fixedRegisters[5];            // fixed registers rbx, r12, r13, r14, r15
    149                 uint32_t mxcr;                      // SSE Status and Control bits (control bits are preserved across function calls)
    150                 uint16_t fcw;                       // X97 FPU control word (preserved across function calls)
    151145                void *rturn;                        // where to go on return from uSwitch
    152146                void *dummyReturn;                  // NULL return address to provide proper alignment
     
    162156        fs->fixedRegisters[0] = this;
    163157        fs->fixedRegisters[1] = invoke;
    164         fs->mxcr = 0x1F80; //Vol. 2A 3-520
    165         fs->fcw = 0x037F;  //Vol. 1 8-7
    166158
    167159#elif defined( __ARM_ARCH )
  • libcfa/src/concurrency/invoke.h

    r3c06bba rdeca0f5  
    264264        // void CtxRet   ( void * dst  ) asm ("CtxRet");
    265265
    266         #if   defined( __i386 )
    267         #define CtxGet( ctx ) __asm__ ( \
    268                         "movl %%esp,%0\n"   \
    269                         "movl %%ebp,%1\n"   \
    270                 : "=rm" (ctx.SP), "=rm" (ctx.FP) )
    271         #elif defined( __x86_64 )
    272         #define CtxGet( ctx ) __asm__ ( \
    273                         "movq %%rsp,%0\n"   \
    274                         "movq %%rbp,%1\n"   \
    275                 : "=rm" (ctx.SP), "=rm" (ctx.FP) )
    276         #elif defined( __ARM_ARCH )
    277         #define CtxGet( ctx ) __asm__ ( \
    278                         "mov %0,%%sp\n"   \
    279                         "mov %1,%%r11\n"   \
    280                 : "=rm" (ctx.SP), "=rm" (ctx.FP) )
    281         #else
    282                 #error unknown hardware architecture
    283         #endif
    284 
    285266#endif //_INVOKE_PRIVATE_H_
    286267#endif //! defined(__CFA_INVOKE_PRIVATE__)
  • libcfa/src/concurrency/kernel.cfa

    r3c06bba rdeca0f5  
    3636#include "invoke.h"
    3737
     38//-----------------------------------------------------------------------------
     39// Some assembly required
     40#if   defined( __i386 )
     41        #define CtxGet( ctx )        \
     42                __asm__ volatile (     \
     43                        "movl %%esp,%0\n"\
     44                        "movl %%ebp,%1\n"\
     45                        : "=rm" (ctx.SP),\
     46                                "=rm" (ctx.FP) \
     47                )
     48
     49        // mxcr : SSE Status and Control bits (control bits are preserved across function calls)
     50        // fcw  : X87 FPU control word (preserved across function calls)
     51        #define __x87_store         \
     52                uint32_t __mxcr;      \
     53                uint16_t __fcw;       \
     54                __asm__ volatile (    \
     55                        "stmxcsr %0\n"  \
     56                        "fnstcw  %1\n"  \
     57                        : "=m" (__mxcr),\
     58                                "=m" (__fcw)  \
     59                )
     60
     61        #define __x87_load         \
     62                __asm__ volatile (   \
     63                        "fldcw  %1\n"  \
     64                        "ldmxcsr %0\n" \
     65                        ::"m" (__mxcr),\
     66                                "m" (__fcw)  \
     67                )
     68
     69#elif defined( __x86_64 )
     70        #define CtxGet( ctx )        \
     71                __asm__ volatile (     \
     72                        "movq %%rsp,%0\n"\
     73                        "movq %%rbp,%1\n"\
     74                        : "=rm" (ctx.SP),\
     75                                "=rm" (ctx.FP) \
     76                )
     77
     78        #define __x87_store         \
     79                uint32_t __mxcr;      \
     80                uint16_t __fcw;       \
     81                __asm__ volatile (    \
     82                        "stmxcsr %0\n"  \
     83                        "fnstcw  %1\n"  \
     84                        : "=m" (__mxcr),\
     85                                "=m" (__fcw)  \
     86                )
     87
     88        #define __x87_load          \
     89                __asm__ volatile (    \
     90                        "fldcw  %1\n"   \
     91                        "ldmxcsr %0\n"  \
     92                        :: "m" (__mxcr),\
     93                                "m" (__fcw)  \
     94                )
     95
     96
     97#elif defined( __ARM_ARCH )
     98#define CtxGet( ctx ) __asm__ ( \
     99                "mov %0,%%sp\n"   \
     100                "mov %1,%%r11\n"   \
     101        : "=rm" (ctx.SP), "=rm" (ctx.FP) )
     102#else
     103        #error unknown hardware architecture
     104#endif
     105
     106//-----------------------------------------------------------------------------
    38107//Start and stop routine for the kernel, declared first to make sure they run first
    39108static void kernel_startup(void)  __attribute__(( constructor( STARTUP_PRIORITY_KERNEL ) ));
     
    274343        proc_cor->state = Active;
    275344        int local_errno = *__volatile_errno();
     345        #if defined( __i386 ) || defined( __x86_64 )
     346                __x87_store;
     347        #endif
    276348
    277349        // set new coroutine that the processor is executing
     
    283355        proc_cor->state = proc_cor->state == Halted ? Halted : Inactive;
    284356        thrd_src->state = Active;
     357
     358        #if defined( __i386 ) || defined( __x86_64 )
     359                __x87_load;
     360        #endif
    285361        *__volatile_errno() = local_errno;
    286362}
Note: See TracChangeset for help on using the changeset viewer.