Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 54 additions & 33 deletions linux-user/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,30 +381,11 @@ static void handle_arg_latx_unlink(const char *arg)
options_parse_latx_unlink(arg);
}

static void handle_arg_latx_em_debug(const char *arg)
{
option_em_debug = 1;
}

static void handle_arg_latx_trace(const char *arg)
{
options_parse_trace(arg);
}

static void handle_arg_latx_check(const char *arg)
{
option_check = 1;
}

static void handle_arg_latx_tb_dump(const char *arg)
{
option_dump_all_tb = 1;
}

static void handle_arg_latx_disassemble_trace_cmp(const char *arg)
{
options_parse_latx_disassemble_trace_cmp(arg);
}

#endif

Expand Down Expand Up @@ -810,7 +791,7 @@ struct qemu_argument {

static const struct qemu_argument arg_table[] = {
#ifdef CONFIG_LATX
{"latx-optimize", "LAT_OPTIMIZE", false, handle_arg_optimize,
{"latx-optimize", "LATX_OPTIMIZE", false, handle_arg_optimize,
"", "specify enabled optimize type"},
{"latx-smc", "LATX_SMC", true, handle_arg_latx_smc,
"", "smc strategy: 0 (page) 1 (tb) 2(+shmm) 6(+helper,default)"},
Expand Down Expand Up @@ -889,17 +870,8 @@ static const struct qemu_argument arg_table[] = {
"", "enable all exception bit in fcsr"},
{"latx-unlink", "LATX_UNLINK", true, handle_arg_latx_unlink,
"", "unlink_count[,cpu_index]"},
{"latx-em-debug", "", false, handle_arg_latx_em_debug,
"", ""},
{"latx-trace", "", true, handle_arg_latx_trace,
"bitmap", "LATX-trace-TB-execution: 2 bits each for TB,ir1,ir2"},
{"latx-check", "", false, handle_arg_latx_check,
"", "LATX-enable-check"},
{"latx-tb-dump", "", false, handle_arg_latx_tb_dump,
"", "LATX dump all the run times of all TB"},
{"latx-disassemble-trace-cmp", "LATX_DISASSEMBLE_TRACE_CMP",
true, handle_arg_latx_disassemble_trace_cmp,
"", "LATX Compare different disassemble."},
#endif
{"h", "", false, handle_arg_help,
"", "print this help"},
Expand Down Expand Up @@ -1033,12 +1005,36 @@ static void usage(int exitcode)
}
#endif

static int parse_args(int argc, char **argv)
struct ParseOption {
const char *opt_name;
const char *opt_arg;
};

static struct ParseOption parse_options[128];
static int arg_count = 0;

void find_option(const char* key, const char* val)
{
#define ENVFUN(NAME, name) \
else if (!strcmp(key, #NAME)) { \
name(val); \
}
if (0);
ENVS
else {
printf("no option %s\n", key);
}
}

static void options_set(void)
{
/* set latx.conf */
conf_init(exec_path);

const char *r;
int optind;
const struct qemu_argument *arginfo;

/* set env */
for (arginfo = arg_table; arginfo->handle_opt != NULL; arginfo++) {
if (arginfo->env == NULL) {
continue;
Expand All @@ -1050,6 +1046,27 @@ static int parse_args(int argc, char **argv)
}
}

/* set argv */
for (int i = 0; i < arg_count; i++) {
for (arginfo = arg_table; arginfo->handle_opt != NULL; arginfo++) {
if (!strcmp(parse_options[i].opt_name, arginfo->argv)) {
if (arginfo->has_arg) {
arginfo->handle_opt(parse_options[i].opt_arg);
} else {
arginfo->handle_opt(NULL);
}
break;
}
}
}
}

static int parse_args(int argc, char **argv)
{
const char *r;
int optind;
const struct qemu_argument *arginfo;

optind = 1;
for (;;) {
if (optind >= argc) {
Expand Down Expand Up @@ -1077,11 +1094,14 @@ static int parse_args(int argc, char **argv)
"missing argument for option '%s'\n", r);
exit(EXIT_FAILURE);
}
arginfo->handle_opt(argv[optind]);
parse_options[arg_count].opt_name = arginfo->argv;
parse_options[arg_count].opt_arg = argv[optind];
optind++;
} else {
arginfo->handle_opt(NULL);
parse_options[arg_count].opt_name = arginfo->argv;
parse_options[arg_count].opt_arg = NULL;
}
arg_count++;
break;
}
}
Expand Down Expand Up @@ -1151,6 +1171,7 @@ int main(int argc, char **argv, char **envp)
}

optind = parse_args(argc, argv);
options_set();

error_init(argv[0]);
module_call_init(MODULE_INIT_TRACE);
Expand Down
125 changes: 121 additions & 4 deletions target/i386/latx/include/latx-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "latx-disassemble-trace.h"
#include "latx-debug.h"

extern int option_em_debug;
#ifdef CONFIG_LATX_INSTS_PATTERN
extern int option_instptn;
#endif
Expand All @@ -29,10 +28,7 @@ extern int option_dump_ir2;
extern int option_dump_profile;
extern int option_trace_tb;
extern int option_trace_ir1;
extern int option_check;
extern int option_enable_fcsr_exc;
extern int option_dump_all_tb;
extern int option_latx_disassemble_trace_cmp;
extern int option_jr_ra;
#define SMC_ILL_INST 0x1
/* ld.w $a1,$zero,0 */
Expand Down Expand Up @@ -92,6 +88,121 @@ extern unsigned long long counter_tb_tr;
extern unsigned long long counter_ir1_tr;
extern unsigned long long counter_mips_tr;

#ifdef CONFIG_LATX
#define ENVSUP_LATX \
ENVFUN(LATX_OPTIMIZE, handle_arg_optimize) \
ENVFUN(LATX_SMC, handle_arg_latx_smc) \
ENVFUN(LATX_CLOSE_PARALLEL, handle_arg_latx_parallel) \
ENVFUN(LATX_SOFTFPU, handle_arg_latx_softfpu) \
ENVFUN(LATX_SOFTFPU_FAST, handle_arg_latx_softfpu_fast) \
ENVFUN(LATX_PRLIMIT, handle_arg_latx_prlimit) \
ENVFUN(LATX_ROUNDING_OPT, handle_arg_latx_rounding) \
ENVFUN(LATX_CVT_OPT, handle_arg_latx_cvt_opt) \
ENVFUN(LATX_FPUTAG, handle_arg_latx_fputag) \
ENVFUN(SAVE_XMM, handle_arg_save_xmm) \
ENVFUN(LATX_JRRA, handle_arg_latx_jrra) \
ENVFUN(LATX_IMM_REG, handle_arg_latx_imm_reg) \
ENVFUN(LATX_MT, handle_arg_latx_mem_test) \
ENVFUN(LATX_REAL_MAPS, handle_arg_latx_real_maps) \
ENVFUN(LATX_MONITOR_SHARED_MEM, handle_arg_latx_monitor_shared_mem) \
ENVFUN(LATX_ANONYM, handle_arg_latx_anonym) \
ENVFUN(LATX_MMAP_START, handle_arg_mmap_start) \
ENVFUN(LATX_MMAP_FIXED, handle_arg_mmap_fixed) \
ENVFUN(LATX_UNIMP_DUMP, handle_arg_latx_unimp_dump)
#else
#define ENVSUP_LATX
#endif

#if defined(CONFIG_LATX) && defined(CONFIG_LATX_AVX_OPT)
#define ENVSUP_AVX \
ENVFUN(LATX_AVX_CPUID, handle_arg_latx_avx_cpuid)
#else
#define ENVSUP_AVX
#endif

#if defined(CONFIG_LATX) && defined(CONFIG_LATX_KZT)
#define ENVSUP_KZT \
ENVFUN(LATX_KZT, handle_arg_latx_kzt)
#else
#define ENVSUP_KZT
#endif

#if defined(CONFIG_LATX) && defined(CONFIG_LATX_AOT)
#define ENVSUP_AOT \
ENVFUN(LATX_AOT, handle_arg_latx_aot) \
ENVFUN(LAT_AOT_FILE_SIZE, handle_arg_lat_aot_file_size) \
ENVFUN(LAT_AOT_LEFT_FILE_SIZE, handle_arg_lat_aot_left_file_size) \
ENVFUN(LATX_AOT_WINE_PEFILES_CACHE, handle_arg_latx_aot_wine_pefiles_cache)
#else
#define ENVSUP_AOT
#endif

#if defined(CONFIG_LATX_DEBUG) || defined(CONFIG_DEBUG_TCG)
#define ENVSUP_DEBUG \
ENVFUN(LAT_GDB, handle_arg_gdb) \
ENVFUN(LAT_STACK_SIZE, handle_arg_stack_size) \
ENVFUN(LAT_CPU, handle_arg_cpu) \
ENVFUN(LAT_SET_ENV, handle_arg_set_env) \
ENVFUN(LAT_UNSET_ENV, handle_arg_unset_env) \
ENVFUN(LAT_ARGV0, handle_arg_argv0) \
ENVFUN(LAT_UNAME, handle_arg_uname) \
ENVFUN(LAT_GUEST_BASE, handle_arg_guest_base) \
ENVFUN(LAT_RESERVED_VA, handle_arg_reserved_va) \
ENVFUN(LAT_LOG, handle_arg_log) \
ENVFUN(LAT_IMM_SKIP_PC, handle_arg_imm_skip_pc) \
ENVFUN(LAT_DFILTER, handle_arg_dfilter) \
ENVFUN(LAT_LOG_FILENAME, handle_arg_log_filename) \
ENVFUN(LAT_PAGESIZE, handle_arg_pagesize) \
ENVFUN(LAT_SINGLESTEP, handle_arg_singlestep) \
ENVFUN(LAT_STRACE, handle_arg_strace) \
ENVFUN(LAT_STRACE_ERROR, handle_arg_strace_error) \
ENVFUN(LAT_RAND_SEED, handle_arg_seed) \
ENVFUN(LAT_TRACE, handle_arg_trace) \
ENVFUN(LAT_LD_PREFIX, handle_arg_ld_prefix) \
ENVFUN(LAT_VERSION, handle_arg_version)
#else
#define ENVSUP_DEBUG
#endif

#if (defined(CONFIG_LATX_DEBUG) || defined(CONFIG_DEBUG_TCG)) && defined(CONFIG_LATX)
#define ENVSUP_LATX_DEBUG \
ENVFUN(LATX_BEGIN_TRACE, handle_range_trace_begin) \
ENVFUN(LATX_END_TRACE, handle_range_trace_end) \
ENVFUN(LATX_DUMP, handle_arg_latx_print) \
ENVFUN(LATX_SHOW_TB, handle_arg_latx_show_tb) \
ENVFUN(LATX_TRACE_MEM, handle_arg_latx_trace_mem) \
ENVFUN(LATX_BREAK_INSN, handle_arg_latx_break_insn) \
ENVFUN(LATX_DEBUG_LATIVE, handle_arg_debug_lative) \
ENVFUN(LATX_ENABLE_FCSR_EXC, handle_arg_enable_fcsr_exc) \
ENVFUN(LATX_UNLINK, handle_arg_latx_unlink)
#else
#define ENVSUP_LATX_DEBUG
#endif

#if (defined(CONFIG_LATX_DEBUG) || defined(CONFIG_DEBUG_TCG)) && defined(CONFIG_PLUGIN)
#define ENVSUP_PLUGIN \
ENVFUN(LAT_PLUGIN, handle_arg_plugin)
#else
#define ENVSUP_PLUGIN
#endif

#if defined(TARGET_XTENSA)
#define ENVSUP_XTENSA \
ENVFUN(QEMU_XTENSA_ABI_CALL0, handle_arg_abi_call0)
#else
#define ENVSUP_XTENSA
#endif

#define ENVS \
ENVSUP_LATX \
ENVSUP_AVX \
ENVSUP_KZT \
ENVSUP_AOT \
ENVSUP_DEBUG \
ENVSUP_LATX_DEBUG \
ENVSUP_PLUGIN \
ENVSUP_XTENSA

void options_init(void);
void options_parse_opt(const char *opt);
void options_parse_imm_reg(const char *bits);
Expand All @@ -104,4 +215,10 @@ void options_parse_latx_unlink(const char *arg);
void options_parse_trace(const char *bits);
uint8 options_to_save(void);
void options_parse_latx_disassemble_trace_cmp(const char *args);
void conf_init(const char *program);
void load_conf_file(const char *file, const char* program);
char* trim_name(const char *program);
void find_option(const char *name, const char *val);
int option_line_init(char *line, char **name, char **value);
char* trim(char *s);
#endif
4 changes: 0 additions & 4 deletions target/i386/latx/latx-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,15 +504,11 @@ void latx_guest_stack_init(CPUArchState *env)
#endif
void latx_dt_init(void)
{
#ifdef CONFIG_LATX_DEBUG
disassemble_trace_init(TARGET_ABI_BITS, option_latx_disassemble_trace_cmp);
#else
#ifdef CONFIG_LATX_CAPSTONE_GIT
gitcapstone_init(TARGET_ABI_BITS);
#else
lacapstone_init(TARGET_ABI_BITS);
#endif
#endif
}

void latx_init_fpu_regs(CPUArchState *env)
Expand Down
46 changes: 0 additions & 46 deletions target/i386/latx/latx-disassemble-trace/latx-disassemble-trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,52 +7,6 @@ int (*la_disa_v2)(const uint8_t *code, size_t code_size,
uint64_t address,
size_t count, struct la_dt_insn **insn,
int ir1_num, void *pir1_base, int mode) = NULL;
void disassemble_trace_init(int abi_bits, int args)
{
dt_mode = abi_bits;
switch (args & 0xffff) {
case 0:
break;
case OPT_V1NEXTCAPSTONE:
la_disa_v1 = &gitcapstone_get;
break;
case OPT_V1LACAPSTONE:
la_disa_v1 = &gitcapstone_get;
break;
case OPT_V1LAXED:
la_disa_v1 = &laxed_get;
break;
case OPT_V1LAZYDIS:
la_disa_v1 = &lazydis_get;
break;
default:
lsassertm(0, "invalid V1.");
}
switch (args & 0xffff0000) {
case 0:
break;
case OPT_V2LACAPSTONE:
la_disa_v2 = &gitcapstone_get;
break;
case OPT_V2NEXTCAPSTONE:
la_disa_v2 = &gitcapstone_get;
break;
case OPT_V2LAXED:
la_disa_v2 = &laxed_get;
break;
case OPT_V2LAZYDIS:
la_disa_v2 = &lazydis_get;
break;
default:
dtassert(0);
}
if (la_disa_v2) {
disassemble_trace_cmp = &disassemble_trace_loop;
}
gitcapstone_init(abi_bits);
laxed_init(abi_bits);
lazydis_init(abi_bits);
}
static int64_t imm_cast(int64_t imm, uint32_t size)
{
switch (size) {
Expand Down
Loading