xref: /illumos-gate/usr/src/uts/sparc/v9/ml/ddi_v9_asm.s (revision 9b0bb795)
17c478bd9Sstevel@tonic-gate/*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*b5c1d037Seota * Common Development and Distribution License (the "License").
6*b5c1d037Seota * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate/*
22*b5c1d037Seota * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate#include <sys/asi.h>
277c478bd9Sstevel@tonic-gate#include <sys/asm_linkage.h>
287c478bd9Sstevel@tonic-gate#include <sys/machthread.h>
297c478bd9Sstevel@tonic-gate#include <sys/privregs.h>
307c478bd9Sstevel@tonic-gate#include <sys/ontrap.h>
317c478bd9Sstevel@tonic-gate#include <sys/dditypes.h>
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate#include "assym.h"
347c478bd9Sstevel@tonic-gate
357c478bd9Sstevel@tonic-gate/*
367c478bd9Sstevel@tonic-gate * This file implements the following ddi common access
377c478bd9Sstevel@tonic-gate * functions:
387c478bd9Sstevel@tonic-gate *
397c478bd9Sstevel@tonic-gate *	ddi_get{8,16,32,64}
407c478bd9Sstevel@tonic-gate *	ddi_put{8,16,32,64}
417c478bd9Sstevel@tonic-gate *
427c478bd9Sstevel@tonic-gate * and the underlying "trivial" implementations
437c478bd9Sstevel@tonic-gate *
447c478bd9Sstevel@tonic-gate *      i_ddi_{get,put}{8,16,32,64}
457c478bd9Sstevel@tonic-gate *
467c478bd9Sstevel@tonic-gate * which assume that there is no need to check the access handle -
477c478bd9Sstevel@tonic-gate * byte swapping will be done by the mmu and the address is always
487c478bd9Sstevel@tonic-gate * accessible via ld/st instructions.
497c478bd9Sstevel@tonic-gate */
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate/*
527c478bd9Sstevel@tonic-gate * The functionality of each of the ddi_get/put routines is performed by
537c478bd9Sstevel@tonic-gate * the respective indirect function defined in the access handle.  Use of
547c478bd9Sstevel@tonic-gate * the access handle functions provides compatibility across platforms for
557c478bd9Sstevel@tonic-gate * drivers.
567c478bd9Sstevel@tonic-gate *
577c478bd9Sstevel@tonic-gate * By default, the indirect access handle functions are initialized to the
587c478bd9Sstevel@tonic-gate * i_ddi_get/put routines to perform memory mapped IO.  If memory mapped IO
597c478bd9Sstevel@tonic-gate * is not possible or desired, the access handle must be intialized to another
607c478bd9Sstevel@tonic-gate * valid routine to perform the sepcified IO operation.
617c478bd9Sstevel@tonic-gate *
627c478bd9Sstevel@tonic-gate * The alignment and placement of the following functions have been optimized
637c478bd9Sstevel@tonic-gate * such that the implementation specific versions, i_ddi*, fall within the
647c478bd9Sstevel@tonic-gate * same cache-line of the generic versions, ddi_*.  This insures that an
657c478bd9Sstevel@tonic-gate * I-cache hit will occur thus minimizing the performance impact of using the
667c478bd9Sstevel@tonic-gate * access handle.
677c478bd9Sstevel@tonic-gate */
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate	.align 32
707c478bd9Sstevel@tonic-gate	ENTRY(ddi_get8)
717c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_getb)
727c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_io_get8)
737c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_io_getb)
747c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_mem_get8)
757c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_mem_getb)
767c478bd9Sstevel@tonic-gate	ldn      [%o0 + AHI_GET8], %g1   /* hdl->ahi_get8 access hndl */
777c478bd9Sstevel@tonic-gate	jmpl    %g1, %g0                 /* jump to access handle routine */
787c478bd9Sstevel@tonic-gate	nop
797c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_get8)
807c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_getb)
817c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_io_get8)
827c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_io_getb)
837c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_mem_get8)
847c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_mem_getb)
857c478bd9Sstevel@tonic-gate
867c478bd9Sstevel@tonic-gate	.align 16
877c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_get8)
887c478bd9Sstevel@tonic-gate	retl
897c478bd9Sstevel@tonic-gate	ldub	[%o1], %o0
907c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_get8)
917c478bd9Sstevel@tonic-gate
927c478bd9Sstevel@tonic-gate	.align 32
937c478bd9Sstevel@tonic-gate	ENTRY(ddi_get16)
947c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_getw)
957c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_io_get16)
967c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_io_getw)
977c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_mem_get16)
987c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_mem_getw)
997c478bd9Sstevel@tonic-gate	ldn      [%o0 + AHI_GET16], %g1   /* hdl->ahi_get16 access hndl */
1007c478bd9Sstevel@tonic-gate	jmpl    %g1, %g0                  /* jump to access handle routine */
1017c478bd9Sstevel@tonic-gate	nop
1027c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_get16)
1037c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_getw)
1047c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_io_get16)
1057c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_io_getw)
1067c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_mem_get16)
1077c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_mem_getw)
1087c478bd9Sstevel@tonic-gate
1097c478bd9Sstevel@tonic-gate	.align 16
1107c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_get16)
1117c478bd9Sstevel@tonic-gate	ALTENTRY(i_ddi_swap_get16)
1127c478bd9Sstevel@tonic-gate	retl
1137c478bd9Sstevel@tonic-gate	lduh	[%o1], %o0
1147c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_get16)
1157c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_swap_get16)
1167c478bd9Sstevel@tonic-gate
1177c478bd9Sstevel@tonic-gate	.align 32
1187c478bd9Sstevel@tonic-gate	ENTRY(ddi_get32)
1197c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_getl)
1207c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_io_get32)
1217c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_io_getl)
1227c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_mem_get32)
1237c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_mem_getl)
1247c478bd9Sstevel@tonic-gate	ldn      [%o0 + AHI_GET32], %g1   /* hdl->ahi_get32 access handle */
1257c478bd9Sstevel@tonic-gate	jmpl    %g1, %g0		  /* jump to access handle routine */
1267c478bd9Sstevel@tonic-gate	nop
1277c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_get32)
1287c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_getl)
1297c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_io_get32)
1307c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_io_getl)
1317c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_mem_get32)
1327c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_mem_getl)
1337c478bd9Sstevel@tonic-gate
1347c478bd9Sstevel@tonic-gate	.align 16
1357c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_get32)
1367c478bd9Sstevel@tonic-gate	ALTENTRY(i_ddi_swap_get32)
1377c478bd9Sstevel@tonic-gate	retl
1387c478bd9Sstevel@tonic-gate	ld	[%o1], %o0
1397c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_get32)
1407c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_swap_get32)
1417c478bd9Sstevel@tonic-gate
1427c478bd9Sstevel@tonic-gate	.align 32
1437c478bd9Sstevel@tonic-gate	ENTRY(ddi_get64)
1447c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_getll)
1457c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_io_get64)
1467c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_io_getll)
1477c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_mem_get64)
1487c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_mem_getll)
1497c478bd9Sstevel@tonic-gate	ldn      [%o0 + AHI_GET64], %g1   /* hdl->ahi_get64 access handle */
1507c478bd9Sstevel@tonic-gate	jmpl    %g1, %g0                  /* jump to access handle routine */
1517c478bd9Sstevel@tonic-gate	nop
1527c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_get64)
1537c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_getll)
1547c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_io_get64)
1557c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_io_getll)
1567c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_mem_get64)
1577c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_mem_getll)
1587c478bd9Sstevel@tonic-gate
1597c478bd9Sstevel@tonic-gate	.align 16
1607c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_get64)
1617c478bd9Sstevel@tonic-gate	ALTENTRY(i_ddi_swap_get64)
1627c478bd9Sstevel@tonic-gate	retl
1637c478bd9Sstevel@tonic-gate	ldx	[%o1], %o0
1647c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_get64)
1657c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_swap_get64)
1667c478bd9Sstevel@tonic-gate
1677c478bd9Sstevel@tonic-gate	.align 32
1687c478bd9Sstevel@tonic-gate	ENTRY(ddi_put8)
1697c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_putb)
1707c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_io_put8)
1717c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_io_putb)
1727c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_mem_put8)
1737c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_mem_putb)
1747c478bd9Sstevel@tonic-gate	ldn      [%o0 + AHI_PUT8], %g1   /* hdl->ahi_put8 access handle */
1757c478bd9Sstevel@tonic-gate	jmpl    %g1, %g0                 /* jump to access handle routine */
1767c478bd9Sstevel@tonic-gate	nop
1777c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_put8)
1787c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_putb)
1797c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_io_put8)
1807c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_io_putb)
1817c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_mem_put8)
1827c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_mem_putb)
1837c478bd9Sstevel@tonic-gate
1847c478bd9Sstevel@tonic-gate	.align 16
1857c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_put8)
1867c478bd9Sstevel@tonic-gate	retl
1877c478bd9Sstevel@tonic-gate	stub	%o2, [%o1]
1887c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_put8)
1897c478bd9Sstevel@tonic-gate
1907c478bd9Sstevel@tonic-gate	.align 32
1917c478bd9Sstevel@tonic-gate	ENTRY(ddi_put16)
1927c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_putw)
1937c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_io_put16)
1947c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_io_putw)
1957c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_mem_put16)
1967c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_mem_putw)
1977c478bd9Sstevel@tonic-gate	ldn      [%o0 + AHI_PUT16], %g1   /* hdl->ahi_put16 access handle */
1987c478bd9Sstevel@tonic-gate	jmpl    %g1, %g0                  /* jump to access handle routine */
1997c478bd9Sstevel@tonic-gate	nop
2007c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_put16)
2017c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_putw)
2027c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_io_put16)
2037c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_io_putw)
2047c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_mem_put16)
2057c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_mem_putw)
2067c478bd9Sstevel@tonic-gate
2077c478bd9Sstevel@tonic-gate	.align 16
2087c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_put16)
2097c478bd9Sstevel@tonic-gate	ALTENTRY(i_ddi_swap_put16)
2107c478bd9Sstevel@tonic-gate	retl
2117c478bd9Sstevel@tonic-gate	stuh	%o2, [%o1]
2127c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_put16)
2137c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_swap_put16)
2147c478bd9Sstevel@tonic-gate
2157c478bd9Sstevel@tonic-gate	.align 32
2167c478bd9Sstevel@tonic-gate	ENTRY(ddi_put32)
2177c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_putl)
2187c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_io_put32)
2197c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_io_putl)
2207c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_mem_put32)
2217c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_mem_putl)
2227c478bd9Sstevel@tonic-gate	ldn      [%o0 + AHI_PUT32], %g1   /* hdl->ahi_put16 access handle */
2237c478bd9Sstevel@tonic-gate	jmpl    %g1, %g0                  /* jump to access handle routine */
2247c478bd9Sstevel@tonic-gate	nop
2257c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_put32)
2267c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_putl)
2277c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_io_put32)
2287c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_io_putl)
2297c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_mem_put32)
2307c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_mem_putl)
2317c478bd9Sstevel@tonic-gate
2327c478bd9Sstevel@tonic-gate	.align 16
2337c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_put32)
2347c478bd9Sstevel@tonic-gate	ALTENTRY(i_ddi_swap_put32)
2357c478bd9Sstevel@tonic-gate	retl
2367c478bd9Sstevel@tonic-gate	st	%o2, [%o1]
2377c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_put32)
2387c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_swap_put32)
2397c478bd9Sstevel@tonic-gate
2407c478bd9Sstevel@tonic-gate	.align 32
2417c478bd9Sstevel@tonic-gate	ENTRY(ddi_put64)
2427c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_putll)
2437c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_io_put64)
2447c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_io_putll)
2457c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_mem_put64)
2467c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_mem_putll)
2477c478bd9Sstevel@tonic-gate	ldn      [%o0 + AHI_PUT64], %g1   /* hdl->ahi_put64 access handle */
2487c478bd9Sstevel@tonic-gate	jmpl    %g1, %g0                  /* jump to access handle routine */
2497c478bd9Sstevel@tonic-gate	nop
2507c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_put64)
2517c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_putll)
2527c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_io_put64)
2537c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_io_putll)
2547c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_mem_put64)
2557c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_mem_putll)
2567c478bd9Sstevel@tonic-gate
2577c478bd9Sstevel@tonic-gate	.align 16
2587c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_put64)
2597c478bd9Sstevel@tonic-gate	ALTENTRY(i_ddi_swap_put64)
2607c478bd9Sstevel@tonic-gate	retl
2617c478bd9Sstevel@tonic-gate	stx	%o2, [%o1]
2627c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_put64)
2637c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_swap_put64)
2647c478bd9Sstevel@tonic-gate
2657c478bd9Sstevel@tonic-gate/*
2667c478bd9Sstevel@tonic-gate * The ddi_io_rep_get/put routines don't take a flag argument like the "plain"
2677c478bd9Sstevel@tonic-gate * and mem versions do.  This flag is used to determine whether or not the
2687c478bd9Sstevel@tonic-gate * device address or port should be automatically incremented.  For IO space,
2697c478bd9Sstevel@tonic-gate * the device port is never incremented and as such, the flag is always set
2707c478bd9Sstevel@tonic-gate * to DDI_DEV_NO_AUTOINCR.
2717c478bd9Sstevel@tonic-gate *
2727c478bd9Sstevel@tonic-gate * This define processes the repetitive get functionality.  Automatic
2737c478bd9Sstevel@tonic-gate * incrementing of the device address is determined by the flag field
2747c478bd9Sstevel@tonic-gate * %o4.  If this is set for AUTOINCR, %o4 is updated with 1 for the
2757c478bd9Sstevel@tonic-gate * subsequent increment in 2:.
2767c478bd9Sstevel@tonic-gate *
2777c478bd9Sstevel@tonic-gate * If this flag is not set for AUTOINCR, %o4 is update with a value of 0 thus
2787c478bd9Sstevel@tonic-gate * making the increment operation a non-operation.
2797c478bd9Sstevel@tonic-gate */
2807c478bd9Sstevel@tonic-gate
2817c478bd9Sstevel@tonic-gate#define DDI_REP_GET(n,s)			\
2827c478bd9Sstevel@tonic-gate	cmp	DDI_DEV_NO_AUTOINCR, %o4;	\
2837c478bd9Sstevel@tonic-gate	mov	%g0, %o4;			\
2847c478bd9Sstevel@tonic-gate	brz,pn	%o3, 1f;			\
2857c478bd9Sstevel@tonic-gate	movnz	%xcc, n, %o4;			\
2867c478bd9Sstevel@tonic-gate2:						\
2877c478bd9Sstevel@tonic-gate	dec	%o3;				\
2887c478bd9Sstevel@tonic-gate	ld/**/s	[%o2], %g4;			\
2897c478bd9Sstevel@tonic-gate	add	%o2, %o4, %o2;			\
2907c478bd9Sstevel@tonic-gate	st/**/s	%g4, [%o1];			\
2917c478bd9Sstevel@tonic-gate	brnz,pt	%o3, 2b;			\
2927c478bd9Sstevel@tonic-gate	add	%o1, n, %o1;			\
293*b5c1d037Seota1:
2947c478bd9Sstevel@tonic-gate
2957c478bd9Sstevel@tonic-gate	.align 32
2967c478bd9Sstevel@tonic-gate	ENTRY(ddi_rep_get8)
2977c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_rep_getb)
2987c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_mem_rep_get8)
2997c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_mem_rep_getb)
3007c478bd9Sstevel@tonic-gate	ldn      [%o0 + AHI_REP_GET8], %g1
3017c478bd9Sstevel@tonic-gate	jmpl    %g1, %g0
3027c478bd9Sstevel@tonic-gate	nop
3037c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_rep_get8)
3047c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_rep_getb)
3057c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_mem_rep_get8)
3067c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_mem_rep_getb)
3077c478bd9Sstevel@tonic-gate
3087c478bd9Sstevel@tonic-gate	.align 16
3097c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_rep_get8)
3107c478bd9Sstevel@tonic-gate	DDI_REP_GET(1,ub)
3117c478bd9Sstevel@tonic-gate	retl
3127c478bd9Sstevel@tonic-gate	nop
3137c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_rep_get8)
3147c478bd9Sstevel@tonic-gate
3157c478bd9Sstevel@tonic-gate	.align 32
3167c478bd9Sstevel@tonic-gate	ENTRY(ddi_rep_get16)
3177c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_rep_getw)
3187c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_mem_rep_get16)
3197c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_mem_rep_getw)
3207c478bd9Sstevel@tonic-gate	ldn	[%o0 + AHI_REP_GET16], %g1
3217c478bd9Sstevel@tonic-gate	jmpl    %g1, %g0
3227c478bd9Sstevel@tonic-gate	nop
3237c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_rep_get16)
3247c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_rep_getw)
3257c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_mem_rep_get16)
3267c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_mem_rep_getw)
3277c478bd9Sstevel@tonic-gate
3287c478bd9Sstevel@tonic-gate	.align 16
3297c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_rep_get16)
3307c478bd9Sstevel@tonic-gate	ALTENTRY(i_ddi_swap_rep_get16)
3317c478bd9Sstevel@tonic-gate	DDI_REP_GET(2,uh)
3327c478bd9Sstevel@tonic-gate	retl
3337c478bd9Sstevel@tonic-gate	nop
3347c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_rep_get16)
3357c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_swap_rep_get16)
3367c478bd9Sstevel@tonic-gate
3377c478bd9Sstevel@tonic-gate	.align 32
3387c478bd9Sstevel@tonic-gate	ENTRY(ddi_rep_get32)
3397c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_rep_getl)
3407c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_mem_rep_get32)
3417c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_mem_rep_getl)
3427c478bd9Sstevel@tonic-gate	ldn      [%o0 + AHI_REP_GET32], %g1
3437c478bd9Sstevel@tonic-gate	jmpl    %g1, %g0
3447c478bd9Sstevel@tonic-gate	nop
3457c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_rep_get32)
3467c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_rep_getl)
3477c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_mem_rep_get32)
3487c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_mem_rep_getl)
3497c478bd9Sstevel@tonic-gate
3507c478bd9Sstevel@tonic-gate	.align 16
3517c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_rep_get32)
3527c478bd9Sstevel@tonic-gate	ALTENTRY(i_ddi_swap_rep_get32)
3537c478bd9Sstevel@tonic-gate	DDI_REP_GET(4,/**/)
3547c478bd9Sstevel@tonic-gate	retl
3557c478bd9Sstevel@tonic-gate	nop
3567c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_rep_get32)
3577c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_swap_rep_get32)
3587c478bd9Sstevel@tonic-gate
3597c478bd9Sstevel@tonic-gate	.align 32
3607c478bd9Sstevel@tonic-gate	ENTRY(ddi_rep_get64)
3617c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_rep_getll)
3627c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_mem_rep_get64)
3637c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_mem_rep_getll)
3647c478bd9Sstevel@tonic-gate	ldn      [%o0 + AHI_REP_GET64], %g1
3657c478bd9Sstevel@tonic-gate	jmpl    %g1, %g0
3667c478bd9Sstevel@tonic-gate	nop
3677c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_rep_get64)
3687c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_rep_getll)
3697c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_mem_rep_get64)
3707c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_mem_rep_getll)
3717c478bd9Sstevel@tonic-gate
3727c478bd9Sstevel@tonic-gate	.align 16
3737c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_rep_get64)
3747c478bd9Sstevel@tonic-gate	ALTENTRY(i_ddi_swap_rep_get64)
3757c478bd9Sstevel@tonic-gate	DDI_REP_GET(8,x)
3767c478bd9Sstevel@tonic-gate	retl
3777c478bd9Sstevel@tonic-gate	nop
3787c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_rep_get64)
3797c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_swap_rep_get64)
3807c478bd9Sstevel@tonic-gate
3817c478bd9Sstevel@tonic-gate/*
3827c478bd9Sstevel@tonic-gate * This define processes the repetitive put functionality.  Automatic
3837c478bd9Sstevel@tonic-gate * incrementing of the device address is determined by the flag field
3847c478bd9Sstevel@tonic-gate * %o4.  If this is set for AUTOINCR, %o4 is updated with 1 for the
3857c478bd9Sstevel@tonic-gate * subsequent increment in 2:.
3867c478bd9Sstevel@tonic-gate *
3877c478bd9Sstevel@tonic-gate * If this flag is not set for AUTOINCR, %o4 is update with a value of 0 thus
3887c478bd9Sstevel@tonic-gate * making the increment operation a non-operation.
3897c478bd9Sstevel@tonic-gate */
3907c478bd9Sstevel@tonic-gate#define DDI_REP_PUT(n,s)			\
3917c478bd9Sstevel@tonic-gate	cmp	DDI_DEV_NO_AUTOINCR, %o4;	\
3927c478bd9Sstevel@tonic-gate	mov	%g0, %o4;			\
3937c478bd9Sstevel@tonic-gate	brz,pn	%o3, 1f;			\
3947c478bd9Sstevel@tonic-gate	movnz	%xcc, n, %o4;			\
3957c478bd9Sstevel@tonic-gate2:						\
3967c478bd9Sstevel@tonic-gate	dec	%o3;				\
3977c478bd9Sstevel@tonic-gate	ld/**/s	[%o1], %g4;			\
3987c478bd9Sstevel@tonic-gate	add	%o1, n, %o1;			\
3997c478bd9Sstevel@tonic-gate	st/**/s	%g4, [%o2];			\
4007c478bd9Sstevel@tonic-gate	brnz,pt	%o3, 2b;			\
4017c478bd9Sstevel@tonic-gate	add	%o2, %o4, %o2;			\
402*b5c1d037Seota1:
4037c478bd9Sstevel@tonic-gate
4047c478bd9Sstevel@tonic-gate	.align 32
4057c478bd9Sstevel@tonic-gate	ENTRY(ddi_rep_put8)
4067c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_rep_putb)
4077c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_mem_rep_put8)
4087c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_mem_rep_putb)
4097c478bd9Sstevel@tonic-gate	ldn      [%o0 + AHI_REP_PUT8], %g1
4107c478bd9Sstevel@tonic-gate	jmpl    %g1, %g0
4117c478bd9Sstevel@tonic-gate	nop
4127c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_rep_put8)
4137c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_rep_putb)
4147c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_mem_rep_put8)
4157c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_mem_rep_putb)
4167c478bd9Sstevel@tonic-gate
4177c478bd9Sstevel@tonic-gate	.align 16
4187c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_rep_put8)
4197c478bd9Sstevel@tonic-gate	DDI_REP_PUT(1,ub)
4207c478bd9Sstevel@tonic-gate	retl
4217c478bd9Sstevel@tonic-gate	nop
4227c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_rep_put8)
4237c478bd9Sstevel@tonic-gate
4247c478bd9Sstevel@tonic-gate	.align 32
4257c478bd9Sstevel@tonic-gate	ENTRY(ddi_rep_put16)
4267c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_rep_putw)
4277c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_mem_rep_put16)
4287c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_mem_rep_putw)
4297c478bd9Sstevel@tonic-gate	ldn      [%o0 + AHI_REP_PUT16], %g1
4307c478bd9Sstevel@tonic-gate	jmpl    %g1, %g0
4317c478bd9Sstevel@tonic-gate	nop
4327c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_rep_put16)
4337c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_rep_putw)
4347c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_mem_rep_put16)
4357c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_mem_rep_putw)
4367c478bd9Sstevel@tonic-gate
4377c478bd9Sstevel@tonic-gate	.align 16
4387c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_rep_put16)
4397c478bd9Sstevel@tonic-gate	ALTENTRY(i_ddi_swap_rep_put16)
4407c478bd9Sstevel@tonic-gate	DDI_REP_PUT(2,uh)
4417c478bd9Sstevel@tonic-gate	retl
4427c478bd9Sstevel@tonic-gate	nop
4437c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_rep_put16)
4447c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_swap_rep_put16)
4457c478bd9Sstevel@tonic-gate
4467c478bd9Sstevel@tonic-gate	.align 32
4477c478bd9Sstevel@tonic-gate	ENTRY(ddi_rep_put32)
4487c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_rep_putl)
4497c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_mem_rep_put32)
4507c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_mem_rep_putl)
4517c478bd9Sstevel@tonic-gate	ldn      [%o0 + AHI_REP_PUT32], %g1
4527c478bd9Sstevel@tonic-gate	jmpl    %g1, %g0
4537c478bd9Sstevel@tonic-gate	nop
4547c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_rep_put32)
4557c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_rep_putl)
4567c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_mem_rep_put32)
4577c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_mem_rep_putl)
4587c478bd9Sstevel@tonic-gate
4597c478bd9Sstevel@tonic-gate	.align 16
4607c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_rep_put32)
4617c478bd9Sstevel@tonic-gate	ALTENTRY(i_ddi_swap_rep_put32)
4627c478bd9Sstevel@tonic-gate	DDI_REP_PUT(4,/**/)
4637c478bd9Sstevel@tonic-gate	retl
4647c478bd9Sstevel@tonic-gate	nop
4657c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_rep_put32)
4667c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_swap_rep_put32)
4677c478bd9Sstevel@tonic-gate
4687c478bd9Sstevel@tonic-gate	.align 32
4697c478bd9Sstevel@tonic-gate	ENTRY(ddi_rep_put64)
4707c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_rep_putll)
4717c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_mem_rep_put64)
4727c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_mem_rep_putll)
4737c478bd9Sstevel@tonic-gate	ldn      [%o0 + AHI_REP_PUT64], %g1
4747c478bd9Sstevel@tonic-gate	jmpl    %g1, %g0
4757c478bd9Sstevel@tonic-gate	nop
4767c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_rep_put64)
4777c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_rep_putll)
4787c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_mem_rep_put64)
4797c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_mem_rep_putll)
4807c478bd9Sstevel@tonic-gate
4817c478bd9Sstevel@tonic-gate	.align 16
4827c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_rep_put64)
4837c478bd9Sstevel@tonic-gate	ALTENTRY(i_ddi_swap_rep_put64)
4847c478bd9Sstevel@tonic-gate	DDI_REP_PUT(8,x)
4857c478bd9Sstevel@tonic-gate	retl
4867c478bd9Sstevel@tonic-gate	nop
4877c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_rep_put64)
4887c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_swap_rep_put64)
4897c478bd9Sstevel@tonic-gate
4907c478bd9Sstevel@tonic-gate	.align 16
4917c478bd9Sstevel@tonic-gate	ENTRY(ddi_io_rep_get8)
4927c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_io_rep_getb)
4937c478bd9Sstevel@tonic-gate	set	DDI_DEV_NO_AUTOINCR, %o4 /* Set flag to DDI_DEV_NO_AUTOINCR */
4947c478bd9Sstevel@tonic-gate	ldn	[%o0 + AHI_REP_GET8], %g1
4957c478bd9Sstevel@tonic-gate	jmpl    %g1, %g0
4967c478bd9Sstevel@tonic-gate	nop
4977c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_io_rep_get8)
4987c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_io_rep_getb)
4997c478bd9Sstevel@tonic-gate
5007c478bd9Sstevel@tonic-gate	.align 16
5017c478bd9Sstevel@tonic-gate	ENTRY(ddi_io_rep_get16)
5027c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_io_rep_getw)
5037c478bd9Sstevel@tonic-gate	set	DDI_DEV_NO_AUTOINCR, %o4 /* Set flag to DDI_DEV_NO_AUTOINCR */
5047c478bd9Sstevel@tonic-gate	ldn	[%o0 + AHI_REP_GET16], %g1
5057c478bd9Sstevel@tonic-gate	jmpl    %g1, %g0
5067c478bd9Sstevel@tonic-gate	nop
5077c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_io_rep_get16)
5087c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_io_rep_getw)
5097c478bd9Sstevel@tonic-gate
5107c478bd9Sstevel@tonic-gate	.align 16
5117c478bd9Sstevel@tonic-gate	ENTRY(ddi_io_rep_get32)
5127c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_io_rep_getl)
5137c478bd9Sstevel@tonic-gate	set	DDI_DEV_NO_AUTOINCR, %o4 /* Set flag to DDI_DEV_NO_AUTOINCR */
5147c478bd9Sstevel@tonic-gate	ldn	[%o0 + AHI_REP_GET32], %g1
5157c478bd9Sstevel@tonic-gate	jmpl    %g1, %g0
5167c478bd9Sstevel@tonic-gate	nop
5177c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_io_rep_get32)
5187c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_io_rep_getl)
5197c478bd9Sstevel@tonic-gate
5207c478bd9Sstevel@tonic-gate	.align 16
5217c478bd9Sstevel@tonic-gate	ENTRY(ddi_io_rep_get64)
5227c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_io_rep_getll)
5237c478bd9Sstevel@tonic-gate	set	DDI_DEV_NO_AUTOINCR, %o4 /* Set flag to DDI_DEV_NO_AUTOINCR */
5247c478bd9Sstevel@tonic-gate	ldn	[%o0 + AHI_REP_GET64], %g1
5257c478bd9Sstevel@tonic-gate	jmpl    %g1, %g0
5267c478bd9Sstevel@tonic-gate	nop
5277c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_io_rep_get64)
5287c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_io_rep_getll)
5297c478bd9Sstevel@tonic-gate
5307c478bd9Sstevel@tonic-gate        .align 64
5317c478bd9Sstevel@tonic-gate	ENTRY(ddi_check_acc_handle)
5327c478bd9Sstevel@tonic-gate	save	%sp, -SA(WINDOWSIZE), %sp	! get a new window
5337c478bd9Sstevel@tonic-gate	ldn	[%i0 + AHI_FAULT_CHECK], %g1
5347c478bd9Sstevel@tonic-gate	jmpl	%g1, %o7
5357c478bd9Sstevel@tonic-gate	mov	%i0, %o0
5367c478bd9Sstevel@tonic-gate	brnz,a,pn %o0, 0f			! if (return_value != 0)
5377c478bd9Sstevel@tonic-gate	mov	-1, %o0				! 	return (DDI_FAILURE)
5387c478bd9Sstevel@tonic-gate0:						! else	return (DDI_SUCCESS)
5397c478bd9Sstevel@tonic-gate	sra	%o0, 0, %i0
5407c478bd9Sstevel@tonic-gate	ret
5417c478bd9Sstevel@tonic-gate	restore
5427c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_check_acc_handle)
5437c478bd9Sstevel@tonic-gate
5447c478bd9Sstevel@tonic-gate        .align 16
5457c478bd9Sstevel@tonic-gate        ENTRY(i_ddi_acc_fault_check)
5467c478bd9Sstevel@tonic-gate	retl
5477c478bd9Sstevel@tonic-gate	ld      [%o0 + AHI_FAULT], %o0
5487c478bd9Sstevel@tonic-gate        SET_SIZE(i_ddi_acc_fault_check)
5497c478bd9Sstevel@tonic-gate
5507c478bd9Sstevel@tonic-gate	.align 16
5517c478bd9Sstevel@tonic-gate	ENTRY(ddi_io_rep_put8)
5527c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_io_rep_putb)
5537c478bd9Sstevel@tonic-gate	set	DDI_DEV_NO_AUTOINCR, %o4 /* Set flag to DDI_DEV_NO_AUTOINCR */
5547c478bd9Sstevel@tonic-gate	ldn	[%o0 + AHI_REP_PUT8], %g1
5557c478bd9Sstevel@tonic-gate	jmpl    %g1, %g0
5567c478bd9Sstevel@tonic-gate	nop
5577c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_io_rep_put8)
5587c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_io_rep_putb)
5597c478bd9Sstevel@tonic-gate
5607c478bd9Sstevel@tonic-gate	.align 16
5617c478bd9Sstevel@tonic-gate	ENTRY(ddi_io_rep_put16)
5627c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_io_rep_putw)
5637c478bd9Sstevel@tonic-gate	set	DDI_DEV_NO_AUTOINCR, %o4 /* Set flag to DDI_DEV_NO_AUTOINCR */
5647c478bd9Sstevel@tonic-gate	ldn	[%o0 + AHI_REP_PUT16], %g1
5657c478bd9Sstevel@tonic-gate	jmpl    %g1, %g0
5667c478bd9Sstevel@tonic-gate	nop
5677c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_io_rep_put16)
5687c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_io_rep_putw)
5697c478bd9Sstevel@tonic-gate
5707c478bd9Sstevel@tonic-gate	.align 16
5717c478bd9Sstevel@tonic-gate	ENTRY(ddi_io_rep_put32)
5727c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_io_rep_putl)
5737c478bd9Sstevel@tonic-gate	set	DDI_DEV_NO_AUTOINCR, %o4 /* Set flag to DDI_DEV_NO_AUTOINCR */
5747c478bd9Sstevel@tonic-gate	ldn	[%o0 + AHI_REP_PUT32], %g1
5757c478bd9Sstevel@tonic-gate	jmpl    %g1, %g0
5767c478bd9Sstevel@tonic-gate	nop
5777c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_io_rep_put32)
5787c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_io_rep_putl)
5797c478bd9Sstevel@tonic-gate
5807c478bd9Sstevel@tonic-gate	.align 16
5817c478bd9Sstevel@tonic-gate	ENTRY(ddi_io_rep_put64)
5827c478bd9Sstevel@tonic-gate	ALTENTRY(ddi_io_rep_putll)
5837c478bd9Sstevel@tonic-gate	set	DDI_DEV_NO_AUTOINCR, %o4 /* Set flag to DDI_DEV_NO_AUTOINCR */
5847c478bd9Sstevel@tonic-gate	ldn	[%o0 + AHI_REP_PUT64], %g1
5857c478bd9Sstevel@tonic-gate	jmpl    %g1, %g0
5867c478bd9Sstevel@tonic-gate	nop
5877c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_io_rep_put64)
5887c478bd9Sstevel@tonic-gate	SET_SIZE(ddi_io_rep_putll)
5897c478bd9Sstevel@tonic-gate
5907c478bd9Sstevel@tonic-gate	ENTRY(do_peek)
5917c478bd9Sstevel@tonic-gate	rdpr	%pstate, %o3	! check ints
5927c478bd9Sstevel@tonic-gate	andcc	%o3, PSTATE_IE, %g0
5937c478bd9Sstevel@tonic-gate	bz,a	done
5947c478bd9Sstevel@tonic-gate	or	%g0, 1, %o0	! Return failure if ints are disabled
5957c478bd9Sstevel@tonic-gate	wrpr	%o3, PSTATE_IE, %pstate
5967c478bd9Sstevel@tonic-gate	cmp	%o0, 8		! 64-bit?
5977c478bd9Sstevel@tonic-gate	bne,a	.peek_int
5987c478bd9Sstevel@tonic-gate	cmp	%o0, 4		! 32-bit?
5997c478bd9Sstevel@tonic-gate	ldx	[%o1], %g1
6007c478bd9Sstevel@tonic-gate	ba	.peekdone
6017c478bd9Sstevel@tonic-gate	stx	%g1, [%o2]
6027c478bd9Sstevel@tonic-gate.peek_int:
6037c478bd9Sstevel@tonic-gate	bne,a	.peek_half
6047c478bd9Sstevel@tonic-gate	cmp	%o0, 2		! 16-bit?
6057c478bd9Sstevel@tonic-gate	lduw	[%o1], %g1
6067c478bd9Sstevel@tonic-gate	ba	.peekdone
6077c478bd9Sstevel@tonic-gate	stuw	%g1, [%o2]
6087c478bd9Sstevel@tonic-gate.peek_half:
6097c478bd9Sstevel@tonic-gate	bne,a	.peek_byte
6107c478bd9Sstevel@tonic-gate	ldub	[%o1], %g1	! 8-bit!
6117c478bd9Sstevel@tonic-gate	lduh	[%o1], %g1
6127c478bd9Sstevel@tonic-gate	ba	.peekdone
6137c478bd9Sstevel@tonic-gate	stuh	%g1, [%o2]
6147c478bd9Sstevel@tonic-gate.peek_byte:
6157c478bd9Sstevel@tonic-gate	stub	%g1, [%o2]
6167c478bd9Sstevel@tonic-gate.peekdone:
6177c478bd9Sstevel@tonic-gate	membar	#Sync		! Make sure the loads take
6187c478bd9Sstevel@tonic-gate	rdpr	%pstate, %o3	! check&enable ints
6197c478bd9Sstevel@tonic-gate	andcc	%o3, PSTATE_IE, %g0
6207c478bd9Sstevel@tonic-gate	bnz	1f
6217c478bd9Sstevel@tonic-gate	nop
6227c478bd9Sstevel@tonic-gate	wrpr	%o3, PSTATE_IE, %pstate
6237c478bd9Sstevel@tonic-gate1:
6247c478bd9Sstevel@tonic-gate	mov	%g0, %o0
6257c478bd9Sstevel@tonic-gatedone:
6267c478bd9Sstevel@tonic-gate	retl
6277c478bd9Sstevel@tonic-gate	nop
6287c478bd9Sstevel@tonic-gate	SET_SIZE(do_peek)
6297c478bd9Sstevel@tonic-gate
6307c478bd9Sstevel@tonic-gate	ENTRY(do_poke)
6317c478bd9Sstevel@tonic-gate	cmp	%o0, 8		! 64 bit?
6327c478bd9Sstevel@tonic-gate	bne,a	.poke_int
6337c478bd9Sstevel@tonic-gate	cmp	%o0, 4		! 32-bit?
6347c478bd9Sstevel@tonic-gate	ldx	[%o2], %g1
6357c478bd9Sstevel@tonic-gate	ba	.pokedone
6367c478bd9Sstevel@tonic-gate	stx	%g1, [%o1]
6377c478bd9Sstevel@tonic-gate.poke_int:
6387c478bd9Sstevel@tonic-gate	bne,a	.poke_half
6397c478bd9Sstevel@tonic-gate	cmp	%o0, 2		! 16-bit?
6407c478bd9Sstevel@tonic-gate	lduw	[%o2], %g1
6417c478bd9Sstevel@tonic-gate	ba	.pokedone
6427c478bd9Sstevel@tonic-gate	stuw	%g1, [%o1]
6437c478bd9Sstevel@tonic-gate.poke_half:
6447c478bd9Sstevel@tonic-gate	bne,a	.poke_byte
6457c478bd9Sstevel@tonic-gate	ldub	[%o2], %g1	! 8-bit!
6467c478bd9Sstevel@tonic-gate	lduh	[%o2], %g1
6477c478bd9Sstevel@tonic-gate	ba	.pokedone
6487c478bd9Sstevel@tonic-gate	stuh	%g1, [%o1]
6497c478bd9Sstevel@tonic-gate.poke_byte:
6507c478bd9Sstevel@tonic-gate	stub	%g1, [%o1]
6517c478bd9Sstevel@tonic-gate.pokedone:
6527c478bd9Sstevel@tonic-gate	membar	#Sync
6537c478bd9Sstevel@tonic-gate	retl
6547c478bd9Sstevel@tonic-gate	mov	%g0, %o0
6557c478bd9Sstevel@tonic-gate	SET_SIZE(do_poke)
6567c478bd9Sstevel@tonic-gate
6577c478bd9Sstevel@tonic-gate
6587c478bd9Sstevel@tonic-gate/*
6597c478bd9Sstevel@tonic-gate * The peek_fault() and poke_fault() routines below are used as on_trap()
6607c478bd9Sstevel@tonic-gate * trampoline routines.  i_ddi_peek and i_ddi_poke execute do_peek and do_poke
6617c478bd9Sstevel@tonic-gate * under on_trap protection (see <sys/ontrap.h>), but modify ot_trampoline to
6627c478bd9Sstevel@tonic-gate * refer to the corresponding routine below.  If a trap occurs, the trap code
6637c478bd9Sstevel@tonic-gate * will bounce back to the trampoline code, which will effectively cause
6647c478bd9Sstevel@tonic-gate * do_peek or do_poke to return DDI_FAILURE, instead of longjmp'ing back to
6657c478bd9Sstevel@tonic-gate * on_trap.  In the case of a peek, we may also need to re-enable interrupts.
6667c478bd9Sstevel@tonic-gate */
6677c478bd9Sstevel@tonic-gate	.seg	".data"
6687c478bd9Sstevel@tonic-gate.peek_panic:
6697c478bd9Sstevel@tonic-gate	.asciz	"peek_fault: missing or invalid on_trap_data"
6707c478bd9Sstevel@tonic-gate.poke_panic:
6717c478bd9Sstevel@tonic-gate	.asciz	"poke_fault: missing or invalid on_trap_data"
6727c478bd9Sstevel@tonic-gate
6737c478bd9Sstevel@tonic-gate	ENTRY(peek_fault)
6747c478bd9Sstevel@tonic-gate	ldn	[THREAD_REG + T_ONTRAP], %o0	! %o0 = on_trap_data pointer
6757c478bd9Sstevel@tonic-gate	brz,pn	%o0, .peekfail			! if (%o0 == NULL) panic
6767c478bd9Sstevel@tonic-gate	nop
6777c478bd9Sstevel@tonic-gate	lduh	[%o0 + OT_PROT], %o1		! %o1 = %o0->ot_prot
6787c478bd9Sstevel@tonic-gate	andcc	%o1, OT_DATA_ACCESS, %g0	! if (!(%o1 & OT_DATA_ACCESS))
6797c478bd9Sstevel@tonic-gate	bz,pn	%icc, .peekfail			!     panic
6807c478bd9Sstevel@tonic-gate	rdpr	%pstate, %o3
6817c478bd9Sstevel@tonic-gate
6827c478bd9Sstevel@tonic-gate	andcc	%o3, PSTATE_IE, %g0		! enable interrupts
6837c478bd9Sstevel@tonic-gate	bnz	1f
6847c478bd9Sstevel@tonic-gate	nop
6857c478bd9Sstevel@tonic-gate	wrpr	%o3, PSTATE_IE, %pstate
6867c478bd9Sstevel@tonic-gate1:
6877c478bd9Sstevel@tonic-gate	retl
6887c478bd9Sstevel@tonic-gate	sub	%g0, 1, %o0			! return (DDI_FAILURE);
6897c478bd9Sstevel@tonic-gate.peekfail:
6907c478bd9Sstevel@tonic-gate	set	.peek_panic, %o0		! Load panic message
6917c478bd9Sstevel@tonic-gate	call	panic				! Panic if bad t_ontrap data
6927c478bd9Sstevel@tonic-gate	nop
6937c478bd9Sstevel@tonic-gate	SET_SIZE(peek_fault)
6947c478bd9Sstevel@tonic-gate
6957c478bd9Sstevel@tonic-gate
6967c478bd9Sstevel@tonic-gate	ENTRY(poke_fault)
6977c478bd9Sstevel@tonic-gate	ldn	[THREAD_REG + T_ONTRAP], %o0	! %o0 = on_trap_data pointer
6987c478bd9Sstevel@tonic-gate	brz,pn	%o0, .pokefail			! if (%o0 == NULL) panic
6997c478bd9Sstevel@tonic-gate	nop
7007c478bd9Sstevel@tonic-gate	lduh	[%o0 + OT_PROT], %o1		! %o1 = %o0->ot_prot
7017c478bd9Sstevel@tonic-gate	andcc	%o1, OT_DATA_ACCESS, %g0	! if (!(%o1 & OT_DATA_ACCESS))
7027c478bd9Sstevel@tonic-gate	bz,pn	%icc, .pokefail			!     panic
7037c478bd9Sstevel@tonic-gate	nop
7047c478bd9Sstevel@tonic-gate	retl
7057c478bd9Sstevel@tonic-gate	sub	%g0, 1, %o0			! return (DDI_FAILURE);
7067c478bd9Sstevel@tonic-gate.pokefail:
7077c478bd9Sstevel@tonic-gate	set	.poke_panic, %o0		! Load panic message
7087c478bd9Sstevel@tonic-gate	call	panic				! Panic if bad t_ontrap data
7097c478bd9Sstevel@tonic-gate	nop
7107c478bd9Sstevel@tonic-gate	SET_SIZE(poke_fault)
7117c478bd9Sstevel@tonic-gate
7127c478bd9Sstevel@tonic-gate
7137c478bd9Sstevel@tonic-gate/*
7147c478bd9Sstevel@tonic-gate * IO Fault Services
7157c478bd9Sstevel@tonic-gate *
7167c478bd9Sstevel@tonic-gate * Support for protected IO accesses is implemented in the following
7177c478bd9Sstevel@tonic-gate * functions.  A driver may request one of three protection mechanisms
7187c478bd9Sstevel@tonic-gate * that enable the system to survive an access errors.  The protection
7197c478bd9Sstevel@tonic-gate * mechansim is set-up during ddi_regs_map_setup time and may be one of:
7207c478bd9Sstevel@tonic-gate *
7217c478bd9Sstevel@tonic-gate *	DDI_DEFAULT_ACC	- no error protection requested.  We will
7227c478bd9Sstevel@tonic-gate *			use the standard ddi_get/ddi_put operations
7237c478bd9Sstevel@tonic-gate *			defined above.
7247c478bd9Sstevel@tonic-gate *
7257c478bd9Sstevel@tonic-gate *	DDI_FLAGERR - Driver requests that errors encountered will
7267c478bd9Sstevel@tonic-gate *			be flagged by the system.  The driver is
7277c478bd9Sstevel@tonic-gate *			responsible for checking the error status
7287c478bd9Sstevel@tonic-gate *			of the access with a call to ddi_acc_err_get()
7297c478bd9Sstevel@tonic-gate *			upon return of ddi_get or ddi_put.  To prevent
7307c478bd9Sstevel@tonic-gate *			an access from causing a system we use internal
7317c478bd9Sstevel@tonic-gate *			on_trap semantics.
7327c478bd9Sstevel@tonic-gate *
7337c478bd9Sstevel@tonic-gate *			The system, depending upon the error,
7347c478bd9Sstevel@tonic-gate *			may or may not panic.
7357c478bd9Sstevel@tonic-gate *
7367c478bd9Sstevel@tonic-gate *	DDI_CAUTIOUS_ACC - Driver expects that the access may cause
7377c478bd9Sstevel@tonic-gate *			an error to occur.  The system will return
7387c478bd9Sstevel@tonic-gate *			an error status but will not generate an ereport.
7397c478bd9Sstevel@tonic-gate *			The system will also ensure synchronous and
7407c478bd9Sstevel@tonic-gate *			exclusive access to the IO space accessed by
7417c478bd9Sstevel@tonic-gate *			the caller.
7427c478bd9Sstevel@tonic-gate *
7437c478bd9Sstevel@tonic-gate *			To prevent an access from causing a system panic,
7447c478bd9Sstevel@tonic-gate *			we use on_trap semantics to catch the error and
7457c478bd9Sstevel@tonic-gate *			set error status.
7467c478bd9Sstevel@tonic-gate *
7477c478bd9Sstevel@tonic-gate *	If a read access error is detected and DDI_CAUTIOUS_ACC or
7487c478bd9Sstevel@tonic-gate *	DDI_FLAGERR_ACC	protection was requested, we will trampoline to the
7497c478bd9Sstevel@tonic-gate *	error handler, i_ddi_trampoline.  i_ddi_trampoline will:
7507c478bd9Sstevel@tonic-gate *		- check for proper protection semantics
7517c478bd9Sstevel@tonic-gate *		- set the error status of the access handle to DDI_FM_NONFATAL
7527c478bd9Sstevel@tonic-gate *		- re-enable interrupts if neccessary
7537c478bd9Sstevel@tonic-gate *		- longjmp back to the initiating access function.
7547c478bd9Sstevel@tonic-gate
7557c478bd9Sstevel@tonic-gate *	If a write access error is detected, an interrupt is typically
7567c478bd9Sstevel@tonic-gate *	generated and claimed by a bus nexus responsible for the write
7577c478bd9Sstevel@tonic-gate *	transaction.  The nexus error handler is expected to set the
7587c478bd9Sstevel@tonic-gate *	error status and the IO initiating driver is expected to check
7597c478bd9Sstevel@tonic-gate *	for a failed transaction via ddi_fm_acc_err_get().
7607c478bd9Sstevel@tonic-gate *
7617c478bd9Sstevel@tonic-gate */
7627c478bd9Sstevel@tonic-gate
7637c478bd9Sstevel@tonic-gate	.seg	".data"
7647c478bd9Sstevel@tonic-gate.acc_panic:
7657c478bd9Sstevel@tonic-gate	.asciz	"DDI access: missing or invalid on_trap_data"
7667c478bd9Sstevel@tonic-gate
7677c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_caut_trampoline)
7687c478bd9Sstevel@tonic-gate	ldn	[THREAD_REG + T_ONTRAP], %o5    ! %o5 = curthread->t_ontrap
7697c478bd9Sstevel@tonic-gate	lduh	[%o5 + OT_PROT], %o1		! %o1 = %o0->ot_prot
7707c478bd9Sstevel@tonic-gate	andcc	%o1, OT_DATA_ACCESS, %g0	! if (!(%o1 & OT_DATA_ACCESS))
7717c478bd9Sstevel@tonic-gate	bz,pn	%icc, .cautaccfail		!     panic
7727c478bd9Sstevel@tonic-gate	rdpr	%pstate, %o3
7737c478bd9Sstevel@tonic-gate	andcc	%o3, PSTATE_IE, %g0		! enable interrupts
7747c478bd9Sstevel@tonic-gate	bnz	1f
7757c478bd9Sstevel@tonic-gate	nop
7767c478bd9Sstevel@tonic-gate	wrpr	%o3, PSTATE_IE, %pstate
7777c478bd9Sstevel@tonic-gate1:
7787c478bd9Sstevel@tonic-gate	ldn	[%o5 + OT_HANDLE], %o0		! %o0 = ot_handle
7797c478bd9Sstevel@tonic-gate	brz,pn	%o0, .cautaccfail		! if (ot_handle == NULL) panic
7807c478bd9Sstevel@tonic-gate	nop
7817c478bd9Sstevel@tonic-gate	ldn	[%o0 + AHI_ERR], %o4		! %o4 = hp->ahi_err
7827c478bd9Sstevel@tonic-gate	membar	#Sync
7837c478bd9Sstevel@tonic-gate	stx	%g0, [%o4 + ERR_ENA]		! ahi_err->err_ena = 0
7847c478bd9Sstevel@tonic-gate	mov	-2, %o0
7857c478bd9Sstevel@tonic-gate	st	%o0, [%o4 + ERR_STATUS]		! ahi_err->err_status = NONFATAL
7867c478bd9Sstevel@tonic-gate	b	longjmp                		! longjmp back
7877c478bd9Sstevel@tonic-gate	add	%o5, OT_JMPBUF, %o0		! %o0 = &ot_jmpbuf
7887c478bd9Sstevel@tonic-gate.cautaccfail:
7897c478bd9Sstevel@tonic-gate	set	.acc_panic, %o0			! Load panic message
7907c478bd9Sstevel@tonic-gate	call	panic				! Panic if bad t_ontrap data
7917c478bd9Sstevel@tonic-gate	nop
7927c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_caut_trampoline)
7937c478bd9Sstevel@tonic-gate
7947c478bd9Sstevel@tonic-gate/*
7957c478bd9Sstevel@tonic-gate * DDI on_trap set-up functions,  i_ddi_ontrap() and i_ddinotrap() are used
7967c478bd9Sstevel@tonic-gate * to protect * ddi_get accesses for DDI_CAUT_ACC.  i_ddi_ontrap() sets
7977c478bd9Sstevel@tonic-gate * the jumpbuf (setjmp) that will return back to the access routine from
7987c478bd9Sstevel@tonic-gate * i_ddi_trampoline().  DDI_NOPROTECT() clears the ontrap set-up.
7997c478bd9Sstevel@tonic-gate */
8007c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_ontrap)
8017c478bd9Sstevel@tonic-gate	ldn	[%o0 + AHI_ERR], %o4
8027c478bd9Sstevel@tonic-gate	ldn	[%o4 + ERR_ONTRAP],  %o4	! %o4 = hp->ahi_err->err_ontrap
8037c478bd9Sstevel@tonic-gate	ldn	[THREAD_REG + T_ONTRAP], %o5	! %o5 = curthread->t_ontrap
8047c478bd9Sstevel@tonic-gate	stn	%o5, [%o4 + OT_PREV]		! ot_prev = t_ontrap
8057c478bd9Sstevel@tonic-gate	membar	#Sync				! force error barrier
8067c478bd9Sstevel@tonic-gate	stn	%o4, [THREAD_REG + T_ONTRAP]	! t_ontrap = err_ontrap
8077c478bd9Sstevel@tonic-gate	b	setjmp
8087c478bd9Sstevel@tonic-gate	add	%o4, OT_JMPBUF, %o0
8097c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_ontrap)
8107c478bd9Sstevel@tonic-gate
8117c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_notrap)
8127c478bd9Sstevel@tonic-gate	membar	#Sync				! force error barrier
8137c478bd9Sstevel@tonic-gate	ldn	[%o0 + AHI_ERR], %o4
8147c478bd9Sstevel@tonic-gate	ldn	[%o4 + ERR_ONTRAP],  %o4	! %o4 = hp->ahi_err->err_ontrap
8157c478bd9Sstevel@tonic-gate	ldn	[%o4 + OT_PREV], %o4
8167c478bd9Sstevel@tonic-gate	retl
8177c478bd9Sstevel@tonic-gate	stn	%o4, [THREAD_REG + T_ONTRAP]	! restore curthread->t_ontrap
8187c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_notrap)
8197c478bd9Sstevel@tonic-gate
8207c478bd9Sstevel@tonic-gate/*
8217c478bd9Sstevel@tonic-gate * Internal on_trap set-up macros.  DDI_PROTECT() and DDI_NOPROTECT() are used
8227c478bd9Sstevel@tonic-gate * to protect * ddi_get accesses for DDI_FLAGERR_ACC.  DDI_NOPROTECT() sets
8237c478bd9Sstevel@tonic-gate * the jumpbuf that will return back to the access routine from
8247c478bd9Sstevel@tonic-gate * i_ddi_protect_trampoline().  DDI_NOPROTECT() clears the ontrap set-up.
8257c478bd9Sstevel@tonic-gate */
8267c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_prot_trampoline)
8277c478bd9Sstevel@tonic-gate	ldn	[THREAD_REG + T_ONTRAP], %o5    ! %o5 = curthread->t_ontrap
8287c478bd9Sstevel@tonic-gate	lduh	[%o5 + OT_PROT], %o1		! %o1 = %o0->ot_prot
8297c478bd9Sstevel@tonic-gate	andcc	%o1, OT_DATA_ACCESS, %g0	! if (!(%o1 & OT_DATA_ACCESS))
8307c478bd9Sstevel@tonic-gate	bz,pn	%icc, .protaccfail		!     panic
8317c478bd9Sstevel@tonic-gate	rdpr	%pstate, %o3
8327c478bd9Sstevel@tonic-gate	andcc	%o3, PSTATE_IE, %g0		! enable interrupts
8337c478bd9Sstevel@tonic-gate	bnz	1f
8347c478bd9Sstevel@tonic-gate	nop
8357c478bd9Sstevel@tonic-gate	wrpr	%o3, PSTATE_IE, %pstate
8367c478bd9Sstevel@tonic-gate1:
8377c478bd9Sstevel@tonic-gate	ldn	[%o5 + OT_HANDLE], %o0		! %o0 = ot_handle
8387c478bd9Sstevel@tonic-gate	brz,pn	%o0, .protaccfail		! if (ot_handle == NULL) panic
8397c478bd9Sstevel@tonic-gate	nop
8407c478bd9Sstevel@tonic-gate	ldn	[%o0 + AHI_ERR], %o4		! %o4 = hp->ahi_err
8417c478bd9Sstevel@tonic-gate	stn	%g0, [%o4 + ERR_ENA]		! ahi_err->err_ena = 0
8427c478bd9Sstevel@tonic-gate	mov	-2, %o0
8437c478bd9Sstevel@tonic-gate	st	%o0, [%o4 + ERR_STATUS]		! ahi_err->err_status = NONFATAL
8447c478bd9Sstevel@tonic-gate	ldn	[%o5 + OT_PREV], %o0		! restore ontrap
8457c478bd9Sstevel@tonic-gate	membar	#Sync				! force error barrier
8467c478bd9Sstevel@tonic-gate	stn	%o0, [THREAD_REG + T_ONTRAP];
8477c478bd9Sstevel@tonic-gate	b	longjmp                		! longjmp back
8487c478bd9Sstevel@tonic-gate	add	%o5, OT_JMPBUF, %o0		! %o0 = &ot_jmpbuf
8497c478bd9Sstevel@tonic-gate.protaccfail:
8507c478bd9Sstevel@tonic-gate	set	.acc_panic, %o0			! Load panic message
8517c478bd9Sstevel@tonic-gate	call	panic				! Panic if bad t_ontrap data
8527c478bd9Sstevel@tonic-gate	nop
8537c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_prot_trampoline)
8547c478bd9Sstevel@tonic-gate
8557c478bd9Sstevel@tonic-gate#define	DDI_PROTECT()				\
8567c478bd9Sstevel@tonic-gate	ldn	[%o0 + AHI_ERR], %o4;		\
8577c478bd9Sstevel@tonic-gate	ldn	[%o4 + ERR_ONTRAP],  %o4;	\
8587c478bd9Sstevel@tonic-gate	ldn	[THREAD_REG + T_ONTRAP], %o5;	\
8597c478bd9Sstevel@tonic-gate	stn	%o5, [%o4 + OT_PREV];		\
8607c478bd9Sstevel@tonic-gate	membar	#Sync;				\
8617c478bd9Sstevel@tonic-gate	stn	%o4, [THREAD_REG + T_ONTRAP];	\
8627c478bd9Sstevel@tonic-gate	add     %o4, OT_JMPBUF, %o0;		\
8637c478bd9Sstevel@tonic-gate	stn	%o7, [%o0 + L_PC];		\
8647c478bd9Sstevel@tonic-gate	stn	%sp, [%o0 + L_SP];		\
8657c478bd9Sstevel@tonic-gate	clr	%o0;
8667c478bd9Sstevel@tonic-gate
8677c478bd9Sstevel@tonic-gate#define	DDI_NOPROTECT()				\
8687c478bd9Sstevel@tonic-gate	ldn	[THREAD_REG + T_ONTRAP], %o4;	\
8697c478bd9Sstevel@tonic-gate	ldn	[%o4 + OT_PREV], %o5;		\
8707c478bd9Sstevel@tonic-gate	membar	#Sync;				\
8717c478bd9Sstevel@tonic-gate	stn	%o5, [THREAD_REG + T_ONTRAP];
8727c478bd9Sstevel@tonic-gate
8737c478bd9Sstevel@tonic-gate/*
8747c478bd9Sstevel@tonic-gate * DDI_FLAGERR_ACC specific get/put routines.
8757c478bd9Sstevel@tonic-gate */
8767c478bd9Sstevel@tonic-gate	.align 16
8777c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_prot_get8)
8787c478bd9Sstevel@tonic-gate	DDI_PROTECT()				! set ontrap protection
8797c478bd9Sstevel@tonic-gate	ldub	[%o1], %o2			! do the io access
8807c478bd9Sstevel@tonic-gate	DDI_NOPROTECT()				! remove protection & ret
8817c478bd9Sstevel@tonic-gate	retl
8827c478bd9Sstevel@tonic-gate	mov	%o2, %o0			! set return value
8837c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_prot_get8)
8847c478bd9Sstevel@tonic-gate
8857c478bd9Sstevel@tonic-gate	.align 16
8867c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_prot_get16)
8877c478bd9Sstevel@tonic-gate	DDI_PROTECT()				! set ontrap protection
8887c478bd9Sstevel@tonic-gate	lduh	[%o1], %o2			! do the io access
8897c478bd9Sstevel@tonic-gate	DDI_NOPROTECT()				! remove protection & ret
8907c478bd9Sstevel@tonic-gate	retl
8917c478bd9Sstevel@tonic-gate	mov	%o2, %o0			! set return value
8927c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_prot_get16)
8937c478bd9Sstevel@tonic-gate
8947c478bd9Sstevel@tonic-gate	.align 16
8957c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_prot_get32)
8967c478bd9Sstevel@tonic-gate	DDI_PROTECT()				! set ontrap protection
8977c478bd9Sstevel@tonic-gate	ld	[%o1], %o2			! do the io access
8987c478bd9Sstevel@tonic-gate	DDI_NOPROTECT()				! remove protection & ret
8997c478bd9Sstevel@tonic-gate	retl
9007c478bd9Sstevel@tonic-gate	mov	%o2, %o0			! set return value
9017c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_prot_get32)
9027c478bd9Sstevel@tonic-gate
9037c478bd9Sstevel@tonic-gate	.align 16
9047c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_prot_get64)
9057c478bd9Sstevel@tonic-gate	DDI_PROTECT()				! set ontrap protection
9067c478bd9Sstevel@tonic-gate	ldx	[%o1], %o2			! do the io access
9077c478bd9Sstevel@tonic-gate	DDI_NOPROTECT()				! remove protection & ret
9087c478bd9Sstevel@tonic-gate	retl
9097c478bd9Sstevel@tonic-gate	mov	%o2, %o0			! set return value
9107c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_prot_get64)
9117c478bd9Sstevel@tonic-gate
9127c478bd9Sstevel@tonic-gate	.align 16
9137c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_prot_put8)
9147c478bd9Sstevel@tonic-gate	stub	%o2, [%o1]			! do the io access
9157c478bd9Sstevel@tonic-gate	retl
9167c478bd9Sstevel@tonic-gate	membar	#Sync;
9177c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_prot_put8)
9187c478bd9Sstevel@tonic-gate
9197c478bd9Sstevel@tonic-gate	.align 16
9207c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_prot_put16)
9217c478bd9Sstevel@tonic-gate	stuh	%o2, [%o1]			! do the io access
9227c478bd9Sstevel@tonic-gate	retl
9237c478bd9Sstevel@tonic-gate	membar	#Sync;
9247c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_prot_put16)
9257c478bd9Sstevel@tonic-gate
9267c478bd9Sstevel@tonic-gate	.align 16
9277c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_prot_put32)
9287c478bd9Sstevel@tonic-gate	st	%o2, [%o1]			! do the io access
9297c478bd9Sstevel@tonic-gate	retl
9307c478bd9Sstevel@tonic-gate	membar	#Sync;
9317c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_prot_put32)
9327c478bd9Sstevel@tonic-gate
9337c478bd9Sstevel@tonic-gate	.align 16
9347c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_prot_put64)
9357c478bd9Sstevel@tonic-gate	stx	%o2, [%o1]			! do the io access
9367c478bd9Sstevel@tonic-gate	retl
9377c478bd9Sstevel@tonic-gate	membar	#Sync;
9387c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_prot_put64)
9397c478bd9Sstevel@tonic-gate
9407c478bd9Sstevel@tonic-gate	.align 16
9417c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_prot_rep_get8)
9427c478bd9Sstevel@tonic-gate	DDI_PROTECT()				! set ontrap protection
9437c478bd9Sstevel@tonic-gate	tst	%o0				! check access error
9447c478bd9Sstevel@tonic-gate	bnz,a	1f
9457c478bd9Sstevel@tonic-gate	nop
9467c478bd9Sstevel@tonic-gate	DDI_REP_GET(1,ub)
9477c478bd9Sstevel@tonic-gate1:
9487c478bd9Sstevel@tonic-gate	DDI_NOPROTECT()				! remove protection & ret
9497c478bd9Sstevel@tonic-gate	retl
9507c478bd9Sstevel@tonic-gate	nop
9517c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_prot_rep_get8)
9527c478bd9Sstevel@tonic-gate
9537c478bd9Sstevel@tonic-gate	.align 16
9547c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_prot_rep_get16)
9557c478bd9Sstevel@tonic-gate	DDI_PROTECT()				! set ontrap protection
9567c478bd9Sstevel@tonic-gate	tst	%o0				! check access error
9577c478bd9Sstevel@tonic-gate	bnz,a	1f
9587c478bd9Sstevel@tonic-gate	nop
9597c478bd9Sstevel@tonic-gate	DDI_REP_GET(2,uh)
9607c478bd9Sstevel@tonic-gate1:
9617c478bd9Sstevel@tonic-gate	DDI_NOPROTECT()				! remove protection & ret
9627c478bd9Sstevel@tonic-gate	retl
9637c478bd9Sstevel@tonic-gate	nop
9647c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_prot_rep_get16)
9657c478bd9Sstevel@tonic-gate
9667c478bd9Sstevel@tonic-gate	.align 16
9677c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_prot_rep_get32)
9687c478bd9Sstevel@tonic-gate	DDI_PROTECT()				! set ontrap protection
9697c478bd9Sstevel@tonic-gate	tst	%o0				! check access error
9707c478bd9Sstevel@tonic-gate	bnz,a	1f
9717c478bd9Sstevel@tonic-gate	nop
9727c478bd9Sstevel@tonic-gate	DDI_REP_GET(4,/**/)
9737c478bd9Sstevel@tonic-gate1:
9747c478bd9Sstevel@tonic-gate	DDI_NOPROTECT()				! remove protection & ret
9757c478bd9Sstevel@tonic-gate	retl
9767c478bd9Sstevel@tonic-gate	nop
9777c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_prot_rep_get32)
9787c478bd9Sstevel@tonic-gate
9797c478bd9Sstevel@tonic-gate	.align 16
9807c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_prot_rep_get64)
9817c478bd9Sstevel@tonic-gate	DDI_PROTECT()				! set ontrap protection
9827c478bd9Sstevel@tonic-gate	tst	%o0				! check access error
9837c478bd9Sstevel@tonic-gate	bnz,a	1f
9847c478bd9Sstevel@tonic-gate	nop
9857c478bd9Sstevel@tonic-gate	DDI_REP_GET(8,x)
9867c478bd9Sstevel@tonic-gate1:
9877c478bd9Sstevel@tonic-gate	DDI_NOPROTECT()				! remove protection & ret
9887c478bd9Sstevel@tonic-gate	retl
9897c478bd9Sstevel@tonic-gate	nop
9907c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_prot_rep_get64)
9917c478bd9Sstevel@tonic-gate
9927c478bd9Sstevel@tonic-gate	.align 16
9937c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_prot_rep_put8)
9947c478bd9Sstevel@tonic-gate	DDI_REP_PUT(1,ub)
9957c478bd9Sstevel@tonic-gate	retl
9967c478bd9Sstevel@tonic-gate	membar	#Sync;
9977c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_prot_rep_put8)
9987c478bd9Sstevel@tonic-gate
9997c478bd9Sstevel@tonic-gate	.align 16
10007c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_prot_rep_put16)
10017c478bd9Sstevel@tonic-gate	DDI_REP_PUT(2,uh)
10027c478bd9Sstevel@tonic-gate	retl
10037c478bd9Sstevel@tonic-gate	membar	#Sync;
10047c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_prot_rep_put16)
10057c478bd9Sstevel@tonic-gate
10067c478bd9Sstevel@tonic-gate	.align 16
10077c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_prot_rep_put32)
10087c478bd9Sstevel@tonic-gate	DDI_REP_PUT(4,/**/)
10097c478bd9Sstevel@tonic-gate	retl
10107c478bd9Sstevel@tonic-gate	membar	#Sync;
10117c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_prot_rep_put32)
10127c478bd9Sstevel@tonic-gate
10137c478bd9Sstevel@tonic-gate	.align 16
10147c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_prot_rep_put64)
10157c478bd9Sstevel@tonic-gate	DDI_REP_PUT(8,x)
10167c478bd9Sstevel@tonic-gate	retl
10177c478bd9Sstevel@tonic-gate	membar	#Sync;
10187c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_prot_rep_put64)
10197c478bd9Sstevel@tonic-gate
10207c478bd9Sstevel@tonic-gate/*
10217c478bd9Sstevel@tonic-gate * Common DDI_CAUTIOUS_ACC routine called from cautious access routines
10227c478bd9Sstevel@tonic-gate * in ddi_impl.c
10237c478bd9Sstevel@tonic-gate */
10247c478bd9Sstevel@tonic-gate	ENTRY(i_ddi_caut_get)
10257c478bd9Sstevel@tonic-gate	rdpr	%pstate, %o3	! check ints
10267c478bd9Sstevel@tonic-gate	andcc	%o3, PSTATE_IE, %g0
10277c478bd9Sstevel@tonic-gate	bz,a	cautdone
10287c478bd9Sstevel@tonic-gate	nop
10297c478bd9Sstevel@tonic-gate	wrpr	%o3, PSTATE_IE, %pstate
10307c478bd9Sstevel@tonic-gate	cmp	%o0, 8		! 64-bit?
10317c478bd9Sstevel@tonic-gate	bne,a	.get_int
10327c478bd9Sstevel@tonic-gate	cmp	%o0, 4		! 32-bit?
10337c478bd9Sstevel@tonic-gate	ldx	[%o1], %g1
10347c478bd9Sstevel@tonic-gate	ba	.getdone
10357c478bd9Sstevel@tonic-gate	stx	%g1, [%o2]
10367c478bd9Sstevel@tonic-gate.get_int:
10377c478bd9Sstevel@tonic-gate	bne,a	.get_half
10387c478bd9Sstevel@tonic-gate	cmp	%o0, 2		! 16-bit?
10397c478bd9Sstevel@tonic-gate	lduw	[%o1], %g1
10407c478bd9Sstevel@tonic-gate	ba	.getdone
10417c478bd9Sstevel@tonic-gate	stuw	%g1, [%o2]
10427c478bd9Sstevel@tonic-gate.get_half:
10437c478bd9Sstevel@tonic-gate	bne,a	.get_byte
10447c478bd9Sstevel@tonic-gate	ldub	[%o1], %g1	! 8-bit!
10457c478bd9Sstevel@tonic-gate	lduh	[%o1], %g1
10467c478bd9Sstevel@tonic-gate	ba	.getdone
10477c478bd9Sstevel@tonic-gate	stuh	%g1, [%o2]
10487c478bd9Sstevel@tonic-gate.get_byte:
10497c478bd9Sstevel@tonic-gate	stub	%g1, [%o2]
10507c478bd9Sstevel@tonic-gate.getdone:
10517c478bd9Sstevel@tonic-gate	rdpr	%pstate, %o3	! check&enable ints
10527c478bd9Sstevel@tonic-gate	andcc	%o3, PSTATE_IE, %g0
10537c478bd9Sstevel@tonic-gate	bnz,a	cautdone
10547c478bd9Sstevel@tonic-gate	nop
10557c478bd9Sstevel@tonic-gate	wrpr	%o3, PSTATE_IE, %pstate
10567c478bd9Sstevel@tonic-gatecautdone:
10577c478bd9Sstevel@tonic-gate	retl
10587c478bd9Sstevel@tonic-gate	nop
10597c478bd9Sstevel@tonic-gate	SET_SIZE(i_ddi_caut_get)
10607c478bd9Sstevel@tonic-gate
1061