source: libcfa/src/concurrency/CtxSwitch-i386.S @ 9c2ac95

Last change on this file since 9c2ac95 was a4bdbcd, checked in by Peter A. Buhr <pabuhr@…>, 4 years ago

formatting

  • Property mode set to 100644
File size: 1.8 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 : Sun Sep  6 18:23:37 2020
13// Update Count     : 5
14//
15
16// The context switch routine requires the initial the stack of a thread to
17// look like the thread has saved its context in the normal manner.
18
19// Offsets must synchronized with the __stack_context_t in invoke.h.
20
21#define PTR_BYTE        4
22#define SP_OFFSET       ( 0 * PTR_BYTE )
23#define FP_OFFSET       ( 1 * PTR_BYTE )
24
25// Context switch between coroutines/tasks.
26//   void __cfactx_switch( struct __stack_context_t * from, struct __stack_context_t * to ) ;
27// Arguments "from" in register 4(%esp), "to" in register 20(%esp)
28
29        .file "CtxSwitch-i386.S"
30        .text
31        .align 2
32        .global __cfactx_switch
33        .type __cfactx_switch, @function
34__cfactx_switch:
35
36        // Copy the "from" context argument from the stack to register eax
37        // Return address is at 0(%esp), with parameters following.
38
39        movl 4(%esp),%eax
40
41        // Save volatile registers on the stack.
42
43        pushl %ebx
44        pushl %edi
45        pushl %esi
46
47        // Save old context in the "from" area.
48
49        movl %esp,SP_OFFSET(%eax)
50        movl %ebp,FP_OFFSET(%eax)
51
52        // Copy the "to" context argument from the stack to register eax. Having
53        // pushed 3 words (= 12 bytes) on the stack, the argument is now at
54        // 8 + 12 = 20(%esp).
55
56        movl 20(%esp),%eax
57
58        // Load new context from the "to" area.
59
60        movl SP_OFFSET(%eax),%esp
61        movl FP_OFFSET(%eax),%ebp
62
63        // Load volatile registers from the stack.
64
65        popl %esi
66        popl %edi
67        popl %ebx
68
69        // Return to thread.
70
71        ret
72        .size __cfactx_switch, .-__cfactx_switch
73
74// Local Variables: //
75// mode: c //
76// tab-width: 4 //
77// End: //
Note: See TracBrowser for help on using the repository browser.