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

ADT arm-eh ast-experimental cleanup-dtors enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 3c06bba was 3c06bba, checked in by tdelisle <tdelisle@…>, 7 years ago

Inlined coroutine context switch routine

  • Property mode set to 100644
File size: 2.6 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-i386.S --
8//
9// Author : Thierry Delisle
10// Created On : Tue Dec 6 12:27:26 2016
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Fri Jul 21 22:29:25 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 4
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
46 .type CtxSwitch, @function
47CtxSwitch:
48
49 // Copy the "from" context argument from the stack to register eax
50 // Return address is at 0(%esp), with parameters following
51
52 movl 4(%esp),%eax
53
54 // Save floating & SSE control words on the stack.
55
56 sub $8,%esp
57 stmxcsr 0(%esp) // 4 bytes
58 fnstcw 4(%esp) // 2 bytes
59
60 // Save volatile registers on the stack.
61
62 pushl %ebx
63 pushl %edi
64 pushl %esi
65
66 // Save old context in the "from" area.
67
68 movl %esp,SP_OFFSET(%eax)
69 movl %ebp,FP_OFFSET(%eax)
70
71 // Copy the "to" context argument from the stack to register eax
72 // Having pushed three words (= 12 bytes) on the stack, the
73 // argument is now at 8 + 12 = 20(%esp)
74
75 movl 28(%esp),%eax
76
77 // Load new context from the "to" area.
78
79 movl SP_OFFSET(%eax),%esp
80 movl FP_OFFSET(%eax),%ebp
81
82 // Load volatile registers from the stack.
83
84 popl %esi
85 popl %edi
86 popl %ebx
87
88 // Load floating & SSE control words from the stack.
89
90 fldcw 4(%esp)
91 ldmxcsr 0(%esp)
92 add $8,%esp
93
94 // Return to thread.
95
96 ret
97 .size CtxSwitch, .-CtxSwitch
98
99// Local Variables: //
100// mode: c //
101// tab-width: 4 //
102// End: //
Note: See TracBrowser for help on using the repository browser.