bellard | 7963856 | 2003-06-15 19:46:57 +0000 | [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 |
Blue Swirl | 8167ee8 | 2009-07-16 20:47:01 +0000 | [diff] [blame] | 17 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
bellard | 7963856 | 2003-06-15 19:46:57 +0000 | [diff] [blame] | 18 | */ |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 19 | #if !defined(__DYNGEN_EXEC_H__) |
| 20 | #define __DYNGEN_EXEC_H__ |
| 21 | |
bellard | ec530c8 | 2006-04-25 22:36:06 +0000 | [diff] [blame] | 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 | |
bellard | 1e6cae9 | 2004-07-10 15:31:19 +0000 | [diff] [blame] | 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. */ |
bellard | 513b500 | 2004-01-04 17:44:08 +0000 | [diff] [blame] | 32 | #include <stddef.h> |
aurel32 | b7df4bc | 2009-04-08 22:56:19 +0000 | [diff] [blame] | 33 | #include <stdint.h> |
bellard | 513b500 | 2004-01-04 17:44:08 +0000 | [diff] [blame] | 34 | |
blueswir1 | 128ab2f | 2008-08-15 18:33:42 +0000 | [diff] [blame] | 35 | #ifdef __OpenBSD__ |
| 36 | #include <sys/types.h> |
blueswir1 | 128ab2f | 2008-08-15 18:33:42 +0000 | [diff] [blame] | 37 | #endif |
bellard | 7963856 | 2003-06-15 19:46:57 +0000 | [diff] [blame] | 38 | |
pbrook | 1057eaa | 2007-02-04 13:37:44 +0000 | [diff] [blame] | 39 | /* XXX: This may be wrong for 64-bit ILP32 hosts. */ |
| 40 | typedef void * host_reg_t; |
| 41 | |
Juan Quintela | 71e72a1 | 2009-07-27 16:12:56 +0200 | [diff] [blame] | 42 | #ifdef CONFIG_BSD |
ths | cce1075 | 2007-04-02 12:39:43 +0000 | [diff] [blame] | 43 | typedef struct __sFILE FILE; |
| 44 | #else |
bellard | 7963856 | 2003-06-15 19:46:57 +0000 | [diff] [blame] | 45 | typedef struct FILE FILE; |
ths | cce1075 | 2007-04-02 12:39:43 +0000 | [diff] [blame] | 46 | #endif |
bellard | 7963856 | 2003-06-15 19:46:57 +0000 | [diff] [blame] | 47 | extern int fprintf(FILE *, const char *, ...); |
ths | 24c7b0e | 2007-03-30 16:44:54 +0000 | [diff] [blame] | 48 | extern int fputs(const char *, FILE *); |
bellard | 7963856 | 2003-06-15 19:46:57 +0000 | [diff] [blame] | 49 | extern int printf(const char *, ...); |
bellard | 513b500 | 2004-01-04 17:44:08 +0000 | [diff] [blame] | 50 | #undef NULL |
bellard | 7963856 | 2003-06-15 19:46:57 +0000 | [diff] [blame] | 51 | #define NULL 0 |
bellard | 7963856 | 2003-06-15 19:46:57 +0000 | [diff] [blame] | 52 | |
ths | 522777b | 2007-05-08 23:30:44 +0000 | [diff] [blame] | 53 | #if defined(__i386__) |
bellard | 7963856 | 2003-06-15 19:46:57 +0000 | [diff] [blame] | 54 | #define AREG0 "ebp" |
| 55 | #define AREG1 "ebx" |
| 56 | #define AREG2 "esi" |
ths | 522777b | 2007-05-08 23:30:44 +0000 | [diff] [blame] | 57 | #elif defined(__x86_64__) |
ths | 43024c6 | 2007-02-10 18:21:04 +0000 | [diff] [blame] | 58 | #define AREG0 "r14" |
| 59 | #define AREG1 "r15" |
bellard | bc51c5c | 2004-03-17 23:46:04 +0000 | [diff] [blame] | 60 | #define AREG2 "r12" |
malc | e58ffeb | 2009-01-14 18:39:49 +0000 | [diff] [blame] | 61 | #elif defined(_ARCH_PPC) |
bellard | 7963856 | 2003-06-15 19:46:57 +0000 | [diff] [blame] | 62 | #define AREG0 "r27" |
| 63 | #define AREG1 "r24" |
| 64 | #define AREG2 "r25" |
ths | 522777b | 2007-05-08 23:30:44 +0000 | [diff] [blame] | 65 | #elif defined(__arm__) |
bellard | 7963856 | 2003-06-15 19:46:57 +0000 | [diff] [blame] | 66 | #define AREG0 "r7" |
| 67 | #define AREG1 "r4" |
| 68 | #define AREG2 "r5" |
aurel32 | f54b3f9 | 2008-04-12 20:14:54 +0000 | [diff] [blame] | 69 | #elif defined(__hppa__) |
| 70 | #define AREG0 "r17" |
| 71 | #define AREG1 "r14" |
| 72 | #define AREG2 "r15" |
ths | 522777b | 2007-05-08 23:30:44 +0000 | [diff] [blame] | 73 | #elif defined(__mips__) |
ths | c4b89d1 | 2007-05-05 19:23:11 +0000 | [diff] [blame] | 74 | #define AREG0 "fp" |
bellard | 7963856 | 2003-06-15 19:46:57 +0000 | [diff] [blame] | 75 | #define AREG1 "s0" |
| 76 | #define AREG2 "s1" |
ths | 522777b | 2007-05-08 23:30:44 +0000 | [diff] [blame] | 77 | #elif defined(__sparc__) |
Juan Quintela | dfe5fff | 2009-07-27 16:12:40 +0200 | [diff] [blame] | 78 | #ifdef CONFIG_SOLARIS |
bellard | fdbb469 | 2006-06-14 17:32:25 +0000 | [diff] [blame] | 79 | #define AREG0 "g2" |
| 80 | #define AREG1 "g3" |
| 81 | #define AREG2 "g4" |
bellard | fdbb469 | 2006-06-14 17:32:25 +0000 | [diff] [blame] | 82 | #else |
bellard | 74ccb34 | 2006-07-18 21:23:34 +0000 | [diff] [blame] | 83 | #ifdef __sparc_v9__ |
blueswir1 | e97b640 | 2008-07-26 17:19:35 +0000 | [diff] [blame] | 84 | #define AREG0 "g5" |
| 85 | #define AREG1 "g6" |
| 86 | #define AREG2 "g7" |
bellard | 74ccb34 | 2006-07-18 21:23:34 +0000 | [diff] [blame] | 87 | #else |
bellard | 7963856 | 2003-06-15 19:46:57 +0000 | [diff] [blame] | 88 | #define AREG0 "g6" |
| 89 | #define AREG1 "g1" |
| 90 | #define AREG2 "g2" |
bellard | fdbb469 | 2006-06-14 17:32:25 +0000 | [diff] [blame] | 91 | #endif |
bellard | 74ccb34 | 2006-07-18 21:23:34 +0000 | [diff] [blame] | 92 | #endif |
ths | 522777b | 2007-05-08 23:30:44 +0000 | [diff] [blame] | 93 | #elif defined(__s390__) |
bellard | 7963856 | 2003-06-15 19:46:57 +0000 | [diff] [blame] | 94 | #define AREG0 "r10" |
| 95 | #define AREG1 "r7" |
| 96 | #define AREG2 "r8" |
ths | 522777b | 2007-05-08 23:30:44 +0000 | [diff] [blame] | 97 | #elif defined(__alpha__) |
bellard | 7963856 | 2003-06-15 19:46:57 +0000 | [diff] [blame] | 98 | /* Note $15 is the frame pointer, so anything in op-i386.c that would |
| 99 | require a frame pointer, like alloca, would probably loose. */ |
| 100 | #define AREG0 "$15" |
| 101 | #define AREG1 "$9" |
| 102 | #define AREG2 "$10" |
ths | 522777b | 2007-05-08 23:30:44 +0000 | [diff] [blame] | 103 | #elif defined(__mc68000) |
bellard | 38e584a | 2003-08-10 22:14:22 +0000 | [diff] [blame] | 104 | #define AREG0 "%a5" |
| 105 | #define AREG1 "%a4" |
| 106 | #define AREG2 "%d7" |
ths | 522777b | 2007-05-08 23:30:44 +0000 | [diff] [blame] | 107 | #elif defined(__ia64__) |
bellard | b8076a7 | 2005-04-07 22:20:31 +0000 | [diff] [blame] | 108 | #define AREG0 "r7" |
| 109 | #define AREG1 "r4" |
| 110 | #define AREG2 "r5" |
ths | 522777b | 2007-05-08 23:30:44 +0000 | [diff] [blame] | 111 | #else |
| 112 | #error unsupported CPU |
bellard | 7963856 | 2003-06-15 19:46:57 +0000 | [diff] [blame] | 113 | #endif |
| 114 | |
bellard | 7963856 | 2003-06-15 19:46:57 +0000 | [diff] [blame] | 115 | #define xglue(x, y) x ## y |
| 116 | #define glue(x, y) xglue(x, y) |
bellard | 9621339 | 2003-07-11 15:17:41 +0000 | [diff] [blame] | 117 | #define stringify(s) tostring(s) |
| 118 | #define tostring(s) #s |
bellard | 7963856 | 2003-06-15 19:46:57 +0000 | [diff] [blame] | 119 | |
pbrook | 9b7b85d | 2008-05-25 00:36:06 +0000 | [diff] [blame] | 120 | /* The return address may point to the start of the next instruction. |
| 121 | Subtracting one gets us the call instruction itself. */ |
| 122 | #if defined(__s390__) |
| 123 | # define GETPC() ((void*)(((unsigned long)__builtin_return_address(0) & 0x7fffffffUL) - 1)) |
| 124 | #elif defined(__arm__) |
| 125 | /* Thumb return addresses have the low bit set, so we need to subtract two. |
| 126 | This is still safe in ARM mode because instructions are 4 bytes. */ |
| 127 | # define GETPC() ((void *)((unsigned long)__builtin_return_address(0) - 2)) |
| 128 | #else |
| 129 | # define GETPC() ((void *)((unsigned long)__builtin_return_address(0) - 1)) |
| 130 | #endif |
| 131 | |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 132 | #endif /* !defined(__DYNGEN_EXEC_H__) */ |