145596Sbill /*- 249614Sbostic * Copyright (c) 1989, 1990 William F. Jolitz 3*63359Sbostic * Copyright (c) 1990, 1993 4*63359Sbostic * The Regents of the University of California. All rights reserved. 545596Sbill * 645596Sbill * This code is derived from software contributed to Berkeley by 745964Swilliam * William Jolitz. 845596Sbill * 949614Sbostic * %sccs.include.redist.c% 1045596Sbill * 11*63359Sbostic * @(#)segments.h 8.1 (Berkeley) 06/11/93 1245596Sbill */ 1345596Sbill 1440467Sbill /* 1540467Sbill * 386 Segmentation Data Structures and definitions 1640467Sbill * William F. Jolitz (william@ernie.berkeley.edu) 6/20/1989 1740467Sbill */ 1840467Sbill 1940467Sbill /* 2040467Sbill * Selectors 2140467Sbill */ 2240467Sbill 2340467Sbill #define ISPL(s) ((s)&3) /* what is the priority level of a selector */ 2440467Sbill #define SEL_KPL 0 /* kernel priority level */ 2540467Sbill #define SEL_UPL 3 /* user priority level */ 2640467Sbill #define ISLDT(s) ((s)&SEL_LDT) /* is it local or global */ 2740467Sbill #define SEL_LDT 4 /* local descriptor table */ 2840467Sbill #define IDXSEL(s) (((s)>>3) & 0x1fff) /* index of selector */ 2940467Sbill #define LSEL(s,r) (((s)<<3) | SEL_LDT | r) /* a local selector */ 3040467Sbill #define GSEL(s,r) (((s)<<3) | r) /* a global selector */ 3140467Sbill 3240467Sbill /* 3340467Sbill * Memory and System segment descriptors 3440467Sbill */ 3540467Sbill struct segment_descriptor { 3640467Sbill unsigned sd_lolimit:16 ; /* segment extent (lsb) */ 3740467Sbill unsigned sd_lobase:24 ; /* segment base address (lsb) */ 3840467Sbill unsigned sd_type:5 ; /* segment type */ 3940467Sbill unsigned sd_dpl:2 ; /* segment descriptor priority level */ 4040467Sbill unsigned sd_p:1 ; /* segment descriptor present */ 4140467Sbill unsigned sd_hilimit:4 ; /* segment extent (msb) */ 4240467Sbill unsigned sd_xx:2 ; /* unused */ 4340467Sbill unsigned sd_def32:1 ; /* default 32 vs 16 bit size */ 4440467Sbill unsigned sd_gran:1 ; /* limit granularity (byte/page units)*/ 4540467Sbill unsigned sd_hibase:8 ; /* segment base address (msb) */ 4640467Sbill } ; 4740467Sbill 4840467Sbill /* 4940467Sbill * Gate descriptors (e.g. indirect descriptors) 5040467Sbill */ 5140467Sbill struct gate_descriptor { 5240467Sbill unsigned gd_looffset:16 ; /* gate offset (lsb) */ 5340467Sbill unsigned gd_selector:16 ; /* gate segment selector */ 5440467Sbill unsigned gd_stkcpy:5 ; /* number of stack wds to cpy */ 5540467Sbill unsigned gd_xx:3 ; /* unused */ 5640467Sbill unsigned gd_type:5 ; /* segment type */ 5740467Sbill unsigned gd_dpl:2 ; /* segment descriptor priority level */ 5840467Sbill unsigned gd_p:1 ; /* segment descriptor present */ 5940467Sbill unsigned gd_hioffset:16 ; /* gate offset (msb) */ 6040467Sbill } ; 6140467Sbill 6240467Sbill /* 6340467Sbill * Generic descriptor 6440467Sbill */ 6540467Sbill union descriptor { 6640467Sbill struct segment_descriptor sd; 6740467Sbill struct gate_descriptor gd; 6840467Sbill }; 6940467Sbill #define d_type gd.gd_type 7040467Sbill 7140467Sbill /* system segments and gate types */ 7240467Sbill #define SDT_SYSNULL 0 /* system null */ 7340467Sbill #define SDT_SYS286TSS 1 /* system 286 TSS available */ 7440467Sbill #define SDT_SYSLDT 2 /* system local descriptor table */ 7540467Sbill #define SDT_SYS286BSY 3 /* system 286 TSS busy */ 7640467Sbill #define SDT_SYS286CGT 4 /* system 286 call gate */ 7740467Sbill #define SDT_SYSTASKGT 5 /* system task gate */ 7840467Sbill #define SDT_SYS286IGT 6 /* system 286 interrupt gate */ 7940467Sbill #define SDT_SYS286TGT 7 /* system 286 trap gate */ 8040467Sbill #define SDT_SYSNULL2 8 /* system null again */ 8140467Sbill #define SDT_SYS386TSS 9 /* system 386 TSS available */ 8240467Sbill #define SDT_SYSNULL3 10 /* system null again */ 8340467Sbill #define SDT_SYS386BSY 11 /* system 386 TSS busy */ 8440467Sbill #define SDT_SYS386CGT 12 /* system 386 call gate */ 8540467Sbill #define SDT_SYSNULL4 13 /* system null again */ 8640467Sbill #define SDT_SYS386IGT 14 /* system 386 interrupt gate */ 8740467Sbill #define SDT_SYS386TGT 15 /* system 386 trap gate */ 8840467Sbill 8940467Sbill /* memory segment types */ 9040467Sbill #define SDT_MEMRO 16 /* memory read only */ 9140467Sbill #define SDT_MEMROA 17 /* memory read only accessed */ 9240467Sbill #define SDT_MEMRW 18 /* memory read write */ 9340467Sbill #define SDT_MEMRWA 19 /* memory read write accessed */ 9440467Sbill #define SDT_MEMROD 20 /* memory read only expand dwn limit */ 9540467Sbill #define SDT_MEMRODA 21 /* memory read only expand dwn limit accessed */ 9640467Sbill #define SDT_MEMRWD 22 /* memory read write expand dwn limit */ 9740467Sbill #define SDT_MEMRWDA 23 /* memory read write expand dwn limit acessed */ 9840467Sbill #define SDT_MEME 24 /* memory execute only */ 9940467Sbill #define SDT_MEMEA 25 /* memory execute only accessed */ 10040467Sbill #define SDT_MEMER 26 /* memory execute read */ 10140467Sbill #define SDT_MEMERA 27 /* memory execute read accessed */ 10240467Sbill #define SDT_MEMEC 28 /* memory execute only conforming */ 10340467Sbill #define SDT_MEMEAC 29 /* memory execute only accessed conforming */ 10440467Sbill #define SDT_MEMERC 30 /* memory execute read conforming */ 10540467Sbill #define SDT_MEMERAC 31 /* memory execute read accessed conforming */ 10640467Sbill 10740467Sbill /* is memory segment descriptor pointer ? */ 10840467Sbill #define ISMEMSDP(s) ((s->d_type) >= SDT_MEMRO && (s->d_type) <= SDT_MEMERAC) 10940467Sbill 11040467Sbill /* is 286 gate descriptor pointer ? */ 11140467Sbill #define IS286GDP(s) (((s->d_type) >= SDT_SYS286CGT \ 11240467Sbill && (s->d_type) < SDT_SYS286TGT)) 11340467Sbill 11440467Sbill /* is 386 gate descriptor pointer ? */ 11540467Sbill #define IS386GDP(s) (((s->d_type) >= SDT_SYS386CGT \ 11640467Sbill && (s->d_type) < SDT_SYS386TGT)) 11740467Sbill 11840467Sbill /* is gate descriptor pointer ? */ 11940467Sbill #define ISGDP(s) (IS286GDP(s) || IS386GDP(s)) 12040467Sbill 12140467Sbill /* is segment descriptor pointer ? */ 12240467Sbill #define ISSDP(s) (ISMEMSDP(s) || !ISGDP(s)) 12340467Sbill 12440467Sbill /* is system segment descriptor pointer ? */ 12540467Sbill #define ISSYSSDP(s) (!ISMEMSDP(s) && !ISGDP(s)) 12640467Sbill 12740467Sbill /* 12840467Sbill * Software definitions are in this convenient format, 12940467Sbill * which are translated into inconvenient segment descriptors 13040467Sbill * when needed to be used by the 386 hardware 13140467Sbill */ 13240467Sbill 13340467Sbill struct soft_segment_descriptor { 13440467Sbill unsigned ssd_base ; /* segment base address */ 13540467Sbill unsigned ssd_limit ; /* segment extent */ 13640467Sbill unsigned ssd_type:5 ; /* segment type */ 13740467Sbill unsigned ssd_dpl:2 ; /* segment descriptor priority level */ 13840467Sbill unsigned ssd_p:1 ; /* segment descriptor present */ 13940467Sbill unsigned ssd_xx:4 ; /* unused */ 14040467Sbill unsigned ssd_xx1:2 ; /* unused */ 14140467Sbill unsigned ssd_def32:1 ; /* default 32 vs 16 bit size */ 14240467Sbill unsigned ssd_gran:1 ; /* limit granularity (byte/page units)*/ 14340467Sbill }; 14440467Sbill 14540467Sbill extern ssdtosd() ; /* to decode a ssd */ 14640467Sbill extern sdtossd() ; /* to encode a sd */ 14740467Sbill 14840467Sbill /* 14940467Sbill * region descriptors, used to load gdt/idt tables before segments yet exist 15040467Sbill */ 15140467Sbill struct region_descriptor { 15240467Sbill unsigned rd_limit:16 ; /* segment extent */ 15340467Sbill char *rd_base; /* base address */ 15440467Sbill }; 15540467Sbill 15645596Sbill /* 15745596Sbill * Segment Protection Exception code bits 15845596Sbill */ 15945596Sbill 16045596Sbill #define SEGEX_EXT 0x01 /* recursive or externally induced */ 16145596Sbill #define SEGEX_IDT 0x02 /* interrupt descriptor table */ 16245596Sbill #define SEGEX_TI 0x04 /* local descriptor table */ 16345596Sbill /* other bits are affected descriptor index */ 16445596Sbill #define SEGEX_IDX(s) ((s)>>3)&0x1fff) 165