ASM detect CPU type ?

News,announcements,programming,fixes,game patches & discussions.
User avatar
exxos
Site Admin
Site Admin
Posts: 28357
Joined: 16 Aug 2017 23:19
Location: UK

ASM detect CPU type ?

Post by exxos »

This is in the TOS sources for checking CPU and setting the cookie..

Code: Select all

/* detect CPU type */
        moveq.l   #0,d1         /* assume 68000 */
        movea.w   #_illinst,a2
        movea.l   (a2),a3       /* save illegal instruction vector */
        movea.l   a7,a1         /* save SP */
        move.l    #cpuexit,(a2)
        CCR_D0                  /* move.w ccr,d0 legal on 68010+ */
        moveq.l   #10,d1        /* assume 68000 */
        dc.w $49c0              /* extb.l    d0 */
        moveq.l   #20,d1        /* assume 68020 */
        CACR_D0
        bset      #9,d0         /* set an unused bit */
        D0_CACR
        CACR_D0
        bclr      #9,d0
        beq.s     cpuexit
        moveq.l   #30,d1        /* assume 68030 */
        D0_CACR
cpuexit:
        movea.l   a1,a7         /* restore SP */
        move.l    a3,(a2)       /* save illegal instruction vector */
        move.l    d1,(a0)+      /* set _CPU cookie */
        sne       (_longframe+1).w

I tried to patch it to just output some text when a 68000 or 68010 is found, but well, I am clueless on asm :( I can output text on the screen but as soon as I try and do any processing in the above code, it just goes totally nuts trying to compile several hundred lines further down the code :shrug: #clueless

I just thought it would be useful for ST536 TOS to check for a non-030 CPU and output a warning on the screen saying ST536 TOS is not compatible with a 68000 ot 68010 (currently looks like a 020 boots so assume its safe).

So if anyone can help out... :D
User avatar
exxos
Site Admin
Site Admin
Posts: 28357
Joined: 16 Aug 2017 23:19
Location: UK

Re: ASM detect CPU type ?

Post by exxos »

My attempt compiled but it does not boot up at all now :lol:

Code: Select all

/* detect CPU type */
/* (actually nonsense since 68030 instructions have already been used above) */
        moveq.l   #0,d1         /* assume 68000 */
        movea.w   #_illinst,a2
        movea.l   (a2),a3       /* save illegal instruction vector */
        movea.l   a7,a1         /* save SP */
        jsr			exxos
		move.l    #cpuexit,(a2)
        CCR_D0                  /* move.w ccr,d0 legal on 68010+ */
        moveq.l   #10,d1        /* assume 68000 */
        dc.w $49c0              /* extb.l    d0 */
        moveq.l   #20,d1        /* assume 68020 */
        CACR_D0
        bset      #9,d0         /* set an unused bit */
        D0_CACR
        CACR_D0
        bclr      #9,d0
        beq.s     cpuexit
        moveq.l   #30,d1        /* assume 68030 */
        D0_CACR
cpuexit:
        movea.l   a1,a7         /* restore SP */
        move.l    a3,(a2)       /* save illegal instruction vector */
        move.l    d1,(a0)+      /* set _CPU cookie */
        sne       (_longframe+1).w
		jmp		doneit

exxos:
		move.w    #$0058,-(a7)
        move.l    #$00030002,-(a7)
        trap      #13         /* Bconout(2, 'X') */
		addq.w    #6,a7
rts

doneit:
User avatar
Badwolf
Site sponsor
Site sponsor
Posts: 3043
Joined: 19 Nov 2019 12:09

Re: ASM detect CPU type ?

Post by Badwolf »

exxos wrote: 08 Dec 2022 13:07 My attempt compiled but it does not boot up at all now :lol:
You'll be trampling all over registers by calling your code from the midst of the routine. Try calling your routine from 'doneit'?

BW
DFB1 Open source 50MHz 030 and TT-RAM accelerator for the Falcon
Smalliermouse ST-optimised USB mouse adapter based on SmallyMouse2
FrontBench The Frontier: Elite 2 intro as a benchmark
User avatar
mfro
Posts: 124
Joined: 13 Dec 2018 07:32

Re: ASM detect CPU type ?

Post by mfro »

That probably won't work even if done "correctly".

Chicken and egg situation.

CPU type detection has to happen very early in the boot process. So early that the exception vector table isn't yet initialized, consequently you can't call any BIOS function (well, you can, but it will not succeed).
And remember: Beethoven wrote his first symphony in C.
User avatar
exxos
Site Admin
Site Admin
Posts: 28357
Joined: 16 Aug 2017 23:19
Location: UK

Re: ASM detect CPU type ?

Post by exxos »

mfro wrote: 08 Dec 2022 14:11 CPU type detection has to happen very early in the boot process. So early that the exception vector table isn't yet initialized, consequently you can't call any BIOS function (well, you can, but it will not succeed).
ah never thought of that. I know text after the logo appears works, but I just tried it before the logo and the text does not appear on the screen :roll:

So I guess I should just move this code and duplicate it later on :roll:
User avatar
mfro
Posts: 124
Joined: 13 Dec 2018 07:32

Re: ASM detect CPU type ?

Post by mfro »

exxos wrote: 08 Dec 2022 14:16 So I guess I should just move this code and duplicate it later on :roll:
Then no need to duplicate code - if you call your routine after TOS has figured out the CPU type, you just need to report the value of the _longframe ($59e.w) system variable. TOS will set it to 0 if a '000 or '010 CPU has been detected (and only then).
And remember: Beethoven wrote his first symphony in C.
User avatar
exxos
Site Admin
Site Admin
Posts: 28357
Joined: 16 Aug 2017 23:19
Location: UK

Re: ASM detect CPU type ?

Post by exxos »

mfro wrote: 08 Dec 2022 14:25 Then no need to duplicate code - if you call your routine after TOS has figured out the CPU type, you just need to report the value of the _longframe ($59e.w) system variable. TOS will set it to 0 if a '000 or '010 CPU has been detected (and only then).
Makes sense. Only slight problem is I have no idea how to do that in assembly :lol: I only just figured out how to do a subroutine jump never mind checking registers and various CPU numbers.
User avatar
Badwolf
Site sponsor
Site sponsor
Posts: 3043
Joined: 19 Nov 2019 12:09

Re: ASM detect CPU type ?

Post by Badwolf »

exxos wrote: 08 Dec 2022 14:34
mfro wrote: 08 Dec 2022 14:25 Then no need to duplicate code - if you call your routine after TOS has figured out the CPU type, you just need to report the value of the _longframe ($59e.w) system variable. TOS will set it to 0 if a '000 or '010 CPU has been detected (and only then).
Makes sense. Only slight problem is I have no idea how to do that in assembly :lol: I only just figured out how to do a subroutine jump never mind checking registers and various CPU numbers.
Something like

Code: Select all

	tst.w _longframe
	bne exxosnotneeded
	jsr exxos
exxosnotneeded:	
	
Inserted somewhere appropriate?

BW

(I iz not assemblerist)
DFB1 Open source 50MHz 030 and TT-RAM accelerator for the Falcon
Smalliermouse ST-optimised USB mouse adapter based on SmallyMouse2
FrontBench The Frontier: Elite 2 intro as a benchmark
User avatar
exxos
Site Admin
Site Admin
Posts: 28357
Joined: 16 Aug 2017 23:19
Location: UK

Re: ASM detect CPU type ?

Post by exxos »

Badwolf wrote: 08 Dec 2022 14:43 Inserted somewhere appropriate?
The whole thing is fast heading for the bin literally and metaphorically :lol:


Have been trying to output a string of text and having precisely zero luck as well. I can output a single letter in a different routine though. Very bizarre.

Code: Select all

                lea     stuff(pc),a0
                move.l  a0,-(sp)
                move.w  #9,-(sp)        /* cconws */
                trap    #1
                addq.l  #6,sp

stuff:
                dc.b 'Hello World'
User avatar
mfro
Posts: 124
Joined: 13 Dec 2018 07:32

Re: ASM detect CPU type ?

Post by mfro »

exxos wrote: 08 Dec 2022 14:47
Badwolf wrote: 08 Dec 2022 14:43 Inserted somewhere appropriate?
The whole thing is fast heading for the bin literally and metaphorically :lol:
Now it depends on where "appropriate" is. You are calling a GEMDOS function now. That's supposed to fail as well until GEMDOS is fully initialised.
And remember: Beethoven wrote his first symphony in C.

Return to “SOFTWARE PROGRAMMING & DISCUSSION”

Who is online

Users browsing this forum: ClaudeBot and 4 guests