1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  *   Mupen64plus - r4300_core.c                                            *
3  *   Mupen64Plus homepage: http://code.google.com/p/mupen64plus/           *
4  *   Copyright (C) 2014 Bobby Smiles                                       *
5  *                                                                         *
6  *   This program is free software; you can redistribute it and/or modify  *
7  *   it under the terms of the GNU General Public License as published by  *
8  *   the Free Software Foundation; either version 2 of the License, or     *
9  *   (at your option) any later version.                                   *
10  *                                                                         *
11  *   This program is distributed in the hope that it will be useful,       *
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14  *   GNU General Public License for more details.                          *
15  *                                                                         *
16  *   You should have received a copy of the GNU General Public License     *
17  *   along with this program; if not, write to the                         *
18  *   Free Software Foundation, Inc.,                                       *
19  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.          *
20  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
21 
22 #include <string.h>
23 
24 #include "r4300_core.h"
25 
26 #include "cached_interp.h"
27 #include "cp0_private.h"
28 #include "cp1_private.h"
29 #include "mi_controller.h"
30 #include "new_dynarec/new_dynarec.h"
31 #include "r4300.h"
32 #include "recomp.h"
33 
init_r4300(struct r4300_core * r4300,unsigned int emumode,unsigned int count_per_op,int special_rom)34 void init_r4300(struct r4300_core* r4300, unsigned int emumode, unsigned int count_per_op, int special_rom)
35 {
36     r4300emu = emumode;
37 
38     init_cp0(count_per_op);
39 
40 #if 0
41     r4300->recomp.no_compiled_jump = no_compiled_jump;
42 #endif
43     r4300->special_rom = special_rom;
44 }
45 
poweron_r4300(struct r4300_core * r4300)46 void poweron_r4300(struct r4300_core* r4300)
47 {
48    unsigned int i;
49 
50 
51    hi=0;
52    lo=0;
53    llbit=0;
54 
55    r4300->delay_slot = 0;
56 
57    r4300->recomp.fast_memory = 1;
58    r4300->recomp.delay_slot_compiled = 0;
59 
60    /* set COP0 registers */
61    poweron_cp0();
62 
63    /* setup CP1 registers */
64    poweron_cp1();
65 
66    poweron_mi(&r4300->mi);
67 }
68 
r4300_regs(void)69 int64_t* r4300_regs(void)
70 {
71     return reg;
72 }
73 
r4300_mult_hi(void)74 int64_t* r4300_mult_hi(void)
75 {
76     return &hi;
77 }
78 
r4300_mult_lo(void)79 int64_t* r4300_mult_lo(void)
80 {
81     return &lo;
82 }
83 
r4300_llbit(void)84 unsigned int* r4300_llbit(void)
85 {
86     return &llbit;
87 }
88 
r4300_pc(void)89 uint32_t* r4300_pc(void)
90 {
91 #ifdef NEW_DYNAREC
92    if (r4300emu == CORE_DYNAREC)
93       return (uint32_t*)&pcaddr;
94 #endif
95    return &PC->addr;
96 }
97 
r4300_last_addr(void)98 uint32_t* r4300_last_addr(void)
99 {
100     return &last_addr;
101 }
102 
r4300_next_interrupt(void)103 unsigned int* r4300_next_interrupt(void)
104 {
105     return &next_interrupt;
106 }
107 
get_r4300_emumode(void)108 unsigned int get_r4300_emumode(void)
109 {
110     return r4300emu;
111 }
112 
invalidate_r4300_cached_code(uint32_t address,size_t size)113 void invalidate_r4300_cached_code(uint32_t address, size_t size)
114 {
115    if (r4300emu == CORE_PURE_INTERPRETER)
116       return;
117 
118 #ifdef NEW_DYNAREC
119    if (r4300emu == CORE_DYNAREC)
120       invalidate_cached_code_new_dynarec(address, size);
121    else
122 #endif
123       invalidate_cached_code_hacktarux(address, size);
124 }
125 
126 /* XXX: not really a good interface but it gets the job done... */
savestates_load_set_pc(uint32_t pc)127 void savestates_load_set_pc(uint32_t pc)
128 {
129 #ifdef NEW_DYNAREC
130     if (r4300emu == CORE_DYNAREC)
131     {
132         pcaddr = pc;
133         pending_exception = 1;
134         invalidate_all_pages();
135     }
136     else
137 #endif
138     {
139         generic_jump_to(pc);
140         invalidate_r4300_cached_code(0,0);
141     }
142 }
143