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.


geekos test kernel build fixes
[palacios.git] / test / geekos_test_vm / 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 $
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 /*
23  * The general format of a segment descriptor.
24  */
25 struct Segment_Descriptor {
26     ushort_t sizeLow;
27     uint_t baseLow     : 24;
28     uint_t type        : 4;
29     uint_t system      : 1;
30     uint_t dpl         : 2;
31     uint_t present     : 1;
32     uint_t sizeHigh    : 4;
33     uint_t avail       : 1;
34     uint_t reserved    : 1;  /* set to zero */
35     uint_t dbBit       : 1;
36     uint_t granularity : 1;
37     uchar_t baseHigh ;
38 } __attribute__((packed));
39
40 /**
41  * Construct a segment selector.
42  * @param rpl requestor privilege level; should be KERNEL_PRIVILEGE
43  *    for kernel segments and USER_PRIVILEGE for user segments
44  * @param segmentIsInGDT true if the referenced segment descriptor
45  *    is defined in the GDT, false if it is defined in the LDT
46  * @param index index of the segment descriptor
47  * @return the segment selector
48  */
49 static __inline__ ushort_t Selector(int rpl, bool segmentIsInGDT, int index)
50 {
51     ushort_t selector = 0;
52     selector = (rpl & 0x3) | ((segmentIsInGDT ? 0 : 1) << 2) | ((index & 0x1FFF) << 3);
53     return selector;
54 }
55
56 /*
57  * Routines to initialize segment descriptors.
58  * Code and data segments must start on a page-aligned address
59  * and are sized in pages.
60  */
61
62 void Init_Null_Segment_Descriptor(struct Segment_Descriptor* desc);
63
64 void Init_Code_Segment_Descriptor(
65     struct Segment_Descriptor* desc,
66     ulong_t baseAddr,
67     ulong_t numPages,
68     int privilegeLevel
69 );
70 void Init_Data_Segment_Descriptor(
71     struct Segment_Descriptor* desc,
72     ulong_t baseAddr,
73     ulong_t numPages,
74     int privilegeLevel
75 );
76 void Init_TSS_Descriptor(struct Segment_Descriptor* desc, struct TSS* theTSS);
77
78 void Init_LDT_Descriptor(
79     struct Segment_Descriptor* desc,
80     struct Segment_Descriptor theLDT[],
81     int numEntries
82 );
83
84 #endif  /* GEEKOS_SEGMENT_H */