Gestalt doesn't return the correct CPU type for my G4 upgraded Power Mac 8600 in Mac OS 9. Is there another way to get the CPU type?
The pvr (processor version register) is a special purpose register that has the needed info. The following code in CodeWarrior .cpp file should be able to get the value:
register UInt32 pvrval;
asm { mfpvr pvrval };
but it causes a privileged instruction exception since that register is only available in supervisor mode. Is there a way to enter and exit supervisor mode?
Utilities like Powerlogix CPU Director or XLR8 Mach Speed Control have code to display the pvr. CPU Director seems to use a PowerPC system call but I don't know the details.
I might misremember now, but while you can accomplish this for sure in supervisor mode, I believe you could actually read most previledged registers by exploiting the exception handler functionality of the multiprocessing lib, you could only modify a subset of the bits in each register though- I recall playing around with attempting to implement "protected memory" in OS 8/9 by using an exception handler that used the single step bit in the MSR to break arbitrary in software to calculate the EA of upcoming load/store instructions against the application memory bounds for development purposes.
It should be noted tho the callback that you register with InstallExceptionHandler, does not execute in supervisor mode though- you get all registers handed via a structure to the call and that's also how it "filters" what bits you can modify or not.
I could remember incorrectly though... it's about 23 years ago I actually did any classic MacOS development to speak of.
(Multiprocessing lib has a lot of interesting things outside of this btw if you develop "new" macos software, features that clearly wasn't properly understood or overlooked by the vast majority of the developers back then for whatever reason)