1/* Clock interrupt test code - print a dot every second. */
2
3#include "asm_regnames.h"
4#include "spimconsreg.h"
5
6#define MEM_BASE		0xa0000000
7#define IOBASE			0xa2000000
8#define MEM_SIZE		32768
9#define INIT_STACK_BASE		MEM_BASE + (MEM_SIZE/2) - 4
10
11	.text
12
13	j __start                    /* Let's skip down to the boring stuff. */
14
15	.org 0x180
16intrp:
17        mfc0 k0,EPC                /* Read the exception program counter. */
18
19	li k1, IOBASE+CLOCK_CONTROL /* Get address of clock control reg. */
20	lw k1, 0(k1)               /* Read it.  */
21	andi k1, k1, CTL_RDY       /* Check the ready bit. */
22	beq k1, zero, iret1           /* If not ready, ignore this interrupt. */
23
24printadot:
25	/* Poll for the display. */
26	li k1, IOBASE+DISPLAY_1_CONTROL /* Get address of display ctrl reg. */
27	lw k1, 0(k1)                   /* Read it. */
28	andi k1, k1, CTL_RDY           /* Is the display ready? */
29	beq k1, zero, printadot           /* If not, then loop. */
30	li k1, IOBASE+DISPLAY_1_DATA    /* Get address of display data reg. */
31	li t0, '.'                      /* Load a dot. */
32	sw t0, 0(k1)                   /* Write it to the display. */
33
34iret1:
35	/* Check the keyboard (we didn't turn interrupts on, so we're
36	 * depending on taking clock interrupts. We'll test kybd/display ints
37	 * later (no, really!)). */
38	li k1, IOBASE+KEYBOARD_1_CONTROL
39	lw k1, 0(k1)                   /* Read it. */
40	andi k1, k1, CTL_RDY           /* Is the keyboard ready? */
41	addu v0, k1, v0
42
43iret:
44	rfe                          /* Restore status bits on the way out. */
45	jr k0                       /* "Our work here is done." */
46
47	.globl __start
48__start:
49	/* Initialize the stack pointer. */
50	li sp, INIT_STACK_BASE
51
52	/* Turn interrupts on in the clock device. */
53	li a1, IOBASE+CLOCK_CONTROL
54	li a0, CTL_IE
55	sw a0, 0(a1)
56
57	/* Turn interrupts on in the CP0. */
58	mfc0 a0, Status
59	ori a0, a0, 0x0401		/* IM2 and IEc */
60	mtc0 a0, Status
61
62	/* Sit and stew until something happens. */
63	move v0, zero
64loop:	beq v0, zero, loop
65	break 0x0
66