blob: 18819e4707958997f3b2081ef3ce32fc859e2964 [file] [log] [blame]
bellard79638562003-06-15 19:46:57 +00001/*
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 Swirl8167ee82009-07-16 20:47:01 +000017 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
bellard79638562003-06-15 19:46:57 +000018 */
bellard67867302003-11-23 17:05:30 +000019#if !defined(__DYNGEN_EXEC_H__)
20#define __DYNGEN_EXEC_H__
21
bellardec530c82006-04-25 22:36:06 +000022/* 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
bellard1e6cae92004-07-10 15:31:19 +000029/* 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. */
bellard513b5002004-01-04 17:44:08 +000032#include <stddef.h>
aurel32b7df4bc2009-04-08 22:56:19 +000033#include <stdint.h>
bellard513b5002004-01-04 17:44:08 +000034
blueswir1128ab2f2008-08-15 18:33:42 +000035#ifdef __OpenBSD__
36#include <sys/types.h>
blueswir1128ab2f2008-08-15 18:33:42 +000037#endif
bellard79638562003-06-15 19:46:57 +000038
pbrook1057eaa2007-02-04 13:37:44 +000039/* XXX: This may be wrong for 64-bit ILP32 hosts. */
40typedef void * host_reg_t;
41
Juan Quintela71e72a12009-07-27 16:12:56 +020042#ifdef CONFIG_BSD
thscce10752007-04-02 12:39:43 +000043typedef struct __sFILE FILE;
44#else
bellard79638562003-06-15 19:46:57 +000045typedef struct FILE FILE;
thscce10752007-04-02 12:39:43 +000046#endif
bellard79638562003-06-15 19:46:57 +000047extern int fprintf(FILE *, const char *, ...);
ths24c7b0e2007-03-30 16:44:54 +000048extern int fputs(const char *, FILE *);
bellard79638562003-06-15 19:46:57 +000049extern int printf(const char *, ...);
bellard513b5002004-01-04 17:44:08 +000050#undef NULL
bellard79638562003-06-15 19:46:57 +000051#define NULL 0
bellard79638562003-06-15 19:46:57 +000052
ths522777b2007-05-08 23:30:44 +000053#if defined(__i386__)
bellard79638562003-06-15 19:46:57 +000054#define AREG0 "ebp"
55#define AREG1 "ebx"
56#define AREG2 "esi"
ths522777b2007-05-08 23:30:44 +000057#elif defined(__x86_64__)
ths43024c62007-02-10 18:21:04 +000058#define AREG0 "r14"
59#define AREG1 "r15"
bellardbc51c5c2004-03-17 23:46:04 +000060#define AREG2 "r12"
malce58ffeb2009-01-14 18:39:49 +000061#elif defined(_ARCH_PPC)
bellard79638562003-06-15 19:46:57 +000062#define AREG0 "r27"
63#define AREG1 "r24"
64#define AREG2 "r25"
ths522777b2007-05-08 23:30:44 +000065#elif defined(__arm__)
bellard79638562003-06-15 19:46:57 +000066#define AREG0 "r7"
67#define AREG1 "r4"
68#define AREG2 "r5"
aurel32f54b3f92008-04-12 20:14:54 +000069#elif defined(__hppa__)
70#define AREG0 "r17"
71#define AREG1 "r14"
72#define AREG2 "r15"
ths522777b2007-05-08 23:30:44 +000073#elif defined(__mips__)
thsc4b89d12007-05-05 19:23:11 +000074#define AREG0 "fp"
bellard79638562003-06-15 19:46:57 +000075#define AREG1 "s0"
76#define AREG2 "s1"
ths522777b2007-05-08 23:30:44 +000077#elif defined(__sparc__)
Juan Quinteladfe5fff2009-07-27 16:12:40 +020078#ifdef CONFIG_SOLARIS
bellardfdbb4692006-06-14 17:32:25 +000079#define AREG0 "g2"
80#define AREG1 "g3"
81#define AREG2 "g4"
bellardfdbb4692006-06-14 17:32:25 +000082#else
bellard74ccb342006-07-18 21:23:34 +000083#ifdef __sparc_v9__
blueswir1e97b6402008-07-26 17:19:35 +000084#define AREG0 "g5"
85#define AREG1 "g6"
86#define AREG2 "g7"
bellard74ccb342006-07-18 21:23:34 +000087#else
bellard79638562003-06-15 19:46:57 +000088#define AREG0 "g6"
89#define AREG1 "g1"
90#define AREG2 "g2"
bellardfdbb4692006-06-14 17:32:25 +000091#endif
bellard74ccb342006-07-18 21:23:34 +000092#endif
ths522777b2007-05-08 23:30:44 +000093#elif defined(__s390__)
bellard79638562003-06-15 19:46:57 +000094#define AREG0 "r10"
95#define AREG1 "r7"
96#define AREG2 "r8"
ths522777b2007-05-08 23:30:44 +000097#elif defined(__alpha__)
bellard79638562003-06-15 19:46:57 +000098/* 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"
ths522777b2007-05-08 23:30:44 +0000103#elif defined(__mc68000)
bellard38e584a2003-08-10 22:14:22 +0000104#define AREG0 "%a5"
105#define AREG1 "%a4"
106#define AREG2 "%d7"
ths522777b2007-05-08 23:30:44 +0000107#elif defined(__ia64__)
bellardb8076a72005-04-07 22:20:31 +0000108#define AREG0 "r7"
109#define AREG1 "r4"
110#define AREG2 "r5"
ths522777b2007-05-08 23:30:44 +0000111#else
112#error unsupported CPU
bellard79638562003-06-15 19:46:57 +0000113#endif
114
bellard79638562003-06-15 19:46:57 +0000115#define xglue(x, y) x ## y
116#define glue(x, y) xglue(x, y)
bellard96213392003-07-11 15:17:41 +0000117#define stringify(s) tostring(s)
118#define tostring(s) #s
bellard79638562003-06-15 19:46:57 +0000119
pbrook9b7b85d2008-05-25 00:36:06 +0000120/* 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
bellard67867302003-11-23 17:05:30 +0000132#endif /* !defined(__DYNGEN_EXEC_H__) */