How to reliably detect USER or SUPERVISOR mode across CPUs

Anything QL Software or Programming Related.
User avatar
tofro
Font of All Knowledge
Posts: 2685
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: How to reliably detect USER or SUPERVISOR mode across CPUs

Post by tofro »

Nasta wrote:
Dave wrote:How might detecting this tie in with detecting and enabling caches on the 68000, 68020, 68030 and 68060?
Enabling cache on a 68000 is REALLY hard.
Detecting it is even harder ;)

In earnest: You don't detect cache on a 68k CPU (some cache modes make it impossible to be "seen" by the CPU itself) - you rather detect the CPU and then "know" the cache type and mode.

That is done by exploiting subtle (or not so subtle) differences between CPUs. The brute-force method is to try instructions or addressing modes that were only available on later CPUs and see if they trap out (you must be catching the exception though, which is a bit complicated). If your CPU does allow non-word-aligned word access, it must be >= 68020, there are also some small differences with post-increment and pre-decrement (move (sp),-(sp)) modes that can be used to detect the CPU you're working with.

Tobias


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
Dave
SandySuperQDave
Posts: 2765
Joined: Sat Jan 22, 2011 6:52 am
Location: Austin, TX
Contact:

Re: How to reliably detect USER or SUPERVISOR mode across CPUs

Post by Dave »

Well, then it fails on detecting the cache :P


User avatar
Peter
QL Wafer Drive
Posts: 1953
Joined: Sat Jan 22, 2011 8:47 am

Re: How to reliably detect USER or SUPERVISOR mode across CPUs

Post by Peter »

A good example for detecting and initializing various CPU types is found in QDOS Classic, attached.
It creates a set of flag:

bit 0 - at least 68010
bit 1 - at least 68020
bit 2 - at least 68030
bit 3 - at least 68040
bit 4 - at least 68881 (possibly 68882)
bit 5 - 68882 present (or emulation)
bit 6 - 68040 or 68060 on-chip FPU enabled
bit 7 - at least 68060
Attachments
PROCESSOR.zip
(2.99 KiB) Downloaded 101 times


Post Reply