3 * Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include <arch/pc/x86common.h>
22 #include <multiboot.h>
26 * Allows freeldr to be loaded as a "multiboot kernel" by
27 * other boot loaders like GRUB.
28 * This code is not referenced from anywhere. GRUB searches for
29 * the header signature and uses the header to load it.
32 #define MB_INFO_FLAGS_OFFSET 0
33 #define MB_INFO_BOOT_DEVICE_OFFSET 12
34 #define MB_INFO_COMMAND_LINE_OFFSET 16
35 #define CMDLINE_SIZE 256
38 * We want to execute at FREELDR_BASE (to be compatible with
39 * bootsector loading), but GRUB only allows loading of
40 * multiboot kernels above 1MB. So we let GRUB load us
41 * there and then relocate ourself to FREELDR_BASE.
43 #define INITIAL_BASE HEX(200000)
45 /* Align to 32 bits boundary */
48 /* Multiboot header */
51 .long MULTIBOOT_HEADER_MAGIC
53 .long MULTIBOOT_HEADER_FLAGS
55 .long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
57 .long INITIAL_BASE + MultibootHeader - FREELDR_BASE
65 .long INITIAL_BASE + MultibootEntry - FREELDR_BASE
70 /* Save command line */
71 test dword ptr [ebx + MB_INFO_FLAGS_OFFSET], MB_INFO_FLAG_COMMAND_LINE
73 mov esi, [ebx + MB_INFO_COMMAND_LINE_OFFSET]
74 mov edi, offset cmdline + INITIAL_BASE - FREELDR_BASE
75 mov ecx, CMDLINE_SIZE - 1
85 /* See if the boot device was passed in */
86 test dword ptr [ebx + MB_INFO_FLAGS_OFFSET], MB_INFO_FLAG_BOOT_DEVICE
88 /* If no boot device known, assume first partition of first harddisk */
92 /* Load boot drive into DL, boot partition into DH */
93 mov edx, [ebx + MB_INFO_BOOT_DEVICE_OFFSET]
98 /* Relocate itself to lower address */
100 mov edi, FREELDR_BASE
101 mov ecx, offset __bss_start__ - FREELDR_BASE
105 /* Load segment registers for real-address mode */
114 /* Jump to relocated code */
119 /* Disable protected mode */
124 /* Jump to real entry point */
125 ljmp16 0, FREELDR_BASE
127 /* Force 8-byte alignment */
130 /* 16-bit flat CS (!) */
136 /* 16-bit real mode DS */
144 .word HEX(17) /* Limit */
145 .long gdt - 8 /* Base Address */