EASy68K
http://www.easy68k.com/EASy68Kforum/

Finding out CPU type in assembler
http://www.easy68k.com/EASy68Kforum/viewtopic.php?f=6&t=353
Page 1 of 1

Author:  float [ Tue Feb 27, 2007 8:34 am ]
Post subject:  Finding out CPU type in assembler

Hi there,

I've been searching now for several days for an assembler code sample which can find out which CPU and/or FPU is installed in the system. I've been thinking about something which tries using the extra registers/instructions combined with an exception handler, but since I currently only have access to a 68030/68882 system, I cannot find out if it works.
Is there some ready-made code available anywhere?

Author:  lee [ Wed Feb 28, 2007 5:43 am ]
Post subject: 

This hasn't been tested except on a 68008, reads as 68000, and a 68020.

Code:
* this needs to be run at reset or else a way to get the vector base address needs to
* be known

      MOVEQ       0,d0                    * exception vector base, assumes 68000 here
      MOVEA.l     d0,a5                   * point to vector base
      MOVEA.l     $10(a5),a0              * save the address exception vector
      LEA         continue(pc),a1         * get the continue address
      MOVE.l      a1,(a5)                 * save as the address exception vector
      MOVE.l      sp,d7                   * copy the stack pointer
      MOVE.l      d7,d6                   * copy the stack pointer again
      JMP         *+5(pc)                 * cause an address error - all processors

* now there is an address error exception frame on the stack the processor type can be
* deduced from the size of this frame

continue
      MOVE.l      a0,$10(a5)              * restore the address exception vector
      SUB.l       sp,d7                   * calculate the size of the stack frame

      MOVEQ       #0,d0                   * default to 68000 processor
      CMPI.b      #$12,d7                 * compare frame size with that of 68000
      BEQ.s       proc_found              * if 68000 size then exit

      MOVEQ       #10,d0                  * set 68010 processor
      CMPI.b      #$3E,d7                 * compare frame size with that of 68010
      BEQ.s       proc_found              * if 68010 size then exit

      MOVEQ       #70,d0                  * set 68070 processor
      CMPI.b      #$26,d7                 * compare frame size with that of 68070
      BEQ.s       proc_found              * if 68070 size then exit

      MOVE.l      #300,d0                 * set 68300 processor
      CMPI.b      #$1C,d7                 * compare frame size with that of 68300
      BEQ.s       proc_found              * if 68300 size then exit

      MOVEQ       #40,d0                  * set 68040 processor
      CMPI.b      #$10,d7                 * compare frame size with that of 68040
      BEQ.s       proc_found              * if 68040 size then exit

      MOVEQ       #99,d0                  * set 68099, unknown processor
      CMPI.b      #$24,d7                 * compare frame size with that of 68020/030
      BNE.s       proc_found              * if not 68020/030 size then exit

* else test for 68020/68030

      MOVE.l      $1A(a5),a0              * get illegal instruction exception vector
      MOVE.l      $7E(a5),a1              * get format error exception vector

      LEA         is_68020(pc),a2         * set our format error exception vector
      MOVE.l      a2,$7E(a5)              * save format error exception vector

      LEA         is_68030(pc),a2         * set our illegal instruction exception vector
      MOVE.l      a2,$1A(a5)              * save illegal instruction exception vector
      MOVEQ       #20,d0                  * default to 68020 processor

      dc.w        $06FA,$0000,$0002       * CALLM #0,next_word(pc)
                                          * call module, 68020 only
next_word
      dc.w        -1                      * dummy data, cause format error

* illegal instruction exception arrives here

is_68030
      MOVEQ       #30,d0                  * set 68030 processor

* format error exception arrives here

is_68020
      MOVE.l      a1,$7E(a5)              * restore format error exception vector
      MOVE.l      a0,$1A(a5)              * restore illegal instruction exception vector
proc_found
      MOVE.l      d6,sp                   * restore the stack pointer
      ADD.l       #68000,d0               * the processor type is in d0


Lee.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/