source: libcfa/src/concurrency/CtxSwitch-i386.S @ 8c01e1b

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

Swapped memory storage for context and stack information inside the coroutine implementation

  • Property mode set to 100644
File size: 2.6 KB
Line 
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
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Fri Jul 21 22:29:25 2017
13// Update Count     : 1
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
43.text
44        .align 2
45.globl  CtxSwitch
46CtxSwitch:
47
48        // Copy the "from" context argument from the stack to register eax
49        // Return address is at 0(%esp), with parameters following
50
51        movl 4(%esp),%eax
52
53        // Save floating & SSE control words on the stack.
54
55        sub    $8,%esp
56        stmxcsr 0(%esp)         // 4 bytes
57        fnstcw  4(%esp)         // 2 bytes
58
59        // Save volatile registers on the stack.
60
61        pushl %ebx
62        pushl %edi
63        pushl %esi
64
65        // Save old context in the "from" area.
66
67        movl %esp,SP_OFFSET(%eax)
68        movl %ebp,FP_OFFSET(%eax)
69
70        // Copy the "to" context argument from the stack to register eax
71        // Having pushed three words (= 12 bytes) on the stack, the
72        // argument is now at 8 + 12 = 20(%esp)
73
74        movl 28(%esp),%eax
75
76        // Load new context from the "to" area.
77
78        movl SP_OFFSET(%eax),%esp
79        movl FP_OFFSET(%eax),%ebp
80
81        // Load volatile registers from the stack.
82
83        popl %esi
84        popl %edi
85        popl %ebx
86
87        // Load floating & SSE control words from the stack.
88
89        fldcw   4(%esp)
90        ldmxcsr 0(%esp)
91        add    $8,%esp
92
93        // Return to thread.
94
95        ret
96
97// Local Variables: //
98// mode: c //
99// tab-width: 4 //
100// End: //
Note: See TracBrowser for help on using the repository browser.