1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 #ifndef _SYS_LINUX_LDT_H
  27 #define _SYS_LINUX_LDT_H
  28 
  29 #pragma ident   "%Z%%M% %I%     %E% SMI"
  30 
  31 #include <sys/segments.h>
  32 
  33 #ifdef  __cplusplus
  34 extern "C" {
  35 #endif
  36 
  37 struct ldt_info {
  38         uint_t  entry_number;
  39         uint_t  base_addr;
  40         uint_t  limit;
  41         uint_t  seg_32bit:1,
  42                 contents:2,
  43                 read_exec_only:1,
  44                 limit_in_pages:1,
  45                 seg_not_present:1,
  46                 useable:1;
  47 };
  48 
  49 #define LDT_INFO_EMPTY(info)                                            \
  50         ((info)->base_addr == 0 && (info)->limit == 0 &&          \
  51         (info)->contents == 0 && (info)->read_exec_only == 1 &&           \
  52         (info)->seg_32bit == 0 && (info)->limit_in_pages == 0 &&  \
  53         (info)->seg_not_present == 1 && (info)->useable == 0)
  54 
  55 #if defined(__amd64)
  56 #define SETMODE(desc)   (desc)->usd_long = SDP_SHORT;
  57 #else
  58 #define SETMODE(desc)
  59 #endif
  60 
  61 #define LDT_INFO_TO_DESC(info, desc)    {                               \
  62         USEGD_SETBASE(desc, (info)->base_addr);                              \
  63         USEGD_SETLIMIT(desc, (info)->limit);                         \
  64         (desc)->usd_type = ((info)->contents << 2) |                        \
  65             ((info)->read_exec_only ^ 1) << 1 | 0x10;                  \
  66         (desc)->usd_dpl = SEL_UPL;                                   \
  67         (desc)->usd_p = (info)->seg_not_present ^ 1;                      \
  68         (desc)->usd_def32 = (info)->seg_32bit;                            \
  69         (desc)->usd_gran = (info)->limit_in_pages;                        \
  70         (desc)->usd_avl = (info)->useable;                                \
  71         SETMODE(desc);                                                  \
  72 }
  73 
  74 #define DESC_TO_LDT_INFO(desc, info)    {                               \
  75         bzero((info), sizeof (*(info)));                                \
  76         (info)->base_addr = USEGD_GETBASE(desc);                     \
  77         (info)->limit = USEGD_GETLIMIT(desc);                                \
  78         (info)->seg_not_present = (desc)->usd_p ^ 1;                      \
  79         (info)->contents = ((desc)->usd_type >> 2) & 3;                 \
  80         (info)->read_exec_only = (((desc)->usd_type >> 1) & 1) ^ 1;     \
  81         (info)->seg_32bit = (desc)->usd_def32;                            \
  82         (info)->limit_in_pages = (desc)->usd_gran;                        \
  83         (info)->useable = (desc)->usd_avl;                                \
  84 }
  85 
  86 extern void lx_set_gdt(int, user_desc_t *);
  87 extern void lx_clear_gdt(int);
  88 
  89 #ifdef  __cplusplus
  90 }
  91 #endif
  92 
  93 #endif  /* _SYS_LINUX_LDT_H */