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"
21 ENTRY(machine_real_restart_asm)
22 /* Set up the IDT for real mode. */
23 lidtl pa_machine_real_restart_idt
26 * Set up a GDT from which we can load segment descriptors for real
27 * mode. The GDT is not used in real mode; it is just needed here to
28 * prepare the descriptors.
30 lgdtl pa_machine_real_restart_gdt
33 * Load the data segment registers with 16-bit compatible values
44 * This is 16-bit protected mode code to disable paging and the cache,
45 * switch to real mode and jump to the BIOS reset code.
47 * The instruction that switches to real mode by writing to CR0 must be
48 * followed immediately by a far jump instruction, which set CS to a
49 * valid value for real mode, and flushes the prefetch queue to avoid
50 * running instructions that have already been decoded in protected
53 * Clears all the flags except ET, especially PG (paging), PE
54 * (protected-mode enable) and TS (task switch for coprocessor state
55 * save). Flushes the TLB after paging has been disabled. Sets CD and
56 * NW, to disable the cache on a 486, and invalidates the cache. This
57 * is more like the state of a 486 after reset. I don't know if
58 * something else should be done for other chips.
60 * More could be done here to set up the registers as if a CPU reset had
61 * occurred; hopefully real BIOSs don't assume much. This is not the
62 * actual BIOS entry point, anyway (that is at 0xfffffff0).
64 * Most of this work is probably excessive, but it is what is tested.
70 machine_real_restart_asm16:
74 andl $0x00000011, %edx
79 testl $0x60000000, %edx /* If no cache bits -> no wbinvd */
98 /* This should never return... */
101 ljmpw $0xf000, $0xfff0
103 .section ".rodata", "a"
106 GLOBAL(machine_real_restart_idt)
107 .word 0xffff /* Length - real mode default value */
108 .long 0 /* Base - real mode default value */
109 END(machine_real_restart_idt)
112 GLOBAL(machine_real_restart_gdt)
114 .word 0xffff /* Length - real mode default value */
115 .long pa_machine_real_restart_gdt
119 * 16-bit code segment pointing to real_mode_seg
122 .word 0xffff /* Limit */
123 .long 0x9b000000 + pa_real_mode_base
127 * 16-bit data segment with the selector value 16 = 0x10 and
128 * base value 0x100; since this is consistent with real mode
129 * semantics we don't have to reload the segments once CR0.PE = 0.
131 .quad GDT_ENTRY(0x0093, 0x100, 0xffff)
132 END(machine_real_restart_gdt)