]>
Commit | Line | Data |
---|---|---|
2493e718 | 1 | /* i386 support code for fibers and multithreading. |
8d9254fc | 2 | Copyright (C) 2019-2020 Free Software Foundation, Inc. |
2493e718 IB |
3 | |
4 | This file is part of GCC. | |
5 | ||
6 | GCC is free software; you can redistribute it and/or modify it under | |
7 | the terms of the GNU General Public License as published by the Free | |
8 | Software Foundation; either version 3, or (at your option) any later | |
9 | version. | |
10 | ||
11 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
12 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
14 | for more details. | |
15 | ||
16 | Under Section 7 of GPL version 3, you are granted additional | |
17 | permissions described in the GCC Runtime Library Exception, version | |
18 | 3.1, as published by the Free Software Foundation. | |
19 | ||
20 | You should have received a copy of the GNU General Public License and | |
21 | a copy of the GCC Runtime Library Exception along with this program; | |
22 | see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
23 | <http://www.gnu.org/licenses/>. */ | |
24 | ||
25 | #include "../common/threadasm.S" | |
26 | ||
27 | #if defined(__i386__) | |
28 | ||
29 | .text | |
30 | .globl CSYM(fiber_switchContext) | |
31 | .type CSYM(fiber_switchContext), @function | |
32 | .align 16 | |
33 | CSYM(fiber_switchContext): | |
34 | .cfi_startproc | |
35 | // save current stack state | |
36 | push %ebp | |
37 | mov %esp, %ebp | |
38 | push %edi | |
39 | push %esi | |
40 | push %ebx | |
41 | push %eax | |
42 | ||
43 | // store oldp again with more accurate address | |
44 | mov 8(%ebp), %eax | |
45 | mov %esp, (%eax) | |
46 | // load newp to begin context switch | |
47 | mov 12(%ebp), %esp | |
48 | ||
49 | // load saved state from new stack | |
50 | pop %eax | |
51 | pop %ebx | |
52 | pop %esi | |
53 | pop %edi | |
54 | pop %ebp | |
55 | ||
56 | // 'return' to complete switch | |
57 | ret | |
58 | .cfi_endproc | |
59 | .size CSYM(fiber_switchContext),.-CSYM(fiber_switchContext) | |
60 | ||
61 | #elif defined(__x86_64__) && !defined(__ILP32__) | |
62 | ||
63 | .text | |
64 | .globl CSYM(fiber_switchContext) | |
65 | .type CSYM(fiber_switchContext), @function | |
66 | .align 16 | |
67 | CSYM(fiber_switchContext): | |
68 | .cfi_startproc | |
69 | // Save current stack state.save current stack state | |
70 | push %rbp | |
71 | mov %rsp, %rbp | |
72 | push %rbx | |
73 | push %r12 | |
74 | push %r13 | |
75 | push %r14 | |
76 | push %r15 | |
77 | ||
78 | // store oldp again with more accurate address | |
79 | mov %rsp, (%rdi) | |
80 | // load newp to begin context switch | |
81 | mov %rsi, %rsp | |
82 | ||
83 | // load saved state from new stack | |
84 | pop %r15 | |
85 | pop %r14 | |
86 | pop %r13 | |
87 | pop %r12 | |
88 | pop %rbx | |
89 | pop %rbp | |
90 | ||
91 | // 'return' to complete switch | |
92 | ret | |
93 | .cfi_endproc | |
94 | .size CSYM(fiber_switchContext),.-CSYM(fiber_switchContext) | |
95 | ||
96 | #endif |