[CPU] Use reserved form of sc for imports.

This commit is contained in:
gibbed 2020-02-11 06:05:21 -06:00 committed by Rick Gibbed
parent e2346ee539
commit cc47704a6b
2 changed files with 16 additions and 7 deletions

View File

@ -423,8 +423,15 @@ int InstrEmit_mcrf(PPCHIRBuilder& f, const InstrData& i) {
// System linkage (A-24)
int InstrEmit_sc(PPCHIRBuilder& f, const InstrData& i) {
// Game code should only ever use LEV=0.
// LEV=2 is to signify 'call import' from Xenia.
// TODO(gibbed): syscalls!
if (i.SC.LEV == 2) {
f.CallExtern(f.function());
return 0;
}
XEINSTRNOTIMPLEMENTED();
return 1;
}
// Trap (A-25)

View File

@ -1225,15 +1225,17 @@ bool XexModule::SetupLibraryImports(const char* name,
// bctr
// Real consoles rewrite this with some code that sets r11.
// If we did that we'd still have to put a thunk somewhere and do the
// dynamic lookup. Instead, we rewrite it to use syscalls, as they
// aren't used on the 360. CPU backends can either take the syscall
// or do something smarter.
// sc
// dynamic lookup. Instead, we rewrite it to use syscalls.
// We use sc with a LEV operand of 2, which is reserved usage and
// should never see actual usage outside of our rewrite.
// CPU backends can either take the special form syscall or do
// something smarter.
// sc 2
// blr
// nop
// nop
uint8_t* p = memory()->TranslateVirtual(record_addr);
xe::store_and_swap<uint32_t>(p + 0x0, 0x44000002);
xe::store_and_swap<uint32_t>(p + 0x0, 0x44000042);
xe::store_and_swap<uint32_t>(p + 0x4, 0x4E800020);
xe::store_and_swap<uint32_t>(p + 0x8, 0x60000000);
xe::store_and_swap<uint32_t>(p + 0xC, 0x60000000);