xref: /titanic_52/usr/src/grub/grub-0.97/docs/multiboot.texi (revision 23a1ccea6aac035f084a7a4cdc968687d1b02daf)
1\input texinfo @c -*-texinfo-*-
2@c -*-texinfo-*-
3@c %**start of header
4@setfilename multiboot.info
5@settitle Multiboot Specification
6@c %**end of header
7
8@c Unify all our little indices for now.
9@syncodeindex fn cp
10@syncodeindex vr cp
11@syncodeindex ky cp
12@syncodeindex pg cp
13@syncodeindex tp cp
14
15@footnotestyle separate
16@paragraphindent 3
17@finalout
18
19
20@dircategory Kernel
21@direntry
22* Multiboot Specification: (multiboot).		Multiboot Specification.
23@end direntry
24
25@ifinfo
26Copyright @copyright{} 1995, 96 Bryan Ford <baford@@cs.utah.edu>
27Copyright @copyright{} 1995, 96 Erich Stefan Boleyn <erich@@uruk.org>
28Copyright @copyright{} 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
29
30Permission is granted to make and distribute verbatim copies of
31this manual provided the copyright notice and this permission notice
32are preserved on all copies.
33
34@ignore
35Permission is granted to process this file through TeX and print the
36results, provided the printed document carries a copying permission
37notice identical to this one except for the removal of this paragraph
38(this paragraph not being relevant to the printed manual).
39
40@end ignore
41
42Permission is granted to copy and distribute modified versions of this
43manual under the conditions for verbatim copying, provided also that
44the entire resulting derived work is distributed under the terms of a
45permission notice identical to this one.
46
47Permission is granted to copy and distribute translations of this manual
48into another language, under the above conditions for modified versions.
49@end ifinfo
50
51@titlepage
52@sp 10
53@title The Multiboot Specification
54@author Yoshinori K. Okuji, Bryan Ford, Erich Stefan Boleyn, Kunihiro Ishiguro
55@page
56
57@vskip 0pt plus 1filll
58Copyright @copyright{} 1995, 96 Bryan Ford <baford@@cs.utah.edu>
59Copyright @copyright{} 1995, 96 Erich Stefan Boleyn <erich@@uruk.org>
60Copyright @copyright{} 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
61
62Permission is granted to make and distribute verbatim copies of
63this manual provided the copyright notice and this permission notice
64are preserved on all copies.
65
66Permission is granted to copy and distribute modified versions of this
67manual under the conditions for verbatim copying, provided also that
68the entire resulting derived work is distributed under the terms of a
69permission notice identical to this one.
70
71Permission is granted to copy and distribute translations of this manual
72into another language, under the above conditions for modified versions.
73@end titlepage
74
75@finalout
76@headings double
77
78@ifnottex
79@node Top
80@top Multiboot Specification
81
82This file documents Multiboot Specification, the proposal for the boot
83sequence standard. This edition documents version 0.6.93.
84@end ifnottex
85
86@menu
87* Overview::
88* Terminology::
89* Specification::
90* Examples::
91* History::
92* Index::
93@end menu
94
95
96@node Overview
97@chapter Introduction to Multiboot Specification
98
99This chapter describes some rough information on the Multiboot
100Specification. Note that this is not a part of the specification itself.
101
102@menu
103* Motivation::
104* Architecture::
105* Operating systems::
106* Boot sources::
107* Boot-time configuration::
108* Convenience to operating systems::
109* Boot modules::
110@end menu
111
112
113@node Motivation
114@section The background of Multiboot Specification
115
116Every operating system ever created tends to have its own boot loader.
117Installing a new operating system on a machine generally involves
118installing a whole new set of boot mechanisms, each with completely
119different install-time and boot-time user interfaces. Getting multiple
120operating systems to coexist reliably on one machine through typical
121@dfn{chaining} mechanisms can be a nightmare. There is little or no
122choice of boot loaders for a particular operating system --- if the one
123that comes with the operating system doesn't do exactly what you want,
124or doesn't work on your machine, you're screwed.
125
126While we may not be able to fix this problem in existing commercial
127operating systems, it shouldn't be too difficult for a few people in the
128free operating system communities to put their heads together and solve
129this problem for the popular free operating systems. That's what this
130specification aims for. Basically, it specifies an interface between a
131boot loader and a operating system, such that any complying boot loader
132should be able to load any complying operating system. This
133specification does @emph{not} specify how boot loaders should work ---
134only how they must interface with the operating system being loaded.
135
136
137@node Architecture
138@section The target architecture
139
140This specification is primarily targeted at @sc{pc}, since they are the
141most common and have the largest variety of operating systems and boot
142loaders. However, to the extent that certain other architectures may
143need a boot specification and do not have one already, a variation of
144this specification, stripped of the x86-specific details, could be
145adopted for them as well.
146
147
148@node Operating systems
149@section The target operating systems
150
151This specification is targeted toward free 32-bit operating systems
152that can be fairly easily modified to support the specification without
153going through lots of bureaucratic rigmarole. The particular free
154operating systems that this specification is being primarily designed
155for are Linux, FreeBSD, NetBSD, Mach, and VSTa. It is hoped that other
156emerging free operating systems will adopt it from the start, and thus
157immediately be able to take advantage of existing boot loaders. It would
158be nice if commercial operating system vendors eventually adopted this
159specification as well, but that's probably a pipe dream.
160
161
162@node Boot sources
163@section Boot sources
164
165It should be possible to write compliant boot loaders that load the OS
166image from a variety of sources, including floppy disk, hard disk, and
167across a network.
168
169Disk-based boot loaders may use a variety of techniques to find the
170relevant OS image and boot module data on disk, such as by
171interpretation of specific file systems (e.g. the BSD/Mach boot loader),
172using precalculated @dfn{block lists} (e.g. LILO), loading from a
173special @dfn{boot partition} (e.g. OS/2), or even loading from within
174another operating system (e.g. the VSTa boot code, which loads from
175DOS). Similarly, network-based boot loaders could use a variety of
176network hardware and protocols.
177
178It is hoped that boot loaders will be created that support multiple
179loading mechanisms, increasing their portability, robustness, and
180user-friendliness.
181
182
183@node Boot-time configuration
184@section Configure an operating system at boot-time
185
186It is often necessary for one reason or another for the user to be able
187to provide some configuration information to an operating system
188dynamically at boot time. While this specification should not dictate
189how this configuration information is obtained by the boot loader, it
190should provide a standard means for the boot loader to pass such
191information to the operating system.
192
193
194@node Convenience to operating systems
195@section How to make OS development easier
196
197OS images should be easy to generate. Ideally, an OS image should simply
198be an ordinary 32-bit executable file in whatever file format the
199operating system normally uses. It should be possible to @code{nm} or
200disassemble OS images just like normal executables. Specialized tools
201should not be required to create OS images in a @emph{special} file
202format. If this means shifting some work from the operating system to
203a boot loader, that is probably appropriate, because all the memory
204consumed by the boot loader will typically be made available again after
205the boot process is created, whereas every bit of code in the OS image
206typically has to remain in memory forever. The operating system should
207not have to worry about getting into 32-bit mode initially, because mode
208switching code generally needs to be in the boot loader anyway in order
209to load operating system data above the 1MB boundary, and forcing the
210operating system to do this makes creation of OS images much more
211difficult.
212
213Unfortunately, there is a horrendous variety of executable file formats
214even among free Unix-like @sc{pc}-based operating systems --- generally
215a different format for each operating system. Most of the relevant free
216operating systems use some variant of a.out format, but some are moving
217to @sc{elf}. It is highly desirable for boot loaders not to have to be
218able to interpret all the different types of executable file formats in
219existence in order to load the OS image --- otherwise the boot loader
220effectively becomes operating system specific again.
221
222This specification adopts a compromise solution to this
223problem. Multiboot-compliant OS images always contain a magic
224@dfn{Multiboot header} (@pxref{OS image format}), which allows the boot
225loader to load the image without having to understand numerous a.out
226variants or other executable formats. This magic header does not need to
227be at the very beginning of the executable file, so kernel images can
228still conform to the local a.out format variant in addition to being
229Multiboot-compliant.
230
231
232@node Boot modules
233@section Boot modules
234
235Many modern operating system kernels, such as those of VSTa and Mach, do
236not by themselves contain enough mechanism to get the system fully
237operational: they require the presence of additional software modules at
238boot time in order to access devices, mount file systems, etc. While
239these additional modules could be embedded in the main OS image along
240with the kernel itself, and the resulting image be split apart manually
241by the operating system when it receives control, it is often more
242flexible, more space-efficient, and more convenient to the operating
243system and user if the boot loader can load these additional modules
244independently in the first place.
245
246Thus, this specification should provide a standard method for a boot
247loader to indicate to the operating system what auxiliary boot modules
248were loaded, and where they can be found. Boot loaders don't have to
249support multiple boot modules, but they are strongly encouraged to,
250because some operating systems will be unable to boot without them.
251
252
253@node Terminology
254@chapter The definitions of terms used through the specification
255
256@table @dfn
257@item must
258We use the term @dfn{must}, when any boot loader or OS image needs to
259follow a rule --- otherwise, the boot loader or OS image is @emph{not}
260Multiboot-compliant.
261
262@item should
263We use the term @dfn{should}, when any boot loader or OS image is
264recommended to follow a rule, but it doesn't need to follow the rule.
265
266@item may
267We use the term @dfn{may}, when any boot loader or OS image is allowed
268to follow a rule.
269
270@item boot loader
271Whatever program or set of programs loads the image of the final
272operating system to be run on the machine. The boot loader may itself
273consist of several stages, but that is an implementation detail not
274relevant to this specification. Only the @emph{final} stage of the boot
275loader --- the stage that eventually transfers control to an operating
276system --- must follow the rules specified in this document in order
277to be @dfn{Multiboot-compliant}; earlier boot loader stages may be
278designed in whatever way is most convenient.
279
280@item OS image
281The initial binary image that a boot loader loads into memory and
282transfers control to start an operating system. The OS image is
283typically an executable containing the operating system kernel.
284
285@item boot module
286Other auxiliary files that a boot loader loads into memory along with
287an OS image, but does not interpret in any way other than passing their
288locations to the operating system when it is invoked.
289
290@item Multiboot-compliant
291A boot loader or an OS image which follows the rules defined as
292@dfn{must} is Multiboot-compliant. When this specification specifies a
293rule as @dfn{should} or @dfn{may}, a Multiboot-complaint boot loader/OS
294image doesn't need to follow the rule.
295
296@item u8
297The type of unsigned 8-bit data.
298
299@item u16
300The type of unsigned 16-bit data. Because the target architecture is
301little-endian, u16 is coded in little-endian.
302
303@item u32
304The type of unsigned 32-bit data. Because the target architecture is
305little-endian, u32 is coded in little-endian.
306
307@item u64
308The type of unsigned 64-bit data. Because the target architecture is
309little-endian, u64 is coded in little-endian.
310@end table
311
312
313@node Specification
314@chapter The exact definitions of Multiboot Specification
315
316There are three main aspects of a boot loader/OS image interface:
317
318@enumerate
319@item
320The format of an OS image as seen by a boot loader.
321
322@item
323The state of a machine when a boot loader starts an operating
324system.
325
326@item
327The format of information passed by a boot loader to an operating
328system.
329@end enumerate
330
331@menu
332* OS image format::
333* Machine state::
334* Boot information format::
335@end menu
336
337
338@node OS image format
339@section OS image format
340
341An OS image may be an ordinary 32-bit executable file in the standard
342format for that particular operating system, except that it may be
343linked at a non-default load address to avoid loading on top of the
344@sc{pc}'s I/O region or other reserved areas, and of course it should
345not use shared libraries or other fancy features.
346
347An OS image must contain an additional header called @dfn{Multiboot
348header}, besides the headers of the format used by the OS image. The
349Multiboot header must be contained completely within the first 8192
350bytes of the OS image, and must be longword (32-bit) aligned. In
351general, it should come @emph{as early as possible}, and may be
352embedded in the beginning of the text segment after the @emph{real}
353executable header.
354
355@menu
356* Header layout::               The layout of Multiboot header
357* Header magic fields::         The magic fields of Multiboot header
358* Header address fields::
359* Header graphics fields::
360@end menu
361
362
363@node Header layout
364@subsection The layout of Multiboot header
365
366The layout of the Multiboot header must be as follows:
367
368@multitable @columnfractions .1 .1 .2 .5
369@item Offset @tab Type  @tab Field Name    @tab Note
370@item 0      @tab u32 @tab magic         @tab required
371@item 4      @tab u32 @tab flags         @tab required
372@item 8      @tab u32 @tab checksum      @tab required
373@item 12     @tab u32 @tab header_addr   @tab if flags[16] is set
374@item 16     @tab u32 @tab load_addr     @tab if flags[16] is set
375@item 20     @tab u32 @tab load_end_addr @tab if flags[16] is set
376@item 24     @tab u32 @tab bss_end_addr  @tab if flags[16] is set
377@item 28     @tab u32 @tab entry_addr    @tab if flags[16] is set
378@item 32     @tab u32 @tab mode_type     @tab if flags[2] is set
379@item 36     @tab u32 @tab width         @tab if flags[2] is set
380@item 40     @tab u32 @tab height        @tab if flags[2] is set
381@item 44     @tab u32 @tab depth         @tab if flags[2] is set
382@end multitable
383
384The fields @samp{magic}, @samp{flags} and @samp{checksum} are defined in
385@ref{Header magic fields}, the fields @samp{header_addr},
386@samp{load_addr}, @samp{load_end_addr}, @samp{bss_end_addr} and
387@samp{entry_addr} are defined in @ref{Header address fields}, and the
388fields @samp{mode_type}, @samp{width}, @samp{height} and @samp{depth} are
389defind in @ref{Header graphics fields}.
390
391
392@node Header magic fields
393@subsection The magic fields of Multiboot header
394
395@table @samp
396@item magic
397The field @samp{magic} is the magic number identifying the header,
398which must be the hexadecimal value @code{0x1BADB002}.
399
400@item flags
401The field @samp{flags} specifies features that the OS image requests or
402requires of an boot loader. Bits 0-15 indicate requirements; if the
403boot loader sees any of these bits set but doesn't understand the flag
404or can't fulfill the requirements it indicates for some reason, it must
405notify the user and fail to load the OS image. Bits 16-31 indicate
406optional features; if any bits in this range are set but the boot loader
407doesn't understand them, it may simply ignore them and proceed as
408usual. Naturally, all as-yet-undefined bits in the @samp{flags} word
409must be set to zero in OS images. This way, the @samp{flags} fields
410serves for version control as well as simple feature selection.
411
412If bit 0 in the @samp{flags} word is set, then all boot modules loaded
413along with the operating system must be aligned on page (4KB)
414boundaries. Some operating systems expect to be able to map the pages
415containing boot modules directly into a paged address space during
416startup, and thus need the boot modules to be page-aligned.
417
418If bit 1 in the @samp{flags} word is set, then information on available
419memory via at least the @samp{mem_*} fields of the Multiboot information
420structure (@pxref{Boot information format}) must be included. If the
421boot loader is capable of passing a memory map (the @samp{mmap_*} fields)
422and one exists, then it may be included as well.
423
424If bit 2 in the @samp{flags} word is set, information about the video
425mode table (@pxref{Boot information format}) must be available to the
426kernel.
427
428If bit 16 in the @samp{flags} word is set, then the fields at offsets
4298-24 in the Multiboot header are valid, and the boot loader should use
430them instead of the fields in the actual executable header to calculate
431where to load the OS image. This information does not need to be
432provided if the kernel image is in @sc{elf} format, but it @emph{must}
433be provided if the images is in a.out format or in some other
434format. Compliant boot loaders must be able to load images that either
435are in @sc{elf} format or contain the load address information embedded
436in the Multiboot header; they may also directly support other executable
437formats, such as particular a.out variants, but are not required to.
438
439@item checksum
440The field @samp{checksum} is a 32-bit unsigned value which, when added
441to the other magic fields (i.e. @samp{magic} and @samp{flags}), must
442have a 32-bit unsigned sum of zero.
443@end table
444
445
446@node Header address fields
447@subsection The address fields of Multiboot header
448
449All of the address fields enabled by flag bit 16 are physical addresses.
450The meaning of each is as follows:
451
452@table @code
453@item header_addr
454Contains the address corresponding to the beginning of the Multiboot
455header --- the physical memory location at which the magic value is
456supposed to be loaded. This field serves to @dfn{synchronize} the
457mapping between OS image offsets and physical memory addresses.
458
459@item load_addr
460Contains the physical address of the beginning of the text segment. The
461offset in the OS image file at which to start loading is defined by the
462offset at which the header was found, minus (header_addr -
463load_addr). load_addr must be less than or equal to header_addr.
464
465@item load_end_addr
466Contains the physical address of the end of the data
467segment. (load_end_addr - load_addr) specifies how much data to load.
468This implies that the text and data segments must be consecutive in the
469OS image; this is true for existing a.out executable formats.
470If this field is zero, the boot loader assumes that the text and data
471segments occupy the whole OS image file.
472
473@item bss_end_addr
474Contains the physical address of the end of the bss segment. The boot
475loader initializes this area to zero, and reserves the memory it
476occupies to avoid placing boot modules and other data relevant to the
477operating system in that area. If this field is zero, the boot loader
478assumes that no bss segment is present.
479
480@item entry_addr
481The physical address to which the boot loader should jump in order to
482start running the operating system.
483@end table
484
485
486@node Header graphics fields
487@subsection The graphics fields of Multiboot header
488
489All of the graphics fields are enabled by flag bit 2. They specify the
490preferred graphics mode. Note that that is only a @emph{recommended}
491mode by the OS image. If the mode exists, the boot loader should set
492it, when the user doesn't specify a mode explicitly. Otherwise, the
493boot loader should fall back to a similar mode, if available.
494
495The meaning of each is as follows:
496
497@table @code
498@item mode_type
499Contains @samp{0} for linear graphics mode or @samp{1} for
500EGA-standard text mode. Everything else is reserved for future
501expansion. Note that the boot loader may set a text mode, even if this
502field contains @samp{0}.
503
504@item width
505Contains the number of the columns. This is specified in pixels in a
506graphics mode, and in characters in a text mode. The value zero
507indicates that the OS image has no preference.
508
509@item height
510Contains the number of the lines. This is specified in pixels in a
511graphics mode, and in characters in a text mode. The value zero
512indicates that the OS image has no preference.
513
514@item depth
515Contains the number of bits per pixel in a graphics mode, and zero in
516a text mode. The value zero indicates that the OS image has no
517preference.
518@end table
519
520
521@node Machine state
522@section Machine state
523
524When the boot loader invokes the 32-bit operating system, the machine
525must have the following state:
526
527@table @samp
528@item EAX
529Must contain the magic value @samp{0x2BADB002}; the presence of this
530value indicates to the operating system that it was loaded by a
531Multiboot-compliant boot loader (e.g. as opposed to another type of
532boot loader that the operating system can also be loaded from).
533
534@item EBX
535Must contain the 32-bit physical address of the Multiboot
536information structure provided by the boot loader (@pxref{Boot
537information format}).
538
539@item CS
540Must be a 32-bit read/execute code segment with an offset of @samp{0}
541and a limit of @samp{0xFFFFFFFF}. The exact value is undefined.
542
543@item DS
544@itemx ES
545@itemx FS
546@itemx GS
547@itemx SS
548Must be a 32-bit read/write data segment with an offset of @samp{0}
549and a limit of @samp{0xFFFFFFFF}. The exact values are all undefined.
550
551@item A20 gate
552Must be enabled.
553
554@item CR0
555Bit 31 (PG) must be cleared. Bit 0 (PE) must be set. Other bits are
556all undefined.
557
558@item EFLAGS
559Bit 17 (VM) must be cleared. Bit 9 (IF) must be cleared. Other bits
560are all undefined.
561@end table
562
563All other processor registers and flag bits are undefined. This
564includes, in particular:
565
566@table @samp
567@item ESP
568The OS image must create its own stack as soon as it needs one.
569
570@item GDTR
571Even though the segment registers are set up as described above, the
572@samp{GDTR} may be invalid, so the OS image must not load any segment
573registers (even just reloading the same values!) until it sets up its
574own @samp{GDT}.
575
576@item IDTR
577The OS image must leave interrupts disabled until it sets up its own
578@code{IDT}.
579@end table
580
581However, other machine state should be left by the boot loader in
582@dfn{normal working order}, i.e. as initialized by the @sc{bios} (or
583DOS, if that's what the boot loader runs from). In other words, the
584operating system should be able to make @sc{bios} calls and such after
585being loaded, as long as it does not overwrite the @sc{bios} data
586structures before doing so. Also, the boot loader must leave the
587@sc{pic} programmed with the normal @sc{bios}/DOS values, even if it
588changed them during the switch to 32-bit mode.
589
590
591@node Boot information format
592@section Boot information format
593
594FIXME: Split this chapter like the chapter ``OS image format''.
595
596Upon entry to the operating system, the @code{EBX} register contains the
597physical address of a @dfn{Multiboot information} data structure,
598through which the boot loader communicates vital information to the
599operating system. The operating system can use or ignore any parts of
600the structure as it chooses; all information passed by the boot loader
601is advisory only.
602
603The Multiboot information structure and its related substructures may be
604placed anywhere in memory by the boot loader (with the exception of the
605memory reserved for the kernel and boot modules, of course). It is the
606operating system's responsibility to avoid overwriting this memory until
607it is done using it.
608
609The format of the Multiboot information structure (as defined so far)
610follows:
611
612@example
613@group
614        +-------------------+
6150       | flags             |    (required)
616        +-------------------+
6174       | mem_lower         |    (present if flags[0] is set)
6188       | mem_upper         |    (present if flags[0] is set)
619        +-------------------+
62012      | boot_device       |    (present if flags[1] is set)
621        +-------------------+
62216      | cmdline           |    (present if flags[2] is set)
623        +-------------------+
62420      | mods_count        |    (present if flags[3] is set)
62524      | mods_addr         |    (present if flags[3] is set)
626        +-------------------+
62728 - 40 | syms              |    (present if flags[4] or
628        |                   |                flags[5] is set)
629        +-------------------+
63044      | mmap_length       |    (present if flags[6] is set)
63148      | mmap_addr         |    (present if flags[6] is set)
632        +-------------------+
63352      | drives_length     |    (present if flags[7] is set)
63456      | drives_addr       |    (present if flags[7] is set)
635        +-------------------+
63660      | config_table      |    (present if flags[8] is set)
637        +-------------------+
63864      | boot_loader_name  |    (present if flags[9] is set)
639        +-------------------+
64068      | apm_table         |    (present if flags[10] is set)
641        +-------------------+
64272      | vbe_control_info  |    (present if flags[11] is set)
64376      | vbe_mode_info     |
64480      | vbe_mode          |
64582      | vbe_interface_seg |
64684      | vbe_interface_off |
64786      | vbe_interface_len |
648        +-------------------+
649@end group
650@end example
651
652The first longword indicates the presence and validity of other fields
653in the Multiboot information structure. All as-yet-undefined bits must
654be set to zero by the boot loader. Any set bits that the operating
655system does not understand should be ignored. Thus, the @samp{flags}
656field also functions as a version indicator, allowing the Multiboot
657information structure to be expanded in the future without breaking
658anything.
659
660If bit 0 in the @samp{flags} word is set, then the @samp{mem_*} fields
661are valid. @samp{mem_lower} and @samp{mem_upper} indicate the amount of
662lower and upper memory, respectively, in kilobytes. Lower memory starts
663at address 0, and upper memory starts at address 1 megabyte. The maximum
664possible value for lower memory is 640 kilobytes. The value returned for
665upper memory is maximally the address of the first upper memory hole
666minus 1 megabyte. It is not guaranteed to be this value.
667
668If bit 1 in the @samp{flags} word is set, then the @samp{boot_device}
669field is valid, and indicates which @sc{bios} disk device the boot
670loader loaded the OS image from. If the OS image was not loaded from a
671@sc{bios} disk, then this field must not be present (bit 3 must be
672clear). The operating system may use this field as a hint for
673determining its own @dfn{root} device, but is not required to. The
674@samp{boot_device} field is laid out in four one-byte subfields as
675follows:
676
677@example
678@group
679+-------+-------+-------+-------+
680| drive | part1 | part2 | part3 |
681+-------+-------+-------+-------+
682@end group
683@end example
684
685The first byte contains the @sc{bios} drive number as understood by the
686@sc{bios} INT 0x13 low-level disk interface: e.g. 0x00 for the first
687floppy disk or 0x80 for the first hard disk.
688
689The three remaining bytes specify the boot partition. @samp{part1}
690specifies the @dfn{top-level} partition number, @samp{part2} specifies a
691@dfn{sub-partition} in the top-level partition, etc. Partition numbers
692always start from zero. Unused partition bytes must be set to 0xFF. For
693example, if the disk is partitioned using a simple one-level DOS
694partitioning scheme, then @samp{part1} contains the DOS partition
695number, and @samp{part2} and @samp{part3} are both 0xFF. As another
696example, if a disk is partitioned first into DOS partitions, and then
697one of those DOS partitions is subdivided into several BSD partitions
698using BSD's @dfn{disklabel} strategy, then @samp{part1} contains the DOS
699partition number, @samp{part2} contains the BSD sub-partition within
700that DOS partition, and @samp{part3} is 0xFF.
701
702DOS extended partitions are indicated as partition numbers starting from
7034 and increasing, rather than as nested sub-partitions, even though the
704underlying disk layout of extended partitions is hierarchical in
705nature. For example, if the boot loader boots from the second extended
706partition on a disk partitioned in conventional DOS style, then
707@samp{part1} will be 5, and @samp{part2} and @samp{part3} will both be
7080xFF.
709
710If bit 2 of the @samp{flags} longword is set, the @samp{cmdline} field
711is valid, and contains the physical address of the command line to
712be passed to the kernel. The command line is a normal C-style
713zero-terminated string.
714
715If bit 3 of the @samp{flags} is set, then the @samp{mods} fields
716indicate to the kernel what boot modules were loaded along with the
717kernel image, and where they can be found. @samp{mods_count} contains
718the number of modules loaded; @samp{mods_addr} contains the physical
719address of the first module structure. @samp{mods_count} may be zero,
720indicating no boot modules were loaded, even if bit 1 of @samp{flags} is
721set. Each module structure is formatted as follows:
722
723@example
724@group
725        +-------------------+
7260       | mod_start         |
7274       | mod_end           |
728        +-------------------+
7298       | string            |
730        +-------------------+
73112      | reserved (0)      |
732        +-------------------+
733@end group
734@end example
735
736The first two fields contain the start and end addresses of the boot
737module itself. The @samp{string} field provides an arbitrary string to
738be associated with that particular boot module; it is a zero-terminated
739ASCII string, just like the kernel command line. The @samp{string} field
740may be 0 if there is no string associated with the module. Typically the
741string might be a command line (e.g. if the operating system treats boot
742modules as executable programs), or a pathname (e.g. if the operating
743system treats boot modules as files in a file system), but its exact use
744is specific to the operating system. The @samp{reserved} field must be
745set to 0 by the boot loader and ignored by the operating system.
746
747@strong{Caution:} Bits 4 & 5 are mutually exclusive.
748
749If bit 4 in the @samp{flags} word is set, then the following fields in
750the Multiboot information structure starting at byte 28 are valid:
751
752@example
753@group
754        +-------------------+
75528      | tabsize           |
75632      | strsize           |
75736      | addr              |
75840      | reserved (0)      |
759        +-------------------+
760@end group
761@end example
762
763These indicate where the symbol table from an a.out kernel image can be
764found. @samp{addr} is the physical address of the size (4-byte unsigned
765long) of an array of a.out format @dfn{nlist} structures, followed
766immediately by the array itself, then the size (4-byte unsigned long) of
767a set of zero-terminated @sc{ascii} strings (plus sizeof(unsigned long) in
768this case), and finally the set of strings itself. @samp{tabsize} is
769equal to its size parameter (found at the beginning of the symbol
770section), and @samp{strsize} is equal to its size parameter (found at
771the beginning of the string section) of the following string table to
772which the symbol table refers. Note that @samp{tabsize} may be 0,
773indicating no symbols, even if bit 4 in the @samp{flags} word is set.
774
775If bit 5 in the @samp{flags} word is set, then the following fields in
776the Multiboot information structure starting at byte 28 are valid:
777
778@example
779@group
780        +-------------------+
78128      | num               |
78232      | size              |
78336      | addr              |
78440      | shndx             |
785        +-------------------+
786@end group
787@end example
788
789These indicate where the section header table from an ELF kernel is, the
790size of each entry, number of entries, and the string table used as the
791index of names. They correspond to the @samp{shdr_*} entries
792(@samp{shdr_num}, etc.) in the Executable and Linkable Format (@sc{elf})
793specification in the program header. All sections are loaded, and the
794physical address fields of the @sc{elf} section header then refer to where
795the sections are in memory (refer to the i386 @sc{elf} documentation for
796details as to how to read the section header(s)). Note that
797@samp{shdr_num} may be 0, indicating no symbols, even if bit 5 in the
798@samp{flags} word is set.
799
800If bit 6 in the @samp{flags} word is set, then the @samp{mmap_*} fields
801are valid, and indicate the address and length of a buffer containing a
802memory map of the machine provided by the @sc{bios}. @samp{mmap_addr} is
803the address, and @samp{mmap_length} is the total size of the buffer. The
804buffer consists of one or more of the following size/structure pairs
805(@samp{size} is really used for skipping to the next pair):
806
807@example
808@group
809        +-------------------+
810-4      | size              |
811        +-------------------+
8120       | base_addr_low     |
8134       | base_addr_high    |
8148       | length_low        |
81512      | length_high       |
81616      | type              |
817        +-------------------+
818@end group
819@end example
820
821where @samp{size} is the size of the associated structure in bytes, which
822can be greater than the minimum of 20 bytes. @samp{base_addr_low} is the
823lower 32 bits of the starting address, and @samp{base_addr_high} is the
824upper 32 bits, for a total of a 64-bit starting address. @samp{length_low}
825is the lower 32 bits of the size of the memory region in bytes, and
826@samp{length_high} is the upper 32 bits, for a total of a 64-bit
827length. @samp{type} is the variety of address range represented, where a
828value of 1 indicates available @sc{ram}, and all other values currently
829indicated a reserved area.
830
831The map provided is guaranteed to list all standard @sc{ram} that should
832be available for normal use.
833
834If bit 7 in the @samp{flags} is set, then the @samp{drives_*} fields
835are valid, and indicate the address of the physical address of the first
836drive structure and the size of drive structures. @samp{drives_addr}
837is the address, and @samp{drives_length} is the total size of drive
838structures. Note that @samp{drives_length} may be zero. Each drive
839structure is formatted as follows:
840
841@example
842@group
843        +-------------------+
8440       | size              |
845        +-------------------+
8464       | drive_number      |
847        +-------------------+
8485       | drive_mode        |
849        +-------------------+
8506       | drive_cylinders   |
8518       | drive_heads       |
8529       | drive_sectors     |
853        +-------------------+
85410 - xx | drive_ports       |
855        +-------------------+
856@end group
857@end example
858
859The @samp{size} field specifies the size of this structure. The size
860varies, depending on the number of ports. Note that the size may not be
861equal to (10 + 2 * the number of ports), because of an alignment.
862
863The @samp{drive_number} field contains the BIOS drive number. The
864@samp{drive_mode} field represents the access mode used by the boot
865loader. Currently, the following modes are defined:
866
867@table @samp
868@item 0
869CHS mode (traditional cylinder/head/sector addressing mode).
870
871@item 1
872LBA mode (Logical Block Addressing mode).
873@end table
874
875The three fields, @samp{drive_cylinders}, @samp{drive_heads} and
876@samp{drive_sectors}, indicate the geometry of the drive detected by the
877@sc{bios}. @samp{drive_cylinders} contains the number of the
878cylinders. @samp{drive_heads} contains the number of the
879heads. @samp{drive_sectors} contains the number of the sectors per
880track.
881
882The @samp{drive_ports} field contains the array of the I/O ports used
883for the drive in the @sc{bios} code. The array consists of zero or more
884unsigned two-bytes integers, and is terminated with zero. Note that the
885array may contain any number of I/O ports that are not related to the
886drive actually (such as @sc{dma} controller's ports).
887
888If bit 8 in the @samp{flags} is set, then the @samp{config_table} field
889is valid, and indicates the address of the @sc{rom} configuration table
890returned by the @dfn{GET CONFIGURATION} @sc{bios} call. If the @sc{bios}
891call fails, then the size of the table must be @emph{zero}.
892
893If bit 9 in the @samp{flags} is set, the @samp{boot_loader_name} field
894is valid, and contains the physical address of the name of a boot
895loader booting the kernel. The name is a normal C-style zero-terminated
896string.
897
898If bit 10 in the @samp{flags} is set, the @samp{apm_table} field is
899valid, and contains the physical address of an @sc{apm} table defined as
900below:
901
902@example
903@group
904        +----------------------+
9050       | version              |
9062       | cseg                 |
9074       | offset               |
9088       | cseg_16              |
90910      | dseg                 |
91012      | flags                |
91114      | cseg_len             |
91216      | cseg_16_len          |
91318      | dseg_len             |
914        +----------------------+
915@end group
916@end example
917
918The fields @samp{version}, @samp{cseg}, @samp{offset}, @samp{cseg_16},
919@samp{dseg}, @samp{flags}, @samp{cseg_len}, @samp{cseg_16_len},
920@samp{dseg_len} indicate the version number, the protected mode 32-bit
921code segment, the offset of the entry point, the protected mode 16-bit
922code segment, the protected mode 16-bit data segment, the flags, the
923length of the protected mode 32-bit code segment, the length of the
924protected mode 16-bit code segment, and the length of the protected mode
92516-bit data segment, respectively. Only the field @samp{offset} is 4
926bytes, and the others are 2 bytes. See
927@uref{http://www.microsoft.com/hwdev/busbios/amp_12.htm, Advanced Power
928Management (APM) BIOS Interface Specification}, for more information.
929
930If bit 11 in the @samp{flags} is set, the graphics table is available.
931This must only be done if the kernel has indicated in the
932@samp{Multiboot Header} that it accepts a graphics mode.
933
934The fields @samp{vbe_control_info} and @samp{vbe_mode_info} contain
935the physical addresses of @sc{vbe} control information returned by the
936@sc{vbe} Function 00h and @sc{vbe} mode information returned by the
937@sc{vbe} Function 01h, respectively.
938
939The field @samp{vbe_mode} indicates current video mode in the format
940specified in @sc{vbe} 3.0.
941
942The rest fields @samp{vbe_interface_seg}, @samp{vbe_interface_off}, and
943@samp{vbe_interface_len} contain the table of a protected mode interface
944defined in @sc{vbe} 2.0+. If this information is not available, those
945fields contain zero. Note that @sc{vbe} 3.0 defines another protected
946mode interface which is incompatible with the old one. If you want to
947use the new protected mode interface, you will have to find the table
948yourself.
949
950The fields for the graphics table are designed for @sc{vbe}, but
951Multiboot boot loaders may simulate @sc{vbe} on non-@sc{vbe} modes, as
952if they were @sc{vbe} modes.
953
954
955@node Examples
956@chapter Examples
957
958@strong{Caution:} The following items are not part of the specification
959document, but are included for prospective operating system and boot
960loader writers.
961
962@menu
963* Notes on PC::
964* BIOS device mapping techniques::
965* Example OS code::
966* Example boot loader code::
967@end menu
968
969
970@node Notes on PC
971@section Notes on PC
972
973In reference to bit 0 of the @samp{flags} parameter in the Multiboot
974information structure, if the bootloader in question uses older
975@sc{bios} interfaces, or the newest ones are not available (see
976description about bit 6), then a maximum of either 15 or 63 megabytes of
977memory may be reported. It is @emph{highly} recommended that boot
978loaders perform a thorough memory probe.
979
980In reference to bit 1 of the @samp{flags} parameter in the Multiboot
981information structure, it is recognized that determination of which
982@sc{bios} drive maps to which device driver in an operating system is
983non-trivial, at best. Many kludges have been made to various operating
984systems instead of solving this problem, most of them breaking under
985many conditions. To encourage the use of general-purpose solutions to
986this problem, there are 2 @sc{bios} device mapping techniques
987(@pxref{BIOS device mapping techniques}).
988
989In reference to bit 6 of the @samp{flags} parameter in the Multiboot
990information structure, it is important to note that the data structure
991used there (starting with @samp{BaseAddrLow}) is the data returned by
992the INT 15h, AX=E820h --- Query System Address Map call. See @xref{Query
993System Address Map, , Query System Address Map, grub.info, The GRUB
994Manual}, for more information. The interface here is meant to allow a
995boot loader to work unmodified with any reasonable extensions of the
996@sc{bios} interface, passing along any extra data to be interpreted by
997the operating system as desired.
998
999
1000@node BIOS device mapping techniques
1001@section BIOS device mapping techniques
1002
1003Both of these techniques should be usable from any PC operating system,
1004and neither require any special support in the drivers themselves. This
1005section will be flushed out into detailed explanations, particularly for
1006the I/O restriction technique.
1007
1008The general rule is that the data comparison technique is the quick and
1009dirty solution. It works most of the time, but doesn't cover all the
1010bases, and is relatively simple.
1011
1012The I/O restriction technique is much more complex, but it has potential
1013to solve the problem under all conditions, plus allow access of the
1014remaining @sc{bios} devices when not all of them have operating system
1015drivers.
1016
1017@menu
1018* Data comparison technique::
1019* I/O restriction technique::
1020@end menu
1021
1022
1023@node Data comparison technique
1024@subsection Data comparison technique
1025
1026Before activating @emph{any} of the device drivers, gather enough data
1027from similar sectors on each of the disks such that each one can be
1028uniquely identified.
1029
1030After activating the device drivers, compare data from the drives using
1031the operating system drivers. This should hopefully be sufficient to
1032provide such a mapping.
1033
1034Problems:
1035
1036@enumerate
1037@item
1038The data on some @sc{bios} devices might be identical (so the part
1039reading the drives from the @sc{bios} should have some mechanism to give
1040up).
1041
1042@item
1043There might be extra drives not accessible from the @sc{bios} which are
1044identical to some drive used by the @sc{bios} (so it should be capable
1045of giving up there as well).
1046@end enumerate
1047
1048
1049@node I/O restriction technique
1050@subsection I/O restriction technique
1051
1052This first step may be unnecessary, but first create copy-on-write
1053mappings for the device drivers writing into @sc{pc} @sc{ram}. Keep the
1054original copies for the @dfn{clean @sc{bios} virtual machine} to be
1055created later.
1056
1057For each device driver brought online, determine which @sc{bios} devices
1058become inaccessible by:
1059
1060@enumerate
1061@item
1062Create a @dfn{clean @sc{bios} virtual machine}.
1063
1064@item
1065Set the I/O permission map for the I/O area claimed by the device driver
1066to no permissions (neither read nor write).
1067
1068@item
1069Access each device.
1070
1071@item
1072Record which devices succeed, and those which try to access the
1073@dfn{restricted} I/O areas (hopefully, this will be an @dfn{xor}
1074situation).
1075@end enumerate
1076
1077For each device driver, given how many of the @sc{bios} devices were
1078subsumed by it (there should be no gaps in this list), it should be easy
1079to determine which devices on the controller these are.
1080
1081In general, you have at most 2 disks from each controller given
1082@sc{bios} numbers, but they pretty much always count from the lowest
1083logically numbered devices on the controller.
1084
1085
1086@node Example OS code
1087@section Example OS code
1088
1089In this distribution, the example Multiboot kernel @file{kernel} is
1090included. The kernel just prints out the Multiboot information structure
1091on the screen, so you can make use of the kernel to test a
1092Multiboot-compliant boot loader and for reference to how to implement a
1093Multiboot kernel. The source files can be found under the directory
1094@file{docs} in the GRUB distribution.
1095
1096The kernel @file{kernel} consists of only three files: @file{boot.S},
1097@file{kernel.c} and @file{multiboot.h}. The assembly source
1098@file{boot.S} is written in GAS (@pxref{Top, , GNU assembler, as.info,
1099The GNU assembler}), and contains the Multiboot information structure to
1100comply with the specification. When a Multiboot-compliant boot loader
1101loads and execute it, it initialize the stack pointer and @code{EFLAGS},
1102and then call the function @code{cmain} defined in @file{kernel.c}. If
1103@code{cmain} returns to the callee, then it shows a message to inform
1104the user of the halt state and stops forever until you push the reset
1105key. The file @file{kernel.c} contains the function @code{cmain},
1106which checks if the magic number passed by the boot loader is valid and
1107so on, and some functions to print messages on the screen. The file
1108@file{multiboot.h} defines some macros, such as the magic number for the
1109Multiboot header, the Multiboot header structure and the Multiboot
1110information structure.
1111
1112@menu
1113* multiboot.h::
1114* boot.S::
1115* kernel.c::
1116* Other Multiboot kernels::
1117@end menu
1118
1119
1120@node multiboot.h
1121@subsection multiboot.h
1122
1123This is the source code in the file @file{multiboot.h}:
1124
1125@example
1126@include multiboot.h.texi
1127@end example
1128
1129
1130@node boot.S
1131@subsection boot.S
1132
1133In the file @file{boot.S}:
1134
1135@example
1136@include boot.S.texi
1137@end example
1138
1139
1140@node kernel.c
1141@subsection kernel.c
1142
1143And, in the file @file{kernel.c}:
1144
1145@example
1146@include kernel.c.texi
1147@end example
1148
1149
1150@node Other Multiboot kernels
1151@subsection Other Multiboot kernels
1152
1153Other useful information should be available in Multiboot kernels, such
1154as GNU Mach and Fiasco @url{http://os.inf.tu-dresden.de/fiasco/}. And,
1155it is worth mentioning the OSKit
1156@url{http://www.cs.utah.edu/projects/flux/oskit/}, which provides a
1157library supporting the specification.
1158
1159
1160@node Example boot loader code
1161@section Example boot loader code
1162
1163The GNU GRUB (@pxref{Top, , GRUB, grub.info, The GRUB manual}) project
1164is a full Multiboot-compliant boot loader, supporting all required and
1165optional features present in this specification. A public release has
1166not been made, but the test release is available from:
1167
1168@url{ftp://alpha.gnu.org/gnu/grub}
1169
1170See the webpage @url{http://www.gnu.org/software/grub/grub.html}, for
1171more information.
1172
1173
1174@node History
1175@chapter The change log of this specification
1176
1177@table @asis
1178@item 0.7
1179@itemize @bullet
1180@item
1181@dfn{Multiboot Standard} is renamed to @dfn{Multiboot Specification}.
1182
1183@item
1184Graphics fields are added to Multiboot header.
1185
1186@item
1187BIOS drive information, BIOS configuration table, the name of a boot
1188loader, APM information, and graphics information are added to Multiboot
1189information.
1190
1191@item
1192Rewritten in Texinfo format.
1193
1194@item
1195Rewritten, using more strict words.
1196
1197@item
1198The maintainer changes to the GNU GRUB maintainer team
1199@email{bug-grub@@gnu.org}, from Bryan Ford and Erich Stefan Boleyn.
1200@end itemize
1201
1202@item 0.6
1203@itemize @bullet
1204@item
1205A few wording changes.
1206
1207@item
1208Header checksum.
1209
1210@item
1211Clasification of machine state passed to an operating system.
1212@end itemize
1213
1214@item 0.5
1215@itemize @bullet
1216@item
1217Name change.
1218@end itemize
1219
1220@item 0.4
1221@itemize @bullet
1222@item
1223Major changes plus HTMLification.
1224@end itemize
1225@end table
1226
1227
1228@node Index
1229@unnumbered Index
1230
1231@printindex cp
1232
1233@contents
1234@bye
1235