1 #include <linux/linkage.h>
2 #include <linux/init.h>
3 #include <asm/segment.h>
4 #include <asm/page_types.h>
8 * The following code and data reboots the machine by switching to real
9 * mode and jumping to the BIOS reset entry point, as if the CPU has
10 * really been reset. The previous version asked the keyboard
11 * controller to pulse the CPU reset line, which is more thorough, but
12 * doesn't work with at least one type of 486 motherboard. It is easy
13 * to stop this code working; hence the copious comments.
15 * This code is called with the restart type (0 = BIOS, 1 = APM) in %eax.
17 .section ".text32", "ax"
19 .globl machine_real_restart_asm
22 machine_real_restart_asm:
23 /* Set up the IDT for real mode. */
24 lidtl pa_machine_real_restart_idt
27 * Set up a GDT from which we can load segment descriptors for real
28 * mode. The GDT is not used in real mode; it is just needed here to
29 * prepare the descriptors.
31 lgdtl pa_machine_real_restart_gdt
34 * Load the data segment registers with 16-bit compatible values
45 * This is 16-bit protected mode code to disable paging and the cache,
46 * switch to real mode and jump to the BIOS reset code.
48 * The instruction that switches to real mode by writing to CR0 must be
49 * followed immediately by a far jump instruction, which set CS to a
50 * valid value for real mode, and flushes the prefetch queue to avoid
51 * running instructions that have already been decoded in protected
54 * Clears all the flags except ET, especially PG (paging), PE
55 * (protected-mode enable) and TS (task switch for coprocessor state
56 * save). Flushes the TLB after paging has been disabled. Sets CD and
57 * NW, to disable the cache on a 486, and invalidates the cache. This
58 * is more like the state of a 486 after reset. I don't know if
59 * something else should be done for other chips.
61 * More could be done here to set up the registers as if a CPU reset had
62 * occurred; hopefully real BIOSs don't assume much. This is not the
63 * actual BIOS entry point, anyway (that is at 0xfffffff0).
65 * Most of this work is probably excessive, but it is what is tested.
71 machine_real_restart_asm16:
75 andl $0x00000011, %edx
80 andl $0x60000000, %edx /* If no cache bits -> no wbinvd */
99 /* This should never return... */
102 ljmpw $0xf000, $0xfff0
104 .section ".rodata", "a"
105 .globl machine_real_restart_idt, machine_real_restart_gdt
108 machine_real_restart_idt:
109 .word 0xffff /* Length - real mode default value */
110 .long 0 /* Base - real mode default value */
113 machine_real_restart_gdt:
115 .word 0xffff /* Length - real mode default value */
116 .long pa_machine_real_restart_gdt
120 * 16-bit code segment pointing to real_mode_seg
123 .word 0xffff /* Limit */
124 .long 0x9b000000 + pa_real_mode_base
128 * 16-bit data segment with the selector value 16 = 0x10 and
129 * base value 0x100; since this is consistent with real mode
130 * semantics we don't have to reload the segments once CR0.PE = 0.
132 .quad GDT_ENTRY(0x0093, 0x100, 0xffff)