Amiga.org

Operating System Specific Discussions => Amiga OS => Amiga OS -- Development => Topic started by: srg86 on April 13, 2005, 06:31:20 PM

Title: CPU detection
Post by: srg86 on April 13, 2005, 06:31:20 PM
Hi

Is thare any standard algorithm for m68k cpu detection, as in detecting between 000, 010, 020, 030 etc etc. not forgetting the EC varients.


thanks
srg
Title: Re: CPU detection
Post by: SamuraiCrow on April 13, 2005, 06:41:56 PM
Under AmigaOS you just use the CPU command from the shell.  Other than that I don't know of any.  8-)
Title: Re: CPU detection
Post by: doctorq on April 13, 2005, 06:44:31 PM
Hmm, WhichAmiga by Piru is a execelent program, gives you a lot of useful system information. You can find it on Aminet. Other similar tools are AmiGod and Scout.
Title: Re: CPU detection
Post by: srg86 on April 13, 2005, 06:45:44 PM
This is for use insode my own program, so I can see weather it's safe to procede (requires and MMU).

srg
Title: Re: CPU detection
Post by: Piru on April 13, 2005, 08:58:20 PM
Detecting CPU is trivial job, except when trying to determine between 680EC030 (no mmu) and 68030 (mmu). There is no safe way here, some partially broken 68030 were labeled EC030 and will crash when MMU is used.

Easiest is to test bits in struct ExecBase AttnFlags, that gives you cpu type. That's a good start. Later you can add support for detecting EC040, LC040, EC060 and LC060.

68EC020 vs 68020 test is potentially dangerous as it involves detemining if upper 8bits of address register is ignored (68EC020 only does 24bit addressing, while full 68020 does 32bit).
Title: Re: CPU detection
Post by: srg86 on April 15, 2005, 10:21:37 AM
How do I use ExecBase AttnFlags, how do I access it, I tried declaring:

ExecBase e_base;

and AttnFlags was 0

then I tried:

ExecBase *e_base;

and AttnFlags was $FFFF.

srg
Title: Re: CPU detection
Post by: Piru on April 15, 2005, 10:26:58 AM
Code: [Select]

#include <exec/execbase.h>

#include <proto/dos.h>

extern struct ExecBase *SysBase;

const char *getcpu(void);

int main(void)
{
  Printf(&quot;CPU: %s\n&quot;, getcpu());
  return 0;
}

const char *getcpu(void)
{
  UWORD attnflags = SysBase->AttnFlags;

  if (attnflags & 0x80) return &quot;68060&quot;;
  if (attnflags & AFF_68040) return &quot;68040&quot;;
  if (attnflags & AFF_68030) return &quot;68030&quot;;
  if (attnflags & AFF_68020) return &quot;68020&quot;;
  if (attnflags & AFF_68010) return &quot;68010&quot;;
  return &quot;68000&quot;;
}
Title: Re: CPU detection
Post by: srg86 on April 15, 2005, 02:18:21 PM
Thanks that's great.

srg