Home | History | Annotate | Line # | Download | only in include
ctlreg.h revision 1.25
      1 /*	$NetBSD: ctlreg.h,v 1.25 2000/12/29 17:13:33 eeh Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1996-1999 Eduardo Horvath
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  *
     12  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR  ``AS IS'' AND
     13  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     14  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     15  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR  BE LIABLE
     16  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     17  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     18  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     19  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     20  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     21  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     22  * SUCH DAMAGE.
     23  *
     24  */
     25 
     26 /*
     27  * Sun 4u control registers. (includes address space definitions
     28  * and some registers in control space).
     29  */
     30 
     31 /*
     32  * The Alternate address spaces.
     33  *
     34  * 0x00-0x7f are privileged
     35  * 0x80-0xff can be used by users
     36  */
     37 
     38 #define ASI_LITTLE	0x08		/* This bit should make an ASI little endian */
     39 
     40 #define ASI_NUCLEUS			0x04	/* [4u] kernel address space */
     41 #define ASI_NUCLEUS_LITTLE		0x0c	/* [4u] kernel address space, little endian */
     42 
     43 #define ASI_AS_IF_USER_PRIMARY		0x10	/* [4u] primary user address space */
     44 #define ASI_AS_IF_USER_SECONDARY	0x11	/* [4u] secondary user address space */
     45 
     46 #define ASI_PHYS_CACHED			0x14	/* [4u] MMU bypass to main memory */
     47 #define ASI_PHYS_NON_CACHED		0x15	/* [4u] MMU bypass to I/O location */
     48 
     49 #define ASI_AS_IF_USER_PRIMARY_LITTLE	0x18	/* [4u] primary user address space, little endian  */
     50 #define ASI_AS_IF_USER_SECONDARY_LITTIE	0x19	/* [4u] secondary user address space, little endian  */
     51 
     52 #define ASI_PHYS_CACHED_LITTLE		0x1c	/* [4u] MMU bypass to main memory, little endian */
     53 #define ASI_PHYS_NON_CACHED_LITTLE	0x1d	/* [4u] MMU bypass to I/O location, little endian */
     54 
     55 #define ASI_NUCLEUS_QUAD_LDD		0x24	/* [4u] use w/LDDA to load 128-bit item */
     56 #define ASI_NUCLEUS_QUAD_LDD_LITTLE	0x2c	/* [4u] use w/LDDA to load 128-bit item, little endian */
     57 
     58 #define ASI_FLUSH_D_PAGE_PRIMARY	0x38	/* [4u] flush D-cache page using primary context */
     59 #define ASI_FLUSH_D_PAGE_SECONDARY	0x39	/* [4u] flush D-cache page using secondary context */
     60 #define ASI_FLUSH_D_CTX_PRIMARY		0x3a	/* [4u] flush D-cache context using primary context */
     61 #define ASI_FLUSH_D_CTX_SECONDARY	0x3b	/* [4u] flush D-cache context using secondary context */
     62 
     63 #define ASI_LSU_CONTROL_REGISTER	0x45	/* [4u] load/store unit control register */
     64 
     65 #define ASI_DCACHE_DATA			0x46	/* [4u] diagnostic access to D-cache data RAM */
     66 #define ASI_DCACHE_TAG			0x47	/* [4u] diagnostic access to D-cache tag RAM */
     67 
     68 #define ASI_INTR_DISPATCH_STATUS	0x48	/* [4u] interrupt dispatch status register */
     69 #define ASI_INTR_RECEIVE		0x49	/* [4u] interrupt receive status register */
     70 #define ASI_MID_REG			0x4a	/* [4u] hardware config and MID */
     71 #define ASI_ERROR_EN_REG		0x4b	/* [4u] asynchronous error enables */
     72 #define ASI_AFSR			0x4c	/* [4u] asynchronous fault status register */
     73 #define ASI_AFAR			0x4d	/* [4u] asynchronous fault address register */
     74 
     75 #define ASI_ICACHE_DATA			0x66	/* [4u] diagnostic access to D-cache data RAM */
     76 #define ASI_ICACHE_TAG			0x67	/* [4u] diagnostic access to D-cache tag RAM */
     77 #define ASI_FLUSH_I_PAGE_PRIMARY	0x68	/* [4u] flush D-cache page using primary context */
     78 #define ASI_FLUSH_I_PAGE_SECONDARY	0x69	/* [4u] flush D-cache page using secondary context */
     79 #define ASI_FLUSH_I_CTX_PRIMARY		0x6a	/* [4u] flush D-cache context using primary context */
     80 #define ASI_FLUSH_I_CTX_SECONDARY	0x6b	/* [4u] flush D-cache context using secondary context */
     81 
     82 #define ASI_BLOCK_AS_IF_USER_PRIMARY	0x70	/* [4u] primary user address space, block loads/stores */
     83 #define ASI_BLOCK_AS_IF_USER_SECONDARY	0x71	/* [4u] secondary user address space, block loads/stores */
     84 
     85 #define ASI_ECACHE_DIAG			0x76	/* [4u] diag access to E-cache tag and data */
     86 #define ASI_DATAPATH_ERR_REG_WRITE	0x77	/* [4u] ASI is reused */
     87 
     88 #define ASI_BLOCK_AS_IF_USER_PRIMARY_LITTLE	0x78	/* [4u] primary user address space, block loads/stores */
     89 #define ASI_BLOCK_AS_IF_USER_SECONDARY_LITTLE	0x79	/* [4u] secondary user address space, block loads/stores */
     90 
     91 #define ASI_INTERRUPT_RECEIVE_DATA	0x7f	/* [4u] interrupt receive data registers {0,1,2} */
     92 #define ASI_DATAPATH_ERR_REG_READ	0x7f	/* [4u] read access to datapath error registers (ASI reused) */
     93 
     94 #define ASI_PRIMARY			0x80	/* [4u] primary address space */
     95 #define ASI_SECONDARY			0x81	/* [4u] secondary address space */
     96 #define ASI_PRIMARY_NO_FAULT		0x82	/* [4u] primary address space, no fault */
     97 #define ASI_SECONDARY_NO_FAULT		0x83	/* [4u] secondary address space, no fault */
     98 
     99 #define ASI_PRIMARY_LITTLE		0x88	/* [4u] primary address space, little endian */
    100 #define ASI_SECONDARY_LITTLE		0x89	/* [4u] secondary address space, little endian */
    101 #define ASI_PRIMARY_NO_FAULT_LITTLE	0x8a	/* [4u] primary address space, no fault, little endian */
    102 #define ASI_SECONDARY_NO_FAULT_LITTLE	0x8b	/* [4u] secondary address space, no fault, little endian */
    103 
    104 #define ASI_PST8_PRIMARY		0xc0	/* [VIS] Eight 8-bit partial store, primary */
    105 #define ASI_PST8_SECONDARY		0xc1	/* [VIS] Eight 8-bit partial store, secondary */
    106 #define ASI_PST16_PRIMARY		0xc2	/* [VIS] Four 16-bit partial store, primary */
    107 #define ASI_PST16_SECONDARY		0xc3	/* [VIS] Fout 16-bit partial store, secondary */
    108 #define ASI_PST32_PRIMARY		0xc4	/* [VIS] Two 32-bit partial store, primary */
    109 #define ASI_PST32_SECONDARY		0xc5	/* [VIS] Two 32-bit partial store, secondary */
    110 
    111 #define ASI_PST8_PRIMARY_LITTLE		0xc8	/* [VIS] Eight 8-bit partial store, primary, little endian */
    112 #define ASI_PST8_SECONDARY_LITTLE	0xc9	/* [VIS] Eight 8-bit partial store, secondary, little endian */
    113 #define ASI_PST16_PRIMARY_LITTLE	0xca	/* [VIS] Four 16-bit partial store, primary, little endian */
    114 #define ASI_PST16_SECONDARY_LITTLE	0xcb	/* [VIS] Fout 16-bit partial store, secondary, little endian */
    115 #define ASI_PST32_PRIMARY_LITTLE	0xcc	/* [VIS] Two 32-bit partial store, primary, little endian */
    116 #define ASI_PST32_SECONDARY_LITTLE	0xcd	/* [VIS] Two 32-bit partial store, secondary, little endian */
    117 
    118 #define ASI_FL8_PRIMARY			0xd0	/* [VIS] One 8-bit load/store floating, primary */
    119 #define ASI_FL8_SECONDARY		0xd1	/* [VIS] One 8-bit load/store floating, secondary */
    120 #define ASI_FL16_PRIMARY		0xd2	/* [VIS] One 16-bit load/store floating, primary */
    121 #define ASI_FL16_SECONDARY		0xd3	/* [VIS] One 16-bit load/store floating, secondary */
    122 
    123 #define ASI_FL8_PRIMARY_LITTLE		0xd8	/* [VIS] One 8-bit load/store floating, primary, little endian */
    124 #define ASI_FL8_SECONDARY_LITTLE	0xd9	/* [VIS] One 8-bit load/store floating, secondary, little endian */
    125 #define ASI_FL16_PRIMARY_LITTLE		0xda	/* [VIS] One 16-bit load/store floating, primary, little endian */
    126 #define ASI_FL16_SECONDARY_LITTLE	0xdb	/* [VIS] One 16-bit load/store floating, secondary, little endian */
    127 
    128 #define ASI_BLOCK_COMMIT_PRIMARY	0xe0	/* [4u] block store with commit, primary */
    129 #define ASI_BLOCK_COMMIT_SECONDARY	0xe1	/* [4u] block store with commit, secondary */
    130 #define ASI_BLOCK_PRIMARY		0xf0	/* [4u] block load/store, primary */
    131 #define ASI_BLOCK_SECONDARY		0xf1	/* [4u] block load/store, secondary */
    132 #define ASI_BLOCK_PRIMARY_LITTLE	0xf8	/* [4u] block load/store, primary, little endian */
    133 #define ASI_BLOCK_SECONDARY_LITTLE	0xf9	/* [4u] block load/store, secondary, little endian */
    134 
    135 
    136 /*
    137  * These are the shorter names used by Solaris
    138  */
    139 
    140 #define ASI_N		ASI_NUCLEUS
    141 #define ASI_NL		ASI_NUCLEUS_LITTLE
    142 #define ASI_AIUP	ASI_AS_IF_USER_PRIMARY
    143 #define ASI_AIUS	ASI_AS_IF_USER_SECONDARY
    144 #define ASI_AIUPL	ASI_AS_IF_USER_PRIMARY_LITTLE
    145 #define ASI_AIUSL	ASI_AS_IF_USER_SECONDARY_LITTLE
    146 #define ASI_P		ASI_PRIMARY
    147 #define ASI_S		ASI_SECONDARY
    148 #define ASI_PNF		ASI_PRIMARY_NO_FAULT
    149 #define ASI_SNF		ASI_SECONDARY_NO_FAULT
    150 #define ASI_PL		ASI_PRIMARY_LITTLE
    151 #define ASI_SL		ASI_SECONDARY_LITTLE
    152 #define ASI_PNFL	ASI_PRIMARY_NO_FAULT_LITTLE
    153 #define ASI_SNFL	ASI_SECONDARY_NO_FAULT_LITTLE
    154 #define ASI_BLK_AIUP	ASI_BLOCK_AS_IF_USER_PRIMARY
    155 #define ASI_BLK_AIUPL	ASI_BLOCK_AS_IF_USER_PRIMARY_LITTLE
    156 #define ASI_BLK_AIUS	ASI_BLOCK_AS_IF_USER_SECONDARY
    157 #define ASI_BLK_AIUSL	ASI_BLOCK_AS_IF_USER_SECONDARY_LITTLE
    158 #define ASI_BLK_COMMIT_P		ASI_BLOCK_COMMIT_PRIMARY
    159 #define ASI_BLK_COMMIT_PRIMARY		ASI_BLOCK_COMMIT_PRIMARY
    160 #define ASI_BLK_COMMIT_S		ASI_BLOCK_COMMIT_SECONDARY
    161 #define ASI_BLK_COMMIT_SECONDARY	ASI_BLOCK_COMMIT_SECONDARY
    162 #define ASI_BLK_P			ASI_BLOCK_PRIMARY
    163 #define ASI_BLK_PL			ASI_BLOCK_PRIMARY_LITTLE
    164 #define ASI_BLK_S			ASI_BLOCK_SECONDARY
    165 #define ASI_BLK_SL			ASI_BLOCK_SECONDARY_LITTLE
    166 
    167 #define PHYS_ASI(x)	(((x) | 0x09) == 0x1d)
    168 #define LITTLE_ASI(x)	((x) & ASI_LITTLE)
    169 
    170 /*
    171  * The following are 4u control registers
    172  */
    173 
    174 
    175 /* Get the CPU's UPAID */
    176 #define	UPA_CR_MID(x)	(((x)>>17)&0x1f)
    177 #define	CPU_UPAID	UPA_CR_MID(ldxa(0, ASI_MID_REG))
    178 
    179 /*
    180  * [4u] MMU and Cache Control Register (MCCR)
    181  * use ASI = 0x45
    182  */
    183 #define ASI_MCCR	ASI_LSU_CONTROL_REGISTER
    184 #define MCCR		0x00
    185 
    186 /* MCCR Bits and their meanings */
    187 #define MCCR_DMMU_EN	0x08
    188 #define MCCR_IMMU_EN	0x04
    189 #define MCCR_DCACHE_EN	0x02
    190 #define MCCR_ICACHE_EN	0x01
    191 
    192 
    193 /*
    194  * MMU control registers
    195  */
    196 
    197 /* Choose an MMU */
    198 #define ASI_DMMU		0x58
    199 #define ASI_IMMU		0x50
    200 
    201 /* Other assorted MMU ASIs */
    202 #define ASI_IMMU_8KPTR		0x51
    203 #define ASI_IMMU_64KPTR		0x52
    204 #define ASI_IMMU_DATA_IN	0x54
    205 #define ASI_IMMU_TLB_DATA	0x55
    206 #define ASI_IMMU_TLB_TAG	0x56
    207 #define ASI_DMMU_8KPTR		0x59
    208 #define ASI_DMMU_64KPTR		0x5a
    209 #define ASI_DMMU_DATA_IN	0x5c
    210 #define ASI_DMMU_TLB_DATA	0x5d
    211 #define ASI_DMMU_TLB_TAG	0x5e
    212 
    213 /*
    214  * The following are the control registers
    215  * They work on both MMUs unless noted.
    216  *
    217  * Register contents are defined later on individual registers.
    218  */
    219 #define TSB_TAG_TARGET		0x0
    220 #define TLB_DATA_IN		0x0
    221 #define CTX_PRIMARY		0x08	/* primary context -- DMMU only */
    222 #define CTX_SECONDARY		0x10	/* secondary context -- DMMU only */
    223 #define SFSR			0x18
    224 #define SFAR			0x20	/* fault address -- DMMU only */
    225 #define TSB			0x28
    226 #define TLB_TAG_ACCESS		0x30
    227 #define VIRTUAL_WATCHPOINT	0x38
    228 #define PHYSICAL_WATCHPOINT	0x40
    229 
    230 /* Tag Target bits */
    231 #define TAG_TARGET_VA_MASK	0x03ffffffffffffffffLL
    232 #define TAG_TARGET_VA(x)	(((x)<<22)&TAG_TARGET_VA_MASK)
    233 #define TAG_TARGET_CONTEXT(x)	((x)>>48)
    234 #define TAG_TARGET(c,v)		((((uint64_t)c)<<48)|(((uint64_t)v)&TAG_TARGET_VA_MASK))
    235 
    236 /* SFSR bits for both D_SFSR and I_SFSR */
    237 #define SFSR_ASI(x)		((x)>>16)
    238 #define SFSR_FT_VA_OOR_2	0x02000 /* IMMU: jumpl or return to unsupportd VA */
    239 #define SFSR_FT_VA_OOR_1	0x01000 /* fault at unsupported VA */
    240 #define SFSR_FT_NFO		0x00800	/* DMMU: Access to page marked NFO */
    241 #define SFSR_ILL_ASI		0x00400	/* DMMU: Illegal (unsupported) ASI */
    242 #define SFSR_FT_IO_ATOMIC	0x00200	/* DMMU: Atomic access to noncacheable page */
    243 #define SFSR_FT_ILL_NF		0x00100	/* DMMU: NF load or flush to page marked E (has side effects) */
    244 #define SFSR_FT_PRIV		0x00080	/* Privilege violation */
    245 #define SFSR_FT_E		0x00040	/* DMUU: value of E bit associated address */
    246 #define SFSR_CTXT(x)		(((x)>>4)&0x3)
    247 #define SFSR_CTXT_IS_PRIM(x)	(SFSR_CTXT(x)==0x00)
    248 #define SFSR_CTXT_IS_SECOND(x)	(SFSR_CTXT(x)==0x01)
    249 #define SFSR_CTXT_IS_NUCLEUS(x)	(SFSR_CTXT(x)==0x02)
    250 #define SFSR_PRIV		0x00008	/* value of PSTATE.PRIV for faulting access */
    251 #define SFSR_W			0x00004 /* DMMU: attempted write */
    252 #define SFSR_OW			0x00002 /* Overwrite; prev vault was still valid */
    253 #define SFSR_FV			0x00001	/* Fault is valid */
    254 #define SFSR_FT	(SFSR_FT_VA_OOR_2|SFSR_FT_VA_OOR_1|SFSR_FT_NFO|SFSR_ILL_ASI|SFSR_FT_IO_ATOMIC|SFSR_FT_ILL_NF|SFSR_FT_PRIV)
    255 
    256 #if 0
    257 /* Old bits */
    258 #define SFSR_BITS "\40\16VAT\15VAD\14NFO\13ASI\12A\11NF\10PRIV\7E\6NUCLEUS\5SECONDCTX\4PRIV\3W\2OW\1FV"
    259 #else
    260 /* New bits */
    261 #define SFSR_BITS "\177\20" \
    262 	"f\20\30ASI\0" "b\16VAT\0" "b\15VAD\0" "b\14NFO\0" "b\13ASI\0" "b\12A\0" "b\11NF\0" "b\10PRIV\0" \
    263 	 "b\7E\0" "b\6NUCLEUS\0" "b\5SECONDCTX\0" "b\4PRIV\0" "b\3W\0" "b\2OW\0" "b\1FV\0"
    264 #endif
    265 
    266 /* ASFR bits */
    267 #define ASFR_ME			0x100000000LL
    268 #define ASFR_PRIV		0x080000000LL
    269 #define ASFR_ISAP		0x040000000LL
    270 #define ASFR_ETP		0x020000000LL
    271 #define ASFR_IVUE		0x010000000LL
    272 #define ASFR_TO			0x008000000LL
    273 #define ASFR_BERR		0x004000000LL
    274 #define ASFR_LDP		0x002000000LL
    275 #define ASFR_CP			0x001000000LL
    276 #define ASFR_WP			0x000800000LL
    277 #define ASFR_EDP		0x000400000LL
    278 #define ASFR_UE			0x000200000LL
    279 #define ASFR_CE			0x000100000LL
    280 #define ASFR_ETS		0x0000f0000LL
    281 #define ASFT_P_SYND		0x00000ffffLL
    282 
    283 #define AFSR_BITS "\177\20" \
    284         "b\40ME\0"      "b\37PRIV\0"    "b\36ISAP\0"    "b\35ETP\0" \
    285         "b\34IVUE\0"    "b\33TO\0"      "b\32BERR\0"    "b\31LDP\0" \
    286         "b\30CP\0"      "b\27WP\0"      "b\26EDP\0"     "b\25UE\0" \
    287         "b\24CE\0"      "f\20\4ETS\0"   "f\0\20P_SYND\0"
    288 
    289 /*
    290  * Here's the spitfire TSB control register bits.
    291  *
    292  * Each TSB entry is 16-bytes wide.  The TSB must be size aligned
    293  */
    294 #define TSB_SIZE_512		0x0	/* 8kB, etc. */
    295 #define TSB_SIZE_1K		0x01
    296 #define TSB_SIZE_2K		0x02
    297 #define TSB_SIZE_4K		0x03
    298 #define	TSB_SIZE_8K		0x04
    299 #define TSB_SIZE_16K		0x05
    300 #define TSB_SIZE_32K		0x06
    301 #define TSB_SIZE_64K		0x07
    302 #define TSB_SPLIT		0x1000
    303 #define TSB_BASE		0xffffffffffffe000
    304 
    305 /*  TLB Tag Access bits */
    306 #define TLB_TAG_ACCESS_VA	0xffffffffffffe000
    307 #define TLB_TAG_ACCESS_CTX	0x0000000000001fff
    308 
    309 /*
    310  * TLB demap registers.  TTEs are defined in v9pte.h
    311  *
    312  * Use the address space to select between IMMU and DMMU.
    313  * The address of the register selects which context register
    314  * to read the ASI from.
    315  *
    316  * The data stored in the register is interpreted as the VA to
    317  * use.  The DEMAP_CTX_<> registers ignore the address and demap the
    318  * entire ASI.
    319  *
    320  */
    321 #define ASI_IMMU_DEMAP			0x57	/* [4u] IMMU TLB demap */
    322 #define ASI_DMMU_DEMAP			0x5f	/* [4u] IMMU TLB demap */
    323 
    324 #define DEMAP_PAGE_NUCLEUS		((0x02)<<4)	/* Demap page from kernel AS */
    325 #define DEMAP_PAGE_PRIMARY		((0x00)<<4)	/* Demap a page from primary CTXT */
    326 #define DEMAP_PAGE_SECONDARY		((0x01)<<4)	/* Demap page from secondary CTXT (DMMU only) */
    327 #define DEMAP_CTX_NUCLEUS		((0x06)<<4)	/* Demap all of kernel CTXT */
    328 #define DEMAP_CTX_PRIMARY		((0x04)<<4)	/* Demap all of primary CTXT */
    329 #define DEMAP_CTX_SECONDARY		((0x05)<<4)	/* Demap all of secondary CTXT */
    330 
    331 /*
    332  * Interrupt registers.  This really gets hairy.
    333  */
    334 
    335 /* IRSR -- Interrupt Receive Status Ragister */
    336 #define ASI_IRSR	0x49
    337 #define IRSR		0x00
    338 #define IRSR_BUSY	0x020
    339 #define IRSR_MID(x)	(x&0x1f)
    340 
    341 /* IRDR -- Interrupt Receive Data Registers */
    342 #define ASI_IRDR	0x7f
    343 #define IRDR_0H		0x40
    344 #define IRDR_0L		0x48	/* unimplemented */
    345 #define IRDR_1H		0x50
    346 #define IRDR_1L		0x58	/* unimplemented */
    347 #define IRDR_2H		0x60
    348 #define IRDR_2L		0x68	/* unimplemented */
    349 #define IRDR_3H		0x70	/* unimplemented */
    350 #define IRDR_3L		0x78	/* unimplemented */
    351 
    352 /* SOFTINT ASRs */
    353 #define SET_SOFTINT	%asr20	/* Sets these bits */
    354 #define CLEAR_SOFTINT	%asr21	/* Clears these bits */
    355 #define SOFTINT		%asr22	/* Reads the register */
    356 #define TICK_CMPR	%asr23
    357 
    358 #define	TICK_INT	0x01	/* level-14 clock tick */
    359 #define SOFTINT1	(0x1<<1)
    360 #define SOFTINT2	(0x1<<2)
    361 #define SOFTINT3	(0x1<<3)
    362 #define SOFTINT4	(0x1<<4)
    363 #define SOFTINT5	(0x1<<5)
    364 #define SOFTINT6	(0x1<<6)
    365 #define SOFTINT7	(0x1<<7)
    366 #define SOFTINT8	(0x1<<8)
    367 #define SOFTINT9	(0x1<<9)
    368 #define SOFTINT10	(0x1<<10)
    369 #define SOFTINT11	(0x1<<11)
    370 #define SOFTINT12	(0x1<<12)
    371 #define SOFTINT13	(0x1<<13)
    372 #define SOFTINT14	(0x1<<14)
    373 #define SOFTINT15	(0x1<<15)
    374 
    375 /* Interrupt Dispatch -- usually reserved for cross-calls */
    376 #define ASR_IDSR	0x48 /* Interrupt dispatch status reg */
    377 #define IDSR		0x00
    378 #define IDSR_NACK	0x02
    379 #define IDSR_BUSY	0x01
    380 
    381 #define ASI_INTERRUPT_DISPATCH		0x77	/* [4u] spitfire interrupt dispatch regs */
    382 #define IDCR(x)		(((x)<<14)&0x70)	/* Store anything to this address to dispatch crosscall to CPU (x) */
    383 #define IDDR_0H		0x40			/* Store data to send in these regs */
    384 #define IDDR_0L		0x48	/* unimplemented */
    385 #define IDDR_1H		0x50
    386 #define IDDR_1L		0x58	/* unimplemented */
    387 #define IDDR_2H		0x60
    388 #define IDDR_2L		0x68	/* unimplemented */
    389 #define IDDR_3H		0x70	/* unimplemented */
    390 #define IDDR_3L		0x78	/* unimplemented */
    391 
    392 /*
    393  * Error registers
    394  */
    395 
    396 /* Since we won't try to fix async errs, we don't care about the bits in the regs */
    397 #define ASI_AFAR	0x4d	/* Asynchronous fault address register */
    398 #define AFAR		0x00
    399 #define ASI_AFSR	0x4c	/* Asynchronous fault status register */
    400 #define AFSR		0x00
    401 
    402 #define ASI_P_EER	0x4b	/* Error enable register */
    403 #define P_EER		0x00
    404 #define P_EER_ISAPEN	0x04	/* Enable fatal on ISAP */
    405 #define P_EER_NCEEN	0x02	/* Enable trap on uncorrectable errs */
    406 #define P_EER_CEEN	0x01	/* Enable trap on correctable errs */
    407 
    408 #define ASI_DATAPATH_READ	0x7f /* Read the regs */
    409 #define ASI_DATAPATH_WRITE	0x77 /* Write to the regs */
    410 #define P_DPER_0	0x00	/* Datapath err reg 0 */
    411 #define P_DPER_1	0x18	/* Datapath err reg 1 */
    412 #define P_DCR_0		0x20	/* Datapath control reg 0 */
    413 #define P_DCR_1		0x38	/* Datapath control reg 0 */
    414 
    415 
    416 /* From sparc64/asm.h which I think I'll deprecate since it makes bus.h a pain. */
    417 
    418 #ifndef _LOCORE
    419 /*
    420  * GCC __asm constructs for doing assembly stuff.
    421  */
    422 
    423 /*
    424  * ``Routines'' to load and store from/to alternate address space.
    425  * The location can be a variable, the asi value (address space indicator)
    426  * must be a constant.
    427  *
    428  * N.B.: You can put as many special functions here as you like, since
    429  * they cost no kernel space or time if they are not used.
    430  *
    431  * These were static inline functions, but gcc screws up the constraints
    432  * on the address space identifiers (the "n"umeric value part) because
    433  * it inlines too late, so we have to use the funny valued-macro syntax.
    434  */
    435 
    436 /*
    437  * Apparently the definition of bypass ASIs is that they all use the
    438  * D$ so we need to flush the D$ to make sure we don't get data pollution.
    439  */
    440 
    441 static __inline__ u_char lduba __P((paddr_t loc, int asi));
    442 static __inline__ u_short lduha __P((paddr_t loc, int asi));
    443 static __inline__ u_int lda __P((paddr_t loc, int asi));
    444 static __inline__ int ldswa __P((paddr_t loc, int asi));
    445 static __inline__ u_int64_t ldxa __P((paddr_t loc, int asi));
    446 static __inline__ u_int64_t ldda __P((paddr_t loc, int asi));
    447 
    448 static __inline__ void stba __P((paddr_t loc, int asi, u_char value));
    449 static __inline__ void stha __P((paddr_t loc, int asi, u_short value));
    450 static __inline__ void sta __P((paddr_t loc, int asi, u_int value));
    451 static __inline__ void stxa __P((paddr_t loc, int asi, u_int64_t value));
    452 static __inline__ void stda __P((paddr_t loc, int asi, u_int64_t value));
    453 
    454 #if 0
    455 static __inline__ unsigned int casa __P((paddr_t loc, int asi,
    456 	unsigned int value, unsigned int oldvalue));
    457 static __inline__ u_int64_t casxa __P((paddr_t loc, int asi,
    458 	u_int64_t value, u_int64_t oldvalue));
    459 #endif
    460 
    461 #ifdef __arch64__
    462 static __inline__ u_char
    463 lduba(paddr_t loc, int asi)
    464 {
    465 	register unsigned int _lduba_v;
    466 
    467 	if (PHYS_ASI(asi)) {
    468 		__asm __volatile("wr %3,%%g0,%%asi; "
    469 " andn %2,0x1f,%0; stxa %%g0,[%0] %4; membar #Sync; "
    470 " lduba [%2]%%asi,%0; andn %2,0x1f,%1; membar #Sync; "
    471 " stxa %%g0,[%1] %4; membar #Sync" :
    472 				 "=&r" (_lduba_v), "=r" (loc):
    473 				 "r" ((unsigned long)(loc)),
    474 				 "r" (asi), "n" (ASI_DCACHE_TAG));
    475 	} else {
    476 		__asm __volatile("wr %2,%%g0,%%asi; lduba [%1]%%asi,%0" :
    477 				 "=r" (_lduba_v) :
    478 				 "r" ((unsigned long)(loc)), "r" (asi));
    479 	}
    480 	return (_lduba_v);
    481 }
    482 #else
    483 static __inline__ u_char
    484 lduba(paddr_t loc, int asi)
    485 {
    486 	register unsigned int _lduba_v, _loc_hi, _pstate;
    487 
    488 	_loc_hi = (((u_int64_t)loc)>>32);
    489 	if (PHYS_ASI(asi)) {
    490 		__asm __volatile("wr %4,%%g0,%%asi; "
    491 " andn %2,0x1f,%0; stxa %%g0,[%0] %5; rdpr %%pstate,%1; "
    492 " sllx %3,32,%0; or %0,%2,%0; wrpr %1,8,%%pstate; "
    493 " membar #Sync; lduba [%0]%%asi,%0; wrpr %1,0,%%pstate; "
    494 " andn %2,0x1f,%1; membar #Sync; stxa %%g0,[%1] %5; membar #Sync" :
    495 				 "=&r" (_lduba_v),  "=&r" (_pstate) :
    496 				 "r" ((unsigned long)(loc)), "r" (_loc_hi),
    497 				 "r" (asi), "n" (ASI_DCACHE_TAG));
    498 	} else {
    499 		__asm __volatile("wr %3,%%g0,%%asi; sllx %2,32,%0; "
    500 " or %0,%1,%0; lduba [%0]%%asi,%0" : "=&r" (_lduba_v) :
    501 				 "r" ((unsigned long)(loc)),
    502 				 "r" (_loc_hi), "r" (asi));
    503 	}
    504 	return (_lduba_v);
    505 }
    506 #endif
    507 
    508 #ifdef __arch64__
    509 /* load half-word from alternate address space */
    510 static __inline__ u_short
    511 lduha(paddr_t loc, int asi)
    512 {
    513 	register unsigned int _lduha_v;
    514 
    515 	if (PHYS_ASI(asi)) {
    516 		__asm __volatile("wr %3,%%g0,%%asi; "
    517 " andn %2,0x1f,%0; stxa %%g0,[%0] %4; membar #Sync; "
    518 " lduha [%2]%%asi,%0; andn %2,0x1f,%1; membar #Sync; "
    519 " stxa %%g0,[%1] %4; membar #Sync" : "=&r" (_lduha_v), "=r" (loc) :
    520 				 "r" ((unsigned long)(loc)),
    521 				 "r" (asi), "n" (ASI_DCACHE_TAG));
    522 	} else {
    523 		__asm __volatile("wr %2,%%g0,%%asi; lduha [%1]%%asi,%0" :
    524 				 "=r" (_lduha_v) :
    525 				 "r" ((unsigned long)(loc)), "r" (asi));
    526 	}
    527 	return (_lduha_v);
    528 }
    529 #else
    530 /* load half-word from alternate address space */
    531 static __inline__ u_short
    532 lduha(paddr_t loc, int asi) {
    533 	register unsigned int _lduha_v, _loc_hi, _pstate;
    534 
    535 	_loc_hi = (((u_int64_t)loc)>>32);
    536 
    537 	if (PHYS_ASI(asi)) {
    538 		__asm __volatile("wr %4,%%g0,%%asi; rdpr %%pstate,%1; "
    539 " andn %2,0x1f,%0; stxa %%g0,[%0] %5; wrpr %1,8,%%pstate; sllx %3,32,%0; "
    540 " or %0,%2,%0; membar #Sync; lduha [%0]%%asi,%0; wrpr %1,0,%%pstate; "
    541 " andn %2,0x1f,%1; membar #Sync; stxa %%g0,[%1] %5; membar #Sync" :
    542 				 "=&r" (_lduha_v), "=&r" (_pstate) :
    543 				 "r" ((unsigned long)(loc)), "r" (_loc_hi),
    544 				 "r" (asi), "n" (ASI_DCACHE_TAG));
    545 	} else {
    546 		__asm __volatile("wr %3,%%g0,%%asi; sllx %2,32,%0; "
    547 " or %0,%1,%0; lduha [%0]%%asi,%0" : "=&r" (_lduha_v) :
    548 				 "r" ((unsigned long)(loc)), "r" (_loc_hi), "r" (asi));
    549 	}
    550 	return (_lduha_v);
    551 }
    552 #endif
    553 
    554 
    555 #ifdef __arch64__
    556 /* load unsigned int from alternate address space */
    557 static __inline__ u_int
    558 lda(paddr_t loc, int asi)
    559 {
    560 	register unsigned int _lda_v;
    561 
    562 	if (PHYS_ASI(asi)) {
    563 		__asm __volatile("wr %3,%%g0,%%asi; "
    564 " andn %2,0x1f,%0; stxa %%g0,[%0] %4; membar #Sync; "
    565 " lda [%2]%%asi,%0; andn %2,0x1f,%1; membar #Sync; "
    566 " stxa %%g0,[%1] %4; membar #Sync" : "=&r" (_lda_v), "=r" (loc) :
    567 				 "r" ((unsigned long)(loc)),
    568 				 "r" (asi), "n" (ASI_DCACHE_TAG));
    569 	} else {
    570 		__asm __volatile("wr %2,%%g0,%%asi; lda [%1]%%asi,%0" :
    571 				 "=r" (_lda_v) :
    572 				 "r" ((unsigned long)(loc)), "r" (asi));
    573 	}
    574 	return (_lda_v);
    575 }
    576 
    577 /* load signed int from alternate address space */
    578 static __inline__ int
    579 ldswa(paddr_t loc, int asi)
    580 {
    581 	register int _lda_v;
    582 
    583 	if (PHYS_ASI(asi)) {
    584 		__asm __volatile("wr %3,%%g0,%%asi; "
    585 " andn %2,0x1f,%0; stxa %%g0,[%0] %4; membar #Sync; "
    586 " ldswa [%2]%%asi,%0; andn %2,0x1f,%1; membar #Sync; "
    587 " stxa %%g0,[%1] %4; membar #Sync" : "=&r" (_lda_v), "=r" (loc) :
    588 				 "r" ((unsigned long)(loc)),
    589 				 "r" (asi), "n" (ASI_DCACHE_TAG));
    590 	} else {
    591 		__asm __volatile("wr %2,%%g0,%%asi; ldswa [%1]%%asi,%0" :
    592 				 "=r" (_lda_v) :
    593 				 "r" ((unsigned long)(loc)), "r" (asi));
    594 	}
    595 	return (_lda_v);
    596 }
    597 #else	/* __arch64__ */
    598 /* load unsigned int from alternate address space */
    599 static __inline__ u_int
    600 lda(paddr_t loc, int asi)
    601 {
    602 	register unsigned int _lda_v, _loc_hi, _pstate;
    603 
    604 	_loc_hi = (((u_int64_t)loc)>>32);
    605 	if (PHYS_ASI(asi)) {
    606 		__asm __volatile("wr %4,%%g0,%%asi; rdpr %%pstate,%1;"
    607 " andn %2,0x1f,%0; stxa %%g0,[%0] %5; wrpr %1,8,%%pstate; "
    608 " sllx %3,32,%0; or %0,%2,%0; membar #Sync;lda [%0]%%asi,%0; "
    609 " wrpr %1,0,%%pstate; andn %2,0x1f,%1; membar #Sync; "
    610 " stxa %%g0,[%1] %5; membar #Sync" : "=&r" (_lda_v), "=&r" (_pstate) :
    611 				 "r" ((unsigned long)(loc)), "r" (_loc_hi),
    612 				 "r" (asi), "n" (ASI_DCACHE_TAG));
    613 	} else {
    614 		__asm __volatile("wr %3,%%g0,%%asi; sllx %2,32,%0; "
    615 " or %0,%1,%0; lda [%0]%%asi,%0" : "=&r" (_lda_v) :
    616 				 "r" ((unsigned long)(loc)),
    617 				 "r" (_loc_hi), "r" (asi));
    618 	}
    619 	return (_lda_v);
    620 }
    621 
    622 /* load signed int from alternate address space */
    623 static __inline__ int
    624 ldswa(paddr_t loc, int asi)
    625 {
    626 	register int _lda_v, _loc_hi, _pstate;
    627 
    628 	_loc_hi = (((u_int64_t)loc)>>32);
    629 	if (PHYS_ASI(asi)) {
    630 		__asm __volatile("wr %4,%%g0,%%asi; rdpr %%pstate,%1;"
    631 " andn %2,0x1f,%0; stxa %%g0,[%0] %5; wrpr %1,8,%%pstate; sllx %3,32,%0;"
    632 " or %0,%2,%0; membar #Sync; ldswa [%0]%%asi,%0; wrpr %1,0,%%pstate; "
    633 " andn %2,0x1f,%1; membar #Sync; stxa %%g0,[%1] %5; membar #Sync" :
    634 				 "=&r" (_lda_v), "=&r" (_pstate) :
    635 				 "r" ((unsigned long)(loc)), "r" (_loc_hi),
    636 				 "r" (asi), "n" (ASI_DCACHE_TAG));
    637 	} else {
    638 		__asm __volatile("wr %3,%%g0,%%asi; sllx %2,32,%0; "
    639 " or %0,%1,%0; ldswa [%0]%%asi,%0" : "=&r" (_lda_v) :
    640 				 "r" ((unsigned long)(loc)),
    641 				 "r" (_loc_hi), "r" (asi));
    642 	}
    643 	return (_lda_v);
    644 }
    645 #endif /* __arch64__ */
    646 
    647 #ifdef	__arch64__
    648 /* load 64-bit int from alternate address space -- these should never be used */
    649 static __inline__ u_int64_t
    650 ldda(paddr_t loc, int asi)
    651 {
    652 	register long long _lda_v;
    653 
    654 	if (PHYS_ASI(asi)) {
    655 		__asm __volatile("wr %3,%%g0,%%asi; "
    656 " andn %2,0x1f,%0; stxa %%g0,[%0] %4; membar #Sync; "
    657 " ldda [%2]%%asi,%0; andn %2,0x1f,%1; membar #Sync; "
    658 " stxa %%g0,[%1] %4; membar #Sync" : "=&r" (_lda_v), "=&r" (loc) :
    659 				 "r" ((unsigned long)(loc)),
    660 				 "r" (asi), "n" (ASI_DCACHE_TAG));
    661 	} else {
    662 		__asm __volatile("wr %2,%%g0,%%asi; ldda [%1]%%asi,%0" :
    663 				 "=r" (_lda_v) :
    664 				 "r" ((unsigned long)(loc)), "r" (asi));
    665 	}
    666 	return (_lda_v);
    667 }
    668 #else
    669 /* load 64-bit int from alternate address space */
    670 static __inline__ u_int64_t
    671 ldda(paddr_t loc, int asi)
    672 {
    673 	register long long _lda_v, _loc_hi, _pstate;
    674 
    675 	_loc_hi = (((u_int64_t)loc)>>32);
    676 	if (PHYS_ASI(asi)) {
    677 		__asm __volatile("wr %4,%%g0,%%asi; rdpr %%pstate,%1;"
    678 " andn %2,0x1f,%0; rdpr %%pstate,%1; stxa %%g0,[%0] %5; wrpr %1,8,%%pstate;"
    679 " sllx %3,32,%0; or %0,%2,%0; membar #Sync; ldda [%0]%%asi,%0; wrpr %1,0,%%pstate; "
    680 " andn %2,0x1f,%1; membar #Sync; stxa %%g0,[%1] %5; membar #Sync" :
    681 				 "=&r" (_lda_v), "=&r" (_pstate) :
    682 				 "r" ((unsigned long)(loc)), "r" (_loc_hi),
    683 				 "r" (asi), "n" (ASI_DCACHE_TAG));
    684 	} else {
    685 		__asm __volatile("wr %3,%%g0,%%asi; sllx %2,32,%0; "
    686 " or %0,%1,%0; ldda [%0]%%asi,%0" : "=&r" (_lda_v) :
    687 				 "r" ((unsigned long)(loc)), "r" (_loc_hi), "r" (asi));
    688 	}
    689 	return (_lda_v);
    690 }
    691 #endif
    692 
    693 
    694 #ifdef __arch64__
    695 /* native load 64-bit int from alternate address space w/64-bit compiler*/
    696 static __inline__ u_int64_t
    697 ldxa(paddr_t loc, int asi)
    698 {
    699 	register unsigned long _lda_v;
    700 
    701 	if (PHYS_ASI(asi)) {
    702 		__asm __volatile("wr %3,%%g0,%%asi; "
    703 " andn %2,0x1f,%0; stxa %%g0,[%0] %4; membar #Sync; "
    704 " ldxa [%2]%%asi,%0; andn %2,0x1f,%1; membar #Sync; "
    705 " stxa %%g0,[%1] %4; membar #Sync" : "=&r" (_lda_v), "=r" (loc) :
    706 				 "r" ((unsigned long)(loc)),
    707 				 "r" (asi), "n" (ASI_DCACHE_TAG));
    708 	} else {
    709 		__asm __volatile("wr %2,%%g0,%%asi; ldxa [%1]%%asi,%0" :
    710 				 "=r" (_lda_v) :
    711 				 "r" ((unsigned long)(loc)), "r" (asi));
    712 	}
    713 	return (_lda_v);
    714 }
    715 #else
    716 /* native load 64-bit int from alternate address space w/32-bit compiler*/
    717 static __inline__ u_int64_t
    718 ldxa(paddr_t loc, int asi)
    719 {
    720 	register unsigned long _ldxa_lo, _ldxa_hi, _loc_hi;
    721 
    722 	_loc_hi = (((u_int64_t)loc)>>32);
    723 	if (PHYS_ASI(asi)) {
    724 		__asm __volatile("wr %4,%%g0,%%asi; "
    725 " andn %2,0x1f,%0; rdpr %%pstate,%1; stxa %%g0,[%0] %5; "
    726 " sllx %3,32,%0; wrpr %1,8,%%pstate; or %0,%2,%0; membar #Sync; ldxa [%0]%%asi,%0; "
    727 " wrpr %1,0,%%pstate; andn %2,0x1f,%1; membar #Sync; stxa %%g0,[%1] %5; membar #Sync; "
    728 " srlx %0,32,%1; srl %0,0,%0" :
    729 				 "=&r" (_ldxa_lo), "=&r" (_ldxa_hi) :
    730 				 "r" ((unsigned long)(loc)), "r" (_loc_hi),
    731 				 "r" (asi), "n" (ASI_DCACHE_TAG));
    732 	} else {
    733 		__asm __volatile("wr %4,%%g0,%%asi; sllx %3,32,%0; "
    734 " or %0,%2,%0; ldxa [%0]%%asi,%0; srlx %0,32,%1; srl %0,0,%0;" :
    735 				 "=&r" (_ldxa_lo), "=&r" (_ldxa_hi) :
    736 				 "r" ((unsigned long)(loc)), "r" (_loc_hi),
    737 				 "r" (asi));
    738 	}
    739 	return ((((int64_t)_ldxa_hi)<<32)|_ldxa_lo);
    740 }
    741 #endif
    742 
    743 /* store byte to alternate address space */
    744 #ifdef __arch64__
    745 static __inline__ void
    746 stba(paddr_t loc, int asi, u_char value)
    747 {
    748 	if (PHYS_ASI(asi)) {
    749 		__asm __volatile("wr %3,%%g0,%%asi; stba %1,[%2]%%asi;"
    750 " andn %2,0x1f,%0; membar #Sync; stxa %%g0,[%0] %4; membar #Sync" :
    751 			"=&r" (loc) :
    752 			"r" ((int)(value)), "r" ((unsigned long)(loc)),
    753 			"r" (asi), "n" (ASI_DCACHE_TAG));
    754 	} else {
    755 		__asm __volatile("wr %2,%%g0,%%asi; stba %0,[%1]%%asi" : :
    756 			"r" ((int)(value)), "r" ((unsigned long)(loc)),
    757 			"r" (asi));
    758 	}
    759 }
    760 #else
    761 static __inline__ void
    762 stba(paddr_t loc, int asi, u_char value)
    763 {
    764 	register int _loc_hi, _pstate;
    765 
    766 	_loc_hi = (((u_int64_t)loc)>>32);
    767 	if (PHYS_ASI(asi)) {
    768 		__asm __volatile("wr %5,%%g0,%%asi; sllx %4,32,%0; rdpr %%pstate,%1;"
    769 " or %3,%0,%0; wrpr %1,8,%%pstate; stba %2,[%0]%%asi; wrpr %1,0,%%pstate; "
    770 " andn %0,0x1f,%1;  membar #Sync; stxa %%g0,[%1] %6; membar #Sync" :
    771 				 "=&r" (_loc_hi), "=&r" (_pstate) :
    772 				 "r" ((int)(value)), "r" ((unsigned long)(loc)),
    773 				 "r" (_loc_hi), "r" (asi), "n" (ASI_DCACHE_TAG));
    774 	} else {
    775 		__asm __volatile("wr %4,%%g0,%%asi; sllx %3,32,%0; "
    776 " or %2,%0,%0; stba %1,[%0]%%asi" : "=&r" (_loc_hi) :
    777 				 "r" ((int)(value)), "r" ((unsigned long)(loc)),
    778 				 "r" (_loc_hi), "r" (asi));
    779 	}
    780 }
    781 #endif
    782 
    783 /* store half-word to alternate address space */
    784 #ifdef __arch64__
    785 static __inline__ void
    786 stha(paddr_t loc, int asi, u_short value)
    787 {
    788 	if (PHYS_ASI(asi)) {
    789 		__asm __volatile("wr %3,%%g0,%%asi; stha %1,[%2]%%asi;"
    790 " andn %2,0x1f,%0; membar #Sync; stxa %%g0,[%0] %4; membar #Sync" :
    791 			"=&r" (loc) :
    792 			"r" ((int)(value)), "r" ((unsigned long)(loc)),
    793 			"r" (asi), "n" (ASI_DCACHE_TAG) : "memory");
    794 	} else {
    795 		__asm __volatile("wr %2,%%g0,%%asi; stha %0,[%1]%%asi" : :
    796 			"r" ((int)(value)), "r" ((unsigned long)(loc)),
    797 			"r" (asi) : "memory");
    798 	}
    799 }
    800 #else
    801 static __inline__ void
    802 stha(paddr_t loc, int asi, u_short value)
    803 {
    804 	register int _loc_hi, _pstate;
    805 
    806 	_loc_hi = (((u_int64_t)loc)>>32);
    807 	if (PHYS_ASI(asi)) {
    808 		__asm __volatile("wr %5,%%g0,%%asi; sllx %4,32,%0; rdpr %%pstate,%1;"
    809 " or %3,%0,%0; wrpr %1,8,%%pstate; stha %2,[%0]%%asi; wrpr %1,0,%%pstate; "
    810 " andn %0,0x1f,%1;  membar #Sync; stxa %%g0,[%1] %6; membar #Sync" :
    811 			"=&r" (_loc_hi), "=&r" (_pstate) :
    812 			"r" ((int)(value)), "r" ((unsigned long)(loc)),
    813 			"r" (_loc_hi), "r" (asi),
    814 			"n" (ASI_DCACHE_TAG) : "memory");
    815 	} else {
    816 		__asm __volatile("wr %4,%%g0,%%asi; sllx %3,32,%0; "
    817 " or %2,%0,%0; stha %1,[%0]%%asi" : "=&r" (_loc_hi) :
    818 				 "r" ((int)(value)), "r" ((unsigned long)(loc)),
    819 				 "r" (_loc_hi), "r" (asi) : "memory");
    820 	}
    821 }
    822 #endif
    823 
    824 
    825 /* store int to alternate address space */
    826 #ifdef __arch64__
    827 static __inline__ void
    828 sta(paddr_t loc, int asi, u_int value)
    829 {
    830 	if (PHYS_ASI(asi)) {
    831 		__asm __volatile("wr %3,%%g0,%%asi; sta %1,[%2]%%asi;"
    832 " andn %2,0x1f,%0; membar #Sync; stxa %%g0,[%0] %4; membar #Sync" :
    833 			"=&r" (loc) :
    834 			"r" ((int)(value)), "r" ((unsigned long)(loc)),
    835 			"r" (asi), "n" (ASI_DCACHE_TAG) : "memory");
    836 	} else {
    837 		__asm __volatile("wr %2,%%g0,%%asi; sta %0,[%1]%%asi" : :
    838 			"r" ((int)(value)), "r" ((unsigned long)(loc)),
    839 			"r" (asi) : "memory");
    840 	}
    841 }
    842 #else
    843 static __inline__ void
    844 sta(paddr_t loc, int asi, u_int value)
    845 {
    846 	register int _loc_hi, _pstate;
    847 
    848 	_loc_hi = (((u_int64_t)loc)>>32);
    849 	if (PHYS_ASI(asi)) {
    850 		__asm __volatile("wr %5,%%g0,%%asi; sllx %4,32,%0; rdpr %%pstate,%1;"
    851 " or %3,%0,%0; wrpr %1,8,%%pstate; sta %2,[%0]%%asi; wrpr %1,0,%%pstate; "
    852 " andn %0,0x1f,%1;  membar #Sync; stxa %%g0,[%1] %6; membar #Sync" :
    853 			"=&r" (_loc_hi), "=&r" (_pstate) :
    854 			"r" ((int)(value)), "r" ((unsigned long)(loc)),
    855 			"r" (_loc_hi), "r" (asi),
    856 			"n" (ASI_DCACHE_TAG) : "memory");
    857 	} else {
    858 		__asm __volatile("wr %4,%%g0,%%asi; sllx %3,32,%0; "
    859 " or %2,%0,%0; sta %1,[%0]%%asi" : "=&r" (_loc_hi) :
    860 				 "r" ((int)(value)), "r" ((unsigned long)(loc)),
    861 				 "r" (_loc_hi), "r" (asi) : "memory");
    862 	}
    863 }
    864 #endif
    865 
    866 /* store 64-bit int to alternate address space */
    867 #ifdef __arch64__
    868 static __inline__ void
    869 stda(paddr_t loc, int asi, u_int64_t value)
    870 {
    871 	if (PHYS_ASI(asi)) {
    872 		__asm __volatile("wr %3,%%g0,%%asi; stda %1,[%2]%%asi;"
    873 " andn %2,0x1f,%0; membar #Sync; stxa %%g0,[%0] %4; membar #Sync" :
    874 			"=&r" (loc) :
    875 			"r" ((long long)(value)), "r" ((unsigned long)(loc)),
    876 			"r" (asi), "n" (ASI_DCACHE_TAG) : "memory");
    877 	} else {
    878 		__asm __volatile("wr %2,%%g0,%%asi; stda %0,[%1]%%asi" : :
    879 			"r" ((long long)(value)), "r" ((unsigned long)(loc)),
    880 			"r" (asi) : "memory");
    881 	}
    882 }
    883 #else
    884 static __inline__ void
    885 stda(paddr_t loc, int asi, u_int64_t value)
    886 {
    887 	register int _loc_hi, _pstate;
    888 
    889 	_loc_hi = (((u_int64_t)loc)>>32);
    890 	if (PHYS_ASI(asi)) {
    891 		__asm __volatile("wr %5,%%g0,%%asi; sllx %4,32,%0; rdpr %%pstate,%1; "
    892 " or %3,%0,%0; wrpr %1,8,%%pstate; stda %2,[%0]%%asi; wrpr %1,0,%%pstate;"
    893 " andn %0,0x1f,%1;  membar #Sync; stxa %%g0,[%1] %6; membar #Sync" :
    894 			"=&r" (_loc_hi), "=&r" (_pstate) :
    895 			"r" ((long long)(value)), "r" ((unsigned long)(loc)),
    896 			"r" (_loc_hi), "r" (asi),
    897 			"n" (ASI_DCACHE_TAG) : "memory");
    898 	} else {
    899 		__asm __volatile("wr %4,%%g0,%%asi; sllx %3,32,%0; "
    900 " or %2,%0,%0; stda %1,[%0]%%asi" :
    901 			"=&r" (_loc_hi) :
    902 			"r" ((long long)(value)), "r" ((unsigned long)(loc)),
    903 			"r" (_loc_hi), "r" (asi) : "memory");
    904 	}
    905 }
    906 #endif
    907 
    908 #ifdef __arch64__
    909 /* native store 64-bit int to alternate address space w/64-bit compiler*/
    910 static __inline__ void
    911 stxa(paddr_t loc, int asi, u_int64_t value)
    912 {
    913 	if (PHYS_ASI(asi)) {
    914 		__asm __volatile("wr %3,%%g0,%%asi; stxa %1,[%2]%%asi;"
    915 " andn %2,0x1f,%0; membar #Sync; stxa %%g0,[%0] %4; membar #Sync" :
    916 			"=&r" (asi) :
    917 			"r" ((unsigned long)(value)),
    918 			"r" ((unsigned long)(loc)),
    919 			"r" (asi), "n" (ASI_DCACHE_TAG) : "memory");
    920 	} else {
    921 		__asm __volatile("wr %2,%%g0,%%asi; stxa %0,[%1]%%asi" : :
    922 			"r" ((unsigned long)(value)),
    923 			"r" ((unsigned long)(loc)), "r" (asi) : "memory");
    924 	}
    925 }
    926 #else
    927 /* native store 64-bit int to alternate address space w/32-bit compiler*/
    928 static __inline__ void
    929 stxa(paddr_t loc, int asi, u_int64_t value)
    930 {
    931 	int _stxa_lo, _stxa_hi, _loc_hi;
    932 
    933 	_stxa_lo = value;
    934 	_stxa_hi = ((u_int64_t)value)>>32;
    935 	_loc_hi = (((u_int64_t)(u_long)loc)>>32);
    936 
    937 	if (PHYS_ASI(asi)) {
    938 		__asm __volatile("wr %7,%%g0,%%asi; sllx %4,32,%1; sllx %6,32,%0; "
    939 " or %1,%3,%1; rdpr %%pstate,%2; or %0,%5,%0; wrpr %2,8,%%pstate; "
    940 " stxa %1,[%0]%%asi; wrpr %2,0,%%pstate; "
    941 " andn %0,0x1f,%1;  membar #Sync; stxa %%g0,[%1] %8; membar #Sync" :
    942 				 "=&r" (_loc_hi), "=&r" (_stxa_hi),
    943 				 "=&r" ((int)(_stxa_lo)) :
    944 				 "r" ((int)(_stxa_lo)), "r" ((int)(_stxa_hi)),
    945 				 "r" ((unsigned long)(loc)), "r" (_loc_hi),
    946 				 "r" (asi), "n" (ASI_DCACHE_TAG) : "memory");
    947 	} else {
    948 		__asm __volatile("wr %6,%%g0,%%asi; sllx %3,32,%1; sllx %5,32,%0; "
    949 " or %1,%2,%1; or %0,%4,%0; stxa %1,[%0]%%asi" :
    950 				 "=&r" (_loc_hi), "=&r" (_stxa_hi) :
    951 				 "r" ((int)(_stxa_lo)), "r" ((int)(_stxa_hi)),
    952 				 "r" ((unsigned long)(loc)), "r" (_loc_hi),
    953 				 "r" (asi) : "memory");
    954 	}
    955 }
    956 #endif
    957 
    958 #if 0
    959 #ifdef __arch64__
    960 /* native store 64-bit int to alternate address space w/64-bit compiler*/
    961 static __inline__ u_int64_t
    962 casxa(paddr_t loc, int asi, u_int64_t value, u_int64_t oldvalue)
    963 {
    964 	if (PHYS_ASI(asi)) {
    965 		__asm __volatile("wr %4,%%g0,%%asi; casxa [%3]%%asi,%2,%1;"
    966 " andn %3,0x1f,%0; membar #Sync; stxa %%g0,[%0] %5; membar #Sync" :
    967 			"=&r" (loc), "+r" (value) :
    968 			"r" ((unsigned long)(oldvalue)),
    969 			"r" ((unsigned long)(loc)),
    970 			"r" (asi), "n" (ASI_DCACHE_TAG) : "memory");
    971 	} else {
    972 		__asm __volatile("wr %3,%%g0,%%asi; casxa [%1]%%asi,%2,%0" :
    973 			"+r" (value) :
    974 			"r" ((unsigned long)(loc)), "r" (oldvalue), "r" (asi) :
    975 			"memory");
    976 	}
    977 	return (value);
    978 }
    979 #else
    980 /* native store 64-bit int to alternate address space w/32-bit compiler*/
    981 static __inline__ u_int64_t
    982 casxa(paddr_t loc, int asi, u_int64_t value, u_int64_t oldvalue)
    983 {
    984 	int _casxa_lo, _casxa_hi, _loc_hi, _oval_hi;
    985 
    986 	_casxa_lo = value;
    987 	_casxa_hi = ((u_int64_t)value)>>32;
    988 	_oval_hi = ((u_int64_t)oldvalue)>>32;
    989 	_loc_hi = (((u_int64_t)(u_long)loc)>>32);
    990 
    991 #ifdef __notyet
    992 /*
    993  * gcc cannot handle this since it thinks it has >10 asm operands.
    994  */
    995 	if (PHYS_ASI(asi)) {
    996 		__asm __volatile("wr %6,%%g0,%%asi; sllx %1,32,%1; sllx %0,32,%0; "
    997 " sllx %3,32,%3; or %1,%2,%1; rdpr %%pstate,%2; or %0,%4,%0; or %3,%5,%3; "
    998 " wrpr %2,8,%%pstate; casxa [%0]%%asi,%3,%1; wrpr %2,0,%%pstate; "
    999 " andn %0,0x1f,%3;  membar #Sync; stxa %%g0,[%3] %7; membar #Sync; "
   1000 " sll %1,0,%2; srax %1,32,%1 " :
   1001 			"+r" (_loc_hi), "+r" (_casxa_hi),
   1002 			"+r" (_casxa_lo), "+r" (_oval_hi) :
   1003 			"r" ((unsigned long)(loc)),
   1004 			"r" ((unsigned int)(oldvalue)),
   1005 			"r" (asi), "n" (ASI_DCACHE_TAG));
   1006 	} else {
   1007 		__asm __volatile("wr %7,%%g0,%%asi; sllx %1,32,%1; sllx %5,32,%0; "
   1008 " or %1,%2,%1; sllx %3,32,%2; or %0,%4,%0; or %2,%4,%2; "
   1009 " casxa [%0]%%asi,%2,%1; sll %1,0,%2; srax %o1,32,%o1 " :
   1010 			"=&r" (_loc_hi), "+r" (_casxa_hi), "+r" (_casxa_lo) :
   1011 			"r" ((int)(_oval_hi)), "r" ((int)(oldvalue)),
   1012 			"r" ((unsigned long)(loc)), "r" (_loc_hi),
   1013 			"r" (asi) : "memory");
   1014 	}
   1015 #endif
   1016 	return (((u_int64_t)_casxa_hi<<32)|(u_int64_t)_casxa_lo);
   1017 }
   1018 #endif
   1019 #endif /* 0 */
   1020 
   1021 #if 0
   1022 #ifdef __arch64__
   1023 /* load byte from alternate address space */
   1024 #define	lduba(loc, asi) ({ \
   1025 	register unsigned int _lduba_v; \
   1026 	if (PHYS_ASI(asi)) { \
   1027 		__asm __volatile("wr %3,%%g0,%%asi; " \
   1028 " andn %2,0x1f,%0; stxa %%g0,[%0] %4; membar #Sync; " \
   1029 " lduba [%2]%%asi,%0; andn %2,0x1f,%1; membar #Sync; " \
   1030 " stxa %%g0,[%1] %4; membar #Sync" : \
   1031 		"=&r" (_lduba_v), "=r" (loc): \
   1032 		"r" ((unsigned long)(loc)), "r" (asi), "n" (ASI_DCACHE_TAG)); \
   1033 	} else { \
   1034 		__asm __volatile("wr %2,%%g0,%%asi; lduba [%1]%%asi,%0" : \
   1035 		"=r" (_lduba_v) : \
   1036 		"r" ((unsigned long)(loc)), "r" (asi)); \
   1037 	} \
   1038 	_lduba_v; \
   1039 })
   1040 #else
   1041 /* load byte from alternate address space */
   1042 #define	lduba(loc, asi) ({ \
   1043 	register unsigned int _lduba_v, _loc_hi, _pstate; \
   1044 	_loc_hi = (((u_int64_t)loc)>>32); \
   1045 	if (PHYS_ASI(asi)) { \
   1046 		__asm __volatile("wr %4,%%g0,%%asi; " \
   1047 " andn %2,0x1f,%0; stxa %%g0,[%0] %5; rdpr %%pstate,%1; " \
   1048 " sllx %3,32,%0; or %0,%2,%0; wrpr %1,8,%%pstate; " \
   1049 " membar #Sync; lduba [%0]%%asi,%0; wrpr %1,0,%%pstate; " \
   1050 " andn %2,0x1f,%1; membar #Sync; stxa %%g0,[%1] %5; membar #Sync" : \
   1051 		"=&r" (_lduba_v),  "=&r" (_pstate) : \
   1052 		"r" ((unsigned long)(loc)), "r" (_loc_hi), \
   1053 		"r" (asi), "n" (ASI_DCACHE_TAG)); \
   1054 	} else { \
   1055 		__asm __volatile("wr %3,%%g0,%%asi; sllx %2,32,%0; " \
   1056 " or %0,%1,%0; lduba [%0]%%asi,%0" : "=&r" (_lduba_v) : \
   1057 		"r" ((unsigned long)(loc)), "r" (_loc_hi), "r" (asi)); \
   1058 	} \
   1059 	_lduba_v; \
   1060 })
   1061 #endif
   1062 
   1063 #ifdef __arch64__
   1064 /* load half-word from alternate address space */
   1065 #define	lduha(loc, asi) ({ \
   1066 	register unsigned int _lduha_v; \
   1067 	if (PHYS_ASI(asi)) { \
   1068 		__asm __volatile("wr %3,%%g0,%%asi; " \
   1069 " andn %2,0x1f,%0; stxa %%g0,[%0] %4; membar #Sync; " \
   1070 " lduha [%2]%%asi,%0; andn %2,0x1f,%1; membar #Sync; " \
   1071 " stxa %%g0,[%1] %4; membar #Sync" : "=&r" (_lduha_v), "=r" (loc) : \
   1072 		"r" ((unsigned long)(loc)), "r" (asi), "n" (ASI_DCACHE_TAG)); \
   1073 	} else { \
   1074 		__asm __volatile("wr %2,%%g0,%%asi; lduha [%1]%%asi,%0" : "=r" (_lduha_v) : \
   1075 		"r" ((unsigned long)(loc)), "r" (asi)); \
   1076 	} \
   1077 	_lduha_v; \
   1078 })
   1079 #else
   1080 /* load half-word from alternate address space */
   1081 #define	lduha(loc, asi) ({ \
   1082 	register unsigned int _lduha_v, _loc_hi, _pstate; \
   1083 	_loc_hi = (((u_int64_t)loc)>>32); \
   1084 	if (PHYS_ASI(asi)) { \
   1085 		__asm __volatile("wr %4,%%g0,%%asi; rdpr %%pstate,%1; " \
   1086 " andn %2,0x1f,%0; stxa %%g0,[%0] %5; wrpr %1,8,%%pstate; sllx %3,32,%0; " \
   1087 " or %0,%2,%0; membar #Sync; lduha [%0]%%asi,%0; wrpr %1,0,%%pstate; " \
   1088 " andn %2,0x1f,%1; membar #Sync; stxa %%g0,[%1] %5; membar #Sync" : \
   1089 		"=&r" (_lduha_v), "=&r" (_pstate) : \
   1090 		"r" ((unsigned long)(loc)), "r" (_loc_hi), \
   1091 		"r" (asi), "n" (ASI_DCACHE_TAG)); \
   1092 	} else { \
   1093 		__asm __volatile("wr %3,%%g0,%%asi; sllx %2,32,%0; " \
   1094 " or %0,%1,%0; lduha [%0]%%asi,%0" : "=&r" (_lduha_v) : \
   1095 		"r" ((unsigned long)(loc)), "r" (_loc_hi), "r" (asi)); \
   1096 	} \
   1097 	_lduha_v; \
   1098 })
   1099 #endif
   1100 
   1101 #ifdef __arch64__
   1102 /* load unsigned int from alternate address space */
   1103 #define	lda(loc, asi) ({ \
   1104 	register unsigned int _lda_v; \
   1105 	if (PHYS_ASI(asi)) { \
   1106 		__asm __volatile("wr %3,%%g0,%%asi; " \
   1107 " andn %2,0x1f,%0; stxa %%g0,[%0] %4; membar #Sync; " \
   1108 " lda [%2]%%asi,%0; andn %2,0x1f,%1; membar #Sync; " \
   1109 " stxa %%g0,[%1] %4; membar #Sync" : "=&r" (_lda_v), "=r" (loc) : \
   1110 		"r" ((unsigned long)(loc)), "r" (asi), "n" (ASI_DCACHE_TAG)); \
   1111 	} else { \
   1112 		__asm __volatile("wr %2,%%g0,%%asi; lda [%1]%%asi,%0" : "=r" (_lda_v) : \
   1113 		"r" ((unsigned long)(loc)), "r" (asi)); \
   1114 	} \
   1115 	_lda_v; \
   1116 })
   1117 
   1118 /* load signed int from alternate address space */
   1119 #define	ldswa(loc, asi) ({ \
   1120 	register int _lda_v; \
   1121 	if (PHYS_ASI(asi)) { \
   1122 		__asm __volatile("wr %3,%%g0,%%asi; " \
   1123 " andn %2,0x1f,%0; stxa %%g0,[%0] %4; membar #Sync; " \
   1124 " ldswa [%2]%%asi,%0; andn %2,0x1f,%1; membar #Sync; " \
   1125 " stxa %%g0,[%1] %4; membar #Sync" : "=&r" (_lda_v), "=r" (loc) : \
   1126 		"r" ((unsigned long)(loc)), "r" (asi), "n" (ASI_DCACHE_TAG)); \
   1127 	} else { \
   1128 		__asm __volatile("wr %2,%%g0,%%asi; ldswa [%1]%%asi,%0" : "=r" (_lda_v) : \
   1129 		"r" ((unsigned long)(loc)), "r" (asi)); \
   1130 	} \
   1131 	_lda_v; \
   1132 })
   1133 #else	/* __arch64__ */
   1134 /* load unsigned int from alternate address space */
   1135 #define	lda(loc, asi) ({ \
   1136 	register unsigned int _lda_v, _loc_hi, _pstate; \
   1137 	_loc_hi = (((u_int64_t)loc)>>32); \
   1138 	if (PHYS_ASI(asi)) { \
   1139 		__asm __volatile("wr %4,%%g0,%%asi; rdpr %%pstate,%1;" \
   1140 " andn %2,0x1f,%0; stxa %%g0,[%0] %5; wrpr %1,8,%%pstate; " \
   1141 " sllx %3,32,%0; or %0,%2,%0; membar #Sync;lda [%0]%%asi,%0; " \
   1142 " wrpr %1,0,%%pstate; andn %2,0x1f,%1; membar #Sync; " \
   1143 " stxa %%g0,[%1] %5; membar #Sync" : "=&r" (_lda_v), "=&r" (_pstate) : \
   1144 		"r" ((unsigned long)(loc)), "r" (_loc_hi), \
   1145 		"r" (asi), "n" (ASI_DCACHE_TAG)); \
   1146 	} else { \
   1147 		__asm __volatile("wr %3,%%g0,%%asi; sllx %2,32,%0; " \
   1148 " or %0,%1,%0; lda [%0]%%asi,%0" : "=&r" (_lda_v) : \
   1149 		"r" ((unsigned long)(loc)), "r" (_loc_hi), "r" (asi)); \
   1150 	} \
   1151 	_lda_v; \
   1152 })
   1153 
   1154 /* load signed int from alternate address space */
   1155 #define	ldswa(loc, asi) ({ \
   1156 	register int _lda_v, _loc_hi, _pstate; \
   1157 	_loc_hi = (((u_int64_t)loc)>>32); \
   1158 	if (PHYS_ASI(asi)) { \
   1159 		__asm __volatile("wr %4,%%g0,%%asi; rdpr %%pstate,%1;" \
   1160 " andn %2,0x1f,%0; stxa %%g0,[%0] %5; wrpr %1,8,%%pstate; sllx %3,32,%0;" \
   1161 " or %0,%2,%0; membar #Sync; ldswa [%0]%%asi,%0; wrpr %1,0,%%pstate; " \
   1162 " andn %2,0x1f,%1; membar #Sync; stxa %%g0,[%1] %5; membar #Sync" : \
   1163 		"=&r" (_lda_v), "=&r" (_pstate) : \
   1164 		"r" ((unsigned long)(loc)), "r" (_loc_hi), \
   1165 		"r" (asi), "n" (ASI_DCACHE_TAG)); \
   1166 	} else { \
   1167 		__asm __volatile("wr %3,%%g0,%%asi; sllx %2,32,%0; " \
   1168 " or %0,%1,%0; ldswa [%0]%%asi,%0" : "=&r" (_lda_v) : \
   1169 		"r" ((unsigned long)(loc)), "r" (_loc_hi), "r" (asi)); \
   1170 	} \
   1171 	_lda_v; \
   1172 })
   1173 #endif /* __arch64__ */
   1174 
   1175 #ifdef	__arch64__
   1176 /* load 64-bit int from alternate address space -- these should never be used */
   1177 #define	ldda(loc, asi) ({ \
   1178 	register long long _lda_v; \
   1179 	if (PHYS_ASI(asi)) { \
   1180 		__asm __volatile("wr %3,%%g0,%%asi; " \
   1181 " andn %2,0x1f,%0; stxa %%g0,[%0] %4; membar #Sync; " \
   1182 " ldda [%2]%%asi,%0; andn %2,0x1f,%1; membar #Sync; " \
   1183 " stxa %%g0,[%1] %4; membar #Sync" : "=&r" (_lda_v), "=&r" (loc) : \
   1184 		"r" ((unsigned long)(loc)), "r" (asi), "n" (ASI_DCACHE_TAG)); \
   1185 	} else { \
   1186 		__asm __volatile("wr %2,%%g0,%%asi; ldda [%1]%%asi,%0" : "=r" (_lda_v) : \
   1187 		"r" ((unsigned long)(loc)), "r" (asi)); \
   1188 	} \
   1189 	_lda_v; \
   1190 })
   1191 #else
   1192 /* load 64-bit int from alternate address space */
   1193 #define	ldda(loc, asi) ({ \
   1194 	register long long _lda_v, _loc_hi, _pstate; \
   1195 	_loc_hi = (((u_int64_t)loc)>>32); \
   1196 	if (PHYS_ASI(asi)) { \
   1197 		__asm __volatile("wr %4,%%g0,%%asi; rdpr %%pstate,%1;" \
   1198 " andn %2,0x1f,%0; rdpr %%pstate,%1; stxa %%g0,[%0] %5; wrpr %1,8,%%pstate;" \
   1199 " sllx %3,32,%0; or %0,%2,%0; membar #Sync; ldda [%0]%%asi,%0; wrpr %1,0,%%pstate; " \
   1200 " andn %2,0x1f,%1; membar #Sync; stxa %%g0,[%1] %5; membar #Sync" : \
   1201 		 "=&r" (_lda_v), "=&r" (_pstate) : \
   1202 		"r" ((unsigned long)(loc)), "r" (_loc_hi), "r" (asi), "n" (ASI_DCACHE_TAG)); \
   1203 	} else { \
   1204 		__asm __volatile("wr %3,%%g0,%%asi; sllx %2,32,%0; " \
   1205 " or %0,%1,%0; ldda [%0]%%asi,%0" : "=&r" (_lda_v) : \
   1206 			"r" ((unsigned long)(loc)), "r" (_loc_hi), "r" (asi)); \
   1207 	} \
   1208 	_lda_v; \
   1209 })
   1210 #endif
   1211 
   1212 #ifdef __arch64__
   1213 /* native load 64-bit int from alternate address space w/64-bit compiler*/
   1214 #define	ldxa(loc, asi) ({ \
   1215 	register unsigned long _lda_v; \
   1216 	if (PHYS_ASI(asi)) { \
   1217 		__asm __volatile("wr %3,%%g0,%%asi; "\
   1218 " andn %2,0x1f,%0; stxa %%g0,[%0] %4; membar #Sync; " \
   1219 " ldxa [%2]%%asi,%0; andn %2,0x1f,%1; membar #Sync; " \
   1220 " stxa %%g0,[%1] %4; membar #Sync" : "=&r" (_lda_v), "=r" (loc) : \
   1221 		"r" ((unsigned long)(loc)), "r" (asi), "n" (ASI_DCACHE_TAG)); \
   1222 	} else { \
   1223 		__asm __volatile("wr %2,%%g0,%%asi; ldxa [%1]%%asi,%0" : "=r" (_lda_v) : \
   1224 		"r" ((unsigned long)(loc)), "r" (asi)); \
   1225 	} \
   1226 	_lda_v; \
   1227 })
   1228 #else
   1229 /* native load 64-bit int from alternate address space w/32-bit compiler*/
   1230 #define	ldxa(loc, asi) ({ \
   1231 	register unsigned long _ldxa_lo, _ldxa_hi, _loc_hi; \
   1232 	_loc_hi = (((u_int64_t)loc)>>32); \
   1233 	if (PHYS_ASI(asi)) { \
   1234 		__asm __volatile("wr %4,%%g0,%%asi; " \
   1235 " andn %2,0x1f,%0; rdpr %%pstate,%1; stxa %%g0,[%0] %5; " \
   1236 " sllx %3,32,%0; wrpr %1,8,%%pstate; or %0,%2,%0; membar #Sync; ldxa [%0]%%asi,%0; " \
   1237 " wrpr %1,0,%%pstate; andn %2,0x1f,%1; membar #Sync; stxa %%g0,[%1] %5; membar #Sync; " \
   1238 " srlx %0,32,%1; srl %0,0,%0" : \
   1239 		"=&r" (_ldxa_lo), "=&r" (_ldxa_hi) : \
   1240 		"r" ((unsigned long)(loc)), "r" (_loc_hi), \
   1241 		"r" (asi), "n" (ASI_DCACHE_TAG)); \
   1242 	} else { \
   1243 		__asm __volatile("wr %4,%%g0,%%asi; sllx %3,32,%0; " \
   1244 " or %0,%2,%0; ldxa [%0]%%asi,%0; srlx %0,32,%1; srl %0,0,%0;" : \
   1245 		"=&r" (_ldxa_lo), "=&r" (_ldxa_hi) : \
   1246 		"r" ((unsigned long)(loc)), "r" (_loc_hi), "r" (asi)); \
   1247 	} \
   1248 	((((int64_t)_ldxa_hi)<<32)|_ldxa_lo); \
   1249 })
   1250 #endif
   1251 
   1252 
   1253 /* store byte to alternate address space */
   1254 #ifdef __arch64__
   1255 #define	stba(loc, asi, value) ({ \
   1256 	if (PHYS_ASI(asi)) { \
   1257 		__asm __volatile("wr %3,%%g0,%%asi; stba %1,[%2]%%asi;" \
   1258 " andn %2,0x1f,%0; membar #Sync; stxa %%g0,[%0] %4; membar #Sync" : "=&r" (loc) : \
   1259 			"r" ((int)(value)), "r" ((unsigned long)(loc)), \
   1260 			"r" (asi), "n" (ASI_DCACHE_TAG)); \
   1261 	} else { \
   1262 		__asm __volatile("wr %2,%%g0,%%asi; stba %0,[%1]%%asi" : : \
   1263 		"r" ((int)(value)), "r" ((unsigned long)(loc)), "r" (asi)); \
   1264 	} \
   1265 })
   1266 #else
   1267 #define	stba(loc, asi, value) ({ \
   1268 	register int _loc_hi, _pstate; \
   1269 	_loc_hi = (((u_int64_t)loc)>>32); \
   1270 	if (PHYS_ASI(asi)) { \
   1271 		__asm __volatile("wr %5,%%g0,%%asi; sllx %4,32,%0; rdpr %%pstate,%1;" \
   1272 " or %3,%0,%0; wrpr %1,8,%%pstate; stba %2,[%0]%%asi; wrpr %1,0,%%pstate; " \
   1273 " andn %0,0x1f,%1;  membar #Sync; stxa %%g0,[%1] %6; membar #Sync" : \
   1274 		"=&r" (_loc_hi), "=&r" (_pstate) : \
   1275 		"r" ((int)(value)), "r" ((unsigned long)(loc)), \
   1276 		"r" (_loc_hi), "r" (asi), "n" (ASI_DCACHE_TAG)); \
   1277 	} else { \
   1278 		__asm __volatile("wr %4,%%g0,%%asi; sllx %3,32,%0; " \
   1279 " or %2,%0,%0; stba %1,[%0]%%asi" : "=&r" (_loc_hi) : \
   1280 		"r" ((int)(value)), "r" ((unsigned long)(loc)), \
   1281 		"r" (_loc_hi), "r" (asi)); \
   1282 	} \
   1283 })
   1284 #endif
   1285 
   1286 /* store half-word to alternate address space */
   1287 #ifdef __arch64__
   1288 #define	stha(loc, asi, value) ({ \
   1289 	if (PHYS_ASI(asi)) { \
   1290 		__asm __volatile("wr %3,%%g0,%%asi; stha %1,[%2]%%asi;" \
   1291 " andn %2,0x1f,%0; membar #Sync; stxa %%g0,[%0] %4; membar #Sync" : "=&r" (loc) : \
   1292 			"r" ((int)(value)), "r" ((unsigned long)(loc)), \
   1293 			"r" (asi), "n" (ASI_DCACHE_TAG)); \
   1294 	} else { \
   1295 	__asm __volatile("wr %2,%%g0,%%asi; stha %0,[%1]%%asi" : : \
   1296 	    "r" ((int)(value)), "r" ((unsigned long)(loc)), "r" (asi)); \
   1297 	} \
   1298 })
   1299 #else
   1300 #define	stha(loc, asi, value) ({ \
   1301 	register int _loc_hi, _pstate; \
   1302 	_loc_hi = (((u_int64_t)loc)>>32); \
   1303 	if (PHYS_ASI(asi)) { \
   1304 		__asm __volatile("wr %5,%%g0,%%asi; sllx %4,32,%0; rdpr %%pstate,%1;" \
   1305 " or %3,%0,%0; wrpr %1,8,%%pstate; stha %2,[%0]%%asi; wrpr %1,0,%%pstate; " \
   1306 " andn %0,0x1f,%1;  membar #Sync; stxa %%g0,[%1] %6; membar #Sync" : \
   1307 		"=&r" (_loc_hi), "=&r" (_pstate) : \
   1308 		"r" ((int)(value)), "r" ((unsigned long)(loc)), \
   1309 		"r" (_loc_hi), "r" (asi), "n" (ASI_DCACHE_TAG)); \
   1310 	} else { \
   1311 		__asm __volatile("wr %4,%%g0,%%asi; sllx %3,32,%0; " \
   1312 " or %2,%0,%0; stha %1,[%0]%%asi" : "=&r" (_loc_hi) : \
   1313 	    "r" ((int)(value)), "r" ((unsigned long)(loc)), \
   1314 		"r" (_loc_hi), "r" (asi)); \
   1315 	} \
   1316 })
   1317 #endif
   1318 
   1319 /* store int to alternate address space */
   1320 #ifdef __arch64__
   1321 #define	sta(loc, asi, value) ({ \
   1322 	if (PHYS_ASI(asi)) { \
   1323 		__asm __volatile("wr %3,%%g0,%%asi; sta %1,[%2]%%asi;" \
   1324 " andn %2,0x1f,%0; membar #Sync; stxa %%g0,[%0] %4; membar #Sync" : "=&r" (loc) : \
   1325 			"r" ((int)(value)), "r" ((unsigned long)(loc)), \
   1326 			"r" (asi), "n" (ASI_DCACHE_TAG)); \
   1327 	} else { \
   1328 	__asm __volatile("wr %2,%%g0,%%asi; sta %0,[%1]%%asi" : : \
   1329 	    "r" ((int)(value)), "r" ((unsigned long)(loc)), "r" (asi)); \
   1330 	} \
   1331 })
   1332 #else
   1333 #define	sta(loc, asi, value) ({ \
   1334 	register int _loc_hi, _pstate; \
   1335 	_loc_hi = (((u_int64_t)loc)>>32); \
   1336 	if (PHYS_ASI(asi)) { \
   1337 		__asm __volatile("wr %5,%%g0,%%asi; sllx %4,32,%0; rdpr %%pstate,%1;" \
   1338 " or %3,%0,%0; wrpr %1,8,%%pstate; sta %2,[%0]%%asi; wrpr %1,0,%%pstate; " \
   1339 " andn %0,0x1f,%1;  membar #Sync; stxa %%g0,[%1] %6; membar #Sync" : \
   1340 		"=&r" (_loc_hi), "=&r" (_pstate) : \
   1341 		"r" ((int)(value)), "r" ((unsigned long)(loc)), \
   1342 		"r" (_loc_hi), "r" (asi), "n" (ASI_DCACHE_TAG)); \
   1343 	} else { \
   1344 		__asm __volatile("wr %4,%%g0,%%asi; sllx %3,32,%0; " \
   1345 " or %2,%0,%0; sta %1,[%0]%%asi" : "=&r" (_loc_hi) : \
   1346 		"r" ((int)(value)), "r" ((unsigned long)(loc)), \
   1347 		"r" (_loc_hi), "r" (asi)); \
   1348 	} \
   1349 })
   1350 #endif
   1351 
   1352 /* store 64-bit int to alternate address space */
   1353 #ifdef __arch64__
   1354 #define	stda(loc, asi, value) ({ \
   1355 	if (PHYS_ASI(asi)) { \
   1356 		__asm __volatile("wr %3,%%g0,%%asi; stda %1,[%2]%%asi;" \
   1357 " andn %2,0x1f,%0; membar #Sync; stxa %%g0,[%0] %4; membar #Sync" : "=&r" (loc) : \
   1358 			"r" ((int)(value)), "r" ((unsigned long)(loc)), \
   1359 			"r" (asi), "n" (ASI_DCACHE_TAG)); \
   1360 	} else { \
   1361 	__asm __volatile("wr %2,%%g0,%%asi; stda %0,[%1]%%asi" : : \
   1362 	    "r" ((long long)(value)), "r" ((unsigned long)(loc)), "r" (asi)); \
   1363 	} \
   1364 })
   1365 #else
   1366 #define	stda(loc, asi, value) ({ \
   1367 	register int _loc_hi, _pstate; \
   1368 	_loc_hi = (((u_int64_t)loc)>>32); \
   1369 	if (PHYS_ASI(asi)) { \
   1370 	__asm __volatile("wr %5,%%g0,%%asi; sllx %4,32,%0; rdpr %%pstate,%1; " \
   1371 " or %3,%0,%0; wrpr %1,8,%%pstate; stda %2,[%0]%%asi; wrpr %1,0,%%pstate;" \
   1372 " andn %0,0x1f,%1;  membar #Sync; stxa %%g0,[%1] %6; membar #Sync" : \
   1373 		"=&r" (_loc_hi), "=&r" (_pstate) : \
   1374 		"r" ((long long)(value)), "r" ((unsigned long)(loc)), \
   1375 		"r" (_loc_hi), "r" (asi), "n" (ASI_DCACHE_TAG)); \
   1376 	} else { \
   1377 		__asm __volatile("wr %4,%%g0,%%asi; sllx %3,32,%0; " \
   1378 " or %2,%0,%0; stda %1,[%0]%%asi" : "=&r" (_loc_hi) : \
   1379 		"r" ((long long)(value)), "r" ((unsigned long)(loc)), \
   1380 		"r" (_loc_hi), "r" (asi)); \
   1381 	} \
   1382 })
   1383 #endif
   1384 
   1385 #ifdef __arch64__
   1386 /* native store 64-bit int to alternate address space w/64-bit compiler*/
   1387 #define	stxa(loc, asi, value) ({ \
   1388 	if (PHYS_ASI(asi)) { \
   1389 		__asm __volatile("wr %3,%%g0,%%asi; stxa %1,[%2]%%asi;" \
   1390 " andn %2,0x1f,%0; membar #Sync; stxa %%g0,[%0] %4; membar #Sync" : "=&r" (loc) : \
   1391 			"r" ((int)(value)), "r" ((unsigned long)(loc)), \
   1392 			"r" (asi), "n" (ASI_DCACHE_TAG)); \
   1393 	} else { \
   1394 	__asm __volatile("wr %2,%%g0,%%asi; stxa %0,[%1]%%asi" : : \
   1395 	    "r" ((unsigned long)(value)), "r" ((unsigned long)(loc)), "r" (asi)); \
   1396 })
   1397 #else
   1398 /* native store 64-bit int to alternate address space w/32-bit compiler*/
   1399 #define	stxa(loc, asi, value) ({ \
   1400 	int _stxa_lo, _stxa_hi, _loc_hi; \
   1401 	_stxa_lo = value; _stxa_hi = ((u_int64_t)value)>>32; \
   1402 	_loc_hi = (((u_int64_t)(u_long)loc)>>32); \
   1403 	if (PHYS_ASI(asi)) { \
   1404 		__asm __volatile("wr %7,%%g0,%%asi; sllx %4,32,%1; sllx %6,32,%0; " \
   1405 " or %1,%3,%1; rdpr %%pstate,%2; or %0,%5,%0; wrpr %2,8,%%pstate; " \
   1406 " stxa %1,[%0]%%asi; wrpr %2,0,%%pstate; "  \
   1407 " andn %0,0x1f,%1;  membar #Sync; stxa %%g0,[%1] %8; membar #Sync": \
   1408 		"=&r" (_loc_hi), "=&r" (_stxa_hi), "=&r" ((int)(_stxa_lo)): \
   1409 		"r" ((int)(_stxa_lo)), "r" ((int)(_stxa_hi)), \
   1410 		"r" ((unsigned long)(loc)), "r" (_loc_hi), \
   1411 		"r" (asi), "n" (ASI_DCACHE_TAG)); \
   1412 	} else { \
   1413 	__asm __volatile("wr %6,%%g0,%%asi; sllx %3,32,%1; sllx %5,32,%0; " \
   1414 " or %1,%2,%1; or %0,%4,%0; stxa %1,[%0]%%asi" : \
   1415 	    "=&r" (_loc_hi), "=&r" (_stxa_hi) : \
   1416 	    "r" ((int)(_stxa_lo)), "r" ((int)(_stxa_hi)), \
   1417 	    "r" ((unsigned long)(loc)), "r" (_loc_hi), "r" (asi)); \
   1418 	} \
   1419 })
   1420 #endif
   1421 
   1422 
   1423 #ifdef __arch64__
   1424 /* native store 64-bit int to alternate address space w/64-bit compiler*/
   1425 #define	casxa(loc, asi, value, ovalue) ({ \
   1426 	if (PHYS_ASI(asi)) { \
   1427 		__asm __volatile("wr %5,%%g0,%%asi; casxa [%4]%%asi,%3, %1;" \
   1428 " andn %4,0x1f,%0; membar #Sync; stxa %%g0,[%0] %5; membar #Sync" : \
   1429 			"=&r" (loc), "=&r" (value) : \
   1430 			"r" ((unsigned long)(value)),  "r" ((unsigned long)(ovalue)), \
   1431 			"r" ((unsigned long)(loc)), \
   1432 			"r" (asi), "n" (ASI_DCACHE_TAG)); \
   1433 	} else { \
   1434 	__asm __volatile("wr %4,%%g0,%%asi; casxa [%3]%%asi,%2,%1" : \
   1435 	    "=&r" (value) : \
   1436 	    "r" ((unsigned long)(value)), "r" ((unsigned long)(ovalue), \
   1437 	    "r" ((unsigned long)(loc)), "r" (asi)); \
   1438 })
   1439 #else
   1440 /* native store 64-bit int to alternate address space w/32-bit compiler*/
   1441 #define	casxa(loc, asi, value, ovalue) ({ \
   1442 	int _casxa_lo, _casxa_hi, _oval_lo, _oval_hi, _loc_hi; \
   1443 	_casxa_lo = value; _casxa_hi = ((u_int64_t)value)>>32; \
   1444 	_oval_lo = ovalue; _oval_hi = ((u_int64_t)ovalue)>>32; \
   1445 	_loc_hi = (((u_int64_t)(u_long)loc)>>32); \
   1446 	if (PHYS_ASI(asi)) { \
   1447 		__asm __volatile("wr %9,%%g0,%%asi; sllx %4,32,%1; sllx %8,32,%0; " \
   1448 " or %1,%3,%1; rdpr %%pstate,%3; or %0,%5,%0; wrpr %3,8,%%pstate; " \
   1449 " casxa %1,[%0]%%asi; wrpr %3,0,%%pstate; "  \
   1450 " andn %0,0x1f,%1;  membar #Sync; stxa %%g0,[%1] %8; membar #Sync": \
   1451 		"=&r" (_casxa_hi), "=&r" ((int)(_casxa_lo)): \
   1452 		"r" ((int)(_casxa_lo)), "r" ((int)(_casxa_hi)), \
   1453 		"r" ((int)(_oval_lo)), "r" ((int)(_oval_hi)), \
   1454 		"r" ((unsigned long)(loc)), "r" (_loc_hi), \
   1455 		"r" (asi), "n" (ASI_DCACHE_TAG) : \
   1456 		"r" (loc), "r", (oval_lo) \
   1457 	} else { \
   1458 	__asm __volatile("wr %6,%%g0,%%asi; sllx %3,32,%1; sllx %5,32,%0; " \
   1459 " or %1,%2,%1; or %0,%4,%0; stxa %1,[%0]%%asi" : \
   1460 	    "=&r" (_loc_hi), "=&r" (_stxa_hi) : \
   1461 	    "r" ((int)(_stxa_lo)), "r" ((int)(_stxa_hi)), \
   1462 	    "r" ((unsigned long)(loc)), "r" (_loc_hi), "r" (asi)); \
   1463 	} \
   1464 })
   1465 #endif
   1466 #endif
   1467 
   1468 
   1469 /* flush address from data cache */
   1470 #define flush(loc) ({ \
   1471 	__asm __volatile("flush %0" : : \
   1472 	     "r" ((unsigned long)(loc))); \
   1473 })
   1474 
   1475 /* Flush a D$ line */
   1476 #if 0
   1477 #define flushline(loc) ({ \
   1478 	stxa(((paddr_t)loc)&(~0x1f), (ASI_DCACHE_TAG), 0); \
   1479         membar_sync(); \
   1480 })
   1481 #else
   1482 #define flushline(loc)
   1483 #endif
   1484 
   1485 /* The following two enable or disable the dcache in the LSU control register */
   1486 #define dcenable() ({ \
   1487 	int res; \
   1488 	__asm __volatile("ldxa [%%g0] %1,%0; or %0,%2,%0; stxa %0,[%%g0] %1; membar #Sync" \
   1489 		: "r" (res) : "n" (ASI_MCCR), "n" (MCCR_DCACHE_EN)); \
   1490 })
   1491 #define dcdisable() ({ \
   1492 	int res; \
   1493 	__asm __volatile("ldxa [%%g0] %1,%0; andn %0,%2,%0; stxa %0,[%%g0] %1; membar #Sync" \
   1494 		: "r" (res) : "n" (ASI_MCCR), "n" (MCCR_DCACHE_EN)); \
   1495 })
   1496 
   1497 /*
   1498  * SPARC V9 memory barrier instructions.
   1499  */
   1500 /* Make all stores complete before next store */
   1501 #define membar_storestore() __asm __volatile("membar #StoreStore" : :)
   1502 /* Make all loads complete before next store */
   1503 #define membar_loadstore() __asm __volatile("membar #LoadStore" : :)
   1504 /* Make all stores complete before next load */
   1505 #define membar_storeload() __asm __volatile("membar #StoreLoad" : :)
   1506 /* Make all loads complete before next load */
   1507 #define membar_loadload() __asm __volatile("membar #LoadLoad" : :)
   1508 /* Complete all outstanding memory operations and exceptions */
   1509 #define membar_sync() __asm __volatile("membar #Sync" : :)
   1510 /* Complete all outstanding memory operations */
   1511 #define membar_memissue() __asm __volatile("membar #MemIssue" : :)
   1512 /* Complete all outstanding stores before any new loads */
   1513 #define membar_lookaside() __asm __volatile("membar #Lookaside" : :)
   1514 
   1515 #ifdef __arch64__
   1516 /* read 64-bit %tick register */
   1517 #define	tick() ({ \
   1518 	register u_long _tick_tmp; \
   1519 	__asm __volatile("rdpr %%tick, %0" : "=r" (_tick_tmp) :); \
   1520 	_tick_tmp; \
   1521 })
   1522 #else
   1523 /* read 64-bit %tick register on 32-bit system */
   1524 #define	tick() ({ \
   1525 	register u_int _tick_hi = 0, _tick_lo = 0; \
   1526 	__asm __volatile("rdpr %%tick, %0; srl %0,0,%1; srlx %0,32,%0 " \
   1527 		: "=r" (_tick_hi), "=r" (_tick_lo) : ); \
   1528 	(((u_int64_t)_tick_hi)<<32)|((u_int64_t)_tick_lo); \
   1529 })
   1530 #endif
   1531 
   1532 extern void next_tick __P((long));
   1533 #endif
   1534