Home | History | Annotate | Line # | Download | only in include
locore.h revision 1.48
      1 /* $NetBSD: locore.h,v 1.48 2000/10/05 01:06:06 cgd Exp $ */
      2 
      3 /*
      4  * Copyright 1996 The Board of Trustees of The Leland Stanford
      5  * Junior University. All Rights Reserved.
      6  *
      7  * Permission to use, copy, modify, and distribute this
      8  * software and its documentation for any purpose and without
      9  * fee is hereby granted, provided that the above copyright
     10  * notice appear in all copies.  Stanford University
     11  * makes no representations about the suitability of this
     12  * software for any purpose.  It is provided "as is" without
     13  * express or implied warranty.
     14  */
     15 
     16 /*
     17  * Jump table for MIPS cpu locore functions that are implemented
     18  * differently on different generations, or instruction-level
     19  * archtecture (ISA) level, the Mips family.
     20  * The following functions must be provided for each mips ISA level:
     21  *
     22  *
     23  *	MachFlushCache
     24  *	MachFlushDCache
     25  *	MachFlushICache
     26  *	wbflush
     27  *	proc_trampoline()
     28  *	cpu_switch_resume()
     29  *
     30  * We currently provide support for MIPS I and MIPS III.
     31  */
     32 
     33 #ifndef _MIPS_LOCORE_H
     34 #define  _MIPS_LOCORE_H
     35 
     36 #ifndef _LKM
     37 #include "opt_cputype.h"
     38 #include "opt_mips_cache.h"
     39 #endif
     40 
     41 struct tlb;
     42 
     43 /*
     44  * locore service routine for exception vectors. Used outside locore
     45  * only to print them by name in stack tracebacks
     46  */
     47 
     48 u_int32_t mips_cp0_cause_read(void);
     49 void	mips_cp0_cause_write(u_int32_t);
     50 u_int32_t mips_cp0_status_read(void);
     51 void	mips_cp0_status_write(u_int32_t);
     52 
     53 int	mips1_icsize(void);
     54 int	mips1_dcsize(void);
     55 void	mips1_ConfigCache(void);	/* XXX TX3900 XXX */
     56 void	mips1_FlushCache(void);
     57 void	mips1_FlushDCache(vaddr_t addr, vsize_t len);
     58 void	mips1_FlushICache(vaddr_t addr, vsize_t len);
     59 
     60 void	mips1_SetPID(int pid);
     61 void	mips1_TBIA(int);
     62 void	mips1_TBIAP(int);
     63 void	mips1_TBIS(vaddr_t);
     64 int	mips1_TLBUpdate(u_int, u_int);
     65 void	mips1_wbflush(void);
     66 void	mips1_proc_trampoline(void);
     67 void	mips1_cpu_switch_resume(void);
     68 
     69 void	mips3_ConfigCache(int);
     70 void	mips3_FlushCache(void);
     71 void	mips3_FlushDCache(vaddr_t addr, vaddr_t len);
     72 void	mips3_FlushICache(vaddr_t addr, vaddr_t len);
     73 void	mips3_HitFlushDCache(vaddr_t, int);
     74 
     75 void	mips3_SetPID(int pid);
     76 void	mips3_TBIA(int);
     77 void	mips3_TBIAP(int);
     78 void	mips3_TBIS(vaddr_t);
     79 int	mips3_TLBUpdate(u_int, u_int);
     80 void	mips3_TLBRead(int, struct tlb *);
     81 void	mips3_SetWIRED(int);
     82 void	mips3_wbflush(void);
     83 void	mips3_proc_trampoline(void);
     84 void	mips3_cpu_switch_resume(void);
     85 
     86 void	mips3_FlushCache_2way(void);
     87 void	mips3_FlushDCache_2way(vaddr_t addr, vaddr_t len);
     88 void	mips3_HitFlushDCache_2way(vaddr_t, int);
     89 void	mips3_FlushICache_2way(vaddr_t addr, vaddr_t len);
     90 
     91 u_int32_t mips3_read_config(void);
     92 u_int32_t mips3_cycle_count(void);
     93 u_int32_t mips3_write_count(u_int32_t);
     94 u_int32_t mips3_read_compare(void);
     95 void	mips3_write_config(u_int32_t);
     96 void	mips3_write_compare(u_int32_t);
     97 
     98 u_int64_t mips3_ld(u_int64_t *);
     99 void	mips3_sd(u_int64_t *, u_int64_t);
    100 
    101 /*
    102  *  A vector with an entry for each mips-ISA-level dependent
    103  * locore function, and macros which jump through it.
    104  * XXX the macro names are chosen to be compatible with the old
    105  * Sprite  coding-convention names used in 4.4bsd/pmax.
    106  */
    107 typedef struct  {
    108 	void (*flushCache)(void);
    109 	void (*flushDCache)(vaddr_t addr, vsize_t len);
    110 	void (*flushICache)(vaddr_t addr, vsize_t len);
    111 	void (*setTLBpid)(int pid);
    112 	void (*TBIAP)(int);
    113 	void (*TBIS)(vaddr_t);
    114 	int  (*tlbUpdate)(u_int highreg, u_int lowreg);
    115 	void (*wbflush)(void);
    116 } mips_locore_jumpvec_t;
    117 
    118 /* Override writebuffer-drain method. */
    119 void	mips_set_wbflush(void (*)(void));
    120 
    121 
    122 /* stacktrace() -- print a stack backtrace to the console */
    123 void	stacktrace(void);
    124 /* logstacktrace() -- log a stack traceback to msgbuf */
    125 void	logstacktrace(void);
    126 
    127 /*
    128  * The "active" locore-fuction vector, and
    129 
    130  */
    131 extern mips_locore_jumpvec_t mips_locore_jumpvec;
    132 extern mips_locore_jumpvec_t r2000_locore_vec;
    133 extern mips_locore_jumpvec_t r4000_locore_vec;
    134 extern long *mips_locoresw[];
    135 
    136 #if defined(MIPS3) && !defined (MIPS1)
    137 #if	defined(MIPS3_5200)
    138 #define MachFlushCache		mips3_FlushCache_2way
    139 #define MachFlushDCache		mips3_FlushDCache_2way
    140 #define MachHitFlushDCache	mips3_HitFlushDCache_2way
    141 #define MachFlushICache		mips3_FlushICache_2way
    142 #else
    143 #define MachFlushCache		mips3_FlushCache
    144 #if	defined(MIPS3_L2CACHE_ABSENT) && defined(MIPS3_4100)
    145 #define MachFlushDCache         mips3_FlushDCache		/* VR4100 */
    146 #elif	!defined(MIPS3_L2CACHE_ABSENT) && defined(MIPS3_L2CACHE_PRESENT)
    147 #define MachFlushDCache		mips3_FlushDCache
    148 #else
    149 #define MachFlushDCache		(*(mips_locore_jumpvec.flushDCache))
    150 #endif
    151 #define MachHitFlushDCache	mips3_HitFlushDCache
    152 #define MachFlushICache		mips3_FlushICache
    153 #endif
    154 #define MachSetPID		mips3_SetPID
    155 #define MIPS_TBIAP()		mips3_TBIAP(mips_num_tlb_entries)
    156 #define MIPS_TBIS		mips3_TBIS
    157 #define MachTLBUpdate		mips3_TLBUpdate
    158 #define wbflush()		mips3_wbflush()
    159 #define proc_trampoline		mips3_proc_trampoline
    160 #endif
    161 
    162 #if !defined(MIPS3) && defined (MIPS1)
    163 #define MachFlushCache		mips1_FlushCache
    164 #define MachFlushDCache		mips1_FlushDCache
    165 #define MachFlushICache		mips1_FlushICache
    166 #define MachSetPID		mips1_SetPID
    167 #define MIPS_TBIAP()		mips1_TBIAP(mips_num_tlb_entries)
    168 #define MIPS_TBIS		mips1_TBIS
    169 #define MachTLBUpdate		mips1_TLBUpdate
    170 #define wbflush()		mips1_wbflush()
    171 #define proc_trampoline		mips1_proc_trampoline
    172 #endif
    173 
    174 
    175 
    176 #if defined(MIPS3) && defined (MIPS1)
    177 #define MachFlushCache		(*(mips_locore_jumpvec.flushCache))
    178 #define MachFlushDCache		(*(mips_locore_jumpvec.flushDCache))
    179 #define MachFlushICache		(*(mips_locore_jumpvec.flushICache))
    180 #define MachSetPID		(*(mips_locore_jumpvec.setTLBpid))
    181 #define MIPS_TBIAP()		(*(mips_locore_jumpvec.TBIAP))(mips_num_tlb_entries)
    182 #define MIPS_TBIS		(*(mips_locore_jumpvec.TBIS))
    183 #define MachTLBUpdate		(*(mips_locore_jumpvec.tlbUpdate))
    184 #define MachHitFlushDCache	mips3_HitFlushDCache
    185 #define wbflush()		(*(mips_locore_jumpvec.wbflush))()
    186 #define proc_trampoline		(mips_locoresw[1])
    187 #endif
    188 
    189 #define CPU_IDLE		(mips_locoresw[2])
    190 
    191 /* cpu_switch_resume is called inside locore.S */
    192 
    193 /*
    194  * CPU identification, from PRID register.
    195  */
    196 typedef int mips_prid_t;
    197 
    198 #define	MIPS_PRID_REV(x)	(((x) >>  0) & 0x00ff)
    199 #define	MIPS_PRID_IMPL(x)	(((x) >>  8) & 0x00ff)
    200 
    201 /* pre-MIPS32 */
    202 #define	MIPS_PRID_RSVD(x)	(((x) >> 16) & 0xffff)
    203 #define	MIPS_PRID_REV_MIN(x)	((MIPS_PRID_REV(x) >> 0) & 0x0f)
    204 #define	MIPS_PRID_REV_MAJ(x)	((MIPS_PRID_REV(x) >> 4) & 0x0f)
    205 
    206 /* MIPS32 */
    207 #define	MIPS_PRID_CID(x)	(((x) >> 16) & 0x00ff)	/* Company ID */
    208 #define	    MIPS_PRID_CID_PREHISTORIC	0x00	/* Not MIPS32 */
    209 #define	    MIPS_PRID_CID_MTI		0x01	/* MIPS Technologies, Inc. */
    210 
    211 #ifdef _KERNEL
    212 
    213 /*
    214  * Global variables used to communicate CPU type, and parameters
    215  * such as cache size, from locore to higher-level code (e.g., pmap).
    216  */
    217 
    218 extern mips_prid_t cpu_id;
    219 extern mips_prid_t fpu_id;
    220 extern int	mips_num_tlb_entries;
    221 extern u_int	mips_L1DCacheSize;
    222 extern u_int	mips_L1ICacheSize;
    223 extern u_int	mips_L1DCacheLSize;
    224 extern u_int	mips_L1ICacheLSize;
    225 extern int	mips_L2CachePresent;
    226 extern u_int	mips_L2CacheLSize;
    227 extern u_int	mips_CacheAliasMask;
    228 extern u_int	mips_CachePreferMask;
    229 
    230 #ifdef MIPS3
    231 extern int	mips3_L1TwoWayCache;
    232 extern int	mips3_cacheflush_bug;
    233 #endif /* MIPS3 */
    234 
    235 /*
    236  * trapframe argument passed to trap()
    237  */
    238 struct trapframe {
    239 	mips_reg_t tf_regs[17];
    240 	mips_reg_t tf_ra;
    241 	mips_reg_t tf_sr;
    242 	mips_reg_t tf_mullo;
    243 	mips_reg_t tf_mulhi;
    244 	mips_reg_t tf_epc;		/* may be changed by trap() call */
    245 };
    246 
    247 /*
    248  * Stack frame for kernel traps. four args passed in registers.
    249  * A trapframe is pointed to by the 5th arg, and a dummy sixth argument
    250  * is used to avoid alignment problems
    251  */
    252 
    253 struct kernframe {
    254 	register_t cf_args[4 + 1];
    255 	register_t cf_pad;		/* (for 8 word alignment) */
    256 	register_t cf_sp;
    257 	register_t cf_ra;
    258 	struct trapframe cf_frame;
    259 };
    260 
    261 #endif
    262 
    263 #endif	/* _MIPS_LOCORE_H */
    264