2
* GRUB -- GRand Unified Bootloader
3
* Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc.
5
* GRUB 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 3 of the License, or
8
* (at your option) any later version.
10
* GRUB 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
16
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19
#include <grub/memory.h>
20
#ifdef GRUB_MACHINE_PCBIOS
21
#include <grub/machine/biosnum.h>
22
#include <grub/machine/apm.h>
23
#include <grub/machine/memory.h>
25
#include <grub/multiboot.h>
26
#include <grub/cpu/multiboot.h>
27
#include <grub/cpu/relocator.h>
28
#include <grub/disk.h>
29
#include <grub/device.h>
30
#include <grub/partition.h>
32
#include <grub/misc.h>
34
#include <grub/video.h>
35
#include <grub/acpi.h>
37
#if defined (GRUB_MACHINE_EFI)
38
#include <grub/efi/efi.h>
41
#if defined (GRUB_MACHINE_PCBIOS) || defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_MULTIBOOT) || defined (GRUB_MACHINE_QEMU)
42
#include <grub/i386/pc/vbe.h>
43
#define HAS_VGA_TEXT 1
45
#define HAS_VGA_TEXT 0
57
struct module *modules, *modules_last;
58
static grub_size_t cmdline_size;
59
static grub_size_t total_modcmd;
60
static unsigned modcnt;
61
static char *cmdline = NULL;
62
static int bootdev_set;
63
static grub_uint32_t biosdev, slice, part;
64
static grub_size_t elf_sec_num, elf_sec_entsize;
65
static unsigned elf_sec_shstrndx;
66
static void *elf_sections;
69
grub_multiboot_add_elfsyms (grub_size_t num, grub_size_t entsize,
70
unsigned shndx, void *data)
73
elf_sec_shstrndx = shndx;
74
elf_sec_entsize = entsize;
79
grub_multiboot_load (grub_file_t file)
83
struct multiboot_header *header;
85
struct multiboot_header_tag *tag;
86
struct multiboot_header_tag_address *addr_tag = NULL;
87
int entry_specified = 0;
88
grub_addr_t entry = 0;
89
grub_uint32_t console_required = 0;
90
struct multiboot_header_tag_framebuffer *fbtag = NULL;
91
int accepted_consoles = GRUB_MULTIBOOT_CONSOLE_EGA_TEXT;
93
buffer = grub_malloc (MULTIBOOT_SEARCH);
97
len = grub_file_read (file, buffer, MULTIBOOT_SEARCH);
101
return grub_error (GRUB_ERR_BAD_OS, "file too small");
104
/* Look for the multiboot header in the buffer. The header should
105
be at least 12 bytes and aligned on a 4-byte boundary. */
106
for (header = (struct multiboot_header *) buffer;
107
((char *) header <= buffer + len - 12) || (header = 0);
108
header = (struct multiboot_header *) ((char *) header + MULTIBOOT_HEADER_ALIGN))
110
if (header->magic == MULTIBOOT_HEADER_MAGIC
111
&& !(header->magic + header->architecture
112
+ header->header_length + header->checksum)
113
&& header->architecture == MULTIBOOT_ARCHITECTURE_CURRENT)
120
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no multiboot header found");
123
for (tag = (struct multiboot_header_tag *) (header + 1);
124
tag->type != MULTIBOOT_TAG_TYPE_END;
125
tag = (struct multiboot_header_tag *) ((char *) tag + tag->size))
128
case MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST:
131
struct multiboot_header_tag_information_request *request_tag
132
= (struct multiboot_header_tag_information_request *) tag;
133
if (request_tag->flags & MULTIBOOT_HEADER_TAG_OPTIONAL)
135
for (i = 0; i < (request_tag->size - sizeof (request_tag))
136
/ sizeof (request_tag->requests[0]); i++)
137
switch (request_tag->requests[i])
139
case MULTIBOOT_TAG_TYPE_END:
140
case MULTIBOOT_TAG_TYPE_CMDLINE:
141
case MULTIBOOT_TAG_TYPE_BOOT_LOADER_NAME:
142
case MULTIBOOT_TAG_TYPE_MODULE:
143
case MULTIBOOT_TAG_TYPE_BASIC_MEMINFO:
144
case MULTIBOOT_TAG_TYPE_BOOTDEV:
145
case MULTIBOOT_TAG_TYPE_MMAP:
146
case MULTIBOOT_TAG_TYPE_FRAMEBUFFER:
147
case MULTIBOOT_TAG_TYPE_VBE:
148
case MULTIBOOT_TAG_TYPE_ELF_SECTIONS:
149
case MULTIBOOT_TAG_TYPE_APM:
150
case MULTIBOOT_TAG_TYPE_EFI32:
151
case MULTIBOOT_TAG_TYPE_EFI64:
152
case MULTIBOOT_TAG_TYPE_ACPI_OLD:
153
case MULTIBOOT_TAG_TYPE_ACPI_NEW:
158
return grub_error (GRUB_ERR_UNKNOWN_OS,
159
"unsupported information tag: 0x%x",
160
request_tag->requests[i]);
165
case MULTIBOOT_HEADER_TAG_ADDRESS:
166
addr_tag = (struct multiboot_header_tag_address *) tag;
169
case MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS:
171
entry = ((struct multiboot_header_tag_entry_address *) tag)->entry_addr;
174
case MULTIBOOT_HEADER_TAG_CONSOLE_FLAGS:
175
if (!(((struct multiboot_header_tag_console_flags *) tag)->console_flags
176
& MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED))
177
accepted_consoles &= ~GRUB_MULTIBOOT_CONSOLE_EGA_TEXT;
178
if (((struct multiboot_header_tag_console_flags *) tag)->console_flags
179
& MULTIBOOT_CONSOLE_FLAGS_CONSOLE_REQUIRED)
180
console_required = 1;
183
case MULTIBOOT_HEADER_TAG_FRAMEBUFFER:
184
fbtag = (struct multiboot_header_tag_framebuffer *) tag;
185
accepted_consoles |= GRUB_MULTIBOOT_CONSOLE_FRAMEBUFFER;
188
/* GRUB always page-aligns modules. */
189
case MULTIBOOT_HEADER_TAG_MODULE_ALIGN:
193
if (! (tag->flags & MULTIBOOT_HEADER_TAG_OPTIONAL))
196
return grub_error (GRUB_ERR_UNKNOWN_OS,
197
"unsupported tag: 0x%x", tag->type);
202
if (addr_tag && !entry_specified)
205
return grub_error (GRUB_ERR_UNKNOWN_OS,
206
"load address tag without entry address tag");
211
int offset = ((char *) header - buffer -
212
(addr_tag->header_addr - addr_tag->load_addr));
213
int load_size = ((addr_tag->load_end_addr == 0) ? file->size - offset :
214
addr_tag->load_end_addr - addr_tag->load_addr);
215
grub_size_t code_size;
217
grub_relocator_chunk_t ch;
219
if (addr_tag->bss_end_addr)
220
code_size = (addr_tag->bss_end_addr - addr_tag->load_addr);
222
code_size = load_size;
224
err = grub_relocator_alloc_chunk_addr (grub_multiboot_relocator,
225
&ch, addr_tag->load_addr,
229
grub_dprintf ("multiboot_loader", "Error loading aout kludge\n");
233
source = get_virtual_current_address (ch);
235
if ((grub_file_seek (file, offset)) == (grub_off_t) -1)
241
grub_file_read (file, source, load_size);
248
if (addr_tag->bss_end_addr)
249
grub_memset ((grub_uint32_t *) source + load_size, 0,
250
addr_tag->bss_end_addr - addr_tag->load_addr - load_size);
254
err = grub_multiboot_load_elf (file, buffer);
263
grub_multiboot_payload_eip = entry;
266
err = grub_multiboot_set_console (GRUB_MULTIBOOT_CONSOLE_FRAMEBUFFER,
268
fbtag->width, fbtag->height,
269
fbtag->depth, console_required);
271
err = grub_multiboot_set_console (GRUB_MULTIBOOT_CONSOLE_EGA_TEXT,
273
0, 0, 0, console_required);
280
#if GRUB_MACHINE_HAS_ACPI
281
struct grub_acpi_rsdp_v20 *p = grub_acpi_get_rsdpv2 ();
286
return ALIGN_UP (sizeof (struct multiboot_tag_old_acpi)
287
+ p->length, MULTIBOOT_TAG_ALIGN);
294
grub_multiboot_get_mbi_size (void)
296
return 2 * sizeof (grub_uint32_t) + sizeof (struct multiboot_tag)
297
+ (sizeof (struct multiboot_tag_string)
298
+ ALIGN_UP (cmdline_size, MULTIBOOT_TAG_ALIGN))
299
+ (sizeof (struct multiboot_tag_string)
300
+ ALIGN_UP (sizeof (PACKAGE_STRING), MULTIBOOT_TAG_ALIGN))
301
+ (modcnt * sizeof (struct multiboot_tag_module) + total_modcmd)
302
+ ALIGN_UP (sizeof (struct multiboot_tag_basic_meminfo),
304
+ ALIGN_UP (sizeof (struct multiboot_tag_bootdev), MULTIBOOT_TAG_ALIGN)
305
+ ALIGN_UP (sizeof (struct multiboot_tag_elf_sections), MULTIBOOT_TAG_ALIGN)
306
+ ALIGN_UP (elf_sec_entsize * elf_sec_num, MULTIBOOT_TAG_ALIGN)
307
+ ALIGN_UP ((sizeof (struct multiboot_tag_mmap)
308
+ grub_get_multiboot_mmap_count ()
309
* sizeof (struct multiboot_mmap_entry)), MULTIBOOT_TAG_ALIGN)
310
+ ALIGN_UP (sizeof (struct multiboot_tag_framebuffer), MULTIBOOT_TAG_ALIGN)
311
+ ALIGN_UP (sizeof (struct multiboot_tag_efi32), MULTIBOOT_TAG_ALIGN)
312
+ ALIGN_UP (sizeof (struct multiboot_tag_efi64), MULTIBOOT_TAG_ALIGN)
313
+ ALIGN_UP (sizeof (struct multiboot_tag_old_acpi)
314
+ sizeof (struct grub_acpi_rsdp_v10), MULTIBOOT_TAG_ALIGN)
316
+ sizeof (struct multiboot_tag_vbe) + MULTIBOOT_TAG_ALIGN - 1
317
+ sizeof (struct multiboot_tag_apm) + MULTIBOOT_TAG_ALIGN - 1;
320
/* Fill previously allocated Multiboot mmap. */
322
grub_fill_multiboot_mmap (struct multiboot_tag_mmap *tag)
324
struct multiboot_mmap_entry *mmap_entry = tag->entries;
326
auto int NESTED_FUNC_ATTR hook (grub_uint64_t, grub_uint64_t,
328
int NESTED_FUNC_ATTR hook (grub_uint64_t addr, grub_uint64_t size,
329
grub_memory_type_t type)
331
mmap_entry->addr = addr;
332
mmap_entry->len = size;
335
case GRUB_MEMORY_AVAILABLE:
336
mmap_entry->type = MULTIBOOT_MEMORY_AVAILABLE;
339
case GRUB_MEMORY_ACPI:
340
mmap_entry->type = MULTIBOOT_MEMORY_ACPI_RECLAIMABLE;
343
case GRUB_MEMORY_NVS:
344
mmap_entry->type = MULTIBOOT_MEMORY_NVS;
347
case GRUB_MEMORY_BADRAM:
348
mmap_entry->type = MULTIBOOT_MEMORY_BADRAM;
352
mmap_entry->type = MULTIBOOT_MEMORY_RESERVED;
360
tag->type = MULTIBOOT_TAG_TYPE_MMAP;
361
tag->size = sizeof (struct multiboot_tag_mmap)
362
+ sizeof (struct multiboot_mmap_entry) * grub_get_multiboot_mmap_count ();
363
tag->entry_size = sizeof (struct multiboot_mmap_entry);
364
tag->entry_version = 0;
366
grub_mmap_iterate (hook);
369
#if defined (GRUB_MACHINE_PCBIOS)
371
fill_vbe_tag (struct multiboot_tag_vbe *tag)
373
grub_vbe_status_t status;
374
void *scratch = (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR;
376
tag->type = MULTIBOOT_TAG_TYPE_VBE;
379
status = grub_vbe_bios_get_controller_info (scratch);
380
if (status != GRUB_VBE_STATUS_OK)
383
grub_memcpy (&tag->vbe_control_info, scratch,
384
sizeof (struct grub_vbe_info_block));
386
status = grub_vbe_bios_get_mode (scratch);
387
tag->vbe_mode = *(grub_uint32_t *) scratch;
388
if (status != GRUB_VBE_STATUS_OK)
391
/* get_mode_info isn't available for mode 3. */
392
if (tag->vbe_mode == 3)
394
struct grub_vbe_mode_info_block *mode_info = (void *) &tag->vbe_mode_info;
395
grub_memset (mode_info, 0,
396
sizeof (struct grub_vbe_mode_info_block));
397
mode_info->memory_model = GRUB_VBE_MEMORY_MODEL_TEXT;
398
mode_info->x_resolution = 80;
399
mode_info->y_resolution = 25;
403
status = grub_vbe_bios_get_mode_info (tag->vbe_mode, scratch);
404
if (status != GRUB_VBE_STATUS_OK)
406
grub_memcpy (&tag->vbe_mode_info, scratch,
407
sizeof (struct grub_vbe_mode_info_block));
409
grub_vbe_bios_get_pm_interface (&tag->vbe_interface_seg,
410
&tag->vbe_interface_off,
411
&tag->vbe_interface_len);
413
tag->size = sizeof (*tag);
418
retrieve_video_parameters (grub_uint8_t **ptrorig)
421
struct grub_video_mode_info mode_info;
423
grub_video_driver_id_t driv_id;
424
struct grub_video_palette_data palette[256];
425
struct multiboot_tag_framebuffer *tag
426
= (struct multiboot_tag_framebuffer *) *ptrorig;
428
err = grub_multiboot_set_video_mode ();
432
grub_errno = GRUB_ERR_NONE;
435
grub_video_get_palette (0, ARRAY_SIZE (palette), palette);
437
driv_id = grub_video_get_driver_id ();
439
if (driv_id == GRUB_VIDEO_DRIVER_NONE)
441
struct grub_vbe_mode_info_block vbe_mode_info;
442
grub_uint32_t vbe_mode;
444
#if defined (GRUB_MACHINE_PCBIOS)
446
grub_vbe_status_t status;
447
void *scratch = (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR;
448
status = grub_vbe_bios_get_mode (scratch);
449
vbe_mode = *(grub_uint32_t *) scratch;
450
if (status != GRUB_VBE_STATUS_OK)
451
return GRUB_ERR_NONE;
457
/* get_mode_info isn't available for mode 3. */
460
grub_memset (&vbe_mode_info, 0,
461
sizeof (struct grub_vbe_mode_info_block));
462
vbe_mode_info.memory_model = GRUB_VBE_MEMORY_MODEL_TEXT;
463
vbe_mode_info.x_resolution = 80;
464
vbe_mode_info.y_resolution = 25;
466
#if defined (GRUB_MACHINE_PCBIOS)
469
grub_vbe_status_t status;
470
void *scratch = (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR;
471
status = grub_vbe_bios_get_mode_info (vbe_mode, scratch);
472
if (status != GRUB_VBE_STATUS_OK)
473
return GRUB_ERR_NONE;
474
grub_memcpy (&vbe_mode_info, scratch,
475
sizeof (struct grub_vbe_mode_info_block));
479
if (vbe_mode_info.memory_model == GRUB_VBE_MEMORY_MODEL_TEXT)
481
tag = (struct multiboot_tag_framebuffer *) *ptrorig;
482
tag->common.type = MULTIBOOT_TAG_TYPE_FRAMEBUFFER;
483
tag->common.size = 0;
485
tag->common.framebuffer_addr = 0xb8000;
487
tag->common.framebuffer_pitch = 2 * vbe_mode_info.x_resolution;
488
tag->common.framebuffer_width = vbe_mode_info.x_resolution;
489
tag->common.framebuffer_height = vbe_mode_info.y_resolution;
491
tag->common.framebuffer_bpp = 16;
493
tag->common.framebuffer_type = MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT;
494
tag->common.size = sizeof (tag->common);
495
tag->common.reserved = 0;
496
*ptrorig += ALIGN_UP (tag->common.size, MULTIBOOT_TAG_ALIGN);
498
return GRUB_ERR_NONE;
501
if (driv_id == GRUB_VIDEO_DRIVER_NONE)
502
return GRUB_ERR_NONE;
505
#if GRUB_MACHINE_HAS_VBE
507
struct multiboot_tag_vbe *tag_vbe = (struct multiboot_tag_vbe *) *ptrorig;
509
fill_vbe_tag (tag_vbe);
511
*ptrorig += ALIGN_UP (tag_vbe->size, MULTIBOOT_TAG_ALIGN);
515
err = grub_video_get_info_and_fini (&mode_info, &framebuffer);
519
tag = (struct multiboot_tag_framebuffer *) *ptrorig;
520
tag->common.type = MULTIBOOT_TAG_TYPE_FRAMEBUFFER;
521
tag->common.size = 0;
523
tag->common.framebuffer_addr = (grub_addr_t) framebuffer;
524
tag->common.framebuffer_pitch = mode_info.pitch;
526
tag->common.framebuffer_width = mode_info.width;
527
tag->common.framebuffer_height = mode_info.height;
529
tag->common.framebuffer_bpp = mode_info.bpp;
531
tag->common.reserved = 0;
533
if (mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_INDEX_COLOR)
536
tag->common.framebuffer_type = MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED;
537
tag->framebuffer_palette_num_colors = mode_info.number_of_colors;
538
if (tag->framebuffer_palette_num_colors > ARRAY_SIZE (palette))
539
tag->framebuffer_palette_num_colors = ARRAY_SIZE (palette);
540
tag->common.size = sizeof (struct multiboot_tag_framebuffer_common)
541
+ sizeof (multiboot_uint16_t) + tag->framebuffer_palette_num_colors
542
* sizeof (struct multiboot_color);
543
for (i = 0; i < tag->framebuffer_palette_num_colors; i++)
545
tag->framebuffer_palette[i].red = palette[i].r;
546
tag->framebuffer_palette[i].green = palette[i].g;
547
tag->framebuffer_palette[i].blue = palette[i].b;
552
tag->common.framebuffer_type = MULTIBOOT_FRAMEBUFFER_TYPE_RGB;
553
tag->framebuffer_red_field_position = mode_info.red_field_pos;
554
tag->framebuffer_red_mask_size = mode_info.red_mask_size;
555
tag->framebuffer_green_field_position = mode_info.green_field_pos;
556
tag->framebuffer_green_mask_size = mode_info.green_mask_size;
557
tag->framebuffer_blue_field_position = mode_info.blue_field_pos;
558
tag->framebuffer_blue_mask_size = mode_info.blue_mask_size;
560
tag->common.size = sizeof (struct multiboot_tag_framebuffer_common) + 6;
562
*ptrorig += ALIGN_UP (tag->common.size, MULTIBOOT_TAG_ALIGN);
564
return GRUB_ERR_NONE;
568
grub_multiboot_make_mbi (grub_uint32_t *target)
570
grub_uint8_t *ptrorig;
571
grub_uint8_t *mbistart;
574
grub_relocator_chunk_t ch;
576
bufsize = grub_multiboot_get_mbi_size ();
578
err = grub_relocator_alloc_chunk_align (grub_multiboot_relocator, &ch,
579
0, 0xffffffff - bufsize,
580
bufsize, MULTIBOOT_TAG_ALIGN,
581
GRUB_RELOCATOR_PREFERENCE_NONE);
585
ptrorig = get_virtual_current_address (ch);
586
#if defined (__i386__) || defined (__x86_64__)
587
*target = get_physical_target_address (ch);
588
#elif defined (__mips)
589
*target = get_physical_target_address (ch) | 0x80000000;
591
#error Please complete this
595
ptrorig += 2 * sizeof (grub_uint32_t);
598
struct multiboot_tag_string *tag = (struct multiboot_tag_string *) ptrorig;
599
tag->type = MULTIBOOT_TAG_TYPE_CMDLINE;
600
tag->size = sizeof (struct multiboot_tag_string) + cmdline_size;
601
grub_memcpy (tag->string, cmdline, cmdline_size);
602
ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN);
606
struct multiboot_tag_string *tag = (struct multiboot_tag_string *) ptrorig;
607
tag->type = MULTIBOOT_TAG_TYPE_BOOT_LOADER_NAME;
608
tag->size = sizeof (struct multiboot_tag_string) + sizeof (PACKAGE_STRING);
609
grub_memcpy (tag->string, PACKAGE_STRING, sizeof (PACKAGE_STRING));
610
ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN);
613
#ifdef GRUB_MACHINE_PCBIOS
615
struct grub_apm_info info;
616
if (grub_apm_get_info (&info))
618
struct multiboot_tag_apm *tag = (struct multiboot_tag_apm *) ptrorig;
620
tag->type = MULTIBOOT_TAG_TYPE_APM;
621
tag->size = sizeof (struct multiboot_tag_apm);
623
tag->cseg = info.cseg;
624
tag->offset = info.offset;
625
tag->cseg_16 = info.cseg_16;
626
tag->dseg = info.dseg;
627
tag->flags = info.flags;
628
tag->cseg_len = info.cseg_len;
629
tag->dseg_len = info.dseg_len;
630
tag->cseg_16_len = info.cseg_16_len;
631
tag->version = info.version;
633
ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN);
642
for (i = 0, cur = modules; i < modcnt; i++, cur = cur->next)
644
struct multiboot_tag_module *tag
645
= (struct multiboot_tag_module *) ptrorig;
646
tag->type = MULTIBOOT_TAG_TYPE_MODULE;
647
tag->size = sizeof (struct multiboot_tag_module) + cur->cmdline_size;
648
tag->mod_start = cur->start;
649
tag->mod_end = tag->mod_start + cur->size;
650
grub_memcpy (tag->cmdline, cur->cmdline, cur->cmdline_size);
651
ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN);
656
struct multiboot_tag_mmap *tag = (struct multiboot_tag_mmap *) ptrorig;
657
grub_fill_multiboot_mmap (tag);
658
ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN);
662
struct multiboot_tag_elf_sections *tag
663
= (struct multiboot_tag_elf_sections *) ptrorig;
664
tag->type = MULTIBOOT_TAG_TYPE_ELF_SECTIONS;
665
tag->size = sizeof (struct multiboot_tag_elf_sections)
666
+ elf_sec_entsize * elf_sec_num;
667
grub_memcpy (tag->sections, elf_sections, elf_sec_entsize * elf_sec_num);
668
tag->num = elf_sec_num;
669
tag->entsize = elf_sec_entsize;
670
tag->shndx = elf_sec_shstrndx;
671
ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN);
675
struct multiboot_tag_basic_meminfo *tag
676
= (struct multiboot_tag_basic_meminfo *) ptrorig;
677
tag->type = MULTIBOOT_TAG_TYPE_BASIC_MEMINFO;
678
tag->size = sizeof (struct multiboot_tag_basic_meminfo);
680
/* Convert from bytes to kilobytes. */
681
tag->mem_lower = grub_mmap_get_lower () / 1024;
682
tag->mem_upper = grub_mmap_get_upper () / 1024;
683
ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN);
688
struct multiboot_tag_bootdev *tag
689
= (struct multiboot_tag_bootdev *) ptrorig;
690
tag->type = MULTIBOOT_TAG_TYPE_BOOTDEV;
691
tag->size = sizeof (struct multiboot_tag_bootdev);
693
tag->biosdev = biosdev;
696
ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN);
700
err = retrieve_video_parameters (&ptrorig);
704
grub_errno = GRUB_ERR_NONE;
708
#if defined (GRUB_MACHINE_EFI) && defined (__x86_64__)
710
struct multiboot_tag_efi64 *tag = (struct multiboot_tag_efi64 *) ptrorig;
711
tag->type = MULTIBOOT_TAG_TYPE_EFI64;
712
tag->size = sizeof (*tag);
713
tag->pointer = (grub_addr_t) grub_efi_system_table;
714
ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN);
718
#if defined (GRUB_MACHINE_EFI) && defined (__i386__)
720
struct multiboot_tag_efi32 *tag = (struct multiboot_tag_efi32 *) ptrorig;
721
tag->type = MULTIBOOT_TAG_TYPE_EFI32;
722
tag->size = sizeof (*tag);
723
tag->pointer = (grub_addr_t) grub_efi_system_table;
724
ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN);
728
#if GRUB_MACHINE_HAS_ACPI
730
struct multiboot_tag_old_acpi *tag = (struct multiboot_tag_old_acpi *)
732
struct grub_acpi_rsdp_v10 *a = grub_acpi_get_rsdpv1 ();
735
tag->type = MULTIBOOT_TAG_TYPE_ACPI_OLD;
736
tag->size = sizeof (*tag) + sizeof (*a);
737
grub_memcpy (tag->rsdp, a, sizeof (*a));
738
ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN);
743
struct multiboot_tag_new_acpi *tag = (struct multiboot_tag_new_acpi *)
745
struct grub_acpi_rsdp_v20 *a = grub_acpi_get_rsdpv2 ();
748
tag->type = MULTIBOOT_TAG_TYPE_ACPI_NEW;
749
tag->size = sizeof (*tag) + a->length;
750
grub_memcpy (tag->rsdp, a, a->length);
751
ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN);
757
struct multiboot_tag *tag = (struct multiboot_tag *) ptrorig;
758
tag->type = MULTIBOOT_TAG_TYPE_END;
759
tag->size = sizeof (struct multiboot_tag);
760
ptrorig += ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN);
763
((grub_uint32_t *) mbistart)[0] = ptrorig - mbistart;
764
((grub_uint32_t *) mbistart)[1] = 0;
766
return GRUB_ERR_NONE;
770
grub_multiboot_free_mbi (void)
772
struct module *cur, *next;
781
for (cur = modules; cur; cur = next)
784
grub_free (cur->cmdline);
792
grub_multiboot_init_mbi (int argc, char *argv[])
794
grub_ssize_t len = 0;
798
grub_multiboot_free_mbi ();
800
for (i = 0; i < argc; i++)
801
len += grub_strlen (argv[i]) + 1;
805
cmdline = p = grub_malloc (len);
810
for (i = 0; i < argc; i++)
812
p = grub_stpcpy (p, argv[i]);
816
/* Remove the space after the last word. */
821
return GRUB_ERR_NONE;
825
grub_multiboot_add_module (grub_addr_t start, grub_size_t size,
826
int argc, char *argv[])
828
struct module *newmod;
830
grub_ssize_t len = 0;
833
newmod = grub_malloc (sizeof (*newmod));
836
newmod->start = start;
839
for (i = 0; i < argc; i++)
840
len += grub_strlen (argv[i]) + 1;
845
newmod->cmdline = p = grub_malloc (len);
846
if (! newmod->cmdline)
851
newmod->cmdline_size = len;
852
total_modcmd += ALIGN_UP (len, MULTIBOOT_TAG_ALIGN);
854
for (i = 0; i < argc; i++)
856
p = grub_stpcpy (p, argv[i]);
860
/* Remove the space after the last word. */
861
if (p != newmod->cmdline)
866
modules_last->next = newmod;
870
modules_last->next = NULL;
872
modules_last = newmod;
876
return GRUB_ERR_NONE;
880
grub_multiboot_set_bootdev (void)
887
#ifdef GRUB_MACHINE_PCBIOS
888
biosdev = grub_get_root_biosnumber ();
890
biosdev = 0xffffffff;
893
if (biosdev == 0xffffffff)
896
dev = grub_device_open (0);
897
if (dev && dev->disk && dev->disk->partition)
899
if (dev->disk->partition->parent)
901
part = dev->disk->partition->number;
902
slice = dev->disk->partition->parent->number;
905
slice = dev->disk->partition->number;
908
grub_device_close (dev);