1 /* Run function for the micromips simulator
3 Copyright (C) 2005-2018 Free Software Foundation, Inc.
4 Contributed by Imagination Technologies, Ltd.
5 Written by Andrew Bennett <andrew.bennett@imgtec.com>.
7 This file is part of the MIPS sim.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "micromips16_idecode.h"
24 #include "micromips32_idecode.h"
25 #include "micromips_m32_idecode.h"
27 #include "sim-engine.h"
29 /* These definitions come from the *_support.h files generated by igen and are
30 required because they are used in some of the macros in the code below.
31 Unfortunately we can not just blindly include the *_support.h files to get
32 these definitions because some of the defines in these files are specific
33 for a particular configuration of the simulator for example instruction word
34 size is 16 bits for micromips16 and 32 bits for micromips32. This means we
35 could break future code changes by doing this, so a safer approach is to just
36 extract the defines that we need to get this file to compile. */
41 micromips_instruction_decode (SIM_DESC sd
, sim_cpu
* cpu
,
45 if (instruction_size
== MICROMIPS_DELAYSLOT_SIZE_ANY
)
47 micromips16_instruction_word instruction_0
= IMEM16_MICROMIPS (cia
);
48 if (MICROMIPS_MINOR_OPCODE (instruction_0
) > 0
49 && MICROMIPS_MINOR_OPCODE (instruction_0
) < 4)
50 return micromips16_idecode_issue (sd
, instruction_0
, cia
);
53 micromips32_instruction_word instruction_0
= IMEM32_MICROMIPS (cia
);
54 return micromips32_idecode_issue (sd
, instruction_0
, cia
);
57 else if (instruction_size
== MICROMIPS_DELAYSLOT_SIZE_16
)
59 micromips16_instruction_word instruction_0
= IMEM16_MICROMIPS (cia
);
60 if (MICROMIPS_MINOR_OPCODE (instruction_0
) > 0
61 && MICROMIPS_MINOR_OPCODE (instruction_0
) < 4)
62 return micromips16_idecode_issue (sd
, instruction_0
, cia
);
64 sim_engine_abort (sd
, cpu
, cia
,
65 "Invalid 16 bit micromips instruction");
67 else if (instruction_size
== MICROMIPS_DELAYSLOT_SIZE_32
)
69 micromips32_instruction_word instruction_0
= IMEM32_MICROMIPS (cia
);
70 return micromips32_idecode_issue (sd
, instruction_0
, cia
);
77 sim_engine_run (SIM_DESC sd
, int next_cpu_nr
, int nr_cpus
,
80 micromips_m32_instruction_word instruction_0
;
81 sim_cpu
*cpu
= STATE_CPU (sd
, next_cpu_nr
);
82 micromips32_instruction_address cia
= CPU_PC_GET (cpu
);
83 sd
->isa_mode
= ISA_MODE_MIPS32
;
87 micromips32_instruction_address nia
;
89 /* Allow us to switch back from MIPS32 to microMIPS
90 This covers two cases:
91 1. Setting the correct isa mode based on the start address
93 2. Setting the correct isa mode after a MIPS32 jump or branch
95 if ((sd
->isa_mode
== ISA_MODE_MIPS32
)
96 && ((cia
& 0x1) == ISA_MODE_MICROMIPS
))
98 sd
->isa_mode
= ISA_MODE_MICROMIPS
;
102 #if defined (ENGINE_ISSUE_PREFIX_HOOK)
103 ENGINE_ISSUE_PREFIX_HOOK ();
105 switch (sd
->isa_mode
)
107 case ISA_MODE_MICROMIPS
:
109 micromips_instruction_decode (sd
, cpu
, cia
,
110 MICROMIPS_DELAYSLOT_SIZE_ANY
);
112 case ISA_MODE_MIPS32
:
113 instruction_0
= IMEM32 (cia
);
114 nia
= micromips_m32_idecode_issue (sd
, instruction_0
, cia
);
120 #if defined (ENGINE_ISSUE_POSTFIX_HOOK)
121 ENGINE_ISSUE_POSTFIX_HOOK ();
124 /* Update the instruction address */
127 /* process any events */
128 if (sim_events_tick (sd
))
130 CPU_PC_SET (cpu
, cia
);
131 sim_events_process (sd
);
132 cia
= CPU_PC_GET (cpu
);