1
// Copyright (c) 2012- PPSSPP Project.
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
18
#include "Core/MIPS/MIPS.h"
19
#include "Core/MIPS/MIPSTables.h"
20
#include "Core/MIPS/MIPSCodeUtils.h"
21
#include "Core/Host.h"
22
#include "Core/MemMap.h"
24
namespace MIPSCodeUtils
27
#define OP_SYSCALL 0x0000000c
28
#define OP_SYSCALL_MASK 0xFC00003F
29
#define _RS ((op>>21) & 0x1F)
30
#define _RT ((op>>16) & 0x1F)
32
u32 GetJumpTarget(u32 addr)
34
MIPSOpcode op = Memory::Read_Instruction(addr, true);
37
MIPSInfo info = MIPSGetInfo(op);
38
if ((info & IS_JUMP) && (info & IN_IMM26))
40
u32 target = (addr & 0xF0000000) | ((op&0x03FFFFFF) << 2);
50
u32 GetBranchTarget(u32 addr)
52
MIPSOpcode op = Memory::Read_Instruction(addr, true);
55
MIPSInfo info = MIPSGetInfo(op);
56
if (info & IS_CONDBRANCH)
58
return addr + 4 + ((signed short)(op&0xFFFF)<<2);
67
u32 GetBranchTargetNoRA(u32 addr)
69
MIPSOpcode op = Memory::Read_Instruction(addr, true);
70
return GetBranchTargetNoRA(addr, op);
73
u32 GetBranchTargetNoRA(u32 addr, MIPSOpcode op)
77
MIPSInfo info = MIPSGetInfo(op);
78
if ((info & IS_CONDBRANCH) && !(info & OUT_RA))
80
return addr + 4 + ((signed short)(op&0xFFFF)<<2);
89
u32 GetSureBranchTarget(u32 addr)
91
MIPSOpcode op = Memory::Read_Instruction(addr, true);
94
MIPSInfo info = MIPSGetInfo(op);
95
if ((info & IS_CONDBRANCH) && !(info & (IN_FPUFLAG | IS_VFPU)))
99
switch (info & CONDTYPE_MASK)
127
if (sure && takeBranch)
128
return addr + 4 + ((signed short)(op&0xFFFF)<<2);
129
else if (sure && !takeBranch)
132
return INVALIDTARGET;
135
return INVALIDTARGET;
138
return INVALIDTARGET;
141
bool IsVFPUBranch(MIPSOpcode op) {
142
return (MIPSGetInfo(op) & (IS_VFPU | IS_CONDBRANCH)) == (IS_VFPU | IS_CONDBRANCH);
145
bool IsBranch(MIPSOpcode op) {
146
return (MIPSGetInfo(op) & IS_CONDBRANCH) == IS_CONDBRANCH;