source: grub-pc/trunk/fuentes/docs/grub-dev.info @ 22

Last change on this file since 22 was 22, checked in by mabarracus, 5 years ago

updated version and apply net.ifnames=0 into debian/rules

File size: 98.8 KB
Line 
1This is grub-dev.info, produced by makeinfo version 5.2 from
2grub-dev.texi.
3
4This developer manual is for GNU GRUB (version 2.02~beta2, 17 December
52013).
6
7   Copyright (C) 1999,2000,2001,2002,2004,2005,2006,2008,2009,2010,2011
8Free Software Foundation, Inc.
9
10     Permission is granted to copy, distribute and/or modify this
11     document under the terms of the GNU Free Documentation License,
12     Version 1.2 or any later version published by the Free Software
13     Foundation; with no Invariant Sections.
14INFO-DIR-SECTION Kernel
15START-INFO-DIR-ENTRY
16* grub-dev: (grub-dev).                 The GRand Unified Bootloader Dev
17END-INFO-DIR-ENTRY
18
19
20File: grub-dev.info,  Node: Top,  Next: Getting the source code,  Up: (dir)
21
22GNU GRUB developer manual
23*************************
24
25This is the developer documentation of GNU GRUB, the GRand Unified
26Bootloader, a flexible and powerful boot loader program for a wide range
27of architectures.
28
29   This edition documents version 2.02~beta2.
30
31   This developer manual is for GNU GRUB (version 2.02~beta2, 17
32December 2013).
33
34   Copyright (C) 1999,2000,2001,2002,2004,2005,2006,2008,2009,2010,2011
35Free Software Foundation, Inc.
36
37     Permission is granted to copy, distribute and/or modify this
38     document under the terms of the GNU Free Documentation License,
39     Version 1.2 or any later version published by the Free Software
40     Foundation; with no Invariant Sections.
41
42* Menu:
43
44* Getting the source code::
45* Coding style::
46* Finding your way around::
47* Contributing Changes::
48* Porting::
49* Error Handling::
50* Stack and heap size::
51* BIOS port memory map::
52* Video Subsystem::
53* PFF2 Font File Format::
54* Graphical Menu Software Design::
55* Copying This Manual::         Copying This Manual
56* Index::
57
58
59File: grub-dev.info,  Node: Getting the source code,  Next: Coding style,  Prev: Top,  Up: Top
60
611 Getting the source code
62*************************
63
64GRUB is maintained using the <GIT revision control system>.  To fetch:
65
66     git clone git://git.sv.gnu.org/grub.git
67
68   Web access is available under
69     http://git.savannah.gnu.org/cgit/grub.git/
70
71   The branches available are:
72
73'master'
74     Main developpement branch.
75'grub-legacy'
76     GRUB 0.97 codebase.  Kept for reference and legal reasons
77'multiboot'
78     Multiboot specfication
79'multiboot2'
80     Multiboot2 specfication
81'developper branches'
82     Prefixed with developper name.  Every developper of a team manages
83     his own branches.  Developper branches do not need changelog
84     entries.
85
86   Once you have used 'git clone' to fetch an initial copy of a branch,
87you can use 'git pull' to keep it up to date.  If you have modified your
88local version, you may need to resolve conflicts when pulling.
89
90
91File: grub-dev.info,  Node: Coding style,  Next: Finding your way around,  Prev: Getting the source code,  Up: Top
92
932 Coding style
94**************
95
96Basically we follow the GNU Coding Standards
97(http://www.gnu.org/prep/standards_toc.html).  We define additional
98conventions for GRUB here.
99
100* Menu:
101
102* Naming Conventions::
103* Functions::
104* Variables::
105* Types::
106* Macros::
107* Comments::
108* Multi-Line Comments::
109
110
111File: grub-dev.info,  Node: Naming Conventions,  Next: Functions,  Up: Coding style
112
1132.1 Naming Conventions
114======================
115
116All global symbols (i.e.  functions, variables, types, and macros) must
117have the prefix grub_ or GRUB_.  The all capital form is used only by
118macros.
119
120
121File: grub-dev.info,  Node: Functions,  Next: Variables,  Prev: Naming Conventions,  Up: Coding style
122
1232.2 Functions
124=============
125
126If a function is global, its name must be prefixed with grub_ and must
127consist of only small letters.  If the function belongs to a specific
128function module, the name must also be prefixed with the module name.
129For example, if a function is for file systems, its name is prefixed
130with grub_fs_.  If a function is for FAT file system but not for all
131file systems, its name is prefixed with grub_fs_fat_.  The hierarchy is
132noted this way.
133
134   After a prefix, a function name must start with a verb (such as get
135or is).  It must not be a noun.  Some kind of abbreviation is permitted,
136as long as it wouldn't make code less readable (e.g.  init).
137
138   If a function is local, its name may not start with any prefix.  It
139must start with a verb.
140
141
142File: grub-dev.info,  Node: Variables,  Next: Types,  Prev: Functions,  Up: Coding style
143
1442.3 Variables
145=============
146
147The rule is mostly the same as functions, as noted above.  If a variable
148is global, its name must be prefixed with grub_ and must consist of only
149small letters.  If the variable belongs to a specific function module,
150the name must also be prefixed with the module name.  For example, if a
151function is for dynamic loading, its name is prefixed with grub_dl_.  If
152a variable is for ELF but not for all dynamic loading systems, its name
153is prefixed with grub_dl_elf_.
154
155   After a prefix, a variable name must start with a noun or an
156adjective (such as name or long) and it should end with a noun.  Some
157kind of abbreviation is permitted, as long as it wouldn't make code less
158readable (e.g.  i18n).
159
160   If a variable is global in the scope of a single file (i.e.  it is
161declared with static), its name may not start with any prefix.  It must
162start with a noun or an adjective.
163
164   If a variable is local, you may choose any shorter name, as long as
165it wouldn't make code less readable (e.g.  i).
166
167
168File: grub-dev.info,  Node: Types,  Next: Macros,  Prev: Variables,  Up: Coding style
169
1702.4 Types
171=========
172
173The name of a type must be prefixed with grub_ and must consist of only
174small letters.  If the type belongs to a specific function module, the
175name must also be prefixed with the module name.  For example, if a type
176is for OS loaders, its name is prefixed with grub_loader_.  If a type is
177for Multiboot but not for all OS loaders, its name is prefixed with
178grub_loader_linux_.
179
180   The name must be suffixed with _t, to emphasize the fact that it is a
181type but not a variable or a function.
182
183
184File: grub-dev.info,  Node: Macros,  Next: Comments,  Prev: Types,  Up: Coding style
185
1862.5 Macros
187==========
188
189If a macro is global, its name must be prefixed with GRUB_ and must
190consist of only large letters.  Other rules are the same as functions or
191variables, depending on whether a macro is used like a function or a
192variable.
193
194
195File: grub-dev.info,  Node: Comments,  Next: Multi-Line Comments,  Prev: Macros,  Up: Coding style
196
1972.6 Comments
198============
199
200All comments shall be C-style comments, of the form '/* ... */'.
201
202   Comments shall be placed only on a line by themselves.  They shall
203not be placed together with code, variable declarations, or other
204non-comment entities.  A comment should be placed immediately preceding
205the entity it describes.
206
207   Acceptable:
208     /* The page # that is the front buffer.  */
209     int displayed_page;
210     /* The page # that is the back buffer.  */
211     int render_page;
212
213   Unacceptable:
214     int displayed_page;           /* The page # that is the front buffer. */
215     int render_page;              /* The page # that is the back buffer. */
216
217
218File: grub-dev.info,  Node: Multi-Line Comments,  Prev: Comments,  Up: Coding style
219
2202.7 Multi-Line Comments
221=======================
222
223Comments spanning multiple lines shall be formatted with all lines after
224the first aligned with the first line.
225
226   Asterisk characters should not be repeated a the start of each
227subsequent line.
228
229   Acceptable:
230     /* This is a comment
231        which spans multiple lines.
232        It is long.  */
233
234   Unacceptable:
235     /*
236      * This is a comment
237      * which spans multiple lines.
238      * It is long. */
239
240   The opening '/*' and closing '*/' should be placed together on a line
241with text.
242
243
244File: grub-dev.info,  Node: Finding your way around,  Next: Contributing Changes,  Prev: Coding style,  Up: Top
245
2463 Finding your way around
247*************************
248
249Here is a brief map of the GRUB code base.
250
251   GRUB uses Autoconf and Automake, with most of the Automake input
252generated by AutoGen.  The top-level build rules are in 'configure.ac',
253'grub-core/Makefile.core.def', and 'Makefile.util.def'.  Each block in a
254'*.def' file represents a build target, and specifies the source files
255used to build it on various platforms.  The '*.def' files are processed
256into AutoGen input by 'gentpl.py' (which you only need to look at if you
257are extending the build system).  If you are adding a new module which
258follows an existing pattern, such as a new command or a new filesystem
259implementation, it is usually easiest to grep
260'grub-core/Makefile.core.def' and 'Makefile.util.def' for an existing
261example of that pattern to find out where it should be added.
262
263   In general, code that may be run at boot time is in a subdirectory of
264'grub-core', while code that is only run from within a full operating
265system is in a subdirectory of the top level.
266
267   Low-level boot code, such as the MBR implementation on PC BIOS
268systems, is in the 'grub-core/boot/' directory.
269
270   The GRUB kernel is in 'grub-core/kern/'.  This contains core
271facilities such as the device, disk, and file frameworks, environment
272variable handling, list processing, and so on.  The kernel should
273contain enough to get up to a rescue prompt.  Header files for kernel
274facilities, among others, are in 'include/'.
275
276   Terminal implementations are in 'grub-core/term/'.
277
278   Disk access code is spread across 'grub-core/disk/' (for accessing
279the disk devices themselves), 'grub-core/partmap/' (for interpreting
280partition table data), and 'grub-core/fs/' (for accessing filesystems).
281Note that, with the odd specialised exception, GRUB only contains code
282to _read_ from filesystems and tries to avoid containing any code to
283_write_ to filesystems; this lets us confidently assure users that GRUB
284cannot be responsible for filesystem corruption.
285
286   PCI and USB bus handling is in 'grub-core/bus/'.
287
288   Video handling code is in 'grub-core/video/'.  The graphical menu
289system uses this heavily, but is in a separate directory,
290'grub-core/gfxmenu/'.
291
292   Most commands are implemented by files in 'grub-core/commands/', with
293the following exceptions:
294
295   * A few core commands live in 'grub-core/kern/corecmd.c'.
296
297   * Commands related to normal mode live under 'grub-core/normal/'.
298
299   * Commands that load and boot kernels live under 'grub-core/loader/'.
300
301   * The 'loopback' command is really a disk device, and so lives in
302     'grub-core/disk/loopback.c'.
303
304   * The 'gettext' command lives under 'grub-core/gettext/'.
305
306   * The 'loadfont' and 'lsfonts' commands live under 'grub-core/font/'.
307
308   * The 'serial', 'terminfo', and 'background_image' commands live
309     under 'grub-core/term/'.
310
311   * The 'efiemu_*' commands live under 'grub-core/efiemu/'.
312
313   * OS-dependent code should be under 'grub-core/osdep/'
314
315   * Utility programs meant to be run from a full operating system
316     (except OS-dependent code mentioned previously) are in 'util/'.
317
318   There are a few other special-purpose exceptions; grep for them if
319they matter to you.
320
321
322File: grub-dev.info,  Node: Contributing Changes,  Next: Porting,  Prev: Finding your way around,  Up: Top
323
3244 Contributing changes
325**********************
326
327Contributing changes to GRUB 2 is welcomed activity.  However we have a
328bit of control what kind of changes will be accepted to GRUB 2.
329Therefore it is important to discuss your changes on grub-devel mailing
330list (see MailingLists).  On this page there are some basic details on
331the development process and activities.
332
333   First of all you should come up with the idea yourself what you want
334to contribute.  If you do not have that beforehand you are advised to
335study this manual and try GRUB 2 out to see what you think is missing
336from there.
337
338   Here are additional pointers:
339   * <https://savannah.gnu.org/task/?group=grub GRUB's Task Tracker>
340   * <https://savannah.gnu.org/bugs/?group=grub GRUB's Bug Tracker>
341
342   If you intended to make changes to GRUB Legacy (<=0.97) those are not
343accepted anymore.
344
345* Menu:
346
347* Getting started::
348* Typical Developer Experience::
349* When you are approved for write access to project's files::
350
351
352File: grub-dev.info,  Node: Getting started,  Next: Typical Developer Experience,  Up: Contributing Changes
353
3544.1 Getting started
355===================
356
357   * Always use latest GRUB 2 source code.  So get that first.
358
359     For developers it is recommended always to use the newest
360     development version of GRUB 2.  If development takes a long period
361     of time, please remember to keep in sync with newest developments
362     regularly so it is much easier to integrate your change in the
363     future.  GRUB 2 is being developed in a GIT repository.
364
365     Please check Savannah's GRUB project page for details how to get
366     newest git: GRUB 2 git Repository
367     (https://savannah.gnu.org/git/?group=grub)
368
369   * Compile it and try it out.
370
371     It is always good idea to first see that things work somehow and
372     after that to start to implement new features or develop fixes to
373     bugs.
374
375   * Study the code.
376
377     There are sometimes odd ways to do things in GRUB 2 code base.
378     This is mainly related to limited environment where GRUB 2 is being
379     executed.  You usually do not need to understand it all so it is
380     better to only try to look at places that relates to your work.
381     Please do not hesitate to ask for help if there is something that
382     you do not understand.
383
384   * Develop a new feature.
385
386     Now that you know what to do and how it should work in GRUB 2 code
387     base, please be free to develop it.  If you have not so far
388     announced your idea on grub-devel mailing list, please do it now.
389     This is to make sure you are not wasting your time working on the
390     solution that will not be integrated to GRUB 2 code base.
391
392     You might want to study our coding style before starting
393     development so you do not need to change much of the code when your
394     patch is being reviewed.  (see *note Coding style::)
395
396     For every accepted patch there has to exist a ChangeLog entry.  Our
397     ChangeLog consist of changes within source code and are not
398     describing about what the change logically does.  Please see
399     examples from previous entries.
400
401     Also remember that GRUB 2 is licensed under GPLv3 license and that
402     usually means that you are not allowed to copy pieces of code from
403     other projects.  Even if the source project's license would be
404     compatible with GPLv3, please discuss it beforehand on grub-devel
405     mailing list.
406
407   * Test your change.
408
409     Test that your change works properly.  Try it out a couple of
410     times, preferably on different systems, and try to find problems
411     with it.
412
413   * Publish your change.
414
415     When you are happy with your change, first make sure it is
416     compilable with latest development version of GRUB 2.  After that
417     please send a patch to grub-devel for review.  Please describe in
418     your email why you made the change, what it changes and so on.
419     Please be prepared to receive even discouraging comments about your
420     patch.  There is usually at least something that needs to be
421     improved in every patch.
422
423     Please use unified diff to make your patch (good match of arguments
424     for diff is '-pruN').
425
426   * Respond to received feedback.
427
428     If you are asked to modify your patch, please do that and resubmit
429     it for review.  If your change is large you are required to submit
430     a copyright agreement to FSF. Please keep in mind that if you are
431     asked to submit for copyright agreement, process can take some time
432     and is mandatory in order to get your changes integrated.
433
434     If you are not on grub-devel to respond to questions, most likely
435     your patch will not be accepted.  Also if problems arise from your
436     changes later on, it would be preferable that you also fix the
437     problem.  So stay around for a while.
438
439   * Your patch is accepted.
440
441     Good job!  Your patch will now be integrated into GRUB 2 mainline,
442     and if it didn't break anything it will be publicly available in
443     the next release.
444
445     Now you are welcome to do further improvements :)
446
447
448File: grub-dev.info,  Node: Typical Developer Experience,  Next: When you are approved for write access to project's files,  Prev: Getting started,  Up: Contributing Changes
449
4504.2 Typical Developer Experience
451================================
452
453The typical experience for a developer in this project is the following:
454
455  1. You find yourself wanting to do something (e.g.  fixing a bug).
456  2. You show some result in the mailing list or the IRC.
457  3. You are getting to be known to other developers.
458  4. You accumulate significant amount of contribution, so copyright
459     assignment is processed.
460  5. You are free to check in your changes on your own, legally
461     speaking.
462
463   At this point, it is rather annoying that you ought to ask somebody
464else every change to be checked in.  For efficiency, it is far better,
465if you can commit it yourself.  Therefore, our policy is to give you the
466write permission to our official repository, once you have shown your
467skill and will, and the FSF clerks have dealt with your copyright
468assignment.
469
470
471File: grub-dev.info,  Node: When you are approved for write access to project's files,  Prev: Typical Developer Experience,  Up: Contributing Changes
472
4734.3 When you are approved for write access to project's files
474=============================================================
475
476As you might know, GRUB is hosted on
477<https://savannah.gnu.org/projects/grub Savannah>, thus the membership
478is managed by Savannah.  This means that, if you want to be a member of
479this project:
480
481  1. You need to create your own account on Savannah.
482  2. You can submit "Request for Inclusion" from "My Groups" on
483     Savannah.
484
485   Then, one of the admins can approve your request, and you will be a
486member.  If you don't want to use the Savannah interface to submit a
487request, you can simply notify the admins by email or something else,
488alternatively.  But you still need to create an account beforehand.
489
490   NOTE: we sometimes receive a "Request for Inclusion" from an unknown
491person.  In this case, the request would be just discarded, since it is
492too dangerous to allow a stranger to be a member, which automatically
493gives him a commit right to the repository, both for a legal reason and
494for a technical reason.
495
496   If your intention is to just get started, please do not submit a
497inclusion request.  Instead, please subscribe to the mailing list, and
498communicate first (e.g.  sending a patch, asking a question, commenting
499on another message...).
500
501
502File: grub-dev.info,  Node: Porting,  Next: Error Handling,  Prev: Contributing Changes,  Up: Top
503
5045 Porting
505*********
506
507GRUB2 is designed to be easily portable accross platforms.  But because
508of the nature of bootloader every new port must be done separately.
509Here is how I did MIPS (loongson and ARC) and Xen ports.  Note than this
510is more of suggestions, not absolute truth.
511
512   First of all grab any architecture specifications you can find in
513public (please avoid NDA).
514
515   First stage is "Hello world".  I've done it outside of GRUB for
516simplicity.  Your task is to have a small program which is loadable as
517bootloader and clearly shows its presence to you.  If you have easily
518accessible console you can just print a message.  If you have a mapped
519framebuffer you know address of, you can draw a square.  If you have a
520debug facility, just hanging without crashing might be enough.  For the
521first stage you can choose to load the bootloader across the network
522since format for network image is often easier than for local boot and
523it skips the need of small intermediary stages and nvram handling.
524Additionally you can often have a good idea of the needed format by
525running "file" on any netbootable executable for given platform.
526
527   This program should probably have 2 parts: an assembler and C one.
528Assembler one handles BSS cleaning and other needed setup (on some
529platforms you may need to switch modes or copy the executable to its
530definitive position).  So your code may look like (x86 assembly for
531illustration purposes)
532
533             .globl _start
534     _start:
535        movl    $_bss_start, %edi
536        movl    $_end, %ecx
537        subl    %edi, %ecx
538        xorl    %eax, %eax
539        cld
540        rep
541        stosb
542             call main
543
544
545     static const char msg[] = "Hello, world";
546
547     void
548     putchar (int c)
549     {
550       ...
551     }
552
553     void
554     main (void)
555     {
556       const char *ptr = msg;
557       while (*ptr)
558         putchar (*ptr++);
559       while (1);
560     }
561
562   Sometimes you need a third file: assembly stubs for
563ABI-compatibility.
564
565   Once this file is functional it's time to move it into GRUB2.  The
566startup assembly file goes to grub-core/kern/$cpu/$platform/startup.S.
567You should also include grub/symbol.h and replace call to entry point
568with call to EXT_C(grub_main).  The C file goes to
569grub-core/kern/$cpu/$platform/init.c and its entry point is renamed to
570void grub_machine_init (void).  Keep final infinite loop for now.  Stubs
571file if any goes to grub-core/kern/$cpu/$platform/callwrap.S. Sometimes
572either $cpu or $platform is dropped if file is used on several cpus
573respectivelyplatforms.  Check those locations if they already have what
574you're looking for.
575
576   Then modify in configure.ac the following parts:
577
578   CPU names:
579
580     case "$target_cpu" in
581       i[[3456]]86)     target_cpu=i386 ;;
582       amd64)   target_cpu=x86_64 ;;
583       sparc)   target_cpu=sparc64 ;;
584       s390x)   target_cpu=s390 ;;
585       ...
586     esac
587
588   Sometimes CPU have additional architecture names which don't
589influence booting.  You might want to have some canonical name to avoid
590having bunch of identical platforms with different names.
591
592   NOTE: it doesn't influence compile optimisations which depend solely
593on chosen compiler and compile options.
594
595     if test "x$with_platform" = x; then
596       case "$target_cpu"-"$target_vendor" in
597         i386-apple) platform=efi ;;
598         i386-*) platform=pc ;;
599         x86_64-apple) platform=efi ;;
600         x86_64-*) platform=pc ;;
601         powerpc-*) platform=ieee1275 ;;
602         ...
603       esac
604     else
605       ...
606     fi
607
608   This part deals with guessing the platform from CPU and vendor.
609Sometimes you need to use 32-bit mode for booting even if OS runs in
61064-bit one.  If so add your platform to:
611
612     case "$target_cpu"-"$platform" in
613       x86_64-efi) ;;
614       x86_64-emu) ;;
615       x86_64-*) target_cpu=i386 ;;
616       powerpc64-ieee1275) target_cpu=powerpc ;;
617     esac
618
619   Add your platform to the list of supported ones:
620
621     case "$target_cpu"-"$platform" in
622       i386-efi) ;;
623       x86_64-efi) ;;
624       i386-pc) ;;
625       i386-multiboot) ;;
626       i386-coreboot) ;;
627       ...
628     esac
629
630   If explicit -m32 or -m64 is needed add it to:
631
632     case "$target_cpu" in
633       i386 | powerpc) target_m32=1 ;;
634       x86_64 | sparc64) target_m64=1 ;;
635     esac
636
637   Finally you need to add a conditional to the following block:
638
639     AM_CONDITIONAL([COND_mips_arc], [test x$target_cpu = xmips -a x$platform = xarc])
640     AM_CONDITIONAL([COND_sparc64_ieee1275], [test x$target_cpu = xsparc64 -a x$platform = xieee1275])
641     AM_CONDITIONAL([COND_powerpc_ieee1275], [test x$target_cpu = xpowerpc -a x$platform = xieee1275])
642
643   Next stop is gentpl.py.  You need to add your platform to the list of
644supported ones (sorry that this list is duplicated):
645
646     GRUB_PLATFORMS = [ "emu", "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot",
647                        "i386_multiboot", "i386_ieee1275", "x86_64_efi",
648                        "mips_loongson", "sparc64_ieee1275",
649                        "powerpc_ieee1275", "mips_arc", "ia64_efi",
650                        "mips_qemu_mips", "s390_mainframe" ]
651
652   You may also want already to add new platform to one or several of
653available groups.  In particular we always have a group for each CPU
654even when only one platform for given CPU is available.
655
656   Then comes grub-core/Makefile.core.def.  In the block "kernel" you'll
657need to define ldflags for your platform ($cpu_$platform_ldflags).  You
658also need to declare startup asm file ($cpu_$platform_startup) as well
659as any other files (e.g.  init.c and callwrap.S) (e.g.  $cpu_$platform =
660kern/$cpu/$platform/init.c).  At this stage you will also need to add
661dummy dl.c and cache.S with functions grub_err_t
662grub_arch_dl_check_header (void *ehdr), grub_err_t
663grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) (dl.c) and
664void grub_arch_sync_caches (void *address, grub_size_t len) (cache.S).
665They won't be used for now.
666
667   You will need to create directory include/$cpu/$platform and a file
668include/$cpu/types.h.  The later folowing this template:
669
670     #ifndef GRUB_TYPES_CPU_HEADER
671     #define GRUB_TYPES_CPU_HEADER      1
672
673     /* The size of void *.  */
674     #define GRUB_TARGET_SIZEOF_VOID_P  4
675
676     /* The size of long.  */
677     #define GRUB_TARGET_SIZEOF_LONG            4
678
679     /* mycpu is big-endian.  */
680     #define GRUB_TARGET_WORDS_BIGENDIAN        1
681     /* Alternatively: mycpu is little-endian.  */
682     #undef GRUB_TARGET_WORDS_BIGENDIAN
683
684     #endif /* ! GRUB_TYPES_CPU_HEADER */
685
686   You will also need to add a dummy file to datetime and setjmp modules
687to avoid any of it having no files.  It can be just completely empty at
688this stage.
689
690   You'll need to make grub-mkimage.c (util/grub_mkimage.c) aware of the
691needed format.  For most commonly used formats like ELF, PE, aout or raw
692the support is already present and you'll need to make it follow the
693existant code paths for your platform adding adjustments if necessary.
694When done compile:
695
696     ./autogen.sh
697     ./configure --target=$cpu --with-platform=$platform TARGET_CC=.. OBJCOPY=... STRIP=...
698     make > /dev/null
699
700   And create image
701
702     ./grub-mkimage -d grub-core -O $format_id -o test.img
703
704   And it's time to test your test.img.
705
706   If it works next stage is to have heap, console and timer.
707
708   To have the heap working you need to determine which regions are
709suitable for heap usage, allocate them from firmware and map (if
710applicable).  Then call grub_mm_init_region (vois *start, grub_size_t s)
711for every of this region.  As a shortcut for early port you can allocate
712right after _end or have a big static array for heap.  If you do you'll
713probably need to come back to this later.  As for output console you
714should distinguish between an array of text, terminfo or graphics-based
715console.  Many of real-world examples don't fit perfectly into any of
716these categories but one of the models is easier to be used as base.  In
717second and third case you should add your platform to terminfokernel
718respectively videoinkernel group.  A good example of array of text is
719i386-pc (kern/i386/pc/init.c and term/i386/pc/console.c).  Of terminfo
720is ieee1275 (kern/ieee1275/init.c and term/ieee1275/console.c).  Of
721video is loongson (kern/mips/loongson/init.c).  Note that terminfo has
722to be inited in 2 stages: one before (to get at least rudimentary
723console as early as possible) and another after the heap (to get
724full-featured console).  For the input there are string of keys,
725terminfo and direct hardware.  For string of keys look at i386-pc (same
726files), for termino ieee1275 (same files) and for hardware loongson
727(kern/mips/loongson/init.c and term/at_keyboard.c).
728
729   For the timer you'll need to call grub_install_get_time_ms (...)
730with as sole argument a function returning a grub_uint64_t of a number
731of milliseconds elapsed since arbitrary point in the past.
732
733   Once these steps accomplished you can remove the inifinite loop and
734you should be able to get to the minimal console.  Next step is to have
735module loading working.  For this you'll need to fill kern/$cpu/dl.c and
736kern/$cpu/cache.S with real handling of relocations and respectively the
737real sync of I and D caches.  Also you'll need to decide where in the
738image to store the modules.  Usual way is to have it concatenated at the
739end.  In this case you'll need to modify startup.S to copy modules out
740of bss to let's say ALIGN_UP (_end, 8) before cleaning out bss.  You'll
741probably find useful to add total_module_size field to startup.S. In
742init.c you need to set grub_modbase to the address where modules can be
743found.  You may need grub_modules_get_end () to avoid declaring the
744space occupied by modules as usable for heap.  You can test modules
745with:
746
747     ./grub-mkimage -d grub-core -O $format_id -o test.img hello
748
749   and then running "hello" in the shell.
750
751   Once this works, you should think of implementing disk access.  Look
752around disk/ for examples.
753
754   Then, very importantly, you probably need to implement the actual
755loader (examples available in loader/)
756
757   Last step to have minimally usable port is to add support to
758grub-install to put GRUB in a place where firmware or platform will pick
759it up.
760
761   Next steps are: filling datetime.c, setjmp.S, network (net/drivers),
762video (video/), halt (lib/), reboot (lib/).
763
764   Please add your platform to Platform limitations and Supported
765kernels chapter in user documentation and mention any steps you skipped
766which result in reduced features or performance.  Here is the quick
767checklist of features.  Some of them are less important than others and
768skipping them is completely ok, just needs to be mentioned in user
769documentation.
770
771   Checklist:
772   * Is heap big enough?
773   * Which charset is supported by console?
774   * Does platform have disk driver?
775   * Do you have network card support?
776   * Are you able to retrieve datetime (with date)?
777   * Are you able to set datetime (with date)?
778   * Is serial supported?
779   * Do you have direct disk support?
780   * Do you have direct keyboard support?
781   * Do you have USB support?
782   * Do you support loading through network?
783   * Do you support loading from disk?
784   * Do you support chainloading?
785   * Do you support network chainloading?
786   * Does cpuid command supports checking all CPU features that the user
787     might want conditionalise on (64-bit mode, hypervisor,...)
788   * Do you support hints?  How reliable are they?
789   * Does platform have ACPI? If so do "acpi" and "lsacpi" modules work?
790   * Do any of platform-specific operations mentioned in the relevant
791     section of user manual makes sense on your platform?
792   * Does your platform support PCI? If so is there an appropriate
793     driver for GRUB?
794   * Do you support badram?
795
796
797File: grub-dev.info,  Node: Error Handling,  Next: Stack and heap size,  Prev: Porting,  Up: Top
798
7996 Error Handling
800****************
801
802Error handling in GRUB 2 is based on exception handling model.  As C
803language doesn't directly support exceptions, exception handling
804behavior is emulated in software.
805
806   When exception is raised, function must return to calling function.
807If calling function does not provide handling of the exception it must
808return back to its calling function and so on, until exception is
809handled.  If exception is not handled before prompt is displayed, error
810message will be shown to user.
811
812   Exception information is stored on 'grub_errno' global variable.  If
813'grub_errno' variable contains value 'GRUB_ERR_NONE', there is no active
814exception and application can continue normal processing.  When
815'grub_errno' has other value, it is required that application code
816either handles this error or returns instantly to caller.  If function
817is with return type 'grub_err_t' is about to return 'GRUB_ERR_NONE', it
818should not set 'grub_errno' to that value.  Only set 'grub_errno' in
819cases where there is error situation.
820
821   Simple exception forwarder.
822     grub_err_t
823     forwarding_example (void)
824     {
825       /* Call function that might cause exception.  */
826       foobar ();
827
828       /* No special exception handler, just forward possible exceptions.  */
829       if (grub_errno != GRUB_ERR_NONE)
830         {
831           return grub_errno;
832         }
833
834       /* All is OK, do more processing.  */
835
836       /* Return OK signal, to caller.  */
837       return GRUB_ERR_NONE;
838     }
839
840   Error reporting has two components, the actual error code (of type
841'grub_err_t') and textual message that will be displayed to user.  List
842of valid error codes is listed in header file 'include/grub/err.h'.
843Textual error message can contain any textual data.  At time of writing,
844error message can contain up to 256 characters (including terminating
845NUL). To ease error reporting there is a helper function 'grub_error'
846that allows easier formatting of error messages and should be used
847instead of writing directly to global variables.
848
849   Example of error reporting.
850     grub_err_t
851     failing_example ()
852     {
853       return grub_error (GRUB_ERR_FILE_NOT_FOUND,
854                          "Failed to read %s, tried %d times.",
855                          "test.txt",
856                          10);
857     }
858
859   If there is a special reason that error code does not need to be
860taken account, 'grub_errno' can be zeroed back to 'GRUB_ERR_NONE'.  In
861cases like this all previous error codes should have been handled
862correctly.  This makes sure that there are no unhandled exceptions.
863
864   Example of zeroing 'grub_errno'.
865     grub_err_t
866     probe_example ()
867     {
868       /* Try to probe device type 1.  */
869       probe_for_device ();
870       if (grub_errno == GRUB_ERR_NONE)
871         {
872           /* Device type 1 was found on system.  */
873           register_device ();
874           return GRUB_ERR_NONE;
875         }
876       /* Zero out error code.  */
877       grub_errno = GRUB_ERR_NONE;
878
879       /* No device type 1 found, try to probe device type 2.  */
880       probe_for_device2 ();
881       if (grub_errno == GRUB_ERR_NONE)
882         {
883           /* Device type 2 was found on system.  */
884           register_device2 ();
885           return GRUB_ERR_NONE;
886         }
887       /* Zero out error code.  */
888       grub_errno = GRUB_ERR_NONE;
889
890       /* Return custom error message.  */
891       return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "No device type 1 or 2 found.");
892     }
893
894   Some times there is a need to continue processing even if there is a
895error state in application.  In situations like this, there is a needed
896to save old error state and then call other functions that might fail.
897To aid in this, there is a error stack implemented.  Error state can be
898pushed to error stack by calling function 'grub_error_push ()'.  When
899processing has been completed, 'grub_error_pop ()' can be used to pop
900error state from stack.  Error stack contains predefined amount of error
901stack items.  Error stack is protected for overflow and marks these
902situations so overflow error does not get unseen.  If there is no space
903available to store error message, it is simply discarded and overflow
904will be marked as happened.  When overflow happens, it most likely will
905corrupt error stack consistency as for pushed error there is no matching
906pop, but overflow message will be shown to inform user about the
907situation.  Overflow message will be shown at time when prompt is about
908to be drawn.
909
910   Example usage of error stack.
911     /* Save possible old error message.  */
912     grub_error_push ();
913
914     /* Do your stuff here.  */
915     call_possibly_failing_function ();
916
917     if (grub_errno != GRUB_ERR_NONE)
918       {
919         /* Inform rest of the code that there is error (grub_errno
920            is set). There is no pop here as we want both error states
921            to be displayed.  */
922         return;
923       }
924
925     /* Restore old error state by popping previous item from stack. */
926     grub_error_pop ();
927
928
929File: grub-dev.info,  Node: Stack and heap size,  Next: BIOS port memory map,  Prev: Error Handling,  Up: Top
930
9317 Stack and heap size
932*********************
933
934On emu stack and heap are just normal host OS stack and heap.  Stack is
935typically 8 MiB although it's OS-dependent.
936
937   On i386-pc, i386-coreboot, i386-qemu and i386-multiboot the stack is
93860KiB. All available space between 1MiB and 4GiB marks is part of heap.
939
940   On *-xen stack is 4MiB. If compiled for x86-64 with GCC 4.4 or later
941adressable space is unlimited.  When compiled for x86-64 with older GCC
942version adressable space is limited to 2GiB. When compiling for i386
943adressable space is limited to 4GiB. All adressable pages except the
944ones for stack, GRUB binary, special pages and page table are in the
945heap.
946
947   On *-efi GRUB uses same stack as EFI. If compiled for x86-64 with GCC
9484.4 or later adressable space is unlimited.  When compiled for x86-64
949with older GCC version adressable space is limited to 2GiB. For all
950other platforms adressable space is limited to 4GiB. GRUB allocates
951pages from EFI for its heap, at most 1.6 GiB.
952
953   On i386-ieee1275 and powerpc-ieee1275 GRUB uses same stack as
954IEEE1275.  It allocates at most 32MiB for its heap.
955
956   On sparc64-ieee1275 stack is 256KiB and heap is 2MiB.
957
958   On mips(el)-qemu_mips and mipsel-loongson stack is 2MiB (everything
959below GRUB image) and everything above GRUB image (from 2MiB + kernel
960size) until 256MiB is part of heap.
961
962   On mips-arc stack is 2MiB (everything below GRUB image) and
963everything above GRUB image(from 2MiB + kernel size) until 128MiB is
964part of heap.
965
966   On mipsel-arc stack is 2MiB (everything below GRUB image which is not
967part of ARC) and everything above GRUB image (from 7MiB + kernel size)
968until 256MiB is part of heap.
969
970   On arm-uboot stack is 256KiB and heap is 2MiB.
971
972   In short:
973
974Platform    Stack              Heap
975--------------------------------------------------------------------
976emu         8 MiB              ?
977i386-pc     60 KiB             < 4 GiB
978i386-coreboot60 KiB            < 4 GiB
979i386-multiboot60 KiB           < 4 GiB
980i386-qemu   60 KiB             < 4 GiB
981*-efi       ?                  < 1.6 GiB
982i386-ieee1275?                 < 32 MiB
983powerpc-ieee1275?              < 32 MiB
984sparc64-ieee1275256KiB         2 MiB
985arm-uboot   256KiB             2 MiB
986mips(el)-qemu_mips2MiB         253 MiB
987mipsel-loongson2MiB            253 MiB
988mips-arc    2MiB               125 MiB
989mipsel-arc  2MiB               248 MiB
990x86_64-xen  4MiB               unlimited
991(GCC >=
9924.4)
993x86_64-xen  4MiB               < 2GiB
994(GCC <
9954.4)
996i386-xen    4MiB               < 4GiB
997
998
999File: grub-dev.info,  Node: BIOS port memory map,  Next: Video Subsystem,  Prev: Stack and heap size,  Up: Top
1000
10018 BIOS port memory map
1002**********************
1003
1004Start       End                Usage
1005--------------------------------------------------------------------
10060           0x1000 - 1         BIOS and real mode interrupts
10070x07BE      0x07FF             Partition table passed to another
1008                               boot loader
1009?           0x2000 - 1         Real mode stack
10100x7C00      0x7D00 - 1         Boot sector
10110x8000      ?                  GRUB kernel
10120x68000     0x71000 - 1        Disk buffer
1013?           0x80000 - 1        Protected mode stack
1014?           0xA0000 - 1        Extended BIOS Data Area
10150xA0000     0xC0000 - 1        Video RAM
10160xC0000     0x100000 - 1       BIOS
10170x100000    ?                  Heap and module code
1018
1019
1020File: grub-dev.info,  Node: Video Subsystem,  Next: PFF2 Font File Format,  Prev: BIOS port memory map,  Up: Top
1021
10229 Video Subsystem
1023*****************
1024
1025This document contains specification for Video Subsystem for GRUB2.
1026Currently only the usage interface is described in this document.
1027Internal structure of how video drivers are registering and how video
1028driver manager works are not included here.
1029
1030* Menu:
1031
1032* Video API::
1033* Example usage of Video API::
1034* Bitmap API::
1035
1036
1037File: grub-dev.info,  Node: Video API,  Next: Example usage of Video API,  Up: Video Subsystem
1038
10399.1 Video API
1040=============
1041
10429.1.1 grub_video_setup
1043----------------------
1044
1045   * Prototype:
1046          grub_err_t
1047          grub_video_setup (unsigned int width, unsigned int height, unsigned int mode_type);
1048   * Description:
1049
1050     Driver will use information provided to it to select best possible
1051     video mode and switch to it.  Supported values for 'mode_type' are
1052     'GRUB_VIDEO_MODE_TYPE_INDEX_COLOR' for index color modes,
1053     'GRUB_VIDEO_MODE_TYPE_RGB' for direct RGB color modes and
1054     'GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED' for double buffering.  When
1055     requesting RGB mode, highest bits per pixel mode will be selected.
1056     When requesting Index color mode, mode with highest number of
1057     colors will be selected.  If all parameters are specified as zero,
1058     video adapter will try to figure out best possible mode and
1059     initialize it, platform specific differences are allowed here.  If
1060     there is no mode matching request, error X will be returned.  If
1061     there are no problems, function returns 'GRUB_ERR_NONE'.
1062
1063     This function also performs following task upon succesful mode
1064     switch.  Active rendering target is changed to screen and viewport
1065     is maximized to allow whole screen to be used when performing
1066     graphics operations.  In RGB modes, emulated palette gets 16
1067     entries containing default values for VGA palette, other colors are
1068     defined as black.  When switching to Indexed Color mode, driver may
1069     set default VGA palette to screen if the video card allows the
1070     operation.
1071
10729.1.2 grub_video_restore
1073------------------------
1074
1075   * Prototype:
1076
1077          grub_err_t
1078          grub_video_restore (void);
1079   * Description:
1080
1081     Video subsystem will deinitialize activated video driver to restore
1082     old state of video device.  This can be used to switch back to text
1083     mode.
1084
10859.1.3 grub_video_get_info
1086-------------------------
1087
1088   * Prototype:
1089
1090          grub_err_t
1091          grub_video_get_info (struct grub_video_mode_info *mode_info);
1092          struct grub_video_mode_info
1093          {
1094            /* Width of the screen.  */
1095            unsigned int width;
1096            /* Height of the screen.  */
1097            unsigned int height;
1098            /* Mode type bitmask.  Contains information like is it Index color or
1099               RGB mode.  */
1100            unsigned int mode_type;
1101            /* Bits per pixel.  */
1102            unsigned int bpp;
1103            /* Bytes per pixel.  */
1104            unsigned int bytes_per_pixel;
1105            /* Pitch of one scanline.  How many bytes there are for scanline.  */
1106            unsigned int pitch;
1107            /* In index color mode, number of colors.  In RGB mode this is 256.  */
1108            unsigned int number_of_colors;
1109            /* Optimization hint how binary data is coded.  */
1110            enum grub_video_blit_format blit_format;
1111            /* How many bits are reserved for red color.  */
1112            unsigned int red_mask_size;
1113            /* What is location of red color bits.  In Index Color mode, this is 0.  */
1114            unsigned int red_field_pos;
1115            /* How many bits are reserved for green color.  */
1116            unsigned int green_mask_size;
1117            /* What is location of green color bits.  In Index Color mode, this is 0.  */
1118            unsigned int green_field_pos;
1119            /* How many bits are reserved for blue color.  */
1120            unsigned int blue_mask_size;
1121            /* What is location of blue color bits.  In Index Color mode, this is 0.  */
1122            unsigned int blue_field_pos;
1123            /* How many bits are reserved in color.  */
1124            unsigned int reserved_mask_size;
1125            /* What is location of reserved color bits.  In Index Color mode,
1126               this is 0.  */
1127            unsigned int reserved_field_pos;
1128          };
1129   * Description:
1130
1131     Software developer can use this function to query properties of
1132     active rendering taget.  Information provided here can be used by
1133     other parts of GRUB, like image loaders to convert loaded images to
1134     correct screen format to allow more optimized blitters to be used.
1135     If there there is no configured video driver with active screen,
1136     error 'GRUB_ERR_BAD_DEVICE' is returned, otherwise 'mode_info' is
1137     filled with valid information and 'GRUB_ERR_NONE' is returned.
1138
11399.1.4 grub_video_get_blit_format
1140--------------------------------
1141
1142   * Prototype:
1143
1144          enum grub_video_blit_format
1145          grub_video_get_blit_format (struct grub_video_mode_info *mode_info);
1146          enum grub_video_blit_format
1147            {
1148              /* Follow exactly field & mask information.  */
1149              GRUB_VIDEO_BLIT_FORMAT_RGBA,
1150              /* Make optimization assumption.  */
1151              GRUB_VIDEO_BLIT_FORMAT_R8G8B8A8,
1152              /* Follow exactly field & mask information.  */
1153              GRUB_VIDEO_BLIT_FORMAT_RGB,
1154              /* Make optimization assumption.  */
1155              GRUB_VIDEO_BLIT_FORMAT_R8G8B8,
1156              /* When needed, decode color or just use value as is.  */
1157              GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR
1158            };
1159   * Description:
1160
1161     Used to query how data could be optimized to suit specified video
1162     mode.  Returns exact video format type, or a generic one if there
1163     is no definition for the type.  For generic formats, use
1164     'grub_video_get_info' to query video color coding settings.
1165
11669.1.5 grub_video_set_palette
1167----------------------------
1168
1169   * Prototype:
1170
1171          grub_err_t
1172          grub_video_set_palette (unsigned int start, unsigned int count, struct grub_video_palette_data *palette_data);
1173          struct grub_video_palette_data
1174          {
1175              grub_uint8_t r; /* Red color value (0-255). */
1176              grub_uint8_t g; /* Green color value (0-255). */
1177              grub_uint8_t b; /* Blue color value (0-255). */
1178              grub_uint8_t a; /* Reserved bits value (0-255). */
1179          };
1180   * Description:
1181
1182     Used to setup indexed color palettes.  If mode is RGB mode, colors
1183     will be set to emulated palette data.  In Indexed Color modes,
1184     palettes will be set to hardware.  Color values will be converted
1185     to suit requirements of the video mode.  'start' will tell what
1186     hardware color index (or emulated color index) will be set to
1187     according information in first indice of 'palette_data', after that
1188     both hardware color index and 'palette_data' index will be
1189     incremented until 'count' number of colors have been set.
1190
11919.1.6 grub_video_get_palette
1192----------------------------
1193
1194   * Prototype:
1195
1196          grub_err_t
1197          grub_video_get_palette (unsigned int start, unsigned int count, struct grub_video_palette_data *palette_data);
1198          struct grub_video_palette_data
1199          {
1200              grub_uint8_t r; /* Red color value (0-255). */
1201              grub_uint8_t g; /* Green color value (0-255). */
1202              grub_uint8_t b; /* Blue color value (0-255). */
1203              grub_uint8_t a; /* Reserved bits value (0-255). */
1204          };
1205   * Description:
1206
1207     Used to query indexed color palettes.  If mode is RGB mode, colors
1208     will be copied from emulated palette data.  In Indexed Color modes,
1209     palettes will be read from hardware.  Color values will be
1210     converted to suit structure format.  'start' will tell what
1211     hardware color index (or emulated color index) will be used as a
1212     source for first indice of 'palette_data', after that both hardware
1213     color index and 'palette_data' index will be incremented until
1214     'count' number of colors have been read.
1215
12169.1.7 grub_video_set_area_status
1217--------------------------------
1218
1219   * Prototype:
1220          grub_err_t
1221          grub_video_set_area_status (grub_video_area_status_t area_status);
1222          enum grub_video_area_status_t
1223            {
1224              GRUB_VIDEO_AREA_DISABLED,
1225              GRUB_VIDEO_AREA_ENABLED
1226            };
1227
1228   * Description:
1229
1230     Used to set area drawing mode for redrawing the specified region.
1231     Draw commands are performed in the intersection of the viewport and
1232     the region called area.  Coordinates remain related to the
1233     viewport.  If draw commands try to draw over the area, they are
1234     clipped.  Set status to DISABLED if you need to draw everything.
1235     Set status to ENABLED and region to the desired rectangle to redraw
1236     everything inside the region leaving everything else intact.
1237     Should be used for redrawing of active elements.
1238
12399.1.8 grub_video_get_area_status
1240--------------------------------
1241
1242   * Prototype:
1243          grub_err_r
1244          grub_video_get_area_status (grub_video_area_status_t *area_status);
1245
1246   * Description: Used to query the area status.
1247
12489.1.9 grub_video_set_viewport
1249-----------------------------
1250
1251   * Prototype:
1252
1253          grub_err_t
1254          grub_video_set_viewport (unsigned int x, unsigned int y, unsigned int width, unsigned int height);
1255   * Description:
1256
1257     Used to specify viewport where draw commands are performed.  When
1258     viewport is set, all draw commands coordinates relate to those
1259     specified by 'x' and 'y'.  If draw commands try to draw over
1260     viewport, they are clipped.  If developer requests larger than
1261     possible viewport, width and height will be clamped to fit screen.
1262     If 'x' and 'y' are out of bounds, all functions drawing to screen
1263     will not be displayed.  In order to maximize viewport, use
1264     'grub_video_get_info' to query actual screen dimensions and provide
1265     that information to this function.
1266
12679.1.10 grub_video_get_viewport
1268------------------------------
1269
1270   * Prototype:
1271
1272          grub_err_t
1273          grub_video_get_viewport (unsigned int *x, unsigned int *y, unsigned int *width, unsigned int *height);
1274   * Description:
1275
1276     Used to query current viewport dimensions.  Software developer can
1277     use this to choose best way to render contents of the viewport.
1278
12799.1.11 grub_video_set_region
1280----------------------------
1281
1282   * Prototype:
1283
1284          grub_err_t
1285          grub_video_set_region (unsigned int x, unsigned int y, unsigned int width, unsigned int height);
1286   * Description:
1287
1288     Used to specify the region of the screen which should be redrawn.
1289     Use absolute values.  When the region is set and area status is
1290     ENABLE all draw commands will be performed inside the interseption
1291     of region and viewport named area.  If draw commands try to draw
1292     over viewport, they are clipped.  If developer requests larger than
1293     possible region, width and height will be clamped to fit screen.
1294     Should be used for redrawing of active elements.
1295
12969.1.12 grub_video_get_region
1297----------------------------
1298
1299   * Prototype:
1300
1301          grub_err_t
1302          grub_video_get_region (unsigned int *x, unsigned int *y, unsigned int *width, unsigned int *height);
1303   * Description:
1304
1305     Used to query current region dimensions.
1306
13079.1.13 grub_video_map_color
1308---------------------------
1309
1310   * Prototype:
1311
1312          grub_video_color_t
1313          grub_video_map_color (grub_uint32_t color_name);
1314   * Description:
1315
1316     Map color can be used to support color themes in GRUB. There will
1317     be collection of color names that can be used to query actual
1318     screen mapped color data.  Examples could be
1319     'GRUB_COLOR_CONSOLE_BACKGROUND', 'GRUB_COLOR_CONSOLE_TEXT'.  The
1320     actual color defines are not specified at this point.
1321
13229.1.14 grub_video_map_rgb
1323-------------------------
1324
1325   * Prototype:
1326
1327          grub_video_color_t
1328          grub_video_map_rgb (grub_uint8_t red, grub_uint8_t green, grub_uint8_t blue);
1329   * Description:
1330
1331     Map RGB values to compatible screen color data.  Values are
1332     expected to be in range 0-255 and in RGB modes they will be
1333     converted to screen color data.  In index color modes, index color
1334     palette will be searched for specified color and then index is
1335     returned.
1336
13379.1.15 grub_video_map_rgba
1338--------------------------
1339
1340   * Prototype:
1341
1342          grub_video_color_t
1343          grub_video_map_rgba (grub_uint8_t red, grub_uint8_t green, grub_uint8_t blue, grub_uint8_t alpha);
1344   * Description:
1345
1346     Map RGBA values to compatible screen color data.  Values are
1347     expected to be in range 0-255.  In RGBA modes they will be
1348     converted to screen color data.  In index color modes, index color
1349     palette will be searched for best matching color and its index is
1350     returned.
1351
13529.1.16 grub_video_unmap_color
1353-----------------------------
1354
1355   * Prototype:
1356
1357          grub_err_t
1358          grub_video_unmap_color (grub_video_color_t color, grub_uint8_t *red, grub_uint8_t *green, grub_uint8_t *blue, grub_uint8_t *alpha);
1359   * Description:
1360
1361     Unmap color value from 'color' to color channels in 'red', 'green',
1362     'blue' and 'alpha'.  Values will be in range 0-255.  Active
1363     rendering target will be used for color domain.  In case alpha
1364     information is not available in rendering target, it is assumed to
1365     be opaque (having value 255).
1366
13679.1.17 grub_video_fill_rect
1368---------------------------
1369
1370   * Prototype:
1371
1372          grub_err_t
1373          grub_video_fill_rect (grub_video_color_t color, int x, int y, unsigned int width, unsigned int height);
1374   * Description:
1375
1376     Fill specified area limited by given coordinates within specified
1377     viewport.  Negative coordinates are accepted in order to allow easy
1378     moving of rectangle within viewport.  If coordinates are negative,
1379     area of the rectangle will be shrinken to follow size limits of the
1380     viewport.
1381
1382     Software developer should use either 'grub_video_map_color',
1383     'grub_video_map_rgb' or 'grub_video_map_rgba' to map requested
1384     color to 'color' parameter.
1385
13869.1.18 grub_video_blit_glyph
1387----------------------------
1388
1389   * Prototype:
1390
1391          grub_err_t
1392          grub_video_blit_glyph (struct grub_font_glyph *glyph, grub_video_color_t color, int x, int y);
1393          struct grub_font_glyph {
1394              /* TBD. */
1395          };
1396   * Description:
1397
1398     Used to blit glyph to viewport in specified coodinates.  If glyph
1399     is at edge of viewport, pixels outside of viewport will be clipped
1400     out.  Software developer should use either 'grub_video_map_rgb' or
1401     'grub_video_map_rgba' to map requested color to 'color' parameter.
1402
14039.1.19 grub_video_blit_bitmap
1404-----------------------------
1405
1406   * Prototype:
1407
1408          grub_err_t
1409          grub_video_blit_bitmap (struct grub_video_bitmap *bitmap, enum grub_video_blit_operators oper, int x, int y, int offset_x, int offset_y, unsigned int width, unsigned int height);
1410          struct grub_video_bitmap
1411          {
1412              /* TBD. */
1413          };
1414
1415          enum grub_video_blit_operators
1416            {
1417              GRUB_VIDEO_BLIT_REPLACE,
1418              GRUB_VIDEO_BLIT_BLEND
1419            };
1420   * Description:
1421
1422     Used to blit bitmap to viewport in specified coordinates.  If part
1423     of bitmap is outside of viewport region, it will be clipped out.
1424     Offsets affect bitmap position where data will be copied from.
1425     Negative values for both viewport coordinates and bitmap offset
1426     coordinates are allowed.  If data is looked out of bounds of
1427     bitmap, color value will be assumed to be transparent.  If viewport
1428     coordinates are negative, area of the blitted rectangle will be
1429     shrinken to follow size limits of the viewport and bitmap.
1430     Blitting operator 'oper' specifies should source pixel replace data
1431     in screen or blend with pixel alpha value.
1432
1433     Software developer should use 'grub_video_bitmap_create' or
1434     'grub_video_bitmap_load' to create or load bitmap data.
1435
14369.1.20 grub_video_blit_render_target
1437------------------------------------
1438
1439   * Prototype:
1440
1441          grub_err_t
1442          grub_video_blit_render_target (struct grub_video_render_target *source, enum grub_video_blit_operators oper, int x, int y, int offset_x, int offset_y, unsigned int width, unsigned int height);
1443          struct grub_video_render_target {
1444              /* This is private data for video driver. Should not be accessed from elsewhere directly.  */
1445          };
1446
1447          enum grub_video_blit_operators
1448            {
1449              GRUB_VIDEO_BLIT_REPLACE,
1450              GRUB_VIDEO_BLIT_BLEND
1451            };
1452   * Description:
1453
1454     Used to blit source render target to viewport in specified
1455     coordinates.  If part of source render target is outside of
1456     viewport region, it will be clipped out.  If blitting operator is
1457     specified and source contains alpha values, resulting pixel color
1458     components will be calculated using formula ((src_color *
1459     src_alpha) + (dst_color * (255 - src_alpha)) / 255, if target
1460     buffer has alpha, it will be set to src_alpha.  Offsets affect
1461     render target position where data will be copied from.  If data is
1462     looked out of bounds of render target, color value will be assumed
1463     to be transparent.  Blitting operator 'oper' specifies should
1464     source pixel replace data in screen or blend with pixel alpha
1465     value.
1466
14679.1.21 grub_video_scroll
1468------------------------
1469
1470   * Prototype:
1471
1472          grub_err_t
1473          grub_video_scroll (grub_video_color_t color, int dx, int dy);
1474   * Description:
1475
1476     Used to scroll viewport to specified direction.  New areas are
1477     filled with specified color.  This function is used when screen is
1478     scroller up in video terminal.
1479
14809.1.22 grub_video_swap_buffers
1481------------------------------
1482
1483   * Prototype:
1484
1485          grub_err_t
1486          grub_video_swap_buffers (void);
1487   * Description:
1488
1489     If double buffering is enabled, this swaps frontbuffer and
1490     backbuffer, in order to show values drawn to back buffer.  Video
1491     driver is free to choose how this operation is techincally done.
1492
14939.1.23 grub_video_create_render_target
1494--------------------------------------
1495
1496   * Prototype:
1497
1498          grub_err_t
1499          grub_video_create_render_target (struct grub_video_render_target **result, unsigned int width, unsigned int height, unsigned int mode_type);
1500          struct grub_video_render_target {
1501              /* This is private data for video driver. Should not be accessed from elsewhere directly.  */
1502          };
1503   * Description:
1504
1505     Driver will use information provided to it to create best fitting
1506     render target.  'mode_type' will be used to guide on selecting what
1507     features are wanted for render target.  Supported values for
1508     'mode_type' are 'GRUB_VIDEO_MODE_TYPE_INDEX_COLOR' for index color
1509     modes, 'GRUB_VIDEO_MODE_TYPE_RGB' for direct RGB color modes and
1510     'GRUB_VIDEO_MODE_TYPE_ALPHA' for alpha component.
1511
15129.1.24 grub_video_delete_render_target
1513--------------------------------------
1514
1515   * Prototype:
1516
1517          grub_err_t
1518          grub_video_delete_render_target (struct grub_video_render_target *target);
1519   * Description:
1520
1521     Used to delete previously created render target.  If 'target'
1522     contains 'NULL' pointer, nothing will be done.  If render target is
1523     correctly destroyed, GRUB_ERR_NONE is returned.
1524
15259.1.25 grub_video_set_active_render_target
1526------------------------------------------
1527
1528   * Prototype:
1529
1530          grub_err_t
1531          grub_video_set_active_render_target (struct grub_video_render_target *target);
1532   * Description:
1533
1534     Sets active render target.  If this comand is successful all
1535     drawing commands will be done to specified 'target'.  There is also
1536     special values for target, 'GRUB_VIDEO_RENDER_TARGET_DISPLAY' used
1537     to reference screen's front buffer,
1538     'GRUB_VIDEO_RENDER_TARGET_FRONT_BUFFER' used to reference screen's
1539     front buffer (alias for 'GRUB_VIDEO_RENDER_TARGET_DISPLAY') and
1540     'GRUB_VIDEO_RENDER_TARGET_BACK_BUFFER' used to reference back
1541     buffer (if double buffering is enabled).  If render target is
1542     correclty switched GRUB_ERR_NONE is returned.  In no any event
1543     shall there be non drawable active render target.
1544
15459.1.26 grub_video_get_active_render_target
1546------------------------------------------
1547
1548   * Prototype:
1549
1550          grub_err_t
1551          grub_video_get_active_render_target (struct grub_video_render_target **target);
1552   * Description:
1553
1554     Returns currently active render target.  It returns value in
1555     'target' that can be subsequently issued back to
1556     'grub_video_set_active_render_target'.
1557
1558
1559File: grub-dev.info,  Node: Example usage of Video API,  Next: Bitmap API,  Prev: Video API,  Up: Video Subsystem
1560
15619.2 Example usage of Video API
1562==============================
1563
15649.2.1 Example of screen setup
1565-----------------------------
1566
1567     grub_err_t rc;
1568     /* Try to initialize video mode 1024 x 768 with direct RGB.  */
1569     rc = grub_video_setup (1024, 768, GRUB_VIDEO_MODE_TYPE_RGB);
1570     if (rc != GRUB_ERR_NONE)
1571     {
1572       /* Fall back to standard VGA Index Color mode.  */
1573       rc = grub_video_setup (640, 480, GRUB_VIDEO_MODE_TYPE_INDEX);
1574       if (rc != GRUB_ERR_NONE)
1575       {
1576       /* Handle error.  */
1577       }
1578     }
1579
15809.2.2 Example of setting up console viewport
1581--------------------------------------------
1582
1583     grub_uint32_t x, y, width, height;
1584     grub_video_color_t color;
1585     struct grub_font_glyph glyph;
1586     grub_err_t rc;
1587     /* Query existing viewport.  */
1588     grub_video_get_viewport (&x, &y, &width, &height);
1589     /* Fill background.  */
1590     color = grub_video_map_color (GRUB_COLOR_BACKGROUND);
1591     grub_video_fill_rect (color, 0, 0, width, height);
1592     /* Setup console viewport.  */
1593     grub_video_set_viewport (x + 10, y + 10, width - 20, height - 20);
1594     grub_video_get_viewport (&x, &y, &width, &height);
1595     color = grub_video_map_color (GRUB_COLOR_CONSOLE_BACKGROUND);
1596     grub_video_fill_rect (color, 0, 0, width, height);
1597     /* Draw text to viewport.  */
1598     color = grub_video_map_color (GRUB_COLOR_CONSOLE_TEXT);
1599     grub_font_get_glyph ('X', &glyph);
1600     grub_video_blit_glyph (&glyph, color, 0, 0);
1601
1602
1603File: grub-dev.info,  Node: Bitmap API,  Prev: Example usage of Video API,  Up: Video Subsystem
1604
16059.3 Bitmap API
1606==============
1607
16089.3.1 grub_video_bitmap_create
1609------------------------------
1610
1611   * Prototype:
1612          grub_err_t grub_video_bitmap_create (struct grub_video_bitmap **bitmap, unsigned int width, unsigned int height, enum grub_video_blit_format blit_format)
1613
1614   * Description:
1615
1616     Creates a new bitmap with given dimensions and blitting format.
1617     Allocated bitmap data can then be modified freely and finally
1618     blitted with 'grub_video_blit_bitmap' to rendering target.
1619
16209.3.2 grub_video_bitmap_destroy
1621-------------------------------
1622
1623   * Prototype:
1624          grub_err_t grub_video_bitmap_destroy (struct grub_video_bitmap *bitmap);
1625
1626   * Description:
1627
1628     When bitmap is no longer needed, it can be freed from memory using
1629     this command.  'bitmap' is previously allocated bitmap with
1630     'grub_video_bitmap_create' or loaded with 'grub_video_bitmap_load'.
1631
16329.3.3 grub_video_bitmap_load
1633----------------------------
1634
1635   * Prototype:
1636          grub_err_t grub_video_bitmap_load (struct grub_video_bitmap **bitmap, const char *filename);
1637
1638   * Description:
1639
1640     Tries to load given bitmap ('filename') using registered bitmap
1641     loaders.  In case bitmap format is not recognized or supported
1642     error 'GRUB_ERR_BAD_FILE_TYPE' is returned.
1643
16449.3.4 grub_video_bitmap_get_width
1645---------------------------------
1646
1647   * Prototype:
1648          unsigned int grub_video_bitmap_get_width (struct grub_video_bitmap *bitmap);
1649
1650   * Description:
1651
1652     Returns bitmap width.
1653
16549.3.5 grub_video_bitmap_get_height
1655----------------------------------
1656
1657   * Prototype:
1658          unsigned int grub_video_bitmap_get_height (struct grub_video_bitmap *bitmap);
1659
1660   * Description:
1661
1662     Return bitmap height.
1663
16649.3.6 grub_video_bitmap_get_mode_info
1665-------------------------------------
1666
1667   * Prototype:
1668          void grub_video_bitmap_get_mode_info (struct grub_video_bitmap *bitmap, struct grub_video_mode_info *mode_info);
1669
1670   * Description:
1671
1672     Returns bitmap format details in form of 'grub_video_mode_info'.
1673
16749.3.7 grub_video_bitmap_get_data
1675--------------------------------
1676
1677   * Prototype:
1678          void *grub_video_bitmap_get_data (struct grub_video_bitmap *bitmap);
1679
1680   * Description:
1681
1682     Return pointer to bitmap data.  Contents of the pointed data can be
1683     freely modified.  There is no extra protection against going off
1684     the bounds so you have to be carefull how to access the data.
1685
1686
1687File: grub-dev.info,  Node: PFF2 Font File Format,  Next: Graphical Menu Software Design,  Prev: Video Subsystem,  Up: Top
1688
168910 PFF2 Font File Format
1690************************
1691
1692* Menu:
1693
1694* Introduction::
1695* File Structure::
1696* Font Metrics::
1697
1698
1699File: grub-dev.info,  Node: Introduction,  Next: File Structure,  Up: PFF2 Font File Format
1700
170110.1 Introduction
1702=================
1703
1704The goal of this format is to provide a bitmap font format that is
1705simple to use, compact, and cleanly supports Unicode.
1706
170710.1.1 Goals of the GRUB Font Format
1708------------------------------------
1709
1710   * Simple to read and use.  Since GRUB will only be reading the font
1711     files, we are more concerned with making the code to read the font
1712     simple than we are with writing the font.
1713
1714   * Compact storage.  The fonts will generally be stored in a small
1715     boot partition where GRUB is located, and this may be on a
1716     removable storage device such as a CD or USB flash drive where
1717     space is more limited than it is on most hard drives.
1718
1719   * Unicode.  GRUB should not have to deal with multiple character
1720     encodings.  The font should always use Unicode character codes for
1721     simple internationalization.
1722
172310.1.2 Why Another Font Format?
1724-------------------------------
1725
1726There are many existing bitmap font formats that GRUB could use.
1727However, there are aspects of these formats that may make them less than
1728suitable for use in GRUB at this time:
1729
1730'BDF'
1731     Inefficient storage; uses ASCII to describe properties and
1732     hexadecimal numbers in ASCII for the bitmap rows.
1733'PCF'
1734     Many format variations such as byte order and bitmap padding (rows
1735     padded to byte, word, etc.)  would result in more complex code to
1736     handle the font format.
1737
1738
1739File: grub-dev.info,  Node: File Structure,  Next: Font Metrics,  Prev: Introduction,  Up: PFF2 Font File Format
1740
174110.2 File Structure
1742===================
1743
1744A file *section* consists of a 4-byte name, a 32-bit big-endian length
1745(not including the name or length), and then LENGTH more
1746section-type-specific bytes.
1747
1748   The standard file extension for PFF2 font files is '.pf2'.
1749
175010.2.1 Section Types
1751--------------------
1752
1753'FILE'
1754     *File type ID* (ASCII string).  This must be the first section in
1755     the file.  It has length 4 and the contents are the four bytes of
1756     the ASCII string 'PFF2'.
1757
1758'NAME'
1759     *Font name* (ASCII string).  This is the full font name including
1760     family, weight, style, and point size.  For instance, "Helvetica
1761     Bold Italic 14".
1762
1763'FAMI'
1764     *Font family name* (ASCII string).  For instance, "Helvetica".
1765     This should be included so that intelligent font substitution can
1766     take place.
1767
1768'WEIG'
1769     *Font weight* (ASCII string).  Valid values are 'bold' and
1770     'normal'.  This should be included so that intelligent font
1771     substitution can take place.
1772
1773'SLAN'
1774     *Font slant* (ASCII string).  Valid values are 'italic' and
1775     'normal'.  This should be included so that intelligent font
1776     substitution can take place.
1777
1778'PTSZ'
1779     *Font point size* (uint16be).
1780
1781'MAXW'
1782     *Maximum character width in pixels* (uint16be).
1783
1784'MAXH'
1785     *Maximum character height in pixels* (uint16be).
1786
1787'ASCE'
1788     *Ascent in pixels* (uint16be).  *Note Font Metrics::, for details.
1789
1790'DESC'
1791     *Descent in pixels* (uint16be).  *Note Font Metrics::, for details.
1792
1793'CHIX'
1794     *Character index.*  The character index begins with a 32-bit
1795     big-endian unsigned integer indicating the total size of the
1796     section, not including this size value.  For each character, there
1797     is an instance of the following entry structure:
1798
1799        * *Unicode code point.*  (32-bit big-endian integer.)
1800
1801        * *Storage flags.*  (byte.)
1802
1803             * Bits 2..0:
1804
1805               If equal to 000 binary, then the character data is stored
1806               uncompressed beginning at the offset indicated by the
1807               character's *offset* value.
1808
1809               If equal to 001 binary, then the character data is stored
1810               within a compressed character definition block that
1811               begins at the offset within the file indicated by the
1812               character's *offset* value.
1813
1814        * *Offset.*  (32-bit big-endian integer.)
1815
1816          A marker that indicates the remainder of the file is data
1817          accessed via the character index (CHIX) section.  When reading
1818          this font file, the rest of the file can be ignored when
1819          scanning the sections.  The length should be set to -1
1820          (0xFFFFFFFF).
1821
1822          Supported data structures:
1823
1824          Character definition Each character definition consists of:
1825
1826             * *Width.*  Width of the bitmap in pixels.  The bitmap's
1827               extents represent the glyph's bounding box.  'uint16be'.
1828
1829             * *Height.*  Height of the bitmap in pixels.  The bitmap's
1830               extents represent the glyph's bounding box.  'uint16be'.
1831
1832             * *X offset.*  The number of pixels to shift the bitmap by
1833               horizontally before drawing the character.  'int16be'.
1834
1835             * *Y offset.*  The number of pixels to shift the bitmap by
1836               vertically before drawing the character.  'int16be'.
1837
1838             * *Device width.*  The number of pixels to advance
1839               horizontally from this character's origin to the origin
1840               of the next character.  'int16be'.
1841
1842             * *Bitmap data.*  This is encoded as a string of bits.  It
1843               is organized as a row-major, top-down, left-to-right
1844               bitmap.  The most significant bit of each byte is taken
1845               to be the leftmost or uppermost bit in the byte.  For the
1846               sake of compact storage, rows are not padded to byte
1847               boundaries (i.e., a single byte may contain bits
1848               belonging to multiple rows).  The last byte of the bitmap
1849               *is* padded with zero bits in the bits positions to the
1850               right of the last used bit if the bitmap data does not
1851               fill the last byte.
1852
1853               The length of the *bitmap data* field is (WIDTH * HEIGHT
1854               + 7) / 8 using integer arithmetic, which is equivalent to
1855               ceil(WIDTH * HEIGHT / 8) using real number arithmetic.
1856
1857               It remains to be determined whether bitmap fonts usually
1858               make all glyph bitmaps the same height, or if smaller
1859               glyphs are stored with bitmaps having a lesser height.
1860               In the latter case, the baseline would have to be used to
1861               calculate the location the bitmap should be anchored at
1862               on screen.
1863
1864
1865File: grub-dev.info,  Node: Font Metrics,  Prev: File Structure,  Up: PFF2 Font File Format
1866
186710.3 Font Metrics
1868=================
1869
1870   * Ascent.  The distance from the baseline to the top of most
1871     characters.  Note that in some cases characters may extend above
1872     the ascent.
1873
1874   * Descent.  The distance from the baseline to the bottom of most
1875     characters.  Note that in some cases characters may extend below
1876     the descent.
1877
1878   * Leading.  The amount of space, in pixels, to leave between the
1879     descent of one line of text and the ascent of the next line.  This
1880     metrics is not specified in the current file format; instead, the
1881     font rendering engine calculates a reasonable leading value based
1882     on the other font metrics.
1883
1884   * Horizonal leading.  The amount of space, in pixels, to leave
1885     horizontally between the left and right edges of two adjacent
1886     glyphs.  The *device width* field determines the effective leading
1887     value that is used to render the font.
1888
1889[image src="font_char_metrics.png" text="Please fill this in."]
1890
1891   An illustration of how the various font metrics apply to characters.
1892
1893
1894File: grub-dev.info,  Node: Graphical Menu Software Design,  Next: Copying This Manual,  Prev: PFF2 Font File Format,  Up: Top
1895
189611 Graphical Menu Software Design
1897*********************************
1898
1899* Menu:
1900
1901* Introduction_2::
1902* Startup Sequence::
1903* GUI Components::
1904* Command Line Window::
1905
1906
1907File: grub-dev.info,  Node: Introduction_2,  Next: Startup Sequence,  Up: Graphical Menu Software Design
1908
190911.1 Introduction
1910=================
1911
1912The 'gfxmenu' module provides a graphical menu interface for GRUB 2.  It
1913functions as an alternative to the menu interface provided by the
1914'normal' module, which uses the grub terminal interface to display a
1915menu on a character-oriented terminal.
1916
1917   The graphical menu uses the GRUB video API, which is currently for
1918the VESA BIOS extensions (VBE) 2.0+.  This is supported on the i386-pc
1919platform.  However, the graphical menu itself does not depend on using
1920VBE, so if another GRUB video driver were implemented, the 'gfxmenu'
1921graphical menu would work on the new video driver as well.
1922
1923
1924File: grub-dev.info,  Node: Startup Sequence,  Next: GUI Components,  Prev: Introduction_2,  Up: Graphical Menu Software Design
1925
192611.2 Startup Sequence
1927=====================
1928
1929   * grub_enter_normal_mode [normal/main.c]
1930   * grub_normal_execute [normal/main.c]
1931   * read_config_file [normal/main.c]
1932   * (When 'gfxmenu.mod' is loaded with 'insmod', it will call
1933     'grub_menu_viewer_register()' to register itself.)
1934   * GRUB_MOD_INIT (gfxmenu) [gfxmenu/gfxmenu.c]
1935   * grub_menu_viewer_register [kern/menu_viewer.c]
1936   * grub_menu_viewer_show_menu [kern/menu_viewer.c]
1937   * get_current_menu_viewer() [kern/menu_viewer.c]
1938   * show_menu() [gfxmenu/gfxmenu.c]
1939   * grub_gfxmenu_model_new [gfxmenu/model.c]
1940   * grub_gfxmenu_view_new [gfxmenu/view.c]
1941   * set_graphics_mode [gfxmenu/view.c]
1942   * grub_gfxmenu_view_load_theme [gfxmenu/theme_loader.c]
1943
1944
1945File: grub-dev.info,  Node: GUI Components,  Next: Command Line Window,  Prev: Startup Sequence,  Up: Graphical Menu Software Design
1946
194711.3 GUI Components
1948===================
1949
1950The graphical menu implements a GUI component system that supports a
1951container-based layout system.  Components can be added to containers,
1952and containers (which are a type of component) can then be added to
1953other containers, to form a tree of components.  Currently, the root
1954component of this tree is a 'canvas' component, which allows manual
1955layout of its child components.
1956
1957   Components (non-container):
1958
1959   * label
1960   * image
1961   * progress_bar
1962   * circular_progress
1963   * list (currently hard coded to be a boot menu list)
1964
1965   Containers:
1966
1967   * canvas
1968   * hbox
1969   * vbox
1970
1971   The GUI component instances are created by the theme loader in
1972'gfxmenu/theme_loader.c' when a theme is loaded.  Theme files specify
1973statements such as '+vbox{ +label { text="Hello" } +label{ text="World"
1974} }' to add components to the component tree root.  By nesting the
1975component creation statements in the theme file, the instantiated
1976components are nested the same way.
1977
1978   When a component is added to a container, that new child is
1979considered *owned* by the container.  Great care should be taken if the
1980caller retains a reference to the child component, since it will be
1981destroyed if its parent container is destroyed.  A better choice instead
1982of storing a pointer to the child component is to use the component ID
1983to find the desired component.  Component IDs do not have to be unique
1984(it is often useful to have multiple components with an ID of
1985"__timeout__", for instance).
1986
1987   In order to access and use components in the component tree, there
1988are two functions (defined in 'gfxmenu/gui_util.c') that are
1989particularly useful:
1990
1991   * 'grub_gui_find_by_id (root, id, callback, userdata)':
1992
1993     This function ecursively traverses the component tree rooted at
1994     ROOT, and for every component that has an ID equal to ID, calls the
1995     function pointed to by CALLBACK with the matching component and the
1996     void pointer USERDATA as arguments.  The callback function can do
1997     whatever is desired to use the component passed in.
1998
1999   * 'grub_gui_iterate_recursively (root, callback, userdata)':
2000
2001     This function calls the function pointed to by CALLBACK for every
2002     component that is a descendant of ROOT in the component tree.  When
2003     the callback function is called, the component and the void pointer
2004     USERDATA as arguments.  The callback function can do whatever is
2005     desired to use the component passed in.
2006
2007
2008File: grub-dev.info,  Node: Command Line Window,  Prev: GUI Components,  Up: Graphical Menu Software Design
2009
201011.4 Command Line Window
2011========================
2012
2013The terminal window used to provide command line access within the
2014graphical menu is managed by 'gfxmenu/view.c'.  The 'gfxterm' terminal
2015is used, and it has been modified to allow rendering to an offscreen
2016render target to allow it to be composed into the double buffering
2017system that the graphical menu view uses.  This is bad for performance,
2018however, so it would probably be a good idea to make it possible to
2019temporarily disable double buffering as long as the terminal window is
2020visible.  There are still unresolved problems that occur when commands
2021are executed from the terminal window that change the graphics mode.
2022It's possible that making 'grub_video_restore()' return to the graphics
2023mode that was in use before 'grub_video_setup()' was called might fix
2024some of the problems.
2025
2026
2027File: grub-dev.info,  Node: Copying This Manual,  Next: Index,  Prev: Graphical Menu Software Design,  Up: Top
2028
2029Appendix A Copying This Manual
2030******************************
2031
2032* Menu:
2033
2034* GNU Free Documentation License::  License for copying this manual.
2035
2036
2037File: grub-dev.info,  Node: GNU Free Documentation License,  Up: Copying This Manual
2038
2039A.1 GNU Free Documentation License
2040==================================
2041
2042                      Version 1.2, November 2002
2043
2044     Copyright (C) 2000,2001,2002 Free Software Foundation, Inc.
2045     51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
2046
2047     Everyone is permitted to copy and distribute verbatim copies
2048     of this license document, but changing it is not allowed.
2049
2050  0. PREAMBLE
2051
2052     The purpose of this License is to make a manual, textbook, or other
2053     functional and useful document "free" in the sense of freedom: to
2054     assure everyone the effective freedom to copy and redistribute it,
2055     with or without modifying it, either commercially or
2056     noncommercially.  Secondarily, this License preserves for the
2057     author and publisher a way to get credit for their work, while not
2058     being considered responsible for modifications made by others.
2059
2060     This License is a kind of "copyleft", which means that derivative
2061     works of the document must themselves be free in the same sense.
2062     It complements the GNU General Public License, which is a copyleft
2063     license designed for free software.
2064
2065     We have designed this License in order to use it for manuals for
2066     free software, because free software needs free documentation: a
2067     free program should come with manuals providing the same freedoms
2068     that the software does.  But this License is not limited to
2069     software manuals; it can be used for any textual work, regardless
2070     of subject matter or whether it is published as a printed book.  We
2071     recommend this License principally for works whose purpose is
2072     instruction or reference.
2073
2074  1. APPLICABILITY AND DEFINITIONS
2075
2076     This License applies to any manual or other work, in any medium,
2077     that contains a notice placed by the copyright holder saying it can
2078     be distributed under the terms of this License.  Such a notice
2079     grants a world-wide, royalty-free license, unlimited in duration,
2080     to use that work under the conditions stated herein.  The
2081     "Document", below, refers to any such manual or work.  Any member
2082     of the public is a licensee, and is addressed as "you".  You accept
2083     the license if you copy, modify or distribute the work in a way
2084     requiring permission under copyright law.
2085
2086     A "Modified Version" of the Document means any work containing the
2087     Document or a portion of it, either copied verbatim, or with
2088     modifications and/or translated into another language.
2089
2090     A "Secondary Section" is a named appendix or a front-matter section
2091     of the Document that deals exclusively with the relationship of the
2092     publishers or authors of the Document to the Document's overall
2093     subject (or to related matters) and contains nothing that could
2094     fall directly within that overall subject.  (Thus, if the Document
2095     is in part a textbook of mathematics, a Secondary Section may not
2096     explain any mathematics.)  The relationship could be a matter of
2097     historical connection with the subject or with related matters, or
2098     of legal, commercial, philosophical, ethical or political position
2099     regarding them.
2100
2101     The "Invariant Sections" are certain Secondary Sections whose
2102     titles are designated, as being those of Invariant Sections, in the
2103     notice that says that the Document is released under this License.
2104     If a section does not fit the above definition of Secondary then it
2105     is not allowed to be designated as Invariant.  The Document may
2106     contain zero Invariant Sections.  If the Document does not identify
2107     any Invariant Sections then there are none.
2108
2109     The "Cover Texts" are certain short passages of text that are
2110     listed, as Front-Cover Texts or Back-Cover Texts, in the notice
2111     that says that the Document is released under this License.  A
2112     Front-Cover Text may be at most 5 words, and a Back-Cover Text may
2113     be at most 25 words.
2114
2115     A "Transparent" copy of the Document means a machine-readable copy,
2116     represented in a format whose specification is available to the
2117     general public, that is suitable for revising the document
2118     straightforwardly with generic text editors or (for images composed
2119     of pixels) generic paint programs or (for drawings) some widely
2120     available drawing editor, and that is suitable for input to text
2121     formatters or for automatic translation to a variety of formats
2122     suitable for input to text formatters.  A copy made in an otherwise
2123     Transparent file format whose markup, or absence of markup, has
2124     been arranged to thwart or discourage subsequent modification by
2125     readers is not Transparent.  An image format is not Transparent if
2126     used for any substantial amount of text.  A copy that is not
2127     "Transparent" is called "Opaque".
2128
2129     Examples of suitable formats for Transparent copies include plain
2130     ASCII without markup, Texinfo input format, LaTeX input format,
2131     SGML or XML using a publicly available DTD, and standard-conforming
2132     simple HTML, PostScript or PDF designed for human modification.
2133     Examples of transparent image formats include PNG, XCF and JPG.
2134     Opaque formats include proprietary formats that can be read and
2135     edited only by proprietary word processors, SGML or XML for which
2136     the DTD and/or processing tools are not generally available, and
2137     the machine-generated HTML, PostScript or PDF produced by some word
2138     processors for output purposes only.
2139
2140     The "Title Page" means, for a printed book, the title page itself,
2141     plus such following pages as are needed to hold, legibly, the
2142     material this License requires to appear in the title page.  For
2143     works in formats which do not have any title page as such, "Title
2144     Page" means the text near the most prominent appearance of the
2145     work's title, preceding the beginning of the body of the text.
2146
2147     A section "Entitled XYZ" means a named subunit of the Document
2148     whose title either is precisely XYZ or contains XYZ in parentheses
2149     following text that translates XYZ in another language.  (Here XYZ
2150     stands for a specific section name mentioned below, such as
2151     "Acknowledgements", "Dedications", "Endorsements", or "History".)
2152     To "Preserve the Title" of such a section when you modify the
2153     Document means that it remains a section "Entitled XYZ" according
2154     to this definition.
2155
2156     The Document may include Warranty Disclaimers next to the notice
2157     which states that this License applies to the Document.  These
2158     Warranty Disclaimers are considered to be included by reference in
2159     this License, but only as regards disclaiming warranties: any other
2160     implication that these Warranty Disclaimers may have is void and
2161     has no effect on the meaning of this License.
2162
2163  2. VERBATIM COPYING
2164
2165     You may copy and distribute the Document in any medium, either
2166     commercially or noncommercially, provided that this License, the
2167     copyright notices, and the license notice saying this License
2168     applies to the Document are reproduced in all copies, and that you
2169     add no other conditions whatsoever to those of this License.  You
2170     may not use technical measures to obstruct or control the reading
2171     or further copying of the copies you make or distribute.  However,
2172     you may accept compensation in exchange for copies.  If you
2173     distribute a large enough number of copies you must also follow the
2174     conditions in section 3.
2175
2176     You may also lend copies, under the same conditions stated above,
2177     and you may publicly display copies.
2178
2179  3. COPYING IN QUANTITY
2180
2181     If you publish printed copies (or copies in media that commonly
2182     have printed covers) of the Document, numbering more than 100, and
2183     the Document's license notice requires Cover Texts, you must
2184     enclose the copies in covers that carry, clearly and legibly, all
2185     these Cover Texts: Front-Cover Texts on the front cover, and
2186     Back-Cover Texts on the back cover.  Both covers must also clearly
2187     and legibly identify you as the publisher of these copies.  The
2188     front cover must present the full title with all words of the title
2189     equally prominent and visible.  You may add other material on the
2190     covers in addition.  Copying with changes limited to the covers, as
2191     long as they preserve the title of the Document and satisfy these
2192     conditions, can be treated as verbatim copying in other respects.
2193
2194     If the required texts for either cover are too voluminous to fit
2195     legibly, you should put the first ones listed (as many as fit
2196     reasonably) on the actual cover, and continue the rest onto
2197     adjacent pages.
2198
2199     If you publish or distribute Opaque copies of the Document
2200     numbering more than 100, you must either include a machine-readable
2201     Transparent copy along with each Opaque copy, or state in or with
2202     each Opaque copy a computer-network location from which the general
2203     network-using public has access to download using public-standard
2204     network protocols a complete Transparent copy of the Document, free
2205     of added material.  If you use the latter option, you must take
2206     reasonably prudent steps, when you begin distribution of Opaque
2207     copies in quantity, to ensure that this Transparent copy will
2208     remain thus accessible at the stated location until at least one
2209     year after the last time you distribute an Opaque copy (directly or
2210     through your agents or retailers) of that edition to the public.
2211
2212     It is requested, but not required, that you contact the authors of
2213     the Document well before redistributing any large number of copies,
2214     to give them a chance to provide you with an updated version of the
2215     Document.
2216
2217  4. MODIFICATIONS
2218
2219     You may copy and distribute a Modified Version of the Document
2220     under the conditions of sections 2 and 3 above, provided that you
2221     release the Modified Version under precisely this License, with the
2222     Modified Version filling the role of the Document, thus licensing
2223     distribution and modification of the Modified Version to whoever
2224     possesses a copy of it.  In addition, you must do these things in
2225     the Modified Version:
2226
2227       A. Use in the Title Page (and on the covers, if any) a title
2228          distinct from that of the Document, and from those of previous
2229          versions (which should, if there were any, be listed in the
2230          History section of the Document).  You may use the same title
2231          as a previous version if the original publisher of that
2232          version gives permission.
2233
2234       B. List on the Title Page, as authors, one or more persons or
2235          entities responsible for authorship of the modifications in
2236          the Modified Version, together with at least five of the
2237          principal authors of the Document (all of its principal
2238          authors, if it has fewer than five), unless they release you
2239          from this requirement.
2240
2241       C. State on the Title page the name of the publisher of the
2242          Modified Version, as the publisher.
2243
2244       D. Preserve all the copyright notices of the Document.
2245
2246       E. Add an appropriate copyright notice for your modifications
2247          adjacent to the other copyright notices.
2248
2249       F. Include, immediately after the copyright notices, a license
2250          notice giving the public permission to use the Modified
2251          Version under the terms of this License, in the form shown in
2252          the Addendum below.
2253
2254       G. Preserve in that license notice the full lists of Invariant
2255          Sections and required Cover Texts given in the Document's
2256          license notice.
2257
2258       H. Include an unaltered copy of this License.
2259
2260       I. Preserve the section Entitled "History", Preserve its Title,
2261          and add to it an item stating at least the title, year, new
2262          authors, and publisher of the Modified Version as given on the
2263          Title Page.  If there is no section Entitled "History" in the
2264          Document, create one stating the title, year, authors, and
2265          publisher of the Document as given on its Title Page, then add
2266          an item describing the Modified Version as stated in the
2267          previous sentence.
2268
2269       J. Preserve the network location, if any, given in the Document
2270          for public access to a Transparent copy of the Document, and
2271          likewise the network locations given in the Document for
2272          previous versions it was based on.  These may be placed in the
2273          "History" section.  You may omit a network location for a work
2274          that was published at least four years before the Document
2275          itself, or if the original publisher of the version it refers
2276          to gives permission.
2277
2278       K. For any section Entitled "Acknowledgements" or "Dedications",
2279          Preserve the Title of the section, and preserve in the section
2280          all the substance and tone of each of the contributor
2281          acknowledgements and/or dedications given therein.
2282
2283       L. Preserve all the Invariant Sections of the Document, unaltered
2284          in their text and in their titles.  Section numbers or the
2285          equivalent are not considered part of the section titles.
2286
2287       M. Delete any section Entitled "Endorsements".  Such a section
2288          may not be included in the Modified Version.
2289
2290       N. Do not retitle any existing section to be Entitled
2291          "Endorsements" or to conflict in title with any Invariant
2292          Section.
2293
2294       O. Preserve any Warranty Disclaimers.
2295
2296     If the Modified Version includes new front-matter sections or
2297     appendices that qualify as Secondary Sections and contain no
2298     material copied from the Document, you may at your option designate
2299     some or all of these sections as invariant.  To do this, add their
2300     titles to the list of Invariant Sections in the Modified Version's
2301     license notice.  These titles must be distinct from any other
2302     section titles.
2303
2304     You may add a section Entitled "Endorsements", provided it contains
2305     nothing but endorsements of your Modified Version by various
2306     parties--for example, statements of peer review or that the text
2307     has been approved by an organization as the authoritative
2308     definition of a standard.
2309
2310     You may add a passage of up to five words as a Front-Cover Text,
2311     and a passage of up to 25 words as a Back-Cover Text, to the end of
2312     the list of Cover Texts in the Modified Version.  Only one passage
2313     of Front-Cover Text and one of Back-Cover Text may be added by (or
2314     through arrangements made by) any one entity.  If the Document
2315     already includes a cover text for the same cover, previously added
2316     by you or by arrangement made by the same entity you are acting on
2317     behalf of, you may not add another; but you may replace the old
2318     one, on explicit permission from the previous publisher that added
2319     the old one.
2320
2321     The author(s) and publisher(s) of the Document do not by this
2322     License give permission to use their names for publicity for or to
2323     assert or imply endorsement of any Modified Version.
2324
2325  5. COMBINING DOCUMENTS
2326
2327     You may combine the Document with other documents released under
2328     this License, under the terms defined in section 4 above for
2329     modified versions, provided that you include in the combination all
2330     of the Invariant Sections of all of the original documents,
2331     unmodified, and list them all as Invariant Sections of your
2332     combined work in its license notice, and that you preserve all
2333     their Warranty Disclaimers.
2334
2335     The combined work need only contain one copy of this License, and
2336     multiple identical Invariant Sections may be replaced with a single
2337     copy.  If there are multiple Invariant Sections with the same name
2338     but different contents, make the title of each such section unique
2339     by adding at the end of it, in parentheses, the name of the
2340     original author or publisher of that section if known, or else a
2341     unique number.  Make the same adjustment to the section titles in
2342     the list of Invariant Sections in the license notice of the
2343     combined work.
2344
2345     In the combination, you must combine any sections Entitled
2346     "History" in the various original documents, forming one section
2347     Entitled "History"; likewise combine any sections Entitled
2348     "Acknowledgements", and any sections Entitled "Dedications".  You
2349     must delete all sections Entitled "Endorsements."
2350
2351  6. COLLECTIONS OF DOCUMENTS
2352
2353     You may make a collection consisting of the Document and other
2354     documents released under this License, and replace the individual
2355     copies of this License in the various documents with a single copy
2356     that is included in the collection, provided that you follow the
2357     rules of this License for verbatim copying of each of the documents
2358     in all other respects.
2359
2360     You may extract a single document from such a collection, and
2361     distribute it individually under this License, provided you insert
2362     a copy of this License into the extracted document, and follow this
2363     License in all other respects regarding verbatim copying of that
2364     document.
2365
2366  7. AGGREGATION WITH INDEPENDENT WORKS
2367
2368     A compilation of the Document or its derivatives with other
2369     separate and independent documents or works, in or on a volume of a
2370     storage or distribution medium, is called an "aggregate" if the
2371     copyright resulting from the compilation is not used to limit the
2372     legal rights of the compilation's users beyond what the individual
2373     works permit.  When the Document is included in an aggregate, this
2374     License does not apply to the other works in the aggregate which
2375     are not themselves derivative works of the Document.
2376
2377     If the Cover Text requirement of section 3 is applicable to these
2378     copies of the Document, then if the Document is less than one half
2379     of the entire aggregate, the Document's Cover Texts may be placed
2380     on covers that bracket the Document within the aggregate, or the
2381     electronic equivalent of covers if the Document is in electronic
2382     form.  Otherwise they must appear on printed covers that bracket
2383     the whole aggregate.
2384
2385  8. TRANSLATION
2386
2387     Translation is considered a kind of modification, so you may
2388     distribute translations of the Document under the terms of section
2389     4.  Replacing Invariant Sections with translations requires special
2390     permission from their copyright holders, but you may include
2391     translations of some or all Invariant Sections in addition to the
2392     original versions of these Invariant Sections.  You may include a
2393     translation of this License, and all the license notices in the
2394     Document, and any Warranty Disclaimers, provided that you also
2395     include the original English version of this License and the
2396     original versions of those notices and disclaimers.  In case of a
2397     disagreement between the translation and the original version of
2398     this License or a notice or disclaimer, the original version will
2399     prevail.
2400
2401     If a section in the Document is Entitled "Acknowledgements",
2402     "Dedications", or "History", the requirement (section 4) to
2403     Preserve its Title (section 1) will typically require changing the
2404     actual title.
2405
2406  9. TERMINATION
2407
2408     You may not copy, modify, sublicense, or distribute the Document
2409     except as expressly provided for under this License.  Any other
2410     attempt to copy, modify, sublicense or distribute the Document is
2411     void, and will automatically terminate your rights under this
2412     License.  However, parties who have received copies, or rights,
2413     from you under this License will not have their licenses terminated
2414     so long as such parties remain in full compliance.
2415
2416  10. FUTURE REVISIONS OF THIS LICENSE
2417
2418     The Free Software Foundation may publish new, revised versions of
2419     the GNU Free Documentation License from time to time.  Such new
2420     versions will be similar in spirit to the present version, but may
2421     differ in detail to address new problems or concerns.  See
2422     <http://www.gnu.org/copyleft/>.
2423
2424     Each version of the License is given a distinguishing version
2425     number.  If the Document specifies that a particular numbered
2426     version of this License "or any later version" applies to it, you
2427     have the option of following the terms and conditions either of
2428     that specified version or of any later version that has been
2429     published (not as a draft) by the Free Software Foundation.  If the
2430     Document does not specify a version number of this License, you may
2431     choose any version ever published (not as a draft) by the Free
2432     Software Foundation.
2433
2434A.1.1 ADDENDUM: How to use this License for your documents
2435----------------------------------------------------------
2436
2437To use this License in a document you have written, include a copy of
2438the License in the document and put the following copyright and license
2439notices just after the title page:
2440
2441       Copyright (C)  YEAR  YOUR NAME.
2442       Permission is granted to copy, distribute and/or modify this document
2443       under the terms of the GNU Free Documentation License, Version 1.2
2444       or any later version published by the Free Software Foundation;
2445       with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
2446       Texts.  A copy of the license is included in the section entitled ``GNU
2447       Free Documentation License''.
2448
2449   If you have Invariant Sections, Front-Cover Texts and Back-Cover
2450Texts, replace the "with...Texts."  line with this:
2451
2452         with the Invariant Sections being LIST THEIR TITLES, with
2453         the Front-Cover Texts being LIST, and with the Back-Cover Texts
2454         being LIST.
2455
2456   If you have Invariant Sections without Cover Texts, or some other
2457combination of the three, merge those two alternatives to suit the
2458situation.
2459
2460   If your document contains nontrivial examples of program code, we
2461recommend releasing these examples in parallel under your choice of free
2462software license, such as the GNU General Public License, to permit
2463their use in free software.
2464
2465
2466File: grub-dev.info,  Node: Index,  Prev: Copying This Manual,  Up: Top
2467
2468Index
2469*****
2470
2471[index]
2472* Menu:
2473
2474* FDL, GNU Free Documentation License:   GNU Free Documentation License.
2475                                                                (line 6)
2476
2477
2478
2479Tag Table:
2480Node: Top647
2481Node: Getting the source code1752
2482Node: Coding style2719
2483Node: Naming Conventions3128
2484Node: Functions3413
2485Node: Variables4287
2486Node: Types5402
2487Node: Macros6003
2488Node: Comments6335
2489Node: Multi-Line Comments7097
2490Node: Finding your way around7728
2491Node: Contributing Changes11036
2492Node: Getting started12126
2493Node: Typical Developer Experience16178
2494Node: When you are approved for write access to project's files17220
2495Node: Porting18653
2496Node: Error Handling30416
2497Node: Stack and heap size35508
2498Node: BIOS port memory map38141
2499Node: Video Subsystem38990
2500Node: Video API39462
2501Node: Example usage of Video API59857
2502Node: Bitmap API61431
2503Node: PFF2 Font File Format63948
2504Node: Introduction64188
2505Node: File Structure65691
2506Node: Font Metrics70609
2507Node: Graphical Menu Software Design71757
2508Node: Introduction_272049
2509Node: Startup Sequence72783
2510Node: GUI Components73634
2511Node: Command Line Window76234
2512Node: Copying This Manual77186
2513Node: GNU Free Documentation License77442
2514Node: Index99835
2515
2516End Tag Table
Note: See TracBrowser for help on using the repository browser.