blob: 8e6d04ca0bb747c6a64567fe8b7793fca46a79b3 [file] [log] [blame]
Christopher Ferris2a25c4a2017-07-07 16:35:48 -07001/*
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#if defined(__arm__)
33
34inline void RegsGetLocal(Regs* regs) {
35 void* reg_data = regs->RawData();
36 asm volatile(
37 ".align 2\n"
38 "bx pc\n"
39 "nop\n"
40 ".code 32\n"
41 "stmia %[base], {r0-r12}\n"
42 "add %[base], #52\n"
43 "mov r1, r13\n"
44 "mov r2, r14\n"
45 "mov r3, r15\n"
46 "stmia %[base], {r1-r3}\n"
47 "orr %[base], pc, #1\n"
48 "bx %[base]\n"
49 : [base] "+r"(reg_data)
50 :
51 : "memory");
52
53 regs->SetFromRaw();
54}
55
56#elif defined(__aarch64__)
57
58inline 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 regs->SetFromRaw();
86}
87
88#elif defined(__i386__) || defined(__x86_64__)
89
90extern "C" void AsmGetRegs(void* regs);
91
92inline void RegsGetLocal(Regs* regs) {
93 AsmGetRegs(regs->RawData());
94
95 regs->SetFromRaw();
96}
97
98#endif
99
100#endif // _LIBUNWINDSTACK_REGS_GET_LOCAL_H