Linux 3.5-rc2
[linux-2.6-microblaze.git] / arch / x86 / realmode / rm / reboot_32.S
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 /*
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.
14  *
15  * This code is called with the restart type (0 = BIOS, 1 = APM) in %eax.
16  */
17         .section ".text32", "ax"
18         .code32
19
20         .balign 16
21 ENTRY(machine_real_restart_asm)
22         /* Set up the IDT for real mode. */
23         lidtl   pa_machine_real_restart_idt
24
25         /*
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.
29          */
30         lgdtl   pa_machine_real_restart_gdt
31
32         /*
33          * Load the data segment registers with 16-bit compatible values
34          */
35         movl    $16, %ecx
36         movl    %ecx, %ds
37         movl    %ecx, %es
38         movl    %ecx, %fs
39         movl    %ecx, %gs
40         movl    %ecx, %ss
41         ljmpw   $8, $1f
42
43 /*
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.
46  *
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
51  * mode.
52  *
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.
59  *
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).
63  *
64  * Most of this work is probably excessive, but it is what is tested.
65  */
66         .text
67         .code16
68
69         .balign 16
70 machine_real_restart_asm16:
71 1:
72         xorl    %ecx, %ecx
73         movl    %cr0, %edx
74         andl    $0x00000011, %edx
75         orl     $0x60000000, %edx
76         movl    %edx, %cr0
77         movl    %ecx, %cr3
78         movl    %cr0, %edx
79         testl   $0x60000000, %edx       /* If no cache bits -> no wbinvd */
80         jz      2f
81         wbinvd
82 2:
83         andb    $0x10, %dl
84         movl    %edx, %cr0
85         LJMPW_RM(3f)
86 3:
87         andw    %ax, %ax
88         jz      bios
89
90 apm:
91         movw    $0x1000, %ax
92         movw    %ax, %ss
93         movw    $0xf000, %sp
94         movw    $0x5307, %ax
95         movw    $0x0001, %bx
96         movw    $0x0003, %cx
97         int     $0x15
98         /* This should never return... */
99
100 bios:
101         ljmpw   $0xf000, $0xfff0
102
103         .section ".rodata", "a"
104
105         .balign 16
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)
110
111         .balign 16
112 GLOBAL(machine_real_restart_gdt)
113         /* Self-pointer */
114         .word   0xffff          /* Length - real mode default value */
115         .long   pa_machine_real_restart_gdt
116         .word   0
117
118         /*
119          * 16-bit code segment pointing to real_mode_seg
120          * Selector value 8
121          */
122         .word   0xffff          /* Limit */
123         .long   0x9b000000 + pa_real_mode_base
124         .word   0
125
126         /*
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.
130          */
131         .quad   GDT_ENTRY(0x0093, 0x100, 0xffff)
132 END(machine_real_restart_gdt)