Merge tag 'sched_ext-for-6.12-rc1-fixes-1' of git://git.kernel.org/pub/scm/linux...
[linux-2.6-block.git] / arch / x86 / boot / main.c
CommitLineData
97873a3d 1// SPDX-License-Identifier: GPL-2.0-only
62607313
PA
2/* -*- linux-c -*- ------------------------------------------------------- *
3 *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 * Copyright 2007 rPath, Inc. - All Rights Reserved
df7699c5 6 * Copyright 2009 Intel Corporation; author H. Peter Anvin
62607313 7 *
62607313
PA
8 * ----------------------------------------------------------------------- */
9
10/*
62607313
PA
11 * Main module for the real-mode kernel code
12 */
d5a1badd 13#include <linux/build_bug.h>
62607313
PA
14
15#include "boot.h"
c041b5ad 16#include "string.h"
62607313
PA
17
18struct boot_params boot_params __attribute__((aligned(16)));
19
eb4ea1ae
KS
20struct port_io_ops pio_ops;
21
62607313
PA
22char *HEAP = _end;
23char *heap_end = _end; /* Default end of heap = no heap */
24
25/*
26 * Copy the header into the boot parameter block. Since this
27 * screws up the old-style command line protocol, adjust by
28 * filling in the new-style command line pointer instead.
29 */
62607313
PA
30static void copy_boot_params(void)
31{
32 struct old_cmdline {
33 u16 cl_magic;
34 u16 cl_offset;
35 };
52cccc64 36 const struct old_cmdline * const oldcmd = absolute_pointer(OLD_CL_ADDRESS);
62607313 37
0e96f31e
JB
38 BUILD_BUG_ON(sizeof(boot_params) != 4096);
39 memcpy(&boot_params.hdr, &hdr, sizeof(hdr));
62607313 40
52cccc64
IM
41 if (!boot_params.hdr.cmd_line_ptr && oldcmd->cl_magic == OLD_CL_MAGIC) {
42 /* Old-style command line protocol */
62607313
PA
43 u16 cmdline_seg;
44
52cccc64
IM
45 /*
46 * Figure out if the command line falls in the region
47 * of memory that an old kernel would have copied up
48 * to 0x90000...
49 */
62607313
PA
50 if (oldcmd->cl_offset < boot_params.hdr.setup_move_size)
51 cmdline_seg = ds();
52 else
53 cmdline_seg = 0x9000;
54
52cccc64 55 boot_params.hdr.cmd_line_ptr = (cmdline_seg << 4) + oldcmd->cl_offset;
62607313
PA
56 }
57}
58
59/*
b2d0b7a0
JC
60 * Query the keyboard lock status as given by the BIOS, and
61 * set the keyboard repeat rate to maximum. Unclear why the latter
62607313
PA
62 * is done here; this might be possible to kill off as stale code.
63 */
b2d0b7a0 64static void keyboard_init(void)
62607313 65{
b2d0b7a0 66 struct biosregs ireg, oreg;
52cccc64 67
df7699c5 68 initregs(&ireg);
b2d0b7a0
JC
69
70 ireg.ah = 0x02; /* Get keyboard status */
71 intcall(0x16, &ireg, &oreg);
72 boot_params.kbd_status = oreg.al;
73
74 ireg.ax = 0x0305; /* Set keyboard repeat rate */
df7699c5 75 intcall(0x16, &ireg, NULL);
62607313
PA
76}
77
78/*
238b706d 79 * Get Intel SpeedStep (IST) information.
62607313 80 */
238b706d 81static void query_ist(void)
62607313 82{
df7699c5
PA
83 struct biosregs ireg, oreg;
84
52cccc64
IM
85 /*
86 * Some older BIOSes apparently crash on this call, so filter
87 * it from machines too old to have SpeedStep at all.
88 */
7b27718b
JR
89 if (cpu.level < 6)
90 return;
91
df7699c5
PA
92 initregs(&ireg);
93 ireg.ax = 0xe980; /* IST Support */
94 ireg.edx = 0x47534943; /* Request value */
95 intcall(0x15, &ireg, &oreg);
96
97 boot_params.ist_info.signature = oreg.eax;
98 boot_params.ist_info.command = oreg.ebx;
99 boot_params.ist_info.event = oreg.ecx;
100 boot_params.ist_info.perf_level = oreg.edx;
62607313
PA
101}
102
103/*
104 * Tell the BIOS what CPU mode we intend to run in.
105 */
106static void set_bios_mode(void)
107{
108#ifdef CONFIG_X86_64
df7699c5 109 struct biosregs ireg;
62607313 110
df7699c5
PA
111 initregs(&ireg);
112 ireg.ax = 0xec00;
113 ireg.bx = 2;
114 intcall(0x15, &ireg, NULL);
62607313
PA
115#endif
116}
117
acd644bb 118static void init_heap(void)
62607313 119{
acd644bb 120 char *stack_end;
62607313 121
62607313 122 if (boot_params.hdr.loadflags & CAN_USE_HEAP) {
52cccc64
IM
123 stack_end = (char *) (current_stack_pointer - STACK_SIZE);
124 heap_end = (char *) ((size_t)boot_params.hdr.heap_end_ptr + 0x200);
acd644bb
PA
125 if (heap_end > stack_end)
126 heap_end = stack_end;
62607313
PA
127 } else {
128 /* Boot protocol 2.00 only, no heap available */
52cccc64 129 puts("WARNING: Ancient bootloader, some functionality may be limited!\n");
62607313 130 }
acd644bb
PA
131}
132
133void main(void)
134{
eb4ea1ae
KS
135 init_default_io_ops();
136
acd644bb
PA
137 /* First, copy the boot header into the "zeropage" */
138 copy_boot_params();
139
fa97bdf9
PE
140 /* Initialize the early-boot console */
141 console_init();
8fee13a4
YL
142 if (cmdline_find_option_bool("debug"))
143 puts("early console in setup code\n");
fa97bdf9 144
acd644bb
PA
145 /* End of heap check */
146 init_heap();
62607313
PA
147
148 /* Make sure we have all the proper CPU support */
149 if (validate_cpu()) {
52cccc64 150 puts("Unable to boot - please use a kernel appropriate for your CPU.\n");
62607313
PA
151 die();
152 }
153
52cccc64 154 /* Tell the BIOS what CPU mode we intend to run in */
62607313
PA
155 set_bios_mode();
156
157 /* Detect memory layout */
158 detect_memory();
159
b2d0b7a0
JC
160 /* Set keyboard repeat rate (why?) and query the lock flags */
161 keyboard_init();
62607313 162
238b706d
PA
163 /* Query Intel SpeedStep (IST) information */
164 query_ist();
62607313
PA
165
166 /* Query APM information */
167#if defined(CONFIG_APM) || defined(CONFIG_APM_MODULE)
168 query_apm_bios();
169#endif
170
171 /* Query EDD information */
172#if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
173 query_edd();
174#endif
1a8514e0
PA
175
176 /* Set the video mode */
177 set_video();
178
62607313
PA
179 /* Do the last things and invoke protected mode */
180 go_to_protected_mode();
181}