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