Home | History | Annotate | Line # | Download | only in include
cpu.h revision 1.9
      1  1.9    bjh21 /*	$NetBSD: cpu.h,v 1.9 2001/02/28 18:15:43 bjh21 Exp $	*/
      2  1.1  reinoud 
      3  1.1  reinoud /*
      4  1.1  reinoud  * Copyright (c) 1994-1996 Mark Brinicombe.
      5  1.1  reinoud  * Copyright (c) 1994 Brini.
      6  1.1  reinoud  * All rights reserved.
      7  1.1  reinoud  *
      8  1.1  reinoud  * This code is derived from software written for Brini by Mark Brinicombe
      9  1.1  reinoud  *
     10  1.1  reinoud  * Redistribution and use in source and binary forms, with or without
     11  1.1  reinoud  * modification, are permitted provided that the following conditions
     12  1.1  reinoud  * are met:
     13  1.1  reinoud  * 1. Redistributions of source code must retain the above copyright
     14  1.1  reinoud  *    notice, this list of conditions and the following disclaimer.
     15  1.1  reinoud  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  reinoud  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  reinoud  *    documentation and/or other materials provided with the distribution.
     18  1.1  reinoud  * 3. All advertising materials mentioning features or use of this software
     19  1.1  reinoud  *    must display the following acknowledgement:
     20  1.1  reinoud  *	This product includes software developed by Brini.
     21  1.1  reinoud  * 4. The name of the company nor the name of the author may be used to
     22  1.1  reinoud  *    endorse or promote products derived from this software without specific
     23  1.1  reinoud  *    prior written permission.
     24  1.1  reinoud  *
     25  1.1  reinoud  * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
     26  1.1  reinoud  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     27  1.1  reinoud  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     28  1.1  reinoud  * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     29  1.1  reinoud  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     30  1.1  reinoud  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     31  1.1  reinoud  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     32  1.1  reinoud  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33  1.1  reinoud  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     34  1.1  reinoud  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     35  1.1  reinoud  * SUCH DAMAGE.
     36  1.1  reinoud  *
     37  1.1  reinoud  * RiscBSD kernel project
     38  1.1  reinoud  *
     39  1.1  reinoud  * cpu.h
     40  1.1  reinoud  *
     41  1.1  reinoud  * CPU specific symbols
     42  1.1  reinoud  *
     43  1.1  reinoud  * Created      : 18/09/94
     44  1.1  reinoud  *
     45  1.1  reinoud  * Based on kate/katelib/arm6.h
     46  1.1  reinoud  */
     47  1.1  reinoud 
     48  1.1  reinoud #ifndef _ARM32_CPU_H_
     49  1.1  reinoud #define _ARM32_CPU_H_
     50  1.1  reinoud 
     51  1.8    bjh21 /*
     52  1.8    bjh21  * User-visible definitions
     53  1.8    bjh21  */
     54  1.8    bjh21 
     55  1.8    bjh21 /*  CTL_MACHDEP definitions. */
     56  1.8    bjh21 #define	CPU_DEBUG		1	/* int: misc kernel debug control */
     57  1.8    bjh21 #define	CPU_BOOTED_DEVICE	2	/* string: device we booted from */
     58  1.8    bjh21 #define	CPU_BOOTED_KERNEL	3	/* string: kernel we booted */
     59  1.8    bjh21 #define	CPU_CONSDEV		4	/* struct: dev_t of our console */
     60  1.8    bjh21 #define	CPU_MAXID		5	/* number of valid machdep ids */
     61  1.8    bjh21 
     62  1.8    bjh21 #define	CTL_MACHDEP_NAMES { \
     63  1.8    bjh21 	{ 0, 0 }, \
     64  1.8    bjh21 	{ "debug", CTLTYPE_INT }, \
     65  1.8    bjh21 	{ "booted_device", CTLTYPE_STRING }, \
     66  1.8    bjh21 	{ "booted_kernel", CTLTYPE_STRING }, \
     67  1.8    bjh21 	{ "console_device", CTLTYPE_STRUCT }, \
     68  1.8    bjh21 }
     69  1.8    bjh21 
     70  1.8    bjh21 #ifdef _KERNEL
     71  1.8    bjh21 
     72  1.8    bjh21 /*
     73  1.8    bjh21  * Kernel-only definitions
     74  1.8    bjh21  */
     75  1.8    bjh21 
     76  1.8    bjh21 #ifndef _LKM
     77  1.1  reinoud #include "opt_cputypes.h"
     78  1.1  reinoud #include "opt_lockdebug.h"
     79  1.7    bjh21 #include "opt_progmode.h"
     80  1.1  reinoud 
     81  1.7    bjh21 #if defined(PROG26) && defined(PROG32)
     82  1.7    bjh21 #error "26-bit and 32-bit CPU support are not compatible"
     83  1.7    bjh21 #endif
     84  1.7    bjh21 #if !defined(PROG26) && !defined(PROG32)
     85  1.7    bjh21 #error "Support for at least one CPU type must be configured into the kernel"
     86  1.1  reinoud #endif
     87  1.1  reinoud 
     88  1.1  reinoud #ifdef CPU_ARM7500
     89  1.7    bjh21 #ifndef CPU_ARM7
     90  1.7    bjh21 #error "option CPU_ARM7 is required with CPU_ARM7500"
     91  1.7    bjh21 #endif
     92  1.1  reinoud #ifdef CPU_ARM6
     93  1.1  reinoud #error "CPU options CPU_ARM6 and CPU_ARM7500 are not compatible"
     94  1.1  reinoud #endif
     95  1.1  reinoud #ifdef CPU_ARM8
     96  1.1  reinoud #error "CPU options CPU_ARM8 and CPU_ARM7500 are not compatible"
     97  1.1  reinoud #endif
     98  1.1  reinoud #ifdef CPU_SA110
     99  1.1  reinoud #error "CPU options CPU_SA110 and CPU_ARM7500 are not compatible"
    100  1.1  reinoud #endif
    101  1.1  reinoud #endif /* CPU_ARM7500 */
    102  1.7    bjh21 
    103  1.8    bjh21 #endif /* !_LKM */
    104  1.8    bjh21 
    105  1.8    bjh21 
    106  1.8    bjh21 #ifndef _LOCORE
    107  1.9    bjh21 #include <sys/user.h>
    108  1.8    bjh21 #include <machine/frame.h>
    109  1.9    bjh21 #include <machine/pcb.h>
    110  1.8    bjh21 #endif	/* !_LOCORE */
    111  1.8    bjh21 
    112  1.8    bjh21 #ifdef arm26
    113  1.8    bjh21 extern int astpending;
    114  1.8    bjh21 #define setsoftast() (astpending = 1)
    115  1.8    bjh21 #else
    116  1.8    bjh21 #include <machine/psl.h>
    117  1.8    bjh21 #endif
    118  1.8    bjh21 
    119  1.7    bjh21 #include <arm/armreg.h>
    120  1.1  reinoud 
    121  1.8    bjh21 #ifdef PROG32
    122  1.1  reinoud #ifdef _LOCORE
    123  1.1  reinoud #define IRQdisable \
    124  1.1  reinoud 	stmfd	sp!, {r0} ; \
    125  1.1  reinoud 	mrs	r0, cpsr_all ; \
    126  1.1  reinoud 	orr	r0, r0, #(I32_bit) ; \
    127  1.1  reinoud 	msr	cpsr_all, r0 ; \
    128  1.1  reinoud 	ldmfd	sp!, {r0}
    129  1.1  reinoud 
    130  1.1  reinoud #define IRQenable \
    131  1.1  reinoud 	stmfd	sp!, {r0} ; \
    132  1.1  reinoud 	mrs	r0, cpsr_all ; \
    133  1.1  reinoud 	bic	r0, r0, #(I32_bit) ; \
    134  1.1  reinoud 	msr	cpsr_all, r0 ; \
    135  1.1  reinoud 	ldmfd	sp!, {r0}
    136  1.1  reinoud 
    137  1.1  reinoud #else
    138  1.1  reinoud #define IRQdisable SetCPSR(I32_bit, I32_bit);
    139  1.1  reinoud #define IRQenable SetCPSR(I32_bit, 0);
    140  1.1  reinoud #endif	/* _LOCORE */
    141  1.8    bjh21 #endif
    142  1.1  reinoud 
    143  1.8    bjh21 /* All the CLKF_* macros take a struct clockframe * as an argument. */
    144  1.8    bjh21 
    145  1.8    bjh21 #ifdef PROG32
    146  1.1  reinoud /*
    147  1.1  reinoud  * Return TRUE/FALSE (1/0) depending on whether the frame came from USR
    148  1.1  reinoud  * mode or not.
    149  1.1  reinoud  */
    150  1.1  reinoud 
    151  1.1  reinoud #define CLKF_USERMODE(frame) ((frame->if_spsr & PSR_MODE) == PSR_USR32_MODE)
    152  1.1  reinoud 
    153  1.1  reinoud /*
    154  1.8    bjh21  * This needs straighening, prob is the frame does not have info on the
    155  1.8    bjh21  * priority a guess that needs trying is (current_spl_level == SPL0)
    156  1.1  reinoud  */
    157  1.1  reinoud 
    158  1.1  reinoud #define CLKF_BASEPRI(frame) ((frame->if_spsr & PSR_MODE) == PSR_USR32_MODE)
    159  1.1  reinoud 
    160  1.1  reinoud #define CLKF_PC(frame) (frame->if_pc)
    161  1.1  reinoud 
    162  1.1  reinoud /*#define CLKF_INTR(frame) (current_intr_depth > 1)*/
    163  1.1  reinoud 
    164  1.1  reinoud /* Hack to treat FPE time as interrupt time so we can measure it */
    165  1.1  reinoud #define CLKF_INTR(frame) ((current_intr_depth > 1) || (frame->if_spsr & PSR_MODE) == PSR_UND32_MODE)
    166  1.1  reinoud 
    167  1.9    bjh21 #define	PROC_PC(p)	((p)->p_addr->u_pcb.pcb_tf->tf_pc)
    168  1.1  reinoud 
    169  1.8    bjh21 #elif defined(PROG26)
    170  1.8    bjh21 
    171  1.8    bjh21 /* True if we took the interrupt in user mode */
    172  1.8    bjh21 #define CLKF_USERMODE(frame)	((frame->if_r15 & R15_MODE) == R15_MODE_USR)
    173  1.8    bjh21 
    174  1.8    bjh21 /* True if we were at spl0 before the interrupt */
    175  1.8    bjh21 #define CLKF_BASEPRI(frame)	0	/* FIXME */
    176  1.8    bjh21 
    177  1.8    bjh21 /* Extract the program counter from a clockframe */
    178  1.8    bjh21 #define CLKF_PC(frame)		(frame->if_r15 & R15_PC)
    179  1.8    bjh21 
    180  1.8    bjh21 /* True if we took the interrupt from inside another interrupt handler. */
    181  1.8    bjh21 /* Non-trivial to check because we handle interrupts in SVC mode. */
    182  1.8    bjh21 #define CLKF_INTR(frame)	0	/* FIXME */
    183  1.8    bjh21 
    184  1.8    bjh21 #endif
    185  1.8    bjh21 
    186  1.1  reinoud /*
    187  1.1  reinoud  * definitions of cpu-dependent requirements
    188  1.1  reinoud  * referenced in generic code
    189  1.1  reinoud  */
    190  1.1  reinoud 
    191  1.1  reinoud #ifndef _LOCORE
    192  1.1  reinoud #include <sys/sched.h>
    193  1.1  reinoud struct cpu_info {
    194  1.1  reinoud 	struct schedstate_percpu ci_schedstate; /* scheduler state */
    195  1.1  reinoud #if defined(DIAGNOSTIC) || defined(LOCKDEBUG)
    196  1.1  reinoud 	u_long ci_spin_locks;		/* # of spin locks held */
    197  1.1  reinoud 	u_long ci_simple_locks;		/* # of simple locks held */
    198  1.1  reinoud #endif
    199  1.1  reinoud };
    200  1.1  reinoud #ifdef _KERNEL
    201  1.1  reinoud extern struct cpu_info cpu_info_store;
    202  1.1  reinoud #define	curcpu()	(&cpu_info_store)
    203  1.1  reinoud #endif /* _KERNEL */
    204  1.1  reinoud #endif /* ! _LOCORE */
    205  1.1  reinoud 
    206  1.1  reinoud /*
    207  1.1  reinoud  * Notify the current process (p) that it has a signal pending,
    208  1.1  reinoud  * process as soon as possible.
    209  1.1  reinoud  */
    210  1.1  reinoud 
    211  1.1  reinoud #define signotify(p)            setsoftast()
    212  1.1  reinoud 
    213  1.5  reinoud #define cpu_wait(p)	/* nothing */
    214  1.6  reinoud #define cpu_number()	0
    215  1.1  reinoud 
    216  1.8    bjh21 #ifndef _LOCORE
    217  1.1  reinoud extern int current_intr_depth;
    218  1.1  reinoud 
    219  1.1  reinoud /*
    220  1.1  reinoud  * Preempt the current process if in interrupt from user mode,
    221  1.1  reinoud  * or after the current trap/syscall if in system mode.
    222  1.1  reinoud  */
    223  1.1  reinoud int	want_resched;		/* resched() was called */
    224  1.1  reinoud #define	need_resched(ci)	(want_resched = 1, setsoftast())
    225  1.1  reinoud 
    226  1.1  reinoud /*
    227  1.1  reinoud  * Give a profiling tick to the current process when the user profiling
    228  1.1  reinoud  * buffer pages are invalid.  On the i386, request an ast to send us
    229  1.1  reinoud  * through trap(), marking the proc as needing a profiling tick.
    230  1.1  reinoud  */
    231  1.1  reinoud #define	need_proftick(p)	((p)->p_flag |= P_OWEUPC, setsoftast())
    232  1.1  reinoud 
    233  1.1  reinoud /* locore.S */
    234  1.1  reinoud void atomic_set_bit	__P((u_int *address, u_int setmask));
    235  1.1  reinoud void atomic_clear_bit	__P((u_int *address, u_int clearmask));
    236  1.1  reinoud 
    237  1.1  reinoud /* cpuswitch.S */
    238  1.1  reinoud struct pcb;
    239  1.1  reinoud void	savectx		__P((struct pcb *pcb));
    240  1.1  reinoud 
    241  1.8    bjh21 #ifndef arm26
    242  1.1  reinoud /* ast.c */
    243  1.1  reinoud void userret		__P((register struct proc *p));
    244  1.8    bjh21 #endif
    245  1.1  reinoud 
    246  1.1  reinoud /* machdep.h */
    247  1.1  reinoud void bootsync		__P((void));
    248  1.1  reinoud 
    249  1.1  reinoud /* strstr.c */
    250  1.1  reinoud char *strstr		__P((const char *s1, const char *s2));
    251  1.1  reinoud 
    252  1.1  reinoud /* syscall.c */
    253  1.1  reinoud void child_return	__P((void *));
    254  1.1  reinoud 
    255  1.8    bjh21 #endif	/* !_LOCORE */
    256  1.1  reinoud 
    257  1.8    bjh21 #endif /* _KERNEL */
    258  1.1  reinoud 
    259  1.1  reinoud #endif /* !_ARM32_CPU_H_ */
    260  1.1  reinoud 
    261  1.1  reinoud /* End of cpu.h */
    262