Classic Mac OS Software (Discussions on Applications) > Application Development & Programming in the Classic Mac OS

Detecting CPU type in OS 9 - Supervisor Mode?

(1/3) > >>

joevt:
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:

--- Code: --- register UInt32 pvrval;
asm { mfpvr pvrval };

--- End code ---
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.

teroyk:
I think you should change Machine Status Register (MSR) first.
Bit 17 in MSR is privilege level (0: user and supervisor-level; 1: user only)
Somebody who know better can continue how to do it nicely.

robespierre:
The only way to enter supervisor mode is by taking an exception—either an explicit system call (sc) or trap (tw) instruction, or a floating point trap—or servicing an interrupt; both of which redirect execution to system code in the trap or interrupt handler. Changing the MSR (with the mtmsr instruction) is not available from user mode.

The whole reason a processor has a user/supervisor mode bit is to establish limits on what ordinary programs can do. If a program running in user mode could simply change the bit, it could effectively take over the system.

With that said, I wonder when Mac OS began using the user mode. When I did most of my hackery in System 7.5.5, it was in supervisor mode all of the time.

Naiw:
If I remember correctly there is a ”backdoor” in the 68k emulator that allows you to enter/exit ppc supervisor mode; I don’t remember the details but as far as I remember you loaded some constants like Gary or similar (suppose it’s either designed by or an homage to Gary Davidian who made the first 68k emulator implementation).

Unfortunately I can’t find the example code when I attempt to google.

Naiw:
After a bit memory juggling I recalled that the old BootX bootloader used this trick (and obviously another as well, the latter I never tested myself- the 68k emulator way I've tested on both PCI and Nubus macs however).

See file EnterPPCSupervisor.c in either of the source packages here.

https://sourceforge.net/projects/nubus-pmac/files/BootX%20boot%20loader/

Navigation

[0] Message Index

[#] Next page

Go to full version