segments.h

Go to the documentation of this file.
00001 /*-
00002  * Copyright (c) 1995, 1997
00003  *      Charles M. Hannum.  All rights reserved.
00004  * Copyright (c) 1989, 1990 William F. Jolitz
00005  * Copyright (c) 1990 The Regents of the University of California.
00006  * All rights reserved.
00007  *
00008  * This code is derived from software contributed to Berkeley by
00009  * William Jolitz.
00010  *
00011  * Redistribution and use in source and binary forms, with or without
00012  * modification, are permitted provided that the following conditions
00013  * are met:
00014  * 1. Redistributions of source code must retain the above copyright
00015  *    notice, this list of conditions and the following disclaimer.
00016  * 2. Redistributions in binary form must reproduce the above copyright
00017  *    notice, this list of conditions and the following disclaimer in the
00018  *    documentation and/or other materials provided with the distribution.
00019  * 3. All advertising materials mentioning features or use of this software
00020  *    must display the following acknowledgement:
00021  *      This product includes software developed by the University of
00022  *      California, Berkeley and its contributors.
00023  * 4. Neither the name of the University nor the names of its contributors
00024  *    may be used to endorse or promote products derived from this software
00025  *    without specific prior written permission.
00026  *
00027  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00028  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00029  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00030  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00031  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00032  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00033  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00034  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00035  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00036  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00037  * SUCH DAMAGE.
00038  *
00039  *      @(#)segments.h  7.1 (Berkeley) 5/9/91
00040  */
00041 #ifndef __MACHDEP_SEGMENTS_H__
00042 #define __MACHDEP_SEGMENTS_H__
00043 /*
00044  * 386 Segmentation Data Structures and definitions
00045  *      William F. Jolitz (william@ernie.berkeley.edu) 6/20/1989
00046  */
00047 
00048 /* modified for LSE/OS by Vianney Rancurel */
00049 
00050 /*
00051  * Selectors
00052  */
00053 
00054 #define ISRING(s)       ((s) & SEL_RPL) /* what is the ring of a selector */
00055 #define RING0           0               /* kernel privilege level */    
00056 #define RING1           1               /* Ring 1                 */
00057 #define RING2           2               /* Ring 2                 */
00058 #define RING3           3               /* user privilege level */      
00059 #define SEL_RPL         3               /* requester's privilege level mask */
00060 #define ISLDT(s)        ((s) & SEL_LDT) /* is it local or global */
00061 #define SEL_LDT         4               /* local descriptor table */    
00062 #define IDXSEL(s)       (((s) >> 3) & 0x1fff)           /* index of selector */
00063 #define GSEL(s,r)       (((s) << 3) | r)                /* a global selector */
00064 #define LSEL(s,r)       (((s) << 3) | r | SEL_LDT)      /* a local selector */
00065 
00066 #if defined(_KERNEL) && !defined(_LKM)
00067 #include "opt_vm86.h"
00068 #endif
00069 
00070 #ifdef VM86
00071 #define USERMODE(c, f)          (ISPL(c) == SEL_UPL || ((f) & PSL_VM) != 0)
00072 #define KERNELMODE(c, f)        (ISPL(c) == SEL_KPL && ((f) & PSL_VM) == 0)
00073 #else
00074 #define USERMODE(c, f)          (ISPL(c) == SEL_UPL)
00075 #define KERNELMODE(c, f)        (ISPL(c) == SEL_KPL)
00076 #endif
00077 
00078 #ifndef __LOCORE__
00079 
00080 #if __GNUC__ == 2 && __GNUC_MINOR__ < 7
00081 #pragma pack(1)
00082 #endif
00083 
00084 /*
00085  * Memory and System segment descriptors
00086  */
00087 struct segment_descriptor {
00088         unsigned sd_lolimit:16;         /* segment extent (lsb) */
00089         unsigned sd_lobase:24;          /* segment base address (lsb) */
00090         unsigned sd_type:5;             /* segment type */
00091         unsigned sd_dpl:2;              /* segment descriptor priority level */
00092         unsigned sd_p:1;                /* segment descriptor present */
00093         unsigned sd_hilimit:4;          /* segment extent (msb) */
00094         unsigned sd_xx:2;               /* unused */
00095         unsigned sd_def32:1;            /* default 32 vs 16 bit size */
00096         unsigned sd_gran:1;             /* limit granularity (byte/page) */
00097         unsigned sd_hibase:8;           /* segment base address (msb) */
00098 } __attribute__((packed));
00099 
00100 /*
00101  * Gate descriptors (e.g. indirect descriptors)
00102  */
00103 struct gate_descriptor {
00104         unsigned gd_looffset:16;        /* gate offset (lsb) */
00105         unsigned gd_selector:16;        /* gate segment selector */
00106         unsigned gd_stkcpy:5;           /* number of stack wds to cpy */
00107         unsigned gd_xx:3;               /* unused */
00108         unsigned gd_type:5;             /* segment type */
00109         unsigned gd_dpl:2;              /* segment descriptor priority level */
00110         unsigned gd_p:1;                /* segment descriptor present */
00111         unsigned gd_hioffset:16;        /* gate offset (msb) */
00112 } __attribute__((packed));
00113 
00114 /*
00115  * Generic descriptor
00116  */
00117 union descriptor {
00118         struct segment_descriptor sd;
00119         struct gate_descriptor gd;
00120 } __attribute__((packed));
00121 
00122 /*
00123  * region descriptors, used to load gdt/idt tables before segments yet exist.
00124  */
00125 struct region_descriptor {
00126         unsigned rd_limit:16;           /* segment extent */
00127         unsigned rd_base:32;            /* base address  */
00128 } __attribute__((packed));
00129 
00130 #if __GNUC__ == 2 && __GNUC_MINOR__ < 7
00131 #pragma pack(4)
00132 #endif
00133 
00134 #endif /* !__LOCORE__ */
00135 
00136 /* system segments and gate types */
00137 #define SDT_SYSNULL      0      /* system null */
00138 #define SDT_SYS286TSS    1      /* system 286 TSS available */
00139 #define SDT_SYSLDT       2      /* system local descriptor table */
00140 #define SDT_SYS286BSY    3      /* system 286 TSS busy */
00141 #define SDT_SYS286CGT    4      /* system 286 call gate */
00142 #define SDT_SYSTASKGT    5      /* system task gate */
00143 #define SDT_SYS286IGT    6      /* system 286 interrupt gate */
00144 #define SDT_SYS286TGT    7      /* system 286 trap gate */
00145 #define SDT_SYSNULL2     8      /* system null again */
00146 #define SDT_SYS386TSS    9      /* system 386 TSS available */
00147 #define SDT_SYSNULL3    10      /* system null again */
00148 #define SDT_SYS386BSY   11      /* system 386 TSS busy */
00149 #define SDT_SYS386CGT   12      /* system 386 call gate */
00150 #define SDT_SYSNULL4    13      /* system null again */
00151 #define SDT_SYS386IGT   14      /* system 386 interrupt gate */
00152 #define SDT_SYS386TGT   15      /* system 386 trap gate */
00153 
00154 /* memory segment types */
00155 #define SDT_MEMRO       16      /* memory read only */
00156 #define SDT_MEMROA      17      /* memory read only accessed */
00157 #define SDT_MEMRW       18      /* memory read write */
00158 #define SDT_MEMRWA      19      /* memory read write accessed */
00159 #define SDT_MEMROD      20      /* memory read only expand dwn limit */
00160 #define SDT_MEMRODA     21      /* memory read only expand dwn limit accessed */
00161 #define SDT_MEMRWD      22      /* memory read write expand dwn limit */
00162 #define SDT_MEMRWDA     23      /* memory read write expand dwn limit acessed */
00163 #define SDT_MEME        24      /* memory execute only */
00164 #define SDT_MEMEA       25      /* memory execute only accessed */
00165 #define SDT_MEMER       26      /* memory execute read */
00166 #define SDT_MEMERA      27      /* memory execute read accessed */
00167 #define SDT_MEMEC       28      /* memory execute only conforming */
00168 #define SDT_MEMEAC      29      /* memory execute only accessed conforming */
00169 #define SDT_MEMERC      30      /* memory execute read conforming */
00170 #define SDT_MEMERAC     31      /* memory execute read accessed conforming */
00171 
00172 /* is memory segment descriptor pointer ? */
00173 #define ISMEMSDP(s)     ((s->d_type) >= SDT_MEMRO && \
00174                          (s->d_type) <= SDT_MEMERAC)
00175 
00176 /* is 286 gate descriptor pointer ? */
00177 #define IS286GDP(s)     ((s->d_type) >= SDT_SYS286CGT && \
00178                          (s->d_type) < SDT_SYS286TGT)
00179 
00180 /* is 386 gate descriptor pointer ? */
00181 #define IS386GDP(s)     ((s->d_type) >= SDT_SYS386CGT && \
00182                          (s->d_type) < SDT_SYS386TGT)
00183 
00184 /* is gate descriptor pointer ? */
00185 #define ISGDP(s)        (IS286GDP(s) || IS386GDP(s))
00186 
00187 /* is segment descriptor pointer ? */
00188 #define ISSDP(s)        (ISMEMSDP(s) || !ISGDP(s))
00189 
00190 /* is system segment descriptor pointer ? */
00191 #define ISSYSSDP(s)     (!ISMEMSDP(s) && !ISGDP(s))
00192 
00193 /*
00194  * Segment Protection Exception code bits
00195  */
00196 #define SEGEX_EXT       0x01    /* recursive or externally induced */
00197 #define SEGEX_IDT       0x02    /* interrupt descriptor table */
00198 #define SEGEX_TI        0x04    /* local descriptor table */
00199 
00200 /*
00201  * Entries in the Interrupt Descriptor Table (IDT)
00202  */
00203 #define NIDT    256
00204 
00205 /*
00206  * Entries in the Global Descriptor Table (GDT)
00207  */
00208 #define GNULL_IDXSEL    0       /* Null descriptor */
00209 #define GCODE_IDXSEL    1       /* Kernel code descriptor */
00210 #define GDATA_IDXSEL    2       /* Kernel data descriptor */
00211 #define GLDT_IDXSEL     3       /* Default LDT descriptor */
00212 #define G1CODE_IDXSEL   4       /* pl1 code descriptor */
00213 #define G1DATA_IDXSEL   5       /* pl1 data descriptor */
00214 #define G2CODE_IDXSEL   6       /* pl2 code descriptor */
00215 #define G2DATA_IDXSEL   7       /* pl2 data descriptor */
00216 #define GUCODE_IDXSEL   8       /* User code descriptor */
00217 #define GUDATA_IDXSEL   9       /* User data descriptor */
00218 
00219 /*
00220  * task selectors
00221  */
00222 #define GBSTRAP_TSS_IDXSEL      15      /* bootstrap tss        */
00223 #define GKERN0_TSS_IDXSEL       16      /* kernel tss           */
00224 #define GKERN1_TSS_IDXSEL       17      /* kernel tss           */
00225 #define GKERN2_TSS_IDXSEL       18      /* kernel tss           */
00226 #define GKERN3_TSS_IDXSEL       19      /* kernel tss           */
00227 #define GKERN4_TSS_IDXSEL       20      /* kernel tss           */
00228 #define GKERN5_TSS_IDXSEL       21      /* kernel tss           */
00229 #define GKERN6_TSS_IDXSEL       22      /* kernel tss           */
00230 #define GKERN7_TSS_IDXSEL       23      /* kernel tss           */
00231 #define GCORE0_TSS_IDXSEL       24      /* core server tss      */
00232 #define GCORE1_TSS_IDXSEL       25      /* core server tss      */
00233 #define GCORE2_TSS_IDXSEL       26      /* core server tss      */
00234 #define GCORE3_TSS_IDXSEL       27      /* core server tss      */
00235 #define GCORE4_TSS_IDXSEL       28      /* core server tss      */
00236 #define GCORE5_TSS_IDXSEL       29      /* core server tss      */
00237 #define GCORE6_TSS_IDXSEL       30      /* core server tss      */
00238 #define GCORE7_TSS_IDXSEL       31      /* core server tss      */
00239 #define GTRAP0_TSS_IDXSEL       32      /* trap server tss      */
00240 #define GTRAP1_TSS_IDXSEL       33      /* trap server tss      */
00241 #define GTRAP2_TSS_IDXSEL       34      /* trap server tss      */
00242 #define GTRAP3_TSS_IDXSEL       35      /* trap server tss      */
00243 #define GTRAP4_TSS_IDXSEL       36      /* trap server tss      */
00244 #define GTRAP5_TSS_IDXSEL       37      /* trap server tss      */
00245 #define GTRAP6_TSS_IDXSEL       38      /* trap server tss      */
00246 #define GTRAP7_TSS_IDXSEL       39      /* trap server tss      */
00247 #define GPGFLT0_TSS_IDXSEL      40      /* page fault server tss        */
00248 #define GPGFLT1_TSS_IDXSEL      41      /* page fault server tss        */
00249 #define GPGFLT2_TSS_IDXSEL      42      /* page fault server tss        */
00250 #define GPGFLT3_TSS_IDXSEL      43      /* page fault server tss        */
00251 #define GPGFLT4_TSS_IDXSEL      44      /* page fault server tss        */
00252 #define GPGFLT5_TSS_IDXSEL      45      /* page fault server tss        */
00253 #define GPGFLT6_TSS_IDXSEL      46      /* page fault server tss        */
00254 #define GPGFLT7_TSS_IDXSEL      47      /* page fault server tss        */
00255 #define GDBLFLT0_TSS_IDXSEL     48      /* dblflt server tss            */
00256 #define GDBLFLT1_TSS_IDXSEL     49      /* dblflt server tss            */
00257 #define GDBLFLT2_TSS_IDXSEL     50      /* dblflt server tss            */
00258 #define GDBLFLT3_TSS_IDXSEL     51      /* dblflt server tss            */
00259 #define GDBLFLT4_TSS_IDXSEL     52      /* dblflt server tss            */
00260 #define GDBLFLT5_TSS_IDXSEL     53      /* dblflt server tss            */
00261 #define GDBLFLT6_TSS_IDXSEL     54      /* dblflt server tss            */
00262 #define GDBLFLT7_TSS_IDXSEL     55      /* dblflt server tss            */
00263 #define GSTRAY0_TSS_IDXSEL      56      /* stray interrupt tss          */
00264 #define GSTRAY1_TSS_IDXSEL      57      /* stray interrupt tss          */
00265 #define GSTRAY2_TSS_IDXSEL      58      /* stray interrupt tss          */
00266 #define GSTRAY3_TSS_IDXSEL      59      /* stray interrupt tss          */
00267 #define GSTRAY4_TSS_IDXSEL      60      /* stray interrupt tss          */
00268 #define GSTRAY5_TSS_IDXSEL      61      /* stray interrupt tss          */
00269 #define GSTRAY6_TSS_IDXSEL      62      /* stray interrupt tss          */
00270 #define GSTRAY7_TSS_IDXSEL      63      /* stray interrupt tss          */
00271 #define GBREAKPOINT0_TSS_IDXSEL 64      /* breakpoint tss               */
00272 #define GBREAKPOINT1_TSS_IDXSEL 65      /* breakpoint tss               */
00273 #define GBREAKPOINT2_TSS_IDXSEL 66      /* breakpoint tss               */
00274 #define GBREAKPOINT3_TSS_IDXSEL 67      /* breakpoint tss               */
00275 #define GBREAKPOINT4_TSS_IDXSEL 68      /* breakpoint tss               */
00276 #define GBREAKPOINT5_TSS_IDXSEL 69      /* breakpoint tss               */
00277 #define GBREAKPOINT6_TSS_IDXSEL 70      /* breakpoint tss               */
00278 #define GBREAKPOINT7_TSS_IDXSEL 71      /* breakpoint tss               */
00279 #define GIDLE0_TSS_IDXSEL       72      /* idle proc tss                */
00280 #define GIDLE1_TSS_IDXSEL       73      /* idle proc tss                */
00281 #define GIDLE2_TSS_IDXSEL       74      /* idle proc tss                */
00282 #define GIDLE3_TSS_IDXSEL       75      /* idle proc tss                */
00283 #define GIDLE4_TSS_IDXSEL       76      /* idle proc tss                */
00284 #define GIDLE5_TSS_IDXSEL       77      /* idle proc tss                */
00285 #define GIDLE6_TSS_IDXSEL       78      /* idle proc tss                */
00286 #define GIDLE7_TSS_IDXSEL       79      /* idle proc tss                */
00287 #define GSOFTSW0_TSS_IDXSEL     80      /* soft csw tss                 */
00288 #define GSOFTSW1_TSS_IDXSEL     81      /* soft csw tss                 */
00289 #define GSOFTSW2_TSS_IDXSEL     82      /* soft csw tss                 */
00290 #define GSOFTSW3_TSS_IDXSEL     83      /* soft csw tss                 */
00291 #define GSOFTSW4_TSS_IDXSEL     84      /* soft csw tss                 */
00292 #define GSOFTSW5_TSS_IDXSEL     85      /* soft csw tss                 */
00293 #define GSOFTSW6_TSS_IDXSEL     86      /* soft csw tss                 */
00294 #define GSOFTSW7_TSS_IDXSEL     87      /* soft csw tss                 */
00295 #define GFIRST_IDXSEL           88      /* start of user entries of the gdt */
00296 
00297 #endif

Generated on Wed May 24 23:04:17 2006 for LSE/OS by  doxygen 1.4.6