1 // SPDX-License-Identifier: GPL-2.0-only
2 /* -*- linux-c -*- ------------------------------------------------------- *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 * Copyright 2007 rPath, Inc. - All Rights Reserved
6 * Copyright 2009 Intel Corporation; author H. Peter Anvin
8 * ----------------------------------------------------------------------- */
11 * Main module for the real-mode kernel code
13 #include <linux/build_bug.h>
18 struct boot_params boot_params __attribute__((aligned(16)));
20 struct port_io_ops pio_ops;
23 char *heap_end = _end; /* Default end of heap = no heap */
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.
31 static void copy_boot_params(void)
37 const struct old_cmdline * const oldcmd =
38 absolute_pointer(OLD_CL_ADDRESS);
40 BUILD_BUG_ON(sizeof(boot_params) != 4096);
41 memcpy(&boot_params.hdr, &hdr, sizeof(hdr));
43 if (!boot_params.hdr.cmd_line_ptr &&
44 oldcmd->cl_magic == OLD_CL_MAGIC) {
45 /* Old-style command line protocol. */
48 /* Figure out if the command line falls in the region
49 of memory that an old kernel would have copied up
51 if (oldcmd->cl_offset < boot_params.hdr.setup_move_size)
56 boot_params.hdr.cmd_line_ptr =
57 (cmdline_seg << 4) + oldcmd->cl_offset;
62 * Query the keyboard lock status as given by the BIOS, and
63 * set the keyboard repeat rate to maximum. Unclear why the latter
64 * is done here; this might be possible to kill off as stale code.
66 static void keyboard_init(void)
68 struct biosregs ireg, oreg;
71 ireg.ah = 0x02; /* Get keyboard status */
72 intcall(0x16, &ireg, &oreg);
73 boot_params.kbd_status = oreg.al;
75 ireg.ax = 0x0305; /* Set keyboard repeat rate */
76 intcall(0x16, &ireg, NULL);
80 * Get Intel SpeedStep (IST) information.
82 static void query_ist(void)
84 struct biosregs ireg, oreg;
86 /* Some older BIOSes apparently crash on this call, so filter
87 it from machines too old to have SpeedStep at all. */
92 ireg.ax = 0xe980; /* IST Support */
93 ireg.edx = 0x47534943; /* Request value */
94 intcall(0x15, &ireg, &oreg);
96 boot_params.ist_info.signature = oreg.eax;
97 boot_params.ist_info.command = oreg.ebx;
98 boot_params.ist_info.event = oreg.ecx;
99 boot_params.ist_info.perf_level = oreg.edx;
103 * Tell the BIOS what CPU mode we intend to run in.
105 static void set_bios_mode(void)
108 struct biosregs ireg;
113 intcall(0x15, &ireg, NULL);
117 static void init_heap(void)
121 if (boot_params.hdr.loadflags & CAN_USE_HEAP) {
122 asm("leal %P1(%%esp),%0"
123 : "=r" (stack_end) : "i" (-STACK_SIZE));
126 ((size_t)boot_params.hdr.heap_end_ptr + 0x200);
127 if (heap_end > stack_end)
128 heap_end = stack_end;
130 /* Boot protocol 2.00 only, no heap available */
131 puts("WARNING: Ancient bootloader, some functionality "
132 "may be limited!\n");
138 init_default_io_ops();
140 /* First, copy the boot header into the "zeropage" */
143 /* Initialize the early-boot console */
145 if (cmdline_find_option_bool("debug"))
146 puts("early console in setup code\n");
148 /* End of heap check */
151 /* Make sure we have all the proper CPU support */
152 if (validate_cpu()) {
153 puts("Unable to boot - please use a kernel appropriate "
158 /* Tell the BIOS what CPU mode we intend to run in. */
161 /* Detect memory layout */
164 /* Set keyboard repeat rate (why?) and query the lock flags */
167 /* Query Intel SpeedStep (IST) information */
170 /* Query APM information */
171 #if defined(CONFIG_APM) || defined(CONFIG_APM_MODULE)
175 /* Query EDD information */
176 #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
180 /* Set the video mode */
183 /* Do the last things and invoke protected mode */
184 go_to_protected_mode();