pcb.h revision 235539
1214478Srpaulo/*-
2190207Srpaulo * Copyright (c) 2003 Peter Wemm.
318976Sdfr * Copyright (c) 1990 The Regents of the University of California.
418976Sdfr * All rights reserved.
518976Sdfr *
618976Sdfr * This code is derived from software contributed to Berkeley by
718976Sdfr * William Jolitz.
818976Sdfr *
918976Sdfr * Redistribution and use in source and binary forms, with or without
1018976Sdfr * modification, are permitted provided that the following conditions
1118976Sdfr * are met:
1218976Sdfr * 1. Redistributions of source code must retain the above copyright
1318976Sdfr *    notice, this list of conditions and the following disclaimer.
1418976Sdfr * 2. Redistributions in binary form must reproduce the above copyright
1518976Sdfr *    notice, this list of conditions and the following disclaimer in the
1618976Sdfr *    documentation and/or other materials provided with the distribution.
1718976Sdfr * 4. Neither the name of the University nor the names of its contributors
1818976Sdfr *    may be used to endorse or promote products derived from this software
1918976Sdfr *    without specific prior written permission.
2018976Sdfr *
2118976Sdfr * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2218976Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2318976Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2418976Sdfr * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2518976Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2618976Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2718976Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2818976Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2918976Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3018976Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3118976Sdfr * SUCH DAMAGE.
3218976Sdfr *
3318976Sdfr *	from: @(#)pcb.h	5.10 (Berkeley) 5/12/91
3418976Sdfr * $FreeBSD: stable/9/sys/amd64/include/pcb.h 235539 2012-05-17 10:25:34Z dim $
3518976Sdfr */
3618976Sdfr
3718976Sdfr#ifndef _AMD64_PCB_H_
3818976Sdfr#define _AMD64_PCB_H_
3956896Sfenner
4018976Sdfr/*
4118976Sdfr * AMD64 process control block
4218976Sdfr */
4318976Sdfr#include <machine/fpu.h>
4418976Sdfr#include <machine/segments.h>
4518976Sdfr
4618976Sdfrstruct pcb {
4718976Sdfr	register_t	pcb_r15;
4818976Sdfr	register_t	pcb_r14;
4918976Sdfr	register_t	pcb_r13;
5018976Sdfr	register_t	pcb_r12;
5118976Sdfr	register_t	pcb_rbp;
5218976Sdfr	register_t	pcb_rsp;
5318976Sdfr	register_t	pcb_rbx;
5418976Sdfr	register_t	pcb_rip;
5518976Sdfr	register_t	pcb_fsbase;
5618976Sdfr	register_t	pcb_gsbase;
5718976Sdfr	register_t	pcb_kgsbase;
5818976Sdfr	register_t	pcb_cr0;
5918976Sdfr	register_t	pcb_cr2;
6018976Sdfr	register_t	pcb_cr3;
6118976Sdfr	register_t	pcb_cr4;
6218976Sdfr	register_t	pcb_dr0;
6318976Sdfr	register_t	pcb_dr1;
6418976Sdfr	register_t	pcb_dr2;
6518976Sdfr	register_t	pcb_dr3;
6618976Sdfr	register_t	pcb_dr6;
6718976Sdfr	register_t	pcb_dr7;
6818976Sdfr
6918976Sdfr	struct region_descriptor pcb_gdt;
7018976Sdfr	struct region_descriptor pcb_idt;
7118976Sdfr	struct region_descriptor pcb_ldt;
7218976Sdfr	uint16_t	pcb_tr;
7318976Sdfr
7418976Sdfr	u_int		pcb_flags;
7518976Sdfr#define	PCB_FULL_IRET	0x01	/* full iret is required */
7618976Sdfr#define	PCB_DBREGS	0x02	/* process using debug registers */
7718976Sdfr#define	PCB_KERNFPU	0x04	/* kernel uses fpu */
7818976Sdfr#define	PCB_FPUINITDONE	0x08	/* fpu state is initialized */
7918976Sdfr#define	PCB_USERFPUINITDONE 0x10 /* fpu user state is initialized */
8018976Sdfr#define	PCB_GS32BIT	0x20	/* linux gs switch */
8118976Sdfr#define	PCB_32BIT	0x40	/* process has 32 bit context (segs etc) */
8218976Sdfr
8318976Sdfr	uint16_t	pcb_initial_fpucw;
8418976Sdfr
8518976Sdfr	/* copyin/out fault recovery */
8618976Sdfr	caddr_t		pcb_onfault;
8718976Sdfr
8818976Sdfr	/* 32-bit segment descriptor */
8918976Sdfr	struct user_segment_descriptor pcb_gs32sd;
9018976Sdfr
9118976Sdfr	/* local tss, with i/o bitmap; NULL for common */
9218976Sdfr	struct amd64tss *pcb_tssp;
9318976Sdfr
9418976Sdfr	struct savefpu	*pcb_save;
9518976Sdfr
9618976Sdfr	uint64_t	pcb_pad[2];
9718976Sdfr};
9818976Sdfr
9918976Sdfr#ifdef _KERNEL
10018976Sdfrstruct trapframe;
10118976Sdfr
10218976Sdfr/*
10318976Sdfr * The pcb_flags is only modified by current thread, or by other threads
10418976Sdfr * when current thread is stopped.  However, current thread may change it
10518976Sdfr * from the interrupt context in cpu_switch(), or in the trap handler.
10618976Sdfr * When we read-modify-write pcb_flags from C sources, compiler may generate
10718976Sdfr * code that is not atomic regarding the interrupt handler.  If a trap or
10818976Sdfr * interrupt happens and any flag is modified from the handler, it can be
10918976Sdfr * clobbered with the cached value later.  Therefore, we implement setting
11018976Sdfr * and clearing flags with single-instruction functions, which do not race
11118976Sdfr * with possible modification of the flags from the trap or interrupt context,
11218976Sdfr * because traps and interrupts are executed only on instruction boundary.
11318976Sdfr */
11418976Sdfrstatic __inline void
11518976Sdfrset_pcb_flags(struct pcb *pcb, const u_int flags)
11618976Sdfr{
11718976Sdfr
11818976Sdfr	__asm __volatile("orl %1,%0"
11918976Sdfr	    : "=m" (pcb->pcb_flags) : "ir" (flags), "m" (pcb->pcb_flags)
12018976Sdfr	    : "cc");
12118976Sdfr}
12218976Sdfr
12318976Sdfrstatic __inline void
12418976Sdfrclear_pcb_flags(struct pcb *pcb, const u_int flags)
12518976Sdfr{
12618976Sdfr
12718976Sdfr	__asm __volatile("andl %1,%0"
12818976Sdfr	    : "=m" (pcb->pcb_flags) : "ir" (~flags), "m" (pcb->pcb_flags)
12918976Sdfr	    : "cc");
13018976Sdfr}
13118976Sdfr
13218976Sdfrvoid	makectx(struct trapframe *, struct pcb *);
13318976Sdfrint	savectx(struct pcb *) __returns_twice;
13418976Sdfr
13518976Sdfr#endif
13618976Sdfr
13718976Sdfr#endif /* _AMD64_PCB_H_ */
13818976Sdfr