segments.h revision 92761
1231200Smm/*- 2231200Smm * Copyright (c) 1989, 1990 William F. Jolitz 3231200Smm * Copyright (c) 1990 The Regents of the University of California. 4231200Smm * All rights reserved. 5231200Smm * 6231200Smm * This code is derived from software contributed to Berkeley by 7231200Smm * William Jolitz. 8231200Smm * 9231200Smm * Redistribution and use in source and binary forms, with or without 10231200Smm * modification, are permitted provided that the following conditions 11231200Smm * are met: 12231200Smm * 1. Redistributions of source code must retain the above copyright 13231200Smm * notice, this list of conditions and the following disclaimer. 14231200Smm * 2. Redistributions in binary form must reproduce the above copyright 15231200Smm * notice, this list of conditions and the following disclaimer in the 16231200Smm * documentation and/or other materials provided with the distribution. 17231200Smm * 3. All advertising materials mentioning features or use of this software 18231200Smm * must display the following acknowledgement: 19231200Smm * This product includes software developed by the University of 20231200Smm * California, Berkeley and its contributors. 21231200Smm * 4. Neither the name of the University nor the names of its contributors 22231200Smm * may be used to endorse or promote products derived from this software 23231200Smm * without specific prior written permission. 24231200Smm * 25238856Smm * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26231200Smm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27368708Smm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28238856Smm * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29231200Smm * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30231200Smm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31231200Smm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32368708Smm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33231200Smm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34231200Smm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35231200Smm * SUCH DAMAGE. 36231200Smm * 37231200Smm * from: @(#)segments.h 7.1 (Berkeley) 5/9/91 38238856Smm * $FreeBSD: head/sys/i386/include/segments.h 92761 2002-03-20 05:48:58Z alfred $ 39238856Smm */ 40231200Smm 41231200Smm#ifndef _MACHINE_SEGMENTS_H_ 42231200Smm#define _MACHINE_SEGMENTS_H_ 43231200Smm 44231200Smm/* 45231200Smm * 386 Segmentation Data Structures and definitions 46231200Smm * William F. Jolitz (william@ernie.berkeley.edu) 6/20/1989 47231200Smm */ 48231200Smm 49231200Smm/* 50231200Smm * Selectors 51368708Smm */ 52368708Smm 53368708Smm#define ISPL(s) ((s)&3) /* what is the priority level of a selector */ 54368708Smm#define SEL_KPL 0 /* kernel priority level */ 55368708Smm#define SEL_UPL 3 /* user priority level */ 56368708Smm#define ISLDT(s) ((s)&SEL_LDT) /* is it local or global */ 57368708Smm#define SEL_LDT 4 /* local descriptor table */ 58368708Smm#define IDXSEL(s) (((s)>>3) & 0x1fff) /* index of selector */ 59368708Smm#define LSEL(s,r) (((s)<<3) | SEL_LDT | r) /* a local selector */ 60231200Smm#define GSEL(s,r) (((s)<<3) | r) /* a global selector */ 61231200Smm 62231200Smm/* 63231200Smm * Memory and System segment descriptors 64231200Smm */ 65231200Smmstruct segment_descriptor { 66231200Smm unsigned sd_lolimit:16 ; /* segment extent (lsb) */ 67231200Smm unsigned sd_lobase:24 __attribute__ ((packed)); 68231200Smm /* segment base address (lsb) */ 69231200Smm unsigned sd_type:5 ; /* segment type */ 70231200Smm unsigned sd_dpl:2 ; /* segment descriptor priority level */ 71231200Smm unsigned sd_p:1 ; /* segment descriptor present */ 72231200Smm unsigned sd_hilimit:4 ; /* segment extent (msb) */ 73231200Smm unsigned sd_xx:2 ; /* unused */ 74231200Smm unsigned sd_def32:1 ; /* default 32 vs 16 bit size */ 75231200Smm unsigned sd_gran:1 ; /* limit granularity (byte/page units)*/ 76231200Smm unsigned sd_hibase:8 ; /* segment base address (msb) */ 77231200Smm} ; 78231200Smm 79313571Smm/* 80368708Smm * Gate descriptors (e.g. indirect descriptors) 81368708Smm */ 82368708Smmstruct gate_descriptor { 83368708Smm unsigned gd_looffset:16 ; /* gate offset (lsb) */ 84368708Smm unsigned gd_selector:16 ; /* gate segment selector */ 85231200Smm unsigned gd_stkcpy:5 ; /* number of stack wds to cpy */ 86231200Smm unsigned gd_xx:3 ; /* unused */ 87231200Smm unsigned gd_type:5 ; /* segment type */ 88231200Smm unsigned gd_dpl:2 ; /* segment descriptor priority level */ 89231200Smm unsigned gd_p:1 ; /* segment descriptor present */ 90231200Smm unsigned gd_hioffset:16 ; /* gate offset (msb) */ 91231200Smm} ; 92231200Smm 93231200Smm/* 94231200Smm * Generic descriptor 95231200Smm */ 96231200Smmunion descriptor { 97231200Smm struct segment_descriptor sd; 98231200Smm struct gate_descriptor gd; 99231200Smm}; 100231200Smm 101231200Smm /* system segments and gate types */ 102231200Smm#define SDT_SYSNULL 0 /* system null */ 103231200Smm#define SDT_SYS286TSS 1 /* system 286 TSS available */ 104231200Smm#define SDT_SYSLDT 2 /* system local descriptor table */ 105231200Smm#define SDT_SYS286BSY 3 /* system 286 TSS busy */ 106231200Smm#define SDT_SYS286CGT 4 /* system 286 call gate */ 107231200Smm#define SDT_SYSTASKGT 5 /* system task gate */ 108231200Smm#define SDT_SYS286IGT 6 /* system 286 interrupt gate */ 109231200Smm#define SDT_SYS286TGT 7 /* system 286 trap gate */ 110231200Smm#define SDT_SYSNULL2 8 /* system null again */ 111231200Smm#define SDT_SYS386TSS 9 /* system 386 TSS available */ 112231200Smm#define SDT_SYSNULL3 10 /* system null again */ 113231200Smm#define SDT_SYS386BSY 11 /* system 386 TSS busy */ 114231200Smm#define SDT_SYS386CGT 12 /* system 386 call gate */ 115231200Smm#define SDT_SYSNULL4 13 /* system null again */ 116231200Smm#define SDT_SYS386IGT 14 /* system 386 interrupt gate */ 117231200Smm#define SDT_SYS386TGT 15 /* system 386 trap gate */ 118231200Smm 119231200Smm /* memory segment types */ 120231200Smm#define SDT_MEMRO 16 /* memory read only */ 121231200Smm#define SDT_MEMROA 17 /* memory read only accessed */ 122231200Smm#define SDT_MEMRW 18 /* memory read write */ 123231200Smm#define SDT_MEMRWA 19 /* memory read write accessed */ 124368708Smm#define SDT_MEMROD 20 /* memory read only expand dwn limit */ 125231200Smm#define SDT_MEMRODA 21 /* memory read only expand dwn limit accessed */ 126231200Smm#define SDT_MEMRWD 22 /* memory read write expand dwn limit */ 127231200Smm#define SDT_MEMRWDA 23 /* memory read write expand dwn limit accessed */ 128231200Smm#define SDT_MEME 24 /* memory execute only */ 129231200Smm#define SDT_MEMEA 25 /* memory execute only accessed */ 130231200Smm#define SDT_MEMER 26 /* memory execute read */ 131368708Smm#define SDT_MEMERA 27 /* memory execute read accessed */ 132231200Smm#define SDT_MEMEC 28 /* memory execute only conforming */ 133231200Smm#define SDT_MEMEAC 29 /* memory execute only accessed conforming */ 134231200Smm#define SDT_MEMERC 30 /* memory execute read conforming */ 135231200Smm#define SDT_MEMERAC 31 /* memory execute read accessed conforming */ 136231200Smm 137231200Smm/* is memory segment descriptor pointer ? */ 138231200Smm#define ISMEMSDP(s) ((s->d_type) >= SDT_MEMRO && (s->d_type) <= SDT_MEMERAC) 139231200Smm 140231200Smm/* is 286 gate descriptor pointer ? */ 141231200Smm#define IS286GDP(s) (((s->d_type) >= SDT_SYS286CGT \ 142313571Smm && (s->d_type) < SDT_SYS286TGT)) 143313571Smm 144231200Smm/* is 386 gate descriptor pointer ? */ 145231200Smm#define IS386GDP(s) (((s->d_type) >= SDT_SYS386CGT \ 146231200Smm && (s->d_type) < SDT_SYS386TGT)) 147231200Smm 148231200Smm/* is gate descriptor pointer ? */ 149231200Smm#define ISGDP(s) (IS286GDP(s) || IS386GDP(s)) 150313571Smm 151313571Smm/* is segment descriptor pointer ? */ 152313571Smm#define ISSDP(s) (ISMEMSDP(s) || !ISGDP(s)) 153313571Smm 154313571Smm/* is system segment descriptor pointer ? */ 155313571Smm#define ISSYSSDP(s) (!ISMEMSDP(s) && !ISGDP(s)) 156313571Smm 157231200Smm/* 158231200Smm * Software definitions are in this convenient format, 159231200Smm * which are translated into inconvenient segment descriptors 160231200Smm * when needed to be used by the 386 hardware 161231200Smm */ 162231200Smm 163368708Smmstruct soft_segment_descriptor { 164231200Smm unsigned ssd_base ; /* segment base address */ 165231200Smm unsigned ssd_limit ; /* segment extent */ 166231200Smm unsigned ssd_type:5 ; /* segment type */ 167231200Smm unsigned ssd_dpl:2 ; /* segment descriptor priority level */ 168231200Smm unsigned ssd_p:1 ; /* segment descriptor present */ 169231200Smm unsigned ssd_xx:4 ; /* unused */ 170231200Smm unsigned ssd_xx1:2 ; /* unused */ 171231200Smm unsigned ssd_def32:1 ; /* default 32 vs 16 bit size */ 172231200Smm unsigned ssd_gran:1 ; /* limit granularity (byte/page units)*/ 173231200Smm}; 174231200Smm 175231200Smm/* 176231200Smm * region descriptors, used to load gdt/idt tables before segments yet exist. 177231200Smm */ 178231200Smmstruct region_descriptor { 179231200Smm unsigned rd_limit:16; /* segment extent */ 180368708Smm unsigned rd_base:32 __attribute__ ((packed)); /* base address */ 181368708Smm}; 182231200Smm 183231200Smm/* 184302001Smm * Segment Protection Exception code bits 185231200Smm */ 186231200Smm 187231200Smm#define SEGEX_EXT 0x01 /* recursive or externally induced */ 188231200Smm#define SEGEX_IDT 0x02 /* interrupt descriptor table */ 189231200Smm#define SEGEX_TI 0x04 /* local descriptor table */ 190231200Smm /* other bits are affected descriptor index */ 191231200Smm#define SEGEX_IDX(s) (((s)>>3)&0x1fff) 192231200Smm 193231200Smm/* 194231200Smm * Size of IDT table 195231200Smm */ 196231200Smm 197231200Smm#if defined(SMP) || defined(APIC_IO) 198231200Smm#define NIDT 256 /* we use them all */ 199231200Smm#else 200231200Smm#define NIDT 129 /* 32 reserved, 16 h/w, 0 s/w, linux's 0x80 */ 201231200Smm#endif /* SMP || APIC_IO */ 202231200Smm#define NRSVIDT 32 /* reserved entries for cpu exceptions */ 203231200Smm 204231200Smm/* 205231200Smm * Entries in the Global Descriptor Table (GDT) 206231200Smm */ 207231200Smm#define GNULL_SEL 0 /* Null Descriptor */ 208231200Smm#define GCODE_SEL 1 /* Kernel Code Descriptor */ 209231200Smm#define GDATA_SEL 2 /* Kernel Data Descriptor */ 210231200Smm#define GPRIV_SEL 3 /* SMP Per-Processor Private Data */ 211231200Smm#define GPROC0_SEL 4 /* Task state process slot zero and up */ 212368708Smm#define GLDT_SEL 5 /* LDT - eventually one per process */ 213368708Smm#define GUSERLDT_SEL 6 /* User LDT */ 214231200Smm#define GTGATE_SEL 7 /* Process task switch gate */ 215231200Smm#define GBIOSLOWMEM_SEL 8 /* BIOS low memory access (must be entry 8) */ 216231200Smm#define GPANIC_SEL 9 /* Task state to consider panic from */ 217231200Smm#define GBIOSCODE32_SEL 10 /* BIOS interface (32bit Code) */ 218231200Smm#define GBIOSCODE16_SEL 11 /* BIOS interface (16bit Code) */ 219231200Smm#define GBIOSDATA_SEL 12 /* BIOS interface (Data) */ 220231200Smm#define GBIOSUTIL_SEL 13 /* BIOS interface (Utility) */ 221368708Smm#define GBIOSARGS_SEL 14 /* BIOS interface (Arguments) */ 222368708Smm 223368708Smm#ifdef BDE_DEBUGGER 224368708Smm#define NGDT 18 /* some of 11-17 are reserved for debugger */ 225368708Smm#else 226231200Smm#define NGDT 15 227368708Smm#endif 228368708Smm 229368708Smm/* 230231200Smm * Entries in the Local Descriptor Table (LDT) 231231200Smm */ 232231200Smm#define LSYS5CALLS_SEL 0 /* forced by intel BCS */ 233231200Smm#define LSYS5SIGR_SEL 1 234231200Smm#define L43BSDCALLS_SEL 2 /* notyet */ 235231200Smm#define LUCODE_SEL 3 236231200Smm#define LSOL26CALLS_SEL 4 /* Solaris >= 2.6 system call gate */ 237231200Smm#define LUDATA_SEL 5 238231200Smm/* separate stack, es,fs,gs sels ? */ 239231200Smm/* #define LPOSIXCALLS_SEL 5*/ /* notyet */ 240231200Smm#define LBSDICALLS_SEL 16 /* BSDI system call gate */ 241231200Smm#define NLDT (LBSDICALLS_SEL + 1) 242231200Smm 243231200Smm#ifdef _KERNEL 244231200Smmextern int _default_ldt; 245231200Smmextern union descriptor gdt[]; 246231200Smmextern struct soft_segment_descriptor gdt_segs[]; 247231200Smmextern struct gate_descriptor *idt; 248231200Smmextern union descriptor ldt[NLDT]; 249231200Smm 250231200Smmvoid lgdt (struct region_descriptor *rdp); 251231200Smmvoid lidt (struct region_descriptor *rdp); 252231200Smmvoid lldt (u_short sel); 253231200Smmvoid sdtossd (struct segment_descriptor *sdp, 254231200Smm struct soft_segment_descriptor *ssdp); 255231200Smmvoid ssdtosd (struct soft_segment_descriptor *ssdp, 256231200Smm struct segment_descriptor *sdp); 257231200Smm#endif /* _KERNEL */ 258231200Smm 259231200Smm#endif /* !_MACHINE_SEGMENTS_H_ */ 260231200Smm