Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


(no commit message)
[palacios.git] / palacios / include / geekos / segment.h
1 /*
2  * General data structures and routines for segmentation
3  * Copyright (c) 2001, David H. Hovemeyer <daveho@cs.umd.edu>
4  * $Revision: 1.1.1.1 $
5  * 
6  * This is free software.  You are permitted to use,
7  * redistribute, and modify it as specified in the file "COPYING".
8  */
9
10 /*
11  * Source: _Protected Mode Software Architecture_ by Tom Shanley,
12  * ISBN 020155447X.
13  */
14
15 #ifndef GEEKOS_SEGMENT_H
16 #define GEEKOS_SEGMENT_H
17
18 #include <geekos/ktypes.h>
19
20 struct TSS;
21
22 #if __TINYC__
23 #define PACKED
24 #else
25 #define PACKED __attribute__((packed))
26 #endif
27
28 /*
29  * The general format of a segment descriptor.
30  */
31 struct Segment_Descriptor {
32     ushort_t sizeLow        PACKED ;
33     uint_t baseLow     : 24 PACKED ;
34     uint_t type        : 4  PACKED ;
35     uint_t system      : 1  PACKED ;
36     uint_t dpl         : 2  PACKED ;
37     uint_t present     : 1  PACKED ;
38     uint_t sizeHigh    : 4  PACKED ;
39     uint_t avail       : 1  PACKED ;
40     uint_t reserved    : 1  PACKED ;  /* set to zero */
41     uint_t dbBit       : 1  PACKED ;
42     uint_t granularity : 1  PACKED ;
43     uchar_t baseHigh        PACKED ;
44 };
45
46 /**
47  * Construct a segment selector.
48  * @param rpl requestor privilege level; should be KERNEL_PRIVILEGE
49  *    for kernel segments and USER_PRIVILEGE for user segments
50  * @param segmentIsInGDT true if the referenced segment descriptor
51  *    is defined in the GDT, false if it is defined in the LDT
52  * @param index index of the segment descriptor
53  * @return the segment selector
54  */
55 static __inline__ ushort_t Selector(int rpl, bool segmentIsInGDT, int index)
56 {
57     ushort_t selector = 0;
58     selector = (rpl & 0x3) | ((segmentIsInGDT ? 0 : 1) << 2) | ((index & 0x1FFF) << 3);
59     return selector;
60 }
61
62 /*
63  * Routines to initialize segment descriptors.
64  * Code and data segments must start on a page-aligned address
65  * and are sized in pages.
66  */
67
68 void Init_Null_Segment_Descriptor(struct Segment_Descriptor* desc);
69
70 void Init_Code_Segment_Descriptor(
71     struct Segment_Descriptor* desc,
72     ulong_t baseAddr,
73     ulong_t numPages,
74     int privilegeLevel
75 );
76 void Init_Data_Segment_Descriptor(
77     struct Segment_Descriptor* desc,
78     ulong_t baseAddr,
79     ulong_t numPages,
80     int privilegeLevel
81 );
82 void Init_TSS_Descriptor(struct Segment_Descriptor* desc, struct TSS* theTSS);
83
84 void Init_LDT_Descriptor(
85     struct Segment_Descriptor* desc,
86     struct Segment_Descriptor theLDT[],
87     int numEntries
88 );
89
90 #endif  /* GEEKOS_SEGMENT_H */