mirror of
				https://github.com/hedge-dev/XenonRecomp.git
				synced 2025-11-04 06:47:09 +00:00 
			
		
		
		
	Handle setjmp/longjmp explicitly.
This commit is contained in:
		@@ -35,17 +35,32 @@ bool Recompiler::Recompile(const Function& fn, uint32_t base, const ppc_insn& in
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    println("\t// {} {}", insn.opcode->name, insn.op_str);
 | 
					    println("\t// {} {}", insn.opcode->name, insn.op_str);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    bool printedJmpEnv = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    auto printFunctionCall = [&](uint32_t ea)
 | 
					    auto printFunctionCall = [&](uint32_t ea)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            auto targetSymbol = image.symbols.find(ea);
 | 
					            if (ea == longJmpAddress)
 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (targetSymbol != image.symbols.end() && targetSymbol->address == ea && targetSymbol->type == Symbol_Function)
 | 
					 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                println("\t{}(ctx, base);", targetSymbol->name);
 | 
					                println("\tlongjmp(*reinterpret_cast<jmp_buf*>(base + ctx.r3.u32), ctx.r4.s32);");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            else if (ea == setJmpAddress)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                println("\tenv = ctx;");
 | 
				
			||||||
 | 
					                println("\tctx.r3.s64 = setjmp(*reinterpret_cast<jmp_buf*>(base + ctx.r3.u32));");
 | 
				
			||||||
 | 
					                println("\tif (ctx.r3.s64 != 0) ctx = env;");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else
 | 
					            else
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                println("\t// ERROR", ea);
 | 
					                auto targetSymbol = image.symbols.find(ea);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if (targetSymbol != image.symbols.end() && targetSymbol->address == ea && targetSymbol->type == Symbol_Function)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    println("\t{}(ctx, base);", targetSymbol->name);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                else
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    println("\t// ERROR", ea);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,6 +15,8 @@ struct Recompiler
 | 
				
			|||||||
    std::string out;
 | 
					    std::string out;
 | 
				
			||||||
    size_t cppFileIndex = 0;
 | 
					    size_t cppFileIndex = 0;
 | 
				
			||||||
    std::vector<uint8_t> temp;
 | 
					    std::vector<uint8_t> temp;
 | 
				
			||||||
 | 
					    uint32_t setJmpAddress = 0;
 | 
				
			||||||
 | 
					    uint32_t longJmpAddress = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void LoadSwitchTables(const char* filePath);
 | 
					    void LoadSwitchTables(const char* filePath);
 | 
				
			||||||
    void LoadExecutable(const char* filePath);
 | 
					    void LoadExecutable(const char* filePath);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -191,4 +191,7 @@ void SWARecompiler::Analyse()
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    std::sort(functions.begin(), functions.end(), [](auto& lhs, auto& rhs) { return lhs.base < rhs.base; });
 | 
					    std::sort(functions.begin(), functions.end(), [](auto& lhs, auto& rhs) { return lhs.base < rhs.base; });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    setJmpAddress = 0x831B6AB0;
 | 
				
			||||||
 | 
					    longJmpAddress = 0x831B6790;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user