H. Peter Anvin | 6260731 | 2007-07-11 12:18:54 -0700 | [diff] [blame] | 1 | /* -*- linux-c -*- ------------------------------------------------------- * |
| 2 | * |
| 3 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 4 | * Copyright 2007 rPath, Inc. - All Rights Reserved |
H. Peter Anvin | df7699c | 2009-04-01 18:13:46 -0700 | [diff] [blame] | 5 | * Copyright 2009 Intel Corporation; author H. Peter Anvin |
H. Peter Anvin | 6260731 | 2007-07-11 12:18:54 -0700 | [diff] [blame] | 6 | * |
| 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. |
| 9 | * |
| 10 | * ----------------------------------------------------------------------- */ |
| 11 | |
| 12 | /* |
H. Peter Anvin | 6260731 | 2007-07-11 12:18:54 -0700 | [diff] [blame] | 13 | * Main module for the real-mode kernel code |
| 14 | */ |
| 15 | |
| 16 | #include "boot.h" |
Vivek Goyal | c041b5a | 2014-03-18 15:26:37 -0400 | [diff] [blame] | 17 | #include "string.h" |
H. Peter Anvin | 6260731 | 2007-07-11 12:18:54 -0700 | [diff] [blame] | 18 | |
| 19 | struct boot_params boot_params __attribute__((aligned(16))); |
| 20 | |
| 21 | char *HEAP = _end; |
| 22 | char *heap_end = _end; /* Default end of heap = no heap */ |
| 23 | |
| 24 | /* |
| 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. |
| 28 | */ |
H. Peter Anvin | 6260731 | 2007-07-11 12:18:54 -0700 | [diff] [blame] | 29 | |
| 30 | static void copy_boot_params(void) |
| 31 | { |
| 32 | struct old_cmdline { |
| 33 | u16 cl_magic; |
| 34 | u16 cl_offset; |
| 35 | }; |
| 36 | const struct old_cmdline * const oldcmd = |
| 37 | (const struct old_cmdline *)OLD_CL_ADDRESS; |
| 38 | |
| 39 | BUILD_BUG_ON(sizeof boot_params != 4096); |
| 40 | memcpy(&boot_params.hdr, &hdr, sizeof hdr); |
| 41 | |
| 42 | if (!boot_params.hdr.cmd_line_ptr && |
| 43 | oldcmd->cl_magic == OLD_CL_MAGIC) { |
| 44 | /* Old-style command line protocol. */ |
| 45 | u16 cmdline_seg; |
| 46 | |
| 47 | /* Figure out if the command line falls in the region |
| 48 | of memory that an old kernel would have copied up |
| 49 | to 0x90000... */ |
| 50 | if (oldcmd->cl_offset < boot_params.hdr.setup_move_size) |
| 51 | cmdline_seg = ds(); |
| 52 | else |
| 53 | cmdline_seg = 0x9000; |
| 54 | |
| 55 | boot_params.hdr.cmd_line_ptr = |
| 56 | (cmdline_seg << 4) + oldcmd->cl_offset; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | /* |
Joshua Cov | b2d0b7a | 2012-04-13 21:08:26 +0200 | [diff] [blame] | 61 | * Query the keyboard lock status as given by the BIOS, and |
| 62 | * set the keyboard repeat rate to maximum. Unclear why the latter |
H. Peter Anvin | 6260731 | 2007-07-11 12:18:54 -0700 | [diff] [blame] | 63 | * is done here; this might be possible to kill off as stale code. |
| 64 | */ |
Joshua Cov | b2d0b7a | 2012-04-13 21:08:26 +0200 | [diff] [blame] | 65 | static void keyboard_init(void) |
H. Peter Anvin | 6260731 | 2007-07-11 12:18:54 -0700 | [diff] [blame] | 66 | { |
Joshua Cov | b2d0b7a | 2012-04-13 21:08:26 +0200 | [diff] [blame] | 67 | struct biosregs ireg, oreg; |
H. Peter Anvin | df7699c | 2009-04-01 18:13:46 -0700 | [diff] [blame] | 68 | initregs(&ireg); |
Joshua Cov | b2d0b7a | 2012-04-13 21:08:26 +0200 | [diff] [blame] | 69 | |
| 70 | ireg.ah = 0x02; /* Get keyboard status */ |
| 71 | intcall(0x16, &ireg, &oreg); |
| 72 | boot_params.kbd_status = oreg.al; |
| 73 | |
| 74 | ireg.ax = 0x0305; /* Set keyboard repeat rate */ |
H. Peter Anvin | df7699c | 2009-04-01 18:13:46 -0700 | [diff] [blame] | 75 | intcall(0x16, &ireg, NULL); |
H. Peter Anvin | 6260731 | 2007-07-11 12:18:54 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | /* |
H. Peter Anvin | 238b706 | 2007-07-18 17:19:30 -0700 | [diff] [blame] | 79 | * Get Intel SpeedStep (IST) information. |
H. Peter Anvin | 6260731 | 2007-07-11 12:18:54 -0700 | [diff] [blame] | 80 | */ |
H. Peter Anvin | 238b706 | 2007-07-18 17:19:30 -0700 | [diff] [blame] | 81 | static void query_ist(void) |
H. Peter Anvin | 6260731 | 2007-07-11 12:18:54 -0700 | [diff] [blame] | 82 | { |
H. Peter Anvin | df7699c | 2009-04-01 18:13:46 -0700 | [diff] [blame] | 83 | struct biosregs ireg, oreg; |
| 84 | |
H. Peter Anvin | c2dcfde | 2008-08-13 13:14:22 -0700 | [diff] [blame] | 85 | /* Some older BIOSes apparently crash on this call, so filter |
| 86 | it from machines too old to have SpeedStep at all. */ |
Joerg Roedel | 7b27718 | 2008-08-13 10:07:05 +0200 | [diff] [blame] | 87 | if (cpu.level < 6) |
| 88 | return; |
| 89 | |
H. Peter Anvin | df7699c | 2009-04-01 18:13:46 -0700 | [diff] [blame] | 90 | initregs(&ireg); |
| 91 | ireg.ax = 0xe980; /* IST Support */ |
| 92 | ireg.edx = 0x47534943; /* Request value */ |
| 93 | intcall(0x15, &ireg, &oreg); |
| 94 | |
| 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; |
H. Peter Anvin | 6260731 | 2007-07-11 12:18:54 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | /* |
| 102 | * Tell the BIOS what CPU mode we intend to run in. |
| 103 | */ |
| 104 | static void set_bios_mode(void) |
| 105 | { |
| 106 | #ifdef CONFIG_X86_64 |
H. Peter Anvin | df7699c | 2009-04-01 18:13:46 -0700 | [diff] [blame] | 107 | struct biosregs ireg; |
H. Peter Anvin | 6260731 | 2007-07-11 12:18:54 -0700 | [diff] [blame] | 108 | |
H. Peter Anvin | df7699c | 2009-04-01 18:13:46 -0700 | [diff] [blame] | 109 | initregs(&ireg); |
| 110 | ireg.ax = 0xec00; |
| 111 | ireg.bx = 2; |
| 112 | intcall(0x15, &ireg, NULL); |
H. Peter Anvin | 6260731 | 2007-07-11 12:18:54 -0700 | [diff] [blame] | 113 | #endif |
| 114 | } |
| 115 | |
H. Peter Anvin | acd644b | 2008-01-30 13:33:04 +0100 | [diff] [blame] | 116 | static void init_heap(void) |
| 117 | { |
| 118 | char *stack_end; |
| 119 | |
| 120 | if (boot_params.hdr.loadflags & CAN_USE_HEAP) { |
| 121 | asm("leal %P1(%%esp),%0" |
| 122 | : "=r" (stack_end) : "i" (-STACK_SIZE)); |
| 123 | |
| 124 | heap_end = (char *) |
| 125 | ((size_t)boot_params.hdr.heap_end_ptr + 0x200); |
| 126 | if (heap_end > stack_end) |
| 127 | heap_end = stack_end; |
| 128 | } else { |
| 129 | /* Boot protocol 2.00 only, no heap available */ |
| 130 | puts("WARNING: Ancient bootloader, some functionality " |
| 131 | "may be limited!\n"); |
| 132 | } |
| 133 | } |
| 134 | |
H. Peter Anvin | 6260731 | 2007-07-11 12:18:54 -0700 | [diff] [blame] | 135 | void main(void) |
| 136 | { |
| 137 | /* First, copy the boot header into the "zeropage" */ |
| 138 | copy_boot_params(); |
| 139 | |
Pekka Enberg | fa97bdf | 2010-07-11 11:06:57 +0300 | [diff] [blame] | 140 | /* Initialize the early-boot console */ |
| 141 | console_init(); |
Yinghai Lu | 8fee13a | 2010-08-02 16:21:22 -0700 | [diff] [blame] | 142 | if (cmdline_find_option_bool("debug")) |
| 143 | puts("early console in setup code\n"); |
Pekka Enberg | fa97bdf | 2010-07-11 11:06:57 +0300 | [diff] [blame] | 144 | |
H. Peter Anvin | 6260731 | 2007-07-11 12:18:54 -0700 | [diff] [blame] | 145 | /* End of heap check */ |
H. Peter Anvin | acd644b | 2008-01-30 13:33:04 +0100 | [diff] [blame] | 146 | init_heap(); |
H. Peter Anvin | 6260731 | 2007-07-11 12:18:54 -0700 | [diff] [blame] | 147 | |
| 148 | /* Make sure we have all the proper CPU support */ |
| 149 | if (validate_cpu()) { |
| 150 | puts("Unable to boot - please use a kernel appropriate " |
| 151 | "for your CPU.\n"); |
| 152 | die(); |
| 153 | } |
| 154 | |
| 155 | /* Tell the BIOS what CPU mode we intend to run in. */ |
| 156 | set_bios_mode(); |
| 157 | |
| 158 | /* Detect memory layout */ |
| 159 | detect_memory(); |
| 160 | |
Joshua Cov | b2d0b7a | 2012-04-13 21:08:26 +0200 | [diff] [blame] | 161 | /* Set keyboard repeat rate (why?) and query the lock flags */ |
| 162 | keyboard_init(); |
H. Peter Anvin | 6260731 | 2007-07-11 12:18:54 -0700 | [diff] [blame] | 163 | |
H. Peter Anvin | 6260731 | 2007-07-11 12:18:54 -0700 | [diff] [blame] | 164 | /* Query MCA information */ |
| 165 | query_mca(); |
| 166 | |
H. Peter Anvin | 238b706 | 2007-07-18 17:19:30 -0700 | [diff] [blame] | 167 | /* Query Intel SpeedStep (IST) information */ |
| 168 | query_ist(); |
H. Peter Anvin | 6260731 | 2007-07-11 12:18:54 -0700 | [diff] [blame] | 169 | |
| 170 | /* Query APM information */ |
| 171 | #if defined(CONFIG_APM) || defined(CONFIG_APM_MODULE) |
| 172 | query_apm_bios(); |
| 173 | #endif |
| 174 | |
| 175 | /* Query EDD information */ |
| 176 | #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE) |
| 177 | query_edd(); |
| 178 | #endif |
H. Peter Anvin | 1a8514e | 2008-01-30 13:33:03 +0100 | [diff] [blame] | 179 | |
| 180 | /* Set the video mode */ |
| 181 | set_video(); |
| 182 | |
H. Peter Anvin | 6260731 | 2007-07-11 12:18:54 -0700 | [diff] [blame] | 183 | /* Do the last things and invoke protected mode */ |
| 184 | go_to_protected_mode(); |
| 185 | } |