1/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_RUNTIME_ARCH_ARM_ASM_SUPPORT_ARM_S_
18#define ART_RUNTIME_ARCH_ARM_ASM_SUPPORT_ARM_S_
19
20#include "asm_support_arm.h"
21
22// Define special registers.
23
24// Register holding suspend check count down.
25#define rSUSPEND r4
26// Register holding Thread::Current().
27#define rSELF r9
28
29.syntax unified
30.arch armv7-a
31.thumb
32
33// Macro to generate the value of Runtime::Current into rDest clobbering rTemp. As it uses labels
34// then the labels need to be unique. We bind these to the function name in the ENTRY macros.
35.macro RUNTIME_CURRENT name, num, rDest, rTemp
36    .if .Lruntime_current\num\()_used
37         .error
38    .endif
39    .set .Lruntime_current\num\()_used, 1
40    ldr \rDest, .Lgot_\name\()_\num               @ Load offset of the GOT.
41    ldr \rTemp, .Lruntime_instance_\name\()_\num  @ Load GOT offset of Runtime::instance_.
42.Lload_got_\name\()_\num\():
43    add \rDest, pc                                @ Fixup GOT address.
44    ldr \rDest, [\rDest, \rTemp]                  @ Load address of Runtime::instance_.
45    ldr \rDest, [\rDest]                          @ Load Runtime::instance_.
46.endm
47
48// Common ENTRY declaration code for ARM and thumb, an ENTRY should always be paired with an END.
49// Declares the RUNTIME_CURRENT[123] macros that can be used within an ENTRY and will have literals
50// generated at END.
51.macro DEF_ENTRY thumb_or_arm, name
52    \thumb_or_arm
53    .type \name, #function
54    .hidden \name  // Hide this as a global symbol, so we do not incur plt calls.
55    .global \name
56    // Cache alignment for function entry.
57    .balign 16
58\name:
59    .cfi_startproc
60    .fnstart
61    // Track whether RUNTIME_CURRENT was used.
62    .set .Lruntime_current1_used, 0
63    .set .Lruntime_current2_used, 0
64    .set .Lruntime_current3_used, 0
65    // The RUNTIME_CURRENT macros that are bound to the \name argument of DEF_ENTRY to ensure
66    // that label names are unique.
67    .macro RUNTIME_CURRENT1 rDest, rTemp
68        RUNTIME_CURRENT \name, 1, \rDest, \rTemp
69    .endm
70    .macro RUNTIME_CURRENT2 rDest, rTemp
71        RUNTIME_CURRENT \name, 2, \rDest, \rTemp
72    .endm
73    .macro RUNTIME_CURRENT3 rDest, rTemp
74        RUNTIME_CURRENT \name, 3, \rDest, \rTemp
75    .endm
76.endm
77
78// A thumb2 style ENTRY.
79.macro ENTRY name
80    DEF_ENTRY .thumb_func, \name
81.endm
82
83// A ARM style ENTRY.
84.macro ARM_ENTRY name
85    DEF_ENTRY .arm, \name
86.endm
87
88// Terminate an ENTRY and generate GOT references.
89.macro END name
90     // Generate offsets of GOT and Runtime::instance_ used in RUNTIME_CURRENT.
91     .if .Lruntime_current1_used
92         .Lgot_\name\()_1:
93             .word   _GLOBAL_OFFSET_TABLE_-(.Lload_got_\name\()_1+4)
94         .Lruntime_instance_\name\()_1:
95             .word   _ZN3art7Runtime9instance_E(GOT)
96     .endif
97     .if .Lruntime_current2_used
98         .Lgot_\name\()_2:
99             .word   _GLOBAL_OFFSET_TABLE_-(.Lload_got_\name\()_2+4)
100         .Lruntime_instance_\name\()_2:
101             .word   _ZN3art7Runtime9instance_E(GOT)
102    .endif
103     .if .Lruntime_current3_used
104         .Lgot_\name\()_3:
105             .word   _GLOBAL_OFFSET_TABLE_-(.Lload_got_\name\()_3+4)
106         .Lruntime_instance_\name\()_3:
107             .word   _ZN3art7Runtime9instance_E(GOT)
108    .endif
109    // Remove the RUNTIME_CURRENTx macros so they get rebound in the next function entry.
110    .purgem RUNTIME_CURRENT1
111    .purgem RUNTIME_CURRENT2
112    .purgem RUNTIME_CURRENT3
113    .fnend
114    .cfi_endproc
115    .size \name, .-\name
116.endm
117
118// Declare an unimplemented ENTRY that will halt a debugger.
119.macro UNIMPLEMENTED name
120    ENTRY \name
121    bkpt
122    bkpt
123    END \name
124.endm
125
126#endif  // ART_RUNTIME_ARCH_X86_ASM_SUPPORT_X86_S_
127