summaryrefslogtreecommitdiffstats
path: root/arch/x86/boot/prepare_uboot.c
blob: 9cac594a4633980a7b1b76cbbe6ff8a495239bb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// SPDX-License-Identifier: GPL-2.0-only
// SPDX-FileCopyrightText: 1991,1992 Linus Torvalds
// SPDX-FileCopyrightText: 2007 rPath, Inc.

/*
 * Prepare the machine for transition to protected mode.
 */
#include <asm/segment.h>
#include <asm/modes.h>
#include <io.h>
#include "boot.h"

/* be aware of: */
THIS_IS_REALMODE_CODE

/*
 * While we are in flat mode, we can't handle interrupts. But we can't
 * switch them off for ever in the PIC, because we need them again while
 * entering real mode code again and again....
 */
static void __bootcode realmode_switch_hook(void)
{
	asm volatile("cli");
	outb(0x80, 0x70); /* Disable NMI */
	io_delay();
}

/*
 * Reset IGNNE# if asserted in the FPU.
 */
static void __bootcode reset_coprocessor(void)
{
	outb(0, 0xf0);
	io_delay();
	outb(0, 0xf1);
	io_delay();
}

/**
 * Setup and register the global descriptor table (GDT)
 *
 * @note This is for the first time only
 */
static void __bootcode setup_gdt(void)
{
	/* Xen HVM incorrectly stores a pointer to the gdt_ptr, instead
	   of the gdt_ptr contents.  Thus, make it static so it will
	   stay in memory, at least long enough that we switch to the
	   proper kernel GDT. */
	static struct gdt_ptr __bootdata gdt_ptr;

	gdt_ptr.len = gdt_size - 1;
	gdt_ptr.ptr = (uint32_t)&gdt + (ds() << 4);

	asm volatile("lgdtl %0" : : "m" (gdt_ptr));
}

static char a20_message[] __bootdata = "A20 gate not responding, unable to boot...\n";

/*
 * Actual invocation sequence
 */
void __bootcode start_pre_uboot(void)
{
	/* Hook before leaving real mode, also disables interrupts */
	realmode_switch_hook();

	/* Enable the A20 gate */
	if (enable_a20()) {
		boot_puts(a20_message);
		die();
	}

	/* Reset coprocessor (IGNNE#) */
	reset_coprocessor();

	setup_gdt();
	/* Actual transition to protected mode... */
	protected_mode_jump();
}