]> git.saurik.com Git - apple/libplatform.git/blame - src/setjmp/i386/_sigtramp.s
libplatform-177.250.1.tar.gz
[apple/libplatform.git] / src / setjmp / i386 / _sigtramp.s
CommitLineData
ada7c492
A
1/*
2 * Copyright (c) 2007, 2011 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24#include <sys/syscall.h>
25
26#if defined(__DYNAMIC__)
ada7c492 27 .private_extern ___in_sigtramp
ada7c492
A
28 .globl ___in_sigtramp
29 .data
30 .align 2
31___in_sigtramp:
32 .space 4
33#endif
34
35#define UC_TRAD 1
36#define UC_FLAVOR 30
37
38/* Structure fields for ucontext and mcontext. */
39#define UCONTEXT_UC_MCONTEXT 28
40
41#define MCONTEXT_ES_EXCEPTION 0
42#define MCONTEXT_SS_EAX 12
43#define MCONTEXT_SS_EBX 16
44#define MCONTEXT_SS_ECX 20
45#define MCONTEXT_SS_EDX 24
46#define MCONTEXT_SS_EDI 28
47#define MCONTEXT_SS_ESI 32
48#define MCONTEXT_SS_EBP 36
49#define MCONTEXT_SS_ESP 40
50#define MCONTEXT_SS_EFLAGS 48
51#define MCONTEXT_SS_EIP 52
52
53/* register use:
54 %ebp frame pointer
55 %ebx Address of "L00000000001$pb"
56 %esi uctx
438624e0
A
57 %edi token
58
ada7c492
A
59void
60_sigtramp(
61 union __sigaction_u __sigaction_u,
62 int sigstyle,
63 int sig,
64 siginfo_t *sinfo,
65 ucontext_t *uctx
66)
67*/
68
438624e0
A
69#if RDAR_35834092
70 .private_extern __sigtramp
71#endif
ada7c492
A
72 .globl __sigtramp
73 .text
74 .align 4,0x90
75__sigtramp:
76Lstart:
77 /* Although this routine does not need any stack frame, various parts
78 of the OS can't analyse the stack without them. */
79 pushl %ebp
80 movl %esp, %ebp
81 subl $24, %esp
82 movl 8(%ebp), %ecx # get '__sigaction_u'
83#if defined(__DYNAMIC__)
84 call 0f
85"L00000000001$pb":
860:
87 popl %ebx
88 incl ___in_sigtramp-"L00000000001$pb"(%ebx)
89#endif
90 movl 16(%ebp), %edx # get 'sig'
91 movl 20(%ebp), %eax # get 'sinfo'
92 movl 24(%ebp), %esi # get 'uctx'
438624e0 93 movl 28(%ebp), %edi # get 'token'
ada7c492
A
94 /* Call the signal handler.
95 Some variants are not supposed to get the last two parameters,
96 but the test to prevent this is more expensive than just passing
97 them. */
98 movl %esi, 8(%esp)
99 movl %eax, 4(%esp)
100 movl %edx, (%esp)
101 call *%ecx
102#if defined(__DYNAMIC__)
103 decl ___in_sigtramp-"L00000000001$pb"(%ebx)
104#endif
105 movl %esi, 4(%esp)
106 movl $ UC_FLAVOR, 8(%esp)
438624e0 107 movl %edi, 12(%esp)
ada7c492
A
108 movl $ SYS_sigreturn, %eax
109 int $0x80
438624e0 110 ud2 /* __sigreturn returning is a fatal error */
ada7c492
A
111Lend:
112
113/* DWARF unwind table #defines. */
114#define DW_CFA_advance_loc_4 0x44
115#define DW_CFA_def_cfa 0x0c
116#define DW_CFA_def_cfa_expression 0x0F
117#define DW_CFA_expression 0x10
118#define DW_CFA_val_expression 0x16
119#define DW_CFA_offset(column) 0x80+(column)
120
121/* DWARF expression #defines. */
122#define DW_OP_deref 0x06
123#define DW_OP_const1u 0x08
124#define DW_OP_dup 0x12
125#define DW_OP_drop 0x13
126#define DW_OP_over 0x14
127#define DW_OP_pick 0x15
128#define DW_OP_swap 0x16
129#define DW_OP_rot 0x17
130#define DW_OP_abs 0x19
131#define DW_OP_and 0x1a
132#define DW_OP_div 0x1b
133#define DW_OP_minus 0x1c
134#define DW_OP_mod 0x1d
135#define DW_OP_mul 0x1e
136#define DW_OP_neg 0x1f
137#define DW_OP_not 0x20
138#define DW_OP_or 0x21
139#define DW_OP_plus 0x22
140#define DW_OP_plus_uconst 0x23
141#define DW_OP_shl 0x24
142#define DW_OP_shr 0x25
143#define DW_OP_shra 0x26
144#define DW_OP_xor 0x27
145#define DW_OP_skip 0x2f
146#define DW_OP_bra 0x28
147#define DW_OP_eq 0x29
148#define DW_OP_ge 0x2A
149#define DW_OP_gt 0x2B
150#define DW_OP_le 0x2C
151#define DW_OP_lt 0x2D
152#define DW_OP_ne 0x2E
153#define DW_OP_lit(n) 0x30+(n)
154#define DW_OP_breg(n) 0x70+(n)
155#define DW_OP_deref_size 0x94
156
157/* The location expression we'll use. */
158
159#define loc_expr_for_reg(regno, offs) \
160 .byte DW_CFA_expression, regno, 5 /* block length */, \
161 DW_OP_breg(6), UCONTEXT_UC_MCONTEXT, DW_OP_deref, \
162 DW_OP_plus_uconst, offs
163
164 /* Unwind tables. */
165 .section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support
166EH_frame1:
167 .set L$set$0,LECIE1-LSCIE1
168 .long L$set$0 # Length of Common Information Entry
169LSCIE1:
170 .long 0 # CIE Identifier Tag
171 .byte 0x1 # CIE Version
172 .ascii "zRS\0" # CIE Augmentation
173 .byte 0x1 # uleb128 0x1; CIE Code Alignment Factor
174 .byte 0x7c # sleb128 -4; CIE Data Alignment Factor
175 .byte 0x8 # CIE RA Column
176 .byte 0x1 # uleb128 0x1; Augmentation size
177 .byte 0x10 # FDE Encoding (pcrel)
178 .byte DW_CFA_def_cfa
179 .byte 0x5 # uleb128 0x5
180 .byte 0x4 # uleb128 0x4
181 .byte DW_CFA_offset(8)
182 .byte 0x1 # uleb128 0x1
183 .byte DW_CFA_offset(8) // double DW_CFA_offset (eip, -4) tells linker to not make compact unwind
184 .byte 0x1 # uleb128 0x1
185 .align 2
186LECIE1:
187 .globl _sigtramp.eh
188_sigtramp.eh:
189LSFDE1:
190 .set L$set$1,LEFDE1-LASFDE1
191 .long L$set$1 # FDE Length
192LASFDE1:
193 .long LASFDE1-EH_frame1 # FDE CIE offset
194 .long Lstart-. # FDE initial location
195 .set L$set$2,Lend-Lstart
196 .long L$set$2 # FDE address range
197 .byte 0x0 # uleb128 0x0; Augmentation size
198
199 /* Now for the expressions, which all compute
200 uctx->uc_mcontext->register
201 for each register.
202
203 Describe even the registers that are not call-saved because they
204 might be being used in the prologue to save other registers.
205 Only integer registers are described at present. */
206
207 loc_expr_for_reg (0, MCONTEXT_SS_EAX)
208 loc_expr_for_reg (1, MCONTEXT_SS_ECX)
209 loc_expr_for_reg (2, MCONTEXT_SS_EDX)
210 loc_expr_for_reg (3, MCONTEXT_SS_EBX)
211 loc_expr_for_reg (4, MCONTEXT_SS_EBP) # note that GCC switches
212 loc_expr_for_reg (5, MCONTEXT_SS_ESP) # DWARF registers 4 & 5
213 loc_expr_for_reg (6, MCONTEXT_SS_ESI)
214 loc_expr_for_reg (7, MCONTEXT_SS_EDI)
215 loc_expr_for_reg (9, MCONTEXT_SS_EFLAGS)
216
217 /* The Intel architecture classifies exceptions into three categories,
218 'faults' which put the address of the faulting instruction
219 in EIP, 'traps' which put the following instruction in EIP,
220 and 'aborts' which don't typically report the instruction
221 causing the exception.
222
223 The traps are #BP and #OF. */
224
225 .byte DW_CFA_val_expression, 8
226 .set L$set$3,Lpc_end-Lpc_start
227 .byte L$set$3
228Lpc_start:
229 /* Push the mcontext address twice. */
230 .byte DW_OP_breg(6), UCONTEXT_UC_MCONTEXT, DW_OP_deref, DW_OP_dup
231 /* Find the value of EIP. */
232 .byte DW_OP_plus_uconst, MCONTEXT_SS_EIP, DW_OP_deref, DW_OP_swap
233 /* Determine the exception type. */
234 .byte DW_OP_plus_uconst, MCONTEXT_ES_EXCEPTION, DW_OP_deref
235 /* Check whether it is #BP (3) or #OF (4). */
236 .byte DW_OP_dup, DW_OP_lit(3), DW_OP_ne
237 .byte DW_OP_swap, DW_OP_lit(4), DW_OP_ne, DW_OP_and
238 /* If it is, then add 1 to the instruction address, so as to point
239 within or past the faulting instruction. */
240 .byte DW_OP_plus
241Lpc_end:
242
243 /* The CFA will have been saved as the value of ESP (it is not
244 ESP+4). */
245 .byte DW_CFA_def_cfa_expression
246 .set L$set$4,Lcfa_end-Lcfa_start
247 .byte L$set$4
248Lcfa_start:
249 .byte DW_OP_breg(6), UCONTEXT_UC_MCONTEXT, DW_OP_deref
250 .byte DW_OP_plus_uconst, MCONTEXT_SS_ESP, DW_OP_deref
251Lcfa_end:
252
253 .align 2
254LEFDE1:
255
256 .subsections_via_symbols