Skip to content

Conversation

@Fancy2209
Copy link

This is currently has a hardcoded Timebase Frequency that should probably be made customizable at some point, but at least it works.
Closes #2256

#if 0
#if 1
// Broadway clock speed
#define TB_TIMER_CLOCK (243000000u/4000)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it from original qemu code?

Copy link
Author

@Fancy2209 Fancy2209 Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, for my specific case I needed to use the Wii CPU's Timebase Frequency which is what this value represents
I can replace it with a value used by Qemu somewhere if desired, not sure which one since timebase frequency is different per machine in qemu due to it being hardware and software implementation dependent

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops sorry I thought it was from QEMU. How does QEMU ever set that?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Qemu hardcodes the frequency per machine
E.g. old world PowerMac frequency is set here
https://github.com/qemu/qemu/blob/593aee5df98b4a862ff8841a57ea3dbf22131a5f/hw/ppc/mac_oldworld.c#L117

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh in that case, we have cpu_model to do this things (see uc_ctl_set_cpu_model). Does the Wii use a specific cpu model?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh in that case, we have cpu_model to do this things (see uc_ctl_set_cpu_model). Does the Wii use a specific cpu model?

On the code I've just been using PPC 750 who is the closest qemu has
I'll look into that, thanks!

}

#if 0
#if 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can safely remote all such #if 0 swtiches instead of changing it to #if 1.


OK(uc_emu_start(uc, code_start, code_start + sizeof(code_tblr) - 1, 0, 0));
OK(uc_reg_read(uc, UC_PPC_REG_3, &r3_val));
printf("TBLr: 0x%08x\n", BEINT32(r3_val));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a simple TEST_CHECK ?

OK(uc_close(uc));

char code_tbur[] = "\x7c\x6d\x42\xa6"; // mfspr r3, TBUr
uc_common_setup(&uc, UC_ARCH_PPC, UC_MODE_32 | UC_MODE_BIG_ENDIAN, code_tbur,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider splitting these into 2 or 3 tests.

@wtdcode
Copy link
Member

wtdcode commented Nov 11, 2025

A few stylish reviews. Thanks for your efforts!

The CI failure has nothing to do with this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ppc: TimeBase SPRs aren't emulated properly

2 participants