source: rtems/cpukit/score/cpu/i386/rtems/score/i386.h @ dda25b1

5
Last change on this file since dda25b1 was 038e1dba, checked in by Jan Dolezal <dolezj21@…>, on 12/03/14 at 23:56:39

i386: doxygen and comments related to VESA real mode framebuffer

  • Property mode set to 100644
File size: 6.0 KB
Line 
1/**
2 * @file
3 *
4 * @brief Intel I386 CPU Dependent Source
5 *
6 * This include file contains information pertaining to the Intel
7 * i386 processor.
8 */
9
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
23extern "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
100static 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
116static 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 */
129static 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
138static inline void i386_set_cr0(unsigned int segment)
139{
140  __asm__ volatile ( "movl %0,%%cr0" : "=r" (segment) : "0" (segment) );
141}
142
143static 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
152static 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
161static 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 */
173void *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 */
183void *i386_Physical_to_logical(
184  unsigned short  segment,
185  void           *address
186);
187
188/**
189 * @brief Converts real mode pointer {segment, offset} to physical address.
190 *
191 * i386_Real_to_physical
192 *
193 * @param[in] segment used with \p offset to compute physical address
194 * @param[in] offset used with \p segment to compute physical address
195 * @retval    physical address
196 */
197RTEMS_INLINE_ROUTINE void *i386_Real_to_physical(
198    uint16_t segment,
199    uint16_t offset)
200{
201    return (void *)(((uint32_t)segment<<4)+offset);
202}
203
204/**
205 * @brief Retreives real mode pointer elements {segmnet, offset} from
206 * physical address.
207 *
208 * i386_Physical_to_real
209 * Function returns the highest segment (base) address possible.
210 * Example:    input   address - 0x4B3A2
211 *             output  segment - 0x4B3A
212 *                     offset  - 0x2
213 *             input   address - 0x10F12E
214 *             output  segment - 0xFFFF
215 *                     offset  - 0xF13E
216 *
217 * @param[in]  address address to be converted, must be less than 0x10FFEF
218 * @param[out] segment segment computed from \p address
219 * @param[out] offset offset computed from \p address
220 * @retval  0 address not convertible
221 * @retval  1 segment and offset extracted
222 */
223int i386_Physical_to_real(
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
Note: See TracBrowser for help on using the repository browser.