1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#include "optionrom.h"
24
25#define BOOT_ROM_PRODUCT "Linux loader"
26
27BOOT_ROM_START
28
29run_linuxboot:
30
31 cli
32 cld
33
34 jmp copy_kernel
35boot_kernel:
36
37 read_fw FW_CFG_SETUP_ADDR
38
39 mov %eax, %ebx
40 shr $4, %ebx
41
42
43 mov %bx, %ds
44 mov %bx, %es
45 mov %bx, %fs
46 mov %bx, %gs
47 mov %bx, %ss
48
49
50 add $0x20, %bx
51 mov %bx, %cx
52
53
54 read_fw FW_CFG_CMDLINE_ADDR
55 mov %eax, %ebx
56 read_fw FW_CFG_SETUP_ADDR
57 sub %eax, %ebx
58 sub $16, %ebx
59 mov %ebx, %esp
60
61
62 pushw %cx
63 xor %ax, %ax
64 pushw %ax
65
66
67 xor %eax, %eax
68 xor %ebx, %ebx
69 xor %ecx, %ecx
70 xor %edx, %edx
71 xor %edi, %edi
72 xor %ebp, %ebp
73
74
75 lret
76
77
78copy_kernel:
79
80 read_fw FW_CFG_SETUP_ADDR
81 shr $4, %eax
82 mov %eax, %es
83 xor %edi, %edi
84 read_fw_blob_addr32_edi(FW_CFG_SETUP)
85
86 cmpw $0x203, %es:0x206
87 jae 1f
88 movl $0x37ffffff, %es:0x22c
891:
90
91
92 read_fw FW_CFG_INITRD_ADDR
93 mov %eax, %edi
94 read_fw FW_CFG_INITRD_SIZE
95 add %edi, %eax
96 xor %es:0x22c, %eax
97 and $-4096, %eax
98 jz load_kernel
99
100
101
102
103
104 mov $0xe801, %ax
105 xor %cx, %cx
106 xor %dx, %dx
107 int $0x15
108
109
110 or %cx, %cx
111 jnz 1f
112 or %dx, %dx
113 jnz 1f
114 mov %ax, %cx
115 mov %bx, %dx
1161:
117
118 or %dx, %dx
119 jnz 2f
120 addw $1024, %cx
121 movzwl %cx, %edi
122 shll $10, %edi
123 jmp 3f
124
1252:
126 addw $16777216 >> 16, %dx
127 movzwl %dx, %edi
128 shll $16, %edi
129
1303:
131 read_fw FW_CFG_INITRD_SIZE
132 subl %eax, %edi
133 andl $-4096, %edi
134 movl %edi, %es:0x218
135
136load_kernel:
137
138
139
140
141
142 mov %esp, %ebp
143 sub $16, %esp
144
145
146 movw $((3 * 8) - 1), -16(%bp)
147 mov %cs, %eax
148 movzwl %ax, %eax
149 shl $4, %eax
150 addl $gdt, %eax
151 movl %eax, -14(%bp)
152
153
154 data32 lgdt -16(%bp)
155 mov %ebp, %esp
156
157
158 mov $1, %eax
159 mov %eax, %cr0
160
161
162 mov $0x10, %eax
163 mov %eax, %es
164
165
166
167
168 read_fw_blob_addr32_edi(FW_CFG_INITRD)
169 read_fw_blob_addr32(FW_CFG_KERNEL)
170 read_fw_blob_addr32(FW_CFG_CMDLINE)
171
172
173 mov $0, %eax
174 mov %eax, %cr0
175
176
177 mov %cs, %ax
178 mov %ax, %es
179
180 jmp boot_kernel
181
182
183
184.align 4, 0
185gdt:
186
187.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
188
189
190.byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x9a, 0xcf, 0x00
191
192
193.byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x92, 0xcf, 0x00
194
195BOOT_ROM_END
196