166a4f9a2SBen Gras /* $NetBSD: cpu.h,v 1.178 2011/12/30 17:57:49 cherry Exp $ */
2f87b9a3dSAntoine Leca
366a4f9a2SBen Gras /*-
466a4f9a2SBen Gras * Copyright (c) 1990 The Regents of the University of California.
566a4f9a2SBen Gras * All rights reserved.
666a4f9a2SBen Gras *
766a4f9a2SBen Gras * This code is derived from software contributed to Berkeley by
866a4f9a2SBen Gras * William Jolitz.
966a4f9a2SBen Gras *
1066a4f9a2SBen Gras * Redistribution and use in source and binary forms, with or without
1166a4f9a2SBen Gras * modification, are permitted provided that the following conditions
1266a4f9a2SBen Gras * are met:
1366a4f9a2SBen Gras * 1. Redistributions of source code must retain the above copyright
1466a4f9a2SBen Gras * notice, this list of conditions and the following disclaimer.
1566a4f9a2SBen Gras * 2. Redistributions in binary form must reproduce the above copyright
1666a4f9a2SBen Gras * notice, this list of conditions and the following disclaimer in the
1766a4f9a2SBen Gras * documentation and/or other materials provided with the distribution.
1866a4f9a2SBen Gras * 3. Neither the name of the University nor the names of its contributors
1966a4f9a2SBen Gras * may be used to endorse or promote products derived from this software
2066a4f9a2SBen Gras * without specific prior written permission.
2166a4f9a2SBen Gras *
2266a4f9a2SBen Gras * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2366a4f9a2SBen Gras * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2466a4f9a2SBen Gras * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2566a4f9a2SBen Gras * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2666a4f9a2SBen Gras * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2766a4f9a2SBen Gras * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2866a4f9a2SBen Gras * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2966a4f9a2SBen Gras * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3066a4f9a2SBen Gras * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3166a4f9a2SBen Gras * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3266a4f9a2SBen Gras * SUCH DAMAGE.
3366a4f9a2SBen Gras *
3466a4f9a2SBen Gras * @(#)cpu.h 5.4 (Berkeley) 5/9/91
3566a4f9a2SBen Gras */
36f87b9a3dSAntoine Leca
3766a4f9a2SBen Gras #ifndef _I386_CPU_H_
3866a4f9a2SBen Gras #define _I386_CPU_H_
39f87b9a3dSAntoine Leca
40f14fb602SLionel Sambuc #include <x86/cpu.h>
41f14fb602SLionel Sambuc
4266a4f9a2SBen Gras #ifdef _KERNEL
4366a4f9a2SBen Gras
4466a4f9a2SBen Gras #if defined(__GNUC__) && !defined(_MODULE)
4566a4f9a2SBen Gras static struct cpu_info *x86_curcpu(void);
4666a4f9a2SBen Gras static lwp_t *x86_curlwp(void);
4766a4f9a2SBen Gras
4866a4f9a2SBen Gras __inline static struct cpu_info * __unused
x86_curcpu(void)4966a4f9a2SBen Gras x86_curcpu(void)
5066a4f9a2SBen Gras {
5166a4f9a2SBen Gras struct cpu_info *ci;
5266a4f9a2SBen Gras
5366a4f9a2SBen Gras __asm volatile("movl %%fs:%1, %0" :
5466a4f9a2SBen Gras "=r" (ci) :
5566a4f9a2SBen Gras "m"
5666a4f9a2SBen Gras (*(struct cpu_info * const *)offsetof(struct cpu_info, ci_self)));
5766a4f9a2SBen Gras return ci;
5866a4f9a2SBen Gras }
5966a4f9a2SBen Gras
6066a4f9a2SBen Gras __inline static lwp_t * __attribute__ ((const))
x86_curlwp(void)6166a4f9a2SBen Gras x86_curlwp(void)
6266a4f9a2SBen Gras {
6366a4f9a2SBen Gras lwp_t *l;
6466a4f9a2SBen Gras
6566a4f9a2SBen Gras __asm volatile("movl %%fs:%1, %0" :
6666a4f9a2SBen Gras "=r" (l) :
6766a4f9a2SBen Gras "m"
6866a4f9a2SBen Gras (*(struct cpu_info * const *)offsetof(struct cpu_info, ci_curlwp)));
6966a4f9a2SBen Gras return l;
7066a4f9a2SBen Gras }
7166a4f9a2SBen Gras
7266a4f9a2SBen Gras __inline static void __unused
cpu_set_curpri(int pri)7366a4f9a2SBen Gras cpu_set_curpri(int pri)
7466a4f9a2SBen Gras {
7566a4f9a2SBen Gras
7666a4f9a2SBen Gras __asm volatile(
7766a4f9a2SBen Gras "movl %1, %%fs:%0" :
7866a4f9a2SBen Gras "=m" (*(struct cpu_info *)offsetof(struct cpu_info, ci_schedstate.spc_curpriority)) :
7966a4f9a2SBen Gras "r" (pri)
8066a4f9a2SBen Gras );
8166a4f9a2SBen Gras }
82f87b9a3dSAntoine Leca #endif
8366a4f9a2SBen Gras
8466a4f9a2SBen Gras #define CLKF_USERMODE(frame) USERMODE((frame)->cf_if.if_cs, (frame)->cf_if.if_eflags)
8566a4f9a2SBen Gras #define CLKF_PC(frame) ((frame)->cf_if.if_eip)
8666a4f9a2SBen Gras #define CLKF_INTR(frame) (curcpu()->ci_idepth > 0)
8766a4f9a2SBen Gras #define LWP_PC(l) ((l)->l_md.md_regs->tf_eip)
8866a4f9a2SBen Gras
8966a4f9a2SBen Gras #ifdef PAE
9066a4f9a2SBen Gras void cpu_alloc_l3_page(struct cpu_info *);
9166a4f9a2SBen Gras #endif /* PAE */
9266a4f9a2SBen Gras
9366a4f9a2SBen Gras #endif /* _KERNEL */
9466a4f9a2SBen Gras
95*84d9c625SLionel Sambuc #if defined(__minix)
9666a4f9a2SBen Gras #include <x86/psl.h>
9766a4f9a2SBen Gras /* User flags are S (Status) and C (Control) flags. */
9866a4f9a2SBen Gras #define X86_FLAGS_USER (PSL_C | PSL_PF | PSL_AF | PSL_Z | \
9966a4f9a2SBen Gras PSL_N | PSL_D | PSL_V)
100*84d9c625SLionel Sambuc #endif /* defined(__minix) */
10166a4f9a2SBen Gras
10266a4f9a2SBen Gras #endif /* !_I386_CPU_H_ */
103