source: libcfa/src/concurrency/CtxSwitch-x86_64.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: 3.2 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-x86_64.S --
8//
9// Author           : Thierry Delisle
10// Created On       : Mon Nov 28 12:27:26 2016
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Fri Jul 21 22:28:11 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        8
39#define SP_OFFSET       ( 0 * PTR_BYTE )
40#define FP_OFFSET       ( 1 * PTR_BYTE )
41
42.text
43        .align 2
44.globl  CtxSwitch
45CtxSwitch:
46
47        // Save floating & SSE control words on the stack.
48
49        subq   $8,%rsp
50        stmxcsr 0(%rsp)         // 4 bytes
51        fnstcw  4(%rsp)         // 2 bytes
52
53        // Save volatile registers on the stack.
54
55        pushq %r15
56        pushq %r14
57        pushq %r13
58        pushq %r12
59        pushq %rbx
60
61        // Save old context in the "from" area.
62
63        movq %rsp,SP_OFFSET(%rdi)
64        movq %rbp,FP_OFFSET(%rdi)
65
66        // Load new context from the "to" area.
67
68        movq SP_OFFSET(%rsi),%rsp
69        movq FP_OFFSET(%rsi),%rbp
70
71        // Load volatile registers from the stack.
72
73        popq %rbx
74        popq %r12
75        popq %r13
76        popq %r14
77        popq %r15
78
79        // Load floating & SSE control words from the stack.
80
81        fldcw   4(%rsp)
82        ldmxcsr 0(%rsp)
83        addq   $8,%rsp
84
85        // Return to thread.
86
87        ret
88
89//.text
90//      .align 2
91//.globl        CtxStore
92//CtxStore:
93//      // Save floating & SSE control words on the stack.
94//
95//      subq   $8,%rsp
96//      stmxcsr 0(%rsp)         // 4 bytes
97//      fnstcw  4(%rsp)         // 2 bytes
98//
99//      // Save volatile registers on the stack.
100//
101//      pushq %r15
102//      pushq %r14
103//      pushq %r13
104//      pushq %r12
105//      pushq %rbx
106//
107//      // Save old context in the "from" area.
108//
109//      movq %rsp,SP_OFFSET(%rdi)
110//      movq %rbp,FP_OFFSET(%rdi)
111//
112//      // Return to thread
113//
114//      ret
115//
116//.text
117//      .align 2
118//.globl        CtxRet
119//CtxRet:
120//      // Load new context from the "to" area.
121//
122//      movq SP_OFFSET(%rdi),%rsp
123//      movq FP_OFFSET(%rdi),%rbp
124//
125//      // Load volatile registers from the stack.
126//
127//      popq %rbx
128//      popq %r12
129//      popq %r13
130//      popq %r14
131//      popq %r15
132//
133//      // Load floating & SSE control words from the stack.
134//
135//      fldcw   4(%rsp)
136//      ldmxcsr 0(%rsp)
137//      addq   $8,%rsp
138//
139//      // Return to thread.
140//
141//      ret
142
143
144.text
145        .align 2
146.globl  CtxInvokeStub
147CtxInvokeStub:
148        movq %rbx, %rdi
149        jmp *%r12
150
151// Local Variables: //
152// mode: c //
153// tab-width: 4 //
154// End: //
Note: See TracBrowser for help on using the repository browser.