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 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Functions to support the virtual addressing method of relocation
  3. * that Etherboot uses.
  4. *
  5. */
  6. #include "virtaddr.h"
  7. .arch i386
  8. .text
  9. .code32
  10. /****************************************************************************
  11. * _virt_to_phys (virtual addressing)
  12. *
  13. * Switch from virtual to flat physical addresses. %esp is adjusted
  14. * to a physical value. Segment registers are set to flat physical
  15. * selectors. All other registers are preserved. Flags are
  16. * preserved.
  17. *
  18. * Parameters: none
  19. * Returns: none
  20. ****************************************************************************
  21. */
  22. .globl _virt_to_phys
  23. _virt_to_phys:
  24. /* Preserve registers and flags */
  25. pushfl
  26. pushl %eax
  27. pushl %ebp
  28. /* Change return address to a physical address */
  29. movl virt_offset, %ebp
  30. addl %ebp, 12(%esp)
  31. /* Switch to physical code segment */
  32. pushl $PHYSICAL_CS
  33. leal 1f(%ebp), %eax
  34. pushl %eax
  35. lret
  36. 1:
  37. /* Reload other segment registers and adjust %esp */
  38. movl $PHYSICAL_DS, %eax
  39. movl %eax, %ds
  40. movl %eax, %es
  41. movl %eax, %fs
  42. movl %eax, %gs
  43. movl %eax, %ss
  44. addl %ebp, %esp
  45. /* Restore registers and flags, and return */
  46. popl %ebp
  47. popl %eax
  48. popfl
  49. ret
  50. /****************************************************************************
  51. * _phys_to_virt (flat physical addressing)
  52. *
  53. * Switch from flat physical to virtual addresses. %esp is adjusted
  54. * to a virtual value. Segment registers are set to virtual
  55. * selectors. All other registers are preserved. Flags are
  56. * preserved.
  57. *
  58. * Note that this depends on the GDT already being correctly set up
  59. * (e.g. by a call to run_here()).
  60. *
  61. * Parameters: none
  62. * Returns: none
  63. ****************************************************************************
  64. */
  65. .globl _phys_to_virt
  66. _phys_to_virt:
  67. /* Preserve registers and flags */
  68. pushfl
  69. pushl %eax
  70. pushl %ebp
  71. /* Switch to virtual code segment */
  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