xref: /netbsd/sys/arch/hpcsh/dev/hd6446x/hd6446x_subr.S (revision bf9ec67e)
1/*	$NetBSD: hd6446x_subr.S,v 1.2 2002/05/09 12:41:09 uch Exp $	*/
2
3/*-
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by UCHIYAMA Yasushi.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 *    must display the following acknowledgement:
20 *        This product includes software developed by the NetBSD
21 *        Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 *    contributors may be used to endorse or promote products derived
24 *    from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39#include <sh3/asm.h>
40#include <sh3/locore.h>
41#include <hpcsh/dev/hd6446x/hd6446xintcreg.h>
42
43/*
44 * int hd6446x_intr_raise(int s):
45 *	raise SR.IMASK and HD6446x ICU interrupt mask to 's'.
46 *	if current SR.IMASK is greater equal 's',nothing to do.
47 *	Returns previous SR.IMASK.
48 */
49NENTRY(hd6446x_intr_raise)
50	stc	sr,	r2
51	mov	#0x78,	r1
52	mov	r2,	r0
53	shll	r1		/* r1 = 0xf0 */
54	and	r1,	r0	/* r0 = SR & 0xf0 */
55	cmp/ge	r4,	r0	/* r0 >= r4 ? T = 1 */
56	bt/s	1f
57	 not	r1,	r1	/* r1 = 0xffffff0f */
58	and	r1,	r2	/* r2 = SR & ~0xf0 */
59	mov	r4,	r1
60	or	r2,	r1	/* r1 = (SR & ~0xf0) | s */
61	ldc	r1,	sr	/* SR = r1 */
62	shlr2	r4
63	shlr	r4
64	mov.l	2f,	r1
65	add	r4,	r1
66	mov.w	@r1,	r2	/* r2 = hd6446x_imask[s >> 4] */
67	mov.l	3f,	r1
68	mov.w	r2,	@r1	/* Set new interrupt mask to HD6446x */
691:	rts
70	 nop	/* return (SR & 0xf0) */
71	.align	2
722:	.long	_C_LABEL(hd6446x_imask)
733:	.long	HD6446X_NIMR
74
75/*
76 * int hd6446x_intr_resume(int s):
77 *	Set SR.IMASK and HD6446x interrupt mask register to
78 *	's' interrupt level. Returns previous SR.IMASK.
79 */
80NENTRY(hd6446x_intr_resume)
81	mov	r4,	r0
82	shlr2	r0
83	shlr	r0
84	mov.l	2f,	r1
85	add	r0,	r1
86	mov.w	@r1,	r2	/* r2 = hd6446x_imask[s >> 4] */
87	mov.l	3f,	r1
88	mov.w	r2,	@r1	/* Set new interrupt mask to HD6446x */
89	stc	sr,	r0	/* r0 = SR */
90	mov	#0x78,	r2
91	shll	r2		/* r2 = 0x000000f0 */
92	not	r2,	r1	/* r1 = 0xffffff0f */
93	and	r0,	r1	/* r1 = (SR & ~0xf0) */
94	or	r1,	r4	/* r4 = (SR & ~0xf0) | level */
95	ldc	r4,	sr	/* Set new IMASK to SR */
96	rts
97	 and	r2,	r0	/* return (SR & 0xf0) */
98	.align	2
992:	.long	_C_LABEL(hd6446x_imask)
1003:	.long	HD6446X_NIMR
101