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/MIPSAnalyst.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 "ppsspp_config.h"18#include <algorithm>19#include <map>20#include <set>21#include <unordered_map>22#include <unordered_set>23#include <mutex>2425#include "ext/cityhash/city.h"26#include "ext/xxhash.h"2728#include "Common/File/FileUtil.h"29#include "Common/Log.h"30#include "Common/StringUtils.h"31#include "Common/TimeUtil.h"32#include "Core/Config.h"33#include "Core/MemMap.h"34#include "Core/System.h"35#include "Core/MIPS/MIPS.h"36#include "Core/MIPS/MIPSVFPUUtils.h"37#include "Core/MIPS/MIPSTables.h"38#include "Core/MIPS/MIPSAnalyst.h"39#include "Core/MIPS/MIPSCodeUtils.h"40#include "Core/Debugger/SymbolMap.h"41#include "Core/Debugger/DebugInterface.h"42#include "Core/HLE/ReplaceTables.h"4344using namespace MIPSCodeUtils;4546// Not in a namespace because MSVC's debugger doesn't like it47typedef std::vector<MIPSAnalyst::AnalyzedFunction> FunctionsVector;48static FunctionsVector functions;49std::recursive_mutex functions_lock;5051// One function can appear in multiple copies in memory, and they will all have52// the same hash and should all be replaced if possible.53static std::unordered_multimap<u64, MIPSAnalyst::AnalyzedFunction *> hashToFunction;5455struct HashMapFunc {56char name[64];57u64 hash;58u32 size; //number of bytes59bool hardcoded; // should not be saved6061bool operator < (const HashMapFunc &other) const {62return hash < other.hash || (hash == other.hash && size < other.size);63}6465bool operator == (const HashMapFunc &other) const {66return hash == other.hash && size == other.size;67}68};6970namespace std {71template <>72struct hash<HashMapFunc> {73size_t operator()(const HashMapFunc &f) const {74return std::hash<u64>()(f.hash) ^ f.size;75}76};77}7879static std::unordered_set<HashMapFunc> hashMap;8081static Path hashmapFileName;8283#define MIPSTABLE_IMM_MASK 0xFC0000008485// Similar to HashMapFunc but has a char pointer for the name for efficiency.86struct HardHashTableEntry {87uint64_t hash;88int funcSize;89const char *funcName;9091bool operator <(const HardHashTableEntry &e) const {92if (hash < e.hash) return true;93if (hash > e.hash) return false;94return funcSize < e.funcSize;95}96};9798// Some hardcoded hashes. Some have a comment specifying at least one game they are found in.99static const HardHashTableEntry hardcodedHashes[] = {100{ 0x006b570008068310, 184, "strtok_r", },101{ 0x019ba2099fb88f3c, 48, "vector_normalize_t", },102{ 0x0266f96d740c7e03, 912, "memcpy", }, // Final Fantasy 4 (US)103{ 0x02bd2859045d2383, 240, "bcmp", },104{ 0x030507c9a1f0fc85, 92, "sceVfpuMatrix4RotX", },105{ 0x0483fceefa4557ff, 1360, "__udivdi3", },106{ 0x0558ad5c5be00ca1, 76, "vtfm_t", },107{ 0x05aceb23092fd6a1, 36, "zettai_hero_update_minimap_tex", }, // Zettai Hero Project (US)108{ 0x05aedd0c04b451a1, 356, "sqrt", },109{ 0x0654fc8adbe16ef7, 28, "vmul_q", },110{ 0x06628f6052cda3c1, 1776, "toheart2_download_frame", }, // To Heart 2 Portable111{ 0x06b243c926fa6ab5, 24, "vf2in_q", },112{ 0x06e2826e02056114, 56, "wcslen", },113{ 0x073cf0b61d3b875a, 416, "hexyzforce_monoclome_thread", }, // Hexyz Force (US)114{ 0x075fa9b234b41e9b, 32, "fmodf", },115{ 0x0a051019bdd786c3, 184, "strcasecmp", },116{ 0x0a1bed70958935d2, 644, "youkosohitsujimura_download_frame", }, // Youkoso Hitsuji-Mura Portable117{ 0x0a46dc426054bb9d, 24, "vector_add_t", },118{ 0x0c0173ed70f84f66, 48, "vnormalize_t", },119{ 0x0c65188f5bfb3915, 24, "vsgn_q", },120{ 0x0d898513a722ea3c, 40, "copysignf", },121{ 0x0e99b037b852c8ea, 68, "isnan", },122// Unsafe due to immediates.123//{ 0x0eb5f2e95f59276a, 40, "dl_write_lightmode", },124{ 0x0f1e7533a546f6a1, 228, "dl_write_bone_matrix_4", },125{ 0x0f2a1106ad84fb74, 52, "strcmp", },126{ 0x0ffa5db8396d4274, 64, "memcpy_jak", }, // CRUSH127{ 0x1252e902d0b49bfb, 44, "vector_sub_q_2", },128{ 0x12df3d33a58d0298, 52, "sceVfpuMatrix3Unit", },129{ 0x12feef7b017d3431, 700, "memmove", },130{ 0x1322c7e3fe6dff4d, 784, "_free_r", },131{ 0x1376c115d5f1d90c, 36, "strlen", },132{ 0x1448134dd3acd1f9, 240, "memchr", },133{ 0x14800e59c04968d7, 100, "wcsstr", },134{ 0x14b56e858a27a8a4, 24, "vi2f_q", },135{ 0x15c4662d5d3c728e, 308, "acosf", },136{ 0x1616ee7052542059, 48, "vtfm_t", },137{ 0x16965ca11a4e7dac, 104, "vmmul_q_transp", },138{ 0x16afe830a5dd2de2, 40, "vdiv_q", },139{ 0x184e834a63a79016, 32, "isnanf", },140{ 0x1874ee898c7b9f16, 512, "kokoroconnect_download_frame", }, // Kokoro Connect Yochi Random141{ 0x189212bda9c94df1, 736, "atanf", },142{ 0x199821ce500ef9d2, 24, "vocp_t", },143{ 0x1a3c8e9d637ed421, 104, "__adddf3", },144{ 0x1a7564fa3e25c992, 844, "memcpy", }, // Valkyria Chronicles 3145{ 0x1aad94c0723edfc0, 124, "sceVfpuMatrix3Mul", },146{ 0x1ab33b12b3cb8cb0, 28, "vqmul_q", },147{ 0x1ac05627df1f87f4, 112, "memcpy16", }, // Valkyria Chronicles 3148{ 0x1bdf3600844373fd, 112, "strstr", },149{ 0x1c967be07917ddc9, 92, "strcat", },150{ 0x1d03fa48334ca966, 556, "_strtol_r", },151{ 0x1d1311966d2243e9, 428, "suikoden1_and_2_download_frame_1", }, // Gensou Suikoden 1&2152{ 0x1d7de04b4e87d00b, 680, "kankabanchoutbr_download_frame", }, // Kenka Banchou Bros: Tokyo Battle Royale153{ 0x1daf6eaf0442391d, 1024, "utawarerumono_download_frame", }, // Utawarerumono portable154{ 0x1e1525e3bc2f6703, 676, "rint", },155{ 0x1ec055f28bb9f4d1, 88, "_sceGuUpdateStallAddr", },156{ 0x1ef9cfe6afd3c035, 180, "memset", }, // Kingdom Hearts (US)157{ 0x1f53eac122f96b37, 224, "cosf", },158{ 0x2097a8b75c8fe651, 436, "atan2", },159{ 0x21411b3c860822c0, 36, "matrix_scale_q_t", },160{ 0x2161ea81a06bcacd, 1032, "soltrigger_render_ucschar", }, // Sol Trigger161{ 0x24d82a8675800808, 220, "ceilf", },162{ 0x26cc90cb25af9d27, 476, "log10", },163{ 0x275c79791a2bab83, 116, "rezel_cross_download_frame", }, // Rezel Cross164{ 0x2774614d57d4baa2, 28, "vsub_q", },165{ 0x279c6bf9cf99cc85, 436, "strncpy", },166{ 0x2876ed93c5fd1211, 328, "dl_write_matrix_4", },167{ 0x2965b1ad3ca15cc1, 44, "vtfm_t", },168{ 0x299a370587df078f, 116, "strange_copy_routine", },169{ 0x2aa9634a9951c7df, 212, "sdgundamggenerationportable_download_frame", }, // SD Gundam G Generation Portable170{ 0x2abca53599f09ea7, 608, "dl_write_matrix_3", },171{ 0x2adb92e8855c454e, 48, "vtfm_q", },172{ 0x2adc229bef7bbc75, 40, "isnan", },173{ 0x2bcf5268dd26345a, 340, "acos", },174{ 0x2c4cb2028a1735bf, 600, "floor", },175{ 0x2c61a9a06a345b43, 1084, "otomenoheihou_download_frame", }, // Sangoku Koi Senki Otome no Heihou176{ 0x2ca5958bb816c72e, 44, "sceVfpuVector3FromIVector", },177{ 0x2e7022d9767c9018, 2100, "atan", },178{ 0x2f10d3faec84b5bb, 276, "sinf", },179{ 0x2f639673670caa0e, 772, "sceGupSetMatrix", },180{ 0x2f718936b371fc44, 40, "sceVfpuScalarCos", },181{ 0x3024e961d1811dea, 396, "fmod", },182{ 0x3050bfd0e729dfbf, 220, "atvoffroadfuryblazintrails_download_frame", }, // ATV Offroad Fury Blazin' Trails (US)183{ 0x30c9c4f420573eb6, 540, "expf", },184{ 0x311779b4db21dbf3, 124, "motorstorm_pixel_read" }, // Motorstorm Arctic Edge (US)185{ 0x317afeb882ff324a, 212, "memcpy", }, // Mimana (US)186{ 0x31ea2e192f5095a1, 52, "vector_add_t", },187{ 0x31f523ef18898e0e, 420, "logf", },188{ 0x32215b1d2196377f, 844, "godseaterburst_blit_texture", }, // Gods Eater Burst (US)189{ 0x32806967fe81568b, 40, "vector_sub_t_2", },190{ 0x32ceb9a7f72b9385, 440, "_strtoul_r", },191{ 0x32e6bc7c151491ed, 68, "memchr", },192{ 0x335df69db1073a8d, 96, "wcscpy", },193{ 0x33dc6b144cb302c1, 304, "memmove", }, // Kingdom Hearts (US)194{ 0x35d3527ff8c22ff2, 56, "matrix_scale_q", },195{ 0x368f6cf979709a31, 744, "memmove", }, // Jui Dr. Touma Jotarou196{ 0x373ce518eee5a2d2, 20, "matrix300_store_q", },197{ 0x3840f5766fada4b1, 592, "dissidia_recordframe_avi", }, // Dissidia (US), Dissidia 012 (US)198{ 0x388043e96b0e11fd, 144, "sceGupMaterial", },199{ 0x38f19bc3be215acc, 388, "log10f", },200{ 0x3913b81ddcbe1efe, 880, "katamari_render_check", }, // Me and My Katamari (US)201{ 0x393047f06eceaba1, 96, "strcspn", },202{ 0x39a651942a0b3861, 204, "tan", },203{ 0x3a3bc2b20a55bf02, 68, "memchr", },204{ 0x3ab08b5659de1746, 40, "sceVfpuScalarSin", },205{ 0x3c421a9265f37ebc, 700, "memmove", }, // Final Fantasy 4 (US)206{ 0x3cbc2d50a3db59e9, 100, "strncmp", },207{ 0x3ce1806699a91d9d, 148, "sceGupLight", },208{ 0x3d5e914011c181d4, 444, "scalbnf", },209{ 0x3ea41eafb53fc99a, 388, "logf", },210{ 0x3fe38bff09ac3da0, 436, "_strtoul_r", },211{ 0x40a25c7e1fd44fe2, 24, "fabsf", },212// Unsafe due to immediates.213//{ 0x410d48d9b6580b4a, 36, "dl_write_ztest", },214{ 0x42dc17c8018f30f2, 44, "sceVfpuScalarTan", },215{ 0x436b07caa2aab931, 352, "acos", },216{ 0x444472537eedf966, 32, "sceVfpuMatrix4Zero", },217{ 0x449ff96982626338, 28, "vmidt_q", },218{ 0x44f65b1a72c45703, 36, "strlen", },219{ 0x45528de3948615dc, 64, "memcpy", },220{ 0x456a0d78ac318d15, 164, "gta_dl_write_matrix", },221{ 0x497248c9d12f44fd, 68, "strcpy", },222{ 0x4a70207212a4c497, 24, "strlen", },223{ 0x4b16a5c602c74c6c, 24, "vsub_t", },224{ 0x4bb677dace6ca526, 184, "memset", }, // Final FantasyTactics (JPN)225{ 0x4c4bdedcc13ac77c, 624, "dl_write_matrix_5", },226{ 0x4c91c556d1aa896b, 104, "dl_write_material_3", },227{ 0x4cf38c368078181e, 616, "dl_write_matrix", },228{ 0x4d3e7085e01d30e4, 324, "memcpy", }, // PoPoLoCrois (JPN)229{ 0x4d72b294501cddfb, 80, "copysign", },230{ 0x4ddd83b7f4ed8d4e, 844, "memcpy", },231{ 0x4e266783291b0220, 28, "vsub_t", },232{ 0x4e5950928c0bb082, 44, "vmmul_q_transp4", },233{ 0x4f34fc596ecf5b25, 40, "vdiv_t", },234{ 0x500a949afb39133f, 24, "vf2iu_q", },235{ 0x50d8f01ea8fa713d, 48, "send_commandi", },236{ 0x50fa6db2fb14814a, 544, "rint", },237{ 0x513ce13cd7ce97ea, 332, "scalbnf", },238{ 0x514161da54d37416, 1416, "__umoddi3", },239{ 0x51c52d7dd4d2191c, 360, "cos", },240{ 0x5287d4b8abd5806b, 768, "_strtoll_r", },241{ 0x52d5141545a75eda, 60, "sceGuClutMode", },242{ 0x530cbe1ce9b45d58, 108, "sceGuLightAtt", },243{ 0x53c9aa23504a630f, 96, "vmmul_q_5", },244{ 0x54015ccbcbc75374, 24, "strlen", }, // Metal Gear Solid: Peace Walker demo245{ 0x5550d87a851c218c, 168, "dl_write_viewport", },246{ 0x55c1294280bfade0, 88, "sceGuBlendFunc", },247{ 0x5642a63f3802a792, 456, "orenoimouto_download_frame", }, // Ore no Imouto ga Konnani Kawaii Wake ga Nai248{ 0x56c9929e8c8c5768, 24, "fabsf", },249{ 0x572b2d9e57e6e363, 788, "memcpy_thingy", },250{ 0x580200b840b47c58, 1856, "_realloc_r", },251{ 0x5961f681bbd69035, 28, "vfad_q", },252{ 0x598b91c64cf7e036, 2388, "qsort", },253{ 0x59a0cb08f5ecf8b6, 28, "copysignf", },254{ 0x5ae4ec2a5e133de3, 28, "vector_cross_t", },255{ 0x5b005f8375d7c364, 236, "floorf", },256{ 0x5b103d973fd1dd94, 92, "sceVfpuMatrix4RotY", },257{ 0x5b9d7e9d4c905694, 196, "_calloc_r", },258{ 0x5bf7a77b028e9f66, 324, "sqrtf", },259{ 0x5c0b3edc0e48852c, 148, "memmove", }, // Dissidia 1 (US)260{ 0x5e898df42c4af6b8, 76, "wcsncmp", },261{ 0x5f473780835e3458, 52, "vclamp_q", },262{ 0x5fc58ed2c4d48b79, 40, "sceVfpuMatrix4Transform", },263{ 0x6145029ef86f0365, 76, "__extendsfdf2", },264{ 0x62815f41fa86a131, 656, "scalbn", },265{ 0x6301fa5149bd973a, 120, "wcscat", },266{ 0x658b07240a690dbd, 36, "strlen", },267{ 0x66122f0ab50b2ef9, 296, "dl_write_dither_matrix_5", },268{ 0x66f7f1beccbc104a, 256, "memcpy_swizzled", }, // God Eater 2269{ 0x679e647e34ecf7f1, 132, "roundf", },270{ 0x67afe74d9ec72f52, 4380, "_strtod_r", },271{ 0x68b22c2aa4b8b915, 400, "sqrt", },272{ 0x6962da85a6dad937, 60, "strrchr", },273{ 0x69a3c4f774859404, 64, "vmmul_q_transp2", },274{ 0x6ab54910104ef000, 628, "sd_gundam_g_generation_download_frame", }, // SD Gundam G Generation World275{ 0x6ac2cd44e042592b, 252, "atvoffroadfurypro_download_frame", }, // ATV Offroad Fury Pro (US)276{ 0x6b022e20ee3fa733, 68, "__negdf2", },277{ 0x6b2a6347c0dfcb57, 152, "strcpy", },278{ 0x6b4148322c569cb3, 240, "wmemchr", },279{ 0x6c4cb6d25851553a, 44, "vtfm_t", },280{ 0x6c7b2462b9ec7bc7, 56, "vmmul_q", },281{ 0x6ca9cc8fa485d096, 304, "__ieee754_sqrtf", },282{ 0x6ccffc753d2c148e, 96, "strlwr", },283{ 0x6e40ec681fb5c571, 40, "matrix_copy_q", },284{ 0x6e9884c842a51142, 236, "strncasecmp", },285{ 0x6f101c5c4311c144, 276, "floorf", },286{ 0x6f1731f84bbf76c3, 116, "strcmp", },287{ 0x6f4e1a1a84df1da0, 68, "sceGupTexMode", },288{ 0x6f7c9109b5b8fa47, 688, "danganronpa1_2_download_frame", }, // Danganronpa 1289{ 0x70649c7211f6a8da, 16, "fabsf", },290{ 0x70a6152b265228e8, 296, "unendingbloodycall_download_frame", }, // unENDing Bloody Call291{ 0x7245b74db370ae72, 64, "sceVfpuMatrix4Mul", },292{ 0x7259d52b21814a5a, 40, "sceVfpuMatrix4TransformXYZ", },293{ 0x730f59cc6c0f5732, 452, "godseaterburst_depthmask_5551", }, // Gods Eater Burst (US)294{ 0x7354fd206796d817, 864, "flowers_download_frame", }, // Flowers295{ 0x736b34ebc702d873, 104, "vmmul_q_transp", },296{ 0x73a614c08f777d52, 792, "danganronpa2_2_download_frame", }, // Danganronpa 2297{ 0x7499a2ce8b60d801, 12, "abs", },298{ 0x74c77fb521740cd2, 284, "toheart2_download_frame_2", }, // To Heart 2 Portable299{ 0x74ebbe7d341463f3, 72, "sceGuColorFunc", },300{ 0x755a41f9183bb89a, 60, "vmmul_q", },301{ 0x757d7ab0afbc03f5, 948, "kirameki_school_life_download_frame", }, // Toradora! Portable302{ 0x759834c69bb12c12, 68, "strcpy", },303{ 0x75c5a88d62c9c99f, 276, "sinf", },304{ 0x76c661fecbb39990, 364, "sin", },305{ 0x770c9c07bf58fd14, 16, "fabsf", },306{ 0x774e479eb9634525, 464, "_strtol_r", },307{ 0x77aeb1c23f9aa2ad, 56, "strchr", },308{ 0x78e8c65b5a458f33, 148, "memcmp", },309{ 0x794d1b073c183c77, 24, "fabsf", },310{ 0x7978a886cf70b1c9, 56, "wcschr", },311{ 0x79faa339fff5a80c, 28, "finitef", },312{ 0x7c50728008c288e3, 36, "vector_transform_q_4x4", },313{ 0x7e33d4eaf573f937, 208, "memset", }, // Toukiden (JPN)314{ 0x7f1fc0dce6be120a, 404, "fmod", },315{ 0x8126a59ffa504614, 540, "brandish_download_frame", }, // Brandish, Zero no Kiseki, and Ao no Kiseki316{ 0x828b98925af9ff8f, 40, "vector_distance_t", },317{ 0x83ac39971df4b966, 336, "sqrtf", },318{ 0x84c6cd47834f4c79, 1284, "powf", },319{ 0x8734dc1d155ea493, 24, "vf2iz_q", },320{ 0x87fe3f7e621ddebb, 212, "memcpy", },321{ 0x891ca854e1c664e9, 2392, "qsort", },322{ 0x8965d4b004adad28, 420, "log10f", },323{ 0x89e1858ba11b84e4, 52, "memset", },324{ 0x8a00e7207e7dbc81, 232, "_exit", },325{ 0x8a1f9daadecbaf7f, 104, "vmmul_q_transp", },326{ 0x8a610f34078ce360, 32, "vector_copy_q_t", },327{ 0x8c3fd997a544d0b1, 268, "memcpy", }, // Valkyrie Profile (US)328{ 0x8da0164e69e9b531, 1040, "grisaianokajitsu_download_frame", }, // Grisaia no Kajitsu La Fruit de la Grisaia329{ 0x8dd0546db930ef25, 992, "memmove", }, // PoPoLoCrois (JPN)330{ 0x8df2928848857e97, 164, "strcat", },331{ 0x8e48cabd529ca6b5, 52, "sceVfpuVector3Mul", },332{ 0x8e97dcb03fbaba5c, 104, "vmmul_q_transp", },333{ 0x8ecf804bbe7922e5, 572, "worms_copy_normalize_alpha" }, // Worms Battle Islands (US)334{ 0x8ee81b03d2eef1e7, 28, "vmul_t", },335{ 0x8f09fb8693c3c49d, 992, "kirameki_school_life_download_frame", }, // Hentai Ouji To Warawanai Neko336{ 0x8f19c41e8b987e18, 100, "matrix_mogrify", },337{ 0x8ff11e9bed387401, 700, "memmove", }, // God Eater 2338{ 0x910140c1a07aa59e, 256, "sceVfpuMatrix4Rot", },339{ 0x91606bd72ae90481, 44, "wmemcpy", },340{ 0x92c7d2de74068c9c, 32, "vcross_t", },341{ 0x93d8a275ba288b26, 32, "vdot_t", },342{ 0x94c7083b64a946b4, 2028, "powf", },343{ 0x94eb1e7dccca76a4, 680, "shinigamitoshoujo_download_frame", }, // Shinigami to Shoujo (JP)344{ 0x95a52ce1bc460108, 2036, "_malloc_r", },345{ 0x95bd33ac373c019a, 24, "fabsf", },346{ 0x9705934b0950d68d, 280, "dl_write_framebuffer_ptr", },347{ 0x9734cf721bc0f3a1, 732, "atanf", },348{ 0x99b85c5fce389911, 408, "mytranwars_upload_frame", }, // Mytran Wars349{ 0x99c9288185c352ea, 592, "orenoimouto_download_frame_2", }, // Ore no Imouto ga Konnani Kawaii Wake ga Nai350{ 0x9a06b9d5c16c4c20, 76, "dl_write_clut_ptrload", },351{ 0x9b88b739267d189e, 88, "strrchr", },352{ 0x9ce53975bb88c0e7, 96, "strncpy", },353{ 0x9d4f5f56b52f07f2, 808, "memmove", }, // Jeanne d'Arc (US)354{ 0x9e2941c4a5c5e847, 792, "memcpy", }, // LittleBigPlanet (US)355{ 0x9e6ce11f9d49f954, 292, "memcpy", }, // Jeanne d'Arc (US)356{ 0x9f269daa6f0da803, 128, "sceGupScissor", },357{ 0x9f7919eeb43982b0, 208, "__fixdfsi", },358{ 0xa1c9b0a2c71235bf, 1752, "marvelalliance1_copy" }, // Marvel Ultimate Alliance 1 (EU)359{ 0x9b76c7f2a41aa805, 1752, "marvelalliance1_copy" }, // Marvel Ultimate alliance 1 (US)360{ 0xa1ca0640f11182e7, 72, "strcspn", },361{ 0xa243486be51ce224, 272, "cosf", },362{ 0xa2bcef60a550a3ef, 92, "sceVfpuMatrix4RotZ", },363{ 0xa373f55c65cd757a, 312, "memcpy_swizzled" }, // God Eater Burst Demo364{ 0xa41989db0f9bf97e, 1304, "pow", },365{ 0xa44f6227fdbc12b1, 132, "memcmp", }, // Popolocrois (US)366{ 0xa46cc6ea720d5775, 44, "sceGupFrontFace", },367{ 0xa54967288afe8f26, 600, "ceil", },368{ 0xa5ddbbc688e89a4d, 56, "isinf", },369{ 0xa615f6bd33195dae, 220, "atvoffroadfuryprodemo_download_frame", }, // ATV Offroad Fury Pro (US) demo370{ 0xa662359e30b829e4, 148, "memcmp", },371{ 0xa6a03f0487a911b0, 392, "danganronpa1_1_download_frame", }, // Danganronpa 1372{ 0xa8390e65fa087c62, 140, "vtfm_t_q", },373{ 0xa85e48ee10b2dc50, 432, "omertachinmokunookitethelegacy_download_frame", }, // Omerta Chinmoku No Okite The Legacy374{ 0xa85fe8abb88b1c6f, 52, "vector_sub_t", },375{ 0xa9194e55cc586557, 268, "memcpy", },376{ 0xa91b3d60bd75105b, 28, "vadd_t", },377{ 0xab97ec58c58a7c75, 52, "sceVfpuVector3Div", },378{ 0xac84fa7571895c9a, 68, "memcpy", }, // Marvel Ultimate Alliance 2379{ 0xacc2c11c3ea28320, 268, "ceilf", },380{ 0xad67add5122b8c64, 52, "sceVfpuMatrix4Transfer", },381{ 0xada952a1adcea4f5, 60, "vmmul_q_transp5", },382{ 0xadfbf8fb8c933193, 56, "fabs", },383{ 0xae39bac51fd6e76b, 628, "gakuenheaven_download_frame", }, // Gakuen Heaven: Boy's Love Scramble!384{ 0xae50226363135bdd, 24, "vector_sub_t", },385{ 0xae6cd7dfac82c244, 48, "sceVfpuScalarPow", },386{ 0xaf85d47f95ad2921, 1936, "pow", },387{ 0xafb2c7e56c04c8e9, 48, "vtfm_q", },388{ 0xafc9968e7d246a5e, 1588, "atan", },389{ 0xafcb7dfbc4d72588, 44, "vector_transform_3x4", },390{ 0xb07f9d82d79deea9, 536, "brandish_download_frame", }, // Brandish, and Sora no kiseki 3rd391{ 0xb09c9bc1343a774c, 456, "danganronpa2_1_download_frame", }, // Danganronpa 2392{ 0xb0db731f27d3aa1b, 40, "sceVfpuScalarMax", },393{ 0xb0ef265e87899f0a, 32, "vector_divide_t_s", },394{ 0xb183a37baa12607b, 32, "vscl_t", },395{ 0xb1a3e60a89af9857, 20, "fabs", },396{ 0xb25670ff47b4843d, 232, "starocean_clear_framebuf" },397{ 0xb3fef47fb27d57c9, 44, "vector_scale_t", },398{ 0xb43fd5078ae78029, 84, "send_commandi_stall", },399{ 0xb43ffbd4dc446dd2, 324, "atan2f", },400{ 0xb5fdb3083e6f4b3f, 36, "vhtfm_t", },401{ 0xb6a04277fb1e1a1a, 104, "vmmul_q_transp", },402{ 0xb726917d688ac95b, 268, "kagaku_no_ensemble_download_frame", }, // Toaru Majutsu to Kagaku no Ensemble403{ 0xb7448c5ffdd3b0fc, 356, "atan2f", },404{ 0xb7d88567dc22aab1, 820, "memcpy", }, // Trails in the Sky (US)405{ 0xb877d3c37a7aaa5d, 60, "vmmul_q_2", },406{ 0xb89aa73b6f94ba95, 52, "vclamp_t", },407{ 0xb8bd1f0e02e9ad87, 156, "sceGuLightSpot", },408{ 0xb8cfaeebfeb2de20, 7548, "_vfprintf_r", },409{ 0xb97f352e85661af6, 32, "finitef", },410{ 0xba76a8e853426baa, 544, "soranokiseki_fc_download_frame", }, // Sora no kiseki FC411{ 0xbb3c6592ed319ba4, 132, "sceGuFog", },412{ 0xbb7d7c93e4c08577, 124, "__truncdfsf2", },413{ 0xbdf54d66079afb96, 200, "sceGuBoneMatrix", },414{ 0xbe773f78afd1a70f, 128, "rand", },415{ 0xbf5d02ccb8514881, 108, "strcmp", },416{ 0xbf791954ebef4afb, 396, "expf", },417{ 0xbfa8c16038b7753d, 868, "sakurasou_download_frame", }, // Sakurasou No Pet Na Kanojo418{ 0xbfe07e305abc4cd1, 808, "memmove" }, // Final Fantasy Tactics (US)419{ 0xc062f2545ef5dc39, 1076, "kirameki_school_life_download_frame", },// Kirameki School Life SP,and Boku wa Tomodati ga Sukunai420{ 0xc0feb88cc04a1dc7, 48, "sceVfpuVector3Neg", },421{ 0xc1220040b0599a75, 472, "soranokiseki_sc_download_frame", }, // Sora no kiseki SC422{ 0xc1f34599d0b9146b, 116, "__subdf3", },423{ 0xc3089f66ee6f0a24, 464, "growlanser_create_saveicon", }, // Growlanswer IV424{ 0xc319f0d107dd2f45, 888, "__muldf3", },425{ 0xc35c10300b6b6091, 620, "floor", },426{ 0xc3dbf3e6c80a0a51, 164, "dl_write_bone_matrix", },427{ 0xc51519f5dab342d4, 224, "cosf", },428{ 0xc52c14b9af8c3008, 76, "memcmp", },429{ 0xc54eae62622f1e11, 164, "dl_write_bone_matrix_2", },430{ 0xc6b29de7d3245198, 656, "starocean_write_stencil" }, // Star Ocean 1 (US)431{ 0xc7b1113cfdfedab6, 104, "tonyhawkp8_upload_tutorial_frame", }, // Tony Hawk's Project 8 (US)432{ 0xc96e3a087ebf49a9, 100, "dl_write_light_color", },433{ 0xca7cb2c0b9410618, 680, "kudwafter_download_frame", }, // Kud Wafter434{ 0xcb22120018386319, 692, "photokano_download_frame", }, // Photo Kano435{ 0xcb7a2edd603ecfef, 48, "vtfm_p", },436{ 0xcdf64d21418b2667, 24, "vzero_q", },437{ 0xce1c95ee25b8e2ea, 448, "fmod", },438{ 0xce4d18a75b98859f, 40, "vector_add_t_2", },439// Unsafe due to immediates.440//{ 0xceb5372d0003d951, 52, "dl_write_stenciltest", },441{ 0xcee11483b550ce8f, 24, "vocp_q", },442{ 0xcfecf208769ed5fd, 272, "cosf", },443{ 0xd019b067b58cf6c3, 700, "memmove", }, // Star Ocean 1 (US)444{ 0xd12a3a91e0040229, 524, "sceGupSetStatus", },445{ 0xd141d1efbfe13ca3, 968, "kirameki_school_life_download_frame", }, // Kirameki School Life SP,and Boku wa Tomodati ga Sukunai446{ 0xd1db467a23ebe00d, 724, "rewrite_download_frame", }, // Rewrite Portable447{ 0xd1faacfc711d61e8, 68, "__negdf2", },448{ 0xd207b0650a41dd9c, 28, "vmin_q", },449{ 0xd6d6e0bb21654778, 24, "vneg_t", },450{ 0xd7229fee680e7851, 40, "sceVfpuScalarMin", },451{ 0xd75670860a7f4b05, 144, "wcsncpy", },452{ 0xd76d1a8804c7ec2c, 100, "sceGupModelColor", },453{ 0xd7d350c0b33a4662, 28, "vadd_q", },454{ 0xd80051931427dca0, 116, "__subdf3", },455{ 0xd96ba6e4ff86f1bf, 276, "katamari_screenshot_to_565", }, // Me and My Katamari (US)456{ 0xda51dab503b06979, 32, "vmidt_q", },457{ 0xdc0cc8b400ecfbf2, 36, "strcmp", },458{ 0xdcab869acf2bacab, 292, "strncasecmp", },459{ 0xdcdf7e1c1a3dc260, 372, "strncmp", },460{ 0xdcfc28e624a81bf1, 5476, "_dtoa_r", },461{ 0xddfa5a85937aa581, 32, "vdot_q", },462{ 0xdeb6a583659e3948, 1080, "littlebustersce_download_frame", }, // Little Busters! Converted Edition (JP)463{ 0xe0214719d8a0aa4e, 104, "strstr", },464{ 0xe029f0699ca3a886, 76, "matrix300_transform_by", },465{ 0xe086d5c9ce89148f, 212, "bokunonatsuyasumi4_download_frame", }, // Boku no Natsuyasumi 2 and 4,466{ 0xe093c2b0194d52b3, 820, "ff1_battle_effect", }, // Final Fantasy 1 (US)467{ 0xe1107cf3892724a0, 460, "_memalign_r", },468{ 0xe1724e6e29209d97, 24, "vector_length_t_2", },469{ 0xe1a5d939cc308195, 68, "wcscmp", },470{ 0xe2d9106e5b9e39e6, 80, "strnlen", },471{ 0xe3154c81a76515fa, 208, "narisokonai_download_frame", }, // Narisokonai Eiyuutan472{ 0xe32cb5c062d1a1c4, 700, "_strtoull_r", },473{ 0xe3835fb2c9c04e59, 44, "vmmul_q", },474{ 0xe527c62d8613f297, 136, "strcpy", },475{ 0xe6002fc9affd678e, 480, "topx_create_saveicon", }, // Tales of Phantasia X476{ 0xe7b36c2c1348551d, 148, "tan", },477{ 0xe83a7a9d80a21c11, 4448, "_strtod_r", },478{ 0xe894bda909a8a8f9, 1064, "expensive_wipeout_pulse", },479{ 0xe8ad7719be44e7c8, 276, "strchr", },480{ 0xeabb9c1b4f83d2b4, 52, "memset_jak", }, // Crisis Core (US), Jak and Daxter (this is a slow memset and needs to have slow timing)481{ 0xeb0f7bf63d52ece9, 88, "strncat", },482{ 0xeb8c0834d8bbc28c, 416, "fmodf", },483{ 0xed8918f378e9a563, 628, "sd_gundam_g_generation_download_frame", }, // SD Gundam G Generation Overworld484{ 0xedbbe9bf9fbceca8, 172, "dl_write_viewport2", },485{ 0xedc3f476221f96e6, 148, "tanf", },486{ 0xf1f660fdf349eac2, 1588, "_malloc_r", },487{ 0xf38a356a359dbe06, 28, "vmax_q", },488{ 0xf3fc2220ed0f2703, 32, "send_commandf", },489{ 0xf4d797cef4ac88cd, 684, "_free_r", },490{ 0xf4ea7d2ec943fa02, 224, "sinf", },491{ 0xf4f8cdf479dfc4a4, 224, "sinf", },492{ 0xf527d906d69005a0, 848, "photokano_download_frame_2", }, // Photo Kano493{ 0xf52f993e444b6c52, 44, "sceGupShadeModel", },494{ 0xf56641884b36c638, 468, "scalbn", },495{ 0xf5e91870b5b76ddc, 288, "motorstorm_download_frame", }, // MotorStorm: Arctic Edge496{ 0xf5f7826b4a61767c, 40, "matrix_copy_q", },497{ 0xf73c094e492bc163, 396, "hypot", },498{ 0xf773297d89ff7a63, 532, "kumonohatateni_download_frame", }, // Amatsumi Sora ni Kumo no Hatate ni, and Hanakisou499{ 0xf7fc691db0147e25, 96, "strspn", },500{ 0xf842aea3baa61f29, 32, "vector_length_t", },501{ 0xf8e0902f4099a9d6, 2260, "qsort", },502{ 0xf972543ab7df071a, 32, "sceVfpuScalarSqrt", },503{ 0xf9b00ef163e8b9d4, 32, "vscl_q", },504{ 0xf9ea1bf2a897ef24, 588, "ceil", },505{ 0xfa156c48461eeeb9, 24, "vf2id_q", },506{ 0xfb4253a1d9d9df9f, 20, "isnanf", },507{ 0xfd34a9ad94fa6241, 76, "__extendsfdf2", },508{ 0xfe2566ad957054b7, 232, "suikoden1_and_2_download_frame_2", }, // Gensou Suikoden 1&2509{ 0xfe4f0280240008e9, 28, "vavg_q", },510{ 0xfe5dd338ab862291, 216, "memset", }, // Metal Gear Solid: Peace Walker demo511{ 0xffc8f5f8f946152c, 192, "dl_write_light_color", },512{ 0x249a3c5981c73480, 1472, "openseason_data_decode", }, // Open Season513{ 0x795d940ad0a605f8, 40, "gow_fps_hack", }, // God of War (all)514{ 0x4c75043b7b0c643b, 512, "gow_vortex_hack", }, // God of War: Ghost of Sparta vortex timer hack, avoids softlock #8299515{ 0x7624dde603717640, 288, "ZZT3_select_hack", }, // Zettai Zetsumei Toshi 3 - bypasses softlock on character select screen #4901516{ 0x0dc5ca84f707863c, 452, "blitz_fps_hack", }, // Blitz: Overtime517{ 0xf93d3cd093595a6c, 856, "brian_lara_fps_hack", }, // Brian Lara 2007: Pressure Play518};519520namespace MIPSAnalyst {521// Only can ever output a single reg.522MIPSGPReg GetOutGPReg(MIPSOpcode op) {523MIPSInfo opinfo = MIPSGetInfo(op);524if (opinfo & OUT_RT) {525return MIPS_GET_RT(op);526}527if (opinfo & OUT_RD) {528return MIPS_GET_RD(op);529}530if (opinfo & OUT_RA) {531return MIPS_REG_RA;532}533return MIPS_REG_INVALID;534}535536bool ReadsFromGPReg(MIPSOpcode op, MIPSGPReg reg) {537MIPSInfo info = MIPSGetInfo(op);538if ((info & IN_RS) != 0 && MIPS_GET_RS(op) == reg) {539return true;540}541if ((info & IN_RT) != 0 && MIPS_GET_RT(op) == reg) {542return true;543}544return false;545}546547bool IsDelaySlotNiceReg(MIPSOpcode branchOp, MIPSOpcode op, MIPSGPReg reg1, MIPSGPReg reg2) {548MIPSInfo branchInfo = MIPSGetInfo(branchOp);549MIPSInfo info = MIPSGetInfo(op);550if (info & IS_CONDBRANCH) {551return false;552}553// $0 is never an out reg, it's always 0.554if (reg1 != MIPS_REG_ZERO && GetOutGPReg(op) == reg1) {555return false;556}557if (reg2 != MIPS_REG_ZERO && GetOutGPReg(op) == reg2) {558return false;559}560// If the branch is an "and link" branch, check the delay slot for RA.561if ((branchInfo & OUT_RA) != 0) {562return GetOutGPReg(op) != MIPS_REG_RA && !ReadsFromGPReg(op, MIPS_REG_RA);563}564return true;565}566567bool IsDelaySlotNiceVFPU(MIPSOpcode branchOp, MIPSOpcode op) {568MIPSInfo info = MIPSGetInfo(op);569if (info & IS_CONDBRANCH) {570return false;571}572return (info & OUT_VFPU_CC) == 0;573}574575bool IsDelaySlotNiceFPU(MIPSOpcode branchOp, MIPSOpcode op) {576MIPSInfo info = MIPSGetInfo(op);577if (info & IS_CONDBRANCH) {578return false;579}580return (info & OUT_FPUFLAG) == 0;581}582583bool IsSyscall(MIPSOpcode op) {584// Syscalls look like this: 0000 00-- ---- ---- ---- --00 1100585return (op >> 26) == 0 && (op & 0x3f) == 12;586}587588static bool IsSWInstr(MIPSOpcode op) {589return (op & MIPSTABLE_IMM_MASK) == 0xAC000000;590}591static bool IsSBInstr(MIPSOpcode op) {592return (op & MIPSTABLE_IMM_MASK) == 0xA0000000;593}594static bool IsSHInstr(MIPSOpcode op) {595return (op & MIPSTABLE_IMM_MASK) == 0xA4000000;596}597598static bool IsSWLInstr(MIPSOpcode op) {599return (op & MIPSTABLE_IMM_MASK) == 0xA8000000;600}601static bool IsSWRInstr(MIPSOpcode op) {602return (op & MIPSTABLE_IMM_MASK) == 0xB8000000;603}604605static bool IsSWC1Instr(MIPSOpcode op) {606return (op & MIPSTABLE_IMM_MASK) == 0xE4000000;607}608static bool IsSVSInstr(MIPSOpcode op) {609return (op & MIPSTABLE_IMM_MASK) == 0xE8000000;610}611static bool IsSVQInstr(MIPSOpcode op) {612return (op & MIPSTABLE_IMM_MASK) == 0xF8000000;613}614615int OpMemoryAccessSize(u32 pc) {616const auto op = Memory::Read_Instruction(pc, true);617return MIPSGetMemoryAccessSize(op);618}619620bool IsOpMemoryWrite(u32 pc) {621const auto op = Memory::Read_Instruction(pc, true);622MIPSInfo info = MIPSGetInfo(op);623return (info & OUT_MEM) != 0;624}625626bool OpHasDelaySlot(u32 pc) {627const auto op = Memory::Read_Instruction(pc, true);628MIPSInfo info = MIPSGetInfo(op);629return (info & DELAYSLOT) != 0;630}631632bool OpWouldChangeMemory(u32 pc, u32 addr, u32 size) {633const auto op = Memory::Read_Instruction(pc, true);634635// TODO: Trap sc/ll, svl.q, svr.q?636637int gprMask = 0;638if (IsSWInstr(op))639gprMask = 0xFFFFFFFF;640if (IsSHInstr(op))641gprMask = 0x0000FFFF;642if (IsSBInstr(op))643gprMask = 0x000000FF;644if (IsSWLInstr(op)) {645const u32 shift = (addr & 3) * 8;646gprMask = 0xFFFFFFFF >> (24 - shift);647}648if (IsSWRInstr(op)) {649const u32 shift = (addr & 3) * 8;650gprMask = 0xFFFFFFFF << shift;651}652653u32 writeVal = 0xFFFFFFFF;654u32 prevVal = 0x00000000;655656if (gprMask != 0)657{658MIPSGPReg rt = MIPS_GET_RT(op);659writeVal = currentMIPS->r[rt] & gprMask;660prevVal = Memory::Read_U32(addr) & gprMask;661}662663if (IsSWC1Instr(op)) {664int ft = MIPS_GET_FT(op);665writeVal = currentMIPS->fi[ft];666prevVal = Memory::Read_U32(addr);667}668669if (IsSVSInstr(op)) {670int vt = ((op >> 16) & 0x1f) | ((op & 3) << 5);671writeVal = currentMIPS->vi[voffset[vt]];672prevVal = Memory::Read_U32(addr);673}674675if (IsSVQInstr(op)) {676int vt = (((op >> 16) & 0x1f)) | ((op & 1) << 5);677float rd[4];678ReadVector(rd, V_Quad, vt);679return memcmp(rd, Memory::GetPointerRange(addr, 16), sizeof(float) * 4) != 0;680}681682return writeVal != prevVal;683}684685AnalysisResults Analyze(u32 address) {686const int MAX_ANALYZE = 10000;687688AnalysisResults results;689690//set everything to -1 (FF)691memset(&results, 255, sizeof(AnalysisResults));692for (int i = 0; i < MIPS_NUM_GPRS; i++) {693results.r[i].used = false;694results.r[i].readCount = 0;695results.r[i].writeCount = 0;696results.r[i].readAsAddrCount = 0;697}698699for (u32 addr = address, endAddr = address + MAX_ANALYZE; addr <= endAddr; addr += 4) {700MIPSOpcode op = Memory::Read_Instruction(addr, true);701MIPSInfo info = MIPSGetInfo(op);702703MIPSGPReg rs = MIPS_GET_RS(op);704MIPSGPReg rt = MIPS_GET_RT(op);705706if (info & IN_RS) {707if ((info & IN_RS_ADDR) == IN_RS_ADDR) {708results.r[rs].MarkReadAsAddr(addr);709} else {710results.r[rs].MarkRead(addr);711}712}713714if (info & IN_RT) {715results.r[rt].MarkRead(addr);716}717718MIPSGPReg outReg = GetOutGPReg(op);719if (outReg != MIPS_REG_INVALID) {720results.r[outReg].MarkWrite(addr);721}722723if (info & DELAYSLOT) {724// Let's just finish the delay slot before bailing.725endAddr = addr + 4;726}727}728729int numUsedRegs = 0;730static int totalUsedRegs = 0;731static int numAnalyzings = 0;732for (int i = 0; i < MIPS_NUM_GPRS; i++) {733if (results.r[i].used) {734numUsedRegs++;735}736}737totalUsedRegs += numUsedRegs;738numAnalyzings++;739VERBOSE_LOG(Log::CPU, "[ %08x ] Used regs: %i Average: %f", address, numUsedRegs, (float)totalUsedRegs / (float)numAnalyzings);740741return results;742}743744void Reset() {745std::lock_guard<std::recursive_mutex> guard(functions_lock);746functions.clear();747hashToFunction.clear();748}749750void UpdateHashToFunctionMap() {751std::lock_guard<std::recursive_mutex> guard(functions_lock);752hashToFunction.clear();753// Really need to detect C++11 features with better defines.754#if !PPSSPP_PLATFORM(IOS)755hashToFunction.reserve(functions.size());756#endif757for (auto iter = functions.begin(); iter != functions.end(); iter++) {758AnalyzedFunction &f = *iter;759if (f.hasHash && f.size > 16) {760hashToFunction.emplace(f.hash, &f);761}762}763}764765enum RegisterUsage {766USAGE_CLOBBERED,767USAGE_INPUT,768USAGE_UNKNOWN,769};770771static RegisterUsage DetermineInOutUsage(u64 inFlag, u64 outFlag, u32 addr, int instrs) {772const u32 start = addr;773u32 end = addr + instrs * sizeof(u32);774bool canClobber = true;775while (addr < end) {776const MIPSOpcode op = Memory::Read_Instruction(addr, true);777const MIPSInfo info = MIPSGetInfo(op);778779// Yes, used.780if (info & inFlag)781return USAGE_INPUT;782783// Clobbered, so not used.784if (info & outFlag)785return canClobber ? USAGE_CLOBBERED : USAGE_UNKNOWN;786787// Bail early if we hit a branch (could follow each path for continuing?)788if ((info & IS_CONDBRANCH) || (info & IS_JUMP)) {789// Still need to check the delay slot (so end after it.)790// We'll assume likely are taken.791end = addr + 8;792// The reason for the start != addr check is that we compile delay slots before branches.793// That means if we're starting at the branch, it's not safe to allow the delay slot794// to clobber, since it might have already been compiled.795// As for LIKELY, we don't know if it'll run the branch or not.796canClobber = (info & LIKELY) == 0 && start != addr;797}798addr += 4;799}800return USAGE_UNKNOWN;801}802803static RegisterUsage DetermineRegisterUsage(MIPSGPReg reg, u32 addr, int instrs) {804switch (reg) {805case MIPS_REG_HI:806return DetermineInOutUsage(IN_HI, OUT_HI, addr, instrs);807case MIPS_REG_LO:808return DetermineInOutUsage(IN_LO, OUT_LO, addr, instrs);809case MIPS_REG_FPCOND:810return DetermineInOutUsage(IN_FPUFLAG, OUT_FPUFLAG, addr, instrs);811case MIPS_REG_VFPUCC:812return DetermineInOutUsage(IN_VFPU_CC, OUT_VFPU_CC, addr, instrs);813default:814break;815}816817if (reg >= 32) {818return USAGE_UNKNOWN;819}820821const u32 start = addr;822u32 end = addr + instrs * sizeof(u32);823bool canClobber = true;824while (addr < end) {825const MIPSOpcode op = Memory::Read_Instruction(addr, true);826const MIPSInfo info = MIPSGetInfo(op);827828// Yes, used.829if ((info & IN_RS) && (MIPS_GET_RS(op) == reg))830return USAGE_INPUT;831if ((info & IN_RT) && (MIPS_GET_RT(op) == reg))832return USAGE_INPUT;833834// Clobbered, so not used.835bool clobbered = false;836if ((info & OUT_RT) && (MIPS_GET_RT(op) == reg))837clobbered = true;838if ((info & OUT_RD) && (MIPS_GET_RD(op) == reg))839clobbered = true;840if ((info & OUT_RA) && (reg == MIPS_REG_RA))841clobbered = true;842if (clobbered) {843if (!canClobber || (info & IS_CONDMOVE))844return USAGE_UNKNOWN;845return USAGE_CLOBBERED;846}847848// Bail early if we hit a branch (could follow each path for continuing?)849if ((info & IS_CONDBRANCH) || (info & IS_JUMP)) {850// Still need to check the delay slot (so end after it.)851// We'll assume likely are taken.852end = addr + 8;853// The reason for the start != addr check is that we compile delay slots before branches.854// That means if we're starting at the branch, it's not safe to allow the delay slot855// to clobber, since it might have already been compiled.856// As for LIKELY, we don't know if it'll run the branch or not.857canClobber = (info & LIKELY) == 0 && start != addr;858}859addr += 4;860}861return USAGE_UNKNOWN;862}863864bool IsRegisterUsed(MIPSGPReg reg, u32 addr, int instrs) {865return DetermineRegisterUsage(reg, addr, instrs) == USAGE_INPUT;866}867868bool IsRegisterClobbered(MIPSGPReg reg, u32 addr, int instrs) {869return DetermineRegisterUsage(reg, addr, instrs) == USAGE_CLOBBERED;870}871872void HashFunctions() {873std::lock_guard<std::recursive_mutex> guard(functions_lock);874std::vector<u32> buffer;875876for (auto iter = functions.begin(), end = functions.end(); iter != end; iter++) {877AnalyzedFunction &f = *iter;878if (!Memory::IsValidRange(f.start, f.end - f.start + 4)) {879continue;880}881882// This is unfortunate. In case of emuhacks or relocs, we have to make a copy.883buffer.resize((f.end - f.start + 4) / 4);884size_t pos = 0;885for (u32 addr = f.start; addr <= f.end; addr += 4) {886u32 validbits = 0xFFFFFFFF;887MIPSOpcode instr = Memory::ReadUnchecked_Instruction(addr, true);888if (MIPS_IS_EMUHACK(instr)) {889f.hasHash = false;890goto skip;891}892893MIPSInfo flags = MIPSGetInfo(instr);894if (flags & IN_IMM16)895validbits &= ~0xFFFF;896if (flags & IN_IMM26)897validbits &= ~0x03FFFFFF;898buffer[pos++] = instr & validbits;899}900901f.hash = CityHash64((const char *) &buffer[0], buffer.size() * sizeof(u32));902f.hasHash = true;903skip:904;905}906}907908void PrecompileFunction(u32 startAddr, u32 length) {909// Direct calls to this ignore the bPreloadFunctions flag, since it's just for stubs.910std::lock_guard<std::recursive_mutex> guard(MIPSComp::jitLock);911if (MIPSComp::jit) {912MIPSComp::jit->CompileFunction(startAddr, length);913}914}915916void PrecompileFunctions() {917if (!g_Config.bPreloadFunctions) {918return;919}920std::lock_guard<std::recursive_mutex> guard(functions_lock);921922// TODO: Load from cache file if available instead.923924double st = time_now_d();925for (auto iter = functions.begin(), end = functions.end(); iter != end; iter++) {926const AnalyzedFunction &f = *iter;927928PrecompileFunction(f.start, f.end - f.start + 4);929}930double et = time_now_d();931932NOTICE_LOG(Log::JIT, "Precompiled %d MIPS functions in %0.2f milliseconds", (int)functions.size(), (et - st) * 1000.0);933}934935static const char *DefaultFunctionName(char buffer[256], u32 startAddr) {936snprintf(buffer, 256, "z_un_%08x", startAddr);937return buffer;938}939940static bool IsDefaultFunction(const char *name) {941if (name == NULL) {942// Must be I guess?943return true;944}945946// Un named stubs, just in case.947if (!strncmp(name, "[UNK:", strlen("[UNK:")))948return true;949950// Assume any z_un, not just the address, is a default func.951return !strncmp(name, "z_un_", strlen("z_un_")) || !strncmp(name, "u_un_", strlen("u_un_"));952}953954static bool IsDefaultFunction(const std::string &name) {955if (name.empty()) {956// Must be I guess?957return true;958}959960return IsDefaultFunction(name.c_str());961}962963static u32 ScanAheadForJumpback(u32 fromAddr, u32 knownStart, u32 knownEnd) {964static const u32 MAX_AHEAD_SCAN = 0x1000;965// Maybe a bit high... just to make sure we don't get confused by recursive tail recursion.966static const u32 MAX_FUNC_SIZE = 0x20000;967968if (fromAddr > knownEnd + MAX_FUNC_SIZE) {969return INVALIDTARGET;970}971972// Code might jump halfway up to before fromAddr, but after knownEnd.973// In that area, there could be another jump up to the valid range.974// So we track that for a second scan.975u32 closestJumpbackAddr = INVALIDTARGET;976u32 closestJumpbackTarget = fromAddr;977978// We assume the furthest jumpback is within the func.979u32 furthestJumpbackAddr = INVALIDTARGET;980981const u32 scanEnd = fromAddr + Memory::ValidSize(fromAddr, MAX_AHEAD_SCAN);982for (u32 ahead = fromAddr; ahead < scanEnd; ahead += 4) {983MIPSOpcode aheadOp = Memory::Read_Instruction(ahead, true);984u32 target = GetBranchTargetNoRA(ahead, aheadOp);985if (target == INVALIDTARGET && ((aheadOp & 0xFC000000) == 0x08000000)) {986target = GetJumpTarget(ahead);987}988989if (target != INVALIDTARGET) {990// Only if it comes back up to known code within this func.991if (target >= knownStart && target <= knownEnd) {992furthestJumpbackAddr = ahead;993}994// But if it jumps above fromAddr, we should scan that area too...995if (target < closestJumpbackTarget && target < fromAddr && target > knownEnd) {996closestJumpbackAddr = ahead;997closestJumpbackTarget = target;998}999}1000if (aheadOp == MIPS_MAKE_JR_RA()) {1001break;1002}1003}10041005if (closestJumpbackAddr != INVALIDTARGET && furthestJumpbackAddr == INVALIDTARGET) {1006for (u32 behind = closestJumpbackTarget; behind < fromAddr; behind += 4) {1007MIPSOpcode behindOp = Memory::Read_Instruction(behind, true);1008u32 target = GetBranchTargetNoRA(behind, behindOp);1009if (target == INVALIDTARGET && ((behindOp & 0xFC000000) == 0x08000000)) {1010target = GetJumpTarget(behind);1011}10121013if (target != INVALIDTARGET) {1014if (target >= knownStart && target <= knownEnd) {1015furthestJumpbackAddr = closestJumpbackAddr;1016}1017}1018}1019}10201021return furthestJumpbackAddr;1022}10231024bool ScanForFunctions(u32 startAddr, u32 endAddr, bool insertSymbols) {1025std::lock_guard<std::recursive_mutex> guard(functions_lock);10261027FunctionsVector new_functions;10281029AnalyzedFunction currentFunction = {startAddr};10301031u32 furthestBranch = 0;1032bool looking = false;1033bool end = false;1034bool isStraightLeaf = true;1035bool decreasedSp = false;10361037u32 addr;1038for (addr = startAddr; addr <= endAddr; addr += 4) {1039MIPSOpcode op = Memory::Read_Instruction(addr, true);1040u32 target = GetBranchTargetNoRA(addr, op);1041if (target != INVALIDTARGET) {1042isStraightLeaf = false;1043if (target > furthestBranch) {1044furthestBranch = target;1045}1046// j X1047} else if ((op & 0xFC000000) == 0x08000000) {1048u32 sureTarget = GetJumpTarget(addr);1049// Check for a tail call. Might not even have a jr ra.1050if (sureTarget != INVALIDTARGET && sureTarget < currentFunction.start) {1051if (furthestBranch > addr) {1052looking = true;1053addr += 4;1054} else {1055end = true;1056}1057} else if (sureTarget != INVALIDTARGET && sureTarget > addr && sureTarget > furthestBranch) {1058static const u32 MAX_JUMP_FORWARD = 128;1059// If it's a nearby forward jump, and not a stackless leaf, assume not a tail call.1060if (sureTarget <= addr + MAX_JUMP_FORWARD && decreasedSp) {1061// But let's check the delay slot.1062MIPSOpcode op = Memory::Read_Instruction(addr + 4, true);1063// addiu sp, sp, +X1064if ((op & 0xFFFF8000) != 0x27BD0000) {1065furthestBranch = sureTarget;1066continue;1067}1068}10691070// A jump later. Probably tail, but let's check if it jumps back.1071// We use + 8 here in case it jumps right back to the delay slot. We'll consider that inside the func.1072u32 knownEnd = furthestBranch == 0 ? addr + 8 : furthestBranch;1073u32 jumpback = ScanAheadForJumpback(sureTarget, currentFunction.start, knownEnd);1074if (jumpback != INVALIDTARGET && jumpback > addr && jumpback > knownEnd) {1075furthestBranch = jumpback;1076} else {1077if (furthestBranch > addr) {1078looking = true;1079addr += 4;1080} else {1081end = true;1082}1083}1084}1085}1086if (op == MIPS_MAKE_JR_RA()) {1087// If a branch goes to the jr ra, it's still ending here.1088if (furthestBranch > addr) {1089looking = true;1090addr += 4;1091} else {1092end = true;1093}1094}1095// addiu sp, sp, -X1096if ((op & 0xFFFF8000) == 0x27BD8000) {1097decreasedSp = true;1098}1099// addiu sp, sp, +X1100if ((op & 0xFFFF8000) == 0x27BD0000) {1101decreasedSp = false;1102}1103if (op == MIPS_MAKE_NOP() && currentFunction.start == addr) {1104// Skip nop padding at the beginning of functions (alignment?)1105currentFunction.start += 4;1106}11071108if (looking) {1109if (addr >= furthestBranch) {1110u32 sureTarget = GetSureBranchTarget(addr);1111// Regular j only, jals are to new funcs.1112if (sureTarget == INVALIDTARGET && ((op & 0xFC000000) == 0x08000000)) {1113sureTarget = GetJumpTarget(addr);1114}11151116if (sureTarget != INVALIDTARGET && sureTarget < addr) {1117end = true;1118} else if (sureTarget != INVALIDTARGET) {1119// Okay, we have a downward jump. Might be an else or a tail call...1120// If there's a jump back upward in spitting distance of it, it's an else.1121u32 knownEnd = furthestBranch == 0 ? addr : furthestBranch;1122u32 jumpback = ScanAheadForJumpback(sureTarget, currentFunction.start, knownEnd);1123if (jumpback != INVALIDTARGET && jumpback > addr && jumpback > knownEnd) {1124furthestBranch = jumpback;1125}1126}1127}1128}11291130if (end) {1131currentFunction.end = addr + 4;1132currentFunction.isStraightLeaf = isStraightLeaf;11331134// Check if we already have symbol info starting here. If so, skip insertion.1135// We used to use the symbols to find the functions, but sometimes we'd find1136// wrong ones due to two modules with the same name.1137u32 existingSize = g_symbolMap->GetFunctionSize(currentFunction.start);1138if (existingSize != SymbolMap::INVALID_ADDRESS) {1139currentFunction.foundInSymbolMap = true;11401141// If we run into a func with a different size, skip updating the hash map.1142// This will prevent us saving incorrectly named funcs with wrong hashes.1143u32 detectedSize = currentFunction.end - currentFunction.start + 4;1144if (existingSize != detectedSize) {1145insertSymbols = false;1146}1147}11481149new_functions.push_back(currentFunction);11501151furthestBranch = 0;1152addr += 4;1153looking = false;1154end = false;1155isStraightLeaf = true;1156decreasedSp = false;1157currentFunction.start = addr + 4;1158currentFunction.foundInSymbolMap = false;1159}1160}11611162if (addr <= endAddr) {1163currentFunction.end = addr + 4;1164new_functions.push_back(currentFunction);1165}11661167for (auto iter = new_functions.begin(); iter != new_functions.end(); iter++) {1168iter->size = iter->end - iter->start + 4;1169if (insertSymbols && !iter->foundInSymbolMap) {1170char temp[256];1171g_symbolMap->AddFunction(DefaultFunctionName(temp, iter->start), iter->start, iter->end - iter->start + 4);1172}1173}11741175// Concatenate the new functions to the end of the old ones.1176functions.insert(functions.end(), new_functions.begin(), new_functions.end());1177return insertSymbols;1178}11791180void FinalizeScan(bool insertSymbols) {1181HashFunctions();11821183if (g_Config.bFuncHashMap || g_Config.bFuncReplacements) {1184LoadBuiltinHashMap();1185if (g_Config.bFuncHashMap) {1186Path hashMapFilename = GetSysDirectory(DIRECTORY_SYSTEM) / "knownfuncs.ini";1187LoadHashMap(hashMapFilename);1188StoreHashMap(hashMapFilename);1189}1190if (insertSymbols) {1191ApplyHashMap();1192}1193if (g_Config.bFuncReplacements) {1194ReplaceFunctions();1195}1196}1197}11981199bool SkipFuncHash(const std::string &name) {1200std::vector<std::string> funcs;1201SplitString(g_Config.sSkipFuncHashMap, ',', funcs);1202return std::find(funcs.begin(), funcs.end(), name) != funcs.end();1203}12041205void RegisterFunction(u32 startAddr, u32 size, const char *name) {1206std::lock_guard<std::recursive_mutex> guard(functions_lock);12071208// Check if we have this already1209for (auto iter = functions.begin(); iter != functions.end(); iter++) {1210if (iter->start == startAddr) {1211// Let's just add it to the hashmap.1212if (iter->hasHash && size > 16 && SkipFuncHash(name)) {1213HashMapFunc hfun;1214hfun.hash = iter->hash;1215strncpy(hfun.name, name, 64);1216hfun.name[63] = 0;1217hfun.size = size;1218hashMap.insert(hfun);1219return;1220} else if (!iter->hasHash || size == 0) {1221ERROR_LOG(Log::HLE, "%s: %08x %08x : match but no hash (%i) or no size", name, startAddr, size, iter->hasHash);1222}1223}1224}12251226// Cheats a little.1227AnalyzedFunction fun;1228fun.start = startAddr;1229fun.end = startAddr + size - 4;1230fun.isStraightLeaf = false; // dunno really1231strncpy(fun.name, name, 64);1232fun.name[63] = 0;1233functions.push_back(fun);12341235HashFunctions();1236}12371238void ForgetFunctions(u32 startAddr, u32 endAddr) {1239std::lock_guard<std::recursive_mutex> guard(functions_lock);12401241// It makes sense to forget functions as modules are unloaded but it breaks1242// the easy way of saving a hashmap by unloading and loading a game. I added1243// an alternative way.12441245// Most of the time, functions from the same module will be contiguous in functions.1246FunctionsVector::iterator prevMatch = functions.end();1247size_t originalSize = functions.size();1248for (auto iter = functions.begin(); iter != functions.end(); ++iter) {1249const bool hadPrevMatch = prevMatch != functions.end();1250const bool match = iter->start >= startAddr && iter->start <= endAddr;12511252if (!hadPrevMatch && match) {1253// Entering a range.1254prevMatch = iter;1255} else if (hadPrevMatch && !match) {1256// Left a range.1257iter = functions.erase(prevMatch, iter);1258prevMatch = functions.end();1259}1260}1261if (prevMatch != functions.end()) {1262// Cool, this is the fastest way.1263functions.erase(prevMatch, functions.end());1264}12651266RestoreReplacedInstructions(startAddr, endAddr);12671268if (functions.empty()) {1269hashToFunction.clear();1270} else if (originalSize != functions.size()) {1271UpdateHashToFunctionMap();1272}1273}12741275void ReplaceFunctions() {1276std::lock_guard<std::recursive_mutex> guard(functions_lock);12771278for (size_t i = 0; i < functions.size(); i++) {1279WriteReplaceInstructions(functions[i].start, functions[i].hash, functions[i].size);1280}1281}12821283void UpdateHashMap() {1284std::lock_guard<std::recursive_mutex> guard(functions_lock);12851286for (auto it = functions.begin(), end = functions.end(); it != end; ++it) {1287const AnalyzedFunction &f = *it;1288// Small functions aren't very interesting.1289if (!f.hasHash || f.size <= 16) {1290continue;1291}1292// Functions with default names aren't very interesting either.1293const std::string name = g_symbolMap->GetLabelString(f.start);1294if (IsDefaultFunction(name) || SkipFuncHash(name)) {1295continue;1296}12971298HashMapFunc mf = { "", f.hash, f.size };1299strncpy(mf.name, name.c_str(), sizeof(mf.name) - 1);1300hashMap.insert(mf);1301}1302}13031304const char *LookupHash(u64 hash, u32 funcsize) {1305const HashMapFunc f = { "", hash, funcsize };1306auto it = hashMap.find(f);1307if (it != hashMap.end()) {1308return it->name;1309}1310return 0;1311}13121313void SetHashMapFilename(const std::string& filename) {1314if (filename.empty())1315hashmapFileName = GetSysDirectory(DIRECTORY_SYSTEM) / "knownfuncs.ini";1316else1317hashmapFileName = Path(filename);1318}13191320void StoreHashMap(Path filename) {1321if (filename.empty())1322filename = hashmapFileName;13231324UpdateHashMap();1325if (hashMap.empty()) {1326return;1327}13281329FILE *file = File::OpenCFile(filename, "wt");1330if (!file) {1331WARN_LOG(Log::Loader, "Could not store hash map: %s", filename.c_str());1332return;1333}13341335for (auto it = hashMap.begin(), end = hashMap.end(); it != end; ++it) {1336const HashMapFunc &mf = *it;1337if (!mf.hardcoded) {1338if (fprintf(file, "%016llx:%d = %s\n", mf.hash, mf.size, mf.name) <= 0) {1339WARN_LOG(Log::Loader, "Could not store hash map: %s", filename.c_str());1340break;1341}1342}1343}1344fclose(file);1345}13461347void ApplyHashMap() {1348UpdateHashToFunctionMap();13491350for (auto mf = hashMap.begin(), end = hashMap.end(); mf != end; ++mf) {1351auto range = hashToFunction.equal_range(mf->hash);1352if (range.first == range.second) {1353continue;1354}13551356// Yay, found a function.1357for (auto iter = range.first; iter != range.second; ++iter) {1358AnalyzedFunction &f = *iter->second;1359if (f.hash == mf->hash && f.size == mf->size) {1360strncpy(f.name, mf->name, sizeof(mf->name) - 1);13611362std::string existingLabel = g_symbolMap->GetLabelString(f.start);1363char defaultLabel[256];1364// If it was renamed, keep it. Only change the name if it's still the default.1365if (existingLabel.empty() || existingLabel == DefaultFunctionName(defaultLabel, f.start)) {1366g_symbolMap->SetLabelName(mf->name, f.start);1367}1368}1369}1370}1371}13721373void LoadBuiltinHashMap() {1374HashMapFunc mf;1375for (size_t i = 0; i < ARRAY_SIZE(hardcodedHashes); i++) {1376mf.hash = hardcodedHashes[i].hash;1377mf.size = hardcodedHashes[i].funcSize;1378strncpy(mf.name, hardcodedHashes[i].funcName, sizeof(mf.name));1379mf.name[sizeof(mf.name) - 1] = 0;1380mf.hardcoded = true;1381hashMap.insert(mf);1382}1383}13841385void LoadHashMap(const Path &filename) {1386FILE *file = File::OpenCFile(filename, "rt");1387if (!file) {1388WARN_LOG(Log::Loader, "Could not load hash map: %s", filename.c_str());1389return;1390}1391hashmapFileName = filename;13921393while (!feof(file)) {1394HashMapFunc mf = { "" };1395mf.hardcoded = false;1396if (fscanf(file, "%llx:%d = %63s\n", &mf.hash, &mf.size, mf.name) < 3) {1397char temp[1024];1398if (!fgets(temp, 1024, file)) {1399WARN_LOG(Log::Loader, "Could not read from hash map: %s", filename.c_str());1400}1401continue;1402}14031404hashMap.insert(mf);1405}1406fclose(file);1407}14081409std::vector<MIPSGPReg> GetInputRegs(MIPSOpcode op) {1410std::vector<MIPSGPReg> vec;1411MIPSInfo info = MIPSGetInfo(op);1412if (info & IN_RS) vec.push_back(MIPS_GET_RS(op));1413if (info & IN_RT) vec.push_back(MIPS_GET_RT(op));1414return vec;1415}14161417std::vector<MIPSGPReg> GetOutputRegs(MIPSOpcode op) {1418std::vector<MIPSGPReg> vec;1419MIPSInfo info = MIPSGetInfo(op);1420if (info & OUT_RD) vec.push_back(MIPS_GET_RD(op));1421if (info & OUT_RT) vec.push_back(MIPS_GET_RT(op));1422if (info & OUT_RA) vec.push_back(MIPS_REG_RA);1423return vec;1424}14251426MipsOpcodeInfo GetOpcodeInfo(DebugInterface* cpu, u32 address) {1427MipsOpcodeInfo info;1428memset(&info, 0, sizeof(info));14291430if (!Memory::IsValidAddress(address)) {1431info.opcodeAddress = address;1432return info;1433}14341435info.cpu = cpu;1436info.opcodeAddress = address;1437info.encodedOpcode = Memory::Read_Instruction(address);14381439MIPSOpcode op = info.encodedOpcode;1440MIPSInfo opInfo = MIPSGetInfo(op);1441info.isLikelyBranch = (opInfo & LIKELY) != 0;14421443// gather relevant address for alu operations1444// that's usually the value of the dest register1445switch (MIPS_GET_OP(op)) {1446case 0: // special1447switch (MIPS_GET_FUNC(op)) {1448case 0x20: // add1449case 0x21: // addu1450info.hasRelevantAddress = true;1451info.relevantAddress = cpu->GetRegValue(0,MIPS_GET_RS(op))+cpu->GetRegValue(0,MIPS_GET_RT(op));1452break;1453case 0x22: // sub1454case 0x23: // subu1455info.hasRelevantAddress = true;1456info.relevantAddress = cpu->GetRegValue(0,MIPS_GET_RS(op))-cpu->GetRegValue(0,MIPS_GET_RT(op));1457break;1458}1459break;1460case 0x08: // addi1461case 0x09: // addiu1462info.hasRelevantAddress = true;1463info.relevantAddress = cpu->GetRegValue(0, MIPS_GET_RS(op)) + SignExtend16ToS32(op & 0xFFFF);1464break;1465}14661467//j , jal, ...1468if (opInfo & IS_JUMP) {1469info.isBranch = true;1470if ((opInfo & OUT_RA) || (opInfo & OUT_RD)) { // link1471info.isLinkedBranch = true;1472}14731474if (opInfo & IN_RS) { // to register1475info.isBranchToRegister = true;1476info.branchRegisterNum = (int)MIPS_GET_RS(op);1477info.branchTarget = cpu->GetRegValue(0,info.branchRegisterNum);1478} else { // to immediate1479info.branchTarget = GetJumpTarget(address);1480}1481}14821483// movn, movz1484if (opInfo & IS_CONDMOVE) {1485info.isConditional = true;14861487u32 rt = cpu->GetRegValue(0, (int)MIPS_GET_RT(op));1488switch (opInfo & CONDTYPE_MASK) {1489case CONDTYPE_EQ:1490info.conditionMet = (rt == 0);1491break;1492case CONDTYPE_NE:1493info.conditionMet = (rt != 0);1494break;1495}1496}14971498// beq, bgtz, ...1499if (opInfo & IS_CONDBRANCH) {1500info.isBranch = true;1501info.isConditional = true;1502info.branchTarget = GetBranchTarget(address);15031504if (opInfo & OUT_RA) { // link1505info.isLinkedBranch = true;1506}15071508u32 rt = cpu->GetRegValue(0, (int)MIPS_GET_RT(op));1509u32 rs = cpu->GetRegValue(0, (int)MIPS_GET_RS(op));1510switch (opInfo & CONDTYPE_MASK) {1511case CONDTYPE_EQ:1512if (opInfo & IN_FPUFLAG) { // fpu branch1513info.conditionMet = currentMIPS->fpcond == 0;1514} else {1515info.conditionMet = (rt == rs);1516if (MIPS_GET_RT(op) == MIPS_GET_RS(op)) { // always true1517info.isConditional = false;1518}1519}1520break;1521case CONDTYPE_NE:1522if (opInfo & IN_FPUFLAG) { // fpu branch1523info.conditionMet = currentMIPS->fpcond != 0;1524} else {1525info.conditionMet = (rt != rs);1526if (MIPS_GET_RT(op) == MIPS_GET_RS(op)) { // always true1527info.isConditional = false;1528}1529}1530break;1531case CONDTYPE_LEZ:1532info.conditionMet = (((s32)rs) <= 0);1533break;1534case CONDTYPE_GTZ:1535info.conditionMet = (((s32)rs) > 0);1536break;1537case CONDTYPE_LTZ:1538info.conditionMet = (((s32)rs) < 0);1539break;1540case CONDTYPE_GEZ:1541info.conditionMet = (((s32)rs) >= 0);1542break;1543}1544}15451546// lw, sh, ...1547if (!IsSyscall(op) && (opInfo & (IN_MEM | OUT_MEM)) != 0) {1548info.isDataAccess = true;1549info.dataSize = MIPSGetMemoryAccessSize(op);15501551u32 rs = cpu->GetRegValue(0, (int)MIPS_GET_RS(op));1552s16 imm16 = op & 0xFFFF;1553info.dataAddress = rs + imm16;15541555info.hasRelevantAddress = true;1556info.relevantAddress = info.dataAddress;1557}15581559return info;1560}1561}156215631564