Home | History | Annotate | Line # | Download | only in include
locore.h revision 1.17.2.2
      1  1.17.2.2  tls /*	$NetBSD: locore.h,v 1.17.2.2 2014/08/20 00:02:46 tls Exp $	*/
      2  1.17.2.2  tls 
      3  1.17.2.2  tls /*
      4  1.17.2.2  tls  * Copyright (c) 1994-1996 Mark Brinicombe.
      5  1.17.2.2  tls  * Copyright (c) 1994 Brini.
      6  1.17.2.2  tls  * All rights reserved.
      7  1.17.2.2  tls  *
      8  1.17.2.2  tls  * This code is derived from software written for Brini by Mark Brinicombe
      9  1.17.2.2  tls  *
     10  1.17.2.2  tls  * Redistribution and use in source and binary forms, with or without
     11  1.17.2.2  tls  * modification, are permitted provided that the following conditions
     12  1.17.2.2  tls  * are met:
     13  1.17.2.2  tls  * 1. Redistributions of source code must retain the above copyright
     14  1.17.2.2  tls  *    notice, this list of conditions and the following disclaimer.
     15  1.17.2.2  tls  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.17.2.2  tls  *    notice, this list of conditions and the following disclaimer in the
     17  1.17.2.2  tls  *    documentation and/or other materials provided with the distribution.
     18  1.17.2.2  tls  * 3. All advertising materials mentioning features or use of this software
     19  1.17.2.2  tls  *    must display the following acknowledgement:
     20  1.17.2.2  tls  *	This product includes software developed by Brini.
     21  1.17.2.2  tls  * 4. The name of the company nor the name of the author may be used to
     22  1.17.2.2  tls  *    endorse or promote products derived from this software without specific
     23  1.17.2.2  tls  *    prior written permission.
     24  1.17.2.2  tls  *
     25  1.17.2.2  tls  * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
     26  1.17.2.2  tls  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     27  1.17.2.2  tls  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     28  1.17.2.2  tls  * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     29  1.17.2.2  tls  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     30  1.17.2.2  tls  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     31  1.17.2.2  tls  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     32  1.17.2.2  tls  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33  1.17.2.2  tls  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     34  1.17.2.2  tls  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     35  1.17.2.2  tls  * SUCH DAMAGE.
     36  1.17.2.2  tls  *
     37  1.17.2.2  tls  * RiscBSD kernel project
     38  1.17.2.2  tls  *
     39  1.17.2.2  tls  * cpu.h
     40  1.17.2.2  tls  *
     41  1.17.2.2  tls  * CPU specific symbols
     42  1.17.2.2  tls  *
     43  1.17.2.2  tls  * Created      : 18/09/94
     44  1.17.2.2  tls  *
     45  1.17.2.2  tls  * Based on kate/katelib/arm6.h
     46  1.17.2.2  tls  */
     47  1.17.2.2  tls 
     48  1.17.2.2  tls #ifndef _ARM_LOCORE_H_
     49  1.17.2.2  tls #define _ARM_LOCORE_H_
     50  1.17.2.2  tls 
     51  1.17.2.2  tls #ifdef _KERNEL_OPT
     52  1.17.2.2  tls #include "opt_cpuoptions.h"
     53  1.17.2.2  tls #include "opt_cputypes.h"
     54  1.17.2.2  tls #include "opt_arm_debug.h"
     55  1.17.2.2  tls #endif
     56  1.17.2.2  tls 
     57  1.17.2.2  tls #include <arm/cpuconf.h>
     58  1.17.2.2  tls #include <arm/armreg.h>
     59  1.17.2.2  tls 
     60  1.17.2.2  tls #include <machine/frame.h>
     61  1.17.2.2  tls 
     62  1.17.2.2  tls #ifdef _LOCORE
     63  1.17.2.2  tls 
     64  1.17.2.2  tls #if defined(_ARM_ARCH_6)
     65  1.17.2.2  tls #define IRQdisable	cpsid	i
     66  1.17.2.2  tls #define IRQenable	cpsie	i
     67  1.17.2.2  tls #elif defined(__PROG32)
     68  1.17.2.2  tls #define IRQdisable \
     69  1.17.2.2  tls 	stmfd	sp!, {r0} ; \
     70  1.17.2.2  tls 	mrs	r0, cpsr ; \
     71  1.17.2.2  tls 	orr	r0, r0, #(I32_bit) ; \
     72  1.17.2.2  tls 	msr	cpsr_c, r0 ; \
     73  1.17.2.2  tls 	ldmfd	sp!, {r0}
     74  1.17.2.2  tls 
     75  1.17.2.2  tls #define IRQenable \
     76  1.17.2.2  tls 	stmfd	sp!, {r0} ; \
     77  1.17.2.2  tls 	mrs	r0, cpsr ; \
     78  1.17.2.2  tls 	bic	r0, r0, #(I32_bit) ; \
     79  1.17.2.2  tls 	msr	cpsr_c, r0 ; \
     80  1.17.2.2  tls 	ldmfd	sp!, {r0}
     81  1.17.2.2  tls #else
     82  1.17.2.2  tls /* Not yet used in 26-bit code */
     83  1.17.2.2  tls #endif
     84  1.17.2.2  tls 
     85  1.17.2.2  tls #if defined (TPIDRPRW_IS_CURCPU)
     86  1.17.2.2  tls #define GET_CURCPU(rX)		mrc	p15, 0, rX, c13, c0, 4
     87  1.17.2.2  tls #define GET_CURLWP(rX)		GET_CURCPU(rX); ldr rX, [rX, #CI_CURLWP]
     88  1.17.2.2  tls #elif defined (TPIDRPRW_IS_CURLWP)
     89  1.17.2.2  tls #define GET_CURLWP(rX)		mrc	p15, 0, rX, c13, c0, 4
     90  1.17.2.2  tls #define GET_CURCPU(rX)		GET_CURLWP(rX); ldr rX, [rX, #L_CPU]
     91  1.17.2.2  tls #elif !defined(MULTIPROCESSOR)
     92  1.17.2.2  tls #define GET_CURCPU(rX)		ldr rX, =_C_LABEL(cpu_info_store)
     93  1.17.2.2  tls #define GET_CURLWP(rX)		GET_CURCPU(rX); ldr rX, [rX, #CI_CURLWP]
     94  1.17.2.2  tls #endif
     95  1.17.2.2  tls #define GET_CURPCB(rX)		GET_CURLWP(rX); ldr rX, [rX, #L_PCB]
     96  1.17.2.2  tls 
     97  1.17.2.2  tls #else /* !_LOCORE */
     98  1.17.2.2  tls 
     99  1.17.2.2  tls #include <arm/cpufunc.h>
    100  1.17.2.2  tls 
    101  1.17.2.2  tls #ifdef __PROG32
    102  1.17.2.2  tls #define IRQdisable __set_cpsr_c(I32_bit, I32_bit);
    103  1.17.2.2  tls #define IRQenable __set_cpsr_c(I32_bit, 0);
    104  1.17.2.2  tls #else
    105  1.17.2.2  tls #define IRQdisable set_r15(R15_IRQ_DISABLE, R15_IRQ_DISABLE);
    106  1.17.2.2  tls #define IRQenable set_r15(R15_IRQ_DISABLE, 0);
    107  1.17.2.2  tls #endif
    108  1.17.2.2  tls 
    109  1.17.2.2  tls /*
    110  1.17.2.2  tls  * Validate a PC or PSR for a user process.  Used by various system calls
    111  1.17.2.2  tls  * that take a context passed by the user and restore it.
    112  1.17.2.2  tls  */
    113  1.17.2.2  tls 
    114  1.17.2.2  tls #ifdef __PROG32
    115  1.17.2.2  tls #define VALID_R15_PSR(r15,psr)						\
    116  1.17.2.2  tls 	(((psr) & PSR_MODE) == PSR_USR32_MODE &&			\
    117  1.17.2.2  tls 		((psr) & (I32_bit | F32_bit)) == 0)
    118  1.17.2.2  tls #else
    119  1.17.2.2  tls #define VALID_R15_PSR(r15,psr)						\
    120  1.17.2.2  tls 	(((r15) & R15_MODE) == R15_MODE_USR &&				\
    121  1.17.2.2  tls 		((r15) & (R15_IRQ_DISABLE | R15_FIQ_DISABLE)) == 0)
    122  1.17.2.2  tls #endif
    123  1.17.2.2  tls 
    124  1.17.2.2  tls 
    125  1.17.2.2  tls 
    126  1.17.2.2  tls /* The address of the vector page. */
    127  1.17.2.2  tls extern vaddr_t vector_page;
    128  1.17.2.2  tls #ifdef __PROG32
    129  1.17.2.2  tls void	arm32_vector_init(vaddr_t, int);
    130  1.17.2.2  tls 
    131  1.17.2.2  tls #define	ARM_VEC_RESET			(1 << 0)
    132  1.17.2.2  tls #define	ARM_VEC_UNDEFINED		(1 << 1)
    133  1.17.2.2  tls #define	ARM_VEC_SWI			(1 << 2)
    134  1.17.2.2  tls #define	ARM_VEC_PREFETCH_ABORT		(1 << 3)
    135  1.17.2.2  tls #define	ARM_VEC_DATA_ABORT		(1 << 4)
    136  1.17.2.2  tls #define	ARM_VEC_ADDRESS_EXCEPTION	(1 << 5)
    137  1.17.2.2  tls #define	ARM_VEC_IRQ			(1 << 6)
    138  1.17.2.2  tls #define	ARM_VEC_FIQ			(1 << 7)
    139  1.17.2.2  tls 
    140  1.17.2.2  tls #define	ARM_NVEC			8
    141  1.17.2.2  tls #define	ARM_VEC_ALL			0xffffffff
    142  1.17.2.2  tls #endif /* __PROG32 */
    143  1.17.2.2  tls 
    144  1.17.2.2  tls #ifndef acorn26
    145  1.17.2.2  tls /*
    146  1.17.2.2  tls  * cpu device glue (belongs in cpuvar.h)
    147  1.17.2.2  tls  */
    148  1.17.2.2  tls void	cpu_attach(device_t, cpuid_t);
    149  1.17.2.2  tls #endif
    150  1.17.2.2  tls 
    151  1.17.2.2  tls /* 1 == use cpu_sleep(), 0 == don't */
    152  1.17.2.2  tls extern int cpu_do_powersave;
    153  1.17.2.2  tls extern int cpu_printfataltraps;
    154  1.17.2.2  tls extern int cpu_fpu_present;
    155  1.17.2.2  tls extern int cpu_hwdiv_present;
    156  1.17.2.2  tls extern int cpu_neon_present;
    157  1.17.2.2  tls extern int cpu_simd_present;
    158  1.17.2.2  tls extern int cpu_simdex_present;
    159  1.17.2.2  tls extern int cpu_umull_present;
    160  1.17.2.2  tls extern int cpu_synchprim_present;
    161  1.17.2.2  tls 
    162  1.17.2.2  tls extern int cpu_instruction_set_attributes[6];
    163  1.17.2.2  tls extern int cpu_memory_model_features[4];
    164  1.17.2.2  tls extern int cpu_processor_features[2];
    165  1.17.2.2  tls extern int cpu_media_and_vfp_features[2];
    166  1.17.2.2  tls 
    167  1.17.2.2  tls extern bool arm_has_tlbiasid_p;
    168  1.17.2.2  tls #ifdef MULTIPROCESSOR
    169  1.17.2.2  tls extern u_int arm_cpu_max;
    170  1.17.2.2  tls extern volatile u_int arm_cpu_hatched;
    171  1.17.2.2  tls #endif
    172  1.17.2.2  tls 
    173  1.17.2.2  tls #if !defined(CPU_ARMV7)
    174  1.17.2.2  tls #define	CPU_IS_ARMV7_P()		false
    175  1.17.2.2  tls #elif defined(CPU_ARMV6) || defined(CPU_PRE_ARMV6)
    176  1.17.2.2  tls extern bool cpu_armv7_p;
    177  1.17.2.2  tls #define	CPU_IS_ARMV7_P()		(cpu_armv7_p)
    178  1.17.2.2  tls #else
    179  1.17.2.2  tls #define	CPU_IS_ARMV7_P()		true
    180  1.17.2.2  tls #endif
    181  1.17.2.2  tls #if !defined(CPU_ARMV6)
    182  1.17.2.2  tls #define	CPU_IS_ARMV6_P()		false
    183  1.17.2.2  tls #elif defined(CPU_ARMV7) || defined(CPU_PRE_ARMV6)
    184  1.17.2.2  tls extern bool cpu_armv6_p;
    185  1.17.2.2  tls #define	CPU_IS_ARMV6_P()		(cpu_armv6_p)
    186  1.17.2.2  tls #else
    187  1.17.2.2  tls #define	CPU_IS_ARMV6_P()		true
    188  1.17.2.2  tls #endif
    189  1.17.2.2  tls 
    190  1.17.2.2  tls /*
    191  1.17.2.2  tls  * Used by the fault code to read the current instruction.
    192  1.17.2.2  tls  */
    193  1.17.2.2  tls static inline uint32_t
    194  1.17.2.2  tls read_insn(vaddr_t va, bool user_p)
    195  1.17.2.2  tls {
    196  1.17.2.2  tls 	uint32_t insn;
    197  1.17.2.2  tls 	if (user_p) {
    198  1.17.2.2  tls 		__asm __volatile("ldrt %0, [%1]" : "=&r"(insn) : "r"(va));
    199  1.17.2.2  tls 	} else {
    200  1.17.2.2  tls 		insn = *(const uint32_t *)va;
    201  1.17.2.2  tls 	}
    202  1.17.2.2  tls #if defined(__ARMEB__) && defined(_ARM_ARCH_7)
    203  1.17.2.2  tls 	insn = bswap32(insn);
    204  1.17.2.2  tls #endif
    205  1.17.2.2  tls 	return insn;
    206  1.17.2.2  tls }
    207  1.17.2.2  tls 
    208  1.17.2.2  tls /*
    209  1.17.2.2  tls  * Used by the fault code to read the current thumb instruction.
    210  1.17.2.2  tls  */
    211  1.17.2.2  tls static inline uint32_t
    212  1.17.2.2  tls read_thumb_insn(vaddr_t va, bool user_p)
    213  1.17.2.2  tls {
    214  1.17.2.2  tls 	va &= ~1;
    215  1.17.2.2  tls 	uint32_t insn;
    216  1.17.2.2  tls 	if (user_p) {
    217  1.17.2.2  tls #ifdef _ARM_ARCH_T2
    218  1.17.2.2  tls 		__asm __volatile("ldrht %0, [%1], #0" : "=&r"(insn) : "r"(va));
    219  1.17.2.2  tls #else
    220  1.17.2.2  tls 		__asm __volatile("ldrt %0, [%1]" : "=&r"(insn) : "r"(va & ~3));
    221  1.17.2.2  tls #ifdef __ARMEB__
    222  1.17.2.2  tls 		insn = (uint16_t) (insn >> (((va ^ 2) & 2) << 3));
    223  1.17.2.2  tls #else
    224  1.17.2.2  tls 		insn = (uint16_t) (insn >> ((va & 2) << 3));
    225  1.17.2.2  tls #endif
    226  1.17.2.2  tls #endif
    227  1.17.2.2  tls 	} else {
    228  1.17.2.2  tls 		insn = *(const uint16_t *)va;
    229  1.17.2.2  tls 	}
    230  1.17.2.2  tls #if defined(__ARMEB__) && defined(_ARM_ARCH_7)
    231  1.17.2.2  tls 	insn = bswap16(insn);
    232  1.17.2.2  tls #endif
    233  1.17.2.2  tls 	return insn;
    234  1.17.2.2  tls }
    235  1.17.2.2  tls 
    236  1.17.2.2  tls static inline void
    237  1.17.2.2  tls arm_dmb(void)
    238  1.17.2.2  tls {
    239  1.17.2.2  tls 	if (CPU_IS_ARMV6_P())
    240  1.17.2.2  tls 		armreg_dmb_write(0);
    241  1.17.2.2  tls 	else if (CPU_IS_ARMV7_P())
    242  1.17.2.2  tls 		__asm __volatile("dmb");
    243  1.17.2.2  tls }
    244  1.17.2.2  tls 
    245  1.17.2.2  tls static inline void
    246  1.17.2.2  tls arm_dsb(void)
    247  1.17.2.2  tls {
    248  1.17.2.2  tls 	if (CPU_IS_ARMV6_P())
    249  1.17.2.2  tls 		armreg_dsb_write(0);
    250  1.17.2.2  tls 	else if (CPU_IS_ARMV7_P())
    251  1.17.2.2  tls 		__asm __volatile("dsb");
    252  1.17.2.2  tls }
    253  1.17.2.2  tls 
    254  1.17.2.2  tls static inline void
    255  1.17.2.2  tls arm_isb(void)
    256  1.17.2.2  tls {
    257  1.17.2.2  tls 	if (CPU_IS_ARMV6_P())
    258  1.17.2.2  tls 		armreg_isb_write(0);
    259  1.17.2.2  tls 	else if (CPU_IS_ARMV7_P())
    260  1.17.2.2  tls 		__asm __volatile("isb");
    261  1.17.2.2  tls }
    262  1.17.2.2  tls 
    263  1.17.2.2  tls /*
    264  1.17.2.2  tls  * Random cruft
    265  1.17.2.2  tls  */
    266  1.17.2.2  tls 
    267  1.17.2.2  tls struct lwp;
    268  1.17.2.2  tls 
    269  1.17.2.2  tls /* cpu.c */
    270  1.17.2.2  tls void	identify_arm_cpu(device_t, struct cpu_info *);
    271  1.17.2.2  tls 
    272  1.17.2.2  tls /* cpuswitch.S */
    273  1.17.2.2  tls struct pcb;
    274  1.17.2.2  tls void	savectx(struct pcb *);
    275  1.17.2.2  tls 
    276  1.17.2.2  tls /* ast.c */
    277  1.17.2.2  tls void	userret(struct lwp *);
    278  1.17.2.2  tls 
    279  1.17.2.2  tls /* *_machdep.c */
    280  1.17.2.2  tls void	bootsync(void);
    281  1.17.2.2  tls 
    282  1.17.2.2  tls /* fault.c */
    283  1.17.2.2  tls int	badaddr_read(void *, size_t, void *);
    284  1.17.2.2  tls 
    285  1.17.2.2  tls /* syscall.c */
    286  1.17.2.2  tls void	swi_handler(trapframe_t *);
    287  1.17.2.2  tls 
    288  1.17.2.2  tls /* arm_machdep.c */
    289  1.17.2.2  tls void	ucas_ras_check(trapframe_t *);
    290  1.17.2.2  tls 
    291  1.17.2.2  tls /* vfp_init.c */
    292  1.17.2.2  tls void	vfp_attach(struct cpu_info *);
    293  1.17.2.2  tls void	vfp_discardcontext(bool);
    294  1.17.2.2  tls void	vfp_savecontext(void);
    295  1.17.2.2  tls void	vfp_kernel_acquire(void);
    296  1.17.2.2  tls void	vfp_kernel_release(void);
    297  1.17.2.2  tls bool	vfp_used_p(void);
    298  1.17.2.2  tls extern const pcu_ops_t arm_vfp_ops;
    299  1.17.2.2  tls 
    300  1.17.2.2  tls #endif	/* !_LOCORE */
    301  1.17.2.2  tls 
    302  1.17.2.2  tls #endif /* !_ARM_LOCORE_H_ */
    303