bool DSPCore_Init(const DSPInitOptions& opts) { g_dsp.step_counter = 0; g_init_hax = false; g_dsp.accelerator = std::make_unique<LLEAccelerator>(); g_dsp.irom = static_cast<u16*>(Common::AllocateMemoryPages(DSP_IROM_BYTE_SIZE)); g_dsp.iram = static_cast<u16*>(Common::AllocateMemoryPages(DSP_IRAM_BYTE_SIZE)); g_dsp.dram = static_cast<u16*>(Common::AllocateMemoryPages(DSP_DRAM_BYTE_SIZE)); g_dsp.coef = static_cast<u16*>(Common::AllocateMemoryPages(DSP_COEF_BYTE_SIZE)); memcpy(g_dsp.irom, opts.irom_contents.data(), DSP_IROM_BYTE_SIZE); memcpy(g_dsp.coef, opts.coef_contents.data(), DSP_COEF_BYTE_SIZE); // Try to load real ROM contents. if (!VerifyRoms()) { DSPCore_FreeMemoryPages(); return false; } memset(&g_dsp.r, 0, sizeof(g_dsp.r)); std::fill(std::begin(g_dsp.reg_stack_ptr), std::end(g_dsp.reg_stack_ptr), 0); for (size_t i = 0; i < ArraySize(g_dsp.reg_stack); i++) std::fill(std::begin(g_dsp.reg_stack[i]), std::end(g_dsp.reg_stack[i]), 0); // Fill IRAM with HALT opcodes. std::fill(g_dsp.iram, g_dsp.iram + DSP_IRAM_SIZE, 0x0021); // Just zero out DRAM. std::fill(g_dsp.dram, g_dsp.dram + DSP_DRAM_SIZE, 0); // Copied from a real console after the custom UCode has been loaded. // These are the indexing wrapping registers. std::fill(std::begin(g_dsp.r.wr), std::end(g_dsp.r.wr), 0xffff); g_dsp.r.sr |= SR_INT_ENABLE; g_dsp.r.sr |= SR_EXT_INT_ENABLE; g_dsp.cr = 0x804; gdsp_ifx_init(); // Mostly keep IRAM write protected. We unprotect only when DMA-ing // in new ucodes. Common::WriteProtectMemory(g_dsp.iram, DSP_IRAM_BYTE_SIZE, false); // Initialize JIT, if necessary if (opts.core_type == DSPInitOptions::CORE_JIT) g_dsp_jit = std::make_unique<JIT::x64::DSPEmitter>(); g_dsp_cap.reset(opts.capture_logger); core_state = State::Running; return true; }
bool DSPCore_Init(const std::string& irom_filename, const std::string& coef_filename, bool bUsingJIT) { g_dsp.step_counter = 0; cyclesLeft = 0; init_hax = false; dspjit = nullptr; g_dsp.irom = (u16*)AllocateMemoryPages(DSP_IROM_BYTE_SIZE); g_dsp.iram = (u16*)AllocateMemoryPages(DSP_IRAM_BYTE_SIZE); g_dsp.dram = (u16*)AllocateMemoryPages(DSP_DRAM_BYTE_SIZE); g_dsp.coef = (u16*)AllocateMemoryPages(DSP_COEF_BYTE_SIZE); // Fill roms with zeros. memset(g_dsp.irom, 0, DSP_IROM_BYTE_SIZE); memset(g_dsp.coef, 0, DSP_COEF_BYTE_SIZE); // Try to load real ROM contents. if (!LoadRom(irom_filename, DSP_IROM_SIZE, g_dsp.irom) || !LoadRom(coef_filename, DSP_COEF_SIZE, g_dsp.coef) || !VerifyRoms(irom_filename, coef_filename)) { DSPCore_FreeMemoryPages(); return false; } memset(&g_dsp.r,0,sizeof(g_dsp.r)); for (int i = 0; i < 4; i++) { g_dsp.reg_stack_ptr[i] = 0; for (int j = 0; j < DSP_STACK_DEPTH; j++) { g_dsp.reg_stack[i][j] = 0; } } // Fill IRAM with HALT opcodes. for (int i = 0; i < DSP_IRAM_SIZE; i++) { g_dsp.iram[i] = 0x0021; // HALT opcode } // Just zero out DRAM. for (int i = 0; i < DSP_DRAM_SIZE; i++) { g_dsp.dram[i] = 0; } // Copied from a real console after the custom UCode has been loaded. // These are the indexing wrapping registers. g_dsp.r.wr[0] = 0xffff; g_dsp.r.wr[1] = 0xffff; g_dsp.r.wr[2] = 0xffff; g_dsp.r.wr[3] = 0xffff; g_dsp.r.sr |= SR_INT_ENABLE; g_dsp.r.sr |= SR_EXT_INT_ENABLE; g_dsp.cr = 0x804; gdsp_ifx_init(); // Mostly keep IRAM write protected. We unprotect only when DMA-ing // in new ucodes. WriteProtectMemory(g_dsp.iram, DSP_IRAM_BYTE_SIZE, false); // Initialize JIT, if necessary if (bUsingJIT) dspjit = new DSPEmitter(); core_state = DSPCORE_RUNNING; return true; }