|
@ -1,6 +1,7 @@ |
|
|
#include "boot.h" |
|
|
#include "boot.h" |
|
|
#include "cpu.h" |
|
|
#include "cpu.h" |
|
|
#include "insn.h" |
|
|
#include "insn.h" |
|
|
|
|
|
#include "log.h" |
|
|
#include "psx.h" |
|
|
#include "psx.h" |
|
|
|
|
|
|
|
|
#include <assert.h> |
|
|
#include <assert.h> |
|
@ -16,12 +17,21 @@ psx_header_t parse_psx_header(byte_arr_t *prgm) |
|
|
psx_header_t header; |
|
|
psx_header_t header; |
|
|
|
|
|
|
|
|
// TODO: Convert asserts into recoverable error |
|
|
// TODO: Convert asserts into recoverable error |
|
|
|
|
|
debug("Checking header struct size"); |
|
|
assert(sizeof header == 0x38 - 0x10); |
|
|
assert(sizeof header == 0x38 - 0x10); |
|
|
|
|
|
|
|
|
|
|
|
debug("Checking program size is greater than header"); |
|
|
assert(prgm->size >= 0x800); |
|
|
assert(prgm->size >= 0x800); |
|
|
|
|
|
|
|
|
|
|
|
debug("Checking magic number in header"); |
|
|
assert(memcmp(MAGIC, prgm->data, sizeof MAGIC) == 0); |
|
|
assert(memcmp(MAGIC, prgm->data, sizeof MAGIC) == 0); |
|
|
|
|
|
|
|
|
memcpy(&header, &prgm->data[sizeof MAGIC], sizeof header); |
|
|
memcpy(&header, &prgm->data[sizeof MAGIC], sizeof header); |
|
|
|
|
|
|
|
|
|
|
|
debug("Checking file size in header matches program size"); |
|
|
assert(header.size_file == prgm->size - 0x800); |
|
|
assert(header.size_file == prgm->size - 0x800); |
|
|
|
|
|
|
|
|
|
|
|
debug("Checking A34h region is zero"); |
|
|
assert(memcmp(RESERVED, &prgm->data[0x38], sizeof RESERVED) == 0); |
|
|
assert(memcmp(RESERVED, &prgm->data[0x38], sizeof RESERVED) == 0); |
|
|
|
|
|
|
|
|
return header; |
|
|
return header; |
|
@ -43,17 +53,16 @@ uint32_t translate_addr(uint32_t addr) |
|
|
|
|
|
|
|
|
void boot_psx_prgm(byte_arr_t *prgm) |
|
|
void boot_psx_prgm(byte_arr_t *prgm) |
|
|
{ |
|
|
{ |
|
|
printf("parsing program header\n"); |
|
|
|
|
|
|
|
|
debug("Parsing program header"); |
|
|
|
|
|
|
|
|
psx_header_t header = parse_psx_header(prgm); |
|
|
psx_header_t header = parse_psx_header(prgm); |
|
|
|
|
|
|
|
|
printf("=== header ===\n"); |
|
|
|
|
|
printf("pc = %08x, gp = %08x\n", header.pc, header.gp); |
|
|
|
|
|
printf("sp = %08x, fp = %08x\n", header.sp, header.fp); |
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
debug("Program header"); |
|
|
|
|
|
debug("size=%u bytes", header.size_file); |
|
|
|
|
|
debug("pc=%08x, gp=%08x, sp=%08x, fp=%08x", header.pc, header.gp, header.sp, header.fp); |
|
|
|
|
|
debug("data=%08x (%u bytes)", header.addr_data, header.size_data); |
|
|
|
|
|
debug("bss=%08x (%u bytes)", header.addr_bss, header.size_bss); |
|
|
|
|
|
debug("dest=%08x", header.addr_dest); |
|
|
|
|
|
|
|
|
cpu_t *cpu = malloc(sizeof *cpu); |
|
|
cpu_t *cpu = malloc(sizeof *cpu); |
|
|
|
|
|
|
|
@ -67,12 +76,10 @@ void boot_psx_prgm(byte_arr_t *prgm) |
|
|
cpu->regs[REG_FP] = header.fp; |
|
|
cpu->regs[REG_FP] = header.fp; |
|
|
|
|
|
|
|
|
psx_t psx = {header, cpu}; |
|
|
psx_t psx = {header, cpu}; |
|
|
const int max_insns = 1; |
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < max_insns; i++) |
|
|
|
|
|
|
|
|
while (1) |
|
|
{ |
|
|
{ |
|
|
printf("=== insn ===\n"); |
|
|
|
|
|
printf("pc = %08x\n", psx.cpu->pc); |
|
|
|
|
|
|
|
|
debug("Executing instruction at %08x", psx.cpu->pc); |
|
|
|
|
|
|
|
|
const uint32_t insn = cpu_read32(cpu, psx.cpu->pc); |
|
|
const uint32_t insn = cpu_read32(cpu, psx.cpu->pc); |
|
|
insn_execute(cpu, insn); |
|
|
insn_execute(cpu, insn); |
|
|