source: libcfa/src/concurrency/CtxSwitch-x86_64.S @ f019069

arm-ehcleanup-dtorsenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since f019069 was f019069, checked in by Thierry Delisle <tdelisle@…>, 4 years ago

Some more work on suspend_then

  • Property mode set to 100644
File size: 3.7 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//-----------------------------------------------------------------------------
43// Regular context switch routine which enables switching from one context to anouther
44        .text
45        .align 2
46        .globl CtxSwitch
47        .type  CtxSwitch, @function
48CtxSwitch:
49
50        // Save volatile registers on the stack.
51
52        pushq %r15
53        pushq %r14
54        pushq %r13
55        pushq %r12
56        pushq %rbx
57
58        // Save old context in the "from" area.
59
60        movq %rsp,SP_OFFSET(%rdi)
61        movq %rbp,FP_OFFSET(%rdi)
62
63        // Load new context from the "to" area.
64
65        movq SP_OFFSET(%rsi),%rsp
66        movq FP_OFFSET(%rsi),%rbp
67
68        // Load volatile registers from the stack.
69
70        popq %rbx
71        popq %r12
72        popq %r13
73        popq %r14
74        popq %r15
75
76        // Return to thread.
77
78        ret
79        .size  CtxSwitch, .-CtxSwitch
80
81//-----------------------------------------------------------------------------
82// Part of a 2 part context switch routine, use with CtxRet, stores the current context and then makes a function call
83        .text
84        .align 2
85        .globl CtxStore
86        .type  CtxStore, @function
87CtxStore:
88
89        // Save volatile registers on the stack.
90
91        pushq %r15
92        pushq %r14
93        pushq %r13
94        pushq %r12
95        pushq %rbx
96
97        // Save old context in the "from" area.
98
99        movq %rsp,SP_OFFSET(%rdi)
100        movq %rbp,FP_OFFSET(%rdi)
101
102        mfence
103
104        // Don't load a new context, directly jump to the desired function
105#if defined(PIC)
106        call __suspend_callback@plt
107#else
108        call __suspend_callback
109#endif
110        .size  CtxStore, .-CtxStore
111
112//-----------------------------------------------------------------------------
113// Part of a 2 part context switch routine, use with CtxStore, context switches to the desired target without saving the current context
114        .text
115        .align 2
116        .globl CtxRet
117        .type  CtxRet, @function
118CtxRet:
119        // Load new context from the "to" area.
120
121        movq SP_OFFSET(%rdi),%rsp
122        movq FP_OFFSET(%rdi),%rbp
123
124        // Load volatile registers from the stack.
125
126        popq %rbx
127        popq %r12
128        popq %r13
129        popq %r14
130        popq %r15
131
132        // Return to thread.
133
134        ret
135        .size  CtxRet, .-CtxRet
136
137
138//-----------------------------------------------------------------------------
139// Stub used to create new stacks which are ready to be context switched to
140        .text
141        .align 2
142        .globl CtxInvokeStub
143        .type    CtxInvokeStub, @function
144CtxInvokeStub:
145        movq %rbx, %rdi
146        jmp *%r12
147        .size  CtxInvokeStub, .-CtxInvokeStub
148
149// Local Variables: //
150// mode: c //
151// tab-width: 4 //
152// End: //
Note: See TracBrowser for help on using the repository browser.