diff contextSwitch.s @ 76:9ddbb071142d

make hardware independent and port to 64bit
author Merten Sach <msach@mailbox.tu-berlin.de>
date Thu, 16 Jun 2011 14:41:15 +0200
parents f6990e1ba998
children dbfc8382d546 bfaebdf60df3
line diff
     1.1 --- a/contextSwitch.s	Thu Jun 02 13:55:51 2011 +0200
     1.2 +++ b/contextSwitch.s	Thu Jun 16 14:41:15 2011 +0200
     1.3 @@ -7,64 +7,70 @@
     1.4  //Arguments: Pointer to variable holding address
     1.5  .globl saveCoreLoopReturnAddr
     1.6  saveCoreLoopReturnAddr:
     1.7 -    movl    0x4(%esp) , %eax       #load pointer
     1.8 -    movl    $coreLoopReturn, %ecx   #load label address
     1.9 -    movl    %ecx, (%eax)           #save address
    1.10 +    movq    $coreLoopReturn, %rcx   #load label address
    1.11 +    movq    %rcx, (%rdi)           #save address to pointer
    1.12      ret
    1.13  
    1.14  
    1.15 +//Initializes VirtProcrFn at first run for 64 bit mode
    1.16 +//Puts argument from stack into registers
    1.17 +.globl startVirtProcrFn
    1.18 +startVirtProcrFn:
    1.19 +    movq    %rdi      , %rsi #get second argument from first argument of switchVP
    1.20 +    movq    0x08(%rsp), %rdi #get first argument
    1.21 +    movq    (%rsp)    , %rax #get function addr
    1.22 +    jmp     *%rax
    1.23  
    1.24 -//Switches form CoreLoop to VP ether normal VP or the Master Loop
    1.25 +//Switches form CoreLoop to VP ether a normal VP or the Master Loop
    1.26  //switch to virt procr's stack and frame ptr then jump to virt procr fn
    1.27  /* VirtProcr  offsets:
    1.28 - * 0xc  stackPtr
    1.29 - * 0x10 framePtr
    1.30 - * 0x14 nextInstrPt
    1.31 - * 0x1c coreLoopFramePtr
    1.32 - * 0x20 coreLoopStackPtr
    1.33 + * 0x10  stackPtr
    1.34 + * 0x18 framePtr
    1.35 + * 0x20 nextInstrPt
    1.36 + * 0x30 coreLoopFramePtr
    1.37 + * 0x38 coreLoopStackPtr
    1.38   *
    1.39   * _VMSMasterEnv  offsets:
    1.40 - * 0x24 coreLoopReturnPt
    1.41 - * 0x2c masterLock
    1.42 + * 0x48 coreLoopReturnPt
    1.43 + * 0x54 masterLock
    1.44   */
    1.45  .globl switchToVP
    1.46  switchToVP:
    1.47 -    movl    0x4(%esp) , %ecx         #get VirtProcr
    1.48 -    movl    %esp      , 0x20(%ecx)   #save core loop stack pointer 
    1.49 -    movl    %ebp      , 0x1c(%ecx)   #save core loop frame pointer
    1.50 -    movl    0x0c(%ecx), %esp         #restore stack pointer
    1.51 -    movl    0x10(%ecx), %ebp         #restore frame pointer
    1.52 -    movl    0x14(%ecx), %eax         #get jmp pointer
    1.53 -    jmp     *%eax                    #jmp to VP
    1.54 +    #VirtProcr in %rdi
    1.55 +    movq    %rsp      , 0x38(%rdi)   #save core loop stack pointer 
    1.56 +    movq    %rbp      , 0x30(%rdi)   #save core loop frame pointer
    1.57 +    movq    0x10(%rdi), %rsp         #restore stack pointer
    1.58 +    movq    0x18(%rdi), %rbp         #restore frame pointer
    1.59 +    movq    0x20(%rdi), %rax         #get jmp pointer
    1.60 +    jmp     *%rax                    #jmp to VP
    1.61  coreLoopReturn:
    1.62      ret
    1.63  
    1.64      
    1.65  //switches to core loop. saves return address
    1.66  /* VirtProcr  offsets:
    1.67 - * 0xc  stackPtr
    1.68 - * 0x10 framePtr
    1.69 - * 0x14 nextInstrPt
    1.70 - * 0x1c coreLoopFramePtr
    1.71 - * 0x20 coreLoopStackPtr
    1.72 + * 0x10  stackPtr
    1.73 + * 0x18 framePtr
    1.74 + * 0x20 nextInstrPt
    1.75 + * 0x30 coreLoopFramePtr
    1.76 + * 0x38 coreLoopStackPtr
    1.77   *
    1.78   * _VMSMasterEnv  offsets:
    1.79 - * 0x24 coreLoopReturnPt
    1.80 - * 0x28 coreLoopEndPt
    1.81 - * 0x2c masterLock
    1.82 + * 0x48 coreLoopReturnPt
    1.83 + * 0x54 masterLock
    1.84   */
    1.85  .globl switchToCoreLoop
    1.86  switchToCoreLoop:
    1.87 -    movl    0x4(%esp) , %ecx         #get VirtProcr
    1.88 -    movl    $VPReturn , 0x14(%ecx)   #store return address
    1.89 -    movl    %esp      , 0x0c(%ecx)   #save stack pointer 
    1.90 -    movl    %ebp      , 0x10(%ecx)   #save frame pointer
    1.91 -    movl    0x20(%ecx), %esp         #restore stack pointer
    1.92 -    movl    0x1c(%ecx), %ebp         #restore frame pointer
    1.93 -    movl    $_VMSMasterEnv, %ecx
    1.94 -    movl    (%ecx)    , %ecx
    1.95 -    movl    0x24(%ecx), %eax         #get CoreLoopStartPt
    1.96 -    jmp     *%eax                    #jmp to CoreLoop
    1.97 +    #VirtProcr in %rdi
    1.98 +    movq    $VPReturn , 0x20(%rdi)   #store return address
    1.99 +    movq    %rsp      , 0x10(%rdi)   #save stack pointer 
   1.100 +    movq    %rbp      , 0x18(%rdi)   #save frame pointer
   1.101 +    movq    0x38(%rdi), %rsp         #restore stack pointer
   1.102 +    movq    0x30(%rdi), %rbp         #restore frame pointer
   1.103 +    movq    $_VMSMasterEnv, %rcx
   1.104 +    movq    (%rcx)    , %rcx
   1.105 +    movq    0x48(%rcx), %rax         #get CoreLoopStartPt
   1.106 +    jmp     *%rax                    #jmp to CoreLoop
   1.107  VPReturn:
   1.108      ret
   1.109  
   1.110 @@ -73,55 +79,57 @@
   1.111  //switches to core loop from master. saves return address
   1.112  //Releases masterLock so the next MasterLoop can be executed
   1.113  /* VirtProcr  offsets:
   1.114 - * 0xc  stackPtr
   1.115 - * 0x10 framePtr
   1.116 - * 0x14 nextInstrPt
   1.117 - * 0x1c coreLoopFramePtr
   1.118 - * 0x20 coreLoopStackPtr
   1.119 + * 0x10  stackPtr
   1.120 + * 0x18 framePtr
   1.121 + * 0x20 nextInstrPt
   1.122 + * 0x30 coreLoopFramePtr
   1.123 + * 0x38 coreLoopStackPtr
   1.124   *
   1.125   * _VMSMasterEnv  offsets:
   1.126 - * 0x24 coreLoopReturnPt
   1.127 - * 0x2c masterLock
   1.128 + * 0x48 coreLoopReturnPt
   1.129 + * 0x54 masterLock
   1.130   */
   1.131  .globl masterSwitchToCoreLoop
   1.132  masterSwitchToCoreLoop:
   1.133 -    movl    0x4(%esp) , %ecx         #get VirtProcr
   1.134 -    movl    $MasterReturn, 0x14(%ecx)   #store return address
   1.135 -    movl    %esp      , 0x0c(%ecx)   #save stack pointer 
   1.136 -    movl    %ebp      , 0x10(%ecx)   #save frame pointer
   1.137 -    movl    0x20(%ecx), %esp         #restore stack pointer
   1.138 -    movl    0x1c(%ecx), %ebp         #restore frame pointer
   1.139 -    movl    $_VMSMasterEnv, %ecx
   1.140 -    movl    (%ecx)    , %ecx
   1.141 -    movl    0x24(%ecx), %eax         #get CoreLoopStartPt
   1.142 -    movl    $0x0      , 0x2c(%ecx)   #release lock
   1.143 -    jmp     *%eax                    #jmp to CoreLoop
   1.144 +    #VirtProcr in %rdi
   1.145 +    movq    $MasterReturn, 0x20(%rdi)   #store return address
   1.146 +    movq    %rsp      , 0x10(%rdi)   #save stack pointer 
   1.147 +    movq    %rbp      , 0x18(%rdi)   #save frame pointer
   1.148 +    movq    0x38(%rdi), %rsp         #restore stack pointer
   1.149 +    movq    0x30(%rdi), %rbp         #restore frame pointer
   1.150 +    movq    $_VMSMasterEnv, %rcx
   1.151 +    movq    (%rcx)    , %rcx
   1.152 +    movq    0x48(%rcx), %rax         #get CoreLoopStartPt
   1.153 +    movl    $0x0      , 0x54(%rcx)   #release lock
   1.154 +    jmp     *%rax                    #jmp to CoreLoop
   1.155  MasterReturn:
   1.156      ret
   1.157  
   1.158  
   1.159  //Switch to terminateCoreLoop
   1.160 +//therefor switch to coreLoop context from master context
   1.161  // no need to call because the stack is already set up for switchVP
   1.162 +// and virtPr is in %rdi
   1.163  // and both functions have the same argument.
   1.164  // do not save register of VP because this function will never return
   1.165  /* VirtProcr  offsets:
   1.166 - * 0xc  stackPtr
   1.167 - * 0x10 framePtr
   1.168 - * 0x14 nextInstrPt
   1.169 - * 0x1c coreLoopFramePtr
   1.170 - * 0x20 coreLoopStackPtr
   1.171 + * 0x10  stackPtr
   1.172 + * 0x18 framePtr
   1.173 + * 0x20 nextInstrPt
   1.174 + * 0x30 coreLoopFramePtr
   1.175 + * 0x38 coreLoopStackPtr
   1.176   *
   1.177   * _VMSMasterEnv  offsets:
   1.178 - * 0x24 coreLoopReturnPt
   1.179 - * 0x2c masterLock
   1.180 + * 0x48 coreLoopReturnPt
   1.181 + * 0x58 masterLock
   1.182   */
   1.183  .globl asmTerminateCoreLoop
   1.184  asmTerminateCoreLoop:
   1.185 -    movl    0x4(%esp) , %ecx         #get VirtProcr
   1.186 -    movl    0x20(%ecx), %esp         #restore stack pointer
   1.187 -    movl    0x1c(%ecx), %ebp         #restore frame pointer
   1.188 -    movl    $terminateCoreLoop, %eax
   1.189 -    jmp     *%eax                    #jmp to CoreLoop
   1.190 +    #VirtProcr in %rdi
   1.191 +    movq    0x38(%rdi), %rsp         #restore stack pointer
   1.192 +    movq    0x30(%rdi), %rbp         #restore frame pointer
   1.193 +    movq    $terminateCoreLoop, %rax
   1.194 +    jmp     *%rax                    #jmp to CoreLoop
   1.195  
   1.196  
   1.197  /*
   1.198 @@ -130,13 +138,12 @@
   1.199   */
   1.200  .globl asmTerminateCoreLoopSeq
   1.201  asmTerminateCoreLoopSeq:
   1.202 -    movl    0x4(%esp) , %ecx         #get VirtProcr
   1.203 -    movl    0x20(%ecx), %esp         #restore stack pointer
   1.204 -    movl    0x1c(%ecx), %ebp         #restore frame pointer
   1.205 -    sub     $0x4      , %esp
   1.206 -    movl    %ecx      , (%esp)       #put argument on stack
   1.207 +    #VirtProcr in %rdi
   1.208 +    movq    0x38(%rdi), %rsp         #restore stack pointer
   1.209 +    movq    0x30(%rdi), %rbp         #restore frame pointer
   1.210 +    #argument is in %rdi
   1.211      call    VMS__dissipate_procr
   1.212 -    movl    %ebp      , %esp        #goto the coreLoops stack
   1.213 -    pop     %ebp        #restore the old framepointer
   1.214 +    movq    %rbp      , %rsp        #goto the coreLoops stack
   1.215 +    pop     %rbp        #restore the old framepointer
   1.216      ret                 #return from core loop
   1.217