source: libcfa/src/concurrency/CtxSwitch-i386.S @ 3c06bba

ADTarm-ehast-experimentalcleanup-dtorsenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 3c06bba was 3c06bba, checked in by tdelisle <tdelisle@…>, 5 years ago

Inlined coroutine context switch routine

  • Property mode set to 100644
File size: 2.6 KB
RevLine 
[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
[3c06bba]45        .globl CtxSwitch
46        .type  CtxSwitch, @function
[e4745d7a]47CtxSwitch:
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
[b2f6113]56        sub    $8,%esp
57        stmxcsr 0(%esp)         // 4 bytes
58        fnstcw  4(%esp)         // 2 bytes
[7b2c2c5f]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
71        // Copy the "to" context argument from the stack to register eax
72        // Having pushed three words (= 12 bytes) on the stack, the
73        // argument is now at 8 + 12 = 20(%esp)
74
[7b2c2c5f]75        movl 28(%esp),%eax
[e4745d7a]76
77        // Load new context from the "to" area.
78
79        movl SP_OFFSET(%eax),%esp
80        movl FP_OFFSET(%eax),%ebp
81
82        // Load volatile registers from the stack.
83
84        popl %esi
85        popl %edi
86        popl %ebx
87
[7b2c2c5f]88        // Load floating & SSE control words from the stack.
89
[b2f6113]90        fldcw   4(%esp)
91        ldmxcsr 0(%esp)
92        add    $8,%esp
[7b2c2c5f]93
[e4745d7a]94        // Return to thread.
95
96        ret
[3c06bba]97        .size  CtxSwitch, .-CtxSwitch
[e4745d7a]98
99// Local Variables: //
[6b0b624]100// mode: c //
101// tab-width: 4 //
[e4745d7a]102// End: //
Note: See TracBrowser for help on using the repository browser.