[e4745d7a] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
| 6 | // |
---|
| 7 | // CtxSwitch-i386.S -- |
---|
| 8 | // |
---|
| 9 | // Author : Thierry Delisle |
---|
| 10 | // Created On : Tue Dec 6 12:27:26 2016 |
---|
[6b0b624] | 11 | // Last Modified By : Peter A. Buhr |
---|
| 12 | // Last Modified On : Fri Jul 21 22:29:25 2017 |
---|
| 13 | // Update Count : 1 |
---|
[e4745d7a] | 14 | // |
---|
| 15 | // This library is free software; you can redistribute it and/or modify it |
---|
| 16 | // under the terms of the GNU Lesser General Public License as published by the |
---|
| 17 | // Free Software Foundation; either version 2.1 of the License, or (at your |
---|
| 18 | // option) any later version. |
---|
| 19 | // |
---|
| 20 | // This library is distributed in the hope that it will be useful, but WITHOUT |
---|
| 21 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
| 22 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
---|
| 23 | // for more details. |
---|
| 24 | // |
---|
| 25 | // You should have received a copy of the GNU Lesser General Public License |
---|
| 26 | // along with this library. |
---|
| 27 | // |
---|
| 28 | |
---|
| 29 | // This context switch routine depends on the fact that the stack of a new |
---|
| 30 | // thread has been set up to look like the thread has saved its context in |
---|
| 31 | // the normal manner. |
---|
| 32 | // |
---|
| 33 | // void CtxSwitch( machine_context *from, machine_context *to ); |
---|
| 34 | |
---|
| 35 | // Offsets in the context structure. This needs to be synchronized with the |
---|
| 36 | // high level code a little better. |
---|
| 37 | |
---|
| 38 | #define PTR_BYTE 4 |
---|
| 39 | #define SP_OFFSET ( 0 * PTR_BYTE ) |
---|
| 40 | #define FP_OFFSET ( 1 * PTR_BYTE ) |
---|
| 41 | #define PC_OFFSET ( 2 * PTR_BYTE ) |
---|
| 42 | |
---|
[3c06bba] | 43 | .text |
---|
[e4745d7a] | 44 | .align 2 |
---|
[c7a900a] | 45 | .globl __cfactx_switch |
---|
| 46 | .type __cfactx_switch, @function |
---|
| 47 | __cfactx_switch: |
---|
[e4745d7a] | 48 | |
---|
| 49 | // Copy the "from" context argument from the stack to register eax |
---|
| 50 | // Return address is at 0(%esp), with parameters following |
---|
| 51 | |
---|
| 52 | movl 4(%esp),%eax |
---|
| 53 | |
---|
| 54 | // Save volatile registers on the stack. |
---|
| 55 | |
---|
| 56 | pushl %ebx |
---|
| 57 | pushl %edi |
---|
| 58 | pushl %esi |
---|
| 59 | |
---|
| 60 | // Save old context in the "from" area. |
---|
| 61 | |
---|
| 62 | movl %esp,SP_OFFSET(%eax) |
---|
| 63 | movl %ebp,FP_OFFSET(%eax) |
---|
| 64 | |
---|
| 65 | // Copy the "to" context argument from the stack to register eax |
---|
| 66 | // Having pushed three words (= 12 bytes) on the stack, the |
---|
| 67 | // argument is now at 8 + 12 = 20(%esp) |
---|
| 68 | |
---|
[b78129a] | 69 | movl 20(%esp),%eax |
---|
[e4745d7a] | 70 | |
---|
| 71 | // Load new context from the "to" area. |
---|
| 72 | |
---|
| 73 | movl SP_OFFSET(%eax),%esp |
---|
| 74 | movl FP_OFFSET(%eax),%ebp |
---|
| 75 | |
---|
| 76 | // Load volatile registers from the stack. |
---|
| 77 | |
---|
| 78 | popl %esi |
---|
| 79 | popl %edi |
---|
| 80 | popl %ebx |
---|
| 81 | |
---|
| 82 | // Return to thread. |
---|
| 83 | |
---|
| 84 | ret |
---|
[c7a900a] | 85 | .size __cfactx_switch, .-__cfactx_switch |
---|
[e4745d7a] | 86 | |
---|
| 87 | // Local Variables: // |
---|
[6b0b624] | 88 | // mode: c // |
---|
| 89 | // tab-width: 4 // |
---|
[e4745d7a] | 90 | // End: // |
---|