Home | History | Annotate | Line # | Download | only in include
locore.h revision 1.93.2.1
      1  1.93.2.1  jdolecek /* $NetBSD: locore.h,v 1.93.2.1 2017/12/03 11:36:27 jdolecek Exp $ */
      2      1.83      matt 
      3      1.83      matt /*
      4      1.83      matt  * This file should not be included by MI code!!!
      5      1.83      matt  */
      6       1.1  jonathan 
      7       1.1  jonathan /*
      8       1.1  jonathan  * Copyright 1996 The Board of Trustees of The Leland Stanford
      9       1.1  jonathan  * Junior University. All Rights Reserved.
     10       1.1  jonathan  *
     11       1.1  jonathan  * Permission to use, copy, modify, and distribute this
     12       1.1  jonathan  * software and its documentation for any purpose and without
     13       1.1  jonathan  * fee is hereby granted, provided that the above copyright
     14       1.1  jonathan  * notice appear in all copies.  Stanford University
     15       1.1  jonathan  * makes no representations about the suitability of this
     16       1.1  jonathan  * software for any purpose.  It is provided "as is" without
     17       1.1  jonathan  * express or implied warranty.
     18       1.1  jonathan  */
     19       1.1  jonathan 
     20       1.1  jonathan /*
     21      1.68       wiz  * Jump table for MIPS CPU locore functions that are implemented
     22       1.1  jonathan  * differently on different generations, or instruction-level
     23      1.81       snj  * architecture (ISA) level, the Mips family.
     24       1.1  jonathan  *
     25      1.33     soren  * We currently provide support for MIPS I and MIPS III.
     26       1.1  jonathan  */
     27       1.1  jonathan 
     28       1.1  jonathan #ifndef _MIPS_LOCORE_H
     29      1.70   tsutsui #define _MIPS_LOCORE_H
     30       1.2  jonathan 
     31      1.91    dyoung #if !defined(_LKM) && defined(_KERNEL_OPT)
     32      1.32     soren #include "opt_cputype.h"
     33      1.17    castor #endif
     34      1.16    castor 
     35  1.93.2.1  jdolecek #ifndef __ASSEMBLER__
     36  1.93.2.1  jdolecek 
     37  1.93.2.1  jdolecek #include <sys/cpu.h>
     38  1.93.2.1  jdolecek 
     39      1.83      matt #include <mips/mutex.h>
     40      1.59    simonb #include <mips/cpuregs.h>
     41      1.83      matt #include <mips/reg.h>
     42      1.83      matt 
     43  1.93.2.1  jdolecek #ifndef __BSD_PTENTRY_T__
     44  1.93.2.1  jdolecek #define __BSD_PTENTRY_T__
     45  1.93.2.1  jdolecek typedef uint32_t pt_entry_t;
     46  1.93.2.1  jdolecek #define PRIxPTE		PRIx32
     47  1.93.2.1  jdolecek #endif
     48  1.93.2.1  jdolecek 
     49  1.93.2.1  jdolecek #include <uvm/pmap/tlb.h>
     50  1.93.2.1  jdolecek #endif /* !__ASSEMBLER__ */
     51  1.93.2.1  jdolecek 
     52  1.93.2.1  jdolecek #ifdef _KERNEL
     53  1.93.2.1  jdolecek 
     54  1.93.2.1  jdolecek #if defined(_MODULAR) || defined(_LKM) || defined(_STANDALONE)
     55  1.93.2.1  jdolecek /* Assume all CPU architectures are valid for LKM's and standlone progs */
     56  1.93.2.1  jdolecek #if !defined(__mips_n32) && !defined(__mips_n64)
     57  1.93.2.1  jdolecek #define	MIPS1		1
     58  1.93.2.1  jdolecek #endif
     59  1.93.2.1  jdolecek #define	MIPS3		1
     60  1.93.2.1  jdolecek #define	MIPS4		1
     61  1.93.2.1  jdolecek #if !defined(__mips_n32) && !defined(__mips_n64)
     62  1.93.2.1  jdolecek #define	MIPS32		1
     63  1.93.2.1  jdolecek #define	MIPS32R2	1
     64  1.93.2.1  jdolecek #endif
     65  1.93.2.1  jdolecek #define	MIPS64		1
     66  1.93.2.1  jdolecek #define	MIPS64R2	1
     67  1.93.2.1  jdolecek #endif /* _MODULAR || _LKM || _STANDALONE */
     68  1.93.2.1  jdolecek 
     69  1.93.2.1  jdolecek #if (MIPS1 + MIPS3 + MIPS4 + MIPS32 + MIPS32R2 + MIPS64 + MIPS64R2) == 0
     70  1.93.2.1  jdolecek #error at least one of MIPS1, MIPS3, MIPS4, MIPS32, MIPS32R2, MIPS64, or MIPS64R2 must be specified
     71  1.93.2.1  jdolecek #endif
     72  1.93.2.1  jdolecek 
     73  1.93.2.1  jdolecek /* Shortcut for MIPS3 or above defined */
     74  1.93.2.1  jdolecek #if defined(MIPS3) || defined(MIPS4) \
     75  1.93.2.1  jdolecek     || defined(MIPS32) || defined(MIPS32R2) \
     76  1.93.2.1  jdolecek     || defined(MIPS64) || defined(MIPS64R2)
     77  1.93.2.1  jdolecek 
     78  1.93.2.1  jdolecek #define	MIPS3_PLUS	1
     79  1.93.2.1  jdolecek #if !defined(MIPS32) && !defined(MIPS32R2)
     80  1.93.2.1  jdolecek #define MIPS3_64BIT	1
     81  1.93.2.1  jdolecek #endif
     82  1.93.2.1  jdolecek #if !defined(MIPS3) && !defined(MIPS4)
     83  1.93.2.1  jdolecek #define MIPSNN		1
     84  1.93.2.1  jdolecek #endif
     85  1.93.2.1  jdolecek #if defined(MIPS32R2) || defined(MIPS64R2)
     86  1.93.2.1  jdolecek #define MIPSNNR2	1
     87  1.93.2.1  jdolecek #endif
     88  1.93.2.1  jdolecek #else
     89  1.93.2.1  jdolecek #undef MIPS3_PLUS
     90  1.93.2.1  jdolecek #endif
     91  1.93.2.1  jdolecek 
     92  1.93.2.1  jdolecek #if !defined(MIPS3_PLUS) && (ENABLE_MIPS_8KB_PAGE + ENABLE_MIPS_16KB_PAGE) > 0
     93  1.93.2.1  jdolecek #error MIPS1 does not support non-4KB page sizes.
     94  1.93.2.1  jdolecek #endif
     95  1.93.2.1  jdolecek 
     96  1.93.2.1  jdolecek /* XXX some .S files look for MIPS3_PLUS */
     97  1.93.2.1  jdolecek #ifndef __ASSEMBLER__
     98  1.93.2.1  jdolecek 
     99  1.93.2.1  jdolecek /* XXX simonb
    100  1.93.2.1  jdolecek  * Should the following be in a cpu_info type structure?
    101  1.93.2.1  jdolecek  * And how many of these are per-cpu vs. per-system?  (Ie,
    102  1.93.2.1  jdolecek  * we can assume that all cpus have the same mmu-type, but
    103  1.93.2.1  jdolecek  * maybe not that all cpus run at the same clock speed.
    104  1.93.2.1  jdolecek  * Some SGI's apparently support R12k and R14k in the same
    105  1.93.2.1  jdolecek  * box.)
    106  1.93.2.1  jdolecek  */
    107  1.93.2.1  jdolecek struct mips_options {
    108  1.93.2.1  jdolecek 	const struct pridtab *mips_cpu;
    109  1.93.2.1  jdolecek 
    110  1.93.2.1  jdolecek 	u_int mips_cpu_arch;
    111  1.93.2.1  jdolecek 	u_int mips_cpu_mhz; /* CPU speed in MHz, estimated by mc_cpuspeed(). */
    112  1.93.2.1  jdolecek 	u_int mips_cpu_flags;
    113  1.93.2.1  jdolecek 	u_int mips_num_tlb_entries;
    114  1.93.2.1  jdolecek 	mips_prid_t mips_cpu_id;
    115  1.93.2.1  jdolecek 	mips_prid_t mips_fpu_id;
    116  1.93.2.1  jdolecek 	bool mips_has_r4k_mmu;
    117  1.93.2.1  jdolecek 	bool mips_has_llsc;
    118  1.93.2.1  jdolecek 	u_int mips3_pg_shift;
    119  1.93.2.1  jdolecek 	u_int mips3_pg_cached;
    120  1.93.2.1  jdolecek 	u_int mips3_cca_devmem;
    121  1.93.2.1  jdolecek #ifdef MIPS3_PLUS
    122  1.93.2.1  jdolecek #ifndef __mips_o32
    123  1.93.2.1  jdolecek 	uint64_t mips3_xkphys_cached;
    124  1.93.2.1  jdolecek #endif
    125  1.93.2.1  jdolecek 	uint64_t mips3_tlb_vpn_mask;
    126  1.93.2.1  jdolecek 	uint64_t mips3_tlb_pfn_mask;
    127  1.93.2.1  jdolecek 	uint32_t mips3_tlb_pg_mask;
    128  1.93.2.1  jdolecek #endif
    129  1.93.2.1  jdolecek };
    130  1.93.2.1  jdolecek 
    131  1.93.2.1  jdolecek #endif /* !__ASSEMBLER__ */
    132  1.93.2.1  jdolecek 
    133  1.93.2.1  jdolecek /*
    134  1.93.2.1  jdolecek  * Macros to find the CPU architecture we're on at run-time,
    135  1.93.2.1  jdolecek  * or if possible, at compile-time.
    136  1.93.2.1  jdolecek  */
    137  1.93.2.1  jdolecek 
    138  1.93.2.1  jdolecek #define	CPU_ARCH_MIPSx		0		/* XXX unknown */
    139  1.93.2.1  jdolecek #define	CPU_ARCH_MIPS1		(1 << 0)
    140  1.93.2.1  jdolecek #define	CPU_ARCH_MIPS2		(1 << 1)
    141  1.93.2.1  jdolecek #define	CPU_ARCH_MIPS3		(1 << 2)
    142  1.93.2.1  jdolecek #define	CPU_ARCH_MIPS4		(1 << 3)
    143  1.93.2.1  jdolecek #define	CPU_ARCH_MIPS5		(1 << 4)
    144  1.93.2.1  jdolecek #define	CPU_ARCH_MIPS32		(1 << 5)
    145  1.93.2.1  jdolecek #define	CPU_ARCH_MIPS64		(1 << 6)
    146  1.93.2.1  jdolecek #define	CPU_ARCH_MIPS32R2	(1 << 7)
    147  1.93.2.1  jdolecek #define	CPU_ARCH_MIPS64R2	(1 << 8)
    148  1.93.2.1  jdolecek 
    149  1.93.2.1  jdolecek #define	CPU_MIPS_R4K_MMU		0x0001
    150  1.93.2.1  jdolecek #define	CPU_MIPS_NO_LLSC		0x0002
    151  1.93.2.1  jdolecek #define	CPU_MIPS_CAUSE_IV		0x0004
    152  1.93.2.1  jdolecek #define	CPU_MIPS_HAVE_SPECIAL_CCA	0x0008	/* Defaults to '3' if not set. */
    153  1.93.2.1  jdolecek #define	CPU_MIPS_CACHED_CCA_MASK	0x0070
    154  1.93.2.1  jdolecek #define	CPU_MIPS_CACHED_CCA_SHIFT	 4
    155  1.93.2.1  jdolecek #define	CPU_MIPS_DOUBLE_COUNT		0x0080	/* 1 cp0 count == 2 clock cycles */
    156  1.93.2.1  jdolecek #define	CPU_MIPS_USE_WAIT		0x0100	/* Use "wait"-based cpu_idle() */
    157  1.93.2.1  jdolecek #define	CPU_MIPS_NO_WAIT		0x0200	/* Inverse of previous, for mips32/64 */
    158  1.93.2.1  jdolecek #define	CPU_MIPS_D_CACHE_COHERENT	0x0400	/* D-cache is fully coherent */
    159  1.93.2.1  jdolecek #define	CPU_MIPS_I_D_CACHE_COHERENT	0x0800	/* I-cache funcs don't need to flush the D-cache */
    160  1.93.2.1  jdolecek #define	CPU_MIPS_NO_LLADDR		0x1000
    161  1.93.2.1  jdolecek #define	CPU_MIPS_HAVE_MxCR		0x2000	/* have mfcr, mtcr insns */
    162  1.93.2.1  jdolecek #define	CPU_MIPS_LOONGSON2		0x4000
    163  1.93.2.1  jdolecek #define	MIPS_NOT_SUPP			0x8000
    164  1.93.2.1  jdolecek #define	CPU_MIPS_HAVE_DSP		0x10000
    165  1.93.2.1  jdolecek 
    166  1.93.2.1  jdolecek #endif	/* !_LOCORE */
    167  1.93.2.1  jdolecek 
    168  1.93.2.1  jdolecek #if ((MIPS1 + MIPS3 + MIPS4 + MIPS32 + MIPS32R2 + MIPS64 + MIPS64R2) == 1) || defined(_LOCORE)
    169  1.93.2.1  jdolecek 
    170  1.93.2.1  jdolecek #if defined(MIPS1)
    171  1.93.2.1  jdolecek 
    172  1.93.2.1  jdolecek # define CPUISMIPS3		0
    173  1.93.2.1  jdolecek # define CPUIS64BITS		0
    174  1.93.2.1  jdolecek # define CPUISMIPS32		0
    175  1.93.2.1  jdolecek # define CPUISMIPS32R2		0
    176  1.93.2.1  jdolecek # define CPUISMIPS64		0
    177  1.93.2.1  jdolecek # define CPUISMIPS64R2		0
    178  1.93.2.1  jdolecek # define CPUISMIPSNN		0
    179  1.93.2.1  jdolecek # define CPUISMIPSNNR2		0
    180  1.93.2.1  jdolecek # define MIPS_HAS_R4K_MMU	0
    181  1.93.2.1  jdolecek # define MIPS_HAS_CLOCK		0
    182  1.93.2.1  jdolecek # define MIPS_HAS_LLSC		0
    183  1.93.2.1  jdolecek # define MIPS_HAS_LLADDR	0
    184  1.93.2.1  jdolecek # define MIPS_HAS_DSP		0
    185  1.93.2.1  jdolecek # define MIPS_HAS_LMMI		0
    186  1.93.2.1  jdolecek 
    187  1.93.2.1  jdolecek #elif defined(MIPS3) || defined(MIPS4)
    188  1.93.2.1  jdolecek 
    189  1.93.2.1  jdolecek # define CPUISMIPS3		1
    190  1.93.2.1  jdolecek # define CPUIS64BITS		1
    191  1.93.2.1  jdolecek # define CPUISMIPS32		0
    192  1.93.2.1  jdolecek # define CPUISMIPS32R2		0
    193  1.93.2.1  jdolecek # define CPUISMIPS64		0
    194  1.93.2.1  jdolecek # define CPUISMIPS64R2		0
    195  1.93.2.1  jdolecek # define CPUISMIPSNN		0
    196  1.93.2.1  jdolecek # define CPUISMIPSNNR2		0
    197  1.93.2.1  jdolecek # define MIPS_HAS_R4K_MMU	1
    198  1.93.2.1  jdolecek # define MIPS_HAS_CLOCK		1
    199  1.93.2.1  jdolecek # if defined(_LOCORE)
    200  1.93.2.1  jdolecek #  if !defined(MIPS3_4100)
    201  1.93.2.1  jdolecek #   define MIPS_HAS_LLSC	1
    202  1.93.2.1  jdolecek #  else
    203  1.93.2.1  jdolecek #   define MIPS_HAS_LLSC	0
    204  1.93.2.1  jdolecek #  endif
    205  1.93.2.1  jdolecek # else	/* _LOCORE */
    206  1.93.2.1  jdolecek #  define MIPS_HAS_LLSC		(mips_options.mips_has_llsc)
    207  1.93.2.1  jdolecek # endif	/* _LOCORE */
    208  1.93.2.1  jdolecek # define MIPS_HAS_LLADDR	((mips_options.mips_cpu_flags & CPU_MIPS_NO_LLADDR) == 0)
    209  1.93.2.1  jdolecek # define MIPS_HAS_DSP		0
    210  1.93.2.1  jdolecek # if defined(MIPS3_LOONGSON2)
    211  1.93.2.1  jdolecek #  define MIPS_HAS_LMMI		((mips_options.mips_cpu_flags & CPU_MIPS_LOONGSON2) != 0)
    212  1.93.2.1  jdolecek # else
    213  1.93.2.1  jdolecek #  define MIPS_HAS_LMMI		0
    214  1.93.2.1  jdolecek # endif
    215  1.93.2.1  jdolecek #elif defined(MIPS32)
    216  1.93.2.1  jdolecek 
    217  1.93.2.1  jdolecek # define CPUISMIPS3		1
    218  1.93.2.1  jdolecek # define CPUIS64BITS		0
    219  1.93.2.1  jdolecek # define CPUISMIPS32		1
    220  1.93.2.1  jdolecek # define CPUISMIPS32R2		0
    221  1.93.2.1  jdolecek # define CPUISMIPS64		0
    222  1.93.2.1  jdolecek # define CPUISMIPS64R2		0
    223  1.93.2.1  jdolecek # define CPUISMIPSNN		1
    224  1.93.2.1  jdolecek # define CPUISMIPSNNR2		0
    225  1.93.2.1  jdolecek # define MIPS_HAS_R4K_MMU	1
    226  1.93.2.1  jdolecek # define MIPS_HAS_CLOCK		1
    227  1.93.2.1  jdolecek # define MIPS_HAS_LLSC		1
    228  1.93.2.1  jdolecek # define MIPS_HAS_LLADDR	((mips_options.mips_cpu_flags & CPU_MIPS_NO_LLADDR) == 0)
    229  1.93.2.1  jdolecek # define MIPS_HAS_DSP		0
    230  1.93.2.1  jdolecek # define MIPS_HAS_LMMI		0
    231  1.93.2.1  jdolecek 
    232  1.93.2.1  jdolecek #elif defined(MIPS32R2)
    233  1.93.2.1  jdolecek 
    234  1.93.2.1  jdolecek # define CPUISMIPS3		1
    235  1.93.2.1  jdolecek # define CPUIS64BITS		0
    236  1.93.2.1  jdolecek # define CPUISMIPS32		0
    237  1.93.2.1  jdolecek # define CPUISMIPS32R2		1
    238  1.93.2.1  jdolecek # define CPUISMIPS64		0
    239  1.93.2.1  jdolecek # define CPUISMIPS64R2		0
    240  1.93.2.1  jdolecek # define CPUISMIPSNN		1
    241  1.93.2.1  jdolecek # define CPUISMIPSNNR2		1
    242  1.93.2.1  jdolecek # define MIPS_HAS_R4K_MMU	1
    243  1.93.2.1  jdolecek # define MIPS_HAS_CLOCK		1
    244  1.93.2.1  jdolecek # define MIPS_HAS_LLSC		1
    245  1.93.2.1  jdolecek # define MIPS_HAS_LLADDR	((mips_options.mips_cpu_flags & CPU_MIPS_NO_LLADDR) == 0)
    246  1.93.2.1  jdolecek # define MIPS_HAS_DSP		(mips_options.mips_cpu_flags & CPU_MIPS_HAVE_DSP)
    247  1.93.2.1  jdolecek # define MIPS_HAS_LMMI		0
    248  1.93.2.1  jdolecek 
    249  1.93.2.1  jdolecek #elif defined(MIPS64)
    250  1.93.2.1  jdolecek 
    251  1.93.2.1  jdolecek # define CPUISMIPS3		1
    252  1.93.2.1  jdolecek # define CPUIS64BITS		1
    253  1.93.2.1  jdolecek # define CPUISMIPS32		0
    254  1.93.2.1  jdolecek # define CPUISMIPS32R2		0
    255  1.93.2.1  jdolecek # define CPUISMIPS64		1
    256  1.93.2.1  jdolecek # define CPUISMIPS64R2		0
    257  1.93.2.1  jdolecek # define CPUISMIPSNN		1
    258  1.93.2.1  jdolecek # define CPUISMIPSNNR2		0
    259  1.93.2.1  jdolecek # define MIPS_HAS_R4K_MMU	1
    260  1.93.2.1  jdolecek # define MIPS_HAS_CLOCK		1
    261  1.93.2.1  jdolecek # define MIPS_HAS_LLSC		1
    262  1.93.2.1  jdolecek # define MIPS_HAS_LLADDR	((mips_options.mips_cpu_flags & CPU_MIPS_NO_LLADDR) == 0)
    263  1.93.2.1  jdolecek # define MIPS_HAS_DSP		0
    264  1.93.2.1  jdolecek # define MIPS_HAS_LMMI		0
    265  1.93.2.1  jdolecek 
    266  1.93.2.1  jdolecek #elif defined(MIPS64R2)
    267  1.93.2.1  jdolecek 
    268  1.93.2.1  jdolecek # define CPUISMIPS3		1
    269  1.93.2.1  jdolecek # define CPUIS64BITS		1
    270  1.93.2.1  jdolecek # define CPUISMIPS32		0
    271  1.93.2.1  jdolecek # define CPUISMIPS32R2		0
    272  1.93.2.1  jdolecek # define CPUISMIPS64		0
    273  1.93.2.1  jdolecek # define CPUISMIPS64R2		1
    274  1.93.2.1  jdolecek # define CPUISMIPSNN		1
    275  1.93.2.1  jdolecek # define CPUISMIPSNNR2		1
    276  1.93.2.1  jdolecek # define MIPS_HAS_R4K_MMU	1
    277  1.93.2.1  jdolecek # define MIPS_HAS_CLOCK		1
    278  1.93.2.1  jdolecek # define MIPS_HAS_LLSC		1
    279  1.93.2.1  jdolecek # define MIPS_HAS_LLADDR	((mips_options.mips_cpu_flags & CPU_MIPS_NO_LLADDR) == 0)
    280  1.93.2.1  jdolecek # define MIPS_HAS_DSP		(mips_options.mips_cpu_flags & CPU_MIPS_HAVE_DSP)
    281  1.93.2.1  jdolecek # define MIPS_HAS_LMMI		0
    282  1.93.2.1  jdolecek 
    283  1.93.2.1  jdolecek #endif
    284  1.93.2.1  jdolecek 
    285  1.93.2.1  jdolecek #else /* run-time test */
    286  1.93.2.1  jdolecek 
    287  1.93.2.1  jdolecek #ifdef MIPS1
    288  1.93.2.1  jdolecek #define	MIPS_HAS_R4K_MMU	(mips_options.mips_has_r4k_mmu)
    289  1.93.2.1  jdolecek #define	MIPS_HAS_LLSC		(mips_options.mips_has_llsc)
    290  1.93.2.1  jdolecek #else
    291  1.93.2.1  jdolecek #define	MIPS_HAS_R4K_MMU	1
    292  1.93.2.1  jdolecek #if !defined(MIPS3_4100)
    293  1.93.2.1  jdolecek #define MIPS_HAS_LLSC		1
    294  1.93.2.1  jdolecek #else
    295  1.93.2.1  jdolecek #define MIPS_HAS_LLSC		(mips_options.mips_has_llsc)
    296  1.93.2.1  jdolecek #endif
    297  1.93.2.1  jdolecek #endif
    298  1.93.2.1  jdolecek #define	MIPS_HAS_LLADDR		((mips_options.mips_cpu_flags & CPU_MIPS_NO_LLADDR) == 0)
    299  1.93.2.1  jdolecek #define MIPS_HAS_DSP		(mips_options.mips_cpu_flags & CPU_MIPS_HAVE_DSP)
    300  1.93.2.1  jdolecek 
    301  1.93.2.1  jdolecek /* This test is ... rather bogus */
    302  1.93.2.1  jdolecek #define	CPUISMIPS3	((mips_options.mips_cpu_arch & \
    303  1.93.2.1  jdolecek 	(CPU_ARCH_MIPS3 | CPU_ARCH_MIPS4 | CPU_ARCH_MIPS32 | CPU_ARCH_MIPS64)) != 0)
    304  1.93.2.1  jdolecek 
    305  1.93.2.1  jdolecek /* And these aren't much better while the previous test exists as is... */
    306  1.93.2.1  jdolecek #define	CPUISMIPS4	((mips_options.mips_cpu_arch & CPU_ARCH_MIPS4) != 0)
    307  1.93.2.1  jdolecek #define	CPUISMIPS5	((mips_options.mips_cpu_arch & CPU_ARCH_MIPS5) != 0)
    308  1.93.2.1  jdolecek #define	CPUISMIPS32	((mips_options.mips_cpu_arch & CPU_ARCH_MIPS32) != 0)
    309  1.93.2.1  jdolecek #define	CPUISMIPS32R2	((mips_options.mips_cpu_arch & CPU_ARCH_MIPS32R2) != 0)
    310  1.93.2.1  jdolecek #define	CPUISMIPS64	((mips_options.mips_cpu_arch & CPU_ARCH_MIPS64) != 0)
    311  1.93.2.1  jdolecek #define	CPUISMIPS64R2	((mips_options.mips_cpu_arch & CPU_ARCH_MIPS64R2) != 0)
    312  1.93.2.1  jdolecek #define	CPUISMIPSNN	((mips_options.mips_cpu_arch & (CPU_ARCH_MIPS32 | CPU_ARCH_MIPS32R2 | CPU_ARCH_MIPS64 | CPU_ARCH_MIPS64R2)) != 0)
    313  1.93.2.1  jdolecek #define	CPUIS64BITS	((mips_options.mips_cpu_arch & \
    314  1.93.2.1  jdolecek 	(CPU_ARCH_MIPS3 | CPU_ARCH_MIPS4 | CPU_ARCH_MIPS64 | CPU_ARCH_MIPS64R2)) != 0)
    315  1.93.2.1  jdolecek 
    316  1.93.2.1  jdolecek #define	MIPS_HAS_CLOCK	(mips_options.mips_cpu_arch >= CPU_ARCH_MIPS3)
    317  1.93.2.1  jdolecek 
    318  1.93.2.1  jdolecek #endif /* run-time test */
    319  1.93.2.1  jdolecek 
    320  1.93.2.1  jdolecek #ifndef __ASSEMBLER__
    321  1.93.2.1  jdolecek 
    322      1.83      matt struct tlbmask;
    323      1.83      matt struct trapframe;
    324      1.59    simonb 
    325      1.83      matt void	trap(uint32_t, uint32_t, vaddr_t, vaddr_t, struct trapframe *);
    326      1.83      matt void	ast(void);
    327      1.83      matt 
    328      1.83      matt void	mips_fpu_trap(vaddr_t, struct trapframe *);
    329      1.83      matt void	mips_fpu_intr(vaddr_t, struct trapframe *);
    330      1.83      matt 
    331      1.83      matt vaddr_t mips_emul_branch(struct trapframe *, vaddr_t, uint32_t, bool);
    332      1.83      matt void	mips_emul_inst(uint32_t, uint32_t, vaddr_t, struct trapframe *);
    333      1.83      matt 
    334      1.83      matt void	mips_emul_fp(uint32_t, struct trapframe *, uint32_t);
    335      1.83      matt void	mips_emul_branchdelayslot(uint32_t, struct trapframe *, uint32_t);
    336      1.83      matt 
    337      1.83      matt void	mips_emul_lwc0(uint32_t, struct trapframe *, uint32_t);
    338      1.83      matt void	mips_emul_swc0(uint32_t, struct trapframe *, uint32_t);
    339      1.83      matt void	mips_emul_special(uint32_t, struct trapframe *, uint32_t);
    340      1.83      matt void	mips_emul_special3(uint32_t, struct trapframe *, uint32_t);
    341      1.83      matt 
    342      1.83      matt void	mips_emul_lwc1(uint32_t, struct trapframe *, uint32_t);
    343      1.83      matt void	mips_emul_swc1(uint32_t, struct trapframe *, uint32_t);
    344      1.83      matt void	mips_emul_ldc1(uint32_t, struct trapframe *, uint32_t);
    345      1.83      matt void	mips_emul_sdc1(uint32_t, struct trapframe *, uint32_t);
    346      1.83      matt 
    347      1.83      matt void	mips_emul_lb(uint32_t, struct trapframe *, uint32_t);
    348      1.83      matt void	mips_emul_lbu(uint32_t, struct trapframe *, uint32_t);
    349      1.83      matt void	mips_emul_lh(uint32_t, struct trapframe *, uint32_t);
    350      1.83      matt void	mips_emul_lhu(uint32_t, struct trapframe *, uint32_t);
    351      1.83      matt void	mips_emul_lw(uint32_t, struct trapframe *, uint32_t);
    352      1.83      matt void	mips_emul_lwl(uint32_t, struct trapframe *, uint32_t);
    353      1.83      matt void	mips_emul_lwr(uint32_t, struct trapframe *, uint32_t);
    354      1.83      matt #if defined(__mips_n32) || defined(__mips_n64) || defined(__mips_o64)
    355      1.83      matt void	mips_emul_lwu(uint32_t, struct trapframe *, uint32_t);
    356      1.83      matt void	mips_emul_ld(uint32_t, struct trapframe *, uint32_t);
    357      1.83      matt void	mips_emul_ldl(uint32_t, struct trapframe *, uint32_t);
    358      1.83      matt void	mips_emul_ldr(uint32_t, struct trapframe *, uint32_t);
    359      1.83      matt #endif
    360      1.83      matt void	mips_emul_sb(uint32_t, struct trapframe *, uint32_t);
    361      1.83      matt void	mips_emul_sh(uint32_t, struct trapframe *, uint32_t);
    362      1.83      matt void	mips_emul_sw(uint32_t, struct trapframe *, uint32_t);
    363      1.83      matt void	mips_emul_swl(uint32_t, struct trapframe *, uint32_t);
    364      1.83      matt void	mips_emul_swr(uint32_t, struct trapframe *, uint32_t);
    365      1.83      matt #if defined(__mips_n32) || defined(__mips_n64) || defined(__mips_o64)
    366      1.83      matt void	mips_emul_sd(uint32_t, struct trapframe *, uint32_t);
    367      1.83      matt void	mips_emul_sdl(uint32_t, struct trapframe *, uint32_t);
    368      1.83      matt void	mips_emul_sdr(uint32_t, struct trapframe *, uint32_t);
    369      1.83      matt #endif
    370      1.38       cgd 
    371      1.59    simonb uint32_t mips_cp0_cause_read(void);
    372      1.59    simonb void	mips_cp0_cause_write(uint32_t);
    373      1.59    simonb uint32_t mips_cp0_status_read(void);
    374      1.59    simonb void	mips_cp0_status_write(uint32_t);
    375      1.29    simonb 
    376      1.83      matt void	softint_process(uint32_t);
    377      1.83      matt void	softint_fast_dispatch(struct lwp *, int);
    378      1.83      matt 
    379      1.83      matt /*
    380      1.83      matt  * Convert an address to an offset used in a MIPS jump instruction.  The offset
    381      1.83      matt  * contains the low 28 bits (allowing a jump to anywhere within the same 256MB
    382      1.83      matt  * segment of address space) of the address but since mips instructions are
    383      1.83      matt  * always on a 4 byte boundary the low 2 bits are always zero so the 28 bits
    384      1.83      matt  * get shifted right by 2 bits leaving us with a 26 bit result.  To make the
    385      1.83      matt  * offset, we shift left to clear the upper four bits and then right by 6.
    386      1.83      matt  */
    387      1.83      matt #define	fixup_addr2offset(x)	((((uint32_t)(uintptr_t)(x)) << 4) >> 6)
    388  1.93.2.1  jdolecek typedef bool (*mips_fixup_callback_t)(int32_t, uint32_t [2], void *);
    389      1.83      matt struct mips_jump_fixup_info {
    390      1.83      matt 	uint32_t jfi_stub;
    391      1.83      matt 	uint32_t jfi_real;
    392      1.83      matt };
    393      1.83      matt 
    394      1.83      matt void	fixup_splcalls(void);				/* splstubs.c */
    395  1.93.2.1  jdolecek bool	mips_fixup_exceptions(mips_fixup_callback_t, void *);
    396  1.93.2.1  jdolecek bool	mips_fixup_zero_relative(int32_t, uint32_t [2], void *);
    397      1.92      matt intptr_t
    398      1.92      matt 	mips_fixup_addr(const uint32_t *);
    399      1.83      matt void	mips_fixup_stubs(uint32_t *, uint32_t *);
    400      1.83      matt 
    401      1.83      matt /*
    402      1.83      matt  * Define these stubs...
    403      1.83      matt  */
    404      1.83      matt void	mips_cpu_switch_resume(struct lwp *);
    405      1.83      matt void	wbflush(void);
    406      1.77   tsutsui 
    407      1.59    simonb #ifdef MIPS1
    408      1.83      matt void	mips1_tlb_invalidate_all(void);
    409      1.38       cgd 
    410      1.58   thorpej uint32_t tx3900_cp0_config_read(void);
    411      1.59    simonb #endif
    412      1.38       cgd 
    413  1.93.2.1  jdolecek #ifdef MIPS3_PLUS
    414      1.59    simonb uint32_t mips3_cp0_compare_read(void);
    415      1.59    simonb void	mips3_cp0_compare_write(uint32_t);
    416      1.49       cgd 
    417      1.59    simonb uint32_t mips3_cp0_config_read(void);
    418      1.59    simonb void	mips3_cp0_config_write(uint32_t);
    419      1.86      matt 
    420  1.93.2.1  jdolecek #ifdef MIPSNN
    421      1.59    simonb uint32_t mipsNN_cp0_config1_read(void);
    422      1.59    simonb void	mipsNN_cp0_config1_write(uint32_t);
    423      1.63    simonb uint32_t mipsNN_cp0_config2_read(void);
    424      1.63    simonb uint32_t mipsNN_cp0_config3_read(void);
    425  1.93.2.1  jdolecek uint32_t mipsNN_cp0_config4_read(void);
    426  1.93.2.1  jdolecek uint32_t mipsNN_cp0_config5_read(void);
    427  1.93.2.1  jdolecek uint32_t mipsNN_cp0_config6_read(void);
    428  1.93.2.1  jdolecek uint32_t mipsNN_cp0_config7_read(void);
    429      1.85      matt 
    430      1.89      matt intptr_t mipsNN_cp0_watchlo_read(u_int);
    431      1.89      matt void	mipsNN_cp0_watchlo_write(u_int, intptr_t);
    432      1.87      matt uint32_t mipsNN_cp0_watchhi_read(u_int);
    433      1.87      matt void	mipsNN_cp0_watchhi_write(u_int, uint32_t);
    434      1.87      matt 
    435  1.93.2.1  jdolecek int32_t mipsNN_cp0_ebase_read(void);
    436  1.93.2.1  jdolecek void	mipsNN_cp0_ebase_write(int32_t);
    437  1.93.2.1  jdolecek 
    438  1.93.2.1  jdolecek #ifdef MIPSNNR2
    439      1.85      matt void	mipsNN_cp0_hwrena_write(uint32_t);
    440      1.85      matt void	mipsNN_cp0_userlocal_write(void *);
    441      1.85      matt #endif
    442  1.93.2.1  jdolecek #endif /* MIPSNN */
    443      1.59    simonb 
    444      1.59    simonb uint32_t mips3_cp0_count_read(void);
    445      1.59    simonb void	mips3_cp0_count_write(uint32_t);
    446      1.59    simonb 
    447      1.59    simonb uint32_t mips3_cp0_wired_read(void);
    448      1.59    simonb void	mips3_cp0_wired_write(uint32_t);
    449      1.69   tsutsui void	mips3_cp0_pg_mask_write(uint32_t);
    450      1.59    simonb 
    451  1.93.2.1  jdolecek #endif	/* MIPS3_PLUS */
    452      1.80      matt 
    453  1.93.2.1  jdolecek /* 64-bit address space accessor for n32, n64 ABI */
    454  1.93.2.1  jdolecek /* 32-bit address space accessor for o32 ABI */
    455  1.93.2.1  jdolecek static inline uint8_t	mips_lbu(register_t addr) __unused;
    456  1.93.2.1  jdolecek static inline void	mips_sb(register_t addr, uint8_t val) __unused;
    457  1.93.2.1  jdolecek static inline uint16_t	mips_lhu(register_t addr) __unused;
    458  1.93.2.1  jdolecek static inline void	mips_sh(register_t addr, uint16_t val) __unused;
    459  1.93.2.1  jdolecek static inline uint32_t	mips_lwu(register_t addr) __unused;
    460  1.93.2.1  jdolecek static inline void	mips_sw(register_t addr, uint32_t val) __unused;
    461  1.93.2.1  jdolecek #ifdef MIPS3_64BIT
    462  1.93.2.1  jdolecek #if defined(__mips_o32)
    463  1.93.2.1  jdolecek uint64_t		mips3_ld(register_t addr);
    464  1.93.2.1  jdolecek void			mips3_sd(register_t addr, uint64_t val);
    465      1.80      matt #else
    466  1.93.2.1  jdolecek static inline uint64_t	mips3_ld(register_t addr) __unused;
    467  1.93.2.1  jdolecek static inline void	mips3_sd(register_t addr, uint64_t val) __unused;
    468  1.93.2.1  jdolecek #endif
    469      1.80      matt #endif
    470      1.80      matt 
    471  1.93.2.1  jdolecek static inline uint8_t
    472  1.93.2.1  jdolecek mips_lbu(register_t addr)
    473  1.93.2.1  jdolecek {
    474  1.93.2.1  jdolecek 	uint8_t rv;
    475  1.93.2.1  jdolecek #if defined(__mips_n32)
    476  1.93.2.1  jdolecek 	__asm volatile("lbu\t%0, 0(%1)" : "=r"(rv) : "d"(addr));
    477  1.93.2.1  jdolecek #else
    478  1.93.2.1  jdolecek 	rv = *(const volatile uint8_t *)addr;
    479  1.93.2.1  jdolecek #endif
    480      1.80      matt 	return rv;
    481      1.80      matt }
    482      1.80      matt 
    483  1.93.2.1  jdolecek static inline uint16_t
    484  1.93.2.1  jdolecek mips_lhu(register_t addr)
    485  1.93.2.1  jdolecek {
    486  1.93.2.1  jdolecek 	uint16_t rv;
    487  1.93.2.1  jdolecek #if defined(__mips_n32)
    488  1.93.2.1  jdolecek 	__asm volatile("lhu\t%0, 0(%1)" : "=r"(rv) : "d"(addr));
    489      1.80      matt #else
    490  1.93.2.1  jdolecek 	rv = *(const volatile uint16_t *)addr;
    491      1.80      matt #endif
    492  1.93.2.1  jdolecek 	return rv;
    493      1.80      matt }
    494      1.59    simonb 
    495  1.93.2.1  jdolecek static inline uint32_t
    496  1.93.2.1  jdolecek mips_lwu(register_t addr)
    497      1.59    simonb {
    498      1.59    simonb 	uint32_t rv;
    499  1.93.2.1  jdolecek #if defined(__mips_n32)
    500  1.93.2.1  jdolecek 	__asm volatile("lwu\t%0, 0(%1)" : "=r"(rv) : "d"(addr));
    501  1.93.2.1  jdolecek #else
    502  1.93.2.1  jdolecek 	rv = *(const volatile uint32_t *)addr;
    503  1.93.2.1  jdolecek #endif
    504  1.93.2.1  jdolecek 	return (rv);
    505  1.93.2.1  jdolecek }
    506      1.59    simonb 
    507  1.93.2.1  jdolecek #if defined(MIPS3_64BIT) && !defined(__mips_o32)
    508  1.93.2.1  jdolecek static inline uint64_t
    509  1.93.2.1  jdolecek mips3_ld(register_t addr)
    510  1.93.2.1  jdolecek {
    511  1.93.2.1  jdolecek 	uint64_t rv;
    512  1.93.2.1  jdolecek #if defined(__mips_n32)
    513  1.93.2.1  jdolecek 	__asm volatile("ld\t%0, 0(%1)" : "=r"(rv) : "d"(addr));
    514      1.80      matt #elif defined(_LP64)
    515  1.93.2.1  jdolecek 	rv = *(const volatile uint64_t *)addr;
    516      1.80      matt #else
    517      1.83      matt #error unknown ABI
    518      1.80      matt #endif
    519      1.59    simonb 	return (rv);
    520      1.59    simonb }
    521  1.93.2.1  jdolecek #endif	/* MIPS3_64BIT && !__mips_o32 */
    522  1.93.2.1  jdolecek 
    523  1.93.2.1  jdolecek static inline void
    524  1.93.2.1  jdolecek mips_sb(register_t addr, uint8_t val)
    525  1.93.2.1  jdolecek {
    526  1.93.2.1  jdolecek #if defined(__mips_n32)
    527  1.93.2.1  jdolecek 	__asm volatile("sb\t%1, 0(%0)" :: "d"(addr), "r"(val));
    528  1.93.2.1  jdolecek #else
    529  1.93.2.1  jdolecek 	*(volatile uint8_t *)addr = val;
    530  1.93.2.1  jdolecek #endif
    531  1.93.2.1  jdolecek }
    532      1.59    simonb 
    533  1.93.2.1  jdolecek static inline void
    534  1.93.2.1  jdolecek mips_sh(register_t addr, uint16_t val)
    535      1.59    simonb {
    536  1.93.2.1  jdolecek #if defined(__mips_n32)
    537  1.93.2.1  jdolecek 	__asm volatile("sh\t%1, 0(%0)" :: "d"(addr), "r"(val));
    538  1.93.2.1  jdolecek #else
    539  1.93.2.1  jdolecek 	*(volatile uint16_t *)addr = val;
    540  1.93.2.1  jdolecek #endif
    541  1.93.2.1  jdolecek }
    542      1.59    simonb 
    543  1.93.2.1  jdolecek static inline void
    544  1.93.2.1  jdolecek mips_sw(register_t addr, uint32_t val)
    545  1.93.2.1  jdolecek {
    546  1.93.2.1  jdolecek #if defined(__mips_n32)
    547  1.93.2.1  jdolecek 	__asm volatile("sw\t%1, 0(%0)" :: "d"(addr), "r"(val));
    548  1.93.2.1  jdolecek #else
    549  1.93.2.1  jdolecek 	*(volatile uint32_t *)addr = val;
    550  1.93.2.1  jdolecek #endif
    551  1.93.2.1  jdolecek }
    552      1.59    simonb 
    553  1.93.2.1  jdolecek #if defined(MIPS3_64BIT) && !defined(__mips_o32)
    554  1.93.2.1  jdolecek static inline void
    555  1.93.2.1  jdolecek mips3_sd(register_t addr, uint64_t val)
    556  1.93.2.1  jdolecek {
    557  1.93.2.1  jdolecek #if defined(__mips_n32)
    558  1.93.2.1  jdolecek 	__asm volatile("sd\t%1, 0(%0)" :: "d"(addr), "r"(val));
    559      1.80      matt #else
    560  1.93.2.1  jdolecek 	*(volatile uint64_t *)addr = val;
    561      1.80      matt #endif
    562      1.59    simonb }
    563  1.93.2.1  jdolecek #endif	/* MIPS3_64BIT && !__mips_o32 */
    564       1.7  jonathan 
    565       1.1  jonathan /*
    566      1.58   thorpej  * A vector with an entry for each mips-ISA-level dependent
    567       1.1  jonathan  * locore function, and macros which jump through it.
    568       1.1  jonathan  */
    569       1.1  jonathan typedef struct  {
    570      1.83      matt 	void	(*ljv_cpu_switch_resume)(struct lwp *);
    571      1.83      matt 	intptr_t ljv_lwp_trampoline;
    572      1.83      matt 	void	(*ljv_wbflush)(void);
    573  1.93.2.1  jdolecek 	tlb_asid_t (*ljv_tlb_get_asid)(void);
    574  1.93.2.1  jdolecek 	void	(*ljv_tlb_set_asid)(tlb_asid_t pid);
    575  1.93.2.1  jdolecek 	void	(*ljv_tlb_invalidate_asids)(tlb_asid_t, tlb_asid_t);
    576  1.93.2.1  jdolecek 	void	(*ljv_tlb_invalidate_addr)(vaddr_t, tlb_asid_t);
    577      1.83      matt 	void	(*ljv_tlb_invalidate_globals)(void);
    578      1.83      matt 	void	(*ljv_tlb_invalidate_all)(void);
    579  1.93.2.1  jdolecek 	u_int	(*ljv_tlb_record_asids)(u_long *, tlb_asid_t);
    580  1.93.2.1  jdolecek 	int	(*ljv_tlb_update_addr)(vaddr_t, tlb_asid_t, pt_entry_t, bool);
    581  1.93.2.1  jdolecek 	void	(*ljv_tlb_read_entry)(size_t, struct tlbmask *);
    582  1.93.2.1  jdolecek 	void	(*ljv_tlb_write_entry)(size_t, const struct tlbmask *);
    583       1.1  jonathan } mips_locore_jumpvec_t;
    584      1.13  jonathan 
    585      1.83      matt typedef struct {
    586      1.83      matt 	u_int	(*lav_atomic_cas_uint)(volatile u_int *, u_int, u_int);
    587      1.83      matt 	u_long	(*lav_atomic_cas_ulong)(volatile u_long *, u_long, u_long);
    588      1.83      matt 	int	(*lav_ucas_uint)(volatile u_int *, u_int, u_int, u_int *);
    589      1.83      matt 	int	(*lav_ucas_ulong)(volatile u_long *, u_long, u_long, u_long *);
    590      1.83      matt 	void	(*lav_mutex_enter)(kmutex_t *);
    591      1.83      matt 	void	(*lav_mutex_exit)(kmutex_t *);
    592      1.83      matt 	void	(*lav_mutex_spin_enter)(kmutex_t *);
    593      1.83      matt 	void	(*lav_mutex_spin_exit)(kmutex_t *);
    594      1.83      matt } mips_locore_atomicvec_t;
    595      1.83      matt 
    596      1.38       cgd void	mips_set_wbflush(void (*)(void));
    597      1.62    simonb void	mips_wait_idle(void);
    598       1.1  jonathan 
    599      1.38       cgd void	stacktrace(void);
    600      1.38       cgd void	logstacktrace(void);
    601       1.1  jonathan 
    602      1.83      matt struct cpu_info;
    603      1.83      matt struct splsw;
    604      1.83      matt 
    605      1.80      matt struct locoresw {
    606      1.83      matt 	void		(*lsw_wbflush)(void);
    607      1.83      matt 	void		(*lsw_cpu_idle)(void);
    608      1.83      matt 	int		(*lsw_send_ipi)(struct cpu_info *, int);
    609      1.83      matt 	void		(*lsw_cpu_offline_md)(void);
    610      1.83      matt 	void		(*lsw_cpu_init)(struct cpu_info *);
    611      1.88     cliff 	void		(*lsw_cpu_run)(struct cpu_info *);
    612      1.83      matt 	int		(*lsw_bus_error)(unsigned int);
    613      1.83      matt };
    614      1.83      matt 
    615      1.83      matt struct mips_vmfreelist {
    616      1.83      matt 	paddr_t fl_start;
    617      1.83      matt 	paddr_t fl_end;
    618      1.83      matt 	int fl_freelist;
    619      1.80      matt };
    620      1.80      matt 
    621  1.93.2.1  jdolecek struct cpu_info *
    622  1.93.2.1  jdolecek 	cpu_info_alloc(struct pmap_tlb_info *, cpuid_t, cpuid_t, cpuid_t,
    623  1.93.2.1  jdolecek 	    cpuid_t);
    624  1.93.2.1  jdolecek void	cpu_attach_common(device_t, struct cpu_info *);
    625  1.93.2.1  jdolecek void	cpu_startup_common(void);
    626  1.93.2.1  jdolecek 
    627  1.93.2.1  jdolecek #ifdef MULTIPROCESSOR
    628  1.93.2.1  jdolecek void	cpu_hatch(struct cpu_info *ci);
    629  1.93.2.1  jdolecek void	cpu_trampoline(void);
    630  1.93.2.1  jdolecek void	cpu_halt(void);
    631  1.93.2.1  jdolecek void	cpu_halt_others(void);
    632  1.93.2.1  jdolecek void	cpu_pause(struct reg *);
    633  1.93.2.1  jdolecek void	cpu_pause_others(void);
    634  1.93.2.1  jdolecek void	cpu_resume(cpuid_t);
    635  1.93.2.1  jdolecek void	cpu_resume_others(void);
    636  1.93.2.1  jdolecek bool	cpu_is_paused(cpuid_t);
    637  1.93.2.1  jdolecek void	cpu_debug_dump(void);
    638  1.93.2.1  jdolecek 
    639  1.93.2.1  jdolecek extern kcpuset_t *cpus_running;
    640  1.93.2.1  jdolecek extern kcpuset_t *cpus_hatched;
    641  1.93.2.1  jdolecek extern kcpuset_t *cpus_paused;
    642  1.93.2.1  jdolecek extern kcpuset_t *cpus_resumed;
    643  1.93.2.1  jdolecek extern kcpuset_t *cpus_halted;
    644  1.93.2.1  jdolecek #endif
    645  1.93.2.1  jdolecek 
    646  1.93.2.1  jdolecek /* copy.S */
    647  1.93.2.1  jdolecek int32_t kfetch_32(volatile uint32_t *, uint32_t);
    648  1.93.2.1  jdolecek int8_t	ufetch_int8(void *);
    649  1.93.2.1  jdolecek int16_t	ufetch_int16(void *);
    650  1.93.2.1  jdolecek int32_t ufetch_int32(void *);
    651  1.93.2.1  jdolecek uint8_t	ufetch_uint8(void *);
    652  1.93.2.1  jdolecek uint16_t ufetch_uint16(void *);
    653  1.93.2.1  jdolecek uint32_t ufetch_uint32(void *);
    654  1.93.2.1  jdolecek int8_t	ufetch_int8_intrsafe(void *);
    655  1.93.2.1  jdolecek int16_t	ufetch_int16_intrsafe(void *);
    656  1.93.2.1  jdolecek int32_t ufetch_int32_intrsafe(void *);
    657  1.93.2.1  jdolecek uint8_t	ufetch_uint8_intrsafe(void *);
    658  1.93.2.1  jdolecek uint16_t ufetch_uint16_intrsafe(void *);
    659  1.93.2.1  jdolecek uint32_t ufetch_uint32_intrsafe(void *);
    660  1.93.2.1  jdolecek #ifdef _LP64
    661  1.93.2.1  jdolecek int64_t ufetch_int64(void *);
    662  1.93.2.1  jdolecek uint64_t ufetch_uint64(void *);
    663  1.93.2.1  jdolecek int64_t ufetch_int64_intrsafe(void *);
    664  1.93.2.1  jdolecek uint64_t ufetch_uint64_intrsafe(void *);
    665  1.93.2.1  jdolecek #endif
    666  1.93.2.1  jdolecek char	ufetch_char(void *);
    667  1.93.2.1  jdolecek short	ufetch_short(void *);
    668  1.93.2.1  jdolecek int	ufetch_int(void *);
    669  1.93.2.1  jdolecek long	ufetch_long(void *);
    670  1.93.2.1  jdolecek char	ufetch_char_intrsafe(void *);
    671  1.93.2.1  jdolecek short	ufetch_short_intrsafe(void *);
    672  1.93.2.1  jdolecek int	ufetch_int_intrsafe(void *);
    673  1.93.2.1  jdolecek long	ufetch_long_intrsafe(void *);
    674  1.93.2.1  jdolecek 
    675  1.93.2.1  jdolecek u_char	ufetch_uchar(void *);
    676  1.93.2.1  jdolecek u_short	ufetch_ushort(void *);
    677  1.93.2.1  jdolecek u_int	ufetch_uint(void *);
    678  1.93.2.1  jdolecek u_long	ufetch_ulong(void *);
    679  1.93.2.1  jdolecek u_char	ufetch_uchar_intrsafe(void *);
    680  1.93.2.1  jdolecek u_short	ufetch_ushort_intrsafe(void *);
    681  1.93.2.1  jdolecek u_int	ufetch_uint_intrsafe(void *);
    682  1.93.2.1  jdolecek u_long	ufetch_ulong_intrsafe(void *);
    683  1.93.2.1  jdolecek void 	*ufetch_ptr(void *);
    684  1.93.2.1  jdolecek 
    685  1.93.2.1  jdolecek int	ustore_int8(void *, int8_t);
    686  1.93.2.1  jdolecek int	ustore_int16(void *, int16_t);
    687  1.93.2.1  jdolecek int	ustore_int32(void *, int32_t);
    688  1.93.2.1  jdolecek int	ustore_uint8(void *, uint8_t);
    689  1.93.2.1  jdolecek int	ustore_uint16(void *, uint16_t);
    690  1.93.2.1  jdolecek int	ustore_uint32(void *, uint32_t);
    691  1.93.2.1  jdolecek int	ustore_int8_intrsafe(void *, int8_t);
    692  1.93.2.1  jdolecek int	ustore_int16_intrsafe(void *, int16_t);
    693  1.93.2.1  jdolecek int	ustore_int32_intrsafe(void *, int32_t);
    694  1.93.2.1  jdolecek int	ustore_uint8_intrsafe(void *, uint8_t);
    695  1.93.2.1  jdolecek int	ustore_uint16_intrsafe(void *, uint16_t);
    696  1.93.2.1  jdolecek int	ustore_uint32_intrsafe(void *, uint32_t);
    697  1.93.2.1  jdolecek #ifdef _LP64
    698  1.93.2.1  jdolecek int	ustore_int64(void *, int64_t);
    699  1.93.2.1  jdolecek int	ustore_uint64(void *, uint64_t);
    700  1.93.2.1  jdolecek int	ustore_int64_intrsafe(void *, int64_t);
    701  1.93.2.1  jdolecek int	ustore_uint64_intrsafe(void *, uint64_t);
    702  1.93.2.1  jdolecek #endif
    703  1.93.2.1  jdolecek int	ustore_char(void *, char);
    704  1.93.2.1  jdolecek int	ustore_char_intrsafe(void *, char);
    705  1.93.2.1  jdolecek int	ustore_short(void *, short);
    706  1.93.2.1  jdolecek int	ustore_short_intrsafe(void *, short);
    707  1.93.2.1  jdolecek int	ustore_int(void *, int);
    708  1.93.2.1  jdolecek int	ustore_int_intrsafe(void *, int);
    709  1.93.2.1  jdolecek int	ustore_long(void *, long);
    710  1.93.2.1  jdolecek int	ustore_long_intrsafe(void *, long);
    711  1.93.2.1  jdolecek int	ustore_uchar(void *, u_char);
    712  1.93.2.1  jdolecek int	ustore_uchar_intrsafe(void *, u_char);
    713  1.93.2.1  jdolecek int	ustore_ushort(void *, u_short);
    714  1.93.2.1  jdolecek int	ustore_ushort_intrsafe(void *, u_short);
    715  1.93.2.1  jdolecek int	ustore_uint(void *, u_int);
    716  1.93.2.1  jdolecek int	ustore_uint_intrsafe(void *, u_int);
    717  1.93.2.1  jdolecek int	ustore_ulong(void *, u_long);
    718  1.93.2.1  jdolecek int	ustore_ulong_intrsafe(void *, u_long);
    719  1.93.2.1  jdolecek int 	ustore_ptr(void *, void *);
    720  1.93.2.1  jdolecek int	ustore_ptr_intrsafe(void *, void *);
    721  1.93.2.1  jdolecek 
    722  1.93.2.1  jdolecek int	ustore_uint32_isync(void *, uint32_t);
    723  1.93.2.1  jdolecek 
    724  1.93.2.1  jdolecek /* trap.c */
    725  1.93.2.1  jdolecek void	netintr(void);
    726  1.93.2.1  jdolecek int	kdbpeek(vaddr_t);
    727  1.93.2.1  jdolecek 
    728  1.93.2.1  jdolecek /* mips_dsp.c */
    729  1.93.2.1  jdolecek void	dsp_init(void);
    730  1.93.2.1  jdolecek void	dsp_discard(lwp_t *);
    731  1.93.2.1  jdolecek void	dsp_load(void);
    732  1.93.2.1  jdolecek void	dsp_save(lwp_t *);
    733  1.93.2.1  jdolecek bool	dsp_used_p(const lwp_t *);
    734  1.93.2.1  jdolecek extern const pcu_ops_t mips_dsp_ops;
    735  1.93.2.1  jdolecek 
    736  1.93.2.1  jdolecek /* mips_fpu.c */
    737  1.93.2.1  jdolecek void	fpu_init(void);
    738  1.93.2.1  jdolecek void	fpu_discard(lwp_t *);
    739  1.93.2.1  jdolecek void	fpu_load(void);
    740  1.93.2.1  jdolecek void	fpu_save(lwp_t *);
    741  1.93.2.1  jdolecek bool	fpu_used_p(const lwp_t *);
    742  1.93.2.1  jdolecek extern const pcu_ops_t mips_fpu_ops;
    743  1.93.2.1  jdolecek 
    744  1.93.2.1  jdolecek /* mips_machdep.c */
    745  1.93.2.1  jdolecek void	dumpsys(void);
    746  1.93.2.1  jdolecek int	savectx(struct pcb *);
    747  1.93.2.1  jdolecek void	cpu_identify(device_t);
    748  1.93.2.1  jdolecek 
    749  1.93.2.1  jdolecek /* locore*.S */
    750  1.93.2.1  jdolecek int	badaddr(void *, size_t);
    751  1.93.2.1  jdolecek int	badaddr64(uint64_t, size_t);
    752  1.93.2.1  jdolecek 
    753  1.93.2.1  jdolecek /* vm_machdep.c */
    754  1.93.2.1  jdolecek int	ioaccess(vaddr_t, paddr_t, vsize_t);
    755  1.93.2.1  jdolecek int	iounaccess(vaddr_t, vsize_t);
    756  1.93.2.1  jdolecek 
    757       1.1  jonathan /*
    758      1.81       snj  * The "active" locore-function vector, and
    759       1.1  jonathan  */
    760      1.83      matt extern const mips_locore_atomicvec_t mips_llsc_locore_atomicvec;
    761      1.83      matt 
    762      1.83      matt extern mips_locore_atomicvec_t mips_locore_atomicvec;
    763       1.1  jonathan extern mips_locore_jumpvec_t mips_locore_jumpvec;
    764      1.80      matt extern struct locoresw mips_locoresw;
    765       1.1  jonathan 
    766  1.93.2.1  jdolecek extern int mips_poolpage_vmfreelist;	/* freelist to allocate poolpages */
    767  1.93.2.1  jdolecek extern struct mips_options mips_options;
    768  1.93.2.1  jdolecek 
    769      1.83      matt struct splsw;
    770      1.83      matt struct mips_vmfreelist;
    771      1.83      matt struct phys_ram_seg;
    772      1.83      matt 
    773  1.93.2.1  jdolecek void	mips64r2_vector_init(const struct splsw *);
    774      1.83      matt void	mips_vector_init(const struct splsw *, bool);
    775      1.83      matt void	mips_init_msgbuf(void);
    776      1.83      matt void	mips_init_lwp0_uarea(void);
    777      1.83      matt void	mips_page_physload(vaddr_t, vaddr_t,
    778      1.83      matt 	    const struct phys_ram_seg *, size_t,
    779      1.83      matt 	    const struct mips_vmfreelist *, size_t);
    780      1.11  jonathan 
    781       1.7  jonathan 
    782       1.7  jonathan /*
    783       1.7  jonathan  * CPU identification, from PRID register.
    784       1.7  jonathan  */
    785      1.70   tsutsui #define MIPS_PRID_REV(x)	(((x) >>  0) & 0x00ff)
    786      1.70   tsutsui #define MIPS_PRID_IMPL(x)	(((x) >>  8) & 0x00ff)
    787      1.45       cgd 
    788      1.59    simonb /* pre-MIPS32/64 */
    789      1.70   tsutsui #define MIPS_PRID_RSVD(x)	(((x) >> 16) & 0xffff)
    790      1.70   tsutsui #define MIPS_PRID_REV_MIN(x)	((MIPS_PRID_REV(x) >> 0) & 0x0f)
    791      1.70   tsutsui #define MIPS_PRID_REV_MAJ(x)	((MIPS_PRID_REV(x) >> 4) & 0x0f)
    792      1.45       cgd 
    793      1.59    simonb /* MIPS32/64 */
    794      1.70   tsutsui #define MIPS_PRID_CID(x)	(((x) >> 16) & 0x00ff)	/* Company ID */
    795      1.70   tsutsui #define     MIPS_PRID_CID_PREHISTORIC	0x00	/* Not MIPS32/64 */
    796      1.70   tsutsui #define     MIPS_PRID_CID_MTI		0x01	/* MIPS Technologies, Inc. */
    797      1.70   tsutsui #define     MIPS_PRID_CID_BROADCOM	0x02	/* Broadcom */
    798      1.70   tsutsui #define     MIPS_PRID_CID_ALCHEMY	0x03	/* Alchemy Semiconductor */
    799      1.70   tsutsui #define     MIPS_PRID_CID_SIBYTE	0x04	/* SiByte */
    800      1.70   tsutsui #define     MIPS_PRID_CID_SANDCRAFT	0x05	/* SandCraft */
    801      1.70   tsutsui #define     MIPS_PRID_CID_PHILIPS	0x06	/* Philips */
    802      1.70   tsutsui #define     MIPS_PRID_CID_TOSHIBA	0x07	/* Toshiba */
    803      1.82     pooka #define     MIPS_PRID_CID_MICROSOFT	0x07	/* Microsoft also, sigh */
    804      1.70   tsutsui #define     MIPS_PRID_CID_LSI		0x08	/* LSI */
    805      1.67    simonb 				/*	0x09	unannounced */
    806      1.67    simonb 				/*	0x0a	unannounced */
    807      1.70   tsutsui #define     MIPS_PRID_CID_LEXRA		0x0b	/* Lexra */
    808      1.80      matt #define     MIPS_PRID_CID_RMI		0x0c	/* RMI / NetLogic */
    809  1.93.2.1  jdolecek #define     MIPS_PRID_CID_CAVIUM	0x0d	/* Cavium */
    810  1.93.2.1  jdolecek #define     MIPS_PRID_CID_INGENIC	0xe1
    811      1.70   tsutsui #define MIPS_PRID_COPTS(x)	(((x) >> 24) & 0x00ff)	/* Company Options */
    812       1.6  jonathan 
    813       1.6  jonathan #ifdef _KERNEL
    814       1.6  jonathan /*
    815       1.6  jonathan  * Global variables used to communicate CPU type, and parameters
    816       1.6  jonathan  * such as cache size, from locore to higher-level code (e.g., pmap).
    817       1.6  jonathan  */
    818  1.93.2.1  jdolecek void mips_pagecopy(register_t dst, register_t src);
    819  1.93.2.1  jdolecek void mips_pagezero(register_t dst);
    820      1.19  jonathan 
    821      1.59    simonb #ifdef __HAVE_MIPS_MACHDEP_CACHE_CONFIG
    822      1.59    simonb void mips_machdep_cache_config(void);
    823      1.59    simonb #endif
    824      1.59    simonb 
    825      1.19  jonathan /*
    826      1.20    simonb  * trapframe argument passed to trap()
    827      1.19  jonathan  */
    828      1.64   thorpej 
    829      1.83      matt #if 0
    830      1.83      matt #define TF_AST		0		/* really zero */
    831      1.83      matt #define TF_V0		_R_V0
    832      1.83      matt #define TF_V1		_R_V1
    833      1.83      matt #define TF_A0		_R_A0
    834      1.83      matt #define TF_A1		_R_A1
    835      1.83      matt #define TF_A2		_R_A2
    836      1.83      matt #define TF_A3		_R_A3
    837      1.83      matt #define TF_T0		_R_T0
    838      1.83      matt #define TF_T1		_R_T1
    839      1.83      matt #define TF_T2		_R_T2
    840      1.83      matt #define TF_T3		_R_T3
    841      1.64   thorpej 
    842      1.64   thorpej #if defined(__mips_n32) || defined(__mips_n64)
    843      1.83      matt #define TF_A4		_R_A4
    844      1.83      matt #define TF_A5		_R_A5
    845      1.83      matt #define TF_A6		_R_A6
    846      1.83      matt #define TF_A7		_R_A7
    847      1.64   thorpej #else
    848      1.83      matt #define TF_T4		_R_T4
    849      1.83      matt #define TF_T5		_R_T5
    850      1.83      matt #define TF_T6		_R_T6
    851      1.83      matt #define TF_T7		_R_T7
    852      1.64   thorpej #endif /* __mips_n32 || __mips_n64 */
    853      1.64   thorpej 
    854      1.83      matt #define TF_TA0		_R_TA0
    855      1.83      matt #define TF_TA1		_R_TA1
    856      1.83      matt #define TF_TA2		_R_TA2
    857      1.83      matt #define TF_TA3		_R_TA3
    858      1.83      matt 
    859      1.83      matt #define TF_T8		_R_T8
    860      1.83      matt #define TF_T9		_R_T9
    861      1.83      matt 
    862      1.83      matt #define TF_RA		_R_RA
    863      1.83      matt #define TF_SR		_R_SR
    864      1.83      matt #define TF_MULLO	_R_MULLO
    865      1.83      matt #define TF_MULHI	_R_MULLO
    866      1.83      matt #define TF_EPC		_R_PC		/* may be changed by trap() call */
    867      1.65   thorpej 
    868      1.83      matt #define	TF_NREGS	(sizeof(struct reg) / sizeof(mips_reg_t))
    869      1.83      matt #endif
    870      1.64   thorpej 
    871      1.19  jonathan struct trapframe {
    872      1.83      matt 	struct reg tf_registers;
    873      1.83      matt #define	tf_regs	tf_registers.r_regs
    874      1.80      matt 	uint32_t   tf_ppl;		/* previous priority level */
    875      1.80      matt 	mips_reg_t tf_pad;		/* for 8 byte aligned */
    876      1.19  jonathan };
    877      1.19  jonathan 
    878      1.83      matt CTASSERT(sizeof(struct trapframe) % (4*sizeof(mips_reg_t)) == 0);
    879      1.83      matt 
    880      1.19  jonathan /*
    881      1.19  jonathan  * Stack frame for kernel traps. four args passed in registers.
    882      1.19  jonathan  * A trapframe is pointed to by the 5th arg, and a dummy sixth argument
    883      1.19  jonathan  * is used to avoid alignment problems
    884      1.19  jonathan  */
    885      1.19  jonathan 
    886      1.19  jonathan struct kernframe {
    887      1.80      matt #if defined(__mips_o32) || defined(__mips_o64)
    888      1.19  jonathan 	register_t cf_args[4 + 1];
    889      1.80      matt #if defined(__mips_o32)
    890      1.83      matt 	register_t cf_pad;		/* (for 8 byte alignment) */
    891      1.80      matt #endif
    892      1.80      matt #endif
    893      1.80      matt #if defined(__mips_n32) || defined(__mips_n64)
    894      1.80      matt 	register_t cf_pad[2];		/* for 16 byte alignment */
    895      1.80      matt #endif
    896      1.19  jonathan 	register_t cf_sp;
    897      1.19  jonathan 	register_t cf_ra;
    898      1.19  jonathan 	struct trapframe cf_frame;
    899      1.19  jonathan };
    900      1.83      matt 
    901      1.83      matt CTASSERT(sizeof(struct kernframe) % (2*sizeof(mips_reg_t)) == 0);
    902      1.83      matt 
    903      1.83      matt /*
    904      1.83      matt  * PRocessor IDentity TABle
    905      1.83      matt  */
    906      1.83      matt 
    907      1.83      matt struct pridtab {
    908      1.83      matt 	int	cpu_cid;
    909      1.83      matt 	int	cpu_pid;
    910      1.83      matt 	int	cpu_rev;	/* -1 == wildcard */
    911      1.83      matt 	int	cpu_copts;	/* -1 == wildcard */
    912      1.83      matt 	int	cpu_isa;	/* -1 == probed (mips32/mips64) */
    913      1.83      matt 	int	cpu_ntlb;	/* -1 == unknown, 0 == probed */
    914      1.83      matt 	int	cpu_flags;
    915      1.83      matt 	u_int	cpu_cp0flags;	/* presence of some cp0 regs */
    916      1.83      matt 	u_int	cpu_cidflags;	/* company-specific flags */
    917      1.83      matt 	const char	*cpu_name;
    918      1.83      matt };
    919      1.83      matt 
    920      1.83      matt /*
    921      1.83      matt  * bitfield defines for cpu_cp0flags
    922      1.83      matt  */
    923      1.83      matt #define  MIPS_CP0FL_USE		__BIT(0)	/* use these flags */
    924      1.83      matt #define  MIPS_CP0FL_ECC		__BIT(1)
    925      1.83      matt #define  MIPS_CP0FL_CACHE_ERR	__BIT(2)
    926      1.83      matt #define  MIPS_CP0FL_EIRR	__BIT(3)
    927      1.83      matt #define  MIPS_CP0FL_EIMR	__BIT(4)
    928      1.83      matt #define  MIPS_CP0FL_EBASE	__BIT(5)
    929      1.83      matt #define  MIPS_CP0FL_CONFIG	__BIT(6)
    930      1.84      matt #define  MIPS_CP0FL_CONFIG1	__BIT(7)
    931      1.84      matt #define  MIPS_CP0FL_CONFIG2	__BIT(8)
    932      1.84      matt #define  MIPS_CP0FL_CONFIG3	__BIT(9)
    933      1.84      matt #define  MIPS_CP0FL_CONFIG4	__BIT(10)
    934      1.84      matt #define  MIPS_CP0FL_CONFIG5	__BIT(11)
    935      1.84      matt #define  MIPS_CP0FL_CONFIG6	__BIT(12)
    936      1.84      matt #define  MIPS_CP0FL_CONFIG7	__BIT(13)
    937      1.84      matt #define  MIPS_CP0FL_USERLOCAL	__BIT(14)
    938      1.84      matt #define  MIPS_CP0FL_HWRENA	__BIT(15)
    939      1.83      matt 
    940      1.83      matt /*
    941      1.83      matt  * cpu_cidflags defines, by company
    942      1.83      matt  */
    943      1.83      matt /*
    944      1.83      matt  * RMI company-specific cpu_cidflags
    945      1.83      matt  */
    946      1.84      matt #define MIPS_CIDFL_RMI_TYPE		__BITS(2,0)
    947      1.84      matt # define  CIDFL_RMI_TYPE_XLR		0
    948      1.84      matt # define  CIDFL_RMI_TYPE_XLS		1
    949      1.84      matt # define  CIDFL_RMI_TYPE_XLP		2
    950      1.83      matt #define MIPS_CIDFL_RMI_THREADS_MASK	__BITS(6,3)
    951      1.83      matt # define MIPS_CIDFL_RMI_THREADS_SHIFT	3
    952      1.83      matt #define MIPS_CIDFL_RMI_CORES_MASK	__BITS(10,7)
    953      1.83      matt # define MIPS_CIDFL_RMI_CORES_SHIFT	7
    954      1.83      matt # define LOG2_1	0
    955      1.83      matt # define LOG2_2	1
    956      1.83      matt # define LOG2_4	2
    957      1.83      matt # define LOG2_8	3
    958      1.83      matt # define MIPS_CIDFL_RMI_CPUS(ncores, nthreads)				\
    959      1.83      matt 		((LOG2_ ## ncores << MIPS_CIDFL_RMI_CORES_SHIFT)	\
    960      1.83      matt 		|(LOG2_ ## nthreads << MIPS_CIDFL_RMI_THREADS_SHIFT))
    961      1.83      matt # define MIPS_CIDFL_RMI_NTHREADS(cidfl)					\
    962      1.83      matt 		(1 << (((cidfl) & MIPS_CIDFL_RMI_THREADS_MASK)		\
    963      1.83      matt 			>> MIPS_CIDFL_RMI_THREADS_SHIFT))
    964      1.83      matt # define MIPS_CIDFL_RMI_NCORES(cidfl)					\
    965      1.83      matt 		(1 << (((cidfl) & MIPS_CIDFL_RMI_CORES_MASK)		\
    966      1.83      matt 			>> MIPS_CIDFL_RMI_CORES_SHIFT))
    967      1.83      matt #define MIPS_CIDFL_RMI_L2SZ_MASK	__BITS(14,11)
    968      1.83      matt # define MIPS_CIDFL_RMI_L2SZ_SHIFT	11
    969      1.83      matt # define RMI_L2SZ_256KB	 0
    970      1.83      matt # define RMI_L2SZ_512KB  1
    971      1.83      matt # define RMI_L2SZ_1MB    2
    972      1.83      matt # define RMI_L2SZ_2MB    3
    973      1.83      matt # define RMI_L2SZ_4MB    4
    974      1.83      matt # define MIPS_CIDFL_RMI_L2(l2sz)					\
    975      1.83      matt 		(RMI_L2SZ_ ## l2sz << MIPS_CIDFL_RMI_L2SZ_SHIFT)
    976      1.83      matt # define MIPS_CIDFL_RMI_L2SZ(cidfl)					\
    977      1.83      matt 		((256*1024) << (((cidfl) & MIPS_CIDFL_RMI_L2SZ_MASK)	\
    978      1.83      matt 			>> MIPS_CIDFL_RMI_L2SZ_SHIFT))
    979  1.93.2.1  jdolecek #endif /* !__ASSEMBLER__ */
    980      1.61    simonb #endif	/* _KERNEL */
    981  1.93.2.1  jdolecek 
    982       1.1  jonathan #endif	/* _MIPS_LOCORE_H */
    983