source: libcfa/src/concurrency/CtxSwitch-x86_64.S@ 3531e09

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 3531e09 was 0c4a90d, checked in by Peter A. Buhr <pabuhr@…>, 5 years ago

update emacs mode

  • Property mode set to 100644
File size: 1.9 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//
[636d115b]9// Author : Peter A. Buhr
10// Created On : Mon Aug 10 08:10:26 2020
[6b0b624]11// Last Modified By : Peter A. Buhr
[0c4a90d]12// Last Modified On : Sat Oct 24 14:36:25 2020
13// Update Count : 10
[f32e53e]14//
[78b3f52]15
[636d115b]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.
[78b3f52]18
[636d115b]19// Offsets must synchronized with the __stack_context_t in invoke.h.
[78b3f52]20
21#define PTR_BYTE 8
22#define SP_OFFSET ( 0 * PTR_BYTE )
23#define FP_OFFSET ( 1 * PTR_BYTE )
24
[636d115b]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 rdi, "to" in register rsi.
28
29 .file "CtxSwitch-x86_64.S"
[3c06bba]30 .text
[78b3f52]31 .align 2
[636d115b]32 .global __cfactx_switch
33 .type __cfactx_switch, @function
[c7a900a]34__cfactx_switch:
[78b3f52]35
[7b2c2c5f]36 // Save volatile registers on the stack.
37
[78b3f52]38 pushq %r15
39 pushq %r14
40 pushq %r13
41 pushq %r12
42 pushq %rbx
43
44 // Save old context in the "from" area.
45
46 movq %rsp,SP_OFFSET(%rdi)
47 movq %rbp,FP_OFFSET(%rdi)
48
49 // Load new context from the "to" area.
50
51 movq SP_OFFSET(%rsi),%rsp
52 movq FP_OFFSET(%rsi),%rbp
53
54 // Load volatile registers from the stack.
55
56 popq %rbx
57 popq %r12
58 popq %r13
59 popq %r14
60 popq %r15
[7b2c2c5f]61
[78b3f52]62 // Return to thread.
63
64 ret
[636d115b]65 .size __cfactx_switch, .-__cfactx_switch
66
67// Stub to create new stacks which can be context switched to
68// void __cfactx_invoke_stub( void );
[3c06bba]69
[5b11c25]70 .text
[78b3f52]71 .align 2
[636d115b]72 .global __cfactx_invoke_stub
73 .type __cfactx_invoke_stub, @function
[c7a900a]74__cfactx_invoke_stub:
[636d115b]75 movq %rbx, %rdi // move main and this to first two arguments
[09f357ec]76 movq %r12, %rsi
[636d115b]77 jmp *%r13 // jmp to invoke
78 .size __cfactx_invoke_stub, .-__cfactx_invoke_stub
[78b3f52]79
80// Local Variables: //
[0c4a90d]81// mode: asm //
[78b3f52]82// tab-width: 4 //
[ffc3b26]83// End: //
Note: See TracBrowser for help on using the repository browser.