reboot_32.S 3.6 KB

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