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

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation new-ast new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 61d7bec was c7a900a, checked in by Thierry Delisle <tdelisle@…>, 6 years ago

More renames and clean-ups

  • Property mode set to 100644
File size: 2.6 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
[5b11c25]42//-----------------------------------------------------------------------------
43// Regular context switch routine which enables switching from one context to anouther
[3c06bba]44 .text
[78b3f52]45 .align 2
[c7a900a]46 .globl __cfactx_switch
47 .type __cfactx_switch, @function
48__cfactx_switch:
[78b3f52]49
[7b2c2c5f]50 // Save volatile registers on the stack.
51
[78b3f52]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
[7b2c2c5f]75
[78b3f52]76 // Return to thread.
77
78 ret
[c7a900a]79 .size __cfactx_switch, .-__cfactx_switch
[3c06bba]80
[5b11c25]81//-----------------------------------------------------------------------------
82// Stub used to create new stacks which are ready to be context switched to
83 .text
[78b3f52]84 .align 2
[c7a900a]85 .globl __cfactx_invoke_stub
86 .type __cfactx_invoke_stub, @function
87__cfactx_invoke_stub:
[f32e53e]88 movq %rbx, %rdi
[09f357ec]89 movq %r12, %rsi
90 jmp *%r13
[c7a900a]91 .size __cfactx_invoke_stub, .-__cfactx_invoke_stub
[78b3f52]92
93// Local Variables: //
94// mode: c //
95// tab-width: 4 //
[ffc3b26]96// End: //
Note: See TracBrowser for help on using the repository browser.