1a9643ea8Slogwang /*- 2*22ce4affSfengbojiang * SPDX-License-Identifier: BSD-3-Clause 3*22ce4affSfengbojiang * 4a9643ea8Slogwang * Copyright (c) 2003 Peter Wemm. 5a9643ea8Slogwang * Copyright (c) 1990 The Regents of the University of California. 6a9643ea8Slogwang * All rights reserved. 7a9643ea8Slogwang * 8a9643ea8Slogwang * This code is derived from software contributed to Berkeley by 9a9643ea8Slogwang * William Jolitz. 10a9643ea8Slogwang * 11a9643ea8Slogwang * Redistribution and use in source and binary forms, with or without 12a9643ea8Slogwang * modification, are permitted provided that the following conditions 13a9643ea8Slogwang * are met: 14a9643ea8Slogwang * 1. Redistributions of source code must retain the above copyright 15a9643ea8Slogwang * notice, this list of conditions and the following disclaimer. 16a9643ea8Slogwang * 2. Redistributions in binary form must reproduce the above copyright 17a9643ea8Slogwang * notice, this list of conditions and the following disclaimer in the 18a9643ea8Slogwang * documentation and/or other materials provided with the distribution. 19*22ce4affSfengbojiang * 3. Neither the name of the University nor the names of its contributors 20a9643ea8Slogwang * may be used to endorse or promote products derived from this software 21a9643ea8Slogwang * without specific prior written permission. 22a9643ea8Slogwang * 23a9643ea8Slogwang * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24a9643ea8Slogwang * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25a9643ea8Slogwang * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26a9643ea8Slogwang * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27a9643ea8Slogwang * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28a9643ea8Slogwang * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29a9643ea8Slogwang * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30a9643ea8Slogwang * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31a9643ea8Slogwang * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32a9643ea8Slogwang * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33a9643ea8Slogwang * SUCH DAMAGE. 34a9643ea8Slogwang * 35a9643ea8Slogwang * from: @(#)pcb.h 5.10 (Berkeley) 5/12/91 36a9643ea8Slogwang * $FreeBSD$ 37a9643ea8Slogwang */ 38a9643ea8Slogwang 39a9643ea8Slogwang #ifndef _AMD64_PCB_H_ 40a9643ea8Slogwang #define _AMD64_PCB_H_ 41a9643ea8Slogwang 42a9643ea8Slogwang /* 43a9643ea8Slogwang * AMD64 process control block 44a9643ea8Slogwang */ 45a9643ea8Slogwang #include <machine/fpu.h> 46a9643ea8Slogwang #include <machine/segments.h> 47a9643ea8Slogwang 48a9643ea8Slogwang #ifdef __amd64__ 49a9643ea8Slogwang /* 50a9643ea8Slogwang * NB: The fields marked with (*) are used by kernel debuggers. Their 51a9643ea8Slogwang * ABI should be preserved. 52a9643ea8Slogwang */ 53a9643ea8Slogwang struct pcb { 54a9643ea8Slogwang register_t pcb_r15; /* (*) */ 55a9643ea8Slogwang register_t pcb_r14; /* (*) */ 56a9643ea8Slogwang register_t pcb_r13; /* (*) */ 57a9643ea8Slogwang register_t pcb_r12; /* (*) */ 58a9643ea8Slogwang register_t pcb_rbp; /* (*) */ 59a9643ea8Slogwang register_t pcb_rsp; /* (*) */ 60a9643ea8Slogwang register_t pcb_rbx; /* (*) */ 61a9643ea8Slogwang register_t pcb_rip; /* (*) */ 62a9643ea8Slogwang register_t pcb_fsbase; 63a9643ea8Slogwang register_t pcb_gsbase; 64a9643ea8Slogwang register_t pcb_kgsbase; 65a9643ea8Slogwang register_t pcb_cr0; 66a9643ea8Slogwang register_t pcb_cr2; 67a9643ea8Slogwang register_t pcb_cr3; 68a9643ea8Slogwang register_t pcb_cr4; 69a9643ea8Slogwang register_t pcb_dr0; 70a9643ea8Slogwang register_t pcb_dr1; 71a9643ea8Slogwang register_t pcb_dr2; 72a9643ea8Slogwang register_t pcb_dr3; 73a9643ea8Slogwang register_t pcb_dr6; 74a9643ea8Slogwang register_t pcb_dr7; 75a9643ea8Slogwang 76a9643ea8Slogwang struct region_descriptor pcb_gdt; 77a9643ea8Slogwang struct region_descriptor pcb_idt; 78a9643ea8Slogwang struct region_descriptor pcb_ldt; 79a9643ea8Slogwang uint16_t pcb_tr; 80a9643ea8Slogwang 81a9643ea8Slogwang u_int pcb_flags; 82a9643ea8Slogwang #define PCB_FULL_IRET 0x01 /* full iret is required */ 83a9643ea8Slogwang #define PCB_DBREGS 0x02 /* process using debug registers */ 84a9643ea8Slogwang #define PCB_KERNFPU 0x04 /* kernel uses fpu */ 85a9643ea8Slogwang #define PCB_FPUINITDONE 0x08 /* fpu state is initialized */ 86a9643ea8Slogwang #define PCB_USERFPUINITDONE 0x10 /* fpu user state is initialized */ 87*22ce4affSfengbojiang #define PCB_KERNFPU_THR 0x20 /* fpu_kern_thread() */ 88a9643ea8Slogwang #define PCB_32BIT 0x40 /* process has 32 bit context (segs etc) */ 89*22ce4affSfengbojiang #define PCB_FPUNOSAVE 0x80 /* no save area for current FPU ctx */ 90a9643ea8Slogwang 91a9643ea8Slogwang uint16_t pcb_initial_fpucw; 92a9643ea8Slogwang 93a9643ea8Slogwang /* copyin/out fault recovery */ 94a9643ea8Slogwang caddr_t pcb_onfault; 95a9643ea8Slogwang 96*22ce4affSfengbojiang uint64_t pcb_saved_ucr3; 97a9643ea8Slogwang 98a9643ea8Slogwang /* local tss, with i/o bitmap; NULL for common */ 99a9643ea8Slogwang struct amd64tss *pcb_tssp; 100a9643ea8Slogwang 101a9643ea8Slogwang /* model specific registers */ 102a9643ea8Slogwang register_t pcb_efer; 103a9643ea8Slogwang register_t pcb_star; 104a9643ea8Slogwang register_t pcb_lstar; 105a9643ea8Slogwang register_t pcb_cstar; 106a9643ea8Slogwang register_t pcb_sfmask; 107a9643ea8Slogwang 108a9643ea8Slogwang struct savefpu *pcb_save; 109a9643ea8Slogwang 110a9643ea8Slogwang uint64_t pcb_pad[5]; 111a9643ea8Slogwang }; 112a9643ea8Slogwang 113a9643ea8Slogwang /* Per-CPU state saved during suspend and resume. */ 114a9643ea8Slogwang struct susppcb { 115a9643ea8Slogwang struct pcb sp_pcb; 116a9643ea8Slogwang 117a9643ea8Slogwang /* fpu context for suspend/resume */ 118a9643ea8Slogwang void *sp_fpususpend; 119a9643ea8Slogwang }; 120*22ce4affSfengbojiang #else /* 32bit */ 121*22ce4affSfengbojiang struct pcb { 122*22ce4affSfengbojiang uint64_t pcb_dummy[40]; 123*22ce4affSfengbojiang }; 124a9643ea8Slogwang #endif 125a9643ea8Slogwang 126a9643ea8Slogwang #ifdef _KERNEL 127a9643ea8Slogwang struct trapframe; 128a9643ea8Slogwang 129*22ce4affSfengbojiang void clear_pcb_flags(struct pcb *pcb, const u_int flags); 130a9643ea8Slogwang void makectx(struct trapframe *, struct pcb *); 131*22ce4affSfengbojiang void set_pcb_flags(struct pcb *pcb, const u_int flags); 132*22ce4affSfengbojiang void set_pcb_flags_raw(struct pcb *pcb, const u_int flags); 133a9643ea8Slogwang int savectx(struct pcb *) __returns_twice; 134a9643ea8Slogwang void resumectx(struct pcb *); 135a9643ea8Slogwang 136*22ce4affSfengbojiang /* Ensure that pcb_gsbase and pcb_fsbase are up to date */ 137*22ce4affSfengbojiang #define update_pcb_bases(pcb) set_pcb_flags((pcb), PCB_FULL_IRET) 138a9643ea8Slogwang #endif 139a9643ea8Slogwang 140a9643ea8Slogwang #endif /* _AMD64_PCB_H_ */ 141