[7908ba5b] | 1 | /* i386.h |
---|
| 2 | * |
---|
| 3 | * This include file contains information pertaining to the Intel |
---|
| 4 | * i386 processor. |
---|
| 5 | * |
---|
[08311cc3] | 6 | * COPYRIGHT (c) 1989-1999. |
---|
[7908ba5b] | 7 | * On-Line Applications Research Corporation (OAR). |
---|
| 8 | * |
---|
| 9 | * The license and distribution terms for this file may be |
---|
| 10 | * found in the file LICENSE in this distribution or at |
---|
| 11 | * http://www.OARcorp.com/rtems/license.html. |
---|
| 12 | * |
---|
| 13 | * $Id$ |
---|
| 14 | */ |
---|
| 15 | |
---|
| 16 | #ifndef __i386_h |
---|
| 17 | #define __i386_h |
---|
| 18 | |
---|
| 19 | #ifdef __cplusplus |
---|
| 20 | extern "C" { |
---|
| 21 | #endif |
---|
| 22 | |
---|
| 23 | /* |
---|
| 24 | * This section contains the information required to build |
---|
| 25 | * RTEMS for a particular member of the Intel i386 |
---|
| 26 | * family when executing in protected mode. It does |
---|
| 27 | * this by setting variables to indicate which implementation |
---|
| 28 | * dependent features are present in a particular member |
---|
| 29 | * of the family. |
---|
| 30 | * |
---|
| 31 | * Currently recognized: |
---|
| 32 | * i386_fp (i386 DX or SX w/i387) |
---|
| 33 | * i386_nofp (i386 DX or SX w/o i387) |
---|
| 34 | * i486dx |
---|
| 35 | * i486sx |
---|
| 36 | * pentium |
---|
[318f591] | 37 | * pentiumpro |
---|
[7908ba5b] | 38 | * |
---|
| 39 | * CPU Model Feature Flags: |
---|
| 40 | * |
---|
| 41 | * I386_HAS_BSWAP: Defined to "1" if the instruction for endian swapping |
---|
| 42 | * (bswap) should be used. This instruction appears to |
---|
| 43 | * be present in all i486's and above. |
---|
| 44 | * |
---|
| 45 | * I386_HAS_FPU: Defined to "1" if the CPU has an FPU. |
---|
| 46 | * |
---|
| 47 | */ |
---|
| 48 | |
---|
[df49c60] | 49 | #if defined(rtems_multilib) |
---|
| 50 | /* |
---|
| 51 | * Figure out all CPU Model Feature Flags based upon compiler |
---|
| 52 | * predefines. |
---|
| 53 | */ |
---|
| 54 | |
---|
| 55 | #define CPU_MODEL_NAME "rtems_multilib" |
---|
| 56 | #define I386_HAS_FPU 0 |
---|
| 57 | #define I386_HAS_BSWAP 0 |
---|
| 58 | |
---|
| 59 | #elif defined(i386_fp) |
---|
[7908ba5b] | 60 | |
---|
| 61 | #define CPU_MODEL_NAME "i386 with i387" |
---|
| 62 | #define I386_HAS_BSWAP 0 |
---|
| 63 | |
---|
| 64 | #elif defined(i386_nofp) |
---|
| 65 | |
---|
| 66 | #define CPU_MODEL_NAME "i386 w/o i387" |
---|
| 67 | #define I386_HAS_FPU 0 |
---|
| 68 | #define I386_HAS_BSWAP 0 |
---|
| 69 | |
---|
| 70 | #elif defined(i486dx) |
---|
| 71 | |
---|
| 72 | #define CPU_MODEL_NAME "i486dx" |
---|
| 73 | |
---|
| 74 | #elif defined(i486sx) |
---|
| 75 | |
---|
| 76 | #define CPU_MODEL_NAME "i486sx" |
---|
| 77 | #define I386_HAS_FPU 0 |
---|
| 78 | |
---|
| 79 | #elif defined(pentium) |
---|
| 80 | |
---|
| 81 | #define CPU_MODEL_NAME "Pentium" |
---|
| 82 | |
---|
[318f591] | 83 | #elif defined(pentiumpro) |
---|
| 84 | |
---|
| 85 | #define CPU_MODEL_NAME "Pentium Pro" |
---|
| 86 | |
---|
[7908ba5b] | 87 | #else |
---|
| 88 | |
---|
| 89 | #error "Unsupported CPU Model" |
---|
| 90 | |
---|
| 91 | #endif |
---|
| 92 | |
---|
| 93 | /* |
---|
| 94 | * Set default values for CPU model feature flags |
---|
| 95 | * |
---|
| 96 | * NOTE: These settings are chosen to reflect most of the family members. |
---|
| 97 | */ |
---|
| 98 | |
---|
| 99 | #ifndef I386_HAS_FPU |
---|
| 100 | #define I386_HAS_FPU 1 |
---|
| 101 | #endif |
---|
| 102 | |
---|
| 103 | #ifndef I386_HAS_BSWAP |
---|
| 104 | #define I386_HAS_BSWAP 1 |
---|
| 105 | #endif |
---|
| 106 | |
---|
| 107 | /* |
---|
| 108 | * Define the name of the CPU family. |
---|
| 109 | */ |
---|
| 110 | |
---|
| 111 | #define CPU_NAME "Intel i386" |
---|
| 112 | |
---|
| 113 | #ifndef ASM |
---|
| 114 | |
---|
| 115 | /* |
---|
| 116 | * The following routine swaps the endian format of an unsigned int. |
---|
| 117 | * It must be static so it can be referenced indirectly. |
---|
| 118 | */ |
---|
| 119 | |
---|
| 120 | static inline unsigned int i386_swap_U32( |
---|
| 121 | unsigned int value |
---|
| 122 | ) |
---|
| 123 | { |
---|
| 124 | unsigned long lout; |
---|
| 125 | |
---|
| 126 | #if (I386_HAS_BSWAP == 0) |
---|
| 127 | asm volatile( "rorw $8,%%ax;" |
---|
| 128 | "rorl $16,%0;" |
---|
| 129 | "rorw $8,%%ax" : "=a" (lout) : "0" (value) ); |
---|
| 130 | #else |
---|
| 131 | __asm__ volatile( "bswap %0" : "=r" (lout) : "0" (value)); |
---|
| 132 | #endif |
---|
| 133 | return( lout ); |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | static inline unsigned int i386_swap_U16( |
---|
| 137 | unsigned int value |
---|
| 138 | ) |
---|
| 139 | { |
---|
| 140 | unsigned short sout; |
---|
| 141 | |
---|
| 142 | __asm__ volatile( "rorw $8,%0" : "=r" (sout) : "0" (value)); |
---|
| 143 | return (sout); |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | |
---|
[8ef3818] | 147 | /* |
---|
| 148 | * Added for pagination management |
---|
| 149 | */ |
---|
| 150 | |
---|
| 151 | static inline unsigned int i386_get_cr0() |
---|
| 152 | { |
---|
| 153 | register unsigned int segment = 0; |
---|
| 154 | |
---|
| 155 | asm volatile ( "movl %%cr0,%0" : "=r" (segment) : "0" (segment) ); |
---|
| 156 | |
---|
| 157 | return segment; |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | static inline void i386_set_cr0(unsigned int segment) |
---|
| 161 | { |
---|
| 162 | asm volatile ( "movl %0,%%cr0" : "=r" (segment) : "0" (segment) ); |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | static inline unsigned int i386_get_cr2() |
---|
| 166 | { |
---|
| 167 | register unsigned int segment = 0; |
---|
| 168 | |
---|
| 169 | asm volatile ( "movl %%cr2,%0" : "=r" (segment) : "0" (segment) ); |
---|
| 170 | |
---|
| 171 | return segment; |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | static inline unsigned int i386_get_cr3() |
---|
| 175 | { |
---|
| 176 | register unsigned int segment = 0; |
---|
| 177 | |
---|
| 178 | asm volatile ( "movl %%cr3,%0" : "=r" (segment) : "0" (segment) ); |
---|
| 179 | |
---|
| 180 | return segment; |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | static inline void i386_set_cr3(unsigned int segment) |
---|
| 184 | { |
---|
| 185 | asm volatile ( "movl %0,%%cr3" : "=r" (segment) : "0" (segment) ); |
---|
| 186 | } |
---|
| 187 | |
---|
[7908ba5b] | 188 | /* routines */ |
---|
| 189 | |
---|
| 190 | /* |
---|
| 191 | * i386_Logical_to_physical |
---|
| 192 | * |
---|
| 193 | * Converts logical address to physical address. |
---|
| 194 | */ |
---|
| 195 | |
---|
| 196 | void *i386_Logical_to_physical( |
---|
| 197 | unsigned short segment, |
---|
| 198 | void *address |
---|
| 199 | ); |
---|
| 200 | |
---|
| 201 | /* |
---|
| 202 | * i386_Physical_to_logical |
---|
| 203 | * |
---|
| 204 | * Converts physical address to logical address. |
---|
| 205 | */ |
---|
| 206 | |
---|
| 207 | void *i386_Physical_to_logical( |
---|
| 208 | unsigned short segment, |
---|
| 209 | void *address |
---|
| 210 | ); |
---|
| 211 | |
---|
| 212 | |
---|
| 213 | /* |
---|
| 214 | * "Simpler" names for a lot of the things defined in this file |
---|
| 215 | */ |
---|
| 216 | |
---|
| 217 | /* segment access routines */ |
---|
| 218 | |
---|
| 219 | #define get_cs() i386_get_cs() |
---|
| 220 | #define get_ds() i386_get_ds() |
---|
| 221 | #define get_es() i386_get_es() |
---|
| 222 | #define get_ss() i386_get_ss() |
---|
| 223 | #define get_fs() i386_get_fs() |
---|
| 224 | #define get_gs() i386_get_gs() |
---|
| 225 | |
---|
| 226 | #define CPU_swap_u32( _value ) i386_swap_U32( _value ) |
---|
| 227 | #define CPU_swap_u16( _value ) i386_swap_U16( _value ) |
---|
| 228 | |
---|
| 229 | /* i80x86 I/O instructions */ |
---|
| 230 | |
---|
| 231 | #define outport_byte( _port, _value ) i386_outport_byte( _port, _value ) |
---|
| 232 | #define outport_word( _port, _value ) i386_outport_word( _port, _value ) |
---|
| 233 | #define outport_long( _port, _value ) i386_outport_long( _port, _value ) |
---|
| 234 | #define inport_byte( _port, _value ) i386_inport_byte( _port, _value ) |
---|
| 235 | #define inport_word( _port, _value ) i386_inport_word( _port, _value ) |
---|
| 236 | #define inport_long( _port, _value ) i386_inport_long( _port, _value ) |
---|
| 237 | |
---|
| 238 | |
---|
| 239 | #ifdef __cplusplus |
---|
| 240 | } |
---|
| 241 | #endif |
---|
| 242 | |
---|
| 243 | #endif /* !ASM */ |
---|
| 244 | |
---|
| 245 | #endif |
---|
| 246 | /* end of include file */ |
---|