* Personal prototype "gx" translation-based JIT engine for M32R.
[deliverable/binutils-gdb.git] / sim / common / sim-gx.h
1 /* GX generic simulator structs.
2 Copyright (C) 1998 Cygnus Solutions.
3 */
4
5 #ifndef SIM_GX_H
6 #define SIM_GX_H
7
8 #include <stdio.h>
9 #include "sim-base.h"
10 #include "sim-core.h"
11
12
13 /*
14 #ifndef SIM_GX
15 #error "Compile this file only if configured SIM_GX"
16 #endif
17 */
18
19
20 /* configuration */
21
22 #define GX_DIR ".gx"
23 #define GX_VERSION 1
24
25
26 struct sim_gx_compiled_block;
27
28
29 /* record for a particular GX block */
30 typedef struct sim_gx_block
31 {
32 /* ---- BLOCK EXTENT ---- */
33 address_word origin; /* first code-segment address translated */
34 unsigned_4 length; /* length of translated code-segment */
35
36 #define GX_PC_INCLUDES(gx,pc) ((gx)->origin <= (pc) && (pc) < (gx)->origin + (gx)->length)
37
38 short divisor; /* minimum instruction word size; address_word -> index divisor */
39 char* pc_flags; /* see GX_PC_* below */
40
41 #define GX_PCF_INSTRUCTION 0x01 /* learned */
42 #define GX_PCF_JUMPTARGET 0x02 /* learned */
43 #define GX_PCF_COND_HALT 0x10 /* translate-time input */
44 #define GX_PCF_HALT 0x20 /* run-time input */
45 #define GX_PC_FLAGS_INDEX(gx,pc) ((((pc) - ((gx)->origin)) / (gx)->divisor))
46 #define GX_PC_FLAGS(gx,pc) ((gx)->pc_flags[GX_PC_FLAGS_INDEX((gx),(pc))])
47
48 /* GX callbacks */
49 struct tgx_callbacks* callbacks;
50
51 /* compilation statistics */
52 unsigned_4 compile_time; /* time to compile [s] */
53
54 /* ---- LEARNING MODE STATE ---- */
55 unsigned_4 learn_last_change; /* time of last flag change */
56 struct sim_gx_compiled_block* learning_block;
57
58 /* ---- OPTIMIZED MODE STATE ---- */
59 unsigned opt_compile_count; /* number of optimized compile attempts */
60 struct sim_gx_compiled_block* optimized_block;
61 } sim_gx_block;
62
63
64
65
66 typedef struct sim_gx_compiled_block
67 {
68 /* ---- TRANSLATION OBJECTS ---- */
69 char* source_name; /* source file for translated object */
70 char* object_name; /* file name of translated object */
71 char* symbol_name; /* symbol name of function */
72 /* (all above pointers are zalloc()'d buffers, to be zfree()'d. */
73
74 FILE* source_file; /* working file pointer during translation */
75
76 /* ---- LOADED TRANSLATIONS ---- */
77 void* object_dlhandle; /* dlopen() handle to loaded object (if open) */
78 void* function_dlhandle; /* dlsym() pointer to function (if found) */
79 } sim_gx_compiled_block;
80
81
82
83 /* GX block vector: for quick search of translated blocks */
84 typedef struct sim_gx_block_list
85 {
86 /* ---- BLOCK VECTOR ---- */
87 sim_gx_block** gx_blocks; /* vector of GX blocks, sorted by origin field */
88 unsigned gx_blocks_size; /* vector length */
89 unsigned gx_blocks_used; /* number of elements used in vector */
90 address_word gx_first, gx_last; /* first & last addresses translated by any gx block */
91 } sim_gx_block_list;
92
93
94 /* actual gx function pointer type */
95 struct tgx_cpu_regs;
96 typedef int (*sim_gx_function)(struct tgx_cpu_regs* cpu, char* pc_flags, struct tgx_callbacks* callbacks);
97
98
99 /* return values from gx function */
100 #define GX_F_HALT 0
101 #define GX_F_NONPC 1
102 #define GX_F_RANGE 2
103 #define GX_F_YIELD 3
104
105
106 /* Limit on loop cycles within a learning mode gx block */
107 #define GX_LEARN_RUN_LIMIT 10000
108
109 /* Operations */
110 sim_gx_block* sim_gx_block_create(sim_cia cia);
111
112 sim_gx_block* sim_gx_block_find(sim_cia cia);
113 void sim_gx_block_add(sim_gx_block* block);
114 void sim_gx_block_remove(sim_gx_block* block);
115
116 /* State save/restore */
117 void sim_gx_write_block_list();
118 void sim_gx_read_block_list();
119
120 sim_gx_function sim_gx_compiled_block_f(sim_gx_compiled_block* gx);
121 void sim_gx_compiled_block_dispose(sim_gx_compiled_block* gx);
122 void sim_gx_block_translate(sim_gx_block* gx, int optimized);
123
124
125
126 /* Target-specific translation operations */
127
128 int tgx_optimize_test(sim_gx_block* block);
129
130 void tgx_block_ctor(sim_gx_block* block, sim_cia cia);
131 void tgx_block_ctor2(sim_gx_block* block, unsigned_4 origin,
132 unsigned_4 length, unsigned_4 divisor);
133 void tgx_block_dtor(sim_gx_block* block);
134
135 void tgx_emit_pre_function(sim_gx_block* block, int optimized);
136 void tgx_emit_load_block(sim_gx_block* block, int optimized);
137 sim_cia tgx_emit_insn(sim_gx_block* block, sim_cia cia, int optimized);
138 void tgx_emit_save_block(sim_gx_block* block, int optimized);
139 void tgx_emit_post_function(sim_gx_block* block, int optimized);
140
141
142 #endif /* SIM_GX_H */
This page took 0.031732 seconds and 4 git commands to generate.