#include "boot.h"
|
|
|
|
#include <assert.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
static const uint8_t MAGIC[0x10] = "PS-X EXE";
|
|
static const uint8_t RESERVED[0x10] = {0};
|
|
|
|
typedef struct __attribute__((packed))
|
|
{
|
|
uint32_t pc;
|
|
uint32_t gp;
|
|
uint32_t addr_dest;
|
|
uint32_t size_file;
|
|
uint32_t addr_data;
|
|
uint32_t size_data;
|
|
uint32_t addr_bss;
|
|
uint32_t size_bss;
|
|
} psx_header_t;
|
|
|
|
psx_header_t parse_psx_header(byte_arr_t *prgm)
|
|
{
|
|
psx_header_t header;
|
|
|
|
// TODO: Convert asserts into recoverable error
|
|
assert(prgm->size >= 0x800);
|
|
assert(memcmp(MAGIC, prgm->data, sizeof MAGIC) == 0);
|
|
memcpy(&header, &prgm->data[sizeof MAGIC], sizeof header);
|
|
|
|
assert(header.size_file == prgm->size - 0x800);
|
|
assert(memcmp(RESERVED, &prgm->data[0x38], sizeof RESERVED) == 0);
|
|
|
|
return header;
|
|
}
|
|
|
|
void boot_psx_prgm(byte_arr_t *prgm)
|
|
{
|
|
psx_header_t header = parse_psx_header(prgm);
|
|
|
|
printf("pc = %08x\n", header.pc);
|
|
printf("gp = %08x\n", header.gp);
|
|
printf("data = %08x (%u bytes)\n", header.addr_data, header.size_data);
|
|
printf("bss = %08x (%u bytes)\n", header.addr_bss, header.size_bss);
|
|
printf("dest = %08x\n", header.addr_dest);
|
|
printf("size = %08x (%u bytes)\n", header.size_file, header.size_file);
|
|
}
|