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