17c478bd9Sstevel@tonic-gate@node Internals
27c478bd9Sstevel@tonic-gate@appendix Hacking GRUB
37c478bd9Sstevel@tonic-gate
47c478bd9Sstevel@tonic-gateThis chapter documents the user-invisible aspect of GRUB.
57c478bd9Sstevel@tonic-gate
67c478bd9Sstevel@tonic-gateAs a general rule of software development, it is impossible to keep the
77c478bd9Sstevel@tonic-gatedescriptions of the internals up-to-date, and it is quite hard to
87c478bd9Sstevel@tonic-gatedocument everything. So refer to the source code, whenever you are not
97c478bd9Sstevel@tonic-gatesatisfied with this documentation.  Please assume that this gives just
107c478bd9Sstevel@tonic-gatehints to you.
117c478bd9Sstevel@tonic-gate
127c478bd9Sstevel@tonic-gate@menu
137c478bd9Sstevel@tonic-gate* Memory map::                  The memory map of various components
147c478bd9Sstevel@tonic-gate* Embedded data::               Embedded variables in GRUB
157c478bd9Sstevel@tonic-gate* Filesystem interface::        The generic interface for filesystems
167c478bd9Sstevel@tonic-gate* Command interface::           The generic interface for built-ins
177c478bd9Sstevel@tonic-gate* Bootstrap tricks::            The bootstrap mechanism used in GRUB
187c478bd9Sstevel@tonic-gate* I/O ports detection::         How to probe I/O ports used by INT 13H
197c478bd9Sstevel@tonic-gate* Memory detection::            How to detect all installed RAM
207c478bd9Sstevel@tonic-gate* Low-level disk I/O::          INT 13H disk I/O interrupts
217c478bd9Sstevel@tonic-gate* MBR::                         The structure of Master Boot Record
227c478bd9Sstevel@tonic-gate* Partition table::             The format of partition tables
237c478bd9Sstevel@tonic-gate* Submitting patches::          Where and how you should send patches
247c478bd9Sstevel@tonic-gate@end menu
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate@node Memory map
287c478bd9Sstevel@tonic-gate@section The memory map of various components
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gateGRUB consists of two distinct components, called @dfn{stages}, which are
317c478bd9Sstevel@tonic-gateloaded at different times in the boot process. Because they run
327c478bd9Sstevel@tonic-gatemutual-exclusively, sometimes a memory area overlaps with another
337c478bd9Sstevel@tonic-gatememory area. And, even in one stage, a single memory area can be used
347c478bd9Sstevel@tonic-gatefor various purposes, because their usages are mutually exclusive.
357c478bd9Sstevel@tonic-gate
367c478bd9Sstevel@tonic-gateHere is the memory map of the various components:
377c478bd9Sstevel@tonic-gate
387c478bd9Sstevel@tonic-gate@table @asis
397c478bd9Sstevel@tonic-gate@item 0 to 4K-1
407c478bd9Sstevel@tonic-gateBIOS and real mode interrupts
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate@item 0x07BE to 0x07FF
437c478bd9Sstevel@tonic-gatePartition table passed to another boot loader
447c478bd9Sstevel@tonic-gate
457c478bd9Sstevel@tonic-gate@item down from 8K-1
467c478bd9Sstevel@tonic-gateReal mode stack
477c478bd9Sstevel@tonic-gate
487c478bd9Sstevel@tonic-gate@item 0x2000 to ?
497c478bd9Sstevel@tonic-gateThe optional Stage 1.5 is loaded here
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate@item 0x2000 to 0x7FFF
527c478bd9Sstevel@tonic-gateCommand-line buffer for Multiboot kernels and modules
537c478bd9Sstevel@tonic-gate
547c478bd9Sstevel@tonic-gate@item 0x7C00 to 0x7DFF
557c478bd9Sstevel@tonic-gateStage 1 is loaded here by BIOS or another boot loader
567c478bd9Sstevel@tonic-gate
577c478bd9Sstevel@tonic-gate@item 0x7F00 to 0x7F42
587c478bd9Sstevel@tonic-gateLBA drive parameters
597c478bd9Sstevel@tonic-gate
607c478bd9Sstevel@tonic-gate@item 0x8000 to ?
617c478bd9Sstevel@tonic-gateStage2 is loaded here
627c478bd9Sstevel@tonic-gate
637c478bd9Sstevel@tonic-gate@item The end of Stage 2 to 416K-1
647c478bd9Sstevel@tonic-gateHeap, in particular used for the menu
657c478bd9Sstevel@tonic-gate
667c478bd9Sstevel@tonic-gate@item down from 416K-1
677c478bd9Sstevel@tonic-gateProtected mode stack
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate@item 416K to 448K-1
707c478bd9Sstevel@tonic-gateFilesystem buffer
717c478bd9Sstevel@tonic-gate
727c478bd9Sstevel@tonic-gate@item 448K to 479.5K-1
737c478bd9Sstevel@tonic-gateRaw device buffer
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate@item 479.5K to 480K-1
767c478bd9Sstevel@tonic-gate512-byte scratch area
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gate@item 480K to 512K-1
797c478bd9Sstevel@tonic-gateBuffers for various functions, such as password, command-line, cut and
807c478bd9Sstevel@tonic-gatepaste, and completion.
817c478bd9Sstevel@tonic-gate
827c478bd9Sstevel@tonic-gate@item The last 1K of lower memory
837c478bd9Sstevel@tonic-gateDisk swapping code and data
847c478bd9Sstevel@tonic-gate@end table
857c478bd9Sstevel@tonic-gate
867c478bd9Sstevel@tonic-gateSee the file @file{stage2/shared.h}, for more information.
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate
897c478bd9Sstevel@tonic-gate@node Embedded data
907c478bd9Sstevel@tonic-gate@section Embedded variables in GRUB
917c478bd9Sstevel@tonic-gate
927c478bd9Sstevel@tonic-gateStage 1 and Stage 2 have embedded variables whose locations are
937c478bd9Sstevel@tonic-gatewell-defined, so that the installation can patch the binary file
947c478bd9Sstevel@tonic-gatedirectly without recompilation of the stages.
957c478bd9Sstevel@tonic-gate
967c478bd9Sstevel@tonic-gateIn Stage 1, these are defined:
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate@table @code
997c478bd9Sstevel@tonic-gate@item 0x3E
1007c478bd9Sstevel@tonic-gateThe version number (not GRUB's, but the installation mechanism's).
1017c478bd9Sstevel@tonic-gate
1027c478bd9Sstevel@tonic-gate@item 0x40
1037c478bd9Sstevel@tonic-gateThe boot drive. If it is 0xFF, use a drive passed by BIOS.
1047c478bd9Sstevel@tonic-gate
1057c478bd9Sstevel@tonic-gate@item 0x41
1067c478bd9Sstevel@tonic-gateThe flag for if forcing LBA.
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate@item 0x42
1097c478bd9Sstevel@tonic-gateThe starting address of Stage 2.
1107c478bd9Sstevel@tonic-gate
1117c478bd9Sstevel@tonic-gate@item 0x44
1127c478bd9Sstevel@tonic-gateThe first sector of Stage 2.
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate@item 0x48
1157c478bd9Sstevel@tonic-gateThe starting segment of Stage 2.
1167c478bd9Sstevel@tonic-gate
1177c478bd9Sstevel@tonic-gate@item 0x1FE
1187c478bd9Sstevel@tonic-gateThe signature (@code{0xAA55}).
1197c478bd9Sstevel@tonic-gate@end table
1207c478bd9Sstevel@tonic-gate
1217c478bd9Sstevel@tonic-gateSee the file @file{stage1/stage1.S}, for more information.
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gateIn the first sector of Stage 1.5 and Stage 2, the block lists are
1247c478bd9Sstevel@tonic-gaterecorded between @code{firstlist} and @code{lastlist}. The address of
1257c478bd9Sstevel@tonic-gate@code{lastlist} is determined when assembling the file
1267c478bd9Sstevel@tonic-gate@file{stage2/start.S}.
1277c478bd9Sstevel@tonic-gate
1287c478bd9Sstevel@tonic-gateThe trick here is that it is actually read backward, and the first
1297c478bd9Sstevel@tonic-gate8-byte block list is not read here, but after the pointer is decremented
1307c478bd9Sstevel@tonic-gate8 bytes, then after reading it, it decrements again, reads, and so on,
1317c478bd9Sstevel@tonic-gateuntil it is finished. The terminating condition is when the number of
1327c478bd9Sstevel@tonic-gatesectors to be read in the next block list is zero.
1337c478bd9Sstevel@tonic-gate
1347c478bd9Sstevel@tonic-gateThe format of a block list can be seen from the example in the code just
1357c478bd9Sstevel@tonic-gatebefore the @code{firstlist} label. Note that it is always from the
1367c478bd9Sstevel@tonic-gatebeginning of the disk, but @emph{not} relative to the partition
1377c478bd9Sstevel@tonic-gateboundaries.
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gateIn the second sector of Stage 1.5 and Stage 2, these are defined:
1407c478bd9Sstevel@tonic-gate
1417c478bd9Sstevel@tonic-gate@table @asis
1427c478bd9Sstevel@tonic-gate@item @code{0x6}
1437c478bd9Sstevel@tonic-gateThe version number (likewise, the installation mechanism's).
1447c478bd9Sstevel@tonic-gate
1457c478bd9Sstevel@tonic-gate@item @code{0x8}
1467c478bd9Sstevel@tonic-gateThe installed partition.
1477c478bd9Sstevel@tonic-gate
1487c478bd9Sstevel@tonic-gate@item @code{0xC}
1497c478bd9Sstevel@tonic-gateThe saved entry number.
1507c478bd9Sstevel@tonic-gate
1517c478bd9Sstevel@tonic-gate@item @code{0x10}
1527c478bd9Sstevel@tonic-gateThe identifier.
1537c478bd9Sstevel@tonic-gate
1547c478bd9Sstevel@tonic-gate@item @code{0x11}
1557c478bd9Sstevel@tonic-gateThe flag for if forcing LBA.
1567c478bd9Sstevel@tonic-gate
1577c478bd9Sstevel@tonic-gate@item @code{0x12}
1587c478bd9Sstevel@tonic-gateThe version string (GRUB's).
1597c478bd9Sstevel@tonic-gate
1607c478bd9Sstevel@tonic-gate@item @code{0x12} + @dfn{the length of the version string}
1617c478bd9Sstevel@tonic-gateThe name of a configuration file.
1627c478bd9Sstevel@tonic-gate@end table
1637c478bd9Sstevel@tonic-gate
1647c478bd9Sstevel@tonic-gateSee the file @file{stage2/asm.S}, for more information.
1657c478bd9Sstevel@tonic-gate
1667c478bd9Sstevel@tonic-gate
1677c478bd9Sstevel@tonic-gate@node Filesystem interface
1687c478bd9Sstevel@tonic-gate@section The generic interface for filesystems
1697c478bd9Sstevel@tonic-gate
1707c478bd9Sstevel@tonic-gateFor any particular partition, it is presumed that only one of the
1717c478bd9Sstevel@tonic-gate@dfn{normal} filesystems such as FAT, FFS, or ext2fs can be used, so
1727c478bd9Sstevel@tonic-gatethere is a switch table managed by the functions in
1737c478bd9Sstevel@tonic-gate@file{disk_io.c}. The notation is that you can only @dfn{mount} one at a
1747c478bd9Sstevel@tonic-gatetime.
1757c478bd9Sstevel@tonic-gate
1767c478bd9Sstevel@tonic-gateThe block list filesystem has a special place in the system. In addition
1777c478bd9Sstevel@tonic-gateto the @dfn{normal} filesystem (or even without one mounted), you can
1787c478bd9Sstevel@tonic-gateaccess disk blocks directly (in the indicated partition) via the block
1797c478bd9Sstevel@tonic-gatelist notation. Using the block list filesystem doesn't effect any other
1807c478bd9Sstevel@tonic-gatefilesystem mounts.
1817c478bd9Sstevel@tonic-gate
1827c478bd9Sstevel@tonic-gateThe variables which can be read by the filesystem backend are:
1837c478bd9Sstevel@tonic-gate
1847c478bd9Sstevel@tonic-gate@vtable @code
1857c478bd9Sstevel@tonic-gate@item current_drive
1867c478bd9Sstevel@tonic-gateThe current BIOS drive number (numbered from 0, if a floppy, and
1877c478bd9Sstevel@tonic-gatenumbered from 0x80, if a hard disk).
1887c478bd9Sstevel@tonic-gate
1897c478bd9Sstevel@tonic-gate@item current_partition
1907c478bd9Sstevel@tonic-gateThe current partition number.
1917c478bd9Sstevel@tonic-gate
1927c478bd9Sstevel@tonic-gate@item current_slice
1937c478bd9Sstevel@tonic-gateThe current partition type.
1947c478bd9Sstevel@tonic-gate
1957c478bd9Sstevel@tonic-gate@item saved_drive
1967c478bd9Sstevel@tonic-gateThe @dfn{drive} part of the root device.
1977c478bd9Sstevel@tonic-gate
1987c478bd9Sstevel@tonic-gate@item saved_partition
1997c478bd9Sstevel@tonic-gateThe @dfn{partition} part of the root device.
2007c478bd9Sstevel@tonic-gate
2017c478bd9Sstevel@tonic-gate@item part_start
2027c478bd9Sstevel@tonic-gateThe current partition starting address, in sectors.
2037c478bd9Sstevel@tonic-gate
2047c478bd9Sstevel@tonic-gate@item part_length
2057c478bd9Sstevel@tonic-gateThe current partition length, in sectors.
2067c478bd9Sstevel@tonic-gate
2077c478bd9Sstevel@tonic-gate@item print_possibilities
2087c478bd9Sstevel@tonic-gateTrue when the @code{dir} function should print the possible completions
2097c478bd9Sstevel@tonic-gateof a file, and false when it should try to actually open a file of that
2107c478bd9Sstevel@tonic-gatename.
2117c478bd9Sstevel@tonic-gate
2127c478bd9Sstevel@tonic-gate@item FSYS_BUF
2137c478bd9Sstevel@tonic-gateFilesystem buffer which is 32K in size, to use in any way which the
2147c478bd9Sstevel@tonic-gatefilesystem backend desires.
2157c478bd9Sstevel@tonic-gate@end vtable
2167c478bd9Sstevel@tonic-gate
2177c478bd9Sstevel@tonic-gateThe variables which need to be written by a filesystem backend are:
2187c478bd9Sstevel@tonic-gate
2197c478bd9Sstevel@tonic-gate@vtable @code
2207c478bd9Sstevel@tonic-gate@item filepos
2217c478bd9Sstevel@tonic-gateThe current position in the file, in sectors.
2227c478bd9Sstevel@tonic-gate
2237c478bd9Sstevel@tonic-gate@strong{Caution:} the value of @var{filepos} can be changed out from
2247c478bd9Sstevel@tonic-gateunder the filesystem code in the current implementation. Don't depend on
2257c478bd9Sstevel@tonic-gateit being the same for later calls into the backend code!
2267c478bd9Sstevel@tonic-gate
2277c478bd9Sstevel@tonic-gate@item filemax
2287c478bd9Sstevel@tonic-gateThe length of the file.
2297c478bd9Sstevel@tonic-gate
2307c478bd9Sstevel@tonic-gate@item disk_read_func
2317c478bd9Sstevel@tonic-gateThe value of @var{disk_read_hook} @emph{only} during reading of data
2327c478bd9Sstevel@tonic-gatefor the file, not any other fs data, inodes, FAT tables, whatever, then
2337c478bd9Sstevel@tonic-gateset to @code{NULL} at all other times (it will be @code{NULL} by
2347c478bd9Sstevel@tonic-gatedefault). If this isn't done correctly, then the @command{testload} and
2357c478bd9Sstevel@tonic-gate@command{install} commands won't work correctly.
2367c478bd9Sstevel@tonic-gate@end vtable
2377c478bd9Sstevel@tonic-gate
2387c478bd9Sstevel@tonic-gateThe functions expected to be used by the filesystem backend are:
2397c478bd9Sstevel@tonic-gate
2407c478bd9Sstevel@tonic-gate@ftable @code
2417c478bd9Sstevel@tonic-gate@item devread
2427c478bd9Sstevel@tonic-gateOnly read sectors from within a partition. Sector 0 is the first sector
2437c478bd9Sstevel@tonic-gatein the partition.
2447c478bd9Sstevel@tonic-gate
2457c478bd9Sstevel@tonic-gate@item grub_read
2467c478bd9Sstevel@tonic-gateIf the backend uses the block list code, then @code{grub_read} can be
2477c478bd9Sstevel@tonic-gateused, after setting @var{block_file} to 1.
2487c478bd9Sstevel@tonic-gate
2497c478bd9Sstevel@tonic-gate@item print_a_completion
2507c478bd9Sstevel@tonic-gateIf @var{print_possibilities} is true, call @code{print_a_completion} for
2517c478bd9Sstevel@tonic-gateeach possible file name. Otherwise, the file name completion won't work.
2527c478bd9Sstevel@tonic-gate@end ftable
2537c478bd9Sstevel@tonic-gate
2547c478bd9Sstevel@tonic-gateThe functions expected to be defined by the filesystem backend are
2557c478bd9Sstevel@tonic-gatedescribed at least moderately in the file @file{filesys.h}. Their usage
2567c478bd9Sstevel@tonic-gateis fairly evident from their use in the functions in @file{disk_io.c},
2577c478bd9Sstevel@tonic-gatelook for the use of the @var{fsys_table} array.
2587c478bd9Sstevel@tonic-gate
2597c478bd9Sstevel@tonic-gate@strong{Caution:} The semantics are such that then @samp{mount}ing the
2607c478bd9Sstevel@tonic-gatefilesystem, presume the filesystem buffer @code{FSYS_BUF} is corrupted,
2617c478bd9Sstevel@tonic-gateand (re-)load all important contents. When opening and reading a file,
2627c478bd9Sstevel@tonic-gatepresume that the data from the @samp{mount} is available, and doesn't
2637c478bd9Sstevel@tonic-gateget corrupted by the open/read (i.e. multiple opens and/or reads will be
2647c478bd9Sstevel@tonic-gatedone with only one mount if in the same filesystem).
2657c478bd9Sstevel@tonic-gate
2667c478bd9Sstevel@tonic-gate
2677c478bd9Sstevel@tonic-gate@node Command interface
2687c478bd9Sstevel@tonic-gate@section The generic interface for built-ins
2697c478bd9Sstevel@tonic-gate
2707c478bd9Sstevel@tonic-gateGRUB built-in commands are defined in a uniformal interface, whether
2717c478bd9Sstevel@tonic-gatethey are menu-specific or can be used anywhere. The definition of a
2727c478bd9Sstevel@tonic-gatebuiltin command consists of two parts: the code itself and the table of
2737c478bd9Sstevel@tonic-gatethe information.
2747c478bd9Sstevel@tonic-gate
2757c478bd9Sstevel@tonic-gateThe code must be a function which takes two arguments, a command-line
2767c478bd9Sstevel@tonic-gatestring and flags, and returns an @samp{int} value. The @dfn{flags}
2777c478bd9Sstevel@tonic-gateargument specifies how the function is called, using a bit mask. The
2787c478bd9Sstevel@tonic-gatereturn value must be zero if successful, otherwise non-zero. So it is
2797c478bd9Sstevel@tonic-gatenormally enough to return @var{errnum}.
2807c478bd9Sstevel@tonic-gate
2817c478bd9Sstevel@tonic-gateThe table of the information is represented by the structure
2827c478bd9Sstevel@tonic-gate@code{struct builtin}, which contains the name of the command, a pointer
2837c478bd9Sstevel@tonic-gateto the function, flags, a short description of the command and a long
2847c478bd9Sstevel@tonic-gatedescription of the command. Since the descriptions are used only for
2857c478bd9Sstevel@tonic-gatehelp messages interactively, you don't have to define them, if the
2867c478bd9Sstevel@tonic-gatecommand may not be called interactively (such as @command{title}).
2877c478bd9Sstevel@tonic-gate
2887c478bd9Sstevel@tonic-gateThe table is finally registered in the table @var{builtin_table}, so
2897c478bd9Sstevel@tonic-gatethat @code{run_script} and @code{enter_cmdline} can find the
2907c478bd9Sstevel@tonic-gatecommand. See the files @file{cmdline.c} and @file{builtins.c}, for more
2917c478bd9Sstevel@tonic-gatedetails.
2927c478bd9Sstevel@tonic-gate
2937c478bd9Sstevel@tonic-gate
2947c478bd9Sstevel@tonic-gate@node Bootstrap tricks
2957c478bd9Sstevel@tonic-gate@section The bootstrap mechanism used in GRUB
2967c478bd9Sstevel@tonic-gate
2977c478bd9Sstevel@tonic-gateThe disk space can be used in a boot loader is very restricted because
2987c478bd9Sstevel@tonic-gatea MBR (@pxref{MBR}) is only 512 bytes but it also contains a partition
2997c478bd9Sstevel@tonic-gatetable (@pxref{Partition table}) and a BPB. So the question is how to
3007c478bd9Sstevel@tonic-gatemake a boot loader code enough small to be fit in a MBR.
3017c478bd9Sstevel@tonic-gate
3027c478bd9Sstevel@tonic-gateHowever, GRUB is a very large program, so we break GRUB into 2 (or 3)
3037c478bd9Sstevel@tonic-gatedistinct components, @dfn{Stage 1} and @dfn{Stage 2} (and optionally
3047c478bd9Sstevel@tonic-gate@dfn{Stage 1.5}). @xref{Memory map}, for more information.
3057c478bd9Sstevel@tonic-gate
3067c478bd9Sstevel@tonic-gateWe embed Stage 1 in a MBR or in the boot sector of a partition, and
3077c478bd9Sstevel@tonic-gateplace Stage 2 in a filesystem. The optional Stage 1.5 can be installed
3087c478bd9Sstevel@tonic-gatein a filesystem, in the @dfn{boot loader} area in a FFS or a ReiserFS,
3097c478bd9Sstevel@tonic-gateand in the sectors right after a MBR, because Stage 1.5 is enough small
3107c478bd9Sstevel@tonic-gateand the sectors right after a MBR is normally an unused region. The size
3117c478bd9Sstevel@tonic-gateof this region is the number of sectors per head minus 1.
3127c478bd9Sstevel@tonic-gate
3137c478bd9Sstevel@tonic-gateThus, all Stage1 must do is just load Stage2 or Stage1.5. But even if
3147c478bd9Sstevel@tonic-gateStage 1 needs not to support the user interface or the filesystem
3157c478bd9Sstevel@tonic-gateinterface, it is impossible to make Stage 1 less than 400 bytes, because
3167c478bd9Sstevel@tonic-gateGRUB should support both the CHS mode and the LBA mode (@pxref{Low-level
3177c478bd9Sstevel@tonic-gatedisk I/O}).
3187c478bd9Sstevel@tonic-gate
3197c478bd9Sstevel@tonic-gateThe solution used by GRUB is that Stage 1 loads only the first sector of
3207c478bd9Sstevel@tonic-gateStage 2 (or Stage 1.5) and Stage 2 itself loads the rest. The flow of
3217c478bd9Sstevel@tonic-gateStage 1 is:
3227c478bd9Sstevel@tonic-gate
3237c478bd9Sstevel@tonic-gate@enumerate
3247c478bd9Sstevel@tonic-gate@item
3257c478bd9Sstevel@tonic-gateInitialize the system briefly.
3267c478bd9Sstevel@tonic-gate
3277c478bd9Sstevel@tonic-gate@item
3287c478bd9Sstevel@tonic-gateDetect the geometry and the accessing mode of the @dfn{loading drive}.
3297c478bd9Sstevel@tonic-gate
3307c478bd9Sstevel@tonic-gate@item
3317c478bd9Sstevel@tonic-gateLoad the first sector of Stage 2.
3327c478bd9Sstevel@tonic-gate
3337c478bd9Sstevel@tonic-gate@item
3347c478bd9Sstevel@tonic-gateJump to the starting address of the Stage 2.
3357c478bd9Sstevel@tonic-gate@end enumerate
3367c478bd9Sstevel@tonic-gate
3377c478bd9Sstevel@tonic-gateThe flow of Stage 2 (and Stage 1.5) is:
3387c478bd9Sstevel@tonic-gate
3397c478bd9Sstevel@tonic-gate@enumerate
3407c478bd9Sstevel@tonic-gate@item
3417c478bd9Sstevel@tonic-gateLoad the rest of itself to the real starting address, that is, the
3427c478bd9Sstevel@tonic-gatestarting address plus 512 bytes. The block lists are stored in the last
3437c478bd9Sstevel@tonic-gatepart of the first sector.
3447c478bd9Sstevel@tonic-gate
3457c478bd9Sstevel@tonic-gate@item
3467c478bd9Sstevel@tonic-gateLong jump to the real starting address.
3477c478bd9Sstevel@tonic-gate@end enumerate
3487c478bd9Sstevel@tonic-gate
3497c478bd9Sstevel@tonic-gateNote that Stage 2 (or Stage 1.5) does not probe the geometry
3507c478bd9Sstevel@tonic-gateor the accessing mode of the @dfn{loading drive}, since Stage 1 has
3517c478bd9Sstevel@tonic-gatealready probed them.
3527c478bd9Sstevel@tonic-gate
3537c478bd9Sstevel@tonic-gate
3547c478bd9Sstevel@tonic-gate@node I/O ports detection
3557c478bd9Sstevel@tonic-gate@section How to probe I/O ports used by INT 13H
3567c478bd9Sstevel@tonic-gate
3577c478bd9Sstevel@tonic-gateFIXME: I will write this chapter after implementing the new technique.
3587c478bd9Sstevel@tonic-gate
3597c478bd9Sstevel@tonic-gate
3607c478bd9Sstevel@tonic-gate
3617c478bd9Sstevel@tonic-gate@node Memory detection
3627c478bd9Sstevel@tonic-gate@section How to detect all installed RAM
3637c478bd9Sstevel@tonic-gate
3647c478bd9Sstevel@tonic-gateFIXME: I doubt if Erich didn't write this chapter only himself wholly,
3657c478bd9Sstevel@tonic-gateso I will rewrite this chapter.
3667c478bd9Sstevel@tonic-gate
3677c478bd9Sstevel@tonic-gate
3687c478bd9Sstevel@tonic-gate@node Low-level disk I/O
3697c478bd9Sstevel@tonic-gate@section INT 13H disk I/O interrupts
3707c478bd9Sstevel@tonic-gate
3717c478bd9Sstevel@tonic-gateFIXME: I'm not sure where some part of the original chapter is derived,
3727c478bd9Sstevel@tonic-gateso I will rewrite this chapter.
3737c478bd9Sstevel@tonic-gate
3747c478bd9Sstevel@tonic-gate
3757c478bd9Sstevel@tonic-gate@node MBR
3767c478bd9Sstevel@tonic-gate@section The structure of Master Boot Record
3777c478bd9Sstevel@tonic-gate
3787c478bd9Sstevel@tonic-gateFIXME: Likewise.
3797c478bd9Sstevel@tonic-gate
3807c478bd9Sstevel@tonic-gate
3817c478bd9Sstevel@tonic-gate@node Partition table
3827c478bd9Sstevel@tonic-gate@section The format of partition tables
3837c478bd9Sstevel@tonic-gate
3847c478bd9Sstevel@tonic-gateFIXME: Probably the original chapter is derived from "How It Works", so
3857c478bd9Sstevel@tonic-gateI will rewrite this chapter.
3867c478bd9Sstevel@tonic-gate
3877c478bd9Sstevel@tonic-gate
3887c478bd9Sstevel@tonic-gate@node Submitting patches
3897c478bd9Sstevel@tonic-gate@section Where and how you should send patches
3907c478bd9Sstevel@tonic-gate
3917c478bd9Sstevel@tonic-gateWhen you write patches for GRUB, please send them to the mailing list
3927c478bd9Sstevel@tonic-gate@email{bug-grub@@gnu.org}. Here is the list of items of which you
3937c478bd9Sstevel@tonic-gateshould take care:
3947c478bd9Sstevel@tonic-gate
3957c478bd9Sstevel@tonic-gate@itemize @bullet
3967c478bd9Sstevel@tonic-gate@item
3977c478bd9Sstevel@tonic-gatePlease make your patch as small as possible. Generally, it is not a good
3987c478bd9Sstevel@tonic-gatething to make one big patch which changes many things. Instead,
3997c478bd9Sstevel@tonic-gatesegregate features and produce many patches.
4007c478bd9Sstevel@tonic-gate
4017c478bd9Sstevel@tonic-gate@item
4027c478bd9Sstevel@tonic-gateUse as late code as possible, for the original code. The CVS repository
4037c478bd9Sstevel@tonic-gatealways has the current version (@pxref{Obtaining and Building GRUB}).
4047c478bd9Sstevel@tonic-gate
4057c478bd9Sstevel@tonic-gate@item
4067c478bd9Sstevel@tonic-gateWrite ChangeLog entries. @xref{Change Logs, , Change Logs, standards,
4077c478bd9Sstevel@tonic-gateGNU Coding Standards}, if you don't know how to write ChangeLog.
4087c478bd9Sstevel@tonic-gate
4097c478bd9Sstevel@tonic-gate@item
4107c478bd9Sstevel@tonic-gateMake patches in unified diff format. @samp{diff -urN} is appropriate in
4117c478bd9Sstevel@tonic-gatemost cases.
4127c478bd9Sstevel@tonic-gate
4137c478bd9Sstevel@tonic-gate@item
4147c478bd9Sstevel@tonic-gateDon't make patches reversely. Reverse patches are difficult to read and
4157c478bd9Sstevel@tonic-gateuse.
4167c478bd9Sstevel@tonic-gate
4177c478bd9Sstevel@tonic-gate@item
4187c478bd9Sstevel@tonic-gateBe careful enough of the license term and the copyright. Because GRUB
4197c478bd9Sstevel@tonic-gateis under GNU General Public License, you may not steal code from
4207c478bd9Sstevel@tonic-gatesoftware whose license is incompatible against GPL. And, if you copy
4217c478bd9Sstevel@tonic-gatecode written by others, you must not ignore their copyrights. Feel free
4227c478bd9Sstevel@tonic-gateto ask GRUB maintainers, whenever you are not sure what you should do.
4237c478bd9Sstevel@tonic-gate
4247c478bd9Sstevel@tonic-gate@item
4257c478bd9Sstevel@tonic-gateIf your patch is too large to send in e-mail, put it at somewhere we can
4267c478bd9Sstevel@tonic-gatesee. Usually, you shouldn't send e-mail over 20K.
4277c478bd9Sstevel@tonic-gate@end itemize
428