2015-08-21 07:04:50 +00:00
|
|
|
#ifndef UNICORN_COMMON_H_
|
|
|
|
#define UNICORN_COMMON_H_
|
|
|
|
|
|
|
|
#include "tcg.h"
|
|
|
|
|
|
|
|
// This header define common patterns/codes that will be included in all arch-sepcific
|
|
|
|
// codes for unicorns purposes.
|
|
|
|
|
|
|
|
// return true on success, false on failure
|
|
|
|
static inline bool cpu_physical_mem_read(AddressSpace *as, hwaddr addr,
|
|
|
|
uint8_t *buf, int len)
|
|
|
|
{
|
2018-09-03 14:40:10 +00:00
|
|
|
return cpu_physical_memory_rw(as, addr, (void *)buf, len, 0);
|
2015-08-21 07:04:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool cpu_physical_mem_write(AddressSpace *as, hwaddr addr,
|
2015-08-24 15:02:14 +00:00
|
|
|
const uint8_t *buf, int len)
|
2015-08-21 07:04:50 +00:00
|
|
|
{
|
2018-09-03 14:40:10 +00:00
|
|
|
return cpu_physical_memory_rw(as, addr, (void *)buf, len, 1);
|
2015-08-21 07:04:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tb_cleanup(struct uc_struct *uc);
|
2016-07-11 15:13:13 +00:00
|
|
|
void free_code_gen_buffer(struct uc_struct *uc);
|
2015-08-21 07:04:50 +00:00
|
|
|
|
2018-03-11 23:54:46 +00:00
|
|
|
static inline void free_address_spaces(struct uc_struct *uc)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
address_space_destroy(&uc->as);
|
|
|
|
for (i = 0; i < uc->cpu->num_ases; i++) {
|
|
|
|
AddressSpace *as = uc->cpu->cpu_ases[i].as;
|
|
|
|
address_space_destroy(as);
|
|
|
|
g_free(as);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is *supposed* to be done by the class finalizer but it never executes */
|
|
|
|
static inline void free_machine_class_name(struct uc_struct *uc) {
|
|
|
|
MachineClass *mc = MACHINE_GET_CLASS(uc, uc->machine_state);
|
|
|
|
|
|
|
|
g_free(mc->name);
|
|
|
|
mc->name = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void free_tcg_temp_names(TCGContext *s)
|
|
|
|
{
|
|
|
|
#if TCG_TARGET_REG_BITS == 32
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < s->nb_globals; i++) {
|
|
|
|
TCGTemp *ts = &s->temps[i];
|
|
|
|
if (ts->base_type == TCG_TYPE_I64) {
|
|
|
|
if (ts->name && ((strcmp(ts->name+(strlen(ts->name)-2), "_0") == 0) ||
|
|
|
|
(strcmp(ts->name+(strlen(ts->name)-2), "_1") == 0))) {
|
|
|
|
free((void *)ts->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-08-21 07:04:50 +00:00
|
|
|
/** Freeing common resources */
|
|
|
|
static void release_common(void *t)
|
|
|
|
{
|
2017-01-19 11:50:28 +00:00
|
|
|
TCGPool *po, *to;
|
2015-08-21 07:04:50 +00:00
|
|
|
TCGContext *s = (TCGContext *)t;
|
|
|
|
|
|
|
|
// Clean TCG.
|
|
|
|
TCGOpDef* def = &s->tcg_op_defs[0];
|
2016-12-21 14:28:36 +00:00
|
|
|
g_free(def->args_ct);
|
|
|
|
g_free(s->tcg_op_defs);
|
2016-01-31 22:22:20 +00:00
|
|
|
|
2015-08-21 07:04:50 +00:00
|
|
|
for (po = s->pool_first; po; po = to) {
|
|
|
|
to = po->next;
|
2016-12-21 14:28:36 +00:00
|
|
|
g_free(po);
|
2015-08-21 07:04:50 +00:00
|
|
|
}
|
|
|
|
tcg_pool_reset(s);
|
|
|
|
g_hash_table_destroy(s->helpers);
|
|
|
|
|
2018-03-12 01:48:48 +00:00
|
|
|
// Destory flat view hash table
|
|
|
|
g_hash_table_destroy(s->uc->flat_views);
|
2018-03-12 02:23:21 +00:00
|
|
|
unicorn_free_empty_flat_view(s->uc);
|
2018-03-12 01:48:48 +00:00
|
|
|
|
2016-07-08 16:16:23 +00:00
|
|
|
// TODO(danghvu): these function is not available outside qemu
|
|
|
|
// so we keep them here instead of outside uc_close.
|
2018-03-11 23:54:46 +00:00
|
|
|
free_address_spaces(s->uc);
|
2016-07-08 16:16:23 +00:00
|
|
|
memory_free(s->uc);
|
2016-07-08 17:49:43 +00:00
|
|
|
tb_cleanup(s->uc);
|
2016-07-11 15:13:13 +00:00
|
|
|
free_code_gen_buffer(s->uc);
|
2018-03-11 23:54:46 +00:00
|
|
|
free_machine_class_name(s->uc);
|
|
|
|
free_tcg_temp_names(s);
|
2015-08-21 07:04:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void uc_common_init(struct uc_struct* uc)
|
|
|
|
{
|
|
|
|
memory_register_types(uc);
|
|
|
|
uc->write_mem = cpu_physical_mem_write;
|
|
|
|
uc->read_mem = cpu_physical_mem_read;
|
|
|
|
uc->tcg_enabled = tcg_enabled;
|
|
|
|
uc->tcg_exec_init = tcg_exec_init;
|
|
|
|
uc->cpu_exec_init_all = cpu_exec_init_all;
|
2018-03-21 11:57:39 +00:00
|
|
|
uc->cpu_exec_exit = cpu_exec_exit;
|
2015-08-21 07:04:50 +00:00
|
|
|
uc->vm_start = vm_start;
|
|
|
|
uc->memory_map = memory_map;
|
2015-11-28 01:25:53 +00:00
|
|
|
uc->memory_map_ptr = memory_map_ptr;
|
2015-08-30 04:17:30 +00:00
|
|
|
uc->memory_unmap = memory_unmap;
|
2015-08-26 20:29:54 +00:00
|
|
|
uc->readonly_mem = memory_region_set_readonly;
|
2015-08-21 07:04:50 +00:00
|
|
|
|
2015-08-31 08:00:44 +00:00
|
|
|
uc->target_page_size = TARGET_PAGE_SIZE;
|
2015-09-03 10:16:49 +00:00
|
|
|
uc->target_page_align = TARGET_PAGE_SIZE - 1;
|
2015-08-31 08:00:44 +00:00
|
|
|
|
2018-03-11 23:54:46 +00:00
|
|
|
if (!uc->release) {
|
2015-08-21 07:04:50 +00:00
|
|
|
uc->release = release_common;
|
2018-03-11 23:54:46 +00:00
|
|
|
}
|
2015-08-21 07:04:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|