pcb.h revision 237027
1227825Stheraven/*- 2227825Stheraven * Copyright (c) 2003 Peter Wemm. 3227825Stheraven * Copyright (c) 1990 The Regents of the University of California. 4227825Stheraven * All rights reserved. 5227825Stheraven * 6227825Stheraven * This code is derived from software contributed to Berkeley by 7227825Stheraven * William Jolitz. 8227825Stheraven * 9227825Stheraven * Redistribution and use in source and binary forms, with or without 10227825Stheraven * modification, are permitted provided that the following conditions 11227825Stheraven * are met: 12227825Stheraven * 1. Redistributions of source code must retain the above copyright 13227825Stheraven * notice, this list of conditions and the following disclaimer. 14227825Stheraven * 2. Redistributions in binary form must reproduce the above copyright 15227825Stheraven * notice, this list of conditions and the following disclaimer in the 16227825Stheraven * documentation and/or other materials provided with the distribution. 17227825Stheraven * 4. Neither the name of the University nor the names of its contributors 18227825Stheraven * may be used to endorse or promote products derived from this software 19227825Stheraven * without specific prior written permission. 20227825Stheraven * 21227825Stheraven * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22227825Stheraven * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23227825Stheraven * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24227825Stheraven * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25227825Stheraven * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26227825Stheraven * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27227825Stheraven * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28227825Stheraven * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29227825Stheraven * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30227825Stheraven * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31227825Stheraven * SUCH DAMAGE. 32227825Stheraven * 33227825Stheraven * from: @(#)pcb.h 5.10 (Berkeley) 5/12/91 34227825Stheraven * $FreeBSD: head/sys/amd64/include/pcb.h 237027 2012-06-13 21:03:01Z jkim $ 35227825Stheraven */ 36227825Stheraven 37227825Stheraven#ifndef _AMD64_PCB_H_ 38227825Stheraven#define _AMD64_PCB_H_ 39227825Stheraven 40227825Stheraven/* 41227825Stheraven * AMD64 process control block 42227825Stheraven */ 43227825Stheraven#include <machine/fpu.h> 44227825Stheraven#include <machine/segments.h> 45227825Stheraven 46227825Stheravenstruct pcb { 47227825Stheraven register_t pcb_r15; 48227825Stheraven register_t pcb_r14; 49227825Stheraven register_t pcb_r13; 50227825Stheraven register_t pcb_r12; 51227825Stheraven register_t pcb_rbp; 52227825Stheraven register_t pcb_rsp; 53227825Stheraven register_t pcb_rbx; 54227825Stheraven register_t pcb_rip; 55227825Stheraven register_t pcb_fsbase; 56227825Stheraven register_t pcb_gsbase; 57227825Stheraven register_t pcb_kgsbase; 58227825Stheraven register_t pcb_cr0; 59227825Stheraven register_t pcb_cr2; 60227825Stheraven register_t pcb_cr3; 61227825Stheraven register_t pcb_cr4; 62227825Stheraven register_t pcb_dr0; 63227825Stheraven register_t pcb_dr1; 64227825Stheraven register_t pcb_dr2; 65227825Stheraven register_t pcb_dr3; 66227825Stheraven register_t pcb_dr6; 67227825Stheraven register_t pcb_dr7; 68227825Stheraven 69227825Stheraven struct region_descriptor pcb_gdt; 70227825Stheraven struct region_descriptor pcb_idt; 71227825Stheraven struct region_descriptor pcb_ldt; 72227825Stheraven uint16_t pcb_tr; 73227825Stheraven 74227825Stheraven u_int pcb_flags; 75227825Stheraven#define PCB_FULL_IRET 0x01 /* full iret is required */ 76227825Stheraven#define PCB_DBREGS 0x02 /* process using debug registers */ 77227825Stheraven#define PCB_KERNFPU 0x04 /* kernel uses fpu */ 78227825Stheraven#define PCB_FPUINITDONE 0x08 /* fpu state is initialized */ 79227825Stheraven#define PCB_USERFPUINITDONE 0x10 /* fpu user state is initialized */ 80227825Stheraven#define PCB_GS32BIT 0x20 /* linux gs switch */ 81227825Stheraven#define PCB_32BIT 0x40 /* process has 32 bit context (segs etc) */ 82227825Stheraven 83227825Stheraven uint16_t pcb_initial_fpucw; 84227825Stheraven 85227825Stheraven /* copyin/out fault recovery */ 86227825Stheraven caddr_t pcb_onfault; 87227825Stheraven 88227825Stheraven /* 32-bit segment descriptor */ 89227825Stheraven struct user_segment_descriptor pcb_gs32sd; 90227825Stheraven 91227825Stheraven /* local tss, with i/o bitmap; NULL for common */ 92227825Stheraven struct amd64tss *pcb_tssp; 93227825Stheraven 94227825Stheraven /* model specific registers */ 95227825Stheraven register_t pcb_efer; 96227825Stheraven register_t pcb_star; 97227825Stheraven register_t pcb_lstar; 98227825Stheraven register_t pcb_cstar; 99227825Stheraven register_t pcb_sfmask; 100227825Stheraven register_t pcb_xsmask; 101227825Stheraven 102227825Stheraven /* fpu context for suspend/resume */ 103227825Stheraven void *pcb_fpususpend; 104227825Stheraven 105227825Stheraven struct savefpu *pcb_save; 106227825Stheraven 107227825Stheraven uint64_t pcb_pad[3]; 108227825Stheraven}; 109227825Stheraven 110227825Stheraven#ifdef _KERNEL 111227825Stheravenstruct trapframe; 112227825Stheraven 113227825Stheraven/* 114227825Stheraven * The pcb_flags is only modified by current thread, or by other threads 115227825Stheraven * when current thread is stopped. However, current thread may change it 116227825Stheraven * from the interrupt context in cpu_switch(), or in the trap handler. 117227825Stheraven * When we read-modify-write pcb_flags from C sources, compiler may generate 118227825Stheraven * code that is not atomic regarding the interrupt handler. If a trap or 119227825Stheraven * interrupt happens and any flag is modified from the handler, it can be 120227825Stheraven * clobbered with the cached value later. Therefore, we implement setting 121227825Stheraven * and clearing flags with single-instruction functions, which do not race 122227825Stheraven * with possible modification of the flags from the trap or interrupt context, 123227825Stheraven * because traps and interrupts are executed only on instruction boundary. 124227825Stheraven */ 125227825Stheravenstatic __inline void 126227825Stheravenset_pcb_flags(struct pcb *pcb, const u_int flags) 127227825Stheraven{ 128227825Stheraven 129227825Stheraven __asm __volatile("orl %1,%0" 130227825Stheraven : "=m" (pcb->pcb_flags) : "ir" (flags), "m" (pcb->pcb_flags) 131227825Stheraven : "cc"); 132232950Stheraven} 133232950Stheraven 134227825Stheravenstatic __inline void 135227825Stheravenclear_pcb_flags(struct pcb *pcb, const u_int flags) 136227825Stheraven{ 137227825Stheraven 138227825Stheraven __asm __volatile("andl %1,%0" 139227825Stheraven : "=m" (pcb->pcb_flags) : "ir" (~flags), "m" (pcb->pcb_flags) 140227825Stheraven : "cc"); 141227825Stheraven} 142227825Stheraven 143227825Stheravenvoid makectx(struct trapframe *, struct pcb *); 144227825Stheravenint savectx(struct pcb *) __returns_twice; 145227825Stheravenvoid resumectx(struct pcb *, register_t); 146227825Stheraven 147227825Stheraven#endif 148227825Stheraven 149227825Stheraven#endif /* _AMD64_PCB_H_ */ 150227825Stheraven