Amiga.org

Amiga computer related discussion => Amiga Hardware Issues and discussion => Topic started by: ejstans on July 23, 2009, 10:49:41 PM

Title: How to detect CPU?
Post by: ejstans on July 23, 2009, 10:49:41 PM
Hello (Again? Possible repost as forum seems to have eaten my previous one...)

Is there a way to determine the model (68000 - 68060) of the CPU? The old "How to code" document suggest to check the AttnFlags of Exec, but this only supports up to 68040, at least on V3.0. Does later versions support 68060? And how does the OS detect the model of the CPU anyway?
Also, short of trying to measure it, is there a way to determine the clock frequency of the CPU?

Thanks!
Title: Re: How to detect CPU?
Post by: Karlos on July 24, 2009, 12:05:57 AM
You can still use AttnFlags, but you might have to #define the value:

#ifndef AFB_68060
#define AFB_68060 7
#endif

#ifndef AFF_68060
#define AFF_68060 (1<#endif

I believe this only works if the 68060.library is installed. As for speed, timing a known-cycle (per CPU type) loop seems to be a way to do it, but you'll need to ensure the instruction cache (if present) is enabled.

Piru would be the man to ask as his WhichAmiga tool detects the entire gamut of m68k amiga configurations.
Title: Re: How to detect CPU?
Post by: boing4000 on July 24, 2009, 06:14:01 PM
Take a look at this archive:
http://aminet.net/package/util/moni/WhichAmiga

It also contain the assembly source code with all kind of info and hardware detection issue.
Title: Re: How to detect CPU?
Post by: ejstans on July 24, 2009, 07:27:12 PM
Great! I think that's exactly what I need! :)

Thanks!
Title: Re: How to detect CPU?
Post by: terminator4 on July 24, 2009, 07:43:23 PM
Quote from: Karlos;516689

Piru would be the man to ask as his WhichAmiga tool detects the entire gamut of m68k amiga configurations.


Lets not exaggerate, not entire gamut.  Works fine on my Amiga 4000 060 but not with A2000 060.   In that respect it was quite disappointing for me.
Title: Re: How to detect CPU?
Post by: Karlos on July 24, 2009, 08:22:26 PM
Quote from: terminator4;516744
Lets not exaggerate, not entire gamut.  Works fine on my Amiga 4000 060 but not with A2000 060.   In that respect it was quite disappointing for me.


What I meant was it clearly has code that can differentiate 060 from every other m68k that has been used in an Amiga, which means that Piru obviously knows a suitable method.
Title: Re: How to detect CPU?
Post by: delshay on July 24, 2009, 09:42:41 PM
i wonder if any program can detect my freescale MC68EC020AA25 located on my A1200 motherboard.
Title: Re: How to detect CPU?
Post by: Piru on July 24, 2009, 10:20:31 PM
Quote from: delshay;516752
i wonder if any program can detect my freescale MC68EC020AA25 located on my A1200 motherboard.
WhichAmiga can at least tell 68EC020 from full 68020.

Regarding WhichAmiga failing on certain configurations: It is a known feature. Unfortunately it's impossible to make such a hacky application work on every imaginable configuration.
Title: Re: How to detect CPU?
Post by: x303 on July 24, 2009, 10:32:59 PM
What you need is this:

UBYTE *cpu[]= { "MC68000", "MC68010", "MC68020", "MC68030", "XC68040", "XC68060" };
int cpux=0;

int main()
{

UBYTE cpuname[40];
.......
checkcpu();
strcpy(cpuname, "CPU = ");
 strcat(cpuname, cpu[cpux]);
.......
}

void checkcpu(void)
{
  UWORD attn = SysBase->AttnFlags;

  if(attn & AFF_68010)
  {
    cpux=1;
  }
  if(attn & AFF_68020)
  {
    cpux=2;
  }
  if(attn & AFF_68030)
  {
    cpux=3;
  }
  if(attn & AFF_68040)
  {
    cpux=4;
  }
  if(attn & AFF_68060)
  {
    cpux=5;
  }
}

x303 :D :D :D
Title: Re: How to detect CPU?
Post by: Karlos on July 24, 2009, 10:44:55 PM
If you need to differentiate between EC and non-EC versions, AttnFlags is no longer sufficient.

Incidentally, AFB_68060/AFF_68060 didn't seem to be #defined in any of my NDK versions.
Title: Re: How to detect CPU?
Post by: Piru on July 24, 2009, 11:55:59 PM
Quote from: Karlos;516759
If you need to differentiate between EC and non-EC versions, AttnFlags is no longer sufficient.

Incidentally, AFB_68060/AFF_68060 didn't seem to be #defined in any of my NDK versions.

68060 was never supported officially by commodore, so the define didn't make any C= NDK, either.

Basically phase5 (and Ralph Schmidt) defined all of that 68060 stuff. See here:

http://www.aminet.net/dev/misc/68060Guide.txt
Title: Re: How to detect CPU?
Post by: x303 on July 25, 2009, 06:25:00 PM
Quote from: Karlos;516759
Incidentally, AFB_68060/AFF_68060 didn't seem to be #defined in any of my NDK versions.

Have you tried ndk os3.9 ? AFB_68060 and AFF_68060 are defined in exec/execbase.h !!!

x303 :D :D :D
Title: Re: How to detect CPU?
Post by: matthey on July 25, 2009, 09:43:28 PM
Quote from: x303;516831
Have you tried ndk os3.9 ? AFB_68060 and AFF_68060 are defined in exec/execbase.h !!!

x303 :D :D :D


Yes, but not in exec/execbase.i

It should look like this...

   BITDEF   AF,FPU40,6   ; Set if 68040/68060 FPU
   BITDEF   AF,68060,7   ; Set if 68060

The 68060 is bit 7 so we can do a tst.b to check it...

   tst.b (AttnFlags+1,a6)   ;btst #AFB_68060,(AttnFlags+1,a6)

Saves 2 bytes and it's faster on some 68k processors ;).
Title: Re: How to detect CPU?
Post by: JosephC on July 25, 2009, 11:57:40 PM
How does one detect if running on ECS or AGA?
Title: Re: How to detect CPU?
Post by: x303 on July 26, 2009, 03:06:53 AM
Quote from: JosephC;516852
How does one detect if running on ECS or AGA?

    Taken from RandyAGA.doc:

          LEA     $DFF000,A5
           MOVE.W  $7C(A5),D0      ; DeniseID or LisaID in AGA
           MOVEQ   #30,D2          ; Check 30 times ( prevents old denise random)
           ANDI.W  #%000000011111111,d0    ; low byte only
DENLOOP:
           MOVE.W  $7C(A5),D1      ; Denise ID (LisaID on AGA)
           ANDI.W  #%000000011111111,d1    ; low byte only
           CMP.B   d0,d1           ; same value?
           BNE.S   NOTAGA          ; Not the same value, then OCS Denise!
           DBRA    D2,DENLOOP      ; (THANX TO DDT/HBT FOR MULTICHECK HINT)
           ORI.B   #%11110000,D0   ; MASK AGA REVISION (will work on new aga)
           CMPI.B  #%11111000,D0   ; BIT 3=AGA (this bit will be=0 in AAA!)
           BNE.S   NOTAGA          ; IS THE AGA CHIPSET PRESENT?
           ST.B    AGA             ; Set the AGA flag that will be tested later
NOTAGA:                         ; NOT AGA, BUT IS POSSIBLE AN AAA MACHINE!!

You can find it here: http://aminet.net/docs/misc/RandyAGA.lha

x303 :D :D :D
Title: Re: How to detect CPU?
Post by: Piru on July 26, 2009, 11:16:13 AM
Quote from: x303;516874
Taken from RandyAGA.doc:

          LEA     $DFF000,A5
           MOVE.W  $7C(A5),D0      ; DeniseID or LisaID in AGA
           MOVEQ   #30,D2          ; Check 30 times ( prevents old denise random)
           ANDI.W  #%000000011111111,d0    ; low byte only
DENLOOP:
           MOVE.W  $7C(A5),D1      ; Denise ID (LisaID on AGA)
           ANDI.W  #%000000011111111,d1    ; low byte only
           CMP.B   d0,d1           ; same value?
           BNE.S   NOTAGA          ; Not the same value, then OCS Denise!
           DBRA    D2,DENLOOP      ; (THANX TO DDT/HBT FOR MULTICHECK HINT)
           ORI.B   #%11110000,D0   ; MASK AGA REVISION (will work on new aga)
           CMPI.B  #%11111000,D0   ; BIT 3=AGA (this bit will be=0 in AAA!)
           BNE.S   NOTAGA          ; IS THE AGA CHIPSET PRESENT?
           ST.B    AGA             ; Set the AGA flag that will be tested later
NOTAGA:                         ; NOT AGA, BUT IS POSSIBLE AN AAA MACHINE!!

You can find it here: http://aminet.net/docs/misc/RandyAGA.lha


That's a bit unreliable, it's better to check Agnus/Alice version.

Code: [Select]

        move.w  $DFF004,d0
        and.w   #$6F00,d0
        cmp.w   #$2200,d0
        beq.b  .aga
        cmp.w   #$2300,d0
 .aga:  seq.b   ISAGA

        ...
        ...

ISAGA:  dc.b    0