| [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
|
|---|
| [a4bdbcd] | 12 | // Last Modified On : Sun Sep 6 18:23:37 2020
|
|---|
| 13 | // Update Count : 5
|
|---|
| [e4745d7a] | 14 | //
|
|---|
| 15 |
|
|---|
| [636d115b] | 16 | // The context switch routine requires the initial the stack of a thread to
|
|---|
| 17 | // look like the thread has saved its context in the normal manner.
|
|---|
| [e4745d7a] | 18 |
|
|---|
| [636d115b] | 19 | // Offsets must synchronized with the __stack_context_t in invoke.h.
|
|---|
| [e4745d7a] | 20 |
|
|---|
| 21 | #define PTR_BYTE 4
|
|---|
| 22 | #define SP_OFFSET ( 0 * PTR_BYTE )
|
|---|
| 23 | #define FP_OFFSET ( 1 * PTR_BYTE )
|
|---|
| 24 |
|
|---|
| [636d115b] | 25 | // Context switch between coroutines/tasks.
|
|---|
| 26 | // void __cfactx_switch( struct __stack_context_t * from, struct __stack_context_t * to ) ;
|
|---|
| 27 | // Arguments "from" in register 4(%esp), "to" in register 20(%esp)
|
|---|
| 28 |
|
|---|
| 29 | .file "CtxSwitch-i386.S"
|
|---|
| [3c06bba] | 30 | .text
|
|---|
| [e4745d7a] | 31 | .align 2
|
|---|
| [636d115b] | 32 | .global __cfactx_switch
|
|---|
| 33 | .type __cfactx_switch, @function
|
|---|
| [c7a900a] | 34 | __cfactx_switch:
|
|---|
| [e4745d7a] | 35 |
|
|---|
| 36 | // Copy the "from" context argument from the stack to register eax
|
|---|
| [a4bdbcd] | 37 | // Return address is at 0(%esp), with parameters following.
|
|---|
| [e4745d7a] | 38 |
|
|---|
| 39 | movl 4(%esp),%eax
|
|---|
| 40 |
|
|---|
| 41 | // Save volatile registers on the stack.
|
|---|
| 42 |
|
|---|
| 43 | pushl %ebx
|
|---|
| 44 | pushl %edi
|
|---|
| 45 | pushl %esi
|
|---|
| 46 |
|
|---|
| 47 | // Save old context in the "from" area.
|
|---|
| 48 |
|
|---|
| 49 | movl %esp,SP_OFFSET(%eax)
|
|---|
| 50 | movl %ebp,FP_OFFSET(%eax)
|
|---|
| 51 |
|
|---|
| [a4bdbcd] | 52 | // Copy the "to" context argument from the stack to register eax. Having
|
|---|
| 53 | // pushed 3 words (= 12 bytes) on the stack, the argument is now at
|
|---|
| 54 | // 8 + 12 = 20(%esp).
|
|---|
| [e4745d7a] | 55 |
|
|---|
| [b78129a] | 56 | movl 20(%esp),%eax
|
|---|
| [e4745d7a] | 57 |
|
|---|
| 58 | // Load new context from the "to" area.
|
|---|
| 59 |
|
|---|
| 60 | movl SP_OFFSET(%eax),%esp
|
|---|
| 61 | movl FP_OFFSET(%eax),%ebp
|
|---|
| 62 |
|
|---|
| 63 | // Load volatile registers from the stack.
|
|---|
| 64 |
|
|---|
| 65 | popl %esi
|
|---|
| 66 | popl %edi
|
|---|
| 67 | popl %ebx
|
|---|
| 68 |
|
|---|
| 69 | // Return to thread.
|
|---|
| 70 |
|
|---|
| 71 | ret
|
|---|
| [636d115b] | 72 | .size __cfactx_switch, .-__cfactx_switch
|
|---|
| [e4745d7a] | 73 |
|
|---|
| 74 | // Local Variables: //
|
|---|
| [6b0b624] | 75 | // mode: c //
|
|---|
| 76 | // tab-width: 4 //
|
|---|
| [e4745d7a] | 77 | // End: //
|
|---|