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

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 6ce9f7c7 was ffc3b26, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

x86_64 now properly save x87 FPU and SSE control words on context switch

  • Property mode set to 100644
File size: 2.4 KB
Line 
1//                               -*- Mode: Asm -*-
2//
3// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
4//
5// The contents of this file are covered under the licence agreement in the
6// file "LICENCE" distributed with Cforall.
7//
8// CtxSwitch-x86_64.S --
9//
10// Author           : Thierry Delisle
11// Created On       : Mon Nov 28 12:27:26 2016
12// Last Modified By : Thierry Delisle
13// Last Modified On : Mon Nov 28 12:27:26 2016
14// Update Count     : 0
15//
16// This  library is free  software; you  can redistribute  it and/or  modify it
17// under the terms of the GNU Lesser General Public License as published by the
18// Free Software  Foundation; either  version 2.1 of  the License, or  (at your
19// option) any later version.
20//
21// This library is distributed in the  hope that it will be useful, but WITHOUT
22// ANY  WARRANTY;  without even  the  implied  warranty  of MERCHANTABILITY  or
23// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
24// for more details.
25//
26// You should  have received a  copy of the  GNU Lesser General  Public License
27// along  with this library.
28//
29
30// This context switch routine depends on the fact that the stack of a new
31// thread has been set up to look like the thread has saved its context in
32// the normal manner.
33//
34// void CtxSwitch( machine_context *from, machine_context *to );
35
36// Offsets in the context structure. This needs to be synchronized with the
37// high level code a little better.
38
39#define PTR_BYTE        8
40#define SP_OFFSET       ( 0 * PTR_BYTE )
41#define FP_OFFSET       ( 1 * PTR_BYTE )
42#define PC_OFFSET       ( 2 * PTR_BYTE )
43
44.text
45        .align 2
46.globl  CtxSwitch
47CtxSwitch:
48
49        // Save volatile registers on the stack.
50
51        subq   $8,%rsp
52        stmxcsr 0(%rsp)         // 4 bytes
53        fnstcw  4(%rsp)         // 2 bytes
54        pushq %r15
55        pushq %r14
56        pushq %r13
57        pushq %r12
58        pushq %rbx
59
60        // Save old context in the "from" area.
61
62        movq %rsp,SP_OFFSET(%rdi)
63        movq %rbp,FP_OFFSET(%rdi)
64
65        // Load new context from the "to" area.
66
67        movq SP_OFFSET(%rsi),%rsp
68        movq FP_OFFSET(%rsi),%rbp
69
70        // Load volatile registers from the stack.
71
72        popq %rbx
73        popq %r12
74        popq %r13
75        popq %r14
76        popq %r15
77        fldcw   4(%rsp)
78        ldmxcsr 0(%rsp)
79        addq $8,%rsp
80
81        // Return to thread.
82
83        ret
84
85.text
86        .align 2
87.globl  CtxInvokeStub
88CtxInvokeStub:
89        movq %rbx, %rdi
90        jmp *%r12
91
92.text
93        .align 2
94.globl  CtxGet
95CtxGet:
96        movq %rsp,SP_OFFSET(%rdi)
97        movq %rbp,FP_OFFSET(%rdi)
98
99        ret
100
101// Local Variables: //
102// mode: c //
103// tab-width: 4 //
104// End: //
Note: See TracBrowser for help on using the repository browser.