1 #include <linux/linkage.h>
2 #include <asm/segment.h>
3 #include <asm/page_types.h>
4 #include <asm/processor-flags.h>
5 #include <asm/msr-index.h>
9 * The following code and data reboots the machine by switching to real
10 * mode and jumping to the BIOS reset entry point, as if the CPU has
11 * really been reset. The previous version asked the keyboard
12 * controller to pulse the CPU reset line, which is more thorough, but
13 * doesn't work with at least one type of 486 motherboard. It is easy
14 * to stop this code working; hence the copious comments.
16 * This code is called with the restart type (0 = BIOS, 1 = APM) in
17 * the primary argument register (%eax for 32 bit, %edi for 64 bit).
19 .section ".text32", "ax"
21 ENTRY(machine_real_restart_asm)
24 /* Switch to trampoline GDT as it is guaranteed < 4 GiB */
25 movl $__KERNEL_DS, %eax
29 /* Disable paging to drop us out of long mode */
31 andl $~X86_CR0_PG, %eax
33 ljmpl $__KERNEL32_CS, $pa_machine_real_restart_paging_off
35 GLOBAL(machine_real_restart_paging_off)
43 #endif /* CONFIG_X86_64 */
45 /* Set up the IDT for real mode. */
46 lidtl pa_machine_real_restart_idt
49 * Set up a GDT from which we can load segment descriptors for real
50 * mode. The GDT is not used in real mode; it is just needed here to
51 * prepare the descriptors.
53 lgdtl pa_machine_real_restart_gdt
56 * Load the data segment registers with 16-bit compatible values
67 * This is 16-bit protected mode code to disable paging and the cache,
68 * switch to real mode and jump to the BIOS reset code.
70 * The instruction that switches to real mode by writing to CR0 must be
71 * followed immediately by a far jump instruction, which set CS to a
72 * valid value for real mode, and flushes the prefetch queue to avoid
73 * running instructions that have already been decoded in protected
76 * Clears all the flags except ET, especially PG (paging), PE
77 * (protected-mode enable) and TS (task switch for coprocessor state
78 * save). Flushes the TLB after paging has been disabled. Sets CD and
79 * NW, to disable the cache on a 486, and invalidates the cache. This
80 * is more like the state of a 486 after reset. I don't know if
81 * something else should be done for other chips.
83 * More could be done here to set up the registers as if a CPU reset had
84 * occurred; hopefully real BIOSs don't assume much. This is not the
85 * actual BIOS entry point, anyway (that is at 0xfffffff0).
87 * Most of this work is probably excessive, but it is what is tested.
93 machine_real_restart_asm16:
97 andl $0x00000011, %edx
102 testl $0x60000000, %edx /* If no cache bits -> no wbinvd */
121 /* This should never return... */
124 ljmpw $0xf000, $0xfff0
126 .section ".rodata", "a"
129 GLOBAL(machine_real_restart_idt)
130 .word 0xffff /* Length - real mode default value */
131 .long 0 /* Base - real mode default value */
132 END(machine_real_restart_idt)
135 GLOBAL(machine_real_restart_gdt)
137 .word 0xffff /* Length - real mode default value */
138 .long pa_machine_real_restart_gdt
142 * 16-bit code segment pointing to real_mode_seg
145 .word 0xffff /* Limit */
146 .long 0x9b000000 + pa_real_mode_base
150 * 16-bit data segment with the selector value 16 = 0x10 and
151 * base value 0x100; since this is consistent with real mode
152 * semantics we don't have to reload the segments once CR0.PE = 0.
154 .quad GDT_ENTRY(0x0093, 0x100, 0xffff)
155 END(machine_real_restart_gdt)