annotate 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
rev   line source
msach@71 1 .data
msach@71 2
msach@71 3
msach@71 4 .text
msach@71 5
msach@71 6 //Save return label address for the coreLoop to pointer
msach@71 7 //Arguments: Pointer to variable holding address
msach@71 8 .globl saveCoreLoopReturnAddr
msach@71 9 saveCoreLoopReturnAddr:
msach@76 10 movq $coreLoopReturn, %rcx #load label address
msach@76 11 movq %rcx, (%rdi) #save address to pointer
msach@71 12 ret
msach@71 13
msach@71 14
msach@76 15 //Initializes VirtProcrFn at first run for 64 bit mode
msach@76 16 //Puts argument from stack into registers
msach@76 17 .globl startVirtProcrFn
msach@76 18 startVirtProcrFn:
msach@76 19 movq %rdi , %rsi #get second argument from first argument of switchVP
msach@76 20 movq 0x08(%rsp), %rdi #get first argument
msach@76 21 movq (%rsp) , %rax #get function addr
msach@76 22 jmp *%rax
msach@71 23
msach@76 24 //Switches form CoreLoop to VP ether a normal VP or the Master Loop
msach@71 25 //switch to virt procr's stack and frame ptr then jump to virt procr fn
msach@71 26 /* VirtProcr offsets:
msach@76 27 * 0x10 stackPtr
msach@76 28 * 0x18 framePtr
msach@76 29 * 0x20 nextInstrPt
msach@76 30 * 0x30 coreLoopFramePtr
msach@76 31 * 0x38 coreLoopStackPtr
msach@71 32 *
msach@71 33 * _VMSMasterEnv offsets:
msach@76 34 * 0x48 coreLoopReturnPt
msach@76 35 * 0x54 masterLock
msach@71 36 */
msach@71 37 .globl switchToVP
msach@71 38 switchToVP:
msach@76 39 #VirtProcr in %rdi
msach@76 40 movq %rsp , 0x38(%rdi) #save core loop stack pointer
msach@76 41 movq %rbp , 0x30(%rdi) #save core loop frame pointer
msach@76 42 movq 0x10(%rdi), %rsp #restore stack pointer
msach@76 43 movq 0x18(%rdi), %rbp #restore frame pointer
msach@76 44 movq 0x20(%rdi), %rax #get jmp pointer
msach@76 45 jmp *%rax #jmp to VP
msach@71 46 coreLoopReturn:
msach@71 47 ret
msach@71 48
msach@71 49
msach@71 50 //switches to core loop. saves return address
msach@71 51 /* VirtProcr offsets:
msach@76 52 * 0x10 stackPtr
msach@76 53 * 0x18 framePtr
msach@76 54 * 0x20 nextInstrPt
msach@76 55 * 0x30 coreLoopFramePtr
msach@76 56 * 0x38 coreLoopStackPtr
msach@71 57 *
msach@71 58 * _VMSMasterEnv offsets:
msach@76 59 * 0x48 coreLoopReturnPt
msach@76 60 * 0x54 masterLock
msach@71 61 */
msach@71 62 .globl switchToCoreLoop
msach@71 63 switchToCoreLoop:
msach@76 64 #VirtProcr in %rdi
msach@76 65 movq $VPReturn , 0x20(%rdi) #store return address
msach@76 66 movq %rsp , 0x10(%rdi) #save stack pointer
msach@76 67 movq %rbp , 0x18(%rdi) #save frame pointer
msach@76 68 movq 0x38(%rdi), %rsp #restore stack pointer
msach@76 69 movq 0x30(%rdi), %rbp #restore frame pointer
msach@76 70 movq $_VMSMasterEnv, %rcx
msach@76 71 movq (%rcx) , %rcx
msach@76 72 movq 0x48(%rcx), %rax #get CoreLoopStartPt
msach@76 73 jmp *%rax #jmp to CoreLoop
msach@71 74 VPReturn:
msach@71 75 ret
msach@71 76
msach@71 77
msach@71 78
msach@71 79 //switches to core loop from master. saves return address
msach@73 80 //Releases masterLock so the next MasterLoop can be executed
msach@71 81 /* VirtProcr offsets:
msach@76 82 * 0x10 stackPtr
msach@76 83 * 0x18 framePtr
msach@76 84 * 0x20 nextInstrPt
msach@76 85 * 0x30 coreLoopFramePtr
msach@76 86 * 0x38 coreLoopStackPtr
msach@71 87 *
msach@71 88 * _VMSMasterEnv offsets:
msach@76 89 * 0x48 coreLoopReturnPt
msach@76 90 * 0x54 masterLock
msach@71 91 */
msach@71 92 .globl masterSwitchToCoreLoop
msach@71 93 masterSwitchToCoreLoop:
msach@76 94 #VirtProcr in %rdi
msach@76 95 movq $MasterReturn, 0x20(%rdi) #store return address
msach@76 96 movq %rsp , 0x10(%rdi) #save stack pointer
msach@76 97 movq %rbp , 0x18(%rdi) #save frame pointer
msach@76 98 movq 0x38(%rdi), %rsp #restore stack pointer
msach@76 99 movq 0x30(%rdi), %rbp #restore frame pointer
msach@76 100 movq $_VMSMasterEnv, %rcx
msach@76 101 movq (%rcx) , %rcx
msach@76 102 movq 0x48(%rcx), %rax #get CoreLoopStartPt
msach@76 103 movl $0x0 , 0x54(%rcx) #release lock
msach@76 104 jmp *%rax #jmp to CoreLoop
msach@71 105 MasterReturn:
msach@71 106 ret
msach@71 107
msach@71 108
msach@71 109 //Switch to terminateCoreLoop
msach@76 110 //therefor switch to coreLoop context from master context
msach@73 111 // no need to call because the stack is already set up for switchVP
msach@76 112 // and virtPr is in %rdi
msach@73 113 // and both functions have the same argument.
msach@73 114 // do not save register of VP because this function will never return
msach@71 115 /* VirtProcr offsets:
msach@76 116 * 0x10 stackPtr
msach@76 117 * 0x18 framePtr
msach@76 118 * 0x20 nextInstrPt
msach@76 119 * 0x30 coreLoopFramePtr
msach@76 120 * 0x38 coreLoopStackPtr
msach@71 121 *
msach@71 122 * _VMSMasterEnv offsets:
msach@76 123 * 0x48 coreLoopReturnPt
msach@76 124 * 0x58 masterLock
msach@71 125 */
msach@71 126 .globl asmTerminateCoreLoop
msach@71 127 asmTerminateCoreLoop:
msach@76 128 #VirtProcr in %rdi
msach@76 129 movq 0x38(%rdi), %rsp #restore stack pointer
msach@76 130 movq 0x30(%rdi), %rbp #restore frame pointer
msach@76 131 movq $terminateCoreLoop, %rax
msach@76 132 jmp *%rax #jmp to CoreLoop
msach@75 133
msach@75 134
msach@75 135 /*
msach@75 136 * This one for the sequential version is special. It discards the current stack
msach@75 137 * and returns directly from the coreLoop after VMS__dissipate_procr was called
msach@75 138 */
msach@75 139 .globl asmTerminateCoreLoopSeq
msach@75 140 asmTerminateCoreLoopSeq:
msach@76 141 #VirtProcr in %rdi
msach@76 142 movq 0x38(%rdi), %rsp #restore stack pointer
msach@76 143 movq 0x30(%rdi), %rbp #restore frame pointer
msach@76 144 #argument is in %rdi
msach@75 145 call VMS__dissipate_procr
msach@76 146 movq %rbp , %rsp #goto the coreLoops stack
msach@76 147 pop %rbp #restore the old framepointer
msach@75 148 ret #return from core loop
msach@71 149