CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Core/MIPS/MIPSCodeUtils.cpp
Views: 1401
// Copyright (c) 2012- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#include "Core/MIPS/MIPS.h"18#include "Core/MIPS/MIPSTables.h"19#include "Core/MIPS/MIPSCodeUtils.h"20#include "Core/MemMap.h"2122namespace MIPSCodeUtils23{2425#define OP_SYSCALL 0x0000000c26#define OP_SYSCALL_MASK 0xFC00003F27#define _RS ((op>>21) & 0x1F)28#define _RT ((op>>16) & 0x1F)29#define _IMM26 (op & 0x03FFFFFF)30#define TARGET16 ((int)(SignExtend16ToU32(op) << 2))31#define TARGET26 (_IMM26 << 2)3233u32 GetJumpTarget(u32 addr) {34MIPSOpcode op = Memory::Read_Instruction(addr, true);35if (op != 0) {36MIPSInfo info = MIPSGetInfo(op);37if ((info & IS_JUMP) && (info & IN_IMM26))38return (addr & 0xF0000000) | TARGET26;39else40return INVALIDTARGET;41} else {42return INVALIDTARGET;43}44}4546u32 GetBranchTarget(u32 addr) {47MIPSOpcode op = Memory::Read_Instruction(addr, true);48if (op != 0) {49MIPSInfo info = MIPSGetInfo(op);50if (info & IS_CONDBRANCH)51return addr + 4 + TARGET16;52else53return INVALIDTARGET;54} else {55return INVALIDTARGET;56}57}5859u32 GetBranchTargetNoRA(u32 addr) {60MIPSOpcode op = Memory::Read_Instruction(addr, true);61return GetBranchTargetNoRA(addr, op);62}6364u32 GetBranchTargetNoRA(u32 addr, MIPSOpcode op) {65if (op != 0) {66MIPSInfo info = MIPSGetInfo(op);67if ((info & IS_CONDBRANCH) && !(info & OUT_RA))68return addr + 4 + TARGET16;69else70return INVALIDTARGET;71} else {72return INVALIDTARGET;73}74}7576u32 GetSureBranchTarget(u32 addr) {77MIPSOpcode op = Memory::Read_Instruction(addr, true);78if (op != 0) {79MIPSInfo info = MIPSGetInfo(op);80if ((info & IS_CONDBRANCH) && !(info & (IN_FPUFLAG | IS_VFPU))) {81bool sure;82bool takeBranch;83switch (info & CONDTYPE_MASK)84{85case CONDTYPE_EQ:86sure = _RS == _RT;87takeBranch = true;88break;8990case CONDTYPE_NE:91sure = _RS == _RT;92takeBranch = false;93break;9495case CONDTYPE_LEZ:96case CONDTYPE_GEZ:97sure = _RS == 0;98takeBranch = true;99break;100101case CONDTYPE_LTZ:102case CONDTYPE_GTZ:103sure = _RS == 0;104takeBranch = false;105break;106107default:108sure = false;109}110111if (sure && takeBranch)112return addr + 4 + TARGET16;113else if (sure && !takeBranch)114return addr + 8;115else116return INVALIDTARGET;117} else {118return INVALIDTARGET;119}120} else {121return INVALIDTARGET;122}123}124125bool IsVFPUBranch(MIPSOpcode op) {126return (MIPSGetInfo(op) & (IS_VFPU | IS_CONDBRANCH)) == (IS_VFPU | IS_CONDBRANCH);127}128129bool IsBranch(MIPSOpcode op) {130return (MIPSGetInfo(op) & IS_CONDBRANCH) == IS_CONDBRANCH;131}132133134}135136137