/**************************************************************************1* *2* Copyright (C) 1995, Silicon Graphics, Inc. *3* *4* These coded instructions, statements, and computer programs contain *5* unpublished proprietary information of Silicon Graphics, Inc., and *6* are protected by Federal copyright law. They may not be disclosed *7* to third parties or copied or duplicated in any form, in whole or *8* in part, without the prior written consent of Silicon Graphics, Inc. *9* *10**************************************************************************/1112/**************************************************************************13*14* $Revision: 1.13 $15* $Date: 1997/02/11 08:15:34 $16* $Source: /disk6/Master/cvsmdev2/PR/include/R4300.h,v $17*18**************************************************************************/1920#ifndef __R4300_H__21#define __R4300_H__2223#include <PR/ultratypes.h>2425/*26* Segment base addresses and sizes27*/28#define KUBASE 029#define KUSIZE 0x8000000030#define K0BASE 0x8000000031#define K0SIZE 0x2000000032#define K1BASE 0xA000000033#define K1SIZE 0x2000000034#define K2BASE 0xC000000035#define K2SIZE 0x200000003637/*38* Exception vectors39*/40#define SIZE_EXCVEC 0x80 /* Size of an exc. vec */41#define UT_VEC K0BASE /* utlbmiss vector */42#define R_VEC (K1BASE+0x1fc00000) /* reset vector */43#define XUT_VEC (K0BASE+0x80) /* extended address tlbmiss */44#define ECC_VEC (K0BASE+0x100) /* Ecc exception vector */45#define E_VEC (K0BASE+0x180) /* Gen. exception vector */4647/*48* Address conversion macros49*/50#ifdef _LANGUAGE_ASSEMBLY5152#define K0_TO_K1(x) ((x)|0xA0000000) /* kseg0 to kseg1 */53#define K1_TO_K0(x) ((x)&0x9FFFFFFF) /* kseg1 to kseg0 */54#define K0_TO_PHYS(x) ((x)&0x1FFFFFFF) /* kseg0 to physical */55#define K1_TO_PHYS(x) ((x)&0x1FFFFFFF) /* kseg1 to physical */56#define KDM_TO_PHYS(x) ((x)&0x1FFFFFFF) /* direct mapped to physical */57#define PHYS_TO_K0(x) ((x)|0x80000000) /* physical to kseg0 */58#define PHYS_TO_K1(x) ((x)|0xA0000000) /* physical to kseg1 */5960#else /* _LANGUAGE_C */6162#define K0_TO_K1(x) ((u32)(x)|0xA0000000) /* kseg0 to kseg1 */63#define K1_TO_K0(x) ((u32)(x)&0x9FFFFFFF) /* kseg1 to kseg0 */64#define K0_TO_PHYS(x) ((u32)(x)&0x1FFFFFFF) /* kseg0 to physical */65#define K1_TO_PHYS(x) ((u32)(x)&0x1FFFFFFF) /* kseg1 to physical */66#define KDM_TO_PHYS(x) ((u32)(x)&0x1FFFFFFF) /* direct mapped to physical */67#define PHYS_TO_K0(x) ((u32)(x)|0x80000000) /* physical to kseg0 */68#define PHYS_TO_K1(x) ((u32)(x)|0xA0000000) /* physical to kseg1 */6970#endif /* _LANGUAGE_ASSEMBLY */7172/*73* Address predicates74*/75#define IS_KSEG0(x) ((u32)(x) >= K0BASE && (u32)(x) < K1BASE)76#define IS_KSEG1(x) ((u32)(x) >= K1BASE && (u32)(x) < K2BASE)77#define IS_KSEGDM(x) ((u32)(x) >= K0BASE && (u32)(x) < K2BASE)78#define IS_KSEG2(x) ((u32)(x) >= K2BASE && (u32)(x) < KPTE_SHDUBASE)79#define IS_KPTESEG(x) ((u32)(x) >= KPTE_SHDUBASE)80#define IS_KUSEG(x) ((u32)(x) < K0BASE)8182/*83* TLB size constants84*/8586#define NTLBENTRIES 31 /* entry 31 is reserved by rdb */8788#define TLBHI_VPN2MASK 0xffffe00089#define TLBHI_VPN2SHIFT 1390#define TLBHI_PIDMASK 0xff91#define TLBHI_PIDSHIFT 092#define TLBHI_NPID 255 /* 255 to fit in 8 bits */9394#define TLBLO_PFNMASK 0x3fffffc095#define TLBLO_PFNSHIFT 696#define TLBLO_CACHMASK 0x38 /* cache coherency algorithm */97#define TLBLO_CACHSHIFT 398#define TLBLO_UNCACHED 0x10 /* not cached */99#define TLBLO_NONCOHRNT 0x18 /* Cacheable non-coherent */100#define TLBLO_EXLWR 0x28 /* Exclusive write */101#define TLBLO_D 0x4 /* writeable */102#define TLBLO_V 0x2 /* valid bit */103#define TLBLO_G 0x1 /* global access bit */104105#define TLBINX_PROBE 0x80000000106#define TLBINX_INXMASK 0x3f107#define TLBINX_INXSHIFT 0108109#define TLBRAND_RANDMASK 0x3f110#define TLBRAND_RANDSHIFT 0111112#define TLBWIRED_WIREDMASK 0x3f113114#define TLBCTXT_BASEMASK 0xff800000115#define TLBCTXT_BASESHIFT 23116#define TLBCTXT_BASEBITS 9117118#define TLBCTXT_VPNMASK 0x7ffff0119#define TLBCTXT_VPNSHIFT 4120121#define TLBPGMASK_4K 0x0122#define TLBPGMASK_16K 0x6000123#define TLBPGMASK_64K 0x1e000124125/*126* Status register127*/128#define SR_CUMASK 0xf0000000 /* coproc usable bits */129130#define SR_CU3 0x80000000 /* Coprocessor 3 usable */131#define SR_CU2 0x40000000 /* Coprocessor 2 usable */132#define SR_CU1 0x20000000 /* Coprocessor 1 usable */133#define SR_CU0 0x10000000 /* Coprocessor 0 usable */134#define SR_RP 0x08000000 /* Reduced power (quarter speed) */135#define SR_FR 0x04000000 /* MIPS III FP register mode */136#define SR_RE 0x02000000 /* Reverse endian */137#define SR_ITS 0x01000000 /* Instruction trace support */138#define SR_BEV 0x00400000 /* Use boot exception vectors */139#define SR_TS 0x00200000 /* TLB shutdown */140#define SR_SR 0x00100000 /* Soft reset occured */141#define SR_CH 0x00040000 /* Cache hit for last 'cache' op */142#define SR_CE 0x00020000 /* Create ECC */143#define SR_DE 0x00010000 /* ECC of parity does not cause error */144145/*146* Interrupt enable bits147* (NOTE: bits set to 1 enable the corresponding level interrupt)148*/149#define SR_IMASK 0x0000ff00 /* Interrupt mask */150#define SR_IMASK8 0x00000000 /* mask level 8 */151#define SR_IMASK7 0x00008000 /* mask level 7 */152#define SR_IMASK6 0x0000c000 /* mask level 6 */153#define SR_IMASK5 0x0000e000 /* mask level 5 */154#define SR_IMASK4 0x0000f000 /* mask level 4 */155#define SR_IMASK3 0x0000f800 /* mask level 3 */156#define SR_IMASK2 0x0000fc00 /* mask level 2 */157#define SR_IMASK1 0x0000fe00 /* mask level 1 */158#define SR_IMASK0 0x0000ff00 /* mask level 0 */159160#define SR_IBIT8 0x00008000 /* bit level 8 */161#define SR_IBIT7 0x00004000 /* bit level 7 */162#define SR_IBIT6 0x00002000 /* bit level 6 */163#define SR_IBIT5 0x00001000 /* bit level 5 */164#define SR_IBIT4 0x00000800 /* bit level 4 */165#define SR_IBIT3 0x00000400 /* bit level 3 */166#define SR_IBIT2 0x00000200 /* bit level 2 */167#define SR_IBIT1 0x00000100 /* bit level 1 */168169#define SR_IMASKSHIFT 8170171#define SR_KX 0x00000080 /* extended-addr TLB vec in kernel */172#define SR_SX 0x00000040 /* xtended-addr TLB vec supervisor */173#define SR_UX 0x00000020 /* xtended-addr TLB vec in user mode */174#define SR_KSU_MASK 0x00000018 /* mode mask */175#define SR_KSU_USR 0x00000010 /* user mode */176#define SR_KSU_SUP 0x00000008 /* supervisor mode */177#define SR_KSU_KER 0x00000000 /* kernel mode */178#define SR_ERL 0x00000004 /* Error level, 1=>cache error */179#define SR_EXL 0x00000002 /* Exception level, 1=>exception */180#define SR_IE 0x00000001 /* interrupt enable, 1=>enable */181182/*183* Cause Register184*/185#define CAUSE_BD 0x80000000 /* Branch delay slot */186#define CAUSE_CEMASK 0x30000000 /* coprocessor error */187#define CAUSE_CESHIFT 28188189/* Interrupt pending bits */190#define CAUSE_IP8 0x00008000 /* External level 8 pending - COMPARE */191#define CAUSE_IP7 0x00004000 /* External level 7 pending - INT4 */192#define CAUSE_IP6 0x00002000 /* External level 6 pending - INT3 */193#define CAUSE_IP5 0x00001000 /* External level 5 pending - INT2 */194#define CAUSE_IP4 0x00000800 /* External level 4 pending - INT1 */195#define CAUSE_IP3 0x00000400 /* External level 3 pending - INT0 */196#define CAUSE_SW2 0x00000200 /* Software level 2 pending */197#define CAUSE_SW1 0x00000100 /* Software level 1 pending */198199#define CAUSE_IPMASK 0x0000FF00 /* Pending interrupt mask */200#define CAUSE_IPSHIFT 8201202#define CAUSE_EXCMASK 0x0000007C /* Cause code bits */203204#define CAUSE_EXCSHIFT 2205206/* Cause register exception codes */207208#define EXC_CODE(x) ((x)<<2)209210/* Hardware exception codes */211#define EXC_INT EXC_CODE(0) /* interrupt */212#define EXC_MOD EXC_CODE(1) /* TLB mod */213#define EXC_RMISS EXC_CODE(2) /* Read TLB Miss */214#define EXC_WMISS EXC_CODE(3) /* Write TLB Miss */215#define EXC_RADE EXC_CODE(4) /* Read Address Error */216#define EXC_WADE EXC_CODE(5) /* Write Address Error */217#define EXC_IBE EXC_CODE(6) /* Instruction Bus Error */218#define EXC_DBE EXC_CODE(7) /* Data Bus Error */219#define EXC_SYSCALL EXC_CODE(8) /* SYSCALL */220#define EXC_BREAK EXC_CODE(9) /* BREAKpoint */221#define EXC_II EXC_CODE(10) /* Illegal Instruction */222#define EXC_CPU EXC_CODE(11) /* CoProcessor Unusable */223#define EXC_OV EXC_CODE(12) /* OVerflow */224#define EXC_TRAP EXC_CODE(13) /* Trap exception */225#define EXC_VCEI EXC_CODE(14) /* Virt. Coherency on Inst. fetch */226#define EXC_FPE EXC_CODE(15) /* Floating Point Exception */227#define EXC_WATCH EXC_CODE(23) /* Watchpoint reference */228#define EXC_VCED EXC_CODE(31) /* Virt. Coherency on data read */229230/* C0_PRID Defines */231#define C0_IMPMASK 0xff00232#define C0_IMPSHIFT 8233#define C0_REVMASK 0xff234#define C0_MAJREVMASK 0xf0235#define C0_MAJREVSHIFT 4236#define C0_MINREVMASK 0xf237238/*239* Coprocessor 0 operations240*/241#define C0_READI 0x1 /* read ITLB entry addressed by C0_INDEX */242#define C0_WRITEI 0x2 /* write ITLB entry addressed by C0_INDEX */243#define C0_WRITER 0x6 /* write ITLB entry addressed by C0_RAND */244#define C0_PROBE 0x8 /* probe for ITLB entry addressed by TLBHI */245#define C0_RFE 0x10 /* restore for exception */246247/*248* 'cache' instruction definitions249*/250251/* Target cache */252#define CACH_PI 0x0 /* specifies primary inst. cache */253#define CACH_PD 0x1 /* primary data cache */254#define CACH_SI 0x2 /* secondary instruction cache */255#define CACH_SD 0x3 /* secondary data cache */256257/* Cache operations */258#define C_IINV 0x0 /* index invalidate (inst, 2nd inst) */259#define C_IWBINV 0x0 /* index writeback inval (d, sd) */260#define C_ILT 0x4 /* index load tag (all) */261#define C_IST 0x8 /* index store tag (all) */262#define C_CDX 0xc /* create dirty exclusive (d, sd) */263#define C_HINV 0x10 /* hit invalidate (all) */264#define C_HWBINV 0x14 /* hit writeback inv. (d, sd) */265#define C_FILL 0x14 /* fill (i) */266#define C_HWB 0x18 /* hit writeback (i, d, sd) */267#define C_HSV 0x1c /* hit set virt. (si, sd) */268269/*270* Cache size definitions271*/272#define ICACHE_SIZE 0x4000 /* 16K */273#define ICACHE_LINESIZE 32 /* 8 words */274#define ICACHE_LINEMASK (ICACHE_LINESIZE-1)275276#define DCACHE_SIZE 0x2000 /* 8K */277#define DCACHE_LINESIZE 16 /* 4 words */278#define DCACHE_LINEMASK (DCACHE_LINESIZE-1)279280/*281* C0_CONFIG register definitions282*/283#define CONFIG_CM 0x80000000 /* 1 == Master-Checker enabled */284#define CONFIG_EC 0x70000000 /* System Clock ratio */285#define CONFIG_EC_1_1 0x6 /* System Clock ratio 1 :1 */286#define CONFIG_EC_3_2 0x7 /* System Clock ratio 1.5 :1 */287#define CONFIG_EC_2_1 0x0 /* System Clock ratio 2 :1 */288#define CONFIG_EC_3_1 0x1 /* System Clock ratio 3 :1 */289#define CONFIG_EP 0x0f000000 /* Transmit Data Pattern */290#define CONFIG_SB 0x00c00000 /* Secondary cache block size */291292#define CONFIG_SS 0x00200000 /* Split scache: 0 == I&D combined */293#define CONFIG_SW 0x00100000 /* scache port: 0==128, 1==64 */294#define CONFIG_EW 0x000c0000 /* System Port width: 0==64, 1==32 */295#define CONFIG_SC 0x00020000 /* 0 -> 2nd cache present */296#define CONFIG_SM 0x00010000 /* 0 -> Dirty Shared Coherency enabled*/297#define CONFIG_BE 0x00008000 /* Endian-ness: 1 --> BE */298#define CONFIG_EM 0x00004000 /* 1 -> ECC mode, 0 -> parity */299#define CONFIG_EB 0x00002000 /* Block order:1->sequent,0->subblock */300301#define CONFIG_IC 0x00000e00 /* Primary Icache size */302#define CONFIG_DC 0x000001c0 /* Primary Dcache size */303#define CONFIG_IB 0x00000020 /* Icache block size */304#define CONFIG_DB 0x00000010 /* Dcache block size */305#define CONFIG_CU 0x00000008 /* Update on Store-conditional */306#define CONFIG_K0 0x00000007 /* K0SEG Coherency algorithm */307308#define CONFIG_UNCACHED 0x00000002 /* K0 is uncached */309#define CONFIG_NONCOHRNT 0x00000003310#define CONFIG_COHRNT_EXLWR 0x00000005311#define CONFIG_SB_SHFT 22 /* shift SB to bit position 0 */312#define CONFIG_IC_SHFT 9 /* shift IC to bit position 0 */313#define CONFIG_DC_SHFT 6 /* shift DC to bit position 0 */314#define CONFIG_BE_SHFT 15 /* shift BE to bit position 0 */315316/*317* C0_TAGLO definitions for setting/getting cache states and physaddr bits318*/319#define SADDRMASK 0xFFFFE000 /* 31..13 -> scache paddr bits 35..17 */320#define SVINDEXMASK 0x00000380 /* 9..7: prim virt index bits 14..12 */321#define SSTATEMASK 0x00001c00 /* bits 12..10 hold scache line state */322#define SINVALID 0x00000000 /* invalid --> 000 == state 0 */323#define SCLEANEXCL 0x00001000 /* clean exclusive --> 100 == state 4 */324#define SDIRTYEXCL 0x00001400 /* dirty exclusive --> 101 == state 5 */325#define SECC_MASK 0x0000007f /* low 7 bits are ecc for the tag */326#define SADDR_SHIFT 4 /* shift STagLo (31..13) to 35..17 */327328#define PADDRMASK 0xFFFFFF00 /* PTagLo31..8->prim paddr bits35..12 */329#define PADDR_SHIFT 4 /* roll bits 35..12 down to 31..8 */330#define PSTATEMASK 0x00C0 /* bits 7..6 hold primary line state */331#define PINVALID 0x0000 /* invalid --> 000 == state 0 */332#define PCLEANEXCL 0x0080 /* clean exclusive --> 10 == state 2 */333#define PDIRTYEXCL 0x00C0 /* dirty exclusive --> 11 == state 3 */334#define PPARITY_MASK 0x0001 /* low bit is parity bit (even). */335336/*337* C0_CACHE_ERR definitions.338*/339#define CACHERR_ER 0x80000000 /* 0: inst ref, 1: data ref */340#define CACHERR_EC 0x40000000 /* 0: primary, 1: secondary */341#define CACHERR_ED 0x20000000 /* 1: data error */342#define CACHERR_ET 0x10000000 /* 1: tag error */343#define CACHERR_ES 0x08000000 /* 1: external ref, e.g. snoop*/344#define CACHERR_EE 0x04000000 /* error on SysAD bus */345#define CACHERR_EB 0x02000000 /* complicated, see spec. */346#define CACHERR_EI 0x01000000 /* complicated, see spec. */347#define CACHERR_SIDX_MASK 0x003ffff8 /* secondary cache index */348#define CACHERR_PIDX_MASK 0x00000007 /* primary cache index */349#define CACHERR_PIDX_SHIFT 12 /* bits 2..0 are paddr14..12 */350351/* R4000 family supports hardware watchpoints:352* C0_WATCHLO:353* bits 31..3 are bits 31..3 of physaddr to watch354* bit 2: reserved; must be written as 0.355* bit 1: when set causes a watchpoint trap on load accesses to paddr.356* bit 0: when set traps on stores to paddr;357* C0_WATCHHI358* bits 31..4 are reserved and must be written as zeros.359* bits 3..0 are bits 35..32 of the physaddr to watch360*/361#define WATCHLO_WTRAP 0x00000001362#define WATCHLO_RTRAP 0x00000002363#define WATCHLO_ADDRMASK 0xfffffff8364#define WATCHLO_VALIDMASK 0xfffffffb365#define WATCHHI_VALIDMASK 0x0000000f366367/*368* Coprocessor 0 registers369*/370#ifdef _LANGUAGE_ASSEMBLY371#define C0_INX $0372#define C0_RAND $1373#define C0_ENTRYLO0 $2374#define C0_ENTRYLO1 $3375#define C0_CONTEXT $4376#define C0_PAGEMASK $5 /* page mask */377#define C0_WIRED $6 /* # wired entries in tlb */378#define C0_BADVADDR $8379#define C0_COUNT $9 /* free-running counter */380#define C0_ENTRYHI $10381#define C0_SR $12382#define C0_CAUSE $13383#define C0_EPC $14384#define C0_PRID $15 /* revision identifier */385#define C0_COMPARE $11 /* counter comparison reg. */386#define C0_CONFIG $16 /* hardware configuration */387#define C0_LLADDR $17 /* load linked address */388#define C0_WATCHLO $18 /* watchpoint */389#define C0_WATCHHI $19 /* watchpoint */390#define C0_ECC $26 /* S-cache ECC and primary parity */391#define C0_CACHE_ERR $27 /* cache error status */392#define C0_TAGLO $28 /* cache operations */393#define C0_TAGHI $29 /* cache operations */394#define C0_ERROR_EPC $30 /* ECC error prg. counter */395396# else /* ! _LANGUAGE_ASSEMBLY */397398#define C0_INX 0399#define C0_RAND 1400#define C0_ENTRYLO0 2401#define C0_ENTRYLO1 3402#define C0_CONTEXT 4403#define C0_PAGEMASK 5 /* page mask */404#define C0_WIRED 6 /* # wired entries in tlb */405#define C0_BADVADDR 8406#define C0_COUNT 9 /* free-running counter */407#define C0_ENTRYHI 10408#define C0_SR 12409#define C0_CAUSE 13410#define C0_EPC 14411#define C0_PRID 15 /* revision identifier */412#define C0_COMPARE 11 /* counter comparison reg. */413#define C0_CONFIG 16 /* hardware configuration */414#define C0_LLADDR 17 /* load linked address */415#define C0_WATCHLO 18 /* watchpoint */416#define C0_WATCHHI 19 /* watchpoint */417#define C0_ECC 26 /* S-cache ECC and primary parity */418#define C0_CACHE_ERR 27 /* cache error status */419#define C0_TAGLO 28 /* cache operations */420#define C0_TAGHI 29 /* cache operations */421#define C0_ERROR_EPC 30 /* ECC error prg. counter */422423#endif /* _LANGUAGE_ASSEMBLY */424425/*426* floating-point status register427*/428#define FPCSR_FS 0x01000000 /* flush denorm to zero */429#define FPCSR_C 0x00800000 /* condition bit */430#define FPCSR_CE 0x00020000 /* cause: unimplemented operation */431#define FPCSR_CV 0x00010000 /* cause: invalid operation */432#define FPCSR_CZ 0x00008000 /* cause: division by zero */433#define FPCSR_CO 0x00004000 /* cause: overflow */434#define FPCSR_CU 0x00002000 /* cause: underflow */435#define FPCSR_CI 0x00001000 /* cause: inexact operation */436#define FPCSR_EV 0x00000800 /* enable: invalid operation */437#define FPCSR_EZ 0x00000400 /* enable: division by zero */438#define FPCSR_EO 0x00000200 /* enable: overflow */439#define FPCSR_EU 0x00000100 /* enable: underflow */440#define FPCSR_EI 0x00000080 /* enable: inexact operation */441#define FPCSR_FV 0x00000040 /* flag: invalid operation */442#define FPCSR_FZ 0x00000020 /* flag: division by zero */443#define FPCSR_FO 0x00000010 /* flag: overflow */444#define FPCSR_FU 0x00000008 /* flag: underflow */445#define FPCSR_FI 0x00000004 /* flag: inexact operation */446#define FPCSR_RM_MASK 0x00000003 /* rounding mode mask */447#define FPCSR_RM_RN 0x00000000 /* round to nearest */448#define FPCSR_RM_RZ 0x00000001 /* round to zero */449#define FPCSR_RM_RP 0x00000002 /* round to positive infinity */450#define FPCSR_RM_RM 0x00000003 /* round to negative infinity */451452#endif /* __R4300_H */453454455