segments.h revision 46129
139287Ssos/*- 239643Syokota * Copyright (c) 1989, 1990 William F. Jolitz 3205566Sjkim * Copyright (c) 1990 The Regents of the University of California. 439287Ssos * All rights reserved. 539287Ssos * 639287Ssos * This code is derived from software contributed to Berkeley by 739287Ssos * William Jolitz. 839287Ssos * 939287Ssos * Redistribution and use in source and binary forms, with or without 1039643Syokota * modification, are permitted provided that the following conditions 1139643Syokota * are met: 1239287Ssos * 1. Redistributions of source code must retain the above copyright 1339287Ssos * notice, this list of conditions and the following disclaimer. 1439287Ssos * 2. Redistributions in binary form must reproduce the above copyright 1539287Ssos * notice, this list of conditions and the following disclaimer in the 1639643Syokota * documentation and/or other materials provided with the distribution. 1739643Syokota * 3. All advertising materials mentioning features or use of this software 1839643Syokota * must display the following acknowledgement: 1939643Syokota * This product includes software developed by the University of 2039643Syokota * California, Berkeley and its contributors. 2139643Syokota * 4. Neither the name of the University nor the names of its contributors 2239643Syokota * may be used to endorse or promote products derived from this software 2339643Syokota * without specific prior written permission. 2439643Syokota * 2539643Syokota * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2639287Ssos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2739287Ssos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28115703Sobrien * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29115703Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30115703Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3142504Syokota * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3266710Sjhb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3339287Ssos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3456836Speter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3539287Ssos * SUCH DAMAGE. 3639287Ssos * 37198251Sjkim * from: @(#)segments.h 7.1 (Berkeley) 5/9/91 3839287Ssos * $Id: segments.h,v 1.18 1999/01/28 11:45:49 newton Exp $ 3939287Ssos */ 4042179Syokota 4139287Ssos#ifndef _MACHINE_SEGMENTS_H_ 4248104Syokota#define _MACHINE_SEGMENTS_H_ 4348104Syokota 4439287Ssos#include <machine/globals.h> 4548104Syokota 4648104Syokota/* 47130312Sjhb * 386 Segmentation Data Structures and definitions 4839287Ssos * William F. Jolitz (william@ernie.berkeley.edu) 6/20/1989 4939287Ssos */ 50197383Sdelphij 51197025Sdelphij/* 5239287Ssos * Selectors 5342504Syokota */ 5442504Syokota 5539287Ssos#define ISPL(s) ((s)&3) /* what is the priority level of a selector */ 56198251Sjkim#define SEL_KPL 0 /* kernel priority level */ 57198251Sjkim#define SEL_UPL 3 /* user priority level */ 5842504Syokota#define ISLDT(s) ((s)&SEL_LDT) /* is it local or global */ 5942504Syokota#define SEL_LDT 4 /* local descriptor table */ 60197444Sjkim#define IDXSEL(s) (((s)>>3) & 0x1fff) /* index of selector */ 61197025Sdelphij#define LSEL(s,r) (((s)<<3) | SEL_LDT | r) /* a local selector */ 62117710Srobert#define GSEL(s,r) (((s)<<3) | r) /* a global selector */ 63117710Srobert 6442504Syokota/* 6542611Syokota * Memory and System segment descriptors 6642504Syokota */ 6742504Syokotastruct segment_descriptor { 6839287Ssos unsigned sd_lolimit:16 ; /* segment extent (lsb) */ 6939287Ssos unsigned sd_lobase:24 __attribute__ ((packed)); 7039287Ssos /* segment base address (lsb) */ 7139287Ssos unsigned sd_type:5 ; /* segment type */ 7239287Ssos unsigned sd_dpl:2 ; /* segment descriptor priority level */ 7339287Ssos unsigned sd_p:1 ; /* segment descriptor present */ 7439287Ssos unsigned sd_hilimit:4 ; /* segment extent (msb) */ 7539287Ssos unsigned sd_xx:2 ; /* unused */ 7639287Ssos unsigned sd_def32:1 ; /* default 32 vs 16 bit size */ 7739287Ssos unsigned sd_gran:1 ; /* limit granularity (byte/page units)*/ 78198419Sjkim unsigned sd_hibase:8 ; /* segment base address (msb) */ 7939287Ssos} ; 8039287Ssos 8148399Speter/* 8242504Syokota * Gate descriptors (e.g. indirect descriptors) 8348399Speter */ 8448104Syokotastruct gate_descriptor { 8542504Syokota unsigned gd_looffset:16 ; /* gate offset (lsb) */ 8639287Ssos unsigned gd_selector:16 ; /* gate segment selector */ 8739287Ssos unsigned gd_stkcpy:5 ; /* number of stack wds to cpy */ 8839287Ssos unsigned gd_xx:3 ; /* unused */ 8939287Ssos unsigned gd_type:5 ; /* segment type */ 9039287Ssos unsigned gd_dpl:2 ; /* segment descriptor priority level */ 9139287Ssos unsigned gd_p:1 ; /* segment descriptor present */ 9239287Ssos unsigned gd_hioffset:16 ; /* gate offset (msb) */ 9339287Ssos} ; 9439287Ssos 9539287Ssos/* 9639287Ssos * Generic descriptor 9739287Ssos */ 9839287Ssosunion descriptor { 9939287Ssos struct segment_descriptor sd; 10039287Ssos struct gate_descriptor gd; 10142504Syokota}; 10248104Syokota 10342504Syokota /* system segments and gate types */ 10448104Syokota#define SDT_SYSNULL 0 /* system null */ 10548104Syokota#define SDT_SYS286TSS 1 /* system 286 TSS available */ 10648104Syokota#define SDT_SYSLDT 2 /* system local descriptor table */ 10748104Syokota#define SDT_SYS286BSY 3 /* system 286 TSS busy */ 10839287Ssos#define SDT_SYS286CGT 4 /* system 286 call gate */ 10948104Syokota#define SDT_SYSTASKGT 5 /* system task gate */ 11039287Ssos#define SDT_SYS286IGT 6 /* system 286 interrupt gate */ 11142504Syokota#define SDT_SYS286TGT 7 /* system 286 trap gate */ 11242504Syokota#define SDT_SYSNULL2 8 /* system null again */ 11342504Syokota#define SDT_SYS386TSS 9 /* system 386 TSS available */ 11442504Syokota#define SDT_SYSNULL3 10 /* system null again */ 11542504Syokota#define SDT_SYS386BSY 11 /* system 386 TSS busy */ 11642504Syokota#define SDT_SYS386CGT 12 /* system 386 call gate */ 11742504Syokota#define SDT_SYSNULL4 13 /* system null again */ 11842504Syokota#define SDT_SYS386IGT 14 /* system 386 interrupt gate */ 11942504Syokota#define SDT_SYS386TGT 15 /* system 386 trap gate */ 12042504Syokota 12142504Syokota /* memory segment types */ 12242504Syokota#define SDT_MEMRO 16 /* memory read only */ 12342504Syokota#define SDT_MEMROA 17 /* memory read only accessed */ 12442504Syokota#define SDT_MEMRW 18 /* memory read write */ 12542504Syokota#define SDT_MEMRWA 19 /* memory read write accessed */ 12642504Syokota#define SDT_MEMROD 20 /* memory read only expand dwn limit */ 12742504Syokota#define SDT_MEMRODA 21 /* memory read only expand dwn limit accessed */ 12842504Syokota#define SDT_MEMRWD 22 /* memory read write expand dwn limit */ 12948104Syokota#define SDT_MEMRWDA 23 /* memory read write expand dwn limit accessed */ 13042504Syokota#define SDT_MEME 24 /* memory execute only */ 13148104Syokota#define SDT_MEMEA 25 /* memory execute only accessed */ 13248104Syokota#define SDT_MEMER 26 /* memory execute read */ 13348104Syokota#define SDT_MEMERA 27 /* memory execute read accessed */ 13448104Syokota#define SDT_MEMEC 28 /* memory execute only conforming */ 13548104Syokota#define SDT_MEMEAC 29 /* memory execute only accessed conforming */ 13648104Syokota#define SDT_MEMERC 30 /* memory execute read conforming */ 13739287Ssos#define SDT_MEMERAC 31 /* memory execute read accessed conforming */ 13839287Ssos 13939287Ssos/* is memory segment descriptor pointer ? */ 14042504Syokota#define ISMEMSDP(s) ((s->d_type) >= SDT_MEMRO && (s->d_type) <= SDT_MEMERAC) 14139287Ssos 14239287Ssos/* is 286 gate descriptor pointer ? */ 14339287Ssos#define IS286GDP(s) (((s->d_type) >= SDT_SYS286CGT \ 14439287Ssos && (s->d_type) < SDT_SYS286TGT)) 14539287Ssos 14639287Ssos/* is 386 gate descriptor pointer ? */ 14748104Syokota#define IS386GDP(s) (((s->d_type) >= SDT_SYS386CGT \ 14839287Ssos && (s->d_type) < SDT_SYS386TGT)) 14948104Syokota 15048104Syokota/* is gate descriptor pointer ? */ 15148104Syokota#define ISGDP(s) (IS286GDP(s) || IS386GDP(s)) 15248104Syokota 15339287Ssos/* is segment descriptor pointer ? */ 15439287Ssos#define ISSDP(s) (ISMEMSDP(s) || !ISGDP(s)) 15539287Ssos 15639287Ssos/* is system segment descriptor pointer ? */ 15739858Syokota#define ISSYSSDP(s) (!ISMEMSDP(s) && !ISGDP(s)) 15839858Syokota 15939858Syokota/* 16039858Syokota * Software definitions are in this convenient format, 16139287Ssos * which are translated into inconvenient segment descriptors 16239287Ssos * when needed to be used by the 386 hardware 16339287Ssos */ 16439287Ssos 16542504Syokotastruct soft_segment_descriptor { 166198251Sjkim unsigned ssd_base ; /* segment base address */ 16739287Ssos unsigned ssd_limit ; /* segment extent */ 16839287Ssos unsigned ssd_type:5 ; /* segment type */ 169204265Sjkim unsigned ssd_dpl:2 ; /* segment descriptor priority level */ 17045117Syokota unsigned ssd_p:1 ; /* segment descriptor present */ 171204265Sjkim unsigned ssd_xx:4 ; /* unused */ 17239287Ssos unsigned ssd_xx1:2 ; /* unused */ 17342729Syokota unsigned ssd_def32:1 ; /* default 32 vs 16 bit size */ 17442729Syokota unsigned ssd_gran:1 ; /* limit granularity (byte/page units)*/ 17548104Syokota}; 17648104Syokota 17742729Syokota/* 17842729Syokota * region descriptors, used to load gdt/idt tables before segments yet exist. 17948104Syokota */ 18048104Syokotastruct region_descriptor { 18139287Ssos unsigned rd_limit:16; /* segment extent */ 18239287Ssos unsigned rd_base:32 __attribute__ ((packed)); /* base address */ 18339287Ssos}; 18439287Ssos 18539287Ssos/* 18639287Ssos * Segment Protection Exception code bits 18739287Ssos */ 18839287Ssos 18939287Ssos#define SEGEX_EXT 0x01 /* recursive or externally induced */ 190198419Sjkim#define SEGEX_IDT 0x02 /* interrupt descriptor table */ 19139287Ssos#define SEGEX_TI 0x04 /* local descriptor table */ 192205653Sjkim /* other bits are affected descriptor index */ 19343664Syokota#define SEGEX_IDX(s) ((s)>>3)&0x1fff) 194205653Sjkim 19550446Syokota/* 19648399Speter * Size of IDT table 19748104Syokota */ 19848399Speter 19948104Syokota#if defined(SMP) || defined(APIC_IO) 20039591Syokota#define NIDT 256 /* we use them all */ 20139591Syokota#else 20248104Syokota#define NIDT 129 /* 32 reserved, 16 h/w, 0 s/w, linux's 0x80 */ 203205564Sjkim#endif /* SMP || APIC_IO */ 20439287Ssos#define NRSVIDT 32 /* reserved entries for cpu exceptions */ 20539591Syokota 20639287Ssos/* 20748399Speter * Entries in the Global Descriptor Table (GDT) 20848104Syokota */ 20948399Speter#define GNULL_SEL 0 /* Null Descriptor */ 21048104Syokota#define GCODE_SEL 1 /* Kernel Code Descriptor */ 21142504Syokota#define GDATA_SEL 2 /* Kernel Data Descriptor */ 21242504Syokota#define GPRIV_SEL 3 /* SMP Per-Processor Private Data */ 21342504Syokota#define GPROC0_SEL 4 /* Task state process slot zero and up */ 21442504Syokota#define GLDT_SEL 5 /* LDT - eventually one per process */ 215197383Sdelphij#define GUSERLDT_SEL 6 /* User LDT */ 21642504Syokota#define GTGATE_SEL 7 /* Process task switch gate */ 217198251Sjkim#define GPANIC_SEL 8 /* Task state to consider panic from */ 218198251Sjkim#define GAPMCODE32_SEL 9 /* APM BIOS 32-bit interface (32bit Code) */ 219197383Sdelphij#define GAPMCODE16_SEL 10 /* APM BIOS 32-bit interface (16bit Code) */ 220197466Sjkim#define GAPMDATA_SEL 11 /* APM BIOS 32-bit interface (Data) */ 221197383Sdelphij 222198251Sjkim#ifdef BDE_DEBUGGER 22342504Syokota#define NGDT 18 /* some of 11-17 are reserved for debugger */ 22442504Syokota#else 225198251Sjkim#define NGDT 12 226198251Sjkim#endif 227198251Sjkim 228198251Sjkim/* 229198251Sjkim * Entries in the Local Descriptor Table (LDT) 230198251Sjkim */ 231198251Sjkim#define LSYS5CALLS_SEL 0 /* forced by intel BCS */ 232198251Sjkim#define LSYS5SIGR_SEL 1 233198251Sjkim#define L43BSDCALLS_SEL 2 /* notyet */ 234198251Sjkim#define LUCODE_SEL 3 235198251Sjkim#define LSOL26CALLS_SEL 4 /* Solaris >= 2.6 system call gate */ 236198251Sjkim#define LUDATA_SEL 5 237198251Sjkim/* separate stack, es,fs,gs sels ? */ 238198251Sjkim/* #define LPOSIXCALLS_SEL 5*/ /* notyet */ 239198251Sjkim#define LBSDICALLS_SEL 16 /* BSDI system call gate */ 240198251Sjkim#define NLDT (LBSDICALLS_SEL + 1) 241198251Sjkim 242198251Sjkim#ifdef KERNEL 243198251Sjkim#ifndef currentldt 244199230Sjkimextern int currentldt; 245199230Sjkim#endif 246198251Sjkimextern int _default_ldt; 247198251Sjkimextern union descriptor gdt[]; 248198251Sjkimextern struct soft_segment_descriptor gdt_segs[]; 249198251Sjkimextern struct gate_descriptor idt[NIDT]; 250198251Sjkimextern union descriptor ldt[NLDT]; 251198251Sjkim 252198251Sjkimvoid lgdt __P((struct region_descriptor *rdp)); 253198251Sjkimvoid lidt __P((struct region_descriptor *rdp)); 254198251Sjkimvoid lldt __P((u_short sel)); 255198251Sjkimvoid sdtossd __P((struct segment_descriptor *sdp, 256198251Sjkim struct soft_segment_descriptor *ssdp)); 257198251Sjkimvoid ssdtosd __P((struct soft_segment_descriptor *ssdp, 258198251Sjkim struct segment_descriptor *sdp)); 259198251Sjkim#endif /* KERNEL */ 260198251Sjkim 261198251Sjkim#endif /* !_MACHINE_SEGMENTS_H_ */ 262198251Sjkim