You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #ifndef VIRTADDR_H
  2. #define VIRTADDR_H
  3. /* Segment selectors as used in our protected-mode GDTs.
  4. *
  5. * Don't change these unless you really know what you're doing.
  6. */
  7. #define PHYSICAL_CS 0x08
  8. #define PHYSICAL_DS 0x10
  9. #define VIRTUAL_CS 0x18
  10. #define VIRTUAL_DS 0x20
  11. #define LONG_CS 0x28
  12. #define LONG_DS 0x30
  13. #ifndef ASSEMBLY
  14. #include "stdint.h"
  15. #include "string.h"
  16. #ifndef KEEP_IT_REAL
  17. /*
  18. * Without -DKEEP_IT_REAL, we are in 32-bit protected mode with a
  19. * fixed link address but an unknown physical start address. Our GDT
  20. * sets up code and data segments with an offset of virt_offset, so
  21. * that link-time addresses can still work.
  22. *
  23. */
  24. /* C-callable function prototypes */
  25. extern void relocate_to ( uint32_t new_phys_addr );
  26. /* Variables in virtaddr.S */
  27. extern unsigned long virt_offset;
  28. /*
  29. * Convert between virtual and physical addresses
  30. *
  31. */
  32. static inline unsigned long virt_to_phys ( volatile const void *virt_addr ) {
  33. return ( ( unsigned long ) virt_addr ) + virt_offset;
  34. }
  35. static inline void * phys_to_virt ( unsigned long phys_addr ) {
  36. return ( void * ) ( phys_addr - virt_offset );
  37. }
  38. static inline void copy_to_phys ( physaddr_t dest, const void *src,
  39. size_t len ) {
  40. memcpy ( phys_to_virt ( dest ), src, len );
  41. }
  42. static inline void copy_from_phys ( void *dest, physaddr_t src, size_t len ) {
  43. memcpy ( dest, phys_to_virt ( src ), len );
  44. }
  45. static inline void copy_phys_to_phys ( physaddr_t dest, physaddr_t src,
  46. size_t len ) {
  47. memcpy ( phys_to_virt ( dest ), phys_to_virt ( src ), len );
  48. }
  49. #else /* KEEP_IT_REAL */
  50. /*
  51. * With -DKEEP_IT_REAL, we are in 16-bit real mode with fixed link
  52. * addresses and a segmented memory model. We have separate code and
  53. * data segments.
  54. *
  55. * Because we may be called in 16-bit protected mode (damn PXE spec),
  56. * we cannot simply assume that physical = segment * 16 + offset.
  57. * Instead, we have to look up the physical start address of the
  58. * segment in the !PXE structure. We have to assume that
  59. * virt_to_phys() is called only on pointers within the data segment,
  60. * because nothing passes segment information to us.
  61. *
  62. * We don't implement phys_to_virt at all, because there will be many
  63. * addresses that simply cannot be reached via a virtual address when
  64. * the virtual address space is limited to 64kB!
  65. */
  66. static inline unsigned long virt_to_phys ( volatile const void *virt_addr ) {
  67. /* Cheat: just for now, do the segment*16+offset calculation */
  68. uint16_t ds;
  69. __asm__ ( "movw %%ds, %%ax" : "=a" ( ds ) : );
  70. return ( 16 * ds + ( ( unsigned long ) virt_addr ) );
  71. }
  72. /* Define it as a deprecated function so that we get compile-time
  73. * warnings, rather than just the link-time errors.
  74. */
  75. extern void * phys_to_virt ( unsigned long phys_addr )
  76. __attribute__ ((deprecated));
  77. #endif /* KEEP_IT_REAL */
  78. #endif /* ASSEMBLY */
  79. #endif /* VIRTADDR_H */