4 /* Segment selectors as used in our protected-mode GDTs.
6 * Don't change these unless you really know what you're doing.
8 #define PHYSICAL_CS 0x08
9 #define PHYSICAL_DS 0x10
10 #define VIRTUAL_CS 0x18
11 #define VIRTUAL_DS 0x20
23 * Without -DKEEP_IT_REAL, we are in 32-bit protected mode with a
24 * fixed link address but an unknown physical start address. Our GDT
25 * sets up code and data segments with an offset of virt_offset, so
26 * that link-time addresses can still work.
30 /* C-callable function prototypes */
32 extern void relocate_to ( uint32_t new_phys_addr );
34 /* Variables in virtaddr.S */
35 extern unsigned long virt_offset;
38 * Convert between virtual and physical addresses
41 static inline unsigned long virt_to_phys ( volatile const void *virt_addr ) {
42 return ( ( unsigned long ) virt_addr ) + virt_offset;
45 static inline void * phys_to_virt ( unsigned long phys_addr ) {
46 return ( void * ) ( phys_addr - virt_offset );
49 static inline void copy_to_phys ( physaddr_t dest, const void *src,
51 memcpy ( phys_to_virt ( dest ), src, len );
54 static inline void copy_from_phys ( void *dest, physaddr_t src, size_t len ) {
55 memcpy ( dest, phys_to_virt ( src ), len );
58 static inline void copy_phys_to_phys ( physaddr_t dest, physaddr_t src,
60 memcpy ( phys_to_virt ( dest ), phys_to_virt ( src ), len );
63 #else /* KEEP_IT_REAL */
66 * With -DKEEP_IT_REAL, we are in 16-bit real mode with fixed link
67 * addresses and a segmented memory model. We have separate code and
70 * Because we may be called in 16-bit protected mode (damn PXE spec),
71 * we cannot simply assume that physical = segment * 16 + offset.
72 * Instead, we have to look up the physical start address of the
73 * segment in the !PXE structure. We have to assume that
74 * virt_to_phys() is called only on pointers within the data segment,
75 * because nothing passes segment information to us.
77 * We don't implement phys_to_virt at all, because there will be many
78 * addresses that simply cannot be reached via a virtual address when
79 * the virtual address space is limited to 64kB!
82 static inline unsigned long virt_to_phys ( volatile const void *virt_addr ) {
83 /* Cheat: just for now, do the segment*16+offset calculation */
86 __asm__ ( "movw %%ds, %%ax" : "=a" ( ds ) : );
87 return ( 16 * ds + ( ( unsigned long ) virt_addr ) );
90 /* Define it as a deprecated function so that we get compile-time
91 * warnings, rather than just the link-time errors.
93 extern void * phys_to_virt ( unsigned long phys_addr )
94 __attribute__ ((deprecated));
96 #endif /* KEEP_IT_REAL */
100 #endif /* VIRTADDR_H */