Welcome, Guest. Please login or register.

Author Topic: CPU detection  (Read 3478 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: CPU detection
« 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).
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: CPU detection
« Reply #1 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;;
}