1 /* -*- linux-c -*- ------------------------------------------------------- *
3 * Copyright (C) 1991, 1992 Linus Torvalds
4 * Copyright 2007 rPath, Inc. - All Rights Reserved
5 * Copyright 2009 Intel Corporation; author H. Peter Anvin
7 * This file is part of the Linux kernel, and is made available under
8 * the terms of the GNU General Public License version 2.
10 * ----------------------------------------------------------------------- */
13 * Main module for the real-mode kernel code
19 struct boot_params boot_params __attribute__((aligned(16)));
22 char *heap_end = _end; /* Default end of heap = no heap */
25 * Copy the header into the boot parameter block. Since this
26 * screws up the old-style command line protocol, adjust by
27 * filling in the new-style command line pointer instead.
30 static void copy_boot_params(void)
36 const struct old_cmdline * const oldcmd =
37 (const struct old_cmdline *)OLD_CL_ADDRESS;
39 BUILD_BUG_ON(sizeof boot_params != 4096);
40 memcpy(&boot_params.hdr, &hdr, sizeof hdr);
42 if (!boot_params.hdr.cmd_line_ptr &&
43 oldcmd->cl_magic == OLD_CL_MAGIC) {
44 /* Old-style command line protocol. */
47 /* Figure out if the command line falls in the region
48 of memory that an old kernel would have copied up
50 if (oldcmd->cl_offset < boot_params.hdr.setup_move_size)
55 boot_params.hdr.cmd_line_ptr =
56 (cmdline_seg << 4) + oldcmd->cl_offset;
61 * Query the keyboard lock status as given by the BIOS, and
62 * set the keyboard repeat rate to maximum. Unclear why the latter
63 * is done here; this might be possible to kill off as stale code.
65 static void keyboard_init(void)
67 struct biosregs ireg, oreg;
70 ireg.ah = 0x02; /* Get keyboard status */
71 intcall(0x16, &ireg, &oreg);
72 boot_params.kbd_status = oreg.al;
74 ireg.ax = 0x0305; /* Set keyboard repeat rate */
75 intcall(0x16, &ireg, NULL);
79 * Get Intel SpeedStep (IST) information.
81 static void query_ist(void)
83 struct biosregs ireg, oreg;
85 /* Some older BIOSes apparently crash on this call, so filter
86 it from machines too old to have SpeedStep at all. */
91 ireg.ax = 0xe980; /* IST Support */
92 ireg.edx = 0x47534943; /* Request value */
93 intcall(0x15, &ireg, &oreg);
95 boot_params.ist_info.signature = oreg.eax;
96 boot_params.ist_info.command = oreg.ebx;
97 boot_params.ist_info.event = oreg.ecx;
98 boot_params.ist_info.perf_level = oreg.edx;
102 * Tell the BIOS what CPU mode we intend to run in.
104 static void set_bios_mode(void)
107 struct biosregs ireg;
112 intcall(0x15, &ireg, NULL);
116 static void init_heap(void)
120 if (boot_params.hdr.loadflags & CAN_USE_HEAP) {
121 asm("leal %P1(%%esp),%0"
122 : "=r" (stack_end) : "i" (-STACK_SIZE));
125 ((size_t)boot_params.hdr.heap_end_ptr + 0x200);
126 if (heap_end > stack_end)
127 heap_end = stack_end;
129 /* Boot protocol 2.00 only, no heap available */
130 puts("WARNING: Ancient bootloader, some functionality "
131 "may be limited!\n");
137 /* First, copy the boot header into the "zeropage" */
140 /* Initialize the early-boot console */
142 if (cmdline_find_option_bool("debug"))
143 puts("early console in setup code\n");
145 /* End of heap check */
148 /* Make sure we have all the proper CPU support */
149 if (validate_cpu()) {
150 puts("Unable to boot - please use a kernel appropriate "
155 /* Tell the BIOS what CPU mode we intend to run in. */
158 /* Detect memory layout */
161 /* Set keyboard repeat rate (why?) and query the lock flags */
164 /* Query Intel SpeedStep (IST) information */
167 /* Query APM information */
168 #if defined(CONFIG_APM) || defined(CONFIG_APM_MODULE)
172 /* Query EDD information */
173 #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
177 /* Set the video mode */
180 /* Do the last things and invoke protected mode */
181 go_to_protected_mode();