Home | History | Annotate | Line # | Download | only in include
      1  1.25  thorpej /*	$NetBSD: cpu.h,v 1.25 2024/02/28 13:05:39 thorpej Exp $	*/
      2   1.1  thorpej 
      3   1.1  thorpej /*
      4  1.14    rmind  * Copyright (c) 1988 University of Utah.
      5   1.1  thorpej  * Copyright (c) 1982, 1990, 1993
      6   1.1  thorpej  *	The Regents of the University of California.  All rights reserved.
      7  1.10      agc  *
      8  1.10      agc  * This code is derived from software contributed to Berkeley by
      9  1.10      agc  * the Systems Programming Group of the University of Utah Computer
     10  1.10      agc  * Science Department.
     11  1.10      agc  *
     12  1.10      agc  * Redistribution and use in source and binary forms, with or without
     13  1.10      agc  * modification, are permitted provided that the following conditions
     14  1.10      agc  * are met:
     15  1.10      agc  * 1. Redistributions of source code must retain the above copyright
     16  1.10      agc  *    notice, this list of conditions and the following disclaimer.
     17  1.10      agc  * 2. Redistributions in binary form must reproduce the above copyright
     18  1.10      agc  *    notice, this list of conditions and the following disclaimer in the
     19  1.10      agc  *    documentation and/or other materials provided with the distribution.
     20  1.10      agc  * 3. Neither the name of the University nor the names of its contributors
     21  1.10      agc  *    may be used to endorse or promote products derived from this software
     22  1.10      agc  *    without specific prior written permission.
     23  1.10      agc  *
     24  1.10      agc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25  1.10      agc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26  1.10      agc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27  1.10      agc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28  1.10      agc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29  1.10      agc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30  1.10      agc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31  1.10      agc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32  1.10      agc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33  1.10      agc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34  1.10      agc  * SUCH DAMAGE.
     35  1.10      agc  *
     36  1.10      agc  * from: Utah $Hdr: cpu.h 1.16 91/03/25$
     37  1.10      agc  *
     38  1.10      agc  *	@(#)cpu.h	8.4 (Berkeley) 1/5/94
     39  1.10      agc  */
     40   1.1  thorpej 
     41   1.1  thorpej #ifndef _M68K_CPU_H_
     42   1.1  thorpej #define	_M68K_CPU_H_
     43   1.1  thorpej 
     44  1.20  thorpej #if defined(_KERNEL_OPT)
     45  1.20  thorpej #include "opt_m68k_arch.h"	/* XXX Should not do this here. */
     46  1.20  thorpej #endif
     47  1.20  thorpej 
     48   1.1  thorpej /*
     49   1.1  thorpej  * Exported definitions common to Motorola m68k-based ports.
     50   1.1  thorpej  */
     51   1.1  thorpej 
     52   1.1  thorpej /*
     53   1.5      gwr  * XXX  The remaining contents of this file should be split out
     54   1.5      gwr  * XXX  into separate files (like m68k.h) and then this file
     55   1.5      gwr  * XXX  should go away.  Furthermore, most of the stuff defined
     56   1.5      gwr  * XXX  here does NOT belong in <machine/cpu.h>, and the ports
     57   1.5      gwr  * XXX  using this file should remove <m68k/cpu.h> from there.
     58   1.1  thorpej  */
     59   1.1  thorpej 
     60   1.5      gwr #include <m68k/m68k.h>
     61   1.5      gwr 
     62   1.5      gwr /* XXX - Move this stuff into <m68k/cacr.h> maybe? */
     63   1.5      gwr 
     64   1.1  thorpej /* fields in the 68020 cache control register */
     65   1.1  thorpej #define	IC_ENABLE	0x0001	/* enable instruction cache */
     66   1.1  thorpej #define	IC_FREEZE	0x0002	/* freeze instruction cache */
     67   1.1  thorpej #define	IC_CE		0x0004	/* clear instruction cache entry */
     68   1.1  thorpej #define	IC_CLR		0x0008	/* clear entire instruction cache */
     69   1.1  thorpej 
     70   1.1  thorpej /* additional fields in the 68030 cache control register */
     71   1.1  thorpej #define	IC_BE		0x0010	/* instruction burst enable */
     72   1.1  thorpej #define	DC_ENABLE	0x0100	/* data cache enable */
     73   1.1  thorpej #define	DC_FREEZE	0x0200	/* data cache freeze */
     74   1.1  thorpej #define	DC_CE		0x0400	/* clear data cache entry */
     75   1.1  thorpej #define	DC_CLR		0x0800	/* clear entire data cache */
     76   1.1  thorpej #define	DC_BE		0x1000	/* data burst enable */
     77   1.1  thorpej #define	DC_WA		0x2000	/* write allocate */
     78   1.1  thorpej 
     79   1.1  thorpej /* fields in the 68040 cache control register */
     80   1.1  thorpej #define	IC40_ENABLE	0x00008000	/* instruction cache enable bit */
     81   1.1  thorpej #define	DC40_ENABLE	0x80000000	/* data cache enable bit */
     82   1.1  thorpej 
     83   1.1  thorpej /* additional fields in the 68060 cache control register */
     84   1.1  thorpej #define	DC60_NAD	0x40000000	/* no allocate mode, data cache */
     85   1.1  thorpej #define	DC60_ESB	0x20000000	/* enable store buffer */
     86   1.1  thorpej #define	DC60_DPI	0x10000000	/* disable CPUSH invalidation */
     87   1.1  thorpej #define	DC60_FOC	0x08000000	/* four kB data cache mode (else 8) */
     88   1.1  thorpej 
     89   1.1  thorpej #define	IC60_EBC	0x00800000	/* enable branch cache */
     90   1.1  thorpej #define IC60_CABC	0x00400000	/* clear all branch cache entries */
     91   1.1  thorpej #define	IC60_CUBC	0x00200000	/* clear user branch cache entries */
     92   1.1  thorpej 
     93   1.1  thorpej #define	IC60_NAI	0x00004000	/* no allocate mode, instr. cache */
     94   1.1  thorpej #define	IC60_FIC	0x00002000	/* four kB instr. cache (else 8) */
     95   1.1  thorpej 
     96   1.1  thorpej #define	CACHE_ON	(DC_WA|DC_BE|DC_CLR|DC_ENABLE|IC_BE|IC_CLR|IC_ENABLE)
     97   1.1  thorpej #define	CACHE_OFF	(DC_CLR|IC_CLR)
     98   1.1  thorpej #define	CACHE_CLR	(CACHE_ON)
     99   1.1  thorpej #define	IC_CLEAR	(DC_WA|DC_BE|DC_ENABLE|IC_BE|IC_CLR|IC_ENABLE)
    100   1.1  thorpej #define	DC_CLEAR	(DC_WA|DC_BE|DC_CLR|DC_ENABLE|IC_BE|IC_ENABLE)
    101   1.1  thorpej 
    102   1.1  thorpej #define	CACHE40_ON	(IC40_ENABLE|DC40_ENABLE)
    103   1.1  thorpej #define	CACHE40_OFF	(0x00000000)
    104   1.1  thorpej 
    105   1.1  thorpej #define	CACHE60_ON	(CACHE40_ON|IC60_CABC|IC60_EBC|DC60_ESB)
    106   1.1  thorpej #define	CACHE60_OFF	(CACHE40_OFF|IC60_CABC)
    107   1.6      scw 
    108  1.15  rkujawa #define CACHELINE_SIZE	16
    109  1.15  rkujawa #define CACHELINE_MASK	(CACHELINE_SIZE - 1)
    110  1.15  rkujawa 
    111  1.16  msaitoh /* CTL_MACHDEP definitions. (Common to all m68k ports.) */
    112  1.16  msaitoh #define	CPU_CONSDEV		1	/* dev_t: console terminal device */
    113  1.16  msaitoh #define	CPU_ROOT_DEVICE		2	/* string: root device name */
    114  1.16  msaitoh #define	CPU_BOOTED_KERNEL	3	/* string: booted kernel name */
    115  1.16  msaitoh 
    116  1.13       he #if defined(_KERNEL) || defined(_KMEMUSER)
    117  1.12     matt #include <sys/cpu_data.h>
    118  1.12     matt 
    119  1.12     matt struct cpu_info {
    120  1.12     matt 	struct cpu_data ci_data;	/* MI per-cpu data */
    121  1.12     matt 	cpuid_t	ci_cpuid;
    122  1.12     matt 	int	ci_mtx_count;
    123  1.12     matt 	int	ci_mtx_oldspl;
    124  1.12     matt 	volatile int	ci_want_resched;
    125  1.12     matt 	volatile int	ci_idepth;
    126  1.17       ad 	struct lwp *ci_onproc;		/* current user LWP / kthread */
    127  1.12     matt };
    128  1.12     matt #endif /* _KERNEL || _KMEMUSER */
    129  1.12     matt 
    130   1.6      scw #ifdef _KERNEL
    131  1.12     matt extern struct cpu_info cpu_info_store;
    132  1.12     matt 
    133  1.12     matt struct	proc;
    134  1.12     matt void	cpu_proc_fork(struct proc *, struct proc *);
    135  1.12     matt 
    136  1.12     matt #define	curcpu()	(&cpu_info_store)
    137  1.12     matt 
    138   1.6      scw /*
    139  1.12     matt  * definitions of cpu-dependent requirements
    140  1.12     matt  * referenced in generic code
    141   1.6      scw  */
    142  1.12     matt #define cpu_number()			0
    143   1.9  thorpej 
    144   1.9  thorpej #define LWP_PC(l)	(((struct trapframe *)((l)->l_md.md_regs))->tf_pc)
    145  1.22  thorpej 
    146  1.22  thorpej /*
    147  1.22  thorpej  * Arguments to hardclock and gatherstats encapsulate the previous
    148  1.22  thorpej  * machine state in an opaque clockframe.  On the m68k platforms, we use
    149  1.22  thorpej  * what the interrupt stub puts on the stack before calling C code.
    150  1.22  thorpej  */
    151  1.22  thorpej struct clockframe {
    152  1.22  thorpej 	/* regs saved on the stack by the interrupt stub */
    153  1.22  thorpej 	u_int	cf_regs[4];	/* d0,d1,a0,a1 */
    154  1.22  thorpej 	/* hardware frame */
    155  1.22  thorpej 	u_short	cf_sr;		/* sr at time of interrupt */
    156  1.22  thorpej 	u_long	cf_pc;		/* pc at time of interrupt */
    157  1.22  thorpej 	u_short	cf_vo;		/* vector offset (4-word HW frame) */
    158  1.22  thorpej } __attribute__((__packed__));
    159  1.22  thorpej 
    160  1.22  thorpej #define	CLKF_USERMODE(framep)	(((framep)->cf_sr & PSL_S) == 0)
    161  1.22  thorpej #define	CLKF_PC(framep)		((framep)->cf_pc)
    162  1.22  thorpej 
    163  1.22  thorpej #if 0
    164  1.22  thorpej /*
    165  1.22  thorpej  * We can determine if we were previously in an interrupt context
    166  1.22  thorpej  * if we were running on the interrupt stack (as opposed to the
    167  1.22  thorpej  * "master" stack).
    168  1.22  thorpej  *
    169  1.22  thorpej  * XXX Actually, we can't, because we don't use the master stack
    170  1.22  thorpej  * XXX right now.
    171  1.23  thorpej  *
    172  1.23  thorpej  * (Actually, it's unlikely that we'll ever use the master stack in NetBSD.
    173  1.23  thorpej  * It would complicate the spl*() functions considerably and it just doesn't
    174  1.23  thorpej  * seem like a good trade-off for what seems like extremely marginal gains.
    175  1.23  thorpej  * So, just blissfully run the kernel on the interrupt stack all the time,
    176  1.23  thorpej  * and it's been that way for >30 years and no one has really complained
    177  1.23  thorpej  * about it.)
    178  1.22  thorpej  */
    179  1.22  thorpej #define	CLKF_INTR(framep)	(((framep)->cf_sr & PSL_M) == 0)
    180  1.22  thorpej #else
    181  1.22  thorpej /*
    182  1.22  thorpej  * The clock interrupt handler can determine if it's a nested
    183  1.22  thorpej  * interrupt by checking for intr_depth > 1.
    184  1.22  thorpej  * (Remember, the clock interrupt handler itself will cause the
    185  1.22  thorpej  * depth counter to be incremented).
    186  1.22  thorpej  */
    187  1.22  thorpej extern volatile unsigned int intr_depth;
    188  1.22  thorpej #define	CLKF_INTR(framep)	(intr_depth > 1)
    189  1.22  thorpej #endif
    190  1.22  thorpej 
    191  1.22  thorpej #ifndef __HAVE_M68K_HW_AST
    192  1.22  thorpej #define	cpu_set_hw_ast(l)	__nothing
    193  1.22  thorpej #endif
    194  1.22  thorpej 
    195  1.22  thorpej extern volatile int astpending;
    196  1.22  thorpej #define	cpu_set_ast(l)							\
    197  1.22  thorpej 	do {								\
    198  1.22  thorpej 		__USE(l); astpending = 1; cpu_set_hw_ast(l);		\
    199  1.22  thorpej 	} while (/*CONSTCOND*/0)
    200  1.22  thorpej 
    201  1.22  thorpej /*
    202  1.22  thorpej  * Preempt the current process if in interrupt from user mode,
    203  1.22  thorpej  * or after the current trap/syscall if in system mode.
    204  1.22  thorpej  */
    205  1.22  thorpej #define	cpu_need_resched(ci, l, flags)					\
    206  1.22  thorpej 	do {								\
    207  1.22  thorpej 		__USE(ci); __USE(flags); cpu_set_ast(l);		\
    208  1.22  thorpej 	} while (/*CONSTCOND*/0)
    209  1.22  thorpej 
    210  1.22  thorpej /*
    211  1.22  thorpej  * Give a profiling tick to the current process when the user profiling
    212  1.22  thorpej  * buffer pages are invalid.  On m68k, request an ast to send us through
    213  1.22  thorpej  * trap, marking the proc as needing a profiling tick.
    214  1.22  thorpej  */
    215  1.22  thorpej #define	cpu_need_proftick(l)						\
    216  1.22  thorpej 	do {								\
    217  1.22  thorpej 		(l)->l_pflag |= LP_OWEUPC; cpu_set_ast(l);		\
    218  1.22  thorpej 	} while (/*CONSTCOND*/0)
    219  1.22  thorpej 
    220  1.22  thorpej /*
    221  1.22  thorpej  * Notify the current process (p) that it has a signal pending,
    222  1.22  thorpej  * process as soon as possible.
    223  1.22  thorpej  */
    224  1.22  thorpej #define	cpu_signotify(l)	cpu_set_ast(l)
    225  1.22  thorpej 
    226   1.6      scw #endif /* _KERNEL */
    227   1.1  thorpej 
    228   1.1  thorpej #endif /* _M68K_CPU_H_ */
    229