Begun conversion for Ys1&2. (cdrom0 and some instructions)

git-svn-id: http://svn.purei.org/purei/trunk@226 b36208d7-6611-0410-8bec-b1987f11c4a2
This commit is contained in:
jpd002 2008-01-19 03:36:27 +00:00
parent a36b01dbbc
commit ff52e430f6
19 changed files with 222 additions and 97 deletions

View File

@ -1838,6 +1838,14 @@
RelativePath=".\Source\iop\IopBios.h"
>
</File>
<File
RelativePath=".\Source\iop\IsoDevice.cpp"
>
</File>
<File
RelativePath=".\Source\iop\IsoDevice.h"
>
</File>
</Filter>
</Filter>
<File

View File

@ -110,15 +110,15 @@ void CCOP_FPU::MTC1()
//06
void CCOP_FPU::CTC1()
{
CCodeGen::Begin(m_pB);
if(m_nFS == 31)
{
if(m_nFS == 31)
{
m_pB->PushAddr(&m_pCtx->m_State.nGPR[m_nFT].nV[0]);
m_pB->PullAddr(&m_pCtx->m_State.nFCSR);
}
m_codeGen->PushRel(offsetof(CMIPS, m_State.nGPR[m_nFT].nV[0]));
m_codeGen->PullRel(offsetof(CMIPS, m_State.nFCSR));
}
CCodeGen::End();
else
{
assert(0);
}
}
//08
@ -284,14 +284,10 @@ void CCOP_FPU::NEG_S()
//18
void CCOP_FPU::ADDA_S()
{
CCodeGen::Begin(m_pB);
{
CFPU::PushSingle(&m_pCtx->m_State.nCOP10[m_nFS * 2]);
CFPU::PushSingle(&m_pCtx->m_State.nCOP10[m_nFT * 2]);
CFPU::Add();
CFPU::PullSingle(&m_pCtx->m_State.nCOP1A);
}
CCodeGen::End();
m_codeGen->FP_PushSingle(offsetof(CMIPS, m_State.nCOP10[m_nFS * 2]));
m_codeGen->FP_PushSingle(offsetof(CMIPS, m_State.nCOP10[m_nFT * 2]));
m_codeGen->FP_Add();
m_codeGen->FP_PullSingle(offsetof(CMIPS, m_State.nCOP1A));
}
//1A

View File

@ -2435,6 +2435,11 @@ void CCodeGen::Xor()
PushReg(resultRegister);
}
else if(FitsPattern<ConstantConstant>())
{
ConstantConstant::PatternValue ops(GetPattern<ConstantConstant>());
PushCst(ops.first ^ ops.second);
}
else
{
assert(0);

View File

@ -151,6 +151,7 @@ public:
virtual void MD_PullRel(size_t);
void MD_PushReg(XMMREGISTER);
void MD_AddWUS();
void MD_And();
void MD_Not();
void MD_Or();

View File

@ -50,6 +50,42 @@ void CCodeGen::MD_PushReg(XMMREGISTER registerId)
m_Shadow.Push(REGISTER128);
}
void CCodeGen::MD_AddWUS()
{
if(FitsPattern<RelativeRelative128>())
{
RelativeRelative128::PatternValue ops(GetPattern<RelativeRelative128>());
unsigned int tempRegister = AllocateRegister();
XMMREGISTER resultRegister = AllocateXmmRegister();
for(int i = 3; i >= 0; i--)
{
CX86Assembler::LABEL overflowLabel = m_Assembler.CreateLabel();
CX86Assembler::LABEL doneLabel = m_Assembler.CreateLabel();
m_Assembler.MovEd(m_nRegisterLookupEx[tempRegister],
CX86Assembler::MakeIndRegOffAddress(g_nBaseRegister, ops.first + (i * 4)));
m_Assembler.AddEd(m_nRegisterLookupEx[tempRegister],
CX86Assembler::MakeIndRegOffAddress(g_nBaseRegister, ops.second + (i * 4)));
m_Assembler.JcJb(overflowLabel);
m_Assembler.PushEd(CX86Assembler::MakeRegisterAddress(m_nRegisterLookupEx[tempRegister]));
m_Assembler.JmpJb(doneLabel);
m_Assembler.MarkLabel(overflowLabel);
m_Assembler.PushId(0xFFFFFFFF);
m_Assembler.MarkLabel(doneLabel);
}
FreeRegister(tempRegister);
m_Assembler.ResolveLabelReferences();
m_Assembler.MovdquVo(resultRegister,
CX86Assembler::MakeIndRegAddress(CX86Assembler::rSP));
m_Assembler.AddId(CX86Assembler::MakeRegisterAddress(CX86Assembler::rSP),
0x10);
MD_PushReg(resultRegister);
}
else
{
assert(0);
}
}
void CCodeGen::MD_And()
{
if(FitsPattern<RelativeRelative128>())

View File

@ -132,14 +132,13 @@ void CMA_EE::MTSAB()
//19
void CMA_EE::MTSAH()
{
m_pB->PushImm(m_nImmediate & 0x07);
m_pB->PushAddr(&m_pCtx->m_State.nGPR[m_nRS].nV[0]);
m_pB->AndImm(0x07);
m_pB->Xor();
m_pB->SllImm(0x04);
m_pB->PullAddr(&m_pCtx->m_State.nSA);
m_codeGen->PushRel(offsetof(CMIPS, m_State.nGPR[m_nRS].nV[0]));
m_codeGen->PushCst(0x07);
m_codeGen->And();
m_codeGen->PushCst(m_nImmediate & 0x07);
m_codeGen->Xor();
m_codeGen->Shl(0x04);
m_codeGen->PullRel(offsetof(CMIPS, m_State.nSA));
}
//////////////////////////////////////////////////
@ -253,11 +252,11 @@ void CMA_EE::MFHI1()
//11
void CMA_EE::MTHI1()
{
m_pB->PushAddr(&m_pCtx->m_State.nGPR[m_nRS].nV[0]);
m_pB->PullAddr(&m_pCtx->m_State.nHI1[0]);
m_codeGen->PushRel(offsetof(CMIPS, m_State.nGPR[m_nRS].nV[0]));
m_codeGen->PullRel(offsetof(CMIPS, m_State.nHI1[0]));
m_pB->PushAddr(&m_pCtx->m_State.nGPR[m_nRS].nV[1]);
m_pB->PullAddr(&m_pCtx->m_State.nHI1[1]);
m_codeGen->PushRel(offsetof(CMIPS, m_State.nGPR[m_nRS].nV[1]));
m_codeGen->PullRel(offsetof(CMIPS, m_State.nHI1[1]));
}
//12
@ -273,11 +272,11 @@ void CMA_EE::MFLO1()
//13
void CMA_EE::MTLO1()
{
m_pB->PushAddr(&m_pCtx->m_State.nGPR[m_nRS].nV[0]);
m_pB->PullAddr(&m_pCtx->m_State.nLO1[0]);
m_codeGen->PushRel(offsetof(CMIPS, m_State.nGPR[m_nRS].nV[0]));
m_codeGen->PullRel(offsetof(CMIPS, m_State.nLO1[0]));
m_pB->PushAddr(&m_pCtx->m_State.nGPR[m_nRS].nV[1]);
m_pB->PullAddr(&m_pCtx->m_State.nLO1[1]);
m_codeGen->PushRel(offsetof(CMIPS, m_State.nGPR[m_nRS].nV[1]));
m_codeGen->PullRel(offsetof(CMIPS, m_State.nLO1[1]));
}
//18
@ -562,14 +561,10 @@ void CMA_EE::PMINH()
//10
void CMA_EE::PADDUW()
{
CCodeGen::Begin(m_pB);
{
PushVector(m_nRS);
PushVector(m_nRT);
CVUI128::AddWUS();
PullVector(m_nRD);
}
CCodeGen::End();
PushVector(m_nRS);
PushVector(m_nRT);
m_codeGen->MD_AddWUS();
PullVector(m_nRD);
}
//12

View File

@ -883,11 +883,11 @@ void CMA_MIPSIV::MFHI()
//11
void CMA_MIPSIV::MTHI()
{
m_pB->PushAddr(&m_pCtx->m_State.nGPR[m_nRS].nV[0]);
m_pB->PullAddr(&m_pCtx->m_State.nHI[0]);
m_codeGen->PushRel(offsetof(CMIPS, m_State.nGPR[m_nRS].nV[0]));
m_codeGen->PullRel(offsetof(CMIPS, m_State.nHI[0]));
m_pB->PushAddr(&m_pCtx->m_State.nGPR[m_nRS].nV[1]);
m_pB->PullAddr(&m_pCtx->m_State.nHI[1]);
m_codeGen->PushRel(offsetof(CMIPS, m_State.nGPR[m_nRS].nV[1]));
m_codeGen->PullRel(offsetof(CMIPS, m_State.nHI[1]));
}
//12

View File

@ -20,6 +20,7 @@
#include "xml/Parser.h"
#include "xml/FilteringNodeIterator.h"
#include "Log.h"
#include "iop/IopBios.h"
// PS2OS Memory Allocation
// Start End Description
@ -55,7 +56,7 @@ using namespace Framework;
using namespace std;
using namespace boost;
CPS2OS::CPS2OS(CMIPS& ee, CMIPS& vu1, uint8* ram, uint8* bios, CGSHandler*& gs, CSIF& sif) :
CPS2OS::CPS2OS(CMIPS& ee, CMIPS& vu1, uint8* ram, uint8* bios, CGSHandler*& gs, CSIF& sif, CIopBios& iopBios) :
m_ee(ee),
m_vu1(vu1),
m_gs(gs),
@ -63,7 +64,8 @@ m_pELF(NULL),
m_ram(ram),
m_bios(bios),
m_pThreadSchedule(NULL),
m_sif(sif)
m_sif(sif),
m_iopBios(iopBios)
{
Initialize();
}
@ -176,54 +178,72 @@ void CPS2OS::DumpDmacHandlers()
void CPS2OS::BootFromFile(const char* sPath)
{
filesystem::path ExecPath(sPath, filesystem::native);
LoadELF(new CStdStream(fopen(ExecPath.string().c_str(), "rb")), ExecPath.leaf().c_str());
CStdStream stream(fopen(ExecPath.string().c_str(), "rb"));
LoadELF(stream, ExecPath.leaf().c_str());
}
void CPS2OS::BootFromCDROM()
{
CStream* pFile;
string sLine;
const char* sExecPath;
const char* sExecName;
string executablePath;
Iop::CIoman* ioman = m_iopBios.GetIoman();
assert(0);
// pFile = CSIF::GetFileIO()->GetFile(IOP::CFileIO::O_RDONLY, "cdrom0:SYSTEM.CNF");
if(pFile == NULL)
{
throw runtime_error("No 'SYSTEM.CNF' file found on the cdrom0 device.");
}
{
uint32 handle = ioman->Open(Iop::Ioman::CDevice::O_RDONLY, "cdrom0:SYSTEM.CNF");
if(static_cast<int32>(handle) < 0)
{
throw runtime_error("No 'SYSTEM.CNF' file found on the cdrom0 device.");
}
sExecPath = NULL;
{
CStream* file(ioman->GetFileStream(handle));
string line;
Utils::GetLine(pFile, &sLine);
while(!pFile->IsEOF())
{
if(!strncmp(sLine.c_str(), "BOOT2", 5))
{
sExecPath = strstr(sLine.c_str(), "=");
if(sExecPath != NULL)
{
sExecPath++;
if(sExecPath[0] == ' ') sExecPath++;
break;
}
}
Utils::GetLine(pFile, &sLine);
}
Utils::GetLine(file, &line);
while(!file->IsEOF())
{
if(!strncmp(line.c_str(), "BOOT2", 5))
{
const char* tempPath = strstr(line.c_str(), "=");
if(tempPath != NULL)
{
tempPath++;
if(tempPath[0] == ' ') tempPath++;
executablePath = tempPath;
break;
}
}
Utils::GetLine(file, &line);
}
}
delete pFile;
ioman->Close(handle);
}
if(sExecPath == NULL)
if(executablePath.length() == 0)
{
throw runtime_error("Error parsing 'SYSTEM.CNF' for a BOOT2 value.");
}
// pFile = CSIF::GetFileIO()->GetFile(IOP::CFileIO::O_RDONLY, sExecPath);
{
uint32 handle = ioman->Open(Iop::Ioman::CDevice::O_RDONLY, executablePath.c_str());
if(static_cast<int32>(handle) < 0)
{
throw runtime_error("Couldn't open executable specified in SYSTEM.CNF.");
}
sExecName = strchr(sExecPath, ':') + 1;
if(sExecName[0] == '/' || sExecName[0] == '\\') sExecName++;
try
{
const char* executableName = strchr(executablePath.c_str(), ':') + 1;
if(executableName[0] == '/' || executableName[0] == '\\') executableName++;
CStream* file(ioman->GetFileStream(handle));
LoadELF(*file, executableName);
}
catch(...)
{
LoadELF(pFile, sExecName);
}
ioman->Close(handle);
}
}
CELF* CPS2OS::GetELF()
@ -236,18 +256,16 @@ const char* CPS2OS::GetExecutableName()
return m_sExecutableName.c_str();
}
void CPS2OS::LoadELF(CStream* pStream, const char* sExecName)
void CPS2OS::LoadELF(CStream& stream, const char* sExecName)
{
CELF* pELF;
try
{
pELF = new CELF(pStream);
delete pStream;
pELF = new CELF(&stream);
}
catch(const exception& Exception)
{
delete pStream;
throw Exception;
}

View File

@ -8,10 +8,12 @@
#include "GSHandler.h"
#include "SIF.h"
class CIopBios;
class CPS2OS
{
public:
CPS2OS(CMIPS&, CMIPS&, uint8*, uint8*, CGSHandler*&, CSIF&);
CPS2OS(CMIPS&, CMIPS&, uint8*, uint8*, CGSHandler*&, CSIF&, CIopBios&);
virtual ~CPS2OS();
void Initialize();
@ -194,7 +196,7 @@ private:
typedef void (CPS2OS::*SystemCallHandler)();
void LoadELF(Framework::CStream*, const char*);
void LoadELF(Framework::CStream&, const char*);
void LoadExecutable();
void UnloadExecutable();
@ -294,6 +296,7 @@ private:
uint8* m_bios;
CGSHandler*& m_gs;
CSIF& m_sif;
CIopBios& m_iopBios;
};
#endif

View File

@ -1,6 +1,7 @@
#include <stdio.h>
#include <exception>
#include "PS2VM.h"
#include "PS2OS.h"
#include "Ps2Const.h"
#include "IPU.h"
#include "VIF.h"
@ -22,6 +23,7 @@
#include "Profiler.h"
#include "iop/IopBios.h"
#include "iop/DirectoryDevice.h"
#include "iop/IsoDevice.h"
#define STATE_EE ("ee")
#define STATE_VU1 ("vu1")
@ -91,8 +93,8 @@ m_intc(m_dmac)
CConfig::GetInstance()->RegisterPreferenceString(PREF_PS2_MC0_DIRECTORY, PREF_PS2_MC0_DIRECTORY_DEFAULT);
CConfig::GetInstance()->RegisterPreferenceString(PREF_PS2_MC1_DIRECTORY, PREF_PS2_MC1_DIRECTORY_DEFAULT);
m_os = new CPS2OS(m_EE, m_VU1, m_pRAM, m_pBIOS, m_pGS, m_sif);
m_iopOs = new CIopBios(0x100, m_iop, m_iopRam, PS2::IOPRAMSIZE, m_sif);
m_os = new CPS2OS(m_EE, m_VU1, m_pRAM, m_pBIOS, m_pGS, m_sif, *m_iopOs);
}
CPS2VM::~CPS2VM()
@ -353,9 +355,10 @@ void CPS2VM::ResetVM()
m_os->Initialize();
m_iopOs->Reset();
m_iopOs->GetIoman()->RegisterDevice("host", new CDirectoryDevice(PREF_PS2_HOST_DIRECTORY));
m_iopOs->GetIoman()->RegisterDevice("mc0", new CDirectoryDevice(PREF_PS2_MC0_DIRECTORY));
m_iopOs->GetIoman()->RegisterDevice("mc1", new CDirectoryDevice(PREF_PS2_MC1_DIRECTORY));
m_iopOs->GetIoman()->RegisterDevice("host", new Iop::Ioman::CDirectoryDevice(PREF_PS2_HOST_DIRECTORY));
m_iopOs->GetIoman()->RegisterDevice("mc0", new Iop::Ioman::CDirectoryDevice(PREF_PS2_MC0_DIRECTORY));
m_iopOs->GetIoman()->RegisterDevice("mc1", new Iop::Ioman::CDirectoryDevice(PREF_PS2_MC1_DIRECTORY));
m_iopOs->GetIoman()->RegisterDevice("cdrom0", new Iop::Ioman::CIsoDevice(m_pCDROM0));
RegisterModulesInPadHandler();
}

View File

@ -3,7 +3,6 @@
#include <boost/thread.hpp>
#include "Types.h"
#include "PS2OS.h"
#include "DMAC.h"
#include "GIF.h"
#include "SIF.h"
@ -18,6 +17,7 @@
#include "MipsExecutor.h"
class CIopBios;
class CPS2OS;
enum PS2VM_MSG
{

View File

@ -280,6 +280,13 @@ void CX86Assembler::JaeJb(LABEL label)
WriteByte(0x00);
}
void CX86Assembler::JcJb(LABEL label)
{
WriteByte(0x72);
CreateLabelReference(label, 1);
WriteByte(0x00);
}
void CX86Assembler::JeJb(LABEL label)
{
WriteByte(0x74);

View File

@ -126,6 +126,7 @@ public:
void IdivEd(const CAddress&);
void ImulEd(const CAddress&);
void JaeJb(LABEL);
void JcJb(LABEL);
void JeJb(LABEL);
void JmpJb(LABEL);
void JneJb(LABEL);

View File

@ -4,6 +4,7 @@
using namespace Framework;
using namespace std;
using namespace Iop::Ioman;
CDirectoryDevice::CDirectoryDevice(const char* basePathPreferenceName) :
m_basePathPreferenceName(basePathPreferenceName)

View File

@ -4,15 +4,21 @@
#include <string>
#include "Ioman_Device.h"
class CDirectoryDevice : public Iop::Ioman::CDevice
namespace Iop
{
public:
CDirectoryDevice(const char*);
virtual ~CDirectoryDevice();
virtual Framework::CStream* GetFile(uint32, const char*);
namespace Ioman
{
class CDirectoryDevice : public CDevice
{
public:
CDirectoryDevice(const char*);
virtual ~CDirectoryDevice();
virtual Framework::CStream* GetFile(uint32, const char*);
private:
std::string m_basePathPreferenceName;
};
private:
std::string m_basePathPreferenceName;
};
}
}
#endif

21
Source/iop/IsoDevice.cpp Normal file
View File

@ -0,0 +1,21 @@
#include "IsoDevice.h"
using namespace Framework;
using namespace Iop::Ioman;
CIsoDevice::CIsoDevice(CISO9660*& iso) :
m_iso(iso)
{
}
CIsoDevice::~CIsoDevice()
{
}
CStream* CIsoDevice::GetFile(uint32 mode, const char* devicePath)
{
if(mode != O_RDONLY) return NULL;
return m_iso->Open(devicePath);
}

24
Source/iop/IsoDevice.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef _ISODEVICE_H_
#define _ISODEVICE_H_
#include "Ioman_Device.h"
#include "../ISO9660/ISO9660.h"
namespace Iop
{
namespace Ioman
{
class CIsoDevice : public CDevice
{
public:
CIsoDevice(CISO9660*&);
virtual ~CIsoDevice();
virtual Framework::CStream* GetFile(uint32, const char*);
private:
CISO9660*& m_iso;
};
}
}
#endif

Binary file not shown.

Binary file not shown.