Beispiel #1
0
bool RawSPUThread::Write32(const u64 addr, const u32 value)
{
	const u64 offset = addr - GetStartAddr() - RAW_SPU_PROB_OFFSET;

	switch (offset)
	{
	case MFC_LSA_offs:
	{
		MFC2.LSA.SetValue(value);
		break;
	}

	case MFC_EAH_offs:
	{
		MFC2.EAH.SetValue(value);
		break;
	}

	case MFC_EAL_offs:
	{
		MFC2.EAL.SetValue(value);
		break;
	}

	case MFC_Size_Tag_offs:
	{
		MFC2.Size_Tag.SetValue(value);
		break;
	}

	case MFC_CMDStatus_offs:
	{
		MFC2.CMDStatus.SetValue(value);
		EnqMfcCmd(MFC2);
		break;
	}
		
	case Prxy_QueryType_offs:
	{
		switch(value)
		{
		case 2: break;

		default:
		{
			LOG_ERROR(Log::SPU, "RawSPUThread[%d]: Unknown Prxy Query Type. (prxy_query=0x%x)", m_index, value);
			return false;
		}
		}

		MFC2.QueryType.SetValue(value); // not used
		break;
	}

	case Prxy_QueryMask_offs:
	{
		MFC2.QueryMask.SetValue(value); // TagStatus is not used
		break;
	}

	case SPU_In_MBox_offs:
	{
		// if In_MBox is already full, the last message is overwritten  
		SPU.In_MBox.PushUncond(value); 
		break;
	}

	case SPU_RunCntl_offs:
	{
		if (value == SPU_RUNCNTL_RUNNABLE)
		{
			SPU.Status.SetValue(SPU_STATUS_RUNNING);
			Exec();
		}
		else if (value == SPU_RUNCNTL_STOP)
		{
			SPU.Status.SetValue(SPU_STATUS_STOPPED);
			Stop();
		}
		else
		{
			LOG_ERROR(Log::SPU, "RawSPUThread[%d]: Write32(SPU_RunCtrl, 0x%x): unknown value", m_index, value);
			return false;
		}
		break;
	}

	case SPU_NPC_offs:
	{
		if (value & 3)
		{
			// least significant bit contains some interrupt flag
			LOG_ERROR(Log::SPU, "RawSPUThread[%d]: Write32(SPU_NPC_offs, 0x%x): lowest bits set", m_index, value);
			return false;
		}
		SPU.NPC.SetValue(value);
		break;
	}

	case SPU_RdSigNotify1_offs:
	{
		WriteSNR(0, value);
		break;
	}

	case SPU_RdSigNotify2_offs:
	{
		WriteSNR(1, value);
		break;
	}

	default:
	{
		// TODO: write value to LS if necessary (not important)
		LOG_ERROR(Log::SPU, "RawSPUThread[%d]: Write32(0x%llx, 0x%x)", m_index, offset, value);
		return false;
	}
	}

	return true;
}
Beispiel #2
0
bool RawSPUThread::Write32(const u64 addr, const u32 value)
{
	if(addr < GetStartAddr() + RAW_SPU_PROB_OFFSET)
	{
		return MemoryBlock::Write32(addr, value);
	}

	u32 offset = addr - GetStartAddr() - RAW_SPU_PROB_OFFSET;

	switch(offset)
	{
	case MFC_LSA_offs:	MFC2.LSA.SetValue(value); break;
	case MFC_EAH_offs:	MFC2.EAH.SetValue(value); break;
	case MFC_EAL_offs:	MFC2.EAL.SetValue(value); break;
	case MFC_Size_Tag_offs:	MFC2.Size_Tag.SetValue(value); break;
	case MFC_CMDStatus_offs:
		MFC2.CMDStatus.SetValue(value);
		EnqMfcCmd(MFC2);
	break;
	case MFC_QStatus_offs:			ConLog.Warning("RawSPUThread[%d]: Write32(MFC_QStatus, 0x%x)", m_index, value);			MFC2.QStatus.SetValue(value); break;
	case Prxy_QueryType_offs:
	{
		ConLog.Warning("RawSPUThread[%d]: Write32(Prxy_QueryType, 0x%x)", m_index, value);
		Prxy.QueryType.SetValue(value);

		switch(value)
		{
		case 2:
			ConLog.Warning("RawSPUThread[%d]: Prxy Query Immediate.", m_index);
		break;

		default:
			ConLog.Error("RawSPUThread[%d]: Unknown Prxy Query Type. (prxy_query=0x%x)", m_index, value);
		break;
		}

		Prxy.QueryType.SetValue(0);
		MFC2.QStatus.SetValue(Prxy.QueryMask.GetValue());
	}
	break;
	case Prxy_QueryMask_offs:   ConLog.Warning("RawSPUThread[%d]: Write32(Prxy_QueryMask, 0x%x)", m_index, value);      Prxy.QueryMask.SetValue(value); break;
	case Prxy_TagStatus_offs:   ConLog.Warning("RawSPUThread[%d]: Write32(Prxy_TagStatus, 0x%x)", m_index, value);      Prxy.TagStatus.SetValue(value); break;
	case SPU_Out_MBox_offs:     ConLog.Warning("RawSPUThread[%d]: Write32(SPU_Out_MBox, 0x%x)", m_index, value);        while(!SPU.Out_MBox.Push(value) && !Emu.IsStopped()) Sleep(1); break;
	case SPU_In_MBox_offs:
		ConLog.Warning("RawSPUThread[%d]: Write32(SPU_In_MBox, 0x%x)", m_index, value);
		SPU.In_MBox.PushUncond(value); //if In_MBox is already full, the last message will be overwritten  
	break;
	case SPU_MBox_Status_offs:  ConLog.Warning("RawSPUThread[%d]: Write32(SPU_MBox_Status, 0x%x)", m_index, value);     SPU.MBox_Status.SetValue(value); break;
	case SPU_RunCntl_offs:      ConLog.Warning("RawSPUThread[%d]: Write32(SPU_RunCntl, 0x%x)", m_index, value);         SPU.RunCntl.SetValue(value); break;
	case SPU_Status_offs:       ConLog.Warning("RawSPUThread[%d]: Write32(SPU_Status, 0x%x)", m_index, value);          SPU.Status.SetValue(value); break;
	case SPU_NPC_offs:          ConLog.Warning("RawSPUThread[%d]: Write32(SPU_NPC, 0x%x)", m_index, value);             SPU.NPC.SetValue(value); break;
	case SPU_RdSigNotify1_offs: ConLog.Warning("RawSPUThread[%d]: Write32(SPU_RdSigNotify1, 0x%x)", m_index, value);    SPU.SNR[0].SetValue(value); break;
	case SPU_RdSigNotify2_offs: ConLog.Warning("RawSPUThread[%d]: Write32(SPU_RdSigNotify2, 0x%x)", m_index, value);    SPU.SNR[1].SetValue(value); break;

	default:
		ConLog.Error("RawSPUThread[%d]: Write32(0x%x, 0x%x)", m_index, offset, value);
		Emu.Pause();
	break;
	}

	return true;
}
Beispiel #3
0
void SPUThread::WriteChannel(u32 ch, const u128& r)
{
	const u32 v = r._u32[3];

	switch (ch)
	{
	case SPU_WrOutIntrMbox:
	{
		if (!group) // if RawSPU
		{
			if (Ini.HLELogging.GetValue()) LOG_NOTICE(Log::SPU, "SPU_WrOutIntrMbox: interrupt(v=0x%x)", v);
			while (!SPU.Out_IntrMBox.Push(v))
			{
				std::this_thread::sleep_for(std::chrono::milliseconds(1));
				if (Emu.IsStopped())
				{
					LOG_WARNING(Log::SPU, "%s(%s) aborted", __FUNCTION__, spu_ch_name[ch]);
					return;
				}
			}
			m_intrtag[2].stat |= 1;
			if (CPUThread* t = Emu.GetCPU().GetThread(m_intrtag[2].thread))
			{
				if (t->GetType() == CPU_THREAD_PPU)
				{
					if (t->IsAlive())
					{
						LOG_ERROR(Log::SPU, "%s(%s): interrupt thread was alive", __FUNCTION__, spu_ch_name[ch]);
						Emu.Pause();
						return;
					}
					PPUThread& ppu = *(PPUThread*)t;
					ppu.GPR[3] = ppu.m_interrupt_arg;
					ppu.FastCall2(vm::read32(ppu.entry), vm::read32(ppu.entry + 4));
				}
			}
		}
		else
		{
			const u8 code = v >> 24;
			if (code < 64)
			{
				/* ===== sys_spu_thread_send_event (used by spu_printf) ===== */

				u8 spup = code & 63;

				u32 data;
				if (!SPU.Out_MBox.Pop(data))
				{
					LOG_ERROR(Log::SPU, "sys_spu_thread_send_event(v=0x%x, spup=%d): Out_MBox is empty", v, spup);
					return;
				}

				if (Ini.HLELogging.GetValue())
				{
					LOG_NOTICE(Log::SPU, "sys_spu_thread_send_event(spup=%d, data0=0x%x, data1=0x%x)", spup, v & 0x00ffffff, data);
				}

				EventPort& port = SPUPs[spup];

				std::lock_guard<std::mutex> lock(port.m_mutex);

				if (!port.eq)
				{
					LOG_WARNING(Log::SPU, "sys_spu_thread_send_event(spup=%d, data0=0x%x, data1=0x%x): event queue not connected", spup, (v & 0x00ffffff), data);
					SPU.In_MBox.PushUncond(CELL_ENOTCONN); // TODO: check error passing
					return;
				}

				if (!port.eq->events.push(SYS_SPU_THREAD_EVENT_USER_KEY, GetCurrentCPUThread()->GetId(), ((u64)spup << 32) | (v & 0x00ffffff), data))
				{
					SPU.In_MBox.PushUncond(CELL_EBUSY);
					return;
				}

				SPU.In_MBox.PushUncond(CELL_OK);
				return;
			}
			else if (code < 128)
			{
				/* ===== sys_spu_thread_throw_event ===== */

				const u8 spup = code & 63;

				u32 data;
				if (!SPU.Out_MBox.Pop(data))
				{
					LOG_ERROR(Log::SPU, "sys_spu_thread_throw_event(v=0x%x, spup=%d): Out_MBox is empty", v, spup);
					return;
				}

				//if (Ini.HLELogging.GetValue())
				{
					LOG_WARNING(Log::SPU, "sys_spu_thread_throw_event(spup=%d, data0=0x%x, data1=0x%x)", spup, v & 0x00ffffff, data);
				}

				EventPort& port = SPUPs[spup];

				std::lock_guard<std::mutex> lock(port.m_mutex);

				if (!port.eq)
				{
					LOG_WARNING(Log::SPU, "sys_spu_thread_throw_event(spup=%d, data0=0x%x, data1=0x%x): event queue not connected", spup, (v & 0x00ffffff), data);
					return;
				}

				// TODO: check passing spup value
				if (!port.eq->events.push(SYS_SPU_THREAD_EVENT_USER_KEY, GetCurrentCPUThread()->GetId(), ((u64)spup << 32) | (v & 0x00ffffff), data))
				{
					LOG_WARNING(Log::SPU, "sys_spu_thread_throw_event(spup=%d, data0=0x%x, data1=0x%x) failed (queue is full)", spup, (v & 0x00ffffff), data);
					return;
				}

				return;
			}
			else if (code == 128)
			{
				/* ===== sys_event_flag_set_bit ===== */
				u32 flag = v & 0xffffff;

				u32 data;
				if (!SPU.Out_MBox.Pop(data))
				{
					LOG_ERROR(Log::SPU, "sys_event_flag_set_bit(v=0x%x (flag=%d)): Out_MBox is empty", v, flag);
					return;
				}

				if (flag > 63)
				{
					LOG_ERROR(Log::SPU, "sys_event_flag_set_bit(id=%d, v=0x%x): flag > 63", data, v, flag);
					return;
				}

				//if (Ini.HLELogging.GetValue())
				{
					LOG_WARNING(Log::SPU, "sys_event_flag_set_bit(id=%d, v=0x%x (flag=%d))", data, v, flag);
				}

				EventFlag* ef;
				if (!Emu.GetIdManager().GetIDData(data, ef))
				{
					LOG_ERROR(Log::SPU, "sys_event_flag_set_bit(id=%d, v=0x%x (flag=%d)): EventFlag not found", data, v, flag);
					SPU.In_MBox.PushUncond(CELL_ESRCH);
					return;
				}

				u32 tid = GetCurrentCPUThread()->GetId();

				ef->m_mutex.lock(tid);
				ef->flags |= (u64)1 << flag;
				if (u32 target = ef->check())
				{
					// if signal, leave both mutexes locked...
					ef->signal.lock(target);
					ef->m_mutex.unlock(tid, target);
				}
				else
				{
					ef->m_mutex.unlock(tid);
				}

				SPU.In_MBox.PushUncond(CELL_OK);
				return;
			}
			else if (code == 192)
			{
				/* ===== sys_event_flag_set_bit_impatient ===== */
				u32 flag = v & 0xffffff;

				u32 data;
				if (!SPU.Out_MBox.Pop(data))
				{
					LOG_ERROR(Log::SPU, "sys_event_flag_set_bit_impatient(v=0x%x (flag=%d)): Out_MBox is empty", v, flag);
					return;
				}

				if (flag > 63)
				{
					LOG_ERROR(Log::SPU, "sys_event_flag_set_bit_impatient(id=%d, v=0x%x): flag > 63", data, v, flag);
					return;
				}

				//if (Ini.HLELogging.GetValue())
				{
					LOG_WARNING(Log::SPU, "sys_event_flag_set_bit_impatient(id=%d, v=0x%x (flag=%d))", data, v, flag);
				}

				EventFlag* ef;
				if (!Emu.GetIdManager().GetIDData(data, ef))
				{
					LOG_WARNING(Log::SPU, "sys_event_flag_set_bit_impatient(id=%d, v=0x%x (flag=%d)): EventFlag not found", data, v, flag);
					return;
				}

				u32 tid = GetCurrentCPUThread()->GetId();

				ef->m_mutex.lock(tid);
				ef->flags |= (u64)1 << flag;
				if (u32 target = ef->check())
				{
					// if signal, leave both mutexes locked...
					ef->signal.lock(target);
					ef->m_mutex.unlock(tid, target);
				}
				else
				{
					ef->m_mutex.unlock(tid);
				}

				return;
			}
			else
			{
				u32 data;
				if (SPU.Out_MBox.Pop(data))
				{
					LOG_ERROR(Log::SPU, "SPU_WrOutIntrMbox: unknown data (v=0x%x); Out_MBox = 0x%x", v, data);
				}
				else
				{
					LOG_ERROR(Log::SPU, "SPU_WrOutIntrMbox: unknown data (v=0x%x)", v);
				}
				SPU.In_MBox.PushUncond(CELL_EINVAL); // ???
				return;
			}
		}
		break;
	}

	case SPU_WrOutMbox:
	{
		while (!SPU.Out_MBox.Push(v) && !Emu.IsStopped()) std::this_thread::sleep_for(std::chrono::milliseconds(1));
		break;
	}

	case MFC_WrTagMask:
	{
		MFC1.QueryMask.SetValue(v);
		break;
	}

	case MFC_WrTagUpdate:
	{
		MFC1.TagStatus.PushUncond(MFC1.QueryMask.GetValue());
		break;
	}

	case MFC_LSA:
	{
		MFC1.LSA.SetValue(v);
		break;
	}

	case MFC_EAH:
	{
		MFC1.EAH.SetValue(v);
		break;
	}

	case MFC_EAL:
	{
		MFC1.EAL.SetValue(v);
		break;
	}

	case MFC_Size:
	{
		MFC1.Size_Tag.SetValue((MFC1.Size_Tag.GetValue() & 0xffff) | (v << 16));
		break;
	}

	case MFC_TagID:
	{
		MFC1.Size_Tag.SetValue((MFC1.Size_Tag.GetValue() & ~0xffff) | (v & 0xffff));
		break;
	}


	case MFC_Cmd:
	{
		MFC1.CMDStatus.SetValue(v);
		EnqMfcCmd(MFC1);
		break;
	}

	case MFC_WrListStallAck:
	{
		if (v >= 32)
		{
			LOG_ERROR(Log::SPU, "MFC_WrListStallAck error: invalid tag(%d)", v);
			return;
		}
		StalledList temp = StallList[v];
		if (!temp.MFCArgs)
		{
			LOG_ERROR(Log::SPU, "MFC_WrListStallAck error: empty tag(%d)", v);
			return;
		}
		StallList[v].MFCArgs = nullptr;
		ListCmd(temp.lsa, temp.ea, temp.tag, temp.size, temp.cmd, *temp.MFCArgs);
		break;
	}

	case SPU_WrDec:
	{
		m_dec_start = get_time();
		m_dec_value = v;
		break;
	}

	case SPU_WrEventMask:
	{
		m_event_mask = v;
		if (v & ~(SPU_EVENT_IMPLEMENTED)) LOG_ERROR(Log::SPU, "SPU_WrEventMask: unsupported event masked (0x%x)");
		break;
	}

	case SPU_WrEventAck:
	{
		m_events &= ~v;
		break;
	}

	default:
	{
		LOG_ERROR(Log::SPU, "%s error (v=0x%x): unknown/illegal channel (%d [%s]).", __FUNCTION__, v, ch, spu_ch_name[ch]);
		break;
	}
	}

	if (Emu.IsStopped()) LOG_WARNING(Log::SPU, "%s(%s) aborted", __FUNCTION__, spu_ch_name[ch]);
}