blob: 77569a4a3be114aaca948d04b060ebd28c80c1a9 [file] [log] [blame]
H. Peter Anvin62607312007-07-11 12:18:54 -07001/* -*- linux-c -*- ------------------------------------------------------- *
2 *
3 * Copyright (C) 1991, 1992 Linus Torvalds
4 * Copyright 2007 rPath, Inc. - All Rights Reserved
5 *
6 * This file is part of the Linux kernel, and is made available under
7 * the terms of the GNU General Public License version 2.
8 *
9 * ----------------------------------------------------------------------- */
10
11/*
H. Peter Anvin62607312007-07-11 12:18:54 -070012 * Main module for the real-mode kernel code
13 */
14
15#include "boot.h"
16
17struct boot_params boot_params __attribute__((aligned(16)));
18
19char *HEAP = _end;
20char *heap_end = _end; /* Default end of heap = no heap */
21
22/*
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.
26 */
H. Peter Anvin62607312007-07-11 12:18:54 -070027
28static void copy_boot_params(void)
29{
30 struct old_cmdline {
31 u16 cl_magic;
32 u16 cl_offset;
33 };
34 const struct old_cmdline * const oldcmd =
35 (const struct old_cmdline *)OLD_CL_ADDRESS;
36
37 BUILD_BUG_ON(sizeof boot_params != 4096);
38 memcpy(&boot_params.hdr, &hdr, sizeof hdr);
39
40 if (!boot_params.hdr.cmd_line_ptr &&
41 oldcmd->cl_magic == OLD_CL_MAGIC) {
42 /* Old-style command line protocol. */
43 u16 cmdline_seg;
44
45 /* Figure out if the command line falls in the region
46 of memory that an old kernel would have copied up
47 to 0x90000... */
48 if (oldcmd->cl_offset < boot_params.hdr.setup_move_size)
49 cmdline_seg = ds();
50 else
51 cmdline_seg = 0x9000;
52
53 boot_params.hdr.cmd_line_ptr =
54 (cmdline_seg << 4) + oldcmd->cl_offset;
55 }
56}
57
58/*
59 * Set the keyboard repeat rate to maximum. Unclear why this
60 * is done here; this might be possible to kill off as stale code.
61 */
62static void keyboard_set_repeat(void)
63{
64 u16 ax = 0x0305;
65 u16 bx = 0;
66 asm volatile("int $0x16"
67 : "+a" (ax), "+b" (bx)
68 : : "ecx", "edx", "esi", "edi");
69}
70
71/*
H. Peter Anvin238b7062007-07-18 17:19:30 -070072 * Get Intel SpeedStep (IST) information.
H. Peter Anvin62607312007-07-11 12:18:54 -070073 */
H. Peter Anvin238b7062007-07-18 17:19:30 -070074static void query_ist(void)
H. Peter Anvin62607312007-07-11 12:18:54 -070075{
76 asm("int $0x15"
H. Peter Anvin238b7062007-07-18 17:19:30 -070077 : "=a" (boot_params.ist_info.signature),
78 "=b" (boot_params.ist_info.command),
79 "=c" (boot_params.ist_info.event),
80 "=d" (boot_params.ist_info.perf_level)
H. Peter Anvin62607312007-07-11 12:18:54 -070081 : "a" (0x0000e980), /* IST Support */
82 "d" (0x47534943)); /* Request value */
83}
84
85/*
86 * Tell the BIOS what CPU mode we intend to run in.
87 */
88static void set_bios_mode(void)
89{
90#ifdef CONFIG_X86_64
91 u32 eax, ebx;
92
93 eax = 0xec00;
94 ebx = 2;
95 asm volatile("int $0x15"
96 : "+a" (eax), "+b" (ebx)
97 : : "ecx", "edx", "esi", "edi");
98#endif
99}
100
H. Peter Anvinacd644b2008-01-30 13:33:04 +0100101static void init_heap(void)
102{
103 char *stack_end;
104
105 if (boot_params.hdr.loadflags & CAN_USE_HEAP) {
106 asm("leal %P1(%%esp),%0"
107 : "=r" (stack_end) : "i" (-STACK_SIZE));
108
109 heap_end = (char *)
110 ((size_t)boot_params.hdr.heap_end_ptr + 0x200);
111 if (heap_end > stack_end)
112 heap_end = stack_end;
113 } else {
114 /* Boot protocol 2.00 only, no heap available */
115 puts("WARNING: Ancient bootloader, some functionality "
116 "may be limited!\n");
117 }
118}
119
H. Peter Anvin62607312007-07-11 12:18:54 -0700120void main(void)
121{
122 /* First, copy the boot header into the "zeropage" */
123 copy_boot_params();
124
125 /* End of heap check */
H. Peter Anvinacd644b2008-01-30 13:33:04 +0100126 init_heap();
H. Peter Anvin62607312007-07-11 12:18:54 -0700127
128 /* Make sure we have all the proper CPU support */
129 if (validate_cpu()) {
130 puts("Unable to boot - please use a kernel appropriate "
131 "for your CPU.\n");
132 die();
133 }
134
135 /* Tell the BIOS what CPU mode we intend to run in. */
136 set_bios_mode();
137
138 /* Detect memory layout */
139 detect_memory();
140
141 /* Set keyboard repeat rate (why?) */
142 keyboard_set_repeat();
143
H. Peter Anvin62607312007-07-11 12:18:54 -0700144 /* Query MCA information */
145 query_mca();
146
147 /* Voyager */
148#ifdef CONFIG_X86_VOYAGER
149 query_voyager();
150#endif
151
H. Peter Anvin238b7062007-07-18 17:19:30 -0700152 /* Query Intel SpeedStep (IST) information */
153 query_ist();
H. Peter Anvin62607312007-07-11 12:18:54 -0700154
155 /* Query APM information */
156#if defined(CONFIG_APM) || defined(CONFIG_APM_MODULE)
157 query_apm_bios();
158#endif
159
160 /* Query EDD information */
161#if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
162 query_edd();
163#endif
H. Peter Anvin1a8514e2008-01-30 13:33:03 +0100164
165 /* Set the video mode */
166 set_video();
167
H. Peter Anvin62607312007-07-11 12:18:54 -0700168 /* Do the last things and invoke protected mode */
169 go_to_protected_mode();
170}