Skip to content

Commit 06fdac5

Browse files
authored
Merge pull request #1846 from nicolasnoble/ps1-packer-raw-icache
Ensuring ps1-packer's raw mode uses the i-cache.
2 parents 11ea342 + 882ef98 commit 06fdac5

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/supportpsx/ps1-packer.cc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ int16_t getLO(uint32_t v) {
7979

8080
void PCSX::PS1Packer::pack(IO<File> src, IO<File> dest, uint32_t addr, uint32_t pc, uint32_t gp, uint32_t sp,
8181
const Options& options) {
82-
constexpr size_t stubSize = 7 * 4;
82+
constexpr size_t stubSize = 12 * 4;
8383
std::vector<uint8_t> dataIn;
8484
dataIn.resize(src->size());
8585
src->read(dataIn.data(), dataIn.size());
@@ -134,7 +134,9 @@ void PCSX::PS1Packer::pack(IO<File> src, IO<File> dest, uint32_t addr, uint32_t
134134
// to be the same as our tload address, so we need to inject
135135
// a jump to the start of our code. We are doing this in
136136
// a fully position-independent way, so raw files can be
137-
// loaded anywhere in memory.
137+
// loaded anywhere in memory. We're also going to ensure
138+
// that we're jumping to a segment where the i-cache is
139+
// enabled, so the decompressor code can run fast.
138140
auto offset = newPC - 4 * 4;
139141
std::vector<uint8_t> stub;
140142
if (options.resetstack) {
@@ -145,9 +147,14 @@ void PCSX::PS1Packer::pack(IO<File> src, IO<File> dest, uint32_t addr, uint32_t
145147
pushBytes(stub, lui(Reg::T1, getHI(offset)));
146148
pushBytes(stub, bgezal(Reg::R0, 4));
147149
pushBytes(stub, addiu(Reg::T1, Reg::T1, getLO(offset)));
150+
pushBytes(stub, lui(Reg::T0, 0x1fff));
151+
pushBytes(stub, ori(Reg::T0, Reg::T0, 0xffff));
152+
pushBytes(stub, andd(Reg::RA, Reg::RA, Reg::T0));
153+
pushBytes(stub, lui(Reg::T0, 0x8000));
154+
pushBytes(stub, orr(Reg::RA, Reg::RA, Reg::T0));
148155
pushBytes(stub, addu(Reg::T0, Reg::RA, Reg::T1));
149156
pushBytes(stub, jr(Reg::T0));
150-
pushBytes(stub, addiu(Reg::A0, Reg::RA, 12));
157+
pushBytes(stub, addiu(Reg::A0, Reg::RA, 32));
151158

152159
assert(stub.size() == stubSize);
153160

0 commit comments

Comments
 (0)