• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *  * Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  *  * Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in
12  *    the documentation and/or other materials provided with the
13  *    distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #ifndef _LIBUNWINDSTACK_REGS_GET_LOCAL_H
30 #define _LIBUNWINDSTACK_REGS_GET_LOCAL_H
31 
32 namespace unwindstack {
33 
34 #if defined(__arm__)
35 
RegsGetLocal(Regs * regs)36 inline __always_inline void RegsGetLocal(Regs* regs) {
37   void* reg_data = regs->RawData();
38   asm volatile(
39       ".align 2\n"
40       "bx pc\n"
41       "nop\n"
42       ".code 32\n"
43       "stmia %[base], {r0-r12}\n"
44       "add %[base], #52\n"
45       "mov r1, r13\n"
46       "mov r2, r14\n"
47       "mov r3, r15\n"
48       "stmia %[base], {r1-r3}\n"
49       "orr %[base], pc, #1\n"
50       "bx %[base]\n"
51       : [base] "+r"(reg_data)
52       :
53       : "memory");
54 }
55 
56 #elif defined(__aarch64__)
57 
58 inline __always_inline void RegsGetLocal(Regs* regs) {
59   void* reg_data = regs->RawData();
60   asm volatile(
61       "1:\n"
62       "stp x0, x1, [%[base], #0]\n"
63       "stp x2, x3, [%[base], #16]\n"
64       "stp x4, x5, [%[base], #32]\n"
65       "stp x6, x7, [%[base], #48]\n"
66       "stp x8, x9, [%[base], #64]\n"
67       "stp x10, x11, [%[base], #80]\n"
68       "stp x12, x13, [%[base], #96]\n"
69       "stp x14, x15, [%[base], #112]\n"
70       "stp x16, x17, [%[base], #128]\n"
71       "stp x18, x19, [%[base], #144]\n"
72       "stp x20, x21, [%[base], #160]\n"
73       "stp x22, x23, [%[base], #176]\n"
74       "stp x24, x25, [%[base], #192]\n"
75       "stp x26, x27, [%[base], #208]\n"
76       "stp x28, x29, [%[base], #224]\n"
77       "str x30, [%[base], #240]\n"
78       "mov x12, sp\n"
79       "adr x13, 1b\n"
80       "stp x12, x13, [%[base], #248]\n"
81       : [base] "+r"(reg_data)
82       :
83       : "x12", "x13", "memory");
84 }
85 
86 #elif defined(__i386__) || defined(__x86_64__) || defined(__mips__)
87 
88 extern "C" void AsmGetRegs(void* regs);
89 
90 inline void RegsGetLocal(Regs* regs) {
91   AsmGetRegs(regs->RawData());
92 }
93 
94 #endif
95 
96 }  // namespace unwindstack
97 
98 #endif  // _LIBUNWINDSTACK_REGS_GET_LOCAL_H
99