The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 1 | /* |
| 2 | * dyngen defines for micro operation code |
| 3 | * |
| 4 | * Copyright (c) 2003 Fabrice Bellard |
| 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 17 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 18 | */ |
| 19 | #if !defined(__DYNGEN_EXEC_H__) |
| 20 | #define __DYNGEN_EXEC_H__ |
| 21 | |
| 22 | /* prevent Solaris from trying to typedef FILE in gcc's |
| 23 | include/floatingpoint.h which will conflict with the |
| 24 | definition down below */ |
| 25 | #ifdef __sun__ |
| 26 | #define _FILEDEFED |
| 27 | #endif |
| 28 | |
| 29 | /* NOTE: standard headers should be used with special care at this |
| 30 | point because host CPU registers are used as global variables. Some |
| 31 | host headers do not allow that. */ |
| 32 | #include <stddef.h> |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 33 | #include <stdint.h> |
David Turner | 3b290c3 | 2010-09-09 23:49:44 +0200 | [diff] [blame^] | 34 | #include <stdbool.h> |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 35 | |
| 36 | #ifdef __OpenBSD__ |
| 37 | #include <sys/types.h> |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 38 | #endif |
| 39 | |
| 40 | /* XXX: This may be wrong for 64-bit ILP32 hosts. */ |
| 41 | typedef void * host_reg_t; |
| 42 | |
David 'Digit' Turner | 2c538c8 | 2010-05-10 16:48:20 -0700 | [diff] [blame] | 43 | #ifdef CONFIG_BSD |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 44 | typedef struct __sFILE FILE; |
| 45 | #else |
| 46 | typedef struct FILE FILE; |
| 47 | #endif |
| 48 | extern int fprintf(FILE *, const char *, ...); |
| 49 | extern int fputs(const char *, FILE *); |
| 50 | extern int printf(const char *, ...); |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 51 | |
| 52 | #if defined(__i386__) |
| 53 | #define AREG0 "ebp" |
| 54 | #define AREG1 "ebx" |
| 55 | #define AREG2 "esi" |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 56 | #elif defined(__x86_64__) |
| 57 | #define AREG0 "r14" |
| 58 | #define AREG1 "r15" |
| 59 | #define AREG2 "r12" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 60 | #elif defined(_ARCH_PPC) |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 61 | #define AREG0 "r27" |
| 62 | #define AREG1 "r24" |
| 63 | #define AREG2 "r25" |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 64 | #elif defined(__arm__) |
| 65 | #define AREG0 "r7" |
| 66 | #define AREG1 "r4" |
| 67 | #define AREG2 "r5" |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 68 | #elif defined(__hppa__) |
| 69 | #define AREG0 "r17" |
| 70 | #define AREG1 "r14" |
| 71 | #define AREG2 "r15" |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 72 | #elif defined(__mips__) |
| 73 | #define AREG0 "fp" |
| 74 | #define AREG1 "s0" |
| 75 | #define AREG2 "s1" |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 76 | #elif defined(__sparc__) |
David 'Digit' Turner | 2c538c8 | 2010-05-10 16:48:20 -0700 | [diff] [blame] | 77 | #ifdef CONFIG_SOLARIS |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 78 | #define AREG0 "g2" |
| 79 | #define AREG1 "g3" |
| 80 | #define AREG2 "g4" |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 81 | #else |
| 82 | #ifdef __sparc_v9__ |
| 83 | #define AREG0 "g5" |
| 84 | #define AREG1 "g6" |
| 85 | #define AREG2 "g7" |
| 86 | #else |
| 87 | #define AREG0 "g6" |
| 88 | #define AREG1 "g1" |
| 89 | #define AREG2 "g2" |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 90 | #endif |
| 91 | #endif |
| 92 | #elif defined(__s390__) |
| 93 | #define AREG0 "r10" |
| 94 | #define AREG1 "r7" |
| 95 | #define AREG2 "r8" |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 96 | #elif defined(__alpha__) |
| 97 | /* Note $15 is the frame pointer, so anything in op-i386.c that would |
| 98 | require a frame pointer, like alloca, would probably loose. */ |
| 99 | #define AREG0 "$15" |
| 100 | #define AREG1 "$9" |
| 101 | #define AREG2 "$10" |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 102 | #elif defined(__mc68000) |
| 103 | #define AREG0 "%a5" |
| 104 | #define AREG1 "%a4" |
| 105 | #define AREG2 "%d7" |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 106 | #elif defined(__ia64__) |
| 107 | #define AREG0 "r7" |
| 108 | #define AREG1 "r4" |
| 109 | #define AREG2 "r5" |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 110 | #else |
| 111 | #error unsupported CPU |
| 112 | #endif |
| 113 | |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 114 | #define xglue(x, y) x ## y |
| 115 | #define glue(x, y) xglue(x, y) |
| 116 | #define stringify(s) tostring(s) |
| 117 | #define tostring(s) #s |
| 118 | |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 119 | /* The return address may point to the start of the next instruction. |
| 120 | Subtracting one gets us the call instruction itself. */ |
David 'Digit' Turner | 2910f18 | 2010-05-10 18:48:35 -0700 | [diff] [blame] | 121 | #if defined(__s390__) && !defined(__s390x__) |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 122 | # define GETPC() ((void*)(((unsigned long)__builtin_return_address(0) & 0x7fffffffUL) - 1)) |
| 123 | #elif defined(__arm__) |
| 124 | /* Thumb return addresses have the low bit set, so we need to subtract two. |
| 125 | This is still safe in ARM mode because instructions are 4 bytes. */ |
| 126 | # define GETPC() ((void *)((unsigned long)__builtin_return_address(0) - 2)) |
| 127 | #else |
| 128 | # define GETPC() ((void *)((unsigned long)__builtin_return_address(0) - 1)) |
| 129 | #endif |
| 130 | |
| 131 | #endif /* !defined(__DYNGEN_EXEC_H__) */ |