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

arm-ehcleanup-dtorsjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-expr
Last change on this file since 3c06bba was 3c06bba, checked in by tdelisle <tdelisle@…>, 3 years ago

Inlined coroutine context switch routine

  • Property mode set to 100644
File size: 3.3 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
45        .type  CtxSwitch, @function
46CtxSwitch:
47
48        // Save floating & SSE control words on the stack.
49
50        subq   $8,%rsp
51        stmxcsr 0(%rsp)         // 4 bytes
52        fnstcw  4(%rsp)         // 2 bytes
53
54        // Save volatile registers on the stack.
55
56        pushq %r15
57        pushq %r14
58        pushq %r13
59        pushq %r12
60        pushq %rbx
61
62        // Save old context in the "from" area.
63
64        movq %rsp,SP_OFFSET(%rdi)
65        movq %rbp,FP_OFFSET(%rdi)
66
67        // Load new context from the "to" area.
68
69        movq SP_OFFSET(%rsi),%rsp
70        movq FP_OFFSET(%rsi),%rbp
71
72        // Load volatile registers from the stack.
73
74        popq %rbx
75        popq %r12
76        popq %r13
77        popq %r14
78        popq %r15
79
80        // Load floating & SSE control words from the stack.
81
82        fldcw   4(%rsp)
83        ldmxcsr 0(%rsp)
84        addq   $8,%rsp
85
86        // Return to thread.
87
88        ret
89        .size  CtxSwitch, .-CtxSwitch
90
91
92//.text
93//      .align 2
94//.globl        CtxStore
95//CtxStore:
96//      // Save floating & SSE control words on the stack.
97//
98//      subq   $8,%rsp
99//      stmxcsr 0(%rsp)         // 4 bytes
100//      fnstcw  4(%rsp)         // 2 bytes
101//
102//      // Save volatile registers on the stack.
103//
104//      pushq %r15
105//      pushq %r14
106//      pushq %r13
107//      pushq %r12
108//      pushq %rbx
109//
110//      // Save old context in the "from" area.
111//
112//      movq %rsp,SP_OFFSET(%rdi)
113//      movq %rbp,FP_OFFSET(%rdi)
114//
115//      // Return to thread
116//
117//      ret
118//
119//.text
120//      .align 2
121//.globl        CtxRet
122//CtxRet:
123//      // Load new context from the "to" area.
124//
125//      movq SP_OFFSET(%rdi),%rsp
126//      movq FP_OFFSET(%rdi),%rbp
127//
128//      // Load volatile registers from the stack.
129//
130//      popq %rbx
131//      popq %r12
132//      popq %r13
133//      popq %r14
134//      popq %r15
135//
136//      // Load floating & SSE control words from the stack.
137//
138//      fldcw   4(%rsp)
139//      ldmxcsr 0(%rsp)
140//      addq   $8,%rsp
141//
142//      // Return to thread.
143//
144//      ret
145
146
147.text
148        .align 2
149.globl  CtxInvokeStub
150CtxInvokeStub:
151        movq %rbx, %rdi
152        jmp *%r12
153
154// Local Variables: //
155// mode: c //
156// tab-width: 4 //
157// End: //
Note: See TracBrowser for help on using the repository browser.