Commit | Line | Data |
---|---|---|
97873a3d | 1 | // SPDX-License-Identifier: GPL-2.0-only |
62607313 PA |
2 | /* -*- linux-c -*- ------------------------------------------------------- * |
3 | * | |
4 | * Copyright (C) 1991, 1992 Linus Torvalds | |
5 | * Copyright 2007 rPath, Inc. - All Rights Reserved | |
df7699c5 | 6 | * Copyright 2009 Intel Corporation; author H. Peter Anvin |
62607313 | 7 | * |
62607313 PA |
8 | * ----------------------------------------------------------------------- */ |
9 | ||
10 | /* | |
62607313 PA |
11 | * Main module for the real-mode kernel code |
12 | */ | |
13 | ||
14 | #include "boot.h" | |
c041b5ad | 15 | #include "string.h" |
62607313 PA |
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 | */ | |
62607313 PA |
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 | ||
0e96f31e JB |
37 | BUILD_BUG_ON(sizeof(boot_params) != 4096); |
38 | memcpy(&boot_params.hdr, &hdr, sizeof(hdr)); | |
62607313 PA |
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 | /* | |
b2d0b7a0 JC |
59 | * Query the keyboard lock status as given by the BIOS, and |
60 | * set the keyboard repeat rate to maximum. Unclear why the latter | |
62607313 PA |
61 | * is done here; this might be possible to kill off as stale code. |
62 | */ | |
b2d0b7a0 | 63 | static void keyboard_init(void) |
62607313 | 64 | { |
b2d0b7a0 | 65 | struct biosregs ireg, oreg; |
df7699c5 | 66 | initregs(&ireg); |
b2d0b7a0 JC |
67 | |
68 | ireg.ah = 0x02; /* Get keyboard status */ | |
69 | intcall(0x16, &ireg, &oreg); | |
70 | boot_params.kbd_status = oreg.al; | |
71 | ||
72 | ireg.ax = 0x0305; /* Set keyboard repeat rate */ | |
df7699c5 | 73 | intcall(0x16, &ireg, NULL); |
62607313 PA |
74 | } |
75 | ||
76 | /* | |
238b706d | 77 | * Get Intel SpeedStep (IST) information. |
62607313 | 78 | */ |
238b706d | 79 | static void query_ist(void) |
62607313 | 80 | { |
df7699c5 PA |
81 | struct biosregs ireg, oreg; |
82 | ||
c2dcfde8 PA |
83 | /* Some older BIOSes apparently crash on this call, so filter |
84 | it from machines too old to have SpeedStep at all. */ | |
7b27718b JR |
85 | if (cpu.level < 6) |
86 | return; | |
87 | ||
df7699c5 PA |
88 | initregs(&ireg); |
89 | ireg.ax = 0xe980; /* IST Support */ | |
90 | ireg.edx = 0x47534943; /* Request value */ | |
91 | intcall(0x15, &ireg, &oreg); | |
92 | ||
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; | |
62607313 PA |
97 | } |
98 | ||
99 | /* | |
100 | * Tell the BIOS what CPU mode we intend to run in. | |
101 | */ | |
102 | static void set_bios_mode(void) | |
103 | { | |
104 | #ifdef CONFIG_X86_64 | |
df7699c5 | 105 | struct biosregs ireg; |
62607313 | 106 | |
df7699c5 PA |
107 | initregs(&ireg); |
108 | ireg.ax = 0xec00; | |
109 | ireg.bx = 2; | |
110 | intcall(0x15, &ireg, NULL); | |
62607313 PA |
111 | #endif |
112 | } | |
113 | ||
acd644bb | 114 | static void init_heap(void) |
62607313 | 115 | { |
acd644bb | 116 | char *stack_end; |
62607313 | 117 | |
62607313 | 118 | if (boot_params.hdr.loadflags & CAN_USE_HEAP) { |
acd644bb PA |
119 | asm("leal %P1(%%esp),%0" |
120 | : "=r" (stack_end) : "i" (-STACK_SIZE)); | |
121 | ||
122 | heap_end = (char *) | |
123 | ((size_t)boot_params.hdr.heap_end_ptr + 0x200); | |
124 | if (heap_end > stack_end) | |
125 | heap_end = stack_end; | |
62607313 PA |
126 | } else { |
127 | /* Boot protocol 2.00 only, no heap available */ | |
128 | puts("WARNING: Ancient bootloader, some functionality " | |
129 | "may be limited!\n"); | |
130 | } | |
acd644bb PA |
131 | } |
132 | ||
133 | void main(void) | |
134 | { | |
135 | /* First, copy the boot header into the "zeropage" */ | |
136 | copy_boot_params(); | |
137 | ||
fa97bdf9 PE |
138 | /* Initialize the early-boot console */ |
139 | console_init(); | |
8fee13a4 YL |
140 | if (cmdline_find_option_bool("debug")) |
141 | puts("early console in setup code\n"); | |
fa97bdf9 | 142 | |
acd644bb PA |
143 | /* End of heap check */ |
144 | init_heap(); | |
62607313 PA |
145 | |
146 | /* Make sure we have all the proper CPU support */ | |
147 | if (validate_cpu()) { | |
148 | puts("Unable to boot - please use a kernel appropriate " | |
149 | "for your CPU.\n"); | |
150 | die(); | |
151 | } | |
152 | ||
153 | /* Tell the BIOS what CPU mode we intend to run in. */ | |
154 | set_bios_mode(); | |
155 | ||
156 | /* Detect memory layout */ | |
157 | detect_memory(); | |
158 | ||
b2d0b7a0 JC |
159 | /* Set keyboard repeat rate (why?) and query the lock flags */ |
160 | keyboard_init(); | |
62607313 | 161 | |
238b706d PA |
162 | /* Query Intel SpeedStep (IST) information */ |
163 | query_ist(); | |
62607313 PA |
164 | |
165 | /* Query APM information */ | |
166 | #if defined(CONFIG_APM) || defined(CONFIG_APM_MODULE) | |
167 | query_apm_bios(); | |
168 | #endif | |
169 | ||
170 | /* Query EDD information */ | |
171 | #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE) | |
172 | query_edd(); | |
173 | #endif | |
1a8514e0 PA |
174 | |
175 | /* Set the video mode */ | |
176 | set_video(); | |
177 | ||
62607313 PA |
178 | /* Do the last things and invoke protected mode */ |
179 | go_to_protected_mode(); | |
180 | } |