[78b3f52] | 1 | // -*- Mode: Asm -*- |
---|
| 2 | // |
---|
| 3 | // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo |
---|
| 4 | // |
---|
| 5 | // The contents of this file are covered under the licence agreement in the |
---|
| 6 | // file "LICENCE" distributed with Cforall. |
---|
| 7 | // |
---|
| 8 | // CtxSwitch-x86_64.S -- |
---|
| 9 | // |
---|
| 10 | // Author : Thierry Delisle |
---|
| 11 | // Created On : Mon Nov 28 12:27:26 2016 |
---|
| 12 | // Last Modified By : Thierry Delisle |
---|
| 13 | // Last Modified On : Mon Nov 28 12:27:26 2016 |
---|
| 14 | // Update Count : 0 |
---|
| 15 | // |
---|
| 16 | // This library is free software; you can redistribute it and/or modify it |
---|
| 17 | // under the terms of the GNU Lesser General Public License as published by the |
---|
| 18 | // Free Software Foundation; either version 2.1 of the License, or (at your |
---|
| 19 | // option) any later version. |
---|
| 20 | // |
---|
| 21 | // This library is distributed in the hope that it will be useful, but WITHOUT |
---|
| 22 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
| 23 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
---|
| 24 | // for more details. |
---|
| 25 | // |
---|
| 26 | // You should have received a copy of the GNU Lesser General Public License |
---|
| 27 | // along with this library. |
---|
| 28 | // |
---|
| 29 | |
---|
| 30 | // This context switch routine depends on the fact that the stack of a new |
---|
| 31 | // thread has been set up to look like the thread has saved its context in |
---|
| 32 | // the normal manner. |
---|
| 33 | // |
---|
| 34 | // void CtxSwitch( machine_context *from, machine_context *to ); |
---|
| 35 | |
---|
| 36 | // Offsets in the context structure. This needs to be synchronized with the |
---|
| 37 | // high level code a little better. |
---|
| 38 | |
---|
| 39 | #define PTR_BYTE 8 |
---|
| 40 | #define SP_OFFSET ( 0 * PTR_BYTE ) |
---|
| 41 | #define FP_OFFSET ( 1 * PTR_BYTE ) |
---|
| 42 | #define PC_OFFSET ( 2 * PTR_BYTE ) |
---|
| 43 | |
---|
| 44 | .text |
---|
| 45 | .align 2 |
---|
| 46 | .globl CtxSwitch |
---|
| 47 | CtxSwitch: |
---|
| 48 | |
---|
| 49 | // Save volatile registers on the stack. |
---|
| 50 | |
---|
| 51 | pushq %r15 |
---|
| 52 | pushq %r14 |
---|
| 53 | pushq %r13 |
---|
| 54 | pushq %r12 |
---|
| 55 | pushq %rbx |
---|
| 56 | |
---|
| 57 | // Save old context in the "from" area. |
---|
| 58 | |
---|
| 59 | movq %rsp,SP_OFFSET(%rdi) |
---|
| 60 | movq %rbp,FP_OFFSET(%rdi) |
---|
| 61 | |
---|
| 62 | // Load new context from the "to" area. |
---|
| 63 | |
---|
| 64 | movq SP_OFFSET(%rsi),%rsp |
---|
| 65 | movq FP_OFFSET(%rsi),%rbp |
---|
| 66 | |
---|
| 67 | // Load volatile registers from the stack. |
---|
| 68 | |
---|
| 69 | popq %rbx |
---|
| 70 | popq %r12 |
---|
| 71 | popq %r13 |
---|
| 72 | popq %r14 |
---|
| 73 | popq %r15 |
---|
| 74 | |
---|
| 75 | // Return to thread. |
---|
| 76 | |
---|
| 77 | ret |
---|
| 78 | |
---|
| 79 | .text |
---|
| 80 | .align 2 |
---|
[b58a5772] | 81 | .globl CtxInvokeStub |
---|
| 82 | CtxInvokeStub: |
---|
[5c81105] | 83 | movq %rbx, %rdi |
---|
| 84 | jmp *%r12 |
---|
[78b3f52] | 85 | |
---|
[eb2e723] | 86 | .text |
---|
| 87 | .align 2 |
---|
| 88 | .globl CtxGet |
---|
| 89 | CtxGet: |
---|
| 90 | movq %rsp,SP_OFFSET(%rdi) |
---|
| 91 | movq %rbp,FP_OFFSET(%rdi) |
---|
| 92 | |
---|
| 93 | ret |
---|
| 94 | |
---|
[78b3f52] | 95 | // Local Variables: // |
---|
| 96 | // mode: c // |
---|
| 97 | // tab-width: 4 // |
---|
| 98 | // End: // |
---|