Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ps2-packer.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,11 +501,13 @@ void packing(FILE * out, FILE * in, u32 base) {
pdata = (loadbuf + eph[i].offset);
section_size = eph[i].filesz;

psh.originalSize = section_size;
psh.virtualAddr = eph[i].vaddr;
psh.zeroByteSize = eph[i].memsz - eph[i].filesz;

remove_section_zeroes(pdata, &section_size, &psh.zeroByteSize);
/* The stub decompresses originalSize bytes and zero-fills from there, so it must be the
trimmed size: the bytes remove_section_zeroes() took off the end are now in zeroByteSize. */
psh.originalSize = section_size;
printv("Loaded section: %08X bytes (with %08X zeroes) based at %08X\n", psh.originalSize, psh.zeroByteSize, psh.virtualAddr);

#ifndef PS2_PACKER_LITE
Expand Down
22 changes: 15 additions & 7 deletions stub/main-kmode.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,27 @@

#include "packer-stub.h"

/* Zero exactly [ptr, ptr + size). ptr and the loop flag are written by the asm, so they are output
operands, and the flag is early-clobber so it cannot share a register with end. */
static void fast_memzero(u8 * ptr, u32 size) {
u32 t;
u8 * end = ptr + size;
u32 more;
if (!size)
return;
__asm__ volatile ("\n"
"\taddu %0, %1, %2\n"
"\t.set push\n"
"\t.set noreorder\n"
"1:\n"
"\tnop\n"
"\tnop\n"
"\tnop\n"
"\tsb $0, 0(%1)\n"
"\tsltu %2, %1, %0\n"
"\taddiu %1, 1\n"
"\tbnez %2, 1b\n"
: "=r" (t) : "r" (ptr), "r" (size)
"\tsb $0, 0(%0)\n"
"\taddiu %0, %0, 1\n"
"\tsltu %1, %0, %2\n"
"\tbnez %1, 1b\n"
"\tnop\n"
"\t.set pop\n"
: "+r" (ptr), "=&r" (more) : "r" (end) : "memory"
);
}

Expand Down
22 changes: 15 additions & 7 deletions stub/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,27 @@
#include "packer-stub.h"

#if 1
/* Zero exactly [ptr, ptr + size). ptr and the loop flag are written by the asm, so they are output
operands, and the flag is early-clobber so it cannot share a register with end. */
static void fast_memzero(u8 * ptr, u32 size) {
u32 t;
u8 * end = ptr + size;
u32 more;
if (!size)
return;
__asm__ volatile ("\n"
"\taddu %0, %1, %2\n"
"\t.set push\n"
"\t.set noreorder\n"
"1:\n"
"\tnop\n"
"\tnop\n"
"\tnop\n"
"\tsb $0, 0(%1)\n"
"\tsltu %2, %1, %0\n"
"\taddiu %1, 1\n"
"\tbnez %2, 1b\n"
: "=r" (t) : "r" (ptr), "r" (size)
"\tsb $0, 0(%0)\n"
"\taddiu %0, %0, 1\n"
"\tsltu %1, %0, %2\n"
"\tbnez %1, 1b\n"
"\tnop\n"
"\t.set pop\n"
: "+r" (ptr), "=&r" (more) : "r" (end) : "memory"
);
}
#elif 1
Expand Down
Loading