(WiiU) Cleanups in aux code

This commit is contained in:
libretroadmin 2022-11-22 06:08:17 +01:00
parent 8db6197e4b
commit a93a2186c0
4 changed files with 68 additions and 143 deletions

View File

@ -91,6 +91,7 @@ void *getApplicationEndAddr(void)
/* Create memory areas arrays */ /* Create memory areas arrays */
static void memoryInitAreaTable(u32 args_size) static void memoryInitAreaTable(u32 args_size)
{ {
int i = 0;
u32 ApplicationMemoryEnd = (u32)getApplicationEndAddr() + args_size; u32 ApplicationMemoryEnd = (u32)getApplicationEndAddr() + args_size;
/* This one seems to be available on every firmware and therefore its our code area but also our main RPX area behind our code */ /* This one seems to be available on every firmware and therefore its our code area but also our main RPX area behind our code */
@ -100,7 +101,6 @@ static void memoryInitAreaTable(u32 args_size)
const memory_values_t * mem_vals = mem_vals_540; const memory_values_t * mem_vals = mem_vals_540;
/* Fill entries */ /* Fill entries */
int i = 0;
while (mem_vals[i].start_address) while (mem_vals[i].start_address)
{ {
memoryAddArea(mem_vals[i].start_address, mem_vals[i].end_address, i + 1); memoryAddArea(mem_vals[i].start_address, mem_vals[i].end_address, i + 1);
@ -124,8 +124,6 @@ static int HomebrewCopyMemory(u8 *address, u32 bytes, u32 args_size)
if (*(u16 *)&address[7] != 0xCAFE) if (*(u16 *)&address[7] != 0xCAFE)
{ {
/* assume ELF */ /* assume ELF */
printf("loading ELF file \n");
ELF_DATA_ADDR = (u32)getApplicationEndAddr() + args_size; ELF_DATA_ADDR = (u32)getApplicationEndAddr() + args_size;
if (ELF_DATA_ADDR >= 0x01000000) if (ELF_DATA_ADDR >= 0x01000000)
return -1; return -1;
@ -133,8 +131,6 @@ static int HomebrewCopyMemory(u8 *address, u32 bytes, u32 args_size)
else else
{ {
/* RPX */ /* RPX */
printf("loading RPX file \n");
ELF_DATA_ADDR = MEM_AREA_TABLE->address; ELF_DATA_ADDR = MEM_AREA_TABLE->address;
} }
@ -150,13 +146,14 @@ static int HomebrewCopyMemory(u8 *address, u32 bytes, u32 args_size)
} }
else else
{ {
u32 done = 0;
u32 mapPosition = 0;
DCFlushRange(address, bytes); DCFlushRange(address, bytes);
u32 done = 0;
u32 addressPhysical = (u32)OSEffectiveToPhysical(address); u32 addressPhysical = (u32)OSEffectiveToPhysical(address);
s_mem_area *mem_map = MEM_AREA_TABLE; s_mem_area *mem_map = MEM_AREA_TABLE;
u32 mapPosition = 0;
while ((done < bytes) && mem_map) while ((done < bytes) && mem_map)
{ {
@ -200,14 +197,14 @@ static int HomebrewCopyMemory(u8 *address, u32 bytes, u32 args_size)
*/ */
void log_rpx(const char *filepath, unsigned char *buf, size_t len) void log_rpx(const char *filepath, unsigned char *buf, size_t len)
{ {
int i;
unsigned int line_buffer[LINE_LEN]; unsigned int line_buffer[LINE_LEN];
int i, offset;
RARCH_LOG("=== BEGIN file=%s size=%d ===\n", filepath, len); RARCH_LOG("=== BEGIN file=%s size=%d ===\n", filepath, len);
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
{ {
offset = i % LINE_LEN; int offset = i % LINE_LEN;
line_buffer[offset] = buf[i]; line_buffer[offset] = buf[i];
if (offset == (LINE_LEN-1)) if (offset == (LINE_LEN-1))
@ -239,86 +236,66 @@ void log_rpx(const char *filepath, unsigned char *buf, size_t len)
} }
RARCH_LOG("=== END %s ===\n", filepath); RARCH_LOG("=== END %s ===\n", filepath);
} }
#endif #endif
int HBL_loadToMemory(const char *filepath, u32 args_size) int HBL_loadToMemory(const char *filepath, u32 args_size)
{ {
int ret;
FILE *fp;
u32 bytesRead = 0;
u3 fileSize = 0;
if (!filepath || !*filepath) if (!filepath || !*filepath)
return -1; return -1;
printf("Loading file %s\n", filepath); if (!(fp = fopen(filepath, "rb")))
FILE *fp = fopen(filepath, "rb");
if (!fp)
{
printf("failed to open file %s\n", filepath);
return -1; return -1;
}
u32 bytesRead = 0;
fseek(fp, 0, SEEK_END); fseek(fp, 0, SEEK_END);
u32 fileSize = ftell(fp); fileSize = ftell(fp);
fseek(fp, 0, SEEK_SET); fseek(fp, 0, SEEK_SET);
size_t buffer_size = (fileSize + 0x3f) & ~0x3f; size_t buffer_size = (fileSize + 0x3f) & ~0x3f;
unsigned char *buffer = (unsigned char *) memalign(0x40, buffer_size); unsigned char *buffer = (unsigned char *) memalign(0x40, buffer_size);
if (!buffer) if (!buffer)
{
printf("Not enough memory\n");
return -1; return -1;
}
memset(buffer, 0, buffer_size); memset(buffer, 0, buffer_size);
/* Copy rpl in memory */ /* Copy rpl in memory */
while (bytesRead < fileSize) while (bytesRead < fileSize)
{ {
printf("progress: %f \r", 100.0f * (f32)bytesRead / (f32)fileSize); int ret;
u32 blockSize = 0x8000; u32 blockSize = 0x8000;
if (blockSize > (fileSize - bytesRead)) if (blockSize > (fileSize - bytesRead))
blockSize = fileSize - bytesRead; blockSize = fileSize - bytesRead;
int ret = fread(buffer + bytesRead, 1, blockSize, fp); ret = fread(buffer + bytesRead, 1, blockSize, fp);
if (ret <= 0) if (ret <= 0)
{
printf("Failure on reading file %s\n", filepath);
break; break;
}
bytesRead += ret; bytesRead += ret;
} }
printf("progress: %f \n", 100.0f * (f32)bytesRead / (f32)fileSize);
if (bytesRead != fileSize) if (bytesRead != fileSize)
{ {
free(buffer); free(buffer);
printf("File loading not finished for file %s, finished %" PRIi32 " of %" PRIi32 " bytes\n", filepath, bytesRead,
fileSize);
printf("File read failure");
return -1; return -1;
} }
#ifdef WIIU_LOG_RPX #ifdef WIIU_LOG_RPX
log_rpx(filepath, buffer, bytesRead); log_rpx(filepath, buffer, bytesRead);
#endif #endif
int ret = HomebrewCopyMemory(buffer, bytesRead, args_size); ret = HomebrewCopyMemory(buffer, bytesRead, args_size);
free(buffer); free(buffer);
if (ret < 0) if (ret < 0)
{
printf("Not enough memory");
return -1; return -1;
}
return fileSize; return fileSize;
} }

View File

@ -163,13 +163,10 @@ static bool try_init_iosuhax(void)
int result = IOSUHAX_Open(NULL); int result = IOSUHAX_Open(NULL);
if (result < 0) if (result < 0)
result = MCPHookOpen(); result = MCPHookOpen();
if (result >= 0)
if (result < 0)
return false;
return true; return true;
#else /* don't HAVE_IOSUHAX */ #endif /* HAVE_IOSUHAX */
return false; return false;
#endif
} }
static void try_shutdown_iosuhax(void) static void try_shutdown_iosuhax(void)

View File

@ -98,7 +98,8 @@ void GX2SetShader(GX2Shader *shader)
GX2SetGeometryShader(&shader->gs); GX2SetGeometryShader(&shader->gs);
} }
void dump_vs_data(GX2VertexShader* vs) #if 0
static void dump_vs_data(GX2VertexShader* vs)
{ {
unsigned i; unsigned i;
@ -153,7 +154,7 @@ void dump_vs_data(GX2VertexShader* vs)
} }
} }
void dump_ps_data(GX2PixelShader* ps) static void dump_ps_data(GX2PixelShader* ps)
{ {
unsigned i; unsigned i;
@ -197,10 +198,9 @@ void dump_ps_data(GX2PixelShader* ps)
DEBUG_INT(ps->samplerVars[i].type); DEBUG_INT(ps->samplerVars[i].type);
DEBUG_INT(ps->samplerVars[i].location); DEBUG_INT(ps->samplerVars[i].location);
} }
} }
void check_shader_verbose(u32 *shader, u32 shader_size, u32 *org, u32 org_size, const char *name) static void check_shader_verbose(u32 *shader, u32 shader_size, u32 *org, u32 org_size, const char *name)
{ {
unsigned i; unsigned i;
@ -225,7 +225,8 @@ void check_shader_verbose(u32 *shader, u32 shader_size, u32 *org, u32 org_size,
__builtin_bswap32(org[i])); __builtin_bswap32(org[i]));
} }
} }
void check_shader(const void *shader_, u32 shader_size, const void *org_, u32 org_size, const char *name)
static void check_shader(const void *shader_, u32 shader_size, const void *org_, u32 org_size, const char *name)
{ {
unsigned i; unsigned i;
bool different = false; bool different = false;
@ -255,6 +256,7 @@ void check_shader(const void *shader_, u32 shader_size, const void *org_, u32 or
printf("\n"); printf("\n");
} }
#endif
#define MAKE_MAGIC(c0,c1,c2,c3) ((c0 << 24) |(c1 << 16) |(c2 << 8) |(c3 << 0)) #define MAKE_MAGIC(c0,c1,c2,c3) ((c0 << 24) |(c1 << 16) |(c2 << 8) |(c3 << 0))
@ -339,16 +341,10 @@ static bool gfd_relocate_block(GFDBlock* block)
GFDRelocationHeader* rel = (GFDRelocationHeader*)(block->data + block->header.dataSize) - 1; GFDRelocationHeader* rel = (GFDRelocationHeader*)(block->data + block->header.dataSize) - 1;
if (rel->magic != GFD_BLOCK_RELOCATIONS_MAGIC) if (rel->magic != GFD_BLOCK_RELOCATIONS_MAGIC)
{
printf("wrong relocations magic number.\n");
return false; return false;
}
if ((rel->patchOffset & GFD_RELOCATIONS_TYPE_MASK) != GFD_RELOCATIONS_DATA) if ((rel->patchOffset & GFD_RELOCATIONS_TYPE_MASK) != GFD_RELOCATIONS_DATA)
{
printf("wrong data relocations mask.\n");
return false; return false;
}
u32* patches = (u32*)(block->data + (rel->patchOffset & GFD_RELOCATIONS_VALUE_MASK)); u32* patches = (u32*)(block->data + (rel->patchOffset & GFD_RELOCATIONS_VALUE_MASK));
@ -357,18 +353,12 @@ static bool gfd_relocate_block(GFDBlock* block)
if (patches[i]) if (patches[i])
{ {
if ((patches[i] & GFD_RELOCATIONS_TYPE_MASK) != GFD_RELOCATIONS_DATA) if ((patches[i] & GFD_RELOCATIONS_TYPE_MASK) != GFD_RELOCATIONS_DATA)
{
printf("wrong patch relocations mask.\n");
return false; return false;
}
u32* ptr = (u32*)(block->data + (patches[i] & GFD_RELOCATIONS_VALUE_MASK)); u32* ptr = (u32*)(block->data + (patches[i] & GFD_RELOCATIONS_VALUE_MASK));
if ((((*ptr) & GFD_RELOCATIONS_TYPE_MASK) != GFD_RELOCATIONS_DATA) && if ((((*ptr) & GFD_RELOCATIONS_TYPE_MASK) != GFD_RELOCATIONS_DATA) &&
(((*ptr) & GFD_RELOCATIONS_TYPE_MASK) != GFD_RELOCATIONS_TEXT)) (((*ptr) & GFD_RELOCATIONS_TYPE_MASK) != GFD_RELOCATIONS_TEXT))
{
printf("wrong relocations mask.\n");
return false; return false;
}
*ptr = (u32)block->data + ((*ptr) & GFD_RELOCATIONS_VALUE_MASK); *ptr = (u32)block->data + ((*ptr) & GFD_RELOCATIONS_VALUE_MASK);
} }
} }
@ -378,14 +368,15 @@ static bool gfd_relocate_block(GFDBlock* block)
GFDFile *gfd_open(const char *filename) GFDFile *gfd_open(const char *filename)
{ {
GFDFile* gfd = calloc(1, sizeof(*gfd)); int size;
GFDFile* gfd = (GFDFile*)calloc(1, sizeof(*gfd));
FILE *fp = fopen(filename, "rb"); FILE *fp = fopen(filename, "rb");
if (!fp) if (!fp)
goto error; goto error;
fseek(fp, 0, SEEK_END); fseek(fp, 0, SEEK_END);
int size = ftell(fp); size = ftell(fp);
fseek(fp, 0, SEEK_SET); fseek(fp, 0, SEEK_SET);
gfd->data = MEM2_alloc(size, GX2_SHADER_ALIGNMENT); gfd->data = MEM2_alloc(size, GX2_SHADER_ALIGNMENT);
fread(gfd->data, 1, size, fp); fread(gfd->data, 1, size, fp);
@ -394,56 +385,32 @@ GFDFile *gfd_open(const char *filename)
GFDFileHeader *header = (GFDFileHeader *)gfd->data; GFDFileHeader *header = (GFDFileHeader *)gfd->data;
if (header->magic != GFD_FILE_MAGIC) if (header->magic != GFD_FILE_MAGIC)
{
printf("wrong file magic number.\n");
goto error; goto error;
}
if (header->headerSize != sizeof(GFDFileHeader)) if (header->headerSize != sizeof(GFDFileHeader))
{
printf("wrong file header size.\n");
goto error; goto error;
}
if (header->majorVersion != GFD_FILE_MAJOR_VERSION) if (header->majorVersion != GFD_FILE_MAJOR_VERSION)
{
printf("file version not supported.\n");
goto error; goto error;
}
if (header->gpuVersion != GFD_FILE_GPU_VERSION) if (header->gpuVersion != GFD_FILE_GPU_VERSION)
{
printf("gpu version not supported.\n");
goto error; goto error;
}
if (!header->align) if (!header->align)
{
printf("data is not aligned.\n");
goto error; goto error;
}
GFDBlock *block = (GFDBlock *)(gfd->data + header->headerSize); GFDBlock *block = (GFDBlock *)(gfd->data + header->headerSize);
while (block->header.type != GFD_BLOCK_TYPE_END_OF_FILE) while (block->header.type != GFD_BLOCK_TYPE_END_OF_FILE)
{ {
if (block->header.magic != GFD_BLOCK_MAGIC) if (block->header.magic != GFD_BLOCK_MAGIC)
{
printf("wrong block magic number.\n");
goto error; goto error;
}
if (block->header.headerSize != sizeof(GFDBlockHeader)) if (block->header.headerSize != sizeof(GFDBlockHeader))
{
printf("wrong block header size.\n");
goto error; goto error;
}
if (block->header.majorVersion != GFD_BLOCK_MAJOR_VERSION) if (block->header.majorVersion != GFD_BLOCK_MAJOR_VERSION)
{
printf("block version not supported.\n");
goto error; goto error;
}
switch (block->header.type) switch (block->header.type)
{ {
@ -491,33 +458,20 @@ GFDFile *gfd_open(const char *filename)
} }
if (!gfd->vs) if (!gfd->vs)
{
printf("vertex shader is missing.\n");
goto error; goto error;
}
if (!gfd->vs->program) if (!gfd->vs->program)
{
printf("vertex shader program is missing.\n");
goto error; goto error;
}
if (!gfd->ps) if (!gfd->ps)
{
printf("pixel shader is missing.\n");
goto error; goto error;
}
if (!gfd->ps->program) if (!gfd->ps->program)
{
printf("pixel shader program is missing.\n");
goto error; goto error;
}
return gfd; return gfd;
error: error:
printf("failed to open file : %s\n", filename);
gfd_free(gfd); gfd_free(gfd);
return NULL; return NULL;

View File

@ -73,9 +73,6 @@ void GX2InitShader(GX2Shader* shader);
void GX2DestroyShader(GX2Shader* shader); void GX2DestroyShader(GX2Shader* shader);
void GX2SetShader(GX2Shader* shader); void GX2SetShader(GX2Shader* shader);
void check_shader(const void* shader_, u32 shader_size, const void* org_, u32 org_size, const char* name);
void check_shader_verbose(u32* shader, u32 shader_size, u32* org, u32 org_size, const char* name);
typedef struct typedef struct
{ {
GX2VertexShader* vs; GX2VertexShader* vs;