Home | History | Annotate | Line # | Download | only in sparc
bsd_fdintr.s revision 1.1
      1 /*
      2  * Copyright (c) 1995 Paul Kranenburg
      3  * All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  * 1. Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  * 2. Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in the
     12  *    documentation and/or other materials provided with the distribution.
     13  * 3. All advertising materials mentioning features or use of this software
     14  *    must display the following acknowledgement:
     15  *      This product includes software developed by Paul Kranenburg.
     16  * 4. The name of the author may not be used to endorse or promote products
     17  *    derived from this software without specific prior written permission
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  *
     30  *	$NetBSD: bsd_fdintr.s,v 1.1 1995/02/22 21:14:18 pk Exp $
     31  */
     32 
     33 #ifndef FDC_C_HANDLER
     34 #ifndef LOCORE
     35 #define LOCORE
     36 #endif
     37 #include "assym.s"
     38 #include <sparc/sparc/intreg.h>
     39 #include <sparc/sparc/auxreg.h>
     40 #include <sparc/sparc/vaddrs.h>
     41 #include <sparc/dev/fdreg.h>
     42 #include <sparc/dev/fdvar.h>
     43 /* XXX this goes in a header file -- currently, it's hidden in locore.s */
     44 #define INTREG_ADDR 0xf8002000
     45 
     46 /* Timeout waiting for chip ready */
     47 #define POLL_TIMO	100000
     48 
     49 /*
     50  * register mnemonics. note overlapping assignments.
     51  */
     52 #define R_fdc	%l0
     53 #define R_msr	%l1
     54 #define R_fifo	%l2
     55 #define R_buf	%l3
     56 #define R_tc	%l4
     57 #define R_stat	%l3
     58 #define R_nstat	%l4
     59 #define R_stcnt	%l5
     60 /* use %l6 and %l7 as short term temporaries */
     61 
     62 
     63 	.seg	"data"
     64 	.align	8
     65 	.global _fdciop
     66 /* A save haven for three precious registers */
     67 save_l:
     68 	.word	0
     69 	.word	0
     70 	.word	0
     71 /* Pointer to a `struct fdcio', set in fd.c */
     72 _fdciop:
     73 	.word	0
     74 
     75 	.seg	"text"
     76 	.align	4
     77 	.global _fdchwintr
     78 
     79 _fdchwintr:
     80 	set	save_l, %l7
     81 	std	%l0, [%l7]
     82 	st	%l2, [%l7 + 8]
     83 
     84 	! load fdc, if it's NULL there's nothing to do: schedule soft interrupt
     85 	sethi	%hi(_fdciop), %l7
     86 	ld	[%l7 + %lo(_fdciop)], R_fdc
     87 
     88 	! load chips register addresses
     89 	ld	[R_fdc + FDC_REG_MSR], R_msr	! get chip MSR reg addr
     90 	ld	[R_fdc + FDC_REG_FIFO], R_fifo	! get chip FIFO reg addr
     91 	!!ld	[R_fdc + FDC_REG_DOR], R_dor	! get chip DOR reg addr
     92 
     93 	! find out what we are supposed to do
     94 	ld	[R_fdc + FDC_ISTATE], %l7	! examine flags
     95 	cmp	%l7, ISTATE_SENSEI
     96 	be	sensei
     97 	 nop
     98 	cmp	%l7, ISTATE_DMA
     99 	bne	spurious
    100 	 nop
    101 
    102 	! pseudo DMA
    103 	ld	[R_fdc + FDC_TC], R_tc		! residual count
    104 	ld	[R_fdc + FDC_DATA], R_buf	! IO buffer
    105 
    106 	ldub	[R_msr], %l7			! get MSR value
    107 nextc:
    108 	btst	NE7_RQM, %l7			! room in fifo?
    109 	bnz,a	0f
    110 	 btst	NE7_NDM, %l7			! overrun?
    111 
    112 	! we filled/emptied the FIFO; update fdc->sc_buf & fdc->sc_tc
    113 	st	R_tc, [R_fdc + FDC_TC]
    114 	b	x
    115 	st	R_buf, [R_fdc + FDC_DATA]
    116 
    117 0:
    118 	bz	resultphase			! overrun/underrun
    119 	btst	NE7_DIO, %l7			! IO direction
    120 	bz	1f
    121 	 deccc	R_tc
    122 	ldub	[R_fifo], %l7			! reading:
    123 	b	2f
    124 	stb	%l7, [R_buf]			!    *fdc->sc_bufp = *reg_fifo
    125 
    126 1:
    127 	ldub	[R_buf], %l7			! writing:
    128 	stb	%l7, [R_fifo]			!    *reg_fifo = *fdc->sc_bufp
    129 2:
    130 	inc	R_buf				! fdc->sc_bufp++
    131 	bne,a	nextc				! if (--fdc->sc_tc) goto ...
    132 	 ldub	[R_msr], %l7			! get MSR value
    133 
    134 	! xfer done: update fdc->sc_buf & fdc->sc_tc, mark istate IDLE
    135 	st	R_tc, [R_fdc + FDC_TC]
    136 	st	R_buf, [R_fdc + FDC_DATA]
    137 
    138 	! flip TC bit in auxreg
    139 	sethi	%hi(_auxio_reg), %l6
    140 	ld	[%l6 + %lo(_auxio_reg)], %l6
    141 	ldub	[%l6], %l7
    142 	or	%l7, AUXIO_MB1|AUXIO_FTC, %l7
    143 	stb	%l7, [%l6]
    144 
    145 	! we have some time to kill; anticipate on upcoming
    146 	! result phase.
    147 	add	R_fdc, FDC_STATUS, R_stat	! &fdc->sc_status[0]
    148 	mov	-1, %l7
    149 	st	%l7, [R_fdc + FDC_NSTAT]	! fdc->sc_nstat = -1;
    150 
    151 	ldub	[%l6], %l7
    152 	andn	%l7, AUXIO_FTC, %l7
    153 	or	%l7, AUXIO_MB1, %l7
    154 	stb	%l7, [%l6]
    155 	b	resultphase1
    156 	 nop
    157 
    158 spurious:
    159 	mov	ISTATE_SPURIOUS, %l7
    160 	st	%l7, [R_fdc + FDC_ISTATE]
    161 	b,a	ssi
    162 
    163 sensei:
    164 	ldub	[R_msr], %l7
    165 	set	POLL_TIMO, %l6
    166 1:	deccc	%l6				! timeout?
    167 	be	ssi
    168 	and	%l7, (NE7_RQM | NE7_DIO | NE7_CB), %l7
    169 	cmp	%l7, NE7_RQM
    170 	bne,a	1b				! loop till chip ready
    171 	 ldub	[R_msr], %l7
    172 	mov	NE7CMD_SENSEI, %l7
    173 	stb	%l7, [R_fifo]
    174 
    175 resultphase:
    176 	! prepare for result phase
    177 	add	R_fdc, FDC_STATUS, R_stat	! &fdc->sc_status[0]
    178 	mov	-1, %l7
    179 	st	%l7, [R_fdc + FDC_NSTAT]	! fdc->sc_nstat = -1;
    180 
    181 resultphase1:
    182 	clr	R_stcnt
    183 	ldub	[R_msr], %l7
    184 	set	POLL_TIMO, %l6
    185 1:	deccc	%l6				! timeout?
    186 	be	ssi
    187 	and	%l7, (NE7_RQM | NE7_DIO | NE7_CB), %l7
    188 	cmp	%l7, NE7_RQM
    189 	be	3f				! done
    190 	cmp	%l7, (NE7_RQM | NE7_DIO | NE7_CB)
    191 	bne,a	1b				! loop till chip ready
    192 	 ldub	[R_msr], %l7
    193 
    194 	cmp	R_stcnt, FDC_NSTATUS		! status overrun?
    195 	bge	2f				! if so, load but dont store
    196 	ldub	[R_fifo], %l7			! load the status byte
    197 	stb	%l7, [R_stat]
    198 	inc	R_stat
    199 	inc	R_stcnt
    200 2:	b	1b
    201 	 ldub	[R_msr], %l7
    202 
    203 3:
    204 	! got status, update sc_nstat and mark istate IDLE
    205 	st	R_stcnt, [R_fdc + FDC_NSTAT]
    206 	mov	ISTATE_IDLE, %l7
    207 	st	%l7, [R_fdc + FDC_ISTATE]
    208 
    209 ssi:
    210 	! set software interrupt
    211 	sethi	%hi(INTREG_ADDR), %l7
    212 	ldsb	[%l7 + %lo(INTREG_ADDR)], %l6
    213 	or	%l6, IE_L4, %l6
    214 	stb	%l6, [%l7 + %lo(INTREG_ADDR)]
    215 
    216 x:
    217 	/*
    218 	 * Restore psr -- note: psr delay honored by pc restore loads.
    219 	 */
    220 	set	save_l, %l7
    221 	ldd	[%l7], %l0
    222 	mov	%l0, %psr
    223 	 nop
    224 	ld	[%l7 + 8], %l2
    225 	jmp	%l1
    226 	rett	%l2
    227 #endif
    228