2 * machine.h: Intel CPU specific definitions
4 * Leendert van Doorn, leendert@watson.ibm.com
5 * Copyright (c) 2005, International Business Machines Corporation.
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.
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
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.
23 /* the size of our stack (4KB) */
24 #define STACK_SIZE 8192
26 #define TSS_SELECTOR 0x08
27 #define CODE_SELECTOR 0x10
28 #define DATA_SELECTOR 0x18
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)
36 #define CR4_VME (1 << 0)
37 #define CR4_PVI (1 << 1)
38 #define CR4_PSE (1 << 4)
39 #define CR4_PAE (1 << 5)
41 #define EFLAGS_ZF (1 << 6)
42 #define EFLAGS_TF (1 << 8)
43 #define EFLAGS_IF (1 << 9)
44 #define EFLAGS_DF (1 << 10)
45 #define EFLAGS_IOPL (3 << 12)
46 #define EFLAGS_VM ((1 << 17) | EFLAGS_IOPL)
47 #define EFLAGS_VIF (1 << 19)
48 #define EFLAGS_VIP (1 << 20)
50 #define LOG_PGSIZE 12 /* log2(page size) */
51 #define LOG_PDSIZE 22 /* log2(page directory size) */
53 /* Derived constants */
54 #define PGSIZE (1 << LOG_PGSIZE) /* page size */
55 #define PGMASK (~(PGSIZE - 1)) /* page mask */
56 #define LPGSIZE (1 << LOG_PDSIZE) /* large page size */
57 #define LPGMASK (~(LPGSIZE - 1)) /* large page mask */
60 #define PTE_P (1 << 0) /* Present */
61 #define PTE_RW (1 << 1) /* Read/Write */
62 #define PTE_US (1 << 2) /* User/Supervisor */
63 #define PTE_PS (1 << 7) /* Page Size */
66 /* Programmable Interrupt Contoller (PIC) defines */
67 #define PIC_MASTER 0x20
68 #define PIC_SLAVE 0xA0
70 #define PIC_CMD 0 /* command */
71 #define PIC_ISR 0 /* interrupt status */
72 #define PIC_IMR 1 /* interrupt mask */
79 unsigned long base __attribute__ ((packed));
83 unsigned short prev_link;
111 unsigned short ldt_segment;
114 unsigned short iomap_base;
116 unsigned long int_redir[8];
118 unsigned char iomap[8192];
122 outw(unsigned short addr, unsigned short val)
124 __asm__ __volatile__ ("outw %%ax, %%dx" :: "d"(addr), "a"(val));
128 outb(unsigned short addr, unsigned char val)
130 __asm__ __volatile__ ("outb %%al, %%dx" :: "d"(addr), "a"(val));
133 static inline unsigned char
134 inb(unsigned short addr)
138 __asm__ __volatile__ ("inb %w1,%0" : "=a" (val) : "Nd" (addr));
142 static inline unsigned
149 static inline unsigned
153 __asm__ __volatile__("movl %%cr0, %0" : "=r"(rv));
158 set_cr0(unsigned value)
160 __asm__ __volatile__(
169 static inline unsigned
174 __asm__ __volatile__("movl %%cr2, %0" : "=r"(rv));
178 static inline unsigned
182 __asm__ __volatile__("movl %%cr4, %0" : "=r"(rv));
187 set_cr3(unsigned addr)
189 __asm__ __volatile__("movl %0, %%cr3" : /* no outputs */ : "r"(addr));
193 set_cr4(unsigned value)
195 __asm__ __volatile__("movl %0, %%cr4" : /* no outputs */ : "r"(value));
202 outw(0x8A00, 0x8AE0);
206 #endif /* __ASSEMBLY__ */
208 #endif /* __MACHINE_H__ */