Home | History | Annotate | Line # | Download | only in include
locore.h revision 1.53.2.3
      1  1.53.2.3  jdolecek /* $NetBSD: locore.h,v 1.53.2.3 2002/03/16 15:58:35 jdolecek Exp $ */
      2       1.1  jonathan 
      3       1.1  jonathan /*
      4       1.1  jonathan  * Copyright 1996 The Board of Trustees of The Leland Stanford
      5       1.1  jonathan  * Junior University. All Rights Reserved.
      6       1.1  jonathan  *
      7       1.1  jonathan  * Permission to use, copy, modify, and distribute this
      8       1.1  jonathan  * software and its documentation for any purpose and without
      9       1.1  jonathan  * fee is hereby granted, provided that the above copyright
     10       1.1  jonathan  * notice appear in all copies.  Stanford University
     11       1.1  jonathan  * makes no representations about the suitability of this
     12       1.1  jonathan  * software for any purpose.  It is provided "as is" without
     13       1.1  jonathan  * express or implied warranty.
     14       1.1  jonathan  */
     15       1.1  jonathan 
     16       1.1  jonathan /*
     17       1.1  jonathan  * Jump table for MIPS cpu locore functions that are implemented
     18       1.1  jonathan  * differently on different generations, or instruction-level
     19       1.1  jonathan  * archtecture (ISA) level, the Mips family.
     20       1.1  jonathan  *
     21      1.33     soren  * We currently provide support for MIPS I and MIPS III.
     22       1.1  jonathan  */
     23       1.1  jonathan 
     24       1.1  jonathan #ifndef _MIPS_LOCORE_H
     25       1.1  jonathan #define  _MIPS_LOCORE_H
     26       1.2  jonathan 
     27      1.17    castor #ifndef _LKM
     28      1.32     soren #include "opt_cputype.h"
     29      1.16    castor #include "opt_mips_cache.h"
     30      1.17    castor #endif
     31      1.16    castor 
     32  1.53.2.3  jdolecek #include <mips/cpuregs.h>
     33  1.53.2.3  jdolecek 
     34      1.38       cgd struct tlb;
     35      1.38       cgd 
     36       1.2  jonathan /*
     37      1.16    castor  * locore service routine for exception vectors. Used outside locore
     38       1.2  jonathan  * only to print them by name in stack tracebacks
     39       1.2  jonathan  */
     40       1.2  jonathan 
     41  1.53.2.3  jdolecek uint32_t mips_cp0_cause_read(void);
     42  1.53.2.3  jdolecek void	mips_cp0_cause_write(uint32_t);
     43  1.53.2.3  jdolecek uint32_t mips_cp0_status_read(void);
     44  1.53.2.3  jdolecek void	mips_cp0_status_write(uint32_t);
     45      1.29    simonb 
     46  1.53.2.3  jdolecek #ifdef MIPS1
     47  1.53.2.1   thorpej void	mips1_SetPID(int);
     48      1.38       cgd void	mips1_TBIA(int);
     49      1.38       cgd void	mips1_TBIAP(int);
     50      1.38       cgd void	mips1_TBIS(vaddr_t);
     51      1.38       cgd int	mips1_TLBUpdate(u_int, u_int);
     52      1.38       cgd void	mips1_wbflush(void);
     53      1.38       cgd void	mips1_proc_trampoline(void);
     54      1.38       cgd void	mips1_cpu_switch_resume(void);
     55      1.38       cgd 
     56  1.53.2.2   thorpej uint32_t tx3900_cp0_config_read(void);
     57  1.53.2.3  jdolecek #endif
     58      1.38       cgd 
     59  1.53.2.3  jdolecek #if defined(MIPS3) || defined(MIPS4)
     60  1.53.2.1   thorpej void	mips3_SetPID(int);
     61      1.38       cgd void	mips3_TBIA(int);
     62      1.38       cgd void	mips3_TBIAP(int);
     63      1.38       cgd void	mips3_TBIS(vaddr_t);
     64      1.38       cgd int	mips3_TLBUpdate(u_int, u_int);
     65      1.38       cgd void	mips3_TLBRead(int, struct tlb *);
     66      1.38       cgd void	mips3_wbflush(void);
     67      1.38       cgd void	mips3_proc_trampoline(void);
     68      1.38       cgd void	mips3_cpu_switch_resume(void);
     69      1.38       cgd 
     70  1.53.2.3  jdolecek #ifdef MIPS3_5900
     71  1.53.2.3  jdolecek void	mips5900_SetPID(int);
     72  1.53.2.3  jdolecek void	mips5900_TBIA(int);
     73  1.53.2.3  jdolecek void	mips5900_TBIAP(int);
     74  1.53.2.3  jdolecek void	mips5900_TBIS(vaddr_t);
     75  1.53.2.3  jdolecek int	mips5900_TLBUpdate(u_int, u_int);
     76  1.53.2.3  jdolecek void	mips5900_TLBRead(int, struct tlb *);
     77  1.53.2.3  jdolecek void	mips5900_wbflush(void);
     78  1.53.2.3  jdolecek void	mips5900_proc_trampoline(void);
     79  1.53.2.3  jdolecek void	mips5900_cpu_switch_resume(void);
     80  1.53.2.3  jdolecek #endif
     81  1.53.2.3  jdolecek #endif
     82      1.49       cgd 
     83  1.53.2.3  jdolecek #ifdef MIPS32
     84  1.53.2.3  jdolecek void	mips32_SetPID(int);
     85  1.53.2.3  jdolecek void	mips32_TBIA(int);
     86  1.53.2.3  jdolecek void	mips32_TBIAP(int);
     87  1.53.2.3  jdolecek void	mips32_TBIS(vaddr_t);
     88  1.53.2.3  jdolecek int	mips32_TLBUpdate(u_int, u_int);
     89  1.53.2.3  jdolecek void	mips32_TLBRead(int, struct tlb *);
     90  1.53.2.3  jdolecek void	mips32_wbflush(void);
     91  1.53.2.3  jdolecek void	mips32_proc_trampoline(void);
     92  1.53.2.3  jdolecek void	mips32_cpu_switch_resume(void);
     93  1.53.2.3  jdolecek #endif
     94  1.53.2.3  jdolecek 
     95  1.53.2.3  jdolecek #ifdef MIPS64
     96  1.53.2.3  jdolecek void	mips64_SetPID(int);
     97  1.53.2.3  jdolecek void	mips64_TBIA(int);
     98  1.53.2.3  jdolecek void	mips64_TBIAP(int);
     99  1.53.2.3  jdolecek void	mips64_TBIS(vaddr_t);
    100  1.53.2.3  jdolecek int	mips64_TLBUpdate(u_int, u_int);
    101  1.53.2.3  jdolecek void	mips64_TLBRead(int, struct tlb *);
    102  1.53.2.3  jdolecek void	mips64_wbflush(void);
    103  1.53.2.3  jdolecek void	mips64_proc_trampoline(void);
    104  1.53.2.3  jdolecek void	mips64_cpu_switch_resume(void);
    105  1.53.2.3  jdolecek #endif
    106      1.49       cgd 
    107  1.53.2.3  jdolecek uint32_t mips3_cp0_compare_read(void);
    108  1.53.2.3  jdolecek void	mips3_cp0_compare_write(uint32_t);
    109      1.49       cgd 
    110  1.53.2.3  jdolecek uint32_t mips3_cp0_config_read(void);
    111  1.53.2.3  jdolecek void	mips3_cp0_config_write(uint32_t);
    112  1.53.2.3  jdolecek uint32_t mipsNN_cp0_config1_read(void);
    113  1.53.2.3  jdolecek void	mipsNN_cp0_config1_write(uint32_t);
    114  1.53.2.3  jdolecek 
    115  1.53.2.3  jdolecek uint32_t mips3_cp0_count_read(void);
    116  1.53.2.3  jdolecek void	mips3_cp0_count_write(uint32_t);
    117  1.53.2.3  jdolecek 
    118  1.53.2.3  jdolecek uint32_t mips3_cp0_wired_read(void);
    119  1.53.2.3  jdolecek void	mips3_cp0_wired_write(uint32_t);
    120  1.53.2.3  jdolecek 
    121  1.53.2.3  jdolecek uint64_t mips3_ld(uint64_t *);
    122  1.53.2.3  jdolecek void	mips3_sd(uint64_t *, uint64_t);
    123  1.53.2.3  jdolecek 
    124  1.53.2.3  jdolecek static inline uint32_t	mips3_lw_a64(uint64_t addr)
    125  1.53.2.3  jdolecek 		    __attribute__((__unused__));
    126  1.53.2.3  jdolecek static inline void	mips3_sw_a64(uint64_t addr, uint32_t val)
    127  1.53.2.3  jdolecek 		    __attribute__ ((__unused__));
    128  1.53.2.3  jdolecek 
    129  1.53.2.3  jdolecek static inline uint32_t
    130  1.53.2.3  jdolecek mips3_lw_a64(uint64_t addr)
    131  1.53.2.3  jdolecek {
    132  1.53.2.3  jdolecek 	uint32_t addrlo, addrhi;
    133  1.53.2.3  jdolecek 	uint32_t rv;
    134  1.53.2.3  jdolecek 	uint32_t sr;
    135  1.53.2.3  jdolecek 
    136  1.53.2.3  jdolecek 	sr = mips_cp0_status_read();
    137  1.53.2.3  jdolecek 	mips_cp0_status_write(sr | MIPS3_SR_KX);
    138  1.53.2.3  jdolecek 
    139  1.53.2.3  jdolecek 	addrlo = addr & 0xffffffff;
    140  1.53.2.3  jdolecek 	addrhi = addr >> 32;
    141  1.53.2.3  jdolecek 	__asm__ __volatile__ ("		\n\
    142  1.53.2.3  jdolecek 		.set push		\n\
    143  1.53.2.3  jdolecek 		.set mips3		\n\
    144  1.53.2.3  jdolecek 		.set noreorder		\n\
    145  1.53.2.3  jdolecek 		.set noat		\n\
    146  1.53.2.3  jdolecek 		dsll32	$3, %1, 0	\n\
    147  1.53.2.3  jdolecek 		dsll32	$1, %2, 0	\n\
    148  1.53.2.3  jdolecek 		dsrl32	$3, $3, 0	\n\
    149  1.53.2.3  jdolecek 		or	$1, $1, $3	\n\
    150  1.53.2.3  jdolecek 		lw	%0, 0($1)	\n\
    151  1.53.2.3  jdolecek 		.set pop		\n\
    152  1.53.2.3  jdolecek 	" : "=r"(rv) : "r"(addrlo), "r"(addrhi) : "$1", "$3" );
    153  1.53.2.3  jdolecek 
    154  1.53.2.3  jdolecek 	mips_cp0_status_write(sr);
    155  1.53.2.3  jdolecek 
    156  1.53.2.3  jdolecek 	return (rv);
    157  1.53.2.3  jdolecek }
    158  1.53.2.3  jdolecek 
    159  1.53.2.3  jdolecek static inline void
    160  1.53.2.3  jdolecek mips3_sw_a64(uint64_t addr, uint32_t val)
    161  1.53.2.3  jdolecek {
    162  1.53.2.3  jdolecek 	uint32_t addrlo, addrhi;
    163  1.53.2.3  jdolecek 	uint32_t sr;
    164  1.53.2.3  jdolecek 
    165  1.53.2.3  jdolecek 	sr = mips_cp0_status_read();
    166  1.53.2.3  jdolecek 	mips_cp0_status_write(sr | MIPS3_SR_KX);
    167  1.53.2.3  jdolecek 
    168  1.53.2.3  jdolecek 	addrlo = addr & 0xffffffff;
    169  1.53.2.3  jdolecek 	addrhi = addr >> 32;
    170  1.53.2.3  jdolecek 	__asm__ __volatile__ ("			\n\
    171  1.53.2.3  jdolecek 		.set push			\n\
    172  1.53.2.3  jdolecek 		.set mips3			\n\
    173  1.53.2.3  jdolecek 		.set noreorder			\n\
    174  1.53.2.3  jdolecek 		.set noat			\n\
    175  1.53.2.3  jdolecek 		dsll32	$3, %1, 0		\n\
    176  1.53.2.3  jdolecek 		dsll32	$1, %2, 0		\n\
    177  1.53.2.3  jdolecek 		dsrl32	$3, $3, 0		\n\
    178  1.53.2.3  jdolecek 		or	$1, $1, $3		\n\
    179  1.53.2.3  jdolecek 		sw	%0, 0($1)		\n\
    180  1.53.2.3  jdolecek 		.set pop			\n\
    181  1.53.2.3  jdolecek 	" : : "r"(val), "r"(addrlo), "r"(addrhi) : "$1", "$3" );
    182      1.44       cgd 
    183  1.53.2.3  jdolecek 	mips_cp0_status_write(sr);
    184  1.53.2.3  jdolecek }
    185       1.7  jonathan 
    186       1.1  jonathan /*
    187  1.53.2.2   thorpej  * A vector with an entry for each mips-ISA-level dependent
    188       1.1  jonathan  * locore function, and macros which jump through it.
    189  1.53.2.2   thorpej  *
    190       1.1  jonathan  * XXX the macro names are chosen to be compatible with the old
    191  1.53.2.2   thorpej  * XXX Sprite coding-convention names used in 4.4bsd/pmax.
    192       1.1  jonathan  */
    193       1.1  jonathan typedef struct  {
    194      1.38       cgd 	void (*setTLBpid)(int pid);
    195      1.38       cgd 	void (*TBIAP)(int);
    196      1.38       cgd 	void (*TBIS)(vaddr_t);
    197      1.38       cgd 	int  (*tlbUpdate)(u_int highreg, u_int lowreg);
    198      1.38       cgd 	void (*wbflush)(void);
    199       1.1  jonathan } mips_locore_jumpvec_t;
    200      1.13  jonathan 
    201      1.13  jonathan /* Override writebuffer-drain method. */
    202      1.38       cgd void	mips_set_wbflush(void (*)(void));
    203       1.1  jonathan 
    204      1.23    simonb /* stacktrace() -- print a stack backtrace to the console */
    205      1.38       cgd void	stacktrace(void);
    206      1.23    simonb /* logstacktrace() -- log a stack traceback to msgbuf */
    207      1.38       cgd void	logstacktrace(void);
    208       1.1  jonathan 
    209       1.1  jonathan /*
    210       1.1  jonathan  * The "active" locore-fuction vector, and
    211       1.1  jonathan  */
    212       1.1  jonathan extern mips_locore_jumpvec_t mips_locore_jumpvec;
    213      1.31  nisimura extern long *mips_locoresw[];
    214       1.1  jonathan 
    215  1.53.2.3  jdolecek #if    defined(MIPS1) && !defined(MIPS3) && !defined(MIPS32) && !defined(MIPS64)
    216      1.11  jonathan #define MachSetPID		mips1_SetPID
    217      1.30  nisimura #define MIPS_TBIAP()		mips1_TBIAP(mips_num_tlb_entries)
    218      1.30  nisimura #define MIPS_TBIS		mips1_TBIS
    219      1.11  jonathan #define MachTLBUpdate		mips1_TLBUpdate
    220      1.22  nisimura #define wbflush()		mips1_wbflush()
    221      1.11  jonathan #define proc_trampoline		mips1_proc_trampoline
    222  1.53.2.3  jdolecek #elif !defined(MIPS1) &&  defined(MIPS3) && !defined(MIPS32) && !defined(MIPS64) && !defined(MIPS3_5900)
    223  1.53.2.3  jdolecek #define MachSetPID		mips3_SetPID
    224  1.53.2.3  jdolecek #define MIPS_TBIAP()		mips3_TBIAP(mips_num_tlb_entries)
    225  1.53.2.3  jdolecek #define MIPS_TBIS		mips3_TBIS
    226  1.53.2.3  jdolecek #define MachTLBUpdate		mips3_TLBUpdate
    227  1.53.2.3  jdolecek #define proc_trampoline		mips3_proc_trampoline
    228  1.53.2.3  jdolecek #define wbflush()		mips3_wbflush()
    229  1.53.2.3  jdolecek #elif !defined(MIPS1) && !defined(MIPS3) &&  defined(MIPS32) && !defined(MIPS64)
    230  1.53.2.3  jdolecek #define	MachSetPID		mips32_SetPID
    231  1.53.2.3  jdolecek #define	MIPS_TBIAP()		mips32_TBIAP(mips_num_tlb_entries)
    232  1.53.2.3  jdolecek #define	MIPS_TBIS		mips32_TBIS
    233  1.53.2.3  jdolecek #define	MachTLBUpdate		mips32_TLBUpdate
    234  1.53.2.3  jdolecek #define proc_trampoline		mips32_proc_trampoline
    235  1.53.2.3  jdolecek #define wbflush()		mips32_wbflush()
    236  1.53.2.3  jdolecek #elif !defined(MIPS1) && !defined(MIPS3) && !defined(MIPS32) &&  defined(MIPS64)
    237  1.53.2.3  jdolecek  /* all common with mips3 */
    238  1.53.2.3  jdolecek #define MachSetPID		mips64_SetPID
    239  1.53.2.3  jdolecek #define MIPS_TBIAP()		mips64_TBIAP(mips_num_tlb_entries)
    240  1.53.2.3  jdolecek #define MIPS_TBIS		mips64_TBIS
    241  1.53.2.3  jdolecek #define MachTLBUpdate		mips64_TLBUpdate
    242  1.53.2.3  jdolecek #define proc_trampoline		mips64_proc_trampoline
    243  1.53.2.3  jdolecek #define wbflush()		mips64_wbflush()
    244  1.53.2.3  jdolecek #elif !defined(MIPS1) &&  defined(MIPS3) && !defined(MIPS32) && !defined(MIPS64) && defined(MIPS3_5900)
    245  1.53.2.3  jdolecek #define MachSetPID		mips5900_SetPID
    246  1.53.2.3  jdolecek #define MIPS_TBIAP()		mips5900_TBIAP(mips_num_tlb_entries)
    247  1.53.2.3  jdolecek #define MIPS_TBIS		mips5900_TBIS
    248  1.53.2.3  jdolecek #define MachTLBUpdate		mips5900_TLBUpdate
    249  1.53.2.3  jdolecek #define proc_trampoline		mips5900_proc_trampoline
    250  1.53.2.3  jdolecek #define wbflush()		mips5900_wbflush()
    251  1.53.2.3  jdolecek #else
    252       1.1  jonathan #define MachSetPID		(*(mips_locore_jumpvec.setTLBpid))
    253      1.31  nisimura #define MIPS_TBIAP()		(*(mips_locore_jumpvec.TBIAP))(mips_num_tlb_entries)
    254      1.31  nisimura #define MIPS_TBIS		(*(mips_locore_jumpvec.TBIS))
    255       1.1  jonathan #define MachTLBUpdate		(*(mips_locore_jumpvec.tlbUpdate))
    256      1.22  nisimura #define wbflush()		(*(mips_locore_jumpvec.wbflush))()
    257      1.31  nisimura #define proc_trampoline		(mips_locoresw[1])
    258      1.11  jonathan #endif
    259      1.31  nisimura 
    260      1.31  nisimura #define CPU_IDLE		(mips_locoresw[2])
    261      1.11  jonathan 
    262      1.16    castor /* cpu_switch_resume is called inside locore.S */
    263       1.7  jonathan 
    264       1.7  jonathan /*
    265       1.7  jonathan  * CPU identification, from PRID register.
    266       1.7  jonathan  */
    267      1.40       cgd typedef int mips_prid_t;
    268      1.40       cgd 
    269      1.40       cgd #define	MIPS_PRID_REV(x)	(((x) >>  0) & 0x00ff)
    270      1.40       cgd #define	MIPS_PRID_IMPL(x)	(((x) >>  8) & 0x00ff)
    271      1.45       cgd 
    272  1.53.2.3  jdolecek /* pre-MIPS32/64 */
    273      1.40       cgd #define	MIPS_PRID_RSVD(x)	(((x) >> 16) & 0xffff)
    274      1.40       cgd #define	MIPS_PRID_REV_MIN(x)	((MIPS_PRID_REV(x) >> 0) & 0x0f)
    275      1.40       cgd #define	MIPS_PRID_REV_MAJ(x)	((MIPS_PRID_REV(x) >> 4) & 0x0f)
    276      1.45       cgd 
    277  1.53.2.3  jdolecek /* MIPS32/64 */
    278      1.45       cgd #define	MIPS_PRID_CID(x)	(((x) >> 16) & 0x00ff)	/* Company ID */
    279  1.53.2.3  jdolecek #define	    MIPS_PRID_CID_PREHISTORIC	0x00	/* Not MIPS32/64 */
    280      1.45       cgd #define	    MIPS_PRID_CID_MTI		0x01	/* MIPS Technologies, Inc. */
    281  1.53.2.3  jdolecek #define	    MIPS_PRID_CID_BROADCOM	0x02	/* Broadcom */
    282  1.53.2.1   thorpej #define	    MIPS_PRID_CID_ALCHEMY	0x03	/* Alchemy Semiconductor */
    283  1.53.2.1   thorpej #define	    MIPS_PRID_CID_SIBYTE	0x04	/* SiByte */
    284  1.53.2.3  jdolecek #define	    MIPS_PRID_CID_SANDCRAFT	0x05	/* SandCraft */
    285  1.53.2.3  jdolecek #define	MIPS_PRID_COPTS(x)	(((x) >> 24) & 0x00ff)	/* Company Options */
    286       1.6  jonathan 
    287       1.6  jonathan #ifdef _KERNEL
    288       1.6  jonathan /*
    289       1.6  jonathan  * Global variables used to communicate CPU type, and parameters
    290       1.6  jonathan  * such as cache size, from locore to higher-level code (e.g., pmap).
    291       1.6  jonathan  */
    292      1.40       cgd 
    293      1.40       cgd extern mips_prid_t cpu_id;
    294      1.40       cgd extern mips_prid_t fpu_id;
    295      1.14  jonathan extern int	mips_num_tlb_entries;
    296      1.52     jeffs 
    297      1.52     jeffs void mips_pagecopy(caddr_t dst, caddr_t src);
    298      1.52     jeffs void mips_pagezero(caddr_t dst);
    299      1.19  jonathan 
    300  1.53.2.3  jdolecek #ifdef __HAVE_MIPS_MACHDEP_CACHE_CONFIG
    301  1.53.2.3  jdolecek void mips_machdep_cache_config(void);
    302  1.53.2.3  jdolecek #endif
    303  1.53.2.3  jdolecek 
    304      1.19  jonathan /*
    305      1.20    simonb  * trapframe argument passed to trap()
    306      1.19  jonathan  */
    307      1.19  jonathan struct trapframe {
    308      1.19  jonathan 	mips_reg_t tf_regs[17];
    309      1.19  jonathan 	mips_reg_t tf_ra;
    310      1.19  jonathan 	mips_reg_t tf_sr;
    311      1.19  jonathan 	mips_reg_t tf_mullo;
    312      1.19  jonathan 	mips_reg_t tf_mulhi;
    313      1.19  jonathan 	mips_reg_t tf_epc;		/* may be changed by trap() call */
    314  1.53.2.2   thorpej 	u_int32_t  tf_ppl;		/* previous priority level */
    315  1.53.2.2   thorpej 	int32_t    tf_pad;		/* for 8 byte aligned */
    316      1.19  jonathan };
    317      1.19  jonathan 
    318      1.19  jonathan /*
    319      1.19  jonathan  * Stack frame for kernel traps. four args passed in registers.
    320      1.19  jonathan  * A trapframe is pointed to by the 5th arg, and a dummy sixth argument
    321      1.19  jonathan  * is used to avoid alignment problems
    322      1.19  jonathan  */
    323      1.19  jonathan 
    324      1.19  jonathan struct kernframe {
    325      1.19  jonathan 	register_t cf_args[4 + 1];
    326      1.19  jonathan 	register_t cf_pad;		/* (for 8 word alignment) */
    327      1.19  jonathan 	register_t cf_sp;
    328      1.19  jonathan 	register_t cf_ra;
    329      1.19  jonathan 	struct trapframe cf_frame;
    330      1.19  jonathan };
    331       1.6  jonathan #endif
    332       1.1  jonathan #endif	/* _MIPS_LOCORE_H */
    333