|
@ -1,19 +1,19 @@ |
|
|
#include "boot.h" |
|
|
#include "boot.h" |
|
|
#include "cpu.h" |
|
|
|
|
|
#include "insn.h" |
|
|
|
|
|
#include "log.h" |
|
|
|
|
|
#include "psx.h" |
|
|
|
|
|
|
|
|
|
|
|
#include <assert.h> |
|
|
#include <assert.h> |
|
|
#include <stdlib.h> |
|
|
|
|
|
#include <stdio.h> |
|
|
#include <stdio.h> |
|
|
|
|
|
#include <stdlib.h> |
|
|
#include <string.h> |
|
|
#include <string.h> |
|
|
|
|
|
|
|
|
|
|
|
#include "cpu.h" |
|
|
|
|
|
#include "insn.h" |
|
|
|
|
|
#include "log.h" |
|
|
|
|
|
#include "psx.h" |
|
|
|
|
|
|
|
|
static const uint8_t MAGIC[0x10] = "PS-X EXE"; |
|
|
static const uint8_t MAGIC[0x10] = "PS-X EXE"; |
|
|
static const uint8_t RESERVED[0x10] = {0}; |
|
|
static const uint8_t RESERVED[0x10] = {0}; |
|
|
|
|
|
|
|
|
psx_header_t parse_psx_header(byte_arr_t *prgm) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
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 |
|
@ -37,29 +37,25 @@ psx_header_t parse_psx_header(byte_arr_t *prgm) |
|
|
return header; |
|
|
return header; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
uint32_t translate_addr(uint32_t addr) |
|
|
|
|
|
{ |
|
|
|
|
|
if (addr >= 0xA0000000) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
uint32_t translate_addr(uint32_t addr) { |
|
|
|
|
|
if (addr >= 0xA0000000) { |
|
|
addr = addr - 0xA0000000; |
|
|
addr = addr - 0xA0000000; |
|
|
} |
|
|
|
|
|
else if (addr >= 0x80000000) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
} else if (addr >= 0x80000000) { |
|
|
addr = addr - 0x80000000; |
|
|
addr = addr - 0x80000000; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return addr; |
|
|
return addr; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void boot_psx_prgm(byte_arr_t *prgm) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
void boot_psx_prgm(byte_arr_t *prgm) { |
|
|
debug("Parsing program header"); |
|
|
debug("Parsing program header"); |
|
|
|
|
|
|
|
|
psx_header_t header = parse_psx_header(prgm); |
|
|
psx_header_t header = parse_psx_header(prgm); |
|
|
|
|
|
|
|
|
debug("Program header"); |
|
|
debug("Program header"); |
|
|
debug("size=%u bytes", header.size_file); |
|
|
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("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("data=%08x (%u bytes)", header.addr_data, header.size_data); |
|
|
debug("bss=%08x (%u bytes)", header.addr_bss, header.size_bss); |
|
|
debug("bss=%08x (%u bytes)", header.addr_bss, header.size_bss); |
|
|
debug("dest=%08x", header.addr_dest); |
|
|
debug("dest=%08x", header.addr_dest); |
|
@ -77,8 +73,7 @@ void boot_psx_prgm(byte_arr_t *prgm) |
|
|
|
|
|
|
|
|
psx_t psx = {header, cpu}; |
|
|
psx_t psx = {header, cpu}; |
|
|
|
|
|
|
|
|
while (1) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
while (1) { |
|
|
debug("Executing instruction at %08x", 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); |
|
|