Home | History | Annotate | Line # | Download | only in include
cpu.h revision 1.53
      1  1.53    simonb /*	$NetBSD: cpu.h,v 1.53 2001/09/04 06:19:22 simonb Exp $	*/
      2   1.8       cgd 
      3   1.1   deraadt /*-
      4   1.5     glass  * Copyright (c) 1992, 1993
      5   1.5     glass  *	The Regents of the University of California.  All rights reserved.
      6   1.1   deraadt  *
      7   1.1   deraadt  * This code is derived from software contributed to Berkeley by
      8   1.1   deraadt  * Ralph Campbell and Rick Macklem.
      9   1.1   deraadt  *
     10   1.1   deraadt  * Redistribution and use in source and binary forms, with or without
     11   1.1   deraadt  * modification, are permitted provided that the following conditions
     12   1.1   deraadt  * are met:
     13   1.1   deraadt  * 1. Redistributions of source code must retain the above copyright
     14   1.1   deraadt  *    notice, this list of conditions and the following disclaimer.
     15   1.1   deraadt  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1   deraadt  *    notice, this list of conditions and the following disclaimer in the
     17   1.1   deraadt  *    documentation and/or other materials provided with the distribution.
     18   1.1   deraadt  * 3. All advertising materials mentioning features or use of this software
     19   1.1   deraadt  *    must display the following acknowledgement:
     20   1.1   deraadt  *	This product includes software developed by the University of
     21   1.1   deraadt  *	California, Berkeley and its contributors.
     22   1.1   deraadt  * 4. Neither the name of the University nor the names of its contributors
     23   1.1   deraadt  *    may be used to endorse or promote products derived from this software
     24   1.1   deraadt  *    without specific prior written permission.
     25   1.1   deraadt  *
     26   1.1   deraadt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     27   1.1   deraadt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     28   1.1   deraadt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     29   1.1   deraadt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     30   1.1   deraadt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     31   1.1   deraadt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     32   1.1   deraadt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     33   1.1   deraadt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     34   1.1   deraadt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     35   1.1   deraadt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     36   1.1   deraadt  * SUCH DAMAGE.
     37   1.1   deraadt  *
     38   1.8       cgd  *	@(#)cpu.h	8.4 (Berkeley) 1/4/94
     39   1.1   deraadt  */
     40   1.1   deraadt 
     41   1.1   deraadt #ifndef _CPU_H_
     42   1.1   deraadt #define _CPU_H_
     43   1.1   deraadt 
     44  1.53    simonb #include <sys/sched.h>
     45  1.53    simonb 
     46   1.1   deraadt /*
     47  1.13  jonathan  * Exported definitions unique to NetBSD/mips cpu support.
     48   1.1   deraadt  */
     49  1.36     soren 
     50  1.53    simonb #ifndef _LOCORE
     51  1.53    simonb #if defined(_KERNEL_OPT)
     52  1.53    simonb #include "opt_lockdebug.h"
     53  1.53    simonb #endif
     54  1.53    simonb 
     55  1.53    simonb struct cpu_info {
     56  1.53    simonb 	struct schedstate_percpu ci_schedstate; /* scheduler state */
     57  1.53    simonb #if defined(DIAGNOSTIC) || defined(LOCKDEBUG)
     58  1.53    simonb 	u_long ci_spin_locks;		/* # of spin locks held */
     59  1.53    simonb 	u_long ci_simple_locks;		/* # of simple locks held */
     60  1.53    simonb #endif
     61  1.53    simonb };
     62  1.53    simonb #endif /* !defined(_LOCORE) */
     63  1.53    simonb 
     64  1.36     soren /*
     65  1.36     soren  * CTL_MACHDEP definitions.
     66  1.36     soren  */
     67  1.36     soren #define CPU_CONSDEV		1	/* dev_t: console terminal device */
     68  1.36     soren #define CPU_BOOTED_KERNEL	2	/* string: booted kernel name */
     69  1.36     soren #define CPU_ROOT_DEVICE		3	/* string: root device name */
     70  1.43     jeffs 
     71  1.43     jeffs /*
     72  1.51       wiz  * Platform can override, but note this breaks userland compatibility
     73  1.43     jeffs  * with other mips platforms.
     74  1.43     jeffs  */
     75  1.43     jeffs #ifndef CPU_MAXID
     76  1.36     soren #define CPU_MAXID		4	/* number of valid machdep ids */
     77  1.36     soren 
     78  1.36     soren #define CTL_MACHDEP_NAMES { \
     79  1.36     soren 	{ 0, 0 }, \
     80  1.36     soren 	{ "console_device", CTLTYPE_STRUCT }, \
     81  1.36     soren 	{ "booted_kernel", CTLTYPE_STRING }, \
     82  1.36     soren 	{ "root_device", CTLTYPE_STRING }, \
     83  1.36     soren }
     84  1.42     jeffs #endif
     85  1.33    simonb 
     86  1.33    simonb #ifdef _KERNEL
     87  1.33    simonb #ifndef _LOCORE
     88  1.53    simonb extern struct cpu_info cpu_info_store;
     89  1.53    simonb 
     90  1.53    simonb #define	curcpu()	(&cpu_info_store)
     91  1.53    simonb #define	cpu_number()	(0)
     92  1.33    simonb 
     93  1.33    simonb /*
     94  1.21  jonathan  * Macros to find the CPU architecture we're on at run-time,
     95  1.21  jonathan  * or if possible, at compile-time.
     96  1.21  jonathan  */
     97  1.21  jonathan 
     98  1.46       cgd extern int cpu_arch;
     99  1.46       cgd 
    100  1.46       cgd #define	CPU_ARCH_MIPS1	(1 << 0)
    101  1.46       cgd #define	CPU_ARCH_MIPS2	(1 << 1)
    102  1.46       cgd #define	CPU_ARCH_MIPS3	(1 << 2)
    103  1.46       cgd #define	CPU_ARCH_MIPS4	(1 << 3)
    104  1.46       cgd #define	CPU_ARCH_MIPS5	(1 << 4)
    105  1.46       cgd #define	CPU_ARCH_MIPS32	(1 << 5)
    106  1.46       cgd #define	CPU_ARCH_MIPS64	(1 << 6)
    107  1.46       cgd 
    108  1.21  jonathan #if (MIPS1 + MIPS3) == 1
    109  1.21  jonathan #ifdef MIPS1
    110  1.21  jonathan # define CPUISMIPS3	0
    111  1.21  jonathan #endif /* mips1 */
    112  1.21  jonathan 
    113  1.21  jonathan #ifdef MIPS3
    114  1.21  jonathan #  define CPUISMIPS3	 1
    115  1.21  jonathan #endif /* mips1 */
    116  1.21  jonathan 
    117  1.21  jonathan #else /* run-time test */
    118  1.45       cgd 
    119  1.45       cgd /* This test is ... rather bogus */
    120  1.45       cgd #define CPUISMIPS3	((cpu_arch & (CPU_ARCH_MIPS3 | CPU_ARCH_MIPS4)) != 0)
    121  1.21  jonathan #endif /* run-time test */
    122  1.21  jonathan 
    123  1.21  jonathan /*
    124   1.1   deraadt  * definitions of cpu-dependent requirements
    125   1.1   deraadt  * referenced in generic code
    126   1.1   deraadt  */
    127  1.11       cgd #define	cpu_wait(p)			/* nothing */
    128  1.11       cgd #define	cpu_swapout(p)			panic("cpu_swapout: can't get here");
    129  1.42     jeffs 
    130  1.42     jeffs void cpu_intr __P((u_int32_t, u_int32_t, u_int32_t, u_int32_t));
    131   1.1   deraadt 
    132   1.1   deraadt /*
    133   1.1   deraadt  * Arguments to hardclock and gatherstats encapsulate the previous
    134   1.1   deraadt  * machine state in an opaque clockframe.
    135   1.1   deraadt  */
    136   1.5     glass struct clockframe {
    137   1.1   deraadt 	int	pc;	/* program counter at time of interrupt */
    138   1.1   deraadt 	int	sr;	/* status register at time of interrupt */
    139   1.5     glass };
    140   1.1   deraadt 
    141  1.14  jonathan /*
    142  1.14  jonathan  * A port must provde CLKF_USERMODE() and CLKF_BASEPRI() for use
    143  1.14  jonathan  * in machine-independent code. These differ on r4000 and r3000 systems;
    144  1.14  jonathan  * provide them in the port-dependent file that includes this one, using
    145  1.14  jonathan  * the macros below.
    146  1.14  jonathan  */
    147  1.14  jonathan 
    148  1.21  jonathan /* mips1 versions */
    149  1.22  jonathan #define	MIPS1_CLKF_USERMODE(framep)	((framep)->sr & MIPS_SR_KU_PREV)
    150  1.21  jonathan #define	MIPS1_CLKF_BASEPRI(framep)	\
    151  1.22  jonathan 	((~(framep)->sr & (MIPS_INT_MASK | MIPS_SR_INT_ENA_PREV)) == 0)
    152  1.14  jonathan 
    153  1.21  jonathan /* mips3 versions */
    154  1.22  jonathan #define	MIPS3_CLKF_USERMODE(framep)	((framep)->sr & MIPS_SR_KSU_USER)
    155  1.21  jonathan #define	MIPS3_CLKF_BASEPRI(framep)	\
    156  1.34     soren 	((~(framep)->sr & (MIPS_INT_MASK | MIPS_SR_INT_IE)) == 0)
    157  1.14  jonathan 
    158   1.1   deraadt #define	CLKF_PC(framep)		((framep)->pc)
    159   1.1   deraadt #define	CLKF_INTR(framep)	(0)
    160  1.18  jonathan 
    161  1.21  jonathan #if defined(MIPS3) && !defined(MIPS1)
    162  1.21  jonathan #define	CLKF_USERMODE(framep)	MIPS3_CLKF_USERMODE(framep)
    163  1.21  jonathan #define	CLKF_BASEPRI(framep)	MIPS3_CLKF_BASEPRI(framep)
    164  1.21  jonathan #endif
    165  1.21  jonathan 
    166  1.21  jonathan #if !defined(MIPS3) && defined(MIPS1)
    167  1.21  jonathan #define	CLKF_USERMODE(framep)	MIPS1_CLKF_USERMODE(framep)
    168  1.21  jonathan #define	CLKF_BASEPRI(framep)	MIPS1_CLKF_BASEPRI(framep)
    169  1.21  jonathan #endif
    170  1.21  jonathan 
    171  1.21  jonathan #if defined(MIPS3) && defined(MIPS1)
    172  1.21  jonathan #define CLKF_USERMODE(framep) \
    173  1.21  jonathan     ((CPUISMIPS3) ? MIPS3_CLKF_USERMODE(framep):  MIPS1_CLKF_USERMODE(framep))
    174  1.21  jonathan #define CLKF_BASEPRI(framep) \
    175  1.21  jonathan     ((CPUISMIPS3) ? MIPS3_CLKF_BASEPRI(framep):  MIPS1_CLKF_BASEPRI(framep))
    176  1.18  jonathan #endif
    177  1.18  jonathan 
    178  1.47   thorpej /*
    179  1.47   thorpej  * This is used during profiling to integrate system time.  It can safely
    180  1.47   thorpej  * assume that the process is resident.
    181  1.47   thorpej  */
    182  1.48   thorpej #define	PROC_PC(p)							\
    183  1.48   thorpej 	(((struct frame *)(p)->p_md.md_regs)->f_regs[37])	/* XXX PC */
    184   1.1   deraadt 
    185   1.1   deraadt /*
    186   1.1   deraadt  * Preempt the current process if in interrupt from user mode,
    187   1.1   deraadt  * or after the current trap/syscall if in system mode.
    188   1.1   deraadt  */
    189  1.50   thorpej #define	need_resched(ci)						\
    190  1.50   thorpej do {									\
    191  1.50   thorpej 	want_resched = 1;						\
    192  1.50   thorpej 	if (curproc != NULL)						\
    193  1.50   thorpej 		aston(curproc);						\
    194  1.50   thorpej } while (/*CONSTCOND*/0)
    195   1.1   deraadt 
    196   1.1   deraadt /*
    197   1.1   deraadt  * Give a profiling tick to the current process when the user profiling
    198  1.13  jonathan  * buffer pages are invalid.  On the MIPS, request an ast to send us
    199   1.1   deraadt  * through trap, marking the proc as needing a profiling tick.
    200   1.1   deraadt  */
    201  1.50   thorpej #define	need_proftick(p)						\
    202  1.50   thorpej do {									\
    203  1.50   thorpej 	(p)->p_flag |= P_OWEUPC;					\
    204  1.50   thorpej 	aston(p);							\
    205  1.50   thorpej } while (/*CONSTCOND*/0)
    206   1.1   deraadt 
    207   1.1   deraadt /*
    208   1.1   deraadt  * Notify the current process (p) that it has a signal pending,
    209   1.1   deraadt  * process as soon as possible.
    210   1.1   deraadt  */
    211  1.50   thorpej #define	signotify(p)	aston(p)
    212   1.1   deraadt 
    213  1.50   thorpej #define aston(p)	((p)->p_md.md_astpending = 1)
    214   1.1   deraadt 
    215  1.49   thorpej extern int want_resched;		/* resched() was called */
    216  1.25  jonathan #ifdef MIPS3
    217  1.25  jonathan extern u_int	mips_L2CacheSize;
    218  1.25  jonathan extern int	mips_L2CacheIsSnooping; /* L2 cache snoops uncached writes ? */
    219  1.25  jonathan extern int	mips_L2CacheMixed;
    220  1.33    simonb #endif /* MIPS3 */
    221  1.28    castor 
    222  1.23   thorpej /*
    223  1.37    simonb  * Misc prototypes and variable declarations.
    224  1.23   thorpej  */
    225  1.28    castor struct proc;
    226  1.28    castor struct user;
    227  1.37    simonb 
    228  1.37    simonb extern struct proc *fpcurproc;
    229  1.25  jonathan 
    230  1.28    castor /* trap.c */
    231  1.38  nisimura void	netintr __P((void));
    232  1.28    castor int	kdbpeek __P((vaddr_t));
    233  1.23   thorpej 
    234  1.28    castor /* mips_machdep.c */
    235  1.23   thorpej void	dumpsys __P((void));
    236  1.23   thorpej int	savectx __P((struct user *));
    237  1.24   thorpej void	mips_init_msgbuf __P((void));
    238  1.41  nisimura void	savefpregs __P((struct proc *));
    239  1.41  nisimura void	loadfpregs __P((struct proc *));
    240  1.13  jonathan 
    241  1.25  jonathan /* locore.S */
    242  1.28    castor int	badaddr __P((void *, size_t));
    243  1.25  jonathan 
    244  1.25  jonathan /* mips_machdep.c */
    245  1.28    castor void	cpu_identify __P((void));
    246  1.28    castor void	mips_vector_init __P((void));
    247  1.27   thorpej 
    248  1.33    simonb #endif /* ! _LOCORE */
    249  1.28    castor #endif /* _KERNEL */
    250   1.1   deraadt 
    251   1.1   deraadt #endif /* _CPU_H_ */
    252