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 #define NO_QEMU_PROTOS
22 #include "../../hw/fw_cfg.h"
24 #define BIOS_CFG_IOPORT_CFG 0x510
25 #define BIOS_CFG_IOPORT_DATA 0x511
27 #define MULTIBOOT_MAGIC 0x2badb002
29 /* Read a variable from the fw_cfg device.
34 mov $BIOS_CFG_IOPORT_CFG, %dx
36 mov $BIOS_CFG_IOPORT_DATA, %dx
52 .byte 1 /* (_end - _start) / 512 */
56 /* setup ds so we can access the IVT */
62 mov %eax, %cs:old_int19
64 /* install our int 19 handler */
65 movw $int19_handler, (0x19*4)
87 /* fix the gdt descriptor to be PC relative */
88 mov (gdt_desc+2), %ebx
90 mov %ebx, (gdt_desc+2)
92 /* fix the prot mode indirect jump to be PC relative */
97 /* FS = bootinfo_struct */
98 read_fw FW_CFG_INITRD_ADDR
103 read_fw FW_CFG_INITRD_SIZE
107 /* Initialize multiboot mmap structs using int 0x15(e820) */
109 /* mmap start after first size */
113 /* entry size (mmap struct) & max buffer size (int15) */
115 /* store entry size */
116 /* old as(1) doesn't like this insn so emit the bytes instead:
117 movl %ecx, %es:-4(%edi)
119 .dc.b 0x26,0x67,0x66,0x89,0x4f,0xfc
121 movl $0x0000e820, %eax
123 movl $0x534d4150, %edx
127 /* last entry? then we're done */
131 /* valid entry, so let's loop on */
134 /* %ax = entry_number * 24 */
139 /* %di = 4 + (entry_number * 24) */
145 /* Load the GDT before going into protected mode */
147 data32 lgdt %cs:gdt_desc
149 /* get us to protected mode now */
153 /* the LJMP sets CS for us and gets us to 32-bit */
155 data32 ljmp *%cs:prot_jump
160 /* initialize all other segments */
168 /* Jump off to the kernel */
169 read_fw FW_CFG_KERNEL_ADDR
172 /* EBX contains a pointer to the bootinfo struct */
173 read_fw FW_CFG_INITRD_ADDR
176 /* EAX has to contain the magic */
177 movl $MULTIBOOT_MAGIC, %eax
185 prot_jump: .long prot_mode
191 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
193 /* 0x08: code segment (base=0, limit=0xfffff, type=32bit code exec/read, DPL=0, 4k) */
194 .byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x9a, 0xcf, 0x00
196 /* 0x10: data segment (base=0, limit=0xfffff, type=32bit data read/write, DPL=0, 4k) */
197 .byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x92, 0xcf, 0x00
199 /* 0x18: code segment (base=0, limit=0x0ffff, type=16bit code exec/read/conf, DPL=0, 1b) */
200 .byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x9e, 0x00, 0x00
202 /* 0x20: data segment (base=0, limit=0x0ffff, type=16bit data read/write, DPL=0, 1b) */
203 .byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x92, 0x00, 0x00