pcb.h revision 330897
1314818Sngie/*- 2272343Sngie * SPDX-License-Identifier: BSD-3-Clause 3272343Sngie * 4272343Sngie * Copyright (c) 2003 Peter Wemm. 5272343Sngie * Copyright (c) 1990 The Regents of the University of California. 6272343Sngie * All rights reserved. 7272343Sngie * 8272343Sngie * This code is derived from software contributed to Berkeley by 9272343Sngie * William Jolitz. 10272343Sngie * 11272343Sngie * Redistribution and use in source and binary forms, with or without 12272343Sngie * modification, are permitted provided that the following conditions 13272343Sngie * are met: 14272343Sngie * 1. Redistributions of source code must retain the above copyright 15272343Sngie * notice, this list of conditions and the following disclaimer. 16272343Sngie * 2. Redistributions in binary form must reproduce the above copyright 17272343Sngie * notice, this list of conditions and the following disclaimer in the 18272343Sngie * documentation and/or other materials provided with the distribution. 19272343Sngie * 4. Neither the name of the University nor the names of its contributors 20272343Sngie * may be used to endorse or promote products derived from this software 21272343Sngie * without specific prior written permission. 22272343Sngie * 23272343Sngie * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24272343Sngie * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25272343Sngie * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26272343Sngie * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27272343Sngie * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28272343Sngie * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29272343Sngie * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30272343Sngie * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31272343Sngie * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32314818Sngie * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33272343Sngie * SUCH DAMAGE. 34272343Sngie * 35272343Sngie * from: @(#)pcb.h 5.10 (Berkeley) 5/12/91 36272343Sngie * $FreeBSD: stable/11/sys/amd64/include/pcb.h 330897 2018-03-14 03:19:51Z eadler $ 37272343Sngie */ 38272343Sngie 39272343Sngie#ifndef _AMD64_PCB_H_ 40272343Sngie#define _AMD64_PCB_H_ 41272343Sngie 42273535Sngie/* 43272343Sngie * AMD64 process control block 44273535Sngie */ 45272343Sngie#include <machine/fpu.h> 46272343Sngie#include <machine/segments.h> 47272343Sngie 48272343Sngie#ifdef __amd64__ 49272343Sngie/* 50272343Sngie * NB: The fields marked with (*) are used by kernel debuggers. Their 51272343Sngie * ABI should be preserved. 52272343Sngie */ 53327855Sasomersstruct pcb { 54327855Sasomers register_t pcb_r15; /* (*) */ 55327855Sasomers register_t pcb_r14; /* (*) */ 56327855Sasomers register_t pcb_r13; /* (*) */ 57327855Sasomers register_t pcb_r12; /* (*) */ 58272343Sngie register_t pcb_rbp; /* (*) */ 59272343Sngie register_t pcb_rsp; /* (*) */ 60272343Sngie register_t pcb_rbx; /* (*) */ 61272343Sngie register_t pcb_rip; /* (*) */ 62272343Sngie register_t pcb_fsbase; 63272343Sngie register_t pcb_gsbase; 64272343Sngie register_t pcb_kgsbase; 65272343Sngie register_t pcb_cr0; 66272343Sngie register_t pcb_cr2; 67272343Sngie register_t pcb_cr3; 68272343Sngie register_t pcb_cr4; 69272343Sngie register_t pcb_dr0; 70272343Sngie register_t pcb_dr1; 71272343Sngie register_t pcb_dr2; 72272343Sngie register_t pcb_dr3; 73272343Sngie register_t pcb_dr6; 74272343Sngie register_t pcb_dr7; 75272343Sngie 76272343Sngie struct region_descriptor pcb_gdt; 77272343Sngie struct region_descriptor pcb_idt; 78272343Sngie struct region_descriptor pcb_ldt; 79272343Sngie uint16_t pcb_tr; 80272343Sngie 81272343Sngie u_int pcb_flags; 82272343Sngie#define PCB_FULL_IRET 0x01 /* full iret is required */ 83272343Sngie#define PCB_DBREGS 0x02 /* process using debug registers */ 84272343Sngie#define PCB_KERNFPU 0x04 /* kernel uses fpu */ 85272343Sngie#define PCB_FPUINITDONE 0x08 /* fpu state is initialized */ 86272343Sngie#define PCB_USERFPUINITDONE 0x10 /* fpu user state is initialized */ 87272343Sngie#define PCB_32BIT 0x40 /* process has 32 bit context (segs etc) */ 88272343Sngie#define PCB_FPUNOSAVE 0x80 /* no save area for current FPU ctx */ 89272343Sngie 90272343Sngie uint16_t pcb_initial_fpucw; 91272343Sngie 92272343Sngie /* copyin/out fault recovery */ 93272343Sngie caddr_t pcb_onfault; 94272343Sngie 95272343Sngie uint64_t pcb_saved_ucr3; 96272343Sngie 97272343Sngie /* local tss, with i/o bitmap; NULL for common */ 98272343Sngie struct amd64tss *pcb_tssp; 99272343Sngie 100272343Sngie /* model specific registers */ 101272343Sngie register_t pcb_efer; 102272343Sngie register_t pcb_star; 103272343Sngie register_t pcb_lstar; 104272343Sngie register_t pcb_cstar; 105272343Sngie register_t pcb_sfmask; 106272343Sngie 107272343Sngie struct savefpu *pcb_save; 108272343Sngie 109272343Sngie uint64_t pcb_pad[5]; 110272343Sngie}; 111272343Sngie 112272343Sngie/* Per-CPU state saved during suspend and resume. */ 113272343Sngiestruct susppcb { 114272343Sngie struct pcb sp_pcb; 115272343Sngie 116272343Sngie /* fpu context for suspend/resume */ 117272343Sngie void *sp_fpususpend; 118272343Sngie}; 119272343Sngie#endif 120272343Sngie 121272343Sngie#ifdef _KERNEL 122272343Sngiestruct trapframe; 123272343Sngie 124272343Sngievoid clear_pcb_flags(struct pcb *pcb, const u_int flags); 125272343Sngievoid makectx(struct trapframe *, struct pcb *); 126272343Sngievoid set_pcb_flags(struct pcb *pcb, const u_int flags); 127272343Sngievoid set_pcb_flags_raw(struct pcb *pcb, const u_int flags); 128272343Sngieint savectx(struct pcb *) __returns_twice; 129272343Sngievoid resumectx(struct pcb *); 130272343Sngie 131272343Sngie/* Ensure that pcb_gsbase and pcb_fsbase are up to date */ 132311624Sngie#define update_pcb_bases(pcb) set_pcb_flags((pcb), PCB_FULL_IRET) 133272343Sngie#endif 134272343Sngie 135272343Sngie#endif /* _AMD64_PCB_H_ */ 136272343Sngie