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
17 struct boot_params boot_params __attribute__((aligned(16)));
20 char *heap_end = _end; /* Default end of heap = no heap */
23 * Copy the header into the boot parameter block. Since this
24 * screws up the old-style command line protocol, adjust by
25 * filling in the new-style command line pointer instead.
28 static void copy_boot_params(void)
34 const struct old_cmdline * const oldcmd =
35 (const struct old_cmdline *)OLD_CL_ADDRESS;
37 BUILD_BUG_ON(sizeof(boot_params) != 4096);
38 memcpy(&boot_params.hdr, &hdr, sizeof(hdr));
40 if (!boot_params.hdr.cmd_line_ptr &&
41 oldcmd->cl_magic == OLD_CL_MAGIC) {
42 /* Old-style command line protocol. */
45 /* Figure out if the command line falls in the region
46 of memory that an old kernel would have copied up
48 if (oldcmd->cl_offset < boot_params.hdr.setup_move_size)
53 boot_params.hdr.cmd_line_ptr =
54 (cmdline_seg << 4) + oldcmd->cl_offset;
59 * Query the keyboard lock status as given by the BIOS, and
60 * set the keyboard repeat rate to maximum. Unclear why the latter
61 * is done here; this might be possible to kill off as stale code.
63 static void keyboard_init(void)
65 struct biosregs ireg, oreg;
68 ireg.ah = 0x02; /* Get keyboard status */
69 intcall(0x16, &ireg, &oreg);
70 boot_params.kbd_status = oreg.al;
72 ireg.ax = 0x0305; /* Set keyboard repeat rate */
73 intcall(0x16, &ireg, NULL);
77 * Get Intel SpeedStep (IST) information.
79 static void query_ist(void)
81 struct biosregs ireg, oreg;
83 /* Some older BIOSes apparently crash on this call, so filter
84 it from machines too old to have SpeedStep at all. */
89 ireg.ax = 0xe980; /* IST Support */
90 ireg.edx = 0x47534943; /* Request value */
91 intcall(0x15, &ireg, &oreg);
93 boot_params.ist_info.signature = oreg.eax;
94 boot_params.ist_info.command = oreg.ebx;
95 boot_params.ist_info.event = oreg.ecx;
96 boot_params.ist_info.perf_level = oreg.edx;
100 * Tell the BIOS what CPU mode we intend to run in.
102 static void set_bios_mode(void)
105 struct biosregs ireg;
110 intcall(0x15, &ireg, NULL);
114 static void init_heap(void)
118 if (boot_params.hdr.loadflags & CAN_USE_HEAP) {
119 asm("leal %P1(%%esp),%0"
120 : "=r" (stack_end) : "i" (-STACK_SIZE));
123 ((size_t)boot_params.hdr.heap_end_ptr + 0x200);
124 if (heap_end > stack_end)
125 heap_end = stack_end;
127 /* Boot protocol 2.00 only, no heap available */
128 puts("WARNING: Ancient bootloader, some functionality "
129 "may be limited!\n");
135 /* First, copy the boot header into the "zeropage" */
138 /* Initialize the early-boot console */
140 if (cmdline_find_option_bool("debug"))
141 puts("early console in setup code\n");
143 /* End of heap check */
146 /* Make sure we have all the proper CPU support */
147 if (validate_cpu()) {
148 puts("Unable to boot - please use a kernel appropriate "
153 /* Tell the BIOS what CPU mode we intend to run in. */
156 /* Detect memory layout */
159 /* Set keyboard repeat rate (why?) and query the lock flags */
162 /* Query Intel SpeedStep (IST) information */
165 /* Query APM information */
166 #if defined(CONFIG_APM) || defined(CONFIG_APM_MODULE)
170 /* Query EDD information */
171 #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
175 /* Set the video mode */
178 /* Do the last things and invoke protected mode */
179 go_to_protected_mode();