reboot_32.S 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #include <linux/linkage.h>
  2. #include <linux/init.h>
  3. #include <asm/segment.h>
  4. #include <asm/page_types.h>
  5. #include "realmode.h"
  6. /*
  7. * The following code and data reboots the machine by switching to real
  8. * mode and jumping to the BIOS reset entry point, as if the CPU has
  9. * really been reset. The previous version asked the keyboard
  10. * controller to pulse the CPU reset line, which is more thorough, but
  11. * doesn't work with at least one type of 486 motherboard. It is easy
  12. * to stop this code working; hence the copious comments.
  13. *
  14. * This code is called with the restart type (0 = BIOS, 1 = APM) in %eax.
  15. */
  16. .section ".text32", "ax"
  17. .code32
  18. .balign 16
  19. ENTRY(machine_real_restart_asm)
  20. /* Set up the IDT for real mode. */
  21. lidtl pa_machine_real_restart_idt
  22. /*
  23. * Set up a GDT from which we can load segment descriptors for real
  24. * mode. The GDT is not used in real mode; it is just needed here to
  25. * prepare the descriptors.
  26. */
  27. lgdtl pa_machine_real_restart_gdt
  28. /*
  29. * Load the data segment registers with 16-bit compatible values
  30. */
  31. movl $16, %ecx
  32. movl %ecx, %ds
  33. movl %ecx, %es
  34. movl %ecx, %fs
  35. movl %ecx, %gs
  36. movl %ecx, %ss
  37. ljmpw $8, $1f
  38. /*
  39. * This is 16-bit protected mode code to disable paging and the cache,
  40. * switch to real mode and jump to the BIOS reset code.
  41. *
  42. * The instruction that switches to real mode by writing to CR0 must be
  43. * followed immediately by a far jump instruction, which set CS to a
  44. * valid value for real mode, and flushes the prefetch queue to avoid
  45. * running instructions that have already been decoded in protected
  46. * mode.
  47. *
  48. * Clears all the flags except ET, especially PG (paging), PE
  49. * (protected-mode enable) and TS (task switch for coprocessor state
  50. * save). Flushes the TLB after paging has been disabled. Sets CD and
  51. * NW, to disable the cache on a 486, and invalidates the cache. This
  52. * is more like the state of a 486 after reset. I don't know if
  53. * something else should be done for other chips.
  54. *
  55. * More could be done here to set up the registers as if a CPU reset had
  56. * occurred; hopefully real BIOSs don't assume much. This is not the
  57. * actual BIOS entry point, anyway (that is at 0xfffffff0).
  58. *
  59. * Most of this work is probably excessive, but it is what is tested.
  60. */
  61. .text
  62. .code16
  63. .balign 16
  64. machine_real_restart_asm16:
  65. 1:
  66. xorl %ecx, %ecx
  67. movl %cr0, %edx
  68. andl $0x00000011, %edx
  69. orl $0x60000000, %edx
  70. movl %edx, %cr0
  71. movl %ecx, %cr3
  72. movl %cr0, %edx
  73. testl $0x60000000, %edx /* If no cache bits -> no wbinvd */
  74. jz 2f
  75. wbinvd
  76. 2:
  77. andb $0x10, %dl
  78. movl %edx, %cr0
  79. LJMPW_RM(3f)
  80. 3:
  81. andw %ax, %ax
  82. jz bios
  83. apm:
  84. movw $0x1000, %ax
  85. movw %ax, %ss
  86. movw $0xf000, %sp
  87. movw $0x5307, %ax
  88. movw $0x0001, %bx
  89. movw $0x0003, %cx
  90. int $0x15
  91. /* This should never return... */
  92. bios:
  93. ljmpw $0xf000, $0xfff0
  94. .section ".rodata", "a"
  95. .balign 16
  96. GLOBAL(machine_real_restart_idt)
  97. .word 0xffff /* Length - real mode default value */
  98. .long 0 /* Base - real mode default value */
  99. END(machine_real_restart_idt)
  100. .balign 16
  101. GLOBAL(machine_real_restart_gdt)
  102. /* Self-pointer */
  103. .word 0xffff /* Length - real mode default value */
  104. .long pa_machine_real_restart_gdt
  105. .word 0
  106. /*
  107. * 16-bit code segment pointing to real_mode_seg
  108. * Selector value 8
  109. */
  110. .word 0xffff /* Limit */
  111. .long 0x9b000000 + pa_real_mode_base
  112. .word 0
  113. /*
  114. * 16-bit data segment with the selector value 16 = 0x10 and
  115. * base value 0x100; since this is consistent with real mode
  116. * semantics we don't have to reload the segments once CR0.PE = 0.
  117. */
  118. .quad GDT_ENTRY(0x0093, 0x100, 0xffff)
  119. END(machine_real_restart_gdt)