Simplified prog_counter back to pc

This commit is contained in:
dingusdev 2020-03-05 07:48:10 -07:00
parent 78fc5c408b
commit 4ceed27ccf
4 changed files with 60 additions and 60 deletions

View File

@ -65,7 +65,7 @@ fpscr = FP Status and Condition Register
typedef struct struct_ppc_state {
FPR_storage fpr[32];
uint32_t prog_counter; //Referred as the CIA in the PPC manual
uint32_t pc; //Referred as the CIA in the PPC manual
uint32_t gpr[32];
uint32_t cr;
uint32_t fpscr;
@ -111,7 +111,7 @@ enum PPC_VER : uint32_t {
/**
typedef struct struct_ppc64_state {
FPR_storage fpr [32];
uint64_t prog_counter; //Referred as the CIA in the PPC manual
uint64_t pc; //Referred as the CIA in the PPC manual
uint64_t gpr [32];
uint32_t cr;
uint32_t fpscr;

View File

@ -39,7 +39,7 @@ jmp_buf exc_env; /* Global exception environment. */
switch(exception_type) {
case Except_Type::EXC_SYSTEM_RESET:
ppc_state.spr[SPR::SRR0] = ppc_state.prog_counter & 0xFFFFFFFC;
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
ppc_next_instruction_address = 0x0100;
break;
@ -47,12 +47,12 @@ jmp_buf exc_env; /* Global exception environment. */
if (!(ppc_state.msr & 0x1000)) {
/* TODO: handle internal checkstop */
}
ppc_state.spr[SPR::SRR0] = ppc_state.prog_counter & 0xFFFFFFFC;
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
ppc_next_instruction_address = 0x0200;
break;
case Except_Type::EXC_DSI:
ppc_state.spr[SPR::SRR0] = ppc_state.prog_counter & 0xFFFFFFFC;
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
ppc_next_instruction_address = 0x0300;
break;
@ -67,32 +67,32 @@ jmp_buf exc_env; /* Global exception environment. */
break;
case Except_Type::EXC_ALIGNMENT:
ppc_state.spr[SPR::SRR0] = ppc_state.prog_counter & 0xFFFFFFFC;
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
ppc_next_instruction_address = 0x0600;
break;
case Except_Type::EXC_PROGRAM:
ppc_state.spr[SPR::SRR0] = ppc_state.prog_counter & 0xFFFFFFFC;
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
ppc_next_instruction_address = 0x0700;
break;
case Except_Type::EXC_NO_FPU:
ppc_state.spr[SPR::SRR0] = ppc_state.prog_counter & 0xFFFFFFFC;
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
ppc_next_instruction_address = 0x0800;
break;
case Except_Type::EXC_DECR:
ppc_state.spr[SPR::SRR0] = (ppc_state.prog_counter & 0xFFFFFFFC) + 4;
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFC) + 4;
ppc_next_instruction_address = 0x0900;
break;
case Except_Type::EXC_SYSCALL:
ppc_state.spr[SPR::SRR0] = (ppc_state.prog_counter & 0xFFFFFFFC) + 4;
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFC) + 4;
ppc_next_instruction_address = 0x0C00;
break;
case Except_Type::EXC_TRACE:
ppc_state.spr[SPR::SRR0] = (ppc_state.prog_counter & 0xFFFFFFFC) + 4;
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFC) + 4;
ppc_next_instruction_address = 0x0D00;
break;

View File

@ -563,22 +563,22 @@ void tbr_update()
void ppc_exec()
{
while (power_on) {
//printf("PowerPC Address: %x \n", ppc_state.prog_counter);
quickinstruction_translate(ppc_state.prog_counter);
//printf("PowerPC Address: %x \n", ppc_state.pc);
quickinstruction_translate(ppc_state.pc);
ppc_main_opcode();
if (grab_branch & !grab_exception) {
ppc_state.prog_counter = ppc_next_instruction_address;
ppc_state.pc = ppc_next_instruction_address;
grab_branch = 0;
tbr_update();
}
else if (grab_return | grab_exception) {
ppc_state.prog_counter = ppc_next_instruction_address;
ppc_state.pc = ppc_next_instruction_address;
grab_exception = 0;
grab_return = 0;
tbr_update();
}
else {
ppc_state.prog_counter += 4;
ppc_state.pc += 4;
tbr_update();
}
}
@ -590,16 +590,16 @@ void ppc_exec()
uint8_t* pc_real;
/* start new basic block */
bb_start_la = ppc_state.prog_counter;
bb_start_la = ppc_state.pc;
bb_kind = BB_end_kind::BB_NONE;
if (setjmp(exc_env)) {
/* reaching here means we got a low-level exception */
timebase_counter += (ppc_state.prog_counter - bb_start_la) >> 2;
timebase_counter += (ppc_state.pc - bb_start_la) >> 2;
bb_start_la = ppc_next_instruction_address;
pc_real = quickinstruction_translate(bb_start_la);
page_start = bb_start_la & 0xFFFFF000;
ppc_state.prog_counter = bb_start_la;
ppc_state.pc = bb_start_la;
bb_kind = BB_end_kind::BB_NONE;
goto again;
}
@ -614,21 +614,21 @@ again:
while (power_on) {
ppc_main_opcode();
if (bb_kind != BB_end_kind::BB_NONE) {
timebase_counter += (ppc_state.prog_counter - bb_start_la) >> 2;
timebase_counter += (ppc_state.pc - bb_start_la) >> 2;
bb_start_la = ppc_next_instruction_address;
if ((ppc_next_instruction_address & 0xFFFFF000) != page_start) {
page_start = bb_start_la & 0xFFFFF000;
pc_real = quickinstruction_translate(bb_start_la);
}
else {
pc_real += (int)bb_start_la - (int)ppc_state.prog_counter;
pc_real += (int)bb_start_la - (int)ppc_state.pc;
ppc_set_cur_instruction(pc_real);
}
ppc_state.prog_counter = bb_start_la;
ppc_state.pc = bb_start_la;
bb_kind = BB_end_kind::BB_NONE;
}
else {
ppc_state.prog_counter += 4;
ppc_state.pc += 4;
pc_real += 4;
ppc_set_cur_instruction(pc_real);
}
@ -640,21 +640,21 @@ again:
#if 0
void ppc_exec_single()
{
quickinstruction_translate(ppc_state.prog_counter);
quickinstruction_translate(ppc_state.pc);
ppc_main_opcode();
if (grab_branch && !grab_exception) {
ppc_state.prog_counter = ppc_next_instruction_address;
ppc_state.pc = ppc_next_instruction_address;
grab_branch = 0;
tbr_update();
}
else if (grab_return || grab_exception) {
ppc_state.prog_counter = ppc_next_instruction_address;
ppc_state.pc = ppc_next_instruction_address;
grab_exception = 0;
grab_return = 0;
tbr_update();
}
else {
ppc_state.prog_counter += 4;
ppc_state.pc += 4;
tbr_update();
}
}
@ -664,19 +664,19 @@ void ppc_exec_single()
if (setjmp(exc_env)) {
/* reaching here means we got a low-level exception */
timebase_counter += 1;
ppc_state.prog_counter = ppc_next_instruction_address;
ppc_state.pc = ppc_next_instruction_address;
bb_kind = BB_end_kind::BB_NONE;
return;
}
quickinstruction_translate(ppc_state.prog_counter);
quickinstruction_translate(ppc_state.pc);
ppc_main_opcode();
if (bb_kind != BB_end_kind::BB_NONE) {
ppc_state.prog_counter = ppc_next_instruction_address;
ppc_state.pc = ppc_next_instruction_address;
bb_kind = BB_end_kind::BB_NONE;
}
else {
ppc_state.prog_counter += 4;
ppc_state.pc += 4;
}
timebase_counter += 1;
}
@ -686,22 +686,22 @@ void ppc_exec_single()
#if 0
void ppc_exec_until(uint32_t goal_addr)
{
while (ppc_state.prog_counter != goal_addr) {
quickinstruction_translate(ppc_state.prog_counter);
while (ppc_state.pc != goal_addr) {
quickinstruction_translate(ppc_state.pc);
ppc_main_opcode();
if (grab_branch && !grab_exception) {
ppc_state.prog_counter = ppc_next_instruction_address;
ppc_state.pc = ppc_next_instruction_address;
grab_branch = 0;
tbr_update();
}
else if (grab_return || grab_exception) {
ppc_state.prog_counter = ppc_next_instruction_address;
ppc_state.pc = ppc_next_instruction_address;
grab_exception = 0;
grab_return = 0;
tbr_update();
}
else {
ppc_state.prog_counter += 4;
ppc_state.pc += 4;
tbr_update();
}
ppc_cur_instruction = 0;
@ -714,16 +714,16 @@ void ppc_exec_until(uint32_t goal_addr)
uint8_t* pc_real;
/* start new basic block */
bb_start_la = ppc_state.prog_counter;
bb_start_la = ppc_state.pc;
bb_kind = BB_end_kind::BB_NONE;
if (setjmp(exc_env)) {
/* reaching here means we got a low-level exception */
timebase_counter += (ppc_state.prog_counter - bb_start_la) >> 2;
timebase_counter += (ppc_state.pc - bb_start_la) >> 2;
bb_start_la = ppc_next_instruction_address;
pc_real = quickinstruction_translate(bb_start_la);
page_start = bb_start_la & 0xFFFFF000;
ppc_state.prog_counter = bb_start_la;
ppc_state.pc = bb_start_la;
bb_kind = BB_end_kind::BB_NONE;
goto again;
}
@ -735,24 +735,24 @@ void ppc_exec_until(uint32_t goal_addr)
page_start = bb_start_la & 0xFFFFF000;
again:
while (ppc_state.prog_counter != goal_addr) {
while (ppc_state.pc != goal_addr) {
ppc_main_opcode();
if (bb_kind != BB_end_kind::BB_NONE) {
timebase_counter += (ppc_state.prog_counter - bb_start_la) >> 2;
timebase_counter += (ppc_state.pc - bb_start_la) >> 2;
bb_start_la = ppc_next_instruction_address;
if ((ppc_next_instruction_address & 0xFFFFF000) != page_start) {
page_start = bb_start_la & 0xFFFFF000;
pc_real = quickinstruction_translate(bb_start_la);
}
else {
pc_real += (int)bb_start_la - (int)ppc_state.prog_counter;
pc_real += (int)bb_start_la - (int)ppc_state.pc;
ppc_set_cur_instruction(pc_real);
}
ppc_state.prog_counter = bb_start_la;
ppc_state.pc = bb_start_la;
bb_kind = BB_end_kind::BB_NONE;
}
else {
ppc_state.prog_counter += 4;
ppc_state.pc += 4;
pc_real += 4;
ppc_set_cur_instruction(pc_real);
}
@ -788,7 +788,7 @@ void ppc_cpu_init(uint32_t proc_version)
ppc_state.cr = 0;
ppc_state.fpscr = 0;
ppc_state.prog_counter = 0;
ppc_state.pc = 0;
ppc_state.tbr[0] = 0;
ppc_state.tbr[1] = 0;
@ -811,7 +811,7 @@ void ppc_cpu_init(uint32_t proc_version)
ppc_mmu_init();
/* redirect code execution to reset vector */
ppc_state.prog_counter = 0xFFF00100;
ppc_state.pc = 0xFFF00100;
}
void print_gprs()
@ -820,7 +820,7 @@ void print_gprs()
cout << "GPR " << dec << i << " : " << uppercase << hex
<< ppc_state.gpr[i] << endl;
cout << "PC: " << uppercase << hex << ppc_state.prog_counter << endl;
cout << "PC: " << uppercase << hex << ppc_state.pc << endl;
cout << "LR: " << uppercase << hex << ppc_state.spr[SPR::LR] << endl;
cout << "CR: " << uppercase << hex << ppc_state.cr << endl;
cout << "CTR: " << uppercase << hex << ppc_state.spr[SPR::CTR] << endl;
@ -858,8 +858,8 @@ uint64_t reg_op(string &reg_name, uint64_t val, bool is_write)
try {
if (reg_name_u == "PC") {
if (is_write)
ppc_state.prog_counter = val;
return ppc_state.prog_counter;
ppc_state.pc = val;
return ppc_state.pc;
}
if (reg_name_u == "MSR") {
if (is_write)

View File

@ -1426,7 +1426,7 @@ void ppc_extshdot() {
void ppc_b() {
uint32_t quick_test = (ppc_cur_instruction & 0x03FFFFFC);
adr_li = (quick_test < 0x2000000) ? quick_test : (0xFC000000UL + quick_test);
ppc_next_instruction_address = (uint32_t)(ppc_state.prog_counter + adr_li);
ppc_next_instruction_address = (uint32_t)(ppc_state.pc + adr_li);
grab_branch = 1;
bb_kind = BB_end_kind::BB_BRANCH;
}
@ -1434,8 +1434,8 @@ void ppc_b() {
void ppc_bl() {
uint32_t quick_test = (ppc_cur_instruction & 0x03FFFFFC);
adr_li = (quick_test < 0x2000000) ? quick_test : (0xFC000000UL + quick_test);
ppc_next_instruction_address = (uint32_t)(ppc_state.prog_counter + adr_li);
ppc_state.spr[SPR::LR] = (uint32_t)(ppc_state.prog_counter + 4);
ppc_next_instruction_address = (uint32_t)(ppc_state.pc + adr_li);
ppc_state.spr[SPR::LR] = (uint32_t)(ppc_state.pc + 4);
grab_branch = 1;
bb_kind = BB_end_kind::BB_BRANCH;
}
@ -1452,7 +1452,7 @@ void ppc_bla() {
uint32_t quick_test = (ppc_cur_instruction & 0x03FFFFFC);
adr_li = (quick_test < 0x2000000) ? quick_test : (0xFC000000UL + quick_test);
ppc_next_instruction_address = adr_li;
ppc_state.spr[SPR::LR] = ppc_state.prog_counter + 4;
ppc_state.spr[SPR::LR] = ppc_state.pc + 4;
grab_branch = 1;
bb_kind = BB_end_kind::BB_BRANCH;
}
@ -1472,7 +1472,7 @@ void ppc_bc()
cnd_ok = (br_bo & 0x10) || (!(ppc_state.cr & (0x80000000UL >> br_bi)) == !(br_bo & 0x08));
if (ctr_ok && cnd_ok) {
ppc_next_instruction_address = (ppc_state.prog_counter + br_bd);
ppc_next_instruction_address = (ppc_state.pc + br_bd);
grab_branch = 1;
bb_kind = BB_end_kind::BB_BRANCH;
}
@ -1514,11 +1514,11 @@ void ppc_bcl()
cnd_ok = (br_bo & 0x10) || (!(ppc_state.cr & (0x80000000UL >> br_bi)) == !(br_bo & 0x08));
if (ctr_ok && cnd_ok) {
ppc_next_instruction_address = (ppc_state.prog_counter + br_bd);
ppc_next_instruction_address = (ppc_state.pc + br_bd);
grab_branch = 1;
bb_kind = BB_end_kind::BB_BRANCH;
}
ppc_state.spr[SPR::LR] = ppc_state.prog_counter + 4;
ppc_state.spr[SPR::LR] = ppc_state.pc + 4;
}
void ppc_bcla()
@ -1540,7 +1540,7 @@ void ppc_bcla()
grab_branch = 1;
bb_kind = BB_end_kind::BB_BRANCH;
}
ppc_state.spr[SPR::LR] = ppc_state.prog_counter + 4;
ppc_state.spr[SPR::LR] = ppc_state.pc + 4;
}
void ppc_bcctr()
@ -1569,7 +1569,7 @@ void ppc_bcctrl()
grab_branch = 1;
bb_kind = BB_end_kind::BB_BRANCH;
}
ppc_state.spr[SPR::LR] = ppc_state.prog_counter + 4;
ppc_state.spr[SPR::LR] = ppc_state.pc + 4;
}
void ppc_bclr()
@ -1610,7 +1610,7 @@ void ppc_bclrl()
grab_branch = 1;
bb_kind = BB_end_kind::BB_BRANCH;
}
ppc_state.spr[SPR::LR] = ppc_state.prog_counter + 4;
ppc_state.spr[SPR::LR] = ppc_state.pc + 4;
}
//Compare Instructions
@ -1843,7 +1843,7 @@ void ppc_dcbtst() {
void ppc_dcbz() {
ppc_grab_regsdab();
ppc_effective_address = (reg_a == 0) ? ppc_result_b : (ppc_result_a + ppc_result_b);
if (!(ppc_state.prog_counter & 32) && (ppc_state.prog_counter < 0xFFFFFFE0UL)) {
if (!(ppc_state.pc & 32) && (ppc_state.pc < 0xFFFFFFE0UL)) {
ppc_grab_regsdab();
ppc_effective_address = (reg_a == 0) ? ppc_result_b : (ppc_result_a + ppc_result_b);
mem_write_qword(ppc_effective_address, 0);