blob: 283c28625c5fc3922d2d069d7c0c3036f2c1c64d [file] [log] [blame]
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001/*
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' Turner2910f182010-05-10 18:48:35 -070017 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080018 */
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' Turner5d8f37a2009-09-14 14:32:27 -070033#include <stdint.h>
David Turner3b290c32010-09-09 23:49:44 +020034#include <stdbool.h>
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080035
36#ifdef __OpenBSD__
37#include <sys/types.h>
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080038#endif
39
40/* XXX: This may be wrong for 64-bit ILP32 hosts. */
41typedef void * host_reg_t;
42
David 'Digit' Turner2c538c82010-05-10 16:48:20 -070043#ifdef CONFIG_BSD
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080044typedef struct __sFILE FILE;
45#else
46typedef struct FILE FILE;
47#endif
48extern int fprintf(FILE *, const char *, ...);
49extern int fputs(const char *, FILE *);
50extern int printf(const char *, ...);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080051
52#if defined(__i386__)
53#define AREG0 "ebp"
54#define AREG1 "ebx"
55#define AREG2 "esi"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080056#elif defined(__x86_64__)
57#define AREG0 "r14"
58#define AREG1 "r15"
59#define AREG2 "r12"
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -070060#elif defined(_ARCH_PPC)
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080061#define AREG0 "r27"
62#define AREG1 "r24"
63#define AREG2 "r25"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080064#elif defined(__arm__)
65#define AREG0 "r7"
66#define AREG1 "r4"
67#define AREG2 "r5"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080068#elif defined(__hppa__)
69#define AREG0 "r17"
70#define AREG1 "r14"
71#define AREG2 "r15"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080072#elif defined(__mips__)
73#define AREG0 "fp"
74#define AREG1 "s0"
75#define AREG2 "s1"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080076#elif defined(__sparc__)
David 'Digit' Turner2c538c82010-05-10 16:48:20 -070077#ifdef CONFIG_SOLARIS
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080078#define AREG0 "g2"
79#define AREG1 "g3"
80#define AREG2 "g4"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080081#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 Project8b23a6c2009-03-03 19:30:32 -080090#endif
91#endif
92#elif defined(__s390__)
93#define AREG0 "r10"
94#define AREG1 "r7"
95#define AREG2 "r8"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080096#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 Project8b23a6c2009-03-03 19:30:32 -0800102#elif defined(__mc68000)
103#define AREG0 "%a5"
104#define AREG1 "%a4"
105#define AREG2 "%d7"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800106#elif defined(__ia64__)
107#define AREG0 "r7"
108#define AREG1 "r4"
109#define AREG2 "r5"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800110#else
111#error unsupported CPU
112#endif
113
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800114#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 Project8b23a6c2009-03-03 19:30:32 -0800119/* The return address may point to the start of the next instruction.
120 Subtracting one gets us the call instruction itself. */
David 'Digit' Turner2910f182010-05-10 18:48:35 -0700121#if defined(__s390__) && !defined(__s390x__)
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800122# 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__) */