]>
git.proxmox.com Git - qemu.git/blob - translate.c
4 * Copyright (c) 2003 Fabrice Bellard
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.
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.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "cpu-" TARGET_ARCH ".h"
33 #define DEF(s, n, copy_size) INDEX_op_ ## s,
34 #include "opc-" TARGET_ARCH ".h"
40 #include "op-" TARGET_ARCH ".h"
42 uint16_t gen_opc_buf
[OPC_BUF_SIZE
];
43 uint32_t gen_opparam_buf
[OPPARAM_BUF_SIZE
];
44 uint32_t gen_opc_pc
[OPC_BUF_SIZE
];
45 uint8_t gen_opc_instr_start
[OPC_BUF_SIZE
];
49 static const char *op_str
[] = {
50 #define DEF(s, n, copy_size) #s,
51 #include "opc-" TARGET_ARCH ".h"
55 static uint8_t op_nb_args
[] = {
56 #define DEF(s, n, copy_size) n,
57 #include "opc-" TARGET_ARCH ".h"
61 void dump_ops(const uint16_t *opc_buf
, const uint32_t *opparam_buf
)
63 const uint16_t *opc_ptr
;
64 const uint32_t *opparam_ptr
;
68 opparam_ptr
= opparam_buf
;
72 fprintf(logfile
, "0x%04x: %s",
73 (int)(opc_ptr
- opc_buf
- 1), op_str
[c
]);
74 for(i
= 0; i
< n
; i
++) {
75 fprintf(logfile
, " 0x%x", opparam_ptr
[i
]);
77 fprintf(logfile
, "\n");
78 if (c
== INDEX_op_end
)
86 /* return non zero if the very first instruction is invalid so that
87 the virtual CPU can trigger an exception.
89 '*gen_code_size_ptr' contains the size of the generated code (host
92 int cpu_gen_code(TranslationBlock
*tb
,
93 int max_code_size
, int *gen_code_size_ptr
)
95 uint8_t *gen_code_buf
;
98 if (gen_intermediate_code(tb
, 0) < 0)
101 /* generate machine code */
102 tb
->tb_next_offset
[0] = 0xffff;
103 tb
->tb_next_offset
[1] = 0xffff;
104 gen_code_buf
= tb
->tc_ptr
;
105 gen_code_size
= dyngen_code(gen_code_buf
, tb
->tb_next_offset
,
106 #ifdef USE_DIRECT_JUMP
111 gen_opc_buf
, gen_opparam_buf
);
112 *gen_code_size_ptr
= gen_code_size
;
115 fprintf(logfile
, "OUT: [size=%d]\n", *gen_code_size_ptr
);
116 disas(logfile
, gen_code_buf
, *gen_code_size_ptr
, 1, 0);
117 fprintf(logfile
, "\n");
124 static const unsigned short opc_copy_size
[] = {
125 #define DEF(s, n, copy_size) copy_size,
126 #include "opc-" TARGET_ARCH ".h"
130 /* The simulated PC corresponding to
131 'searched_pc' in the generated code is searched. 0 is returned if
132 found. *found_pc contains the found PC.
134 int cpu_search_pc(TranslationBlock
*tb
,
135 uint32_t *found_pc
, unsigned long searched_pc
)
138 unsigned long tc_ptr
;
141 if (gen_intermediate_code(tb
, 1) < 0)
144 /* find opc index corresponding to search_pc */
145 tc_ptr
= (unsigned long)tb
->tc_ptr
;
146 if (searched_pc
< tc_ptr
)
149 opc_ptr
= gen_opc_buf
;
152 if (c
== INDEX_op_end
)
154 tc_ptr
+= opc_copy_size
[c
];
155 if (searched_pc
< tc_ptr
)
159 j
= opc_ptr
- gen_opc_buf
;
160 /* now find start of instruction before */
161 while (gen_opc_instr_start
[j
] == 0)
163 *found_pc
= gen_opc_pc
[j
];