1 /* i386 support code for fibers and multithreading.
2 Copyright (C) 2019-2025 Free Software Foundation, Inc.
4 This file is part of GCC.
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
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
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.
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/>. */
25 #include "../common/threadasm.S"
27 /* NB: Generate the CET marker for -fcf-protection. */
36 # if defined(__i386__)
39 .globl CSYM(fiber_switchContext)
40 .type CSYM(fiber_switchContext), @function
42 CSYM(fiber_switchContext):
44 // save current stack state
52 // store oldp again with more accurate address
55 // load newp to begin context switch
58 // load saved state from new stack
65 // 'return' to complete switch
68 .size CSYM(fiber_switchContext),.-CSYM(fiber_switchContext)
70 # endif /* defined(__ELF__) && defined(__i386__) */
72 # if defined(__x86_64__) && !defined(__ILP32__)
75 .globl CSYM(fiber_switchContext)
76 .type CSYM(fiber_switchContext), @function
78 CSYM(fiber_switchContext):
80 // Save current stack state.save current stack state
89 // store oldp again with more accurate address
91 // load newp to begin context switch
94 // load saved state from new stack
102 // 'return' to complete switch
105 .size CSYM(fiber_switchContext),.-CSYM(fiber_switchContext)
107 # endif /* defined(__ELF__) && defined(__x86_64__) && !defined(__ILP32__) */
109 # endif /* defined(__ELF__) */
111 # if defined(__MACH__)
113 # if defined(__i386__)
116 .globl CSYM(fiber_switchContext)
118 CSYM(fiber_switchContext):
120 // save current stack state
128 // store oldp again with more accurate address
131 // load newp to begin context switch
134 // load saved state from new stack
141 // 'return' to complete switch
146 .section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support
148 .set L$set$0,LECIE1-LSCIE1
149 .long L$set$0 # Length of Common Information Entry
151 .long 0 # CIE Identifier Tag
152 .byte 0x1 # CIE Version
153 .ascii "zR\0" # CIE Augmentation
154 .byte 0x1 # uleb128 0x1; CIE Code Alignment Factor
155 .byte 0x7c # sleb128 -4; CIE Data Alignment Factor
156 .byte 0x8 # CIE RA Column
157 .byte 0x1 # uleb128 0x1; Augmentation size
158 .byte 0x10 # FDE Encoding (pcrel)
159 .byte 0xc # DW_CFA_def_cfa
160 .byte 0x5 # uleb128 0x5
161 .byte 0x4 # uleb128 0x4
162 .byte 0x88 # DW_CFA_offset, column 0x8
163 .byte 0x1 # uleb128 0x1
167 /* minimal FDE - does not record the stack frame changes. */
169 .set L$set$1,LEFDE1-LASFDE1
170 .long L$set$1 # FDE Length
172 .long LASFDE1-EH_frame1 # FDE CIE offset
173 .long LFB0-. # FDE initial location
174 .set L$set$2,LFE0-LFB0
175 .long L$set$2 # FDE address range
176 .byte 0 # uleb128 0; Augmentation size
180 # endif /* defined(__MACH__) && defined(__i386__) */
182 # if defined(__x86_64__) && !defined(__ILP32__)
185 .globl CSYM(fiber_switchContext)
187 CSYM(fiber_switchContext):
189 // Save current stack state.save current stack state
198 // store oldp again with more accurate address
200 // load newp to begin context switch
203 // load saved state from new stack
211 // 'return' to complete switch
216 .section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support
218 .set L$set$0,LECIE1-LSCIE1
219 .long L$set$0 # Length of Common Information Entry
221 .long 0 # CIE Identifier Tag
222 .byte 0x1 # CIE Version
223 .ascii "zR\0" # CIE Augmentation
224 .byte 0x1 # uleb128 0x1; CIE Code Alignment Factor
225 .byte 0x78 # sleb128 -8; CIE Data Alignment Factor
226 .byte 0x10 # CIE RA Column
227 .byte 0x1 # uleb128 0x1; Augmentation size
228 .byte 0x10 # FDE Encoding (pcrel)
229 .byte 0xc # DW_CFA_def_cfa
230 .byte 0x7 # uleb128 0x7
231 .byte 0x8 # uleb128 0x8
232 .byte 0x90 # DW_CFA_offset, column 0x10
233 .byte 0x1 # uleb128 0x1
237 /* minimal FDE - does not record the stack frame changes. */
239 .set L$set$1,LEFDE1-LASFDE1
240 .long L$set$1 # FDE Length
242 .long LASFDE1-EH_frame1 # FDE CIE offset
243 .quad LFB0-. # FDE initial location
244 .set L$set$2,LFE0-LFB0
245 .quad L$set$2 # FDE address range
246 .byte 0 # uleb128 0; Augmentation size
250 # endif /* defined(__MACH__) && defined(__x86_64__) && !defined(__ILP32__) */
252 # endif /* defined (__MACH__) */
254 #endif /* !defined(__CET__) */