File: descriptor.h

package info (click to toggle)
plex86 0.0.20011018-8
  • links: PTS
  • area: main
  • in suites: woody
  • size: 4,868 kB
  • ctags: 8,721
  • sloc: ansic: 46,915; cpp: 17,817; xml: 1,283; makefile: 1,130; sh: 451; asm: 360; csh: 18
file content (120 lines) | stat: -rw-r--r-- 3,457 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 *  plex86: run multiple x86 operating systems concurrently
 *  Copyright (C) 1999-2000  Kevin P. Lawton
 *
 *  descriptor.h: defines for descriptors and selectors
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 */


#ifndef __DESCRIPTOR_H__
#define __DESCRIPTOR_H__

#define SET_DESCRIPTOR(d, B, L, G, DB, AVL, P, DPL, T) {\
    d.base_high = (B) >> 24;\
    d.base_med  = ((B) >> 16) & 0xff;\
    d.base_low  = (B) & 0xffff;\
    d.limit_high = ((L) & 0xf0000) >> 16;\
    d.limit_low  = ((L) & 0x0ffff);\
    d.g = (G);\
    d.d_b = (DB);\
    d.reserved = 0;\
    d.avl = (AVL);\
    d.p = (P);\
    d.dpl = (DPL);\
    d.type = (T);\
    }

typedef struct {
    Bit16u     limit_low;       /* limit 0..15 */
    Bit16u     base_low;        /* base  0..15 */
    Bit8u      base_med;        /* base  16..23 */
    unsigned   type:5;          /* S/type field */
    unsigned   dpl:2;           /* DPL */
    unsigned   p:1;             /* present */
    unsigned   limit_high:4;    /* limit 16..19 */
    unsigned   avl:1;           /* Available for use by system software */
    unsigned   reserved:1;      /* 0 */
    unsigned   d_b:1;           /* D/B */
    unsigned   g:1;             /* granularity */
    Bit8u      base_high;       /* base 24..31 */
    } __attribute__ ((packed)) descriptor_t;


typedef union {
  struct {
    Bit16u  rpl:2;
    Bit16u  ti:1;
    Bit16u  index:13;
    } __attribute__ ((packed)) fields;
  Bit16u raw;
  } __attribute__ ((packed)) selector_t;

#define D_DPL0 0
#define D_DPL1 1
#define D_DPL2 2
#define D_DPL3 3

#define D_BG 0
#define D_PG 1

#define D_D16 0
#define D_D32 1

#define D_NOTPRESENT 0
#define D_PRESENT    1

#define D_S        0x10
#define D_DATA     0x10
#define D_CODE     0x18
#define D_EXECUTE  0x08
#define D_EXDOWN   0x04
#define D_CONFORM  0x04
#define D_WRITE    0x02  /* writable (data segment) */
#define D_READ     0x02  /* readable (code segment) */
#define D_ACCESSED 0x01

#define D_LDT   0x02   /* LDT segment */
#define D_TASK  0x05   /* Task gate */
#define D_TSS   0x09   /* TSS */
#define D_CALL  0x0C  /* 386 call gate */
#define D_INT   0x0E  /* 386 interrupt gate */
#define D_TRAP  0x0F  /* 386 trap gate */

#define D_AVL0  0
#define D_AVL1  1

#define LimitOfDataDescriptor(d) \
  ( d.g ? \
      ( ((d.type & 0xc) == 0x4) ? \
          ((d.limit_high << 16) | d.limit_low)<<12 : \
          ((d.limit_high << 16) | d.limit_low)<<12 | 0xfff) : \
      ((d.limit_high << 16) | d.limit_low) )

#define BaseOfDescriptor(d) \
  ( (d.base_low) | (d.base_med << 16) | (d.base_high << 24) )

/*
 *  selector stuff
 */

#define Selector(sel, ti, rpl) (((sel)<<3) | ((ti)<<2) | (rpl))
#define RPL0 0
#define RPL1 1
#define RPL2 2
#define RPL3 3

#endif  /* __DESCRIPTOR_H__ */