Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

virtaddr.S 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Functions to support the virtual addressing method of relocation
  3. * that Etherboot uses.
  4. *
  5. */
  6. FILE_LICENCE ( GPL2_OR_LATER )
  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. pushl $PHYSICAL_CS
  34. leal 1f(%ebp), %eax
  35. pushl %eax
  36. lret
  37. 1:
  38. /* Reload other segment registers and adjust %esp */
  39. movl $PHYSICAL_DS, %eax
  40. movl %eax, %ds
  41. movl %eax, %es
  42. movl %eax, %fs
  43. movl %eax, %gs
  44. movl %eax, %ss
  45. addl %ebp, %esp
  46. /* Restore registers and flags, and return */
  47. popl %ebp
  48. popl %eax
  49. popfl
  50. ret
  51. /****************************************************************************
  52. * _phys_to_virt (flat physical addressing)
  53. *
  54. * Switch from flat physical to virtual addresses. %esp is adjusted
  55. * to a virtual value. Segment registers are set to virtual
  56. * selectors. All other registers are preserved. Flags are
  57. * preserved.
  58. *
  59. * Note that this depends on the GDT already being correctly set up
  60. * (e.g. by a call to run_here()).
  61. *
  62. * Parameters: none
  63. * Returns: none
  64. ****************************************************************************
  65. */
  66. .globl _phys_to_virt
  67. _phys_to_virt:
  68. /* Preserve registers and flags */
  69. pushfl
  70. pushl %eax
  71. pushl %ebp
  72. /* Switch to virtual code segment */
  73. ljmp $VIRTUAL_CS, $1f
  74. 1:
  75. /* Reload data segment registers */
  76. movl $VIRTUAL_DS, %eax
  77. movl %eax, %ds
  78. movl %eax, %es
  79. movl %eax, %fs
  80. movl %eax, %gs
  81. /* Reload stack segment and adjust %esp */
  82. movl virt_offset, %ebp
  83. movl %eax, %ss
  84. subl %ebp, %esp
  85. /* Change the return address to a virtual address */
  86. subl %ebp, 12(%esp)
  87. /* Restore registers and flags, and return */
  88. popl %ebp
  89. popl %eax
  90. popfl
  91. ret