2 * Linux Boot Option ROM
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 * Copyright Novell Inc, 2009
18 * Authors: Alexander Graf <agraf@suse.de>
20 * Based on code in hw/pc.c.
23 #include "optionrom.h"
25 #define BOOT_ROM_PRODUCT "Linux loader"
37 read_fw FW_CFG_SETUP_ADDR
42 /* All segments contain real_addr */
49 /* CX = CS we want to jump to */
53 /* SP = cmdline_addr-real_addr-16 */
54 read_fw FW_CFG_CMDLINE_ADDR
56 read_fw FW_CFG_SETUP_ADDR
61 /* Build indirect lret descriptor */
64 pushw %ax /* IP = 0 */
79 /* Read info block in low memory (0x10000 or 0x90000) */
80 read_fw FW_CFG_SETUP_ADDR
84 read_fw_blob_addr32_edi(FW_CFG_SETUP)
86 cmpw $0x203, %es:0x206 // if protocol >= 0x203
87 jae 1f // have initrd_max
88 movl $0x37ffffff, %es:0x22c // else assume 0x37ffffff
91 /* Check if using kernel-specified initrd address */
92 read_fw FW_CFG_INITRD_ADDR
93 mov %eax, %edi // (load_kernel wants it in %edi)
94 read_fw FW_CFG_INITRD_SIZE // find end of initrd
96 xor %es:0x22c, %eax // if it matches es:0x22c
97 and $-4096, %eax // (apart from padding for page)
98 jz load_kernel // then initrd is not at top
101 /* pc.c placed the initrd at end of memory. Compute a better
102 * initrd address based on e801 data.
109 /* Output could be in AX/BX or CX/DX */
120 addw $1024, %cx /* add 1 MB */
122 shll $10, %edi /* convert to bytes */
126 addw $16777216 >> 16, %dx /* add 16 MB */
128 shll $16, %edi /* convert to bytes */
131 read_fw FW_CFG_INITRD_SIZE
133 andl $-4096, %edi /* EDI = start of initrd */
134 movl %edi, %es:0x218 /* put it in the header */
137 /* We need to load the kernel into memory we can't access in 16 bit
138 mode, so let's get into 32 bit mode, write the kernel and jump
141 /* Reserve space on the stack for our GDT descriptor. */
145 /* Now create the GDT descriptor */
146 movw $((3 * 8) - 1), -16(%bp)
153 /* And load the GDT */
157 /* Get us to protected mode now */
161 /* So we can set ES to a 32-bit segment */
165 /* We're now running in 16-bit CS, but 32-bit ES! */
167 /* Load kernel and initrd */
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)
172 /* And now jump into Linux! */
187 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
189 /* 0x08: code segment (base=0, limit=0xfffff, type=32bit code exec/read, DPL=0, 4k) */
190 .byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x9a, 0xcf, 0x00
192 /* 0x10: data segment (base=0, limit=0xfffff, type=32bit data read/write, DPL=0, 4k) */
193 .byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x92, 0xcf, 0x00