]> git.proxmox.com Git - qemu.git/blame - pc-bios/optionrom/multiboot.S
multiboot: Don't forget last mmap entry
[qemu.git] / pc-bios / optionrom / multiboot.S
CommitLineData
f16408df
AG
1/*
2 * Multiboot Option ROM
3 *
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.
8 *
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.
13 *
14 * You should have received a copy of the GNU General Public License
8167ee88 15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
f16408df
AG
16 *
17 * Copyright Novell Inc, 2009
18 * Authors: Alexander Graf <agraf@suse.de>
19 */
20
dd4b2659 21#include "optionrom.h"
f16408df 22
75b9f690
GN
23#define BOOT_ROM_PRODUCT "multiboot loader"
24
f16408df
AG
25#define MULTIBOOT_MAGIC 0x2badb002
26
77873196
AG
27#define GS_PROT_JUMP 0
28#define GS_GDT_DESC 6
29
f16408df 30
dd4b2659 31BOOT_ROM_START
f16408df
AG
32
33run_multiboot:
34
35 cli
36 cld
37
38 mov %cs, %eax
39 shl $0x4, %eax
40
77873196 41 /* set up a long jump descriptor that is PC relative */
f16408df 42
77873196
AG
43 /* move stack memory to %gs */
44 mov %ss, %ecx
45 shl $0x4, %ecx
46 mov %esp, %ebx
47 add %ebx, %ecx
48 sub $0x20, %ecx
49 sub $0x30, %esp
50 shr $0x4, %ecx
51 mov %cx, %gs
52
e7d81004 53 /* now push the indirect jump descriptor there */
f16408df
AG
54 mov (prot_jump), %ebx
55 add %eax, %ebx
77873196
AG
56 movl %ebx, %gs:GS_PROT_JUMP
57 mov $8, %bx
58 movw %bx, %gs:GS_PROT_JUMP + 4
59
60 /* fix the gdt descriptor to be PC relative */
61 movw (gdt_desc), %bx
62 movw %bx, %gs:GS_GDT_DESC
63 movl (gdt_desc+2), %ebx
64 add %eax, %ebx
65 movl %ebx, %gs:GS_GDT_DESC + 2
66
53ea95de
AL
67 xor %eax, %eax
68 mov %eax, %es
69
77873196
AG
70 /* Read the bootinfo struct into RAM */
71 read_fw_blob(FW_CFG_INITRD)
f16408df
AG
72
73 /* FS = bootinfo_struct */
74 read_fw FW_CFG_INITRD_ADDR
75 shr $4, %eax
76 mov %ax, %fs
77
c6e052f0
PB
78 /* Account for the EBDA in the multiboot structure's e801
79 * map.
80 */
81 int $0x12
82 cwtl
83 movl %eax, %fs:4
84
f16408df 85 /* ES = mmap_addr */
53ea95de 86 mov %fs:48, %eax
f16408df
AG
87 shr $4, %eax
88 mov %ax, %es
89
90 /* Initialize multiboot mmap structs using int 0x15(e820) */
91 xor %ebx, %ebx
390fb6b4
KW
92 /* Start storing mmap data at %es:0 */
93 xor %edi, %edi
f16408df
AG
94
95mmap_loop:
390fb6b4
KW
96 /* The multiboot entry size has offset -4, so leave some space */
97 add $4, %di
f16408df
AG
98 /* entry size (mmap struct) & max buffer size (int15) */
99 movl $20, %ecx
f16408df
AG
100 /* e820 */
101 movl $0x0000e820, %eax
102 /* 'SMAP' magic */
103 movl $0x534d4150, %edx
104 int $0x15
105
106mmap_check_entry:
390fb6b4 107 /* Error or last entry already done? */
f16408df 108 jb mmap_done
f16408df
AG
109
110mmap_store_entry:
390fb6b4
KW
111 /* store entry size */
112 /* old as(1) doesn't like this insn so emit the bytes instead:
113 movl %ecx, %es:-4(%edi)
114 */
115 .dc.b 0x26,0x67,0x66,0x89,0x4f,0xfc
116
117 /* %edi += entry_size, store as mbs_mmap_length */
118 add %ecx, %edi
f16408df 119 movw %di, %fs:0x2c
390fb6b4
KW
120
121 /* Continuation value 0 means last entry */
122 test %ebx, %ebx
123 jnz mmap_loop
f16408df
AG
124
125mmap_done:
126real_to_prot:
127 /* Load the GDT before going into protected mode */
128lgdt:
77873196 129 data32 lgdt %gs:GS_GDT_DESC
f16408df
AG
130
131 /* get us to protected mode now */
132 movl $1, %eax
133 movl %eax, %cr0
134
135 /* the LJMP sets CS for us and gets us to 32-bit */
136ljmp:
77873196 137 data32 ljmp *%gs:GS_PROT_JUMP
f16408df
AG
138
139prot_mode:
140.code32
141
142 /* initialize all other segments */
143 movl $0x10, %eax
144 movl %eax, %ss
145 movl %eax, %ds
146 movl %eax, %es
147 movl %eax, %fs
148 movl %eax, %gs
149
77873196
AG
150 /* Read the kernel and modules into RAM */
151 read_fw_blob(FW_CFG_KERNEL)
152
f16408df 153 /* Jump off to the kernel */
77873196 154 read_fw FW_CFG_KERNEL_ENTRY
f16408df
AG
155 mov %eax, %ecx
156
157 /* EBX contains a pointer to the bootinfo struct */
158 read_fw FW_CFG_INITRD_ADDR
159 movl %eax, %ebx
160
161 /* EAX has to contain the magic */
162 movl $MULTIBOOT_MAGIC, %eax
163ljmp2:
164 jmp *%ecx
165
166/* Variables */
167.align 4, 0
f16408df
AG
168prot_jump: .long prot_mode
169 .short 8
170
171.align 4, 0
172gdt:
173 /* 0x00 */
174.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
175
176 /* 0x08: code segment (base=0, limit=0xfffff, type=32bit code exec/read, DPL=0, 4k) */
177.byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x9a, 0xcf, 0x00
178
179 /* 0x10: data segment (base=0, limit=0xfffff, type=32bit data read/write, DPL=0, 4k) */
180.byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x92, 0xcf, 0x00
181
182 /* 0x18: code segment (base=0, limit=0x0ffff, type=16bit code exec/read/conf, DPL=0, 1b) */
183.byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x9e, 0x00, 0x00
184
185 /* 0x20: data segment (base=0, limit=0x0ffff, type=16bit data read/write, DPL=0, 1b) */
186.byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x92, 0x00, 0x00
187
188gdt_desc:
189.short (5 * 8) - 1
190.long gdt
191
dd4b2659 192BOOT_ROM_END