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
AsmGetRegs(void * reg_data)36 inline __attribute__((__always_inline__)) void AsmGetRegs(void* reg_data) {
37 asm volatile(
38 ".align 2\n"
39 "bx pc\n"
40 "nop\n"
41 ".code 32\n"
42 "stmia %[base], {r0-r12}\n"
43 "add %[base], #52\n"
44 "mov r1, r13\n"
45 "mov r2, r14\n"
46 "mov r3, r15\n"
47 "stmia %[base], {r1-r3}\n"
48 "orr %[base], pc, #1\n"
49 "bx %[base]\n"
50 : [base] "+r"(reg_data)
51 :
52 : "memory");
53 }
54
55 #elif defined(__aarch64__)
56
57 inline __attribute__((__always_inline__)) void AsmGetRegs(void* reg_data) {
58 asm volatile(
59 "1:\n"
60 "stp x0, x1, [%[base], #0]\n"
61 "stp x2, x3, [%[base], #16]\n"
62 "stp x4, x5, [%[base], #32]\n"
63 "stp x6, x7, [%[base], #48]\n"
64 "stp x8, x9, [%[base], #64]\n"
65 "stp x10, x11, [%[base], #80]\n"
66 "stp x12, x13, [%[base], #96]\n"
67 "stp x14, x15, [%[base], #112]\n"
68 "stp x16, x17, [%[base], #128]\n"
69 "stp x18, x19, [%[base], #144]\n"
70 "stp x20, x21, [%[base], #160]\n"
71 "stp x22, x23, [%[base], #176]\n"
72 "stp x24, x25, [%[base], #192]\n"
73 "stp x26, x27, [%[base], #208]\n"
74 "stp x28, x29, [%[base], #224]\n"
75 "str x30, [%[base], #240]\n"
76 "mov x12, sp\n"
77 "adr x13, 1b\n"
78 "stp x12, x13, [%[base], #248]\n"
79 : [base] "+r"(reg_data)
80 :
81 : "x12", "x13", "memory");
82 }
83
84 #elif defined(__i386__) || defined(__x86_64__)
85
86 extern "C" void AsmGetRegs(void* regs);
87
88 #endif
89
RegsGetLocal(Regs * regs)90 inline __attribute__((__always_inline__)) void RegsGetLocal(Regs* regs) {
91 AsmGetRegs(regs->RawData());
92 }
93
94
95 } // namespace unwindstack
96
97 #endif // _LIBUNWINDSTACK_REGS_GET_LOCAL_H
98