1 /* -*- linux-c -*- ------------------------------------------------------- *
3 * Copyright (C) 1991, 1992 Linus Torvalds
4 * Copyright 2007 rPath, Inc. - All Rights Reserved
6 * This file is part of the Linux kernel, and is made available under
7 * the terms of the GNU General Public License version 2.
9 * ----------------------------------------------------------------------- */
12 * Prepare the machine for transition to protected mode.
16 #include <asm/segment.h>
19 * Invoke the realmode switch hook if present; otherwise
20 * disable all interrupts.
22 static void realmode_switch_hook(void)
24 if (boot_params
.hdr
.realmode_swtch
) {
25 asm volatile("lcallw *%0"
26 : : "m" (boot_params
.hdr
.realmode_swtch
)
27 : "eax", "ebx", "ecx", "edx");
30 outb(0x80, 0x70); /* Disable NMI */
36 * Disable all interrupts at the legacy PIC.
38 static void mask_all_interrupts(void)
40 outb(0xff, 0xa1); /* Mask all interrupts on the secondary PIC */
42 outb(0xfb, 0x21); /* Mask all but cascade on the primary PIC */
47 * Reset IGNNE# if asserted in the FPU.
49 static void reset_coprocessor(void)
64 } __attribute__((packed
));
66 static void setup_gdt(void)
68 /* There are machines which are known to not boot with the GDT
69 being 8-byte unaligned. Intel recommends 16 byte alignment. */
70 static const u64 boot_gdt
[] __attribute__((aligned(16))) = {
71 /* CS: code, read/execute, 4 GB, base 0 */
72 [GDT_ENTRY_BOOT_CS
] = GDT_ENTRY(0xc09b, 0, 0xfffff),
73 /* DS: data, read/write, 4 GB, base 0 */
74 [GDT_ENTRY_BOOT_DS
] = GDT_ENTRY(0xc093, 0, 0xfffff),
75 /* TSS: 32-bit tss, 104 bytes, base 4096 */
76 /* We only have a TSS here to keep Intel VT happy;
77 we don't actually use it for anything. */
78 [GDT_ENTRY_BOOT_TSS
] = GDT_ENTRY(0x0089, 4096, 103),
80 /* Xen HVM incorrectly stores a pointer to the gdt_ptr, instead
81 of the gdt_ptr contents. Thus, make it static so it will
82 stay in memory, at least long enough that we switch to the
84 static struct gdt_ptr gdt
;
86 gdt
.len
= sizeof(boot_gdt
)-1;
87 gdt
.ptr
= (u32
)&boot_gdt
+ (ds() << 4);
89 asm volatile("lgdtl %0" : : "m" (gdt
));
95 static void setup_idt(void)
97 static const struct gdt_ptr null_idt
= {0, 0};
98 asm volatile("lidtl %0" : : "m" (null_idt
));
102 * Actual invocation sequence
104 void go_to_protected_mode(void)
106 /* Hook before leaving real mode, also disables interrupts */
107 realmode_switch_hook();
109 /* Enable the A20 gate */
111 puts("A20 gate not responding, unable to boot...\n");
115 /* Reset coprocessor (IGNNE#) */
118 /* Mask all interrupts in the PIC */
119 mask_all_interrupts();
121 /* Actual transition to protected mode... */
124 protected_mode_jump(boot_params
.hdr
.code32_start
,
125 (u32
)&boot_params
+ (ds() << 4));