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

4.115
Last change on this file since d78eac6 was 58af50d, checked in by Jan Dolezal <dolezj21@…>, on 11/20/14 at 14:00:27

score: i386: functions converting real mode pointer to physical address and back

  • Property mode set to 100644
File size: 5.7 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 *  i386_Real_to_physical
190 *
191 *  Converts real mode pointer {segment, offset} to physical address.
192 */
193RTEMS_INLINE_ROUTINE void *i386_Real_to_physical(
194    uint16_t segment,
195    uint16_t offset)
196{
197    return (void *)(((uint32_t)segment<<4)+offset);
198}
199
200/*
201 *  i386_Physical_to_real
202 *  Retreives real mode pointer elements {segmnet, offset} from physical address
203 *  Function returns the highest segment (base) address possible.
204 *  Example:    input   address - 0x4B3A2
205 *              output  segment - 0x4B3A
206 *                      offset  - 0x2
207 *              input   address - 0x10F12E
208 *              output  segment - 0xFFFF
209 *                      offset  - 0xF13E
210 *
211 *  return  0 address not convertible, must be less than 0x10FFEF
212 *          1 segment and offset extracted
213 */
214int i386_Physical_to_real(
215  void *address,
216  uint16_t *segment,
217  uint16_t *offset
218);
219
220/*
221 *  "Simpler" names for a lot of the things defined in this file
222 */
223
224/* segment access routines */
225
226#define get_cs()   i386_get_cs()
227#define get_ds()   i386_get_ds()
228#define get_es()   i386_get_es()
229#define get_ss()   i386_get_ss()
230#define get_fs()   i386_get_fs()
231#define get_gs()   i386_get_gs()
232
233#define CPU_swap_u32( _value )  i386_swap_u32( _value )
234#define CPU_swap_u16( _value )  i386_swap_u16( _value )
235
236/* i80x86 I/O instructions */
237
238#define outport_byte( _port, _value ) i386_outport_byte( _port, _value )
239#define outport_word( _port, _value ) i386_outport_word( _port, _value )
240#define outport_long( _port, _value ) i386_outport_long( _port, _value )
241#define inport_byte( _port, _value )  i386_inport_byte( _port, _value )
242#define inport_word( _port, _value )  i386_inport_word( _port, _value )
243#define inport_long( _port, _value )  i386_inport_long( _port, _value )
244
245
246#ifdef __cplusplus
247}
248#endif
249
250#endif /* !ASM */
251
252#endif
Note: See TracBrowser for help on using the repository browser.