ref: 5a6813f7877fde6f959b10dc41efa44277d9f8f2
parent: ae76d829e794bf5af82ef76d357db76bddacf169
author: allkern <lisandroaalarcon@gmail.com>
date: Sat Jun 24 21:14:28 EDT 2023
Implement more CLI settings
--- a/frontend/config.c
+++ b/frontend/config.c
@@ -98,6 +98,8 @@
cfg->settings_path = NULL;
cfg->use_args = 0;
cfg->version = 0;
+ cfg->log_level = LOG_FATAL;
+ cfg->quiet = 0;
}
void psxe_cfg_load(psxe_config_t* cfg, int argc, const char* argv[]) {@@ -107,6 +109,8 @@
int version = 0;
int help_model = 0;
int help_region = 0;
+ int log_level = 0;
+ int quiet = 0;
const char* settings_path = NULL;
const char* bios = NULL;
const char* bios_search = NULL;
@@ -128,11 +132,13 @@
OPT_GROUP("Basic options"), OPT_BOOLEAN ('a', "use-args" , &use_args , "Ignore settings file, use CLI args instead", NULL, 0, 0), OPT_STRING ('S', "settings-file", &settings_path, "Specify settings file path", NULL, 0, 0),- OPT_BOOLEAN ('b', "bios" , &bios , "Use this BIOS file (ignores -B, -M)", NULL, 0, 0),+ OPT_STRING ('b', "bios" , &bios , "Use this BIOS file (ignores -B, -M)", NULL, 0, 0), OPT_BOOLEAN ('B', "bios-folder" , &bios_search , "Specify a BIOS search folder", NULL, 0, 0), OPT_STRING ('M', "model" , &model , "Specify console model (SPCH-XXXX)", NULL, 0, 0), OPT_STRING ('r', "region" , ®ion , "Specify console region"), OPT_STRING ('x', "exe" , &exe , "Boot this PS-X EXE file (ignores CDROM image)"),+ OPT_INTEGER ('L', "log-level" , &log_level , "Set log level"),+ OPT_BOOLEAN ('q', "quiet" , &quiet , "Silence all logs (ignores -L)"),OPT_END()
};
@@ -161,6 +167,8 @@
exit(0);
}
+ log_set_quiet(quiet);
+
if (!use_args) {if (!settings_path)
settings_path = "settings.toml";
@@ -237,6 +245,9 @@
fclose(settings);
}
+
+ if (log_level)
+ cfg->log_level = log_level - 1;
if (bios)
cfg->bios = bios;
--- a/frontend/config.h
+++ b/frontend/config.h
@@ -12,6 +12,8 @@
int version;
int help_model;
int help_region;
+ int log_level;
+ int quiet;
const char* settings_path;
const char* bios;
const char* bios_search;
--- a/frontend/main.c
+++ b/frontend/main.c
@@ -18,7 +18,7 @@
log_fatal("s4=%08x s5=%08x s6=%08x s7=%08x", g_cpu->r[20], g_cpu->r[21], g_cpu->r[22], g_cpu->r[23]); log_fatal("t8=%08x t9=%08x k0=%08x k1=%08x", g_cpu->r[24], g_cpu->r[25], g_cpu->r[26], g_cpu->r[27]); log_fatal("gp=%08x sp=%08x fp=%08x ra=%08x", g_cpu->r[28], g_cpu->r[29], g_cpu->r[30], g_cpu->r[31]);- log_fatal("pc=%08x hi=%08x lo=%08x", g_cpu->pc, g_cpu->hi, g_cpu->lo);+ log_fatal("pc=%08x hi=%08x lo=%08x epc=%08x", g_cpu->pc, g_cpu->hi, g_cpu->lo, g_cpu->cop0_epc);exit(1);
}
@@ -30,12 +30,12 @@
psxe_cfg_load_defaults(cfg);
psxe_cfg_load(cfg, argc, argv);
- log_set_level(LOG_FATAL);
+ log_set_level(LOG_ERROR);
signal(SIGINT, sigint_handler);
psx_t* psx = psx_create();
- psx_init(psx, "SCPH1001.BIN");
+ psx_init(psx, cfg->bios);
psx_gpu_t* gpu = psx_get_gpu(psx);
@@ -49,12 +49,12 @@
psx_gpu_set_event_callback(gpu, GPU_EVENT_DMODE, psxe_gpu_dmode_event_cb);
psx_gpu_set_udata(gpu, 0, screen);
- if (argv[1]) {+ if (cfg->exe) { while (psx->cpu->pc != 0x80030008) {psx_update(psx);
}
- psx_load_exe(psx, argv[1]);
+ psx_load_exe(psx, cfg->exe);
}
while (psxe_screen_is_open(screen)) {@@ -73,7 +73,7 @@
log_fatal("s4=%08x s5=%08x s6=%08x s7=%08x", cpu->r[20], cpu->r[21], cpu->r[22], cpu->r[23]); log_fatal("t8=%08x t9=%08x k0=%08x k1=%08x", cpu->r[24], cpu->r[25], cpu->r[26], cpu->r[27]); log_fatal("gp=%08x sp=%08x fp=%08x ra=%08x", cpu->r[28], cpu->r[29], cpu->r[30], cpu->r[31]);- log_fatal("pc=%08x hi=%08x lo=%08x", cpu->pc, cpu->hi, cpu->lo);+ log_fatal("pc=%08x hi=%08x lo=%08x ep=%08x", cpu->pc, cpu->hi, cpu->lo, cpu->cop0_epc);psx_destroy(psx);
psxe_screen_destroy(screen);
--- a/psx/cpu.c
+++ b/psx/cpu.c
@@ -62,6 +62,7 @@
cpu->bus = bus;
cpu->pc = 0xbfc00000;
+ cpu->cop0_sr = 0x10900000;
cpu->cop0_prid = 0x00000002;
psx_cpu_fetch(cpu);
@@ -139,6 +140,8 @@
#define IMM16 (cpu->buf[1] & 0xffff)
#define IMM16S ((int32_t)((int16_t)IMM16))
+// #define CPU_TRACE
+
#ifdef CPU_TRACE
#define TRACE_M(m) \
log_trace("%08x: %-7s $%s, %+i($%s)", cpu->pc-8, m, g_mips_cc_register_names[T], IMM16S, g_mips_cc_register_names[S])@@ -337,17 +340,17 @@
// If we're in a delay slot, set delay slot bit
// on CAUSE
if (cpu->delay_slot) {- cpu->cop0_epc = cpu->pc - 4;
+ cpu->cop0_epc = cpu->pc - 12;
cpu->cop0_cause |= 0x80000000;
} else {cpu->cop0_epc = cpu->pc - 8;
- cpu->cop0_cause &= ~0x80000000;
+ cpu->cop0_cause &= 0x7fffffff;
}
// Do exception stack push
uint32_t mode = cpu->cop0_sr & 0x3f;
- cpu->cop0_sr &= ~0x3ful;
+ cpu->cop0_sr &= 0xffffffc0;
cpu->cop0_sr |= (mode << 2) & 0x3f;
// Set PC to the vector selected on BEV
--- a/psx/cpu.h
+++ b/psx/cpu.h
@@ -15,84 +15,66 @@
typedef void (*psx_cpu_kcall_hook_t)(psx_cpu_t*);
+/*
+ Name Alias Common Usage
+ R0 zero Constant (always 0)
+ R1 at Assembler temporary (destroyed by some assembler pseudoinstructions!)
+ R2-R3 v0-v1 Subroutine return values, may be changed by subroutines
+ R4-R7 a0-a3 Subroutine arguments, may be changed by subroutines
+ R8-R15 t0-t7 Temporaries, may be changed by subroutines
+ R16-R23 s0-s7 Static variables, must be saved by subs
+ R24-R25 t8-t9 Temporaries, may be changed by subroutines
+ R26-R27 k0-k1 Reserved for kernel (destroyed by some IRQ handlers!)
+ R28 gp Global pointer (rarely used)
+ R29 sp Stack pointer
+ R30 fp(s8) Frame Pointer, or 9th Static variable, must be saved
+ R31 ra Return address (used so by JAL,BLTZAL,BGEZAL opcodes)
+ - pc Program counter
+ - hi,lo Multiply/divide results, may be changed by subroutines
+*/
+
+/*
+ cop0r0 - N/A
+ cop0r1 - N/A
+ cop0r2 - N/A
+ cop0r3 - BPC - Breakpoint on execute (R/W)
+ cop0r4 - N/A
+ cop0r5 - BDA - Breakpoint on data access (R/W)
+ cop0r6 - JUMPDEST - Randomly memorized jump address (R)
+ cop0r7 - DCIC - Breakpoint control (R/W)
+ cop0r8 - BadVaddr - Bad Virtual Address (R)
+ cop0r9 - BDAM - Data Access breakpoint mask (R/W)
+ cop0r10 - N/A
+ cop0r11 - BPCM - Execute breakpoint mask (R/W)
+ cop0r12 - SR - System status register (R/W)
+ cop0r13 - CAUSE - Describes the most recently recognised exception (R)
+ cop0r14 - EPC - Return Address from Trap (R)
+ cop0r15 - PRID - Processor ID (R)
+*/
+
struct psx_cpu_t {- // Registers (including $zero and $ra)
uint32_t r[32];
-
- // Pipeline simulation (for branch delay slots)
uint32_t buf[2];
-
- // Program Counter
uint32_t pc;
-
- // Result registers for mult and div
uint32_t hi, lo;
-
- // Pending load data
uint32_t load_d, load_v;
-
- // Are we in a delay slot?
+ uint32_t last_cycles;
int branch, delay_slot;
- // How many cycles the last instruction took
- uint32_t last_cycles;
-
- /*
- cop0r0 - N/A
- cop0r1 - N/A
- cop0r2 - N/A
- cop0r3 - BPC - Breakpoint on execute (R/W)
- cop0r4 - N/A
- cop0r5 - BDA - Breakpoint on data access (R/W)
- cop0r6 - JUMPDEST - Randomly memorized jump address (R)
- cop0r7 - DCIC - Breakpoint control (R/W)
- cop0r8 - BadVaddr - Bad Virtual Address (R)
- cop0r9 - BDAM - Data Access breakpoint mask (R/W)
- cop0r10 - N/A
- cop0r11 - BPCM - Execute breakpoint mask (R/W)
- cop0r12 - SR - System status register (R/W)
- cop0r13 - CAUSE - Describes the most recently recognised exception (R)
- cop0r14 - EPC - Return Address from Trap (R)
- cop0r15 - PRID - Processor ID (R)
- */
-
- // r3 - BPC - Breakpoint on execute (R/W)
uint32_t cop0_bpc;
-
- // r5 - BDA - Breakpoint on data access (R/W)
uint32_t cop0_bda;
-
- // r6 - JUMPDEST - Randomly memorized jump address (R)
uint32_t cop0_jumpdest;
-
- // r7 - DCIC - Breakpoint control (R/W)
uint32_t cop0_dcic;
-
- // r8 - BadVaddr - Bad Virtual Address (R)
uint32_t cop0_badvaddr;
-
- // r9 - BDAM - Data Access breakpoint mask (R/W)
uint32_t cop0_bdam;
-
- // r11 - BPCM - Execute breakpoint mask (R/W)
uint32_t cop0_bpcm;
-
- // r12 - SR - System status register (R/W)
uint32_t cop0_sr;
-
- // r13 - CAUSE - Describes the most recently recognised exception (R)
uint32_t cop0_cause;
-
- // r14 - EPC - Return Address from Trap (R)
uint32_t cop0_epc;
-
- // r15 - PRID - Processor ID (R)
uint32_t cop0_prid;
- // Pointer to bus structure
psx_bus_t* bus;
- // Optional hooks for kernel calls
psx_cpu_kcall_hook_t a_function_hook;
psx_cpu_kcall_hook_t b_function_hook;
};
--
⑨