source: src/libcfa/concurrency/CtxSwitch-i386.S @ 84e2523

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 84e2523 was 35dd180f, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

Implemented CtxSwitch?-i386 : CtxGet?

  • Property mode set to 100644
File size: 2.6 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-i386.S --
9//
10// Author           : Thierry Delisle
11// Created On       : Tue Dec 6 12:27:26 2016
12// Last Modified By : Thierry Delisle
13// Last Modified On : Tue Dec 6 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        4
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        // 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 volatile registers on the stack.
55
56        pushl %ebx
57        pushl %edi
58        pushl %esi
59
60        // Save old context in the "from" area.
61
62        movl %esp,SP_OFFSET(%eax)
63        movl %ebp,FP_OFFSET(%eax)
64//      movl 4(%ebp),%ebx       // save previous eip for debugger
65//      movl %ebx,PC_OFFSET(%eax)
66
67        // Copy the "to" context argument from the stack to register eax
68        // Having pushed three words (= 12 bytes) on the stack, the
69        // argument is now at 8 + 12 = 20(%esp)
70
71        movl 20(%esp),%eax
72
73        // Load new context from the "to" area.
74
75        movl SP_OFFSET(%eax),%esp
76        movl FP_OFFSET(%eax),%ebp
77
78        // Load volatile registers from the stack.
79
80        popl %esi
81        popl %edi
82        popl %ebx
83
84        // Return to thread.
85
86        ret
87
88.text
89        .align 2
90.globl  CtxGet
91CtxGet:
92        movl %esp,SP_OFFSET(%eax)
93        movl %ebp,FP_OFFSET(%eax)
94
95        ret
96
97// Local Variables: //
98// compile-command: "make install" //
99// End: //
Note: See TracBrowser for help on using the repository browser.