From ec2a7484481ae6f618bfa28c8657debae0cc72af Mon Sep 17 00:00:00 2001 From: Serge Vakulenko Date: Tue, 27 Oct 2015 22:17:58 -0700 Subject: [PATCH] Virtualmips: implement magic opcodes. --- tools/virtualmips/.gitignore | 3 +- tools/virtualmips/m4k.c | 90 ++++++------------------------ tools/virtualmips/main.c | 2 + tools/virtualmips/mips.h | 1 + tools/virtualmips/mips_codetable.c | 16 +++++- 5 files changed, 38 insertions(+), 74 deletions(-) diff --git a/tools/virtualmips/.gitignore b/tools/virtualmips/.gitignore index cba2dbe..369a0ab 100644 --- a/tools/virtualmips/.gitignore +++ b/tools/virtualmips/.gitignore @@ -1,3 +1,4 @@ .deps pic32 -pic32-log.txt +m4k +*~ diff --git a/tools/virtualmips/m4k.c b/tools/virtualmips/m4k.c index 38cf35a..77daf8a 100644 --- a/tools/virtualmips/m4k.c +++ b/tools/virtualmips/m4k.c @@ -212,77 +212,10 @@ void host_alarm (cpu_mips_t *cpu, int nclocks) //TODO } -/* - * Configuration information. - */ -static char *start_address = "0xbfc00000"; - -static void configure_parameter (void *arg, char *section, char *param, char *value) -{ - m4k_t *m4k = arg; - vm_instance_t *vm = m4k->vm; - - if (strcmp (param, "ram_size") == 0) - vm->ram_size = strtoul (value, 0, 0); - else if (strcmp (param, "gdb_debug") == 0) - vm->gdb_debug = strtoul (value, 0, 0); - else if (strcmp (param, "gdb_port") == 0) - vm->gdb_port = strtoul (value, 0, 0); - else if (strcmp (param, "jit_use") == 0) - vm->jit_use = strtoul (value, 0, 0); - else if (strcmp (param, "debug_level") == 0) - vm->debug_level = strtoul (value, 0, 0); - else if (strcmp (param, "hex_file_name") == 0) - m4k->boot_file_name = strdup (value); - else if (strcmp (param, "start_address") == 0) - start_address = strdup (value); - else { - fprintf (stderr, "%s: unknown parameter `%s'\n", vm->configure_filename, param); - exit (-1); - } - //printf ("Configure: %s = '%s'\n", param, value); -} - -static void m4k_parse_configure (m4k_t *m4k) -{ - vm_instance_t *vm = m4k->vm; - - conf_parse (vm->configure_filename, configure_parameter, m4k); - if (start_address) - m4k->start_address = strtoul (start_address, 0, 0); - - ASSERT(vm->ram_size != 0, "ram_size can not be 0\n"); - - /* Add other configure information validation here */ - if (vm->jit_use) { - ASSERT (JIT_SUPPORT == 1, - "You must compile with JIT Support to use jit.\n"); - } - - const char *output_file_name = "m4k.trace"; - printf ("Redirect output to %s\n", output_file_name); - if (freopen(output_file_name, "w", stdout) != stdout) { - fprintf (stderr, "M4K: Unable to redirect output!\n"); - exit(-1); - } - - /* Print the configure information */ - printf("Using configure file: %s\n", vm->configure_filename); - printf("ram_size: %dk bytes \n", vm->ram_size); - - if (vm->gdb_debug != 0) { - printf("GDB debug enable\n"); - printf("GDB port: %d \n",vm->gdb_port); - } - - /* print other configure information here */ - printf ("start_address: 0x%x\n", m4k->start_address); -} - /* * Create an instance of virtual machine. */ -vm_instance_t *create_instance (char *configure_filename) +vm_instance_t *create_instance (char *filename) { vm_instance_t *vm; m4k_t *m4k; @@ -305,12 +238,22 @@ vm_instance_t *create_instance (char *configure_filename) m4k->vm = vm; /* Initialize default parameters for m4k */ - if (configure_filename == NULL) - configure_filename = "m4k.conf"; - vm->configure_filename = strdup (configure_filename); vm->ram_size = 4*1024; /* kilobytes */ + vm->debug_level = 3; /* trace all instructions */ - m4k_parse_configure (m4k); + m4k->boot_file_name = filename ? filename : "test.hex"; + m4k->start_address = 0xbfc00000; + + const char *output_file_name = "m4k.trace"; + printf ("Redirect output to %s\n", output_file_name); + if (freopen(output_file_name, "w", stdout) != stdout) { + fprintf (stderr, "M4K: Unable to redirect output!\n"); + exit(-1); + } + + /* Print the configure information */ + printf("ram_size: %dk bytes \n", vm->ram_size); + printf("start_address: 0x%x\n", m4k->start_address); /* init gdb debug */ vm_debug_init (m4k->vm); @@ -360,6 +303,9 @@ int init_instance (vm_instance_t * vm) cpu->cp0.tlb_entries = 0; cpu->pc = m4k->start_address; + /* Enable magic opcodes. */ + cpu->magic_opcodes = 1; + /* reset all devices */ dev_reset_all (vm); diff --git a/tools/virtualmips/main.c b/tools/virtualmips/main.c index 7d44f0f..5093880 100644 --- a/tools/virtualmips/main.c +++ b/tools/virtualmips/main.c @@ -73,6 +73,8 @@ int main (int argc, char *argv[]) vtty_init (); /* Create the default instance */ + if (argc > 1) + configure_filename = argv[1]; vm = create_instance (configure_filename); if (!vm) return EXIT_FAILURE; diff --git a/tools/virtualmips/mips.h b/tools/virtualmips/mips.h index 71f5784..61545eb 100644 --- a/tools/virtualmips/mips.h +++ b/tools/virtualmips/mips.h @@ -431,6 +431,7 @@ struct cpu_mips { int is_mips16e; /* 1 if ISA Mode is MIPS16e, 0 if MIPS32 */ int trace_syscall; + int magic_opcodes; /* Current exec page (non-JIT) info */ m_va_t njm_exec_page; diff --git a/tools/virtualmips/mips_codetable.c b/tools/virtualmips/mips_codetable.c index ff56607..2b9da62 100644 --- a/tools/virtualmips/mips_codetable.c +++ b/tools/virtualmips/mips_codetable.c @@ -1389,6 +1389,21 @@ static int sltiu_op (cpu_mips_t * cpu, mips_insn_t insn) int imm = bits (insn, 0, 15); m_reg_t val = sign_extend (imm, 16); + if (rs == 0 && rt == 0 && cpu->magic_opcodes) { + if (imm == 0xabc1) { + printf ("%08x: Test FAIL\n", cpu->pc); + printf ("\n--- Stop simulation\n"); + fprintf (stderr, "Test FAIL\n"); + exit (EXIT_SUCCESS); + } + if (imm == 0xabc2) { + printf ("%08x: Test PASS\n", cpu->pc); + printf ("\n--- Stop simulation\n"); + fprintf (stderr, "Test PASS\n"); + exit (EXIT_SUCCESS); + } + } + if (cpu->gpr[rs] < val) cpu->reg_set (cpu, rt, 1); else @@ -2745,4 +2760,3 @@ lInvalidInstruction: #undef xsregs #undef code6 } -