/*F============================================================ FUNCTION NAME: cpu_test DESCRIPTION: This function tests the cpu instructions. INPUTS: OUTPUTS: return bool_t TRUE = pass FALSE = fail =============================================================F*/ #define _ASMLANGUAGE .equ BOOT_CPU_TEST_FAIL,0x00009105 .equ LONGPOSVALUE,0x7fa32409 .equ SWAPLONGPOSVALUE,0x24097fa3 .equ LONGNEGVALUE,0x8461bcde .equ LOGICALVALUE1,0xaaaaaaaa .equ LOGICALVALUE2,0x55555555 .equ ADDVAL1,0x1 .equ ADDVAL2,0x3 .equ ADDVAL3,0x4 .equ SUBVAL1,0x8 .equ SUBVAL2,0x6 .equ SUBVAL3,0x2 .equ MULVAL1,0x12 .equ MULVAL2,0x14 .equ MULVAL3,0x168 .equ DIVVAL1,0x8000 .equ DIVVAL2,0x100 .equ DIVVAL3,0x80 .equ SHIFTVAL1,0x0000000f .equ SHIFTVAL2,0x000000f0 .equ SHIFTVAL3,0xf0000000 .equ SHIFTVAL4,0xff000000 .equ EFFECTIVEADD,0x300345 .equ LINKADDR,0x300fa4 .equ MOVEBYTE,0x5a .equ MOVEWORD,0xffff .equ MOVELONG,0xa5a533cc .equ TRUE,0x01 .equ FALSE,0x00 .globl _cpu_test /* entry point */ .data .even .text .even _cpu_test: /* Branch Always Test */ bra cpu0 /* branch always */ move.l #FALSE,d0 /* if falls through, error */ rts /* exit */ /* Any failures from the tests below branch to this fail location. */ fail: movem.l (sp)+,d0-d7/a0-a6 /* restore registers */ /* d0 was included for testing */ move.l #FALSE,d0 /* error return */ rts cpu0: movem.l d0-d7/a0-a6,-(sp) /* push registers - test later */ /* d0 is included to test later */ /* Branch on equ/ne zero Test */ clr.l d0 /* clear a register */ bne fail /* should not branch */ beq cpu10 /* should branch */ bra fail /* go fail */ cpu10: /* Move / Compare / Branch on Conditions / Jmp Tests */ move.l #LONGPOSVALUE,d0 /* set value in register */ cmp.l #LONGPOSVALUE,d0 /* equal ? */ bne fail /* should not branch */ bge cpu20 /* should branch */ bra fail /* go fail */ cpu20: bgt fail /* should not branch */ cmp.l #0,d0 /* equal ? */ beq fail /* should not branch */ blt fail /* should not branch */ bgt cpu30 /* should branch */ bra fail /* go fail */ cpu30: bge cpu31 /* should branch */ bra fail /* go fail */ cpu31: jmp cpu32 /* should jump */ bra fail /* go fail */ cpu32: /* Test movem.l and cmpm */ cmp.l 4(sp),d1 /* regs d1 - a6 must compare */ bne fail /* if no compare - fail */ cmp.l 8(sp),d2 bne fail cmp.l 12(sp),d3 bne fail cmp.l 16(sp),d4 bne fail cmp.l 20(sp),d5 bne fail cmp.l 24(sp),d6 bne fail cmp.l 28(sp),d7 bne fail cmpa.l 32(sp),a0 bne fail cmpa.l 36(sp),a1 bne fail cmpa.l 40(sp),a2 bne fail cmpa.l 44(sp),a3 bne fail cmpa.l 48(sp),a4 bne fail cmpa.l 52(sp),a5 bne fail cmpa.l 56(sp),a6 bne fail /* Register Contents Test */ /* Patterns and bit/byte/word crosstalking */ move.l #LONGNEGVALUE,d0 /* load data registers */ move.l #LONGNEGVALUE,d1 move.l #LONGNEGVALUE,d2 move.l #LONGNEGVALUE,d3 move.l #LONGNEGVALUE,d4 move.l #LONGNEGVALUE,d5 move.l #LONGNEGVALUE,d6 move.l #LONGNEGVALUE,d7 cmp.l #LONGNEGVALUE,d0 /* compare register contents */ bne fail cmp.l #LONGNEGVALUE,d1 bne fail cmp.l #LONGNEGVALUE,d2 bne fail cmp.l #LONGNEGVALUE,d3 bne fail cmp.l #LONGNEGVALUE,d4 bne fail cmp.l #LONGNEGVALUE,d5 bne fail cmp.l #LONGNEGVALUE,d6 bne fail cmp.l #LONGNEGVALUE,d7 bne fail /* Byte swapping */ move.l #LONGPOSVALUE,d0 swap d0 cmp.l #SWAPLONGPOSVALUE,d0 bne fail move.l #LONGPOSVALUE,a0 /* load address registers */ move.l #LONGPOSVALUE,a1 move.l #LONGPOSVALUE,a2 move.l #LONGPOSVALUE,a3 move.l #LONGPOSVALUE,a4 move.l #LONGPOSVALUE,a5 move.l #LONGPOSVALUE,a6 cmpa.l #LONGPOSVALUE,a0 /* compare register contents */ bne fail cmpa.l #LONGPOSVALUE,a1 bne fail cmpa.l #LONGPOSVALUE,a2 bne fail cmpa.l #LONGPOSVALUE,a3 bne fail cmpa.l #LONGPOSVALUE,a4 bne fail cmpa.l #LONGPOSVALUE,a5 bne fail cmpa.l #LONGPOSVALUE,a6 bne fail /* Logical Instructions Test */ move.l #LOGICALVALUE1,d4 /* pattern into register */ andi.l #LOGICALVALUE1,d4 /* and with same pattern */ cmp.l #LOGICALVALUE1,d4 /* pattern should not change */ bne fail /* should not branch */ eori.l #LOGICALVALUE1,d4 /* xor should clear pattern */ bne fail /* should not branch */ ori.l #LOGICALVALUE2,d4 /* or in new pattern */ cmp.l #LOGICALVALUE2,d4 /* should match */ bne fail /* go fail if no match */ /* Arithmetic Instructions Test */ move.l #ADDVAL1,d5 /* test add */ addi.l #ADDVAL2,d5 cmp.l #ADDVAL3,d5 bne fail /* should not branch */ move.l #SUBVAL1,d5 /* test subtract */ subi.l #SUBVAL2,d5 cmp.l #SUBVAL3,d5 bne fail /* should not branch */ move.l #MULVAL1,d5 /* test multiply */ muls.l #MULVAL2,d5 cmp.l #MULVAL3,d5 bne fail /* should not branch */ move.l #DIVVAL1,d5 /* test divide */ divs.l #DIVVAL2,d5 cmp.l #DIVVAL3,d5 bne fail /* should not branch */ /* Shift & Rotate Instructions Test */ move.l #SHIFTVAL1,d7 /* left shift */ lsl.l #4,d7 /* 4 places */ cmp.l #SHIFTVAL2,d7 /* is it equal yet ? */ bne.l fail /* should not branch */ lsr.l #8,d7 /* 8 places right */ bne.l fail /* should not branch */ move.l #SHIFTVAL3,d3 /* arithmetic shift */ asr.l #4,d3 /* right shift */ cmp.l #SHIFTVAL4,d3 /* compare */ bne.l fail /* should not branch */ asl.l #8,d3 /* left shift */ bne.l fail /* should not branch */ move.l #SHIFTVAL1,d2 /* rotate */ ror.l #4,d2 /* right */ cmp.l #SHIFTVAL3,d2 /* compare */ bne.l fail /* should not branch */ rol.l #8,d2 /* rotate left */ cmp.l #SHIFTVAL2,d2 /* compare */ bne.l fail /* should not branch */ /* Control Instructions Test */ /* Bsr and Jsr Instructions */ bsr cpu80 /* test bsr */ bra.l fail /* should not return here - fail */ bra cpu81 /* jump around subroutine */ cpu80: addi.l #6,(sp) /* add 6 to return address */ rts /* return */ bra.l fail /* should never get here */ cpu81: jsr cpu90 /* test jsr */ bra.l fail /* should not return here - fail */ bra cpu91 /* jump around subroutine */ cpu90: addi.l #6,(sp) /* add 6 to return address */ rts /* return */ bra.l fail /* should never get here */ cpu91: /* Effective address Test - lea and pea */ lea.l EFFECTIVEADD,a0 /* effective address test */ cmpa.l #EFFECTIVEADD,a0 /* compare */ bne.l fail /* go fail */ pea EFFECTIVEADD /* push address on stack */ move.l (sp)+,d0 /* pop off stack */ cmp.l #EFFECTIVEADD,d0 /* compare */ bne.l fail /* go fail */ /* Link and Unlink Test */ movea.l #LINKADDR,a6 /* set up a valid link address */ movea.l a7,a3 /* save sp */ movea.l a6,a2 /* save frame ptr */ move.l a3,a1 /* accum */ move.l a3,a0 /* accum */ adda.l #-4,a1 /* new a6 value */ adda.l #-12,a0 /* new sp value */ link a6,#-8 /* do link */ cmpa.l a0,a7 /* check stack position */ bne.l fail /* fail if not same */ cmpa.l a1,a6 /* check frame position */ bne.l fail /* fail if not same */ cmpa.l 8(sp),a2 /* check orig contents of a6 */ unlk a6 /* unlink */ cmpa.l a7,a3 /* should be back to orig */ bne.l fail /* fail if not same */ cmpa.l a6,a2 /* should be back to orig */ bne.l fail /* fail if not same */ /* Bit Instructions Test and moveq */ /* bclr - test bit and clear it */ moveq.l #1,d0 /* set rightmost bit */ bclr.l #0,d0 /* test and clear the bit */ beq.l fail /* sense should not be zero */ tst.l d0 /* see if the bit is now gone */ bne.l fail /* bit should now be zero */ bclr.l #0,d0 /* test and clear zero */ bne.l fail /* should not sense 1 */ tst.l d0 /* see if the bit is still gone */ bne.l fail /* br if its there - go fail */ /* bchg - test bit and change it */ moveq.l #1,d0 /* set rightmost bit */ bchg.l #0,d0 /* test and flip the bit */ beq.l fail /* bit should sense 1 */ tst.l d0 /* see if the bit is now gone */ bne.l fail /* br if still there - go fail */ bchg.l #0,d0 /* test and change zero */ bne.l fail /* should sense 0 */ tst.l d0 /* see if the bit is there */ beq.l fail /* br if not there - go fail */ /* bset - set bit and change it */ moveq.l #0,d0 /* clr rightmost bit */ bset.l #0,d0 /* test and set the bit */ bne.l fail /* bit should sense zero */ tst.l d0 /* see if the bit is there */ beq.l fail /* br if still there - go fail */ bset.l #0,d0 /* test and set a 1 */ beq.l fail /* should sense 1 - fail */ tst.l d0 /* see if the bit is gone */ beq.l fail /* br if not there - go fail */ /* btst - test bit */ moveq.l #0,d0 /* clr rightmost bit */ btst.l #0,d0 /* test the bit */ bne.l fail /* bit should sense zero */ move.l #1,d0 /* set rightmost bit */ btst.l #0,d0 /* test the bit */ beq.l fail /* should sense 1 */ /* Byte and Word Instructions Test */ moveq.l #0,d6 /* clear d0 */ move.b #MOVEBYTE,d6 /* byte into register */ cmpi.l #MOVEBYTE,d6 /* reg contents validation */ bne.l fail /* br if failed */ move.w #MOVEWORD,d6 /* word into register */ cmpi.l #MOVEWORD,d6 /* reg contents validation */ bne.l fail /* br if failed */ move.l #MOVELONG,d6 /* long into register */ cmpi.l #MOVELONG,d6 /* reg contents validation */ bne.l fail /* br if failed */ /* Exit area */ movem.l (sp)+,d0-d7/a0-a6 /* restore registers */ /* d0 was included for testing */ move.l #TRUE,d0 /* pass return */ rts