]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/x86/boot/main.c
01aa64b5575bab043cd43df70b3f0ebedfe05025
[linux-2.6-omap-h63xx.git] / arch / x86 / boot / main.c
1 /* -*- 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 /*
12  * Main module for the real-mode kernel code
13  */
14
15 #include "boot.h"
16
17 struct boot_params boot_params __attribute__((aligned(16)));
18
19 char *HEAP = _end;
20 char *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  */
27
28 static 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  */
62 static 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 /*
72  * Get Intel SpeedStep (IST) information.
73  */
74 static void query_ist(void)
75 {
76         /* Some 486 BIOSes apparently crash on this call */
77         if (cpu.level < 6)
78                 return;
79
80         asm("int $0x15"
81             : "=a" (boot_params.ist_info.signature),
82               "=b" (boot_params.ist_info.command),
83               "=c" (boot_params.ist_info.event),
84               "=d" (boot_params.ist_info.perf_level)
85             : "a" (0x0000e980),  /* IST Support */
86               "d" (0x47534943)); /* Request value */
87 }
88
89 /*
90  * Tell the BIOS what CPU mode we intend to run in.
91  */
92 static void set_bios_mode(void)
93 {
94 #ifdef CONFIG_X86_64
95         u32 eax, ebx;
96
97         eax = 0xec00;
98         ebx = 2;
99         asm volatile("int $0x15"
100                      : "+a" (eax), "+b" (ebx)
101                      : : "ecx", "edx", "esi", "edi");
102 #endif
103 }
104
105 static void init_heap(void)
106 {
107         char *stack_end;
108
109         if (boot_params.hdr.loadflags & CAN_USE_HEAP) {
110                 asm("leal %P1(%%esp),%0"
111                     : "=r" (stack_end) : "i" (-STACK_SIZE));
112
113                 heap_end = (char *)
114                         ((size_t)boot_params.hdr.heap_end_ptr + 0x200);
115                 if (heap_end > stack_end)
116                         heap_end = stack_end;
117         } else {
118                 /* Boot protocol 2.00 only, no heap available */
119                 puts("WARNING: Ancient bootloader, some functionality "
120                      "may be limited!\n");
121         }
122 }
123
124 void main(void)
125 {
126         /* First, copy the boot header into the "zeropage" */
127         copy_boot_params();
128
129         /* End of heap check */
130         init_heap();
131
132         /* Make sure we have all the proper CPU support */
133         if (validate_cpu()) {
134                 puts("Unable to boot - please use a kernel appropriate "
135                      "for your CPU.\n");
136                 die();
137         }
138
139         /* Tell the BIOS what CPU mode we intend to run in. */
140         set_bios_mode();
141
142         /* Detect memory layout */
143         detect_memory();
144
145         /* Set keyboard repeat rate (why?) */
146         keyboard_set_repeat();
147
148         /* Query MCA information */
149         query_mca();
150
151         /* Voyager */
152 #ifdef CONFIG_X86_VOYAGER
153         query_voyager();
154 #endif
155
156         /* Query Intel SpeedStep (IST) information */
157         query_ist();
158
159         /* Query APM information */
160 #if defined(CONFIG_APM) || defined(CONFIG_APM_MODULE)
161         query_apm_bios();
162 #endif
163
164         /* Query EDD information */
165 #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
166         query_edd();
167 #endif
168
169         /* Set the video mode */
170         set_video();
171
172         /* Parse command line for 'quiet' and pass it to decompressor. */
173         if (cmdline_find_option_bool("quiet"))
174                 boot_params.hdr.loadflags |= QUIET_FLAG;
175
176         /* Do the last things and invoke protected mode */
177         go_to_protected_mode();
178 }