Home | History | Annotate | Line # | Download | only in include
locore.h revision 1.70
      1  1.70   tsutsui /* $NetBSD: locore.h,v 1.70 2005/10/30 04:40:43 tsutsui 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.68       wiz  * 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.70   tsutsui #define _MIPS_LOCORE_H
     26   1.2  jonathan 
     27  1.17    castor #ifndef _LKM
     28  1.32     soren #include "opt_cputype.h"
     29  1.17    castor #endif
     30  1.16    castor 
     31  1.59    simonb #include <mips/cpuregs.h>
     32  1.59    simonb 
     33  1.38       cgd struct tlb;
     34  1.38       cgd 
     35  1.59    simonb uint32_t mips_cp0_cause_read(void);
     36  1.59    simonb void	mips_cp0_cause_write(uint32_t);
     37  1.59    simonb uint32_t mips_cp0_status_read(void);
     38  1.59    simonb void	mips_cp0_status_write(uint32_t);
     39  1.29    simonb 
     40  1.59    simonb #ifdef MIPS1
     41  1.54    simonb void	mips1_SetPID(int);
     42  1.38       cgd void	mips1_TBIA(int);
     43  1.38       cgd void	mips1_TBIAP(int);
     44  1.38       cgd void	mips1_TBIS(vaddr_t);
     45  1.38       cgd int	mips1_TLBUpdate(u_int, u_int);
     46  1.38       cgd void	mips1_wbflush(void);
     47  1.38       cgd void	mips1_proc_trampoline(void);
     48  1.38       cgd void	mips1_cpu_switch_resume(void);
     49  1.38       cgd 
     50  1.58   thorpej uint32_t tx3900_cp0_config_read(void);
     51  1.59    simonb #endif
     52  1.38       cgd 
     53  1.59    simonb #if defined(MIPS3) || defined(MIPS4)
     54  1.54    simonb void	mips3_SetPID(int);
     55  1.38       cgd void	mips3_TBIA(int);
     56  1.38       cgd void	mips3_TBIAP(int);
     57  1.38       cgd void	mips3_TBIS(vaddr_t);
     58  1.38       cgd int	mips3_TLBUpdate(u_int, u_int);
     59  1.38       cgd void	mips3_TLBRead(int, struct tlb *);
     60  1.38       cgd void	mips3_wbflush(void);
     61  1.38       cgd void	mips3_proc_trampoline(void);
     62  1.38       cgd void	mips3_cpu_switch_resume(void);
     63  1.63    simonb void	mips3_pagezero(caddr_t dst);
     64  1.38       cgd 
     65  1.59    simonb #ifdef MIPS3_5900
     66  1.59    simonb void	mips5900_SetPID(int);
     67  1.59    simonb void	mips5900_TBIA(int);
     68  1.59    simonb void	mips5900_TBIAP(int);
     69  1.59    simonb void	mips5900_TBIS(vaddr_t);
     70  1.59    simonb int	mips5900_TLBUpdate(u_int, u_int);
     71  1.59    simonb void	mips5900_TLBRead(int, struct tlb *);
     72  1.59    simonb void	mips5900_wbflush(void);
     73  1.59    simonb void	mips5900_proc_trampoline(void);
     74  1.59    simonb void	mips5900_cpu_switch_resume(void);
     75  1.63    simonb void	mips5900_pagezero(caddr_t dst);
     76  1.59    simonb #endif
     77  1.59    simonb #endif
     78  1.49       cgd 
     79  1.59    simonb #ifdef MIPS32
     80  1.59    simonb void	mips32_SetPID(int);
     81  1.59    simonb void	mips32_TBIA(int);
     82  1.59    simonb void	mips32_TBIAP(int);
     83  1.59    simonb void	mips32_TBIS(vaddr_t);
     84  1.59    simonb int	mips32_TLBUpdate(u_int, u_int);
     85  1.59    simonb void	mips32_TLBRead(int, struct tlb *);
     86  1.59    simonb void	mips32_wbflush(void);
     87  1.59    simonb void	mips32_proc_trampoline(void);
     88  1.59    simonb void	mips32_cpu_switch_resume(void);
     89  1.59    simonb #endif
     90  1.59    simonb 
     91  1.59    simonb #ifdef MIPS64
     92  1.59    simonb void	mips64_SetPID(int);
     93  1.59    simonb void	mips64_TBIA(int);
     94  1.59    simonb void	mips64_TBIAP(int);
     95  1.59    simonb void	mips64_TBIS(vaddr_t);
     96  1.59    simonb int	mips64_TLBUpdate(u_int, u_int);
     97  1.59    simonb void	mips64_TLBRead(int, struct tlb *);
     98  1.59    simonb void	mips64_wbflush(void);
     99  1.59    simonb void	mips64_proc_trampoline(void);
    100  1.59    simonb void	mips64_cpu_switch_resume(void);
    101  1.63    simonb void	mips64_pagezero(caddr_t dst);
    102  1.59    simonb #endif
    103  1.49       cgd 
    104  1.63    simonb #if defined(MIPS3) || defined(MIPS4) || defined(MIPS32) || defined(MIPS64)
    105  1.59    simonb uint32_t mips3_cp0_compare_read(void);
    106  1.59    simonb void	mips3_cp0_compare_write(uint32_t);
    107  1.49       cgd 
    108  1.59    simonb uint32_t mips3_cp0_config_read(void);
    109  1.59    simonb void	mips3_cp0_config_write(uint32_t);
    110  1.63    simonb #if defined(MIPS32) || defined(MIPS64)
    111  1.59    simonb uint32_t mipsNN_cp0_config1_read(void);
    112  1.59    simonb void	mipsNN_cp0_config1_write(uint32_t);
    113  1.63    simonb uint32_t mipsNN_cp0_config2_read(void);
    114  1.63    simonb uint32_t mipsNN_cp0_config3_read(void);
    115  1.63    simonb #endif
    116  1.59    simonb 
    117  1.59    simonb uint32_t mips3_cp0_count_read(void);
    118  1.59    simonb void	mips3_cp0_count_write(uint32_t);
    119  1.59    simonb 
    120  1.59    simonb uint32_t mips3_cp0_wired_read(void);
    121  1.59    simonb void	mips3_cp0_wired_write(uint32_t);
    122  1.69   tsutsui void	mips3_cp0_pg_mask_write(uint32_t);
    123  1.59    simonb 
    124  1.59    simonb uint64_t mips3_ld(uint64_t *);
    125  1.59    simonb void	mips3_sd(uint64_t *, uint64_t);
    126  1.63    simonb #endif	/* MIPS3 || MIPS4 || MIPS32 || MIPS64 */
    127  1.59    simonb 
    128  1.63    simonb #if defined(MIPS3) || defined(MIPS4) || defined(MIPS64)
    129  1.59    simonb static inline uint32_t	mips3_lw_a64(uint64_t addr)
    130  1.59    simonb 		    __attribute__((__unused__));
    131  1.59    simonb static inline void	mips3_sw_a64(uint64_t addr, uint32_t val)
    132  1.59    simonb 		    __attribute__ ((__unused__));
    133  1.59    simonb 
    134  1.59    simonb static inline uint32_t
    135  1.59    simonb mips3_lw_a64(uint64_t addr)
    136  1.59    simonb {
    137  1.59    simonb 	uint32_t addrlo, addrhi;
    138  1.59    simonb 	uint32_t rv;
    139  1.59    simonb 	uint32_t sr;
    140  1.59    simonb 
    141  1.59    simonb 	sr = mips_cp0_status_read();
    142  1.59    simonb 	mips_cp0_status_write(sr | MIPS3_SR_KX);
    143  1.59    simonb 
    144  1.59    simonb 	addrlo = addr & 0xffffffff;
    145  1.59    simonb 	addrhi = addr >> 32;
    146  1.59    simonb 	__asm__ __volatile__ ("		\n\
    147  1.59    simonb 		.set push		\n\
    148  1.59    simonb 		.set mips3		\n\
    149  1.59    simonb 		.set noreorder		\n\
    150  1.59    simonb 		.set noat		\n\
    151  1.59    simonb 		dsll32	$3, %1, 0	\n\
    152  1.59    simonb 		dsll32	$1, %2, 0	\n\
    153  1.59    simonb 		dsrl32	$3, $3, 0	\n\
    154  1.59    simonb 		or	$1, $1, $3	\n\
    155  1.59    simonb 		lw	%0, 0($1)	\n\
    156  1.59    simonb 		.set pop		\n\
    157  1.59    simonb 	" : "=r"(rv) : "r"(addrlo), "r"(addrhi) : "$1", "$3" );
    158  1.59    simonb 
    159  1.59    simonb 	mips_cp0_status_write(sr);
    160  1.59    simonb 
    161  1.59    simonb 	return (rv);
    162  1.59    simonb }
    163  1.59    simonb 
    164  1.59    simonb static inline void
    165  1.59    simonb mips3_sw_a64(uint64_t addr, uint32_t val)
    166  1.59    simonb {
    167  1.59    simonb 	uint32_t addrlo, addrhi;
    168  1.59    simonb 	uint32_t sr;
    169  1.59    simonb 
    170  1.59    simonb 	sr = mips_cp0_status_read();
    171  1.59    simonb 	mips_cp0_status_write(sr | MIPS3_SR_KX);
    172  1.59    simonb 
    173  1.59    simonb 	addrlo = addr & 0xffffffff;
    174  1.59    simonb 	addrhi = addr >> 32;
    175  1.59    simonb 	__asm__ __volatile__ ("			\n\
    176  1.59    simonb 		.set push			\n\
    177  1.59    simonb 		.set mips3			\n\
    178  1.59    simonb 		.set noreorder			\n\
    179  1.59    simonb 		.set noat			\n\
    180  1.59    simonb 		dsll32	$3, %1, 0		\n\
    181  1.59    simonb 		dsll32	$1, %2, 0		\n\
    182  1.59    simonb 		dsrl32	$3, $3, 0		\n\
    183  1.59    simonb 		or	$1, $1, $3		\n\
    184  1.59    simonb 		sw	%0, 0($1)		\n\
    185  1.59    simonb 		.set pop			\n\
    186  1.59    simonb 	" : : "r"(val), "r"(addrlo), "r"(addrhi) : "$1", "$3" );
    187  1.44       cgd 
    188  1.59    simonb 	mips_cp0_status_write(sr);
    189  1.59    simonb }
    190  1.63    simonb #endif	/* MIPS3 || MIPS4 || MIPS64 */
    191   1.7  jonathan 
    192   1.1  jonathan /*
    193  1.58   thorpej  * A vector with an entry for each mips-ISA-level dependent
    194   1.1  jonathan  * locore function, and macros which jump through it.
    195  1.58   thorpej  *
    196   1.1  jonathan  * XXX the macro names are chosen to be compatible with the old
    197  1.58   thorpej  * XXX Sprite coding-convention names used in 4.4bsd/pmax.
    198   1.1  jonathan  */
    199   1.1  jonathan typedef struct  {
    200  1.38       cgd 	void (*setTLBpid)(int pid);
    201  1.38       cgd 	void (*TBIAP)(int);
    202  1.38       cgd 	void (*TBIS)(vaddr_t);
    203  1.38       cgd 	int  (*tlbUpdate)(u_int highreg, u_int lowreg);
    204  1.38       cgd 	void (*wbflush)(void);
    205   1.1  jonathan } mips_locore_jumpvec_t;
    206  1.13  jonathan 
    207  1.38       cgd void	mips_set_wbflush(void (*)(void));
    208  1.62    simonb void	mips_wait_idle(void);
    209   1.1  jonathan 
    210  1.38       cgd void	stacktrace(void);
    211  1.38       cgd void	logstacktrace(void);
    212   1.1  jonathan 
    213   1.1  jonathan /*
    214   1.1  jonathan  * The "active" locore-fuction vector, and
    215   1.1  jonathan  */
    216   1.1  jonathan extern mips_locore_jumpvec_t mips_locore_jumpvec;
    217  1.31  nisimura extern long *mips_locoresw[];
    218   1.1  jonathan 
    219  1.59    simonb #if    defined(MIPS1) && !defined(MIPS3) && !defined(MIPS32) && !defined(MIPS64)
    220  1.11  jonathan #define MachSetPID		mips1_SetPID
    221  1.30  nisimura #define MIPS_TBIAP()		mips1_TBIAP(mips_num_tlb_entries)
    222  1.30  nisimura #define MIPS_TBIS		mips1_TBIS
    223  1.11  jonathan #define MachTLBUpdate		mips1_TLBUpdate
    224  1.22  nisimura #define wbflush()		mips1_wbflush()
    225  1.11  jonathan #define proc_trampoline		mips1_proc_trampoline
    226  1.60       uch #elif !defined(MIPS1) &&  defined(MIPS3) && !defined(MIPS32) && !defined(MIPS64) && !defined(MIPS3_5900)
    227  1.59    simonb #define MachSetPID		mips3_SetPID
    228  1.59    simonb #define MIPS_TBIAP()		mips3_TBIAP(mips_num_tlb_entries)
    229  1.59    simonb #define MIPS_TBIS		mips3_TBIS
    230  1.59    simonb #define MachTLBUpdate		mips3_TLBUpdate
    231  1.59    simonb #define proc_trampoline		mips3_proc_trampoline
    232  1.59    simonb #define wbflush()		mips3_wbflush()
    233  1.59    simonb #elif !defined(MIPS1) && !defined(MIPS3) &&  defined(MIPS32) && !defined(MIPS64)
    234  1.70   tsutsui #define MachSetPID		mips32_SetPID
    235  1.70   tsutsui #define MIPS_TBIAP()		mips32_TBIAP(mips_num_tlb_entries)
    236  1.70   tsutsui #define MIPS_TBIS		mips32_TBIS
    237  1.70   tsutsui #define MachTLBUpdate		mips32_TLBUpdate
    238  1.59    simonb #define proc_trampoline		mips32_proc_trampoline
    239  1.59    simonb #define wbflush()		mips32_wbflush()
    240  1.59    simonb #elif !defined(MIPS1) && !defined(MIPS3) && !defined(MIPS32) &&  defined(MIPS64)
    241  1.59    simonb  /* all common with mips3 */
    242  1.59    simonb #define MachSetPID		mips64_SetPID
    243  1.59    simonb #define MIPS_TBIAP()		mips64_TBIAP(mips_num_tlb_entries)
    244  1.59    simonb #define MIPS_TBIS		mips64_TBIS
    245  1.59    simonb #define MachTLBUpdate		mips64_TLBUpdate
    246  1.59    simonb #define proc_trampoline		mips64_proc_trampoline
    247  1.59    simonb #define wbflush()		mips64_wbflush()
    248  1.60       uch #elif !defined(MIPS1) &&  defined(MIPS3) && !defined(MIPS32) && !defined(MIPS64) && defined(MIPS3_5900)
    249  1.60       uch #define MachSetPID		mips5900_SetPID
    250  1.60       uch #define MIPS_TBIAP()		mips5900_TBIAP(mips_num_tlb_entries)
    251  1.60       uch #define MIPS_TBIS		mips5900_TBIS
    252  1.60       uch #define MachTLBUpdate		mips5900_TLBUpdate
    253  1.60       uch #define proc_trampoline		mips5900_proc_trampoline
    254  1.60       uch #define wbflush()		mips5900_wbflush()
    255  1.59    simonb #else
    256   1.1  jonathan #define MachSetPID		(*(mips_locore_jumpvec.setTLBpid))
    257  1.31  nisimura #define MIPS_TBIAP()		(*(mips_locore_jumpvec.TBIAP))(mips_num_tlb_entries)
    258  1.31  nisimura #define MIPS_TBIS		(*(mips_locore_jumpvec.TBIS))
    259   1.1  jonathan #define MachTLBUpdate		(*(mips_locore_jumpvec.tlbUpdate))
    260  1.22  nisimura #define wbflush()		(*(mips_locore_jumpvec.wbflush))()
    261  1.31  nisimura #define proc_trampoline		(mips_locoresw[1])
    262  1.11  jonathan #endif
    263  1.31  nisimura 
    264  1.31  nisimura #define CPU_IDLE		(mips_locoresw[2])
    265  1.11  jonathan 
    266  1.16    castor /* cpu_switch_resume is called inside locore.S */
    267   1.7  jonathan 
    268   1.7  jonathan /*
    269   1.7  jonathan  * CPU identification, from PRID register.
    270   1.7  jonathan  */
    271  1.40       cgd typedef int mips_prid_t;
    272  1.40       cgd 
    273  1.70   tsutsui #define MIPS_PRID_REV(x)	(((x) >>  0) & 0x00ff)
    274  1.70   tsutsui #define MIPS_PRID_IMPL(x)	(((x) >>  8) & 0x00ff)
    275  1.45       cgd 
    276  1.59    simonb /* pre-MIPS32/64 */
    277  1.70   tsutsui #define MIPS_PRID_RSVD(x)	(((x) >> 16) & 0xffff)
    278  1.70   tsutsui #define MIPS_PRID_REV_MIN(x)	((MIPS_PRID_REV(x) >> 0) & 0x0f)
    279  1.70   tsutsui #define MIPS_PRID_REV_MAJ(x)	((MIPS_PRID_REV(x) >> 4) & 0x0f)
    280  1.45       cgd 
    281  1.59    simonb /* MIPS32/64 */
    282  1.70   tsutsui #define MIPS_PRID_CID(x)	(((x) >> 16) & 0x00ff)	/* Company ID */
    283  1.70   tsutsui #define     MIPS_PRID_CID_PREHISTORIC	0x00	/* Not MIPS32/64 */
    284  1.70   tsutsui #define     MIPS_PRID_CID_MTI		0x01	/* MIPS Technologies, Inc. */
    285  1.70   tsutsui #define     MIPS_PRID_CID_BROADCOM	0x02	/* Broadcom */
    286  1.70   tsutsui #define     MIPS_PRID_CID_ALCHEMY	0x03	/* Alchemy Semiconductor */
    287  1.70   tsutsui #define     MIPS_PRID_CID_SIBYTE	0x04	/* SiByte */
    288  1.70   tsutsui #define     MIPS_PRID_CID_SANDCRAFT	0x05	/* SandCraft */
    289  1.70   tsutsui #define     MIPS_PRID_CID_PHILIPS	0x06	/* Philips */
    290  1.70   tsutsui #define     MIPS_PRID_CID_TOSHIBA	0x07	/* Toshiba */
    291  1.70   tsutsui #define     MIPS_PRID_CID_LSI		0x08	/* LSI */
    292  1.67    simonb 				/*	0x09	unannounced */
    293  1.67    simonb 				/*	0x0a	unannounced */
    294  1.70   tsutsui #define     MIPS_PRID_CID_LEXRA		0x0b	/* Lexra */
    295  1.70   tsutsui #define MIPS_PRID_COPTS(x)	(((x) >> 24) & 0x00ff)	/* Company Options */
    296   1.6  jonathan 
    297   1.6  jonathan #ifdef _KERNEL
    298   1.6  jonathan /*
    299   1.6  jonathan  * Global variables used to communicate CPU type, and parameters
    300   1.6  jonathan  * such as cache size, from locore to higher-level code (e.g., pmap).
    301   1.6  jonathan  */
    302  1.40       cgd 
    303  1.40       cgd extern mips_prid_t cpu_id;
    304  1.40       cgd extern mips_prid_t fpu_id;
    305  1.14  jonathan extern int	mips_num_tlb_entries;
    306  1.52     jeffs 
    307  1.52     jeffs void mips_pagecopy(caddr_t dst, caddr_t src);
    308  1.52     jeffs void mips_pagezero(caddr_t dst);
    309  1.19  jonathan 
    310  1.59    simonb #ifdef __HAVE_MIPS_MACHDEP_CACHE_CONFIG
    311  1.59    simonb void mips_machdep_cache_config(void);
    312  1.59    simonb #endif
    313  1.59    simonb 
    314  1.19  jonathan /*
    315  1.20    simonb  * trapframe argument passed to trap()
    316  1.19  jonathan  */
    317  1.64   thorpej 
    318  1.70   tsutsui #define TF_AST		0
    319  1.70   tsutsui #define TF_V0		1
    320  1.70   tsutsui #define TF_V1		2
    321  1.70   tsutsui #define TF_A0		3
    322  1.70   tsutsui #define TF_A1		4
    323  1.70   tsutsui #define TF_A2		5
    324  1.70   tsutsui #define TF_A3		6
    325  1.70   tsutsui #define TF_T0		7
    326  1.70   tsutsui #define TF_T1		8
    327  1.70   tsutsui #define TF_T2		9
    328  1.70   tsutsui #define TF_T3		10
    329  1.64   thorpej 
    330  1.64   thorpej #if defined(__mips_n32) || defined(__mips_n64)
    331  1.70   tsutsui #define TF_A4		11
    332  1.70   tsutsui #define TF_A5		12
    333  1.70   tsutsui #define TF_A6		13
    334  1.70   tsutsui #define TF_A7		14
    335  1.64   thorpej #else
    336  1.70   tsutsui #define TF_T4		11
    337  1.70   tsutsui #define TF_T5		12
    338  1.70   tsutsui #define TF_T6		13
    339  1.70   tsutsui #define TF_T7		14
    340  1.64   thorpej #endif /* __mips_n32 || __mips_n64 */
    341  1.64   thorpej 
    342  1.70   tsutsui #define TF_TA0		11
    343  1.70   tsutsui #define TF_TA1		12
    344  1.70   tsutsui #define TF_TA2		13
    345  1.70   tsutsui #define TF_TA3		14
    346  1.70   tsutsui 
    347  1.70   tsutsui #define TF_T8		15
    348  1.70   tsutsui #define TF_T9		16
    349  1.70   tsutsui 
    350  1.70   tsutsui #define TF_RA		17
    351  1.70   tsutsui #define TF_SR		18
    352  1.70   tsutsui #define TF_MULLO	19
    353  1.70   tsutsui #define TF_MULHI	20
    354  1.70   tsutsui #define TF_EPC		21		/* may be changed by trap() call */
    355  1.65   thorpej 
    356  1.70   tsutsui #define TF_NREGS	22
    357  1.64   thorpej 
    358  1.19  jonathan struct trapframe {
    359  1.64   thorpej 	mips_reg_t tf_regs[TF_NREGS];
    360  1.57       uch 	u_int32_t  tf_ppl;		/* previous priority level */
    361  1.57       uch 	int32_t    tf_pad;		/* for 8 byte aligned */
    362  1.19  jonathan };
    363  1.19  jonathan 
    364  1.19  jonathan /*
    365  1.19  jonathan  * Stack frame for kernel traps. four args passed in registers.
    366  1.19  jonathan  * A trapframe is pointed to by the 5th arg, and a dummy sixth argument
    367  1.19  jonathan  * is used to avoid alignment problems
    368  1.19  jonathan  */
    369  1.19  jonathan 
    370  1.19  jonathan struct kernframe {
    371  1.19  jonathan 	register_t cf_args[4 + 1];
    372  1.19  jonathan 	register_t cf_pad;		/* (for 8 word alignment) */
    373  1.19  jonathan 	register_t cf_sp;
    374  1.19  jonathan 	register_t cf_ra;
    375  1.19  jonathan 	struct trapframe cf_frame;
    376  1.19  jonathan };
    377  1.61    simonb #endif	/* _KERNEL */
    378   1.1  jonathan #endif	/* _MIPS_LOCORE_H */
    379