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

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

Removed kernelTLS.this_coroutine which was redundant and some preleminary work for breaking into 2 step the context-switch

  • Property mode set to 100644
File size: 3.2 KB
RevLine 
[78b3f52]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
[6b0b624]11// Last Modified By : Peter A. Buhr
12// Last Modified On : Fri Jul 21 22:28:11 2017
13// Update Count     : 1
[78b3f52]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.
[f32e53e]19//
[78b3f52]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.
[f32e53e]24//
[78b3f52]25// You should  have received a  copy of the  GNU Lesser General  Public License
26// along  with this library.
[f32e53e]27//
[78b3f52]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#define PC_OFFSET       ( 2 * PTR_BYTE )
42
43.text
44        .align 2
45.globl  CtxSwitch
46CtxSwitch:
47
[7b2c2c5f]48        // Save floating & SSE control words on the stack.
[78b3f52]49
[ffc3b26]50        subq   $8,%rsp
51        stmxcsr 0(%rsp)         // 4 bytes
52        fnstcw  4(%rsp)         // 2 bytes
[7b2c2c5f]53
54        // Save volatile registers on the stack.
55
[78b3f52]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
[7b2c2c5f]79
80        // Load floating & SSE control words from the stack.
81
[ffc3b26]82        fldcw   4(%rsp)
83        ldmxcsr 0(%rsp)
[7b2c2c5f]84        addq   $8,%rsp
[78b3f52]85
86        // Return to thread.
87
88        ret
89
[212c2187]90//.text
91//      .align 2
92//.globl        CtxStore
93//CtxStore:
94//      // Save floating & SSE control words on the stack.
95//
96//      subq   $8,%rsp
97//      stmxcsr 0(%rsp)         // 4 bytes
98//      fnstcw  4(%rsp)         // 2 bytes
99//
100//      // Save volatile registers on the stack.
101//
102//      pushq %r15
103//      pushq %r14
104//      pushq %r13
105//      pushq %r12
106//      pushq %rbx
107//
108//      // Save old context in the "from" area.
109//
110//      movq %rsp,SP_OFFSET(%rdi)
111//      movq %rbp,FP_OFFSET(%rdi)
112//
113//      // Return to thread
114//
115//      ret
116//
117//.text
118//      .align 2
119//.globl        CtxRet
120//CtxRet:
121//      // Load new context from the "to" area.
122//
123//      movq SP_OFFSET(%rdi),%rsp
124//      movq FP_OFFSET(%rdi),%rbp
125//
126//      // Load volatile registers from the stack.
127//
128//      popq %rbx
129//      popq %r12
130//      popq %r13
131//      popq %r14
132//      popq %r15
133//
134//      // Load floating & SSE control words from the stack.
135//
136//      fldcw   4(%rsp)
137//      ldmxcsr 0(%rsp)
138//      addq   $8,%rsp
139//
140//      // Return to thread.
141//
142//      ret
143
144
[78b3f52]145.text
146        .align 2
[b58a5772]147.globl  CtxInvokeStub
148CtxInvokeStub:
[f32e53e]149        movq %rbx, %rdi
[5c81105]150        jmp *%r12
[78b3f52]151
152// Local Variables: //
153// mode: c //
154// tab-width: 4 //
[ffc3b26]155// End: //
Note: See TracBrowser for help on using the repository browser.