xref: /minix3/sys/arch/x86/include/cpufunc.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: cpufunc.h,v 1.18 2014/02/25 22:16:52 dsl Exp $	*/
21cd76c75SBen Gras 
31cd76c75SBen Gras /*-
41cd76c75SBen Gras  * Copyright (c) 1998, 2007 The NetBSD Foundation, Inc.
51cd76c75SBen Gras  * All rights reserved.
61cd76c75SBen Gras  *
71cd76c75SBen Gras  * This code is derived from software contributed to The NetBSD Foundation
81cd76c75SBen Gras  * by Charles M. Hannum, and by Andrew Doran.
91cd76c75SBen Gras  *
101cd76c75SBen Gras  * Redistribution and use in source and binary forms, with or without
111cd76c75SBen Gras  * modification, are permitted provided that the following conditions
121cd76c75SBen Gras  * are met:
131cd76c75SBen Gras  * 1. Redistributions of source code must retain the above copyright
141cd76c75SBen Gras  *    notice, this list of conditions and the following disclaimer.
151cd76c75SBen Gras  * 2. Redistributions in binary form must reproduce the above copyright
161cd76c75SBen Gras  *    notice, this list of conditions and the following disclaimer in the
171cd76c75SBen Gras  *    documentation and/or other materials provided with the distribution.
181cd76c75SBen Gras  *
191cd76c75SBen Gras  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
201cd76c75SBen Gras  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211cd76c75SBen Gras  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221cd76c75SBen Gras  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
231cd76c75SBen Gras  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241cd76c75SBen Gras  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251cd76c75SBen Gras  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261cd76c75SBen Gras  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271cd76c75SBen Gras  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281cd76c75SBen Gras  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291cd76c75SBen Gras  * POSSIBILITY OF SUCH DAMAGE.
301cd76c75SBen Gras  */
311cd76c75SBen Gras 
321cd76c75SBen Gras #ifndef _X86_CPUFUNC_H_
331cd76c75SBen Gras #define	_X86_CPUFUNC_H_
341cd76c75SBen Gras 
351cd76c75SBen Gras /*
361cd76c75SBen Gras  * Functions to provide access to x86-specific instructions.
371cd76c75SBen Gras  */
381cd76c75SBen Gras 
391cd76c75SBen Gras #include <sys/cdefs.h>
401cd76c75SBen Gras #include <sys/types.h>
411cd76c75SBen Gras 
421cd76c75SBen Gras #include <machine/segments.h>
431cd76c75SBen Gras #include <machine/specialreg.h>
441cd76c75SBen Gras 
451cd76c75SBen Gras #ifdef _KERNEL
461cd76c75SBen Gras 
471cd76c75SBen Gras void	x86_pause(void);
481cd76c75SBen Gras void	x86_lfence(void);
491cd76c75SBen Gras void	x86_sfence(void);
501cd76c75SBen Gras void	x86_mfence(void);
511cd76c75SBen Gras void	x86_flush(void);
521cd76c75SBen Gras #ifndef XEN
531cd76c75SBen Gras void	x86_patch(bool);
541cd76c75SBen Gras #endif
551cd76c75SBen Gras void	invlpg(vaddr_t);
561cd76c75SBen Gras void	lidt(struct region_descriptor *);
571cd76c75SBen Gras void	lldt(u_short);
581cd76c75SBen Gras void	ltr(u_short);
591cd76c75SBen Gras void	lcr0(u_long);
601cd76c75SBen Gras u_long	rcr0(void);
611cd76c75SBen Gras void	lcr2(vaddr_t);
621cd76c75SBen Gras vaddr_t	rcr2(void);
631cd76c75SBen Gras void	lcr3(vaddr_t);
641cd76c75SBen Gras vaddr_t	rcr3(void);
651cd76c75SBen Gras void	lcr4(vaddr_t);
661cd76c75SBen Gras vaddr_t	rcr4(void);
671cd76c75SBen Gras void	lcr8(vaddr_t);
681cd76c75SBen Gras vaddr_t	rcr8(void);
691cd76c75SBen Gras void	tlbflush(void);
701cd76c75SBen Gras void	tlbflushg(void);
711cd76c75SBen Gras void	dr0(void *, uint32_t, uint32_t, uint32_t);
721cd76c75SBen Gras vaddr_t	rdr6(void);
731cd76c75SBen Gras void	ldr6(vaddr_t);
741cd76c75SBen Gras void	wbinvd(void);
751cd76c75SBen Gras void	breakpoint(void);
761cd76c75SBen Gras void	x86_hlt(void);
771cd76c75SBen Gras void	x86_stihlt(void);
781cd76c75SBen Gras u_int	x86_getss(void);
79*0a6a1f1dSLionel Sambuc 
80*0a6a1f1dSLionel Sambuc /* fpu save, restore etc */
81*0a6a1f1dSLionel Sambuc union savefpu;
82*0a6a1f1dSLionel Sambuc void	fldcw(const uint16_t *);
831cd76c75SBen Gras void	fnclex(void);
841cd76c75SBen Gras void	fninit(void);
85*0a6a1f1dSLionel Sambuc void	fnsave(union savefpu *);
86*0a6a1f1dSLionel Sambuc void	fnstcw(uint16_t *);
87*0a6a1f1dSLionel Sambuc uint16_t fngetsw(void);
88*0a6a1f1dSLionel Sambuc void	fnstsw(uint16_t *);
89*0a6a1f1dSLionel Sambuc void	frstor(const union savefpu *);
901cd76c75SBen Gras void	fwait(void);
911cd76c75SBen Gras void	clts(void);
921cd76c75SBen Gras void	stts(void);
93*0a6a1f1dSLionel Sambuc void	fxsave(union savefpu *);
94*0a6a1f1dSLionel Sambuc void	fxrstor(const union savefpu *);
95*0a6a1f1dSLionel Sambuc void	x86_ldmxcsr(const uint32_t *);
96*0a6a1f1dSLionel Sambuc void	x86_stmxcsr(uint32_t *);
97*0a6a1f1dSLionel Sambuc 
98*0a6a1f1dSLionel Sambuc void	fldummy(void);
99*0a6a1f1dSLionel Sambuc void	fp_divide_by_0(void);
100*0a6a1f1dSLionel Sambuc 
101*0a6a1f1dSLionel Sambuc /* Extended processor state functions (for AVX registers etc) */
102*0a6a1f1dSLionel Sambuc 
103*0a6a1f1dSLionel Sambuc uint64_t rdxcr(uint32_t);		/* xgetbv */
104*0a6a1f1dSLionel Sambuc void	wrxcr(uint32_t, uint64_t);	/* xsetgv */
105*0a6a1f1dSLionel Sambuc 
106*0a6a1f1dSLionel Sambuc void	xrstor(const union savefpu *, uint64_t);
107*0a6a1f1dSLionel Sambuc void	xsave(union savefpu *, uint64_t);
108*0a6a1f1dSLionel Sambuc void	xsaveopt(union savefpu *, uint64_t);
109*0a6a1f1dSLionel Sambuc 
1101cd76c75SBen Gras void	x86_monitor(const void *, uint32_t, uint32_t);
1111cd76c75SBen Gras void	x86_mwait(uint32_t, uint32_t);
112*0a6a1f1dSLionel Sambuc /* x86_cpuid2() writes four 32bit values, %eax, %ebx, %ecx and %edx */
1131cd76c75SBen Gras #define	x86_cpuid(a,b)	x86_cpuid2((a),0,(b))
114*0a6a1f1dSLionel Sambuc void	x86_cpuid2(uint32_t, uint32_t, uint32_t *);
1151cd76c75SBen Gras 
1161cd76c75SBen Gras /* Use read_psl, write_psl when saving and restoring interrupt state. */
1171cd76c75SBen Gras void	x86_disable_intr(void);
1181cd76c75SBen Gras void	x86_enable_intr(void);
1191cd76c75SBen Gras u_long	x86_read_psl(void);
1201cd76c75SBen Gras void	x86_write_psl(u_long);
1211cd76c75SBen Gras 
1221cd76c75SBen Gras /* Use read_flags, write_flags to adjust other members of %eflags. */
1231cd76c75SBen Gras u_long	x86_read_flags(void);
1241cd76c75SBen Gras void	x86_write_flags(u_long);
1251cd76c75SBen Gras 
1261cd76c75SBen Gras void	x86_reset(void);
1271cd76c75SBen Gras 
1281cd76c75SBen Gras /*
1291cd76c75SBen Gras  * Some of the undocumented AMD64 MSRs need a 'passcode' to access.
1301cd76c75SBen Gras  *
1311cd76c75SBen Gras  * See LinuxBIOSv2: src/cpu/amd/model_fxx/model_fxx_init.c
1321cd76c75SBen Gras  */
1331cd76c75SBen Gras 
1341cd76c75SBen Gras #define	OPTERON_MSR_PASSCODE	0x9c5a203aU
1351cd76c75SBen Gras 
1361cd76c75SBen Gras uint64_t	rdmsr(u_int);
1371cd76c75SBen Gras uint64_t	rdmsr_locked(u_int, u_int);
1381cd76c75SBen Gras int		rdmsr_safe(u_int, uint64_t *);
1391cd76c75SBen Gras uint64_t	rdtsc(void);
1401cd76c75SBen Gras uint64_t	rdpmc(u_int);
1411cd76c75SBen Gras void		wrmsr(u_int, uint64_t);
1421cd76c75SBen Gras void		wrmsr_locked(u_int, u_int, uint64_t);
1431cd76c75SBen Gras void		setfs(int);
1441cd76c75SBen Gras void		setusergs(int);
1451cd76c75SBen Gras 
1461cd76c75SBen Gras #endif /* _KERNEL */
1471cd76c75SBen Gras 
1481cd76c75SBen Gras #endif /* !_X86_CPUFUNC_H_ */
149