[comp.sys.amiga] Short assembler program to determine CPU type

erd@tut.cis.ohio-state.edu (Ethan R. Dicks) (03/15/88)

Here is a very small program to determine the type of CPU you are running.  It
is only 3Kb with source, so I am posting it here.  I include the source because
as the comments state, this is my first attempt at assembler and I know it is
crude...efficient, but crude.  I would apreciate e-mailed comments from those
few assembler hacks out there (Bryce, are you listening?) to inprove my style.
I know how to code 68000 efficiently, I need pointers on style regarding the
Amiga include files - structures in C are easy to use, how do you use them (or
their equvalents) assembler?

#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	whatcpu.asm
#	whatcpu.uue
# This archive created: Mon Mar 14 13:31:56 1988
export PATH; PATH=/bin:$PATH
if test -f 'whatcpu.asm'
then
	echo shar: will not over-write existing file "'whatcpu.asm'"
else
cat << \SHAR_EOF > 'whatcpu.asm'
; WhatCPU.asm
;
; Actually a hand conversion of WhatCPU.c by Dave Haynie
;	done by Ethan Dicks 14-mar-88
;
; I did this as my first project in assembler.  Documentation is very
; scanty regarding the use of structures in assembler.  I got the magic
; offset into the ExecBase structure for the AttnFlags word by compiling
; Dave Haynie's program with Lattice, on a friend's machine, then
; running omd on the .o file.
;
; To recompile:
;	asm WhatCPU.asm
;	blink WhatCPU.o
;
; This code is freely redistributable, although not pretty.
;
	section	code

_LVOCloseLibrary	equ	-$19e
_LVOOpenLibrary		equ	-$228
_LVOWrite		equ     -$30
_LVOOutput		equ     -$3c
execbase		equ	4

start:		movea.l	execbase,a6		;save pointer to Execbase in a6
		lea	dosname(pc),a1		;point to library name
		moveq.l	#0,d0			;pick any version
		jsr	_LVOOpenLibrary(a6)	;open dos.library
		movea.l	d0,a5			;save DosBase in A5
		jsr	_LVOOutput(a5)  
		move.l	d0,d5			;save OutputHandle in D5
;
; title message
;
		move.l	#header,d2		;print intro message
		move.l	headerlength,d3
		bsr.s	print   
;
; check bits
;
		btst	#1,297(a6)		;check Afb_68020
		beq.s	not68020		;nope...
		move.l	#mc68020,d2		;print "68020"
		moveq.l	#6,d3
		bsr.s	print
		bra.s	break
;
not68020:	btst	#0,297(a6)		;check Afb_68010
		beq.s	not68010		;nope...
		move.l	#mc68010,d2		;print "68010"
		moveq.l	#6,d3
		bsr.s	print
		bra.s	break
;
not68010:	move.l	#mc68000,d2		;must be 68000; print it
		moveq.l	#6,d3
		bsr.s	print
;
break:		btst	#4,297(a6)		;check Afb_68881
		beq.s	not68881		;nope...
		move.l	#mc68881,d2		;print "68881"
		moveq.l	#6,d3
		bsr.s	print
not68881:
;
; <CR> at end of string
;
		move.l	#cr,d2			;finish off with <crlf>
		move.l	crlength,d3
		bsr.s	print   
;
; clean up and exit
;
		movea.l	a5,a1			;get DosBase
		jsr	_LVOCloseLibrary(a6)	;close dos.library
		moveq.l	#0,d0			;set return code
		rts				;go home
;
; subroutines
;
print:		move.l  d5,d1			;set output handle
		jsr     _LVOWrite(a5)		;write string to console
		rts				;go back
;
; data section
;
headerlength:	dc.l	22			;table of string lengths
proclength:	dc.l	6			; for _LVOWrite
crlength:	dc.l	2			;

;
; byte aligned data
;
dosname:	dc.b	'dos.library',0
header:		dc.b	'System Configuration: '
mc68020:	dc.b	'68020 '
mc68010:	dc.b	'68010 '
mc68000:	dc.b	'68000 '
mc68881:	dc.b	'68881 '
cr:		dc.b	13,10

		end

SHAR_EOF
fi # end of overwriting check
if test -f 'whatcpu.uue'
then
	echo shar: will not over-write existing file "'whatcpu.uue'"
else
cat << \SHAR_EOF > 'whatcpu.uue'
begin 777 whatcpu.uue
M   #\P         !               U   #Z0   #4L>0    1#^@".< !.
MKOW8*D!.K?_$*@ D/    *(F.0   (IA7 @N  $!*6<,)#P   "X=@9A2F >
M""X   $I9PPD/    +YV!F$V8 HD/    ,1V!F$J""X ! $I9PHD/    ,IV
M!F$8)#P   #0)CD   "280HB34ZN_F)P $YU(@5.K?_03G4    6    !@  
M  )D;W,N;&EB<F%R>0!3>7-T96T@0V]N9FEG=7)A=&EO;CH@-C@P,C @-C@P
M,3 @-C@P,# @-C@X.#$@#0H      ^P    (         '(   !L    8@  
: %    !$    ,    "     :         _((
 
end
SHAR_EOF
fi # end of overwriting check
#	End of shell archive
exit 0
-- 
Ethan R. Dicks      | ######  This signifies that the poster is a member in
Specialized Software|   ##    good sitting of Inertia House: Bodies at rest.
2101 Iuka Ave.      |   ##
Columbus OH 43201   | ######  "You get it, you're closer."

cmcmanis%pepper@Sun.COM (Chuck McManis) (03/15/88)

Nice program, but it is faster to check the CPU type in ExecBase.

--Chuck McManis
uucp: {anywhere}!sun!cmcmanis   BIX: cmcmanis  ARPAnet: cmcmanis@sun.com
These opinions are my own and no one elses, but you knew that didn't you.

erd@tut.cis.ohio-state.edu (Ethan R. Dicks) (03/15/88)

In article <45416@sun.uucp> cmcmanis@sun.UUCP (Chuck McManis) writes:
>Nice program, but it is faster to check the CPU type in ExecBase.
>
>--Chuck McManis

Thanks, but it does.  I realize that the code is at the opposite pole from
clear, but that is how it works.  The program looks through the pointer
at 4 (absexecbase), then at offset 0x129 from that pointer: equvalent to
execbase.AttnFlags in C.  The reason for posting it is to admit my ignorance
in programming 68000 specifically for the Amiga and to ask for help in using
the include files.  I got the offset 0x129 from dissassembling a version of
this program written in C to see where it looked.

-ethan
-- 
Ethan R. Dicks      | ######  This signifies that the poster is a member in
Specialized Software|   ##    good sitting of Inertia House: Bodies at rest.
2101 Iuka Ave.      |   ##
Columbus OH 43201   | ######  "You get it, you're closer."

bryce@eris (Bryce Nesbitt) (03/16/88)

[This is a perfect example of a comp.sys.amiga.tech-type topic]

In a comp.sys.amiga article, erd@tut.cis.ohio-state.edu (Ethan R. Dicks) writes:
>
>This is my first attempt at assembler and I know it is
>crude...efficient, but crude.  I would apreciate [comments]...
>[I need help with] Amiga include files - structures in C are easy to use,
>how do you use them (or their equvalents) in assembler?

Structures work nearly the same in assembler as in C, thanks to some
include file macros provided by C-A.  You will need to have a copy of
those (with comments).  They should have come with your assembler, and you
should have identified just what assembler that is.

Here is an example that gets the processor AttnFlags word....

	INCLUDE "exec/types.i"		;Macro file, always include it
	INCLUDE "exec/execbase.i"	;We want to use execbase

	move.l	4,a6			;Get the location of ExecBase
	move.w	AttnFlags(a6),d0	;Get the word that is "AttnFlags"
					; past a6.
	rts
	

>		btst	#1,297(a6)		;check Afb_68020

Remember, this is really "btst.b".  It only looks at a byte at a time.
To examine a word or long fully, you must fiddle with pointing at
the proper part of the bigger picture.


This is best written:

		btst.b	#AFB_68020,AttnFlags+1(a6)
					     ^ Address second half of word



Again, read the commented include files to figgure out what is what.
This goes for C programming also.

|\_/|  . ACK!, NAK!, EOT!, SOH!
{O_o} .     Bryce Nesbitt
 (")        BIX: mleeds (temporarily)
  U	    USENET: bryce@eris.berkeley.EDU -or- ucbvax!eris!bryce