1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include "boot.h"
17
18struct boot_params boot_params __attribute__((aligned(16)));
19
20char *HEAP = _end;
21char *heap_end = _end;
22
23
24
25
26
27
28
29static void copy_boot_params(void)
30{
31 struct old_cmdline {
32 u16 cl_magic;
33 u16 cl_offset;
34 };
35 const struct old_cmdline * const oldcmd =
36 (const struct old_cmdline *)OLD_CL_ADDRESS;
37
38 BUILD_BUG_ON(sizeof boot_params != 4096);
39 memcpy(&boot_params.hdr, &hdr, sizeof hdr);
40
41 if (!boot_params.hdr.cmd_line_ptr &&
42 oldcmd->cl_magic == OLD_CL_MAGIC) {
43
44 u16 cmdline_seg;
45
46
47
48
49 if (oldcmd->cl_offset < boot_params.hdr.setup_move_size)
50 cmdline_seg = ds();
51 else
52 cmdline_seg = 0x9000;
53
54 boot_params.hdr.cmd_line_ptr =
55 (cmdline_seg << 4) + oldcmd->cl_offset;
56 }
57}
58
59
60
61
62
63static void keyboard_set_repeat(void)
64{
65 struct biosregs ireg;
66 initregs(&ireg);
67 ireg.ax = 0x0305;
68 intcall(0x16, &ireg, NULL);
69}
70
71
72
73
74static void query_ist(void)
75{
76 struct biosregs ireg, oreg;
77
78
79
80 if (cpu.level < 6)
81 return;
82
83 initregs(&ireg);
84 ireg.ax = 0xe980;
85 ireg.edx = 0x47534943;
86 intcall(0x15, &ireg, &oreg);
87
88 boot_params.ist_info.signature = oreg.eax;
89 boot_params.ist_info.command = oreg.ebx;
90 boot_params.ist_info.event = oreg.ecx;
91 boot_params.ist_info.perf_level = oreg.edx;
92}
93
94
95
96
97static void set_bios_mode(void)
98{
99#ifdef CONFIG_X86_64
100 struct biosregs ireg;
101
102 initregs(&ireg);
103 ireg.ax = 0xec00;
104 ireg.bx = 2;
105 intcall(0x15, &ireg, NULL);
106#endif
107}
108
109static void init_heap(void)
110{
111 char *stack_end;
112
113 if (boot_params.hdr.loadflags & CAN_USE_HEAP) {
114 asm("leal %P1(%%esp),%0"
115 : "=r" (stack_end) : "i" (-STACK_SIZE));
116
117 heap_end = (char *)
118 ((size_t)boot_params.hdr.heap_end_ptr + 0x200);
119 if (heap_end > stack_end)
120 heap_end = stack_end;
121 } else {
122
123 puts("WARNING: Ancient bootloader, some functionality "
124 "may be limited!\n");
125 }
126}
127
128void main(void)
129{
130
131 copy_boot_params();
132
133
134 init_heap();
135
136
137 if (validate_cpu()) {
138 puts("Unable to boot - please use a kernel appropriate "
139 "for your CPU.\n");
140 die();
141 }
142
143
144 set_bios_mode();
145
146
147 detect_memory();
148
149
150 keyboard_set_repeat();
151
152
153 query_mca();
154
155
156 query_ist();
157
158
159#if defined(CONFIG_APM) || defined(CONFIG_APM_MODULE)
160 query_apm_bios();
161#endif
162
163
164#if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
165 query_edd();
166#endif
167
168
169 set_video();
170
171
172 if (cmdline_find_option_bool("quiet"))
173 boot_params.hdr.loadflags |= QUIET_FLAG;
174
175
176 go_to_protected_mode();
177}
178