tcg.h revision 88cc6bfb70dbd23172f00ed679d5f1df8e9d7f53
/*
* Tiny Code Generator for QEMU
*
* Copyright (c) 2008 Fabrice Bellard
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "tcg-target.h"
#if TCG_TARGET_REG_BITS == 32
typedef int32_t tcg_target_long;
typedef uint32_t tcg_target_ulong;
typedef int64_t tcg_target_long;
typedef uint64_t tcg_target_ulong;
#else
#endif
#if TCG_TARGET_NB_REGS <= 32
#else
#endif
enum {
#include "tcg-opc.h"
};
#define tcg_regset_clear(d) (d) = 0
#define tcg_regset_set(d, s) (d) = (s)
#define tcg_regset_set_reg(d, r) (d) |= 1 << (r)
#define tcg_regset_reset_reg(d, r) (d) &= ~(1 << (r))
#define tcg_regset_test_reg(d, r) (((d) >> (r)) & 1)
#define tcg_regset_or(d, a, b) (d) = (a) | (b)
#define tcg_regset_and(d, a, b) (d) = (a) & (b)
#define tcg_regset_andnot(d, a, b) (d) = (a) & ~(b)
#define tcg_regset_not(d, a) (d) = ~(a)
typedef struct TCGRelocation {
struct TCGRelocation *next;
int type;
typedef struct TCGLabel {
int has_value;
union {
} u;
} TCGLabel;
typedef struct TCGPool {
int size;
#ifndef VBOX
#else
#endif
} TCGPool;
#define TCG_POOL_CHUNK_SIZE 32768
#define TCG_MAX_LABELS 512
#define TCG_MAX_TEMPS 512
/* when the size of the arguments of a called function is smaller than
this value, they are statically allocated in the TB stack frame */
#define TCG_STATIC_CALL_ARGS_SIZE 128
typedef int TCGType;
#define TCG_TYPE_I32 0
#define TCG_TYPE_I64 1
#if TCG_TARGET_REG_BITS == 32
#define TCG_TYPE_PTR TCG_TYPE_I32
#else
#define TCG_TYPE_PTR TCG_TYPE_I64
#endif
typedef tcg_target_ulong TCGArg;
/* Define a type and accessor macros for varables. Using a struct is
nice because it gives some level of type safely. Ideally the compiler
be able to see through all this. However in practice this is not true,
expecially on targets with braindamaged ABIs (e.g. i386).
We use plain int by default to avoid this runtime overhead.
Users of tcg_gen_* don't need to know about any of this, and should
treat TCGv as an opaque type. */
//#define DEBUG_TCGV 1
#ifdef DEBUG_TCGV
typedef struct
{
int n;
} TCGv;
#define MAKE_TCGV(i) __extension__ \
#define GET_TCGV(t) ((t).n)
#if TCG_TARGET_REG_BITS == 32
#endif
#else /* !DEBUG_TCGV */
typedef int TCGv;
#define MAKE_TCGV(x) (x)
#define GET_TCGV(t) (t)
#if TCG_TARGET_REG_BITS == 32
#define TCGV_HIGH(t) ((t) + 1)
#endif
#endif /* DEBUG_TCGV */
/* Dummy definition to avoid compiler warnings. */
/* call flags */
#define TCG_CALL_TYPE_MASK 0x000f
/* A pure function only reads its arguments and globals variables and
cannot raise exceptions. Hence a call to a pure function can be
safely suppressed if the return value is not used. */
#define TCG_CALL_PURE 0x0010
/* used to align parameters */
typedef enum {
/* unsigned */
} TCGCond;
#define TEMP_VAL_DEAD 0
#define TEMP_VAL_REG 1
#define TEMP_VAL_MEM 2
#define TEMP_VAL_CONST 3
/* XXX: optimize memory layout */
typedef struct TCGTemp {
int val_type;
int reg;
int mem_reg;
unsigned int fixed_reg:1;
unsigned int mem_coherent:1;
unsigned int mem_allocated:1;
basic blocks. Otherwise, it is not
preserved accross basic blocks. */
/* index of next free temp of same base type, -1 if end */
int next_free_temp;
const char *name;
} TCGTemp;
typedef struct TCGHelperInfo {
const char *name;
typedef struct TCGContext TCGContext;
struct TCGContext {
int nb_labels;
int nb_globals;
int nb_temps;
/* index of free temps, -1 if none */
/* goto_tb support */
unsigned long *tb_next;
/* liveness analysis */
corresponding input argument is dead */
/* tells in which temporary a given register is. It does not take
into account fixed registers */
int frame_reg;
int nb_helpers;
int allocated_helpers;
int helpers_sorted;
#ifdef CONFIG_PROFILER
/* profiling info */
int op_count_max; /* max insn per TB */
int temp_count_max;
#endif
};
extern TCGContext tcg_ctx;
extern uint16_t *gen_opc_ptr;
extern TCGArg *gen_opparam_ptr;
extern uint16_t gen_opc_buf[];
extern TCGArg gen_opparam_buf[];
/* pool based memory allocation */
void tcg_pool_reset(TCGContext *s);
void tcg_pool_delete(TCGContext *s);
#ifndef VBOX
static inline void *tcg_malloc(int size)
#else
#endif
{
TCGContext *s = &tcg_ctx;
} else {
return ptr;
}
}
void tcg_context_init(TCGContext *s);
void tcg_func_start(TCGContext *s);
const char *name);
const char *name);
#ifndef VBOX
#else
#endif
{
return tcg_temp_new_internal(type, 0);
}
#ifndef VBOX
#else
#endif
{
}
void tcg_dump_info(FILE *f,
#define TCG_CT_ALIAS 0x80
#define TCG_CT_IALIAS 0x40
#define TCG_CT_REG 0x01
typedef struct TCGArgConstraint {
union {
} u;
#define TCG_MAX_OP_ARGS 16
block */
and potentially update globals. */
cannot be removed if its output
are not used */
typedef struct TCGOpDef {
const char *name;
int *sorted_args;
} TCGOpDef;
typedef struct TCGTargetOpDef {
int op;
const char *args_ct_str[TCG_MAX_OP_ARGS];
extern TCGOpDef tcg_op_defs[];
void tcg_target_init(TCGContext *s);
void tcg_target_qemu_prologue(TCGContext *s);
#ifndef VBOX
#define tcg_abort() \
do {\
abort();\
} while (0)
#else
#define VBOX_STR(x) #x
#define tcg_abort() \
do {\
} while (0)
int(*compar)(const void*, const void*));
do {\
} while (0)
#endif
/* only used for debugging purposes */
#if TCG_TARGET_REG_BITS == 32
#define tcg_const_ptr tcg_const_i32
#define tcg_add_ptr tcg_add_i32
#define tcg_sub_ptr tcg_sub_i32
#else
#define tcg_const_ptr tcg_const_i64
#define tcg_add_ptr tcg_add_i64
#define tcg_sub_ptr tcg_sub_i64
#endif
int label_index, long addend);
unsigned int dead_iargs);
/* tcg-runtime.c */
#ifndef VBOX
extern uint8_t code_gen_prologue[];
#else
extern uint8_t* code_gen_prologue;
#endif
#if defined(__powerpc__) && !defined(__powerpc64__)
#define tcg_qemu_tb_exec(tb_ptr) \
#else
#if defined(VBOX) && defined(GCC_WITH_BUGGY_REGPARM)
__asm__ __volatile__("call *%%ecx" : "=a"(ret) : "a"(tb_ptr), "c" (&code_gen_prologue[0]) : "memory", "%edx", "cc")
#else
#endif
#endif