Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(5)

Side by Side Diff: common/android/breakpad_getcontext.S

Issue 1384002: Add Arm64 version of breakpad_getcontext for Android. (Closed) Base URL: http://google-breakpad.googlecode.com/svn/trunk/src
Patch Set: Created 11 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | common/android/ucontext_constants.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, Google Inc. 1 // Copyright (c) 2012, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 16 matching lines...) Expand all
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 29
30 // A minimalistic implementation of getcontext() to be used by 30 // A minimalistic implementation of getcontext() to be used by
31 // Google Breakpad on Android. 31 // Google Breakpad on Android.
32 32
33 #include "common/android/ucontext_constants.h" 33 #include "common/android/ucontext_constants.h"
34 34
35 /* int getcontext (ucontext_t *ucp) */ 35 /* int getcontext (ucontext_t *ucp) */
36 36
37 #ifdef __arm__ 37 #ifdef __arm__
Mark Mentovai 2014/04/02 16:22:18 Change to #if defined(…) to match all of the #elif
rmcilroy 2014/04/02 23:01:28 Done.
38 38
39 .text 39 .text
40 .global breakpad_getcontext 40 .global breakpad_getcontext
41 .hidden breakpad_getcontext 41 .hidden breakpad_getcontext
42 .type breakpad_getcontext, #function 42 .type breakpad_getcontext, #function
43 .align 0 43 .align 0
44 .fnstart 44 .fnstart
45 breakpad_getcontext: 45 breakpad_getcontext:
46 46
47 /* First, save r4-r11 */ 47 /* First, save r4-r11 */
48 add r1, r0, #(MCONTEXT_GREGS_OFFSET + 4*4) 48 add r1, r0, #(MCONTEXT_GREGS_OFFSET + 4*4)
49 stm r1, {r4-r11} 49 stm r1, {r4-r11}
50 50
51 /* r12 is a scratch register, don't save it */ 51 /* r12 is a scratch register, don't save it */
52 52
53 /* Save sp and lr explicitely. */ 53 /* Save sp and lr explicitly. */
54 /* - sp can't be stored with stmia in Thumb-2 */ 54 /* - sp can't be stored with stmia in Thumb-2 */
55 /* - STM instructions that store sp and pc are deprecated in ARM */ 55 /* - STM instructions that store sp and pc are deprecated in ARM */
56 str sp, [r0, #(MCONTEXT_GREGS_OFFSET + 13*4)] 56 str sp, [r0, #(MCONTEXT_GREGS_OFFSET + 13*4)]
57 str lr, [r0, #(MCONTEXT_GREGS_OFFSET + 14*4)] 57 str lr, [r0, #(MCONTEXT_GREGS_OFFSET + 14*4)]
58 58
59 /* Save the caller's address in 'pc' */ 59 /* Save the caller's address in 'pc' */
60 str lr, [r0, #(MCONTEXT_GREGS_OFFSET + 15*4)] 60 str lr, [r0, #(MCONTEXT_GREGS_OFFSET + 15*4)]
61 61
62 /* Save ucontext_t* pointer accross next call */ 62 /* Save ucontext_t* pointer across next call */
63 mov r4, r0 63 mov r4, r0
64 64
65 /* Call sigprocmask(SIG_BLOCK, NULL, &(ucontext->uc_sigmask)) */ 65 /* Call sigprocmask(SIG_BLOCK, NULL, &(ucontext->uc_sigmask)) */
66 mov r0, #0 /* SIG_BLOCK */ 66 mov r0, #0 /* SIG_BLOCK */
67 mov r1, #0 /* NULL */ 67 mov r1, #0 /* NULL */
68 add r2, r4, #UCONTEXT_SIGMASK_OFFSET 68 add r2, r4, #UCONTEXT_SIGMASK_OFFSET
69 bl sigprocmask(PLT) 69 bl sigprocmask(PLT)
70 70
71 /* Intentionally do not save the FPU state here. This is because on 71 /* Intentionally do not save the FPU state here. This is because on
72 * Linux/ARM, one should instead use ptrace(PTRACE_GETFPREGS) or 72 * Linux/ARM, one should instead use ptrace(PTRACE_GETFPREGS) or
73 * ptrace(PTRACE_GETVFPREGS) to get it. 73 * ptrace(PTRACE_GETVFPREGS) to get it.
74 * 74 *
75 * Note that a real implementation of getcontext() would need to save 75 * Note that a real implementation of getcontext() would need to save
76 * this here to allow setcontext()/swapcontext() to work correctly. 76 * this here to allow setcontext()/swapcontext() to work correctly.
77 */ 77 */
78 78
79 /* Restore the values of r4 and lr */ 79 /* Restore the values of r4 and lr */
80 mov r0, r4 80 mov r0, r4
81 ldr lr, [r0, #(MCONTEXT_GREGS_OFFSET + 14*4)] 81 ldr lr, [r0, #(MCONTEXT_GREGS_OFFSET + 14*4)]
82 ldr r4, [r0, #(MCONTEXT_GREGS_OFFSET + 4*4)] 82 ldr r4, [r0, #(MCONTEXT_GREGS_OFFSET + 4*4)]
83 83
84 /* Return 0 */ 84 /* Return 0 */
85 mov r0, #0 85 mov r0, #0
86 bx lr 86 bx lr
87 87
88 .fnend 88 .fnend
89 .size breakpad_getcontext, . - breakpad_getcontext 89 .size breakpad_getcontext, . - breakpad_getcontext
90 90
91 #elif defined(__aarch64__)
92
93 .text
94 .global breakpad_getcontext
95 .hidden breakpad_getcontext
96 .type breakpad_getcontext, #function
97 .align 4
98 .cfi_startproc
99 breakpad_getcontext:
100
101 /* The saved context will return to the getcontext() call point
102 with a return value of 0 */
103 str xzr, [x0, MCONTEXT_GREGS_OFFSET + 0 * REGISTER_SIZE]
104
105 stp x18, x19, [x0, MCONTEXT_GREGS_OFFSET + 18 * REGISTER_SIZE]
106 stp x20, x21, [x0, MCONTEXT_GREGS_OFFSET + 20 * REGISTER_SIZE]
107 stp x22, x23, [x0, MCONTEXT_GREGS_OFFSET + 22 * REGISTER_SIZE]
108 stp x24, x25, [x0, MCONTEXT_GREGS_OFFSET + 24 * REGISTER_SIZE]
109 stp x26, x27, [x0, MCONTEXT_GREGS_OFFSET + 26 * REGISTER_SIZE]
110 stp x28, x29, [x0, MCONTEXT_GREGS_OFFSET + 28 * REGISTER_SIZE]
111 str x30, [x0, MCONTEXT_GREGS_OFFSET + 30 * REGISTER_SIZE]
112
113 /* Place LR into the saved PC, this will ensure that when
114 switching to this saved context with setcontext() control
115 will pass back to the caller of getcontext(), we have
116 already arrange to return the appropriate return value in x0
Mark Mentovai 2014/04/02 16:22:18 arranged
rmcilroy 2014/04/02 23:01:28 Done.
117 above. */
118 str x30, [x0, MCONTEXT_PC_OFFSET]
119
120 /* Save the current SP */
121 mov x2, sp
122 str x2, [x0, MCONTEXT_SP_OFFSET]
123
124 /* Initialize the pstate. */
125 str xzr, [x0, MCONTEXT_PSTATE_OFFSET]
126
127 /* Figure out where to place the first context extension
128 block. */
129 add x2, x0, #MCONTEXT_EXTENSION_OFFSET
130
131 /* Write the context extension fpsimd header. */
rmcilroy 2014/04/02 16:05:10 Do we need to save the fpsimd context for aarch64?
Mark Mentovai 2014/04/02 16:22:18 rmcilroy wrote:
rmcilroy 2014/04/02 23:01:28 Sounds good, I've updated exception_handler approp
132 mov w3, #(FPSIMD_MAGIC & 0xffff)
133 movk w3, #(FPSIMD_MAGIC >> 16), lsl #16
134 str w3, [x2, #FPSIMD_CONTEXT_MAGIC_OFFSET]
135 mov w3, #FPSIMD_CONTEXT_SIZE
136 str w3, [x2, #FPSIMD_CONTEXT_SIZE_OFFSET]
137
138 /* Fill in the FP SIMD context. */
139 add x3, x2, #(FPSIMD_CONTEXT_VREGS_OFFSET + 8 * SIMD_REGISTER_SIZE)
140 stp d8, d9, [x3], #(2 * SIMD_REGISTER_SIZE)
141 stp d10, d11, [x3], #(2 * SIMD_REGISTER_SIZE)
142 stp d12, d13, [x3], #(2 * SIMD_REGISTER_SIZE)
143 stp d14, d15, [x3], #(2 * SIMD_REGISTER_SIZE)
144
145 add x3, x2, FPSIMD_CONTEXT_FPSR_OFFSET
146
147 mrs x4, fpsr
148 str w4, [x3]
149
150 mrs x4, fpcr
151 str w4, [x3, FPSIMD_CONTEXT_FPCR_OFFSET - FPSIMD_CONTEXT_FPSR_OFFSET]
152
153 /* Write the termination context extension header. */
154 add x2, x2, #FPSIMD_CONTEXT_SIZE
155
156 str xzr, [x2, #FPSIMD_CONTEXT_MAGIC_OFFSET]
157 str xzr, [x2, #FPSIMD_CONTEXT_SIZE_OFFSET]
158
159 /* Grab the signal mask */
160 /* rt_sigprocmask (SIG_BLOCK, NULL, &ucp->uc_sigmask, _NSIG8) */
161 add x2, x0, #UCONTEXT_SIGMASK_OFFSET
162 mov x0, #0 /* SIG_BLOCK */
163 mov x1, #0 /* NULL */
164 mov x3, #(_NSIG / 8)
165 mov x8, #__NR_rt_sigprocmask
166 svc 0
167
168 /* Return x0 for success */
169 mov x0, 0
170 ret
171
172 .cfi_endproc
173 .size breakpad_getcontext, . - breakpad_getcontext
174
91 #elif defined(__i386__) 175 #elif defined(__i386__)
92 176
93 .text 177 .text
94 .global breakpad_getcontext 178 .global breakpad_getcontext
95 .hidden breakpad_getcontext 179 .hidden breakpad_getcontext
96 .align 4 180 .align 4
97 .type breakpad_getcontext, @function 181 .type breakpad_getcontext, @function
98 182
99 breakpad_getcontext: 183 breakpad_getcontext:
100 184
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 push %ecx /* NULL */ 217 push %ecx /* NULL */
134 push %ecx /* SIGBLOCK == 0 on i386 */ 218 push %ecx /* SIGBLOCK == 0 on i386 */
135 call sigprocmask@PLT 219 call sigprocmask@PLT
136 addl $12, %esp 220 addl $12, %esp
137 221
138 movl $0, %eax 222 movl $0, %eax
139 ret 223 ret
140 224
141 .size breakpad_getcontext, . - breakpad_getcontext 225 .size breakpad_getcontext, . - breakpad_getcontext
142 226
143 #elif defined(__aarch64__)
144
145 // TODO(rmcilroy): Implement for arm64.
146
147 #elif defined(__mips__) 227 #elif defined(__mips__)
148 228
149 #if _MIPS_SIM != _ABIO32 229 #if _MIPS_SIM != _ABIO32
150 #error "Unsupported mips ISA. Only mips o32 is supported." 230 #error "Unsupported mips ISA. Only mips o32 is supported."
151 #endif 231 #endif
152 232
153 // This implementation is inspired by implementation of getcontext in glibc. 233 // This implementation is inspired by implementation of getcontext in glibc.
154 #include <asm/asm.h> 234 #include <asm/asm.h>
155 #include <asm/regdef.h> 235 #include <asm/regdef.h>
156 #include <asm/fpregdef.h> 236 #include <asm/fpregdef.h>
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 lw gp, GP_FRAME_OFFSET(sp) 299 lw gp, GP_FRAME_OFFSET(sp)
220 addiu sp, FRAME_SIZE 300 addiu sp, FRAME_SIZE
221 jr ra 301 jr ra
222 302
223 END (breakpad_getcontext) 303 END (breakpad_getcontext)
224 304
225 305
226 #else 306 #else
227 #error "This file has not been ported for your CPU!" 307 #error "This file has not been ported for your CPU!"
228 #endif 308 #endif
OLDNEW
« no previous file with comments | « no previous file | common/android/ucontext_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld 1004:630ec63f810e-tainted