Skip to content

Commit 82a4889

Browse files
joevtdingusdev
authored andcommitted
Change ppc_opcode_grabber to a variable.
1 parent 101bb82 commit 82a4889

5 files changed

Lines changed: 38 additions & 31 deletions

File tree

cpu/ppc/ppcemu.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,8 @@ extern void ppc_exec_single(void);
648648
extern void ppc_exec_until(uint32_t goal_addr);
649649
extern void ppc_exec_dbg(uint32_t start_addr, uint32_t size);
650650

651-
extern PPCOpcode *ppc_opcode_grabber();
652-
extern void ppc_msr_did_change(uint32_t old_msr_val, bool set_next_instruction_address = true);
651+
extern PPCOpcode* ppc_opcode_grabber;
652+
extern void ppc_msr_did_change(uint32_t old_msr_val, uint32_t new_msr_val, bool set_next_instruction_address = true);
653653

654654
/* debugging support API */
655655
void print_fprs(void); /* print content of the floating-point registers */

cpu/ppc/ppcexceptions.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,13 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
115115

116116
ppc_state.spr[SPR::SRR1] = (ppc_state.msr & 0x0000FF73) | srr1_bits;
117117
uint32_t old_msr_val = ppc_state.msr;
118-
ppc_state.msr &= 0xFFFB1041;
118+
uint32_t new_msr_val = old_msr_val & 0xFFFB1041;
119119
/* copy MSR[ILE] to MSR[LE] */
120-
ppc_state.msr = (ppc_state.msr & ~MSR::LE) | !!(ppc_state.msr & MSR::ILE);
120+
if (!is_601) {
121+
new_msr_val = (new_msr_val & ~MSR::LE) | !!(new_msr_val & MSR::ILE);
122+
}
121123
// Don't clobber the ppc_next_instruction_address value
122-
ppc_msr_did_change(old_msr_val, false);
124+
ppc_msr_did_change(old_msr_val, new_msr_val, false);
123125

124126
if (ppc_state.msr & MSR::IP) {
125127
ppc_next_instruction_address |= 0xFFF00000;

cpu/ppc/ppcexec.cpp

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -192,22 +192,27 @@ static PPCOpcode OpcodeGrabber[64 * 2048];
192192
everything else is the same.*/
193193
static PPCOpcode OpcodeGrabberNoFPU[64 * 2048];
194194

195-
void ppc_msr_did_change(uint32_t old_msr_val, bool set_next_instruction_address) {
196-
bool old_fp = old_msr_val & MSR::FP;
197-
bool new_fp = ppc_state.msr & MSR::FP;
198-
if (old_fp != new_fp) {
195+
void ppc_msr_did_change(uint32_t old_msr_val, uint32_t new_msr_val, bool set_next_instruction_address) {
196+
ppc_state.msr = new_msr_val;
197+
if ((old_msr_val ^ new_msr_val) & MSR::FP) {
198+
bool newFP = (new_msr_val & MSR::FP) != 0;
199+
ppc_opcode_grabber = newFP ? OpcodeGrabber : OpcodeGrabberNoFPU;
200+
//LOG_F(INFO, "changed FP to %s", newFP ? "yes" : "no");
201+
#if 1
199202
exec_flags |= EXEF_OPC_DECODER;
200203
if (set_next_instruction_address) {
201204
// Even though we're setting an exception flag, we want normal
202205
// instruction execution to continue.
203206
ppc_next_instruction_address = ppc_state.pc + 4;
204207
}
208+
#else
209+
power_on = false;
210+
power_off_reason = po_endian_switch;
211+
#endif
205212
}
206213
}
207214

208-
PPCOpcode* ppc_opcode_grabber() {
209-
return ppc_state.msr & MSR::FP ? OpcodeGrabber : OpcodeGrabberNoFPU;
210-
}
215+
PPCOpcode* ppc_opcode_grabber = OpcodeGrabberNoFPU;
211216

212217
/** Exception helpers. */
213218

@@ -296,7 +301,7 @@ static void ppc_exec_inner(uint32_t start_addr, uint32_t size)
296301
uint64_t max_cycles = 0;
297302
uint32_t page_start, eb_start, eb_end = 0;
298303
uint32_t opcode;
299-
PPCOpcode* opcode_grabber = ppc_opcode_grabber();
304+
PPCOpcode* opcode_grabber = ppc_opcode_grabber;
300305
uint8_t* pc_real;
301306

302307
while (power_on) {
@@ -321,7 +326,7 @@ static void ppc_exec_inner(uint32_t start_addr, uint32_t size)
321326

322327
if (exec_flags) {
323328
if (exec_flags & EXEF_OPC_DECODER) [[unlikely]] {
324-
opcode_grabber = ppc_opcode_grabber();
329+
opcode_grabber = ppc_opcode_grabber;
325330
}
326331
// define next execution block
327332
eb_start = ppc_next_instruction_address;
@@ -377,7 +382,7 @@ void ppc_exec_single()
377382

378383
uint8_t* pc_real = mmu_translate_imem(ppc_state.pc);
379384
uint32_t opcode = ppc_read_instruction(pc_real);
380-
ppc_main_opcode(ppc_opcode_grabber(), opcode);
385+
ppc_main_opcode(ppc_opcode_grabber, opcode);
381386
g_icycles++;
382387
process_events();
383388

@@ -395,18 +400,15 @@ void ppc_exec_single()
395400
template void ppc_exec_inner<until>(uint32_t start_addr, uint32_t size);
396401

397402
// outer interpreter loop
398-
void ppc_exec_until(volatile uint32_t goal_addr)
399-
{
403+
void ppc_exec_until(volatile uint32_t goal_addr) {
400404
if (setjmp(exc_env)) {
401405
// process low-level exceptions
402-
//LOG_F(9, "PPC-EXEC: low_level exception raised!");
406+
// LOG_F(9, "PPC-EXEC: low_level exception raised!");
403407
ppc_state.pc = ppc_next_instruction_address;
404408
}
405409

406410
while (power_on) {
407411
ppc_exec_inner<until>(goal_addr, 0);
408-
if (ppc_state.pc == goal_addr)
409-
break;
410412
}
411413
}
412414

@@ -845,13 +847,15 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool do_include_6
845847
dec_wr_value = 0;
846848

847849

850+
uint32_t new_msr_val;
848851
if (is_601) {
849852
/* MPC601 sets MSR[ME] bit during hard reset / Power-On */
850-
ppc_state.msr = (MSR::ME + MSR::IP);
853+
new_msr_val = (MSR::ME + MSR::IP);
851854
} else {
852-
ppc_state.msr = MSR::IP;
855+
new_msr_val = MSR::IP;
853856
ppc_state.spr[SPR::DEC_S] = 0xFFFFFFFFUL;
854857
}
858+
ppc_msr_did_change(new_msr_val, new_msr_val, false);
855859

856860
ppc_mmu_init();
857861

@@ -913,8 +917,8 @@ static uint64_t reg_op(string& reg_name, uint64_t val, bool is_write) {
913917
if (reg_name_u == "MSR") {
914918
if (is_write) {
915919
uint32_t old_msr_val = ppc_state.msr;
916-
ppc_state.msr = (uint32_t)val;
917-
ppc_msr_did_change(old_msr_val);
920+
uint32_t new_msr_val = (uint32_t)val;
921+
ppc_msr_did_change(old_msr_val, new_msr_val, false);
918922
}
919923
return ppc_state.msr;
920924
}

cpu/ppc/ppcopcodes.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -802,8 +802,8 @@ void dppc_interpreter::ppc_mtmsr(uint32_t opcode) {
802802
}
803803
uint32_t reg_s = (opcode >> 21) & 0x1F;
804804
uint32_t old_msr_val = ppc_state.msr;
805-
ppc_state.msr = ppc_state.gpr[reg_s];
806-
ppc_msr_did_change(old_msr_val);
805+
uint32_t new_msr_val = ppc_state.gpr[reg_s];
806+
ppc_msr_did_change(old_msr_val, new_msr_val);
807807

808808
// generate External Interrupt Exception
809809
// if CPU interrupt line is asserted
@@ -1381,8 +1381,9 @@ void dppc_interpreter::ppc_rfi(uint32_t opcode) {
13811381
uint32_t old_msr_val = ppc_state.msr;
13821382
uint32_t new_srr1_val = (ppc_state.spr[SPR::SRR1] & 0x87C0FF73UL);
13831383
uint32_t new_msr_val = (ppc_state.msr & ~0x87C0FF73UL);
1384-
ppc_state.msr = (new_msr_val | new_srr1_val) & 0xFFFBFFFFUL;
1385-
ppc_msr_did_change(old_msr_val);
1384+
1385+
new_msr_val = (new_msr_val | new_srr1_val) & 0xFFFBFFFFUL;
1386+
ppc_msr_did_change(old_msr_val, new_msr_val);
13861387

13871388
// generate External Interrupt Exception
13881389
// if CPU interrupt line is still asserted

cpu/ppc/test/ppctests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void xer_ov_test(string mnem, uint32_t opcode) {
4646
ppc_state.gpr[3] = 2;
4747
ppc_state.gpr[4] = 2;
4848
ppc_state.spr[SPR::XER] = 0xFFFFFFFF;
49-
ppc_main_opcode(ppc_opcode_grabber(), opcode);
49+
ppc_main_opcode(ppc_opcode_grabber, opcode);
5050
if (ppc_state.spr[SPR::XER] & 0x40000000UL) {
5151
cout << "Invalid " << mnem << " emulation! XER[OV] should not be set." << endl;
5252
nfailed++;
@@ -150,7 +150,7 @@ static void read_test_data() {
150150
ppc_state.spr[SPR::XER] = 0;
151151
ppc_state.cr = 0;
152152

153-
ppc_main_opcode(ppc_opcode_grabber(), opcode);
153+
ppc_main_opcode(ppc_opcode_grabber, opcode);
154154

155155
ntested++;
156156

@@ -292,7 +292,7 @@ static void read_test_float_data() {
292292

293293
ppc_state.cr = 0;
294294

295-
ppc_main_opcode(ppc_opcode_grabber(), opcode);
295+
ppc_main_opcode(ppc_opcode_grabber, opcode);
296296

297297
ntested++;
298298

0 commit comments

Comments
 (0)