Home | History | Annotate | Line # | Download | only in mips
micromipsrun.c revision 1.1
      1  1.1  christos /*  Run function for the micromips simulator
      2  1.1  christos 
      3  1.1  christos     Copyright (C) 2005-2016 Free Software Foundation, Inc.
      4  1.1  christos     Contributed by Imagination Technologies, Ltd.
      5  1.1  christos     Written by Andrew Bennett <andrew.bennett (at) imgtec.com>.
      6  1.1  christos 
      7  1.1  christos     This file is part of the MIPS sim.
      8  1.1  christos 
      9  1.1  christos     This program is free software; you can redistribute it and/or modify
     10  1.1  christos     it under the terms of the GNU General Public License as published by
     11  1.1  christos     the Free Software Foundation; either version 3 of the License, or
     12  1.1  christos     (at your option) any later version.
     13  1.1  christos 
     14  1.1  christos     This program is distributed in the hope that it will be useful,
     15  1.1  christos     but WITHOUT ANY WARRANTY; without even the implied warranty of
     16  1.1  christos     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17  1.1  christos     GNU General Public License for more details.
     18  1.1  christos 
     19  1.1  christos     You should have received a copy of the GNU General Public License
     20  1.1  christos     along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     21  1.1  christos 
     22  1.1  christos #include "sim-main.h"
     23  1.1  christos #include "micromips16_idecode.h"
     24  1.1  christos #include "micromips32_idecode.h"
     25  1.1  christos #include "micromips_m32_idecode.h"
     26  1.1  christos #include "bfd.h"
     27  1.1  christos #include "sim-engine.h"
     28  1.1  christos 
     29  1.1  christos /* These definitions come from the *_support.h files generated by igen and are
     30  1.1  christos    required because they are used in some of the macros in the code below.
     31  1.1  christos    Unfortunately we can not just blindly include the *_support.h files to get
     32  1.1  christos    these definitions because some of the defines in these files are specific
     33  1.1  christos    for a particular configuration of the simulator for example instruction word
     34  1.1  christos    size is 16 bits for micromips16 and 32 bits for micromips32.  This means we
     35  1.1  christos    could break future code changes by doing this, so a safer approach is to just
     36  1.1  christos    extract the defines that we need to get this file to compile.  */
     37  1.1  christos #define SD sd
     38  1.1  christos #define CPU cpu
     39  1.1  christos 
     40  1.1  christos address_word
     41  1.1  christos micromips_instruction_decode (SIM_DESC sd, sim_cpu * cpu,
     42  1.1  christos 			      address_word cia,
     43  1.1  christos 			      int instruction_size)
     44  1.1  christos {
     45  1.1  christos   if (instruction_size == MICROMIPS_DELAYSLOT_SIZE_ANY)
     46  1.1  christos     {
     47  1.1  christos       micromips16_instruction_word instruction_0 = IMEM16_MICROMIPS (cia);
     48  1.1  christos       if (MICROMIPS_MINOR_OPCODE (instruction_0) > 0
     49  1.1  christos 	  && MICROMIPS_MINOR_OPCODE (instruction_0) < 4)
     50  1.1  christos 	return micromips16_idecode_issue (sd, instruction_0, cia);
     51  1.1  christos       else
     52  1.1  christos 	{
     53  1.1  christos 	  micromips32_instruction_word instruction_0 = IMEM32_MICROMIPS (cia);
     54  1.1  christos 	  return micromips32_idecode_issue (sd, instruction_0, cia);
     55  1.1  christos 	}
     56  1.1  christos     }
     57  1.1  christos   else if (instruction_size == MICROMIPS_DELAYSLOT_SIZE_16)
     58  1.1  christos     {
     59  1.1  christos       micromips16_instruction_word instruction_0 = IMEM16_MICROMIPS (cia);
     60  1.1  christos       if (MICROMIPS_MINOR_OPCODE (instruction_0) > 0
     61  1.1  christos 	  && MICROMIPS_MINOR_OPCODE (instruction_0) < 4)
     62  1.1  christos 	return micromips16_idecode_issue (sd, instruction_0, cia);
     63  1.1  christos       else
     64  1.1  christos 	sim_engine_abort (sd, cpu, cia,
     65  1.1  christos 			  "Invalid 16 bit micromips instruction");
     66  1.1  christos     }
     67  1.1  christos   else if (instruction_size == MICROMIPS_DELAYSLOT_SIZE_32)
     68  1.1  christos     {
     69  1.1  christos       micromips32_instruction_word instruction_0 = IMEM32_MICROMIPS (cia);
     70  1.1  christos       return micromips32_idecode_issue (sd, instruction_0, cia);
     71  1.1  christos     }
     72  1.1  christos   else
     73  1.1  christos     return NULL_CIA;
     74  1.1  christos }
     75  1.1  christos 
     76  1.1  christos void
     77  1.1  christos sim_engine_run (SIM_DESC sd, int next_cpu_nr, int nr_cpus,
     78  1.1  christos 		int signal)
     79  1.1  christos {
     80  1.1  christos   micromips_m32_instruction_word instruction_0;
     81  1.1  christos   sim_cpu *cpu = STATE_CPU (sd, next_cpu_nr);
     82  1.1  christos   micromips32_instruction_address cia = CPU_PC_GET (cpu);
     83  1.1  christos   sd->isa_mode = ISA_MODE_MIPS32;
     84  1.1  christos 
     85  1.1  christos   while (1)
     86  1.1  christos     {
     87  1.1  christos       micromips32_instruction_address nia;
     88  1.1  christos 
     89  1.1  christos       /* Allow us to switch back from MIPS32 to microMIPS
     90  1.1  christos 	 This covers two cases:
     91  1.1  christos 	 1. Setting the correct isa mode based on the start address
     92  1.1  christos 	 from the elf header.
     93  1.1  christos 	 2. Setting the correct isa mode after a MIPS32 jump or branch
     94  1.1  christos 	 instruction.  */
     95  1.1  christos       if ((sd->isa_mode == ISA_MODE_MIPS32)
     96  1.1  christos 	  && ((cia & 0x1) == ISA_MODE_MICROMIPS))
     97  1.1  christos 	{
     98  1.1  christos 	  sd->isa_mode = ISA_MODE_MICROMIPS;
     99  1.1  christos 	  cia = cia & ~0x1;
    100  1.1  christos 	}
    101  1.1  christos 
    102  1.1  christos #if defined (ENGINE_ISSUE_PREFIX_HOOK)
    103  1.1  christos       ENGINE_ISSUE_PREFIX_HOOK ();
    104  1.1  christos #endif
    105  1.1  christos       switch (sd->isa_mode)
    106  1.1  christos 	{
    107  1.1  christos 	case ISA_MODE_MICROMIPS:
    108  1.1  christos 	  nia =
    109  1.1  christos 	    micromips_instruction_decode (sd, cpu, cia,
    110  1.1  christos 					  MICROMIPS_DELAYSLOT_SIZE_ANY);
    111  1.1  christos 	  break;
    112  1.1  christos 	case ISA_MODE_MIPS32:
    113  1.1  christos 	  instruction_0 = IMEM32 (cia);
    114  1.1  christos 	  nia = micromips_m32_idecode_issue (sd, instruction_0, cia);
    115  1.1  christos 	  break;
    116  1.1  christos 	default:
    117  1.1  christos 	  nia = NULL_CIA;
    118  1.1  christos 	}
    119  1.1  christos 
    120  1.1  christos #if defined (ENGINE_ISSUE_POSTFIX_HOOK)
    121  1.1  christos       ENGINE_ISSUE_POSTFIX_HOOK ();
    122  1.1  christos #endif
    123  1.1  christos 
    124  1.1  christos       /* Update the instruction address */
    125  1.1  christos       cia = nia;
    126  1.1  christos 
    127  1.1  christos       /* process any events */
    128  1.1  christos       if (sim_events_tick (sd))
    129  1.1  christos 	{
    130  1.1  christos 	  CPU_PC_SET (cpu, cia);
    131  1.1  christos 	  sim_events_process (sd);
    132  1.1  christos 	  cia = CPU_PC_GET (cpu);
    133  1.1  christos 	}
    134  1.1  christos     }
    135  1.1  christos }
    136