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.


Modified boot and vmxassist to handle real/protected transition.
[palacios.git] / bios / vmxassist / machine.h
1 /*
2  * machine.h: Intel CPU specific definitions
3  *
4  * Leendert van Doorn, leendert@watson.ibm.com
5  * Copyright (c) 2005, International Business Machines Corporation.
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms and conditions of the GNU General Public License,
9  * version 2, as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
18  * Place - Suite 330, Boston, MA 02111-1307 USA.
19  */
20 #ifndef __MACHINE_H__
21 #define __MACHINE_H__
22
23 /* the size of our stack (4KB) */
24 #define STACK_SIZE      8192
25
26 #define TSS_SELECTOR    0x08
27 #define CODE_SELECTOR   0x10
28 #define DATA_SELECTOR   0x18
29
30 #define CR0_PE          (1 << 0)
31 #define CR0_EM          (1 << 2)
32 #define CR0_TS          (1 << 3)
33 #define CR0_NE          (1 << 5)
34 #define CR0_PG          (1 << 31)
35
36 #define CR4_VME         (1 << 0)
37 #define CR4_PVI         (1 << 1)
38 #define CR4_PSE         (1 << 4)
39 #define CR4_PAE         (1 << 5)
40
41 #define EFLAGS_CF       (1 << 0)
42 #define EFLAGS_PF       (1 << 2)
43 #define EFLAGS_AF       (1 << 4)
44 #define EFLAGS_ZF       (1 << 6)
45 #define EFLAGS_SF       (1 << 7)
46 #define EFLAGS_TF       (1 << 8)
47 #define EFLAGS_IF       (1 << 9)
48 #define EFLAGS_DF       (1 << 10)
49 #define EFLAGS_OF       (1 << 11)
50 #define EFLAGS_IOPL     (3 << 12)
51 #define EFLAGS_VM       ((1 << 17) | EFLAGS_IOPL)
52 #define EFLAGS_VIF      (1 << 19)
53 #define EFLAGS_VIP      (1 << 20)
54
55 #define LOG_PGSIZE      12      /* log2(page size) */
56 #define LOG_PDSIZE      22      /* log2(page directory size) */
57
58 /* Derived constants */
59 #define PGSIZE          (1 << LOG_PGSIZE)       /* page size */
60 #define PGMASK          (~(PGSIZE - 1))         /* page mask */
61 #define LPGSIZE         (1 << LOG_PDSIZE)       /* large page size */
62 #define LPGMASK         (~(LPGSIZE - 1))        /* large page mask */
63
64 /* Programmable Interrupt Contoller (PIC) defines */
65 #define PIC_MASTER      0x20
66 #define PIC_SLAVE       0xA0
67
68 #define PIC_CMD         0       /* command */
69 #define PIC_ISR         0       /* interrupt status */
70 #define PIC_IMR         1       /* interrupt mask */
71
72
73 #ifndef __ASSEMBLY__
74
75 struct dtr {
76         unsigned short  size;
77         unsigned long   base __attribute__ ((packed));
78 };
79
80 struct tss {
81         unsigned short  prev_link;
82         unsigned short  _1;
83         unsigned long   esp0;
84         unsigned short  ss0;
85         unsigned short  _2;
86         unsigned long   esp1;
87         unsigned short  ss1;
88         unsigned short  _3;
89         unsigned long   esp2;
90         unsigned short  ss2;
91         unsigned short  _4;
92         unsigned long   cr3;
93         unsigned long   eip;
94         unsigned long   eflags;
95         unsigned long   eax;
96         unsigned long   ecx;
97         unsigned long   edx;
98         unsigned long   ebx;
99         unsigned long   esi;
100         unsigned long   edi;
101         unsigned long   esp;
102         unsigned long   ebp;
103         unsigned long   es;
104         unsigned long   cs;
105         unsigned long   ss;
106         unsigned long   ds;
107         unsigned long   fs;
108         unsigned long   gs;
109         unsigned short  ldt_segment;
110         unsigned short  _5;
111         unsigned short  _6;
112         unsigned short  iomap_base;
113 #ifdef  ENABLE_VME
114         unsigned long   int_redir[8];
115 #endif
116         unsigned char   iomap[8193];
117 };
118
119 static inline void
120 outw(unsigned short addr, unsigned short val)
121 {
122         __asm__ __volatile__ ("outw %%ax, %%dx" :: "d"(addr), "a"(val));
123 }
124
125 static inline void
126 outb(unsigned short addr, unsigned char val)
127 {
128         __asm__ __volatile__ ("outb %%al, %%dx" :: "d"(addr), "a"(val));
129 }
130
131 static inline unsigned char
132 inb(unsigned short addr)
133 {
134         unsigned char val;
135
136         __asm__ __volatile__ ("inb %w1,%0" : "=a" (val) : "Nd" (addr));
137         return val;
138 }
139
140 static inline unsigned
141 get_cmos(int reg)
142 {
143         outb(0x70, reg);
144         return inb(0x71);
145 }
146
147 static inline unsigned
148 get_cr0(void)
149 {
150         unsigned rv;
151         __asm__ __volatile__("movl %%cr0, %0" : "=r"(rv));
152         return rv;
153 }
154
155 static inline void
156 set_cr0(unsigned value)
157 {
158         __asm__ __volatile__(
159                 "movl   %0, %%cr0\n"
160                 "jmp    1f\n"
161                 "1:     nop\n"
162                 : /* no outputs */
163                 : "r"(value)
164         );
165 }
166
167 static inline unsigned
168 get_cr2(void)
169 {
170         unsigned rv;
171
172         __asm__ __volatile__("movl %%cr2, %0" : "=r"(rv));
173         return rv;
174 }
175
176 static inline unsigned
177 get_cr4(void)
178 {
179         unsigned rv;
180         __asm__ __volatile__("movl %%cr4, %0" : "=r"(rv));
181         return rv;
182 }
183
184 static inline void
185 set_cr3(unsigned addr)
186 {
187         __asm__ __volatile__("movl %0, %%cr3" : /* no outputs */ : "r"(addr));
188 }
189
190 static inline void
191 set_cr4(unsigned value)
192 {
193         __asm__ __volatile__("movl %0, %%cr4" : /* no outputs */ : "r"(value));
194 }
195
196 #endif /* __ASSEMBLY__ */
197
198 #endif /* __MACHINE_H__ */
199