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>
21 #include "optionrom.h"
23 #define BOOT_ROM_PRODUCT "multiboot loader"
25 #define MULTIBOOT_MAGIC 0x2badb002
27 #define GS_PROT_JUMP 0
41 /* set up a long jump descriptor that is PC relative */
43 /* move stack memory to %gs */
53 /* now push the indirect jump descriptor there */
56 movl %ebx, %gs:GS_PROT_JUMP
58 movw %bx, %gs:GS_PROT_JUMP + 4
60 /* fix the gdt descriptor to be PC relative */
62 movw %bx, %gs:GS_GDT_DESC
63 movl (gdt_desc+2), %ebx
65 movl %ebx, %gs:GS_GDT_DESC + 2
70 /* Read the bootinfo struct into RAM */
71 read_fw_blob_dma(FW_CFG_INITRD)
73 /* FS = bootinfo_struct */
74 read_fw FW_CFG_INITRD_ADDR
78 /* Account for the EBDA in the multiboot structure's e801
90 /* Initialize multiboot mmap structs using int 0x15(e820) */
92 /* Start storing mmap data at %es:0 */
96 /* The multiboot entry size has offset -4, so leave some space */
98 /* entry size (mmap struct) & max buffer size (int15) */
101 movl $0x0000e820, %eax
103 movl $0x534d4150, %edx
107 /* Error or last entry already done? */
111 /* store entry size */
112 /* old as(1) doesn't like this insn so emit the bytes instead:
113 movl %ecx, %es:-4(%edi)
115 .dc.b 0x26,0x67,0x66,0x89,0x4f,0xfc
117 /* %edi += entry_size, store as mbs_mmap_length */
121 /* Continuation value 0 means last entry */
126 /* Calculate upper_mem field: The amount of memory between 1 MB and
127 the first upper memory hole. Get it from the mmap. */
135 /* Skip if type != 1 */
140 movl %es:4(%di), %eax
144 /* Check for contiguous extension (base <= %edx < base + length) */
148 addl %es:8(%di), %eax
152 /* If so, update %edx, and restart the search (mmap isn't ordered) */
158 addl %es:-4(%di), %edi
167 /* Load the GDT before going into protected mode */
169 data32 lgdt %gs:GS_GDT_DESC
171 /* get us to protected mode now */
175 /* the LJMP sets CS for us and gets us to 32-bit */
177 data32 ljmp *%gs:GS_PROT_JUMP
182 /* initialize all other segments */
190 /* Read the kernel and modules into RAM */
191 read_fw_blob_dma(FW_CFG_KERNEL)
193 /* Jump off to the kernel */
194 read_fw FW_CFG_KERNEL_ENTRY
197 /* EBX contains a pointer to the bootinfo struct */
198 read_fw FW_CFG_INITRD_ADDR
201 /* EAX has to contain the magic */
202 movl $MULTIBOOT_MAGIC, %eax
208 prot_jump: .long prot_mode
214 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
216 /* 0x08: code segment (base=0, limit=0xfffff, type=32bit code exec/read, DPL=0, 4k) */
217 .byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x9a, 0xcf, 0x00
219 /* 0x10: data segment (base=0, limit=0xfffff, type=32bit data read/write, DPL=0, 4k) */
220 .byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x92, 0xcf, 0x00
222 /* 0x18: code segment (base=0, limit=0x0ffff, type=16bit code exec/read/conf, DPL=0, 1b) */
223 .byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x9e, 0x00, 0x00
225 /* 0x20: data segment (base=0, limit=0x0ffff, type=16bit data read/write, DPL=0, 1b) */
226 .byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x92, 0x00, 0x00