Home | History | Annotate | Line # | Download | only in include
locore.h revision 1.81.4.1
      1  1.81.4.1    jruoho /* $NetBSD: locore.h,v 1.81.4.1 2011/06/06 09:06:03 jruoho Exp $ */
      2  1.81.4.1    jruoho 
      3  1.81.4.1    jruoho /*
      4  1.81.4.1    jruoho  * This file should not be included by MI code!!!
      5  1.81.4.1    jruoho  */
      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.17    castor #ifndef _LKM
     32      1.32     soren #include "opt_cputype.h"
     33      1.17    castor #endif
     34      1.16    castor 
     35  1.81.4.1    jruoho #include <mips/mutex.h>
     36      1.59    simonb #include <mips/cpuregs.h>
     37  1.81.4.1    jruoho #include <mips/reg.h>
     38  1.81.4.1    jruoho 
     39  1.81.4.1    jruoho struct tlbmask;
     40  1.81.4.1    jruoho struct trapframe;
     41      1.59    simonb 
     42  1.81.4.1    jruoho void	trap(uint32_t, uint32_t, vaddr_t, vaddr_t, struct trapframe *);
     43  1.81.4.1    jruoho void	ast(void);
     44  1.81.4.1    jruoho 
     45  1.81.4.1    jruoho void	mips_fpu_trap(vaddr_t, struct trapframe *);
     46  1.81.4.1    jruoho void	mips_fpu_intr(vaddr_t, struct trapframe *);
     47  1.81.4.1    jruoho 
     48  1.81.4.1    jruoho vaddr_t mips_emul_branch(struct trapframe *, vaddr_t, uint32_t, bool);
     49  1.81.4.1    jruoho void	mips_emul_inst(uint32_t, uint32_t, vaddr_t, struct trapframe *);
     50  1.81.4.1    jruoho 
     51  1.81.4.1    jruoho void	mips_emul_fp(uint32_t, struct trapframe *, uint32_t);
     52  1.81.4.1    jruoho void	mips_emul_branchdelayslot(uint32_t, struct trapframe *, uint32_t);
     53  1.81.4.1    jruoho 
     54  1.81.4.1    jruoho void	mips_emul_lwc0(uint32_t, struct trapframe *, uint32_t);
     55  1.81.4.1    jruoho void	mips_emul_swc0(uint32_t, struct trapframe *, uint32_t);
     56  1.81.4.1    jruoho void	mips_emul_special(uint32_t, struct trapframe *, uint32_t);
     57  1.81.4.1    jruoho void	mips_emul_special3(uint32_t, struct trapframe *, uint32_t);
     58  1.81.4.1    jruoho 
     59  1.81.4.1    jruoho void	mips_emul_lwc1(uint32_t, struct trapframe *, uint32_t);
     60  1.81.4.1    jruoho void	mips_emul_swc1(uint32_t, struct trapframe *, uint32_t);
     61  1.81.4.1    jruoho void	mips_emul_ldc1(uint32_t, struct trapframe *, uint32_t);
     62  1.81.4.1    jruoho void	mips_emul_sdc1(uint32_t, struct trapframe *, uint32_t);
     63  1.81.4.1    jruoho 
     64  1.81.4.1    jruoho void	mips_emul_lb(uint32_t, struct trapframe *, uint32_t);
     65  1.81.4.1    jruoho void	mips_emul_lbu(uint32_t, struct trapframe *, uint32_t);
     66  1.81.4.1    jruoho void	mips_emul_lh(uint32_t, struct trapframe *, uint32_t);
     67  1.81.4.1    jruoho void	mips_emul_lhu(uint32_t, struct trapframe *, uint32_t);
     68  1.81.4.1    jruoho void	mips_emul_lw(uint32_t, struct trapframe *, uint32_t);
     69  1.81.4.1    jruoho void	mips_emul_lwl(uint32_t, struct trapframe *, uint32_t);
     70  1.81.4.1    jruoho void	mips_emul_lwr(uint32_t, struct trapframe *, uint32_t);
     71  1.81.4.1    jruoho #if defined(__mips_n32) || defined(__mips_n64) || defined(__mips_o64)
     72  1.81.4.1    jruoho void	mips_emul_lwu(uint32_t, struct trapframe *, uint32_t);
     73  1.81.4.1    jruoho void	mips_emul_ld(uint32_t, struct trapframe *, uint32_t);
     74  1.81.4.1    jruoho void	mips_emul_ldl(uint32_t, struct trapframe *, uint32_t);
     75  1.81.4.1    jruoho void	mips_emul_ldr(uint32_t, struct trapframe *, uint32_t);
     76  1.81.4.1    jruoho #endif
     77  1.81.4.1    jruoho void	mips_emul_sb(uint32_t, struct trapframe *, uint32_t);
     78  1.81.4.1    jruoho void	mips_emul_sh(uint32_t, struct trapframe *, uint32_t);
     79  1.81.4.1    jruoho void	mips_emul_sw(uint32_t, struct trapframe *, uint32_t);
     80  1.81.4.1    jruoho void	mips_emul_swl(uint32_t, struct trapframe *, uint32_t);
     81  1.81.4.1    jruoho void	mips_emul_swr(uint32_t, struct trapframe *, uint32_t);
     82  1.81.4.1    jruoho #if defined(__mips_n32) || defined(__mips_n64) || defined(__mips_o64)
     83  1.81.4.1    jruoho void	mips_emul_sd(uint32_t, struct trapframe *, uint32_t);
     84  1.81.4.1    jruoho void	mips_emul_sdl(uint32_t, struct trapframe *, uint32_t);
     85  1.81.4.1    jruoho void	mips_emul_sdr(uint32_t, struct trapframe *, uint32_t);
     86  1.81.4.1    jruoho #endif
     87      1.38       cgd 
     88      1.59    simonb uint32_t mips_cp0_cause_read(void);
     89      1.59    simonb void	mips_cp0_cause_write(uint32_t);
     90      1.59    simonb uint32_t mips_cp0_status_read(void);
     91      1.59    simonb void	mips_cp0_status_write(uint32_t);
     92      1.29    simonb 
     93  1.81.4.1    jruoho void	softint_process(uint32_t);
     94  1.81.4.1    jruoho void	softint_fast_dispatch(struct lwp *, int);
     95      1.77   tsutsui 
     96  1.81.4.1    jruoho /*
     97  1.81.4.1    jruoho  * Convert an address to an offset used in a MIPS jump instruction.  The offset
     98  1.81.4.1    jruoho  * contains the low 28 bits (allowing a jump to anywhere within the same 256MB
     99  1.81.4.1    jruoho  * segment of address space) of the address but since mips instructions are
    100  1.81.4.1    jruoho  * always on a 4 byte boundary the low 2 bits are always zero so the 28 bits
    101  1.81.4.1    jruoho  * get shifted right by 2 bits leaving us with a 26 bit result.  To make the
    102  1.81.4.1    jruoho  * offset, we shift left to clear the upper four bits and then right by 6.
    103  1.81.4.1    jruoho  */
    104  1.81.4.1    jruoho #define	fixup_addr2offset(x)	((((uint32_t)(uintptr_t)(x)) << 4) >> 6)
    105  1.81.4.1    jruoho typedef bool (*mips_fixup_callback_t)(int32_t, uint32_t [2]);
    106  1.81.4.1    jruoho struct mips_jump_fixup_info {
    107  1.81.4.1    jruoho 	uint32_t jfi_stub;
    108  1.81.4.1    jruoho 	uint32_t jfi_real;
    109  1.81.4.1    jruoho };
    110  1.81.4.1    jruoho 
    111  1.81.4.1    jruoho void	fixup_splcalls(void);				/* splstubs.c */
    112  1.81.4.1    jruoho bool	mips_fixup_exceptions(mips_fixup_callback_t);
    113  1.81.4.1    jruoho bool	mips_fixup_zero_relative(int32_t, uint32_t [2]);
    114  1.81.4.1    jruoho void	mips_fixup_stubs(uint32_t *, uint32_t *);
    115      1.38       cgd 
    116  1.81.4.1    jruoho /*
    117  1.81.4.1    jruoho  * Define these stubs...
    118  1.81.4.1    jruoho  */
    119  1.81.4.1    jruoho void	mips_cpu_switch_resume(struct lwp *);
    120  1.81.4.1    jruoho void	tlb_set_asid(uint32_t);
    121  1.81.4.1    jruoho void	tlb_invalidate_all(void);
    122  1.81.4.1    jruoho void	tlb_invalidate_globals(void);
    123  1.81.4.1    jruoho void	tlb_invalidate_asids(uint32_t, uint32_t);
    124  1.81.4.1    jruoho void	tlb_invalidate_addr(vaddr_t);
    125  1.81.4.1    jruoho u_int	tlb_record_asids(u_long *, uint32_t);
    126  1.81.4.1    jruoho int	tlb_update(vaddr_t, uint32_t);
    127  1.81.4.1    jruoho void	tlb_enter(size_t, vaddr_t, uint32_t);
    128  1.81.4.1    jruoho void	tlb_read_indexed(size_t, struct tlbmask *);
    129  1.81.4.1    jruoho void	tlb_write_indexed(size_t, const struct tlbmask *);
    130  1.81.4.1    jruoho void	wbflush(void);
    131      1.38       cgd 
    132  1.81.4.1    jruoho #ifdef MIPS1
    133  1.81.4.1    jruoho void	mips1_tlb_invalidate_all(void);
    134      1.49       cgd 
    135  1.81.4.1    jruoho uint32_t tx3900_cp0_config_read(void);
    136      1.59    simonb #endif
    137      1.49       cgd 
    138  1.81.4.1    jruoho #if (MIPS3 + MIPS4 + MIPS32 + MIPS32R2 + MIPS64 + MIPS64R2) > 0
    139      1.59    simonb uint32_t mips3_cp0_compare_read(void);
    140      1.59    simonb void	mips3_cp0_compare_write(uint32_t);
    141      1.49       cgd 
    142      1.59    simonb uint32_t mips3_cp0_config_read(void);
    143      1.59    simonb void	mips3_cp0_config_write(uint32_t);
    144  1.81.4.1    jruoho 
    145  1.81.4.1    jruoho #if (MIPS32 + MIPS32R2 + MIPS64 + MIPS64R2) > 0
    146      1.59    simonb uint32_t mipsNN_cp0_config1_read(void);
    147      1.59    simonb void	mipsNN_cp0_config1_write(uint32_t);
    148      1.63    simonb uint32_t mipsNN_cp0_config2_read(void);
    149      1.63    simonb uint32_t mipsNN_cp0_config3_read(void);
    150  1.81.4.1    jruoho 
    151  1.81.4.1    jruoho intptr_t mipsNN_cp0_watchlo_read(u_int);
    152  1.81.4.1    jruoho void	mipsNN_cp0_watchlo_write(u_int, intptr_t);
    153  1.81.4.1    jruoho uint32_t mipsNN_cp0_watchhi_read(u_int);
    154  1.81.4.1    jruoho void	mipsNN_cp0_watchhi_write(u_int, uint32_t);
    155  1.81.4.1    jruoho 
    156  1.81.4.1    jruoho #if (MIPS32R2 + MIPS64R2) > 0
    157  1.81.4.1    jruoho void	mipsNN_cp0_hwrena_write(uint32_t);
    158  1.81.4.1    jruoho void	mipsNN_cp0_userlocal_write(void *);
    159  1.81.4.1    jruoho #endif
    160      1.63    simonb #endif
    161      1.59    simonb 
    162      1.59    simonb uint32_t mips3_cp0_count_read(void);
    163      1.59    simonb void	mips3_cp0_count_write(uint32_t);
    164      1.59    simonb 
    165      1.59    simonb uint32_t mips3_cp0_wired_read(void);
    166      1.59    simonb void	mips3_cp0_wired_write(uint32_t);
    167      1.69   tsutsui void	mips3_cp0_pg_mask_write(uint32_t);
    168      1.59    simonb 
    169      1.80      matt #if defined(__GNUC__) && !defined(__mips_o32)
    170      1.80      matt static inline uint64_t
    171      1.80      matt mips3_ld(const volatile uint64_t *va)
    172      1.80      matt {
    173      1.80      matt 	uint64_t rv;
    174      1.80      matt #if defined(__mips_o32)
    175      1.80      matt 	uint32_t sr;
    176      1.80      matt 
    177      1.80      matt 	sr = mips_cp0_status_read();
    178      1.80      matt 	mips_cp0_status_write(sr & ~MIPS_SR_INT_IE);
    179      1.80      matt 
    180      1.80      matt 	__asm volatile(
    181      1.80      matt 		".set push		\n\t"
    182      1.80      matt 		".set mips3		\n\t"
    183      1.80      matt 		".set noreorder		\n\t"
    184      1.80      matt 		".set noat		\n\t"
    185      1.80      matt 		"ld	%M0,0(%1)	\n\t"
    186      1.80      matt 		"dsll32	%L0,%M0,0	\n\t"
    187      1.80      matt 		"dsra32	%M0,%M0,0	\n\t"		/* high word */
    188      1.80      matt 		"dsra32	%L0,%L0,0	\n\t"		/* low word */
    189      1.80      matt 		"ld	%0,0(%1)	\n\t"
    190      1.80      matt 		".set pop"
    191      1.80      matt 	    : "=d"(rv)
    192      1.80      matt 	    : "r"(va));
    193      1.80      matt 
    194      1.80      matt 	mips_cp0_status_write(sr);
    195      1.80      matt #elif defined(_LP64)
    196      1.80      matt 	rv = *va;
    197      1.80      matt #else
    198      1.80      matt 	__asm volatile("ld	%0,0(%1)" : "=d"(rv) : "r"(va));
    199      1.80      matt #endif
    200      1.80      matt 
    201      1.80      matt 	return rv;
    202      1.80      matt }
    203      1.80      matt static inline void
    204      1.80      matt mips3_sd(volatile uint64_t *va, uint64_t v)
    205      1.80      matt {
    206      1.80      matt #if defined(__mips_o32)
    207      1.80      matt 	uint32_t sr;
    208      1.80      matt 
    209      1.80      matt 	sr = mips_cp0_status_read();
    210      1.80      matt 	mips_cp0_status_write(sr & ~MIPS_SR_INT_IE);
    211      1.80      matt 
    212      1.80      matt 	__asm volatile(
    213      1.80      matt 		".set push		\n\t"
    214      1.80      matt 		".set mips3		\n\t"
    215      1.80      matt 		".set noreorder		\n\t"
    216      1.80      matt 		".set noat		\n\t"
    217      1.80      matt 		"dsll32	%M0,%M0,0	\n\t"
    218      1.80      matt 		"dsll32	%L0,%L0,0	\n\t"
    219      1.80      matt 		"dsrl32	%L0,%L0,0	\n\t"
    220      1.80      matt 		"or	%0,%L0,%M0	\n\t"
    221      1.80      matt 		"sd	%0,0(%1)	\n\t"
    222      1.80      matt 		".set pop"
    223      1.80      matt 	    : "=d"(v) : "0"(v), "r"(va));
    224      1.80      matt 
    225      1.80      matt 	mips_cp0_status_write(sr);
    226      1.80      matt #elif defined(_LP64)
    227      1.80      matt 	*va = v;
    228      1.80      matt #else
    229      1.80      matt 	__asm volatile("sd	%0,0(%1)" :: "r"(v), "r"(va));
    230      1.80      matt #endif
    231      1.80      matt }
    232      1.80      matt #else
    233      1.80      matt uint64_t mips3_ld(volatile uint64_t *va);
    234      1.80      matt void	mips3_sd(volatile uint64_t *, uint64_t);
    235      1.80      matt #endif	/* __GNUC__ */
    236  1.81.4.1    jruoho #endif	/* (MIPS3 + MIPS4 + MIPS32 + MIPS32R2 + MIPS64 + MIPS64R2) > 0 */
    237      1.59    simonb 
    238  1.81.4.1    jruoho #if (MIPS3 + MIPS4 + MIPS64 + MIPS64R2) > 0
    239  1.81.4.1    jruoho static __inline uint32_t	mips3_lw_a64(uint64_t addr) __unused;
    240  1.81.4.1    jruoho static __inline void	mips3_sw_a64(uint64_t addr, uint32_t val) __unused;
    241      1.59    simonb 
    242      1.74     perry static __inline uint32_t
    243      1.59    simonb mips3_lw_a64(uint64_t addr)
    244      1.59    simonb {
    245      1.59    simonb 	uint32_t rv;
    246      1.80      matt #if defined(__mips_o32)
    247      1.59    simonb 	uint32_t sr;
    248      1.59    simonb 
    249      1.59    simonb 	sr = mips_cp0_status_read();
    250      1.80      matt 	mips_cp0_status_write((sr & ~MIPS_SR_INT_IE) | MIPS3_SR_KX);
    251      1.59    simonb 
    252      1.80      matt 	__asm volatile (
    253      1.80      matt 		".set push		\n\t"
    254      1.80      matt 		".set mips3		\n\t"
    255      1.80      matt 		".set noreorder		\n\t"
    256      1.80      matt 		".set noat		\n\t"
    257      1.80      matt 		"dsll32	%M1,%M1,0	\n\t"
    258      1.80      matt 		"dsll32	%L1,%L1,0	\n\t"
    259  1.81.4.1    jruoho 		"dsrl32	%L1,%L1,0	\n\t"
    260      1.80      matt 		"or	%1,%M1,%L1	\n\t"
    261      1.80      matt 		"lw	%0, 0(%1)	\n\t"
    262      1.80      matt 		".set pop"
    263      1.80      matt 	    : "=r"(rv), "=d"(addr)
    264      1.80      matt 	    : "1"(addr)
    265      1.80      matt 	    );
    266      1.59    simonb 
    267      1.59    simonb 	mips_cp0_status_write(sr);
    268  1.81.4.1    jruoho #elif defined(__mips_n32)
    269  1.81.4.1    jruoho 	uint32_t sr = mips_cp0_status_read();
    270  1.81.4.1    jruoho 	mips_cp0_status_write((sr & ~MIPS_SR_INT_IE) | MIPS3_SR_KX);
    271  1.81.4.1    jruoho 	__asm volatile("lw	%0, 0(%1)" : "=r"(rv) : "d"(addr));
    272  1.81.4.1    jruoho 	mips_cp0_status_write(sr);
    273      1.80      matt #elif defined(_LP64)
    274      1.80      matt 	rv = *(const uint32_t *)addr;
    275      1.80      matt #else
    276  1.81.4.1    jruoho #error unknown ABI
    277      1.80      matt #endif
    278      1.59    simonb 	return (rv);
    279      1.59    simonb }
    280      1.59    simonb 
    281      1.74     perry static __inline void
    282      1.59    simonb mips3_sw_a64(uint64_t addr, uint32_t val)
    283      1.59    simonb {
    284      1.80      matt #if defined(__mips_o32)
    285      1.59    simonb 	uint32_t sr;
    286      1.59    simonb 
    287      1.59    simonb 	sr = mips_cp0_status_read();
    288      1.80      matt 	mips_cp0_status_write((sr & ~MIPS_SR_INT_IE) | MIPS3_SR_KX);
    289      1.59    simonb 
    290      1.80      matt 	__asm volatile (
    291      1.80      matt 		".set push		\n\t"
    292      1.80      matt 		".set mips3		\n\t"
    293      1.80      matt 		".set noreorder		\n\t"
    294      1.80      matt 		".set noat		\n\t"
    295      1.80      matt 		"dsll32	%M0,%M0,0	\n\t"
    296      1.80      matt 		"dsll32	%L0,%L0,0	\n\t"
    297  1.81.4.1    jruoho 		"dsrl32	%L0,%L0,0	\n\t"
    298      1.80      matt 		"or	%0,%M0,%L0	\n\t"
    299      1.80      matt 		"sw	%1, 0(%0)	\n\t"
    300      1.80      matt 		".set pop"
    301      1.80      matt 	    : "=d"(addr): "r"(val), "0"(addr)
    302      1.80      matt 	    );
    303      1.44       cgd 
    304      1.59    simonb 	mips_cp0_status_write(sr);
    305  1.81.4.1    jruoho #elif defined(__mips_n32)
    306  1.81.4.1    jruoho 	uint32_t sr = mips_cp0_status_read();
    307  1.81.4.1    jruoho 	mips_cp0_status_write((sr & ~MIPS_SR_INT_IE) | MIPS3_SR_KX);
    308  1.81.4.1    jruoho 	__asm volatile("sw	%1, 0(%0)" :: "d"(addr), "r"(val));
    309  1.81.4.1    jruoho 	mips_cp0_status_write(sr);
    310      1.80      matt #elif defined(_LP64)
    311      1.80      matt 	*(uint32_t *)addr = val;
    312      1.80      matt #else
    313  1.81.4.1    jruoho #error unknown ABI
    314      1.80      matt #endif
    315      1.59    simonb }
    316  1.81.4.1    jruoho #endif	/* (MIPS3 + MIPS4 + MIPS64 + MIPS64R2) > 0 */
    317       1.7  jonathan 
    318       1.1  jonathan /*
    319      1.58   thorpej  * A vector with an entry for each mips-ISA-level dependent
    320       1.1  jonathan  * locore function, and macros which jump through it.
    321       1.1  jonathan  */
    322       1.1  jonathan typedef struct  {
    323  1.81.4.1    jruoho 	void	(*ljv_cpu_switch_resume)(struct lwp *);
    324  1.81.4.1    jruoho 	intptr_t ljv_lwp_trampoline;
    325  1.81.4.1    jruoho 	intptr_t ljv_setfunc_trampoline;
    326  1.81.4.1    jruoho 	void	(*ljv_wbflush)(void);
    327  1.81.4.1    jruoho 	void	(*ljv_tlb_set_asid)(uint32_t pid);
    328  1.81.4.1    jruoho 	void	(*ljv_tlb_invalidate_asids)(uint32_t, uint32_t);
    329  1.81.4.1    jruoho 	void	(*ljv_tlb_invalidate_addr)(vaddr_t);
    330  1.81.4.1    jruoho 	void	(*ljv_tlb_invalidate_globals)(void);
    331  1.81.4.1    jruoho 	void	(*ljv_tlb_invalidate_all)(void);
    332  1.81.4.1    jruoho 	u_int	(*ljv_tlb_record_asids)(u_long *, uint32_t);
    333  1.81.4.1    jruoho 	int	(*ljv_tlb_update)(vaddr_t, uint32_t);
    334  1.81.4.1    jruoho 	void	(*ljv_tlb_enter)(size_t, vaddr_t, uint32_t);
    335  1.81.4.1    jruoho 	void	(*ljv_tlb_read_indexed)(size_t, struct tlbmask *);
    336  1.81.4.1    jruoho 	void	(*ljv_tlb_write_indexed)(size_t, const struct tlbmask *);
    337       1.1  jonathan } mips_locore_jumpvec_t;
    338      1.13  jonathan 
    339  1.81.4.1    jruoho typedef struct {
    340  1.81.4.1    jruoho 	u_int	(*lav_atomic_cas_uint)(volatile u_int *, u_int, u_int);
    341  1.81.4.1    jruoho 	u_long	(*lav_atomic_cas_ulong)(volatile u_long *, u_long, u_long);
    342  1.81.4.1    jruoho 	int	(*lav_ucas_uint)(volatile u_int *, u_int, u_int, u_int *);
    343  1.81.4.1    jruoho 	int	(*lav_ucas_ulong)(volatile u_long *, u_long, u_long, u_long *);
    344  1.81.4.1    jruoho 	void	(*lav_mutex_enter)(kmutex_t *);
    345  1.81.4.1    jruoho 	void	(*lav_mutex_exit)(kmutex_t *);
    346  1.81.4.1    jruoho 	void	(*lav_mutex_spin_enter)(kmutex_t *);
    347  1.81.4.1    jruoho 	void	(*lav_mutex_spin_exit)(kmutex_t *);
    348  1.81.4.1    jruoho } mips_locore_atomicvec_t;
    349  1.81.4.1    jruoho 
    350      1.38       cgd void	mips_set_wbflush(void (*)(void));
    351      1.62    simonb void	mips_wait_idle(void);
    352       1.1  jonathan 
    353      1.38       cgd void	stacktrace(void);
    354      1.38       cgd void	logstacktrace(void);
    355       1.1  jonathan 
    356  1.81.4.1    jruoho struct cpu_info;
    357  1.81.4.1    jruoho struct splsw;
    358  1.81.4.1    jruoho 
    359      1.80      matt struct locoresw {
    360  1.81.4.1    jruoho 	void		(*lsw_wbflush)(void);
    361  1.81.4.1    jruoho 	void		(*lsw_cpu_idle)(void);
    362  1.81.4.1    jruoho 	int		(*lsw_send_ipi)(struct cpu_info *, int);
    363  1.81.4.1    jruoho 	void		(*lsw_cpu_offline_md)(void);
    364  1.81.4.1    jruoho 	void		(*lsw_cpu_init)(struct cpu_info *);
    365  1.81.4.1    jruoho 	void		(*lsw_cpu_run)(struct cpu_info *);
    366  1.81.4.1    jruoho 	int		(*lsw_bus_error)(unsigned int);
    367  1.81.4.1    jruoho };
    368  1.81.4.1    jruoho 
    369  1.81.4.1    jruoho struct mips_vmfreelist {
    370  1.81.4.1    jruoho 	paddr_t fl_start;
    371  1.81.4.1    jruoho 	paddr_t fl_end;
    372  1.81.4.1    jruoho 	int fl_freelist;
    373      1.80      matt };
    374      1.80      matt 
    375       1.1  jonathan /*
    376      1.81       snj  * The "active" locore-function vector, and
    377       1.1  jonathan  */
    378  1.81.4.1    jruoho extern const mips_locore_atomicvec_t mips_llsc_locore_atomicvec;
    379  1.81.4.1    jruoho 
    380  1.81.4.1    jruoho extern mips_locore_atomicvec_t mips_locore_atomicvec;
    381       1.1  jonathan extern mips_locore_jumpvec_t mips_locore_jumpvec;
    382      1.80      matt extern struct locoresw mips_locoresw;
    383       1.1  jonathan 
    384  1.81.4.1    jruoho struct splsw;
    385  1.81.4.1    jruoho struct mips_vmfreelist;
    386  1.81.4.1    jruoho struct phys_ram_seg;
    387  1.81.4.1    jruoho 
    388  1.81.4.1    jruoho void	mips_vector_init(const struct splsw *, bool);
    389  1.81.4.1    jruoho void	mips_init_msgbuf(void);
    390  1.81.4.1    jruoho void	mips_init_lwp0_uarea(void);
    391  1.81.4.1    jruoho void	mips_page_physload(vaddr_t, vaddr_t,
    392  1.81.4.1    jruoho 	    const struct phys_ram_seg *, size_t,
    393  1.81.4.1    jruoho 	    const struct mips_vmfreelist *, size_t);
    394      1.31  nisimura 
    395       1.7  jonathan 
    396       1.7  jonathan /*
    397       1.7  jonathan  * CPU identification, from PRID register.
    398       1.7  jonathan  */
    399      1.70   tsutsui #define MIPS_PRID_REV(x)	(((x) >>  0) & 0x00ff)
    400      1.70   tsutsui #define MIPS_PRID_IMPL(x)	(((x) >>  8) & 0x00ff)
    401      1.45       cgd 
    402      1.59    simonb /* pre-MIPS32/64 */
    403      1.70   tsutsui #define MIPS_PRID_RSVD(x)	(((x) >> 16) & 0xffff)
    404      1.70   tsutsui #define MIPS_PRID_REV_MIN(x)	((MIPS_PRID_REV(x) >> 0) & 0x0f)
    405      1.70   tsutsui #define MIPS_PRID_REV_MAJ(x)	((MIPS_PRID_REV(x) >> 4) & 0x0f)
    406      1.45       cgd 
    407      1.59    simonb /* MIPS32/64 */
    408      1.70   tsutsui #define MIPS_PRID_CID(x)	(((x) >> 16) & 0x00ff)	/* Company ID */
    409      1.70   tsutsui #define     MIPS_PRID_CID_PREHISTORIC	0x00	/* Not MIPS32/64 */
    410      1.70   tsutsui #define     MIPS_PRID_CID_MTI		0x01	/* MIPS Technologies, Inc. */
    411      1.70   tsutsui #define     MIPS_PRID_CID_BROADCOM	0x02	/* Broadcom */
    412      1.70   tsutsui #define     MIPS_PRID_CID_ALCHEMY	0x03	/* Alchemy Semiconductor */
    413      1.70   tsutsui #define     MIPS_PRID_CID_SIBYTE	0x04	/* SiByte */
    414      1.70   tsutsui #define     MIPS_PRID_CID_SANDCRAFT	0x05	/* SandCraft */
    415      1.70   tsutsui #define     MIPS_PRID_CID_PHILIPS	0x06	/* Philips */
    416      1.70   tsutsui #define     MIPS_PRID_CID_TOSHIBA	0x07	/* Toshiba */
    417  1.81.4.1    jruoho #define     MIPS_PRID_CID_MICROSOFT	0x07	/* Microsoft also, sigh */
    418      1.70   tsutsui #define     MIPS_PRID_CID_LSI		0x08	/* LSI */
    419      1.67    simonb 				/*	0x09	unannounced */
    420      1.67    simonb 				/*	0x0a	unannounced */
    421      1.70   tsutsui #define     MIPS_PRID_CID_LEXRA		0x0b	/* Lexra */
    422      1.80      matt #define     MIPS_PRID_CID_RMI		0x0c	/* RMI / NetLogic */
    423      1.70   tsutsui #define MIPS_PRID_COPTS(x)	(((x) >> 24) & 0x00ff)	/* Company Options */
    424       1.6  jonathan 
    425       1.6  jonathan #ifdef _KERNEL
    426       1.6  jonathan /*
    427       1.6  jonathan  * Global variables used to communicate CPU type, and parameters
    428       1.6  jonathan  * such as cache size, from locore to higher-level code (e.g., pmap).
    429       1.6  jonathan  */
    430      1.75  christos void mips_pagecopy(void *dst, void *src);
    431      1.75  christos void mips_pagezero(void *dst);
    432      1.19  jonathan 
    433      1.59    simonb #ifdef __HAVE_MIPS_MACHDEP_CACHE_CONFIG
    434      1.59    simonb void mips_machdep_cache_config(void);
    435      1.59    simonb #endif
    436      1.59    simonb 
    437      1.19  jonathan /*
    438      1.20    simonb  * trapframe argument passed to trap()
    439      1.19  jonathan  */
    440      1.64   thorpej 
    441  1.81.4.1    jruoho #if 0
    442  1.81.4.1    jruoho #define TF_AST		0		/* really zero */
    443  1.81.4.1    jruoho #define TF_V0		_R_V0
    444  1.81.4.1    jruoho #define TF_V1		_R_V1
    445  1.81.4.1    jruoho #define TF_A0		_R_A0
    446  1.81.4.1    jruoho #define TF_A1		_R_A1
    447  1.81.4.1    jruoho #define TF_A2		_R_A2
    448  1.81.4.1    jruoho #define TF_A3		_R_A3
    449  1.81.4.1    jruoho #define TF_T0		_R_T0
    450  1.81.4.1    jruoho #define TF_T1		_R_T1
    451  1.81.4.1    jruoho #define TF_T2		_R_T2
    452  1.81.4.1    jruoho #define TF_T3		_R_T3
    453      1.64   thorpej 
    454      1.64   thorpej #if defined(__mips_n32) || defined(__mips_n64)
    455  1.81.4.1    jruoho #define TF_A4		_R_A4
    456  1.81.4.1    jruoho #define TF_A5		_R_A5
    457  1.81.4.1    jruoho #define TF_A6		_R_A6
    458  1.81.4.1    jruoho #define TF_A7		_R_A7
    459      1.64   thorpej #else
    460  1.81.4.1    jruoho #define TF_T4		_R_T4
    461  1.81.4.1    jruoho #define TF_T5		_R_T5
    462  1.81.4.1    jruoho #define TF_T6		_R_T6
    463  1.81.4.1    jruoho #define TF_T7		_R_T7
    464      1.64   thorpej #endif /* __mips_n32 || __mips_n64 */
    465      1.64   thorpej 
    466  1.81.4.1    jruoho #define TF_TA0		_R_TA0
    467  1.81.4.1    jruoho #define TF_TA1		_R_TA1
    468  1.81.4.1    jruoho #define TF_TA2		_R_TA2
    469  1.81.4.1    jruoho #define TF_TA3		_R_TA3
    470  1.81.4.1    jruoho 
    471  1.81.4.1    jruoho #define TF_T8		_R_T8
    472  1.81.4.1    jruoho #define TF_T9		_R_T9
    473  1.81.4.1    jruoho 
    474  1.81.4.1    jruoho #define TF_RA		_R_RA
    475  1.81.4.1    jruoho #define TF_SR		_R_SR
    476  1.81.4.1    jruoho #define TF_MULLO	_R_MULLO
    477  1.81.4.1    jruoho #define TF_MULHI	_R_MULLO
    478  1.81.4.1    jruoho #define TF_EPC		_R_PC		/* may be changed by trap() call */
    479      1.65   thorpej 
    480  1.81.4.1    jruoho #define	TF_NREGS	(sizeof(struct reg) / sizeof(mips_reg_t))
    481  1.81.4.1    jruoho #endif
    482      1.64   thorpej 
    483      1.19  jonathan struct trapframe {
    484  1.81.4.1    jruoho 	struct reg tf_registers;
    485  1.81.4.1    jruoho #define	tf_regs	tf_registers.r_regs
    486      1.80      matt 	uint32_t   tf_ppl;		/* previous priority level */
    487      1.80      matt 	mips_reg_t tf_pad;		/* for 8 byte aligned */
    488      1.19  jonathan };
    489      1.19  jonathan 
    490  1.81.4.1    jruoho CTASSERT(sizeof(struct trapframe) % (4*sizeof(mips_reg_t)) == 0);
    491  1.81.4.1    jruoho 
    492      1.19  jonathan /*
    493      1.19  jonathan  * Stack frame for kernel traps. four args passed in registers.
    494      1.19  jonathan  * A trapframe is pointed to by the 5th arg, and a dummy sixth argument
    495      1.19  jonathan  * is used to avoid alignment problems
    496      1.19  jonathan  */
    497      1.19  jonathan 
    498      1.19  jonathan struct kernframe {
    499      1.80      matt #if defined(__mips_o32) || defined(__mips_o64)
    500      1.19  jonathan 	register_t cf_args[4 + 1];
    501      1.80      matt #if defined(__mips_o32)
    502  1.81.4.1    jruoho 	register_t cf_pad;		/* (for 8 byte alignment) */
    503      1.80      matt #endif
    504      1.80      matt #endif
    505      1.80      matt #if defined(__mips_n32) || defined(__mips_n64)
    506      1.80      matt 	register_t cf_pad[2];		/* for 16 byte alignment */
    507      1.80      matt #endif
    508      1.19  jonathan 	register_t cf_sp;
    509      1.19  jonathan 	register_t cf_ra;
    510      1.19  jonathan 	struct trapframe cf_frame;
    511      1.19  jonathan };
    512  1.81.4.1    jruoho 
    513  1.81.4.1    jruoho CTASSERT(sizeof(struct kernframe) % (2*sizeof(mips_reg_t)) == 0);
    514  1.81.4.1    jruoho 
    515  1.81.4.1    jruoho /*
    516  1.81.4.1    jruoho  * PRocessor IDentity TABle
    517  1.81.4.1    jruoho  */
    518  1.81.4.1    jruoho 
    519  1.81.4.1    jruoho struct pridtab {
    520  1.81.4.1    jruoho 	int	cpu_cid;
    521  1.81.4.1    jruoho 	int	cpu_pid;
    522  1.81.4.1    jruoho 	int	cpu_rev;	/* -1 == wildcard */
    523  1.81.4.1    jruoho 	int	cpu_copts;	/* -1 == wildcard */
    524  1.81.4.1    jruoho 	int	cpu_isa;	/* -1 == probed (mips32/mips64) */
    525  1.81.4.1    jruoho 	int	cpu_ntlb;	/* -1 == unknown, 0 == probed */
    526  1.81.4.1    jruoho 	int	cpu_flags;
    527  1.81.4.1    jruoho 	u_int	cpu_cp0flags;	/* presence of some cp0 regs */
    528  1.81.4.1    jruoho 	u_int	cpu_cidflags;	/* company-specific flags */
    529  1.81.4.1    jruoho 	const char	*cpu_name;
    530  1.81.4.1    jruoho };
    531  1.81.4.1    jruoho 
    532  1.81.4.1    jruoho /*
    533  1.81.4.1    jruoho  * bitfield defines for cpu_cp0flags
    534  1.81.4.1    jruoho  */
    535  1.81.4.1    jruoho #define  MIPS_CP0FL_USE		__BIT(0)	/* use these flags */
    536  1.81.4.1    jruoho #define  MIPS_CP0FL_ECC		__BIT(1)
    537  1.81.4.1    jruoho #define  MIPS_CP0FL_CACHE_ERR	__BIT(2)
    538  1.81.4.1    jruoho #define  MIPS_CP0FL_EIRR	__BIT(3)
    539  1.81.4.1    jruoho #define  MIPS_CP0FL_EIMR	__BIT(4)
    540  1.81.4.1    jruoho #define  MIPS_CP0FL_EBASE	__BIT(5)
    541  1.81.4.1    jruoho #define  MIPS_CP0FL_CONFIG	__BIT(6)
    542  1.81.4.1    jruoho #define  MIPS_CP0FL_CONFIG1	__BIT(7)
    543  1.81.4.1    jruoho #define  MIPS_CP0FL_CONFIG2	__BIT(8)
    544  1.81.4.1    jruoho #define  MIPS_CP0FL_CONFIG3	__BIT(9)
    545  1.81.4.1    jruoho #define  MIPS_CP0FL_CONFIG4	__BIT(10)
    546  1.81.4.1    jruoho #define  MIPS_CP0FL_CONFIG5	__BIT(11)
    547  1.81.4.1    jruoho #define  MIPS_CP0FL_CONFIG6	__BIT(12)
    548  1.81.4.1    jruoho #define  MIPS_CP0FL_CONFIG7	__BIT(13)
    549  1.81.4.1    jruoho #define  MIPS_CP0FL_USERLOCAL	__BIT(14)
    550  1.81.4.1    jruoho #define  MIPS_CP0FL_HWRENA	__BIT(15)
    551  1.81.4.1    jruoho 
    552  1.81.4.1    jruoho /*
    553  1.81.4.1    jruoho  * cpu_cidflags defines, by company
    554  1.81.4.1    jruoho  */
    555  1.81.4.1    jruoho /*
    556  1.81.4.1    jruoho  * RMI company-specific cpu_cidflags
    557  1.81.4.1    jruoho  */
    558  1.81.4.1    jruoho #define MIPS_CIDFL_RMI_TYPE		__BITS(2,0)
    559  1.81.4.1    jruoho # define  CIDFL_RMI_TYPE_XLR		0
    560  1.81.4.1    jruoho # define  CIDFL_RMI_TYPE_XLS		1
    561  1.81.4.1    jruoho # define  CIDFL_RMI_TYPE_XLP		2
    562  1.81.4.1    jruoho #define MIPS_CIDFL_RMI_THREADS_MASK	__BITS(6,3)
    563  1.81.4.1    jruoho # define MIPS_CIDFL_RMI_THREADS_SHIFT	3
    564  1.81.4.1    jruoho #define MIPS_CIDFL_RMI_CORES_MASK	__BITS(10,7)
    565  1.81.4.1    jruoho # define MIPS_CIDFL_RMI_CORES_SHIFT	7
    566  1.81.4.1    jruoho # define LOG2_1	0
    567  1.81.4.1    jruoho # define LOG2_2	1
    568  1.81.4.1    jruoho # define LOG2_4	2
    569  1.81.4.1    jruoho # define LOG2_8	3
    570  1.81.4.1    jruoho # define MIPS_CIDFL_RMI_CPUS(ncores, nthreads)				\
    571  1.81.4.1    jruoho 		((LOG2_ ## ncores << MIPS_CIDFL_RMI_CORES_SHIFT)	\
    572  1.81.4.1    jruoho 		|(LOG2_ ## nthreads << MIPS_CIDFL_RMI_THREADS_SHIFT))
    573  1.81.4.1    jruoho # define MIPS_CIDFL_RMI_NTHREADS(cidfl)					\
    574  1.81.4.1    jruoho 		(1 << (((cidfl) & MIPS_CIDFL_RMI_THREADS_MASK)		\
    575  1.81.4.1    jruoho 			>> MIPS_CIDFL_RMI_THREADS_SHIFT))
    576  1.81.4.1    jruoho # define MIPS_CIDFL_RMI_NCORES(cidfl)					\
    577  1.81.4.1    jruoho 		(1 << (((cidfl) & MIPS_CIDFL_RMI_CORES_MASK)		\
    578  1.81.4.1    jruoho 			>> MIPS_CIDFL_RMI_CORES_SHIFT))
    579  1.81.4.1    jruoho #define MIPS_CIDFL_RMI_L2SZ_MASK	__BITS(14,11)
    580  1.81.4.1    jruoho # define MIPS_CIDFL_RMI_L2SZ_SHIFT	11
    581  1.81.4.1    jruoho # define RMI_L2SZ_256KB	 0
    582  1.81.4.1    jruoho # define RMI_L2SZ_512KB  1
    583  1.81.4.1    jruoho # define RMI_L2SZ_1MB    2
    584  1.81.4.1    jruoho # define RMI_L2SZ_2MB    3
    585  1.81.4.1    jruoho # define RMI_L2SZ_4MB    4
    586  1.81.4.1    jruoho # define MIPS_CIDFL_RMI_L2(l2sz)					\
    587  1.81.4.1    jruoho 		(RMI_L2SZ_ ## l2sz << MIPS_CIDFL_RMI_L2SZ_SHIFT)
    588  1.81.4.1    jruoho # define MIPS_CIDFL_RMI_L2SZ(cidfl)					\
    589  1.81.4.1    jruoho 		((256*1024) << (((cidfl) & MIPS_CIDFL_RMI_L2SZ_MASK)	\
    590  1.81.4.1    jruoho 			>> MIPS_CIDFL_RMI_L2SZ_SHIFT))
    591  1.81.4.1    jruoho 
    592      1.61    simonb #endif	/* _KERNEL */
    593       1.1  jonathan #endif	/* _MIPS_LOCORE_H */
    594