Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

setup.S 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /****************************************************************************
  2. * This file provides the setup() and setup16() functions. The
  3. * purpose of these functions is to set up the internal environment so
  4. * that C code can execute. This includes setting up the internal
  5. * stack and (where applicable) setting up a GDT for virtual
  6. * addressing.
  7. *
  8. * These functions are designed to be called by the prefix.
  9. *
  10. * The same basic assembly code is used to compile both setup()
  11. * and setup16().
  12. ****************************************************************************
  13. */
  14. .text
  15. .arch i386
  16. #ifdef CODE16
  17. /****************************************************************************
  18. * setup16 (real-mode far call)
  19. *
  20. * This function can be called by a 16-bit prefix in order to set up
  21. * the internal (either 16-bit or 32-bit) environment.
  22. *
  23. * Parameters: none
  24. *
  25. * %cs:0000, %ds:0000 and %es:0000 must point to the start of the
  26. * (decompressed) runtime image.
  27. *
  28. * If KEEP_IT_REAL is defined, then %ds:0000 may instead point to the
  29. * start of the (decompressed) data segment portion of the runtime
  30. * image. If %ds==%cs, then it will be assumed that the data segment
  31. * follows immediately after the code segment.
  32. ****************************************************************************
  33. */
  34. #ifdef KEEP_IT_REAL
  35. #define ENTER_FROM_EXTERNAL call ext_to_kir
  36. #define RETURN_TO_EXTERNAL call kir_to_ext
  37. #define ENTRY_POINT kir_call
  38. #else /* KEEP_IT_REAL */
  39. #define ENTER_FROM_EXTERNAL \
  40. pushw %cs ; \
  41. call real_to_prot ; \
  42. .code32
  43. #define RETURN_TO_EXTERNAL \
  44. call prot_to_real ; \
  45. .code16
  46. #define ENTRY_POINT _prot_call /* _prot_call = OFFSET ( prot_call ) in librm */
  47. #endif /* KEEP_IT_REAL */
  48. #define ENTRY_POINT_REGISTER di
  49. .section ".text16"
  50. .code16
  51. .globl setup16
  52. setup16:
  53. #else /* CODE16 */
  54. /****************************************************************************
  55. * setup (32-bit protected-mode near call)
  56. *
  57. * This function can be called by a 32-bit prefix in order to set up
  58. * the internal 32-bit environment.
  59. *
  60. * Parameters: none
  61. ****************************************************************************
  62. */
  63. #define ENTER_FROM_EXTERNAL call ext_to_int
  64. #define RETURN_TO_EXTERNAL call int_to_ext
  65. #define ENTRY_POINT int_call
  66. #define ENTRY_POINT_REGISTER edi
  67. .section ".text"
  68. .code32
  69. .globl setup
  70. setup:
  71. #endif /* CODE16 */
  72. /* Preserve flags (including interrupt status) */
  73. pushfl
  74. /* Switch to (uninitialised) internal environment. This will
  75. * preserve the external environment for when we call
  76. * RETURN_TO_EXTERNAL.
  77. */
  78. ENTER_FROM_EXTERNAL
  79. /* NOTE: We may have only four bytes of stack at this point */
  80. #if defined(CODE16) && defined(KEEP_IT_REAL)
  81. /* If %ds == %cs, then the data segment is located immediately
  82. * after the code segment.
  83. */
  84. pushw %ax
  85. pushw %bx
  86. movw %cs, %ax
  87. movw %ds, %bx
  88. cmpw %ax, %bx
  89. jne 1f
  90. addw $_text_load_size_pgh, %ax
  91. movw %ax, %ds
  92. 1: popw %bx
  93. popw %ax
  94. /* Switch to internal stack */
  95. pushw %ds
  96. popw %ss
  97. movl $_estack, %esp
  98. #else /* CODE16 && KEEP_IT_REAL */
  99. /* Work out where we're running */
  100. call 1f
  101. 1: popl %ebp
  102. /* Switch to internal pmode stack */
  103. leal (_estack-1b)(%ebp), %esp
  104. /* Set up GDT for virtual addressing */
  105. call run_here
  106. #endif /* CODE16 && KEEP_IT_REAL */
  107. /* Switch back to external environment. This will preserve
  108. * the internal environment ready for the next call.
  109. */
  110. RETURN_TO_EXTERNAL
  111. /* Pass pointer to entry-point function back to prefix. %es
  112. * may, by now, have been destroyed, so we re-initialise it
  113. * from %cs.
  114. */
  115. pushw %cs
  116. popw %es
  117. mov $ENTRY_POINT, %ENTRY_POINT_REGISTER
  118. /* Restore flags (including interrupt status) */
  119. popfl
  120. lret
  121. /****************************************************************************
  122. * Internal stack
  123. ****************************************************************************
  124. */
  125. .section ".stack"
  126. .align 8
  127. _stack:
  128. .space 4096
  129. _estack: