RTEMS CPU Kit with SuperCore  4.11.3
i386.h
Go to the documentation of this file.
1 
10 /*
11  * COPYRIGHT (c) 1989-2013.
12  * On-Line Applications Research Corporation (OAR).
13  *
14  * The license and distribution terms for this file may be
15  * found in the file LICENSE in this distribution or at
16  * http://www.rtems.org/license/LICENSE.
17  */
18 
19 #ifndef _RTEMS_SCORE_I386_H
20 #define _RTEMS_SCORE_I386_H
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 /*
27  * This section contains the information required to build
28  * RTEMS for a particular member of the Intel i386
29  * family when executing in protected mode. It does
30  * this by setting variables to indicate which implementation
31  * dependent features are present in a particular member
32  * of the family.
33  *
34  * Currently recognized:
35  * i386_fp (i386 DX or SX w/i387)
36  * i486dx
37  * pentium
38  * pentiumpro
39  *
40  * CPU Model Feature Flags:
41  *
42  * I386_HAS_BSWAP: Defined to "1" if the instruction for endian swapping
43  * (bswap) should be used. This instruction appears to
44  * be present in all i486's and above.
45  *
46  * I386_HAS_FPU: Defined to "1" if the CPU has an FPU.
47  * As of at least gcc 4.7, i386 soft-float was obsoleted.
48  * Thus this is always set to "1".
49  */
50 #define I386_HAS_FPU 1
51 
52 #if defined(__pentiumpro__)
53 
54  #define CPU_MODEL_NAME "Pentium Pro"
55 
56 #elif defined(__i586__)
57 
58  #if defined(__pentium__)
59  #define CPU_MODEL_NAME "Pentium"
60  #elif defined(__k6__)
61  #define CPU_MODEL_NAME "K6"
62  #else
63  #define CPU_MODEL_NAME "i586"
64  #endif
65 
66 #elif defined(__i486__)
67 
68  #define CPU_MODEL_NAME "i486dx"
69 
70 #elif defined(__i386__)
71 
72  #define I386_HAS_BSWAP 0
73  #define CPU_MODEL_NAME "i386 with i387"
74 
75 #else
76  #error "Unknown CPU Model"
77 #endif
78 
79 /*
80  * Set default values for CPU model feature flags
81  *
82  * NOTE: These settings are chosen to reflect most of the family members.
83  */
84 #ifndef I386_HAS_BSWAP
85 #define I386_HAS_BSWAP 1
86 #endif
87 
88 /*
89  * Define the name of the CPU family.
90  */
91 #define CPU_NAME "Intel i386"
92 
93 #ifndef ASM
94 
95 /*
96  * The following routine swaps the endian format of an unsigned int.
97  * It must be static so it can be referenced indirectly.
98  */
99 
100 static inline uint32_t i386_swap_u32(
101  uint32_t value
102 )
103 {
104  uint32_t lout;
105 
106 #if (I386_HAS_BSWAP == 0)
107  __asm__ volatile( "rorw $8,%%ax;"
108  "rorl $16,%0;"
109  "rorw $8,%%ax" : "=a" (lout) : "0" (value) );
110 #else
111  __asm__ volatile( "bswap %0" : "=r" (lout) : "0" (value));
112 #endif
113  return( lout );
114 }
115 
116 static inline uint16_t i386_swap_u16(
117  uint16_t value
118 )
119 {
120  unsigned short sout;
121 
122  __asm__ volatile( "rorw $8,%0" : "=r" (sout) : "0" (value));
123  return (sout);
124 }
125 
126 /*
127  * Added for pagination management
128  */
129 static inline unsigned int i386_get_cr0(void)
130 {
131  register unsigned int segment = 0;
132 
133  __asm__ volatile ( "movl %%cr0,%0" : "=r" (segment) : "0" (segment) );
134 
135  return segment;
136 }
137 
138 static inline void i386_set_cr0(unsigned int segment)
139 {
140  __asm__ volatile ( "movl %0,%%cr0" : "=r" (segment) : "0" (segment) );
141 }
142 
143 static inline unsigned int i386_get_cr2(void)
144 {
145  register unsigned int segment = 0;
146 
147  __asm__ volatile ( "movl %%cr2,%0" : "=r" (segment) : "0" (segment) );
148 
149  return segment;
150 }
151 
152 static inline unsigned int i386_get_cr3(void)
153 {
154  register unsigned int segment = 0;
155 
156  __asm__ volatile ( "movl %%cr3,%0" : "=r" (segment) : "0" (segment) );
157 
158  return segment;
159 }
160 
161 static inline void i386_set_cr3(unsigned int segment)
162 {
163  __asm__ volatile ( "movl %0,%%cr3" : "=r" (segment) : "0" (segment) );
164 }
165 
166 /* routines */
167 
168 /*
169  * i386_Logical_to_physical
170  *
171  * Converts logical address to physical address.
172  */
173 void *i386_Logical_to_physical(
174  unsigned short segment,
175  void *address
176 );
177 
178 /*
179  * i386_Physical_to_logical
180  *
181  * Converts physical address to logical address.
182  */
183 void *i386_Physical_to_logical(
184  unsigned short segment,
185  void *address
186 );
187 
198  uint16_t segment,
199  uint16_t offset)
200 {
201  return (void *)(((uint32_t)segment<<4)+offset);
202 }
203 
224  void *address,
225  uint16_t *segment,
226  uint16_t *offset
227 );
228 
229 /*
230  * "Simpler" names for a lot of the things defined in this file
231  */
232 
233 /* segment access routines */
234 
235 #define get_cs() i386_get_cs()
236 #define get_ds() i386_get_ds()
237 #define get_es() i386_get_es()
238 #define get_ss() i386_get_ss()
239 #define get_fs() i386_get_fs()
240 #define get_gs() i386_get_gs()
241 
242 #define CPU_swap_u32( _value ) i386_swap_u32( _value )
243 #define CPU_swap_u16( _value ) i386_swap_u16( _value )
244 
245 /* i80x86 I/O instructions */
246 
247 #define outport_byte( _port, _value ) i386_outport_byte( _port, _value )
248 #define outport_word( _port, _value ) i386_outport_word( _port, _value )
249 #define outport_long( _port, _value ) i386_outport_long( _port, _value )
250 #define inport_byte( _port, _value ) i386_inport_byte( _port, _value )
251 #define inport_word( _port, _value ) i386_inport_word( _port, _value )
252 #define inport_long( _port, _value ) i386_inport_long( _port, _value )
253 
254 
255 #ifdef __cplusplus
256 }
257 #endif
258 
259 #endif /* !ASM */
260 
261 #endif
#define RTEMS_INLINE_ROUTINE
The following (in conjunction with compiler arguments) are used to choose between the use of static i...
Definition: basedefs.h:135
register struct Per_CPU_Control *_SPARC_Per_CPU_current __asm__("g6")
The pointer to the current per-CPU control is available via register g6.
int i386_Physical_to_real(void *address, uint16_t *segment, uint16_t *offset)
Retreives real mode pointer elements {segmnet, offset} from physical address.
RTEMS_INLINE_ROUTINE void * i386_Real_to_physical(uint16_t segment, uint16_t offset)
Converts real mode pointer {segment, offset} to physical address.
Definition: i386.h:197