1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#include "boot.h"
18
19struct boot_params boot_params __attribute__((aligned(16)));
20
21char *HEAP = _end;
22char *heap_end = _end;
23
24
25
26
27
28
29
30static 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
45 u16 cmdline_seg;
46
47
48
49
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
61
62
63
64static void keyboard_set_repeat(void)
65{
66 u16 ax = 0x0305;
67 u16 bx = 0;
68 asm volatile("int $0x16"
69 : "+a" (ax), "+b" (bx)
70 : : "ecx", "edx", "esi", "edi");
71}
72
73
74
75
76static void query_ist(void)
77{
78 asm("int $0x15"
79 : "=a" (boot_params.ist_info.signature),
80 "=b" (boot_params.ist_info.command),
81 "=c" (boot_params.ist_info.event),
82 "=d" (boot_params.ist_info.perf_level)
83 : "a" (0x0000e980),
84 "d" (0x47534943));
85}
86
87
88
89
90static void set_bios_mode(void)
91{
92#ifdef CONFIG_X86_64
93 u32 eax, ebx;
94
95 eax = 0xec00;
96 ebx = 2;
97 asm volatile("int $0x15"
98 : "+a" (eax), "+b" (ebx)
99 : : "ecx", "edx", "esi", "edi");
100#endif
101}
102
103static void init_heap(void)
104{
105 char *stack_end;
106
107 if (boot_params.hdr.loadflags & CAN_USE_HEAP) {
108 asm("leal %P1(%%esp),%0"
109 : "=r" (stack_end) : "i" (-STACK_SIZE));
110
111 heap_end = (char *)
112 ((size_t)boot_params.hdr.heap_end_ptr + 0x200);
113 if (heap_end > stack_end)
114 heap_end = stack_end;
115 } else {
116
117 puts("WARNING: Ancient bootloader, some functionality "
118 "may be limited!\n");
119 }
120}
121
122void main(void)
123{
124
125 copy_boot_params();
126
127
128 init_heap();
129
130
131 if (validate_cpu()) {
132 puts("Unable to boot - please use a kernel appropriate "
133 "for your CPU.\n");
134 die();
135 }
136
137
138 set_bios_mode();
139
140
141 detect_memory();
142
143
144 keyboard_set_repeat();
145
146
147 query_mca();
148
149
150#ifdef CONFIG_X86_VOYAGER
151 query_voyager();
152#endif
153
154
155 query_ist();
156
157
158#if defined(CONFIG_APM) || defined(CONFIG_APM_MODULE)
159 query_apm_bios();
160#endif
161
162
163#if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
164 query_edd();
165#endif
166
167
168 set_video();
169
170
171 go_to_protected_mode();
172}
173