xref: /freebsd/sys/arm/include/cpu.h (revision 5608fd23c27fa1e8ee595d7b678cbfd35d657fbe)
1 /* $NetBSD: cpu.h,v 1.2 2001/02/23 21:23:52 reinoud Exp $ */
2 /* $FreeBSD$ */
3 
4 #ifndef MACHINE_CPU_H
5 #define MACHINE_CPU_H
6 
7 #include <machine/armreg.h>
8 #include <machine/frame.h>
9 
10 void	cpu_halt(void);
11 void	swi_vm(void *);
12 
13 #ifdef _KERNEL
14 static __inline uint64_t
15 get_cyclecount(void)
16 {
17 /* This '#if' asks the question 'Does CP15/SCC include performance counters?' */
18 #if defined(CPU_ARM1136) || defined(CPU_ARM1176) \
19  || defined(CPU_MV_PJ4B) \
20  || defined(CPU_CORTEXA) || defined(CPU_KRAIT)
21 	uint32_t ccnt;
22 	uint64_t ccnt64;
23 
24 	/*
25 	 * Read PMCCNTR. Curses! Its only 32 bits.
26 	 * TODO: Fix this by catching overflow with interrupt?
27 	 */
28 /* The ARMv6 vs ARMv7 divide is going to need a better way of
29  * distinguishing between them.
30  */
31 #if defined(CPU_ARM1136) || defined(CPU_ARM1176)
32 	/* ARMv6 - Earlier model SCCs */
33 	__asm __volatile("mrc p15, 0, %0, c15, c12, 1": "=r" (ccnt));
34 #else
35 	/* ARMv7 - Later model SCCs */
36 	__asm __volatile("mrc p15, 0, %0, c9, c13, 0": "=r" (ccnt));
37 #endif
38 	ccnt64 = (uint64_t)ccnt;
39 	return (ccnt64);
40 #else /* No performance counters, so use binuptime(9). This is slooooow */
41 	struct bintime bt;
42 
43 	binuptime(&bt);
44 	return ((uint64_t)bt.sec << 56 | bt.frac >> 8);
45 #endif
46 }
47 #endif
48 
49 #define TRAPF_USERMODE(frame)	((frame->tf_spsr & PSR_MODE) == PSR_USR32_MODE)
50 
51 #define TRAPF_PC(tfp)		((tfp)->tf_pc)
52 
53 #define cpu_getstack(td)	((td)->td_frame->tf_usr_sp)
54 #define cpu_setstack(td, sp)	((td)->td_frame->tf_usr_sp = (sp))
55 #define cpu_spinwait()		/* nothing */
56 
57 #define ARM_NVEC		8
58 #define ARM_VEC_ALL		0xffffffff
59 
60 extern vm_offset_t vector_page;
61 
62 /*
63  * Params passed into initarm. If you change the size of this you will
64  * need to update locore.S to allocate more memory on the stack before
65  * it calls initarm.
66  */
67 struct arm_boot_params {
68 	register_t	abp_size;	/* Size of this structure */
69 	register_t	abp_r0;		/* r0 from the boot loader */
70 	register_t	abp_r1;		/* r1 from the boot loader */
71 	register_t	abp_r2;		/* r2 from the boot loader */
72 	register_t	abp_r3;		/* r3 from the boot loader */
73 	vm_offset_t	abp_physaddr;	/* The kernel physical address */
74 	vm_offset_t	abp_pagetable;	/* The early page table */
75 };
76 
77 void	arm_vector_init(vm_offset_t, int);
78 void	fork_trampoline(void);
79 void	identify_arm_cpu(void);
80 void	*initarm(struct arm_boot_params *);
81 
82 extern char btext[];
83 extern char etext[];
84 int badaddr_read(void *, size_t, void *);
85 #endif /* !MACHINE_CPU_H */
86