| [e4745d7a] | 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-i386.S --
|
|---|
| 9 | //
|
|---|
| 10 | // Author : Thierry Delisle
|
|---|
| 11 | // Created On : Tue Dec 6 12:27:26 2016
|
|---|
| 12 | // Last Modified By : Thierry Delisle
|
|---|
| 13 | // Last Modified On : Tue Dec 6 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 4
|
|---|
| 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 | // 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 |
|
|---|
| [7b2c2c5f] | 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 |
|
|---|
| [e4745d7a] | 60 | // Save volatile registers on the stack.
|
|---|
| 61 |
|
|---|
| 62 | pushl %ebx
|
|---|
| 63 | pushl %edi
|
|---|
| 64 | pushl %esi
|
|---|
| 65 |
|
|---|
| 66 | // Save old context in the "from" area.
|
|---|
| 67 |
|
|---|
| 68 | movl %esp,SP_OFFSET(%eax)
|
|---|
| 69 | movl %ebp,FP_OFFSET(%eax)
|
|---|
| 70 | // movl 4(%ebp),%ebx // save previous eip for debugger
|
|---|
| 71 | // movl %ebx,PC_OFFSET(%eax)
|
|---|
| 72 |
|
|---|
| 73 | // Copy the "to" context argument from the stack to register eax
|
|---|
| 74 | // Having pushed three words (= 12 bytes) on the stack, the
|
|---|
| 75 | // argument is now at 8 + 12 = 20(%esp)
|
|---|
| 76 |
|
|---|
| [7b2c2c5f] | 77 | movl 28(%esp),%eax
|
|---|
| [e4745d7a] | 78 |
|
|---|
| 79 | // Load new context from the "to" area.
|
|---|
| 80 |
|
|---|
| 81 | movl SP_OFFSET(%eax),%esp
|
|---|
| 82 | movl FP_OFFSET(%eax),%ebp
|
|---|
| 83 |
|
|---|
| 84 | // Load volatile registers from the stack.
|
|---|
| 85 |
|
|---|
| 86 | popl %esi
|
|---|
| 87 | popl %edi
|
|---|
| 88 | popl %ebx
|
|---|
| 89 |
|
|---|
| [7b2c2c5f] | 90 | // Load floating & SSE control words from the stack.
|
|---|
| 91 |
|
|---|
| 92 | fldcw 4(%esp)
|
|---|
| 93 | ldmxcsr 0(%esp)
|
|---|
| 94 | add $8,%esp
|
|---|
| 95 |
|
|---|
| [e4745d7a] | 96 | // Return to thread.
|
|---|
| 97 |
|
|---|
| 98 | ret
|
|---|
| 99 |
|
|---|
| 100 | // Local Variables: //
|
|---|
| 101 | // compile-command: "make install" //
|
|---|
| 102 | // End: //
|
|---|