⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 multiboot.texi

📁 i386的bootloader源码grub
💻 TEXI
📖 第 1 页 / 共 4 页
字号:
@end table@node Specification@chapter The exact definitions of Multiboot SpecificationThere are three main aspects of a boot loader/OS image interface:@enumerate@itemThe format of an OS image as seen by a boot loader.@itemThe state of a machine when a boot loader starts an operatingsystem.@itemThe format of information passed by a boot loader to an operatingsystem.@end enumerate@menu* OS image format::             * Machine state::               * Boot information format::     @end menu@node OS image format@section OS image formatAn OS image may be an ordinary 32-bit executable file in the standardformat for that particular operating system, except that it may belinked at a non-default load address to avoid loading on top of the@sc{pc}'s I/O region or other reserved areas, and of course it shouldnot use shared libraries or other fancy features.An OS image must contain an additional header called @dfn{Multibootheader}, besides the headers of the format used by the OS image. TheMultiboot header must be contained completely within the first 8192bytes of the OS image, and must be longword (32-bit) aligned. Ingeneral, it should come @emph{as early as possible}, and may beembedded in the beginning of the text segment after the @emph{real}executable header.@menu* Header layout::               The layout of Multiboot header* Header magic fields::         The magic fields of Multiboot header* Header address fields::       * Header graphics fields::      @end menu@node Header layout@subsection The layout of Multiboot headerThe layout of the Multiboot header must be as follows:@multitable @columnfractions .1 .1 .2 .5@item Offset @tab Type  @tab Field Name    @tab Note@item 0      @tab u32 @tab magic         @tab required@item 4      @tab u32 @tab flags         @tab required@item 8      @tab u32 @tab checksum      @tab required@item 12     @tab u32 @tab header_addr   @tab if flags[16] is set@item 16     @tab u32 @tab load_addr     @tab if flags[16] is set@item 20     @tab u32 @tab load_end_addr @tab if flags[16] is set@item 24     @tab u32 @tab bss_end_addr  @tab if flags[16] is set@item 28     @tab u32 @tab entry_addr    @tab if flags[16] is set@item 32     @tab u32 @tab mode_type     @tab if flags[2] is set@item 36     @tab u32 @tab width         @tab if flags[2] is set@item 40     @tab u32 @tab height        @tab if flags[2] is set@item 44     @tab u32 @tab depth         @tab if flags[2] is set@end multitableThe fields @samp{magic}, @samp{flags} and @samp{checksum} are defined in@ref{Header magic fields}, the fields @samp{header_addr},@samp{load_addr}, @samp{load_end_addr}, @samp{bss_end_addr} and@samp{entry_addr} are defined in @ref{Header address fields}, and thefields @samp{mode_type}, @samp{width}, @samp{height} and @samp{depth} aredefind in @ref{Header graphics fields}.@node Header magic fields@subsection The magic fields of Multiboot header@table @samp@item magicThe field @samp{magic} is the magic number identifying the header,which must be the hexadecimal value @code{0x1BADB002}.@item flagsThe field @samp{flags} specifies features that the OS image requests orrequires of an boot loader. Bits 0-15 indicate requirements; if theboot loader sees any of these bits set but doesn't understand the flagor can't fulfill the requirements it indicates for some reason, it mustnotify the user and fail to load the OS image. Bits 16-31 indicateoptional features; if any bits in this range are set but the boot loaderdoesn't understand them, it may simply ignore them and proceed asusual. Naturally, all as-yet-undefined bits in the @samp{flags} wordmust be set to zero in OS images. This way, the @samp{flags} fieldsserves for version control as well as simple feature selection.If bit 0 in the @samp{flags} word is set, then all boot modules loadedalong with the operating system must be aligned on page (4KB)boundaries. Some operating systems expect to be able to map the pagescontaining boot modules directly into a paged address space duringstartup, and thus need the boot modules to be page-aligned.If bit 1 in the @samp{flags} word is set, then information on availablememory via at least the @samp{mem_*} fields of the Multiboot informationstructure (@pxref{Boot information format}) must be included. If theboot loader is capable of passing a memory map (the @samp{mmap_*} fields)and one exists, then it may be included as well.If bit 2 in the @samp{flags} word is set, information about the videomode table (@pxref{Boot information format}) must be available to thekernel.If bit 16 in the @samp{flags} word is set, then the fields at offsets8-24 in the Multiboot header are valid, and the boot loader should usethem instead of the fields in the actual executable header to calculatewhere to load the OS image. This information does not need to beprovided if the kernel image is in @sc{elf} format, but it @emph{must}be provided if the images is in a.out format or in some otherformat. Compliant boot loaders must be able to load images that eitherare in @sc{elf} format or contain the load address information embeddedin the Multiboot header; they may also directly support other executableformats, such as particular a.out variants, but are not required to.@item checksumThe field @samp{checksum} is a 32-bit unsigned value which, when addedto the other magic fields (i.e. @samp{magic} and @samp{flags}), musthave a 32-bit unsigned sum of zero.@end table@node Header address fields@subsection The address fields of Multiboot headerAll of the address fields enabled by flag bit 16 are physical addresses.The meaning of each is as follows:@table @code@item header_addrContains the address corresponding to the beginning of the Multibootheader --- the physical memory location at which the magic value issupposed to be loaded. This field serves to @dfn{synchronize} themapping between OS image offsets and physical memory addresses.@item load_addrContains the physical address of the beginning of the text segment. Theoffset in the OS image file at which to start loading is defined by theoffset at which the header was found, minus (header_addr -load_addr). load_addr must be less than or equal to header_addr.@item load_end_addrContains the physical address of the end of the datasegment. (load_end_addr - load_addr) specifies how much data to load.This implies that the text and data segments must be consecutive in theOS image; this is true for existing a.out executable formats.If this field is zero, the boot loader assumes that the text and datasegments occupy the whole OS image file.@item bss_end_addrContains the physical address of the end of the bss segment. The bootloader initializes this area to zero, and reserves the memory itoccupies to avoid placing boot modules and other data relevant to theoperating system in that area. If this field is zero, the boot loaderassumes that no bss segment is present.@item entry_addrThe physical address to which the boot loader should jump in order tostart running the operating system.@end table@node Header graphics fields@subsection The graphics fields of Multiboot headerAll of the graphics fields are enabled by flag bit 2. They specify thepreferred graphics mode. Note that that is only a @emph{recommended}mode by the OS image. If the mode exists, the boot loader should setit, when the user doesn't specify a mode explicitly. Otherwise, theboot loader should fall back to a similar mode, if available.The meaning of each is as follows:@table @code@item mode_typeContains @samp{0} for linear graphics mode or @samp{1} forEGA-standard text mode. Everything else is reserved for futureexpansion. Note that the boot loader may set a text mode, even if thisfield contains @samp{0}.@item widthContains the number of the columns. This is specified in pixels in agraphics mode, and in characters in a text mode. The value zeroindicates that the OS image has no preference.@item heightContains the number of the lines. This is specified in pixels in agraphics mode, and in characters in a text mode. The value zeroindicates that the OS image has no preference.@item depthContains the number of bits per pixel in a graphics mode, and zero ina text mode. The value zero indicates that the OS image has nopreference.@end table@node Machine state@section Machine stateWhen the boot loader invokes the 32-bit operating system, the machinemust have the following state:@table @samp@item EAXMust contain the magic value @samp{0x2BADB002}; the presence of thisvalue indicates to the operating system that it was loaded by aMultiboot-compliant boot loader (e.g. as opposed to another type ofboot loader that the operating system can also be loaded from).@item EBXMust contain the 32-bit physical address of the Multibootinformation structure provided by the boot loader (@pxref{Bootinformation format}).@item CSMust be a 32-bit read/execute code segment with an offset of @samp{0}and a limit of @samp{0xFFFFFFFF}. The exact value is undefined.@item DS@itemx ES@itemx FS@itemx GS@itemx SSMust be a 32-bit read/write data segment with an offset of @samp{0}and a limit of @samp{0xFFFFFFFF}. The exact values are all undefined.@item A20 gateMust be enabled.@item CR0Bit 31 (PG) must be cleared. Bit 0 (PE) must be set. Other bits areall undefined.@item EFLAGSBit 17 (VM) must be cleared. Bit 9 (IF) must be cleared. Other bitsare all undefined.@end tableAll other processor registers and flag bits are undefined. Thisincludes, in particular:@table @samp@item ESPThe OS image must create its own stack as soon as it needs one.@item GDTREven though the segment registers are set up as described above, the@samp{GDTR} may be invalid, so the OS image must not load any segmentregisters (even just reloading the same values!) until it sets up itsown @samp{GDT}.@item IDTRThe OS image must leave interrupts disabled until it sets up its own@code{IDT}.@end tableHowever, other machine state should be left by the boot loader in@dfn{normal working order}, i.e. as initialized by the @sc{bios} (orDOS, if that's what the boot loader runs from). In other words, theoperating system should be able to make @sc{bios} calls and such afterbeing loaded, as long as it does not overwrite the @sc{bios} datastructures before doing so. Also, the boot loader must leave the@sc{pic} programmed with the normal @sc{bios}/DOS values, even if itchanged them during the switch to 32-bit mode.@node Boot information format@section Boot information formatFIXME: Split this chapter like the chapter ``OS image format''.Upon entry to the operating system, the @code{EBX} register contains thephysical address of a @dfn{Multiboot information} data structure,through which the boot loader communicates vital information to theoperating system. The operating system can use or ignore any parts ofthe structure as it chooses; all information passed by the boot loaderis advisory only.The Multiboot information structure and its related substructures may beplaced anywhere in memory by the boot loader (with the exception of thememory reserved for the kernel and boot modules, of course). It is theoperating system's responsibility to avoid overwriting this memory untilit is done using it.The format of the Multiboot information structure (as defined so far)follows:@example@group        +-------------------+0       | flags             |    (required)        +-------------------+4       | mem_lower         |    (present if flags[0] is set)8       | mem_upper         |    (present if flags[0] is set)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -