English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 24 May 2014, 22:31   #1
Mrs Beanbag
Glastonbridge Software
 
Mrs Beanbag's Avatar
 
Join Date: Jan 2012
Location: Edinburgh/Scotland
Posts: 2,243
Cpuid

is there an easy and/or reliable way to tell from asm what CPU your program is running on?
Mrs Beanbag is offline  
Old 24 May 2014, 23:06   #2
Lonewolf10
AMOS Extensions Developer
 
Lonewolf10's Avatar
 
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 44
Posts: 1,924
Not sure if it's reliable (I have never used it yet), but I have some code that is supposed to do it. I'll just go and dig it up...


Edit: Found the code. Not sure where I got this from...

Code:
***************************************************************************
*                        T E S T   C P U   T Y P E                        *
***************************************************************************
;	INPUT:	None
;
;	OUTPUT:	Result stored in "cpu" variable
;
; Tests the type of CPU installed.
***************************************************************************

test_cpu_type:
	movem.l	d0-d1/a0,-(a7)
	move.l	4.w,a0
	move.b	$129(a0),d0
	move.l	#68040,d1	;68040
	btst	#$03,d0
	bne.b	.exit
	move.l	#68030,d1	;68030
	btst	#$02,d0
	bne.b	.exit
	move.l	#68020,d1	;68020
	btst	#$01,d0
	bne.b	.exit
	move.l	#68010,d1	;68010
	btst	#$00,d0
	bne.b	.exit
	move.l	#68000,d1	;68000
.exit
	move.l	d1,cpu
	movem.l	(a7)+,d0-d1/a0
	rts

cpu:	dc.l	0

Last edited by Lonewolf10; 24 May 2014 at 23:11. Reason: found the code
Lonewolf10 is offline  
Old 25 May 2014, 12:55   #3
Mrs Beanbag
Glastonbridge Software
 
Mrs Beanbag's Avatar
 
Join Date: Jan 2012
Location: Edinburgh/Scotland
Posts: 2,243
ok! i never looked at the Execbase structure as much as i should, what if you have a 68060 though?
Mrs Beanbag is offline  
Old 25 May 2014, 21:31   #4
spud
Registered User
 
Join Date: May 2010
Location: London, UK
Posts: 268
Test bit 7. (Thanks to Stingray)
spud is offline  
Old 25 May 2014, 23:27   #5
Lonewolf10
AMOS Extensions Developer
 
Lonewolf10's Avatar
 
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 44
Posts: 1,924
Quote:
Originally Posted by Mrs Beanbag View Post
ok! i never looked at the Execbase structure as much as i should
Glad I could help you out


Quote:
Originally Posted by spud View Post
Test bit 7. (Thanks to Stingray)
Any ideas what bits 4,5 and 6 are used for? Just for completeness
Lonewolf10 is offline  
Old 26 May 2014, 11:42   #6
musashi5150
move.w #$4489,$dff07e
 
musashi5150's Avatar
 
Join Date: Sep 2005
Location: Norfolk, UK
Age: 42
Posts: 2,351
Quote:
Originally Posted by spud View Post
Test bit 7. (Thanks to Stingray)
IIRC think that's only valid after a Setpatch on my 3.9 system? So it wouldn't work from a bootblock for example
musashi5150 is offline  
Old 26 May 2014, 13:32   #7
hooverphonique
ex. demoscener "Bigmama"
 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
Quote:
Originally Posted by Lonewolf10 View Post
Any ideas what bits 4,5 and 6 are used for? Just for completeness
Code:
******* Bit defines for AttnFlags (see above) *******************************

*  Processors and Co-processors:
	BITDEF	AF,68010,0	; also set for 68020
	BITDEF	AF,68020,1	; also set for 68030
	BITDEF	AF,68030,2	; also set for 68040
	BITDEF	AF,68040,3
	BITDEF	AF,68881,4	; also set for 68882
	BITDEF	AF,68882,5
	BITDEF	AF,FPU40,6	; Set if 68040 FPU
;
; The AFB_FPU40 bit is set when a working 68040 FPU
; is in the system.  If this bit is set and both the
; AFB_68881 and AFB_68882 bits are not set, then the 68040
; math emulation code has not been loaded and only 68040
; FPU instructions are available.  This bit is valid *ONLY*
; if the AFB_68040 bit is set.
;
;	BITDEF	AF,RESERVED8,8
;	BITDEF	AF,RESERVED9,9
	BITDEF	AF,PRIVATE,15	; Just what it says
hooverphonique is offline  
Old 26 May 2014, 15:54   #8
Mrs Beanbag
Glastonbridge Software
 
Mrs Beanbag's Avatar
 
Join Date: Jan 2012
Location: Edinburgh/Scotland
Posts: 2,243
I suppose I really want to know if CPU has certain features or not, rather than the exact model (i.e. does it have 68020 addressing modes), and don't want to rely on OS patches or even OS versions. Maybe something like the following would work?
Code:
  moveq #2,D0
  move.w data(PC,D0*2),D0
...
data:
  dc.w 0, 0, $ff
If CPU doesn't support scaled indexing, it won't throw an exception, it will just reference the "wrong" address.
Mrs Beanbag is offline  
Old 26 May 2014, 18:39   #9
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
In that case you can just stick to checking the AttnFlags in execbase, because the 68020 is supported since Kickstart 1.2, and this flag will be set during early startup.
Leffmann is offline  
Old 26 May 2014, 19:35   #10
Mrs Beanbag
Glastonbridge Software
 
Mrs Beanbag's Avatar
 
Join Date: Jan 2012
Location: Edinburgh/Scotland
Posts: 2,243
ah ok, so the 68020 bit is set even for 68030+ as well
Mrs Beanbag is offline  
Old 29 May 2014, 19:13   #11
Lonewolf10
AMOS Extensions Developer
 
Lonewolf10's Avatar
 
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 44
Posts: 1,924
Quote:
Originally Posted by Mrs Beanbag View Post
ah ok, so the 68020 bit is set even for 68030+ as well


Yes, see hooverphonique's reply to my question.

As I understand it the bit relevant to the cpu is set, aswell as the bits to all the earlier cpu's. So if a 68040 was detected, the flag for the 68040 and the flags for the 68030,68020 and 68010 would all be set.
Lonewolf10 is offline  
Old 29 May 2014, 23:41   #12
Mrs Beanbag
Glastonbridge Software
 
Mrs Beanbag's Avatar
 
Join Date: Jan 2012
Location: Edinburgh/Scotland
Posts: 2,243
d'oh, looks like i've not been paying attention in class
Mrs Beanbag is offline  
Old 03 June 2014, 23:30   #13
Lonewolf10
AMOS Extensions Developer
 
Lonewolf10's Avatar
 
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 44
Posts: 1,924
Quote:
Originally Posted by Mrs Beanbag View Post
d'oh, looks like i've not been paying attention in class
No problem

I just hope the teacher doesn't surprise us with a test...
Lonewolf10 is offline  
Old 06 June 2014, 01:10   #14
Photon
Moderator
 
Photon's Avatar
 
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,602
I could upload my RigInfo source to Coppershade, there's no sure fire way to tell the diff between 040 and 060 easily tho.
Photon is offline  
Old 06 June 2014, 09:20   #15
Gunnar
Registered User
 
Join Date: Apr 2014
Location: Germany
Posts: 154
Quote:
Originally Posted by Photon View Post
I could upload my RigInfo source to Coppershade, there's no sure fire way to tell the diff between 040 and 060 easily tho.

you can identify whether its a 060 or 040.


pseudo_example:

lea its_a_060,A0
move.l A0,illegalvector

movep
its_a_040



If you want to see whether your CPU support Scaling address mode then
I would just prope it.

moveq #1,D0
lea data,A0
move.b -1(A0,D0*2),D1

-- The value in D1 will tell you whether your CPU supports scaling

data dc,b 0,1


EDIT just noticed someone posted the same before...
Gunnar is offline  
Old 06 June 2014, 10:31   #16
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
I wouldn't use MOVEP because future "super" 68060 re-implementation may implement it (also UAE for performance reasons implements all instructions in fast CPU modes unless specifically disabled)

EDIT: Of course testing only for MOVEP to check if emulation is missing (=getting exception) instead of crashing is probably good enough reason to test it

For best compatibility I'd use exact same tests that KS ROM and 68040/060 libraries use (because obviously any re-implementation must pass those tests correctly too!). Only use if there is really need for "low level" check.

MOVEC to/from VBR -> 68000 if exception
MOVEC CACR -> 68010 if exception
Set 68020 inst cache bit in CACR, read it back, if still set, at least 68020+
Set 68030 data cache bit in CACR, read it back, if still set, must be 68030
Set 68040/060 inst cache bit in CACR, read it back, if set, at least 68040+
MOVEC from PCR -> 68040 (or older) if exception

Last edited by Toni Wilen; 06 June 2014 at 11:39.
Toni Wilen is online now  
Old 06 June 2014, 13:45   #17
Photon
Moderator
 
Photon's Avatar
 
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,602
Tests that pass current hardware is good enough, and emulators should not be considered when coding for Amiga.

Toni's last line there to diff 060 from 040 does the job though, so why not use it?

Turns out RigInfo.S was already uploaded :P

With the CPU bit being

Code:
     ;---cpu----------
	moveq #"6",d0
	move.b $129(a5),d4	;processorinfo
	bmi.s .go060		;"default"
	subq.w #2,d0
	btst #3,d4
	bne.s .cpuok		;040
	subq.w #1,d0
	btst #2,d4
	bne.s .cpuok		;030
	subq.w #1,d0
	btst #1,d4
	bne.s .cpuok		;020
	subq.w #1,d0
	btst #0,d4
	bne.s .cpuok		;010
	subq.w #1,d0		;000
.cpuok:
Photon is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 16:38.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.16012 seconds with 12 queries