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.

virtaddr.S 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * Functions to support the virtual addressing method of relocation
  3. * that Etherboot uses.
  4. *
  5. */
  6. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
  7. #include "librm.h"
  8. .arch i386
  9. .text
  10. .code32
  11. /****************************************************************************
  12. * _virt_to_phys (virtual addressing)
  13. *
  14. * Switch from virtual to flat physical addresses. %esp is adjusted
  15. * to a physical value. Segment registers are set to flat physical
  16. * selectors. All other registers are preserved. Flags are
  17. * preserved.
  18. *
  19. * Parameters: none
  20. * Returns: none
  21. ****************************************************************************
  22. */
  23. .globl _virt_to_phys
  24. _virt_to_phys:
  25. /* Preserve registers and flags */
  26. pushfl
  27. pushl %eax
  28. pushl %ebp
  29. /* Change return address to a physical address */
  30. movl virt_offset, %ebp
  31. addl %ebp, 12(%esp)
  32. /* Switch to physical code segment */
  33. cli
  34. pushl $PHYSICAL_CS
  35. leal 1f(%ebp), %eax
  36. pushl %eax
  37. lret
  38. 1:
  39. /* Reload other segment registers and adjust %esp */
  40. movl $PHYSICAL_DS, %eax
  41. movl %eax, %ds
  42. movl %eax, %es
  43. movl %eax, %fs
  44. movl %eax, %gs
  45. movl %eax, %ss
  46. addl %ebp, %esp
  47. /* Restore registers and flags, and return */
  48. popl %ebp
  49. popl %eax
  50. popfl
  51. ret
  52. /****************************************************************************
  53. * _phys_to_virt (flat physical addressing)
  54. *
  55. * Switch from flat physical to virtual addresses. %esp is adjusted
  56. * to a virtual value. Segment registers are set to virtual
  57. * selectors. All other registers are preserved. Flags are
  58. * preserved.
  59. *
  60. * Parameters: none
  61. * Returns: none
  62. ****************************************************************************
  63. */
  64. .globl _phys_to_virt
  65. _phys_to_virt:
  66. /* Preserve registers and flags */
  67. pushfl
  68. pushl %eax
  69. pushl %ebp
  70. /* Switch to virtual code segment */
  71. cli
  72. ljmp $VIRTUAL_CS, $1f
  73. 1:
  74. /* Reload data segment registers */
  75. movl $VIRTUAL_DS, %eax
  76. movl %eax, %ds
  77. movl %eax, %es
  78. movl %eax, %fs
  79. movl %eax, %gs
  80. /* Reload stack segment and adjust %esp */
  81. movl virt_offset, %ebp
  82. movl %eax, %ss
  83. subl %ebp, %esp
  84. /* Change the return address to a virtual address */
  85. subl %ebp, 12(%esp)
  86. /* Restore registers and flags, and return */
  87. popl %ebp
  88. popl %eax
  89. popfl
  90. ret
  91. /****************************************************************************
  92. * _intr_to_virt (virtual code segment, virtual or physical stack segment)
  93. *
  94. * Switch from virtual code segment with either a virtual or physical
  95. * stack segment to using virtual addressing. %esp is adjusted if
  96. * necessary to a virtual value. Segment registers are set to virtual
  97. * selectors. All other registers are preserved. Flags are
  98. * preserved.
  99. *
  100. * Parameters: none
  101. * Returns: none
  102. ****************************************************************************
  103. */
  104. .globl _intr_to_virt
  105. _intr_to_virt:
  106. /* Preserve registers and flags */
  107. pushfl
  108. pushl %eax
  109. pushl %ebp
  110. /* Check whether stack segment is physical or virtual */
  111. movl %ss, %eax
  112. cmpw $VIRTUAL_DS, %ax
  113. movl $VIRTUAL_DS, %eax
  114. /* Reload data segment registers */
  115. movl %eax, %ds
  116. movl %eax, %es
  117. movl %eax, %fs
  118. movl %eax, %gs
  119. /* Reload stack segment and adjust %esp if necessary */
  120. je 1f
  121. movl virt_offset, %ebp
  122. movl %eax, %ss
  123. subl %ebp, %esp
  124. 1:
  125. /* Restore registers and flags, and return */
  126. popl %ebp
  127. popl %eax
  128. popfl
  129. ret