xref: /titanic_51/usr/src/grub/grub-0.97/docs/internals.texi (revision 1b8adde7ba7d5e04395c141c5400dc2cffd7d809)
1*1b8adde7SWilliam Kucharski@node Internals
2*1b8adde7SWilliam Kucharski@appendix Hacking GRUB
3*1b8adde7SWilliam Kucharski
4*1b8adde7SWilliam KucharskiThis chapter documents the user-invisible aspect of GRUB.
5*1b8adde7SWilliam Kucharski
6*1b8adde7SWilliam KucharskiAs a general rule of software development, it is impossible to keep the
7*1b8adde7SWilliam Kucharskidescriptions of the internals up-to-date, and it is quite hard to
8*1b8adde7SWilliam Kucharskidocument everything. So refer to the source code, whenever you are not
9*1b8adde7SWilliam Kucharskisatisfied with this documentation.  Please assume that this gives just
10*1b8adde7SWilliam Kucharskihints to you.
11*1b8adde7SWilliam Kucharski
12*1b8adde7SWilliam Kucharski@menu
13*1b8adde7SWilliam Kucharski* Memory map::                  The memory map of various components
14*1b8adde7SWilliam Kucharski* Embedded data::               Embedded variables in GRUB
15*1b8adde7SWilliam Kucharski* Filesystem interface::        The generic interface for filesystems
16*1b8adde7SWilliam Kucharski* Command interface::           The generic interface for built-ins
17*1b8adde7SWilliam Kucharski* Bootstrap tricks::            The bootstrap mechanism used in GRUB
18*1b8adde7SWilliam Kucharski* I/O ports detection::         How to probe I/O ports used by INT 13H
19*1b8adde7SWilliam Kucharski* Memory detection::            How to detect all installed RAM
20*1b8adde7SWilliam Kucharski* Low-level disk I/O::          INT 13H disk I/O interrupts
21*1b8adde7SWilliam Kucharski* MBR::                         The structure of Master Boot Record
22*1b8adde7SWilliam Kucharski* Partition table::             The format of partition tables
23*1b8adde7SWilliam Kucharski* Submitting patches::          Where and how you should send patches
24*1b8adde7SWilliam Kucharski@end menu
25*1b8adde7SWilliam Kucharski
26*1b8adde7SWilliam Kucharski
27*1b8adde7SWilliam Kucharski@node Memory map
28*1b8adde7SWilliam Kucharski@section The memory map of various components
29*1b8adde7SWilliam Kucharski
30*1b8adde7SWilliam KucharskiGRUB consists of two distinct components, called @dfn{stages}, which are
31*1b8adde7SWilliam Kucharskiloaded at different times in the boot process. Because they run
32*1b8adde7SWilliam Kucharskimutual-exclusively, sometimes a memory area overlaps with another
33*1b8adde7SWilliam Kucharskimemory area. And, even in one stage, a single memory area can be used
34*1b8adde7SWilliam Kucharskifor various purposes, because their usages are mutually exclusive.
35*1b8adde7SWilliam Kucharski
36*1b8adde7SWilliam KucharskiHere is the memory map of the various components:
37*1b8adde7SWilliam Kucharski
38*1b8adde7SWilliam Kucharski@table @asis
39*1b8adde7SWilliam Kucharski@item 0 to 4K-1
40*1b8adde7SWilliam KucharskiBIOS and real mode interrupts
41*1b8adde7SWilliam Kucharski
42*1b8adde7SWilliam Kucharski@item 0x07BE to 0x07FF
43*1b8adde7SWilliam KucharskiPartition table passed to another boot loader
44*1b8adde7SWilliam Kucharski
45*1b8adde7SWilliam Kucharski@item down from 8K-1
46*1b8adde7SWilliam KucharskiReal mode stack
47*1b8adde7SWilliam Kucharski
48*1b8adde7SWilliam Kucharski@item 0x2000 to ?
49*1b8adde7SWilliam KucharskiThe optional Stage 1.5 is loaded here
50*1b8adde7SWilliam Kucharski
51*1b8adde7SWilliam Kucharski@item 0x2000 to 0x7FFF
52*1b8adde7SWilliam KucharskiCommand-line buffer for Multiboot kernels and modules
53*1b8adde7SWilliam Kucharski
54*1b8adde7SWilliam Kucharski@item 0x7C00 to 0x7DFF
55*1b8adde7SWilliam KucharskiStage 1 is loaded here by BIOS or another boot loader
56*1b8adde7SWilliam Kucharski
57*1b8adde7SWilliam Kucharski@item 0x7F00 to 0x7F42
58*1b8adde7SWilliam KucharskiLBA drive parameters
59*1b8adde7SWilliam Kucharski
60*1b8adde7SWilliam Kucharski@item 0x8000 to ?
61*1b8adde7SWilliam KucharskiStage2 is loaded here
62*1b8adde7SWilliam Kucharski
63*1b8adde7SWilliam Kucharski@item The end of Stage 2 to 416K-1
64*1b8adde7SWilliam KucharskiHeap, in particular used for the menu
65*1b8adde7SWilliam Kucharski
66*1b8adde7SWilliam Kucharski@item down from 416K-1
67*1b8adde7SWilliam KucharskiProtected mode stack
68*1b8adde7SWilliam Kucharski
69*1b8adde7SWilliam Kucharski@item 416K to 448K-1
70*1b8adde7SWilliam KucharskiFilesystem buffer
71*1b8adde7SWilliam Kucharski
72*1b8adde7SWilliam Kucharski@item 448K to 479.5K-1
73*1b8adde7SWilliam KucharskiRaw device buffer
74*1b8adde7SWilliam Kucharski
75*1b8adde7SWilliam Kucharski@item 479.5K to 480K-1
76*1b8adde7SWilliam Kucharski512-byte scratch area
77*1b8adde7SWilliam Kucharski
78*1b8adde7SWilliam Kucharski@item 480K to 512K-1
79*1b8adde7SWilliam KucharskiBuffers for various functions, such as password, command-line, cut and
80*1b8adde7SWilliam Kucharskipaste, and completion.
81*1b8adde7SWilliam Kucharski
82*1b8adde7SWilliam Kucharski@item The last 1K of lower memory
83*1b8adde7SWilliam KucharskiDisk swapping code and data
84*1b8adde7SWilliam Kucharski@end table
85*1b8adde7SWilliam Kucharski
86*1b8adde7SWilliam KucharskiSee the file @file{stage2/shared.h}, for more information.
87*1b8adde7SWilliam Kucharski
88*1b8adde7SWilliam Kucharski
89*1b8adde7SWilliam Kucharski@node Embedded data
90*1b8adde7SWilliam Kucharski@section Embedded variables in GRUB
91*1b8adde7SWilliam Kucharski
92*1b8adde7SWilliam KucharskiStage 1 and Stage 2 have embedded variables whose locations are
93*1b8adde7SWilliam Kucharskiwell-defined, so that the installation can patch the binary file
94*1b8adde7SWilliam Kucharskidirectly without recompilation of the stages.
95*1b8adde7SWilliam Kucharski
96*1b8adde7SWilliam KucharskiIn Stage 1, these are defined:
97*1b8adde7SWilliam Kucharski
98*1b8adde7SWilliam Kucharski@table @code
99*1b8adde7SWilliam Kucharski@item 0x3E
100*1b8adde7SWilliam KucharskiThe version number (not GRUB's, but the installation mechanism's).
101*1b8adde7SWilliam Kucharski
102*1b8adde7SWilliam Kucharski@item 0x40
103*1b8adde7SWilliam KucharskiThe boot drive. If it is 0xFF, use a drive passed by BIOS.
104*1b8adde7SWilliam Kucharski
105*1b8adde7SWilliam Kucharski@item 0x41
106*1b8adde7SWilliam KucharskiThe flag for if forcing LBA.
107*1b8adde7SWilliam Kucharski
108*1b8adde7SWilliam Kucharski@item 0x42
109*1b8adde7SWilliam KucharskiThe starting address of Stage 2.
110*1b8adde7SWilliam Kucharski
111*1b8adde7SWilliam Kucharski@item 0x44
112*1b8adde7SWilliam KucharskiThe first sector of Stage 2.
113*1b8adde7SWilliam Kucharski
114*1b8adde7SWilliam Kucharski@item 0x48
115*1b8adde7SWilliam KucharskiThe starting segment of Stage 2.
116*1b8adde7SWilliam Kucharski
117*1b8adde7SWilliam Kucharski@item 0x1FE
118*1b8adde7SWilliam KucharskiThe signature (@code{0xAA55}).
119*1b8adde7SWilliam Kucharski@end table
120*1b8adde7SWilliam Kucharski
121*1b8adde7SWilliam KucharskiSee the file @file{stage1/stage1.S}, for more information.
122*1b8adde7SWilliam Kucharski
123*1b8adde7SWilliam KucharskiIn the first sector of Stage 1.5 and Stage 2, the block lists are
124*1b8adde7SWilliam Kucharskirecorded between @code{firstlist} and @code{lastlist}. The address of
125*1b8adde7SWilliam Kucharski@code{lastlist} is determined when assembling the file
126*1b8adde7SWilliam Kucharski@file{stage2/start.S}.
127*1b8adde7SWilliam Kucharski
128*1b8adde7SWilliam KucharskiThe trick here is that it is actually read backward, and the first
129*1b8adde7SWilliam Kucharski8-byte block list is not read here, but after the pointer is decremented
130*1b8adde7SWilliam Kucharski8 bytes, then after reading it, it decrements again, reads, and so on,
131*1b8adde7SWilliam Kucharskiuntil it is finished. The terminating condition is when the number of
132*1b8adde7SWilliam Kucharskisectors to be read in the next block list is zero.
133*1b8adde7SWilliam Kucharski
134*1b8adde7SWilliam KucharskiThe format of a block list can be seen from the example in the code just
135*1b8adde7SWilliam Kucharskibefore the @code{firstlist} label. Note that it is always from the
136*1b8adde7SWilliam Kucharskibeginning of the disk, but @emph{not} relative to the partition
137*1b8adde7SWilliam Kucharskiboundaries.
138*1b8adde7SWilliam Kucharski
139*1b8adde7SWilliam KucharskiIn the second sector of Stage 1.5 and Stage 2, these are defined:
140*1b8adde7SWilliam Kucharski
141*1b8adde7SWilliam Kucharski@table @asis
142*1b8adde7SWilliam Kucharski@item @code{0x6}
143*1b8adde7SWilliam KucharskiThe version number (likewise, the installation mechanism's).
144*1b8adde7SWilliam Kucharski
145*1b8adde7SWilliam Kucharski@item @code{0x8}
146*1b8adde7SWilliam KucharskiThe installed partition.
147*1b8adde7SWilliam Kucharski
148*1b8adde7SWilliam Kucharski@item @code{0xC}
149*1b8adde7SWilliam KucharskiThe saved entry number.
150*1b8adde7SWilliam Kucharski
151*1b8adde7SWilliam Kucharski@item @code{0x10}
152*1b8adde7SWilliam KucharskiThe identifier.
153*1b8adde7SWilliam Kucharski
154*1b8adde7SWilliam Kucharski@item @code{0x11}
155*1b8adde7SWilliam KucharskiThe flag for if forcing LBA.
156*1b8adde7SWilliam Kucharski
157*1b8adde7SWilliam Kucharski@item @code{0x12}
158*1b8adde7SWilliam KucharskiThe version string (GRUB's).
159*1b8adde7SWilliam Kucharski
160*1b8adde7SWilliam Kucharski@item @code{0x12} + @dfn{the length of the version string}
161*1b8adde7SWilliam KucharskiThe name of a configuration file.
162*1b8adde7SWilliam Kucharski@end table
163*1b8adde7SWilliam Kucharski
164*1b8adde7SWilliam KucharskiSee the file @file{stage2/asm.S}, for more information.
165*1b8adde7SWilliam Kucharski
166*1b8adde7SWilliam Kucharski
167*1b8adde7SWilliam Kucharski@node Filesystem interface
168*1b8adde7SWilliam Kucharski@section The generic interface for filesystems
169*1b8adde7SWilliam Kucharski
170*1b8adde7SWilliam KucharskiFor any particular partition, it is presumed that only one of the
171*1b8adde7SWilliam Kucharski@dfn{normal} filesystems such as FAT, FFS, or ext2fs can be used, so
172*1b8adde7SWilliam Kucharskithere is a switch table managed by the functions in
173*1b8adde7SWilliam Kucharski@file{disk_io.c}. The notation is that you can only @dfn{mount} one at a
174*1b8adde7SWilliam Kucharskitime.
175*1b8adde7SWilliam Kucharski
176*1b8adde7SWilliam KucharskiThe block list filesystem has a special place in the system. In addition
177*1b8adde7SWilliam Kucharskito the @dfn{normal} filesystem (or even without one mounted), you can
178*1b8adde7SWilliam Kucharskiaccess disk blocks directly (in the indicated partition) via the block
179*1b8adde7SWilliam Kucharskilist notation. Using the block list filesystem doesn't effect any other
180*1b8adde7SWilliam Kucharskifilesystem mounts.
181*1b8adde7SWilliam Kucharski
182*1b8adde7SWilliam KucharskiThe variables which can be read by the filesystem backend are:
183*1b8adde7SWilliam Kucharski
184*1b8adde7SWilliam Kucharski@vtable @code
185*1b8adde7SWilliam Kucharski@item current_drive
186*1b8adde7SWilliam KucharskiThe current BIOS drive number (numbered from 0, if a floppy, and
187*1b8adde7SWilliam Kucharskinumbered from 0x80, if a hard disk).
188*1b8adde7SWilliam Kucharski
189*1b8adde7SWilliam Kucharski@item current_partition
190*1b8adde7SWilliam KucharskiThe current partition number.
191*1b8adde7SWilliam Kucharski
192*1b8adde7SWilliam Kucharski@item current_slice
193*1b8adde7SWilliam KucharskiThe current partition type.
194*1b8adde7SWilliam Kucharski
195*1b8adde7SWilliam Kucharski@item saved_drive
196*1b8adde7SWilliam KucharskiThe @dfn{drive} part of the root device.
197*1b8adde7SWilliam Kucharski
198*1b8adde7SWilliam Kucharski@item saved_partition
199*1b8adde7SWilliam KucharskiThe @dfn{partition} part of the root device.
200*1b8adde7SWilliam Kucharski
201*1b8adde7SWilliam Kucharski@item part_start
202*1b8adde7SWilliam KucharskiThe current partition starting address, in sectors.
203*1b8adde7SWilliam Kucharski
204*1b8adde7SWilliam Kucharski@item part_length
205*1b8adde7SWilliam KucharskiThe current partition length, in sectors.
206*1b8adde7SWilliam Kucharski
207*1b8adde7SWilliam Kucharski@item print_possibilities
208*1b8adde7SWilliam KucharskiTrue when the @code{dir} function should print the possible completions
209*1b8adde7SWilliam Kucharskiof a file, and false when it should try to actually open a file of that
210*1b8adde7SWilliam Kucharskiname.
211*1b8adde7SWilliam Kucharski
212*1b8adde7SWilliam Kucharski@item FSYS_BUF
213*1b8adde7SWilliam KucharskiFilesystem buffer which is 32K in size, to use in any way which the
214*1b8adde7SWilliam Kucharskifilesystem backend desires.
215*1b8adde7SWilliam Kucharski@end vtable
216*1b8adde7SWilliam Kucharski
217*1b8adde7SWilliam KucharskiThe variables which need to be written by a filesystem backend are:
218*1b8adde7SWilliam Kucharski
219*1b8adde7SWilliam Kucharski@vtable @code
220*1b8adde7SWilliam Kucharski@item filepos
221*1b8adde7SWilliam KucharskiThe current position in the file, in sectors.
222*1b8adde7SWilliam Kucharski
223*1b8adde7SWilliam Kucharski@strong{Caution:} the value of @var{filepos} can be changed out from
224*1b8adde7SWilliam Kucharskiunder the filesystem code in the current implementation. Don't depend on
225*1b8adde7SWilliam Kucharskiit being the same for later calls into the backend code!
226*1b8adde7SWilliam Kucharski
227*1b8adde7SWilliam Kucharski@item filemax
228*1b8adde7SWilliam KucharskiThe length of the file.
229*1b8adde7SWilliam Kucharski
230*1b8adde7SWilliam Kucharski@item disk_read_func
231*1b8adde7SWilliam KucharskiThe value of @var{disk_read_hook} @emph{only} during reading of data
232*1b8adde7SWilliam Kucharskifor the file, not any other fs data, inodes, FAT tables, whatever, then
233*1b8adde7SWilliam Kucharskiset to @code{NULL} at all other times (it will be @code{NULL} by
234*1b8adde7SWilliam Kucharskidefault). If this isn't done correctly, then the @command{testload} and
235*1b8adde7SWilliam Kucharski@command{install} commands won't work correctly.
236*1b8adde7SWilliam Kucharski@end vtable
237*1b8adde7SWilliam Kucharski
238*1b8adde7SWilliam KucharskiThe functions expected to be used by the filesystem backend are:
239*1b8adde7SWilliam Kucharski
240*1b8adde7SWilliam Kucharski@ftable @code
241*1b8adde7SWilliam Kucharski@item devread
242*1b8adde7SWilliam KucharskiOnly read sectors from within a partition. Sector 0 is the first sector
243*1b8adde7SWilliam Kucharskiin the partition.
244*1b8adde7SWilliam Kucharski
245*1b8adde7SWilliam Kucharski@item grub_read
246*1b8adde7SWilliam KucharskiIf the backend uses the block list code, then @code{grub_read} can be
247*1b8adde7SWilliam Kucharskiused, after setting @var{block_file} to 1.
248*1b8adde7SWilliam Kucharski
249*1b8adde7SWilliam Kucharski@item print_a_completion
250*1b8adde7SWilliam KucharskiIf @var{print_possibilities} is true, call @code{print_a_completion} for
251*1b8adde7SWilliam Kucharskieach possible file name. Otherwise, the file name completion won't work.
252*1b8adde7SWilliam Kucharski@end ftable
253*1b8adde7SWilliam Kucharski
254*1b8adde7SWilliam KucharskiThe functions expected to be defined by the filesystem backend are
255*1b8adde7SWilliam Kucharskidescribed at least moderately in the file @file{filesys.h}. Their usage
256*1b8adde7SWilliam Kucharskiis fairly evident from their use in the functions in @file{disk_io.c},
257*1b8adde7SWilliam Kucharskilook for the use of the @var{fsys_table} array.
258*1b8adde7SWilliam Kucharski
259*1b8adde7SWilliam Kucharski@strong{Caution:} The semantics are such that then @samp{mount}ing the
260*1b8adde7SWilliam Kucharskifilesystem, presume the filesystem buffer @code{FSYS_BUF} is corrupted,
261*1b8adde7SWilliam Kucharskiand (re-)load all important contents. When opening and reading a file,
262*1b8adde7SWilliam Kucharskipresume that the data from the @samp{mount} is available, and doesn't
263*1b8adde7SWilliam Kucharskiget corrupted by the open/read (i.e. multiple opens and/or reads will be
264*1b8adde7SWilliam Kucharskidone with only one mount if in the same filesystem).
265*1b8adde7SWilliam Kucharski
266*1b8adde7SWilliam Kucharski
267*1b8adde7SWilliam Kucharski@node Command interface
268*1b8adde7SWilliam Kucharski@section The generic interface for built-ins
269*1b8adde7SWilliam Kucharski
270*1b8adde7SWilliam KucharskiGRUB built-in commands are defined in a uniformal interface, whether
271*1b8adde7SWilliam Kucharskithey are menu-specific or can be used anywhere. The definition of a
272*1b8adde7SWilliam Kucharskibuiltin command consists of two parts: the code itself and the table of
273*1b8adde7SWilliam Kucharskithe information.
274*1b8adde7SWilliam Kucharski
275*1b8adde7SWilliam KucharskiThe code must be a function which takes two arguments, a command-line
276*1b8adde7SWilliam Kucharskistring and flags, and returns an @samp{int} value. The @dfn{flags}
277*1b8adde7SWilliam Kucharskiargument specifies how the function is called, using a bit mask. The
278*1b8adde7SWilliam Kucharskireturn value must be zero if successful, otherwise non-zero. So it is
279*1b8adde7SWilliam Kucharskinormally enough to return @var{errnum}.
280*1b8adde7SWilliam Kucharski
281*1b8adde7SWilliam KucharskiThe table of the information is represented by the structure
282*1b8adde7SWilliam Kucharski@code{struct builtin}, which contains the name of the command, a pointer
283*1b8adde7SWilliam Kucharskito the function, flags, a short description of the command and a long
284*1b8adde7SWilliam Kucharskidescription of the command. Since the descriptions are used only for
285*1b8adde7SWilliam Kucharskihelp messages interactively, you don't have to define them, if the
286*1b8adde7SWilliam Kucharskicommand may not be called interactively (such as @command{title}).
287*1b8adde7SWilliam Kucharski
288*1b8adde7SWilliam KucharskiThe table is finally registered in the table @var{builtin_table}, so
289*1b8adde7SWilliam Kucharskithat @code{run_script} and @code{enter_cmdline} can find the
290*1b8adde7SWilliam Kucharskicommand. See the files @file{cmdline.c} and @file{builtins.c}, for more
291*1b8adde7SWilliam Kucharskidetails.
292*1b8adde7SWilliam Kucharski
293*1b8adde7SWilliam Kucharski
294*1b8adde7SWilliam Kucharski@node Bootstrap tricks
295*1b8adde7SWilliam Kucharski@section The bootstrap mechanism used in GRUB
296*1b8adde7SWilliam Kucharski
297*1b8adde7SWilliam KucharskiThe disk space can be used in a boot loader is very restricted because
298*1b8adde7SWilliam Kucharskia MBR (@pxref{MBR}) is only 512 bytes but it also contains a partition
299*1b8adde7SWilliam Kucharskitable (@pxref{Partition table}) and a BPB. So the question is how to
300*1b8adde7SWilliam Kucharskimake a boot loader code enough small to be fit in a MBR.
301*1b8adde7SWilliam Kucharski
302*1b8adde7SWilliam KucharskiHowever, GRUB is a very large program, so we break GRUB into 2 (or 3)
303*1b8adde7SWilliam Kucharskidistinct components, @dfn{Stage 1} and @dfn{Stage 2} (and optionally
304*1b8adde7SWilliam Kucharski@dfn{Stage 1.5}). @xref{Memory map}, for more information.
305*1b8adde7SWilliam Kucharski
306*1b8adde7SWilliam KucharskiWe embed Stage 1 in a MBR or in the boot sector of a partition, and
307*1b8adde7SWilliam Kucharskiplace Stage 2 in a filesystem. The optional Stage 1.5 can be installed
308*1b8adde7SWilliam Kucharskiin a filesystem, in the @dfn{boot loader} area in a FFS or a ReiserFS,
309*1b8adde7SWilliam Kucharskiand in the sectors right after a MBR, because Stage 1.5 is enough small
310*1b8adde7SWilliam Kucharskiand the sectors right after a MBR is normally an unused region. The size
311*1b8adde7SWilliam Kucharskiof this region is the number of sectors per head minus 1.
312*1b8adde7SWilliam Kucharski
313*1b8adde7SWilliam KucharskiThus, all Stage1 must do is just load Stage2 or Stage1.5. But even if
314*1b8adde7SWilliam KucharskiStage 1 needs not to support the user interface or the filesystem
315*1b8adde7SWilliam Kucharskiinterface, it is impossible to make Stage 1 less than 400 bytes, because
316*1b8adde7SWilliam KucharskiGRUB should support both the CHS mode and the LBA mode (@pxref{Low-level
317*1b8adde7SWilliam Kucharskidisk I/O}).
318*1b8adde7SWilliam Kucharski
319*1b8adde7SWilliam KucharskiThe solution used by GRUB is that Stage 1 loads only the first sector of
320*1b8adde7SWilliam KucharskiStage 2 (or Stage 1.5) and Stage 2 itself loads the rest. The flow of
321*1b8adde7SWilliam KucharskiStage 1 is:
322*1b8adde7SWilliam Kucharski
323*1b8adde7SWilliam Kucharski@enumerate
324*1b8adde7SWilliam Kucharski@item
325*1b8adde7SWilliam KucharskiInitialize the system briefly.
326*1b8adde7SWilliam Kucharski
327*1b8adde7SWilliam Kucharski@item
328*1b8adde7SWilliam KucharskiDetect the geometry and the accessing mode of the @dfn{loading drive}.
329*1b8adde7SWilliam Kucharski
330*1b8adde7SWilliam Kucharski@item
331*1b8adde7SWilliam KucharskiLoad the first sector of Stage 2.
332*1b8adde7SWilliam Kucharski
333*1b8adde7SWilliam Kucharski@item
334*1b8adde7SWilliam KucharskiJump to the starting address of the Stage 2.
335*1b8adde7SWilliam Kucharski@end enumerate
336*1b8adde7SWilliam Kucharski
337*1b8adde7SWilliam KucharskiThe flow of Stage 2 (and Stage 1.5) is:
338*1b8adde7SWilliam Kucharski
339*1b8adde7SWilliam Kucharski@enumerate
340*1b8adde7SWilliam Kucharski@item
341*1b8adde7SWilliam KucharskiLoad the rest of itself to the real starting address, that is, the
342*1b8adde7SWilliam Kucharskistarting address plus 512 bytes. The block lists are stored in the last
343*1b8adde7SWilliam Kucharskipart of the first sector.
344*1b8adde7SWilliam Kucharski
345*1b8adde7SWilliam Kucharski@item
346*1b8adde7SWilliam KucharskiLong jump to the real starting address.
347*1b8adde7SWilliam Kucharski@end enumerate
348*1b8adde7SWilliam Kucharski
349*1b8adde7SWilliam KucharskiNote that Stage 2 (or Stage 1.5) does not probe the geometry
350*1b8adde7SWilliam Kucharskior the accessing mode of the @dfn{loading drive}, since Stage 1 has
351*1b8adde7SWilliam Kucharskialready probed them.
352*1b8adde7SWilliam Kucharski
353*1b8adde7SWilliam Kucharski
354*1b8adde7SWilliam Kucharski@node I/O ports detection
355*1b8adde7SWilliam Kucharski@section How to probe I/O ports used by INT 13H
356*1b8adde7SWilliam Kucharski
357*1b8adde7SWilliam KucharskiFIXME: I will write this chapter after implementing the new technique.
358*1b8adde7SWilliam Kucharski
359*1b8adde7SWilliam Kucharski
360*1b8adde7SWilliam Kucharski
361*1b8adde7SWilliam Kucharski@node Memory detection
362*1b8adde7SWilliam Kucharski@section How to detect all installed RAM
363*1b8adde7SWilliam Kucharski
364*1b8adde7SWilliam KucharskiFIXME: I doubt if Erich didn't write this chapter only himself wholly,
365*1b8adde7SWilliam Kucharskiso I will rewrite this chapter.
366*1b8adde7SWilliam Kucharski
367*1b8adde7SWilliam Kucharski
368*1b8adde7SWilliam Kucharski@node Low-level disk I/O
369*1b8adde7SWilliam Kucharski@section INT 13H disk I/O interrupts
370*1b8adde7SWilliam Kucharski
371*1b8adde7SWilliam KucharskiFIXME: I'm not sure where some part of the original chapter is derived,
372*1b8adde7SWilliam Kucharskiso I will rewrite this chapter.
373*1b8adde7SWilliam Kucharski
374*1b8adde7SWilliam Kucharski
375*1b8adde7SWilliam Kucharski@node MBR
376*1b8adde7SWilliam Kucharski@section The structure of Master Boot Record
377*1b8adde7SWilliam Kucharski
378*1b8adde7SWilliam KucharskiFIXME: Likewise.
379*1b8adde7SWilliam Kucharski
380*1b8adde7SWilliam Kucharski
381*1b8adde7SWilliam Kucharski@node Partition table
382*1b8adde7SWilliam Kucharski@section The format of partition tables
383*1b8adde7SWilliam Kucharski
384*1b8adde7SWilliam KucharskiFIXME: Probably the original chapter is derived from "How It Works", so
385*1b8adde7SWilliam KucharskiI will rewrite this chapter.
386*1b8adde7SWilliam Kucharski
387*1b8adde7SWilliam Kucharski
388*1b8adde7SWilliam Kucharski@node Submitting patches
389*1b8adde7SWilliam Kucharski@section Where and how you should send patches
390*1b8adde7SWilliam Kucharski
391*1b8adde7SWilliam KucharskiWhen you write patches for GRUB, please send them to the mailing list
392*1b8adde7SWilliam Kucharski@email{bug-grub@@gnu.org}. Here is the list of items of which you
393*1b8adde7SWilliam Kucharskishould take care:
394*1b8adde7SWilliam Kucharski
395*1b8adde7SWilliam Kucharski@itemize @bullet
396*1b8adde7SWilliam Kucharski@item
397*1b8adde7SWilliam KucharskiPlease make your patch as small as possible. Generally, it is not a good
398*1b8adde7SWilliam Kucharskithing to make one big patch which changes many things. Instead,
399*1b8adde7SWilliam Kucharskisegregate features and produce many patches.
400*1b8adde7SWilliam Kucharski
401*1b8adde7SWilliam Kucharski@item
402*1b8adde7SWilliam KucharskiUse as late code as possible, for the original code. The CVS repository
403*1b8adde7SWilliam Kucharskialways has the current version (@pxref{Obtaining and Building GRUB}).
404*1b8adde7SWilliam Kucharski
405*1b8adde7SWilliam Kucharski@item
406*1b8adde7SWilliam KucharskiWrite ChangeLog entries. @xref{Change Logs, , Change Logs, standards,
407*1b8adde7SWilliam KucharskiGNU Coding Standards}, if you don't know how to write ChangeLog.
408*1b8adde7SWilliam Kucharski
409*1b8adde7SWilliam Kucharski@item
410*1b8adde7SWilliam KucharskiMake patches in unified diff format. @samp{diff -urN} is appropriate in
411*1b8adde7SWilliam Kucharskimost cases.
412*1b8adde7SWilliam Kucharski
413*1b8adde7SWilliam Kucharski@item
414*1b8adde7SWilliam KucharskiDon't make patches reversely. Reverse patches are difficult to read and
415*1b8adde7SWilliam Kucharskiuse.
416*1b8adde7SWilliam Kucharski
417*1b8adde7SWilliam Kucharski@item
418*1b8adde7SWilliam KucharskiBe careful enough of the license term and the copyright. Because GRUB
419*1b8adde7SWilliam Kucharskiis under GNU General Public License, you may not steal code from
420*1b8adde7SWilliam Kucharskisoftware whose license is incompatible against GPL. And, if you copy
421*1b8adde7SWilliam Kucharskicode written by others, you must not ignore their copyrights. Feel free
422*1b8adde7SWilliam Kucharskito ask GRUB maintainers, whenever you are not sure what you should do.
423*1b8adde7SWilliam Kucharski
424*1b8adde7SWilliam Kucharski@item
425*1b8adde7SWilliam KucharskiIf your patch is too large to send in e-mail, put it at somewhere we can
426*1b8adde7SWilliam Kucharskisee. Usually, you shouldn't send e-mail over 20K.
427*1b8adde7SWilliam Kucharski@end itemize
428