summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 16:29:51 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 16:29:51 +0000
commit6e7a315eb67cb6c113cf37e1d66c4f11a51a2b3e (patch)
tree32451fa3cdd9321fb2591fada9891b2cb70a9cd1 /include
parentInitial commit. (diff)
downloadgrub2-3e86199209a10ed6555e30b8b71884cb7cc45ed2.tar.xz
grub2-3e86199209a10ed6555e30b8b71884cb7cc45ed2.zip
Adding upstream version 2.06.upstream/2.06upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'include')
-rw-r--r--include/grub/acorn_filecore.h53
-rw-r--r--include/grub/acpi.h247
-rw-r--r--include/grub/aout.h129
-rw-r--r--include/grub/arc/arc.h284
-rw-r--r--include/grub/arc/console.h31
-rw-r--r--include/grub/archelp.h63
-rw-r--r--include/grub/arm/coreboot/console.h29
-rw-r--r--include/grub/arm/coreboot/kernel.h44
-rw-r--r--include/grub/arm/cros_ec.h21
-rw-r--r--include/grub/arm/efi/memory.h6
-rw-r--r--include/grub/arm/linux.h67
-rw-r--r--include/grub/arm/reloc.h51
-rw-r--r--include/grub/arm/setjmp.h27
-rw-r--r--include/grub/arm/startup.h16
-rw-r--r--include/grub/arm/system.h19
-rw-r--r--include/grub/arm/time.h29
-rw-r--r--include/grub/arm/types.h34
-rw-r--r--include/grub/arm/uboot/kernel.h32
-rw-r--r--include/grub/arm64/efi/memory.h6
-rw-r--r--include/grub/arm64/linux.h46
-rw-r--r--include/grub/arm64/reloc.h41
-rw-r--r--include/grub/arm64/setjmp.h27
-rw-r--r--include/grub/arm64/time.h29
-rw-r--r--include/grub/arm64/types.h34
-rw-r--r--include/grub/at_keyboard.h40
-rw-r--r--include/grub/ata.h225
-rw-r--r--include/grub/auth.h37
-rw-r--r--include/grub/autoefi.h64
-rw-r--r--include/grub/backtrace.h26
-rw-r--r--include/grub/bitmap.h87
-rw-r--r--include/grub/bitmap_scale.h85
-rw-r--r--include/grub/boottime.h0
-rw-r--r--include/grub/bsdlabel.h106
-rw-r--r--include/grub/btrfs.h71
-rw-r--r--include/grub/buffer.h144
-rw-r--r--include/grub/bufio.h30
-rw-r--r--include/grub/cache.h56
-rw-r--r--include/grub/cbfs_core.h178
-rw-r--r--include/grub/charset.h323
-rw-r--r--include/grub/cmos.h128
-rw-r--r--include/grub/color.h30
-rw-r--r--include/grub/command.h134
-rw-r--r--include/grub/compiler-rt-emu.h265
-rw-r--r--include/grub/compiler-rt.h213
-rw-r--r--include/grub/compiler.h59
-rw-r--r--include/grub/coreboot/lbio.h114
-rw-r--r--include/grub/crypto.h422
-rw-r--r--include/grub/cryptodisk.h173
-rw-r--r--include/grub/cs5536.h198
-rw-r--r--include/grub/datetime.h133
-rw-r--r--include/grub/decompressor.h34
-rw-r--r--include/grub/deflate.h30
-rw-r--r--include/grub/device.h43
-rw-r--r--include/grub/disk.h294
-rw-r--r--include/grub/diskfilter.h218
-rw-r--r--include/grub/dl.h311
-rw-r--r--include/grub/dma.h44
-rw-r--r--include/grub/efi/api.h1805
-rw-r--r--include/grub/efi/console.h31
-rw-r--r--include/grub/efi/console_control.h57
-rw-r--r--include/grub/efi/disk.h33
-rw-r--r--include/grub/efi/edid.h54
-rw-r--r--include/grub/efi/efi.h127
-rw-r--r--include/grub/efi/fdtload.h32
-rw-r--r--include/grub/efi/graphics_output.h115
-rw-r--r--include/grub/efi/memory.h38
-rw-r--r--include/grub/efi/pci.h319
-rw-r--r--include/grub/efi/pe32.h334
-rw-r--r--include/grub/efi/sb.h43
-rw-r--r--include/grub/efi/tpm.h198
-rw-r--r--include/grub/efi/uga_draw.h76
-rw-r--r--include/grub/efiemu/efiemu.h286
-rw-r--r--include/grub/efiemu/runtime.h37
-rw-r--r--include/grub/elf.h2587
-rw-r--r--include/grub/elfload.h82
-rw-r--r--include/grub/emu/config.h48
-rw-r--r--include/grub/emu/console.h28
-rw-r--r--include/grub/emu/exec.h42
-rw-r--r--include/grub/emu/getroot.h104
-rw-r--r--include/grub/emu/hostdisk.h98
-rw-r--r--include/grub/emu/hostfile.h68
-rw-r--r--include/grub/emu/misc.h75
-rw-r--r--include/grub/emu/net.h37
-rw-r--r--include/grub/env.h72
-rw-r--r--include/grub/env_private.h46
-rw-r--r--include/grub/err.h98
-rw-r--r--include/grub/exfat.h53
-rw-r--r--include/grub/extcmd.h86
-rw-r--r--include/grub/fat.h77
-rw-r--r--include/grub/fbblit.h36
-rw-r--r--include/grub/fbfill.h59
-rw-r--r--include/grub/fbutil.h59
-rw-r--r--include/grub/fdt.h147
-rw-r--r--include/grub/fdtbus.h89
-rw-r--r--include/grub/file.h242
-rw-r--r--include/grub/fileid.h29
-rw-r--r--include/grub/font.h153
-rw-r--r--include/grub/fontformat.h38
-rw-r--r--include/grub/fs.h131
-rw-r--r--include/grub/fshelp.h91
-rw-r--r--include/grub/gcry/types.h37
-rw-r--r--include/grub/gcrypt/g10lib.h302
-rw-r--r--include/grub/gcrypt/gcrypt.h1746
-rw-r--r--include/grub/gcrypt/gpg-error.h32
-rw-r--r--include/grub/gdb.h39
-rw-r--r--include/grub/gfxmenu_model.h1
-rw-r--r--include/grub/gfxmenu_view.h124
-rw-r--r--include/grub/gfxterm.h51
-rw-r--r--include/grub/gfxwidgets.h50
-rw-r--r--include/grub/gpt_partition.h87
-rw-r--r--include/grub/gui.h282
-rw-r--r--include/grub/gui_string_util.h33
-rw-r--r--include/grub/hfs.h72
-rw-r--r--include/grub/hfsplus.h259
-rw-r--r--include/grub/i18n.h68
-rw-r--r--include/grub/i386/at_keyboard.h25
-rw-r--r--include/grub/i386/bsd.h128
-rw-r--r--include/grub/i386/cmos.h30
-rw-r--r--include/grub/i386/coreboot/boot.h1
-rw-r--r--include/grub/i386/coreboot/console.h32
-rw-r--r--include/grub/i386/coreboot/kernel.h0
-rw-r--r--include/grub/i386/coreboot/memory.h54
-rw-r--r--include/grub/i386/coreboot/serial.h24
-rw-r--r--include/grub/i386/coreboot/time.h1
-rw-r--r--include/grub/i386/cpuid.h85
-rw-r--r--include/grub/i386/efi/kernel.h0
-rw-r--r--include/grub/i386/efi/memory.h6
-rw-r--r--include/grub/i386/efi/serial.h1
-rw-r--r--include/grub/i386/efiemu.h33
-rw-r--r--include/grub/i386/floppy.h36
-rw-r--r--include/grub/i386/freebsd_linker.h74
-rw-r--r--include/grub/i386/freebsd_reboot.h77
-rw-r--r--include/grub/i386/gdb.h78
-rw-r--r--include/grub/i386/ieee1275/ieee1275.h1
-rw-r--r--include/grub/i386/ieee1275/kernel.h0
-rw-r--r--include/grub/i386/ieee1275/memory.h1
-rw-r--r--include/grub/i386/ieee1275/serial.h1
-rw-r--r--include/grub/i386/io.h72
-rw-r--r--include/grub/i386/linux.h336
-rw-r--r--include/grub/i386/macho.h32
-rw-r--r--include/grub/i386/memory.h80
-rw-r--r--include/grub/i386/memory_raw.h58
-rw-r--r--include/grub/i386/multiboot.h58
-rw-r--r--include/grub/i386/multiboot/boot.h1
-rw-r--r--include/grub/i386/multiboot/console.h1
-rw-r--r--include/grub/i386/multiboot/kernel.h1
-rw-r--r--include/grub/i386/multiboot/memory.h1
-rw-r--r--include/grub/i386/multiboot/serial.h1
-rw-r--r--include/grub/i386/multiboot/time.h1
-rw-r--r--include/grub/i386/netbsd_bootinfo.h156
-rw-r--r--include/grub/i386/netbsd_reboot.h81
-rw-r--r--include/grub/i386/openbsd_bootarg.h93
-rw-r--r--include/grub/i386/openbsd_reboot.h79
-rw-r--r--include/grub/i386/pc/apm.h48
-rw-r--r--include/grub/i386/pc/biosdisk.h109
-rw-r--r--include/grub/i386/pc/biosnum.h6
-rw-r--r--include/grub/i386/pc/boot.h73
-rw-r--r--include/grub/i386/pc/chainloader.h27
-rw-r--r--include/grub/i386/pc/console.h36
-rw-r--r--include/grub/i386/pc/int.h33
-rw-r--r--include/grub/i386/pc/int_types.h59
-rw-r--r--include/grub/i386/pc/kernel.h41
-rw-r--r--include/grub/i386/pc/memory.h63
-rw-r--r--include/grub/i386/pc/pxe.h292
-rw-r--r--include/grub/i386/pc/time.h24
-rw-r--r--include/grub/i386/pc/vbe.h232
-rw-r--r--include/grub/i386/pc/vesa_modes_table.h19
-rw-r--r--include/grub/i386/pci.h105
-rw-r--r--include/grub/i386/pit.h103
-rw-r--r--include/grub/i386/pmtimer.h37
-rw-r--r--include/grub/i386/qemu/boot.h25
-rw-r--r--include/grub/i386/qemu/console.h1
-rw-r--r--include/grub/i386/qemu/kernel.h35
-rw-r--r--include/grub/i386/qemu/memory.h1
-rw-r--r--include/grub/i386/qemu/serial.h1
-rw-r--r--include/grub/i386/qemu/time.h1
-rw-r--r--include/grub/i386/rdmsr.h37
-rw-r--r--include/grub/i386/reboot.h28
-rw-r--r--include/grub/i386/relocator.h100
-rw-r--r--include/grub/i386/relocator_private.h1
-rw-r--r--include/grub/i386/setjmp.h29
-rw-r--r--include/grub/i386/time.h29
-rw-r--r--include/grub/i386/tsc.h70
-rw-r--r--include/grub/i386/types.h33
-rw-r--r--include/grub/i386/wrmsr.h35
-rw-r--r--include/grub/i386/xen/hypercall.h88
-rw-r--r--include/grub/i386/xen/kernel.h0
-rw-r--r--include/grub/i386/xen/memory.h0
-rw-r--r--include/grub/i386/xen_pvh/boot.h1
-rw-r--r--include/grub/i386/xen_pvh/console.h1
-rw-r--r--include/grub/i386/xen_pvh/int.h1
-rw-r--r--include/grub/i386/xen_pvh/kernel.h30
-rw-r--r--include/grub/i386/xen_pvh/memory.h1
-rw-r--r--include/grub/i386/xen_pvh/time.h1
-rw-r--r--include/grub/i386/xnu.h149
-rw-r--r--include/grub/ia64/efi/memory.h6
-rw-r--r--include/grub/ia64/efi/time.h23
-rw-r--r--include/grub/ia64/kernel.h25
-rw-r--r--include/grub/ia64/reloc.h44
-rw-r--r--include/grub/ia64/setjmp.h28
-rw-r--r--include/grub/ia64/time.h28
-rw-r--r--include/grub/ia64/types.h32
-rw-r--r--include/grub/icon_manager.h41
-rw-r--r--include/grub/ieee1275/console.h34
-rw-r--r--include/grub/ieee1275/ieee1275.h266
-rw-r--r--include/grub/ieee1275/obdisk.h25
-rw-r--r--include/grub/ieee1275/ofdisk.h25
-rw-r--r--include/grub/kernel.h132
-rw-r--r--include/grub/keyboard_layouts.h150
-rw-r--r--include/grub/legacy_parse.h32
-rw-r--r--include/grub/lib/LzFind.h130
-rw-r--r--include/grub/lib/LzHash.h77
-rw-r--r--include/grub/lib/LzmaDec.h246
-rw-r--r--include/grub/lib/LzmaEnc.h95
-rw-r--r--include/grub/lib/LzmaTypes.h151
-rw-r--r--include/grub/lib/arg.h79
-rw-r--r--include/grub/lib/cmdline.h32
-rw-r--r--include/grub/lib/crc.h25
-rw-r--r--include/grub/lib/envblk.h56
-rw-r--r--include/grub/lib/hexdump.h25
-rw-r--r--include/grub/libpciaccess.h26
-rw-r--r--include/grub/linux.h24
-rw-r--r--include/grub/list.h88
-rw-r--r--include/grub/loader.h79
-rw-r--r--include/grub/lockdown.h44
-rw-r--r--include/grub/lvm.h90
-rw-r--r--include/grub/macho.h166
-rw-r--r--include/grub/machoload.h89
-rw-r--r--include/grub/memory.h87
-rw-r--r--include/grub/menu.h106
-rw-r--r--include/grub/menu_viewer.h48
-rw-r--r--include/grub/mips/arc/kernel.h2
-rw-r--r--include/grub/mips/arc/memory.h46
-rw-r--r--include/grub/mips/arc/time.h0
-rw-r--r--include/grub/mips/asm.h18
-rw-r--r--include/grub/mips/at_keyboard.h1
-rw-r--r--include/grub/mips/cmos.h1
-rw-r--r--include/grub/mips/io.h62
-rw-r--r--include/grub/mips/kernel.h24
-rw-r--r--include/grub/mips/loongson.h86
-rw-r--r--include/grub/mips/loongson/at_keyboard.h27
-rw-r--r--include/grub/mips/loongson/cmos.h30
-rw-r--r--include/grub/mips/loongson/ec.h45
-rw-r--r--include/grub/mips/loongson/kernel.h36
-rw-r--r--include/grub/mips/loongson/memory.h51
-rw-r--r--include/grub/mips/loongson/pci.h110
-rw-r--r--include/grub/mips/loongson/serial.h33
-rw-r--r--include/grub/mips/loongson/time.h27
-rw-r--r--include/grub/mips/memory.h60
-rw-r--r--include/grub/mips/mips.h30
-rw-r--r--include/grub/mips/multiboot.h31
-rw-r--r--include/grub/mips/pci.h1
-rw-r--r--include/grub/mips/qemu_mips/at_keyboard.h25
-rw-r--r--include/grub/mips/qemu_mips/cmos.h30
-rw-r--r--include/grub/mips/qemu_mips/console.h25
-rw-r--r--include/grub/mips/qemu_mips/kernel.h30
-rw-r--r--include/grub/mips/qemu_mips/loader.h0
-rw-r--r--include/grub/mips/qemu_mips/memory.h50
-rw-r--r--include/grub/mips/qemu_mips/serial.h24
-rw-r--r--include/grub/mips/qemu_mips/time.h25
-rw-r--r--include/grub/mips/relocator.h38
-rw-r--r--include/grub/mips/setjmp.h27
-rw-r--r--include/grub/mips/time.h37
-rw-r--r--include/grub/mips/types.h38
-rw-r--r--include/grub/misc.h503
-rw-r--r--include/grub/mm.h83
-rw-r--r--include/grub/mm_private.h64
-rw-r--r--include/grub/module_verifier.h20
-rw-r--r--include/grub/msdos_partition.h127
-rw-r--r--include/grub/multiboot.h112
-rw-r--r--include/grub/multiboot2.h104
-rw-r--r--include/grub/multiboot_loader.h28
-rw-r--r--include/grub/net.h583
-rw-r--r--include/grub/net/arp.h32
-rw-r--r--include/grub/net/ethernet.h41
-rw-r--r--include/grub/net/ip.h98
-rw-r--r--include/grub/net/netbuff.h31
-rw-r--r--include/grub/net/tcp.h85
-rw-r--r--include/grub/net/udp.h51
-rw-r--r--include/grub/normal.h177
-rw-r--r--include/grub/ns8250.h80
-rw-r--r--include/grub/ntfs.h198
-rw-r--r--include/grub/offsets.h168
-rw-r--r--include/grub/osdep/hostfile.h7
-rw-r--r--include/grub/osdep/hostfile_aros.h119
-rw-r--r--include/grub/osdep/hostfile_unix.h118
-rw-r--r--include/grub/osdep/hostfile_windows.h85
-rw-r--r--include/grub/parser.h96
-rw-r--r--include/grub/partition.h141
-rw-r--r--include/grub/parttool.h58
-rw-r--r--include/grub/pci.h152
-rw-r--r--include/grub/pciutils.h103
-rw-r--r--include/grub/powerpc/ieee1275/ieee1275.h28
-rw-r--r--include/grub/powerpc/kernel.h22
-rw-r--r--include/grub/powerpc/memory.h47
-rw-r--r--include/grub/powerpc/relocator.h37
-rw-r--r--include/grub/powerpc/setjmp.h27
-rw-r--r--include/grub/powerpc/time.h28
-rw-r--r--include/grub/powerpc/types.h32
-rw-r--r--include/grub/priority_queue.h44
-rw-r--r--include/grub/procfs.h51
-rw-r--r--include/grub/ps2.h43
-rw-r--r--include/grub/pubkey.h38
-rw-r--r--include/grub/random.h33
-rw-r--r--include/grub/reader.h29
-rw-r--r--include/grub/reed_solomon.h30
-rw-r--r--include/grub/relocator.h88
-rw-r--r--include/grub/relocator_private.h113
-rw-r--r--include/grub/riscv32/efi/memory.h6
-rw-r--r--include/grub/riscv32/linux.h41
-rw-r--r--include/grub/riscv32/setjmp.h27
-rw-r--r--include/grub/riscv32/time.h28
-rw-r--r--include/grub/riscv32/types.h34
-rw-r--r--include/grub/riscv64/efi/memory.h6
-rw-r--r--include/grub/riscv64/linux.h43
-rw-r--r--include/grub/riscv64/setjmp.h27
-rw-r--r--include/grub/riscv64/time.h28
-rw-r--r--include/grub/riscv64/types.h34
-rw-r--r--include/grub/safemath.h37
-rw-r--r--include/grub/script_sh.h410
-rw-r--r--include/grub/scsi.h111
-rw-r--r--include/grub/scsicmd.h206
-rw-r--r--include/grub/sdl.h24
-rw-r--r--include/grub/search.h29
-rw-r--r--include/grub/serial.h205
-rw-r--r--include/grub/setjmp.h42
-rw-r--r--include/grub/smbios.h69
-rw-r--r--include/grub/smbus.h70
-rw-r--r--include/grub/sparc64/ieee1275/boot.h62
-rw-r--r--include/grub/sparc64/ieee1275/ieee1275.h50
-rw-r--r--include/grub/sparc64/ieee1275/kernel.h31
-rw-r--r--include/grub/sparc64/setjmp.h29
-rw-r--r--include/grub/sparc64/time.h28
-rw-r--r--include/grub/sparc64/types.h32
-rw-r--r--include/grub/speaker.h47
-rw-r--r--include/grub/stack_protector.h30
-rw-r--r--include/grub/symbol.h72
-rw-r--r--include/grub/syslinux_parse.h37
-rw-r--r--include/grub/term.h469
-rw-r--r--include/grub/terminfo.h87
-rw-r--r--include/grub/test.h125
-rw-r--r--include/grub/time.h48
-rw-r--r--include/grub/tparm.h26
-rw-r--r--include/grub/tpm.h39
-rw-r--r--include/grub/trig.h44
-rw-r--r--include/grub/types.h343
-rw-r--r--include/grub/uboot/api_public.h181
-rw-r--r--include/grub/uboot/console.h29
-rw-r--r--include/grub/uboot/disk.h43
-rw-r--r--include/grub/uboot/image.h175
-rw-r--r--include/grub/uboot/uboot.h87
-rw-r--r--include/grub/udf.h30
-rw-r--r--include/grub/unicode.h360
-rw-r--r--include/grub/usb.h333
-rw-r--r--include/grub/usbdesc.h134
-rw-r--r--include/grub/usbserial.h39
-rw-r--r--include/grub/usbtrans.h155
-rw-r--r--include/grub/util/install.h299
-rw-r--r--include/grub/util/libnvpair.h38
-rw-r--r--include/grub/util/libzfs.h47
-rw-r--r--include/grub/util/misc.h52
-rw-r--r--include/grub/util/mkimage.h187
-rw-r--r--include/grub/util/ofpath.h6
-rw-r--r--include/grub/util/resolve.h36
-rw-r--r--include/grub/util/windows.h33
-rw-r--r--include/grub/verify.h87
-rw-r--r--include/grub/vga.h129
-rw-r--r--include/grub/vgaregs.h307
-rw-r--r--include/grub/video.h704
-rw-r--r--include/grub/video_fb.h151
-rw-r--r--include/grub/x86_64/at_keyboard.h1
-rw-r--r--include/grub/x86_64/efi/boot.h0
-rw-r--r--include/grub/x86_64/efi/kernel.h0
-rw-r--r--include/grub/x86_64/efi/loader.h26
-rw-r--r--include/grub/x86_64/efi/memory.h10
-rw-r--r--include/grub/x86_64/efi/serial.h1
-rw-r--r--include/grub/x86_64/io.h19
-rw-r--r--include/grub/x86_64/linux.h19
-rw-r--r--include/grub/x86_64/macho.h1
-rw-r--r--include/grub/x86_64/memory.h1
-rw-r--r--include/grub/x86_64/multiboot.h1
-rw-r--r--include/grub/x86_64/pci.h19
-rw-r--r--include/grub/x86_64/relocator.h1
-rw-r--r--include/grub/x86_64/setjmp.h27
-rw-r--r--include/grub/x86_64/time.h29
-rw-r--r--include/grub/x86_64/types.h41
-rw-r--r--include/grub/x86_64/xen/hypercall.h36
-rw-r--r--include/grub/x86_64/xnu.h1
-rw-r--r--include/grub/xen.h105
-rw-r--r--include/grub/xen/relocator.h46
-rw-r--r--include/grub/xen_file.h57
-rw-r--r--include/grub/xnu.h119
-rw-r--r--include/grub/zfs/dmu.h164
-rw-r--r--include/grub/zfs/dmu_objset.h43
-rw-r--r--include/grub/zfs/dnode.h74
-rw-r--r--include/grub/zfs/dsl_dataset.h52
-rw-r--r--include/grub/zfs/dsl_dir.h50
-rw-r--r--include/grub/zfs/sa_impl.h37
-rw-r--r--include/grub/zfs/spa.h328
-rw-r--r--include/grub/zfs/uberblock_impl.h60
-rw-r--r--include/grub/zfs/vdev_impl.h69
-rw-r--r--include/grub/zfs/zap_impl.h109
-rw-r--r--include/grub/zfs/zap_leaf.h103
-rw-r--r--include/grub/zfs/zfs.h158
-rw-r--r--include/grub/zfs/zfs_acl.h59
-rw-r--r--include/grub/zfs/zfs_znode.h70
-rw-r--r--include/grub/zfs/zil.h56
-rw-r--r--include/grub/zfs/zio.h95
-rw-r--r--include/grub/zfs/zio_checksum.h33
-rw-r--r--include/multiboot.h274
-rw-r--r--include/multiboot2.h416
-rw-r--r--include/xen/arch-x86/xen-x86_32.h169
-rw-r--r--include/xen/arch-x86/xen-x86_64.h202
-rw-r--r--include/xen/arch-x86/xen.h280
-rw-r--r--include/xen/elfnote.h281
-rw-r--r--include/xen/event_channel.h381
-rw-r--r--include/xen/grant_table.h662
-rw-r--r--include/xen/hvm/hvm_op.h296
-rw-r--r--include/xen/hvm/params.h284
-rw-r--r--include/xen/hvm/start_info.h98
-rw-r--r--include/xen/io/blkif.h608
-rw-r--r--include/xen/io/console.h51
-rw-r--r--include/xen/io/protocols.h40
-rw-r--r--include/xen/io/ring.h312
-rw-r--r--include/xen/io/xenbus.h80
-rw-r--r--include/xen/io/xs_wire.h138
-rw-r--r--include/xen/memory.h665
-rw-r--r--include/xen/physdev.h387
-rw-r--r--include/xen/sched.h174
-rw-r--r--include/xen/trace.h339
-rw-r--r--include/xen/xen-compat.h44
-rw-r--r--include/xen/xen.h998
432 files changed, 44762 insertions, 0 deletions
diff --git a/include/grub/acorn_filecore.h b/include/grub/acorn_filecore.h
new file mode 100644
index 0000000..6cda6cf
--- /dev/null
+++ b/include/grub/acorn_filecore.h
@@ -0,0 +1,53 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2004,2005,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_ACORN_FILECORE_HEADER
+#define GRUB_ACORN_FILECORE_HEADER 1
+
+#include <grub/types.h>
+
+struct grub_filecore_disc_record
+{
+ grub_uint8_t log2secsize;
+ grub_uint8_t secspertrack;
+ grub_uint8_t heads;
+ grub_uint8_t density;
+ grub_uint8_t idlen;
+ grub_uint8_t log2bpmb;
+ grub_uint8_t skew;
+ grub_uint8_t bootoption;
+ /* In bits 0-5, flags in bits 6 and 7. */
+ grub_uint8_t lowsector;
+ grub_uint8_t nzones;
+ grub_uint16_t zone_spare;
+ grub_uint32_t root_address;
+ /* Disc size in bytes. */
+ grub_uint32_t disc_size;
+ grub_uint16_t cycle_id;
+ char disc_name[10];
+ /* Yes, it is 32 bits! */
+ grub_uint32_t disctype;
+ /* Most significant part of the disc size. */
+ grub_uint32_t disc_size2;
+ grub_uint8_t share_size;
+ grub_uint8_t big_flag;
+ grub_uint8_t reserved[18];
+};
+
+
+#endif /* ! GRUB_ACORN_FILECORE_HEADER */
diff --git a/include/grub/acpi.h b/include/grub/acpi.h
new file mode 100644
index 0000000..84f4948
--- /dev/null
+++ b/include/grub/acpi.h
@@ -0,0 +1,247 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_ACPI_HEADER
+#define GRUB_ACPI_HEADER 1
+
+#ifndef GRUB_DSDT_TEST
+#include <grub/types.h>
+#include <grub/err.h>
+#else
+#define GRUB_PACKED __attribute__ ((packed))
+#endif
+
+#define GRUB_RSDP_SIGNATURE "RSD PTR "
+#define GRUB_RSDP_SIGNATURE_SIZE 8
+
+struct grub_acpi_rsdp_v10
+{
+ grub_uint8_t signature[GRUB_RSDP_SIGNATURE_SIZE];
+ grub_uint8_t checksum;
+ grub_uint8_t oemid[6];
+ grub_uint8_t revision;
+ grub_uint32_t rsdt_addr;
+} GRUB_PACKED;
+
+struct grub_acpi_rsdp_v20
+{
+ struct grub_acpi_rsdp_v10 rsdpv1;
+ grub_uint32_t length;
+ grub_uint64_t xsdt_addr;
+ grub_uint8_t checksum;
+ grub_uint8_t reserved[3];
+} GRUB_PACKED;
+
+struct grub_acpi_table_header
+{
+ grub_uint8_t signature[4];
+ grub_uint32_t length;
+ grub_uint8_t revision;
+ grub_uint8_t checksum;
+ grub_uint8_t oemid[6];
+ grub_uint8_t oemtable[8];
+ grub_uint32_t oemrev;
+ grub_uint8_t creator_id[4];
+ grub_uint32_t creator_rev;
+} GRUB_PACKED;
+
+#define GRUB_ACPI_FADT_SIGNATURE "FACP"
+
+struct grub_acpi_fadt
+{
+ struct grub_acpi_table_header hdr;
+ grub_uint32_t facs_addr;
+ grub_uint32_t dsdt_addr;
+ grub_uint8_t somefields1[20];
+ grub_uint32_t pm1a;
+ grub_uint8_t somefields2[8];
+ grub_uint32_t pmtimer;
+ grub_uint8_t somefields3[32];
+ grub_uint32_t flags;
+ grub_uint8_t somefields4[16];
+ grub_uint64_t facs_xaddr;
+ grub_uint64_t dsdt_xaddr;
+ grub_uint8_t somefields5[96];
+} GRUB_PACKED;
+
+#define GRUB_ACPI_MADT_SIGNATURE "APIC"
+
+struct grub_acpi_madt_entry_header
+{
+ grub_uint8_t type;
+ grub_uint8_t len;
+};
+
+struct grub_acpi_madt
+{
+ struct grub_acpi_table_header hdr;
+ grub_uint32_t lapic_addr;
+ grub_uint32_t flags;
+ struct grub_acpi_madt_entry_header entries[0];
+} GRUB_PACKED;
+
+enum
+ {
+ GRUB_ACPI_MADT_ENTRY_TYPE_LAPIC = 0,
+ GRUB_ACPI_MADT_ENTRY_TYPE_IOAPIC = 1,
+ GRUB_ACPI_MADT_ENTRY_TYPE_INTERRUPT_OVERRIDE = 2,
+ GRUB_ACPI_MADT_ENTRY_TYPE_LAPIC_NMI = 4,
+ GRUB_ACPI_MADT_ENTRY_TYPE_SAPIC = 6,
+ GRUB_ACPI_MADT_ENTRY_TYPE_LSAPIC = 7,
+ GRUB_ACPI_MADT_ENTRY_TYPE_PLATFORM_INT_SOURCE = 8
+ };
+
+struct grub_acpi_madt_entry_lapic
+{
+ struct grub_acpi_madt_entry_header hdr;
+ grub_uint8_t acpiid;
+ grub_uint8_t apicid;
+ grub_uint32_t flags;
+};
+
+struct grub_acpi_madt_entry_ioapic
+{
+ struct grub_acpi_madt_entry_header hdr;
+ grub_uint8_t id;
+ grub_uint8_t pad;
+ grub_uint32_t address;
+ grub_uint32_t global_sys_interrupt;
+};
+
+struct grub_acpi_madt_entry_interrupt_override
+{
+ struct grub_acpi_madt_entry_header hdr;
+ grub_uint8_t bus;
+ grub_uint8_t source;
+ grub_uint32_t global_sys_interrupt;
+ grub_uint16_t flags;
+} GRUB_PACKED;
+
+
+struct grub_acpi_madt_entry_lapic_nmi
+{
+ struct grub_acpi_madt_entry_header hdr;
+ grub_uint8_t acpiid;
+ grub_uint16_t flags;
+ grub_uint8_t lint;
+} GRUB_PACKED;
+
+struct grub_acpi_madt_entry_sapic
+{
+ struct grub_acpi_madt_entry_header hdr;
+ grub_uint8_t id;
+ grub_uint8_t pad;
+ grub_uint32_t global_sys_interrupt_base;
+ grub_uint64_t addr;
+};
+
+struct grub_acpi_madt_entry_lsapic
+{
+ struct grub_acpi_madt_entry_header hdr;
+ grub_uint8_t cpu_id;
+ grub_uint8_t id;
+ grub_uint8_t eid;
+ grub_uint8_t pad[3];
+ grub_uint32_t flags;
+ grub_uint32_t cpu_uid;
+ grub_uint8_t cpu_uid_str[0];
+};
+
+struct grub_acpi_madt_entry_platform_int_source
+{
+ struct grub_acpi_madt_entry_header hdr;
+ grub_uint16_t flags;
+ grub_uint8_t inttype;
+ grub_uint8_t cpu_id;
+ grub_uint8_t cpu_eid;
+ grub_uint8_t sapic_vector;
+ grub_uint32_t global_sys_int;
+ grub_uint32_t src_flags;
+};
+
+enum
+ {
+ GRUB_ACPI_MADT_ENTRY_SAPIC_FLAGS_ENABLED = 1
+ };
+
+#ifndef GRUB_DSDT_TEST
+struct grub_acpi_rsdp_v10 *grub_acpi_get_rsdpv1 (void);
+struct grub_acpi_rsdp_v20 *grub_acpi_get_rsdpv2 (void);
+struct grub_acpi_rsdp_v10 *EXPORT_FUNC(grub_machine_acpi_get_rsdpv1) (void);
+struct grub_acpi_rsdp_v20 *EXPORT_FUNC(grub_machine_acpi_get_rsdpv2) (void);
+grub_uint8_t EXPORT_FUNC(grub_byte_checksum) (void *base, grub_size_t size);
+
+grub_err_t grub_acpi_create_ebda (void);
+
+void grub_acpi_halt (void);
+#endif
+
+#define GRUB_ACPI_SLP_EN (1 << 13)
+#define GRUB_ACPI_SLP_TYP_OFFSET 10
+
+enum
+ {
+ GRUB_ACPI_OPCODE_ZERO = 0, GRUB_ACPI_OPCODE_ONE = 1,
+ GRUB_ACPI_OPCODE_NAME = 8, GRUB_ACPI_OPCODE_ALIAS = 0x06,
+ GRUB_ACPI_OPCODE_BYTE_CONST = 0x0a,
+ GRUB_ACPI_OPCODE_WORD_CONST = 0x0b,
+ GRUB_ACPI_OPCODE_DWORD_CONST = 0x0c,
+ GRUB_ACPI_OPCODE_STRING_CONST = 0x0d,
+ GRUB_ACPI_OPCODE_SCOPE = 0x10,
+ GRUB_ACPI_OPCODE_BUFFER = 0x11,
+ GRUB_ACPI_OPCODE_PACKAGE = 0x12,
+ GRUB_ACPI_OPCODE_METHOD = 0x14, GRUB_ACPI_OPCODE_EXTOP = 0x5b,
+ GRUB_ACPI_OPCODE_ADD = 0x72,
+ GRUB_ACPI_OPCODE_CONCAT = 0x73,
+ GRUB_ACPI_OPCODE_SUBTRACT = 0x74,
+ GRUB_ACPI_OPCODE_MULTIPLY = 0x77,
+ GRUB_ACPI_OPCODE_DIVIDE = 0x78,
+ GRUB_ACPI_OPCODE_LSHIFT = 0x79,
+ GRUB_ACPI_OPCODE_RSHIFT = 0x7a,
+ GRUB_ACPI_OPCODE_AND = 0x7b,
+ GRUB_ACPI_OPCODE_NAND = 0x7c,
+ GRUB_ACPI_OPCODE_OR = 0x7d,
+ GRUB_ACPI_OPCODE_NOR = 0x7e,
+ GRUB_ACPI_OPCODE_XOR = 0x7f,
+ GRUB_ACPI_OPCODE_CONCATRES = 0x84,
+ GRUB_ACPI_OPCODE_MOD = 0x85,
+ GRUB_ACPI_OPCODE_INDEX = 0x88,
+ GRUB_ACPI_OPCODE_CREATE_DWORD_FIELD = 0x8a,
+ GRUB_ACPI_OPCODE_CREATE_WORD_FIELD = 0x8b,
+ GRUB_ACPI_OPCODE_CREATE_BYTE_FIELD = 0x8c,
+ GRUB_ACPI_OPCODE_TOSTRING = 0x9c,
+ GRUB_ACPI_OPCODE_IF = 0xa0, GRUB_ACPI_OPCODE_ONES = 0xff
+ };
+enum
+ {
+ GRUB_ACPI_EXTOPCODE_MUTEX = 0x01,
+ GRUB_ACPI_EXTOPCODE_EVENT_OP = 0x02,
+ GRUB_ACPI_EXTOPCODE_OPERATION_REGION = 0x80,
+ GRUB_ACPI_EXTOPCODE_FIELD_OP = 0x81,
+ GRUB_ACPI_EXTOPCODE_DEVICE_OP = 0x82,
+ GRUB_ACPI_EXTOPCODE_PROCESSOR_OP = 0x83,
+ GRUB_ACPI_EXTOPCODE_POWER_RES_OP = 0x84,
+ GRUB_ACPI_EXTOPCODE_THERMAL_ZONE_OP = 0x85,
+ GRUB_ACPI_EXTOPCODE_INDEX_FIELD_OP = 0x86,
+ GRUB_ACPI_EXTOPCODE_BANK_FIELD_OP = 0x87,
+ };
+
+struct grub_acpi_fadt *
+EXPORT_FUNC(grub_acpi_find_fadt) (void);
+
+#endif /* ! GRUB_ACPI_HEADER */
diff --git a/include/grub/aout.h b/include/grub/aout.h
new file mode 100644
index 0000000..c8c1d94
--- /dev/null
+++ b/include/grub/aout.h
@@ -0,0 +1,129 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*-
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * from: @(#)exec.h 8.1 (Berkeley) 6/11/93
+ * $FreeBSD$
+ */
+
+#ifndef GRUB_AOUT_HEADER
+#define GRUB_AOUT_HEADER 1
+
+#include <grub/types.h>
+#include <grub/file.h>
+
+struct grub_aout32_header
+{
+ grub_uint32_t a_midmag; /* htonl(flags<<26 | mid<<16 | magic) */
+ grub_uint32_t a_text; /* text segment size */
+ grub_uint32_t a_data; /* initialized data size */
+ grub_uint32_t a_bss; /* uninitialized data size */
+ grub_uint32_t a_syms; /* symbol table size */
+ grub_uint32_t a_entry; /* entry point */
+ grub_uint32_t a_trsize; /* text relocation size */
+ grub_uint32_t a_drsize; /* data relocation size */
+};
+
+struct grub_aout64_header
+{
+ grub_uint32_t a_midmag; /* htonl(flags<<26 | mid<<16 | magic) */
+ grub_uint64_t a_text; /* text segment size */
+ grub_uint64_t a_data; /* initialized data size */
+ grub_uint64_t a_bss; /* uninitialized data size */
+ grub_uint64_t a_syms; /* symbol table size */
+ grub_uint64_t a_entry; /* entry point */
+ grub_uint64_t a_trsize; /* text relocation size */
+ grub_uint64_t a_drsize; /* data relocation size */
+};
+
+union grub_aout_header
+{
+ struct grub_aout32_header aout32;
+ struct grub_aout64_header aout64;
+};
+
+#define AOUT_TYPE_NONE 0
+#define AOUT_TYPE_AOUT32 1
+#define AOUT_TYPE_AOUT64 6
+
+#define AOUT32_OMAGIC 0x107 /* 0407 old impure format */
+#define AOUT32_NMAGIC 0x108 /* 0410 read-only text */
+#define AOUT32_ZMAGIC 0x10b /* 0413 demand load format */
+#define AOUT32_QMAGIC 0xcc /* 0314 "compact" demand load format */
+
+#define AOUT64_OMAGIC 0x1001
+#define AOUT64_ZMAGIC 0x1002
+#define AOUT64_NMAGIC 0x1003
+
+#define AOUT_MID_ZERO 0 /* unknown - implementation dependent */
+#define AOUT_MID_SUN010 1 /* sun 68010/68020 binary */
+#define AOUT_MID_SUN020 2 /* sun 68020-only binary */
+#define AOUT_MID_I386 134 /* i386 BSD binary */
+#define AOUT_MID_SPARC 138 /* sparc */
+#define AOUT_MID_HP200 200 /* hp200 (68010) BSD binary */
+#define AOUT_MID_SUN 0x103
+#define AOUT_MID_HP300 300 /* hp300 (68020+68881) BSD binary */
+#define AOUT_MID_HPUX 0x20C /* hp200/300 HP-UX binary */
+#define AOUT_MID_HPUX800 0x20B /* hp800 HP-UX binary */
+
+#define AOUT_FLAG_PIC 0x10 /* contains position independent code */
+#define AOUT_FLAG_DYNAMIC 0x20 /* contains run-time link-edit info */
+#define AOUT_FLAG_DPMASK 0x30 /* mask for the above */
+
+#define AOUT_GETMAGIC(header) ((header).a_midmag & 0xffff)
+#define AOUT_GETMID(header) ((header).a_midmag >> 16) & 0x03ff)
+#define AOUT_GETFLAG(header) ((header).a_midmag >> 26) & 0x3f)
+
+#ifndef GRUB_UTIL
+
+int EXPORT_FUNC(grub_aout_get_type) (union grub_aout_header *header);
+
+grub_err_t EXPORT_FUNC(grub_aout_load) (grub_file_t file, int offset,
+ void *load_addr, int load_size,
+ grub_size_t bss_size);
+
+#endif
+
+#endif /* ! GRUB_AOUT_HEADER */
diff --git a/include/grub/arc/arc.h b/include/grub/arc/arc.h
new file mode 100644
index 0000000..999de71
--- /dev/null
+++ b/include/grub/arc/arc.h
@@ -0,0 +1,284 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2011 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_ARC_HEADER
+#define GRUB_ARC_HEADER 1
+
+#include <grub/types.h>
+#include <grub/symbol.h>
+
+typedef unsigned grub_arc_enum_t;
+typedef grub_uint64_t grub_arc_ularge_t;
+typedef unsigned long grub_arc_ulong_t;
+typedef long grub_arc_long_t;
+typedef unsigned short grub_arc_ushort_t;
+typedef unsigned char grub_arc_uchar_t;
+
+typedef grub_arc_long_t grub_arc_err_t;
+typedef grub_arc_ulong_t grub_arc_fileno_t;
+
+struct grub_arc_memory_descriptor
+{
+ grub_arc_enum_t type;
+ grub_arc_ulong_t start_page;
+ grub_arc_ulong_t num_pages;
+};
+
+enum grub_arc_memory_type
+ {
+ GRUB_ARC_MEMORY_EXCEPTION_BLOCK,
+ GRUB_ARC_MEMORY_SYSTEM_PARAMETER_BLOCK,
+#ifdef GRUB_CPU_WORDS_BIGENDIAN
+ GRUB_ARC_MEMORY_FREE_CONTIGUOUS,
+#endif
+ GRUB_ARC_MEMORY_FREE,
+ GRUB_ARC_MEMORY_BADRAM,
+ GRUB_ARC_MEMORY_LOADED, GRUB_ARC_MEMORY_FW_TEMPORARY,
+ GRUB_ARC_MEMORY_FW_PERMANENT,
+#ifndef GRUB_CPU_WORDS_BIGENDIAN
+ GRUB_ARC_MEMORY_FREE_CONTIGUOUS,
+#endif
+ };
+
+struct grub_arc_timeinfo
+{
+ grub_arc_ushort_t y;
+ grub_arc_ushort_t m;
+ grub_arc_ushort_t d;
+ grub_arc_ushort_t h;
+ grub_arc_ushort_t min;
+ grub_arc_ushort_t s;
+ grub_arc_ushort_t ms;
+};
+
+struct grub_arc_display_status
+{
+ grub_arc_ushort_t x;
+ grub_arc_ushort_t y;
+ grub_arc_ushort_t w;
+ grub_arc_ushort_t h;
+ grub_arc_uchar_t fgcolor;
+ grub_arc_uchar_t bgcolor;
+ grub_arc_uchar_t high_intensity;
+ grub_arc_uchar_t underscored;
+ grub_arc_uchar_t reverse_video;
+};
+
+enum
+ {
+ GRUB_ARC_COMPONENT_FLAG_OUT = 0x40,
+ GRUB_ARC_COMPONENT_FLAG_IN = 0x20,
+ };
+
+struct grub_arc_component
+{
+ grub_arc_enum_t class;
+ grub_arc_enum_t type;
+ grub_arc_enum_t flags;
+ grub_arc_ushort_t version;
+ grub_arc_ushort_t rev;
+ grub_arc_ulong_t key;
+ grub_arc_ulong_t affinity;
+ grub_arc_ulong_t configdatasize;
+ grub_arc_ulong_t idlen;
+ const char *idstr;
+};
+
+enum
+ {
+#ifdef GRUB_CPU_WORDS_BIGENDIAN
+ GRUB_ARC_COMPONENT_TYPE_ARC = 1,
+#else
+ GRUB_ARC_COMPONENT_TYPE_ARC,
+#endif
+ GRUB_ARC_COMPONENT_TYPE_CPU,
+ GRUB_ARC_COMPONENT_TYPE_FPU,
+ GRUB_ARC_COMPONENT_TYPE_PRI_I_CACHE,
+ GRUB_ARC_COMPONENT_TYPE_PRI_D_CACHE,
+ GRUB_ARC_COMPONENT_TYPE_SEC_I_CACHE,
+ GRUB_ARC_COMPONENT_TYPE_SEC_D_CACHE,
+ GRUB_ARC_COMPONENT_TYPE_SEC_CACHE,
+ GRUB_ARC_COMPONENT_TYPE_EISA,
+ GRUB_ARC_COMPONENT_TYPE_TCA,
+ GRUB_ARC_COMPONENT_TYPE_SCSI,
+ GRUB_ARC_COMPONENT_TYPE_DTIA,
+ GRUB_ARC_COMPONENT_TYPE_MULTIFUNC,
+ GRUB_ARC_COMPONENT_TYPE_DISK_CONTROLLER,
+ GRUB_ARC_COMPONENT_TYPE_TAPE_CONTROLLER,
+ GRUB_ARC_COMPONENT_TYPE_CDROM_CONTROLLER,
+ GRUB_ARC_COMPONENT_TYPE_WORM_CONTROLLER,
+ GRUB_ARC_COMPONENT_TYPE_SERIAL_CONTROLLER,
+ GRUB_ARC_COMPONENT_TYPE_NET_CONTROLLER,
+ GRUB_ARC_COMPONENT_TYPE_DISPLAY_CONTROLLER,
+ GRUB_ARC_COMPONENT_TYPE_PARALLEL_CONTROLLER,
+ GRUB_ARC_COMPONENT_TYPE_POINTER_CONTROLLER,
+ GRUB_ARC_COMPONENT_TYPE_KBD_CONTROLLER,
+ GRUB_ARC_COMPONENT_TYPE_AUDIO_CONTROLLER,
+ GRUB_ARC_COMPONENT_TYPE_OTHER_CONTROLLER,
+ GRUB_ARC_COMPONENT_TYPE_DISK,
+ GRUB_ARC_COMPONENT_TYPE_FLOPPY,
+ GRUB_ARC_COMPONENT_TYPE_TAPE,
+ GRUB_ARC_COMPONENT_TYPE_MODEM,
+ GRUB_ARC_COMPONENT_TYPE_MONITOR,
+ GRUB_ARC_COMPONENT_TYPE_PRINTER,
+ GRUB_ARC_COMPONENT_TYPE_POINTER,
+ GRUB_ARC_COMPONENT_TYPE_KBD,
+ GRUB_ARC_COMPONENT_TYPE_TERMINAL,
+#ifndef GRUB_CPU_WORDS_BIGENDIAN
+ GRUB_ARC_COMPONENT_TYPE_OTHER_PERIPHERAL,
+#endif
+ GRUB_ARC_COMPONENT_TYPE_LINE,
+ GRUB_ARC_COMPONENT_TYPE_NET,
+ GRUB_ARC_COMPONENT_TYPE_MEMORY_UNIT,
+ };
+
+enum grub_arc_file_access
+ {
+ GRUB_ARC_FILE_ACCESS_OPEN_RO,
+ GRUB_ARC_FILE_ACCESS_OPEN_WO,
+ GRUB_ARC_FILE_ACCESS_OPEN_RW,
+ };
+
+struct grub_arc_fileinfo
+{
+ grub_arc_ularge_t start;
+ grub_arc_ularge_t end;
+ grub_arc_ularge_t current;
+ grub_arc_enum_t type;
+ grub_arc_ulong_t fnamelength;
+ grub_arc_uchar_t attr;
+ char filename[32];
+};
+
+struct grub_arc_firmware_vector
+{
+ /* 0x00. */
+ void *load;
+ void *invoke;
+ void *execute;
+ void *halt;
+
+ /* 0x10. */
+ void (*powerdown) (void);
+ void (*restart) (void);
+ void (*reboot) (void);
+ void (*exit) (void);
+
+ /* 0x20. */
+ void *reserved1;
+ const struct grub_arc_component * (*getpeer) (const struct grub_arc_component *comp);
+ const struct grub_arc_component * (*getchild) (const struct grub_arc_component *comp);
+ void *getparent;
+
+ /* 0x30. */
+ void *getconfigurationdata;
+ void *addchild;
+ void *deletecomponent;
+ void *getcomponent;
+
+ /* 0x40. */
+ void *saveconfiguration;
+ void *getsystemid;
+ struct grub_arc_memory_descriptor *(*getmemorydescriptor) (struct grub_arc_memory_descriptor *current);
+ void *reserved2;
+
+ /* 0x50. */
+ struct grub_arc_timeinfo *(*gettime) (void);
+ void *getrelativetime;
+ void *getdirectoryentry;
+ grub_arc_err_t (*open) (const char *path, grub_arc_enum_t mode,
+ grub_arc_fileno_t *fileno);
+
+ /* 0x60. */
+ grub_arc_err_t (*close) (grub_arc_fileno_t fileno);
+ grub_arc_err_t (*read) (grub_arc_fileno_t fileno, void *buf,
+ grub_arc_ulong_t n,
+ grub_arc_ulong_t *count);
+ grub_arc_err_t (*get_read_status) (grub_arc_fileno_t fileno);
+ grub_arc_err_t (*write) (grub_arc_fileno_t fileno, const void *buf,
+ grub_arc_ulong_t n,
+ grub_arc_ulong_t *count);
+
+ /* 0x70. */
+ grub_arc_err_t (*seek) (grub_arc_fileno_t fileno,
+ grub_arc_ularge_t *pos, grub_arc_enum_t mode);
+ void *mount;
+ const char * (*getenvironmentvariable) (const char *name);
+ void *setenvironmentvariable;
+
+ /* 0x80. */
+ grub_arc_err_t (*getfileinformation) (grub_arc_fileno_t fileno,
+ struct grub_arc_fileinfo *info);
+ void *setfileinformation;
+ void *flushallcaches;
+ void *testunicodecharacter;
+
+ /* 0x90. */
+ struct grub_arc_display_status * (*getdisplaystatus) (grub_arc_fileno_t fileno);
+};
+
+struct grub_arc_adapter
+{
+ grub_arc_ulong_t adapter_type;
+ grub_arc_ulong_t adapter_vector_length;
+ void *adapter_vector;
+};
+
+struct grub_arc_system_parameter_block
+{
+ grub_arc_ulong_t signature;
+ grub_arc_ulong_t length;
+ grub_arc_ushort_t version;
+ grub_arc_ushort_t revision;
+ void *restartblock;
+ void *debugblock;
+ void *gevector;
+ void *utlbmissvector;
+ grub_arc_ulong_t firmware_vector_length;
+ struct grub_arc_firmware_vector *firmwarevector;
+ grub_arc_ulong_t private_vector_length;
+ void *private_vector;
+ grub_arc_ulong_t adapter_count;
+ struct grub_arc_adapter adapters[0];
+};
+
+
+#define GRUB_ARC_SYSTEM_PARAMETER_BLOCK ((struct grub_arc_system_parameter_block *) 0xa0001000)
+#define GRUB_ARC_FIRMWARE_VECTOR (GRUB_ARC_SYSTEM_PARAMETER_BLOCK->firmwarevector)
+#define GRUB_ARC_STDIN 0
+#define GRUB_ARC_STDOUT 1
+
+typedef int (*grub_arc_iterate_devs_hook_t)
+ (const char *name, const struct grub_arc_component *comp, void *data);
+
+int EXPORT_FUNC (grub_arc_iterate_devs) (grub_arc_iterate_devs_hook_t hook,
+ void *hook_data,
+ int alt_names);
+
+char *EXPORT_FUNC (grub_arc_alt_name_to_norm) (const char *name, const char *suffix);
+
+int EXPORT_FUNC (grub_arc_is_device_serial) (const char *name, int alt_names);
+
+
+#define FOR_ARC_CHILDREN(comp, parent) for (comp = GRUB_ARC_FIRMWARE_VECTOR->getchild (parent); comp; comp = GRUB_ARC_FIRMWARE_VECTOR->getpeer (comp))
+
+extern void grub_arcdisk_init (void);
+extern void grub_arcdisk_fini (void);
+
+
+#endif
diff --git a/include/grub/arc/console.h b/include/grub/arc/console.h
new file mode 100644
index 0000000..e054f54
--- /dev/null
+++ b/include/grub/arc/console.h
@@ -0,0 +1,31 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_CONSOLE_MACHINE_HEADER
+#define GRUB_CONSOLE_MACHINE_HEADER 1
+
+#include <grub/symbol.h>
+
+/* Initialize the console system. */
+void grub_console_init_early (void);
+void grub_console_init_lately (void);
+
+/* Finish the console system. */
+void grub_console_fini (void);
+
+#endif /* ! GRUB_CONSOLE_MACHINE_HEADER */
diff --git a/include/grub/archelp.h b/include/grub/archelp.h
new file mode 100644
index 0000000..2611d7f
--- /dev/null
+++ b/include/grub/archelp.h
@@ -0,0 +1,63 @@
+/* archelp.h -- Archive helper functions */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_ARCHELP_HEADER
+#define GRUB_ARCHELP_HEADER 1
+
+#include <grub/fs.h>
+#include <grub/file.h>
+
+typedef enum
+ {
+ GRUB_ARCHELP_ATTR_TYPE = 0160000,
+ GRUB_ARCHELP_ATTR_FILE = 0100000,
+ GRUB_ARCHELP_ATTR_DIR = 0040000,
+ GRUB_ARCHELP_ATTR_LNK = 0120000,
+ GRUB_ARCHELP_ATTR_NOTIME = 0x80000000,
+ GRUB_ARCHELP_ATTR_END = 0xffffffff
+ } grub_archelp_mode_t;
+
+struct grub_archelp_data;
+
+struct grub_archelp_ops
+{
+ grub_err_t
+ (*find_file) (struct grub_archelp_data *data, char **name,
+ grub_int32_t *mtime,
+ grub_archelp_mode_t *mode);
+
+ char *
+ (*get_link_target) (struct grub_archelp_data *data);
+
+ void
+ (*rewind) (struct grub_archelp_data *data);
+};
+
+grub_err_t
+grub_archelp_dir (struct grub_archelp_data *data,
+ struct grub_archelp_ops *ops,
+ const char *path_in,
+ grub_fs_dir_hook_t hook, void *hook_data);
+
+grub_err_t
+grub_archelp_open (struct grub_archelp_data *data,
+ struct grub_archelp_ops *ops,
+ const char *name_in);
+
+#endif
diff --git a/include/grub/arm/coreboot/console.h b/include/grub/arm/coreboot/console.h
new file mode 100644
index 0000000..13a14b7
--- /dev/null
+++ b/include/grub/arm/coreboot/console.h
@@ -0,0 +1,29 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MACHINE_CONSOLE_HEADER
+#define GRUB_MACHINE_CONSOLE_HEADER 1
+
+void grub_video_coreboot_fb_init (void);
+void grub_video_coreboot_fb_early_init (void);
+void grub_video_coreboot_fb_late_init (void);
+void grub_video_coreboot_fb_fini (void);
+
+extern struct grub_linuxbios_table_framebuffer *grub_video_coreboot_fbtable;
+
+#endif /* ! GRUB_MACHINE_CONSOLE_HEADER */
diff --git a/include/grub/arm/coreboot/kernel.h b/include/grub/arm/coreboot/kernel.h
new file mode 100644
index 0000000..2695053
--- /dev/null
+++ b/include/grub/arm/coreboot/kernel.h
@@ -0,0 +1,44 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_KERNEL_MACHINE_HEADER
+#define GRUB_KERNEL_MACHINE_HEADER 1
+
+#ifndef ASM_FILE
+
+#include <grub/symbol.h>
+#include <grub/types.h>
+
+struct grub_fdt_board
+{
+ const char *vendor, *part;
+ const grub_uint8_t *dtb;
+ grub_size_t dtb_size;
+};
+
+extern struct grub_fdt_board grub_fdt_boards[];
+void grub_machine_timer_init (void);
+void grub_pl050_init (void);
+void grub_cros_init (void);
+void grub_rk3288_spi_init (void);
+extern grub_addr_t EXPORT_VAR (start_of_ram);
+#endif /* ! ASM_FILE */
+
+#define GRUB_KERNEL_MACHINE_STACK_SIZE GRUB_KERNEL_ARM_STACK_SIZE
+
+#endif /* ! GRUB_KERNEL_MACHINE_HEADER */
diff --git a/include/grub/arm/cros_ec.h b/include/grub/arm/cros_ec.h
new file mode 100644
index 0000000..45a3725
--- /dev/null
+++ b/include/grub/arm/cros_ec.h
@@ -0,0 +1,21 @@
+#ifndef GRUB_ARM_CROS_EC_H
+#define GRUB_ARM_CROS_EC_H 1
+
+#include <grub/types.h>
+#include <grub/fdtbus.h>
+
+#define GRUB_CROS_EC_KEYSCAN_COLS 13
+#define GRUB_CROS_EC_KEYSCAN_ROWS 8
+
+struct grub_cros_ec_keyscan {
+ grub_uint8_t data[GRUB_CROS_EC_KEYSCAN_COLS];
+};
+
+int
+grub_cros_ec_scan_keyboard (const struct grub_fdtbus_dev *dev,
+ struct grub_cros_ec_keyscan *scan);
+
+int
+grub_cros_ec_validate (const struct grub_fdtbus_dev *dev);
+
+#endif
diff --git a/include/grub/arm/efi/memory.h b/include/grub/arm/efi/memory.h
new file mode 100644
index 0000000..2c64918
--- /dev/null
+++ b/include/grub/arm/efi/memory.h
@@ -0,0 +1,6 @@
+#ifndef GRUB_MEMORY_CPU_HEADER
+#include <grub/efi/memory.h>
+
+#define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffff
+
+#endif /* ! GRUB_MEMORY_CPU_HEADER */
diff --git a/include/grub/arm/linux.h b/include/grub/arm/linux.h
new file mode 100644
index 0000000..bcd5a7e
--- /dev/null
+++ b/include/grub/arm/linux.h
@@ -0,0 +1,67 @@
+/* linux.h - ARM linux specific definitions */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_ARM_LINUX_HEADER
+#define GRUB_ARM_LINUX_HEADER 1
+
+#include "system.h"
+
+#define GRUB_LINUX_ARM_MAGIC_SIGNATURE 0x016f2818
+
+struct linux_arm_kernel_header {
+ grub_uint32_t code0;
+ grub_uint32_t reserved1[8];
+ grub_uint32_t magic;
+ grub_uint32_t start; /* _start */
+ grub_uint32_t end; /* _edata */
+ grub_uint32_t reserved2[3];
+ grub_uint32_t hdr_offset;
+};
+
+#if defined(__arm__)
+# define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM_MAGIC_SIGNATURE
+# define linux_arch_kernel_header linux_arm_kernel_header
+#endif
+
+#if defined GRUB_MACHINE_UBOOT
+# include <grub/uboot/uboot.h>
+# define LINUX_ADDRESS (start_of_ram + 0x8000)
+# define LINUX_INITRD_ADDRESS (start_of_ram + 0x03000000)
+# define LINUX_FDT_ADDRESS (LINUX_INITRD_ADDRESS - 0x10000)
+# define grub_arm_firmware_get_boot_data grub_uboot_get_boot_data
+# define grub_arm_firmware_get_machine_type grub_uboot_get_machine_type
+#elif defined (GRUB_MACHINE_COREBOOT)
+#include <grub/fdtbus.h>
+#include <grub/arm/coreboot/kernel.h>
+# define LINUX_ADDRESS (start_of_ram + 0x8000)
+# define LINUX_INITRD_ADDRESS (start_of_ram + 0x03000000)
+# define LINUX_FDT_ADDRESS (LINUX_INITRD_ADDRESS - 0x10000)
+static inline const void *
+grub_arm_firmware_get_boot_data (void)
+{
+ return grub_fdtbus_get_fdt ();
+}
+static inline grub_uint32_t
+grub_arm_firmware_get_machine_type (void)
+{
+ return GRUB_ARM_MACHINE_TYPE_FDT;
+}
+#endif
+
+#endif /* ! GRUB_ARM_LINUX_HEADER */
diff --git a/include/grub/arm/reloc.h b/include/grub/arm/reloc.h
new file mode 100644
index 0000000..ae92e21
--- /dev/null
+++ b/include/grub/arm/reloc.h
@@ -0,0 +1,51 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_ARM_RELOC_H
+#define GRUB_ARM_RELOC_H 1
+
+grub_err_t grub_arm_reloc_abs32 (grub_uint32_t *addr, Elf32_Addr sym_addr);
+
+int
+grub_arm_thm_call_check_offset (grub_int32_t offset, int is_thumb);
+grub_int32_t
+grub_arm_thm_call_get_offset (grub_uint16_t *target);
+grub_err_t
+grub_arm_thm_call_set_offset (grub_uint16_t *target, grub_int32_t offset);
+
+grub_int32_t
+grub_arm_thm_jump19_get_offset (grub_uint16_t *target);
+void
+grub_arm_thm_jump19_set_offset (grub_uint16_t *target, grub_int32_t offset);
+int
+grub_arm_thm_jump19_check_offset (grub_int32_t offset);
+
+grub_int32_t
+grub_arm_jump24_get_offset (grub_uint32_t *target);
+int
+grub_arm_jump24_check_offset (grub_int32_t offset);
+void
+grub_arm_jump24_set_offset (grub_uint32_t *target,
+ grub_int32_t offset);
+
+grub_uint16_t
+grub_arm_thm_movw_movt_get_value (grub_uint16_t *target);
+void
+grub_arm_thm_movw_movt_set_value (grub_uint16_t *target, grub_uint16_t value);
+
+#endif
diff --git a/include/grub/arm/setjmp.h b/include/grub/arm/setjmp.h
new file mode 100644
index 0000000..7990f2e
--- /dev/null
+++ b/include/grub/arm/setjmp.h
@@ -0,0 +1,27 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2004,2006,2007,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_SETJMP_CPU_HEADER
+#define GRUB_SETJMP_CPU_HEADER 1
+
+typedef unsigned long grub_jmp_buf[10];
+
+int grub_setjmp (grub_jmp_buf env) RETURNS_TWICE;
+void grub_longjmp (grub_jmp_buf env, int val) __attribute__ ((noreturn));
+
+#endif /* ! GRUB_SETJMP_CPU_HEADER */
diff --git a/include/grub/arm/startup.h b/include/grub/arm/startup.h
new file mode 100644
index 0000000..9afb6c5
--- /dev/null
+++ b/include/grub/arm/startup.h
@@ -0,0 +1,16 @@
+#ifndef GRUB_STARTUP_CPU_HEADER
+#define GRUB_STARTUP_CPU_HEADER
+
+struct grub_arm_startup_registers
+{
+ /* registers 0-11 */
+ /* for U-boot r[1] is machine type */
+ /* for U-boot r[2] is boot data */
+ grub_uint32_t r[12];
+ grub_uint32_t sp;
+ grub_uint32_t lr;
+};
+
+extern struct grub_arm_startup_registers grub_arm_saved_registers;
+
+#endif
diff --git a/include/grub/arm/system.h b/include/grub/arm/system.h
new file mode 100644
index 0000000..f15ce97
--- /dev/null
+++ b/include/grub/arm/system.h
@@ -0,0 +1,19 @@
+#ifndef GRUB_SYSTEM_CPU_HEADER
+#define GRUB_SYSTEM_CPU_HEADER
+
+#include <grub/symbol.h>
+#include <grub/types.h>
+
+enum
+ {
+ GRUB_ARM_MACHINE_TYPE_RASPBERRY_PI = 3138,
+ GRUB_ARM_MACHINE_TYPE_FDT = 0xFFFFFFFF
+ };
+
+void EXPORT_FUNC(grub_arm_disable_caches_mmu) (void);
+void grub_arm_enable_caches_mmu (void);
+void grub_arm_enable_mmu (grub_uint32_t *mmu_tables);
+void grub_arm_clear_mmu_v6 (void);
+
+#endif /* ! GRUB_SYSTEM_CPU_HEADER */
+
diff --git a/include/grub/arm/time.h b/include/grub/arm/time.h
new file mode 100644
index 0000000..c5a6852
--- /dev/null
+++ b/include/grub/arm/time.h
@@ -0,0 +1,29 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef KERNEL_CPU_TIME_HEADER
+#define KERNEL_CPU_TIME_HEADER 1
+
+static __inline void
+grub_cpu_idle (void)
+{
+ /* FIXME: this can't work until we handle interrupts. */
+/* asm volatile ("wfi"); */
+}
+
+#endif /* ! KERNEL_CPU_TIME_HEADER */
diff --git a/include/grub/arm/types.h b/include/grub/arm/types.h
new file mode 100644
index 0000000..4a806d0
--- /dev/null
+++ b/include/grub/arm/types.h
@@ -0,0 +1,34 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_TYPES_CPU_HEADER
+#define GRUB_TYPES_CPU_HEADER 1
+
+/* The size of void *. */
+#define GRUB_TARGET_SIZEOF_VOID_P 4
+
+/* The size of long. */
+#define GRUB_TARGET_SIZEOF_LONG 4
+
+/* currently only support little-endian. */
+#undef GRUB_TARGET_WORDS_BIGENDIAN
+
+/* Unaligned accesses only supported if MMU enabled */
+//#define GRUB_HAVE_UNALIGNED_ACCESS 1
+
+#endif /* ! GRUB_TYPES_CPU_HEADER */
diff --git a/include/grub/arm/uboot/kernel.h b/include/grub/arm/uboot/kernel.h
new file mode 100644
index 0000000..ce0b149
--- /dev/null
+++ b/include/grub/arm/uboot/kernel.h
@@ -0,0 +1,32 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_KERNEL_MACHINE_HEADER
+#define GRUB_KERNEL_MACHINE_HEADER 1
+
+#ifndef ASM_FILE
+
+#include <grub/symbol.h>
+#include <grub/types.h>
+
+#endif /* ! ASM_FILE */
+
+#define GRUB_KERNEL_MACHINE_STACK_SIZE GRUB_KERNEL_ARM_STACK_SIZE
+#define GRUB_KERNEL_MACHINE_HEAP_SIZE (grub_size_t) (16 * 1024 * 1024)
+
+#endif /* ! GRUB_KERNEL_MACHINE_HEADER */
diff --git a/include/grub/arm64/efi/memory.h b/include/grub/arm64/efi/memory.h
new file mode 100644
index 0000000..c6cb324
--- /dev/null
+++ b/include/grub/arm64/efi/memory.h
@@ -0,0 +1,6 @@
+#ifndef GRUB_MEMORY_CPU_HEADER
+#include <grub/efi/memory.h>
+
+#define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffffffffULL
+
+#endif /* ! GRUB_MEMORY_CPU_HEADER */
diff --git a/include/grub/arm64/linux.h b/include/grub/arm64/linux.h
new file mode 100644
index 0000000..7e22b4a
--- /dev/null
+++ b/include/grub/arm64/linux.h
@@ -0,0 +1,46 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_ARM64_LINUX_HEADER
+#define GRUB_ARM64_LINUX_HEADER 1
+
+#include <grub/types.h>
+
+#define GRUB_LINUX_ARM64_MAGIC_SIGNATURE 0x644d5241 /* 'ARM\x64' */
+
+/* From linux/Documentation/arm64/booting.txt */
+struct linux_arm64_kernel_header
+{
+ grub_uint32_t code0; /* Executable code */
+ grub_uint32_t code1; /* Executable code */
+ grub_uint64_t text_offset; /* Image load offset */
+ grub_uint64_t res0; /* reserved */
+ grub_uint64_t res1; /* reserved */
+ grub_uint64_t res2; /* reserved */
+ grub_uint64_t res3; /* reserved */
+ grub_uint64_t res4; /* reserved */
+ grub_uint32_t magic; /* Magic number, little endian, "ARM\x64" */
+ grub_uint32_t hdr_offset; /* Offset of PE/COFF header */
+};
+
+#if defined(__aarch64__)
+# define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM64_MAGIC_SIGNATURE
+# define linux_arch_kernel_header linux_arm64_kernel_header
+#endif
+
+#endif /* ! GRUB_ARM64_LINUX_HEADER */
diff --git a/include/grub/arm64/reloc.h b/include/grub/arm64/reloc.h
new file mode 100644
index 0000000..c8765de
--- /dev/null
+++ b/include/grub/arm64/reloc.h
@@ -0,0 +1,41 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_ARM64_RELOC_H
+#define GRUB_ARM64_RELOC_H 1
+
+struct grub_arm64_trampoline
+{
+ grub_uint32_t ldr; /* ldr x16, 8 */
+ grub_uint32_t br; /* br x16 */
+ grub_uint64_t addr;
+};
+
+int grub_arm_64_check_xxxx26_offset (grub_int64_t offset);
+void
+grub_arm64_set_xxxx26_offset (grub_uint32_t *place, grub_int64_t offset);
+int
+grub_arm64_check_hi21_signed (grub_int64_t offset);
+void
+grub_arm64_set_hi21 (grub_uint32_t *place, grub_int64_t offset);
+void
+grub_arm64_set_abs_lo12 (grub_uint32_t *place, grub_int64_t target);
+void
+grub_arm64_set_abs_lo12_ldst64 (grub_uint32_t *place, grub_int64_t target);
+
+#endif
diff --git a/include/grub/arm64/setjmp.h b/include/grub/arm64/setjmp.h
new file mode 100644
index 0000000..3ff7dfb
--- /dev/null
+++ b/include/grub/arm64/setjmp.h
@@ -0,0 +1,27 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_SETJMP_CPU_HEADER
+#define GRUB_SETJMP_CPU_HEADER 1
+
+typedef unsigned long long grub_jmp_buf[13];
+
+int grub_setjmp (grub_jmp_buf env) RETURNS_TWICE;
+void grub_longjmp (grub_jmp_buf env, int val) __attribute__ ((noreturn));
+
+#endif /* ! GRUB_SETJMP_CPU_HEADER */
diff --git a/include/grub/arm64/time.h b/include/grub/arm64/time.h
new file mode 100644
index 0000000..c5a6852
--- /dev/null
+++ b/include/grub/arm64/time.h
@@ -0,0 +1,29 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef KERNEL_CPU_TIME_HEADER
+#define KERNEL_CPU_TIME_HEADER 1
+
+static __inline void
+grub_cpu_idle (void)
+{
+ /* FIXME: this can't work until we handle interrupts. */
+/* asm volatile ("wfi"); */
+}
+
+#endif /* ! KERNEL_CPU_TIME_HEADER */
diff --git a/include/grub/arm64/types.h b/include/grub/arm64/types.h
new file mode 100644
index 0000000..d132c5e
--- /dev/null
+++ b/include/grub/arm64/types.h
@@ -0,0 +1,34 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_TYPES_CPU_HEADER
+#define GRUB_TYPES_CPU_HEADER 1
+
+/* The size of void *. */
+#define GRUB_TARGET_SIZEOF_VOID_P 8
+
+/* The size of long. */
+#define GRUB_TARGET_SIZEOF_LONG 8
+
+/* currently only support little-endian. */
+#undef GRUB_TARGET_WORDS_BIGENDIAN
+
+/* Unaligned accesses only supported if MMU enabled */
+#undef GRUB_HAVE_UNALIGNED_ACCESS
+
+#endif /* ! GRUB_TYPES_CPU_HEADER */
diff --git a/include/grub/at_keyboard.h b/include/grub/at_keyboard.h
new file mode 100644
index 0000000..bcb4d9b
--- /dev/null
+++ b/include/grub/at_keyboard.h
@@ -0,0 +1,40 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_AT_KEYBOARD_HEADER
+#define GRUB_AT_KEYBOARD_HEADER 1
+
+/* Used for sending commands to the controller. */
+#define KEYBOARD_COMMAND_ISREADY(x) !((x) & 0x02)
+#define KEYBOARD_COMMAND_READ 0x20
+#define KEYBOARD_COMMAND_WRITE 0x60
+#define KEYBOARD_COMMAND_ENABLE 0xf4
+#define KEYBOARD_COMMAND_REBOOT 0xfe
+
+#define KEYBOARD_AT_TRANSLATE 0x40
+#define KEYBOARD_AT_DISABLE 0x10
+
+#define KEYBOARD_ISMAKE(x) !((x) & 0x80)
+#define KEYBOARD_ISREADY(x) ((x) & 0x01)
+#define KEYBOARD_SCANCODE(x) ((x) & 0x7f)
+
+extern void grub_at_keyboard_init (void);
+extern void grub_at_keyboard_fini (void);
+int grub_at_keyboard_is_alive (void);
+
+#endif
diff --git a/include/grub/ata.h b/include/grub/ata.h
new file mode 100644
index 0000000..e8a84b8
--- /dev/null
+++ b/include/grub/ata.h
@@ -0,0 +1,225 @@
+/* ata.h - ATA disk access. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_ATA_HEADER
+#define GRUB_ATA_HEADER 1
+
+#include <grub/misc.h>
+#include <grub/symbol.h>
+#include <grub/disk.h>
+/* XXX: For now this only works on i386. */
+#include <grub/cpu/io.h>
+
+typedef enum
+ {
+ GRUB_ATA_CHS,
+ GRUB_ATA_LBA,
+ GRUB_ATA_LBA48
+ } grub_ata_addressing_t;
+
+#define GRUB_ATA_CH0_PORT1 0x1f0
+#define GRUB_ATA_CH1_PORT1 0x170
+
+#define GRUB_ATA_CH0_PORT2 0x3f6
+#define GRUB_ATA_CH1_PORT2 0x376
+
+#define GRUB_ATA_REG_DATA 0
+#define GRUB_ATA_REG_ERROR 1
+#define GRUB_ATA_REG_FEATURES 1
+#define GRUB_ATA_REG_SECTORS 2
+#define GRUB_ATAPI_REG_IREASON 2
+#define GRUB_ATA_REG_SECTNUM 3
+#define GRUB_ATA_REG_CYLLSB 4
+#define GRUB_ATA_REG_CYLMSB 5
+#define GRUB_ATA_REG_LBALOW 3
+#define GRUB_ATA_REG_LBAMID 4
+#define GRUB_ATAPI_REG_CNTLOW 4
+#define GRUB_ATA_REG_LBAHIGH 5
+#define GRUB_ATAPI_REG_CNTHIGH 5
+#define GRUB_ATA_REG_DISK 6
+#define GRUB_ATA_REG_CMD 7
+#define GRUB_ATA_REG_STATUS 7
+
+#define GRUB_ATA_REG2_CONTROL 0
+
+#define GRUB_ATA_STATUS_ERR 0x01
+#define GRUB_ATA_STATUS_INDEX 0x02
+#define GRUB_ATA_STATUS_ECC 0x04
+#define GRUB_ATA_STATUS_DRQ 0x08
+#define GRUB_ATA_STATUS_SEEK 0x10
+#define GRUB_ATA_STATUS_WRERR 0x20
+#define GRUB_ATA_STATUS_READY 0x40
+#define GRUB_ATA_STATUS_BUSY 0x80
+
+/* ATAPI interrupt reason values (I/O, D/C bits). */
+#define GRUB_ATAPI_IREASON_MASK 0x3
+#define GRUB_ATAPI_IREASON_DATA_OUT 0x0
+#define GRUB_ATAPI_IREASON_CMD_OUT 0x1
+#define GRUB_ATAPI_IREASON_DATA_IN 0x2
+#define GRUB_ATAPI_IREASON_ERROR 0x3
+
+enum grub_ata_commands
+ {
+ GRUB_ATA_CMD_CHECK_POWER_MODE = 0xe5,
+ GRUB_ATA_CMD_IDENTIFY_DEVICE = 0xec,
+ GRUB_ATA_CMD_IDENTIFY_PACKET_DEVICE = 0xa1,
+ GRUB_ATA_CMD_IDLE = 0xe3,
+ GRUB_ATA_CMD_PACKET = 0xa0,
+ GRUB_ATA_CMD_READ_SECTORS = 0x20,
+ GRUB_ATA_CMD_READ_SECTORS_EXT = 0x24,
+ GRUB_ATA_CMD_READ_SECTORS_DMA = 0xc8,
+ GRUB_ATA_CMD_READ_SECTORS_DMA_EXT = 0x25,
+
+ GRUB_ATA_CMD_SECURITY_FREEZE_LOCK = 0xf5,
+ GRUB_ATA_CMD_SET_FEATURES = 0xef,
+ GRUB_ATA_CMD_SLEEP = 0xe6,
+ GRUB_ATA_CMD_SMART = 0xb0,
+ GRUB_ATA_CMD_STANDBY_IMMEDIATE = 0xe0,
+ GRUB_ATA_CMD_WRITE_SECTORS = 0x30,
+ GRUB_ATA_CMD_WRITE_SECTORS_EXT = 0x34,
+ GRUB_ATA_CMD_WRITE_SECTORS_DMA_EXT = 0x35,
+ GRUB_ATA_CMD_WRITE_SECTORS_DMA = 0xca,
+ };
+
+enum grub_ata_timeout_milliseconds
+ {
+ GRUB_ATA_TOUT_STD = 1000, /* 1s standard timeout. */
+ GRUB_ATA_TOUT_DATA = 10000, /* 10s DATA I/O timeout. */
+ GRUB_ATA_TOUT_SPINUP = 10000, /* Give the device 10s on first try to spinon. */
+ };
+
+typedef union
+{
+ grub_uint8_t raw[11];
+ struct
+ {
+ union
+ {
+ grub_uint8_t features;
+ grub_uint8_t error;
+ };
+ union
+ {
+ grub_uint8_t sectors;
+ grub_uint8_t atapi_ireason;
+ };
+ union
+ {
+ grub_uint8_t lba_low;
+ grub_uint8_t sectnum;
+ };
+ union
+ {
+ grub_uint8_t lba_mid;
+ grub_uint8_t cyllsb;
+ grub_uint8_t atapi_cntlow;
+ };
+ union
+ {
+ grub_uint8_t lba_high;
+ grub_uint8_t cylmsb;
+ grub_uint8_t atapi_cnthigh;
+ };
+ grub_uint8_t disk;
+ union
+ {
+ grub_uint8_t cmd;
+ grub_uint8_t status;
+ };
+ grub_uint8_t sectors48;
+ grub_uint8_t lba48_low;
+ grub_uint8_t lba48_mid;
+ grub_uint8_t lba48_high;
+ };
+} grub_ata_regs_t;
+
+/* ATA pass through parameters and function. */
+struct grub_disk_ata_pass_through_parms
+{
+ grub_ata_regs_t taskfile;
+ void * buffer;
+ grub_size_t size;
+ int write;
+ void *cmd;
+ int cmdsize;
+ int dma;
+};
+
+struct grub_ata
+{
+ /* Addressing methods available for accessing this device. If CHS
+ is only available, use that. Otherwise use LBA, except for the
+ high sectors. In that case use LBA48. */
+ grub_ata_addressing_t addr;
+
+ /* Sector count. */
+ grub_uint64_t size;
+ grub_uint32_t log_sector_size;
+
+ /* CHS maximums. */
+ grub_uint16_t cylinders;
+ grub_uint16_t heads;
+ grub_uint16_t sectors_per_track;
+
+ /* Set to 0 for ATA, set to 1 for ATAPI. */
+ int atapi;
+
+ int dma;
+
+ grub_size_t maxbuffer;
+
+ int *present;
+
+ void *data;
+
+ struct grub_ata_dev *dev;
+};
+
+typedef struct grub_ata *grub_ata_t;
+
+typedef int (*grub_ata_dev_iterate_hook_t) (int id, int bus, void *data);
+
+struct grub_ata_dev
+{
+ /* Call HOOK with each device name, until HOOK returns non-zero. */
+ int (*iterate) (grub_ata_dev_iterate_hook_t hook, void *hook_data,
+ grub_disk_pull_t pull);
+
+ /* Open the device named NAME, and set up SCSI. */
+ grub_err_t (*open) (int id, int bus, struct grub_ata *scsi);
+
+ /* Close the scsi device SCSI. */
+ void (*close) (struct grub_ata *ata);
+
+ /* Read SIZE bytes from the device SCSI into BUF after sending the
+ command CMD of size CMDSIZE. */
+ grub_err_t (*readwrite) (struct grub_ata *ata,
+ struct grub_disk_ata_pass_through_parms *parms,
+ int spinup);
+
+ /* The next scsi device. */
+ struct grub_ata_dev *next;
+};
+
+typedef struct grub_ata_dev *grub_ata_dev_t;
+
+void grub_ata_dev_register (grub_ata_dev_t dev);
+void grub_ata_dev_unregister (grub_ata_dev_t dev);
+
+#endif /* ! GRUB_ATA_HEADER */
diff --git a/include/grub/auth.h b/include/grub/auth.h
new file mode 100644
index 0000000..7473344
--- /dev/null
+++ b/include/grub/auth.h
@@ -0,0 +1,37 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef GRUB_AUTH_HEADER
+#define GRUB_AUTH_HEADER 1
+
+#include <grub/err.h>
+#include <grub/crypto.h>
+
+#define GRUB_AUTH_MAX_PASSLEN 1024
+
+typedef grub_err_t (*grub_auth_callback_t) (const char *, const char *, void *);
+
+grub_err_t grub_auth_register_authentication (const char *user,
+ grub_auth_callback_t callback,
+ void *arg);
+grub_err_t grub_auth_unregister_authentication (const char *user);
+
+grub_err_t grub_auth_authenticate (const char *user);
+grub_err_t grub_auth_deauthenticate (const char *user);
+grub_err_t grub_auth_check_authentication (const char *userlist);
+
+#endif /* ! GRUB_AUTH_HEADER */
diff --git a/include/grub/autoefi.h b/include/grub/autoefi.h
new file mode 100644
index 0000000..b7a252e
--- /dev/null
+++ b/include/grub/autoefi.h
@@ -0,0 +1,64 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+/* This file provides some abstractions so that the same code compiles with
+ both efi and efiemu
+ */
+#ifndef GRUB_AUTOEFI_HEADER
+#define GRUB_AUTOEFI_HEADER 1
+
+
+#ifdef GRUB_MACHINE_EFI
+# include <grub/efi/efi.h>
+# define grub_autoefi_get_memory_map grub_efi_get_memory_map
+# define grub_autoefi_finish_boot_services grub_efi_finish_boot_services
+# define grub_autoefi_exit_boot_services grub_efi_exit_boot_services
+# define grub_autoefi_system_table grub_efi_system_table
+# define grub_autoefi_mmap_iterate grub_machine_mmap_iterate
+# define grub_autoefi_set_virtual_address_map grub_efi_set_virtual_address_map
+static inline grub_err_t grub_autoefi_prepare (void)
+{
+ return GRUB_ERR_NONE;
+};
+# define SYSTEM_TABLE_SIZEOF(x) (sizeof(grub_efi_system_table->x))
+# define SYSTEM_TABLE_VAR(x) ((void *)&(grub_efi_system_table->x))
+# define SYSTEM_TABLE_PTR(x) ((void *)(grub_efi_system_table->x))
+# define SIZEOF_OF_UINTN sizeof (grub_efi_uintn_t)
+# define SYSTEM_TABLE(x) (grub_efi_system_table->x)
+# define grub_autoefi_finish_boot_services grub_efi_finish_boot_services
+# define EFI_PRESENT 1
+#else
+# include <grub/efiemu/efiemu.h>
+# define grub_autoefi_get_memory_map grub_efiemu_get_memory_map
+# define grub_autoefi_finish_boot_services grub_efiemu_finish_boot_services
+# define grub_autoefi_exit_boot_services grub_efiemu_exit_boot_services
+# define grub_autoefi_system_table grub_efiemu_system_table
+# define grub_autoefi_mmap_iterate grub_efiemu_mmap_iterate
+# define grub_autoefi_prepare grub_efiemu_prepare
+# define grub_autoefi_set_virtual_address_map grub_efiemu_set_virtual_address_map
+# define SYSTEM_TABLE_SIZEOF GRUB_EFIEMU_SYSTEM_TABLE_SIZEOF
+# define SYSTEM_TABLE_VAR GRUB_EFIEMU_SYSTEM_TABLE_VAR
+# define SYSTEM_TABLE_PTR GRUB_EFIEMU_SYSTEM_TABLE_PTR
+# define SIZEOF_OF_UINTN GRUB_EFIEMU_SIZEOF_OF_UINTN
+# define SYSTEM_TABLE GRUB_EFIEMU_SYSTEM_TABLE
+# define grub_efi_allocate_fixed(x,y) (x)
+# define grub_efi_free_pages(x,y) GRUB_EFI_SUCCESS
+# define grub_autoefi_finish_boot_services grub_efiemu_finish_boot_services
+# define EFI_PRESENT 1
+#endif
+
+#endif
diff --git a/include/grub/backtrace.h b/include/grub/backtrace.h
new file mode 100644
index 0000000..3955197
--- /dev/null
+++ b/include/grub/backtrace.h
@@ -0,0 +1,26 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_BACKTRACE_HEADER
+#define GRUB_BACKTRACE_HEADER 1
+
+void grub_backtrace (void);
+void grub_backtrace_pointer (void *ptr);
+void grub_backtrace_print_address (void *addr);
+
+#endif
diff --git a/include/grub/bitmap.h b/include/grub/bitmap.h
new file mode 100644
index 0000000..5728f8c
--- /dev/null
+++ b/include/grub/bitmap.h
@@ -0,0 +1,87 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2006,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_BITMAP_HEADER
+#define GRUB_BITMAP_HEADER 1
+
+#include <grub/err.h>
+#include <grub/symbol.h>
+#include <grub/types.h>
+#include <grub/video.h>
+
+struct grub_video_bitmap
+{
+ /* Bitmap format description. */
+ struct grub_video_mode_info mode_info;
+
+ /* Pointer to bitmap data formatted according to mode_info. */
+ void *data;
+};
+
+struct grub_video_bitmap_reader
+{
+ /* File extension for this bitmap type (including dot). */
+ const char *extension;
+
+ /* Reader function to load bitmap. */
+ grub_err_t (*reader) (struct grub_video_bitmap **bitmap,
+ const char *filename);
+
+ /* Next reader. */
+ struct grub_video_bitmap_reader *next;
+};
+typedef struct grub_video_bitmap_reader *grub_video_bitmap_reader_t;
+
+void EXPORT_FUNC (grub_video_bitmap_reader_register) (grub_video_bitmap_reader_t reader);
+void EXPORT_FUNC (grub_video_bitmap_reader_unregister) (grub_video_bitmap_reader_t reader);
+
+grub_err_t EXPORT_FUNC (grub_video_bitmap_create) (struct grub_video_bitmap **bitmap,
+ unsigned int width, unsigned int height,
+ enum grub_video_blit_format blit_format);
+
+grub_err_t EXPORT_FUNC (grub_video_bitmap_destroy) (struct grub_video_bitmap *bitmap);
+
+grub_err_t EXPORT_FUNC (grub_video_bitmap_load) (struct grub_video_bitmap **bitmap,
+ const char *filename);
+
+/* Return bitmap width. */
+static inline unsigned int
+grub_video_bitmap_get_width (struct grub_video_bitmap *bitmap)
+{
+ if (!bitmap)
+ return 0;
+
+ return bitmap->mode_info.width;
+}
+
+/* Return bitmap height. */
+static inline unsigned int
+grub_video_bitmap_get_height (struct grub_video_bitmap *bitmap)
+{
+ if (!bitmap)
+ return 0;
+
+ return bitmap->mode_info.height;
+}
+
+void EXPORT_FUNC (grub_video_bitmap_get_mode_info) (struct grub_video_bitmap *bitmap,
+ struct grub_video_mode_info *mode_info);
+
+void *EXPORT_FUNC (grub_video_bitmap_get_data) (struct grub_video_bitmap *bitmap);
+
+#endif /* ! GRUB_BITMAP_HEADER */
diff --git a/include/grub/bitmap_scale.h b/include/grub/bitmap_scale.h
new file mode 100644
index 0000000..927a7cb
--- /dev/null
+++ b/include/grub/bitmap_scale.h
@@ -0,0 +1,85 @@
+/* bitmap_scale.h - Bitmap scaling functions. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_BITMAP_SCALE_HEADER
+#define GRUB_BITMAP_SCALE_HEADER 1
+
+#include <grub/err.h>
+#include <grub/types.h>
+#include <grub/bitmap_scale.h>
+
+enum grub_video_bitmap_scale_method
+{
+ /* Choose the fastest interpolation algorithm. */
+ GRUB_VIDEO_BITMAP_SCALE_METHOD_FASTEST,
+ /* Choose the highest quality interpolation algorithm. */
+ GRUB_VIDEO_BITMAP_SCALE_METHOD_BEST,
+
+ /* Specific algorithms: */
+ /* Nearest neighbor interpolation. */
+ GRUB_VIDEO_BITMAP_SCALE_METHOD_NEAREST,
+ /* Bilinear interpolation. */
+ GRUB_VIDEO_BITMAP_SCALE_METHOD_BILINEAR
+};
+
+typedef enum grub_video_bitmap_selection_method
+{
+ GRUB_VIDEO_BITMAP_SELECTION_METHOD_STRETCH,
+ GRUB_VIDEO_BITMAP_SELECTION_METHOD_CROP,
+ GRUB_VIDEO_BITMAP_SELECTION_METHOD_PADDING,
+ GRUB_VIDEO_BITMAP_SELECTION_METHOD_FITWIDTH,
+ GRUB_VIDEO_BITMAP_SELECTION_METHOD_FITHEIGHT
+} grub_video_bitmap_selection_method_t;
+
+typedef enum grub_video_bitmap_v_align
+{
+ GRUB_VIDEO_BITMAP_V_ALIGN_TOP,
+ GRUB_VIDEO_BITMAP_V_ALIGN_CENTER,
+ GRUB_VIDEO_BITMAP_V_ALIGN_BOTTOM
+} grub_video_bitmap_v_align_t;
+
+typedef enum grub_video_bitmap_h_align
+{
+ GRUB_VIDEO_BITMAP_H_ALIGN_LEFT,
+ GRUB_VIDEO_BITMAP_H_ALIGN_CENTER,
+ GRUB_VIDEO_BITMAP_H_ALIGN_RIGHT
+} grub_video_bitmap_h_align_t;
+
+grub_err_t
+EXPORT_FUNC (grub_video_bitmap_create_scaled) (struct grub_video_bitmap **dst,
+ int dst_width, int dst_height,
+ struct grub_video_bitmap *src,
+ enum
+ grub_video_bitmap_scale_method
+ scale_method);
+
+grub_err_t
+EXPORT_FUNC (grub_video_bitmap_scale_proportional)
+ (struct grub_video_bitmap **dst,
+ int dst_width, int dst_height,
+ struct grub_video_bitmap *src,
+ enum grub_video_bitmap_scale_method
+ scale_method,
+ grub_video_bitmap_selection_method_t
+ selection_method,
+ grub_video_bitmap_v_align_t v_align,
+ grub_video_bitmap_h_align_t h_align);
+
+
+#endif /* ! GRUB_BITMAP_SCALE_HEADER */
diff --git a/include/grub/boottime.h b/include/grub/boottime.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/include/grub/boottime.h
diff --git a/include/grub/bsdlabel.h b/include/grub/bsdlabel.h
new file mode 100644
index 0000000..83e7b8b
--- /dev/null
+++ b/include/grub/bsdlabel.h
@@ -0,0 +1,106 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 1999,2000,2001,2002,2004,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_BSDLABEL_PARTITION_HEADER
+#define GRUB_BSDLABEL_PARTITION_HEADER 1
+
+/* Constants for BSD disk label. */
+#define GRUB_PC_PARTITION_BSD_LABEL_SECTOR 1
+#define GRUB_PC_PARTITION_BSD_LABEL_MAGIC 0x82564557
+
+/* BSD partition types. */
+enum
+ {
+ GRUB_PC_PARTITION_BSD_TYPE_UNUSED = 0,
+ GRUB_PC_PARTITION_BSD_TYPE_SWAP = 1,
+ GRUB_PC_PARTITION_BSD_TYPE_V6 = 2,
+ GRUB_PC_PARTITION_BSD_TYPE_V7 = 3,
+ GRUB_PC_PARTITION_BSD_TYPE_SYSV = 4,
+ GRUB_PC_PARTITION_BSD_TYPE_V71K = 5,
+ GRUB_PC_PARTITION_BSD_TYPE_V8 = 6,
+ GRUB_PC_PARTITION_BSD_TYPE_BSDFFS = 7,
+ GRUB_PC_PARTITION_BSD_TYPE_MSDOS = 8,
+ GRUB_PC_PARTITION_BSD_TYPE_BSDLFS = 9,
+ GRUB_PC_PARTITION_BSD_TYPE_OTHER = 10,
+ GRUB_PC_PARTITION_BSD_TYPE_HPFS = 11,
+ GRUB_PC_PARTITION_BSD_TYPE_ISO9660 = 12,
+ GRUB_PC_PARTITION_BSD_TYPE_BOOT = 13
+ };
+
+/* FreeBSD-specific types. */
+enum
+ {
+ GRUB_PC_PARTITION_FREEBSD_TYPE_VINUM = 14,
+ GRUB_PC_PARTITION_FREEBSD_TYPE_RAID = 15,
+ GRUB_PC_PARTITION_FREEBSD_TYPE_JFS2 = 21
+ };
+
+/* NetBSD-specific types. */
+enum
+ {
+ GRUB_PC_PARTITION_NETBSD_TYPE_ADOS = 14,
+ GRUB_PC_PARTITION_NETBSD_TYPE_HFS = 15,
+ GRUB_PC_PARTITION_NETBSD_TYPE_FILECORE = 16,
+ GRUB_PC_PARTITION_NETBSD_TYPE_EXT2FS = 17,
+ GRUB_PC_PARTITION_NETBSD_TYPE_NTFS = 18,
+ GRUB_PC_PARTITION_NETBSD_TYPE_RAID = 19,
+ GRUB_PC_PARTITION_NETBSD_TYPE_CCD = 20,
+ GRUB_PC_PARTITION_NETBSD_TYPE_JFS2 = 21,
+ GRUB_PC_PARTITION_NETBSD_TYPE_APPLEUFS = 22
+ };
+
+/* OpenBSD-specific types. */
+enum
+ {
+ GRUB_PC_PARTITION_OPENBSD_TYPE_ADOS = 14,
+ GRUB_PC_PARTITION_OPENBSD_TYPE_HFS = 15,
+ GRUB_PC_PARTITION_OPENBSD_TYPE_FILECORE = 16,
+ GRUB_PC_PARTITION_OPENBSD_TYPE_EXT2FS = 17,
+ GRUB_PC_PARTITION_OPENBSD_TYPE_NTFS = 18,
+ GRUB_PC_PARTITION_OPENBSD_TYPE_RAID = 19
+ };
+
+#define GRUB_PC_PARTITION_BSD_LABEL_WHOLE_DISK_PARTITION 2
+
+/* The BSD partition entry. */
+struct grub_partition_bsd_entry
+{
+ grub_uint32_t size;
+ grub_uint32_t offset;
+ grub_uint32_t fragment_size;
+ grub_uint8_t fs_type;
+ grub_uint8_t fs_fragments;
+ grub_uint16_t fs_cylinders;
+} GRUB_PACKED;
+
+/* The BSD disk label. Only define members useful for GRUB. */
+struct grub_partition_bsd_disk_label
+{
+ grub_uint32_t magic;
+ grub_uint16_t type;
+ grub_uint8_t unused1[18];
+ grub_uint8_t packname[16];
+ grub_uint8_t unused2[92];
+ grub_uint32_t magic2;
+ grub_uint16_t checksum;
+ grub_uint16_t num_partitions;
+ grub_uint32_t boot_size;
+ grub_uint32_t superblock_size;
+} GRUB_PACKED;
+
+#endif /* ! GRUB_PC_PARTITION_HEADER */
diff --git a/include/grub/btrfs.h b/include/grub/btrfs.h
new file mode 100644
index 0000000..9d93fb6
--- /dev/null
+++ b/include/grub/btrfs.h
@@ -0,0 +1,71 @@
+/* btrfs.c - B-tree file system. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010,2011,2012,2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_BTRFS_H
+#define GRUB_BTRFS_H 1
+
+enum
+ {
+ GRUB_BTRFS_ITEM_TYPE_INODE_ITEM = 0x01,
+ GRUB_BTRFS_ITEM_TYPE_INODE_REF = 0x0c,
+ GRUB_BTRFS_ITEM_TYPE_DIR_ITEM = 0x54,
+ GRUB_BTRFS_ITEM_TYPE_EXTENT_ITEM = 0x6c,
+ GRUB_BTRFS_ITEM_TYPE_ROOT_ITEM = 0x84,
+ GRUB_BTRFS_ITEM_TYPE_ROOT_BACKREF = 0x90,
+ GRUB_BTRFS_ITEM_TYPE_DEVICE = 0xd8,
+ GRUB_BTRFS_ITEM_TYPE_CHUNK = 0xe4
+ };
+
+enum
+ {
+ GRUB_BTRFS_ROOT_VOL_OBJECTID = 5,
+ GRUB_BTRFS_TREE_ROOT_OBJECTID = 0x100,
+ };
+
+struct grub_btrfs_root_item
+{
+ grub_uint8_t dummy[0xb0];
+ grub_uint64_t tree;
+ grub_uint64_t inode;
+};
+
+struct grub_btrfs_key
+{
+ grub_uint64_t object_id;
+ grub_uint8_t type;
+ grub_uint64_t offset;
+} GRUB_PACKED;
+
+
+struct grub_btrfs_root_backref
+{
+ grub_uint64_t inode_id;
+ grub_uint64_t seqnr;
+ grub_uint16_t n;
+ char name[0];
+};
+
+struct grub_btrfs_inode_ref
+{
+ grub_uint64_t idxid;
+ grub_uint16_t n;
+ char name[0];
+};
+
+#endif
diff --git a/include/grub/buffer.h b/include/grub/buffer.h
new file mode 100644
index 0000000..bb5e3cd
--- /dev/null
+++ b/include/grub/buffer.h
@@ -0,0 +1,144 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2021 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_BUFFER_H
+#define GRUB_BUFFER_H 1
+
+#include <grub/err.h>
+#include <grub/misc.h>
+#include <grub/mm.h>
+#include <grub/safemath.h>
+#include <grub/types.h>
+
+struct grub_buffer
+{
+ grub_uint8_t *data;
+ grub_size_t sz;
+ grub_size_t pos;
+ grub_size_t used;
+};
+
+/*
+ * grub_buffer_t represents a simple variable sized byte buffer with
+ * read and write cursors. It currently only implements
+ * functionality required by the only user in GRUB (append byte[s],
+ * peeking data at a specified position and updating the read cursor.
+ * Some things that this doesn't do yet are:
+ * - Reading a portion of the buffer by copying data from the current
+ * read position in to a caller supplied destination buffer and then
+ * automatically updating the read cursor.
+ * - Dropping the read part at the start of the buffer when an append
+ * requires more space.
+ */
+typedef struct grub_buffer *grub_buffer_t;
+
+/* Allocate a new buffer with the specified initial size. */
+extern grub_buffer_t grub_buffer_new (grub_size_t sz);
+
+/* Free the buffer and its resources. */
+extern void grub_buffer_free (grub_buffer_t buf);
+
+/* Return the number of unread bytes in this buffer. */
+static inline grub_size_t
+grub_buffer_get_unread_bytes (grub_buffer_t buf)
+{
+ return buf->used - buf->pos;
+}
+
+/*
+ * Ensure that the buffer size is at least the requested
+ * number of bytes.
+ */
+extern grub_err_t grub_buffer_ensure_space (grub_buffer_t buf, grub_size_t req);
+
+/*
+ * Append the specified number of bytes from the supplied
+ * data to the buffer.
+ */
+static inline grub_err_t
+grub_buffer_append_data (grub_buffer_t buf, const void *data, grub_size_t len)
+{
+ grub_size_t req;
+
+ if (grub_add (buf->used, len, &req))
+ return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected"));
+
+ if (grub_buffer_ensure_space (buf, req) != GRUB_ERR_NONE)
+ return grub_errno;
+
+ grub_memcpy (&buf->data[buf->used], data, len);
+ buf->used = req;
+
+ return GRUB_ERR_NONE;
+}
+
+/* Append the supplied character to the buffer. */
+static inline grub_err_t
+grub_buffer_append_char (grub_buffer_t buf, char c)
+{
+ return grub_buffer_append_data (buf, &c, 1);
+}
+
+/*
+ * Forget and return the underlying data buffer. The caller
+ * becomes the owner of this buffer, and must free it when it
+ * is no longer required.
+ */
+extern void *grub_buffer_take_data (grub_buffer_t buf);
+
+/* Reset this buffer. Note that this does not deallocate any resources. */
+void grub_buffer_reset (grub_buffer_t buf);
+
+/*
+ * Return a pointer to the underlying data buffer at the specified
+ * offset from the current read position. Note that this pointer may
+ * become invalid if the buffer is mutated further.
+ */
+static inline void *
+grub_buffer_peek_data_at (grub_buffer_t buf, grub_size_t off)
+{
+ if (grub_add (buf->pos, off, &off))
+ {
+ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected"));
+ return NULL;
+ }
+
+ if (off >= buf->used)
+ {
+ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("peek out of range"));
+ return NULL;
+ }
+
+ return &buf->data[off];
+}
+
+/*
+ * Return a pointer to the underlying data buffer at the current
+ * read position. Note that this pointer may become invalid if the
+ * buffer is mutated further.
+ */
+static inline void *
+grub_buffer_peek_data (grub_buffer_t buf)
+{
+ return grub_buffer_peek_data_at (buf, 0);
+}
+
+/* Advance the read position by the specified number of bytes. */
+extern grub_err_t grub_buffer_advance_read_pos (grub_buffer_t buf, grub_size_t n);
+
+#endif /* GRUB_BUFFER_H */
diff --git a/include/grub/bufio.h b/include/grub/bufio.h
new file mode 100644
index 0000000..0ff72d1
--- /dev/null
+++ b/include/grub/bufio.h
@@ -0,0 +1,30 @@
+/* bufio.h - prototypes for bufio */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_BUFIO_H
+#define GRUB_BUFIO_H 1
+
+#include <grub/file.h>
+
+grub_file_t EXPORT_FUNC (grub_bufio_open) (grub_file_t io, grub_size_t size);
+grub_file_t EXPORT_FUNC (grub_buffile_open) (const char *name,
+ enum grub_file_type type,
+ grub_size_t size);
+
+#endif /* ! GRUB_BUFIO_H */
diff --git a/include/grub/cache.h b/include/grub/cache.h
new file mode 100644
index 0000000..7aa8d79
--- /dev/null
+++ b/include/grub/cache.h
@@ -0,0 +1,56 @@
+/* cache.h - Flush the processor's cache. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2004,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_CACHE_H
+#define GRUB_CACHE_H 1
+
+#include <grub/symbol.h>
+#include <grub/types.h>
+
+#if defined (__i386__) || defined (__x86_64__)
+static inline void
+grub_arch_sync_caches (void *address __attribute__ ((unused)),
+ grub_size_t len __attribute__ ((unused)))
+{
+}
+#else
+void EXPORT_FUNC(grub_arch_sync_caches) (void *address, grub_size_t len);
+#endif
+
+#ifndef GRUB_MACHINE_EMU
+#if defined (__aarch64__) || defined (__ia64__) || defined (__powerpc__) || \
+ defined (__sparc__)
+
+#elif defined (__i386__) || defined (__x86_64__)
+static inline void
+grub_arch_sync_dma_caches (volatile void *address __attribute__ ((unused)),
+ grub_size_t len __attribute__ ((unused)))
+{
+}
+#else
+void EXPORT_FUNC(grub_arch_sync_dma_caches) (volatile void *address, grub_size_t len);
+#endif
+#endif
+
+#ifdef __arm__
+void
+grub_arm_cache_enable (void);
+#endif
+
+#endif /* ! GRUB_CACHE_HEADER */
diff --git a/include/grub/cbfs_core.h b/include/grub/cbfs_core.h
new file mode 100644
index 0000000..98112fb
--- /dev/null
+++ b/include/grub/cbfs_core.h
@@ -0,0 +1,178 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2008 Jordan Crouse <jordan@cosmicpenguin.net>
+ * Copyright (C) 2012 Google, Inc.
+ * Copyright (C) 2013 The Chromium OS Authors. All rights reserved.
+ *
+ * This file is dual-licensed. You can choose between:
+ * - The GNU GPL, version 2, as published by the Free Software Foundation
+ * - The revised BSD license (without advertising clause)
+ *
+ * ---------------------------------------------------------------------------
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
+ * ---------------------------------------------------------------------------
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ---------------------------------------------------------------------------
+ */
+
+#ifndef _CBFS_CORE_H_
+#define _CBFS_CORE_H_
+
+#include <grub/types.h>
+
+/** These are standard values for the known compression
+ alogrithms that coreboot knows about for stages and
+ payloads. Of course, other CBFS users can use whatever
+ values they want, as long as they understand them. */
+
+#define CBFS_COMPRESS_NONE 0
+#define CBFS_COMPRESS_LZMA 1
+
+/** These are standard component types for well known
+ components (i.e - those that coreboot needs to consume.
+ Users are welcome to use any other value for their
+ components */
+
+#define CBFS_TYPE_STAGE 0x10
+#define CBFS_TYPE_PAYLOAD 0x20
+#define CBFS_TYPE_OPTIONROM 0x30
+#define CBFS_TYPE_BOOTSPLASH 0x40
+#define CBFS_TYPE_RAW 0x50
+#define CBFS_TYPE_VSA 0x51
+#define CBFS_TYPE_MBI 0x52
+#define CBFS_TYPE_MICROCODE 0x53
+#define CBFS_COMPONENT_CMOS_DEFAULT 0xaa
+#define CBFS_COMPONENT_CMOS_LAYOUT 0x01aa
+
+#define CBFS_HEADER_MAGIC 0x4F524243
+#define CBFS_HEADER_VERSION1 0x31313131
+#define CBFS_HEADER_VERSION2 0x31313132
+#define CBFS_HEADER_VERSION CBFS_HEADER_VERSION2
+
+#define CBFS_HEADER_INVALID_ADDRESS ((void*)(0xffffffff))
+
+/** this is the master cbfs header - it need to be located somewhere available
+ to bootblock (to load romstage). Where it actually lives is up to coreboot.
+ On x86, a pointer to this header will live at 0xFFFFFFFC.
+ For other platforms, you need to define CONFIG_CBFS_HEADER_ROM_OFFSET */
+
+struct cbfs_header {
+ grub_uint32_t magic;
+ grub_uint32_t version;
+ grub_uint32_t romsize;
+ grub_uint32_t bootblocksize;
+ grub_uint32_t align;
+ grub_uint32_t offset;
+ grub_uint32_t architecture;
+ grub_uint32_t pad[1];
+} GRUB_PACKED;
+
+/* "Unknown" refers to CBFS headers version 1,
+ * before the architecture was defined (i.e., x86 only).
+ */
+#define CBFS_ARCHITECTURE_UNKNOWN 0xFFFFFFFF
+#define CBFS_ARCHITECTURE_X86 0x00000001
+#define CBFS_ARCHITECTURE_ARMV7 0x00000010
+
+/** This is a component header - every entry in the CBFS
+ will have this header.
+
+ This is how the component is arranged in the ROM:
+
+ -------------- <- 0
+ component header
+ -------------- <- sizeof(struct component)
+ component name
+ -------------- <- offset
+ data
+ ...
+ -------------- <- offset + len
+*/
+
+#define CBFS_FILE_MAGIC "LARCHIVE"
+
+struct cbfs_file {
+ char magic[8];
+ grub_uint32_t len;
+ grub_uint32_t type;
+ grub_uint32_t checksum;
+ grub_uint32_t offset;
+} GRUB_PACKED;
+
+/*** Component sub-headers ***/
+
+/* Following are component sub-headers for the "standard"
+ component types */
+
+/** This is the sub-header for stage components. Stages are
+ loaded by coreboot during the normal boot process */
+
+struct cbfs_stage {
+ grub_uint32_t compression; /** Compression type */
+ grub_uint64_t entry; /** entry point */
+ grub_uint64_t load; /** Where to load in memory */
+ grub_uint32_t len; /** length of data to load */
+ grub_uint32_t memlen; /** total length of object in memory */
+} GRUB_PACKED;
+
+/** this is the sub-header for payload components. Payloads
+ are loaded by coreboot at the end of the boot process */
+
+struct cbfs_payload_segment {
+ grub_uint32_t type;
+ grub_uint32_t compression;
+ grub_uint32_t offset;
+ grub_uint64_t load_addr;
+ grub_uint32_t len;
+ grub_uint32_t mem_len;
+} GRUB_PACKED;
+
+struct cbfs_payload {
+ struct cbfs_payload_segment segments;
+};
+
+#define PAYLOAD_SEGMENT_CODE 0x45444F43
+#define PAYLOAD_SEGMENT_DATA 0x41544144
+#define PAYLOAD_SEGMENT_BSS 0x20535342
+#define PAYLOAD_SEGMENT_PARAMS 0x41524150
+#define PAYLOAD_SEGMENT_ENTRY 0x52544E45
+
+struct cbfs_optionrom {
+ grub_uint32_t compression;
+ grub_uint32_t len;
+} GRUB_PACKED;
+
+#endif
diff --git a/include/grub/charset.h b/include/grub/charset.h
new file mode 100644
index 0000000..d14faea
--- /dev/null
+++ b/include/grub/charset.h
@@ -0,0 +1,323 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_CHARSET_HEADER
+#define GRUB_CHARSET_HEADER 1
+
+#include <grub/types.h>
+
+#define GRUB_UINT8_1_LEADINGBIT 0x80
+#define GRUB_UINT8_2_LEADINGBITS 0xc0
+#define GRUB_UINT8_3_LEADINGBITS 0xe0
+#define GRUB_UINT8_4_LEADINGBITS 0xf0
+#define GRUB_UINT8_5_LEADINGBITS 0xf8
+#define GRUB_UINT8_6_LEADINGBITS 0xfc
+#define GRUB_UINT8_7_LEADINGBITS 0xfe
+
+#define GRUB_UINT8_1_TRAILINGBIT 0x01
+#define GRUB_UINT8_2_TRAILINGBITS 0x03
+#define GRUB_UINT8_3_TRAILINGBITS 0x07
+#define GRUB_UINT8_4_TRAILINGBITS 0x0f
+#define GRUB_UINT8_5_TRAILINGBITS 0x1f
+#define GRUB_UINT8_6_TRAILINGBITS 0x3f
+
+#define GRUB_MAX_UTF8_PER_UTF16 4
+/* You need at least one UTF-8 byte to have one UTF-16 word.
+ You need at least three UTF-8 bytes to have 2 UTF-16 words (surrogate pairs).
+ */
+#define GRUB_MAX_UTF16_PER_UTF8 1
+#define GRUB_MAX_UTF8_PER_CODEPOINT 4
+
+#define GRUB_UCS2_LIMIT 0x10000
+#define GRUB_UTF16_UPPER_SURROGATE(code) \
+ (0xD800 | ((((code) - GRUB_UCS2_LIMIT) >> 10) & 0x3ff))
+#define GRUB_UTF16_LOWER_SURROGATE(code) \
+ (0xDC00 | (((code) - GRUB_UCS2_LIMIT) & 0x3ff))
+
+/* Process one character from UTF8 sequence.
+ At beginning set *code = 0, *count = 0. Returns 0 on failure and
+ 1 on success. *count holds the number of trailing bytes. */
+static inline int
+grub_utf8_process (grub_uint8_t c, grub_uint32_t *code, int *count)
+{
+ if (*count)
+ {
+ if ((c & GRUB_UINT8_2_LEADINGBITS) != GRUB_UINT8_1_LEADINGBIT)
+ {
+ *count = 0;
+ /* invalid */
+ return 0;
+ }
+ else
+ {
+ *code <<= 6;
+ *code |= (c & GRUB_UINT8_6_TRAILINGBITS);
+ (*count)--;
+ /* Overlong. */
+ if ((*count == 1 && *code <= 0x1f)
+ || (*count == 2 && *code <= 0xf))
+ {
+ *code = 0;
+ *count = 0;
+ return 0;
+ }
+ return 1;
+ }
+ }
+
+ if ((c & GRUB_UINT8_1_LEADINGBIT) == 0)
+ {
+ *code = c;
+ return 1;
+ }
+ if ((c & GRUB_UINT8_3_LEADINGBITS) == GRUB_UINT8_2_LEADINGBITS)
+ {
+ *count = 1;
+ *code = c & GRUB_UINT8_5_TRAILINGBITS;
+ /* Overlong */
+ if (*code <= 1)
+ {
+ *count = 0;
+ *code = 0;
+ return 0;
+ }
+ return 1;
+ }
+ if ((c & GRUB_UINT8_4_LEADINGBITS) == GRUB_UINT8_3_LEADINGBITS)
+ {
+ *count = 2;
+ *code = c & GRUB_UINT8_4_TRAILINGBITS;
+ return 1;
+ }
+ if ((c & GRUB_UINT8_5_LEADINGBITS) == GRUB_UINT8_4_LEADINGBITS)
+ {
+ *count = 3;
+ *code = c & GRUB_UINT8_3_TRAILINGBITS;
+ return 1;
+ }
+ return 0;
+}
+
+
+/* Convert a (possibly null-terminated) UTF-8 string of at most SRCSIZE
+ bytes (if SRCSIZE is -1, it is ignored) in length to a UTF-16 string.
+ Return the number of characters converted. DEST must be able to hold
+ at least DESTSIZE characters. If an invalid sequence is found, return -1.
+ If SRCEND is not NULL, then *SRCEND is set to the next byte after the
+ last byte used in SRC. */
+static inline grub_size_t
+grub_utf8_to_utf16 (grub_uint16_t *dest, grub_size_t destsize,
+ const grub_uint8_t *src, grub_size_t srcsize,
+ const grub_uint8_t **srcend)
+{
+ grub_uint16_t *p = dest;
+ int count = 0;
+ grub_uint32_t code = 0;
+
+ if (srcend)
+ *srcend = src;
+
+ while (srcsize && destsize)
+ {
+ int was_count = count;
+ if (srcsize != (grub_size_t)-1)
+ srcsize--;
+ if (!grub_utf8_process (*src++, &code, &count))
+ {
+ code = '?';
+ count = 0;
+ /* Character c may be valid, don't eat it. */
+ if (was_count)
+ src--;
+ }
+ if (count != 0)
+ continue;
+ if (code == 0)
+ break;
+ if (destsize < 2 && code >= GRUB_UCS2_LIMIT)
+ break;
+ if (code >= GRUB_UCS2_LIMIT)
+ {
+ *p++ = GRUB_UTF16_UPPER_SURROGATE (code);
+ *p++ = GRUB_UTF16_LOWER_SURROGATE (code);
+ destsize -= 2;
+ }
+ else
+ {
+ *p++ = code;
+ destsize--;
+ }
+ }
+
+ if (srcend)
+ *srcend = src;
+ return p - dest;
+}
+
+/* Determine the last position where the UTF-8 string [beg, end) can
+ be safely cut. */
+static inline grub_size_t
+grub_getend (const char *beg, const char *end)
+{
+ const char *ptr;
+ for (ptr = end - 1; ptr >= beg; ptr--)
+ if ((*ptr & GRUB_UINT8_2_LEADINGBITS) != GRUB_UINT8_1_LEADINGBIT)
+ break;
+ if (ptr < beg)
+ return 0;
+ if ((*ptr & GRUB_UINT8_1_LEADINGBIT) == 0)
+ return ptr + 1 - beg;
+ if ((*ptr & GRUB_UINT8_3_LEADINGBITS) == GRUB_UINT8_2_LEADINGBITS
+ && ptr + 2 <= end)
+ return ptr + 2 - beg;
+ if ((*ptr & GRUB_UINT8_4_LEADINGBITS) == GRUB_UINT8_3_LEADINGBITS
+ && ptr + 3 <= end)
+ return ptr + 3 - beg;
+ if ((*ptr & GRUB_UINT8_5_LEADINGBITS) == GRUB_UINT8_4_LEADINGBITS
+ && ptr + 4 <= end)
+ return ptr + 4 - beg;
+ /* Invalid character or incomplete. Cut before it. */
+ return ptr - beg;
+}
+
+/* Convert UTF-16 to UTF-8. */
+static inline grub_uint8_t *
+grub_utf16_to_utf8 (grub_uint8_t *dest, const grub_uint16_t *src,
+ grub_size_t size)
+{
+ grub_uint32_t code_high = 0;
+
+ while (size--)
+ {
+ grub_uint32_t code = *src++;
+
+ if (code_high)
+ {
+ if (code >= 0xDC00 && code <= 0xDFFF)
+ {
+ /* Surrogate pair. */
+ code = ((code_high - 0xD800) << 10) + (code - 0xDC00) + 0x10000;
+
+ *dest++ = (code >> 18) | 0xF0;
+ *dest++ = ((code >> 12) & 0x3F) | 0x80;
+ *dest++ = ((code >> 6) & 0x3F) | 0x80;
+ *dest++ = (code & 0x3F) | 0x80;
+ }
+ else
+ {
+ /* Error... */
+ *dest++ = '?';
+ /* *src may be valid. Don't eat it. */
+ src--;
+ }
+
+ code_high = 0;
+ }
+ else
+ {
+ if (code <= 0x007F)
+ *dest++ = code;
+ else if (code <= 0x07FF)
+ {
+ *dest++ = (code >> 6) | 0xC0;
+ *dest++ = (code & 0x3F) | 0x80;
+ }
+ else if (code >= 0xD800 && code <= 0xDBFF)
+ {
+ code_high = code;
+ continue;
+ }
+ else if (code >= 0xDC00 && code <= 0xDFFF)
+ {
+ /* Error... */
+ *dest++ = '?';
+ }
+ else if (code < 0x10000)
+ {
+ *dest++ = (code >> 12) | 0xE0;
+ *dest++ = ((code >> 6) & 0x3F) | 0x80;
+ *dest++ = (code & 0x3F) | 0x80;
+ }
+ else
+ {
+ *dest++ = (code >> 18) | 0xF0;
+ *dest++ = ((code >> 12) & 0x3F) | 0x80;
+ *dest++ = ((code >> 6) & 0x3F) | 0x80;
+ *dest++ = (code & 0x3F) | 0x80;
+ }
+ }
+ }
+
+ return dest;
+}
+
+#define GRUB_MAX_UTF8_PER_LATIN1 2
+
+/* Convert Latin1 to UTF-8. */
+static inline grub_uint8_t *
+grub_latin1_to_utf8 (grub_uint8_t *dest, const grub_uint8_t *src,
+ grub_size_t size)
+{
+ while (size--)
+ {
+ if (!(*src & 0x80))
+ *dest++ = *src;
+ else
+ {
+ *dest++ = (*src >> 6) | 0xC0;
+ *dest++ = (*src & 0x3F) | 0x80;
+ }
+ src++;
+ }
+
+ return dest;
+}
+
+/* Convert UCS-4 to UTF-8. */
+char *grub_ucs4_to_utf8_alloc (const grub_uint32_t *src, grub_size_t size);
+
+int
+grub_is_valid_utf8 (const grub_uint8_t *src, grub_size_t srcsize);
+
+grub_ssize_t grub_utf8_to_ucs4_alloc (const char *msg,
+ grub_uint32_t **unicode_msg,
+ grub_uint32_t **last_position);
+
+/* Returns the number of bytes the string src would occupy is converted
+ to UTF-8, excluding \0. */
+grub_size_t
+grub_get_num_of_utf8_bytes (const grub_uint32_t *src, grub_size_t size);
+
+/* Converts UCS-4 to UTF-8. Returns the number of bytes effectively written
+ excluding the trailing \0. */
+grub_size_t
+grub_ucs4_to_utf8 (const grub_uint32_t *src, grub_size_t size,
+ grub_uint8_t *dest, grub_size_t destsize);
+grub_size_t grub_utf8_to_ucs4 (grub_uint32_t *dest, grub_size_t destsize,
+ const grub_uint8_t *src, grub_size_t srcsize,
+ const grub_uint8_t **srcend);
+/* Returns -2 if not enough space, -1 on invalid character. */
+grub_ssize_t
+grub_encode_utf8_character (grub_uint8_t *dest, grub_uint8_t *destend,
+ grub_uint32_t code);
+
+const grub_uint32_t *
+grub_unicode_get_comb_start (const grub_uint32_t *str,
+ const grub_uint32_t *cur);
+
+#endif
diff --git a/include/grub/cmos.h b/include/grub/cmos.h
new file mode 100644
index 0000000..56ccc71
--- /dev/null
+++ b/include/grub/cmos.h
@@ -0,0 +1,128 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008, 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_CMOS_H
+#define GRUB_CMOS_H 1
+
+#include <grub/types.h>
+#if !defined (__powerpc__) && !defined (__sparc__)
+#include <grub/cpu/io.h>
+#include <grub/cpu/cmos.h>
+#endif
+
+#define GRUB_CMOS_INDEX_SECOND 0
+#define GRUB_CMOS_INDEX_SECOND_ALARM 1
+#define GRUB_CMOS_INDEX_MINUTE 2
+#define GRUB_CMOS_INDEX_MINUTE_ALARM 3
+#define GRUB_CMOS_INDEX_HOUR 4
+#define GRUB_CMOS_INDEX_HOUR_ALARM 5
+#define GRUB_CMOS_INDEX_DAY_OF_WEEK 6
+#define GRUB_CMOS_INDEX_DAY_OF_MONTH 7
+#define GRUB_CMOS_INDEX_MONTH 8
+#define GRUB_CMOS_INDEX_YEAR 9
+
+#define GRUB_CMOS_INDEX_STATUS_A 0xA
+#define GRUB_CMOS_INDEX_STATUS_B 0xB
+#define GRUB_CMOS_INDEX_STATUS_C 0xC
+#define GRUB_CMOS_INDEX_STATUS_D 0xD
+
+#define GRUB_CMOS_STATUS_B_DAYLIGHT 1
+#define GRUB_CMOS_STATUS_B_24HOUR 2
+#define GRUB_CMOS_STATUS_B_BINARY 4
+
+static inline grub_uint8_t
+grub_bcd_to_num (grub_uint8_t a)
+{
+ return ((a >> 4) * 10 + (a & 0xF));
+}
+
+static inline grub_uint8_t
+grub_num_to_bcd (grub_uint8_t a)
+{
+ return (((a / 10) << 4) + (a % 10));
+}
+
+#if !defined (__powerpc__) && !defined (__sparc__)
+static inline grub_err_t
+grub_cmos_read (grub_uint8_t index, grub_uint8_t *val)
+{
+ if (index & 0x80)
+ {
+ grub_outb (index & 0x7f, GRUB_CMOS_ADDR_REG_HI);
+ *val = grub_inb (GRUB_CMOS_DATA_REG_HI);
+ }
+ else
+ {
+ grub_outb (index & 0x7f, GRUB_CMOS_ADDR_REG);
+ *val = grub_inb (GRUB_CMOS_DATA_REG);
+ }
+ return GRUB_ERR_NONE;
+}
+
+static inline grub_err_t
+grub_cmos_write (grub_uint8_t index, grub_uint8_t value)
+{
+ if (index & 0x80)
+ {
+ grub_outb (index & 0x7f, GRUB_CMOS_ADDR_REG_HI);
+ grub_outb (value, GRUB_CMOS_DATA_REG_HI);
+ }
+ else
+ {
+ grub_outb (index & 0x7f, GRUB_CMOS_ADDR_REG);
+ grub_outb (value, GRUB_CMOS_DATA_REG);
+ }
+ return GRUB_ERR_NONE;
+}
+#else
+grub_err_t grub_cmos_find_port (void);
+extern volatile grub_uint8_t *grub_cmos_port;
+
+static inline grub_err_t
+grub_cmos_read (grub_uint8_t index, grub_uint8_t *val)
+{
+ if (!grub_cmos_port)
+ {
+ grub_err_t err;
+ err = grub_cmos_find_port ();
+ if (err)
+ return err;
+ }
+ grub_cmos_port[((index & 0x80) >> 6) | 0] = index & 0x7f;
+ *val = grub_cmos_port[((index & 0x80) >> 6) | 1];
+ return GRUB_ERR_NONE;
+}
+
+static inline grub_err_t
+grub_cmos_write (grub_uint8_t index, grub_uint8_t val)
+{
+ if (!grub_cmos_port)
+ {
+ grub_err_t err;
+ err = grub_cmos_find_port ();
+ if (err)
+ return err;
+ }
+ grub_cmos_port[((index & 0x80) >> 6) | 0] = index;
+ grub_cmos_port[((index & 0x80) >> 6) | 1] = val;
+ return GRUB_ERR_NONE;
+}
+
+#endif
+
+#endif /* GRUB_CMOS_H */
diff --git a/include/grub/color.h b/include/grub/color.h
new file mode 100644
index 0000000..cb004a9
--- /dev/null
+++ b/include/grub/color.h
@@ -0,0 +1,30 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_VIDEO_COLOR_HEADER
+#define GRUB_VIDEO_COLOR_HEADER 1
+
+#include <grub/video.h>
+
+int grub_video_get_named_color (const char *name,
+ grub_video_rgba_color_t *color);
+
+grub_err_t grub_video_parse_color (const char *s,
+ grub_video_rgba_color_t *color);
+
+#endif
diff --git a/include/grub/command.h b/include/grub/command.h
new file mode 100644
index 0000000..2a6f7f8
--- /dev/null
+++ b/include/grub/command.h
@@ -0,0 +1,134 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_COMMAND_HEADER
+#define GRUB_COMMAND_HEADER 1
+
+#include <grub/symbol.h>
+#include <grub/err.h>
+#include <grub/list.h>
+#include <grub/misc.h>
+
+typedef enum grub_command_flags
+ {
+ /* This is an extended command. */
+ GRUB_COMMAND_FLAG_EXTCMD = 0x10,
+ /* This is an dynamic command. */
+ GRUB_COMMAND_FLAG_DYNCMD = 0x20,
+ /* This command accepts block arguments. */
+ GRUB_COMMAND_FLAG_BLOCKS = 0x40,
+ /* This command accepts unknown arguments as direct parameters. */
+ GRUB_COMMAND_ACCEPT_DASH = 0x80,
+ /* This command accepts only options preceding direct arguments. */
+ GRUB_COMMAND_OPTIONS_AT_START = 0x100,
+ /* Can be executed in an entries extractor. */
+ GRUB_COMMAND_FLAG_EXTRACTOR = 0x200
+ } grub_command_flags_t;
+
+struct grub_command;
+
+typedef grub_err_t (*grub_command_func_t) (struct grub_command *cmd,
+ int argc, char **argv);
+
+#define GRUB_COMMAND_PRIO_MASK 0xff
+#define GRUB_COMMAND_FLAG_ACTIVE 0x100
+
+/* The command description. */
+struct grub_command
+{
+ /* The next element. */
+ struct grub_command *next;
+ struct grub_command **prev;
+
+ /* The name. */
+ const char *name;
+
+ /* The priority. */
+ int prio;
+
+ /* The callback function. */
+ grub_command_func_t func;
+
+ /* The flags. */
+ grub_command_flags_t flags;
+
+ /* The summary of the command usage. */
+ const char *summary;
+
+ /* The description of the command. */
+ const char *description;
+
+ /* Arbitrary data. */
+ void *data;
+};
+typedef struct grub_command *grub_command_t;
+
+extern grub_command_t EXPORT_VAR(grub_command_list);
+
+grub_command_t
+EXPORT_FUNC(grub_register_command_prio) (const char *name,
+ grub_command_func_t func,
+ const char *summary,
+ const char *description,
+ int prio);
+grub_command_t
+EXPORT_FUNC(grub_register_command_lockdown) (const char *name,
+ grub_command_func_t func,
+ const char *summary,
+ const char *description);
+void EXPORT_FUNC(grub_unregister_command) (grub_command_t cmd);
+
+static inline grub_command_t
+grub_register_command (const char *name,
+ grub_command_func_t func,
+ const char *summary,
+ const char *description)
+{
+ return grub_register_command_prio (name, func, summary, description, 0);
+}
+
+static inline grub_command_t
+grub_register_command_p1 (const char *name,
+ grub_command_func_t func,
+ const char *summary,
+ const char *description)
+{
+ return grub_register_command_prio (name, func, summary, description, 1);
+}
+
+static inline grub_command_t
+grub_command_find (const char *name)
+{
+ return grub_named_list_find (GRUB_AS_NAMED_LIST (grub_command_list), name);
+}
+
+static inline grub_err_t
+grub_command_execute (const char *name, int argc, char **argv)
+{
+ grub_command_t cmd;
+
+ cmd = grub_command_find (name);
+ return (cmd) ? cmd->func (cmd, argc, argv) : GRUB_ERR_FILE_NOT_FOUND;
+}
+
+#define FOR_COMMANDS(var) FOR_LIST_ELEMENTS((var), grub_command_list)
+#define FOR_COMMANDS_SAFE(var, next) FOR_LIST_ELEMENTS_SAFE((var), (next), grub_command_list)
+
+void grub_register_core_commands (void);
+
+#endif /* ! GRUB_COMMAND_HEADER */
diff --git a/include/grub/compiler-rt-emu.h b/include/grub/compiler-rt-emu.h
new file mode 100644
index 0000000..fde620a
--- /dev/null
+++ b/include/grub/compiler-rt-emu.h
@@ -0,0 +1,265 @@
+/* compiler-rt-emu.h - prototypes for compiler helpers. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2003,2005,2006,2007,2008,2009,2010-2014 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_COMPILER_RT_HEADER
+#define GRUB_COMPILER_RT_HEADER 1
+
+#include <config-util.h>
+#include <grub/types.h>
+#include <grub/symbol.h>
+
+#ifdef HAVE___UDIVSI3
+grub_uint32_t
+EXPORT_FUNC (__udivsi3) (grub_uint32_t a, grub_uint32_t b);
+#endif
+
+#ifdef HAVE___UMODSI3
+grub_uint32_t
+EXPORT_FUNC (__umodsi3) (grub_uint32_t a, grub_uint32_t b);
+#endif
+
+#ifdef HAVE___DIVSI3
+grub_int32_t
+EXPORT_FUNC (__divsi3) (grub_int32_t a, grub_int32_t b);
+#endif
+
+#ifdef HAVE___MODSI3
+grub_int32_t
+EXPORT_FUNC (__modsi3) (grub_int32_t a, grub_int32_t b);
+#endif
+
+#ifdef HAVE___DIVDI3
+grub_int64_t
+EXPORT_FUNC (__divdi3) (grub_int64_t a, grub_int64_t b);
+#endif
+
+#ifdef HAVE___MODDI3
+grub_int64_t
+EXPORT_FUNC (__moddi3) (grub_int64_t a, grub_int64_t b);
+#endif
+
+#ifdef HAVE___UDIVDI3
+grub_uint64_t
+EXPORT_FUNC (__udivdi3) (grub_uint64_t a, grub_uint64_t b);
+#endif
+
+#ifdef HAVE___UMODDI3
+grub_uint64_t
+EXPORT_FUNC (__umoddi3) (grub_uint64_t a, grub_uint64_t b);
+#endif
+
+#ifdef HAVE___CTZDI2
+unsigned
+EXPORT_FUNC (__ctzdi2) (grub_uint64_t x);
+#endif
+
+#ifdef HAVE___CTZSI2
+unsigned
+EXPORT_FUNC (__ctzsi2) (grub_uint32_t x);
+#endif
+
+#ifdef HAVE___CLZDI2
+int
+EXPORT_FUNC (__clzdi2) (grub_uint64_t x);
+#endif
+
+#ifdef HAVE___AEABI_UIDIV
+grub_uint32_t
+EXPORT_FUNC (__aeabi_uidiv) (grub_uint32_t a, grub_uint32_t b);
+#endif
+
+#ifdef HAVE___AEABI_UIDIVMOD
+grub_uint32_t
+EXPORT_FUNC (__aeabi_uidivmod) (grub_uint32_t a, grub_uint32_t b);
+#endif
+
+#ifdef HAVE___AEABI_IDIV
+grub_int32_t
+EXPORT_FUNC (__aeabi_idiv) (grub_int32_t a, grub_int32_t b);
+#endif
+
+#ifdef HAVE___AEABI_IDIVMOD
+grub_int32_t
+EXPORT_FUNC (__aeabi_idivmod) (grub_int32_t a, grub_int32_t b);
+#endif
+
+#ifdef HAVE___AEABI_ULCMP
+int
+EXPORT_FUNC (__aeabi_ulcmp) (grub_uint64_t a, grub_uint64_t b);
+#endif
+
+/* Needed for allowing modules to be compiled as thumb. */
+#ifdef HAVE___MULDI3
+grub_uint64_t
+EXPORT_FUNC (__muldi3) (grub_uint64_t a, grub_uint64_t b);
+#endif
+
+#ifdef HAVE___AEABI_LMUL
+grub_uint64_t
+EXPORT_FUNC (__aeabi_lmul) (grub_uint64_t a, grub_uint64_t b);
+#endif
+
+#ifdef HAVE___AEABI_MEMCPY
+void *
+EXPORT_FUNC (__aeabi_memcpy) (void *dest, const void *src, grub_size_t n);
+#endif
+
+#ifdef HAVE___AEABI_MEMCPY4
+void *
+EXPORT_FUNC (__aeabi_memcpy4) (void *dest, const void *src, grub_size_t n);
+#endif
+
+#ifdef HAVE___AEABI_MEMCPY8
+void *
+EXPORT_FUNC (__aeabi_memcpy8) (void *dest, const void *src, grub_size_t n);
+#endif
+
+#ifdef HAVE___AEABI_MEMSET
+void *
+EXPORT_FUNC(__aeabi_memset) (void *s, int c, grub_size_t n);
+#endif
+
+#ifdef HAVE___AEABI_MEMCLR
+void *
+EXPORT_FUNC(__aeabi_memclr) (void *s, grub_size_t n);
+#endif
+
+#ifdef HAVE___AEABI_MEMCLR4
+void *
+EXPORT_FUNC(__aeabi_memclr4) (void *s, grub_size_t n);
+#endif
+
+#ifdef HAVE___AEABI_MEMCLR8
+void *
+EXPORT_FUNC(__aeabi_memclr8) (void *s, grub_size_t n);
+#endif
+
+#ifdef HAVE___AEABI_LASR
+grub_uint64_t
+EXPORT_FUNC (__aeabi_lasr) (grub_uint64_t u, int b);
+#endif
+
+#ifdef HAVE___AEABI_LLSL
+grub_uint64_t
+EXPORT_FUNC (__aeabi_llsl) (grub_uint64_t u, int b);
+#endif
+
+#ifdef HAVE___AEABI_LLSR
+grub_uint64_t
+EXPORT_FUNC (__aeabi_llsr) (grub_uint64_t u, int b);
+#endif
+
+
+#ifdef HAVE__RESTGPR_14_X
+
+void EXPORT_FUNC (_restgpr_14_x) (void);
+void EXPORT_FUNC (_restgpr_15_x) (void);
+void EXPORT_FUNC (_restgpr_16_x) (void);
+void EXPORT_FUNC (_restgpr_17_x) (void);
+void EXPORT_FUNC (_restgpr_18_x) (void);
+void EXPORT_FUNC (_restgpr_19_x) (void);
+void EXPORT_FUNC (_restgpr_20_x) (void);
+void EXPORT_FUNC (_restgpr_21_x) (void);
+void EXPORT_FUNC (_restgpr_22_x) (void);
+void EXPORT_FUNC (_restgpr_23_x) (void);
+void EXPORT_FUNC (_restgpr_24_x) (void);
+void EXPORT_FUNC (_restgpr_25_x) (void);
+void EXPORT_FUNC (_restgpr_26_x) (void);
+void EXPORT_FUNC (_restgpr_27_x) (void);
+void EXPORT_FUNC (_restgpr_28_x) (void);
+void EXPORT_FUNC (_restgpr_29_x) (void);
+void EXPORT_FUNC (_restgpr_30_x) (void);
+void EXPORT_FUNC (_restgpr_31_x) (void);
+void EXPORT_FUNC (_savegpr_14) (void);
+void EXPORT_FUNC (_savegpr_15) (void);
+void EXPORT_FUNC (_savegpr_16) (void);
+void EXPORT_FUNC (_savegpr_17) (void);
+void EXPORT_FUNC (_savegpr_18) (void);
+void EXPORT_FUNC (_savegpr_19) (void);
+void EXPORT_FUNC (_savegpr_20) (void);
+void EXPORT_FUNC (_savegpr_21) (void);
+void EXPORT_FUNC (_savegpr_22) (void);
+void EXPORT_FUNC (_savegpr_23) (void);
+void EXPORT_FUNC (_savegpr_24) (void);
+void EXPORT_FUNC (_savegpr_25) (void);
+void EXPORT_FUNC (_savegpr_26) (void);
+void EXPORT_FUNC (_savegpr_27) (void);
+void EXPORT_FUNC (_savegpr_28) (void);
+void EXPORT_FUNC (_savegpr_29) (void);
+void EXPORT_FUNC (_savegpr_30) (void);
+void EXPORT_FUNC (_savegpr_31) (void);
+
+#endif
+
+#ifdef HAVE___UCMPDI2
+int
+EXPORT_FUNC(__ucmpdi2) (grub_uint64_t a, grub_uint64_t b);
+#endif
+
+#ifdef HAVE___ASHLDI3
+grub_uint64_t
+EXPORT_FUNC(__ashldi3) (grub_uint64_t u, int b);
+#endif
+
+#ifdef HAVE___ASHRDI3
+grub_uint64_t
+EXPORT_FUNC(__ashrdi3) (grub_uint64_t u, int b);
+#endif
+
+#ifdef HAVE___LSHRDI3
+grub_uint64_t
+EXPORT_FUNC (__lshrdi3) (grub_uint64_t u, int b);
+#endif
+
+#ifdef HAVE___BSWAPSI2
+grub_uint32_t
+EXPORT_FUNC(__bswapsi2) (grub_uint32_t u);
+#endif
+
+#ifdef HAVE___BSWAPDI2
+grub_uint64_t
+EXPORT_FUNC(__bswapdi2) (grub_uint64_t u);
+#endif
+
+int EXPORT_FUNC(memcmp) (const void *s1, const void *s2, grub_size_t n);
+void *EXPORT_FUNC(memmove) (void *dest, const void *src, grub_size_t n);
+void *EXPORT_FUNC(memcpy) (void *dest, const void *src, grub_size_t n);
+void *EXPORT_FUNC(memset) (void *s, int c, grub_size_t n);
+
+#ifdef HAVE___BZERO
+void EXPORT_FUNC (__bzero) (void *s, grub_size_t n);
+#endif
+
+#ifdef HAVE___REGISTER_FRAME_INFO
+void EXPORT_FUNC (__register_frame_info) (void);
+#endif
+
+#ifdef HAVE___DEREGISTER_FRAME_INFO
+void EXPORT_FUNC (__deregister_frame_info) (void);
+#endif
+#ifdef HAVE____CHKSTK_MS
+void EXPORT_FUNC (___chkstk_ms) (void);
+#endif
+
+#ifdef HAVE___CHKSTK_MS
+void EXPORT_FUNC (__chkstk_ms) (void);
+#endif
+
+#endif
+
diff --git a/include/grub/compiler-rt.h b/include/grub/compiler-rt.h
new file mode 100644
index 0000000..17828b3
--- /dev/null
+++ b/include/grub/compiler-rt.h
@@ -0,0 +1,213 @@
+/* compiler-rt.h - prototypes for compiler helpers. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2003,2005,2006,2007,2008,2009,2010-2014 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_COMPILER_RT_HEADER
+#define GRUB_COMPILER_RT_HEADER 1
+
+#include <stdarg.h>
+#include <grub/types.h>
+#include <grub/symbol.h>
+#include <grub/misc.h>
+
+#if defined(GRUB_DIVISION_IN_SOFTWARE) && GRUB_DIVISION_IN_SOFTWARE
+
+grub_uint32_t
+EXPORT_FUNC (__udivsi3) (grub_uint32_t a, grub_uint32_t b);
+
+grub_uint32_t
+EXPORT_FUNC (__umodsi3) (grub_uint32_t a, grub_uint32_t b);
+
+grub_int32_t
+EXPORT_FUNC (__divsi3) (grub_int32_t a, grub_int32_t b);
+
+grub_int32_t
+EXPORT_FUNC (__modsi3) (grub_int32_t a, grub_int32_t b);
+
+grub_int64_t
+EXPORT_FUNC (__divdi3) (grub_int64_t a, grub_int64_t b);
+
+grub_int64_t
+EXPORT_FUNC (__moddi3) (grub_int64_t a, grub_int64_t b);
+
+grub_uint64_t
+EXPORT_FUNC (__udivdi3) (grub_uint64_t a, grub_uint64_t b);
+
+grub_uint64_t
+EXPORT_FUNC (__umoddi3) (grub_uint64_t a, grub_uint64_t b);
+
+#endif
+
+#if defined (__sparc__) || defined (__powerpc__) || defined (__mips__) || \
+ defined (__arm__) || defined(__riscv)
+unsigned
+EXPORT_FUNC (__ctzdi2) (grub_uint64_t x);
+#define NEED_CTZDI2 1
+#endif
+
+#if defined (__mips__) || defined (__arm__) || \
+ (defined(__riscv) && (__riscv_xlen == 32))
+unsigned
+EXPORT_FUNC (__ctzsi2) (grub_uint32_t x);
+#define NEED_CTZSI2 1
+#endif
+
+#ifdef __arm__
+grub_uint32_t
+EXPORT_FUNC (__aeabi_uidiv) (grub_uint32_t a, grub_uint32_t b);
+grub_uint32_t
+EXPORT_FUNC (__aeabi_uidivmod) (grub_uint32_t a, grub_uint32_t b);
+
+grub_int32_t
+EXPORT_FUNC (__aeabi_idiv) (grub_int32_t a, grub_int32_t b);
+grub_int32_t
+EXPORT_FUNC (__aeabi_idivmod) (grub_int32_t a, grub_int32_t b);
+
+int
+EXPORT_FUNC (__aeabi_ulcmp) (grub_uint64_t a, grub_uint64_t b);
+
+/* Needed for allowing modules to be compiled as thumb. */
+grub_uint64_t
+EXPORT_FUNC (__muldi3) (grub_uint64_t a, grub_uint64_t b);
+grub_uint64_t
+EXPORT_FUNC (__aeabi_lmul) (grub_uint64_t a, grub_uint64_t b);
+
+void *
+EXPORT_FUNC (__aeabi_memcpy) (void *dest, const void *src, grub_size_t n);
+void *
+EXPORT_FUNC (__aeabi_memcpy4) (void *dest, const void *src, grub_size_t n);
+void *
+EXPORT_FUNC (__aeabi_memcpy8) (void *dest, const void *src, grub_size_t n);
+void *
+EXPORT_FUNC(__aeabi_memset) (void *s, int c, grub_size_t n);
+void EXPORT_FUNC(__aeabi_memclr) (void *s, grub_size_t n);
+void EXPORT_FUNC(__aeabi_memclr4) (void *s, grub_size_t n);
+void EXPORT_FUNC(__aeabi_memclr8) (void *s, grub_size_t n);
+
+grub_uint64_t
+EXPORT_FUNC (__aeabi_lasr) (grub_uint64_t u, int b);
+
+grub_uint64_t
+EXPORT_FUNC (__aeabi_llsl) (grub_uint64_t u, int b);
+
+grub_uint64_t
+EXPORT_FUNC (__aeabi_llsr) (grub_uint64_t u, int b);
+
+#endif
+
+#if defined(__mips__) || defined(__riscv) || defined(__sparc__)
+int
+EXPORT_FUNC (__clzsi2) (grub_uint32_t val);
+#endif
+
+#if defined(__mips__) || defined(__riscv) || defined(__sparc__)
+int
+EXPORT_FUNC (__clzdi2) (grub_uint64_t val);
+#endif
+
+#if defined (__powerpc__)
+
+void EXPORT_FUNC (_restgpr_14_x) (void);
+void EXPORT_FUNC (_restgpr_15_x) (void);
+void EXPORT_FUNC (_restgpr_16_x) (void);
+void EXPORT_FUNC (_restgpr_17_x) (void);
+void EXPORT_FUNC (_restgpr_18_x) (void);
+void EXPORT_FUNC (_restgpr_19_x) (void);
+void EXPORT_FUNC (_restgpr_20_x) (void);
+void EXPORT_FUNC (_restgpr_21_x) (void);
+void EXPORT_FUNC (_restgpr_22_x) (void);
+void EXPORT_FUNC (_restgpr_23_x) (void);
+void EXPORT_FUNC (_restgpr_24_x) (void);
+void EXPORT_FUNC (_restgpr_25_x) (void);
+void EXPORT_FUNC (_restgpr_26_x) (void);
+void EXPORT_FUNC (_restgpr_27_x) (void);
+void EXPORT_FUNC (_restgpr_28_x) (void);
+void EXPORT_FUNC (_restgpr_29_x) (void);
+void EXPORT_FUNC (_restgpr_30_x) (void);
+void EXPORT_FUNC (_restgpr_31_x) (void);
+void EXPORT_FUNC (_savegpr_14) (void);
+void EXPORT_FUNC (_savegpr_15) (void);
+void EXPORT_FUNC (_savegpr_16) (void);
+void EXPORT_FUNC (_savegpr_17) (void);
+void EXPORT_FUNC (_savegpr_18) (void);
+void EXPORT_FUNC (_savegpr_19) (void);
+void EXPORT_FUNC (_savegpr_20) (void);
+void EXPORT_FUNC (_savegpr_21) (void);
+void EXPORT_FUNC (_savegpr_22) (void);
+void EXPORT_FUNC (_savegpr_23) (void);
+void EXPORT_FUNC (_savegpr_24) (void);
+void EXPORT_FUNC (_savegpr_25) (void);
+void EXPORT_FUNC (_savegpr_26) (void);
+void EXPORT_FUNC (_savegpr_27) (void);
+void EXPORT_FUNC (_savegpr_28) (void);
+void EXPORT_FUNC (_savegpr_29) (void);
+void EXPORT_FUNC (_savegpr_30) (void);
+void EXPORT_FUNC (_savegpr_31) (void);
+
+#endif
+
+#if defined (__powerpc__) || defined(__mips__) || defined (__arm__) || \
+ (defined(__riscv) && (__riscv_xlen == 32))
+
+int
+EXPORT_FUNC(__ucmpdi2) (grub_uint64_t a, grub_uint64_t b);
+
+grub_uint64_t
+EXPORT_FUNC(__ashldi3) (grub_uint64_t u, int b);
+
+grub_uint64_t
+EXPORT_FUNC(__ashrdi3) (grub_uint64_t u, int b);
+
+grub_uint64_t
+EXPORT_FUNC (__lshrdi3) (grub_uint64_t u, int b);
+#endif
+
+#if defined (__powerpc__) || defined(__mips__) || defined(__sparc__) || \
+ defined (__arm__) || defined(__riscv)
+grub_uint32_t
+EXPORT_FUNC(__bswapsi2) (grub_uint32_t u);
+
+grub_uint64_t
+EXPORT_FUNC(__bswapdi2) (grub_uint64_t u);
+#endif
+
+#if defined (__APPLE__) && defined(__i386__)
+#define GRUB_BUILTIN_ATTR __attribute__ ((regparm(0)))
+#else
+#define GRUB_BUILTIN_ATTR
+#endif
+
+/* Prototypes for aliases. */
+int GRUB_BUILTIN_ATTR EXPORT_FUNC(memcmp) (const void *s1, const void *s2, grub_size_t n);
+void *GRUB_BUILTIN_ATTR EXPORT_FUNC(memmove) (void *dest, const void *src, grub_size_t n);
+void *GRUB_BUILTIN_ATTR EXPORT_FUNC(memcpy) (void *dest, const void *src, grub_size_t n);
+void *GRUB_BUILTIN_ATTR EXPORT_FUNC(memset) (void *s, int c, grub_size_t n);
+
+#ifdef __APPLE__
+void GRUB_BUILTIN_ATTR EXPORT_FUNC (__bzero) (void *s, grub_size_t n);
+#endif
+
+#if defined (__MINGW32__) || defined (__CYGWIN__)
+void EXPORT_FUNC (__register_frame_info) (void);
+void EXPORT_FUNC (__deregister_frame_info) (void);
+void EXPORT_FUNC (___chkstk_ms) (void);
+void EXPORT_FUNC (__chkstk_ms) (void);
+#endif
+
+#endif
+
diff --git a/include/grub/compiler.h b/include/grub/compiler.h
new file mode 100644
index 0000000..8f3be3a
--- /dev/null
+++ b/include/grub/compiler.h
@@ -0,0 +1,59 @@
+/* compiler.h - macros for various compiler features */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2003,2005,2006,2007,2008,2009,2010,2014 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_COMPILER_HEADER
+#define GRUB_COMPILER_HEADER 1
+
+/* GCC version checking borrowed from glibc. */
+#if defined(__GNUC__) && defined(__GNUC_MINOR__)
+# define GNUC_PREREQ(maj,min) \
+ ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
+#else
+# define GNUC_PREREQ(maj,min) 0
+#endif
+
+/* Does this compiler support compile-time error attributes? */
+#if GNUC_PREREQ(4,3)
+# define ATTRIBUTE_ERROR(msg) \
+ __attribute__ ((__error__ (msg)))
+#else
+# define ATTRIBUTE_ERROR(msg) __attribute__ ((noreturn))
+#endif
+
+#if GNUC_PREREQ(4,4)
+# define GNU_PRINTF gnu_printf
+#else
+# define GNU_PRINTF printf
+#endif
+
+#if GNUC_PREREQ(3,4)
+# define WARN_UNUSED_RESULT __attribute__ ((warn_unused_result))
+#else
+# define WARN_UNUSED_RESULT
+#endif
+
+#if defined(__clang__) && defined(__clang_major__) && defined(__clang_minor__)
+# define CLANG_PREREQ(maj,min) \
+ ((__clang_major__ > (maj)) || \
+ (__clang_major__ == (maj) && __clang_minor__ >= (min)))
+#else
+# define CLANG_PREREQ(maj,min) 0
+#endif
+
+#endif /* ! GRUB_COMPILER_HEADER */
diff --git a/include/grub/coreboot/lbio.h b/include/grub/coreboot/lbio.h
new file mode 100644
index 0000000..5076d36
--- /dev/null
+++ b/include/grub/coreboot/lbio.h
@@ -0,0 +1,114 @@
+/* memory.h - describe the memory map */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2007,2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _GRUB_MACHINE_LBIO_HEADER
+#define _GRUB_MACHINE_LBIO_HEADER 1
+
+#include <grub/types.h>
+#include <grub/err.h>
+
+struct grub_linuxbios_table_header
+{
+ grub_uint8_t signature[4];
+ grub_uint32_t header_size;
+ grub_uint32_t header_checksum;
+ grub_uint32_t table_size;
+ grub_uint32_t table_checksum;
+ grub_uint32_t table_entries;
+};
+typedef struct grub_linuxbios_table_header *grub_linuxbios_table_header_t;
+
+struct grub_linuxbios_timestamp_entry
+{
+ grub_uint32_t id;
+ grub_uint64_t tsc;
+} GRUB_PACKED;
+
+struct grub_linuxbios_timestamp_table
+{
+ grub_uint64_t base_tsc;
+ grub_uint32_t capacity;
+ grub_uint32_t used;
+ struct grub_linuxbios_timestamp_entry entries[0];
+} GRUB_PACKED;
+
+struct grub_linuxbios_mainboard
+{
+ grub_uint8_t vendor;
+ grub_uint8_t part_number;
+ char strings[0];
+};
+
+struct grub_linuxbios_table_item
+{
+ grub_uint32_t tag;
+ grub_uint32_t size;
+};
+typedef struct grub_linuxbios_table_item *grub_linuxbios_table_item_t;
+
+enum
+ {
+ GRUB_LINUXBIOS_MEMBER_UNUSED = 0x00,
+ GRUB_LINUXBIOS_MEMBER_MEMORY = 0x01,
+ GRUB_LINUXBIOS_MEMBER_MAINBOARD = 0x03,
+ GRUB_LINUXBIOS_MEMBER_CONSOLE = 0x10,
+ GRUB_LINUXBIOS_MEMBER_LINK = 0x11,
+ GRUB_LINUXBIOS_MEMBER_FRAMEBUFFER = 0x12,
+ GRUB_LINUXBIOS_MEMBER_TIMESTAMPS = 0x16,
+ GRUB_LINUXBIOS_MEMBER_CBMEMC = 0x17
+ };
+
+struct grub_linuxbios_table_framebuffer {
+ grub_uint64_t lfb;
+ grub_uint32_t width;
+ grub_uint32_t height;
+ grub_uint32_t pitch;
+ grub_uint8_t bpp;
+
+ grub_uint8_t red_field_pos;
+ grub_uint8_t red_mask_size;
+ grub_uint8_t green_field_pos;
+ grub_uint8_t green_mask_size;
+ grub_uint8_t blue_field_pos;
+ grub_uint8_t blue_mask_size;
+ grub_uint8_t reserved_field_pos;
+ grub_uint8_t reserved_mask_size;
+} GRUB_PACKED;
+
+struct grub_linuxbios_mem_region
+{
+ grub_uint64_t addr;
+ grub_uint64_t size;
+#define GRUB_MACHINE_MEMORY_AVAILABLE 1
+ grub_uint32_t type;
+} GRUB_PACKED;
+typedef struct grub_linuxbios_mem_region *mem_region_t;
+
+grub_err_t
+EXPORT_FUNC(grub_linuxbios_table_iterate) (int (*hook) (grub_linuxbios_table_item_t,
+ void *),
+ void *hook_data);
+
+grub_linuxbios_table_header_t
+grub_linuxbios_get_tables (void);
+
+int
+grub_linuxbios_check_signature (grub_linuxbios_table_header_t tbl_header);
+
+#endif
diff --git a/include/grub/crypto.h b/include/grub/crypto.h
new file mode 100644
index 0000000..21cd1f7
--- /dev/null
+++ b/include/grub/crypto.h
@@ -0,0 +1,422 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006
+ * 2007, 2008, 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* Contains elements based on gcrypt-module.h and gcrypt.h.in.
+ If it's changed please update this file. */
+
+#ifndef GRUB_CRYPTO_HEADER
+#define GRUB_CRYPTO_HEADER 1
+
+#include <grub/symbol.h>
+#include <grub/types.h>
+#include <grub/err.h>
+#include <grub/mm.h>
+
+typedef enum
+ {
+ GPG_ERR_NO_ERROR,
+ GPG_ERR_BAD_MPI,
+ GPG_ERR_BAD_SECKEY,
+ GPG_ERR_BAD_SIGNATURE,
+ GPG_ERR_CIPHER_ALGO,
+ GPG_ERR_CONFLICT,
+ GPG_ERR_DECRYPT_FAILED,
+ GPG_ERR_DIGEST_ALGO,
+ GPG_ERR_GENERAL,
+ GPG_ERR_INTERNAL,
+ GPG_ERR_INV_ARG,
+ GPG_ERR_INV_CIPHER_MODE,
+ GPG_ERR_INV_FLAG,
+ GPG_ERR_INV_KEYLEN,
+ GPG_ERR_INV_OBJ,
+ GPG_ERR_INV_OP,
+ GPG_ERR_INV_SEXP,
+ GPG_ERR_INV_VALUE,
+ GPG_ERR_MISSING_VALUE,
+ GPG_ERR_NO_ENCRYPTION_SCHEME,
+ GPG_ERR_NO_OBJ,
+ GPG_ERR_NO_PRIME,
+ GPG_ERR_NO_SIGNATURE_SCHEME,
+ GPG_ERR_NOT_FOUND,
+ GPG_ERR_NOT_IMPLEMENTED,
+ GPG_ERR_NOT_SUPPORTED,
+ GPG_ERR_PUBKEY_ALGO,
+ GPG_ERR_SELFTEST_FAILED,
+ GPG_ERR_TOO_SHORT,
+ GPG_ERR_UNSUPPORTED,
+ GPG_ERR_WEAK_KEY,
+ GPG_ERR_WRONG_KEY_USAGE,
+ GPG_ERR_WRONG_PUBKEY_ALGO,
+ GPG_ERR_OUT_OF_MEMORY,
+ GPG_ERR_TOO_LARGE,
+ GPG_ERR_ENOMEM
+ } gpg_err_code_t;
+typedef gpg_err_code_t gpg_error_t;
+typedef gpg_error_t gcry_error_t;
+typedef gpg_err_code_t gcry_err_code_t;
+#define gcry_error_t gcry_err_code_t
+#if 0
+enum gcry_cipher_modes
+ {
+ GCRY_CIPHER_MODE_NONE = 0, /* Not yet specified. */
+ GCRY_CIPHER_MODE_ECB = 1, /* Electronic codebook. */
+ GCRY_CIPHER_MODE_CFB = 2, /* Cipher feedback. */
+ GCRY_CIPHER_MODE_CBC = 3, /* Cipher block chaining. */
+ GCRY_CIPHER_MODE_STREAM = 4, /* Used with stream ciphers. */
+ GCRY_CIPHER_MODE_OFB = 5, /* Outer feedback. */
+ GCRY_CIPHER_MODE_CTR = 6 /* Counter. */
+ };
+#endif
+
+/* Don't rely on this. Check! */
+#define GRUB_CRYPTO_MAX_MDLEN 64
+#define GRUB_CRYPTO_MAX_CIPHER_BLOCKSIZE 16
+#define GRUB_CRYPTO_MAX_MD_CONTEXT_SIZE 256
+
+/* Type for the cipher_setkey function. */
+typedef gcry_err_code_t (*gcry_cipher_setkey_t) (void *c,
+ const unsigned char *key,
+ unsigned keylen);
+
+/* Type for the cipher_encrypt function. */
+typedef void (*gcry_cipher_encrypt_t) (void *c,
+ unsigned char *outbuf,
+ const unsigned char *inbuf);
+
+/* Type for the cipher_decrypt function. */
+typedef void (*gcry_cipher_decrypt_t) (void *c,
+ unsigned char *outbuf,
+ const unsigned char *inbuf);
+
+/* Type for the cipher_stencrypt function. */
+typedef void (*gcry_cipher_stencrypt_t) (void *c,
+ unsigned char *outbuf,
+ const unsigned char *inbuf,
+ unsigned int n);
+
+/* Type for the cipher_stdecrypt function. */
+typedef void (*gcry_cipher_stdecrypt_t) (void *c,
+ unsigned char *outbuf,
+ const unsigned char *inbuf,
+ unsigned int n);
+
+typedef struct gcry_cipher_oid_spec
+{
+ const char *oid;
+ int mode;
+} gcry_cipher_oid_spec_t;
+
+/* Module specification structure for ciphers. */
+typedef struct gcry_cipher_spec
+{
+ const char *name;
+ const char **aliases;
+ gcry_cipher_oid_spec_t *oids;
+ grub_size_t blocksize;
+ grub_size_t keylen;
+ grub_size_t contextsize;
+ gcry_cipher_setkey_t setkey;
+ gcry_cipher_encrypt_t encrypt;
+ gcry_cipher_decrypt_t decrypt;
+ gcry_cipher_stencrypt_t stencrypt;
+ gcry_cipher_stdecrypt_t stdecrypt;
+#ifdef GRUB_UTIL
+ const char *modname;
+#endif
+ struct gcry_cipher_spec *next;
+} gcry_cipher_spec_t;
+
+/* Type for the md_init function. */
+typedef void (*gcry_md_init_t) (void *c);
+
+/* Type for the md_write function. */
+typedef void (*gcry_md_write_t) (void *c, const void *buf, grub_size_t nbytes);
+
+/* Type for the md_final function. */
+typedef void (*gcry_md_final_t) (void *c);
+
+/* Type for the md_read function. */
+typedef unsigned char *(*gcry_md_read_t) (void *c);
+
+typedef struct gcry_md_oid_spec
+{
+ const char *oidstring;
+} gcry_md_oid_spec_t;
+
+/* Module specification structure for message digests. */
+typedef struct gcry_md_spec
+{
+ const char *name;
+ unsigned char *asnoid;
+ int asnlen;
+ gcry_md_oid_spec_t *oids;
+ grub_size_t mdlen;
+ gcry_md_init_t init;
+ gcry_md_write_t write;
+ gcry_md_final_t final;
+ gcry_md_read_t read;
+ grub_size_t contextsize; /* allocate this amount of context */
+ /* Block size, needed for HMAC. */
+ grub_size_t blocksize;
+#ifdef GRUB_UTIL
+ const char *modname;
+#endif
+ struct gcry_md_spec *next;
+} gcry_md_spec_t;
+
+struct gcry_mpi;
+typedef struct gcry_mpi *gcry_mpi_t;
+
+/* Type for the pk_generate function. */
+typedef gcry_err_code_t (*gcry_pk_generate_t) (int algo,
+ unsigned int nbits,
+ unsigned long use_e,
+ gcry_mpi_t *skey,
+ gcry_mpi_t **retfactors);
+
+/* Type for the pk_check_secret_key function. */
+typedef gcry_err_code_t (*gcry_pk_check_secret_key_t) (int algo,
+ gcry_mpi_t *skey);
+
+/* Type for the pk_encrypt function. */
+typedef gcry_err_code_t (*gcry_pk_encrypt_t) (int algo,
+ gcry_mpi_t *resarr,
+ gcry_mpi_t data,
+ gcry_mpi_t *pkey,
+ int flags);
+
+/* Type for the pk_decrypt function. */
+typedef gcry_err_code_t (*gcry_pk_decrypt_t) (int algo,
+ gcry_mpi_t *result,
+ gcry_mpi_t *data,
+ gcry_mpi_t *skey,
+ int flags);
+
+/* Type for the pk_sign function. */
+typedef gcry_err_code_t (*gcry_pk_sign_t) (int algo,
+ gcry_mpi_t *resarr,
+ gcry_mpi_t data,
+ gcry_mpi_t *skey);
+
+/* Type for the pk_verify function. */
+typedef gcry_err_code_t (*gcry_pk_verify_t) (int algo,
+ gcry_mpi_t hash,
+ gcry_mpi_t *data,
+ gcry_mpi_t *pkey,
+ int (*cmp) (void *, gcry_mpi_t),
+ void *opaquev);
+
+/* Type for the pk_get_nbits function. */
+typedef unsigned (*gcry_pk_get_nbits_t) (int algo, gcry_mpi_t *pkey);
+
+/* Module specification structure for message digests. */
+typedef struct gcry_pk_spec
+{
+ const char *name;
+ const char **aliases;
+ const char *elements_pkey;
+ const char *elements_skey;
+ const char *elements_enc;
+ const char *elements_sig;
+ const char *elements_grip;
+ int use;
+ gcry_pk_generate_t generate;
+ gcry_pk_check_secret_key_t check_secret_key;
+ gcry_pk_encrypt_t encrypt;
+ gcry_pk_decrypt_t decrypt;
+ gcry_pk_sign_t sign;
+ gcry_pk_verify_t verify;
+ gcry_pk_get_nbits_t get_nbits;
+#ifdef GRUB_UTIL
+ const char *modname;
+#endif
+} gcry_pk_spec_t;
+
+struct grub_crypto_cipher_handle
+{
+ const struct gcry_cipher_spec *cipher;
+ char ctx[0];
+};
+
+typedef struct grub_crypto_cipher_handle *grub_crypto_cipher_handle_t;
+
+struct grub_crypto_hmac_handle;
+
+const gcry_cipher_spec_t *
+grub_crypto_lookup_cipher_by_name (const char *name);
+
+grub_crypto_cipher_handle_t
+grub_crypto_cipher_open (const struct gcry_cipher_spec *cipher);
+
+gcry_err_code_t
+grub_crypto_cipher_set_key (grub_crypto_cipher_handle_t cipher,
+ const unsigned char *key,
+ unsigned keylen);
+
+static inline void
+grub_crypto_cipher_close (grub_crypto_cipher_handle_t cipher)
+{
+ grub_free (cipher);
+}
+
+static inline void
+grub_crypto_xor (void *out, const void *in1, const void *in2, grub_size_t size)
+{
+ const grub_uint8_t *in1ptr = in1, *in2ptr = in2;
+ grub_uint8_t *outptr = out;
+ while (size && (((grub_addr_t) in1ptr & (sizeof (grub_uint64_t) - 1))
+ || ((grub_addr_t) in2ptr & (sizeof (grub_uint64_t) - 1))
+ || ((grub_addr_t) outptr & (sizeof (grub_uint64_t) - 1))))
+ {
+ *outptr = *in1ptr ^ *in2ptr;
+ in1ptr++;
+ in2ptr++;
+ outptr++;
+ size--;
+ }
+ while (size >= sizeof (grub_uint64_t))
+ {
+ /* We've already checked that all pointers are aligned. */
+ *(grub_uint64_t *) (void *) outptr
+ = (*(const grub_uint64_t *) (const void *) in1ptr
+ ^ *(const grub_uint64_t *) (const void *) in2ptr);
+ in1ptr += sizeof (grub_uint64_t);
+ in2ptr += sizeof (grub_uint64_t);
+ outptr += sizeof (grub_uint64_t);
+ size -= sizeof (grub_uint64_t);
+ }
+ while (size)
+ {
+ *outptr = *in1ptr ^ *in2ptr;
+ in1ptr++;
+ in2ptr++;
+ outptr++;
+ size--;
+ }
+}
+
+gcry_err_code_t
+grub_crypto_ecb_decrypt (grub_crypto_cipher_handle_t cipher,
+ void *out, const void *in, grub_size_t size);
+
+gcry_err_code_t
+grub_crypto_ecb_encrypt (grub_crypto_cipher_handle_t cipher,
+ void *out, const void *in, grub_size_t size);
+gcry_err_code_t
+grub_crypto_cbc_encrypt (grub_crypto_cipher_handle_t cipher,
+ void *out, const void *in, grub_size_t size,
+ void *iv_in);
+gcry_err_code_t
+grub_crypto_cbc_decrypt (grub_crypto_cipher_handle_t cipher,
+ void *out, const void *in, grub_size_t size,
+ void *iv);
+void
+grub_cipher_register (gcry_cipher_spec_t *cipher);
+void
+grub_cipher_unregister (gcry_cipher_spec_t *cipher);
+void
+grub_md_register (gcry_md_spec_t *digest);
+void
+grub_md_unregister (gcry_md_spec_t *cipher);
+
+extern struct gcry_pk_spec *grub_crypto_pk_dsa;
+extern struct gcry_pk_spec *grub_crypto_pk_ecdsa;
+extern struct gcry_pk_spec *grub_crypto_pk_ecdh;
+extern struct gcry_pk_spec *grub_crypto_pk_rsa;
+
+void
+grub_crypto_hash (const gcry_md_spec_t *hash, void *out, const void *in,
+ grub_size_t inlen);
+const gcry_md_spec_t *
+grub_crypto_lookup_md_by_name (const char *name);
+
+grub_err_t
+grub_crypto_gcry_error (gcry_err_code_t in);
+
+void grub_burn_stack (grub_size_t size);
+
+struct grub_crypto_hmac_handle *
+grub_crypto_hmac_init (const struct gcry_md_spec *md,
+ const void *key, grub_size_t keylen);
+void
+grub_crypto_hmac_write (struct grub_crypto_hmac_handle *hnd,
+ const void *data,
+ grub_size_t datalen);
+gcry_err_code_t
+grub_crypto_hmac_fini (struct grub_crypto_hmac_handle *hnd, void *out);
+
+gcry_err_code_t
+grub_crypto_hmac_buffer (const struct gcry_md_spec *md,
+ const void *key, grub_size_t keylen,
+ const void *data, grub_size_t datalen, void *out);
+
+extern gcry_md_spec_t _gcry_digest_spec_md5;
+extern gcry_md_spec_t _gcry_digest_spec_sha1;
+extern gcry_md_spec_t _gcry_digest_spec_sha256;
+extern gcry_md_spec_t _gcry_digest_spec_sha512;
+extern gcry_md_spec_t _gcry_digest_spec_crc32;
+extern gcry_cipher_spec_t _gcry_cipher_spec_aes;
+#define GRUB_MD_MD5 ((const gcry_md_spec_t *) &_gcry_digest_spec_md5)
+#define GRUB_MD_SHA1 ((const gcry_md_spec_t *) &_gcry_digest_spec_sha1)
+#define GRUB_MD_SHA256 ((const gcry_md_spec_t *) &_gcry_digest_spec_sha256)
+#define GRUB_MD_SHA512 ((const gcry_md_spec_t *) &_gcry_digest_spec_sha512)
+#define GRUB_MD_CRC32 ((const gcry_md_spec_t *) &_gcry_digest_spec_crc32)
+#define GRUB_CIPHER_AES ((const gcry_cipher_spec_t *) &_gcry_cipher_spec_aes)
+
+/* Implement PKCS#5 PBKDF2 as per RFC 2898. The PRF to use is HMAC variant
+ of digest supplied by MD. Inputs are the password P of length PLEN,
+ the salt S of length SLEN, the iteration counter C (> 0), and the
+ desired derived output length DKLEN. Output buffer is DK which
+ must have room for at least DKLEN octets. The output buffer will
+ be filled with the derived data. */
+gcry_err_code_t
+grub_crypto_pbkdf2 (const struct gcry_md_spec *md,
+ const grub_uint8_t *P, grub_size_t Plen,
+ const grub_uint8_t *S, grub_size_t Slen,
+ unsigned int c,
+ grub_uint8_t *DK, grub_size_t dkLen);
+
+int
+grub_crypto_memcmp (const void *a, const void *b, grub_size_t n);
+
+int
+grub_password_get (char buf[], unsigned buf_size);
+
+/* For indistinguishibility. */
+#define GRUB_ACCESS_DENIED grub_error (GRUB_ERR_ACCESS_DENIED, N_("access denied"))
+
+extern void (*grub_crypto_autoload_hook) (const char *name);
+
+void _gcry_assert_failed (const char *expr, const char *file, int line,
+ const char *func) __attribute__ ((noreturn));
+
+void _gcry_burn_stack (int bytes);
+void _gcry_log_error( const char *fmt, ... ) __attribute__ ((format (__printf__, 1, 2)));
+
+
+#ifdef GRUB_UTIL
+void grub_gcry_init_all (void);
+void grub_gcry_fini_all (void);
+
+int
+grub_get_random (void *out, grub_size_t len);
+
+#endif
+
+#endif
diff --git a/include/grub/cryptodisk.h b/include/grub/cryptodisk.h
new file mode 100644
index 0000000..dcf17fb
--- /dev/null
+++ b/include/grub/cryptodisk.h
@@ -0,0 +1,173 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_CRYPTODISK_HEADER
+#define GRUB_CRYPTODISK_HEADER 1
+
+#include <grub/disk.h>
+#include <grub/crypto.h>
+#include <grub/list.h>
+#ifdef GRUB_UTIL
+#include <grub/emu/hostdisk.h>
+#endif
+
+typedef enum
+ {
+ GRUB_CRYPTODISK_MODE_ECB,
+ GRUB_CRYPTODISK_MODE_CBC,
+ GRUB_CRYPTODISK_MODE_PCBC,
+ GRUB_CRYPTODISK_MODE_XTS,
+ GRUB_CRYPTODISK_MODE_LRW
+ } grub_cryptodisk_mode_t;
+
+typedef enum
+ {
+ GRUB_CRYPTODISK_MODE_IV_NULL,
+ GRUB_CRYPTODISK_MODE_IV_PLAIN,
+ GRUB_CRYPTODISK_MODE_IV_PLAIN64,
+ GRUB_CRYPTODISK_MODE_IV_ESSIV,
+ GRUB_CRYPTODISK_MODE_IV_BENBI,
+ GRUB_CRYPTODISK_MODE_IV_BYTECOUNT64,
+ GRUB_CRYPTODISK_MODE_IV_BYTECOUNT64_HASH
+ } grub_cryptodisk_mode_iv_t;
+
+#define GRUB_CRYPTODISK_MAX_UUID_LENGTH 71
+
+/* LUKS1 specification defines the block size to always be 512 bytes. */
+#define GRUB_LUKS1_LOG_SECTOR_SIZE 9
+
+/* By default dm-crypt increments the IV every 512 bytes. */
+#define GRUB_CRYPTODISK_IV_LOG_SIZE 9
+
+#define GRUB_CRYPTODISK_GF_LOG_SIZE 7
+#define GRUB_CRYPTODISK_GF_SIZE (1U << GRUB_CRYPTODISK_GF_LOG_SIZE)
+#define GRUB_CRYPTODISK_GF_LOG_BYTES (GRUB_CRYPTODISK_GF_LOG_SIZE - 3)
+#define GRUB_CRYPTODISK_GF_BYTES (1U << GRUB_CRYPTODISK_GF_LOG_BYTES)
+#define GRUB_CRYPTODISK_MAX_KEYLEN 128
+
+struct grub_cryptodisk;
+
+typedef gcry_err_code_t
+(*grub_cryptodisk_rekey_func_t) (struct grub_cryptodisk *dev,
+ grub_uint64_t zoneno);
+
+struct grub_cryptodisk
+{
+ struct grub_cryptodisk *next;
+ struct grub_cryptodisk **prev;
+
+ char *source;
+ /*
+ * The number of sectors the start of the encrypted data is offset into the
+ * underlying disk, where sectors are the size noted by log_sector_size.
+ */
+ grub_disk_addr_t offset_sectors;
+ /* Total number of encrypted sectors of size (1 << log_sector_size). */
+ grub_disk_addr_t total_sectors;
+ grub_disk_t source_disk;
+ int ref;
+ grub_crypto_cipher_handle_t cipher;
+ grub_crypto_cipher_handle_t secondary_cipher;
+ grub_crypto_cipher_handle_t essiv_cipher;
+ const gcry_md_spec_t *essiv_hash, *hash, *iv_hash;
+ grub_cryptodisk_mode_t mode;
+ grub_cryptodisk_mode_iv_t mode_iv;
+ int benbi_log;
+ unsigned long id, source_id;
+ enum grub_disk_dev_id source_dev_id;
+ char uuid[GRUB_CRYPTODISK_MAX_UUID_LENGTH + 1];
+ grub_uint8_t lrw_key[GRUB_CRYPTODISK_GF_BYTES];
+ grub_uint8_t *lrw_precalc;
+ grub_uint8_t iv_prefix[64];
+ grub_size_t iv_prefix_len;
+ grub_uint8_t key[GRUB_CRYPTODISK_MAX_KEYLEN];
+ grub_size_t keysize;
+#ifdef GRUB_UTIL
+ char *cheat;
+ grub_util_fd_t cheat_fd;
+#endif
+ const char *modname;
+ int log_sector_size;
+ grub_cryptodisk_rekey_func_t rekey;
+ int rekey_shift;
+ grub_uint8_t rekey_key[64];
+ grub_uint64_t last_rekey;
+ int rekey_derived_size;
+ grub_disk_addr_t partition_start;
+};
+typedef struct grub_cryptodisk *grub_cryptodisk_t;
+
+struct grub_cryptodisk_dev
+{
+ struct grub_cryptodisk_dev *next;
+ struct grub_cryptodisk_dev **prev;
+
+ grub_cryptodisk_t (*scan) (grub_disk_t disk, const char *check_uuid,
+ int boot_only);
+ grub_err_t (*recover_key) (grub_disk_t disk, grub_cryptodisk_t dev);
+};
+typedef struct grub_cryptodisk_dev *grub_cryptodisk_dev_t;
+
+extern grub_cryptodisk_dev_t EXPORT_VAR (grub_cryptodisk_list);
+
+#ifndef GRUB_LST_GENERATOR
+static inline void
+grub_cryptodisk_dev_register (grub_cryptodisk_dev_t cr)
+{
+ grub_list_push (GRUB_AS_LIST_P (&grub_cryptodisk_list), GRUB_AS_LIST (cr));
+}
+#endif
+
+static inline void
+grub_cryptodisk_dev_unregister (grub_cryptodisk_dev_t cr)
+{
+ grub_list_remove (GRUB_AS_LIST (cr));
+}
+
+#define FOR_CRYPTODISK_DEVS(var) FOR_LIST_ELEMENTS((var), (grub_cryptodisk_list))
+
+grub_err_t
+grub_cryptodisk_setcipher (grub_cryptodisk_t crypt, const char *ciphername, const char *ciphermode);
+
+gcry_err_code_t
+grub_cryptodisk_setkey (grub_cryptodisk_t dev,
+ grub_uint8_t *key, grub_size_t keysize);
+gcry_err_code_t
+grub_cryptodisk_decrypt (struct grub_cryptodisk *dev,
+ grub_uint8_t * data, grub_size_t len,
+ grub_disk_addr_t sector, grub_size_t log_sector_size);
+grub_err_t
+grub_cryptodisk_insert (grub_cryptodisk_t newdev, const char *name,
+ grub_disk_t source);
+#ifdef GRUB_UTIL
+grub_err_t
+grub_cryptodisk_cheat_insert (grub_cryptodisk_t newdev, const char *name,
+ grub_disk_t source, const char *cheat);
+void
+grub_util_cryptodisk_get_abstraction (grub_disk_t disk,
+ void (*cb) (const char *val, void *data),
+ void *data);
+
+char *
+grub_util_get_geli_uuid (const char *dev);
+#endif
+
+grub_cryptodisk_t grub_cryptodisk_get_by_uuid (const char *uuid);
+grub_cryptodisk_t grub_cryptodisk_get_by_source_disk (grub_disk_t disk);
+
+#endif
diff --git a/include/grub/cs5536.h b/include/grub/cs5536.h
new file mode 100644
index 0000000..6b5b424
--- /dev/null
+++ b/include/grub/cs5536.h
@@ -0,0 +1,198 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_CS5536_HEADER
+#define GRUB_CS5536_HEADER 1
+
+#ifndef ASM_FILE
+#include <grub/pci.h>
+#include <grub/err.h>
+#include <grub/smbus.h>
+#endif
+
+#define GRUB_CS5536_PCIID 0x208f1022
+#define GRUB_CS5536_MSR_MAILBOX_CONFIG_ENABLED 0x1
+#define GRUB_CS5536_MSR_MAILBOX_CONFIG 0xf0
+#define GRUB_CS5536_MSR_MAILBOX_ADDR 0xf4
+#define GRUB_CS5536_MSR_MAILBOX_DATA0 0xf8
+#define GRUB_CS5536_MSR_MAILBOX_DATA1 0xfc
+#define GRUB_CS5536_MSR_IRQ_MAP_BAR 0x80000008
+#define GRUB_CS5536_MSR_SMB_BAR 0x8000000b
+
+#define GRUB_CS5536_SMBUS_REGS_SIZE 8
+#define GRUB_CS5536_GPIO_REGS_SIZE 256
+#define GRUB_CS5536_MFGPT_REGS_SIZE 64
+#define GRUB_CS5536_IRQ_MAP_REGS_SIZE 32
+#define GRUB_CS5536_PM_REGS_SIZE 128
+#define GRUB_CS5536_ACPI_REGS_SIZE 32
+
+#define GRUB_CS5536_USB_OPTION_REGS_SIZE 0x1c
+#define GRUB_CS5536_USB_OPTION_REG_UOCMUX 1
+#define GRUB_CS5536_USB_OPTION_REG_UOCMUX_PMUX_MASK 0x03
+#define GRUB_CS5536_USB_OPTION_REG_UOCMUX_PMUX_HC 0x02
+
+#define GRUB_CS5536_DESTINATION_GLIU 0
+#define GRUB_CS5536_DESTINATION_GLPCI_SB 1
+#define GRUB_CS5536_DESTINATION_USB 2
+#define GRUB_CS5536_DESTINATION_IDE 3
+#define GRUB_CS5536_DESTINATION_DD 4
+#define GRUB_CS5536_DESTINATION_ACC 5
+#define GRUB_CS5536_DESTINATION_GLCP 7
+
+#define GRUB_CS5536_P2D_DEST_SHIFT 61
+#define GRUB_CS5536_P2D_LOG_ALIGN 12
+#define GRUB_CS5536_P2D_ALIGN (1 << GRUB_CS5536_P2D_LOG_ALIGN)
+#define GRUB_CS5536_P2D_BASE_SHIFT 20
+#define GRUB_CS5536_P2D_MASK_SHIFT 0
+
+#define GRUB_CS5536_MSR_GL_IOD_START 0x000100e0
+#define GRUB_CS5536_IOD_DEST_SHIFT 61
+#define GRUB_CS5536_IOD_BASE_SHIFT 20
+#define GRUB_CS5536_IOD_MASK_SHIFT 0
+#define GRUB_CS5536_IOD_ADDR_MASK 0xfffff
+
+#define GRUB_CS5536_MSR_GPIO_BAR 0x8000000c
+#define GRUB_CS5536_MSR_MFGPT_BAR 0x8000000d
+#define GRUB_CS5536_MSR_ACPI_BAR 0x8000000e
+#define GRUB_CS5536_MSR_PM_BAR 0x8000000f
+#define GRUB_CS5536_MSR_DIVIL_LEG_IO 0x80000014
+#define GRUB_CS5536_MSR_DIVIL_LEG_IO_RTC_ENABLE0 0x00000001
+#define GRUB_CS5536_MSR_DIVIL_LEG_IO_RTC_ENABLE1 0x00000002
+#define GRUB_CS5536_MSR_DIVIL_LEG_IO_MODE_X86 0x10000000
+#define GRUB_CS5536_MSR_DIVIL_LEG_IO_F_REMAP 0x04000000
+#define GRUB_CS5536_MSR_DIVIL_LEG_IO_UART1_COM1 0x00070000
+#define GRUB_CS5536_MSR_DIVIL_LEG_IO_UART2_COM3 0x00500000
+#define GRUB_CS5536_MSR_DIVIL_RESET 0x80000017
+#define GRUB_CS5536_MSR_DIVIL_IRQ_MAPPER_PRIMARY_MASK 0x80000024
+#define GRUB_CS5536_MSR_DIVIL_IRQ_MAPPER_LPC_MASK 0x80000025
+#define GRUB_CS5536_DIVIL_LPC_INTERRUPTS 0x1002
+#define GRUB_CS5536_MSR_DIVIL_LPC_SERIAL_IRQ_CONTROL 0x8000004e
+#define GRUB_CS5536_MSR_DIVIL_LPC_SERIAL_IRQ_CONTROL_ENABLE 0x80
+#define GRUB_CS5536_MSR_DIVIL_UART1_CONF 0x8000003a
+#define GRUB_CS5536_MSR_DIVIL_UART2_CONF 0x8000003e
+
+#define GRUB_CS5536_MSR_USB_OHCI_BASE 0x40000008
+#define GRUB_CS5536_MSR_USB_EHCI_BASE 0x40000009
+#define GRUB_CS5536_MSR_USB_CONTROLLER_BASE 0x4000000a
+#define GRUB_CS5536_MSR_USB_OPTION_CONTROLLER_BASE 0x4000000b
+#define GRUB_CS5536_MSR_USB_BASE_ADDR_MASK 0x00ffffff00ULL
+#define GRUB_CS5536_MSR_USB_BASE_SMI_ENABLE 0x3f000000000000ULL
+#define GRUB_CS5536_MSR_USB_BASE_BUS_MASTER 0x0400000000ULL
+#define GRUB_CS5536_MSR_USB_BASE_MEMORY_ENABLE 0x0200000000ULL
+#define GRUB_CS5536_MSR_USB_BASE_PME_ENABLED 0x0800000000ULL
+#define GRUB_CS5536_MSR_USB_BASE_PME_STATUS 0x1000000000ULL
+#define GRUB_CS5536_MSR_USB_EHCI_BASE_FLDJ_SHIFT 40
+
+#define GRUB_CS5536_MSR_IDE_IO_BAR 0x60000008
+#define GRUB_CS5536_MSR_IDE_IO_BAR_UNITS 1
+#define GRUB_CS5536_MSR_IDE_IO_BAR_ADDR_MASK 0xfffffff0
+#define GRUB_CS5536_MSR_IDE_CFG 0x60000010
+#define GRUB_CS5536_MSR_IDE_CFG_CHANNEL_ENABLE 2
+#define GRUB_CS5536_MSR_IDE_TIMING 0x60000012
+#define GRUB_CS5536_MSR_IDE_TIMING_PIO0 0x98
+#define GRUB_CS5536_MSR_IDE_TIMING_DRIVE0_SHIFT 24
+#define GRUB_CS5536_MSR_IDE_TIMING_DRIVE1_SHIFT 16
+#define GRUB_CS5536_MSR_IDE_CAS_TIMING 0x60000013
+#define GRUB_CS5536_MSR_IDE_CAS_TIMING_CMD_PIO0 0x99
+#define GRUB_CS5536_MSR_IDE_CAS_TIMING_CMD_SHIFT 24
+#define GRUB_CS5536_MSR_IDE_CAS_TIMING_DRIVE0_SHIFT 6
+#define GRUB_CS5536_MSR_IDE_CAS_TIMING_DRIVE1_SHIFT 4
+#define GRUB_CS5536_MSR_IDE_CAS_TIMING_PIO0 2
+
+#define GRUB_CS5536_MSR_GL_PCI_CTRL 0x00000010
+#define GRUB_CS5536_MSR_GL_PCI_CTRL_MEMORY_ENABLE 1
+#define GRUB_CS5536_MSR_GL_PCI_CTRL_IO_ENABLE 2
+#define GRUB_CS5536_MSR_GL_PCI_CTRL_LATENCY_SHIFT 35
+#define GRUB_CS5536_MSR_GL_PCI_CTRL_OUT_THR_SHIFT 60
+#define GRUB_CS5536_MSR_GL_PCI_CTRL_IN_THR_SHIFT 56
+
+#define GRUB_CS5536_MSR_GL_REGIONS_START 0x00000020
+#define GRUB_CS5536_MSR_GL_REGIONS_NUM 16
+#define GRUB_CS5536_MSR_GL_REGION_ENABLE 1
+#define GRUB_CS5536_MSR_GL_REGION_IO 0x100000000ULL
+#define GRUB_CS5536_MSR_GL_REGION_BASE_MASK 0xfffff000ULL
+#define GRUB_CS5536_MSR_GL_REGION_IO_BASE_SHIFT 12
+#define GRUB_CS5536_MSR_GL_REGION_TOP_MASK 0xfffff00000000000ULL
+#define GRUB_CS5536_MSR_GL_REGION_IO_TOP_SHIFT 44
+
+#define GRUB_CS5536_MSR_GL_P2D_START 0x00010020
+
+#define GRUB_CS5536_SMB_REG_DATA 0x0
+#define GRUB_CS5536_SMB_REG_STATUS 0x1
+#define GRUB_CS5536_SMB_REG_STATUS_SDAST (1 << 6)
+#define GRUB_CS5536_SMB_REG_STATUS_BER (1 << 5)
+#define GRUB_CS5536_SMB_REG_STATUS_NACK (1 << 4)
+#define GRUB_CS5536_SMB_REG_CTRL1 0x3
+#define GRUB_CS5536_SMB_REG_CTRL1_START 0x01
+#define GRUB_CS5536_SMB_REG_CTRL1_STOP 0x02
+#define GRUB_CS5536_SMB_REG_CTRL1_ACK 0x10
+#define GRUB_CS5536_SMB_REG_ADDR 0x4
+#define GRUB_CS5536_SMB_REG_ADDR_MASTER 0x0
+#define GRUB_CS5536_SMB_REG_CTRL2 0x5
+#define GRUB_CS5536_SMB_REG_CTRL2_ENABLE 0x1
+#define GRUB_CS5536_SMB_REG_CTRL3 0x6
+
+#ifdef ASM_FILE
+#define GRUB_ULL(x) x
+#else
+#define GRUB_ULL(x) x ## ULL
+#endif
+
+#define GRUB_CS5536_LBAR_ADDR_MASK GRUB_ULL (0x000000000000fff8)
+#define GRUB_CS5536_LBAR_ENABLE GRUB_ULL (0x0000000100000000)
+#define GRUB_CS5536_LBAR_MASK_MASK GRUB_ULL (0x0000f00000000000)
+#define GRUB_CS5536_LBAR_TURN_ON (GRUB_CS5536_LBAR_ENABLE | GRUB_CS5536_LBAR_MASK_MASK)
+
+/* PMON-compatible LBARs. */
+#define GRUB_CS5536_LBAR_GPIO 0xb000
+#define GRUB_CS5536_LBAR_ACC 0xb200
+#define GRUB_CS5536_LBAR_PM 0xb280
+#define GRUB_CS5536_LBAR_MFGPT 0xb300
+#define GRUB_CS5536_LBAR_ACPI 0xb340
+#define GRUB_CS5536_LBAR_IRQ_MAP 0xb360
+#define GRUB_CS5536_LBAR_IDE 0xb380
+#define GRUB_CS5536_LBAR_SMBUS 0xb390
+
+#define GRUB_GPIO_SMBUS_PINS ((1 << 14) | (1 << 15))
+#define GRUB_GPIO_REG_OUT_EN 0x4
+#define GRUB_GPIO_REG_OUT_AUX1 0x10
+#define GRUB_GPIO_REG_IN_EN 0x20
+#define GRUB_GPIO_REG_IN_AUX1 0x34
+
+#ifndef ASM_FILE
+int EXPORT_FUNC (grub_cs5536_find) (grub_pci_device_t *devp);
+
+grub_uint64_t EXPORT_FUNC (grub_cs5536_read_msr) (grub_pci_device_t dev,
+ grub_uint32_t addr);
+void EXPORT_FUNC (grub_cs5536_write_msr) (grub_pci_device_t dev,
+ grub_uint32_t addr,
+ grub_uint64_t val);
+grub_err_t grub_cs5536_read_spd_byte (grub_port_t smbbase, grub_uint8_t dev,
+ grub_uint8_t addr, grub_uint8_t *res);
+grub_err_t EXPORT_FUNC (grub_cs5536_read_spd) (grub_port_t smbbase,
+ grub_uint8_t dev,
+ struct grub_smbus_spd *res);
+grub_err_t grub_cs5536_smbus_wait (grub_port_t smbbase);
+grub_err_t EXPORT_FUNC (grub_cs5536_init_smbus) (grub_pci_device_t dev,
+ grub_uint16_t divisor,
+ grub_port_t *smbbase);
+
+void grub_cs5536_init_geode (grub_pci_device_t dev);
+#endif
+
+#endif
diff --git a/include/grub/datetime.h b/include/grub/datetime.h
new file mode 100644
index 0000000..23ae079
--- /dev/null
+++ b/include/grub/datetime.h
@@ -0,0 +1,133 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef KERNEL_DATETIME_HEADER
+#define KERNEL_DATETIME_HEADER 1
+
+#include <grub/types.h>
+#include <grub/err.h>
+
+struct grub_datetime
+{
+ grub_uint16_t year;
+ grub_uint8_t month;
+ grub_uint8_t day;
+ grub_uint8_t hour;
+ grub_uint8_t minute;
+ grub_uint8_t second;
+};
+
+/* Return date and time. */
+#ifdef GRUB_MACHINE_EMU
+grub_err_t EXPORT_FUNC(grub_get_datetime) (struct grub_datetime *datetime);
+
+/* Set date and time. */
+grub_err_t EXPORT_FUNC(grub_set_datetime) (struct grub_datetime *datetime);
+#else
+grub_err_t grub_get_datetime (struct grub_datetime *datetime);
+
+/* Set date and time. */
+grub_err_t grub_set_datetime (struct grub_datetime *datetime);
+#endif
+
+int grub_get_weekday (struct grub_datetime *datetime);
+const char *grub_get_weekday_name (struct grub_datetime *datetime);
+
+void grub_unixtime2datetime (grub_int64_t nix,
+ struct grub_datetime *datetime);
+
+static inline int
+grub_datetime2unixtime (const struct grub_datetime *datetime, grub_int64_t *nix)
+{
+ grub_int32_t ret;
+ int y4, ay;
+ const grub_uint16_t monthssum[12]
+ = { 0,
+ 31,
+ 31 + 28,
+ 31 + 28 + 31,
+ 31 + 28 + 31 + 30,
+ 31 + 28 + 31 + 30 + 31,
+ 31 + 28 + 31 + 30 + 31 + 30,
+ 31 + 28 + 31 + 30 + 31 + 30 + 31,
+ 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31,
+ 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30,
+ 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31,
+ 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30};
+ const grub_uint8_t months[12] = {31, 28, 31, 30, 31, 30,
+ 31, 31, 30, 31, 30, 31};
+ const int SECPERMIN = 60;
+ const int SECPERHOUR = 60 * SECPERMIN;
+ const int SECPERDAY = 24 * SECPERHOUR;
+ const int SECPERYEAR = 365 * SECPERDAY;
+ const int SECPER4YEARS = 4 * SECPERYEAR + SECPERDAY;
+
+ if (datetime->year > 2038 || datetime->year < 1901)
+ return 0;
+ if (datetime->month > 12 || datetime->month < 1)
+ return 0;
+
+ /* In the period of validity of unixtime all years divisible by 4
+ are bissextile*/
+ /* Convenience: let's have 3 consecutive non-bissextile years
+ at the beginning of the epoch. So count from 1973 instead of 1970 */
+ ret = 3 * SECPERYEAR + SECPERDAY;
+
+ /* Transform C divisions and modulos to mathematical ones */
+ y4 = ((datetime->year - 1) >> 2) - (1973 / 4);
+ ay = datetime->year - 1973 - 4 * y4;
+ ret += y4 * SECPER4YEARS;
+ ret += ay * SECPERYEAR;
+
+ ret += monthssum[datetime->month - 1] * SECPERDAY;
+ if (ay == 3 && datetime->month >= 3)
+ ret += SECPERDAY;
+
+ ret += (datetime->day - 1) * SECPERDAY;
+ if ((datetime->day > months[datetime->month - 1]
+ && (!ay || datetime->month != 2 || datetime->day != 29))
+ || datetime->day < 1)
+ return 0;
+
+ ret += datetime->hour * SECPERHOUR;
+ if (datetime->hour > 23)
+ return 0;
+ ret += datetime->minute * 60;
+ if (datetime->minute > 59)
+ return 0;
+
+ ret += datetime->second;
+ /* Accept leap seconds. */
+ if (datetime->second > 60)
+ return 0;
+
+ if ((datetime->year > 1980 && ret < 0)
+ || (datetime->year < 1960 && ret > 0))
+ return 0;
+ *nix = ret;
+ return 1;
+}
+
+#if (defined (__powerpc__) || defined (__sparc__)) && !defined (GRUB_UTIL)
+grub_err_t
+grub_get_datetime_cmos (struct grub_datetime *datetime);
+grub_err_t
+grub_set_datetime_cmos (struct grub_datetime *datetime);
+#endif
+
+#endif /* ! KERNEL_DATETIME_HEADER */
diff --git a/include/grub/decompressor.h b/include/grub/decompressor.h
new file mode 100644
index 0000000..a6eefb0
--- /dev/null
+++ b/include/grub/decompressor.h
@@ -0,0 +1,34 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_DECOMPRESSOR_HEADER
+#define GRUB_DECOMPRESSOR_HEADER 1
+
+void
+grub_decompress_core (void *src, void *dst, unsigned long srcsize,
+ unsigned long dstsize);
+
+void
+find_scratch (void *src, void *dst, unsigned long srcsize,
+ unsigned long dstsize);
+
+#define GRUB_DECOMPRESSOR_DICT_SIZE (1 << 16)
+
+extern void *grub_decompressor_scratch;
+
+#endif
diff --git a/include/grub/deflate.h b/include/grub/deflate.h
new file mode 100644
index 0000000..c87c62f
--- /dev/null
+++ b/include/grub/deflate.h
@@ -0,0 +1,30 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_DEFLATE_HEADER
+#define GRUB_DEFLATE_HEADER 1
+
+grub_ssize_t
+grub_zlib_decompress (char *inbuf, grub_size_t insize, grub_off_t off,
+ char *outbuf, grub_size_t outsize);
+
+grub_ssize_t
+grub_deflate_decompress (char *inbuf, grub_size_t insize, grub_off_t off,
+ char *outbuf, grub_size_t outsize);
+
+#endif
diff --git a/include/grub/device.h b/include/grub/device.h
new file mode 100644
index 0000000..1d1a239
--- /dev/null
+++ b/include/grub/device.h
@@ -0,0 +1,43 @@
+/* device.h - device manager */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2005,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_DEVICE_HEADER
+#define GRUB_DEVICE_HEADER 1
+
+#include <grub/symbol.h>
+#include <grub/err.h>
+
+struct grub_disk;
+struct grub_net;
+
+struct grub_device
+{
+ struct grub_disk *disk;
+ struct grub_net *net;
+};
+typedef struct grub_device *grub_device_t;
+
+typedef int (*grub_device_iterate_hook_t) (const char *name, void *data);
+
+grub_device_t EXPORT_FUNC(grub_device_open) (const char *name);
+grub_err_t EXPORT_FUNC(grub_device_close) (grub_device_t device);
+int EXPORT_FUNC(grub_device_iterate) (grub_device_iterate_hook_t hook,
+ void *hook_data);
+
+#endif /* ! GRUB_DEVICE_HEADER */
diff --git a/include/grub/disk.h b/include/grub/disk.h
new file mode 100644
index 0000000..f95aca9
--- /dev/null
+++ b/include/grub/disk.h
@@ -0,0 +1,294 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_DISK_HEADER
+#define GRUB_DISK_HEADER 1
+
+#include <config.h>
+
+#include <grub/symbol.h>
+#include <grub/err.h>
+#include <grub/types.h>
+#include <grub/device.h>
+/* For NULL. */
+#include <grub/mm.h>
+/* For ALIGN_UP. */
+#include <grub/misc.h>
+
+/* These are used to set a device id. When you add a new disk device,
+ you must define a new id for it here. */
+enum grub_disk_dev_id
+ {
+ GRUB_DISK_DEVICE_BIOSDISK_ID,
+ GRUB_DISK_DEVICE_OFDISK_ID,
+ GRUB_DISK_DEVICE_LOOPBACK_ID,
+ GRUB_DISK_DEVICE_EFIDISK_ID,
+ GRUB_DISK_DEVICE_DISKFILTER_ID,
+ GRUB_DISK_DEVICE_HOST_ID,
+ GRUB_DISK_DEVICE_ATA_ID,
+ GRUB_DISK_DEVICE_MEMDISK_ID,
+ GRUB_DISK_DEVICE_NAND_ID,
+ GRUB_DISK_DEVICE_SCSI_ID,
+ GRUB_DISK_DEVICE_CRYPTODISK_ID,
+ GRUB_DISK_DEVICE_ARCDISK_ID,
+ GRUB_DISK_DEVICE_HOSTDISK_ID,
+ GRUB_DISK_DEVICE_PROCFS_ID,
+ GRUB_DISK_DEVICE_CBFSDISK_ID,
+ GRUB_DISK_DEVICE_UBOOTDISK_ID,
+ GRUB_DISK_DEVICE_XEN,
+ GRUB_DISK_DEVICE_OBDISK_ID,
+ };
+
+struct grub_disk;
+#ifdef GRUB_UTIL
+struct grub_disk_memberlist;
+#endif
+
+typedef enum
+ {
+ GRUB_DISK_PULL_NONE,
+ GRUB_DISK_PULL_REMOVABLE,
+ GRUB_DISK_PULL_RESCAN,
+ GRUB_DISK_PULL_MAX
+ } grub_disk_pull_t;
+
+typedef int (*grub_disk_dev_iterate_hook_t) (const char *name, void *data);
+
+/* Disk device. */
+struct grub_disk_dev
+{
+ /* The device name. */
+ const char *name;
+
+ /* The device id used by the cache manager. */
+ enum grub_disk_dev_id id;
+
+ /* Call HOOK with each device name, until HOOK returns non-zero. */
+ int (*disk_iterate) (grub_disk_dev_iterate_hook_t hook, void *hook_data,
+ grub_disk_pull_t pull);
+
+ /* Open the device named NAME, and set up DISK. */
+ grub_err_t (*disk_open) (const char *name, struct grub_disk *disk);
+
+ /* Close the disk DISK. */
+ void (*disk_close) (struct grub_disk *disk);
+
+ /* Read SIZE sectors from the sector SECTOR of the disk DISK into BUF. */
+ grub_err_t (*disk_read) (struct grub_disk *disk, grub_disk_addr_t sector,
+ grub_size_t size, char *buf);
+
+ /* Write SIZE sectors from BUF into the sector SECTOR of the disk DISK. */
+ grub_err_t (*disk_write) (struct grub_disk *disk, grub_disk_addr_t sector,
+ grub_size_t size, const char *buf);
+
+#ifdef GRUB_UTIL
+ struct grub_disk_memberlist *(*disk_memberlist) (struct grub_disk *disk);
+ const char * (*disk_raidname) (struct grub_disk *disk);
+#endif
+
+ /* The next disk device. */
+ struct grub_disk_dev *next;
+};
+typedef struct grub_disk_dev *grub_disk_dev_t;
+
+extern grub_disk_dev_t EXPORT_VAR (grub_disk_dev_list);
+
+struct grub_partition;
+
+typedef void (*grub_disk_read_hook_t) (grub_disk_addr_t sector,
+ unsigned offset, unsigned length,
+ void *data);
+
+/* Disk. */
+struct grub_disk
+{
+ /* The disk name. */
+ const char *name;
+
+ /* The underlying disk device. */
+ grub_disk_dev_t dev;
+
+ /* The total number of sectors. */
+ grub_uint64_t total_sectors;
+
+ /* Logarithm of sector size. */
+ unsigned int log_sector_size;
+
+ /* Maximum number of sectors read divided by GRUB_DISK_CACHE_SIZE. */
+ unsigned int max_agglomerate;
+
+ /* The id used by the disk cache manager. */
+ unsigned long id;
+
+ /* The partition information. This is machine-specific. */
+ struct grub_partition *partition;
+
+ /* Called when a sector was read. OFFSET is between 0 and
+ the sector size minus 1, and LENGTH is between 0 and the sector size. */
+ grub_disk_read_hook_t read_hook;
+
+ /* Caller-specific data passed to the read hook. */
+ void *read_hook_data;
+
+ /* Device-specific data. */
+ void *data;
+};
+typedef struct grub_disk *grub_disk_t;
+
+#ifdef GRUB_UTIL
+struct grub_disk_memberlist
+{
+ grub_disk_t disk;
+ struct grub_disk_memberlist *next;
+};
+typedef struct grub_disk_memberlist *grub_disk_memberlist_t;
+#endif
+
+/* The sector size. */
+#define GRUB_DISK_SECTOR_SIZE 0x200
+#define GRUB_DISK_SECTOR_BITS 9
+
+/*
+ * Some drivers have problems with disks above reasonable sizes.
+ * Set max disk size at 1 EiB.
+ */
+#define GRUB_DISK_MAX_SECTORS (1ULL << (60 - GRUB_DISK_SECTOR_BITS))
+
+/* The maximum number of disk caches. */
+#define GRUB_DISK_CACHE_NUM 1021
+
+/* The size of a disk cache in 512B units. Must be at least as big as the
+ largest supported sector size, currently 16K. */
+#define GRUB_DISK_CACHE_BITS 6
+#define GRUB_DISK_CACHE_SIZE (1 << GRUB_DISK_CACHE_BITS)
+
+#define GRUB_DISK_MAX_MAX_AGGLOMERATE ((1 << (30 - GRUB_DISK_CACHE_BITS - GRUB_DISK_SECTOR_BITS)) - 1)
+
+/* Return value of grub_disk_native_sectors() in case disk size is unknown. */
+#define GRUB_DISK_SIZE_UNKNOWN 0xffffffffffffffffULL
+
+/* Convert sector number from one sector size to another. */
+static inline grub_disk_addr_t
+grub_convert_sector (grub_disk_addr_t sector,
+ grub_size_t log_sector_size_from,
+ grub_size_t log_sector_size_to)
+{
+ if (log_sector_size_from == log_sector_size_to)
+ return sector;
+ else if (log_sector_size_from < log_sector_size_to)
+ {
+ sector = ALIGN_UP (sector, 1 << (log_sector_size_to - log_sector_size_from));
+ return sector >> (log_sector_size_to - log_sector_size_from);
+ }
+ else
+ return sector << (log_sector_size_from - log_sector_size_to);
+}
+
+/* Convert to GRUB native disk sized sector from disk sized sector. */
+static inline grub_disk_addr_t
+grub_disk_from_native_sector (grub_disk_t disk, grub_disk_addr_t sector)
+{
+ return sector << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS);
+}
+
+/* This is called from the memory manager. */
+void grub_disk_cache_invalidate_all (void);
+
+void EXPORT_FUNC(grub_disk_dev_register) (grub_disk_dev_t dev);
+void EXPORT_FUNC(grub_disk_dev_unregister) (grub_disk_dev_t dev);
+static inline int
+grub_disk_dev_iterate (grub_disk_dev_iterate_hook_t hook, void *hook_data)
+{
+ grub_disk_dev_t p;
+ grub_disk_pull_t pull;
+
+ for (pull = 0; pull < GRUB_DISK_PULL_MAX; pull++)
+ for (p = grub_disk_dev_list; p; p = p->next)
+ if (p->disk_iterate && (p->disk_iterate) (hook, hook_data, pull))
+ return 1;
+
+ return 0;
+}
+
+grub_disk_t EXPORT_FUNC(grub_disk_open) (const char *name);
+void EXPORT_FUNC(grub_disk_close) (grub_disk_t disk);
+grub_err_t EXPORT_FUNC(grub_disk_read) (grub_disk_t disk,
+ grub_disk_addr_t sector,
+ grub_off_t offset,
+ grub_size_t size,
+ void *buf);
+grub_err_t grub_disk_write (grub_disk_t disk,
+ grub_disk_addr_t sector,
+ grub_off_t offset,
+ grub_size_t size,
+ const void *buf);
+extern grub_err_t (*EXPORT_VAR(grub_disk_write_weak)) (grub_disk_t disk,
+ grub_disk_addr_t sector,
+ grub_off_t offset,
+ grub_size_t size,
+ const void *buf);
+
+
+grub_uint64_t EXPORT_FUNC(grub_disk_native_sectors) (grub_disk_t disk);
+
+#if DISK_CACHE_STATS
+void
+EXPORT_FUNC(grub_disk_cache_get_performance) (unsigned long *hits, unsigned long *misses);
+#endif
+
+extern void (* EXPORT_VAR(grub_disk_firmware_fini)) (void);
+extern int EXPORT_VAR(grub_disk_firmware_is_tainted);
+
+static inline void
+grub_stop_disk_firmware (void)
+{
+ /* To prevent two drivers operating on the same disks. */
+ grub_disk_firmware_is_tainted = 1;
+ if (grub_disk_firmware_fini)
+ {
+ grub_disk_firmware_fini ();
+ grub_disk_firmware_fini = NULL;
+ }
+}
+
+/* Disk cache. */
+struct grub_disk_cache
+{
+ enum grub_disk_dev_id dev_id;
+ unsigned long disk_id;
+ grub_disk_addr_t sector;
+ char *data;
+ int lock;
+};
+
+extern struct grub_disk_cache EXPORT_VAR(grub_disk_cache_table)[GRUB_DISK_CACHE_NUM];
+
+#if defined (GRUB_UTIL)
+void grub_lvm_init (void);
+void grub_ldm_init (void);
+void grub_mdraid09_init (void);
+void grub_mdraid1x_init (void);
+void grub_diskfilter_init (void);
+void grub_lvm_fini (void);
+void grub_ldm_fini (void);
+void grub_mdraid09_fini (void);
+void grub_mdraid1x_fini (void);
+void grub_diskfilter_fini (void);
+#endif
+
+#endif /* ! GRUB_DISK_HEADER */
diff --git a/include/grub/diskfilter.h b/include/grub/diskfilter.h
new file mode 100644
index 0000000..8deb1a8
--- /dev/null
+++ b/include/grub/diskfilter.h
@@ -0,0 +1,218 @@
+/* diskfilter.h - On disk structures for RAID. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2006,2007,2008,2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_DISKFILTER_H
+#define GRUB_DISKFILTER_H 1
+
+#include <grub/types.h>
+#include <grub/list.h>
+
+enum
+ {
+ GRUB_RAID_LAYOUT_RIGHT_MASK = 1,
+ GRUB_RAID_LAYOUT_SYMMETRIC_MASK = 2,
+ GRUB_RAID_LAYOUT_MUL_FROM_POS = 4,
+
+ GRUB_RAID_LAYOUT_LEFT_ASYMMETRIC = 0,
+ GRUB_RAID_LAYOUT_RIGHT_ASYMMETRIC = GRUB_RAID_LAYOUT_RIGHT_MASK,
+ GRUB_RAID_LAYOUT_LEFT_SYMMETRIC = GRUB_RAID_LAYOUT_SYMMETRIC_MASK,
+ GRUB_RAID_LAYOUT_RIGHT_SYMMETRIC = (GRUB_RAID_LAYOUT_RIGHT_MASK
+ | GRUB_RAID_LAYOUT_SYMMETRIC_MASK)
+ };
+
+
+struct grub_diskfilter_vg {
+ char *uuid;
+ grub_size_t uuid_len;
+ /* Optional. */
+ char *name;
+ grub_uint64_t extent_size;
+ struct grub_diskfilter_pv *pvs;
+ struct grub_diskfilter_lv *lvs;
+ struct grub_diskfilter_vg *next;
+
+#ifdef GRUB_UTIL
+ struct grub_diskfilter *driver;
+#endif
+};
+
+struct grub_diskfilter_pv_id {
+ union
+ {
+ char *uuid;
+ int id;
+ };
+ grub_size_t uuidlen;
+};
+
+struct grub_diskfilter_pv {
+ struct grub_diskfilter_pv_id id;
+ /* Optional. */
+ char *name;
+ grub_disk_t disk;
+ grub_disk_addr_t part_start;
+ grub_disk_addr_t part_size;
+ grub_disk_addr_t start_sector; /* Sector number where the data area starts. */
+ struct grub_diskfilter_pv *next;
+ /* Optional. */
+ grub_uint8_t *internal_id;
+#ifdef GRUB_UTIL
+ char **partmaps;
+#endif
+};
+
+struct grub_diskfilter_lv {
+ /* Name used for disk. */
+ char *fullname;
+ char *idname;
+ /* Optional. */
+ char *name;
+ int number;
+ unsigned int segment_count;
+ grub_size_t segment_alloc;
+ grub_uint64_t size;
+ int became_readable_at;
+ int scanned;
+ int visible;
+
+ /* Pointer to segment_count segments. */
+ struct grub_diskfilter_segment *segments;
+ struct grub_diskfilter_vg *vg;
+ struct grub_diskfilter_lv *next;
+
+ /* Optional. */
+ char *internal_id;
+};
+
+struct grub_diskfilter_segment {
+ grub_uint64_t start_extent;
+ grub_uint64_t extent_count;
+ enum
+ {
+ GRUB_DISKFILTER_STRIPED = 0,
+ GRUB_DISKFILTER_MIRROR = 1,
+ GRUB_DISKFILTER_RAID4 = 4,
+ GRUB_DISKFILTER_RAID5 = 5,
+ GRUB_DISKFILTER_RAID6 = 6,
+ GRUB_DISKFILTER_RAID10 = 10,
+ } type;
+ int layout;
+ /* valid only for raid10. */
+ grub_uint64_t raid_member_size;
+
+ unsigned int node_count;
+ unsigned int node_alloc;
+ struct grub_diskfilter_node *nodes;
+
+ unsigned int stripe_size;
+};
+
+struct grub_diskfilter_node {
+ grub_disk_addr_t start;
+ /* Optional. */
+ char *name;
+ struct grub_diskfilter_pv *pv;
+ struct grub_diskfilter_lv *lv;
+};
+
+struct grub_diskfilter_vg *
+grub_diskfilter_get_vg_by_uuid (grub_size_t uuidlen, char *uuid);
+
+struct grub_diskfilter
+{
+ struct grub_diskfilter *next;
+ struct grub_diskfilter **prev;
+
+ const char *name;
+
+ struct grub_diskfilter_vg * (*detect) (grub_disk_t disk,
+ struct grub_diskfilter_pv_id *id,
+ grub_disk_addr_t *start_sector);
+};
+typedef struct grub_diskfilter *grub_diskfilter_t;
+
+extern grub_diskfilter_t grub_diskfilter_list;
+static inline void
+grub_diskfilter_register_front (grub_diskfilter_t diskfilter)
+{
+ grub_list_push (GRUB_AS_LIST_P (&grub_diskfilter_list),
+ GRUB_AS_LIST (diskfilter));
+}
+
+static inline void
+grub_diskfilter_register_back (grub_diskfilter_t diskfilter)
+{
+ grub_diskfilter_t p, *q;
+ for (q = &grub_diskfilter_list, p = *q; p; q = &p->next, p = *q);
+ diskfilter->next = NULL;
+ diskfilter->prev = q;
+ *q = diskfilter;
+}
+static inline void
+grub_diskfilter_unregister (grub_diskfilter_t diskfilter)
+{
+ grub_list_remove (GRUB_AS_LIST (diskfilter));
+}
+
+struct grub_diskfilter_vg *
+grub_diskfilter_make_raid (grub_size_t uuidlen, char *uuid, int nmemb,
+ const char *name, grub_uint64_t disk_size,
+ grub_uint64_t stripe_size,
+ int layout, int level);
+
+typedef grub_err_t (*grub_raid5_recover_func_t) (struct grub_diskfilter_segment *array,
+ int disknr, char *buf,
+ grub_disk_addr_t sector,
+ grub_size_t size);
+
+typedef grub_err_t (*grub_raid6_recover_func_t) (struct grub_diskfilter_segment *array,
+ int disknr, int p, char *buf,
+ grub_disk_addr_t sector,
+ grub_size_t size);
+
+extern grub_raid5_recover_func_t grub_raid5_recover_func;
+extern grub_raid6_recover_func_t grub_raid6_recover_func;
+
+typedef grub_err_t (* raid_recover_read_t)(void *data, int disk_nr,
+ grub_uint64_t addr, void *dest,
+ grub_size_t size);
+
+extern grub_err_t
+grub_raid6_recover_gen (void *data, grub_uint64_t nstripes, int disknr, int p,
+ char *buf, grub_uint64_t sector, grub_size_t size,
+ int layout, raid_recover_read_t read_func);
+
+grub_err_t grub_diskfilter_vg_register (struct grub_diskfilter_vg *vg);
+
+grub_err_t
+grub_diskfilter_read_node (const struct grub_diskfilter_node *node,
+ grub_disk_addr_t sector,
+ grub_size_t size, char *buf);
+
+#ifdef GRUB_UTIL
+struct grub_diskfilter_pv *
+grub_diskfilter_get_pv_from_disk (grub_disk_t disk,
+ struct grub_diskfilter_vg **vg);
+void
+grub_diskfilter_get_partmap (grub_disk_t disk,
+ void (*cb) (const char *val, void *data),
+ void *data);
+#endif
+
+#endif /* ! GRUB_RAID_H */
diff --git a/include/grub/dl.h b/include/grub/dl.h
new file mode 100644
index 0000000..b3753c9
--- /dev/null
+++ b/include/grub/dl.h
@@ -0,0 +1,311 @@
+/* dl.h - types and prototypes for loadable module support */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2004,2005,2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_DL_H
+#define GRUB_DL_H 1
+
+#include <grub/symbol.h>
+#ifndef ASM_FILE
+#include <grub/err.h>
+#include <grub/types.h>
+#include <grub/elf.h>
+#include <grub/list.h>
+#include <grub/misc.h>
+#endif
+
+/*
+ * Macros GRUB_MOD_INIT and GRUB_MOD_FINI are also used by build rules
+ * to collect module names, so we define them only when they are not
+ * defined already.
+ */
+#ifndef ASM_FILE
+
+#ifndef GRUB_MOD_INIT
+
+#if !defined (GRUB_UTIL) && !defined (GRUB_MACHINE_EMU) && !defined (GRUB_KERNEL)
+
+#define GRUB_MOD_INIT(name) \
+static void grub_mod_init (grub_dl_t mod __attribute__ ((unused))) __attribute__ ((used)); \
+static void \
+grub_mod_init (grub_dl_t mod __attribute__ ((unused)))
+
+#define GRUB_MOD_FINI(name) \
+static void grub_mod_fini (void) __attribute__ ((used)); \
+static void \
+grub_mod_fini (void)
+
+#elif defined (GRUB_KERNEL)
+
+#define GRUB_MOD_INIT(name) \
+static void grub_mod_init (grub_dl_t mod __attribute__ ((unused))) __attribute__ ((used)); \
+void \
+grub_##name##_init (void) { grub_mod_init (0); } \
+static void \
+grub_mod_init (grub_dl_t mod __attribute__ ((unused)))
+
+#define GRUB_MOD_FINI(name) \
+static void grub_mod_fini (void) __attribute__ ((used)); \
+void \
+grub_##name##_fini (void) { grub_mod_fini (); } \
+static void \
+grub_mod_fini (void)
+
+#else
+
+#define GRUB_MOD_INIT(name) \
+static void grub_mod_init (grub_dl_t mod __attribute__ ((unused))) __attribute__ ((used)); \
+void grub_##name##_init (void); \
+void \
+grub_##name##_init (void) { grub_mod_init (0); } \
+static void \
+grub_mod_init (grub_dl_t mod __attribute__ ((unused)))
+
+#define GRUB_MOD_FINI(name) \
+static void grub_mod_fini (void) __attribute__ ((used)); \
+void grub_##name##_fini (void); \
+void \
+grub_##name##_fini (void) { grub_mod_fini (); } \
+static void \
+grub_mod_fini (void)
+
+#endif
+
+#endif
+
+#endif
+
+#ifndef ASM_FILE
+#ifdef __APPLE__
+#define GRUB_MOD_SECTION(x) "_" #x ", _" #x ""
+#else
+#define GRUB_MOD_SECTION(x) "." #x
+#endif
+#else
+#ifdef __APPLE__
+#define GRUB_MOD_SECTION(x) _ ## x , _ ##x
+#else
+#define GRUB_MOD_SECTION(x) . ## x
+#endif
+#endif
+
+/* Me, Vladimir Serbinenko, hereby I add this module check as per new
+ GNU module policy. Note that this license check is informative only.
+ Modules have to be licensed under GPLv3 or GPLv3+ (optionally
+ multi-licensed under other licences as well) independently of the
+ presence of this check and solely by linking (module loading in GRUB
+ constitutes linking) and GRUB core being licensed under GPLv3+.
+ Be sure to understand your license obligations.
+*/
+#ifndef ASM_FILE
+#if GNUC_PREREQ (3,2)
+#define ATTRIBUTE_USED __used__
+#else
+#define ATTRIBUTE_USED __unused__
+#endif
+#define GRUB_MOD_LICENSE(license) \
+ static char grub_module_license[] __attribute__ ((section (GRUB_MOD_SECTION (module_license)), ATTRIBUTE_USED)) = "LICENSE=" license;
+#define GRUB_MOD_DEP(name) \
+static const char grub_module_depend_##name[] \
+ __attribute__((section(GRUB_MOD_SECTION(moddeps)), ATTRIBUTE_USED)) = #name
+#define GRUB_MOD_NAME(name) \
+static const char grub_module_name_##name[] \
+ __attribute__((section(GRUB_MOD_SECTION(modname)), __used__)) = #name
+#else
+#ifdef __APPLE__
+.macro GRUB_MOD_LICENSE
+ .section GRUB_MOD_SECTION(module_license)
+ .ascii "LICENSE="
+ .ascii $0
+ .byte 0
+.endm
+#else
+.macro GRUB_MOD_LICENSE license
+ .section GRUB_MOD_SECTION(module_license), "a"
+ .ascii "LICENSE="
+ .ascii "\license"
+ .byte 0
+.endm
+#endif
+#endif
+
+/* Under GPL license obligations you have to distribute your module
+ under GPLv3(+). However, you can also distribute the same code under
+ another license as long as GPLv3(+) version is provided.
+*/
+#define GRUB_MOD_DUAL_LICENSE(x)
+
+#ifndef ASM_FILE
+
+struct grub_dl_segment
+{
+ struct grub_dl_segment *next;
+ void *addr;
+ grub_size_t size;
+ unsigned section;
+};
+typedef struct grub_dl_segment *grub_dl_segment_t;
+
+struct grub_dl;
+
+struct grub_dl_dep
+{
+ struct grub_dl_dep *next;
+ struct grub_dl *mod;
+};
+typedef struct grub_dl_dep *grub_dl_dep_t;
+
+#ifndef GRUB_UTIL
+struct grub_dl
+{
+ char *name;
+ int ref_count;
+ int persistent;
+ grub_dl_dep_t dep;
+ grub_dl_segment_t segment;
+ Elf_Sym *symtab;
+ grub_size_t symsize;
+ void (*init) (struct grub_dl *mod);
+ void (*fini) (void);
+#if !defined (__i386__) && !defined (__x86_64__)
+ void *got;
+ void *gotptr;
+ void *tramp;
+ void *trampptr;
+#endif
+#ifdef __mips__
+ grub_uint32_t *reginfo;
+#endif
+ void *base;
+ grub_size_t sz;
+ struct grub_dl *next;
+};
+#endif
+typedef struct grub_dl *grub_dl_t;
+
+grub_dl_t grub_dl_load_file (const char *filename);
+grub_dl_t EXPORT_FUNC(grub_dl_load) (const char *name);
+grub_dl_t grub_dl_load_core (void *addr, grub_size_t size);
+grub_dl_t EXPORT_FUNC(grub_dl_load_core_noinit) (void *addr, grub_size_t size);
+int EXPORT_FUNC(grub_dl_unload) (grub_dl_t mod);
+extern void grub_dl_unload_unneeded (void);
+extern int EXPORT_FUNC(grub_dl_ref) (grub_dl_t mod);
+extern int EXPORT_FUNC(grub_dl_unref) (grub_dl_t mod);
+extern int EXPORT_FUNC(grub_dl_ref_count) (grub_dl_t mod);
+
+extern grub_dl_t EXPORT_VAR(grub_dl_head);
+
+#ifndef GRUB_UTIL
+
+#define FOR_DL_MODULES(var) FOR_LIST_ELEMENTS ((var), (grub_dl_head))
+
+#ifdef GRUB_MACHINE_EMU
+void *
+grub_osdep_dl_memalign (grub_size_t align, grub_size_t size);
+void
+grub_dl_osdep_dl_free (void *ptr);
+#endif
+
+static inline void
+grub_dl_init (grub_dl_t mod)
+{
+ if (mod->init)
+ (mod->init) (mod);
+
+ mod->next = grub_dl_head;
+ grub_dl_head = mod;
+}
+
+static inline grub_dl_t
+grub_dl_get (const char *name)
+{
+ grub_dl_t l;
+
+ FOR_DL_MODULES(l)
+ if (grub_strcmp (name, l->name) == 0)
+ return l;
+
+ return 0;
+}
+
+static inline void
+grub_dl_set_persistent (grub_dl_t mod)
+{
+ mod->persistent = 1;
+}
+
+static inline int
+grub_dl_is_persistent (grub_dl_t mod)
+{
+ return mod->persistent;
+}
+
+#endif
+
+grub_err_t grub_dl_register_symbol (const char *name, void *addr,
+ int isfunc, grub_dl_t mod);
+
+grub_err_t grub_arch_dl_check_header (void *ehdr);
+#ifndef GRUB_UTIL
+grub_err_t
+grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
+ Elf_Shdr *s, grub_dl_segment_t seg);
+#endif
+
+#if defined (_mips)
+#define GRUB_LINKER_HAVE_INIT 1
+void grub_arch_dl_init_linker (void);
+#endif
+
+#define GRUB_IA64_DL_TRAMP_ALIGN 16
+#define GRUB_IA64_DL_GOT_ALIGN 16
+
+grub_err_t
+grub_ia64_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp,
+ grub_size_t *got);
+grub_err_t
+grub_arm64_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp,
+ grub_size_t *got);
+
+#if defined (__ia64__)
+#define GRUB_ARCH_DL_TRAMP_ALIGN GRUB_IA64_DL_TRAMP_ALIGN
+#define GRUB_ARCH_DL_GOT_ALIGN GRUB_IA64_DL_GOT_ALIGN
+#define grub_arch_dl_get_tramp_got_size grub_ia64_dl_get_tramp_got_size
+#elif defined (__aarch64__)
+#define grub_arch_dl_get_tramp_got_size grub_arm64_dl_get_tramp_got_size
+#else
+grub_err_t
+grub_arch_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp,
+ grub_size_t *got);
+#endif
+
+#if defined (__powerpc__) || defined (__mips__) || defined (__arm__) || \
+ (defined(__riscv) && (__riscv_xlen == 32))
+#define GRUB_ARCH_DL_TRAMP_ALIGN 4
+#define GRUB_ARCH_DL_GOT_ALIGN 4
+#endif
+
+#if defined (__aarch64__) || defined (__sparc__) || \
+ (defined(__riscv) && (__riscv_xlen == 64))
+#define GRUB_ARCH_DL_TRAMP_ALIGN 8
+#define GRUB_ARCH_DL_GOT_ALIGN 8
+#endif
+
+#endif
+
+#endif /* ! GRUB_DL_H */
diff --git a/include/grub/dma.h b/include/grub/dma.h
new file mode 100644
index 0000000..19992eb
--- /dev/null
+++ b/include/grub/dma.h
@@ -0,0 +1,44 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_DMA_H
+#define GRUB_DMA_H 1
+
+struct grub_pci_dma_chunk;
+
+struct grub_pci_dma_chunk *EXPORT_FUNC(grub_memalign_dma32) (grub_size_t align,
+ grub_size_t size);
+void EXPORT_FUNC(grub_dma_free) (struct grub_pci_dma_chunk *ch);
+volatile void *EXPORT_FUNC(grub_dma_get_virt) (struct grub_pci_dma_chunk *ch);
+grub_uint32_t EXPORT_FUNC(grub_dma_get_phys) (struct grub_pci_dma_chunk *ch);
+
+static inline void *
+grub_dma_phys2virt (grub_uint32_t phys, struct grub_pci_dma_chunk *chunk)
+{
+ return ((grub_uint8_t *) grub_dma_get_virt (chunk)
+ + (phys - grub_dma_get_phys (chunk)));
+}
+
+static inline grub_uint32_t
+grub_dma_virt2phys (volatile void *virt, struct grub_pci_dma_chunk *chunk)
+{
+ return (((grub_uint8_t *) virt - (grub_uint8_t *) grub_dma_get_virt (chunk))
+ + grub_dma_get_phys (chunk));
+}
+
+#endif
diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h
new file mode 100644
index 0000000..f1a5221
--- /dev/null
+++ b/include/grub/efi/api.h
@@ -0,0 +1,1805 @@
+/* efi.h - declare EFI types and functions */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_EFI_API_HEADER
+#define GRUB_EFI_API_HEADER 1
+
+#include <grub/types.h>
+#include <grub/symbol.h>
+
+/* For consistency and safety, we name the EFI-defined types differently.
+ All names are transformed into lower case, _t appended, and
+ grub_efi_ prepended. */
+
+/* Constants. */
+#define GRUB_EFI_EVT_TIMER 0x80000000
+#define GRUB_EFI_EVT_RUNTIME 0x40000000
+#define GRUB_EFI_EVT_RUNTIME_CONTEXT 0x20000000
+#define GRUB_EFI_EVT_NOTIFY_WAIT 0x00000100
+#define GRUB_EFI_EVT_NOTIFY_SIGNAL 0x00000200
+#define GRUB_EFI_EVT_SIGNAL_EXIT_BOOT_SERVICES 0x00000201
+#define GRUB_EFI_EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE 0x60000202
+
+#define GRUB_EFI_TPL_APPLICATION 4
+#define GRUB_EFI_TPL_CALLBACK 8
+#define GRUB_EFI_TPL_NOTIFY 16
+#define GRUB_EFI_TPL_HIGH_LEVEL 31
+
+#define GRUB_EFI_MEMORY_UC 0x0000000000000001LL
+#define GRUB_EFI_MEMORY_WC 0x0000000000000002LL
+#define GRUB_EFI_MEMORY_WT 0x0000000000000004LL
+#define GRUB_EFI_MEMORY_WB 0x0000000000000008LL
+#define GRUB_EFI_MEMORY_UCE 0x0000000000000010LL
+#define GRUB_EFI_MEMORY_WP 0x0000000000001000LL
+#define GRUB_EFI_MEMORY_RP 0x0000000000002000LL
+#define GRUB_EFI_MEMORY_XP 0x0000000000004000LL
+#define GRUB_EFI_MEMORY_NV 0x0000000000008000LL
+#define GRUB_EFI_MEMORY_MORE_RELIABLE 0x0000000000010000LL
+#define GRUB_EFI_MEMORY_RO 0x0000000000020000LL
+#define GRUB_EFI_MEMORY_RUNTIME 0x8000000000000000LL
+
+#define GRUB_EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL 0x00000001
+#define GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL 0x00000002
+#define GRUB_EFI_OPEN_PROTOCOL_TEST_PROTOCOL 0x00000004
+#define GRUB_EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER 0x00000008
+#define GRUB_EFI_OPEN_PROTOCOL_BY_DRIVER 0x00000010
+#define GRUB_EFI_OPEN_PROTOCOL_BY_EXCLUSIVE 0x00000020
+
+#define GRUB_EFI_OS_INDICATIONS_BOOT_TO_FW_UI 0x0000000000000001ULL
+
+#define GRUB_EFI_VARIABLE_NON_VOLATILE 0x0000000000000001
+#define GRUB_EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002
+#define GRUB_EFI_VARIABLE_RUNTIME_ACCESS 0x0000000000000004
+
+#define GRUB_EFI_TIME_ADJUST_DAYLIGHT 0x01
+#define GRUB_EFI_TIME_IN_DAYLIGHT 0x02
+
+#define GRUB_EFI_UNSPECIFIED_TIMEZONE 0x07FF
+
+#define GRUB_EFI_OPTIONAL_PTR 0x00000001
+
+#define GRUB_EFI_LOADED_IMAGE_GUID \
+ { 0x5b1b31a1, 0x9562, 0x11d2, \
+ { 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \
+ }
+
+#define GRUB_EFI_DISK_IO_GUID \
+ { 0xce345171, 0xba0b, 0x11d2, \
+ { 0x8e, 0x4f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \
+ }
+
+#define GRUB_EFI_BLOCK_IO_GUID \
+ { 0x964e5b21, 0x6459, 0x11d2, \
+ { 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \
+ }
+
+#define GRUB_EFI_SERIAL_IO_GUID \
+ { 0xbb25cf6f, 0xf1d4, 0x11d2, \
+ { 0x9a, 0x0c, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0xfd } \
+ }
+
+#define GRUB_EFI_SIMPLE_NETWORK_GUID \
+ { 0xa19832b9, 0xac25, 0x11d3, \
+ { 0x9a, 0x2d, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \
+ }
+
+#define GRUB_EFI_PXE_GUID \
+ { 0x03c4e603, 0xac28, 0x11d3, \
+ { 0x9a, 0x2d, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \
+ }
+
+#define GRUB_EFI_DEVICE_PATH_GUID \
+ { 0x09576e91, 0x6d3f, 0x11d2, \
+ { 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \
+ }
+
+#define GRUB_EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID \
+ { 0x387477c1, 0x69c7, 0x11d2, \
+ { 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \
+ }
+
+#define GRUB_EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID \
+ { 0xdd9e7534, 0x7762, 0x4698, \
+ { 0x8c, 0x14, 0xf5, 0x85, 0x17, 0xa6, 0x25, 0xaa } \
+ }
+
+#define GRUB_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID \
+ { 0x387477c2, 0x69c7, 0x11d2, \
+ { 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \
+ }
+
+#define GRUB_EFI_SIMPLE_POINTER_PROTOCOL_GUID \
+ { 0x31878c87, 0xb75, 0x11d5, \
+ { 0x9a, 0x4f, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \
+ }
+
+#define GRUB_EFI_ABSOLUTE_POINTER_PROTOCOL_GUID \
+ { 0x8D59D32B, 0xC655, 0x4AE9, \
+ { 0x9B, 0x15, 0xF2, 0x59, 0x04, 0x99, 0x2A, 0x43 } \
+ }
+
+#define GRUB_EFI_DRIVER_BINDING_PROTOCOL_GUID \
+ { 0x18A031AB, 0xB443, 0x4D1A, \
+ { 0xA5, 0xC0, 0x0C, 0x09, 0x26, 0x1E, 0x9F, 0x71 } \
+ }
+
+#define GRUB_EFI_LOADED_IMAGE_PROTOCOL_GUID \
+ { 0x5B1B31A1, 0x9562, 0x11d2, \
+ { 0x8E, 0x3F, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B } \
+ }
+
+#define GRUB_EFI_LOAD_FILE_PROTOCOL_GUID \
+ { 0x56EC3091, 0x954C, 0x11d2, \
+ { 0x8E, 0x3F, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B } \
+ }
+
+#define GRUB_EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \
+ { 0x0964e5b22, 0x6459, 0x11d2, \
+ { 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \
+ }
+
+#define GRUB_EFI_TAPE_IO_PROTOCOL_GUID \
+ { 0x1e93e633, 0xd65a, 0x459e, \
+ { 0xab, 0x84, 0x93, 0xd9, 0xec, 0x26, 0x6d, 0x18 } \
+ }
+
+#define GRUB_EFI_UNICODE_COLLATION_PROTOCOL_GUID \
+ { 0x1d85cd7f, 0xf43d, 0x11d2, \
+ { 0x9a, 0x0c, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \
+ }
+
+#define GRUB_EFI_SCSI_IO_PROTOCOL_GUID \
+ { 0x932f47e6, 0x2362, 0x4002, \
+ { 0x80, 0x3e, 0x3c, 0xd5, 0x4b, 0x13, 0x8f, 0x85 } \
+ }
+
+#define GRUB_EFI_USB2_HC_PROTOCOL_GUID \
+ { 0x3e745226, 0x9818, 0x45b6, \
+ { 0xa2, 0xac, 0xd7, 0xcd, 0x0e, 0x8b, 0xa2, 0xbc } \
+ }
+
+#define GRUB_EFI_DEBUG_SUPPORT_PROTOCOL_GUID \
+ { 0x2755590C, 0x6F3C, 0x42FA, \
+ { 0x9E, 0xA4, 0xA3, 0xBA, 0x54, 0x3C, 0xDA, 0x25 } \
+ }
+
+#define GRUB_EFI_DEBUGPORT_PROTOCOL_GUID \
+ { 0xEBA4E8D2, 0x3858, 0x41EC, \
+ { 0xA2, 0x81, 0x26, 0x47, 0xBA, 0x96, 0x60, 0xD0 } \
+ }
+
+#define GRUB_EFI_DECOMPRESS_PROTOCOL_GUID \
+ { 0xd8117cfe, 0x94a6, 0x11d4, \
+ { 0x9a, 0x3a, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \
+ }
+
+#define GRUB_EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID \
+ { 0x8b843e20, 0x8132, 0x4852, \
+ { 0x90, 0xcc, 0x55, 0x1a, 0x4e, 0x4a, 0x7f, 0x1c } \
+ }
+
+#define GRUB_EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID \
+ { 0x379be4e, 0xd706, 0x437d, \
+ { 0xb0, 0x37, 0xed, 0xb8, 0x2f, 0xb7, 0x72, 0xa4 } \
+ }
+
+#define GRUB_EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL_GUID \
+ { 0x5c99a21, 0xc70f, 0x4ad2, \
+ { 0x8a, 0x5f, 0x35, 0xdf, 0x33, 0x43, 0xf5, 0x1e } \
+ }
+
+#define GRUB_EFI_ACPI_TABLE_PROTOCOL_GUID \
+ { 0xffe06bdd, 0x6107, 0x46a6, \
+ { 0x7b, 0xb2, 0x5a, 0x9c, 0x7e, 0xc5, 0x27, 0x5c} \
+ }
+
+#define GRUB_EFI_HII_CONFIG_ROUTING_PROTOCOL_GUID \
+ { 0x587e72d7, 0xcc50, 0x4f79, \
+ { 0x82, 0x09, 0xca, 0x29, 0x1f, 0xc1, 0xa1, 0x0f } \
+ }
+
+#define GRUB_EFI_HII_DATABASE_PROTOCOL_GUID \
+ { 0xef9fc172, 0xa1b2, 0x4693, \
+ { 0xb3, 0x27, 0x6d, 0x32, 0xfc, 0x41, 0x60, 0x42 } \
+ }
+
+#define GRUB_EFI_HII_STRING_PROTOCOL_GUID \
+ { 0xfd96974, 0x23aa, 0x4cdc, \
+ { 0xb9, 0xcb, 0x98, 0xd1, 0x77, 0x50, 0x32, 0x2a } \
+ }
+
+#define GRUB_EFI_HII_IMAGE_PROTOCOL_GUID \
+ { 0x31a6406a, 0x6bdf, 0x4e46, \
+ { 0xb2, 0xa2, 0xeb, 0xaa, 0x89, 0xc4, 0x9, 0x20 } \
+ }
+
+#define GRUB_EFI_HII_FONT_PROTOCOL_GUID \
+ { 0xe9ca4775, 0x8657, 0x47fc, \
+ { 0x97, 0xe7, 0x7e, 0xd6, 0x5a, 0x8, 0x43, 0x24 } \
+ }
+
+#define GRUB_EFI_HII_CONFIGURATION_ACCESS_PROTOCOL_GUID \
+ { 0x330d4706, 0xf2a0, 0x4e4f, \
+ { 0xa3, 0x69, 0xb6, 0x6f, 0xa8, 0xd5, 0x43, 0x85 } \
+ }
+
+#define GRUB_EFI_COMPONENT_NAME2_PROTOCOL_GUID \
+ { 0x6a7a5cff, 0xe8d9, 0x4f70, \
+ { 0xba, 0xda, 0x75, 0xab, 0x30, 0x25, 0xce, 0x14} \
+ }
+
+#define GRUB_EFI_USB_IO_PROTOCOL_GUID \
+ { 0x2B2F68D6, 0x0CD2, 0x44cf, \
+ { 0x8E, 0x8B, 0xBB, 0xA2, 0x0B, 0x1B, 0x5B, 0x75 } \
+ }
+
+#define GRUB_EFI_TIANO_CUSTOM_DECOMPRESS_GUID \
+ { 0xa31280ad, 0x481e, 0x41b6, \
+ { 0x95, 0xe8, 0x12, 0x7f, 0x4c, 0x98, 0x47, 0x79 } \
+ }
+
+#define GRUB_EFI_CRC32_GUIDED_SECTION_EXTRACTION_GUID \
+ { 0xfc1bcdb0, 0x7d31, 0x49aa, \
+ { 0x93, 0x6a, 0xa4, 0x60, 0x0d, 0x9d, 0xd0, 0x83 } \
+ }
+
+#define GRUB_EFI_LZMA_CUSTOM_DECOMPRESS_GUID \
+ { 0xee4e5898, 0x3914, 0x4259, \
+ { 0x9d, 0x6e, 0xdc, 0x7b, 0xd7, 0x94, 0x03, 0xcf } \
+ }
+
+#define GRUB_EFI_TSC_FREQUENCY_GUID \
+ { 0xdba6a7e3, 0xbb57, 0x4be7, \
+ { 0x8a, 0xf8, 0xd5, 0x78, 0xdb, 0x7e, 0x56, 0x87 } \
+ }
+
+#define GRUB_EFI_SYSTEM_RESOURCE_TABLE_GUID \
+ { 0xb122a263, 0x3661, 0x4f68, \
+ { 0x99, 0x29, 0x78, 0xf8, 0xb0, 0xd6, 0x21, 0x80 } \
+ }
+
+#define GRUB_EFI_DXE_SERVICES_TABLE_GUID \
+ { 0x05ad34ba, 0x6f02, 0x4214, \
+ { 0x95, 0x2e, 0x4d, 0xa0, 0x39, 0x8e, 0x2b, 0xb9 } \
+ }
+
+#define GRUB_EFI_HOB_LIST_GUID \
+ { 0x7739f24c, 0x93d7, 0x11d4, \
+ { 0x9a, 0x3a, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \
+ }
+
+#define GRUB_EFI_MEMORY_TYPE_INFORMATION_GUID \
+ { 0x4c19049f, 0x4137, 0x4dd3, \
+ { 0x9c, 0x10, 0x8b, 0x97, 0xa8, 0x3f, 0xfd, 0xfa } \
+ }
+
+#define GRUB_EFI_DEBUG_IMAGE_INFO_TABLE_GUID \
+ { 0x49152e77, 0x1ada, 0x4764, \
+ { 0xb7, 0xa2, 0x7a, 0xfe, 0xfe, 0xd9, 0x5e, 0x8b } \
+ }
+
+#define GRUB_EFI_MPS_TABLE_GUID \
+ { 0xeb9d2d2f, 0x2d88, 0x11d3, \
+ { 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \
+ }
+
+#define GRUB_EFI_ACPI_TABLE_GUID \
+ { 0xeb9d2d30, 0x2d88, 0x11d3, \
+ { 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \
+ }
+
+#define GRUB_EFI_ACPI_20_TABLE_GUID \
+ { 0x8868e871, 0xe4f1, 0x11d3, \
+ { 0xbc, 0x22, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \
+ }
+
+#define GRUB_EFI_SMBIOS_TABLE_GUID \
+ { 0xeb9d2d31, 0x2d88, 0x11d3, \
+ { 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \
+ }
+
+#define GRUB_EFI_SMBIOS3_TABLE_GUID \
+ { 0xf2fd1544, 0x9794, 0x4a2c, \
+ { 0x99, 0x2e, 0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94 } \
+ }
+
+#define GRUB_EFI_SAL_TABLE_GUID \
+ { 0xeb9d2d32, 0x2d88, 0x11d3, \
+ { 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \
+ }
+
+#define GRUB_EFI_HCDP_TABLE_GUID \
+ { 0xf951938d, 0x620b, 0x42ef, \
+ { 0x82, 0x79, 0xa8, 0x4b, 0x79, 0x61, 0x78, 0x98 } \
+ }
+
+#define GRUB_EFI_RT_PROPERTIES_TABLE_GUID \
+ { 0xeb66918a, 0x7eef, 0x402a, \
+ { 0x84, 0x2e, 0x93, 0x1d, 0x21, 0xc3, 0x8a, 0xe9 } \
+ }
+
+#define GRUB_EFI_DEVICE_TREE_GUID \
+ { 0xb1b621d5, 0xf19c, 0x41a5, \
+ { 0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0 } \
+ }
+
+#define GRUB_EFI_VENDOR_APPLE_GUID \
+ { 0x2B0585EB, 0xD8B8, 0x49A9, \
+ { 0x8B, 0x8C, 0xE2, 0x1B, 0x01, 0xAE, 0xF2, 0xB7 } \
+ }
+
+#define GRUB_EFI_SHIM_LOCK_GUID \
+ { 0x605dab50, 0xe046, 0x4300, \
+ { 0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23 } \
+ }
+
+#define GRUB_EFI_RNG_PROTOCOL_GUID \
+ { 0x3152bca5, 0xeade, 0x433d, \
+ { 0x86, 0x2e, 0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44 } \
+ }
+
+struct grub_efi_sal_system_table
+{
+ grub_uint32_t signature;
+ grub_uint32_t total_table_len;
+ grub_uint16_t sal_rev;
+ grub_uint16_t entry_count;
+ grub_uint8_t checksum;
+ grub_uint8_t reserved1[7];
+ grub_uint16_t sal_a_version;
+ grub_uint16_t sal_b_version;
+ grub_uint8_t oem_id[32];
+ grub_uint8_t product_id[32];
+ grub_uint8_t reserved2[8];
+ grub_uint8_t entries[0];
+};
+
+enum
+ {
+ GRUB_EFI_SAL_SYSTEM_TABLE_TYPE_ENTRYPOINT_DESCRIPTOR = 0,
+ GRUB_EFI_SAL_SYSTEM_TABLE_TYPE_MEMORY_DESCRIPTOR = 1,
+ GRUB_EFI_SAL_SYSTEM_TABLE_TYPE_PLATFORM_FEATURES = 2,
+ GRUB_EFI_SAL_SYSTEM_TABLE_TYPE_TRANSLATION_REGISTER_DESCRIPTOR = 3,
+ GRUB_EFI_SAL_SYSTEM_TABLE_TYPE_PURGE_TRANSLATION_COHERENCE = 4,
+ GRUB_EFI_SAL_SYSTEM_TABLE_TYPE_AP_WAKEUP = 5
+ };
+
+struct grub_efi_sal_system_table_entrypoint_descriptor
+{
+ grub_uint8_t type;
+ grub_uint8_t pad[7];
+ grub_uint64_t pal_proc_addr;
+ grub_uint64_t sal_proc_addr;
+ grub_uint64_t global_data_ptr;
+ grub_uint64_t reserved[2];
+};
+
+struct grub_efi_sal_system_table_memory_descriptor
+{
+ grub_uint8_t type;
+ grub_uint8_t sal_used;
+ grub_uint8_t attr;
+ grub_uint8_t ar;
+ grub_uint8_t attr_mask;
+ grub_uint8_t mem_type;
+ grub_uint8_t usage;
+ grub_uint8_t unknown;
+ grub_uint64_t addr;
+ grub_uint64_t len;
+ grub_uint64_t unknown2;
+};
+
+struct grub_efi_sal_system_table_platform_features
+{
+ grub_uint8_t type;
+ grub_uint8_t flags;
+ grub_uint8_t reserved[14];
+};
+
+struct grub_efi_sal_system_table_translation_register_descriptor
+{
+ grub_uint8_t type;
+ grub_uint8_t register_type;
+ grub_uint8_t register_number;
+ grub_uint8_t reserved[5];
+ grub_uint64_t addr;
+ grub_uint64_t page_size;
+ grub_uint64_t reserver;
+};
+
+struct grub_efi_sal_system_table_purge_translation_coherence
+{
+ grub_uint8_t type;
+ grub_uint8_t reserved[3];
+ grub_uint32_t ndomains;
+ grub_uint64_t coherence;
+};
+
+struct grub_efi_sal_system_table_ap_wakeup
+{
+ grub_uint8_t type;
+ grub_uint8_t mechanism;
+ grub_uint8_t reserved[6];
+ grub_uint64_t vector;
+};
+
+enum
+ {
+ GRUB_EFI_SAL_SYSTEM_TABLE_PLATFORM_FEATURE_BUSLOCK = 1,
+ GRUB_EFI_SAL_SYSTEM_TABLE_PLATFORM_FEATURE_IRQREDIRECT = 2,
+ GRUB_EFI_SAL_SYSTEM_TABLE_PLATFORM_FEATURE_IPIREDIRECT = 4,
+ GRUB_EFI_SAL_SYSTEM_TABLE_PLATFORM_FEATURE_ITCDRIFT = 8,
+ };
+
+typedef enum grub_efi_parity_type
+ {
+ GRUB_EFI_SERIAL_DEFAULT_PARITY,
+ GRUB_EFI_SERIAL_NO_PARITY,
+ GRUB_EFI_SERIAL_EVEN_PARITY,
+ GRUB_EFI_SERIAL_ODD_PARITY
+ }
+grub_efi_parity_type_t;
+
+typedef enum grub_efi_stop_bits
+ {
+ GRUB_EFI_SERIAL_DEFAULT_STOP_BITS,
+ GRUB_EFI_SERIAL_1_STOP_BIT,
+ GRUB_EFI_SERIAL_1_5_STOP_BITS,
+ GRUB_EFI_SERIAL_2_STOP_BITS
+ }
+ grub_efi_stop_bits_t;
+
+/* Enumerations. */
+enum grub_efi_timer_delay
+ {
+ GRUB_EFI_TIMER_CANCEL,
+ GRUB_EFI_TIMER_PERIODIC,
+ GRUB_EFI_TIMER_RELATIVE
+ };
+typedef enum grub_efi_timer_delay grub_efi_timer_delay_t;
+
+enum grub_efi_allocate_type
+ {
+ GRUB_EFI_ALLOCATE_ANY_PAGES,
+ GRUB_EFI_ALLOCATE_MAX_ADDRESS,
+ GRUB_EFI_ALLOCATE_ADDRESS,
+ GRUB_EFI_MAX_ALLOCATION_TYPE
+ };
+typedef enum grub_efi_allocate_type grub_efi_allocate_type_t;
+
+enum grub_efi_memory_type
+ {
+ GRUB_EFI_RESERVED_MEMORY_TYPE,
+ GRUB_EFI_LOADER_CODE,
+ GRUB_EFI_LOADER_DATA,
+ GRUB_EFI_BOOT_SERVICES_CODE,
+ GRUB_EFI_BOOT_SERVICES_DATA,
+ GRUB_EFI_RUNTIME_SERVICES_CODE,
+ GRUB_EFI_RUNTIME_SERVICES_DATA,
+ GRUB_EFI_CONVENTIONAL_MEMORY,
+ GRUB_EFI_UNUSABLE_MEMORY,
+ GRUB_EFI_ACPI_RECLAIM_MEMORY,
+ GRUB_EFI_ACPI_MEMORY_NVS,
+ GRUB_EFI_MEMORY_MAPPED_IO,
+ GRUB_EFI_MEMORY_MAPPED_IO_PORT_SPACE,
+ GRUB_EFI_PAL_CODE,
+ GRUB_EFI_PERSISTENT_MEMORY,
+ GRUB_EFI_MAX_MEMORY_TYPE
+ };
+typedef enum grub_efi_memory_type grub_efi_memory_type_t;
+
+enum grub_efi_interface_type
+ {
+ GRUB_EFI_NATIVE_INTERFACE
+ };
+typedef enum grub_efi_interface_type grub_efi_interface_type_t;
+
+enum grub_efi_locate_search_type
+ {
+ GRUB_EFI_ALL_HANDLES,
+ GRUB_EFI_BY_REGISTER_NOTIFY,
+ GRUB_EFI_BY_PROTOCOL
+ };
+typedef enum grub_efi_locate_search_type grub_efi_locate_search_type_t;
+
+enum grub_efi_reset_type
+ {
+ GRUB_EFI_RESET_COLD,
+ GRUB_EFI_RESET_WARM,
+ GRUB_EFI_RESET_SHUTDOWN
+ };
+typedef enum grub_efi_reset_type grub_efi_reset_type_t;
+
+/* Types. */
+typedef char grub_efi_boolean_t;
+#if GRUB_CPU_SIZEOF_VOID_P == 8
+typedef grub_int64_t grub_efi_intn_t;
+typedef grub_uint64_t grub_efi_uintn_t;
+#else
+typedef grub_int32_t grub_efi_intn_t;
+typedef grub_uint32_t grub_efi_uintn_t;
+#endif
+typedef grub_int8_t grub_efi_int8_t;
+typedef grub_uint8_t grub_efi_uint8_t;
+typedef grub_int16_t grub_efi_int16_t;
+typedef grub_uint16_t grub_efi_uint16_t;
+typedef grub_int32_t grub_efi_int32_t;
+typedef grub_uint32_t grub_efi_uint32_t;
+typedef grub_int64_t grub_efi_int64_t;
+typedef grub_uint64_t grub_efi_uint64_t;
+typedef grub_uint8_t grub_efi_char8_t;
+typedef grub_uint16_t grub_efi_char16_t;
+
+typedef grub_efi_uintn_t grub_efi_status_t;
+
+#define GRUB_EFI_ERROR_CODE(value) \
+ ((((grub_efi_status_t) 1) << (sizeof (grub_efi_status_t) * 8 - 1)) | (value))
+
+#define GRUB_EFI_WARNING_CODE(value) (value)
+
+#define GRUB_EFI_SUCCESS 0
+
+#define GRUB_EFI_LOAD_ERROR GRUB_EFI_ERROR_CODE (1)
+#define GRUB_EFI_INVALID_PARAMETER GRUB_EFI_ERROR_CODE (2)
+#define GRUB_EFI_UNSUPPORTED GRUB_EFI_ERROR_CODE (3)
+#define GRUB_EFI_BAD_BUFFER_SIZE GRUB_EFI_ERROR_CODE (4)
+#define GRUB_EFI_BUFFER_TOO_SMALL GRUB_EFI_ERROR_CODE (5)
+#define GRUB_EFI_NOT_READY GRUB_EFI_ERROR_CODE (6)
+#define GRUB_EFI_DEVICE_ERROR GRUB_EFI_ERROR_CODE (7)
+#define GRUB_EFI_WRITE_PROTECTED GRUB_EFI_ERROR_CODE (8)
+#define GRUB_EFI_OUT_OF_RESOURCES GRUB_EFI_ERROR_CODE (9)
+#define GRUB_EFI_VOLUME_CORRUPTED GRUB_EFI_ERROR_CODE (10)
+#define GRUB_EFI_VOLUME_FULL GRUB_EFI_ERROR_CODE (11)
+#define GRUB_EFI_NO_MEDIA GRUB_EFI_ERROR_CODE (12)
+#define GRUB_EFI_MEDIA_CHANGED GRUB_EFI_ERROR_CODE (13)
+#define GRUB_EFI_NOT_FOUND GRUB_EFI_ERROR_CODE (14)
+#define GRUB_EFI_ACCESS_DENIED GRUB_EFI_ERROR_CODE (15)
+#define GRUB_EFI_NO_RESPONSE GRUB_EFI_ERROR_CODE (16)
+#define GRUB_EFI_NO_MAPPING GRUB_EFI_ERROR_CODE (17)
+#define GRUB_EFI_TIMEOUT GRUB_EFI_ERROR_CODE (18)
+#define GRUB_EFI_NOT_STARTED GRUB_EFI_ERROR_CODE (19)
+#define GRUB_EFI_ALREADY_STARTED GRUB_EFI_ERROR_CODE (20)
+#define GRUB_EFI_ABORTED GRUB_EFI_ERROR_CODE (21)
+#define GRUB_EFI_ICMP_ERROR GRUB_EFI_ERROR_CODE (22)
+#define GRUB_EFI_TFTP_ERROR GRUB_EFI_ERROR_CODE (23)
+#define GRUB_EFI_PROTOCOL_ERROR GRUB_EFI_ERROR_CODE (24)
+#define GRUB_EFI_INCOMPATIBLE_VERSION GRUB_EFI_ERROR_CODE (25)
+#define GRUB_EFI_SECURITY_VIOLATION GRUB_EFI_ERROR_CODE (26)
+#define GRUB_EFI_CRC_ERROR GRUB_EFI_ERROR_CODE (27)
+
+#define GRUB_EFI_WARN_UNKNOWN_GLYPH GRUB_EFI_WARNING_CODE (1)
+#define GRUB_EFI_WARN_DELETE_FAILURE GRUB_EFI_WARNING_CODE (2)
+#define GRUB_EFI_WARN_WRITE_FAILURE GRUB_EFI_WARNING_CODE (3)
+#define GRUB_EFI_WARN_BUFFER_TOO_SMALL GRUB_EFI_WARNING_CODE (4)
+
+typedef void *grub_efi_handle_t;
+typedef void *grub_efi_event_t;
+typedef grub_efi_uint64_t grub_efi_lba_t;
+typedef grub_efi_uintn_t grub_efi_tpl_t;
+typedef grub_uint8_t grub_efi_mac_address_t[32];
+typedef grub_uint8_t grub_efi_ipv4_address_t[4];
+typedef grub_uint16_t grub_efi_ipv6_address_t[8];
+typedef grub_uint8_t grub_efi_ip_address_t[8] __attribute__ ((aligned(4)));
+typedef grub_efi_uint64_t grub_efi_physical_address_t;
+typedef grub_efi_uint64_t grub_efi_virtual_address_t;
+
+struct grub_efi_guid
+{
+ grub_uint32_t data1;
+ grub_uint16_t data2;
+ grub_uint16_t data3;
+ grub_uint8_t data4[8];
+} __attribute__ ((aligned(8)));
+typedef struct grub_efi_guid grub_efi_guid_t;
+
+struct grub_efi_packed_guid
+{
+ grub_uint32_t data1;
+ grub_uint16_t data2;
+ grub_uint16_t data3;
+ grub_uint8_t data4[8];
+} GRUB_PACKED;
+typedef struct grub_efi_packed_guid grub_efi_packed_guid_t;
+
+/* XXX although the spec does not specify the padding, this actually
+ must have the padding! */
+struct grub_efi_memory_descriptor
+{
+ grub_efi_uint32_t type;
+ grub_efi_uint32_t padding;
+ grub_efi_physical_address_t physical_start;
+ grub_efi_virtual_address_t virtual_start;
+ grub_efi_uint64_t num_pages;
+ grub_efi_uint64_t attribute;
+} GRUB_PACKED;
+typedef struct grub_efi_memory_descriptor grub_efi_memory_descriptor_t;
+
+/* Device Path definitions. */
+struct grub_efi_device_path
+{
+ grub_efi_uint8_t type;
+ grub_efi_uint8_t subtype;
+ grub_efi_uint16_t length;
+} GRUB_PACKED;
+typedef struct grub_efi_device_path grub_efi_device_path_t;
+/* XXX EFI does not define EFI_DEVICE_PATH_PROTOCOL but uses it.
+ It seems to be identical to EFI_DEVICE_PATH. */
+typedef struct grub_efi_device_path grub_efi_device_path_protocol_t;
+
+#define GRUB_EFI_DEVICE_PATH_TYPE(dp) ((dp)->type & 0x7f)
+#define GRUB_EFI_DEVICE_PATH_SUBTYPE(dp) ((dp)->subtype)
+#define GRUB_EFI_DEVICE_PATH_LENGTH(dp) ((dp)->length)
+#define GRUB_EFI_DEVICE_PATH_VALID(dp) ((dp) != NULL && GRUB_EFI_DEVICE_PATH_LENGTH (dp) >= 4)
+
+/* The End of Device Path nodes. */
+#define GRUB_EFI_END_DEVICE_PATH_TYPE (0xff & 0x7f)
+
+#define GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE 0xff
+#define GRUB_EFI_END_THIS_DEVICE_PATH_SUBTYPE 0x01
+
+#define GRUB_EFI_END_ENTIRE_DEVICE_PATH(dp) \
+ (!GRUB_EFI_DEVICE_PATH_VALID (dp) || \
+ (GRUB_EFI_DEVICE_PATH_TYPE (dp) == GRUB_EFI_END_DEVICE_PATH_TYPE \
+ && (GRUB_EFI_DEVICE_PATH_SUBTYPE (dp) \
+ == GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE)))
+
+#define GRUB_EFI_NEXT_DEVICE_PATH(dp) \
+ (GRUB_EFI_DEVICE_PATH_VALID (dp) \
+ ? ((grub_efi_device_path_t *) \
+ ((char *) (dp) + GRUB_EFI_DEVICE_PATH_LENGTH (dp))) \
+ : NULL)
+
+/* Hardware Device Path. */
+#define GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE 1
+
+#define GRUB_EFI_PCI_DEVICE_PATH_SUBTYPE 1
+
+struct grub_efi_pci_device_path
+{
+ grub_efi_device_path_t header;
+ grub_efi_uint8_t function;
+ grub_efi_uint8_t device;
+} GRUB_PACKED;
+typedef struct grub_efi_pci_device_path grub_efi_pci_device_path_t;
+
+#define GRUB_EFI_PCCARD_DEVICE_PATH_SUBTYPE 2
+
+struct grub_efi_pccard_device_path
+{
+ grub_efi_device_path_t header;
+ grub_efi_uint8_t function;
+} GRUB_PACKED;
+typedef struct grub_efi_pccard_device_path grub_efi_pccard_device_path_t;
+
+#define GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE 3
+
+struct grub_efi_memory_mapped_device_path
+{
+ grub_efi_device_path_t header;
+ grub_efi_uint32_t memory_type;
+ grub_efi_physical_address_t start_address;
+ grub_efi_physical_address_t end_address;
+} GRUB_PACKED;
+typedef struct grub_efi_memory_mapped_device_path grub_efi_memory_mapped_device_path_t;
+
+#define GRUB_EFI_VENDOR_DEVICE_PATH_SUBTYPE 4
+
+struct grub_efi_vendor_device_path
+{
+ grub_efi_device_path_t header;
+ grub_efi_packed_guid_t vendor_guid;
+ grub_efi_uint8_t vendor_defined_data[0];
+} GRUB_PACKED;
+typedef struct grub_efi_vendor_device_path grub_efi_vendor_device_path_t;
+
+#define GRUB_EFI_CONTROLLER_DEVICE_PATH_SUBTYPE 5
+
+struct grub_efi_controller_device_path
+{
+ grub_efi_device_path_t header;
+ grub_efi_uint32_t controller_number;
+} GRUB_PACKED;
+typedef struct grub_efi_controller_device_path grub_efi_controller_device_path_t;
+
+/* ACPI Device Path. */
+#define GRUB_EFI_ACPI_DEVICE_PATH_TYPE 2
+
+#define GRUB_EFI_ACPI_DEVICE_PATH_SUBTYPE 1
+
+struct grub_efi_acpi_device_path
+{
+ grub_efi_device_path_t header;
+ grub_efi_uint32_t hid;
+ grub_efi_uint32_t uid;
+} GRUB_PACKED;
+typedef struct grub_efi_acpi_device_path grub_efi_acpi_device_path_t;
+
+#define GRUB_EFI_EXPANDED_ACPI_DEVICE_PATH_SUBTYPE 2
+
+struct grub_efi_expanded_acpi_device_path
+{
+ grub_efi_device_path_t header;
+ grub_efi_uint32_t hid;
+ grub_efi_uint32_t uid;
+ grub_efi_uint32_t cid;
+ char hidstr[0];
+} GRUB_PACKED;
+typedef struct grub_efi_expanded_acpi_device_path grub_efi_expanded_acpi_device_path_t;
+
+#define GRUB_EFI_EXPANDED_ACPI_HIDSTR(dp) \
+ (((grub_efi_expanded_acpi_device_path_t *) dp)->hidstr)
+#define GRUB_EFI_EXPANDED_ACPI_UIDSTR(dp) \
+ (GRUB_EFI_EXPANDED_ACPI_HIDSTR(dp) \
+ + grub_strlen (GRUB_EFI_EXPANDED_ACPI_HIDSTR(dp)) + 1)
+#define GRUB_EFI_EXPANDED_ACPI_CIDSTR(dp) \
+ (GRUB_EFI_EXPANDED_ACPI_UIDSTR(dp) \
+ + grub_strlen (GRUB_EFI_EXPANDED_ACPI_UIDSTR(dp)) + 1)
+
+/* Messaging Device Path. */
+#define GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE 3
+
+#define GRUB_EFI_ATAPI_DEVICE_PATH_SUBTYPE 1
+
+struct grub_efi_atapi_device_path
+{
+ grub_efi_device_path_t header;
+ grub_efi_uint8_t primary_secondary;
+ grub_efi_uint8_t slave_master;
+ grub_efi_uint16_t lun;
+} GRUB_PACKED;
+typedef struct grub_efi_atapi_device_path grub_efi_atapi_device_path_t;
+
+#define GRUB_EFI_SCSI_DEVICE_PATH_SUBTYPE 2
+
+struct grub_efi_scsi_device_path
+{
+ grub_efi_device_path_t header;
+ grub_efi_uint16_t pun;
+ grub_efi_uint16_t lun;
+} GRUB_PACKED;
+typedef struct grub_efi_scsi_device_path grub_efi_scsi_device_path_t;
+
+#define GRUB_EFI_FIBRE_CHANNEL_DEVICE_PATH_SUBTYPE 3
+
+struct grub_efi_fibre_channel_device_path
+{
+ grub_efi_device_path_t header;
+ grub_efi_uint32_t reserved;
+ grub_efi_uint64_t wwn;
+ grub_efi_uint64_t lun;
+} GRUB_PACKED;
+typedef struct grub_efi_fibre_channel_device_path grub_efi_fibre_channel_device_path_t;
+
+#define GRUB_EFI_1394_DEVICE_PATH_SUBTYPE 4
+
+struct grub_efi_1394_device_path
+{
+ grub_efi_device_path_t header;
+ grub_efi_uint32_t reserved;
+ grub_efi_uint64_t guid;
+} GRUB_PACKED;
+typedef struct grub_efi_1394_device_path grub_efi_1394_device_path_t;
+
+#define GRUB_EFI_USB_DEVICE_PATH_SUBTYPE 5
+
+struct grub_efi_usb_device_path
+{
+ grub_efi_device_path_t header;
+ grub_efi_uint8_t parent_port_number;
+ grub_efi_uint8_t usb_interface;
+} GRUB_PACKED;
+typedef struct grub_efi_usb_device_path grub_efi_usb_device_path_t;
+
+#define GRUB_EFI_USB_CLASS_DEVICE_PATH_SUBTYPE 15
+
+struct grub_efi_usb_class_device_path
+{
+ grub_efi_device_path_t header;
+ grub_efi_uint16_t vendor_id;
+ grub_efi_uint16_t product_id;
+ grub_efi_uint8_t device_class;
+ grub_efi_uint8_t device_subclass;
+ grub_efi_uint8_t device_protocol;
+} GRUB_PACKED;
+typedef struct grub_efi_usb_class_device_path grub_efi_usb_class_device_path_t;
+
+#define GRUB_EFI_I2O_DEVICE_PATH_SUBTYPE 6
+
+struct grub_efi_i2o_device_path
+{
+ grub_efi_device_path_t header;
+ grub_efi_uint32_t tid;
+} GRUB_PACKED;
+typedef struct grub_efi_i2o_device_path grub_efi_i2o_device_path_t;
+
+#define GRUB_EFI_MAC_ADDRESS_DEVICE_PATH_SUBTYPE 11
+
+struct grub_efi_mac_address_device_path
+{
+ grub_efi_device_path_t header;
+ grub_efi_mac_address_t mac_address;
+ grub_efi_uint8_t if_type;
+} GRUB_PACKED;
+typedef struct grub_efi_mac_address_device_path grub_efi_mac_address_device_path_t;
+
+#define GRUB_EFI_IPV4_DEVICE_PATH_SUBTYPE 12
+
+struct grub_efi_ipv4_device_path
+{
+ grub_efi_device_path_t header;
+ grub_efi_ipv4_address_t local_ip_address;
+ grub_efi_ipv4_address_t remote_ip_address;
+ grub_efi_uint16_t local_port;
+ grub_efi_uint16_t remote_port;
+ grub_efi_uint16_t protocol;
+ grub_efi_uint8_t static_ip_address;
+} GRUB_PACKED;
+typedef struct grub_efi_ipv4_device_path grub_efi_ipv4_device_path_t;
+
+#define GRUB_EFI_IPV6_DEVICE_PATH_SUBTYPE 13
+
+struct grub_efi_ipv6_device_path
+{
+ grub_efi_device_path_t header;
+ grub_efi_ipv6_address_t local_ip_address;
+ grub_efi_ipv6_address_t remote_ip_address;
+ grub_efi_uint16_t local_port;
+ grub_efi_uint16_t remote_port;
+ grub_efi_uint16_t protocol;
+ grub_efi_uint8_t static_ip_address;
+} GRUB_PACKED;
+typedef struct grub_efi_ipv6_device_path grub_efi_ipv6_device_path_t;
+
+#define GRUB_EFI_INFINIBAND_DEVICE_PATH_SUBTYPE 9
+
+struct grub_efi_infiniband_device_path
+{
+ grub_efi_device_path_t header;
+ grub_efi_uint32_t resource_flags;
+ grub_efi_uint8_t port_gid[16];
+ grub_efi_uint64_t remote_id;
+ grub_efi_uint64_t target_port_id;
+ grub_efi_uint64_t device_id;
+} GRUB_PACKED;
+typedef struct grub_efi_infiniband_device_path grub_efi_infiniband_device_path_t;
+
+#define GRUB_EFI_UART_DEVICE_PATH_SUBTYPE 14
+
+struct grub_efi_uart_device_path
+{
+ grub_efi_device_path_t header;
+ grub_efi_uint32_t reserved;
+ grub_efi_uint64_t baud_rate;
+ grub_efi_uint8_t data_bits;
+ grub_efi_uint8_t parity;
+ grub_efi_uint8_t stop_bits;
+} GRUB_PACKED;
+typedef struct grub_efi_uart_device_path grub_efi_uart_device_path_t;
+
+#define GRUB_EFI_SATA_DEVICE_PATH_SUBTYPE 18
+
+struct grub_efi_sata_device_path
+{
+ grub_efi_device_path_t header;
+ grub_efi_uint16_t hba_port;
+ grub_efi_uint16_t multiplier_port;
+ grub_efi_uint16_t lun;
+} GRUB_PACKED;
+typedef struct grub_efi_sata_device_path grub_efi_sata_device_path_t;
+
+#define GRUB_EFI_VENDOR_MESSAGING_DEVICE_PATH_SUBTYPE 10
+
+/* Media Device Path. */
+#define GRUB_EFI_MEDIA_DEVICE_PATH_TYPE 4
+
+#define GRUB_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE 1
+
+struct grub_efi_hard_drive_device_path
+{
+ grub_efi_device_path_t header;
+ grub_efi_uint32_t partition_number;
+ grub_efi_lba_t partition_start;
+ grub_efi_lba_t partition_size;
+ grub_efi_uint8_t partition_signature[16];
+ grub_efi_uint8_t partmap_type;
+ grub_efi_uint8_t signature_type;
+} GRUB_PACKED;
+typedef struct grub_efi_hard_drive_device_path grub_efi_hard_drive_device_path_t;
+
+#define GRUB_EFI_CDROM_DEVICE_PATH_SUBTYPE 2
+
+struct grub_efi_cdrom_device_path
+{
+ grub_efi_device_path_t header;
+ grub_efi_uint32_t boot_entry;
+ grub_efi_lba_t partition_start;
+ grub_efi_lba_t partition_size;
+} GRUB_PACKED;
+typedef struct grub_efi_cdrom_device_path grub_efi_cdrom_device_path_t;
+
+#define GRUB_EFI_VENDOR_MEDIA_DEVICE_PATH_SUBTYPE 3
+
+struct grub_efi_vendor_media_device_path
+{
+ grub_efi_device_path_t header;
+ grub_efi_packed_guid_t vendor_guid;
+ grub_efi_uint8_t vendor_defined_data[0];
+} GRUB_PACKED;
+typedef struct grub_efi_vendor_media_device_path grub_efi_vendor_media_device_path_t;
+
+#define GRUB_EFI_FILE_PATH_DEVICE_PATH_SUBTYPE 4
+
+struct grub_efi_file_path_device_path
+{
+ grub_efi_device_path_t header;
+ grub_efi_char16_t path_name[0];
+} GRUB_PACKED;
+typedef struct grub_efi_file_path_device_path grub_efi_file_path_device_path_t;
+
+#define GRUB_EFI_PROTOCOL_DEVICE_PATH_SUBTYPE 5
+
+struct grub_efi_protocol_device_path
+{
+ grub_efi_device_path_t header;
+ grub_efi_packed_guid_t guid;
+} GRUB_PACKED;
+typedef struct grub_efi_protocol_device_path grub_efi_protocol_device_path_t;
+
+#define GRUB_EFI_PIWG_DEVICE_PATH_SUBTYPE 6
+
+struct grub_efi_piwg_device_path
+{
+ grub_efi_device_path_t header;
+ grub_efi_packed_guid_t guid;
+} GRUB_PACKED;
+typedef struct grub_efi_piwg_device_path grub_efi_piwg_device_path_t;
+
+
+/* BIOS Boot Specification Device Path. */
+#define GRUB_EFI_BIOS_DEVICE_PATH_TYPE 5
+
+#define GRUB_EFI_BIOS_DEVICE_PATH_SUBTYPE 1
+
+struct grub_efi_bios_device_path
+{
+ grub_efi_device_path_t header;
+ grub_efi_uint16_t device_type;
+ grub_efi_uint16_t status_flags;
+ char description[0];
+} GRUB_PACKED;
+typedef struct grub_efi_bios_device_path grub_efi_bios_device_path_t;
+
+struct grub_efi_open_protocol_information_entry
+{
+ grub_efi_handle_t agent_handle;
+ grub_efi_handle_t controller_handle;
+ grub_efi_uint32_t attributes;
+ grub_efi_uint32_t open_count;
+};
+typedef struct grub_efi_open_protocol_information_entry grub_efi_open_protocol_information_entry_t;
+
+struct grub_efi_time
+{
+ grub_efi_uint16_t year;
+ grub_efi_uint8_t month;
+ grub_efi_uint8_t day;
+ grub_efi_uint8_t hour;
+ grub_efi_uint8_t minute;
+ grub_efi_uint8_t second;
+ grub_efi_uint8_t pad1;
+ grub_efi_uint32_t nanosecond;
+ grub_efi_int16_t time_zone;
+ grub_efi_uint8_t daylight;
+ grub_efi_uint8_t pad2;
+} GRUB_PACKED;
+typedef struct grub_efi_time grub_efi_time_t;
+
+struct grub_efi_time_capabilities
+{
+ grub_efi_uint32_t resolution;
+ grub_efi_uint32_t accuracy;
+ grub_efi_boolean_t sets_to_zero;
+};
+typedef struct grub_efi_time_capabilities grub_efi_time_capabilities_t;
+
+struct grub_efi_input_key
+{
+ grub_efi_uint16_t scan_code;
+ grub_efi_char16_t unicode_char;
+};
+typedef struct grub_efi_input_key grub_efi_input_key_t;
+
+typedef grub_efi_uint8_t grub_efi_key_toggle_state_t;
+struct grub_efi_key_state
+{
+ grub_efi_uint32_t key_shift_state;
+ grub_efi_key_toggle_state_t key_toggle_state;
+};
+typedef struct grub_efi_key_state grub_efi_key_state_t;
+
+#define GRUB_EFI_SHIFT_STATE_VALID 0x80000000
+#define GRUB_EFI_RIGHT_SHIFT_PRESSED 0x00000001
+#define GRUB_EFI_LEFT_SHIFT_PRESSED 0x00000002
+#define GRUB_EFI_RIGHT_CONTROL_PRESSED 0x00000004
+#define GRUB_EFI_LEFT_CONTROL_PRESSED 0x00000008
+#define GRUB_EFI_RIGHT_ALT_PRESSED 0x00000010
+#define GRUB_EFI_LEFT_ALT_PRESSED 0x00000020
+#define GRUB_EFI_RIGHT_LOGO_PRESSED 0x00000040
+#define GRUB_EFI_LEFT_LOGO_PRESSED 0x00000080
+#define GRUB_EFI_MENU_KEY_PRESSED 0x00000100
+#define GRUB_EFI_SYS_REQ_PRESSED 0x00000200
+
+#define GRUB_EFI_TOGGLE_STATE_VALID 0x80
+#define GRUB_EFI_KEY_STATE_EXPOSED 0x40
+#define GRUB_EFI_SCROLL_LOCK_ACTIVE 0x01
+#define GRUB_EFI_NUM_LOCK_ACTIVE 0x02
+#define GRUB_EFI_CAPS_LOCK_ACTIVE 0x04
+
+struct grub_efi_simple_text_output_mode
+{
+ grub_efi_int32_t max_mode;
+ grub_efi_int32_t mode;
+ grub_efi_int32_t attribute;
+ grub_efi_int32_t cursor_column;
+ grub_efi_int32_t cursor_row;
+ grub_efi_boolean_t cursor_visible;
+};
+typedef struct grub_efi_simple_text_output_mode grub_efi_simple_text_output_mode_t;
+
+/* Tables. */
+struct grub_efi_table_header
+{
+ grub_efi_uint64_t signature;
+ grub_efi_uint32_t revision;
+ grub_efi_uint32_t header_size;
+ grub_efi_uint32_t crc32;
+ grub_efi_uint32_t reserved;
+};
+typedef struct grub_efi_table_header grub_efi_table_header_t;
+
+struct grub_efi_boot_services
+{
+ grub_efi_table_header_t hdr;
+
+ grub_efi_tpl_t
+ (*raise_tpl) (grub_efi_tpl_t new_tpl);
+
+ void
+ (*restore_tpl) (grub_efi_tpl_t old_tpl);
+
+ grub_efi_status_t
+ (*allocate_pages) (grub_efi_allocate_type_t type,
+ grub_efi_memory_type_t memory_type,
+ grub_efi_uintn_t pages,
+ grub_efi_physical_address_t *memory);
+
+ grub_efi_status_t
+ (*free_pages) (grub_efi_physical_address_t memory,
+ grub_efi_uintn_t pages);
+
+ grub_efi_status_t
+ (*get_memory_map) (grub_efi_uintn_t *memory_map_size,
+ grub_efi_memory_descriptor_t *memory_map,
+ grub_efi_uintn_t *map_key,
+ grub_efi_uintn_t *descriptor_size,
+ grub_efi_uint32_t *descriptor_version);
+
+ grub_efi_status_t
+ (*allocate_pool) (grub_efi_memory_type_t pool_type,
+ grub_efi_uintn_t size,
+ void **buffer);
+
+ grub_efi_status_t
+ (*free_pool) (void *buffer);
+
+ grub_efi_status_t
+ (*create_event) (grub_efi_uint32_t type,
+ grub_efi_tpl_t notify_tpl,
+ void (*notify_function) (grub_efi_event_t event,
+ void *context),
+ void *notify_context,
+ grub_efi_event_t *event);
+
+ grub_efi_status_t
+ (*set_timer) (grub_efi_event_t event,
+ grub_efi_timer_delay_t type,
+ grub_efi_uint64_t trigger_time);
+
+ grub_efi_status_t
+ (*wait_for_event) (grub_efi_uintn_t num_events,
+ grub_efi_event_t *event,
+ grub_efi_uintn_t *index);
+
+ grub_efi_status_t
+ (*signal_event) (grub_efi_event_t event);
+
+ grub_efi_status_t
+ (*close_event) (grub_efi_event_t event);
+
+ grub_efi_status_t
+ (*check_event) (grub_efi_event_t event);
+
+ grub_efi_status_t
+ (*install_protocol_interface) (grub_efi_handle_t *handle,
+ grub_efi_guid_t *protocol,
+ grub_efi_interface_type_t protocol_interface_type,
+ void *protocol_interface);
+
+ grub_efi_status_t
+ (*reinstall_protocol_interface) (grub_efi_handle_t handle,
+ grub_efi_guid_t *protocol,
+ void *old_interface,
+ void *new_interface);
+
+ grub_efi_status_t
+ (*uninstall_protocol_interface) (grub_efi_handle_t handle,
+ grub_efi_guid_t *protocol,
+ void *protocol_interface);
+
+ grub_efi_status_t
+ (*handle_protocol) (grub_efi_handle_t handle,
+ grub_efi_guid_t *protocol,
+ void **protocol_interface);
+
+ void *reserved;
+
+ grub_efi_status_t
+ (*register_protocol_notify) (grub_efi_guid_t *protocol,
+ grub_efi_event_t event,
+ void **registration);
+
+ grub_efi_status_t
+ (*locate_handle) (grub_efi_locate_search_type_t search_type,
+ grub_efi_guid_t *protocol,
+ void *search_key,
+ grub_efi_uintn_t *buffer_size,
+ grub_efi_handle_t *buffer);
+
+ grub_efi_status_t
+ (*locate_device_path) (grub_efi_guid_t *protocol,
+ grub_efi_device_path_t **device_path,
+ grub_efi_handle_t *device);
+
+ grub_efi_status_t
+ (*install_configuration_table) (grub_efi_guid_t *guid, void *table);
+
+ grub_efi_status_t
+ (*load_image) (grub_efi_boolean_t boot_policy,
+ grub_efi_handle_t parent_image_handle,
+ grub_efi_device_path_t *file_path,
+ void *source_buffer,
+ grub_efi_uintn_t source_size,
+ grub_efi_handle_t *image_handle);
+
+ grub_efi_status_t
+ (*start_image) (grub_efi_handle_t image_handle,
+ grub_efi_uintn_t *exit_data_size,
+ grub_efi_char16_t **exit_data);
+
+ grub_efi_status_t
+ (*exit) (grub_efi_handle_t image_handle,
+ grub_efi_status_t exit_status,
+ grub_efi_uintn_t exit_data_size,
+ grub_efi_char16_t *exit_data) __attribute__((noreturn));
+
+ grub_efi_status_t
+ (*unload_image) (grub_efi_handle_t image_handle);
+
+ grub_efi_status_t
+ (*exit_boot_services) (grub_efi_handle_t image_handle,
+ grub_efi_uintn_t map_key);
+
+ grub_efi_status_t
+ (*get_next_monotonic_count) (grub_efi_uint64_t *count);
+
+ grub_efi_status_t
+ (*stall) (grub_efi_uintn_t microseconds);
+
+ grub_efi_status_t
+ (*set_watchdog_timer) (grub_efi_uintn_t timeout,
+ grub_efi_uint64_t watchdog_code,
+ grub_efi_uintn_t data_size,
+ grub_efi_char16_t *watchdog_data);
+
+ grub_efi_status_t
+ (*connect_controller) (grub_efi_handle_t controller_handle,
+ grub_efi_handle_t *driver_image_handle,
+ grub_efi_device_path_protocol_t *remaining_device_path,
+ grub_efi_boolean_t recursive);
+
+ grub_efi_status_t
+ (*disconnect_controller) (grub_efi_handle_t controller_handle,
+ grub_efi_handle_t driver_image_handle,
+ grub_efi_handle_t child_handle);
+
+ grub_efi_status_t
+ (*open_protocol) (grub_efi_handle_t handle,
+ grub_efi_guid_t *protocol,
+ void **protocol_interface,
+ grub_efi_handle_t agent_handle,
+ grub_efi_handle_t controller_handle,
+ grub_efi_uint32_t attributes);
+
+ grub_efi_status_t
+ (*close_protocol) (grub_efi_handle_t handle,
+ grub_efi_guid_t *protocol,
+ grub_efi_handle_t agent_handle,
+ grub_efi_handle_t controller_handle);
+
+ grub_efi_status_t
+ (*open_protocol_information) (grub_efi_handle_t handle,
+ grub_efi_guid_t *protocol,
+ grub_efi_open_protocol_information_entry_t **entry_buffer,
+ grub_efi_uintn_t *entry_count);
+
+ grub_efi_status_t
+ (*protocols_per_handle) (grub_efi_handle_t handle,
+ grub_efi_packed_guid_t ***protocol_buffer,
+ grub_efi_uintn_t *protocol_buffer_count);
+
+ grub_efi_status_t
+ (*locate_handle_buffer) (grub_efi_locate_search_type_t search_type,
+ grub_efi_guid_t *protocol,
+ void *search_key,
+ grub_efi_uintn_t *no_handles,
+ grub_efi_handle_t **buffer);
+
+ grub_efi_status_t
+ (*locate_protocol) (grub_efi_guid_t *protocol,
+ void *registration,
+ void **protocol_interface);
+
+ grub_efi_status_t
+ (*install_multiple_protocol_interfaces) (grub_efi_handle_t *handle, ...);
+
+ grub_efi_status_t
+ (*uninstall_multiple_protocol_interfaces) (grub_efi_handle_t handle, ...);
+
+ grub_efi_status_t
+ (*calculate_crc32) (void *data,
+ grub_efi_uintn_t data_size,
+ grub_efi_uint32_t *crc32);
+
+ void
+ (*copy_mem) (void *destination, void *source, grub_efi_uintn_t length);
+
+ void
+ (*set_mem) (void *buffer, grub_efi_uintn_t size, grub_efi_uint8_t value);
+};
+typedef struct grub_efi_boot_services grub_efi_boot_services_t;
+
+struct grub_efi_runtime_services
+{
+ grub_efi_table_header_t hdr;
+
+ grub_efi_status_t
+ (*get_time) (grub_efi_time_t *time,
+ grub_efi_time_capabilities_t *capabilities);
+
+ grub_efi_status_t
+ (*set_time) (grub_efi_time_t *time);
+
+ grub_efi_status_t
+ (*get_wakeup_time) (grub_efi_boolean_t *enabled,
+ grub_efi_boolean_t *pending,
+ grub_efi_time_t *time);
+
+ grub_efi_status_t
+ (*set_wakeup_time) (grub_efi_boolean_t enabled,
+ grub_efi_time_t *time);
+
+ grub_efi_status_t
+ (*set_virtual_address_map) (grub_efi_uintn_t memory_map_size,
+ grub_efi_uintn_t descriptor_size,
+ grub_efi_uint32_t descriptor_version,
+ grub_efi_memory_descriptor_t *virtual_map);
+
+ grub_efi_status_t
+ (*convert_pointer) (grub_efi_uintn_t debug_disposition, void **address);
+
+#define GRUB_EFI_GLOBAL_VARIABLE_GUID \
+ { 0x8BE4DF61, 0x93CA, 0x11d2, { 0xAA, 0x0D, 0x00, 0xE0, 0x98, 0x03, 0x2B, 0x8C }}
+
+
+ grub_efi_status_t
+ (*get_variable) (grub_efi_char16_t *variable_name,
+ const grub_efi_guid_t *vendor_guid,
+ grub_efi_uint32_t *attributes,
+ grub_efi_uintn_t *data_size,
+ void *data);
+
+ grub_efi_status_t
+ (*get_next_variable_name) (grub_efi_uintn_t *variable_name_size,
+ grub_efi_char16_t *variable_name,
+ grub_efi_guid_t *vendor_guid);
+
+ grub_efi_status_t
+ (*set_variable) (grub_efi_char16_t *variable_name,
+ const grub_efi_guid_t *vendor_guid,
+ grub_efi_uint32_t attributes,
+ grub_efi_uintn_t data_size,
+ void *data);
+
+ grub_efi_status_t
+ (*get_next_high_monotonic_count) (grub_efi_uint32_t *high_count);
+
+ void
+ (*reset_system) (grub_efi_reset_type_t reset_type,
+ grub_efi_status_t reset_status,
+ grub_efi_uintn_t data_size,
+ grub_efi_char16_t *reset_data);
+};
+typedef struct grub_efi_runtime_services grub_efi_runtime_services_t;
+
+struct grub_efi_configuration_table
+{
+ grub_efi_packed_guid_t vendor_guid;
+ void *vendor_table;
+} GRUB_PACKED;
+typedef struct grub_efi_configuration_table grub_efi_configuration_table_t;
+
+#define GRUB_EFIEMU_SYSTEM_TABLE_SIGNATURE 0x5453595320494249LL
+#define GRUB_EFIEMU_RUNTIME_SERVICES_SIGNATURE 0x56524553544e5552LL
+
+struct grub_efi_serial_io_interface
+{
+ grub_efi_uint32_t revision;
+ void (*reset) (void);
+ grub_efi_status_t (*set_attributes) (struct grub_efi_serial_io_interface *this,
+ grub_efi_uint64_t speed,
+ grub_efi_uint32_t fifo_depth,
+ grub_efi_uint32_t timeout,
+ grub_efi_parity_type_t parity,
+ grub_uint8_t word_len,
+ grub_efi_stop_bits_t stop_bits);
+ grub_efi_status_t (*set_control_bits) (struct grub_efi_serial_io_interface *this,
+ grub_efi_uint32_t flags);
+ void (*get_control_bits) (void);
+ grub_efi_status_t (*write) (struct grub_efi_serial_io_interface *this,
+ grub_efi_uintn_t *buf_size,
+ void *buffer);
+ grub_efi_status_t (*read) (struct grub_efi_serial_io_interface *this,
+ grub_efi_uintn_t *buf_size,
+ void *buffer);
+};
+
+struct grub_efi_simple_input_interface
+{
+ grub_efi_status_t
+ (*reset) (struct grub_efi_simple_input_interface *this,
+ grub_efi_boolean_t extended_verification);
+
+ grub_efi_status_t
+ (*read_key_stroke) (struct grub_efi_simple_input_interface *this,
+ grub_efi_input_key_t *key);
+
+ grub_efi_event_t wait_for_key;
+};
+typedef struct grub_efi_simple_input_interface grub_efi_simple_input_interface_t;
+
+struct grub_efi_key_data {
+ grub_efi_input_key_t key;
+ grub_efi_key_state_t key_state;
+};
+typedef struct grub_efi_key_data grub_efi_key_data_t;
+
+typedef grub_efi_status_t (*grub_efi_key_notify_function_t) (
+ grub_efi_key_data_t *key_data
+ );
+
+struct grub_efi_simple_text_input_ex_interface
+{
+ grub_efi_status_t
+ (*reset) (struct grub_efi_simple_text_input_ex_interface *this,
+ grub_efi_boolean_t extended_verification);
+
+ grub_efi_status_t
+ (*read_key_stroke) (struct grub_efi_simple_text_input_ex_interface *this,
+ grub_efi_key_data_t *key_data);
+
+ grub_efi_event_t wait_for_key;
+
+ grub_efi_status_t
+ (*set_state) (struct grub_efi_simple_text_input_ex_interface *this,
+ grub_efi_key_toggle_state_t *key_toggle_state);
+
+ grub_efi_status_t
+ (*register_key_notify) (struct grub_efi_simple_text_input_ex_interface *this,
+ grub_efi_key_data_t *key_data,
+ grub_efi_key_notify_function_t key_notification_function);
+
+ grub_efi_status_t
+ (*unregister_key_notify) (struct grub_efi_simple_text_input_ex_interface *this,
+ void *notification_handle);
+};
+typedef struct grub_efi_simple_text_input_ex_interface grub_efi_simple_text_input_ex_interface_t;
+
+struct grub_efi_simple_text_output_interface
+{
+ grub_efi_status_t
+ (*reset) (struct grub_efi_simple_text_output_interface *this,
+ grub_efi_boolean_t extended_verification);
+
+ grub_efi_status_t
+ (*output_string) (struct grub_efi_simple_text_output_interface *this,
+ grub_efi_char16_t *string);
+
+ grub_efi_status_t
+ (*test_string) (struct grub_efi_simple_text_output_interface *this,
+ grub_efi_char16_t *string);
+
+ grub_efi_status_t
+ (*query_mode) (struct grub_efi_simple_text_output_interface *this,
+ grub_efi_uintn_t mode_number,
+ grub_efi_uintn_t *columns,
+ grub_efi_uintn_t *rows);
+
+ grub_efi_status_t
+ (*set_mode) (struct grub_efi_simple_text_output_interface *this,
+ grub_efi_uintn_t mode_number);
+
+ grub_efi_status_t
+ (*set_attributes) (struct grub_efi_simple_text_output_interface *this,
+ grub_efi_uintn_t attribute);
+
+ grub_efi_status_t
+ (*clear_screen) (struct grub_efi_simple_text_output_interface *this);
+
+ grub_efi_status_t
+ (*set_cursor_position) (struct grub_efi_simple_text_output_interface *this,
+ grub_efi_uintn_t column,
+ grub_efi_uintn_t row);
+
+ grub_efi_status_t
+ (*enable_cursor) (struct grub_efi_simple_text_output_interface *this,
+ grub_efi_boolean_t visible);
+
+ grub_efi_simple_text_output_mode_t *mode;
+};
+typedef struct grub_efi_simple_text_output_interface grub_efi_simple_text_output_interface_t;
+
+typedef grub_uint8_t grub_efi_pxe_packet_t[1472];
+
+typedef struct grub_efi_pxe_mode
+{
+ grub_uint8_t unused[52];
+ grub_efi_pxe_packet_t dhcp_discover;
+ grub_efi_pxe_packet_t dhcp_ack;
+ grub_efi_pxe_packet_t proxy_offer;
+ grub_efi_pxe_packet_t pxe_discover;
+ grub_efi_pxe_packet_t pxe_reply;
+} grub_efi_pxe_mode_t;
+
+typedef struct grub_efi_pxe
+{
+ grub_uint64_t rev;
+ void (*start) (void);
+ void (*stop) (void);
+ void (*dhcp) (void);
+ void (*discover) (void);
+ void (*mftp) (void);
+ void (*udpwrite) (void);
+ void (*udpread) (void);
+ void (*setipfilter) (void);
+ void (*arp) (void);
+ void (*setparams) (void);
+ void (*setstationip) (void);
+ void (*setpackets) (void);
+ struct grub_efi_pxe_mode *mode;
+} grub_efi_pxe_t;
+
+#define GRUB_EFI_BLACK 0x00
+#define GRUB_EFI_BLUE 0x01
+#define GRUB_EFI_GREEN 0x02
+#define GRUB_EFI_CYAN 0x03
+#define GRUB_EFI_RED 0x04
+#define GRUB_EFI_MAGENTA 0x05
+#define GRUB_EFI_BROWN 0x06
+#define GRUB_EFI_LIGHTGRAY 0x07
+#define GRUB_EFI_BRIGHT 0x08
+#define GRUB_EFI_DARKGRAY 0x08
+#define GRUB_EFI_LIGHTBLUE 0x09
+#define GRUB_EFI_LIGHTGREEN 0x0A
+#define GRUB_EFI_LIGHTCYAN 0x0B
+#define GRUB_EFI_LIGHTRED 0x0C
+#define GRUB_EFI_LIGHTMAGENTA 0x0D
+#define GRUB_EFI_YELLOW 0x0E
+#define GRUB_EFI_WHITE 0x0F
+
+#define GRUB_EFI_BACKGROUND_BLACK 0x00
+#define GRUB_EFI_BACKGROUND_BLUE 0x10
+#define GRUB_EFI_BACKGROUND_GREEN 0x20
+#define GRUB_EFI_BACKGROUND_CYAN 0x30
+#define GRUB_EFI_BACKGROUND_RED 0x40
+#define GRUB_EFI_BACKGROUND_MAGENTA 0x50
+#define GRUB_EFI_BACKGROUND_BROWN 0x60
+#define GRUB_EFI_BACKGROUND_LIGHTGRAY 0x70
+
+#define GRUB_EFI_TEXT_ATTR(fg, bg) ((fg) | ((bg)))
+
+struct grub_efi_system_table
+{
+ grub_efi_table_header_t hdr;
+ grub_efi_char16_t *firmware_vendor;
+ grub_efi_uint32_t firmware_revision;
+ grub_efi_handle_t console_in_handler;
+ grub_efi_simple_input_interface_t *con_in;
+ grub_efi_handle_t console_out_handler;
+ grub_efi_simple_text_output_interface_t *con_out;
+ grub_efi_handle_t standard_error_handle;
+ grub_efi_simple_text_output_interface_t *std_err;
+ grub_efi_runtime_services_t *runtime_services;
+ grub_efi_boot_services_t *boot_services;
+ grub_efi_uintn_t num_table_entries;
+ grub_efi_configuration_table_t *configuration_table;
+};
+typedef struct grub_efi_system_table grub_efi_system_table_t;
+
+struct grub_efi_loaded_image
+{
+ grub_efi_uint32_t revision;
+ grub_efi_handle_t parent_handle;
+ grub_efi_system_table_t *system_table;
+
+ grub_efi_handle_t device_handle;
+ grub_efi_device_path_t *file_path;
+ void *reserved;
+
+ grub_efi_uint32_t load_options_size;
+ void *load_options;
+
+ void *image_base;
+ grub_efi_uint64_t image_size;
+ grub_efi_memory_type_t image_code_type;
+ grub_efi_memory_type_t image_data_type;
+
+ grub_efi_status_t (*unload) (grub_efi_handle_t image_handle);
+};
+typedef struct grub_efi_loaded_image grub_efi_loaded_image_t;
+
+struct grub_efi_disk_io
+{
+ grub_efi_uint64_t revision;
+ grub_efi_status_t (*read) (struct grub_efi_disk_io *this,
+ grub_efi_uint32_t media_id,
+ grub_efi_uint64_t offset,
+ grub_efi_uintn_t buffer_size,
+ void *buffer);
+ grub_efi_status_t (*write) (struct grub_efi_disk_io *this,
+ grub_efi_uint32_t media_id,
+ grub_efi_uint64_t offset,
+ grub_efi_uintn_t buffer_size,
+ void *buffer);
+};
+typedef struct grub_efi_disk_io grub_efi_disk_io_t;
+
+struct grub_efi_block_io_media
+{
+ grub_efi_uint32_t media_id;
+ grub_efi_boolean_t removable_media;
+ grub_efi_boolean_t media_present;
+ grub_efi_boolean_t logical_partition;
+ grub_efi_boolean_t read_only;
+ grub_efi_boolean_t write_caching;
+ grub_efi_uint8_t pad[3];
+ grub_efi_uint32_t block_size;
+ grub_efi_uint32_t io_align;
+ grub_efi_uint8_t pad2[4];
+ grub_efi_lba_t last_block;
+};
+typedef struct grub_efi_block_io_media grub_efi_block_io_media_t;
+
+typedef grub_uint8_t grub_efi_mac_t[32];
+
+struct grub_efi_simple_network_mode
+{
+ grub_uint32_t state;
+ grub_uint32_t hwaddr_size;
+ grub_uint32_t media_header_size;
+ grub_uint32_t max_packet_size;
+ grub_uint32_t nvram_size;
+ grub_uint32_t nvram_access_size;
+ grub_uint32_t receive_filter_mask;
+ grub_uint32_t receive_filter_setting;
+ grub_uint32_t max_mcast_filter_count;
+ grub_uint32_t mcast_filter_count;
+ grub_efi_mac_t mcast_filter[16];
+ grub_efi_mac_t current_address;
+ grub_efi_mac_t broadcast_address;
+ grub_efi_mac_t permanent_address;
+ grub_uint8_t if_type;
+ grub_uint8_t mac_changeable;
+ grub_uint8_t multitx_supported;
+ grub_uint8_t media_present_supported;
+ grub_uint8_t media_present;
+};
+
+enum
+ {
+ GRUB_EFI_NETWORK_STOPPED,
+ GRUB_EFI_NETWORK_STARTED,
+ GRUB_EFI_NETWORK_INITIALIZED,
+ };
+
+enum
+ {
+ GRUB_EFI_SIMPLE_NETWORK_RECEIVE_UNICAST = 0x01,
+ GRUB_EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST = 0x02,
+ GRUB_EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST = 0x04,
+ GRUB_EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS = 0x08,
+ GRUB_EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST = 0x10,
+ };
+
+struct grub_efi_simple_network
+{
+ grub_uint64_t revision;
+ grub_efi_status_t (*start) (struct grub_efi_simple_network *this);
+ grub_efi_status_t (*stop) (struct grub_efi_simple_network *this);
+ grub_efi_status_t (*initialize) (struct grub_efi_simple_network *this,
+ grub_efi_uintn_t extra_rx,
+ grub_efi_uintn_t extra_tx);
+ void (*reset) (void);
+ grub_efi_status_t (*shutdown) (struct grub_efi_simple_network *this);
+ grub_efi_status_t (*receive_filters) (struct grub_efi_simple_network *this,
+ grub_uint32_t enable,
+ grub_uint32_t disable,
+ grub_efi_boolean_t reset_mcast_filter,
+ grub_efi_uintn_t mcast_filter_count,
+ grub_efi_mac_address_t *mcast_filter);
+ void (*station_address) (void);
+ void (*statistics) (void);
+ void (*mcastiptomac) (void);
+ void (*nvdata) (void);
+ grub_efi_status_t (*get_status) (struct grub_efi_simple_network *this,
+ grub_uint32_t *int_status,
+ void **txbuf);
+ grub_efi_status_t (*transmit) (struct grub_efi_simple_network *this,
+ grub_efi_uintn_t header_size,
+ grub_efi_uintn_t buffer_size,
+ void *buffer,
+ grub_efi_mac_t *src_addr,
+ grub_efi_mac_t *dest_addr,
+ grub_efi_uint16_t *protocol);
+ grub_efi_status_t (*receive) (struct grub_efi_simple_network *this,
+ grub_efi_uintn_t *header_size,
+ grub_efi_uintn_t *buffer_size,
+ void *buffer,
+ grub_efi_mac_t *src_addr,
+ grub_efi_mac_t *dest_addr,
+ grub_uint16_t *protocol);
+ void (*waitforpacket) (void);
+ struct grub_efi_simple_network_mode *mode;
+};
+typedef struct grub_efi_simple_network grub_efi_simple_network_t;
+
+
+struct grub_efi_block_io
+{
+ grub_efi_uint64_t revision;
+ grub_efi_block_io_media_t *media;
+ grub_efi_status_t (*reset) (struct grub_efi_block_io *this,
+ grub_efi_boolean_t extended_verification);
+ grub_efi_status_t (*read_blocks) (struct grub_efi_block_io *this,
+ grub_efi_uint32_t media_id,
+ grub_efi_lba_t lba,
+ grub_efi_uintn_t buffer_size,
+ void *buffer);
+ grub_efi_status_t (*write_blocks) (struct grub_efi_block_io *this,
+ grub_efi_uint32_t media_id,
+ grub_efi_lba_t lba,
+ grub_efi_uintn_t buffer_size,
+ void *buffer);
+ grub_efi_status_t (*flush_blocks) (struct grub_efi_block_io *this);
+};
+typedef struct grub_efi_block_io grub_efi_block_io_t;
+
+struct grub_efi_shim_lock_protocol
+{
+ grub_efi_status_t (*verify) (void *buffer, grub_uint32_t size);
+};
+typedef struct grub_efi_shim_lock_protocol grub_efi_shim_lock_protocol_t;
+
+typedef grub_efi_guid_t grub_efi_rng_algorithm_t;
+
+struct grub_efi_rng_protocol
+{
+ grub_efi_status_t (*get_info) (struct grub_efi_rng_protocol *this,
+ grub_efi_uintn_t *rng_algorithm_list_size,
+ grub_efi_rng_algorithm_t *rng_algorithm_list);
+ grub_efi_status_t (*get_rng) (struct grub_efi_rng_protocol *this,
+ grub_efi_rng_algorithm_t *rng_algorithm,
+ grub_efi_uintn_t rng_value_length,
+ grub_efi_uint8_t *rng_value);
+};
+typedef struct grub_efi_rng_protocol grub_efi_rng_protocol_t;
+
+#if (GRUB_TARGET_SIZEOF_VOID_P == 4) || defined (__ia64__) \
+ || defined (__aarch64__) || defined (__MINGW64__) || defined (__CYGWIN__) \
+ || defined(__riscv)
+
+#define efi_call_0(func) func()
+#define efi_call_1(func, a) func(a)
+#define efi_call_2(func, a, b) func(a, b)
+#define efi_call_3(func, a, b, c) func(a, b, c)
+#define efi_call_4(func, a, b, c, d) func(a, b, c, d)
+#define efi_call_5(func, a, b, c, d, e) func(a, b, c, d, e)
+#define efi_call_6(func, a, b, c, d, e, f) func(a, b, c, d, e, f)
+#define efi_call_7(func, a, b, c, d, e, f, g) func(a, b, c, d, e, f, g)
+#define efi_call_10(func, a, b, c, d, e, f, g, h, i, j) func(a, b, c, d, e, f, g, h, i, j)
+
+#else
+
+#define efi_call_0(func) \
+ efi_wrap_0(func)
+#define efi_call_1(func, a) \
+ efi_wrap_1(func, (grub_uint64_t) (a))
+#define efi_call_2(func, a, b) \
+ efi_wrap_2(func, (grub_uint64_t) (a), (grub_uint64_t) (b))
+#define efi_call_3(func, a, b, c) \
+ efi_wrap_3(func, (grub_uint64_t) (a), (grub_uint64_t) (b), \
+ (grub_uint64_t) (c))
+#define efi_call_4(func, a, b, c, d) \
+ efi_wrap_4(func, (grub_uint64_t) (a), (grub_uint64_t) (b), \
+ (grub_uint64_t) (c), (grub_uint64_t) (d))
+#define efi_call_5(func, a, b, c, d, e) \
+ efi_wrap_5(func, (grub_uint64_t) (a), (grub_uint64_t) (b), \
+ (grub_uint64_t) (c), (grub_uint64_t) (d), (grub_uint64_t) (e))
+#define efi_call_6(func, a, b, c, d, e, f) \
+ efi_wrap_6(func, (grub_uint64_t) (a), (grub_uint64_t) (b), \
+ (grub_uint64_t) (c), (grub_uint64_t) (d), (grub_uint64_t) (e), \
+ (grub_uint64_t) (f))
+#define efi_call_7(func, a, b, c, d, e, f, g) \
+ efi_wrap_7(func, (grub_uint64_t) (a), (grub_uint64_t) (b), \
+ (grub_uint64_t) (c), (grub_uint64_t) (d), (grub_uint64_t) (e), \
+ (grub_uint64_t) (f), (grub_uint64_t) (g))
+#define efi_call_10(func, a, b, c, d, e, f, g, h, i, j) \
+ efi_wrap_10(func, (grub_uint64_t) (a), (grub_uint64_t) (b), \
+ (grub_uint64_t) (c), (grub_uint64_t) (d), (grub_uint64_t) (e), \
+ (grub_uint64_t) (f), (grub_uint64_t) (g), (grub_uint64_t) (h), \
+ (grub_uint64_t) (i), (grub_uint64_t) (j))
+
+grub_uint64_t EXPORT_FUNC(efi_wrap_0) (void *func);
+grub_uint64_t EXPORT_FUNC(efi_wrap_1) (void *func, grub_uint64_t arg1);
+grub_uint64_t EXPORT_FUNC(efi_wrap_2) (void *func, grub_uint64_t arg1,
+ grub_uint64_t arg2);
+grub_uint64_t EXPORT_FUNC(efi_wrap_3) (void *func, grub_uint64_t arg1,
+ grub_uint64_t arg2, grub_uint64_t arg3);
+grub_uint64_t EXPORT_FUNC(efi_wrap_4) (void *func, grub_uint64_t arg1,
+ grub_uint64_t arg2, grub_uint64_t arg3,
+ grub_uint64_t arg4);
+grub_uint64_t EXPORT_FUNC(efi_wrap_5) (void *func, grub_uint64_t arg1,
+ grub_uint64_t arg2, grub_uint64_t arg3,
+ grub_uint64_t arg4, grub_uint64_t arg5);
+grub_uint64_t EXPORT_FUNC(efi_wrap_6) (void *func, grub_uint64_t arg1,
+ grub_uint64_t arg2, grub_uint64_t arg3,
+ grub_uint64_t arg4, grub_uint64_t arg5,
+ grub_uint64_t arg6);
+grub_uint64_t EXPORT_FUNC(efi_wrap_7) (void *func, grub_uint64_t arg1,
+ grub_uint64_t arg2, grub_uint64_t arg3,
+ grub_uint64_t arg4, grub_uint64_t arg5,
+ grub_uint64_t arg6, grub_uint64_t arg7);
+grub_uint64_t EXPORT_FUNC(efi_wrap_10) (void *func, grub_uint64_t arg1,
+ grub_uint64_t arg2, grub_uint64_t arg3,
+ grub_uint64_t arg4, grub_uint64_t arg5,
+ grub_uint64_t arg6, grub_uint64_t arg7,
+ grub_uint64_t arg8, grub_uint64_t arg9,
+ grub_uint64_t arg10);
+#endif
+
+#endif /* ! GRUB_EFI_API_HEADER */
diff --git a/include/grub/efi/console.h b/include/grub/efi/console.h
new file mode 100644
index 0000000..f90b5b7
--- /dev/null
+++ b/include/grub/efi/console.h
@@ -0,0 +1,31 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2005,2006,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_EFI_CONSOLE_HEADER
+#define GRUB_EFI_CONSOLE_HEADER 1
+
+#include <grub/types.h>
+#include <grub/symbol.h>
+
+/* Initialize the console system. */
+void grub_console_init (void);
+
+/* Finish the console system. */
+void grub_console_fini (void);
+
+#endif /* ! GRUB_EFI_CONSOLE_HEADER */
diff --git a/include/grub/efi/console_control.h b/include/grub/efi/console_control.h
new file mode 100644
index 0000000..7c358fc
--- /dev/null
+++ b/include/grub/efi/console_control.h
@@ -0,0 +1,57 @@
+/* console_control.h - definitions of the console control protocol */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2006,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* The console control protocol is not a part of the EFI spec,
+ but defined in Intel's Sample Implementation. */
+
+#ifndef GRUB_EFI_CONSOLE_CONTROL_HEADER
+#define GRUB_EFI_CONSOLE_CONTROL_HEADER 1
+
+#define GRUB_EFI_CONSOLE_CONTROL_GUID \
+ { 0xf42f7782, 0x12e, 0x4c12, \
+ { 0x99, 0x56, 0x49, 0xf9, 0x43, 0x4, 0xf7, 0x21 } \
+ }
+
+enum grub_efi_screen_mode
+ {
+ GRUB_EFI_SCREEN_TEXT,
+ GRUB_EFI_SCREEN_GRAPHICS,
+ GRUB_EFI_SCREEN_TEXT_MAX_VALUE
+ };
+typedef enum grub_efi_screen_mode grub_efi_screen_mode_t;
+
+struct grub_efi_console_control_protocol
+{
+ grub_efi_status_t
+ (*get_mode) (struct grub_efi_console_control_protocol *this,
+ grub_efi_screen_mode_t *mode,
+ grub_efi_boolean_t *uga_exists,
+ grub_efi_boolean_t *std_in_locked);
+
+ grub_efi_status_t
+ (*set_mode) (struct grub_efi_console_control_protocol *this,
+ grub_efi_screen_mode_t mode);
+
+ grub_efi_status_t
+ (*lock_std_in) (struct grub_efi_console_control_protocol *this,
+ grub_efi_char16_t *password);
+};
+typedef struct grub_efi_console_control_protocol grub_efi_console_control_protocol_t;
+
+#endif /* ! GRUB_EFI_CONSOLE_CONTROL_HEADER */
diff --git a/include/grub/efi/disk.h b/include/grub/efi/disk.h
new file mode 100644
index 0000000..254475c
--- /dev/null
+++ b/include/grub/efi/disk.h
@@ -0,0 +1,33 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2006,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_EFI_DISK_HEADER
+#define GRUB_EFI_DISK_HEADER 1
+
+#include <grub/efi/api.h>
+#include <grub/symbol.h>
+#include <grub/disk.h>
+
+grub_efi_handle_t
+EXPORT_FUNC(grub_efidisk_get_device_handle) (grub_disk_t disk);
+char *EXPORT_FUNC(grub_efidisk_get_device_name) (grub_efi_handle_t *handle);
+
+void grub_efidisk_init (void);
+void grub_efidisk_fini (void);
+
+#endif /* ! GRUB_EFI_DISK_HEADER */
diff --git a/include/grub/efi/edid.h b/include/grub/efi/edid.h
new file mode 100644
index 0000000..a0140b8
--- /dev/null
+++ b/include/grub/efi/edid.h
@@ -0,0 +1,54 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2012 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_EFI_EDID_HEADER
+#define GRUB_EFI_EDID_HEADER 1
+
+/* Based on UEFI specification. */
+
+#define GRUB_EFI_EDID_ACTIVE_GUID \
+ { 0xbd8c1056, 0x9f36, 0x44ec, { 0x92, 0xa8, 0xa6, 0x33, 0x7f, 0x81, 0x79, 0x86 }}
+
+#define GRUB_EFI_EDID_DISCOVERED_GUID \
+ {0x1c0c34f6,0xd380,0x41fa, {0xa0,0x49,0x8a,0xd0,0x6c,0x1a,0x66,0xaa}}
+
+#define GRUB_EFI_EDID_OVERRIDE_GUID \
+ {0x48ecb431,0xfb72,0x45c0, {0xa9,0x22,0xf4,0x58,0xfe,0x4,0xb,0xd5}}
+
+struct grub_efi_edid_override;
+
+typedef grub_efi_status_t
+(*grub_efi_edid_override_get_edid) (struct grub_efi_edid_override *this,
+ grub_efi_handle_t *childhandle,
+ grub_efi_uint32_t *attributes,
+ grub_efi_uintn_t *edidsize,
+ grub_efi_uint8_t *edid);
+struct grub_efi_edid_override {
+ grub_efi_edid_override_get_edid get_edid;
+};
+
+typedef struct grub_efi_edid_override grub_efi_edid_override_t;
+
+
+struct grub_efi_active_edid
+{
+ grub_uint32_t size_of_edid;
+ grub_uint8_t *edid;
+};
+
+#endif
diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h
new file mode 100644
index 0000000..83d958f
--- /dev/null
+++ b/include/grub/efi/efi.h
@@ -0,0 +1,127 @@
+/* efi.h - declare variables and functions for EFI support */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_EFI_EFI_HEADER
+#define GRUB_EFI_EFI_HEADER 1
+
+#include <grub/types.h>
+#include <grub/dl.h>
+#include <grub/efi/api.h>
+
+/* Functions. */
+void *EXPORT_FUNC(grub_efi_locate_protocol) (grub_efi_guid_t *protocol,
+ void *registration);
+grub_efi_handle_t *
+EXPORT_FUNC(grub_efi_locate_handle) (grub_efi_locate_search_type_t search_type,
+ grub_efi_guid_t *protocol,
+ void *search_key,
+ grub_efi_uintn_t *num_handles);
+void *EXPORT_FUNC(grub_efi_open_protocol) (grub_efi_handle_t handle,
+ grub_efi_guid_t *protocol,
+ grub_efi_uint32_t attributes);
+int EXPORT_FUNC(grub_efi_set_text_mode) (int on);
+void EXPORT_FUNC(grub_efi_stall) (grub_efi_uintn_t microseconds);
+void *
+EXPORT_FUNC(grub_efi_allocate_pages_real) (grub_efi_physical_address_t address,
+ grub_efi_uintn_t pages,
+ grub_efi_allocate_type_t alloctype,
+ grub_efi_memory_type_t memtype);
+void *
+EXPORT_FUNC(grub_efi_allocate_fixed) (grub_efi_physical_address_t address,
+ grub_efi_uintn_t pages);
+void *
+EXPORT_FUNC(grub_efi_allocate_any_pages) (grub_efi_uintn_t pages);
+void EXPORT_FUNC(grub_efi_free_pages) (grub_efi_physical_address_t address,
+ grub_efi_uintn_t pages);
+grub_efi_uintn_t EXPORT_FUNC(grub_efi_find_mmap_size) (void);
+int
+EXPORT_FUNC(grub_efi_get_memory_map) (grub_efi_uintn_t *memory_map_size,
+ grub_efi_memory_descriptor_t *memory_map,
+ grub_efi_uintn_t *map_key,
+ grub_efi_uintn_t *descriptor_size,
+ grub_efi_uint32_t *descriptor_version);
+void grub_efi_memory_fini (void);
+grub_efi_loaded_image_t *EXPORT_FUNC(grub_efi_get_loaded_image) (grub_efi_handle_t image_handle);
+void EXPORT_FUNC(grub_efi_print_device_path) (grub_efi_device_path_t *dp);
+char *EXPORT_FUNC(grub_efi_get_filename) (grub_efi_device_path_t *dp);
+grub_efi_device_path_t *
+EXPORT_FUNC(grub_efi_get_device_path) (grub_efi_handle_t handle);
+grub_efi_device_path_t *
+EXPORT_FUNC(grub_efi_find_last_device_path) (const grub_efi_device_path_t *dp);
+grub_efi_device_path_t *
+EXPORT_FUNC(grub_efi_duplicate_device_path) (const grub_efi_device_path_t *dp);
+grub_err_t EXPORT_FUNC (grub_efi_finish_boot_services) (grub_efi_uintn_t *outbuf_size, void *outbuf,
+ grub_efi_uintn_t *map_key,
+ grub_efi_uintn_t *efi_desc_size,
+ grub_efi_uint32_t *efi_desc_version);
+grub_err_t EXPORT_FUNC (grub_efi_set_virtual_address_map) (grub_efi_uintn_t memory_map_size,
+ grub_efi_uintn_t descriptor_size,
+ grub_efi_uint32_t descriptor_version,
+ grub_efi_memory_descriptor_t *virtual_map);
+grub_efi_status_t EXPORT_FUNC (grub_efi_get_variable_with_attributes) (const char *variable,
+ const grub_efi_guid_t *guid,
+ grub_size_t *datasize_out,
+ void **data_out,
+ grub_efi_uint32_t *attributes);
+grub_efi_status_t EXPORT_FUNC (grub_efi_get_variable) (const char *variable,
+ const grub_efi_guid_t *guid,
+ grub_size_t *datasize_out,
+ void **data_out);
+grub_err_t
+EXPORT_FUNC (grub_efi_set_variable) (const char *var,
+ const grub_efi_guid_t *guid,
+ void *data,
+ grub_size_t datasize);
+int
+EXPORT_FUNC (grub_efi_compare_device_paths) (const grub_efi_device_path_t *dp1,
+ const grub_efi_device_path_t *dp2);
+
+extern void (*EXPORT_VAR(grub_efi_net_config)) (grub_efi_handle_t hnd,
+ char **device,
+ char **path);
+
+#if defined(__arm__) || defined(__aarch64__) || defined(__riscv)
+void *EXPORT_FUNC(grub_efi_get_firmware_fdt)(void);
+grub_err_t EXPORT_FUNC(grub_efi_get_ram_base)(grub_addr_t *);
+#include <grub/cpu/linux.h>
+grub_err_t grub_arch_efi_linux_check_image(struct linux_arch_kernel_header *lh);
+grub_err_t grub_arch_efi_linux_boot_image(grub_addr_t addr, grub_size_t size,
+ char *args);
+#endif
+
+grub_addr_t grub_efi_modules_addr (void);
+
+void grub_efi_mm_init (void);
+void grub_efi_mm_fini (void);
+void grub_efi_init (void);
+void grub_efi_fini (void);
+void grub_efi_set_prefix (void);
+
+/* Variables. */
+extern grub_efi_system_table_t *EXPORT_VAR(grub_efi_system_table);
+extern grub_efi_handle_t EXPORT_VAR(grub_efi_image_handle);
+
+extern int EXPORT_VAR(grub_efi_is_finished);
+
+struct grub_net_card;
+
+grub_efi_handle_t
+grub_efinet_get_device_handle (struct grub_net_card *card);
+
+#endif /* ! GRUB_EFI_EFI_HEADER */
diff --git a/include/grub/efi/fdtload.h b/include/grub/efi/fdtload.h
new file mode 100644
index 0000000..713c942
--- /dev/null
+++ b/include/grub/efi/fdtload.h
@@ -0,0 +1,32 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013-2015 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_FDTLOAD_CPU_HEADER
+#define GRUB_FDTLOAD_CPU_HEADER 1
+
+#include <grub/types.h>
+#include <grub/err.h>
+
+void *
+grub_fdt_load (grub_size_t additional_size);
+void
+grub_fdt_unload (void);
+grub_err_t
+grub_fdt_install (void);
+
+#endif
diff --git a/include/grub/efi/graphics_output.h b/include/grub/efi/graphics_output.h
new file mode 100644
index 0000000..e438812
--- /dev/null
+++ b/include/grub/efi/graphics_output.h
@@ -0,0 +1,115 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_EFI_GOP_HEADER
+#define GRUB_EFI_GOP_HEADER 1
+
+/* Based on UEFI specification. */
+
+#define GRUB_EFI_GOP_GUID \
+ { 0x9042a9de, 0x23dc, 0x4a38, { 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a }}
+
+typedef enum
+ {
+ GRUB_EFI_GOT_RGBA8,
+ GRUB_EFI_GOT_BGRA8,
+ GRUB_EFI_GOT_BITMASK,
+ GRUB_EFI_GOT_BLT_ONLY,
+ }
+ grub_efi_gop_pixel_format_t;
+
+typedef enum
+ {
+ GRUB_EFI_BLT_VIDEO_FILL,
+ GRUB_EFI_BLT_VIDEO_TO_BLT_BUFFER,
+ GRUB_EFI_BLT_BUFFER_TO_VIDEO,
+ GRUB_EFI_BLT_VIDEO_TO_VIDEO,
+ GRUB_EFI_BLT_OPERATION_MAX
+ }
+ grub_efi_gop_blt_operation_t;
+
+struct grub_efi_gop_blt_pixel
+{
+ grub_uint8_t blue;
+ grub_uint8_t green;
+ grub_uint8_t red;
+ grub_uint8_t reserved;
+};
+
+struct grub_efi_gop_pixel_bitmask
+{
+ grub_uint32_t r;
+ grub_uint32_t g;
+ grub_uint32_t b;
+ grub_uint32_t a;
+};
+
+struct grub_efi_gop_mode_info
+{
+ grub_efi_uint32_t version;
+ grub_efi_uint32_t width;
+ grub_efi_uint32_t height;
+ grub_efi_gop_pixel_format_t pixel_format;
+ struct grub_efi_gop_pixel_bitmask pixel_bitmask;
+ grub_efi_uint32_t pixels_per_scanline;
+};
+
+struct grub_efi_gop_mode
+{
+ grub_efi_uint32_t max_mode;
+ grub_efi_uint32_t mode;
+ struct grub_efi_gop_mode_info *info;
+ grub_efi_uintn_t info_size;
+ grub_efi_physical_address_t fb_base;
+ grub_efi_uintn_t fb_size;
+};
+
+/* Forward declaration. */
+struct grub_efi_gop;
+
+typedef grub_efi_status_t
+(*grub_efi_gop_query_mode_t) (struct grub_efi_gop *this,
+ grub_efi_uint32_t mode_number,
+ grub_efi_uintn_t *size_of_info,
+ struct grub_efi_gop_mode_info **info);
+
+typedef grub_efi_status_t
+(*grub_efi_gop_set_mode_t) (struct grub_efi_gop *this,
+ grub_efi_uint32_t mode_number);
+
+typedef grub_efi_status_t
+(*grub_efi_gop_blt_t) (struct grub_efi_gop *this,
+ void *buffer,
+ grub_efi_uintn_t operation,
+ grub_efi_uintn_t sx,
+ grub_efi_uintn_t sy,
+ grub_efi_uintn_t dx,
+ grub_efi_uintn_t dy,
+ grub_efi_uintn_t width,
+ grub_efi_uintn_t height,
+ grub_efi_uintn_t delta);
+
+struct grub_efi_gop
+{
+ grub_efi_gop_query_mode_t query_mode;
+ grub_efi_gop_set_mode_t set_mode;
+ grub_efi_gop_blt_t blt;
+ struct grub_efi_gop_mode *mode;
+};
+
+#endif
diff --git a/include/grub/efi/memory.h b/include/grub/efi/memory.h
new file mode 100644
index 0000000..08fe622
--- /dev/null
+++ b/include/grub/efi/memory.h
@@ -0,0 +1,38 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MEMORY_MACHINE_HEADER
+#define GRUB_MEMORY_MACHINE_HEADER 1
+
+#include <grub/err.h>
+#include <grub/types.h>
+
+/* The term "page" in UEFI refers only to a 4 KiB-aligned 4 KiB size region of
+ memory. It is not concerned with underlying translation management concepts,
+ but only used as the granule for memory allocations. */
+#define GRUB_EFI_PAGE_SHIFT 12
+#define GRUB_EFI_PAGE_SIZE (1 << GRUB_EFI_PAGE_SHIFT)
+#define GRUB_EFI_BYTES_TO_PAGES(bytes) (((bytes) + 0xfff) >> GRUB_EFI_PAGE_SHIFT)
+
+#define GRUB_MMAP_REGISTER_BY_FIRMWARE 1
+
+grub_err_t grub_machine_mmap_register (grub_uint64_t start, grub_uint64_t size,
+ int type, int handle);
+grub_err_t grub_machine_mmap_unregister (int handle);
+
+#endif /* ! GRUB_MEMORY_MACHINE_HEADER */
diff --git a/include/grub/efi/pci.h b/include/grub/efi/pci.h
new file mode 100644
index 0000000..b172455
--- /dev/null
+++ b/include/grub/efi/pci.h
@@ -0,0 +1,319 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2006,2007,2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_EFI_PCI_HEADER
+#define GRUB_EFI_PCI_HEADER 1
+
+#include <grub/symbol.h>
+
+#define GRUB_EFI_PCI_IO_GUID \
+ { 0x4cf5b200, 0x68b8, 0x4ca5, { 0x9e, 0xec, 0xb2, 0x3e, 0x3f, 0x50, 0x02, 0x9a }}
+
+#define GRUB_EFI_PCI_ROOT_IO_GUID \
+ { 0x2F707EBB, 0x4A1A, 0x11d4, { 0x9A, 0x38, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0x4D }}
+
+typedef enum
+ {
+ GRUB_EFI_PCI_IO_WIDTH_UINT8,
+ GRUB_EFI_PCI_IO_WIDTH_UINT16,
+ GRUB_EFI_PCI_IO_WIDTH_UINT32,
+ GRUB_EFI_PCI_IO_WIDTH_UINT64,
+ GRUB_EFI_PCI_IO_WIDTH_FIFO_UINT8,
+ GRUB_EFI_PCI_IO_WIDTH_FIFO_UINT16,
+ GRUB_EFI_PCI_IO_WIDTH_FIFO_UINT32,
+ GRUB_EFI_PCI_IO_WIDTH_FIFO_UINT64,
+ GRUB_EFI_PCI_IO_WIDTH_FILL_UINT8,
+ GRUB_EFI_PCI_IO_WIDTH_FILL_UINT16,
+ GRUB_EFI_PCI_IO_WIDTH_FILL_UINT32,
+ GRUB_EFI_PCI_IO_WIDTH_FILL_UINT64,
+ GRUB_EFI_PCI_IO_WIDTH_MAXIMUM,
+ }
+ grub_efi_pci_io_width_t;
+
+struct grub_efi_pci_io;
+
+typedef grub_efi_status_t
+(*grub_efi_pci_io_mem_t) (struct grub_efi_pci_io *this,
+ grub_efi_pci_io_width_t width,
+ grub_efi_uint8_t bar_index,
+ grub_efi_uint64_t offset,
+ grub_efi_uintn_t count,
+ void *buffer);
+
+typedef grub_efi_status_t
+(*grub_efi_pci_io_config_t) (struct grub_efi_pci_io *this,
+ grub_efi_pci_io_width_t width,
+ grub_efi_uint32_t offset,
+ grub_efi_uintn_t count,
+ void *buffer);
+typedef struct
+{
+ grub_efi_pci_io_mem_t read;
+ grub_efi_pci_io_mem_t write;
+} grub_efi_pci_io_access_t;
+
+typedef struct
+{
+ grub_efi_pci_io_config_t read;
+ grub_efi_pci_io_config_t write;
+} grub_efi_pci_io_config_access_t;
+
+typedef enum
+ {
+ GRUB_EFI_PCI_IO_OPERATION_BUS_MASTER_READ,
+ GRUB_EFI_PCI_IO_OPERATION_BUS_MASTER_WRITE,
+ GRUB_EFI_PCI_IO_OPERATION_BUS_MASTER_COMMON_BUFFER,
+ GRUB_EFI_PCI_IO_OPERATION_BUS_MASTER_MAXIMUM
+ }
+ grub_efi_pci_io_operation_t;
+
+#define GRUB_EFI_PCI_IO_ATTRIBUTE_ISA_IO 0x0002
+#define GRUB_EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO 0x0004
+#define GRUB_EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY 0x0008
+#define GRUB_EFI_PCI_IO_ATTRIBUTE_VGA_IO 0x0010
+#define GRUB_EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO 0x0020
+#define GRUB_EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO 0x0040
+#define GRUB_EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE 0x0080
+#define GRUB_EFI_PCI_IO_ATTRIBUTE_IO 0x0100
+#define GRUB_EFI_PCI_IO_ATTRIBUTE_MEMORY 0x0200
+#define GRUB_EFI_PCI_IO_ATTRIBUTE_BUS_MASTER 0x0400
+#define GRUB_EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED 0x0800
+#define GRUB_EFI_PCI_IO_ATTRIBUTE_MEMORY_DISABLE 0x1000
+#define GRUB_EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE 0x2000
+#define GRUB_EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM 0x4000
+#define GRUB_EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE 0x8000
+#define GRUB_EFI_PCI_IO_ATTRIBUTE_ISA_IO_16 0x10000
+#define GRUB_EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16 0x20000
+#define GRUB_EFI_PCI_IO_ATTRIBUTE_VGA_IO_16 0x40000
+
+typedef enum
+ {
+ GRUB_EFI_PCI_IO_ATTRIBUTE_OPERATION_GET,
+ GRUB_EFI_PCI_IO_ATTRIBUTE_OPERATION_SET,
+ GRUB_EFI_PCI_IO_ATTRIBUTE_OPERATION_ENABLE,
+ GRUB_EFI_PCI_IO_ATTRIBUTE_OPERATION_DISABLE,
+ GRUB_EFI_PCI_IO_ATTRIBUTE_OPERATION_SUPPORTED,
+ GRUB_EFI_PCI_IO_ATTRIBUTE_OPERATION_MAXIMUM
+ }
+ grub_efi_pci_io_attribute_operation_t;
+
+typedef grub_efi_status_t
+(*grub_efi_pci_io_poll_io_mem_t) (struct grub_efi_pci_io *this,
+ grub_efi_pci_io_width_t width,
+ grub_efi_uint8_t bar_ndex,
+ grub_efi_uint64_t offset,
+ grub_efi_uint64_t mask,
+ grub_efi_uint64_t value,
+ grub_efi_uint64_t delay,
+ grub_efi_uint64_t *result);
+
+typedef grub_efi_status_t
+(*grub_efi_pci_io_copy_mem_t) (struct grub_efi_pci_io *this,
+ grub_efi_pci_io_width_t width,
+ grub_efi_uint8_t dest_bar_index,
+ grub_efi_uint64_t dest_offset,
+ grub_efi_uint8_t src_bar_index,
+ grub_efi_uint64_t src_offset,
+ grub_efi_uintn_t count);
+
+typedef grub_efi_status_t
+(*grub_efi_pci_io_map_t) (struct grub_efi_pci_io *this,
+ grub_efi_pci_io_operation_t operation,
+ void *host_address,
+ grub_efi_uintn_t *number_of_bytes,
+ grub_efi_uint64_t *device_address,
+ void **mapping);
+
+typedef grub_efi_status_t
+(*grub_efi_pci_io_unmap_t) (struct grub_efi_pci_io *this,
+ void *mapping);
+
+typedef grub_efi_status_t
+(*grub_efi_pci_io_allocate_buffer_t) (struct grub_efi_pci_io *this,
+ grub_efi_allocate_type_t type,
+ grub_efi_memory_type_t memory_type,
+ grub_efi_uintn_t pages,
+ void **host_address,
+ grub_efi_uint64_t attributes);
+
+typedef grub_efi_status_t
+(*grub_efi_pci_io_free_buffer_t) (struct grub_efi_pci_io *this,
+ grub_efi_allocate_type_t type,
+ grub_efi_memory_type_t memory_type,
+ grub_efi_uintn_t pages,
+ void **host_address,
+ grub_efi_uint64_t attributes);
+
+typedef grub_efi_status_t
+(*grub_efi_pci_io_flush_t) (struct grub_efi_pci_io *this);
+
+typedef grub_efi_status_t
+(*grub_efi_pci_io_get_location_t) (struct grub_efi_pci_io *this,
+ grub_efi_uintn_t *segment_number,
+ grub_efi_uintn_t *bus_number,
+ grub_efi_uintn_t *device_number,
+ grub_efi_uintn_t *function_number);
+
+typedef grub_efi_status_t
+(*grub_efi_pci_io_attributes_t) (struct grub_efi_pci_io *this,
+ grub_efi_pci_io_attribute_operation_t operation,
+ grub_efi_uint64_t attributes,
+ grub_efi_uint64_t *result);
+
+typedef grub_efi_status_t
+(*grub_efi_pci_io_get_bar_attributes_t) (struct grub_efi_pci_io *this,
+ grub_efi_uint8_t bar_index,
+ grub_efi_uint64_t *supports,
+ void **resources);
+
+typedef grub_efi_status_t
+(*grub_efi_pci_io_set_bar_attributes_t) (struct grub_efi_pci_io *this,
+ grub_efi_uint64_t attributes,
+ grub_efi_uint8_t bar_index,
+ grub_efi_uint64_t *offset,
+ grub_efi_uint64_t *length);
+struct grub_efi_pci_io {
+ grub_efi_pci_io_poll_io_mem_t poll_mem;
+ grub_efi_pci_io_poll_io_mem_t poll_io;
+ grub_efi_pci_io_access_t mem;
+ grub_efi_pci_io_access_t io;
+ grub_efi_pci_io_config_access_t pci;
+ grub_efi_pci_io_copy_mem_t copy_mem;
+ grub_efi_pci_io_map_t map;
+ grub_efi_pci_io_unmap_t unmap;
+ grub_efi_pci_io_allocate_buffer_t allocate_buffer;
+ grub_efi_pci_io_free_buffer_t free_buffer;
+ grub_efi_pci_io_flush_t flush;
+ grub_efi_pci_io_get_location_t get_location;
+ grub_efi_pci_io_attributes_t attributes;
+ grub_efi_pci_io_get_bar_attributes_t get_bar_attributes;
+ grub_efi_pci_io_set_bar_attributes_t set_bar_attributes;
+ grub_efi_uint64_t rom_size;
+ void *rom_image;
+};
+typedef struct grub_efi_pci_io grub_efi_pci_io_t;
+
+struct grub_efi_pci_root_io;
+
+typedef struct
+{
+ grub_efi_status_t(*read) (struct grub_efi_pci_root_io *this,
+ grub_efi_pci_io_width_t width,
+ grub_efi_uint64_t address,
+ grub_efi_uintn_t count,
+ void *buffer);
+ grub_efi_status_t(*write) (struct grub_efi_pci_root_io *this,
+ grub_efi_pci_io_width_t width,
+ grub_efi_uint64_t address,
+ grub_efi_uintn_t count,
+ void *buffer);
+} grub_efi_pci_root_io_access_t;
+
+typedef enum
+ {
+ GRUB_EFI_PCI_ROOT_IO_OPERATION_BUS_MASTER_READ,
+ GRUB_EFI_PCI_ROOT_IO_OPERATION_BUS_MASTER_WRITE,
+ GRUB_EFI_PCI_ROOT_IO_OPERATION_BUS_MASTER_COMMON_BUFFER,
+ GRUB_EFI_PCI_ROOT_IO_OPERATION_BUS_MASTER_READ_64,
+ GRUB_EFI_PCI_ROOT_IO_OPERATION_BUS_MASTER_WRITE_64,
+ GRUB_EFI_PCI_ROOT_IO_OPERATION_BUS_MASTER_COMMON_BUFFER_64,
+ GRUB_EFI_PCI_ROOT_IO_OPERATION_BUS_MASTER_MAXIMUM
+ }
+ grub_efi_pci_root_io_operation_t;
+
+typedef grub_efi_status_t
+(*grub_efi_pci_root_io_poll_io_mem_t) (struct grub_efi_pci_root_io *this,
+ grub_efi_pci_io_width_t width,
+ grub_efi_uint64_t address,
+ grub_efi_uint64_t mask,
+ grub_efi_uint64_t value,
+ grub_efi_uint64_t delay,
+ grub_efi_uint64_t *result);
+
+typedef grub_efi_status_t
+(*grub_efi_pci_root_io_copy_mem_t) (struct grub_efi_pci_root_io *this,
+ grub_efi_pci_io_width_t width,
+ grub_efi_uint64_t dest_offset,
+ grub_efi_uint64_t src_offset,
+ grub_efi_uintn_t count);
+
+
+typedef grub_efi_status_t
+(*grub_efi_pci_root_io_map_t) (struct grub_efi_pci_root_io *this,
+ grub_efi_pci_root_io_operation_t operation,
+ void *host_address,
+ grub_efi_uintn_t *number_of_bytes,
+ grub_efi_uint64_t *device_address,
+ void **mapping);
+
+typedef grub_efi_status_t
+(*grub_efi_pci_root_io_unmap_t) (struct grub_efi_pci_root_io *this,
+ void *mapping);
+
+typedef grub_efi_status_t
+(*grub_efi_pci_root_io_allocate_buffer_t) (struct grub_efi_pci_root_io *this,
+ grub_efi_allocate_type_t type,
+ grub_efi_memory_type_t memory_type,
+ grub_efi_uintn_t pages,
+ void **host_address,
+ grub_efi_uint64_t attributes);
+
+typedef grub_efi_status_t
+(*grub_efi_pci_root_io_free_buffer_t) (struct grub_efi_pci_root_io *this,
+ grub_efi_uintn_t pages,
+ void **host_address);
+
+typedef grub_efi_status_t
+(*grub_efi_pci_root_io_flush_t) (struct grub_efi_pci_root_io *this);
+
+typedef grub_efi_status_t
+(*grub_efi_pci_root_io_get_attributes_t) (struct grub_efi_pci_root_io *this,
+ grub_efi_uint64_t *supports,
+ void **resources);
+
+typedef grub_efi_status_t
+(*grub_efi_pci_root_io_set_attributes_t) (struct grub_efi_pci_root_io *this,
+ grub_efi_uint64_t attributes,
+ grub_efi_uint64_t *offset,
+ grub_efi_uint64_t *length);
+
+typedef grub_efi_status_t
+(*grub_efi_pci_root_io_configuration_t) (struct grub_efi_pci_root_io *this,
+ void **resources);
+
+struct grub_efi_pci_root_io {
+ grub_efi_handle_t parent;
+ grub_efi_pci_root_io_poll_io_mem_t poll_mem;
+ grub_efi_pci_root_io_poll_io_mem_t poll_io;
+ grub_efi_pci_root_io_access_t mem;
+ grub_efi_pci_root_io_access_t io;
+ grub_efi_pci_root_io_access_t pci;
+ grub_efi_pci_root_io_copy_mem_t copy_mem;
+ grub_efi_pci_root_io_map_t map;
+ grub_efi_pci_root_io_unmap_t unmap;
+ grub_efi_pci_root_io_allocate_buffer_t allocate_buffer;
+ grub_efi_pci_root_io_free_buffer_t free_buffer;
+ grub_efi_pci_root_io_flush_t flush;
+ grub_efi_pci_root_io_get_attributes_t get_attributes;
+ grub_efi_pci_root_io_set_attributes_t set_attributes;
+ grub_efi_pci_root_io_configuration_t configuration;
+};
+
+typedef struct grub_efi_pci_root_io grub_efi_pci_root_io_t;
+
+#endif /* !GRUB_EFI_PCI_HEADER */
diff --git a/include/grub/efi/pe32.h b/include/grub/efi/pe32.h
new file mode 100644
index 0000000..0ed8781
--- /dev/null
+++ b/include/grub/efi/pe32.h
@@ -0,0 +1,334 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_EFI_PE32_HEADER
+#define GRUB_EFI_PE32_HEADER 1
+
+#include <grub/types.h>
+#include <grub/efi/memory.h>
+
+/* The MSDOS compatibility stub. This was copied from the output of
+ objcopy, and it is not necessary to care about what this means. */
+#define GRUB_PE32_MSDOS_STUB \
+ { \
+ 0x4d, 0x5a, 0x90, 0x00, 0x03, 0x00, 0x00, 0x00, \
+ 0x04, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, \
+ 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
+ 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
+ 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, \
+ 0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd, \
+ 0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68, \
+ 0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72, \
+ 0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f, \
+ 0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e, \
+ 0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20, \
+ 0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a, \
+ 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 \
+ }
+
+#define GRUB_PE32_MSDOS_STUB_SIZE 0x80
+
+#define GRUB_PE32_MAGIC 0x5a4d
+
+/* According to the spec, the minimal alignment is 512 bytes...
+ But some examples (such as EFI drivers in the Intel
+ Sample Implementation) use 32 bytes (0x20) instead, and it seems
+ to be working.
+
+ However, there is firmware showing up in the field now with
+ page alignment constraints to guarantee that page protection
+ bits take effect. Because currently existing GRUB code can not
+ properly distinguish between in-memory and in-file layout, let's
+ bump all alignment to GRUB_EFI_PAGE_SIZE. */
+#define GRUB_PE32_SECTION_ALIGNMENT GRUB_EFI_PAGE_SIZE
+#define GRUB_PE32_FILE_ALIGNMENT GRUB_PE32_SECTION_ALIGNMENT
+
+struct grub_pe32_coff_header
+{
+ grub_uint16_t machine;
+ grub_uint16_t num_sections;
+ grub_uint32_t time;
+ grub_uint32_t symtab_offset;
+ grub_uint32_t num_symbols;
+ grub_uint16_t optional_header_size;
+ grub_uint16_t characteristics;
+};
+
+#define GRUB_PE32_MACHINE_I386 0x14c
+#define GRUB_PE32_MACHINE_IA64 0x200
+#define GRUB_PE32_MACHINE_X86_64 0x8664
+#define GRUB_PE32_MACHINE_ARMTHUMB_MIXED 0x01c2
+#define GRUB_PE32_MACHINE_ARM64 0xAA64
+#define GRUB_PE32_MACHINE_RISCV32 0x5032
+#define GRUB_PE32_MACHINE_RISCV64 0x5064
+
+#define GRUB_PE32_RELOCS_STRIPPED 0x0001
+#define GRUB_PE32_EXECUTABLE_IMAGE 0x0002
+#define GRUB_PE32_LINE_NUMS_STRIPPED 0x0004
+#define GRUB_PE32_LOCAL_SYMS_STRIPPED 0x0008
+#define GRUB_PE32_AGGRESSIVE_WS_TRIM 0x0010
+#define GRUB_PE32_LARGE_ADDRESS_AWARE 0x0020
+#define GRUB_PE32_16BIT_MACHINE 0x0040
+#define GRUB_PE32_BYTES_REVERSED_LO 0x0080
+#define GRUB_PE32_32BIT_MACHINE 0x0100
+#define GRUB_PE32_DEBUG_STRIPPED 0x0200
+#define GRUB_PE32_REMOVABLE_RUN_FROM_SWAP 0x0400
+#define GRUB_PE32_SYSTEM 0x1000
+#define GRUB_PE32_DLL 0x2000
+#define GRUB_PE32_UP_SYSTEM_ONLY 0x4000
+#define GRUB_PE32_BYTES_REVERSED_HI 0x8000
+
+struct grub_pe32_data_directory
+{
+ grub_uint32_t rva;
+ grub_uint32_t size;
+};
+
+struct grub_pe32_optional_header
+{
+ grub_uint16_t magic;
+ grub_uint8_t major_linker_version;
+ grub_uint8_t minor_linker_version;
+ grub_uint32_t code_size;
+ grub_uint32_t data_size;
+ grub_uint32_t bss_size;
+ grub_uint32_t entry_addr;
+ grub_uint32_t code_base;
+
+ grub_uint32_t data_base;
+ grub_uint32_t image_base;
+
+ grub_uint32_t section_alignment;
+ grub_uint32_t file_alignment;
+ grub_uint16_t major_os_version;
+ grub_uint16_t minor_os_version;
+ grub_uint16_t major_image_version;
+ grub_uint16_t minor_image_version;
+ grub_uint16_t major_subsystem_version;
+ grub_uint16_t minor_subsystem_version;
+ grub_uint32_t reserved;
+ grub_uint32_t image_size;
+ grub_uint32_t header_size;
+ grub_uint32_t checksum;
+ grub_uint16_t subsystem;
+ grub_uint16_t dll_characteristics;
+
+ grub_uint32_t stack_reserve_size;
+ grub_uint32_t stack_commit_size;
+ grub_uint32_t heap_reserve_size;
+ grub_uint32_t heap_commit_size;
+
+ grub_uint32_t loader_flags;
+ grub_uint32_t num_data_directories;
+
+ /* Data directories. */
+ struct grub_pe32_data_directory export_table;
+ struct grub_pe32_data_directory import_table;
+ struct grub_pe32_data_directory resource_table;
+ struct grub_pe32_data_directory exception_table;
+ struct grub_pe32_data_directory certificate_table;
+ struct grub_pe32_data_directory base_relocation_table;
+ struct grub_pe32_data_directory debug;
+ struct grub_pe32_data_directory architecture;
+ struct grub_pe32_data_directory global_ptr;
+ struct grub_pe32_data_directory tls_table;
+ struct grub_pe32_data_directory load_config_table;
+ struct grub_pe32_data_directory bound_import;
+ struct grub_pe32_data_directory iat;
+ struct grub_pe32_data_directory delay_import_descriptor;
+ struct grub_pe32_data_directory com_runtime_header;
+ struct grub_pe32_data_directory reserved_entry;
+};
+
+struct grub_pe64_optional_header
+{
+ grub_uint16_t magic;
+ grub_uint8_t major_linker_version;
+ grub_uint8_t minor_linker_version;
+ grub_uint32_t code_size;
+ grub_uint32_t data_size;
+ grub_uint32_t bss_size;
+ grub_uint32_t entry_addr;
+ grub_uint32_t code_base;
+
+ grub_uint64_t image_base;
+
+ grub_uint32_t section_alignment;
+ grub_uint32_t file_alignment;
+ grub_uint16_t major_os_version;
+ grub_uint16_t minor_os_version;
+ grub_uint16_t major_image_version;
+ grub_uint16_t minor_image_version;
+ grub_uint16_t major_subsystem_version;
+ grub_uint16_t minor_subsystem_version;
+ grub_uint32_t reserved;
+ grub_uint32_t image_size;
+ grub_uint32_t header_size;
+ grub_uint32_t checksum;
+ grub_uint16_t subsystem;
+ grub_uint16_t dll_characteristics;
+
+ grub_uint64_t stack_reserve_size;
+ grub_uint64_t stack_commit_size;
+ grub_uint64_t heap_reserve_size;
+ grub_uint64_t heap_commit_size;
+
+ grub_uint32_t loader_flags;
+ grub_uint32_t num_data_directories;
+
+ /* Data directories. */
+ struct grub_pe32_data_directory export_table;
+ struct grub_pe32_data_directory import_table;
+ struct grub_pe32_data_directory resource_table;
+ struct grub_pe32_data_directory exception_table;
+ struct grub_pe32_data_directory certificate_table;
+ struct grub_pe32_data_directory base_relocation_table;
+ struct grub_pe32_data_directory debug;
+ struct grub_pe32_data_directory architecture;
+ struct grub_pe32_data_directory global_ptr;
+ struct grub_pe32_data_directory tls_table;
+ struct grub_pe32_data_directory load_config_table;
+ struct grub_pe32_data_directory bound_import;
+ struct grub_pe32_data_directory iat;
+ struct grub_pe32_data_directory delay_import_descriptor;
+ struct grub_pe32_data_directory com_runtime_header;
+ struct grub_pe32_data_directory reserved_entry;
+};
+
+#define GRUB_PE32_PE32_MAGIC 0x10b
+#define GRUB_PE32_PE64_MAGIC 0x20b
+
+#define GRUB_PE32_SUBSYSTEM_EFI_APPLICATION 10
+
+#define GRUB_PE32_NUM_DATA_DIRECTORIES 16
+
+struct grub_pe32_section_table
+{
+ char name[8];
+ grub_uint32_t virtual_size;
+ grub_uint32_t virtual_address;
+ grub_uint32_t raw_data_size;
+ grub_uint32_t raw_data_offset;
+ grub_uint32_t relocations_offset;
+ grub_uint32_t line_numbers_offset;
+ grub_uint16_t num_relocations;
+ grub_uint16_t num_line_numbers;
+ grub_uint32_t characteristics;
+};
+
+#define GRUB_PE32_SCN_CNT_CODE 0x00000020
+#define GRUB_PE32_SCN_CNT_INITIALIZED_DATA 0x00000040
+#define GRUB_PE32_SCN_MEM_DISCARDABLE 0x02000000
+#define GRUB_PE32_SCN_MEM_EXECUTE 0x20000000
+#define GRUB_PE32_SCN_MEM_READ 0x40000000
+#define GRUB_PE32_SCN_MEM_WRITE 0x80000000
+
+#define GRUB_PE32_SCN_ALIGN_1BYTES 0x00100000
+#define GRUB_PE32_SCN_ALIGN_2BYTES 0x00200000
+#define GRUB_PE32_SCN_ALIGN_4BYTES 0x00300000
+#define GRUB_PE32_SCN_ALIGN_8BYTES 0x00400000
+#define GRUB_PE32_SCN_ALIGN_16BYTES 0x00500000
+#define GRUB_PE32_SCN_ALIGN_32BYTES 0x00600000
+#define GRUB_PE32_SCN_ALIGN_64BYTES 0x00700000
+
+#define GRUB_PE32_SCN_ALIGN_SHIFT 20
+#define GRUB_PE32_SCN_ALIGN_MASK 7
+
+#define GRUB_PE32_SIGNATURE_SIZE 4
+
+struct grub_pe32_header
+{
+ /* This should be filled in with GRUB_PE32_MSDOS_STUB. */
+ grub_uint8_t msdos_stub[GRUB_PE32_MSDOS_STUB_SIZE];
+
+ /* This is always PE\0\0. */
+ char signature[GRUB_PE32_SIGNATURE_SIZE];
+
+ /* The COFF file header. */
+ struct grub_pe32_coff_header coff_header;
+
+#if GRUB_TARGET_SIZEOF_VOID_P == 8
+ /* The Optional header. */
+ struct grub_pe64_optional_header optional_header;
+#else
+ /* The Optional header. */
+ struct grub_pe32_optional_header optional_header;
+#endif
+};
+
+struct grub_pe32_fixup_block
+{
+ grub_uint32_t page_rva;
+ grub_uint32_t block_size;
+ grub_uint16_t entries[0];
+};
+
+#define GRUB_PE32_FIXUP_ENTRY(type, offset) (((type) << 12) | (offset))
+
+#define GRUB_PE32_REL_BASED_ABSOLUTE 0
+#define GRUB_PE32_REL_BASED_HIGH 1
+#define GRUB_PE32_REL_BASED_LOW 2
+#define GRUB_PE32_REL_BASED_HIGHLOW 3
+#define GRUB_PE32_REL_BASED_HIGHADJ 4
+#define GRUB_PE32_REL_BASED_MIPS_JMPADDR 5
+#define GRUB_PE32_REL_BASED_ARM_MOV32A 5
+#define GRUB_PE32_REL_BASED_RISCV_HI20 5
+#define GRUB_PE32_REL_BASED_SECTION 6
+#define GRUB_PE32_REL_BASED_REL 7
+#define GRUB_PE32_REL_BASED_ARM_MOV32T 7
+#define GRUB_PE32_REL_BASED_RISCV_LOW12I 7
+#define GRUB_PE32_REL_BASED_RISCV_LOW12S 8
+#define GRUB_PE32_REL_BASED_IA64_IMM64 9
+#define GRUB_PE32_REL_BASED_DIR64 10
+#define GRUB_PE32_REL_BASED_HIGH3ADJ 11
+
+struct grub_pe32_symbol
+{
+ union
+ {
+ char short_name[8];
+ grub_uint32_t long_name[2];
+ };
+
+ grub_uint32_t value;
+ grub_uint16_t section;
+ grub_uint16_t type;
+ grub_uint8_t storage_class;
+ grub_uint8_t num_aux;
+} GRUB_PACKED;
+
+#define GRUB_PE32_SYM_CLASS_EXTERNAL 2
+#define GRUB_PE32_SYM_CLASS_STATIC 3
+#define GRUB_PE32_SYM_CLASS_FILE 0x67
+
+#define GRUB_PE32_DT_FUNCTION 0x20
+
+struct grub_pe32_reloc
+{
+ grub_uint32_t offset;
+ grub_uint32_t symtab_index;
+ grub_uint16_t type;
+} GRUB_PACKED;
+
+#define GRUB_PE32_REL_I386_DIR32 0x6
+#define GRUB_PE32_REL_I386_REL32 0x14
+
+#endif /* ! GRUB_EFI_PE32_HEADER */
diff --git a/include/grub/efi/sb.h b/include/grub/efi/sb.h
new file mode 100644
index 0000000..30c4335
--- /dev/null
+++ b/include/grub/efi/sb.h
@@ -0,0 +1,43 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2020 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_EFI_SB_H
+#define GRUB_EFI_SB_H 1
+
+#include <grub/types.h>
+#include <grub/dl.h>
+
+#define GRUB_EFI_SECUREBOOT_MODE_UNSET 0
+#define GRUB_EFI_SECUREBOOT_MODE_UNKNOWN 1
+#define GRUB_EFI_SECUREBOOT_MODE_DISABLED 2
+#define GRUB_EFI_SECUREBOOT_MODE_ENABLED 3
+
+#ifdef GRUB_MACHINE_EFI
+extern grub_uint8_t
+EXPORT_FUNC (grub_efi_get_secureboot) (void);
+
+extern void
+grub_shim_lock_verifier_setup (void);
+#else
+static inline grub_uint8_t
+grub_efi_get_secureboot (void)
+{
+ return GRUB_EFI_SECUREBOOT_MODE_UNSET;
+}
+#endif
+#endif /* GRUB_EFI_SB_H */
diff --git a/include/grub/efi/tpm.h b/include/grub/efi/tpm.h
new file mode 100644
index 0000000..ec39725
--- /dev/null
+++ b/include/grub/efi/tpm.h
@@ -0,0 +1,198 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2018 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_EFI_TPM_HEADER
+#define GRUB_EFI_TPM_HEADER 1
+
+#define EFI_TPM_GUID {0xf541796d, 0xa62e, 0x4954, {0xa7, 0x75, 0x95, 0x84, 0xf6, 0x1b, 0x9c, 0xdd }};
+#define EFI_TPM2_GUID {0x607f766c, 0x7455, 0x42be, {0x93, 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f }};
+
+#define TCG_ALG_SHA 0x00000004
+
+/* These structs are as defined in the TCG EFI Protocol Specification, family 2.0. */
+
+struct __TCG_VERSION
+{
+ grub_efi_uint8_t Major;
+ grub_efi_uint8_t Minor;
+ grub_efi_uint8_t RevMajor;
+ grub_efi_uint8_t RevMinor;
+};
+typedef struct __TCG_VERSION TCG_VERSION;
+
+struct __TCG_EFI_BOOT_SERVICE_CAPABILITY
+{
+ /* Size of this structure. */
+ grub_efi_uint8_t Size;
+ TCG_VERSION StructureVersion;
+ TCG_VERSION ProtocolSpecVersion;
+ /* Hash algorithms supported by this TPM. */
+ grub_efi_uint8_t HashAlgorithmBitmap;
+ /* 1 if TPM present. */
+ char TPMPresentFlag;
+ /* 1 if TPM deactivated. */
+ char TPMDeactivatedFlag;
+};
+typedef struct __TCG_EFI_BOOT_SERVICE_CAPABILITY TCG_EFI_BOOT_SERVICE_CAPABILITY;
+
+struct tdTCG_PCR_EVENT
+{
+ grub_efi_uint32_t PCRIndex;
+ grub_efi_uint32_t EventType;
+ grub_efi_uint8_t digest[20];
+ grub_efi_uint32_t EventSize;
+ grub_efi_uint8_t Event[1];
+};
+typedef struct tdTCG_PCR_EVENT TCG_PCR_EVENT;
+
+struct grub_efi_tpm_protocol
+{
+ grub_efi_status_t (*status_check) (struct grub_efi_tpm_protocol *this,
+ TCG_EFI_BOOT_SERVICE_CAPABILITY *
+ ProtocolCapability,
+ grub_efi_uint32_t *TCGFeatureFlags,
+ grub_efi_physical_address_t *
+ EventLogLocation,
+ grub_efi_physical_address_t *
+ EventLogLastEntry);
+ grub_efi_status_t (*hash_all) (struct grub_efi_tpm_protocol *this,
+ grub_efi_uint8_t *HashData,
+ grub_efi_uint64_t HashLen,
+ grub_efi_uint32_t AlgorithmId,
+ grub_efi_uint64_t *HashedDataLen,
+ grub_efi_uint8_t **HashedDataResult);
+ grub_efi_status_t (*log_event) (struct grub_efi_tpm_protocol *this,
+ TCG_PCR_EVENT *TCGLogData,
+ grub_efi_uint32_t *EventNumber,
+ grub_efi_uint32_t Flags);
+ grub_efi_status_t (*pass_through_to_tpm) (struct grub_efi_tpm_protocol *
+ this,
+ grub_efi_uint32_t
+ TpmInputParameterBlockSize,
+ grub_efi_uint8_t *
+ TpmInputParameterBlock,
+ grub_efi_uint32_t
+ TpmOutputParameterBlockSize,
+ grub_efi_uint8_t *
+ TpmOutputParameterBlock);
+ grub_efi_status_t (*log_extend_event) (struct grub_efi_tpm_protocol *this,
+ grub_efi_physical_address_t HashData,
+ grub_efi_uint64_t HashDataLen,
+ grub_efi_uint32_t AlgorithmId,
+ TCG_PCR_EVENT *TCGLogData,
+ grub_efi_uint32_t *EventNumber,
+ grub_efi_physical_address_t *
+ EventLogLastEntry);
+};
+
+typedef struct grub_efi_tpm_protocol grub_efi_tpm_protocol_t;
+
+typedef grub_efi_uint32_t EFI_TCG2_EVENT_LOG_BITMAP;
+typedef grub_efi_uint32_t EFI_TCG2_EVENT_LOG_FORMAT;
+typedef grub_efi_uint32_t EFI_TCG2_EVENT_ALGORITHM_BITMAP;
+
+struct tdEFI_TCG2_VERSION
+{
+ grub_efi_uint8_t Major;
+ grub_efi_uint8_t Minor;
+} GRUB_PACKED;
+typedef struct tdEFI_TCG2_VERSION EFI_TCG2_VERSION;
+
+struct tdEFI_TCG2_BOOT_SERVICE_CAPABILITY
+{
+ grub_efi_uint8_t Size;
+ EFI_TCG2_VERSION StructureVersion;
+ EFI_TCG2_VERSION ProtocolVersion;
+ EFI_TCG2_EVENT_ALGORITHM_BITMAP HashAlgorithmBitmap;
+ EFI_TCG2_EVENT_LOG_BITMAP SupportedEventLogs;
+ grub_efi_boolean_t TPMPresentFlag;
+ grub_efi_uint16_t MaxCommandSize;
+ grub_efi_uint16_t MaxResponseSize;
+ grub_efi_uint32_t ManufacturerID;
+ grub_efi_uint32_t NumberOfPcrBanks;
+ EFI_TCG2_EVENT_ALGORITHM_BITMAP ActivePcrBanks;
+};
+typedef struct tdEFI_TCG2_BOOT_SERVICE_CAPABILITY EFI_TCG2_BOOT_SERVICE_CAPABILITY;
+
+typedef grub_efi_uint32_t TCG_PCRINDEX;
+typedef grub_efi_uint32_t TCG_EVENTTYPE;
+
+struct tdEFI_TCG2_EVENT_HEADER
+{
+ grub_efi_uint32_t HeaderSize;
+ grub_efi_uint16_t HeaderVersion;
+ TCG_PCRINDEX PCRIndex;
+ TCG_EVENTTYPE EventType;
+} GRUB_PACKED;
+typedef struct tdEFI_TCG2_EVENT_HEADER EFI_TCG2_EVENT_HEADER;
+
+struct tdEFI_TCG2_EVENT
+{
+ grub_efi_uint32_t Size;
+ EFI_TCG2_EVENT_HEADER Header;
+ grub_efi_uint8_t Event[1];
+} GRUB_PACKED;
+typedef struct tdEFI_TCG2_EVENT EFI_TCG2_EVENT;
+
+struct grub_efi_tpm2_protocol
+{
+ grub_efi_status_t (*get_capability) (struct grub_efi_tpm2_protocol *this,
+ EFI_TCG2_BOOT_SERVICE_CAPABILITY *
+ ProtocolCapability);
+ grub_efi_status_t (*get_event_log) (struct grub_efi_tpm2_protocol *this,
+ EFI_TCG2_EVENT_LOG_FORMAT
+ EventLogFormat,
+ grub_efi_physical_address_t *
+ EventLogLocation,
+ grub_efi_physical_address_t *
+ EventLogLastEntry,
+ grub_efi_boolean_t * EventLogTruncated);
+ grub_efi_status_t (*hash_log_extend_event) (struct grub_efi_tpm2_protocol *
+ this, grub_efi_uint64_t Flags,
+ grub_efi_physical_address_t
+ DataToHash,
+ grub_efi_uint64_t DataToHashLen,
+ EFI_TCG2_EVENT *EfiTcgEvent);
+ grub_efi_status_t (*submit_command) (struct grub_efi_tpm2_protocol *this,
+ grub_efi_uint32_t
+ InputParameterBlockSize,
+ grub_efi_uint8_t *InputParameterBlock,
+ grub_efi_uint32_t
+ OutputParameterBlockSize,
+ grub_efi_uint8_t *
+ OutputParameterBlock);
+ grub_efi_status_t (*get_active_pcr_banks) (struct grub_efi_tpm2_protocol *
+ this,
+ grub_efi_uint32_t *
+ ActivePcrBanks);
+ grub_efi_status_t (*set_active_pcr_banks) (struct grub_efi_tpm2_protocol *
+ this,
+ grub_efi_uint32_t
+ ActivePcrBanks);
+ grub_efi_status_t (*get_result_of_set_active_pcr_banks) (struct
+ grub_efi_tpm2_protocol
+ *this,
+ grub_efi_uint32_t *
+ OperationPresent,
+ grub_efi_uint32_t *
+ Response);
+};
+
+typedef struct grub_efi_tpm2_protocol grub_efi_tpm2_protocol_t;
+
+#endif
diff --git a/include/grub/efi/uga_draw.h b/include/grub/efi/uga_draw.h
new file mode 100644
index 0000000..a31f267
--- /dev/null
+++ b/include/grub/efi/uga_draw.h
@@ -0,0 +1,76 @@
+/* uga_draw.h - definitions of the uga draw protocol */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* The console control protocol is not a part of the EFI spec,
+ but defined in Intel's Sample Implementation. */
+
+#ifndef GRUB_EFI_UGA_DRAW_HEADER
+#define GRUB_EFI_UGA_DRAW_HEADER 1
+
+#define GRUB_EFI_UGA_DRAW_GUID \
+ { 0x982c298b, 0xf4fa, 0x41cb, { 0xb8, 0x38, 0x77, 0xaa, 0x68, 0x8f, 0xb8, 0x39 }}
+
+enum grub_efi_uga_blt_operation
+{
+ GRUB_EFI_UGA_VIDEO_FILL,
+ GRUB_EFI_UGA_VIDEO_TO_BLT,
+ GRUB_EFI_UGA_BLT_TO_VIDEO,
+ GRUB_EFI_UGA_VIDEO_TO_VIDEO,
+ GRUB_EFI_UGA_BLT_MAX
+};
+
+struct grub_efi_uga_pixel
+{
+ grub_uint8_t Blue;
+ grub_uint8_t Green;
+ grub_uint8_t Red;
+ grub_uint8_t Reserved;
+};
+
+struct grub_efi_uga_draw_protocol
+{
+ grub_efi_status_t
+ (*get_mode) (struct grub_efi_uga_draw_protocol *this,
+ grub_uint32_t *width,
+ grub_uint32_t *height,
+ grub_uint32_t *depth,
+ grub_uint32_t *refresh_rate);
+
+ grub_efi_status_t
+ (*set_mode) (struct grub_efi_uga_draw_protocol *this,
+ grub_uint32_t width,
+ grub_uint32_t height,
+ grub_uint32_t depth,
+ grub_uint32_t refresh_rate);
+
+ grub_efi_status_t
+ (*blt) (struct grub_efi_uga_draw_protocol *this,
+ struct grub_efi_uga_pixel *blt_buffer,
+ enum grub_efi_uga_blt_operation blt_operation,
+ grub_efi_uintn_t src_x,
+ grub_efi_uintn_t src_y,
+ grub_efi_uintn_t dest_x,
+ grub_efi_uintn_t dest_y,
+ grub_efi_uintn_t width,
+ grub_efi_uintn_t height,
+ grub_efi_uintn_t delta);
+};
+typedef struct grub_efi_uga_draw_protocol grub_efi_uga_draw_protocol_t;
+
+#endif /* ! GRUB_EFI_UGA_DRAW_HEADER */
diff --git a/include/grub/efiemu/efiemu.h b/include/grub/efiemu/efiemu.h
new file mode 100644
index 0000000..5325e58
--- /dev/null
+++ b/include/grub/efiemu/efiemu.h
@@ -0,0 +1,286 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_EFI_EMU_HEADER
+#define GRUB_EFI_EMU_HEADER 1
+
+#include <grub/efi/api.h>
+#include <grub/file.h>
+#include <grub/memory.h>
+
+#define GRUB_EFIEMU_PAGESIZE 4096
+
+/* EFI api defined in 32-bit and 64-bit version*/
+struct grub_efi_system_table32
+{
+ grub_efi_table_header_t hdr;
+ grub_efi_uint32_t firmware_vendor;
+ grub_efi_uint32_t firmware_revision;
+ grub_efi_uint32_t console_in_handler;
+ grub_efi_uint32_t con_in;
+ grub_efi_uint32_t console_out_handler;
+ grub_efi_uint32_t con_out;
+ grub_efi_uint32_t standard_error_handle;
+ grub_efi_uint32_t std_err;
+ grub_efi_uint32_t runtime_services;
+ grub_efi_uint32_t boot_services;
+ grub_efi_uint32_t num_table_entries;
+ grub_efi_uint32_t configuration_table;
+} GRUB_PACKED;
+typedef struct grub_efi_system_table32 grub_efi_system_table32_t;
+
+struct grub_efi_system_table64
+{
+ grub_efi_table_header_t hdr;
+ grub_efi_uint64_t firmware_vendor;
+ grub_efi_uint32_t firmware_revision;
+ grub_efi_uint32_t pad;
+ grub_efi_uint64_t console_in_handler;
+ grub_efi_uint64_t con_in;
+ grub_efi_uint64_t console_out_handler;
+ grub_efi_uint64_t con_out;
+ grub_efi_uint64_t standard_error_handle;
+ grub_efi_uint64_t std_err;
+ grub_efi_uint64_t runtime_services;
+ grub_efi_uint64_t boot_services;
+ grub_efi_uint64_t num_table_entries;
+ grub_efi_uint64_t configuration_table;
+} GRUB_PACKED;
+typedef struct grub_efi_system_table64 grub_efi_system_table64_t;
+
+struct grub_efiemu_runtime_services32
+{
+ grub_efi_table_header_t hdr;
+ grub_efi_uint32_t get_time;
+ grub_efi_uint32_t set_time;
+ grub_efi_uint32_t get_wakeup_time;
+ grub_efi_uint32_t set_wakeup_time;
+ grub_efi_uint32_t set_virtual_address_map;
+ grub_efi_uint32_t convert_pointer;
+ grub_efi_uint32_t get_variable;
+ grub_efi_uint32_t get_next_variable_name;
+ grub_efi_uint32_t set_variable;
+ grub_efi_uint32_t get_next_high_monotonic_count;
+ grub_efi_uint32_t reset_system;
+} GRUB_PACKED;
+typedef struct grub_efiemu_runtime_services32 grub_efiemu_runtime_services32_t;
+
+struct grub_efiemu_runtime_services64
+{
+ grub_efi_table_header_t hdr;
+ grub_efi_uint64_t get_time;
+ grub_efi_uint64_t set_time;
+ grub_efi_uint64_t get_wakeup_time;
+ grub_efi_uint64_t set_wakeup_time;
+ grub_efi_uint64_t set_virtual_address_map;
+ grub_efi_uint64_t convert_pointer;
+ grub_efi_uint64_t get_variable;
+ grub_efi_uint64_t get_next_variable_name;
+ grub_efi_uint64_t set_variable;
+ grub_efi_uint64_t get_next_high_monotonic_count;
+ grub_efi_uint64_t reset_system;
+} GRUB_PACKED;
+typedef struct grub_efiemu_runtime_services64 grub_efiemu_runtime_services64_t;
+
+extern grub_efi_system_table32_t *grub_efiemu_system_table32;
+extern grub_efi_system_table64_t *grub_efiemu_system_table64;
+
+/* Convenience macros to access currently loaded efiemu */
+#define grub_efiemu_system_table ((grub_efiemu_sizeof_uintn_t () == 8) \
+ ? (void *) grub_efiemu_system_table64 \
+ : (void *) grub_efiemu_system_table32)
+#define GRUB_EFIEMU_SIZEOF_OF_UINTN (grub_efiemu_sizeof_uintn_t ())
+#define GRUB_EFIEMU_SYSTEM_TABLE(x) ((grub_efiemu_sizeof_uintn_t () == 8) \
+ ? grub_efiemu_system_table64->x \
+ : grub_efiemu_system_table32->x)
+#define GRUB_EFIEMU_SYSTEM_TABLE_SET(x,y) ((grub_efiemu_sizeof_uintn_t () == 8)\
+ ? (grub_efiemu_system_table64->x \
+ = (y)) \
+ : (grub_efiemu_system_table32->x \
+ = (y)))
+#define GRUB_EFIEMU_SYSTEM_TABLE_PTR(x) ((grub_efiemu_sizeof_uintn_t () == 8)\
+ ? (void *) (grub_addr_t) \
+ (grub_efiemu_system_table64->x) \
+ : (void *) (grub_addr_t) \
+ (grub_efiemu_system_table32->x))
+#define GRUB_EFIEMU_SYSTEM_TABLE_VAR(x) ((grub_efiemu_sizeof_uintn_t () == 8) \
+ ? (void *) \
+ &(grub_efiemu_system_table64->x) \
+ : (void *) \
+ &(grub_efiemu_system_table32->x))
+#define GRUB_EFIEMU_SYSTEM_TABLE_SIZEOF(x) \
+ ((grub_efiemu_sizeof_uintn_t () == 8) \
+ ? sizeof(grub_efiemu_system_table64->x)\
+ : sizeof(grub_efiemu_system_table32->x))
+#define GRUB_EFIEMU_SYSTEM_TABLE_SIZEOF_TOTAL ((grub_efiemu_sizeof_uintn_t () == 8) ? sizeof(*grub_efiemu_system_table64):sizeof(*grub_efiemu_system_table32))
+
+/* ELF management definitions and functions */
+
+struct grub_efiemu_segment
+{
+ struct grub_efiemu_segment *next;
+ grub_size_t size;
+ unsigned section;
+ int handle;
+ int ptv_rel_needed;
+ grub_off_t off;
+ void *srcptr;
+};
+typedef struct grub_efiemu_segment *grub_efiemu_segment_t;
+
+struct grub_efiemu_elf_sym
+{
+ int handle;
+ grub_off_t off;
+ unsigned section;
+};
+
+int grub_efiemu_check_header32 (void *ehdr, grub_size_t size);
+int grub_efiemu_check_header64 (void *ehdr, grub_size_t size);
+grub_err_t grub_efiemu_loadcore_init32 (void *core,
+ const char *filename,
+ grub_size_t core_size,
+ grub_efiemu_segment_t *segments);
+grub_err_t grub_efiemu_loadcore_init64 (void *core, const char *filename,
+ grub_size_t core_size,
+ grub_efiemu_segment_t *segments);
+grub_err_t grub_efiemu_loadcore_load32 (void *core,
+ grub_size_t core_size,
+ grub_efiemu_segment_t segments);
+grub_err_t grub_efiemu_loadcore_load64 (void *core,
+ grub_size_t core_size,
+ grub_efiemu_segment_t segments);
+grub_err_t grub_efiemu_loadcore_unload32 (void);
+grub_err_t grub_efiemu_loadcore_unload64 (void);
+grub_err_t grub_efiemu_loadcore_unload(void);
+grub_err_t grub_efiemu_loadcore_init (grub_file_t file,
+ const char *filename);
+grub_err_t grub_efiemu_loadcore_load (void);
+
+/* Configuration tables manipulation. Definitions and functions */
+struct grub_efiemu_configuration_table
+{
+ struct grub_efiemu_configuration_table *next;
+ grub_efi_guid_t guid;
+ void * (*get_table) (void *data);
+ void (*unload) (void *data);
+ void *data;
+};
+struct grub_efiemu_configuration_table32
+{
+ grub_efi_packed_guid_t vendor_guid;
+ grub_efi_uint32_t vendor_table;
+} GRUB_PACKED;
+typedef struct grub_efiemu_configuration_table32 grub_efiemu_configuration_table32_t;
+struct grub_efiemu_configuration_table64
+{
+ grub_efi_packed_guid_t vendor_guid;
+ grub_efi_uint64_t vendor_table;
+} GRUB_PACKED;
+typedef struct grub_efiemu_configuration_table64 grub_efiemu_configuration_table64_t;
+grub_err_t grub_efiemu_unregister_configuration_table (grub_efi_guid_t guid);
+grub_err_t
+grub_efiemu_register_configuration_table (grub_efi_guid_t guid,
+ void * (*get_table) (void *data),
+ void (*unload) (void *data),
+ void *data);
+
+/* Memory management functions */
+int grub_efiemu_request_memalign (grub_size_t align, grub_size_t size,
+ grub_efi_memory_type_t type);
+void *grub_efiemu_mm_obtain_request (int handle);
+grub_err_t grub_efiemu_mm_unload (void);
+grub_err_t grub_efiemu_mm_do_alloc (void);
+grub_err_t grub_efiemu_mm_init (void);
+void grub_efiemu_mm_return_request (int handle);
+grub_efi_memory_type_t grub_efiemu_mm_get_type (int handle);
+
+/* Drop-in replacements for grub_efi_* and grub_machine_* */
+int grub_efiemu_get_memory_map (grub_efi_uintn_t *memory_map_size,
+ grub_efi_memory_descriptor_t *memory_map,
+ grub_efi_uintn_t *map_key,
+ grub_efi_uintn_t *descriptor_size,
+ grub_efi_uint32_t *descriptor_version);
+
+
+grub_err_t
+grub_efiemu_finish_boot_services (grub_efi_uintn_t *memory_map_size,
+ grub_efi_memory_descriptor_t *memory_map,
+ grub_efi_uintn_t *map_key,
+ grub_efi_uintn_t *descriptor_size,
+ grub_efi_uint32_t *descriptor_version);
+
+grub_err_t
+grub_efiemu_mmap_iterate (grub_memory_hook_t hook, void *hook_data);
+int grub_efiemu_sizeof_uintn_t (void);
+grub_err_t
+grub_efiemu_get_lower_upper_memory (grub_uint64_t *lower, grub_uint64_t *upper);
+
+/* efiemu main control definitions and functions*/
+typedef enum {GRUB_EFIEMU_NOTLOADED,
+ GRUB_EFIEMU32, GRUB_EFIEMU64} grub_efiemu_mode_t;
+struct grub_efiemu_prepare_hook
+{
+ struct grub_efiemu_prepare_hook *next;
+ grub_err_t (*hook) (void *data);
+ void (*unload) (void *data);
+ void *data;
+};
+grub_err_t grub_efiemu_prepare32 (struct grub_efiemu_prepare_hook
+ *prepare_hooks,
+ struct grub_efiemu_configuration_table
+ *config_tables);
+grub_err_t grub_efiemu_prepare64 (struct grub_efiemu_prepare_hook
+ *prepare_hooks,
+ struct grub_efiemu_configuration_table
+ *config_tables);
+grub_err_t grub_efiemu_unload (void);
+grub_err_t grub_efiemu_prepare (void);
+grub_err_t
+grub_efiemu_register_prepare_hook (grub_err_t (*hook) (void *data),
+ void (*unload) (void *data),
+ void *data);
+
+/* symbols and pointers */
+grub_err_t grub_efiemu_alloc_syms (void);
+grub_err_t grub_efiemu_request_symbols (int num);
+grub_err_t grub_efiemu_resolve_symbol (const char *name,
+ int *handle, grub_off_t *off);
+grub_err_t grub_efiemu_register_symbol (const char *name,
+ int handle, grub_off_t off);
+void grub_efiemu_free_syms (void);
+grub_err_t grub_efiemu_write_value (void * addr, grub_uint32_t value,
+ int plus_handle,
+ int minus_handle, int ptv_needed, int size);
+grub_err_t grub_efiemu_write_sym_markers (void);
+grub_err_t grub_efiemu_pnvram (void);
+const char *grub_efiemu_get_default_core_name (void);
+void grub_efiemu_pnvram_cmd_unregister (void);
+grub_err_t grub_efiemu_autocore (void);
+grub_err_t grub_efiemu_crc32 (void);
+grub_err_t grub_efiemu_crc64 (void);
+grub_err_t
+grub_efiemu_set_virtual_address_map (grub_efi_uintn_t memory_map_size,
+ grub_efi_uintn_t descriptor_size,
+ grub_efi_uint32_t descriptor_version
+ __attribute__ ((unused)),
+ grub_efi_memory_descriptor_t *virtual_map);
+
+grub_err_t grub_machine_efiemu_init_tables (void);
+
+#endif /* ! GRUB_EFI_EMU_HEADER */
diff --git a/include/grub/efiemu/runtime.h b/include/grub/efiemu/runtime.h
new file mode 100644
index 0000000..36d2ded
--- /dev/null
+++ b/include/grub/efiemu/runtime.h
@@ -0,0 +1,37 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_EFI_EMU_RUNTIME_HEADER
+#define GRUB_EFI_EMU_RUNTIME_HEADER 1
+
+struct grub_efiemu_ptv_rel
+{
+ grub_uint64_t addr;
+ grub_efi_memory_type_t plustype;
+ grub_efi_memory_type_t minustype;
+ grub_uint32_t size;
+} GRUB_PACKED;
+
+struct efi_variable
+{
+ grub_efi_packed_guid_t guid;
+ grub_uint32_t namelen;
+ grub_uint32_t size;
+ grub_efi_uint32_t attributes;
+} GRUB_PACKED;
+#endif /* ! GRUB_EFI_EMU_RUNTIME_HEADER */
diff --git a/include/grub/elf.h b/include/grub/elf.h
new file mode 100644
index 0000000..c478933
--- /dev/null
+++ b/include/grub/elf.h
@@ -0,0 +1,2587 @@
+/* This file defines standard ELF types, structures, and macros.
+ Copyright (C) 1995-1999,2000,2001,2002,2008,2009 Free Software Foundation, Inc.
+ This file was part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef GRUB_ELF_H
+#define GRUB_ELF_H 1
+
+/* Standard ELF types. */
+
+#include <grub/types.h>
+
+/* Type for a 16-bit quantity. */
+typedef grub_uint16_t Elf32_Half;
+typedef grub_uint16_t Elf64_Half;
+
+/* Types for signed and unsigned 32-bit quantities. */
+typedef grub_uint32_t Elf32_Word;
+typedef grub_int32_t Elf32_Sword;
+typedef grub_uint32_t Elf64_Word;
+typedef grub_int32_t Elf64_Sword;
+
+/* Types for signed and unsigned 64-bit quantities. */
+typedef grub_uint64_t Elf32_Xword;
+typedef grub_int64_t Elf32_Sxword;
+typedef grub_uint64_t Elf64_Xword;
+typedef grub_int64_t Elf64_Sxword;
+
+/* Type of addresses. */
+typedef grub_uint32_t Elf32_Addr;
+typedef grub_uint64_t Elf64_Addr;
+
+/* Type of file offsets. */
+typedef grub_uint32_t Elf32_Off;
+typedef grub_uint64_t Elf64_Off;
+
+/* Type for section indices, which are 16-bit quantities. */
+typedef grub_uint16_t Elf32_Section;
+typedef grub_uint16_t Elf64_Section;
+
+/* Type for version symbol information. */
+typedef Elf32_Half Elf32_Versym;
+typedef Elf64_Half Elf64_Versym;
+
+
+/* The ELF file header. This appears at the start of every ELF file. */
+
+#define EI_NIDENT (16)
+
+typedef struct
+{
+ unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */
+ Elf32_Half e_type; /* Object file type */
+ Elf32_Half e_machine; /* Architecture */
+ Elf32_Word e_version; /* Object file version */
+ Elf32_Addr e_entry; /* Entry point virtual address */
+ Elf32_Off e_phoff; /* Program header table file offset */
+ Elf32_Off e_shoff; /* Section header table file offset */
+ Elf32_Word e_flags; /* Processor-specific flags */
+ Elf32_Half e_ehsize; /* ELF header size in bytes */
+ Elf32_Half e_phentsize; /* Program header table entry size */
+ Elf32_Half e_phnum; /* Program header table entry count */
+ Elf32_Half e_shentsize; /* Section header table entry size */
+ Elf32_Half e_shnum; /* Section header table entry count */
+ Elf32_Half e_shstrndx; /* Section header string table index */
+} Elf32_Ehdr;
+
+typedef struct
+{
+ unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */
+ Elf64_Half e_type; /* Object file type */
+ Elf64_Half e_machine; /* Architecture */
+ Elf64_Word e_version; /* Object file version */
+ Elf64_Addr e_entry; /* Entry point virtual address */
+ Elf64_Off e_phoff; /* Program header table file offset */
+ Elf64_Off e_shoff; /* Section header table file offset */
+ Elf64_Word e_flags; /* Processor-specific flags */
+ Elf64_Half e_ehsize; /* ELF header size in bytes */
+ Elf64_Half e_phentsize; /* Program header table entry size */
+ Elf64_Half e_phnum; /* Program header table entry count */
+ Elf64_Half e_shentsize; /* Section header table entry size */
+ Elf64_Half e_shnum; /* Section header table entry count */
+ Elf64_Half e_shstrndx; /* Section header string table index */
+} Elf64_Ehdr;
+
+/* Fields in the e_ident array. The EI_* macros are indices into the
+ array. The macros under each EI_* macro are the values the byte
+ may have. */
+
+#define EI_MAG0 0 /* File identification byte 0 index */
+#define ELFMAG0 0x7f /* Magic number byte 0 */
+
+#define EI_MAG1 1 /* File identification byte 1 index */
+#define ELFMAG1 'E' /* Magic number byte 1 */
+
+#define EI_MAG2 2 /* File identification byte 2 index */
+#define ELFMAG2 'L' /* Magic number byte 2 */
+
+#define EI_MAG3 3 /* File identification byte 3 index */
+#define ELFMAG3 'F' /* Magic number byte 3 */
+
+/* Conglomeration of the identification bytes, for easy testing as a word. */
+#define ELFMAG "\177ELF"
+#define SELFMAG 4
+
+#define EI_CLASS 4 /* File class byte index */
+#define ELFCLASSNONE 0 /* Invalid class */
+#define ELFCLASS32 1 /* 32-bit objects */
+#define ELFCLASS64 2 /* 64-bit objects */
+#define ELFCLASSNUM 3
+
+#define EI_DATA 5 /* Data encoding byte index */
+#define ELFDATANONE 0 /* Invalid data encoding */
+#define ELFDATA2LSB 1 /* 2's complement, little endian */
+#define ELFDATA2MSB 2 /* 2's complement, big endian */
+#define ELFDATANUM 3
+
+#define EI_VERSION 6 /* File version byte index */
+ /* Value must be EV_CURRENT */
+
+#define EI_OSABI 7 /* OS ABI identification */
+#define ELFOSABI_NONE 0 /* UNIX System V ABI */
+#define ELFOSABI_SYSV 0 /* Alias. */
+#define ELFOSABI_HPUX 1 /* HP-UX */
+#define ELFOSABI_NETBSD 2 /* NetBSD. */
+#define ELFOSABI_LINUX 3 /* Linux. */
+#define ELFOSABI_SOLARIS 6 /* Sun Solaris. */
+#define ELFOSABI_AIX 7 /* IBM AIX. */
+#define ELFOSABI_IRIX 8 /* SGI Irix. */
+#define ELFOSABI_FREEBSD 9 /* FreeBSD. */
+#define ELFOSABI_TRU64 10 /* Compaq TRU64 UNIX. */
+#define ELFOSABI_MODESTO 11 /* Novell Modesto. */
+#define ELFOSABI_OPENBSD 12 /* OpenBSD. */
+#define ELFOSABI_ARM_AEABI 64 /* ARM EABI */
+#define ELFOSABI_ARM 97 /* ARM */
+#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */
+
+#define EI_ABIVERSION 8 /* ABI version */
+
+#define EI_PAD 9 /* Byte index of padding bytes */
+
+/* Legal values for e_type (object file type). */
+
+#define ET_NONE 0 /* No file type */
+#define ET_REL 1 /* Relocatable file */
+#define ET_EXEC 2 /* Executable file */
+#define ET_DYN 3 /* Shared object file */
+#define ET_CORE 4 /* Core file */
+#define ET_NUM 5 /* Number of defined types */
+#define ET_LOOS 0xfe00 /* OS-specific range start */
+#define ET_HIOS 0xfeff /* OS-specific range end */
+#define ET_LOPROC 0xff00 /* Processor-specific range start */
+#define ET_HIPROC 0xffff /* Processor-specific range end */
+
+/* Legal values for e_machine (architecture). */
+
+#define EM_NONE 0 /* No machine */
+#define EM_M32 1 /* AT&T WE 32100 */
+#define EM_SPARC 2 /* SUN SPARC */
+#define EM_386 3 /* Intel 80386 */
+#define EM_68K 4 /* Motorola m68k family */
+#define EM_88K 5 /* Motorola m88k family */
+#define EM_860 7 /* Intel 80860 */
+#define EM_MIPS 8 /* MIPS R3000 big-endian */
+#define EM_S370 9 /* IBM System/370 */
+#define EM_MIPS_RS3_LE 10 /* MIPS R3000 little-endian */
+
+#define EM_PARISC 15 /* HPPA */
+#define EM_VPP500 17 /* Fujitsu VPP500 */
+#define EM_SPARC32PLUS 18 /* Sun's "v8plus" */
+#define EM_960 19 /* Intel 80960 */
+#define EM_PPC 20 /* PowerPC */
+#define EM_PPC64 21 /* PowerPC 64-bit */
+#define EM_S390 22 /* IBM S390 */
+
+#define EM_V800 36 /* NEC V800 series */
+#define EM_FR20 37 /* Fujitsu FR20 */
+#define EM_RH32 38 /* TRW RH-32 */
+#define EM_RCE 39 /* Motorola RCE */
+#define EM_ARM 40 /* ARM */
+#define EM_FAKE_ALPHA 41 /* Digital Alpha */
+#define EM_SH 42 /* Hitachi SH */
+#define EM_SPARCV9 43 /* SPARC v9 64-bit */
+#define EM_TRICORE 44 /* Siemens Tricore */
+#define EM_ARC 45 /* Argonaut RISC Core */
+#define EM_H8_300 46 /* Hitachi H8/300 */
+#define EM_H8_300H 47 /* Hitachi H8/300H */
+#define EM_H8S 48 /* Hitachi H8S */
+#define EM_H8_500 49 /* Hitachi H8/500 */
+#define EM_IA_64 50 /* Intel Merced */
+#define EM_MIPS_X 51 /* Stanford MIPS-X */
+#define EM_COLDFIRE 52 /* Motorola Coldfire */
+#define EM_68HC12 53 /* Motorola M68HC12 */
+#define EM_MMA 54 /* Fujitsu MMA Multimedia Accelerator*/
+#define EM_PCP 55 /* Siemens PCP */
+#define EM_NCPU 56 /* Sony nCPU embedded RISC */
+#define EM_NDR1 57 /* Denso NDR1 microprocessor */
+#define EM_STARCORE 58 /* Motorola Start*Core processor */
+#define EM_ME16 59 /* Toyota ME16 processor */
+#define EM_ST100 60 /* STMicroelectronics ST100 processor */
+#define EM_TINYJ 61 /* Advanced Logic Corp. Tinyj emb.fam*/
+#define EM_X86_64 62 /* AMD x86-64 architecture */
+#define EM_PDSP 63 /* Sony DSP Processor */
+
+#define EM_FX66 66 /* Siemens FX66 microcontroller */
+#define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 mc */
+#define EM_ST7 68 /* STMicroelectronics ST7 8 bit mc */
+#define EM_68HC16 69 /* Motorola MC68HC16 microcontroller */
+#define EM_68HC11 70 /* Motorola MC68HC11 microcontroller */
+#define EM_68HC08 71 /* Motorola MC68HC08 microcontroller */
+#define EM_68HC05 72 /* Motorola MC68HC05 microcontroller */
+#define EM_SVX 73 /* Silicon Graphics SVx */
+#define EM_AT19 74 /* STMicroelectronics ST19 8 bit mc */
+#define EM_VAX 75 /* Digital VAX */
+#define EM_CRIS 76 /* Axis Communications 32-bit embedded processor */
+#define EM_JAVELIN 77 /* Infineon Technologies 32-bit embedded processor */
+#define EM_FIREPATH 78 /* Element 14 64-bit DSP Processor */
+#define EM_ZSP 79 /* LSI Logic 16-bit DSP Processor */
+#define EM_MMIX 80 /* Donald Knuth's educational 64-bit processor */
+#define EM_HUANY 81 /* Harvard University machine-independent object files */
+#define EM_PRISM 82 /* SiTera Prism */
+#define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */
+#define EM_FR30 84 /* Fujitsu FR30 */
+#define EM_D10V 85 /* Mitsubishi D10V */
+#define EM_D30V 86 /* Mitsubishi D30V */
+#define EM_V850 87 /* NEC v850 */
+#define EM_M32R 88 /* Mitsubishi M32R */
+#define EM_MN10300 89 /* Matsushita MN10300 */
+#define EM_MN10200 90 /* Matsushita MN10200 */
+#define EM_PJ 91 /* picoJava */
+#define EM_OPENRISC 92 /* OpenRISC 32-bit embedded processor */
+#define EM_ARC_A5 93 /* ARC Cores Tangent-A5 */
+#define EM_XTENSA 94 /* Tensilica Xtensa Architecture */
+#define EM_NUM 95
+#define EM_AARCH64 183 /* ARM 64-bit architecture */
+#define EM_RISCV 243 /* RISC-V */
+
+/* If it is necessary to assign new unofficial EM_* values, please
+ pick large random numbers (0x8523, 0xa7f2, etc.) to minimize the
+ chances of collision with official or non-GNU unofficial values. */
+
+#define EM_ALPHA 0x9026
+
+/* Legal values for e_version (version). */
+
+#define EV_NONE 0 /* Invalid ELF version */
+#define EV_CURRENT 1 /* Current version */
+#define EV_NUM 2
+
+/* Section header. */
+
+typedef struct
+{
+ Elf32_Word sh_name; /* Section name (string tbl index) */
+ Elf32_Word sh_type; /* Section type */
+ Elf32_Word sh_flags; /* Section flags */
+ Elf32_Addr sh_addr; /* Section virtual addr at execution */
+ Elf32_Off sh_offset; /* Section file offset */
+ Elf32_Word sh_size; /* Section size in bytes */
+ Elf32_Word sh_link; /* Link to another section */
+ Elf32_Word sh_info; /* Additional section information */
+ Elf32_Word sh_addralign; /* Section alignment */
+ Elf32_Word sh_entsize; /* Entry size if section holds table */
+} Elf32_Shdr;
+
+typedef struct
+{
+ Elf64_Word sh_name; /* Section name (string tbl index) */
+ Elf64_Word sh_type; /* Section type */
+ Elf64_Xword sh_flags; /* Section flags */
+ Elf64_Addr sh_addr; /* Section virtual addr at execution */
+ Elf64_Off sh_offset; /* Section file offset */
+ Elf64_Xword sh_size; /* Section size in bytes */
+ Elf64_Word sh_link; /* Link to another section */
+ Elf64_Word sh_info; /* Additional section information */
+ Elf64_Xword sh_addralign; /* Section alignment */
+ Elf64_Xword sh_entsize; /* Entry size if section holds table */
+} Elf64_Shdr;
+
+/* Special section indices. */
+
+#define SHN_UNDEF 0 /* Undefined section */
+#define SHN_LORESERVE 0xff00 /* Start of reserved indices */
+#define SHN_LOPROC 0xff00 /* Start of processor-specific */
+#define SHN_HIPROC 0xff1f /* End of processor-specific */
+#define SHN_LOOS 0xff20 /* Start of OS-specific */
+#define SHN_HIOS 0xff3f /* End of OS-specific */
+#define SHN_ABS 0xfff1 /* Associated symbol is absolute */
+#define SHN_COMMON 0xfff2 /* Associated symbol is common */
+#define SHN_XINDEX 0xffff /* Index is in extra table. */
+#define SHN_HIRESERVE 0xffff /* End of reserved indices */
+
+/* Legal values for sh_type (section type). */
+
+#define SHT_NULL 0 /* Section header table entry unused */
+#define SHT_PROGBITS 1 /* Program data */
+#define SHT_SYMTAB 2 /* Symbol table */
+#define SHT_STRTAB 3 /* String table */
+#define SHT_RELA 4 /* Relocation entries with addends */
+#define SHT_HASH 5 /* Symbol hash table */
+#define SHT_DYNAMIC 6 /* Dynamic linking information */
+#define SHT_NOTE 7 /* Notes */
+#define SHT_NOBITS 8 /* Program space with no data (bss) */
+#define SHT_REL 9 /* Relocation entries, no addends */
+#define SHT_SHLIB 10 /* Reserved */
+#define SHT_DYNSYM 11 /* Dynamic linker symbol table */
+#define SHT_INIT_ARRAY 14 /* Array of constructors */
+#define SHT_FINI_ARRAY 15 /* Array of destructors */
+#define SHT_PREINIT_ARRAY 16 /* Array of pre-constructors */
+#define SHT_GROUP 17 /* Section group */
+#define SHT_SYMTAB_SHNDX 18 /* Extended section indices */
+#define SHT_NUM 19 /* Number of defined types. */
+#define SHT_LOOS 0x60000000 /* Start OS-specific */
+#define SHT_GNU_LIBLIST 0x6ffffff7 /* Prelink library list */
+#define SHT_CHECKSUM 0x6ffffff8 /* Checksum for DSO content. */
+#define SHT_LOSUNW 0x6ffffffa /* Sun-specific low bound. */
+#define SHT_SUNW_move 0x6ffffffa
+#define SHT_SUNW_COMDAT 0x6ffffffb
+#define SHT_SUNW_syminfo 0x6ffffffc
+#define SHT_GNU_verdef 0x6ffffffd /* Version definition section. */
+#define SHT_GNU_verneed 0x6ffffffe /* Version needs section. */
+#define SHT_GNU_versym 0x6fffffff /* Version symbol table. */
+#define SHT_HISUNW 0x6fffffff /* Sun-specific high bound. */
+#define SHT_HIOS 0x6fffffff /* End OS-specific type */
+#define SHT_LOPROC 0x70000000 /* Start of processor-specific */
+#define SHT_HIPROC 0x7fffffff /* End of processor-specific */
+#define SHT_LOUSER 0x80000000 /* Start of application-specific */
+#define SHT_HIUSER 0x8fffffff /* End of application-specific */
+
+/* Legal values for sh_flags (section flags). */
+
+#define SHF_WRITE (1 << 0) /* Writable */
+#define SHF_ALLOC (1 << 1) /* Occupies memory during execution */
+#define SHF_EXECINSTR (1 << 2) /* Executable */
+#define SHF_MERGE (1 << 4) /* Might be merged */
+#define SHF_STRINGS (1 << 5) /* Contains nul-terminated strings */
+#define SHF_INFO_LINK (1 << 6) /* `sh_info' contains SHT index */
+#define SHF_LINK_ORDER (1 << 7) /* Preserve order after combining */
+#define SHF_OS_NONCONFORMING (1 << 8) /* Non-standard OS specific handling
+ required */
+#define SHF_GROUP (1 << 9) /* Section is member of a group. */
+#define SHF_TLS (1 << 10) /* Section hold thread-local data. */
+#define SHF_MASKOS 0x0ff00000 /* OS-specific. */
+#define SHF_MASKPROC 0xf0000000 /* Processor-specific */
+
+/* Section group handling. */
+#define GRP_COMDAT 0x1 /* Mark group as COMDAT. */
+
+/* Symbol table entry. */
+
+typedef struct
+{
+ Elf32_Word st_name; /* Symbol name (string tbl index) */
+ Elf32_Addr st_value; /* Symbol value */
+ Elf32_Word st_size; /* Symbol size */
+ unsigned char st_info; /* Symbol type and binding */
+ unsigned char st_other; /* Symbol visibility */
+ Elf32_Section st_shndx; /* Section index */
+} Elf32_Sym;
+
+typedef struct
+{
+ Elf64_Word st_name; /* Symbol name (string tbl index) */
+ unsigned char st_info; /* Symbol type and binding */
+ unsigned char st_other; /* Symbol visibility */
+ Elf64_Section st_shndx; /* Section index */
+ Elf64_Addr st_value; /* Symbol value */
+ Elf64_Xword st_size; /* Symbol size */
+} Elf64_Sym;
+
+/* The syminfo section if available contains additional information about
+ every dynamic symbol. */
+
+typedef struct
+{
+ Elf32_Half si_boundto; /* Direct bindings, symbol bound to */
+ Elf32_Half si_flags; /* Per symbol flags */
+} Elf32_Syminfo;
+
+typedef struct
+{
+ Elf64_Half si_boundto; /* Direct bindings, symbol bound to */
+ Elf64_Half si_flags; /* Per symbol flags */
+} Elf64_Syminfo;
+
+/* Possible values for si_boundto. */
+#define SYMINFO_BT_SELF 0xffff /* Symbol bound to self */
+#define SYMINFO_BT_PARENT 0xfffe /* Symbol bound to parent */
+#define SYMINFO_BT_LOWRESERVE 0xff00 /* Beginning of reserved entries */
+
+/* Possible bitmasks for si_flags. */
+#define SYMINFO_FLG_DIRECT 0x0001 /* Direct bound symbol */
+#define SYMINFO_FLG_PASSTHRU 0x0002 /* Pass-thru symbol for translator */
+#define SYMINFO_FLG_COPY 0x0004 /* Symbol is a copy-reloc */
+#define SYMINFO_FLG_LAZYLOAD 0x0008 /* Symbol bound to object to be lazy
+ loaded */
+/* Syminfo version values. */
+#define SYMINFO_NONE 0
+#define SYMINFO_CURRENT 1
+#define SYMINFO_NUM 2
+
+
+/* How to extract and insert information held in the st_info field. */
+
+#define ELF32_ST_BIND(val) (((unsigned char) (val)) >> 4)
+#define ELF32_ST_TYPE(val) ((val) & 0xf)
+#define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf))
+
+/* Both Elf32_Sym and Elf64_Sym use the same one-byte st_info field. */
+#define ELF64_ST_BIND(val) ELF32_ST_BIND (val)
+#define ELF64_ST_TYPE(val) ELF32_ST_TYPE (val)
+#define ELF64_ST_INFO(bind, type) ELF32_ST_INFO ((bind), (type))
+
+/* Legal values for ST_BIND subfield of st_info (symbol binding). */
+
+#define STB_LOCAL 0 /* Local symbol */
+#define STB_GLOBAL 1 /* Global symbol */
+#define STB_WEAK 2 /* Weak symbol */
+#define STB_NUM 3 /* Number of defined types. */
+#define STB_LOOS 10 /* Start of OS-specific */
+#define STB_HIOS 12 /* End of OS-specific */
+#define STB_LOPROC 13 /* Start of processor-specific */
+#define STB_HIPROC 15 /* End of processor-specific */
+
+/* Legal values for ST_TYPE subfield of st_info (symbol type). */
+
+#define STT_NOTYPE 0 /* Symbol type is unspecified */
+#define STT_OBJECT 1 /* Symbol is a data object */
+#define STT_FUNC 2 /* Symbol is a code object */
+#define STT_SECTION 3 /* Symbol associated with a section */
+#define STT_FILE 4 /* Symbol's name is file name */
+#define STT_COMMON 5 /* Symbol is a common data object */
+#define STT_TLS 6 /* Symbol is thread-local data object*/
+#define STT_NUM 7 /* Number of defined types. */
+#define STT_LOOS 10 /* Start of OS-specific */
+#define STT_HIOS 12 /* End of OS-specific */
+#define STT_LOPROC 13 /* Start of processor-specific */
+#define STT_HIPROC 15 /* End of processor-specific */
+
+
+/* Symbol table indices are found in the hash buckets and chain table
+ of a symbol hash table section. This special index value indicates
+ the end of a chain, meaning no further symbols are found in that bucket. */
+
+#define STN_UNDEF 0 /* End of a chain. */
+#define STN_ABS 65521
+
+
+/* How to extract and insert information held in the st_other field. */
+
+#define ELF32_ST_VISIBILITY(o) ((o) & 0x03)
+
+/* For ELF64 the definitions are the same. */
+#define ELF64_ST_VISIBILITY(o) ELF32_ST_VISIBILITY (o)
+
+/* Symbol visibility specification encoded in the st_other field. */
+#define STV_DEFAULT 0 /* Default symbol visibility rules */
+#define STV_INTERNAL 1 /* Processor specific hidden class */
+#define STV_HIDDEN 2 /* Sym unavailable in other modules */
+#define STV_PROTECTED 3 /* Not preemptible, not exported */
+
+
+/* Relocation table entry without addend (in section of type SHT_REL). */
+
+typedef struct
+{
+ Elf32_Addr r_offset; /* Address */
+ Elf32_Word r_info; /* Relocation type and symbol index */
+} Elf32_Rel;
+
+/* I have seen two different definitions of the Elf64_Rel and
+ Elf64_Rela structures, so we'll leave them out until Novell (or
+ whoever) gets their act together. */
+/* The following, at least, is used on Sparc v9, MIPS, and Alpha. */
+
+typedef struct
+{
+ Elf64_Addr r_offset; /* Address */
+ Elf64_Xword r_info; /* Relocation type and symbol index */
+} Elf64_Rel;
+
+/* Relocation table entry with addend (in section of type SHT_RELA). */
+
+typedef struct
+{
+ Elf32_Addr r_offset; /* Address */
+ Elf32_Word r_info; /* Relocation type and symbol index */
+ Elf32_Sword r_addend; /* Addend */
+} Elf32_Rela;
+
+typedef struct
+{
+ Elf64_Addr r_offset; /* Address */
+ Elf64_Xword r_info; /* Relocation type and symbol index */
+ Elf64_Sxword r_addend; /* Addend */
+} Elf64_Rela;
+
+/* How to extract and insert information held in the r_info field. */
+
+#define ELF32_R_SYM(val) ((val) >> 8)
+#define ELF32_R_TYPE(val) ((val) & 0xff)
+#define ELF32_R_INFO(sym, type) (((sym) << 8) + ((type) & 0xff))
+
+#define ELF64_R_SYM(i) ((i) >> 32)
+#define ELF64_R_TYPE(i) ((i) & 0xffffffff)
+#define ELF64_R_INFO(sym,type) ((((Elf64_Xword) (sym)) << 32) + (type))
+
+/* Program segment header. */
+
+typedef struct
+{
+ Elf32_Word p_type; /* Segment type */
+ Elf32_Off p_offset; /* Segment file offset */
+ Elf32_Addr p_vaddr; /* Segment virtual address */
+ Elf32_Addr p_paddr; /* Segment physical address */
+ Elf32_Word p_filesz; /* Segment size in file */
+ Elf32_Word p_memsz; /* Segment size in memory */
+ Elf32_Word p_flags; /* Segment flags */
+ Elf32_Word p_align; /* Segment alignment */
+} Elf32_Phdr;
+
+typedef struct
+{
+ Elf64_Word p_type; /* Segment type */
+ Elf64_Word p_flags; /* Segment flags */
+ Elf64_Off p_offset; /* Segment file offset */
+ Elf64_Addr p_vaddr; /* Segment virtual address */
+ Elf64_Addr p_paddr; /* Segment physical address */
+ Elf64_Xword p_filesz; /* Segment size in file */
+ Elf64_Xword p_memsz; /* Segment size in memory */
+ Elf64_Xword p_align; /* Segment alignment */
+} Elf64_Phdr;
+
+/* Legal values for p_type (segment type). */
+
+#define PT_NULL 0 /* Program header table entry unused */
+#define PT_LOAD 1 /* Loadable program segment */
+#define PT_DYNAMIC 2 /* Dynamic linking information */
+#define PT_INTERP 3 /* Program interpreter */
+#define PT_NOTE 4 /* Auxiliary information */
+#define PT_SHLIB 5 /* Reserved */
+#define PT_PHDR 6 /* Entry for header table itself */
+#define PT_TLS 7 /* Thread-local storage segment */
+#define PT_NUM 8 /* Number of defined types */
+#define PT_LOOS 0x60000000 /* Start of OS-specific */
+#define PT_GNU_EH_FRAME 0x6474e550 /* GCC .eh_frame_hdr segment */
+#define PT_GNU_STACK 0x6474e551 /* GCC stack segment */
+#define PT_LOSUNW 0x6ffffffa
+#define PT_SUNWBSS 0x6ffffffa /* Sun Specific segment */
+#define PT_SUNWSTACK 0x6ffffffb /* Stack segment */
+#define PT_HISUNW 0x6fffffff
+#define PT_HIOS 0x6fffffff /* End of OS-specific */
+#define PT_LOPROC 0x70000000 /* Start of processor-specific */
+#define PT_HIPROC 0x7fffffff /* End of processor-specific */
+
+/* Legal values for p_flags (segment flags). */
+
+#define PF_X (1 << 0) /* Segment is executable */
+#define PF_W (1 << 1) /* Segment is writable */
+#define PF_R (1 << 2) /* Segment is readable */
+#define PF_MASKOS 0x0ff00000 /* OS-specific */
+#define PF_MASKPROC 0xf0000000 /* Processor-specific */
+
+/* Legal values for note segment descriptor types for core files. */
+
+#define NT_PRSTATUS 1 /* Contains copy of prstatus struct */
+#define NT_FPREGSET 2 /* Contains copy of fpregset struct */
+#define NT_PRPSINFO 3 /* Contains copy of prpsinfo struct */
+#define NT_PRXREG 4 /* Contains copy of prxregset struct */
+#define NT_PLATFORM 5 /* String from sysinfo(SI_PLATFORM) */
+#define NT_AUXV 6 /* Contains copy of auxv array */
+#define NT_GWINDOWS 7 /* Contains copy of gwindows struct */
+#define NT_ASRS 8 /* Contains copy of asrset struct */
+#define NT_PSTATUS 10 /* Contains copy of pstatus struct */
+#define NT_PSINFO 13 /* Contains copy of psinfo struct */
+#define NT_PRCRED 14 /* Contains copy of prcred struct */
+#define NT_UTSNAME 15 /* Contains copy of utsname struct */
+#define NT_LWPSTATUS 16 /* Contains copy of lwpstatus struct */
+#define NT_LWPSINFO 17 /* Contains copy of lwpinfo struct */
+#define NT_PRFPXREG 20 /* Contains copy of fprxregset struct*/
+
+/* Legal values for the note segment descriptor types for object files. */
+
+#define NT_VERSION 1 /* Contains a version string. */
+
+
+/* Dynamic section entry. */
+
+typedef struct
+{
+ Elf32_Sword d_tag; /* Dynamic entry type */
+ union
+ {
+ Elf32_Word d_val; /* Integer value */
+ Elf32_Addr d_ptr; /* Address value */
+ } d_un;
+} Elf32_Dyn;
+
+typedef struct
+{
+ Elf64_Sxword d_tag; /* Dynamic entry type */
+ union
+ {
+ Elf64_Xword d_val; /* Integer value */
+ Elf64_Addr d_ptr; /* Address value */
+ } d_un;
+} Elf64_Dyn;
+
+/* Legal values for d_tag (dynamic entry type). */
+
+#define DT_NULL 0 /* Marks end of dynamic section */
+#define DT_NEEDED 1 /* Name of needed library */
+#define DT_PLTRELSZ 2 /* Size in bytes of PLT relocs */
+#define DT_PLTGOT 3 /* Processor defined value */
+#define DT_HASH 4 /* Address of symbol hash table */
+#define DT_STRTAB 5 /* Address of string table */
+#define DT_SYMTAB 6 /* Address of symbol table */
+#define DT_RELA 7 /* Address of Rela relocs */
+#define DT_RELASZ 8 /* Total size of Rela relocs */
+#define DT_RELAENT 9 /* Size of one Rela reloc */
+#define DT_STRSZ 10 /* Size of string table */
+#define DT_SYMENT 11 /* Size of one symbol table entry */
+#define DT_INIT 12 /* Address of init function */
+#define DT_FINI 13 /* Address of termination function */
+#define DT_SONAME 14 /* Name of shared object */
+#define DT_RPATH 15 /* Library search path (deprecated) */
+#define DT_SYMBOLIC 16 /* Start symbol search here */
+#define DT_REL 17 /* Address of Rel relocs */
+#define DT_RELSZ 18 /* Total size of Rel relocs */
+#define DT_RELENT 19 /* Size of one Rel reloc */
+#define DT_PLTREL 20 /* Type of reloc in PLT */
+#define DT_DEBUG 21 /* For debugging; unspecified */
+#define DT_TEXTREL 22 /* Reloc might modify .text */
+#define DT_JMPREL 23 /* Address of PLT relocs */
+#define DT_BIND_NOW 24 /* Process relocations of object */
+#define DT_INIT_ARRAY 25 /* Array with addresses of init fct */
+#define DT_FINI_ARRAY 26 /* Array with addresses of fini fct */
+#define DT_INIT_ARRAYSZ 27 /* Size in bytes of DT_INIT_ARRAY */
+#define DT_FINI_ARRAYSZ 28 /* Size in bytes of DT_FINI_ARRAY */
+#define DT_RUNPATH 29 /* Library search path */
+#define DT_FLAGS 30 /* Flags for the object being loaded */
+#define DT_ENCODING 32 /* Start of encoded range */
+#define DT_PREINIT_ARRAY 32 /* Array with addresses of preinit fct*/
+#define DT_PREINIT_ARRAYSZ 33 /* size in bytes of DT_PREINIT_ARRAY */
+#define DT_NUM 34 /* Number used */
+#define DT_LOOS 0x6000000d /* Start of OS-specific */
+#define DT_HIOS 0x6ffff000 /* End of OS-specific */
+#define DT_LOPROC 0x70000000 /* Start of processor-specific */
+#define DT_HIPROC 0x7fffffff /* End of processor-specific */
+#define DT_PROCNUM DT_MIPS_NUM /* Most used by any processor */
+
+/* DT_* entries which fall between DT_VALRNGHI & DT_VALRNGLO use the
+ Dyn.d_un.d_val field of the Elf*_Dyn structure. This follows Sun's
+ approach. */
+#define DT_VALRNGLO 0x6ffffd00
+#define DT_GNU_PRELINKED 0x6ffffdf5 /* Prelinking timestamp */
+#define DT_GNU_CONFLICTSZ 0x6ffffdf6 /* Size of conflict section */
+#define DT_GNU_LIBLISTSZ 0x6ffffdf7 /* Size of library list */
+#define DT_CHECKSUM 0x6ffffdf8
+#define DT_PLTPADSZ 0x6ffffdf9
+#define DT_MOVEENT 0x6ffffdfa
+#define DT_MOVESZ 0x6ffffdfb
+#define DT_FEATURE_1 0x6ffffdfc /* Feature selection (DTF_*). */
+#define DT_POSFLAG_1 0x6ffffdfd /* Flags for DT_* entries, effecting
+ the following DT_* entry. */
+#define DT_SYMINSZ 0x6ffffdfe /* Size of syminfo table (in bytes) */
+#define DT_SYMINENT 0x6ffffdff /* Entry size of syminfo */
+#define DT_VALRNGHI 0x6ffffdff
+#define DT_VALTAGIDX(tag) (DT_VALRNGHI - (tag)) /* Reverse order! */
+#define DT_VALNUM 12
+
+/* DT_* entries which fall between DT_ADDRRNGHI & DT_ADDRRNGLO use the
+ Dyn.d_un.d_ptr field of the Elf*_Dyn structure.
+
+ If any adjustment is made to the ELF object after it has been
+ built these entries will need to be adjusted. */
+#define DT_ADDRRNGLO 0x6ffffe00
+#define DT_GNU_CONFLICT 0x6ffffef8 /* Start of conflict section */
+#define DT_GNU_LIBLIST 0x6ffffef9 /* Library list */
+#define DT_CONFIG 0x6ffffefa /* Configuration information. */
+#define DT_DEPAUDIT 0x6ffffefb /* Dependency auditing. */
+#define DT_AUDIT 0x6ffffefc /* Object auditing. */
+#define DT_PLTPAD 0x6ffffefd /* PLT padding. */
+#define DT_MOVETAB 0x6ffffefe /* Move table. */
+#define DT_SYMINFO 0x6ffffeff /* Syminfo table. */
+#define DT_ADDRRNGHI 0x6ffffeff
+#define DT_ADDRTAGIDX(tag) (DT_ADDRRNGHI - (tag)) /* Reverse order! */
+#define DT_ADDRNUM 10
+
+/* The versioning entry types. The next are defined as part of the
+ GNU extension. */
+#define DT_VERSYM 0x6ffffff0
+
+#define DT_RELACOUNT 0x6ffffff9
+#define DT_RELCOUNT 0x6ffffffa
+
+/* These were chosen by Sun. */
+#define DT_FLAGS_1 0x6ffffffb /* State flags, see DF_1_* below. */
+#define DT_VERDEF 0x6ffffffc /* Address of version definition
+ table */
+#define DT_VERDEFNUM 0x6ffffffd /* Number of version definitions */
+#define DT_VERNEED 0x6ffffffe /* Address of table with needed
+ versions */
+#define DT_VERNEEDNUM 0x6fffffff /* Number of needed versions */
+#define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
+#define DT_VERSIONTAGNUM 16
+
+/* Sun added these machine-independent extensions in the "processor-specific"
+ range. Be compatible. */
+#define DT_AUXILIARY 0x7ffffffd /* Shared object to load before self */
+#define DT_FILTER 0x7fffffff /* Shared object to get values from */
+#define DT_EXTRATAGIDX(tag) ((Elf32_Word)-((Elf32_Sword) (tag) <<1>>1)-1)
+#define DT_EXTRANUM 3
+
+/* Values of `d_un.d_val' in the DT_FLAGS entry. */
+#define DF_ORIGIN 0x00000001 /* Object may use DF_ORIGIN */
+#define DF_SYMBOLIC 0x00000002 /* Symbol resolutions starts here */
+#define DF_TEXTREL 0x00000004 /* Object contains text relocations */
+#define DF_BIND_NOW 0x00000008 /* No lazy binding for this object */
+#define DF_STATIC_TLS 0x00000010 /* Module uses the static TLS model */
+
+/* State flags selectable in the `d_un.d_val' element of the DT_FLAGS_1
+ entry in the dynamic section. */
+#define DF_1_NOW 0x00000001 /* Set RTLD_NOW for this object. */
+#define DF_1_GLOBAL 0x00000002 /* Set RTLD_GLOBAL for this object. */
+#define DF_1_GROUP 0x00000004 /* Set RTLD_GROUP for this object. */
+#define DF_1_NODELETE 0x00000008 /* Set RTLD_NODELETE for this object.*/
+#define DF_1_LOADFLTR 0x00000010 /* Trigger filtee loading at runtime.*/
+#define DF_1_INITFIRST 0x00000020 /* Set RTLD_INITFIRST for this object*/
+#define DF_1_NOOPEN 0x00000040 /* Set RTLD_NOOPEN for this object. */
+#define DF_1_ORIGIN 0x00000080 /* $ORIGIN must be handled. */
+#define DF_1_DIRECT 0x00000100 /* Direct binding enabled. */
+#define DF_1_TRANS 0x00000200
+#define DF_1_INTERPOSE 0x00000400 /* Object is used to interpose. */
+#define DF_1_NODEFLIB 0x00000800 /* Ignore default lib search path. */
+#define DF_1_NODUMP 0x00001000 /* Object can't be dldump'ed. */
+#define DF_1_CONFALT 0x00002000 /* Configuration alternative created.*/
+#define DF_1_ENDFILTEE 0x00004000 /* Filtee terminates filters search. */
+#define DF_1_DISPRELDNE 0x00008000 /* Disp reloc applied at build time. */
+#define DF_1_DISPRELPND 0x00010000 /* Disp reloc applied at run-time. */
+
+/* Flags for the feature selection in DT_FEATURE_1. */
+#define DTF_1_PARINIT 0x00000001
+#define DTF_1_CONFEXP 0x00000002
+
+/* Flags in the DT_POSFLAG_1 entry effecting only the next DT_* entry. */
+#define DF_P1_LAZYLOAD 0x00000001 /* Lazyload following object. */
+#define DF_P1_GROUPPERM 0x00000002 /* Symbols from next object are not
+ generally available. */
+
+/* Version definition sections. */
+
+typedef struct
+{
+ Elf32_Half vd_version; /* Version revision */
+ Elf32_Half vd_flags; /* Version information */
+ Elf32_Half vd_ndx; /* Version Index */
+ Elf32_Half vd_cnt; /* Number of associated aux entries */
+ Elf32_Word vd_hash; /* Version name hash value */
+ Elf32_Word vd_aux; /* Offset in bytes to verdaux array */
+ Elf32_Word vd_next; /* Offset in bytes to next verdef
+ entry */
+} Elf32_Verdef;
+
+typedef struct
+{
+ Elf64_Half vd_version; /* Version revision */
+ Elf64_Half vd_flags; /* Version information */
+ Elf64_Half vd_ndx; /* Version Index */
+ Elf64_Half vd_cnt; /* Number of associated aux entries */
+ Elf64_Word vd_hash; /* Version name hash value */
+ Elf64_Word vd_aux; /* Offset in bytes to verdaux array */
+ Elf64_Word vd_next; /* Offset in bytes to next verdef
+ entry */
+} Elf64_Verdef;
+
+
+/* Legal values for vd_version (version revision). */
+#define VER_DEF_NONE 0 /* No version */
+#define VER_DEF_CURRENT 1 /* Current version */
+#define VER_DEF_NUM 2 /* Given version number */
+
+/* Legal values for vd_flags (version information flags). */
+#define VER_FLG_BASE 0x1 /* Version definition of file itself */
+#define VER_FLG_WEAK 0x2 /* Weak version identifier */
+
+/* Versym symbol index values. */
+#define VER_NDX_LOCAL 0 /* Symbol is local. */
+#define VER_NDX_GLOBAL 1 /* Symbol is global. */
+#define VER_NDX_LORESERVE 0xff00 /* Beginning of reserved entries. */
+#define VER_NDX_ELIMINATE 0xff01 /* Symbol is to be eliminated. */
+
+/* Auxiliary version information. */
+
+typedef struct
+{
+ Elf32_Word vda_name; /* Version or dependency names */
+ Elf32_Word vda_next; /* Offset in bytes to next verdaux
+ entry */
+} Elf32_Verdaux;
+
+typedef struct
+{
+ Elf64_Word vda_name; /* Version or dependency names */
+ Elf64_Word vda_next; /* Offset in bytes to next verdaux
+ entry */
+} Elf64_Verdaux;
+
+
+/* Version dependency section. */
+
+typedef struct
+{
+ Elf32_Half vn_version; /* Version of structure */
+ Elf32_Half vn_cnt; /* Number of associated aux entries */
+ Elf32_Word vn_file; /* Offset of filename for this
+ dependency */
+ Elf32_Word vn_aux; /* Offset in bytes to vernaux array */
+ Elf32_Word vn_next; /* Offset in bytes to next verneed
+ entry */
+} Elf32_Verneed;
+
+typedef struct
+{
+ Elf64_Half vn_version; /* Version of structure */
+ Elf64_Half vn_cnt; /* Number of associated aux entries */
+ Elf64_Word vn_file; /* Offset of filename for this
+ dependency */
+ Elf64_Word vn_aux; /* Offset in bytes to vernaux array */
+ Elf64_Word vn_next; /* Offset in bytes to next verneed
+ entry */
+} Elf64_Verneed;
+
+
+/* Legal values for vn_version (version revision). */
+#define VER_NEED_NONE 0 /* No version */
+#define VER_NEED_CURRENT 1 /* Current version */
+#define VER_NEED_NUM 2 /* Given version number */
+
+/* Auxiliary needed version information. */
+
+typedef struct
+{
+ Elf32_Word vna_hash; /* Hash value of dependency name */
+ Elf32_Half vna_flags; /* Dependency specific information */
+ Elf32_Half vna_other; /* Unused */
+ Elf32_Word vna_name; /* Dependency name string offset */
+ Elf32_Word vna_next; /* Offset in bytes to next vernaux
+ entry */
+} Elf32_Vernaux;
+
+typedef struct
+{
+ Elf64_Word vna_hash; /* Hash value of dependency name */
+ Elf64_Half vna_flags; /* Dependency specific information */
+ Elf64_Half vna_other; /* Unused */
+ Elf64_Word vna_name; /* Dependency name string offset */
+ Elf64_Word vna_next; /* Offset in bytes to next vernaux
+ entry */
+} Elf64_Vernaux;
+
+
+/* Legal values for vna_flags. */
+#define VER_FLG_WEAK 0x2 /* Weak version identifier */
+
+
+/* Auxiliary vector. */
+
+/* This vector is normally only used by the program interpreter. The
+ usual definition in an ABI supplement uses the name auxv_t. The
+ vector is not usually defined in a standard <elf.h> file, but it
+ can't hurt. We rename it to avoid conflicts. The sizes of these
+ types are an arrangement between the exec server and the program
+ interpreter, so we don't fully specify them here. */
+
+typedef struct
+{
+ int a_type; /* Entry type */
+ union
+ {
+ long int a_val; /* Integer value */
+ void *a_ptr; /* Pointer value */
+ void (*a_fcn) (void); /* Function pointer value */
+ } a_un;
+} Elf32_auxv_t;
+
+typedef struct
+{
+ long int a_type; /* Entry type */
+ union
+ {
+ long int a_val; /* Integer value */
+ void *a_ptr; /* Pointer value */
+ void (*a_fcn) (void); /* Function pointer value */
+ } a_un;
+} Elf64_auxv_t;
+
+/* Legal values for a_type (entry type). */
+
+#define AT_NULL 0 /* End of vector */
+#define AT_IGNORE 1 /* Entry should be ignored */
+#define AT_EXECFD 2 /* File descriptor of program */
+#define AT_PHDR 3 /* Program headers for program */
+#define AT_PHENT 4 /* Size of program header entry */
+#define AT_PHNUM 5 /* Number of program headers */
+#define AT_PAGESZ 6 /* System page size */
+#define AT_BASE 7 /* Base address of interpreter */
+#define AT_FLAGS 8 /* Flags */
+#define AT_ENTRY 9 /* Entry point of program */
+#define AT_NOTELF 10 /* Program is not ELF */
+#define AT_UID 11 /* Real uid */
+#define AT_EUID 12 /* Effective uid */
+#define AT_GID 13 /* Real gid */
+#define AT_EGID 14 /* Effective gid */
+#define AT_CLKTCK 17 /* Frequency of times() */
+
+/* Some more special a_type values describing the hardware. */
+#define AT_PLATFORM 15 /* String identifying platform. */
+#define AT_HWCAP 16 /* Machine dependent hints about
+ processor capabilities. */
+
+/* This entry gives some information about the FPU initialization
+ performed by the kernel. */
+#define AT_FPUCW 18 /* Used FPU control word. */
+
+/* Cache block sizes. */
+#define AT_DCACHEBSIZE 19 /* Data cache block size. */
+#define AT_ICACHEBSIZE 20 /* Instruction cache block size. */
+#define AT_UCACHEBSIZE 21 /* Unified cache block size. */
+
+/* A special ignored value for PPC, used by the kernel to control the
+ interpretation of the AUXV. Must be > 16. */
+#define AT_IGNOREPPC 22 /* Entry should be ignored */
+
+
+/* Note section contents. Each entry in the note section begins with
+ a header of a fixed form. */
+
+typedef struct
+{
+ Elf32_Word n_namesz; /* Length of the note's name. */
+ Elf32_Word n_descsz; /* Length of the note's descriptor. */
+ Elf32_Word n_type; /* Type of the note. */
+} Elf32_Nhdr;
+
+typedef struct
+{
+ Elf64_Word n_namesz; /* Length of the note's name. */
+ Elf64_Word n_descsz; /* Length of the note's descriptor. */
+ Elf64_Word n_type; /* Type of the note. */
+} Elf64_Nhdr;
+
+/* Known names of notes. */
+
+/* Solaris entries in the note section have this name. */
+#define ELF_NOTE_SOLARIS "SUNW Solaris"
+
+/* Note entries for GNU systems have this name. */
+#define ELF_NOTE_GNU "GNU"
+
+
+/* Defined types of notes for Solaris. */
+
+/* Value of descriptor (one word) is desired pagesize for the binary. */
+#define ELF_NOTE_PAGESIZE_HINT 1
+
+
+/* Defined note types for GNU systems. */
+
+/* ABI information. The descriptor consists of words:
+ word 0: OS descriptor
+ word 1: major version of the ABI
+ word 2: minor version of the ABI
+ word 3: subminor version of the ABI
+*/
+#define ELF_NOTE_ABI 1
+
+/* Known OSes. These value can appear in word 0 of an ELF_NOTE_ABI
+ note section entry. */
+#define ELF_NOTE_OS_LINUX 0
+#define ELF_NOTE_OS_GNU 1
+#define ELF_NOTE_OS_SOLARIS2 2
+
+
+/* Move records. */
+typedef struct
+{
+ Elf32_Xword m_value; /* Symbol value. */
+ Elf32_Word m_info; /* Size and index. */
+ Elf32_Word m_poffset; /* Symbol offset. */
+ Elf32_Half m_repeat; /* Repeat count. */
+ Elf32_Half m_stride; /* Stride info. */
+} Elf32_Move;
+
+typedef struct
+{
+ Elf64_Xword m_value; /* Symbol value. */
+ Elf64_Xword m_info; /* Size and index. */
+ Elf64_Xword m_poffset; /* Symbol offset. */
+ Elf64_Half m_repeat; /* Repeat count. */
+ Elf64_Half m_stride; /* Stride info. */
+} Elf64_Move;
+
+/* Macro to construct move records. */
+#define ELF32_M_SYM(info) ((info) >> 8)
+#define ELF32_M_SIZE(info) ((unsigned char) (info))
+#define ELF32_M_INFO(sym, size) (((sym) << 8) + (unsigned char) (size))
+
+#define ELF64_M_SYM(info) ELF32_M_SYM (info)
+#define ELF64_M_SIZE(info) ELF32_M_SIZE (info)
+#define ELF64_M_INFO(sym, size) ELF32_M_INFO (sym, size)
+
+
+/* Motorola 68k specific definitions. */
+
+/* Values for Elf32_Ehdr.e_flags. */
+#define EF_CPU32 0x00810000
+
+/* m68k relocs. */
+
+#define R_68K_NONE 0 /* No reloc */
+#define R_68K_32 1 /* Direct 32 bit */
+#define R_68K_16 2 /* Direct 16 bit */
+#define R_68K_8 3 /* Direct 8 bit */
+#define R_68K_PC32 4 /* PC relative 32 bit */
+#define R_68K_PC16 5 /* PC relative 16 bit */
+#define R_68K_PC8 6 /* PC relative 8 bit */
+#define R_68K_GOT32 7 /* 32 bit PC relative GOT entry */
+#define R_68K_GOT16 8 /* 16 bit PC relative GOT entry */
+#define R_68K_GOT8 9 /* 8 bit PC relative GOT entry */
+#define R_68K_GOT32O 10 /* 32 bit GOT offset */
+#define R_68K_GOT16O 11 /* 16 bit GOT offset */
+#define R_68K_GOT8O 12 /* 8 bit GOT offset */
+#define R_68K_PLT32 13 /* 32 bit PC relative PLT address */
+#define R_68K_PLT16 14 /* 16 bit PC relative PLT address */
+#define R_68K_PLT8 15 /* 8 bit PC relative PLT address */
+#define R_68K_PLT32O 16 /* 32 bit PLT offset */
+#define R_68K_PLT16O 17 /* 16 bit PLT offset */
+#define R_68K_PLT8O 18 /* 8 bit PLT offset */
+#define R_68K_COPY 19 /* Copy symbol at runtime */
+#define R_68K_GLOB_DAT 20 /* Create GOT entry */
+#define R_68K_JMP_SLOT 21 /* Create PLT entry */
+#define R_68K_RELATIVE 22 /* Adjust by program base */
+/* Keep this the last entry. */
+#define R_68K_NUM 23
+
+/* Intel 80386 specific definitions. */
+
+/* i386 relocs. */
+
+#define R_386_NONE 0 /* No reloc */
+#define R_386_32 1 /* Direct 32 bit */
+#define R_386_PC32 2 /* PC relative 32 bit */
+#define R_386_GOT32 3 /* 32 bit GOT entry */
+#define R_386_PLT32 4 /* 32 bit PLT address */
+#define R_386_COPY 5 /* Copy symbol at runtime */
+#define R_386_GLOB_DAT 6 /* Create GOT entry */
+#define R_386_JMP_SLOT 7 /* Create PLT entry */
+#define R_386_RELATIVE 8 /* Adjust by program base */
+#define R_386_GOTOFF 9 /* 32 bit offset to GOT */
+#define R_386_GOTPC 10 /* 32 bit PC relative offset to GOT */
+#define R_386_32PLT 11
+#define R_386_TLS_TPOFF 14 /* Offset in static TLS block */
+#define R_386_TLS_IE 15 /* Address of GOT entry for static TLS
+ block offset */
+#define R_386_TLS_GOTIE 16 /* GOT entry for static TLS block
+ offset */
+#define R_386_TLS_LE 17 /* Offset relative to static TLS
+ block */
+#define R_386_TLS_GD 18 /* Direct 32 bit for GNU version of
+ general dynamic thread local data */
+#define R_386_TLS_LDM 19 /* Direct 32 bit for GNU version of
+ local dynamic thread local data
+ in LE code */
+#define R_386_16 20
+#define R_386_PC16 21
+#define R_386_8 22
+#define R_386_PC8 23
+#define R_386_TLS_GD_32 24 /* Direct 32 bit for general dynamic
+ thread local data */
+#define R_386_TLS_GD_PUSH 25 /* Tag for pushl in GD TLS code */
+#define R_386_TLS_GD_CALL 26 /* Relocation for call to
+ __tls_get_addr() */
+#define R_386_TLS_GD_POP 27 /* Tag for popl in GD TLS code */
+#define R_386_TLS_LDM_32 28 /* Direct 32 bit for local dynamic
+ thread local data in LE code */
+#define R_386_TLS_LDM_PUSH 29 /* Tag for pushl in LDM TLS code */
+#define R_386_TLS_LDM_CALL 30 /* Relocation for call to
+ __tls_get_addr() in LDM code */
+#define R_386_TLS_LDM_POP 31 /* Tag for popl in LDM TLS code */
+#define R_386_TLS_LDO_32 32 /* Offset relative to TLS block */
+#define R_386_TLS_IE_32 33 /* GOT entry for negated static TLS
+ block offset */
+#define R_386_TLS_LE_32 34 /* Negated offset relative to static
+ TLS block */
+#define R_386_TLS_DTPMOD32 35 /* ID of module containing symbol */
+#define R_386_TLS_DTPOFF32 36 /* Offset in TLS block */
+#define R_386_TLS_TPOFF32 37 /* Negated offset in static TLS block */
+/* Keep this the last entry. */
+#define R_386_NUM 38
+
+
+/* SUN SPARC specific definitions. */
+
+/* x86_64 specific definitions. */
+#define R_X86_64_NONE 0
+#define R_X86_64_64 1
+#define R_X86_64_PC32 2
+#define R_X86_64_GOT32 3
+#define R_X86_64_PLT32 4
+#define R_X86_64_COPY 5
+#define R_X86_64_GLOB_DAT 6
+#define R_X86_64_JUMP_SLOT 7
+#define R_X86_64_RELATIVE 8
+#define R_X86_64_GOTPCREL 9
+#define R_X86_64_32 10
+#define R_X86_64_32S 11
+#define R_X86_64_16 12
+#define R_X86_64_PC16 13
+#define R_X86_64_8 14
+#define R_X86_64_PC8 15
+#define R_X86_64_PC64 24
+
+/* Legal values for ST_TYPE subfield of st_info (symbol type). */
+
+#define STT_REGISTER 13 /* Global register reserved to app. */
+
+/* Values for Elf64_Ehdr.e_flags. */
+
+#define EF_SPARCV9_MM 3
+#define EF_SPARCV9_TSO 0
+#define EF_SPARCV9_PSO 1
+#define EF_SPARCV9_RMO 2
+#define EF_SPARC_LEDATA 0x800000 /* little endian data */
+#define EF_SPARC_EXT_MASK 0xFFFF00
+#define EF_SPARC_32PLUS 0x000100 /* generic V8+ features */
+#define EF_SPARC_SUN_US1 0x000200 /* Sun UltraSPARC1 extensions */
+#define EF_SPARC_HAL_R1 0x000400 /* HAL R1 extensions */
+#define EF_SPARC_SUN_US3 0x000800 /* Sun UltraSPARCIII extensions */
+
+/* SPARC relocs. */
+
+#define R_SPARC_NONE 0 /* No reloc */
+#define R_SPARC_8 1 /* Direct 8 bit */
+#define R_SPARC_16 2 /* Direct 16 bit */
+#define R_SPARC_32 3 /* Direct 32 bit */
+#define R_SPARC_DISP8 4 /* PC relative 8 bit */
+#define R_SPARC_DISP16 5 /* PC relative 16 bit */
+#define R_SPARC_DISP32 6 /* PC relative 32 bit */
+#define R_SPARC_WDISP30 7 /* PC relative 30 bit shifted */
+#define R_SPARC_WDISP22 8 /* PC relative 22 bit shifted */
+#define R_SPARC_HI22 9 /* High 22 bit */
+#define R_SPARC_22 10 /* Direct 22 bit */
+#define R_SPARC_13 11 /* Direct 13 bit */
+#define R_SPARC_LO10 12 /* Truncated 10 bit */
+#define R_SPARC_GOT10 13 /* Truncated 10 bit GOT entry */
+#define R_SPARC_GOT13 14 /* 13 bit GOT entry */
+#define R_SPARC_GOT22 15 /* 22 bit GOT entry shifted */
+#define R_SPARC_PC10 16 /* PC relative 10 bit truncated */
+#define R_SPARC_PC22 17 /* PC relative 22 bit shifted */
+#define R_SPARC_WPLT30 18 /* 30 bit PC relative PLT address */
+#define R_SPARC_COPY 19 /* Copy symbol at runtime */
+#define R_SPARC_GLOB_DAT 20 /* Create GOT entry */
+#define R_SPARC_JMP_SLOT 21 /* Create PLT entry */
+#define R_SPARC_RELATIVE 22 /* Adjust by program base */
+#define R_SPARC_UA32 23 /* Direct 32 bit unaligned */
+
+/* Additional Sparc64 relocs. */
+
+#define R_SPARC_PLT32 24 /* Direct 32 bit ref to PLT entry */
+#define R_SPARC_HIPLT22 25 /* High 22 bit PLT entry */
+#define R_SPARC_LOPLT10 26 /* Truncated 10 bit PLT entry */
+#define R_SPARC_PCPLT32 27 /* PC rel 32 bit ref to PLT entry */
+#define R_SPARC_PCPLT22 28 /* PC rel high 22 bit PLT entry */
+#define R_SPARC_PCPLT10 29 /* PC rel trunc 10 bit PLT entry */
+#define R_SPARC_10 30 /* Direct 10 bit */
+#define R_SPARC_11 31 /* Direct 11 bit */
+#define R_SPARC_64 32 /* Direct 64 bit */
+#define R_SPARC_OLO10 33 /* 10bit with secondary 13bit addend */
+#define R_SPARC_HH22 34 /* Top 22 bits of direct 64 bit */
+#define R_SPARC_HM10 35 /* High middle 10 bits of ... */
+#define R_SPARC_LM22 36 /* Low middle 22 bits of ... */
+#define R_SPARC_PC_HH22 37 /* Top 22 bits of pc rel 64 bit */
+#define R_SPARC_PC_HM10 38 /* High middle 10 bit of ... */
+#define R_SPARC_PC_LM22 39 /* Low middle 22 bits of ... */
+#define R_SPARC_WDISP16 40 /* PC relative 16 bit shifted */
+#define R_SPARC_WDISP19 41 /* PC relative 19 bit shifted */
+#define R_SPARC_7 43 /* Direct 7 bit */
+#define R_SPARC_5 44 /* Direct 5 bit */
+#define R_SPARC_6 45 /* Direct 6 bit */
+#define R_SPARC_DISP64 46 /* PC relative 64 bit */
+#define R_SPARC_PLT64 47 /* Direct 64 bit ref to PLT entry */
+#define R_SPARC_HIX22 48 /* High 22 bit complemented */
+#define R_SPARC_LOX10 49 /* Truncated 11 bit complemented */
+#define R_SPARC_H44 50 /* Direct high 12 of 44 bit */
+#define R_SPARC_M44 51 /* Direct mid 22 of 44 bit */
+#define R_SPARC_L44 52 /* Direct low 10 of 44 bit */
+#define R_SPARC_REGISTER 53 /* Global register usage */
+#define R_SPARC_UA64 54 /* Direct 64 bit unaligned */
+#define R_SPARC_UA16 55 /* Direct 16 bit unaligned */
+#define R_SPARC_TLS_GD_HI22 56
+#define R_SPARC_TLS_GD_LO10 57
+#define R_SPARC_TLS_GD_ADD 58
+#define R_SPARC_TLS_GD_CALL 59
+#define R_SPARC_TLS_LDM_HI22 60
+#define R_SPARC_TLS_LDM_LO10 61
+#define R_SPARC_TLS_LDM_ADD 62
+#define R_SPARC_TLS_LDM_CALL 63
+#define R_SPARC_TLS_LDO_HIX22 64
+#define R_SPARC_TLS_LDO_LOX10 65
+#define R_SPARC_TLS_LDO_ADD 66
+#define R_SPARC_TLS_IE_HI22 67
+#define R_SPARC_TLS_IE_LO10 68
+#define R_SPARC_TLS_IE_LD 69
+#define R_SPARC_TLS_IE_LDX 70
+#define R_SPARC_TLS_IE_ADD 71
+#define R_SPARC_TLS_LE_HIX22 72
+#define R_SPARC_TLS_LE_LOX10 73
+#define R_SPARC_TLS_DTPMOD32 74
+#define R_SPARC_TLS_DTPMOD64 75
+#define R_SPARC_TLS_DTPOFF32 76
+#define R_SPARC_TLS_DTPOFF64 77
+#define R_SPARC_TLS_TPOFF32 78
+#define R_SPARC_TLS_TPOFF64 79
+/* Keep this the last entry. */
+#define R_SPARC_NUM 80
+
+/* For Sparc64, legal values for d_tag of Elf64_Dyn. */
+
+#define DT_SPARC_REGISTER 0x70000001
+#define DT_SPARC_NUM 2
+
+/* Bits present in AT_HWCAP, primarily for Sparc32. */
+
+#define HWCAP_SPARC_FLUSH 1 /* The cpu supports flush insn. */
+#define HWCAP_SPARC_STBAR 2
+#define HWCAP_SPARC_SWAP 4
+#define HWCAP_SPARC_MULDIV 8
+#define HWCAP_SPARC_V9 16 /* The cpu is v9, so v8plus is ok. */
+#define HWCAP_SPARC_ULTRA3 32
+
+/* MIPS R3000 specific definitions. */
+
+/* Legal values for e_flags field of Elf32_Ehdr. */
+
+#define EF_MIPS_NOREORDER 1 /* A .noreorder directive was used */
+#define EF_MIPS_PIC 2 /* Contains PIC code */
+#define EF_MIPS_CPIC 4 /* Uses PIC calling sequence */
+#define EF_MIPS_XGOT 8
+#define EF_MIPS_64BIT_WHIRL 16
+#define EF_MIPS_ABI2 32
+#define EF_MIPS_ABI_ON32 64
+#define EF_MIPS_ARCH 0xf0000000 /* MIPS architecture level */
+
+/* Legal values for MIPS architecture level. */
+
+#define EF_MIPS_ARCH_1 0x00000000 /* -mips1 code. */
+#define EF_MIPS_ARCH_2 0x10000000 /* -mips2 code. */
+#define EF_MIPS_ARCH_3 0x20000000 /* -mips3 code. */
+#define EF_MIPS_ARCH_4 0x30000000 /* -mips4 code. */
+#define EF_MIPS_ARCH_5 0x40000000 /* -mips5 code. */
+#define EF_MIPS_ARCH_32 0x60000000 /* MIPS32 code. */
+#define EF_MIPS_ARCH_64 0x70000000 /* MIPS64 code. */
+
+/* The following are non-official names and should not be used. */
+
+#define E_MIPS_ARCH_1 0x00000000 /* -mips1 code. */
+#define E_MIPS_ARCH_2 0x10000000 /* -mips2 code. */
+#define E_MIPS_ARCH_3 0x20000000 /* -mips3 code. */
+#define E_MIPS_ARCH_4 0x30000000 /* -mips4 code. */
+#define E_MIPS_ARCH_5 0x40000000 /* -mips5 code. */
+#define E_MIPS_ARCH_32 0x60000000 /* MIPS32 code. */
+#define E_MIPS_ARCH_64 0x70000000 /* MIPS64 code. */
+
+/* Special section indices. */
+
+#define SHN_MIPS_ACOMMON 0xff00 /* Allocated common symbols */
+#define SHN_MIPS_TEXT 0xff01 /* Allocated test symbols. */
+#define SHN_MIPS_DATA 0xff02 /* Allocated data symbols. */
+#define SHN_MIPS_SCOMMON 0xff03 /* Small common symbols */
+#define SHN_MIPS_SUNDEFINED 0xff04 /* Small undefined symbols */
+
+/* Legal values for sh_type field of Elf32_Shdr. */
+
+#define SHT_MIPS_LIBLIST 0x70000000 /* Shared objects used in link */
+#define SHT_MIPS_MSYM 0x70000001
+#define SHT_MIPS_CONFLICT 0x70000002 /* Conflicting symbols */
+#define SHT_MIPS_GPTAB 0x70000003 /* Global data area sizes */
+#define SHT_MIPS_UCODE 0x70000004 /* Reserved for SGI/MIPS compilers */
+#define SHT_MIPS_DEBUG 0x70000005 /* MIPS ECOFF debugging information*/
+#define SHT_MIPS_REGINFO 0x70000006 /* Register usage information */
+#define SHT_MIPS_PACKAGE 0x70000007
+#define SHT_MIPS_PACKSYM 0x70000008
+#define SHT_MIPS_RELD 0x70000009
+#define SHT_MIPS_IFACE 0x7000000b
+#define SHT_MIPS_CONTENT 0x7000000c
+#define SHT_MIPS_OPTIONS 0x7000000d /* Miscellaneous options. */
+#define SHT_MIPS_SHDR 0x70000010
+#define SHT_MIPS_FDESC 0x70000011
+#define SHT_MIPS_EXTSYM 0x70000012
+#define SHT_MIPS_DENSE 0x70000013
+#define SHT_MIPS_PDESC 0x70000014
+#define SHT_MIPS_LOCSYM 0x70000015
+#define SHT_MIPS_AUXSYM 0x70000016
+#define SHT_MIPS_OPTSYM 0x70000017
+#define SHT_MIPS_LOCSTR 0x70000018
+#define SHT_MIPS_LINE 0x70000019
+#define SHT_MIPS_RFDESC 0x7000001a
+#define SHT_MIPS_DELTASYM 0x7000001b
+#define SHT_MIPS_DELTAINST 0x7000001c
+#define SHT_MIPS_DELTACLASS 0x7000001d
+#define SHT_MIPS_DWARF 0x7000001e /* DWARF debugging information. */
+#define SHT_MIPS_DELTADECL 0x7000001f
+#define SHT_MIPS_SYMBOL_LIB 0x70000020
+#define SHT_MIPS_EVENTS 0x70000021 /* Event section. */
+#define SHT_MIPS_TRANSLATE 0x70000022
+#define SHT_MIPS_PIXIE 0x70000023
+#define SHT_MIPS_XLATE 0x70000024
+#define SHT_MIPS_XLATE_DEBUG 0x70000025
+#define SHT_MIPS_WHIRL 0x70000026
+#define SHT_MIPS_EH_REGION 0x70000027
+#define SHT_MIPS_XLATE_OLD 0x70000028
+#define SHT_MIPS_PDR_EXCEPTION 0x70000029
+
+/* Legal values for sh_flags field of Elf32_Shdr. */
+
+#define SHF_MIPS_GPREL 0x10000000 /* Must be part of global data area */
+#define SHF_MIPS_MERGE 0x20000000
+#define SHF_MIPS_ADDR 0x40000000
+#define SHF_MIPS_STRINGS 0x80000000
+#define SHF_MIPS_NOSTRIP 0x08000000
+#define SHF_MIPS_LOCAL 0x04000000
+#define SHF_MIPS_NAMES 0x02000000
+#define SHF_MIPS_NODUPE 0x01000000
+
+
+/* Symbol tables. */
+
+/* MIPS specific values for `st_other'. */
+#define STO_MIPS_DEFAULT 0x0
+#define STO_MIPS_INTERNAL 0x1
+#define STO_MIPS_HIDDEN 0x2
+#define STO_MIPS_PROTECTED 0x3
+#define STO_MIPS_SC_ALIGN_UNUSED 0xff
+
+/* MIPS specific values for `st_info'. */
+#define STB_MIPS_SPLIT_COMMON 13
+
+/* Entries found in sections of type SHT_MIPS_GPTAB. */
+
+typedef union
+{
+ struct
+ {
+ Elf32_Word gt_current_g_value; /* -G value used for compilation */
+ Elf32_Word gt_unused; /* Not used */
+ } gt_header; /* First entry in section */
+ struct
+ {
+ Elf32_Word gt_g_value; /* If this value were used for -G */
+ Elf32_Word gt_bytes; /* This many bytes would be used */
+ } gt_entry; /* Subsequent entries in section */
+} Elf32_gptab;
+
+/* Entry found in sections of type SHT_MIPS_REGINFO. */
+
+typedef struct
+{
+ Elf32_Word ri_gprmask; /* General registers used */
+ Elf32_Word ri_cprmask[4]; /* Coprocessor registers used */
+ Elf32_Sword ri_gp_value; /* $gp register value */
+} Elf32_RegInfo;
+
+/* Entries found in sections of type SHT_MIPS_OPTIONS. */
+
+typedef struct
+{
+ unsigned char kind; /* Determines interpretation of the
+ variable part of descriptor. */
+ unsigned char size; /* Size of descriptor, including header. */
+ Elf32_Section section; /* Section header index of section affected,
+ 0 for global options. */
+ Elf32_Word info; /* Kind-specific information. */
+} Elf_Options;
+
+/* Values for `kind' field in Elf_Options. */
+
+#define ODK_NULL 0 /* Undefined. */
+#define ODK_REGINFO 1 /* Register usage information. */
+#define ODK_EXCEPTIONS 2 /* Exception processing options. */
+#define ODK_PAD 3 /* Section padding options. */
+#define ODK_HWPATCH 4 /* Hardware workarounds performed */
+#define ODK_FILL 5 /* record the fill value used by the linker. */
+#define ODK_TAGS 6 /* reserve space for desktop tools to write. */
+#define ODK_HWAND 7 /* HW workarounds. 'AND' bits when merging. */
+#define ODK_HWOR 8 /* HW workarounds. 'OR' bits when merging. */
+
+/* Values for `info' in Elf_Options for ODK_EXCEPTIONS entries. */
+
+#define OEX_FPU_MIN 0x1f /* FPE's which MUST be enabled. */
+#define OEX_FPU_MAX 0x1f00 /* FPE's which MAY be enabled. */
+#define OEX_PAGE0 0x10000 /* page zero must be mapped. */
+#define OEX_SMM 0x20000 /* Force sequential memory mode? */
+#define OEX_FPDBUG 0x40000 /* Force floating point debug mode? */
+#define OEX_PRECISEFP OEX_FPDBUG
+#define OEX_DISMISS 0x80000 /* Dismiss invalid address faults? */
+
+#define OEX_FPU_INVAL 0x10
+#define OEX_FPU_DIV0 0x08
+#define OEX_FPU_OFLO 0x04
+#define OEX_FPU_UFLO 0x02
+#define OEX_FPU_INEX 0x01
+
+/* Masks for `info' in Elf_Options for an ODK_HWPATCH entry. */
+
+#define OHW_R4KEOP 0x1 /* R4000 end-of-page patch. */
+#define OHW_R8KPFETCH 0x2 /* may need R8000 prefetch patch. */
+#define OHW_R5KEOP 0x4 /* R5000 end-of-page patch. */
+#define OHW_R5KCVTL 0x8 /* R5000 cvt.[ds].l bug. clean=1. */
+
+#define OPAD_PREFIX 0x1
+#define OPAD_POSTFIX 0x2
+#define OPAD_SYMBOL 0x4
+
+/* Entry found in `.options' section. */
+
+typedef struct
+{
+ Elf32_Word hwp_flags1; /* Extra flags. */
+ Elf32_Word hwp_flags2; /* Extra flags. */
+} Elf_Options_Hw;
+
+/* Masks for `info' in ElfOptions for ODK_HWAND and ODK_HWOR entries. */
+
+#define OHWA0_R4KEOP_CHECKED 0x00000001
+#define OHWA1_R4KEOP_CLEAN 0x00000002
+
+/* MIPS relocs. */
+
+#define R_MIPS_NONE 0 /* No reloc */
+#define R_MIPS_16 1 /* Direct 16 bit */
+#define R_MIPS_32 2 /* Direct 32 bit */
+#define R_MIPS_REL32 3 /* PC relative 32 bit */
+#define R_MIPS_26 4 /* Direct 26 bit shifted */
+#define R_MIPS_HI16 5 /* High 16 bit */
+#define R_MIPS_LO16 6 /* Low 16 bit */
+#define R_MIPS_GPREL16 7 /* GP relative 16 bit */
+#define R_MIPS_LITERAL 8 /* 16 bit literal entry */
+#define R_MIPS_GOT16 9 /* 16 bit GOT entry */
+#define R_MIPS_PC16 10 /* PC relative 16 bit */
+#define R_MIPS_CALL16 11 /* 16 bit GOT entry for function */
+#define R_MIPS_GPREL32 12 /* GP relative 32 bit */
+
+#define R_MIPS_SHIFT5 16
+#define R_MIPS_SHIFT6 17
+#define R_MIPS_64 18
+#define R_MIPS_GOT_DISP 19
+#define R_MIPS_GOT_PAGE 20
+#define R_MIPS_GOT_OFST 21
+#define R_MIPS_GOT_HI16 22
+#define R_MIPS_GOT_LO16 23
+#define R_MIPS_SUB 24
+#define R_MIPS_INSERT_A 25
+#define R_MIPS_INSERT_B 26
+#define R_MIPS_DELETE 27
+#define R_MIPS_HIGHER 28
+#define R_MIPS_HIGHEST 29
+#define R_MIPS_CALL_HI16 30
+#define R_MIPS_CALL_LO16 31
+#define R_MIPS_SCN_DISP 32
+#define R_MIPS_REL16 33
+#define R_MIPS_ADD_IMMEDIATE 34
+#define R_MIPS_PJUMP 35
+#define R_MIPS_RELGOT 36
+#define R_MIPS_JALR 37
+/* Keep this the last entry. */
+#define R_MIPS_NUM 38
+
+/* Legal values for p_type field of Elf32_Phdr. */
+
+#define PT_MIPS_REGINFO 0x70000000 /* Register usage information */
+#define PT_MIPS_RTPROC 0x70000001 /* Runtime procedure table. */
+#define PT_MIPS_OPTIONS 0x70000002
+
+/* Special program header types. */
+
+#define PF_MIPS_LOCAL 0x10000000
+
+/* Legal values for d_tag field of Elf32_Dyn. */
+
+#define DT_MIPS_RLD_VERSION 0x70000001 /* Runtime linker interface version */
+#define DT_MIPS_TIME_STAMP 0x70000002 /* Timestamp */
+#define DT_MIPS_ICHECKSUM 0x70000003 /* Checksum */
+#define DT_MIPS_IVERSION 0x70000004 /* Version string (string tbl index) */
+#define DT_MIPS_FLAGS 0x70000005 /* Flags */
+#define DT_MIPS_BASE_ADDRESS 0x70000006 /* Base address */
+#define DT_MIPS_MSYM 0x70000007
+#define DT_MIPS_CONFLICT 0x70000008 /* Address of CONFLICT section */
+#define DT_MIPS_LIBLIST 0x70000009 /* Address of LIBLIST section */
+#define DT_MIPS_LOCAL_GOTNO 0x7000000a /* Number of local GOT entries */
+#define DT_MIPS_CONFLICTNO 0x7000000b /* Number of CONFLICT entries */
+#define DT_MIPS_LIBLISTNO 0x70000010 /* Number of LIBLIST entries */
+#define DT_MIPS_SYMTABNO 0x70000011 /* Number of DYNSYM entries */
+#define DT_MIPS_UNREFEXTNO 0x70000012 /* First external DYNSYM */
+#define DT_MIPS_GOTSYM 0x70000013 /* First GOT entry in DYNSYM */
+#define DT_MIPS_HIPAGENO 0x70000014 /* Number of GOT page table entries */
+#define DT_MIPS_RLD_MAP 0x70000016 /* Address of run time loader map. */
+#define DT_MIPS_DELTA_CLASS 0x70000017 /* Delta C++ class definition. */
+#define DT_MIPS_DELTA_CLASS_NO 0x70000018 /* Number of entries in
+ DT_MIPS_DELTA_CLASS. */
+#define DT_MIPS_DELTA_INSTANCE 0x70000019 /* Delta C++ class instances. */
+#define DT_MIPS_DELTA_INSTANCE_NO 0x7000001a /* Number of entries in
+ DT_MIPS_DELTA_INSTANCE. */
+#define DT_MIPS_DELTA_RELOC 0x7000001b /* Delta relocations. */
+#define DT_MIPS_DELTA_RELOC_NO 0x7000001c /* Number of entries in
+ DT_MIPS_DELTA_RELOC. */
+#define DT_MIPS_DELTA_SYM 0x7000001d /* Delta symbols that Delta
+ relocations refer to. */
+#define DT_MIPS_DELTA_SYM_NO 0x7000001e /* Number of entries in
+ DT_MIPS_DELTA_SYM. */
+#define DT_MIPS_DELTA_CLASSSYM 0x70000020 /* Delta symbols that hold the
+ class declaration. */
+#define DT_MIPS_DELTA_CLASSSYM_NO 0x70000021 /* Number of entries in
+ DT_MIPS_DELTA_CLASSSYM. */
+#define DT_MIPS_CXX_FLAGS 0x70000022 /* Flags indicating for C++ flavor. */
+#define DT_MIPS_PIXIE_INIT 0x70000023
+#define DT_MIPS_SYMBOL_LIB 0x70000024
+#define DT_MIPS_LOCALPAGE_GOTIDX 0x70000025
+#define DT_MIPS_LOCAL_GOTIDX 0x70000026
+#define DT_MIPS_HIDDEN_GOTIDX 0x70000027
+#define DT_MIPS_PROTECTED_GOTIDX 0x70000028
+#define DT_MIPS_OPTIONS 0x70000029 /* Address of .options. */
+#define DT_MIPS_INTERFACE 0x7000002a /* Address of .interface. */
+#define DT_MIPS_DYNSTR_ALIGN 0x7000002b
+#define DT_MIPS_INTERFACE_SIZE 0x7000002c /* Size of the .interface section. */
+#define DT_MIPS_RLD_TEXT_RESOLVE_ADDR 0x7000002d /* Address of rld_text_rsolve
+ function stored in GOT. */
+#define DT_MIPS_PERF_SUFFIX 0x7000002e /* Default suffix of dso to be added
+ by rld on dlopen() calls. */
+#define DT_MIPS_COMPACT_SIZE 0x7000002f /* (O32)Size of compact rel section. */
+#define DT_MIPS_GP_VALUE 0x70000030 /* GP value for aux GOTs. */
+#define DT_MIPS_AUX_DYNAMIC 0x70000031 /* Address of aux .dynamic. */
+#define DT_MIPS_NUM 0x32
+
+/* Legal values for DT_MIPS_FLAGS Elf32_Dyn entry. */
+
+#define RHF_NONE 0 /* No flags */
+#define RHF_QUICKSTART (1 << 0) /* Use quickstart */
+#define RHF_NOTPOT (1 << 1) /* Hash size not power of 2 */
+#define RHF_NO_LIBRARY_REPLACEMENT (1 << 2) /* Ignore LD_LIBRARY_PATH */
+#define RHF_NO_MOVE (1 << 3)
+#define RHF_SGI_ONLY (1 << 4)
+#define RHF_GUARANTEE_INIT (1 << 5)
+#define RHF_DELTA_C_PLUS_PLUS (1 << 6)
+#define RHF_GUARANTEE_START_INIT (1 << 7)
+#define RHF_PIXIE (1 << 8)
+#define RHF_DEFAULT_DELAY_LOAD (1 << 9)
+#define RHF_REQUICKSTART (1 << 10)
+#define RHF_REQUICKSTARTED (1 << 11)
+#define RHF_CORD (1 << 12)
+#define RHF_NO_UNRES_UNDEF (1 << 13)
+#define RHF_RLD_ORDER_SAFE (1 << 14)
+
+/* Entries found in sections of type SHT_MIPS_LIBLIST. */
+
+typedef struct
+{
+ Elf32_Word l_name; /* Name (string table index) */
+ Elf32_Word l_time_stamp; /* Timestamp */
+ Elf32_Word l_checksum; /* Checksum */
+ Elf32_Word l_version; /* Interface version */
+ Elf32_Word l_flags; /* Flags */
+} Elf32_Lib;
+
+typedef struct
+{
+ Elf64_Word l_name; /* Name (string table index) */
+ Elf64_Word l_time_stamp; /* Timestamp */
+ Elf64_Word l_checksum; /* Checksum */
+ Elf64_Word l_version; /* Interface version */
+ Elf64_Word l_flags; /* Flags */
+} Elf64_Lib;
+
+
+/* Legal values for l_flags. */
+
+#define LL_NONE 0
+#define LL_EXACT_MATCH (1 << 0) /* Require exact match */
+#define LL_IGNORE_INT_VER (1 << 1) /* Ignore interface version */
+#define LL_REQUIRE_MINOR (1 << 2)
+#define LL_EXPORTS (1 << 3)
+#define LL_DELAY_LOAD (1 << 4)
+#define LL_DELTA (1 << 5)
+
+/* Entries found in sections of type SHT_MIPS_CONFLICT. */
+
+typedef Elf32_Addr Elf32_Conflict;
+
+
+/* HPPA specific definitions. */
+
+/* Legal values for e_flags field of Elf32_Ehdr. */
+
+#define EF_PARISC_TRAPNIL 0x00010000 /* Trap nil pointer dereference. */
+#define EF_PARISC_EXT 0x00020000 /* Program uses arch. extensions. */
+#define EF_PARISC_LSB 0x00040000 /* Program expects little endian. */
+#define EF_PARISC_WIDE 0x00080000 /* Program expects wide mode. */
+#define EF_PARISC_NO_KABP 0x00100000 /* No kernel assisted branch
+ prediction. */
+#define EF_PARISC_LAZYSWAP 0x00400000 /* Allow lazy swapping. */
+#define EF_PARISC_ARCH 0x0000ffff /* Architecture version. */
+
+/* Defined values for `e_flags & EF_PARISC_ARCH' are: */
+
+#define EFA_PARISC_1_0 0x020b /* PA-RISC 1.0 big-endian. */
+#define EFA_PARISC_1_1 0x0210 /* PA-RISC 1.1 big-endian. */
+#define EFA_PARISC_2_0 0x0214 /* PA-RISC 2.0 big-endian. */
+
+/* Additional section indices. */
+
+#define SHN_PARISC_ANSI_COMMON 0xff00 /* Section for tentatively declared
+ symbols in ANSI C. */
+#define SHN_PARISC_HUGE_COMMON 0xff01 /* Common blocks in huge model. */
+
+/* Legal values for sh_type field of Elf32_Shdr. */
+
+#define SHT_PARISC_EXT 0x70000000 /* Contains product specific ext. */
+#define SHT_PARISC_UNWIND 0x70000001 /* Unwind information. */
+#define SHT_PARISC_DOC 0x70000002 /* Debug info for optimized code. */
+
+/* Legal values for sh_flags field of Elf32_Shdr. */
+
+#define SHF_PARISC_SHORT 0x20000000 /* Section with short addressing. */
+#define SHF_PARISC_HUGE 0x40000000 /* Section far from gp. */
+#define SHF_PARISC_SBP 0x80000000 /* Static branch prediction code. */
+
+/* Legal values for ST_TYPE subfield of st_info (symbol type). */
+
+#define STT_PARISC_MILLICODE 13 /* Millicode function entry point. */
+
+#define STT_HP_OPAQUE (STT_LOOS + 0x1)
+#define STT_HP_STUB (STT_LOOS + 0x2)
+
+/* HPPA relocs. */
+
+#define R_PARISC_NONE 0 /* No reloc. */
+#define R_PARISC_DIR32 1 /* Direct 32-bit reference. */
+#define R_PARISC_DIR21L 2 /* Left 21 bits of eff. address. */
+#define R_PARISC_DIR17R 3 /* Right 17 bits of eff. address. */
+#define R_PARISC_DIR17F 4 /* 17 bits of eff. address. */
+#define R_PARISC_DIR14R 6 /* Right 14 bits of eff. address. */
+#define R_PARISC_PCREL32 9 /* 32-bit rel. address. */
+#define R_PARISC_PCREL21L 10 /* Left 21 bits of rel. address. */
+#define R_PARISC_PCREL17R 11 /* Right 17 bits of rel. address. */
+#define R_PARISC_PCREL17F 12 /* 17 bits of rel. address. */
+#define R_PARISC_PCREL14R 14 /* Right 14 bits of rel. address. */
+#define R_PARISC_DPREL21L 18 /* Left 21 bits of rel. address. */
+#define R_PARISC_DPREL14R 22 /* Right 14 bits of rel. address. */
+#define R_PARISC_GPREL21L 26 /* GP-relative, left 21 bits. */
+#define R_PARISC_GPREL14R 30 /* GP-relative, right 14 bits. */
+#define R_PARISC_LTOFF21L 34 /* LT-relative, left 21 bits. */
+#define R_PARISC_LTOFF14R 38 /* LT-relative, right 14 bits. */
+#define R_PARISC_SECREL32 41 /* 32 bits section rel. address. */
+#define R_PARISC_SEGBASE 48 /* No relocation, set segment base. */
+#define R_PARISC_SEGREL32 49 /* 32 bits segment rel. address. */
+#define R_PARISC_PLTOFF21L 50 /* PLT rel. address, left 21 bits. */
+#define R_PARISC_PLTOFF14R 54 /* PLT rel. address, right 14 bits. */
+#define R_PARISC_LTOFF_FPTR32 57 /* 32 bits LT-rel. function pointer. */
+#define R_PARISC_LTOFF_FPTR21L 58 /* LT-rel. fct ptr, left 21 bits. */
+#define R_PARISC_LTOFF_FPTR14R 62 /* LT-rel. fct ptr, right 14 bits. */
+#define R_PARISC_FPTR64 64 /* 64 bits function address. */
+#define R_PARISC_PLABEL32 65 /* 32 bits function address. */
+#define R_PARISC_PCREL64 72 /* 64 bits PC-rel. address. */
+#define R_PARISC_PCREL22F 74 /* 22 bits PC-rel. address. */
+#define R_PARISC_PCREL14WR 75 /* PC-rel. address, right 14 bits. */
+#define R_PARISC_PCREL14DR 76 /* PC rel. address, right 14 bits. */
+#define R_PARISC_PCREL16F 77 /* 16 bits PC-rel. address. */
+#define R_PARISC_PCREL16WF 78 /* 16 bits PC-rel. address. */
+#define R_PARISC_PCREL16DF 79 /* 16 bits PC-rel. address. */
+#define R_PARISC_DIR64 80 /* 64 bits of eff. address. */
+#define R_PARISC_DIR14WR 83 /* 14 bits of eff. address. */
+#define R_PARISC_DIR14DR 84 /* 14 bits of eff. address. */
+#define R_PARISC_DIR16F 85 /* 16 bits of eff. address. */
+#define R_PARISC_DIR16WF 86 /* 16 bits of eff. address. */
+#define R_PARISC_DIR16DF 87 /* 16 bits of eff. address. */
+#define R_PARISC_GPREL64 88 /* 64 bits of GP-rel. address. */
+#define R_PARISC_GPREL14WR 91 /* GP-rel. address, right 14 bits. */
+#define R_PARISC_GPREL14DR 92 /* GP-rel. address, right 14 bits. */
+#define R_PARISC_GPREL16F 93 /* 16 bits GP-rel. address. */
+#define R_PARISC_GPREL16WF 94 /* 16 bits GP-rel. address. */
+#define R_PARISC_GPREL16DF 95 /* 16 bits GP-rel. address. */
+#define R_PARISC_LTOFF64 96 /* 64 bits LT-rel. address. */
+#define R_PARISC_LTOFF14WR 99 /* LT-rel. address, right 14 bits. */
+#define R_PARISC_LTOFF14DR 100 /* LT-rel. address, right 14 bits. */
+#define R_PARISC_LTOFF16F 101 /* 16 bits LT-rel. address. */
+#define R_PARISC_LTOFF16WF 102 /* 16 bits LT-rel. address. */
+#define R_PARISC_LTOFF16DF 103 /* 16 bits LT-rel. address. */
+#define R_PARISC_SECREL64 104 /* 64 bits section rel. address. */
+#define R_PARISC_SEGREL64 112 /* 64 bits segment rel. address. */
+#define R_PARISC_PLTOFF14WR 115 /* PLT-rel. address, right 14 bits. */
+#define R_PARISC_PLTOFF14DR 116 /* PLT-rel. address, right 14 bits. */
+#define R_PARISC_PLTOFF16F 117 /* 16 bits LT-rel. address. */
+#define R_PARISC_PLTOFF16WF 118 /* 16 bits PLT-rel. address. */
+#define R_PARISC_PLTOFF16DF 119 /* 16 bits PLT-rel. address. */
+#define R_PARISC_LTOFF_FPTR64 120 /* 64 bits LT-rel. function ptr. */
+#define R_PARISC_LTOFF_FPTR14WR 123 /* LT-rel. fct. ptr., right 14 bits. */
+#define R_PARISC_LTOFF_FPTR14DR 124 /* LT-rel. fct. ptr., right 14 bits. */
+#define R_PARISC_LTOFF_FPTR16F 125 /* 16 bits LT-rel. function ptr. */
+#define R_PARISC_LTOFF_FPTR16WF 126 /* 16 bits LT-rel. function ptr. */
+#define R_PARISC_LTOFF_FPTR16DF 127 /* 16 bits LT-rel. function ptr. */
+#define R_PARISC_LORESERVE 128
+#define R_PARISC_COPY 128 /* Copy relocation. */
+#define R_PARISC_IPLT 129 /* Dynamic reloc, imported PLT */
+#define R_PARISC_EPLT 130 /* Dynamic reloc, exported PLT */
+#define R_PARISC_TPREL32 153 /* 32 bits TP-rel. address. */
+#define R_PARISC_TPREL21L 154 /* TP-rel. address, left 21 bits. */
+#define R_PARISC_TPREL14R 158 /* TP-rel. address, right 14 bits. */
+#define R_PARISC_LTOFF_TP21L 162 /* LT-TP-rel. address, left 21 bits. */
+#define R_PARISC_LTOFF_TP14R 166 /* LT-TP-rel. address, right 14 bits.*/
+#define R_PARISC_LTOFF_TP14F 167 /* 14 bits LT-TP-rel. address. */
+#define R_PARISC_TPREL64 216 /* 64 bits TP-rel. address. */
+#define R_PARISC_TPREL14WR 219 /* TP-rel. address, right 14 bits. */
+#define R_PARISC_TPREL14DR 220 /* TP-rel. address, right 14 bits. */
+#define R_PARISC_TPREL16F 221 /* 16 bits TP-rel. address. */
+#define R_PARISC_TPREL16WF 222 /* 16 bits TP-rel. address. */
+#define R_PARISC_TPREL16DF 223 /* 16 bits TP-rel. address. */
+#define R_PARISC_LTOFF_TP64 224 /* 64 bits LT-TP-rel. address. */
+#define R_PARISC_LTOFF_TP14WR 227 /* LT-TP-rel. address, right 14 bits.*/
+#define R_PARISC_LTOFF_TP14DR 228 /* LT-TP-rel. address, right 14 bits.*/
+#define R_PARISC_LTOFF_TP16F 229 /* 16 bits LT-TP-rel. address. */
+#define R_PARISC_LTOFF_TP16WF 230 /* 16 bits LT-TP-rel. address. */
+#define R_PARISC_LTOFF_TP16DF 231 /* 16 bits LT-TP-rel. address. */
+#define R_PARISC_HIRESERVE 255
+
+/* Legal values for p_type field of Elf32_Phdr/Elf64_Phdr. */
+
+#define PT_HP_TLS (PT_LOOS + 0x0)
+#define PT_HP_CORE_NONE (PT_LOOS + 0x1)
+#define PT_HP_CORE_VERSION (PT_LOOS + 0x2)
+#define PT_HP_CORE_KERNEL (PT_LOOS + 0x3)
+#define PT_HP_CORE_COMM (PT_LOOS + 0x4)
+#define PT_HP_CORE_PROC (PT_LOOS + 0x5)
+#define PT_HP_CORE_LOADABLE (PT_LOOS + 0x6)
+#define PT_HP_CORE_STACK (PT_LOOS + 0x7)
+#define PT_HP_CORE_SHM (PT_LOOS + 0x8)
+#define PT_HP_CORE_MMF (PT_LOOS + 0x9)
+#define PT_HP_PARALLEL (PT_LOOS + 0x10)
+#define PT_HP_FASTBIND (PT_LOOS + 0x11)
+#define PT_HP_OPT_ANNOT (PT_LOOS + 0x12)
+#define PT_HP_HSL_ANNOT (PT_LOOS + 0x13)
+#define PT_HP_STACK (PT_LOOS + 0x14)
+
+#define PT_PARISC_ARCHEXT 0x70000000
+#define PT_PARISC_UNWIND 0x70000001
+
+/* Legal values for p_flags field of Elf32_Phdr/Elf64_Phdr. */
+
+#define PF_PARISC_SBP 0x08000000
+
+#define PF_HP_PAGE_SIZE 0x00100000
+#define PF_HP_FAR_SHARED 0x00200000
+#define PF_HP_NEAR_SHARED 0x00400000
+#define PF_HP_CODE 0x01000000
+#define PF_HP_MODIFY 0x02000000
+#define PF_HP_LAZYSWAP 0x04000000
+#define PF_HP_SBP 0x08000000
+
+
+/* Alpha specific definitions. */
+
+/* Legal values for e_flags field of Elf64_Ehdr. */
+
+#define EF_ALPHA_32BIT 1 /* All addresses must be < 2GB. */
+#define EF_ALPHA_CANRELAX 2 /* Relocations for relaxing exist. */
+
+/* Legal values for sh_type field of Elf64_Shdr. */
+
+/* These two are primarily concerned with ECOFF debugging info. */
+#define SHT_ALPHA_DEBUG 0x70000001
+#define SHT_ALPHA_REGINFO 0x70000002
+
+/* Legal values for sh_flags field of Elf64_Shdr. */
+
+#define SHF_ALPHA_GPREL 0x10000000
+
+/* Legal values for st_other field of Elf64_Sym. */
+#define STO_ALPHA_NOPV 0x80 /* No PV required. */
+#define STO_ALPHA_STD_GPLOAD 0x88 /* PV only used for initial ldgp. */
+
+/* Alpha relocs. */
+
+#define R_ALPHA_NONE 0 /* No reloc */
+#define R_ALPHA_REFLONG 1 /* Direct 32 bit */
+#define R_ALPHA_REFQUAD 2 /* Direct 64 bit */
+#define R_ALPHA_GPREL32 3 /* GP relative 32 bit */
+#define R_ALPHA_LITERAL 4 /* GP relative 16 bit w/optimization */
+#define R_ALPHA_LITUSE 5 /* Optimization hint for LITERAL */
+#define R_ALPHA_GPDISP 6 /* Add displacement to GP */
+#define R_ALPHA_BRADDR 7 /* PC+4 relative 23 bit shifted */
+#define R_ALPHA_HINT 8 /* PC+4 relative 16 bit shifted */
+#define R_ALPHA_SREL16 9 /* PC relative 16 bit */
+#define R_ALPHA_SREL32 10 /* PC relative 32 bit */
+#define R_ALPHA_SREL64 11 /* PC relative 64 bit */
+#define R_ALPHA_GPRELHIGH 17 /* GP relative 32 bit, high 16 bits */
+#define R_ALPHA_GPRELLOW 18 /* GP relative 32 bit, low 16 bits */
+#define R_ALPHA_GPREL16 19 /* GP relative 16 bit */
+#define R_ALPHA_COPY 24 /* Copy symbol at runtime */
+#define R_ALPHA_GLOB_DAT 25 /* Create GOT entry */
+#define R_ALPHA_JMP_SLOT 26 /* Create PLT entry */
+#define R_ALPHA_RELATIVE 27 /* Adjust by program base */
+#define R_ALPHA_TLS_GD_HI 28
+#define R_ALPHA_TLSGD 29
+#define R_ALPHA_TLS_LDM 30
+#define R_ALPHA_DTPMOD64 31
+#define R_ALPHA_GOTDTPREL 32
+#define R_ALPHA_DTPREL64 33
+#define R_ALPHA_DTPRELHI 34
+#define R_ALPHA_DTPRELLO 35
+#define R_ALPHA_DTPREL16 36
+#define R_ALPHA_GOTTPREL 37
+#define R_ALPHA_TPREL64 38
+#define R_ALPHA_TPRELHI 39
+#define R_ALPHA_TPRELLO 40
+#define R_ALPHA_TPREL16 41
+/* Keep this the last entry. */
+#define R_ALPHA_NUM 46
+
+/* Magic values of the LITUSE relocation addend. */
+#define LITUSE_ALPHA_ADDR 0
+#define LITUSE_ALPHA_BASE 1
+#define LITUSE_ALPHA_BYTOFF 2
+#define LITUSE_ALPHA_JSR 3
+#define LITUSE_ALPHA_TLS_GD 4
+#define LITUSE_ALPHA_TLS_LDM 5
+
+
+/* PowerPC specific declarations */
+
+/* Values for Elf32/64_Ehdr.e_flags. */
+#define EF_PPC_EMB 0x80000000 /* PowerPC embedded flag */
+
+/* Cygnus local bits below */
+#define EF_PPC_RELOCATABLE 0x00010000 /* PowerPC -mrelocatable flag*/
+#define EF_PPC_RELOCATABLE_LIB 0x00008000 /* PowerPC -mrelocatable-lib
+ flag */
+
+/* PowerPC relocations defined by the ABIs */
+#define GRUB_ELF_R_PPC_NONE 0
+#define GRUB_ELF_R_PPC_ADDR32 1 /* 32bit absolute address */
+#define GRUB_ELF_R_PPC_ADDR24 2 /* 26bit address, 2 bits ignored. */
+#define GRUB_ELF_R_PPC_ADDR16 3 /* 16bit absolute address */
+#define GRUB_ELF_R_PPC_ADDR16_LO 4 /* lower 16bit of absolute address */
+#define GRUB_ELF_R_PPC_ADDR16_HI 5 /* high 16bit of absolute address */
+#define GRUB_ELF_R_PPC_ADDR16_HA 6 /* adjusted high 16bit */
+#define GRUB_ELF_R_PPC_ADDR14 7 /* 16bit address, 2 bits ignored */
+#define GRUB_ELF_R_PPC_ADDR14_BRTAKEN 8
+#define GRUB_ELF_R_PPC_ADDR14_BRNTAKEN 9
+#define GRUB_ELF_R_PPC_REL24 10 /* PC relative 26 bit */
+#define GRUB_ELF_R_PPC_REL14 11 /* PC relative 16 bit */
+#define GRUB_ELF_R_PPC_REL14_BRTAKEN 12
+#define GRUB_ELF_R_PPC_REL14_BRNTAKEN 13
+#define GRUB_ELF_R_PPC_GOT16 14
+#define GRUB_ELF_R_PPC_GOT16_LO 15
+#define GRUB_ELF_R_PPC_GOT16_HI 16
+#define GRUB_ELF_R_PPC_GOT16_HA 17
+#define GRUB_ELF_R_PPC_PLTREL24 18
+#define GRUB_ELF_R_PPC_COPY 19
+#define GRUB_ELF_R_PPC_GLOB_DAT 20
+#define GRUB_ELF_R_PPC_JMP_SLOT 21
+#define GRUB_ELF_R_PPC_RELATIVE 22
+#define GRUB_ELF_R_PPC_LOCAL24PC 23
+#define GRUB_ELF_R_PPC_UADDR32 24
+#define GRUB_ELF_R_PPC_UADDR16 25
+#define GRUB_ELF_R_PPC_REL32 26
+#define GRUB_ELF_R_PPC_PLT32 27
+#define GRUB_ELF_R_PPC_PLTREL32 28
+#define GRUB_ELF_R_PPC_PLT16_LO 29
+#define GRUB_ELF_R_PPC_PLT16_HI 30
+#define GRUB_ELF_R_PPC_PLT16_HA 31
+#define GRUB_ELF_R_PPC_SDAREL16 32
+#define GRUB_ELF_R_PPC_SECTOFF 33
+#define GRUB_ELF_R_PPC_SECTOFF_LO 34
+#define GRUB_ELF_R_PPC_SECTOFF_HI 35
+#define GRUB_ELF_R_PPC_SECTOFF_HA 36
+/* Keep this the last entry. */
+#define GRUB_ELF_R_PPC_NUM 37
+
+/* PowerPC64 relocations defined by the ABIs */
+#define GRUB_ELF_R_PPC64_NONE GRUB_ELF_R_PPC_NONE
+#define GRUB_ELF_R_PPC64_ADDR32 GRUB_ELF_R_PPC_ADDR32 /* 32bit absolute address. */
+#define GRUB_ELF_R_PPC64_ADDR24 GRUB_ELF_R_PPC_ADDR24 /* 26bit address, word aligned. */
+#define GRUB_ELF_R_PPC64_ADDR16 GRUB_ELF_R_PPC_ADDR16 /* 16bit absolute address. */
+#define GRUB_ELF_R_PPC64_ADDR16_LO GRUB_ELF_R_PPC_ADDR16_LO /* lower 16bits of abs. address. */
+#define GRUB_ELF_R_PPC64_ADDR16_HI GRUB_ELF_R_PPC_ADDR16_HI /* high 16bits of abs. address. */
+#define GRUB_ELF_R_PPC64_ADDR16_HA GRUB_ELF_R_PPC_ADDR16_HA /* adjusted high 16bits. */
+#define GRUB_ELF_R_PPC64_ADDR14 GRUB_ELF_R_PPC_ADDR14 /* 16bit address, word aligned. */
+#define GRUB_ELF_R_PPC64_ADDR14_BRTAKEN GRUB_ELF_R_PPC_ADDR14_BRTAKEN
+#define GRUB_ELF_R_PPC64_ADDR14_BRNTAKEN GRUB_ELF_R_PPC_ADDR14_BRNTAKEN
+#define GRUB_ELF_R_PPC64_REL24 GRUB_ELF_R_PPC_REL24 /* PC relative 26 bit, word aligned. */
+#define GRUB_ELF_R_PPC64_REL14 GRUB_ELF_R_PPC_REL14 /* PC relative 16 bit. */
+#define GRUB_ELF_R_PPC64_REL14_BRTAKEN GRUB_ELF_R_PPC_REL14_BRTAKEN
+#define GRUB_ELF_R_PPC64_REL14_BRNTAKEN GRUB_ELF_R_PPC_REL14_BRNTAKEN
+#define GRUB_ELF_R_PPC64_GOT16 GRUB_ELF_R_PPC_GOT16
+#define GRUB_ELF_R_PPC64_GOT16_LO GRUB_ELF_R_PPC_GOT16_LO
+#define GRUB_ELF_R_PPC64_GOT16_HI GRUB_ELF_R_PPC_GOT16_HI
+#define GRUB_ELF_R_PPC64_GOT16_HA GRUB_ELF_R_PPC_GOT16_HA
+
+#define GRUB_ELF_R_PPC64_COPY GRUB_ELF_R_PPC_COPY
+#define GRUB_ELF_R_PPC64_GLOB_DAT GRUB_ELF_R_PPC_GLOB_DAT
+#define GRUB_ELF_R_PPC64_JMP_SLOT GRUB_ELF_R_PPC_JMP_SLOT
+#define GRUB_ELF_R_PPC64_RELATIVE GRUB_ELF_R_PPC_RELATIVE
+
+#define GRUB_ELF_R_PPC64_UADDR32 GRUB_ELF_R_PPC_UADDR32
+#define GRUB_ELF_R_PPC64_UADDR16 GRUB_ELF_R_PPC_UADDR16
+#define GRUB_ELF_R_PPC64_REL32 GRUB_ELF_R_PPC_REL32
+#define GRUB_ELF_R_PPC64_PLT32 GRUB_ELF_R_PPC_PLT32
+#define GRUB_ELF_R_PPC64_PLTREL32 GRUB_ELF_R_PPC_PLTREL32
+#define GRUB_ELF_R_PPC64_PLT16_LO GRUB_ELF_R_PPC_PLT16_LO
+#define GRUB_ELF_R_PPC64_PLT16_HI GRUB_ELF_R_PPC_PLT16_HI
+#define GRUB_ELF_R_PPC64_PLT16_HA GRUB_ELF_R_PPC_PLT16_HA
+
+#define GRUB_ELF_R_PPC64_SECTOFF GRUB_ELF_R_PPC_SECTOFF
+#define GRUB_ELF_R_PPC64_SECTOFF_LO GRUB_ELF_R_PPC_SECTOFF_LO
+#define GRUB_ELF_R_PPC64_SECTOFF_HI GRUB_ELF_R_PPC_SECTOFF_HI
+#define GRUB_ELF_R_PPC64_SECTOFF_HA GRUB_ELF_R_PPC_SECTOFF_HA
+#define GRUB_ELF_R_PPC64_ADDR30 37 /* word30 (S + A - P) >> 2. */
+#define GRUB_ELF_R_PPC64_ADDR64 38 /* doubleword64 S + A. */
+#define GRUB_ELF_R_PPC64_ADDR16_HIGHER 39 /* half16 #higher(S + A). */
+#define GRUB_ELF_R_PPC64_ADDR16_HIGHERA 40 /* half16 #highera(S + A). */
+#define GRUB_ELF_R_PPC64_ADDR16_HIGHEST 41 /* half16 #highest(S + A). */
+#define GRUB_ELF_R_PPC64_ADDR16_HIGHESTA 42 /* half16 #highesta(S + A). */
+#define GRUB_ELF_R_PPC64_UADDR64 43 /* doubleword64 S + A. */
+#define GRUB_ELF_R_PPC64_REL64 44 /* doubleword64 S + A - P. */
+#define GRUB_ELF_R_PPC64_PLT64 45 /* doubleword64 L + A. */
+#define GRUB_ELF_R_PPC64_PLTREL64 46 /* doubleword64 L + A - P. */
+#define GRUB_ELF_R_PPC64_TOC16 47 /* half16* S + A - .TOC. */
+#define GRUB_ELF_R_PPC64_TOC16_LO 48 /* half16 #lo(S + A - .TOC.). */
+#define GRUB_ELF_R_PPC64_TOC16_HI 49 /* half16 #hi(S + A - .TOC.). */
+#define GRUB_ELF_R_PPC64_TOC16_HA 50 /* half16 #ha(S + A - .TOC.). */
+#define GRUB_ELF_R_PPC64_TOC 51 /* doubleword64 .TOC. */
+#define GRUB_ELF_R_PPC64_PLTGOT16 52 /* half16* M + A. */
+#define GRUB_ELF_R_PPC64_PLTGOT16_LO 53 /* half16 #lo(M + A). */
+#define GRUB_ELF_R_PPC64_PLTGOT16_HI 54 /* half16 #hi(M + A). */
+#define GRUB_ELF_R_PPC64_PLTGOT16_HA 55 /* half16 #ha(M + A). */
+
+#define GRUB_ELF_R_PPC64_ADDR16_DS 56 /* half16ds* (S + A) >> 2. */
+#define GRUB_ELF_R_PPC64_ADDR16_LO_DS 57 /* half16ds #lo(S + A) >> 2. */
+#define GRUB_ELF_R_PPC64_GOT16_DS 58 /* half16ds* (G + A) >> 2. */
+#define GRUB_ELF_R_PPC64_GOT16_LO_DS 59 /* half16ds #lo(G + A) >> 2. */
+#define GRUB_ELF_R_PPC64_PLT16_LO_DS 60 /* half16ds #lo(L + A) >> 2. */
+#define GRUB_ELF_R_PPC64_SECTOFF_DS 61 /* half16ds* (R + A) >> 2. */
+#define GRUB_ELF_R_PPC64_SECTOFF_LO_DS 62 /* half16ds #lo(R + A) >> 2. */
+#define GRUB_ELF_R_PPC64_TOC16_DS 63 /* half16ds* (S + A - .TOC.) >> 2. */
+#define GRUB_ELF_R_PPC64_TOC16_LO_DS 64 /* half16ds #lo(S + A - .TOC.) >> 2. */
+#define GRUB_ELF_R_PPC64_PLTGOT16_DS 65 /* half16ds* (M + A) >> 2. */
+#define GRUB_ELF_R_PPC64_PLTGOT16_LO_DS 66 /* half16ds #lo(M + A) >> 2. */
+/* Keep this the last entry. */
+#define GRUB_ELF_R_PPC64_NUM 67
+
+/* The remaining relocs are from the Embedded ELF ABI, and are not
+ in the SVR4 ELF ABI. */
+#define GRUB_ELF_R_PPC_EMB_NADDR32 101
+#define GRUB_ELF_R_PPC_EMB_NADDR16 102
+#define GRUB_ELF_R_PPC_EMB_NADDR16_LO 103
+#define GRUB_ELF_R_PPC_EMB_NADDR16_HI 104
+#define GRUB_ELF_R_PPC_EMB_NADDR16_HA 105
+#define GRUB_ELF_R_PPC_EMB_SDAI16 106
+#define GRUB_ELF_R_PPC_EMB_SDA2I16 107
+#define GRUB_ELF_R_PPC_EMB_SDA2REL 108
+#define GRUB_ELF_R_PPC_EMB_SDA21 109 /* 16 bit offset in SDA */
+#define GRUB_ELF_R_PPC_EMB_MRKREF 110
+#define GRUB_ELF_R_PPC_EMB_RELSEC16 111
+#define GRUB_ELF_R_PPC_EMB_RELST_LO 112
+#define GRUB_ELF_R_PPC_EMB_RELST_HI 113
+#define GRUB_ELF_R_PPC_EMB_RELST_HA 114
+#define GRUB_ELF_R_PPC_EMB_BIT_FLD 115
+#define GRUB_ELF_R_PPC_EMB_RELSDA 116 /* 16 bit relative offset in SDA */
+
+/* Diab tool relocations. */
+#define GRUB_ELF_R_PPC_DIAB_SDA21_LO 180 /* like EMB_SDA21, but lower 16 bit */
+#define GRUB_ELF_R_PPC_DIAB_SDA21_HI 181 /* like EMB_SDA21, but high 16 bit */
+#define GRUB_ELF_R_PPC_DIAB_SDA21_HA 182 /* like EMB_SDA21, adjusted high 16 */
+#define GRUB_ELF_R_PPC_DIAB_RELSDA_LO 183 /* like EMB_RELSDA, but lower 16 bit */
+#define GRUB_ELF_R_PPC_DIAB_RELSDA_HI 184 /* like EMB_RELSDA, but high 16 bit */
+#define GRUB_ELF_R_PPC_DIAB_RELSDA_HA 185 /* like EMB_RELSDA, adjusted high 16 */
+
+/* This is a phony reloc to handle any old fashioned TOC16 references
+ that may still be in object files. */
+#define GRUB_ELF_R_PPC_TOC16 255
+
+/* PowerPC64 specific values for the Dyn d_tag field. */
+#define DT_PPC64_GLINK (DT_LOPROC + 0)
+#define DT_PPC64_NUM 1
+
+/* ARM specific declarations */
+
+/* Processor specific flags for the ELF header e_flags field. */
+#define EF_ARM_RELEXEC 0x01
+#define EF_ARM_HASENTRY 0x02
+#define EF_ARM_INTERWORK 0x04
+#define EF_ARM_APCS_26 0x08
+#define EF_ARM_APCS_FLOAT 0x10
+#define EF_ARM_PIC 0x20
+#define EF_ARM_ALIGN8 0x40 /* 8-bit structure alignment is in use */
+#define EF_ARM_NEW_ABI 0x80
+#define EF_ARM_OLD_ABI 0x100
+#define EF_ARM_SOFT_FLOAT 0x200
+#define EF_ARM_VFP_FLOAT 0x400
+#define EF_ARM_MAVERICK_FLOAT 0x800
+
+/* Other constants defined in the ARM ELF spec. version B-01. */
+/* NB. These conflict with values defined above. */
+#define EF_ARM_SYMSARESORTED 0x04
+#define EF_ARM_DYNSYMSUSESEGIDX 0x08
+#define EF_ARM_MAPSYMSFIRST 0x10
+#define EF_ARM_EABIMASK 0XFF000000
+
+/* Constants defined in AAELF. */
+#define EF_ARM_BE8 0x00800000
+#define EF_ARM_LE8 0x00400000
+
+#define EF_ARM_EABI_VERSION(flags) ((flags) & EF_ARM_EABIMASK)
+#define EF_ARM_EABI_UNKNOWN 0x00000000
+#define EF_ARM_EABI_VER1 0x01000000
+#define EF_ARM_EABI_VER2 0x02000000
+#define EF_ARM_EABI_VER3 0x03000000
+#define EF_ARM_EABI_VER4 0x04000000
+#define EF_ARM_EABI_VER5 0x05000000
+
+/* Additional symbol types for Thumb */
+#define STT_ARM_TFUNC STT_LOPROC /* A Thumb function. */
+#define STT_ARM_16BIT STT_HIPROC /* A Thumb label. */
+
+/* ARM-specific values for sh_flags */
+#define SHF_ARM_ENTRYSECT 0x10000000 /* Section contains an entry point */
+#define SHF_ARM_COMDEF 0x80000000 /* Section may be multiply defined
+ in the input to a link step */
+
+/* ARM-specific program header flags */
+#define PF_ARM_SB 0x10000000 /* Segment contains the location
+ addressed by the static base */
+#define PF_ARM_PI 0x20000000 /* Position-independent segment. */
+#define PF_ARM_ABS 0x40000000 /* Absolute segment. */
+
+/* Processor specific values for the Phdr p_type field. */
+#define PT_ARM_EXIDX (PT_LOPROC + 1) /* ARM unwind segment. */
+
+/* Processor specific values for the Shdr sh_type field. */
+#define SHT_ARM_EXIDX (SHT_LOPROC + 1) /* ARM unwind section. */
+#define SHT_ARM_PREEMPTMAP (SHT_LOPROC + 2) /* Preemption details. */
+#define SHT_ARM_ATTRIBUTES (SHT_LOPROC + 3) /* ARM attributes section. */
+
+
+/* AArch64 relocs. */
+#define R_AARCH64_NONE 0 /* No relocation. */
+#define R_AARCH64_ABS64 257 /* Direct 64 bit. */
+#define R_AARCH64_ABS32 258 /* Direct 32 bit. */
+#define R_AARCH64_PREL32 261
+#define R_AARCH64_ADR_PREL_PG_HI21 275
+#define R_AARCH64_ADD_ABS_LO12_NC 277
+#define R_AARCH64_LDST64_ABS_LO12_NC 286
+#define R_AARCH64_JUMP26 282 /* 26-bit relative. */
+#define R_AARCH64_CALL26 283 /* 26-bit relative. */
+#define R_AARCH64_ADR_GOT_PAGE 311
+#define R_AARCH64_LD64_GOT_LO12_NC 312
+#define R_AARCH64_COPY 1024 /* Copy symbol at runtime. */
+#define R_AARCH64_GLOB_DAT 1025 /* Create GOT entry. */
+#define R_AARCH64_JUMP_SLOT 1026 /* Create PLT entry. */
+#define R_AARCH64_RELATIVE 1027 /* Adjust by program base. */
+#define R_AARCH64_TLS_DTPMOD64 1028 /* Module number, 64 bit. */
+#define R_AARCH64_TLS_DTPREL64 1029 /* Module-relative offset, 64 bit. */
+#define R_AARCH64_TLS_TPREL64 1030 /* TP-relative offset, 64 bit. */
+#define R_AARCH64_TLSDESC 1031 /* TLS Descriptor. */
+
+/* ARM relocs. */
+#define R_ARM_NONE 0 /* No reloc */
+#define R_ARM_PC24 1 /* PC relative 26 bit branch */
+#define R_ARM_ABS32 2 /* Direct 32 bit */
+#define R_ARM_REL32 3 /* PC relative 32 bit */
+#define R_ARM_LDR_PC_G0 4
+#define R_ARM_ABS16 5 /* Direct 16 bit */
+#define R_ARM_ABS12 6 /* Direct 12 bit */
+#define R_ARM_THM_ABS5 7
+#define R_ARM_ABS8 8 /* Direct 8 bit */
+#define R_ARM_SBREL32 9
+#define R_ARM_THM_CALL 10
+#define R_ARM_THM_PC8 11
+#define R_ARM_BREL_ADJ 12
+#define R_ARM_TLS_DESC 13
+#define R_ARM_THM_SWI8 14
+#define R_ARM_XPC25 15
+#define R_ARM_THM_XPC22 16
+#define R_ARM_TLS_DTPMOD32 17
+#define R_ARM_TLS_DTPOFF32 18
+#define R_ARM_TLS_TPOFF32 19
+#define R_ARM_COPY 20 /* Copy symbol at runtime */
+#define R_ARM_GLOB_DAT 21 /* Create GOT entry */
+#define R_ARM_JUMP_SLOT 22 /* Create PLT entry */
+#define R_ARM_RELATIVE 23 /* Adjust by program base */
+#define R_ARM_GOTOFF32 24 /* 32 bit offset to GOT */
+#define R_ARM_BASE_PREL 25 /* 32 bit PC relative offset to GOT */
+#define R_ARM_GOT_BREL 26 /* 32 bit GOT entry */
+#define R_ARM_PLT32 27 /* 32 bit PLT address */
+#define R_ARM_CALL 28
+#define R_ARM_JUMP24 29
+#define R_ARM_THM_JUMP24 30
+#define R_ARM_BASE_ABS 31
+#define R_ARM_ALU_PCREL_7_0 32
+#define R_ARM_ALU_PCREL_15_8 33
+#define R_ARM_ALU_PCREL_23_15 34
+#define R_ARM_LDR_SBREL_11_0 35
+#define R_ARM_ALU_SBREL_19_12 36
+#define R_ARM_ALU_SBREL_27_20 37
+#define R_ARM_TARGET1 38
+#define R_ARM_SBREL31 39
+#define R_ARM_V4BX 40
+#define R_ARM_TARGET2 41
+#define R_ARM_PREL31 42
+#define R_ARM_MOVW_ABS_NC 43
+#define R_ARM_MOVT_ABS 44
+#define R_ARM_MOVW_PREL_NC 45
+#define R_ARM_MOVT_PREL 46
+#define R_ARM_THM_MOVW_ABS_NC 47
+#define R_ARM_THM_MOVT_ABS 48
+#define R_ARM_THM_MOVW_PREL_NC 49
+#define R_ARM_THM_MOVT_PREL 50
+#define R_ARM_THM_JUMP19 51
+#define R_ARM_THM_JUMP6 52
+#define R_ARM_THM_ALU_PREL_11_0 53
+#define R_ARM_THM_PC12 54
+#define R_ARM_ABS32_NOI 55
+#define R_ARM_REL32_NOI 56
+#define R_ARM_ALU_PC_G0_NC 57
+#define R_ARM_ALU_PC_G0 58
+#define R_ARM_ALU_PC_G1_NC 59
+#define R_ARM_ALU_PC_G1 60
+#define R_ARM_ALU_PC_G2 61
+#define R_ARM_LDR_PC_G1 62
+#define R_ARM_LDR_PC_G2 63
+#define R_ARM_LDRS_PC_G0 64
+#define R_ARM_LDRS_PC_G1 65
+#define R_ARM_LDRS_PC_G2 66
+#define R_ARM_LDC_PC_G0 67
+#define R_ARM_LDC_PC_G1 68
+#define R_ARM_LDC_PC_G2 69
+#define R_ARM_ALU_SB_G0_NC 70
+#define R_ARM_ALU_SB_G0 71
+#define R_ARM_ALU_SB_G1_NC 72
+#define R_ARM_ALU_SB_G1 73
+#define R_ARM_ALU_SB_G2 74
+#define R_ARM_LDR_SB_G0 75
+#define R_ARM_LDR_SB_G1 76
+#define R_ARM_LDR_SB_G2 77
+#define R_ARM_LDRS_SB_G0 78
+#define R_ARM_LDRS_SB_G1 79
+#define R_ARM_LDRS_SB_G2 80
+#define R_ARM_LDC_SB_G0 81
+#define R_ARM_LDC_SB_G1 82
+#define R_ARM_LDC_SB_G2 83
+#define R_ARM_MOVW_BREL_NC 84
+#define R_ARM_MOVT_BREL 85
+#define R_ARM_MOVW_BREL 86
+#define R_ARM_THM_MOVW_BREL_NC 87
+#define R_ARM_THM_MOVT_BREL 88
+#define R_ARM_THM_MOVW_BREL 89
+#define R_ARM_TLS_GOTDESC 90
+#define R_ARM_TLS_CALL 91
+#define R_ARM_TLS_DESCSEQ 92
+#define R_ARM_THM_TLS_CALL 93
+#define R_ARM_PLT32_ABS 94
+#define R_ARM_GOT_ABS 95
+#define R_ARM_GOT_PREL 96
+#define R_ARM_GOT_BREL12 97
+#define R_ARM_GOTOFF12 98
+#define R_ARM_GOTRELAX 99
+#define R_ARM_GNU_VTENTRY 100
+#define R_ARM_GNU_VTINHERIT 101
+#define R_ARM_THM_JUMP11 102 /* thumb unconditional branch */
+#define R_ARM_THM_JUMP8 103 /* thumb conditional branch */
+#define R_ARM_TLS_GD32 104 /* PC-rel 32 bit for global dynamic
+ thread local data */
+#define R_ARM_TLS_LDM32 105 /* PC-rel 32 bit for local dynamic
+ thread local data */
+#define R_ARM_TLS_LDO32 106 /* 32 bit offset relative to TLS
+ block */
+#define R_ARM_TLS_IE32 107 /* PC-rel 32 bit for GOT entry of
+ static TLS block offset */
+#define R_ARM_TLS_LE32 108 /* 32 bit offset relative to static
+ TLS block */
+#define R_ARM_TLS_LDO12 109
+#define R_ARM_TLS_LE12 110
+#define R_ARM_IE12GP 111
+#define R_ARM_PRIVATE_0 112
+#define R_ARM_PRIVATE_1 113
+#define R_ARM_PRIVATE_2 114
+#define R_ARM_PRIVATE_3 115
+#define R_ARM_PRIVATE_4 116
+#define R_ARM_PRIVATE_5 117
+#define R_ARM_PRIVATE_6 118
+#define R_ARM_PRIVATE_7 119
+#define R_ARM_PRIVATE_8 120
+#define R_ARM_PRIVATE_9 121
+#define R_ARM_PRIVATE_10 122
+#define R_ARM_PRIVATE_11 123
+#define R_ARM_PRIVATE_12 124
+#define R_ARM_PRIVATE_13 125
+#define R_ARM_PRIVATE_14 126
+#define R_ARM_PRIVATE_15 127
+#define R_ARM_ME_TOO 128
+#define R_ARM_THM_TLS_DESCSEQ16 129
+#define R_ARM_THM_TLS_DESCSEQ32 130
+#define R_ARM_THM_GOT_BREL12 131
+#define R_ARM_IRELATIVE 140
+/* Keep this the last entry. */
+#define R_ARM_NUM 256
+
+/* IA-64 specific declarations. */
+
+/* Processor specific flags for the Ehdr e_flags field. */
+#define EF_IA_64_MASKOS 0x0000000f /* os-specific flags */
+#define EF_IA_64_ABI64 0x00000010 /* 64-bit ABI */
+#define EF_IA_64_ARCH 0xff000000 /* arch. version mask */
+
+/* Processor specific values for the Phdr p_type field. */
+#define PT_IA_64_ARCHEXT (PT_LOPROC + 0) /* arch extension bits */
+#define PT_IA_64_UNWIND (PT_LOPROC + 1) /* ia64 unwind bits */
+
+/* Processor specific flags for the Phdr p_flags field. */
+#define PF_IA_64_NORECOV 0x80000000 /* spec insns w/o recovery */
+
+/* Processor specific values for the Shdr sh_type field. */
+#define SHT_IA_64_EXT (SHT_LOPROC + 0) /* extension bits */
+#define SHT_IA_64_UNWIND (SHT_LOPROC + 1) /* unwind bits */
+
+/* Processor specific flags for the Shdr sh_flags field. */
+#define SHF_IA_64_SHORT 0x10000000 /* section near gp */
+#define SHF_IA_64_NORECOV 0x20000000 /* spec insns w/o recovery */
+
+/* Processor specific values for the Dyn d_tag field. */
+#define DT_IA_64_PLT_RESERVE (DT_LOPROC + 0)
+#define DT_IA_64_NUM 1
+
+/* IA-64 relocations. */
+#define R_IA64_NONE 0x00 /* none */
+#define R_IA64_IMM14 0x21 /* symbol + addend, add imm14 */
+#define R_IA64_IMM22 0x22 /* symbol + addend, add imm22 */
+#define R_IA64_IMM64 0x23 /* symbol + addend, mov imm64 */
+#define R_IA64_DIR32MSB 0x24 /* symbol + addend, data4 MSB */
+#define R_IA64_DIR32LSB 0x25 /* symbol + addend, data4 LSB */
+#define R_IA64_DIR64MSB 0x26 /* symbol + addend, data8 MSB */
+#define R_IA64_DIR64LSB 0x27 /* symbol + addend, data8 LSB */
+#define R_IA64_GPREL22 0x2a /* @gprel(sym + add), add imm22 */
+#define R_IA64_GPREL64I 0x2b /* @gprel(sym + add), mov imm64 */
+#define R_IA64_GPREL32MSB 0x2c /* @gprel(sym + add), data4 MSB */
+#define R_IA64_GPREL32LSB 0x2d /* @gprel(sym + add), data4 LSB */
+#define R_IA64_GPREL64MSB 0x2e /* @gprel(sym + add), data8 MSB */
+#define R_IA64_GPREL64LSB 0x2f /* @gprel(sym + add), data8 LSB */
+#define R_IA64_LTOFF22 0x32 /* @ltoff(sym + add), add imm22 */
+#define R_IA64_LTOFF64I 0x33 /* @ltoff(sym + add), mov imm64 */
+#define R_IA64_PLTOFF22 0x3a /* @pltoff(sym + add), add imm22 */
+#define R_IA64_PLTOFF64I 0x3b /* @pltoff(sym + add), mov imm64 */
+#define R_IA64_PLTOFF64MSB 0x3e /* @pltoff(sym + add), data8 MSB */
+#define R_IA64_PLTOFF64LSB 0x3f /* @pltoff(sym + add), data8 LSB */
+#define R_IA64_FPTR64I 0x43 /* @fptr(sym + add), mov imm64 */
+#define R_IA64_FPTR32MSB 0x44 /* @fptr(sym + add), data4 MSB */
+#define R_IA64_FPTR32LSB 0x45 /* @fptr(sym + add), data4 LSB */
+#define R_IA64_FPTR64MSB 0x46 /* @fptr(sym + add), data8 MSB */
+#define R_IA64_FPTR64LSB 0x47 /* @fptr(sym + add), data8 LSB */
+#define R_IA64_PCREL60B 0x48 /* @pcrel(sym + add), brl */
+#define R_IA64_PCREL21B 0x49 /* @pcrel(sym + add), ptb, call */
+#define R_IA64_PCREL21M 0x4a /* @pcrel(sym + add), chk.s */
+#define R_IA64_PCREL21F 0x4b /* @pcrel(sym + add), fchkf */
+#define R_IA64_PCREL32MSB 0x4c /* @pcrel(sym + add), data4 MSB */
+#define R_IA64_PCREL32LSB 0x4d /* @pcrel(sym + add), data4 LSB */
+#define R_IA64_PCREL64MSB 0x4e /* @pcrel(sym + add), data8 MSB */
+#define R_IA64_PCREL64LSB 0x4f /* @pcrel(sym + add), data8 LSB */
+#define R_IA64_LTOFF_FPTR22 0x52 /* @ltoff(@fptr(s+a)), imm22 */
+#define R_IA64_LTOFF_FPTR64I 0x53 /* @ltoff(@fptr(s+a)), imm64 */
+#define R_IA64_LTOFF_FPTR32MSB 0x54 /* @ltoff(@fptr(s+a)), data4 MSB */
+#define R_IA64_LTOFF_FPTR32LSB 0x55 /* @ltoff(@fptr(s+a)), data4 LSB */
+#define R_IA64_LTOFF_FPTR64MSB 0x56 /* @ltoff(@fptr(s+a)), data8 MSB */
+#define R_IA64_LTOFF_FPTR64LSB 0x57 /* @ltoff(@fptr(s+a)), data8 LSB */
+#define R_IA64_SEGREL32MSB 0x5c /* @segrel(sym + add), data4 MSB */
+#define R_IA64_SEGREL32LSB 0x5d /* @segrel(sym + add), data4 LSB */
+#define R_IA64_SEGREL64MSB 0x5e /* @segrel(sym + add), data8 MSB */
+#define R_IA64_SEGREL64LSB 0x5f /* @segrel(sym + add), data8 LSB */
+#define R_IA64_SECREL32MSB 0x64 /* @secrel(sym + add), data4 MSB */
+#define R_IA64_SECREL32LSB 0x65 /* @secrel(sym + add), data4 LSB */
+#define R_IA64_SECREL64MSB 0x66 /* @secrel(sym + add), data8 MSB */
+#define R_IA64_SECREL64LSB 0x67 /* @secrel(sym + add), data8 LSB */
+#define R_IA64_REL32MSB 0x6c /* data 4 + REL */
+#define R_IA64_REL32LSB 0x6d /* data 4 + REL */
+#define R_IA64_REL64MSB 0x6e /* data 8 + REL */
+#define R_IA64_REL64LSB 0x6f /* data 8 + REL */
+#define R_IA64_LTV32MSB 0x74 /* symbol + addend, data4 MSB */
+#define R_IA64_LTV32LSB 0x75 /* symbol + addend, data4 LSB */
+#define R_IA64_LTV64MSB 0x76 /* symbol + addend, data8 MSB */
+#define R_IA64_LTV64LSB 0x77 /* symbol + addend, data8 LSB */
+#define R_IA64_PCREL21BI 0x79 /* @pcrel(sym + add), 21bit inst */
+#define R_IA64_PCREL22 0x7a /* @pcrel(sym + add), 22bit inst */
+#define R_IA64_PCREL64I 0x7b /* @pcrel(sym + add), 64bit inst */
+#define R_IA64_IPLTMSB 0x80 /* dynamic reloc, imported PLT, MSB */
+#define R_IA64_IPLTLSB 0x81 /* dynamic reloc, imported PLT, LSB */
+#define R_IA64_COPY 0x84 /* copy relocation */
+#define R_IA64_SUB 0x85 /* Addend and symbol difference */
+#define R_IA64_LTOFF22X 0x86 /* LTOFF22, relaxable. */
+#define R_IA64_LDXMOV 0x87 /* Use of LTOFF22X. */
+#define R_IA64_TPREL14 0x91 /* @tprel(sym + add), imm14 */
+#define R_IA64_TPREL22 0x92 /* @tprel(sym + add), imm22 */
+#define R_IA64_TPREL64I 0x93 /* @tprel(sym + add), imm64 */
+#define R_IA64_TPREL64MSB 0x96 /* @tprel(sym + add), data8 MSB */
+#define R_IA64_TPREL64LSB 0x97 /* @tprel(sym + add), data8 LSB */
+#define R_IA64_LTOFF_TPREL22 0x9a /* @ltoff(@tprel(s+a)), imm2 */
+#define R_IA64_DTPMOD64MSB 0xa6 /* @dtpmod(sym + add), data8 MSB */
+#define R_IA64_DTPMOD64LSB 0xa7 /* @dtpmod(sym + add), data8 LSB */
+#define R_IA64_LTOFF_DTPMOD22 0xaa /* @ltoff(@dtpmod(sym + add)), imm22 */
+#define R_IA64_DTPREL14 0xb1 /* @dtprel(sym + add), imm14 */
+#define R_IA64_DTPREL22 0xb2 /* @dtprel(sym + add), imm22 */
+#define R_IA64_DTPREL64I 0xb3 /* @dtprel(sym + add), imm64 */
+#define R_IA64_DTPREL32MSB 0xb4 /* @dtprel(sym + add), data4 MSB */
+#define R_IA64_DTPREL32LSB 0xb5 /* @dtprel(sym + add), data4 LSB */
+#define R_IA64_DTPREL64MSB 0xb6 /* @dtprel(sym + add), data8 MSB */
+#define R_IA64_DTPREL64LSB 0xb7 /* @dtprel(sym + add), data8 LSB */
+#define R_IA64_LTOFF_DTPREL22 0xba /* @ltoff(@dtprel(s+a)), imm22 */
+
+/* SH specific declarations */
+
+/* SH relocs. */
+#define R_SH_NONE 0
+#define R_SH_DIR32 1
+#define R_SH_REL32 2
+#define R_SH_DIR8WPN 3
+#define R_SH_IND12W 4
+#define R_SH_DIR8WPL 5
+#define R_SH_DIR8WPZ 6
+#define R_SH_DIR8BP 7
+#define R_SH_DIR8W 8
+#define R_SH_DIR8L 9
+#define R_SH_SWITCH16 25
+#define R_SH_SWITCH32 26
+#define R_SH_USES 27
+#define R_SH_COUNT 28
+#define R_SH_ALIGN 29
+#define R_SH_CODE 30
+#define R_SH_DATA 31
+#define R_SH_LABEL 32
+#define R_SH_SWITCH8 33
+#define R_SH_GNU_VTINHERIT 34
+#define R_SH_GNU_VTENTRY 35
+#define R_SH_TLS_GD_32 144
+#define R_SH_TLS_LD_32 145
+#define R_SH_TLS_LDO_32 146
+#define R_SH_TLS_IE_32 147
+#define R_SH_TLS_LE_32 148
+#define R_SH_TLS_DTPMOD32 149
+#define R_SH_TLS_DTPOFF32 150
+#define R_SH_TLS_TPOFF32 151
+#define R_SH_TLS_GD_MOV 152
+#define R_SH_TLS_LDM_MOV 153
+#define R_SH_TLS_LDO_MOV 154
+#define R_SH_TLS_IE_MOV 155
+#define R_SH_TLS_LE_MOV 156
+#define R_SH_GOT32 160
+#define R_SH_PLT32 161
+#define R_SH_COPY 162
+#define R_SH_GLOB_DAT 163
+#define R_SH_JMP_SLOT 164
+#define R_SH_RELATIVE 165
+#define R_SH_GOTOFF 166
+#define R_SH_GOTPC 167
+/* Keep this the last entry. */
+#define R_SH_NUM 256
+
+/* Additional s390 relocs */
+
+#define R_390_NONE 0 /* No reloc. */
+#define R_390_8 1 /* Direct 8 bit. */
+#define R_390_12 2 /* Direct 12 bit. */
+#define R_390_16 3 /* Direct 16 bit. */
+#define R_390_32 4 /* Direct 32 bit. */
+#define R_390_PC32 5 /* PC relative 32 bit. */
+#define R_390_GOT12 6 /* 12 bit GOT offset. */
+#define R_390_GOT32 7 /* 32 bit GOT offset. */
+#define R_390_PLT32 8 /* 32 bit PC relative PLT address. */
+#define R_390_COPY 9 /* Copy symbol at runtime. */
+#define R_390_GLOB_DAT 10 /* Create GOT entry. */
+#define R_390_JMP_SLOT 11 /* Create PLT entry. */
+#define R_390_RELATIVE 12 /* Adjust by program base. */
+#define R_390_GOTOFF 13 /* 32 bit offset to GOT. */
+#define R_390_GOTPC 14 /* 32 bit PC relative offset to GOT. */
+#define R_390_GOT16 15 /* 16 bit GOT offset. */
+#define R_390_PC16 16 /* PC relative 16 bit. */
+#define R_390_PC16DBL 17 /* PC relative 16 bit shifted by 1. */
+#define R_390_PLT16DBL 18 /* 16 bit PC rel. PLT shifted by 1. */
+#define R_390_PC32DBL 19 /* PC relative 32 bit shifted by 1. */
+#define R_390_PLT32DBL 20 /* 32 bit PC rel. PLT shifted by 1. */
+#define R_390_GOTPCDBL 21 /* 32 bit PC rel. GOT shifted by 1. */
+#define R_390_64 22 /* Direct 64 bit. */
+#define R_390_PC64 23 /* PC relative 64 bit. */
+#define R_390_GOT64 24 /* 64 bit GOT offset. */
+#define R_390_PLT64 25 /* 64 bit PC relative PLT address. */
+#define R_390_GOTENT 26 /* 32 bit PC rel. to GOT entry >> 1. */
+
+/* Keep this the last entry. */
+#define R_390_NUM 27
+
+/* CRIS relocations. */
+#define R_CRIS_NONE 0
+#define R_CRIS_8 1
+#define R_CRIS_16 2
+#define R_CRIS_32 3
+#define R_CRIS_8_PCREL 4
+#define R_CRIS_16_PCREL 5
+#define R_CRIS_32_PCREL 6
+#define R_CRIS_GNU_VTINHERIT 7
+#define R_CRIS_GNU_VTENTRY 8
+#define R_CRIS_COPY 9
+#define R_CRIS_GLOB_DAT 10
+#define R_CRIS_JUMP_SLOT 11
+#define R_CRIS_RELATIVE 12
+#define R_CRIS_16_GOT 13
+#define R_CRIS_32_GOT 14
+#define R_CRIS_16_GOTPLT 15
+#define R_CRIS_32_GOTPLT 16
+#define R_CRIS_32_GOTREL 17
+#define R_CRIS_32_PLT_GOTREL 18
+#define R_CRIS_32_PLT_PCREL 19
+
+#define R_CRIS_NUM 20
+
+/* AMD x86-64 relocations. */
+#define R_X86_64_NONE 0 /* No reloc */
+#define R_X86_64_64 1 /* Direct 64 bit */
+#define R_X86_64_PC32 2 /* PC relative 32 bit signed */
+#define R_X86_64_GOT32 3 /* 32 bit GOT entry */
+#define R_X86_64_PLT32 4 /* 32 bit PLT address */
+#define R_X86_64_COPY 5 /* Copy symbol at runtime */
+#define R_X86_64_GLOB_DAT 6 /* Create GOT entry */
+#define R_X86_64_JUMP_SLOT 7 /* Create PLT entry */
+#define R_X86_64_RELATIVE 8 /* Adjust by program base */
+#define R_X86_64_GOTPCREL 9 /* 32 bit signed PC relative
+ offset to GOT */
+#define R_X86_64_32 10 /* Direct 32 bit zero extended */
+#define R_X86_64_32S 11 /* Direct 32 bit sign extended */
+#define R_X86_64_16 12 /* Direct 16 bit zero extended */
+#define R_X86_64_PC16 13 /* 16 bit sign extended pc relative */
+#define R_X86_64_8 14 /* Direct 8 bit sign extended */
+#define R_X86_64_PC8 15 /* 8 bit sign extended pc relative */
+#define R_X86_64_DTPMOD64 16 /* ID of module containing symbol */
+#define R_X86_64_DTPOFF64 17 /* Offset in module's TLS block */
+#define R_X86_64_TPOFF64 18 /* Offset in initial TLS block */
+#define R_X86_64_TLSGD 19 /* 32 bit signed PC relative offset
+ to two GOT entries for GD symbol */
+#define R_X86_64_TLSLD 20 /* 32 bit signed PC relative offset
+ to two GOT entries for LD symbol */
+#define R_X86_64_DTPOFF32 21 /* Offset in TLS block */
+#define r_x86_64_GOTTPOFF 22 /* 32 bit signed PC relative offset
+ to GOT entry for IE symbol */
+#define R_X86_64_TPOFF32 23 /* Offset in initial TLS block */
+
+#define R_X86_64_NUM 24
+
+/* RISC-V relocations */
+#define R_RISCV_NONE 0
+#define R_RISCV_32 1
+#define R_RISCV_64 2
+#define R_RISCV_RELATIVE 3
+#define R_RISCV_COPY 4
+#define R_RISCV_JUMP_SLOT 5
+#define R_RISCV_TLS_DTPMOD32 6
+#define R_RISCV_TLS_DTPMOD64 7
+#define R_RISCV_TLS_DTPREL32 8
+#define R_RISCV_TLS_DTPREL64 9
+#define R_RISCV_TLS_TPREL32 10
+#define R_RISCV_TLS_TPREL64 11
+
+#define R_RISCV_BRANCH 16
+#define R_RISCV_JAL 17
+#define R_RISCV_CALL 18
+#define R_RISCV_CALL_PLT 19
+#define R_RISCV_GOT_HI20 20
+#define R_RISCV_TLS_GOT_HI20 21
+#define R_RISCV_TLS_GD_HI20 22
+#define R_RISCV_PCREL_HI20 23
+#define R_RISCV_PCREL_LO12_I 24
+#define R_RISCV_PCREL_LO12_S 25
+#define R_RISCV_HI20 26
+#define R_RISCV_LO12_I 27
+#define R_RISCV_LO12_S 28
+#define R_RISCV_TPREL_HI20 29
+#define R_RISCV_TPREL_LO12_I 30
+#define R_RISCV_TPREL_LO12_S 31
+#define R_RISCV_TPREL_ADD 32
+#define R_RISCV_ADD8 33
+#define R_RISCV_ADD16 34
+#define R_RISCV_ADD32 35
+#define R_RISCV_ADD64 36
+#define R_RISCV_SUB8 37
+#define R_RISCV_SUB16 38
+#define R_RISCV_SUB32 39
+#define R_RISCV_SUB64 40
+#define R_RISCV_GNU_VTINHERIT 41
+#define R_RISCV_GNU_VTENTRY 42
+#define R_RISCV_ALIGN 43
+#define R_RISCV_RVC_BRANCH 44
+#define R_RISCV_RVC_JUMP 45
+#define R_RISCV_LUI 46
+#define R_RISCV_GPREL_I 47
+#define R_RISCV_GPREL_S 48
+#define R_RISCV_TPREL_I 49
+#define R_RISCV_TPREL_S 50
+#define R_RISCV_RELAX 51
+#define R_RISCV_SUB6 52
+#define R_RISCV_SET6 53
+#define R_RISCV_SET8 54
+#define R_RISCV_SET16 55
+#define R_RISCV_SET32 56
+#define R_RISCV_32_PCREL 57
+
+#ifdef GRUB_TARGET_WORDSIZE
+#if GRUB_TARGET_WORDSIZE == 32
+
+typedef Elf32_Addr Elf_Addr;
+typedef Elf32_Nhdr Elf_Nhdr;
+typedef Elf32_Ehdr Elf_Ehdr;
+typedef Elf32_Phdr Elf_Phdr;
+typedef Elf32_Half Elf_Half;
+typedef Elf32_Off Elf_Off;
+typedef Elf32_Rel Elf_Rel;
+typedef Elf32_Rela Elf_Rela;
+typedef Elf32_Section Elf_Section;
+typedef Elf32_Shdr Elf_Shdr;
+typedef Elf32_Sword Elf_Sword;
+typedef Elf32_Sym Elf_Sym;
+typedef Elf32_Word Elf_Word;
+typedef Elf32_Xword Elf_Xword;
+
+#define ELF_ST_BIND(val) ELF32_ST_BIND(val)
+#define ELF_ST_TYPE(val) ELF32_ST_TYPE(val)
+#define ELF_ST_INFO(a,b) ELF32_ST_INFO(a,b)
+
+#define ELF_R_SYM(val) ELF32_R_SYM(val)
+#define ELF_R_TYPE(val) ELF32_R_TYPE(val)
+#define ELF_R_INFO(sym, type) ELF32_R_INFO(sym, type)
+
+#elif GRUB_TARGET_WORDSIZE == 64
+
+typedef Elf64_Addr Elf_Addr;
+typedef Elf64_Nhdr Elf_Nhdr;
+typedef Elf64_Ehdr Elf_Ehdr;
+typedef Elf64_Phdr Elf_Phdr;
+typedef Elf64_Half Elf_Half;
+typedef Elf64_Off Elf_Off;
+typedef Elf64_Rel Elf_Rel;
+typedef Elf64_Rela Elf_Rela;
+typedef Elf64_Section Elf_Section;
+typedef Elf64_Shdr Elf_Shdr;
+typedef Elf64_Sword Elf_Sword;
+typedef Elf64_Sym Elf_Sym;
+typedef Elf64_Word Elf_Word;
+typedef Elf64_Xword Elf_Xword;
+
+#define ELF_ST_BIND(val) ELF64_ST_BIND (val)
+#define ELF_ST_TYPE(val) ELF64_ST_TYPE (val)
+#define ELF_ST_INFO(a,b) ELF64_ST_INFO(a,b)
+#define ELF_R_SYM(val) ELF64_R_SYM(val)
+#define ELF_R_TYPE(val) ELF64_R_TYPE(val)
+#define ELF_R_INFO(sym, type) ELF64_R_INFO(sym, type)
+
+#endif /* GRUB_TARGET_WORDSIZE == 64 */
+#endif
+
+#endif /* ! GRUB_ELF_H */
diff --git a/include/grub/elfload.h b/include/grub/elfload.h
new file mode 100644
index 0000000..dbb609c
--- /dev/null
+++ b/include/grub/elfload.h
@@ -0,0 +1,82 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_ELFLOAD_HEADER
+#define GRUB_ELFLOAD_HEADER 1
+
+#include <grub/err.h>
+#include <grub/elf.h>
+#include <grub/file.h>
+#include <grub/symbol.h>
+#include <grub/types.h>
+
+struct grub_elf_file
+{
+ grub_file_t file;
+ union {
+ Elf64_Ehdr ehdr64;
+ Elf32_Ehdr ehdr32;
+ } ehdr;
+ void *phdrs;
+ char *filename;
+};
+typedef struct grub_elf_file *grub_elf_t;
+
+typedef int (*grub_elf32_phdr_iterate_hook_t)
+ (grub_elf_t elf, Elf32_Phdr *phdr, void *arg);
+typedef int (*grub_elf64_phdr_iterate_hook_t)
+ (grub_elf_t elf, Elf64_Phdr *phdr, void *arg);
+
+grub_elf_t grub_elf_open (const char *, enum grub_file_type type);
+grub_elf_t grub_elf_file (grub_file_t file, const char *filename);
+grub_err_t grub_elf_close (grub_elf_t);
+
+int grub_elf_is_elf32 (grub_elf_t);
+grub_size_t grub_elf32_size (grub_elf_t,
+ Elf32_Addr *, grub_uint32_t *);
+enum grub_elf_load_flags
+ {
+ GRUB_ELF_LOAD_FLAGS_NONE = 0,
+ GRUB_ELF_LOAD_FLAGS_LOAD_PT_DYNAMIC = 1,
+ GRUB_ELF_LOAD_FLAGS_BITS = 6,
+ GRUB_ELF_LOAD_FLAGS_ALL_BITS = 0,
+ GRUB_ELF_LOAD_FLAGS_28BITS = 2,
+ GRUB_ELF_LOAD_FLAGS_30BITS = 4,
+ GRUB_ELF_LOAD_FLAGS_62BITS = 6,
+ };
+grub_err_t grub_elf32_load (grub_elf_t, const char *filename,
+ void *load_offset, enum grub_elf_load_flags flags, grub_addr_t *,
+ grub_size_t *);
+
+int grub_elf_is_elf64 (grub_elf_t);
+grub_size_t grub_elf64_size (grub_elf_t,
+ Elf64_Addr *, grub_uint64_t *);
+grub_err_t grub_elf64_load (grub_elf_t, const char *filename,
+ void *load_offset, enum grub_elf_load_flags flags, grub_addr_t *,
+ grub_size_t *);
+grub_err_t grub_elf32_load_phdrs (grub_elf_t elf);
+grub_err_t grub_elf64_load_phdrs (grub_elf_t elf);
+
+#define FOR_ELF32_PHDRS(elf, phdr) \
+ for (grub_elf32_load_phdrs (elf), phdr = elf->phdrs; \
+ phdr && phdr < (Elf32_Phdr *) elf->phdrs + elf->ehdr.ehdr32.e_phnum; phdr++)
+#define FOR_ELF64_PHDRS(elf, phdr) \
+ for (grub_elf64_load_phdrs (elf), phdr = elf->phdrs; \
+ phdr && phdr < (Elf64_Phdr *) elf->phdrs + elf->ehdr.ehdr64.e_phnum; phdr++)
+
+#endif /* ! GRUB_ELFLOAD_HEADER */
diff --git a/include/grub/emu/config.h b/include/grub/emu/config.h
new file mode 100644
index 0000000..875d589
--- /dev/null
+++ b/include/grub/emu/config.h
@@ -0,0 +1,48 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_CONFIG_EMU_HEADER
+#define GRUB_CONFIG_EMU_HEADER 1
+
+#include <grub/disk.h>
+#include <grub/partition.h>
+#include <grub/emu/hostfile.h>
+#include <stdio.h>
+
+const char *
+grub_util_get_config_filename (void);
+const char *
+grub_util_get_pkgdatadir (void);
+const char *
+grub_util_get_pkglibdir (void);
+const char *
+grub_util_get_localedir (void);
+
+struct grub_util_config
+{
+ int is_cryptodisk_enabled;
+ char *grub_distributor;
+};
+
+void
+grub_util_load_config (struct grub_util_config *cfg);
+
+void
+grub_util_parse_config (FILE *f, struct grub_util_config *cfg, int simple);
+
+#endif
diff --git a/include/grub/emu/console.h b/include/grub/emu/console.h
new file mode 100644
index 0000000..1e55682
--- /dev/null
+++ b/include/grub/emu/console.h
@@ -0,0 +1,28 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_CONSOLE_UTIL_HEADER
+#define GRUB_CONSOLE_UTIL_HEADER 1
+
+/* Initialize the console system. */
+void grub_console_init (void);
+
+/* Finish the console system. */
+void grub_console_fini (void);
+
+#endif /* ! GRUB_CONSOLE_UTIL_HEADER */
diff --git a/include/grub/emu/exec.h b/include/grub/emu/exec.h
new file mode 100644
index 0000000..d1073ef
--- /dev/null
+++ b/include/grub/emu/exec.h
@@ -0,0 +1,42 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_EMU_EXEC_H
+#define GRUB_EMU_EXEC_H 1
+
+#include <config.h>
+#include <stdarg.h>
+
+#include <sys/types.h>
+pid_t
+grub_util_exec_pipe (const char *const *argv, int *fd);
+pid_t
+grub_util_exec_pipe_stderr (const char *const *argv, int *fd);
+
+int
+grub_util_exec_redirect_all (const char *const *argv, const char *stdin_file,
+ const char *stdout_file, const char *stderr_file);
+int
+grub_util_exec (const char *const *argv);
+int
+grub_util_exec_redirect (const char *const *argv, const char *stdin_file,
+ const char *stdout_file);
+int
+grub_util_exec_redirect_null (const char *const *argv);
+
+#endif
diff --git a/include/grub/emu/getroot.h b/include/grub/emu/getroot.h
new file mode 100644
index 0000000..73fa2d3
--- /dev/null
+++ b/include/grub/emu/getroot.h
@@ -0,0 +1,104 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2003, 2007, 2008, 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_UTIL_GETROOT_HEADER
+#define GRUB_UTIL_GETROOT_HEADER 1
+
+#include <grub/types.h>
+#include <grub/device.h>
+
+#include <sys/types.h>
+#include <stdio.h>
+
+enum grub_dev_abstraction_types {
+ GRUB_DEV_ABSTRACTION_NONE,
+ GRUB_DEV_ABSTRACTION_LVM,
+ GRUB_DEV_ABSTRACTION_RAID,
+ GRUB_DEV_ABSTRACTION_LUKS,
+ GRUB_DEV_ABSTRACTION_GELI,
+};
+
+char *grub_find_device (const char *dir, dev_t dev);
+void grub_util_pull_device (const char *osname);
+char **grub_guess_root_devices (const char *dir);
+int grub_util_get_dev_abstraction (const char *os_dev);
+char *grub_make_system_path_relative_to_its_root (const char *path);
+char *
+grub_make_system_path_relative_to_its_root_os (const char *path);
+char *grub_util_get_grub_dev (const char *os_dev);
+#if defined (__FreeBSD__) || defined(__FreeBSD_kernel__)
+void grub_util_follow_gpart_up (const char *name, grub_disk_addr_t *off_out,
+ char **name_out);
+#endif
+
+#include <sys/stat.h>
+
+#ifdef __linux__
+char **
+grub_find_root_devices_from_mountinfo (const char *dir, char **relroot);
+#endif
+
+/* Devmapper functions provided by getroot_devmapper.c. */
+void
+grub_util_pull_devmapper (const char *os_dev);
+int
+grub_util_device_is_mapped_stat (struct stat *st);
+void grub_util_devmapper_cleanup (void);
+enum grub_dev_abstraction_types
+grub_util_get_dm_abstraction (const char *os_dev);
+char *
+grub_util_get_vg_uuid (const char *os_dev);
+char *
+grub_util_devmapper_part_to_disk (struct stat *st,
+ int *is_part, const char *os_dev);
+char *
+grub_util_get_devmapper_grub_dev (const char *os_dev);
+
+void
+grub_util_pull_lvm_by_command (const char *os_dev);
+char **
+grub_util_find_root_devices_from_poolname (char *poolname);
+
+grub_disk_addr_t
+grub_util_find_partition_start (const char *dev);
+
+/* OS-specific functions provided by getroot_*.c. */
+enum grub_dev_abstraction_types
+grub_util_get_dev_abstraction_os (const char *os_dev);
+char *
+grub_util_part_to_disk (const char *os_dev, struct stat *st,
+ int *is_part);
+int
+grub_util_pull_device_os (const char *osname,
+ enum grub_dev_abstraction_types ab);
+char *
+grub_util_get_grub_dev_os (const char *os_dev);
+grub_disk_addr_t
+grub_util_find_partition_start_os (const char *dev);
+
+char *
+grub_util_guess_bios_drive (const char *orig_path);
+char *
+grub_util_guess_efi_drive (const char *orig_path);
+char *
+grub_util_guess_baremetal_drive (const char *orig_path);
+void
+grub_util_fprint_full_disk_name (FILE *f,
+ const char *drive, grub_device_t dev);
+
+#endif /* ! GRUB_UTIL_GETROOT_HEADER */
diff --git a/include/grub/emu/hostdisk.h b/include/grub/emu/hostdisk.h
new file mode 100644
index 0000000..e006f0b
--- /dev/null
+++ b/include/grub/emu/hostdisk.h
@@ -0,0 +1,98 @@
+/* biosdisk.h - emulate biosdisk */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_BIOSDISK_MACHINE_UTIL_HEADER
+#define GRUB_BIOSDISK_MACHINE_UTIL_HEADER 1
+
+#include <grub/disk.h>
+#include <grub/partition.h>
+#include <sys/types.h>
+#include <grub/emu/hostfile.h>
+
+grub_util_fd_t
+grub_util_fd_open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags,
+ grub_disk_addr_t *max);
+
+void grub_util_biosdisk_init (const char *dev_map);
+void grub_util_biosdisk_fini (void);
+char *grub_util_biosdisk_get_grub_dev (const char *os_dev);
+const char *grub_util_biosdisk_get_osdev (grub_disk_t disk);
+int grub_util_biosdisk_is_present (const char *name);
+int grub_util_biosdisk_is_floppy (grub_disk_t disk);
+const char *
+grub_util_biosdisk_get_compatibility_hint (grub_disk_t disk);
+grub_err_t grub_util_biosdisk_flush (struct grub_disk *disk);
+grub_err_t
+grub_cryptodisk_cheat_mount (const char *sourcedev, const char *cheat);
+const char *
+grub_util_cryptodisk_get_uuid (grub_disk_t disk);
+char *
+grub_util_get_ldm (grub_disk_t disk, grub_disk_addr_t start);
+int
+grub_util_is_ldm (grub_disk_t disk);
+#ifdef GRUB_UTIL
+grub_err_t
+grub_util_ldm_embed (struct grub_disk *disk, unsigned int *nsectors,
+ unsigned int max_nsectors,
+ grub_embed_type_t embed_type,
+ grub_disk_addr_t **sectors);
+#endif
+const char *
+grub_hostdisk_os_dev_to_grub_drive (const char *os_dev, int add);
+
+
+char *
+grub_util_get_os_disk (const char *os_dev);
+
+int
+grub_util_get_dm_node_linear_info (dev_t dev,
+ int *maj, int *min,
+ grub_disk_addr_t *st);
+
+
+/* Supplied by hostdisk_*.c. */
+grub_int64_t
+grub_util_get_fd_size_os (grub_util_fd_t fd, const char *name, unsigned *log_secsize);
+/* REturns partition offset in 512B blocks. */
+grub_disk_addr_t
+grub_hostdisk_find_partition_start_os (const char *dev);
+void
+grub_hostdisk_flush_initial_buffer (const char *os_dev);
+
+#ifdef __GNU__
+int
+grub_util_hurd_get_disk_info (const char *dev, grub_uint32_t *secsize, grub_disk_addr_t *offset,
+ grub_disk_addr_t *size, char **parent);
+#endif
+
+struct grub_util_hostdisk_data
+{
+ char *dev;
+ int access_mode;
+ grub_util_fd_t fd;
+ int is_disk;
+ int device_map;
+};
+
+void grub_host_init (void);
+void grub_host_fini (void);
+void grub_hostfs_init (void);
+void grub_hostfs_fini (void);
+
+#endif /* ! GRUB_BIOSDISK_MACHINE_UTIL_HEADER */
diff --git a/include/grub/emu/hostfile.h b/include/grub/emu/hostfile.h
new file mode 100644
index 0000000..cfb1e2b
--- /dev/null
+++ b/include/grub/emu/hostfile.h
@@ -0,0 +1,68 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_HOSTFILE_EMU_HEADER
+#define GRUB_HOSTFILE_EMU_HEADER 1
+
+#include <grub/disk.h>
+#include <grub/partition.h>
+#include <sys/types.h>
+#include <grub/osdep/hostfile.h>
+
+int
+grub_util_is_directory (const char *path);
+int
+grub_util_is_special_file (const char *path);
+int
+grub_util_is_regular (const char *path);
+
+char *
+grub_util_path_concat (size_t n, ...);
+char *
+grub_util_path_concat_ext (size_t n, ...);
+
+int
+grub_util_fd_seek (grub_util_fd_t fd, grub_uint64_t off);
+ssize_t
+EXPORT_FUNC(grub_util_fd_read) (grub_util_fd_t fd, char *buf, size_t len);
+ssize_t
+EXPORT_FUNC(grub_util_fd_write) (grub_util_fd_t fd, const char *buf, size_t len);
+
+grub_util_fd_t
+EXPORT_FUNC(grub_util_fd_open) (const char *os_dev, int flags);
+const char *
+EXPORT_FUNC(grub_util_fd_strerror) (void);
+int
+grub_util_fd_sync (grub_util_fd_t fd);
+void
+grub_util_disable_fd_syncs (void);
+int
+EXPORT_FUNC(grub_util_fd_close) (grub_util_fd_t fd);
+
+grub_uint64_t
+grub_util_get_fd_size (grub_util_fd_t fd, const char *name, unsigned *log_secsize);
+char *
+grub_util_make_temporary_file (void);
+char *
+grub_util_make_temporary_dir (void);
+void
+grub_util_unlink_recursive (const char *name);
+grub_uint32_t
+grub_util_get_mtime (const char *name);
+
+#endif /* ! GRUB_BIOSDISK_MACHINE_UTIL_HEADER */
diff --git a/include/grub/emu/misc.h b/include/grub/emu/misc.h
new file mode 100644
index 0000000..ff9c48a
--- /dev/null
+++ b/include/grub/emu/misc.h
@@ -0,0 +1,75 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_EMU_MISC_H
+#define GRUB_EMU_MISC_H 1
+
+#include <config.h>
+#include <stdarg.h>
+
+#include <stdio.h>
+
+#include <grub/compiler.h>
+#include <grub/symbol.h>
+#include <grub/types.h>
+#include <grub/misc.h>
+#include <grub/util/misc.h>
+
+extern int verbosity;
+extern const char *program_name;
+
+void grub_init_all (void);
+void grub_fini_all (void);
+
+void grub_find_zpool_from_dir (const char *dir,
+ char **poolname, char **poolfs);
+
+char *grub_make_system_path_relative_to_its_root (const char *path)
+ WARN_UNUSED_RESULT;
+int
+grub_util_device_is_mapped (const char *dev);
+
+#define GRUB_HOST_PRIuLONG_LONG "llu"
+#define GRUB_HOST_PRIxLONG_LONG "llx"
+
+void * EXPORT_FUNC(xcalloc) (grub_size_t nmemb, grub_size_t size) WARN_UNUSED_RESULT;
+void * EXPORT_FUNC(xmalloc) (grub_size_t size) WARN_UNUSED_RESULT;
+void * EXPORT_FUNC(xrealloc) (void *ptr, grub_size_t size) WARN_UNUSED_RESULT;
+char * EXPORT_FUNC(xstrdup) (const char *str) WARN_UNUSED_RESULT;
+char * EXPORT_FUNC(xasprintf) (const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 1, 2))) WARN_UNUSED_RESULT;
+
+void EXPORT_FUNC(grub_util_warn) (const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 1, 2)));
+void EXPORT_FUNC(grub_util_info) (const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 1, 2)));
+void EXPORT_FUNC(grub_util_error) (const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 1, 2), noreturn));
+
+grub_uint64_t EXPORT_FUNC (grub_util_get_cpu_time_ms) (void);
+
+#ifdef HAVE_DEVICE_MAPPER
+int grub_device_mapper_supported (void);
+#endif
+
+#ifdef GRUB_BUILD
+#define grub_util_fopen fopen
+#else
+FILE *
+grub_util_fopen (const char *path, const char *mode);
+#endif
+
+int grub_util_file_sync (FILE *f);
+
+#endif /* GRUB_EMU_MISC_H */
diff --git a/include/grub/emu/net.h b/include/grub/emu/net.h
new file mode 100644
index 0000000..a5d4fcb
--- /dev/null
+++ b/include/grub/emu/net.h
@@ -0,0 +1,37 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_EMUNET_HEADER
+#define GRUB_EMUNET_HEADER 1
+
+#include <grub/types.h>
+#include <grub/symbol.h>
+
+grub_ssize_t
+EXPORT_FUNC(grub_emunet_send) (const void *packet, grub_size_t sz);
+
+grub_ssize_t
+EXPORT_FUNC(grub_emunet_receive) (void *packet, grub_size_t sz);
+
+int
+EXPORT_FUNC(grub_emunet_create) (grub_size_t *mtu);
+
+void
+EXPORT_FUNC(grub_emunet_close) (void);
+
+#endif
diff --git a/include/grub/env.h b/include/grub/env.h
new file mode 100644
index 0000000..76f832e
--- /dev/null
+++ b/include/grub/env.h
@@ -0,0 +1,72 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2003,2005,2006,2007,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_ENV_HEADER
+#define GRUB_ENV_HEADER 1
+
+#include <grub/symbol.h>
+#include <grub/err.h>
+#include <grub/types.h>
+#include <grub/menu.h>
+
+struct grub_env_var;
+
+typedef const char *(*grub_env_read_hook_t) (struct grub_env_var *var,
+ const char *val);
+typedef char *(*grub_env_write_hook_t) (struct grub_env_var *var,
+ const char *val);
+
+struct grub_env_var
+{
+ char *name;
+ char *value;
+ grub_env_read_hook_t read_hook;
+ grub_env_write_hook_t write_hook;
+ struct grub_env_var *next;
+ struct grub_env_var **prevp;
+ struct grub_env_var *sorted_next;
+ int global;
+};
+
+grub_err_t EXPORT_FUNC(grub_env_set) (const char *name, const char *val);
+const char *EXPORT_FUNC(grub_env_get) (const char *name);
+void EXPORT_FUNC(grub_env_unset) (const char *name);
+struct grub_env_var *EXPORT_FUNC(grub_env_update_get_sorted) (void);
+
+#define FOR_SORTED_ENV(var) for (var = grub_env_update_get_sorted (); var; var = var->sorted_next)
+
+grub_err_t EXPORT_FUNC(grub_register_variable_hook) (const char *name,
+ grub_env_read_hook_t read_hook,
+ grub_env_write_hook_t write_hook);
+
+grub_err_t grub_env_context_open (void);
+grub_err_t grub_env_context_close (void);
+grub_err_t EXPORT_FUNC(grub_env_export) (const char *name);
+
+void grub_env_unset_menu (void);
+grub_menu_t grub_env_get_menu (void);
+void grub_env_set_menu (grub_menu_t nmenu);
+
+grub_err_t
+grub_env_extractor_open (int source);
+
+grub_err_t
+grub_env_extractor_close (int source);
+
+
+#endif /* ! GRUB_ENV_HEADER */
diff --git a/include/grub/env_private.h b/include/grub/env_private.h
new file mode 100644
index 0000000..bb00153
--- /dev/null
+++ b/include/grub/env_private.h
@@ -0,0 +1,46 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2003,2005,2006,2007,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_ENV_PRIVATE_HEADER
+#define GRUB_ENV_PRIVATE_HEADER 1
+
+#include <grub/env.h>
+
+/* The size of the hash table. */
+#define HASHSZ 13
+
+/* A hashtable for quick lookup of variables. */
+struct grub_env_context
+{
+ /* A hash table for variables. */
+ struct grub_env_var *vars[HASHSZ];
+
+ /* One level deeper on the stack. */
+ struct grub_env_context *prev;
+};
+
+/* This is used for sorting only. */
+struct grub_env_sorted_var
+{
+ struct grub_env_var *var;
+ struct grub_env_sorted_var *next;
+};
+
+extern struct grub_env_context *EXPORT_VAR(grub_current_context);
+
+#endif /* ! GRUB_ENV_PRIVATE_HEADER */
diff --git a/include/grub/err.h b/include/grub/err.h
new file mode 100644
index 0000000..b08d5d0
--- /dev/null
+++ b/include/grub/err.h
@@ -0,0 +1,98 @@
+/* err.h - error numbers and prototypes */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2005,2007,2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_ERR_HEADER
+#define GRUB_ERR_HEADER 1
+
+#include <grub/symbol.h>
+#include <grub/compiler.h>
+
+#define GRUB_MAX_ERRMSG 256
+
+typedef enum
+ {
+ GRUB_ERR_NONE = 0,
+ GRUB_ERR_TEST_FAILURE,
+ GRUB_ERR_BAD_MODULE,
+ GRUB_ERR_OUT_OF_MEMORY,
+ GRUB_ERR_BAD_FILE_TYPE,
+ GRUB_ERR_FILE_NOT_FOUND,
+ GRUB_ERR_FILE_READ_ERROR,
+ GRUB_ERR_BAD_FILENAME,
+ GRUB_ERR_UNKNOWN_FS,
+ GRUB_ERR_BAD_FS,
+ GRUB_ERR_BAD_NUMBER,
+ GRUB_ERR_OUT_OF_RANGE,
+ GRUB_ERR_UNKNOWN_DEVICE,
+ GRUB_ERR_BAD_DEVICE,
+ GRUB_ERR_READ_ERROR,
+ GRUB_ERR_WRITE_ERROR,
+ GRUB_ERR_UNKNOWN_COMMAND,
+ GRUB_ERR_INVALID_COMMAND,
+ GRUB_ERR_BAD_ARGUMENT,
+ GRUB_ERR_BAD_PART_TABLE,
+ GRUB_ERR_UNKNOWN_OS,
+ GRUB_ERR_BAD_OS,
+ GRUB_ERR_NO_KERNEL,
+ GRUB_ERR_BAD_FONT,
+ GRUB_ERR_NOT_IMPLEMENTED_YET,
+ GRUB_ERR_SYMLINK_LOOP,
+ GRUB_ERR_BAD_COMPRESSED_DATA,
+ GRUB_ERR_MENU,
+ GRUB_ERR_TIMEOUT,
+ GRUB_ERR_IO,
+ GRUB_ERR_ACCESS_DENIED,
+ GRUB_ERR_EXTRACTOR,
+ GRUB_ERR_NET_BAD_ADDRESS,
+ GRUB_ERR_NET_ROUTE_LOOP,
+ GRUB_ERR_NET_NO_ROUTE,
+ GRUB_ERR_NET_NO_ANSWER,
+ GRUB_ERR_NET_NO_CARD,
+ GRUB_ERR_WAIT,
+ GRUB_ERR_BUG,
+ GRUB_ERR_NET_PORT_CLOSED,
+ GRUB_ERR_NET_INVALID_RESPONSE,
+ GRUB_ERR_NET_UNKNOWN_ERROR,
+ GRUB_ERR_NET_PACKET_TOO_BIG,
+ GRUB_ERR_NET_NO_DOMAIN,
+ GRUB_ERR_EOF,
+ GRUB_ERR_BAD_SIGNATURE
+ }
+grub_err_t;
+
+struct grub_error_saved
+{
+ grub_err_t grub_errno;
+ char errmsg[GRUB_MAX_ERRMSG];
+};
+
+extern grub_err_t EXPORT_VAR(grub_errno);
+extern char EXPORT_VAR(grub_errmsg)[GRUB_MAX_ERRMSG];
+
+grub_err_t EXPORT_FUNC(grub_error) (grub_err_t n, const char *fmt, ...)
+ __attribute__ ((format (GNU_PRINTF, 2, 3)));
+void EXPORT_FUNC(grub_fatal) (const char *fmt, ...) __attribute__ ((noreturn));
+void EXPORT_FUNC(grub_error_push) (void);
+int EXPORT_FUNC(grub_error_pop) (void);
+void EXPORT_FUNC(grub_print_error) (void);
+extern int EXPORT_VAR(grub_err_printed_errors);
+int grub_err_printf (const char *fmt, ...)
+ __attribute__ ((format (GNU_PRINTF, 1, 2)));
+
+#endif /* ! GRUB_ERR_HEADER */
diff --git a/include/grub/exfat.h b/include/grub/exfat.h
new file mode 100644
index 0000000..2b8009c
--- /dev/null
+++ b/include/grub/exfat.h
@@ -0,0 +1,53 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_EXFAT_H
+#define GRUB_EXFAT_H 1
+
+#include <grub/types.h>
+
+struct grub_exfat_bpb
+{
+ grub_uint8_t jmp_boot[3];
+ grub_uint8_t oem_name[8];
+ grub_uint8_t mbz[53];
+ grub_uint64_t num_hidden_sectors;
+ grub_uint64_t num_total_sectors;
+ grub_uint32_t num_reserved_sectors;
+ grub_uint32_t sectors_per_fat;
+ grub_uint32_t cluster_offset;
+ grub_uint32_t cluster_count;
+ grub_uint32_t root_cluster;
+ grub_uint32_t num_serial;
+ grub_uint16_t fs_revision;
+ grub_uint16_t volume_flags;
+ grub_uint8_t bytes_per_sector_shift;
+ grub_uint8_t sectors_per_cluster_shift;
+ grub_uint8_t num_fats;
+ grub_uint8_t num_ph_drive;
+ grub_uint8_t reserved[8];
+} GRUB_PACKED;
+
+#ifdef GRUB_UTIL
+#include <grub/disk.h>
+
+grub_disk_addr_t
+grub_exfat_get_cluster_sector (grub_disk_t disk, grub_uint64_t *sec_per_lcn);
+#endif
+
+#endif
diff --git a/include/grub/extcmd.h b/include/grub/extcmd.h
new file mode 100644
index 0000000..fe9248b
--- /dev/null
+++ b/include/grub/extcmd.h
@@ -0,0 +1,86 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_EXTCMD_HEADER
+#define GRUB_EXTCMD_HEADER 1
+
+#include <grub/lib/arg.h>
+#include <grub/command.h>
+#include <grub/script_sh.h>
+
+struct grub_extcmd;
+struct grub_extcmd_context;
+
+typedef grub_err_t (*grub_extcmd_func_t) (struct grub_extcmd_context *ctxt,
+ int argc, char **args);
+
+/* The argcmd description. */
+struct grub_extcmd
+{
+ grub_command_t cmd;
+
+ grub_extcmd_func_t func;
+
+ /* The argument parser optionlist. */
+ const struct grub_arg_option *options;
+
+ void *data;
+};
+typedef struct grub_extcmd *grub_extcmd_t;
+
+/* Command context for each instance of execution. */
+struct grub_extcmd_context
+{
+ struct grub_extcmd *extcmd;
+
+ struct grub_arg_list *state;
+
+ /* Script parameter, if any. */
+ struct grub_script *script;
+};
+typedef struct grub_extcmd_context *grub_extcmd_context_t;
+
+grub_extcmd_t EXPORT_FUNC(grub_register_extcmd) (const char *name,
+ grub_extcmd_func_t func,
+ grub_command_flags_t flags,
+ const char *summary,
+ const char *description,
+ const struct grub_arg_option *parser);
+
+grub_extcmd_t EXPORT_FUNC(grub_register_extcmd_lockdown) (const char *name,
+ grub_extcmd_func_t func,
+ grub_command_flags_t flags,
+ const char *summary,
+ const char *description,
+ const struct grub_arg_option *parser);
+
+grub_extcmd_t EXPORT_FUNC(grub_register_extcmd_prio) (const char *name,
+ grub_extcmd_func_t func,
+ grub_command_flags_t flags,
+ const char *summary,
+ const char *description,
+ const struct grub_arg_option *parser,
+ int prio);
+
+void EXPORT_FUNC(grub_unregister_extcmd) (grub_extcmd_t cmd);
+
+grub_err_t EXPORT_FUNC(grub_extcmd_dispatcher) (struct grub_command *cmd,
+ int argc, char **args,
+ struct grub_script *script);
+
+#endif /* ! GRUB_EXTCMD_HEADER */
diff --git a/include/grub/fat.h b/include/grub/fat.h
new file mode 100644
index 0000000..8d7e4a1
--- /dev/null
+++ b/include/grub/fat.h
@@ -0,0 +1,77 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2000,2001,2002,2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_FAT_H
+#define GRUB_FAT_H 1
+
+#include <grub/types.h>
+
+struct grub_fat_bpb
+{
+ grub_uint8_t jmp_boot[3];
+ grub_uint8_t oem_name[8];
+ grub_uint16_t bytes_per_sector;
+ grub_uint8_t sectors_per_cluster;
+ grub_uint16_t num_reserved_sectors;
+ grub_uint8_t num_fats; /* 0x10 */
+ grub_uint16_t num_root_entries;
+ grub_uint16_t num_total_sectors_16;
+ grub_uint8_t media; /* 0x15 */
+ grub_uint16_t sectors_per_fat_16;
+ grub_uint16_t sectors_per_track; /* 0x18 */
+ grub_uint16_t num_heads; /* 0x1A */
+ grub_uint32_t num_hidden_sectors; /* 0x1C */
+ grub_uint32_t num_total_sectors_32; /* 0x20 */
+ union
+ {
+ struct
+ {
+ grub_uint8_t num_ph_drive;
+ grub_uint8_t reserved;
+ grub_uint8_t boot_sig;
+ grub_uint32_t num_serial;
+ grub_uint8_t label[11];
+ grub_uint8_t fstype[8];
+ } GRUB_PACKED fat12_or_fat16;
+ struct
+ {
+ grub_uint32_t sectors_per_fat_32;
+ grub_uint16_t extended_flags;
+ grub_uint16_t fs_version;
+ grub_uint32_t root_cluster;
+ grub_uint16_t fs_info;
+ grub_uint16_t backup_boot_sector;
+ grub_uint8_t reserved[12];
+ grub_uint8_t num_ph_drive;
+ grub_uint8_t reserved1;
+ grub_uint8_t boot_sig;
+ grub_uint32_t num_serial;
+ grub_uint8_t label[11];
+ grub_uint8_t fstype[8];
+ } GRUB_PACKED fat32;
+ } GRUB_PACKED version_specific;
+} GRUB_PACKED;
+
+#ifdef GRUB_UTIL
+#include <grub/disk.h>
+
+grub_disk_addr_t
+grub_fat_get_cluster_sector (grub_disk_t disk, grub_uint64_t *sec_per_lcn);
+#endif
+
+#endif
diff --git a/include/grub/fbblit.h b/include/grub/fbblit.h
new file mode 100644
index 0000000..66d1005
--- /dev/null
+++ b/include/grub/fbblit.h
@@ -0,0 +1,36 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2006,2007,2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_FBBLIT_HEADER
+#define GRUB_FBBLIT_HEADER 1
+
+/* NOTE: This header is private header for fb driver and should not be used
+ in other parts of the code. */
+
+struct grub_video_fbblit_info;
+
+/* NOTE: This function assumes that given coordinates are within bounds of
+ handled data. */
+void
+grub_video_fb_dispatch_blit (struct grub_video_fbblit_info *target,
+ struct grub_video_fbblit_info *source,
+ enum grub_video_blit_operators oper,
+ int x, int y,
+ unsigned int width, unsigned int height,
+ int offset_x, int offset_y);
+#endif /* ! GRUB_FBBLIT_HEADER */
diff --git a/include/grub/fbfill.h b/include/grub/fbfill.h
new file mode 100644
index 0000000..35a80b8
--- /dev/null
+++ b/include/grub/fbfill.h
@@ -0,0 +1,59 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2006,2007,2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_FBFILL_HEADER
+#define GRUB_FBFILL_HEADER 1
+
+/* NOTE: This header is private header for fb driver and should not be used
+ in other parts of the code. */
+
+struct grub_video_fbblit_info;
+
+struct grub_video_fbrender_target
+{
+ /* Copy of the screen's mode info structure, except that width, height and
+ mode_type has been re-adjusted to requested render target settings. */
+ struct grub_video_mode_info mode_info;
+
+ /* We should not draw outside of viewport. */
+ grub_video_rect_t viewport;
+ /* Set region to make a re-draw of a part of the screen. */
+ grub_video_rect_t region;
+ /* Should be set to 0 if the viewport is inside of the region. */
+ int area_enabled;
+ /* Internal structure - intersection of the viewport and the region. */
+ grub_video_rect_t area;
+ /* Internal values - offsets from the left top point of the viewport. */
+ int area_offset_x;
+ int area_offset_y;
+
+ /* Indicates whether the data has been allocated by us and must be freed
+ when render target is destroyed. */
+ int is_allocated;
+
+ /* Pointer to data. Can either be in video card memory or in local host's
+ memory. */
+ grub_uint8_t *data;
+};
+
+void
+grub_video_fb_fill_dispatch (struct grub_video_fbblit_info *target,
+ grub_video_color_t color, int x, int y,
+ unsigned int width, unsigned int height);
+
+#endif /* ! GRUB_FBFILL_HEADER */
diff --git a/include/grub/fbutil.h b/include/grub/fbutil.h
new file mode 100644
index 0000000..4205eb9
--- /dev/null
+++ b/include/grub/fbutil.h
@@ -0,0 +1,59 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2006,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* NOTE: This header is private header for vbe driver and should not be used
+ in other parts of the code. */
+
+#ifndef GRUB_VBEUTIL_MACHINE_HEADER
+#define GRUB_VBEUTIL_MACHINE_HEADER 1
+
+#include <grub/types.h>
+#include <grub/video.h>
+
+struct grub_video_fbblit_info
+{
+ struct grub_video_mode_info *mode_info;
+ grub_uint8_t *data;
+};
+
+/* Don't use for 1-bit bitmaps, addressing needs to be done at the bit level
+ and it doesn't make sense, in general, to ask for a pointer
+ to a particular pixel's data. */
+static inline void *
+grub_video_fb_get_video_ptr (struct grub_video_fbblit_info *source,
+ unsigned int x, unsigned int y)
+{
+ return source->data + y * source->mode_info->pitch + x * source->mode_info->bytes_per_pixel;
+}
+
+/* Advance pointer by VAL bytes. If there is no unaligned access available,
+ VAL has to be divisible by size of pointed type.
+ */
+#ifdef GRUB_HAVE_UNALIGNED_ACCESS
+#define GRUB_VIDEO_FB_ADVANCE_POINTER(ptr, val) ((ptr) = (typeof (ptr)) ((char *) ptr + val))
+#else
+#define GRUB_VIDEO_FB_ADVANCE_POINTER(ptr, val) ((ptr) += (val) / sizeof (*(ptr)))
+#endif
+
+grub_video_color_t get_pixel (struct grub_video_fbblit_info *source,
+ unsigned int x, unsigned int y);
+
+void set_pixel (struct grub_video_fbblit_info *source,
+ unsigned int x, unsigned int y, grub_video_color_t color);
+
+#endif /* ! GRUB_VBEUTIL_MACHINE_HEADER */
diff --git a/include/grub/fdt.h b/include/grub/fdt.h
new file mode 100644
index 0000000..e609c7e
--- /dev/null
+++ b/include/grub/fdt.h
@@ -0,0 +1,147 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_FDT_HEADER
+#define GRUB_FDT_HEADER 1
+
+#include <grub/types.h>
+#include <grub/symbol.h>
+
+/* Space required when preparing the /chosen node after boot has been called. */
+#define GRUB_EFI_LINUX_FDT_EXTRA_SPACE 0x400
+
+#define FDT_MAGIC 0xD00DFEED
+
+typedef struct {
+ grub_uint32_t magic;
+ grub_uint32_t totalsize;
+ grub_uint32_t off_dt_struct;
+ grub_uint32_t off_dt_strings;
+ grub_uint32_t off_mem_rsvmap;
+ grub_uint32_t version;
+ grub_uint32_t last_comp_version;
+ grub_uint32_t boot_cpuid_phys;
+ grub_uint32_t size_dt_strings;
+ grub_uint32_t size_dt_struct;
+} grub_fdt_header_t;
+
+struct grub_fdt_empty_tree {
+ grub_fdt_header_t header;
+ grub_uint64_t empty_rsvmap[2];
+ struct {
+ grub_uint32_t node_start;
+ grub_uint8_t name[1];
+ grub_uint32_t node_end;
+ grub_uint32_t tree_end;
+ } empty_node;
+};
+
+#define GRUB_FDT_EMPTY_TREE_SZ sizeof (struct grub_fdt_empty_tree)
+
+/* Size needed by a property entry: 1 token (FDT_PROPERTY), plus len and nameoff
+ fields, plus the property value, plus padding if needed. */
+#define grub_fdt_prop_entry_size(prop_len) \
+ (3 * sizeof(grub_uint32_t) + ALIGN_UP(prop_len, sizeof(grub_uint32_t)))
+
+#define grub_fdt_get_header(fdt, field) \
+ grub_be_to_cpu32(((const grub_fdt_header_t *)(fdt))->field)
+#define grub_fdt_set_header(fdt, field, value) \
+ ((grub_fdt_header_t *)(fdt))->field = grub_cpu_to_be32(value)
+
+#define grub_fdt_get_magic(fdt) \
+ grub_fdt_get_header(fdt, magic)
+#define grub_fdt_set_magic(fdt, value) \
+ grub_fdt_set_header(fdt, magic, value)
+#define grub_fdt_get_totalsize(fdt) \
+ grub_fdt_get_header(fdt, totalsize)
+#define grub_fdt_set_totalsize(fdt, value) \
+ grub_fdt_set_header(fdt, totalsize, value)
+#define grub_fdt_get_off_dt_struct(fdt) \
+ grub_fdt_get_header(fdt, off_dt_struct)
+#define grub_fdt_set_off_dt_struct(fdt, value) \
+ grub_fdt_set_header(fdt, off_dt_struct, value)
+#define grub_fdt_get_off_dt_strings(fdt) \
+ grub_fdt_get_header(fdt, off_dt_strings)
+#define grub_fdt_set_off_dt_strings(fdt, value) \
+ grub_fdt_set_header(fdt, off_dt_strings, value)
+#define grub_fdt_get_off_mem_rsvmap(fdt) \
+ grub_fdt_get_header(fdt, off_mem_rsvmap)
+#define grub_fdt_set_off_mem_rsvmap(fdt, value) \
+ grub_fdt_set_header(fdt, off_mem_rsvmap, value)
+#define grub_fdt_get_version(fdt) \
+ grub_fdt_get_header(fdt, version)
+#define grub_fdt_set_version(fdt, value) \
+ grub_fdt_set_header(fdt, version, value)
+#define grub_fdt_get_last_comp_version(fdt) \
+ grub_fdt_get_header(fdt, last_comp_version)
+#define grub_fdt_set_last_comp_version(fdt, value) \
+ grub_fdt_set_header(fdt, last_comp_version, value)
+#define grub_fdt_get_boot_cpuid_phys(fdt) \
+ grub_fdt_get_header(fdt, boot_cpuid_phys)
+#define grub_fdt_set_boot_cpuid_phys(fdt, value) \
+ grub_fdt_set_header(fdt, boot_cpuid_phys, value)
+#define grub_fdt_get_size_dt_strings(fdt) \
+ grub_fdt_get_header(fdt, size_dt_strings)
+#define grub_fdt_set_size_dt_strings(fdt, value) \
+ grub_fdt_set_header(fdt, size_dt_strings, value)
+#define grub_fdt_get_size_dt_struct(fdt) \
+ grub_fdt_get_header(fdt, size_dt_struct)
+#define grub_fdt_set_size_dt_struct(fdt, value) \
+ grub_fdt_set_header(fdt, size_dt_struct, value)
+
+int EXPORT_FUNC(grub_fdt_create_empty_tree) (void *fdt, unsigned int size);
+int EXPORT_FUNC(grub_fdt_check_header) (const void *fdt, unsigned int size);
+int EXPORT_FUNC(grub_fdt_check_header_nosize) (const void *fdt);
+int EXPORT_FUNC(grub_fdt_find_subnode) (const void *fdt, unsigned int parentoffset,
+ const char *name);
+int EXPORT_FUNC(grub_fdt_first_node) (const void *fdt, unsigned int parentoffset);
+int EXPORT_FUNC(grub_fdt_next_node) (const void *fdt, unsigned int currentoffset);
+int EXPORT_FUNC(grub_fdt_add_subnode) (void *fdt, unsigned int parentoffset,
+ const char *name);
+const char *
+EXPORT_FUNC(grub_fdt_get_nodename) (const void *fdt, unsigned int nodeoffset);
+const void *EXPORT_FUNC(grub_fdt_get_prop) (const void *fdt, unsigned int nodeoffset, const char *name,
+ grub_uint32_t *len);
+
+int EXPORT_FUNC(grub_fdt_set_prop) (void *fdt, unsigned int nodeoffset, const char *name,
+ const void *val, grub_uint32_t len);
+#define grub_fdt_set_prop32(fdt, nodeoffset, name, val) \
+({ \
+ grub_uint32_t _val = grub_cpu_to_be32(val); \
+ grub_fdt_set_prop ((fdt), (nodeoffset), (name), &_val, 4); \
+})
+
+#define grub_fdt_set_prop64(fdt, nodeoffset, name, val) \
+({ \
+ grub_uint64_t _val = grub_cpu_to_be64(val); \
+ grub_fdt_set_prop ((fdt), (nodeoffset), (name), &_val, 8); \
+})
+
+/* Setup "reg" property for
+ * #address-cells = <0x2>
+ * #size-cells = <0x2>
+ */
+#define grub_fdt_set_reg64(fdt, nodeoffset, addr, size) \
+({ \
+ grub_uint64_t reg_64[2]; \
+ reg_64[0] = grub_cpu_to_be64(addr); \
+ reg_64[1] = grub_cpu_to_be64(size); \
+ grub_fdt_set_prop ((fdt), (nodeoffset), "reg", reg_64, 16); \
+})
+
+#endif /* ! GRUB_FDT_HEADER */
diff --git a/include/grub/fdtbus.h b/include/grub/fdtbus.h
new file mode 100644
index 0000000..f519c40
--- /dev/null
+++ b/include/grub/fdtbus.h
@@ -0,0 +1,89 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2016 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_FDTBUS_HEADER
+#define GRUB_FDTBUS_HEADER 1
+
+#include <grub/fdt.h>
+#include <grub/err.h>
+
+struct grub_fdtbus_dev
+{
+ struct grub_fdtbus_dev *next;
+ struct grub_fdtbus_dev *parent;
+ int node;
+ struct grub_fdtbus_driver *driver;
+};
+
+struct grub_fdtbus_driver
+{
+ struct grub_fdtbus_driver *next;
+ struct grub_fdtbus_driver **prev;
+
+ const char *compatible;
+
+ grub_err_t (*attach) (const struct grub_fdtbus_dev *dev);
+ void (*detach) (const struct grub_fdtbus_dev *dev);
+
+ /* Message bus operations. */
+ grub_err_t (*send) (const struct grub_fdtbus_dev *dev, const void *data, grub_size_t sz);
+ grub_err_t (*receive) (const struct grub_fdtbus_dev *dev, void *data, grub_size_t sz);
+ grub_err_t (*start) (const struct grub_fdtbus_dev *dev);
+ void (*stop) (const struct grub_fdtbus_dev *dev);
+};
+
+extern char EXPORT_VAR(grub_fdtbus_invalid_mapping)[1];
+
+static inline int
+grub_fdtbus_is_mapping_valid (volatile void *m)
+{
+ return m != grub_fdtbus_invalid_mapping;
+}
+
+volatile void *
+EXPORT_FUNC(grub_fdtbus_map_reg) (const struct grub_fdtbus_dev *dev, int reg, grub_size_t *size);
+
+const void *
+EXPORT_FUNC(grub_fdtbus_get_fdt) (void);
+
+const char *
+EXPORT_FUNC(grub_fdtbus_get_name) (const struct grub_fdtbus_dev *dev);
+
+const void *
+EXPORT_FUNC(grub_fdtbus_get_prop) (const struct grub_fdtbus_dev *dev,
+ const char *name,
+ grub_uint32_t *len);
+
+void
+EXPORT_FUNC(grub_fdtbus_register) (struct grub_fdtbus_driver *driver);
+
+void
+EXPORT_FUNC(grub_fdtbus_unregister) (struct grub_fdtbus_driver *driver);
+
+int
+EXPORT_FUNC(grub_fdtbus_is_compatible) (const char *compat_string,
+ const struct grub_fdtbus_dev *dev);
+
+/* Must be called before any register(). */
+/* dtb is assumed to be unfreeable and must remain
+ valid for lifetime of GRUB.
+ */
+void
+grub_fdtbus_init (const void *dtb, grub_size_t size);
+
+#endif
diff --git a/include/grub/file.h b/include/grub/file.h
new file mode 100644
index 0000000..3156748
--- /dev/null
+++ b/include/grub/file.h
@@ -0,0 +1,242 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_FILE_HEADER
+#define GRUB_FILE_HEADER 1
+
+#include <grub/types.h>
+#include <grub/err.h>
+#include <grub/device.h>
+#include <grub/fs.h>
+#include <grub/disk.h>
+
+enum grub_file_type
+ {
+ GRUB_FILE_TYPE_NONE = 0,
+ /* GRUB module to be loaded. */
+ GRUB_FILE_TYPE_GRUB_MODULE,
+ /* Loopback file to be represented as disk. */
+ GRUB_FILE_TYPE_LOOPBACK,
+ /* Linux kernel to be loaded. */
+ GRUB_FILE_TYPE_LINUX_KERNEL,
+ /* Linux initrd. */
+ GRUB_FILE_TYPE_LINUX_INITRD,
+
+ /* Multiboot kernel. */
+ GRUB_FILE_TYPE_MULTIBOOT_KERNEL,
+ /* Multiboot module. */
+ GRUB_FILE_TYPE_MULTIBOOT_MODULE,
+
+ /* Xen hypervisor - used on ARM only. */
+ GRUB_FILE_TYPE_XEN_HYPERVISOR,
+ /* Xen module - used on ARM only. */
+ GRUB_FILE_TYPE_XEN_MODULE,
+
+ GRUB_FILE_TYPE_BSD_KERNEL,
+ GRUB_FILE_TYPE_FREEBSD_ENV,
+ GRUB_FILE_TYPE_FREEBSD_MODULE,
+ GRUB_FILE_TYPE_FREEBSD_MODULE_ELF,
+ GRUB_FILE_TYPE_NETBSD_MODULE,
+ GRUB_FILE_TYPE_OPENBSD_RAMDISK,
+
+ GRUB_FILE_TYPE_XNU_INFO_PLIST,
+ GRUB_FILE_TYPE_XNU_MKEXT,
+ GRUB_FILE_TYPE_XNU_KEXT,
+ GRUB_FILE_TYPE_XNU_KERNEL,
+ GRUB_FILE_TYPE_XNU_RAMDISK,
+ GRUB_FILE_TYPE_XNU_HIBERNATE_IMAGE,
+ GRUB_FILE_XNU_DEVPROP,
+
+ GRUB_FILE_TYPE_PLAN9_KERNEL,
+
+ GRUB_FILE_TYPE_NTLDR,
+ GRUB_FILE_TYPE_TRUECRYPT,
+ GRUB_FILE_TYPE_FREEDOS,
+ GRUB_FILE_TYPE_PXECHAINLOADER,
+ GRUB_FILE_TYPE_PCCHAINLOADER,
+
+ GRUB_FILE_TYPE_COREBOOT_CHAINLOADER,
+
+ GRUB_FILE_TYPE_EFI_CHAINLOADED_IMAGE,
+
+ /* File holding signature. */
+ GRUB_FILE_TYPE_SIGNATURE,
+ /* File holding public key to verify signature once. */
+ GRUB_FILE_TYPE_PUBLIC_KEY,
+ /* File holding public key to add to trused keys. */
+ GRUB_FILE_TYPE_PUBLIC_KEY_TRUST,
+ /* File of which we intend to print a blocklist to the user. */
+ GRUB_FILE_TYPE_PRINT_BLOCKLIST,
+ /* File we intend to use for test loading or testing speed. */
+ GRUB_FILE_TYPE_TESTLOAD,
+ /* File we open only to get its size. E.g. in ls output. */
+ GRUB_FILE_TYPE_GET_SIZE,
+ /* Font file. */
+ GRUB_FILE_TYPE_FONT,
+ /* File holding encryption key for encrypted ZFS. */
+ GRUB_FILE_TYPE_ZFS_ENCRYPTION_KEY,
+ /* File we open n grub-fstest. */
+ GRUB_FILE_TYPE_FSTEST,
+ /* File we open n grub-mount. */
+ GRUB_FILE_TYPE_MOUNT,
+ /* File which we attempt to identify the type of. */
+ GRUB_FILE_TYPE_FILE_ID,
+ /* File holding ACPI table. */
+ GRUB_FILE_TYPE_ACPI_TABLE,
+ /* File holding Device Tree. */
+ GRUB_FILE_TYPE_DEVICE_TREE_IMAGE,
+ /* File we intend show to user. */
+ GRUB_FILE_TYPE_CAT,
+ GRUB_FILE_TYPE_HEXCAT,
+ /* One of pair of files we intend to compare. */
+ GRUB_FILE_TYPE_CMP,
+ /* List of hashes for hashsum. */
+ GRUB_FILE_TYPE_HASHLIST,
+ /* File hashed by hashsum. */
+ GRUB_FILE_TYPE_TO_HASH,
+ /* Keyboard layout. */
+ GRUB_FILE_TYPE_KEYBOARD_LAYOUT,
+ /* Picture file. */
+ GRUB_FILE_TYPE_PIXMAP,
+ /* *.lst shipped by GRUB. */
+ GRUB_FILE_TYPE_GRUB_MODULE_LIST,
+ /* config file. */
+ GRUB_FILE_TYPE_CONFIG,
+ GRUB_FILE_TYPE_THEME,
+ GRUB_FILE_TYPE_GETTEXT_CATALOG,
+ GRUB_FILE_TYPE_FS_SEARCH,
+ GRUB_FILE_TYPE_AUDIO,
+ GRUB_FILE_TYPE_VBE_DUMP,
+
+ GRUB_FILE_TYPE_LOADENV,
+ GRUB_FILE_TYPE_SAVEENV,
+
+ GRUB_FILE_TYPE_VERIFY_SIGNATURE,
+
+ GRUB_FILE_TYPE_MASK = 0xffff,
+
+ /* --skip-sig is specified. */
+ GRUB_FILE_TYPE_SKIP_SIGNATURE = 0x10000,
+ GRUB_FILE_TYPE_NO_DECOMPRESS = 0x20000
+ };
+
+/* File description. */
+struct grub_file
+{
+ /* File name. */
+ char *name;
+
+ /* The underlying device. */
+ grub_device_t device;
+
+ /* The underlying filesystem. */
+ grub_fs_t fs;
+
+ /* The current offset. */
+ grub_off_t offset;
+ grub_off_t progress_offset;
+
+ /* Progress info. */
+ grub_uint64_t last_progress_time;
+ grub_off_t last_progress_offset;
+ grub_uint64_t estimated_speed;
+
+ /* The file size. */
+ grub_off_t size;
+
+ /* If file is not easily seekable. Should be set by underlying layer. */
+ int not_easily_seekable;
+
+ /* Filesystem-specific data. */
+ void *data;
+
+ /* This is called when a sector is read. Used only for a disk device. */
+ grub_disk_read_hook_t read_hook;
+
+ /* Caller-specific data passed to the read hook. */
+ void *read_hook_data;
+};
+typedef struct grub_file *grub_file_t;
+
+extern grub_disk_read_hook_t EXPORT_VAR(grub_file_progress_hook);
+
+/* Filters with lower ID are executed first. */
+typedef enum grub_file_filter_id
+ {
+ GRUB_FILE_FILTER_VERIFY,
+ GRUB_FILE_FILTER_GZIO,
+ GRUB_FILE_FILTER_XZIO,
+ GRUB_FILE_FILTER_LZOPIO,
+ GRUB_FILE_FILTER_MAX,
+ GRUB_FILE_FILTER_COMPRESSION_FIRST = GRUB_FILE_FILTER_GZIO,
+ GRUB_FILE_FILTER_COMPRESSION_LAST = GRUB_FILE_FILTER_LZOPIO,
+ } grub_file_filter_id_t;
+
+typedef grub_file_t (*grub_file_filter_t) (grub_file_t in, enum grub_file_type type);
+
+extern grub_file_filter_t EXPORT_VAR(grub_file_filters)[GRUB_FILE_FILTER_MAX];
+
+static inline void
+grub_file_filter_register (grub_file_filter_id_t id, grub_file_filter_t filter)
+{
+ grub_file_filters[id] = filter;
+}
+
+static inline void
+grub_file_filter_unregister (grub_file_filter_id_t id)
+{
+ grub_file_filters[id] = 0;
+}
+
+/* Get a device name from NAME. */
+char *EXPORT_FUNC(grub_file_get_device_name) (const char *name);
+
+grub_file_t EXPORT_FUNC(grub_file_open) (const char *name, enum grub_file_type type);
+grub_ssize_t EXPORT_FUNC(grub_file_read) (grub_file_t file, void *buf,
+ grub_size_t len);
+grub_off_t EXPORT_FUNC(grub_file_seek) (grub_file_t file, grub_off_t offset);
+grub_err_t EXPORT_FUNC(grub_file_close) (grub_file_t file);
+
+/* Return value of grub_file_size() in case file size is unknown. */
+#define GRUB_FILE_SIZE_UNKNOWN 0xffffffffffffffffULL
+
+static inline grub_off_t
+grub_file_size (const grub_file_t file)
+{
+ return file->size;
+}
+
+static inline grub_off_t
+grub_file_tell (const grub_file_t file)
+{
+ return file->offset;
+}
+
+static inline int
+grub_file_seekable (const grub_file_t file)
+{
+ return !file->not_easily_seekable;
+}
+
+grub_file_t
+grub_file_offset_open (grub_file_t parent, enum grub_file_type type,
+ grub_off_t start, grub_off_t size);
+void
+grub_file_offset_close (grub_file_t file);
+
+#endif /* ! GRUB_FILE_HEADER */
diff --git a/include/grub/fileid.h b/include/grub/fileid.h
new file mode 100644
index 0000000..ae75b69
--- /dev/null
+++ b/include/grub/fileid.h
@@ -0,0 +1,29 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_FILEID_HEADER
+#define GRUB_FILEID_HEADER 1
+
+#include <grub/elfload.h>
+
+int
+grub_file_check_netbsd32 (grub_elf_t elf);
+int
+grub_file_check_netbsd64 (grub_elf_t elf);
+
+#endif
diff --git a/include/grub/font.h b/include/grub/font.h
new file mode 100644
index 0000000..708fa42
--- /dev/null
+++ b/include/grub/font.h
@@ -0,0 +1,153 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2003,2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_FONT_HEADER
+#define GRUB_FONT_HEADER 1
+
+#include <grub/types.h>
+#include <grub/video.h>
+#include <grub/file.h>
+#include <grub/unicode.h>
+
+/* Forward declaration of opaque structure grub_font.
+ Users only pass struct grub_font pointers to the font module functions,
+ and do not have knowledge of the structure contents. */
+/* Full structure was moved here for inline function but still
+ shouldn't be used directly.
+ */
+struct grub_font
+{
+ char *name;
+ grub_file_t file;
+ char *family;
+ short point_size;
+ short weight;
+ short max_char_width;
+ short max_char_height;
+ short ascent;
+ short descent;
+ short leading;
+ grub_uint32_t num_chars;
+ struct char_index_entry *char_index;
+ grub_uint16_t *bmp_idx;
+};
+
+/* Font type used to access font functions. */
+typedef struct grub_font *grub_font_t;
+
+struct grub_font_node
+{
+ struct grub_font_node *next;
+ grub_font_t value;
+};
+
+/* Global font registry. */
+extern struct grub_font_node *grub_font_list;
+
+struct grub_font_glyph
+{
+ /* Reference to the font this glyph belongs to. */
+ grub_font_t font;
+
+ /* Glyph bitmap width in pixels. */
+ grub_uint16_t width;
+
+ /* Glyph bitmap height in pixels. */
+ grub_uint16_t height;
+
+ /* Glyph bitmap x offset in pixels. Add to screen coordinate. */
+ grub_int16_t offset_x;
+
+ /* Glyph bitmap y offset in pixels. Subtract from screen coordinate. */
+ grub_int16_t offset_y;
+
+ /* Number of pixels to advance to start the next character. */
+ grub_uint16_t device_width;
+
+ /* Row-major order, packed bits (no padding; rows can break within a byte).
+ The length of the array is (width * height + 7) / 8. Within a
+ byte, the most significant bit is the first (leftmost/uppermost) pixel.
+ Pixels are coded as bits, value 1 meaning of opaque pixel and 0 is
+ transparent. If the length of the array does not fit byte boundary, it
+ will be padded with 0 bits to make it fit. */
+ grub_uint8_t bitmap[0];
+};
+
+/* Part of code field which is really used as such. */
+#define GRUB_FONT_CODE_CHAR_MASK 0x001fffff
+#define GRUB_FONT_CODE_RIGHT_JOINED 0x80000000
+#define GRUB_FONT_CODE_LEFT_JOINED 0x40000000
+
+/* Initialize the font loader.
+ Must be called before any fonts are loaded or used. */
+void grub_font_loader_init (void);
+
+/* Load a font and add it to the beginning of the global font list.
+ Returns: 0 upon success; nonzero upon failure. */
+grub_font_t EXPORT_FUNC(grub_font_load) (const char *filename);
+
+/* Get the font that has the specified name. Font names are in the form
+ "Family Name Bold Italic 14", where Bold and Italic are optional.
+ If no font matches the name specified, the most recently loaded font
+ is returned as a fallback. */
+grub_font_t EXPORT_FUNC (grub_font_get) (const char *font_name);
+
+const char *EXPORT_FUNC (grub_font_get_name) (grub_font_t font);
+
+int EXPORT_FUNC (grub_font_get_max_char_width) (grub_font_t font);
+
+/* Get the maximum height of any character in the font in pixels. */
+static inline int
+grub_font_get_max_char_height (grub_font_t font)
+{
+ return font->max_char_height;
+}
+
+/* Get the distance in pixels from the top of characters to the baseline. */
+static inline int
+grub_font_get_ascent (grub_font_t font)
+{
+ return font->ascent;
+}
+
+int EXPORT_FUNC (grub_font_get_descent) (grub_font_t font);
+
+int EXPORT_FUNC (grub_font_get_leading) (grub_font_t font);
+
+int EXPORT_FUNC (grub_font_get_height) (grub_font_t font);
+
+int EXPORT_FUNC (grub_font_get_xheight) (grub_font_t font);
+
+struct grub_font_glyph *EXPORT_FUNC (grub_font_get_glyph) (grub_font_t font,
+ grub_uint32_t code);
+
+struct grub_font_glyph *EXPORT_FUNC (grub_font_get_glyph_with_fallback) (grub_font_t font,
+ grub_uint32_t code);
+
+grub_err_t EXPORT_FUNC (grub_font_draw_glyph) (struct grub_font_glyph *glyph,
+ grub_video_color_t color,
+ int left_x, int baseline_y);
+
+int
+EXPORT_FUNC (grub_font_get_constructed_device_width) (grub_font_t hinted_font,
+ const struct grub_unicode_glyph *glyph_id);
+struct grub_font_glyph *
+EXPORT_FUNC (grub_font_construct_glyph) (grub_font_t hinted_font,
+ const struct grub_unicode_glyph *glyph_id);
+
+#endif /* ! GRUB_FONT_HEADER */
diff --git a/include/grub/fontformat.h b/include/grub/fontformat.h
new file mode 100644
index 0000000..b506058
--- /dev/null
+++ b/include/grub/fontformat.h
@@ -0,0 +1,38 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_FONT_FORMAT_HEADER
+#define GRUB_FONT_FORMAT_HEADER 1
+
+/* FONT_FORMAT_PFF2_MAGIC use only 4 relevants bytes and the \0. */
+#define FONT_FORMAT_PFF2_MAGIC "PFF2"
+#define FONT_FORMAT_SECTION_NAMES_FILE "FILE"
+#define FONT_FORMAT_SECTION_NAMES_FONT_NAME "NAME"
+#define FONT_FORMAT_SECTION_NAMES_POINT_SIZE "PTSZ"
+#define FONT_FORMAT_SECTION_NAMES_WEIGHT "WEIG"
+#define FONT_FORMAT_SECTION_NAMES_MAX_CHAR_WIDTH "MAXW"
+#define FONT_FORMAT_SECTION_NAMES_MAX_CHAR_HEIGHT "MAXH"
+#define FONT_FORMAT_SECTION_NAMES_ASCENT "ASCE"
+#define FONT_FORMAT_SECTION_NAMES_DESCENT "DESC"
+#define FONT_FORMAT_SECTION_NAMES_CHAR_INDEX "CHIX"
+#define FONT_FORMAT_SECTION_NAMES_DATA "DATA"
+#define FONT_FORMAT_SECTION_NAMES_FAMILY "FAMI"
+#define FONT_FORMAT_SECTION_NAMES_SLAN "SLAN"
+
+#endif /* ! GRUB_FONT_FORMAT_HEADER */
+
diff --git a/include/grub/fs.h b/include/grub/fs.h
new file mode 100644
index 0000000..026bc3b
--- /dev/null
+++ b/include/grub/fs.h
@@ -0,0 +1,131 @@
+/* fs.h - filesystem manager */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2003,2004,2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_FS_HEADER
+#define GRUB_FS_HEADER 1
+
+#include <grub/device.h>
+#include <grub/symbol.h>
+#include <grub/types.h>
+
+#include <grub/list.h>
+/* For embedding types. */
+#ifdef GRUB_UTIL
+#include <grub/partition.h>
+#endif
+
+/* Forward declaration is required, because of mutual reference. */
+struct grub_file;
+
+struct grub_dirhook_info
+{
+ unsigned dir:1;
+ unsigned mtimeset:1;
+ unsigned case_insensitive:1;
+ unsigned inodeset:1;
+ grub_int64_t mtime;
+ grub_uint64_t inode;
+};
+
+typedef int (*grub_fs_dir_hook_t) (const char *filename,
+ const struct grub_dirhook_info *info,
+ void *data);
+
+/* Filesystem descriptor. */
+struct grub_fs
+{
+ /* The next filesystem. */
+ struct grub_fs *next;
+ struct grub_fs **prev;
+
+ /* My name. */
+ const char *name;
+
+ /* Call HOOK with each file under DIR. */
+ grub_err_t (*fs_dir) (grub_device_t device, const char *path,
+ grub_fs_dir_hook_t hook, void *hook_data);
+
+ /* Open a file named NAME and initialize FILE. */
+ grub_err_t (*fs_open) (struct grub_file *file, const char *name);
+
+ /* Read LEN bytes data from FILE into BUF. */
+ grub_ssize_t (*fs_read) (struct grub_file *file, char *buf, grub_size_t len);
+
+ /* Close the file FILE. */
+ grub_err_t (*fs_close) (struct grub_file *file);
+
+ /* Return the label of the device DEVICE in LABEL. The label is
+ returned in a grub_malloc'ed buffer and should be freed by the
+ caller. */
+ grub_err_t (*fs_label) (grub_device_t device, char **label);
+
+ /* Return the uuid of the device DEVICE in UUID. The uuid is
+ returned in a grub_malloc'ed buffer and should be freed by the
+ caller. */
+ grub_err_t (*fs_uuid) (grub_device_t device, char **uuid);
+
+ /* Get writing time of filesystem. */
+ grub_err_t (*fs_mtime) (grub_device_t device, grub_int64_t *timebuf);
+
+#ifdef GRUB_UTIL
+ /* Determine sectors available for embedding. */
+ grub_err_t (*fs_embed) (grub_device_t device, unsigned int *nsectors,
+ unsigned int max_nsectors,
+ grub_embed_type_t embed_type,
+ grub_disk_addr_t **sectors);
+
+ /* Whether this filesystem reserves first sector for DOS-style boot. */
+ int reserved_first_sector;
+
+ /* Whether blocklist installs have a chance to work. */
+ int blocklist_install;
+#endif
+};
+typedef struct grub_fs *grub_fs_t;
+
+/* This is special, because block lists are not files in usual sense. */
+extern struct grub_fs grub_fs_blocklist;
+
+/* This hook is used to automatically load filesystem modules.
+ If this hook loads a module, return non-zero. Otherwise return zero.
+ The newly loaded filesystem is assumed to be inserted into the head of
+ the linked list GRUB_FS_LIST through the function grub_fs_register. */
+typedef int (*grub_fs_autoload_hook_t) (void);
+extern grub_fs_autoload_hook_t EXPORT_VAR(grub_fs_autoload_hook);
+extern grub_fs_t EXPORT_VAR (grub_fs_list);
+
+#ifndef GRUB_LST_GENERATOR
+static inline void
+grub_fs_register (grub_fs_t fs)
+{
+ grub_list_push (GRUB_AS_LIST_P (&grub_fs_list), GRUB_AS_LIST (fs));
+}
+#endif
+
+static inline void
+grub_fs_unregister (grub_fs_t fs)
+{
+ grub_list_remove (GRUB_AS_LIST (fs));
+}
+
+#define FOR_FILESYSTEMS(var) FOR_LIST_ELEMENTS((var), (grub_fs_list))
+
+grub_fs_t EXPORT_FUNC(grub_fs_probe) (grub_device_t device);
+
+#endif /* ! GRUB_FS_HEADER */
diff --git a/include/grub/fshelp.h b/include/grub/fshelp.h
new file mode 100644
index 0000000..eb1ba4f
--- /dev/null
+++ b/include/grub/fshelp.h
@@ -0,0 +1,91 @@
+/* fshelp.h -- Filesystem helper functions */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2004,2005,2006,2007,2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_FSHELP_HEADER
+#define GRUB_FSHELP_HEADER 1
+
+#include <grub/types.h>
+#include <grub/symbol.h>
+#include <grub/err.h>
+#include <grub/disk.h>
+
+typedef struct grub_fshelp_node *grub_fshelp_node_t;
+
+#define GRUB_FSHELP_CASE_INSENSITIVE 0x100
+#define GRUB_FSHELP_TYPE_MASK 0xff
+#define GRUB_FSHELP_FLAGS_MASK 0x100
+
+enum grub_fshelp_filetype
+ {
+ GRUB_FSHELP_UNKNOWN,
+ GRUB_FSHELP_REG,
+ GRUB_FSHELP_DIR,
+ GRUB_FSHELP_SYMLINK
+ };
+
+typedef int (*grub_fshelp_iterate_dir_hook_t) (const char *filename,
+ enum grub_fshelp_filetype filetype,
+ grub_fshelp_node_t node,
+ void *data);
+
+/* Lookup the node PATH. The node ROOTNODE describes the root of the
+ directory tree. The node found is returned in FOUNDNODE, which is
+ either a ROOTNODE or a new malloc'ed node. ITERATE_DIR is used to
+ iterate over all directory entries in the current node.
+ READ_SYMLINK is used to read the symlink if a node is a symlink.
+ EXPECTTYPE is the type node that is expected by the called, an
+ error is generated if the node is not of the expected type. */
+grub_err_t
+EXPORT_FUNC(grub_fshelp_find_file) (const char *path,
+ grub_fshelp_node_t rootnode,
+ grub_fshelp_node_t *foundnode,
+ int (*iterate_dir) (grub_fshelp_node_t dir,
+ grub_fshelp_iterate_dir_hook_t hook,
+ void *hook_data),
+ char *(*read_symlink) (grub_fshelp_node_t node),
+ enum grub_fshelp_filetype expect);
+
+
+grub_err_t
+EXPORT_FUNC(grub_fshelp_find_file_lookup) (const char *path,
+ grub_fshelp_node_t rootnode,
+ grub_fshelp_node_t *foundnode,
+ grub_err_t (*lookup_file) (grub_fshelp_node_t dir,
+ const char *name,
+ grub_fshelp_node_t *foundnode,
+ enum grub_fshelp_filetype *foundtype),
+ char *(*read_symlink) (grub_fshelp_node_t node),
+ enum grub_fshelp_filetype expect);
+
+/* Read LEN bytes from the file NODE on disk DISK into the buffer BUF,
+ beginning with the block POS. READ_HOOK should be set before
+ reading a block from the file. GET_BLOCK is used to translate file
+ blocks to disk blocks. The file is FILESIZE bytes big and the
+ blocks have a size of LOG2BLOCKSIZE (in log2). */
+grub_ssize_t
+EXPORT_FUNC(grub_fshelp_read_file) (grub_disk_t disk, grub_fshelp_node_t node,
+ grub_disk_read_hook_t read_hook,
+ void *read_hook_data,
+ grub_off_t pos, grub_size_t len, char *buf,
+ grub_disk_addr_t (*get_block) (grub_fshelp_node_t node,
+ grub_disk_addr_t block),
+ grub_off_t filesize, int log2blocksize,
+ grub_disk_addr_t blocks_start);
+
+#endif /* ! GRUB_FSHELP_HEADER */
diff --git a/include/grub/gcry/types.h b/include/grub/gcry/types.h
new file mode 100644
index 0000000..892a204
--- /dev/null
+++ b/include/grub/gcry/types.h
@@ -0,0 +1,37 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_GCRY_TYPES_HEADER
+#define GRUB_GCRY_TYPES_HEADER 1
+
+#include <grub/types.h>
+#include <grub/misc.h>
+
+#ifdef GRUB_CPU_WORDS_BIGENDIAN
+#define WORDS_BIGENDIAN
+#else
+#undef WORDS_BIGENDIAN
+#endif
+
+typedef grub_uint64_t u64;
+typedef grub_uint32_t u32;
+typedef grub_uint16_t u16;
+typedef grub_uint8_t byte;
+typedef grub_size_t size_t;
+
+#endif
diff --git a/include/grub/gcrypt/g10lib.h b/include/grub/gcrypt/g10lib.h
new file mode 100644
index 0000000..85a51be
--- /dev/null
+++ b/include/grub/gcrypt/g10lib.h
@@ -0,0 +1,302 @@
+/* g10lib.h - Internal definitions for libgcrypt
+ * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2005
+ * 2007, 2011 Free Software Foundation, Inc.
+ *
+ * This file is part of Libgcrypt.
+ *
+ * Libgcrypt is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser general Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * Libgcrypt is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* This header is to be used inside of libgcrypt in place of gcrypt.h.
+ This way we can better distinguish between internal and external
+ usage of gcrypt.h. */
+
+#ifndef G10LIB_H
+#define G10LIB_H 1
+
+#ifdef _GCRYPT_H
+#error gcrypt.h already included
+#endif
+
+#ifndef _GCRYPT_IN_LIBGCRYPT
+#error something is wrong with config.h
+#endif
+
+#include <stdio.h>
+#include <stdarg.h>
+
+#include "visibility.h"
+#include "types.h"
+
+
+
+
+/* Attribute handling macros. */
+
+#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 )
+#define JNLIB_GCC_M_FUNCTION 1
+#define JNLIB_GCC_A_NR __attribute__ ((noreturn))
+#define JNLIB_GCC_A_PRINTF( f, a ) __attribute__ ((format (__printf__,f,a)))
+#define JNLIB_GCC_A_NR_PRINTF( f, a ) \
+ __attribute__ ((noreturn, format (__printf__,f,a)))
+#define GCC_ATTR_NORETURN __attribute__ ((__noreturn__))
+#else
+#define JNLIB_GCC_A_NR
+#define JNLIB_GCC_A_PRINTF( f, a )
+#define JNLIB_GCC_A_NR_PRINTF( f, a )
+#define GCC_ATTR_NORETURN
+#endif
+
+#if __GNUC__ >= 3
+/* According to glibc this attribute is available since 2.8 however we
+ better play safe and use it only with gcc 3 or newer. */
+#define GCC_ATTR_FORMAT_ARG(a) __attribute__ ((format_arg (a)))
+#else
+#define GCC_ATTR_FORMAT_ARG(a)
+#endif
+
+
+/* Gettext macros. */
+
+/* Some handy macros */
+#ifndef STR
+#define STR(v) #v
+#endif
+#define STR2(v) STR(v)
+#define DIM(v) (sizeof(v)/sizeof((v)[0]))
+#define DIMof(type,member) DIM(((type *)0)->member)
+
+
+
+/*-- src/global.c -*/
+int _gcry_global_is_operational (void);
+gcry_error_t _gcry_vcontrol (enum gcry_ctl_cmds cmd, va_list arg_ptr);
+void _gcry_check_heap (const void *a);
+int _gcry_get_debug_flag (unsigned int mask);
+
+
+/*-- src/misc.c --*/
+
+#if defined(JNLIB_GCC_M_FUNCTION) || __STDC_VERSION__ >= 199901L
+void _gcry_bug (const char *file, int line,
+ const char *func) GCC_ATTR_NORETURN;
+void _gcry_assert_failed (const char *expr, const char *file, int line,
+ const char *func) GCC_ATTR_NORETURN;
+#else
+void _gcry_bug (const char *file, int line);
+void _gcry_assert_failed (const char *expr, const char *file, int line);
+#endif
+
+const char *_gcry_gettext (const char *key) GCC_ATTR_FORMAT_ARG(1);
+void _gcry_fatal_error(int rc, const char *text ) JNLIB_GCC_A_NR;
+void _gcry_log( int level, const char *fmt, ... ) JNLIB_GCC_A_PRINTF(2,3);
+void _gcry_log_bug( const char *fmt, ... ) JNLIB_GCC_A_NR_PRINTF(1,2);
+void _gcry_log_fatal( const char *fmt, ... ) JNLIB_GCC_A_NR_PRINTF(1,2);
+void _gcry_log_error( const char *fmt, ... ) JNLIB_GCC_A_PRINTF(1,2);
+void _gcry_log_info( const char *fmt, ... ) JNLIB_GCC_A_PRINTF(1,2);
+int _gcry_log_info_with_dummy_fp (FILE *fp, const char *fmt, ... )
+ JNLIB_GCC_A_PRINTF(2,3);
+void _gcry_log_debug( const char *fmt, ... ) JNLIB_GCC_A_PRINTF(1,2);
+void _gcry_log_printf ( const char *fmt, ... ) JNLIB_GCC_A_PRINTF(1,2);
+void _gcry_log_printhex (const char *text, const void *buffer, size_t length);
+
+void _gcry_set_log_verbosity( int level );
+int _gcry_log_verbosity( int level );
+
+#ifdef JNLIB_GCC_M_FUNCTION
+#define BUG() _gcry_bug( __FILE__ , __LINE__, __FUNCTION__ )
+#define gcry_assert(expr) ((expr)? (void)0 \
+ : _gcry_assert_failed (STR(expr), __FILE__, __LINE__, __FUNCTION__))
+#elif __STDC_VERSION__ >= 199901L
+#define BUG() _gcry_bug( __FILE__ , __LINE__, __func__ )
+#define gcry_assert(expr) ((expr)? (void)0 \
+ : _gcry_assert_failed (STR(expr), __FILE__, __LINE__, __func__))
+#else
+#define BUG() _gcry_bug( __FILE__ , __LINE__ )
+#define gcry_assert(expr) ((expr)? (void)0 \
+ : _gcry_assert_failed (STR(expr), __FILE__, __LINE__))
+#endif
+
+
+#define log_bug _gcry_log_bug
+#define log_fatal _gcry_log_fatal
+#define log_error _gcry_log_error
+#define log_info _gcry_log_info
+#define log_debug _gcry_log_debug
+#define log_printf _gcry_log_printf
+#define log_printhex _gcry_log_printhex
+
+
+/*-- src/hwfeatures.c --*/
+/* (Do not change these values unless synced with the asm code.) */
+#define HWF_PADLOCK_RNG 1
+#define HWF_PADLOCK_AES 2
+#define HWF_PADLOCK_SHA 4
+#define HWF_PADLOCK_MMUL 8
+
+#define HWF_INTEL_AESNI 256
+
+
+unsigned int _gcry_get_hw_features (void);
+void _gcry_detect_hw_features (unsigned int);
+
+
+/*-- mpi/mpiutil.c --*/
+const char *_gcry_mpi_get_hw_config (void);
+
+
+/*-- cipher/pubkey.c --*/
+
+/* FIXME: shouldn't this go into mpi.h? */
+#ifndef mpi_powm
+#define mpi_powm(w,b,e,m) gcry_mpi_powm( (w), (b), (e), (m) )
+#endif
+
+/*-- primegen.c --*/
+gcry_mpi_t _gcry_generate_secret_prime (unsigned int nbits,
+ gcry_random_level_t random_level,
+ int (*extra_check)(void*, gcry_mpi_t),
+ void *extra_check_arg);
+gcry_mpi_t _gcry_generate_public_prime (unsigned int nbits,
+ gcry_random_level_t random_level,
+ int (*extra_check)(void*, gcry_mpi_t),
+ void *extra_check_arg);
+gcry_mpi_t _gcry_generate_elg_prime (int mode,
+ unsigned int pbits, unsigned int qbits,
+ gcry_mpi_t g, gcry_mpi_t **factors);
+gcry_mpi_t _gcry_derive_x931_prime (const gcry_mpi_t xp,
+ const gcry_mpi_t xp1, const gcry_mpi_t xp2,
+ const gcry_mpi_t e,
+ gcry_mpi_t *r_p1, gcry_mpi_t *r_p2);
+gpg_err_code_t _gcry_generate_fips186_2_prime
+ (unsigned int pbits, unsigned int qbits,
+ const void *seed, size_t seedlen,
+ gcry_mpi_t *r_q, gcry_mpi_t *r_p,
+ int *r_counter,
+ void **r_seed, size_t *r_seedlen);
+gpg_err_code_t _gcry_generate_fips186_3_prime
+ (unsigned int pbits, unsigned int qbits,
+ const void *seed, size_t seedlen,
+ gcry_mpi_t *r_q, gcry_mpi_t *r_p,
+ int *r_counter,
+ void **r_seed, size_t *r_seedlen, int *r_hashalgo);
+
+
+/* Replacements of missing functions (missing-string.c). */
+#ifndef HAVE_STPCPY
+char *stpcpy (char *a, const char *b);
+#endif
+#ifndef HAVE_STRCASECMP
+int strcasecmp (const char *a, const char *b) _GCRY_GCC_ATTR_PURE;
+#endif
+
+
+/* Macros used to rename missing functions. */
+#ifndef HAVE_STRTOUL
+#define strtoul(a,b,c) ((unsigned long)strtol((a),(b),(c)))
+#endif
+#ifndef HAVE_MEMMOVE
+#define memmove(d, s, n) bcopy((s), (d), (n))
+#endif
+#ifndef HAVE_STRICMP
+#define stricmp(a,b) strcasecmp( (a), (b) )
+#endif
+#ifndef HAVE_ATEXIT
+#define atexit(a) (on_exit((a),0))
+#endif
+#ifndef HAVE_RAISE
+#define raise(a) kill(getpid(), (a))
+#endif
+
+
+/* Stack burning. */
+
+void _gcry_burn_stack (int bytes);
+
+
+/* To avoid that a compiler optimizes certain memset calls away, these
+ macros may be used instead. */
+#define wipememory2(_ptr,_set,_len) do { \
+ volatile char *_vptr=(volatile char *)(_ptr); \
+ size_t _vlen=(_len); \
+ while(_vlen) { *_vptr=(_set); _vptr++; _vlen--; } \
+ } while(0)
+#define wipememory(_ptr,_len) wipememory2(_ptr,0,_len)
+
+
+
+/* Digit predicates. */
+
+#define digitp(p) (*(p) >= '0' && *(p) <= '9')
+#define octdigitp(p) (*(p) >= '0' && *(p) <= '7')
+#define alphap(a) ( (*(a) >= 'A' && *(a) <= 'Z') \
+ || (*(a) >= 'a' && *(a) <= 'z'))
+#define hexdigitp(a) (digitp (a) \
+ || (*(a) >= 'A' && *(a) <= 'F') \
+ || (*(a) >= 'a' && *(a) <= 'f'))
+
+
+/*-- sexp.c --*/
+gcry_error_t _gcry_sexp_vbuild (gcry_sexp_t *retsexp, size_t *erroff,
+ const char *format, va_list arg_ptr);
+char *_gcry_sexp_nth_string (const gcry_sexp_t list, int number);
+
+
+/*-- fips.c --*/
+
+void _gcry_initialize_fips_mode (int force);
+
+int _gcry_fips_mode (void);
+#define fips_mode() _gcry_fips_mode ()
+
+int _gcry_enforced_fips_mode (void);
+
+void _gcry_set_enforced_fips_mode (void);
+
+void _gcry_inactivate_fips_mode (const char *text);
+int _gcry_is_fips_mode_inactive (void);
+
+
+void _gcry_fips_signal_error (const char *srcfile,
+ int srcline,
+ const char *srcfunc,
+ int is_fatal,
+ const char *description);
+#ifdef JNLIB_GCC_M_FUNCTION
+# define fips_signal_error(a) \
+ _gcry_fips_signal_error (__FILE__, __LINE__, __FUNCTION__, 0, (a))
+# define fips_signal_fatal_error(a) \
+ _gcry_fips_signal_error (__FILE__, __LINE__, __FUNCTION__, 1, (a))
+#else
+# define fips_signal_error(a) \
+ _gcry_fips_signal_error (__FILE__, __LINE__, NULL, 0, (a))
+# define fips_signal_fatal_error(a) \
+ _gcry_fips_signal_error (__FILE__, __LINE__, NULL, 1, (a))
+#endif
+
+int _gcry_fips_is_operational (void);
+#define fips_is_operational() (_gcry_global_is_operational ())
+#define fips_not_operational() (GCRY_GPG_ERR_NOT_OPERATIONAL)
+
+int _gcry_fips_test_operational (void);
+int _gcry_fips_test_error_or_operational (void);
+
+gpg_err_code_t _gcry_fips_run_selftests (int extended);
+
+void _gcry_fips_noreturn (void);
+#define fips_noreturn() (_gcry_fips_noreturn ())
+
+
+
+#endif /* G10LIB_H */
diff --git a/include/grub/gcrypt/gcrypt.h b/include/grub/gcrypt/gcrypt.h
new file mode 100644
index 0000000..c149c6f
--- /dev/null
+++ b/include/grub/gcrypt/gcrypt.h
@@ -0,0 +1,1746 @@
+/* gcrypt.h - GNU Cryptographic Library Interface -*- c -*-
+ Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006
+ 2007, 2008, 2009, 2010, 2011,
+ 2012 Free Software Foundation, Inc.
+ Copyright (C) 2012, 2013 g10 Code GmbH
+
+ This file is part of Libgcrypt.
+
+ Libgcrypt is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of
+ the License, or (at your option) any later version.
+
+ Libgcrypt is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this program; if not, see <http://www.gnu.org/licenses/>.
+
+ File: @configure_input@ */
+
+#ifndef _GCRYPT_H
+#define _GCRYPT_H
+
+#include <stdarg.h>
+
+#include <grub/gcrypt/gpg-error.h>
+
+#include <sys/types.h>
+
+#if defined _WIN32 || defined __WIN32__
+# ifndef __GNUC__
+# endif /*!__GNUC__*/
+#else
+#endif /*!_WIN32*/
+
+
+/* This is required for error code compatibility. */
+#define _GCRY_ERR_SOURCE_DEFAULT GPG_ERR_SOURCE_GCRYPT
+
+#ifdef __cplusplus
+extern "C" {
+#if 0 /* (Keep Emacsens' auto-indent happy.) */
+}
+#endif
+#endif
+
+/* The version of this header should match the one of the library. It
+ should not be used by a program because gcry_check_version() should
+ return the same version. The purpose of this macro is to let
+ autoconf (using the AM_PATH_GCRYPT macro) check that this header
+ matches the installed library. */
+#define GCRYPT_VERSION "@VERSION@"
+
+/* The version number of this header. It may be used to handle minor
+ API incompatibilities. */
+#define GCRYPT_VERSION_NUMBER @VERSION_NUMBER@
+
+
+/* Internal: We can't use the convenience macros for the multi
+ precision integer functions when building this library. */
+#ifdef _GCRYPT_IN_LIBGCRYPT
+#ifndef GCRYPT_NO_MPI_MACROS
+#define GCRYPT_NO_MPI_MACROS 1
+#endif
+#endif
+
+/* We want to use gcc attributes when possible. Warning: Don't use
+ these macros in your programs: As indicated by the leading
+ underscore they are subject to change without notice. */
+#ifdef __GNUC__
+
+#define _GCRY_GCC_VERSION (__GNUC__ * 10000 \
+ + __GNUC_MINOR__ * 100 \
+ + __GNUC_PATCHLEVEL__)
+
+#if _GCRY_GCC_VERSION >= 30100
+#define _GCRY_GCC_ATTR_DEPRECATED __attribute__ ((__deprecated__))
+#endif
+
+#if _GCRY_GCC_VERSION >= 29600
+#define _GCRY_GCC_ATTR_PURE __attribute__ ((__pure__))
+#endif
+
+#if _GCRY_GCC_VERSION >= 30200
+#define _GCRY_GCC_ATTR_MALLOC __attribute__ ((__malloc__))
+#endif
+
+#endif /*__GNUC__*/
+
+#ifndef _GCRY_GCC_ATTR_DEPRECATED
+#define _GCRY_GCC_ATTR_DEPRECATED
+#endif
+#ifndef _GCRY_GCC_ATTR_PURE
+#define _GCRY_GCC_ATTR_PURE
+#endif
+#ifndef _GCRY_GCC_ATTR_MALLOC
+#define _GCRY_GCC_ATTR_MALLOC
+#endif
+
+/* Make up an attribute to mark functions and types as deprecated but
+ allow internal use by Libgcrypt. */
+#ifdef _GCRYPT_IN_LIBGCRYPT
+#define _GCRY_ATTR_INTERNAL
+#else
+#define _GCRY_ATTR_INTERNAL _GCRY_GCC_ATTR_DEPRECATED
+#endif
+
+/* Wrappers for the libgpg-error library. */
+
+typedef gpg_err_source_t gcry_err_source_t;
+
+static GPG_ERR_INLINE gcry_error_t
+gcry_err_make (gcry_err_source_t source, gcry_err_code_t code)
+{
+ return gpg_err_make (source, code);
+}
+
+/* The user can define GPG_ERR_SOURCE_DEFAULT before including this
+ file to specify a default source for gpg_error. */
+#ifndef GCRY_ERR_SOURCE_DEFAULT
+#define GCRY_ERR_SOURCE_DEFAULT GPG_ERR_SOURCE_USER_1
+#endif
+
+static GPG_ERR_INLINE gcry_error_t
+gcry_error (gcry_err_code_t code)
+{
+ return gcry_err_make (GCRY_ERR_SOURCE_DEFAULT, code);
+}
+
+static GPG_ERR_INLINE gcry_err_code_t
+gcry_err_code (gcry_error_t err)
+{
+ return gpg_err_code (err);
+}
+
+
+static GPG_ERR_INLINE gcry_err_source_t
+gcry_err_source (gcry_error_t err)
+{
+ return gpg_err_source (err);
+}
+
+/* Return a pointer to a string containing a description of the error
+ code in the error value ERR. */
+const char *gcry_strerror (gcry_error_t err);
+
+/* Return a pointer to a string containing a description of the error
+ source in the error value ERR. */
+const char *gcry_strsource (gcry_error_t err);
+
+/* Retrieve the error code for the system error ERR. This returns
+ GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped (report
+ this). */
+gcry_err_code_t gcry_err_code_from_errno (int err);
+
+/* Retrieve the system error for the error code CODE. This returns 0
+ if CODE is not a system error code. */
+int gcry_err_code_to_errno (gcry_err_code_t code);
+
+/* Return an error value with the error source SOURCE and the system
+ error ERR. */
+gcry_error_t gcry_err_make_from_errno (gcry_err_source_t source, int err);
+
+/* Return an error value with the system error ERR. */
+gcry_err_code_t gcry_error_from_errno (int err);
+
+
+/* The data object used to hold a multi precision integer. */
+struct gcry_mpi;
+
+#ifndef GCRYPT_NO_DEPRECATED
+typedef struct gcry_mpi *GCRY_MPI _GCRY_GCC_ATTR_DEPRECATED;
+typedef struct gcry_mpi *GcryMPI _GCRY_GCC_ATTR_DEPRECATED;
+#endif
+
+
+
+/* Check that the library fulfills the version requirement. */
+const char *gcry_check_version (const char *req_version);
+
+/* Codes for function dispatchers. */
+
+/* Codes used with the gcry_control function. */
+enum gcry_ctl_cmds
+ {
+ GCRYCTL_SET_KEY = 1,
+ GCRYCTL_SET_IV = 2,
+ GCRYCTL_CFB_SYNC = 3,
+ GCRYCTL_RESET = 4, /* e.g. for MDs */
+ GCRYCTL_FINALIZE = 5,
+ GCRYCTL_GET_KEYLEN = 6,
+ GCRYCTL_GET_BLKLEN = 7,
+ GCRYCTL_TEST_ALGO = 8,
+ GCRYCTL_IS_SECURE = 9,
+ GCRYCTL_GET_ASNOID = 10,
+ GCRYCTL_ENABLE_ALGO = 11,
+ GCRYCTL_DISABLE_ALGO = 12,
+ GCRYCTL_DUMP_RANDOM_STATS = 13,
+ GCRYCTL_DUMP_SECMEM_STATS = 14,
+ GCRYCTL_GET_ALGO_NPKEY = 15,
+ GCRYCTL_GET_ALGO_NSKEY = 16,
+ GCRYCTL_GET_ALGO_NSIGN = 17,
+ GCRYCTL_GET_ALGO_NENCR = 18,
+ GCRYCTL_SET_VERBOSITY = 19,
+ GCRYCTL_SET_DEBUG_FLAGS = 20,
+ GCRYCTL_CLEAR_DEBUG_FLAGS = 21,
+ GCRYCTL_USE_SECURE_RNDPOOL= 22,
+ GCRYCTL_DUMP_MEMORY_STATS = 23,
+ GCRYCTL_INIT_SECMEM = 24,
+ GCRYCTL_TERM_SECMEM = 25,
+ GCRYCTL_DISABLE_SECMEM_WARN = 27,
+ GCRYCTL_SUSPEND_SECMEM_WARN = 28,
+ GCRYCTL_RESUME_SECMEM_WARN = 29,
+ GCRYCTL_DROP_PRIVS = 30,
+ GCRYCTL_ENABLE_M_GUARD = 31,
+ GCRYCTL_START_DUMP = 32,
+ GCRYCTL_STOP_DUMP = 33,
+ GCRYCTL_GET_ALGO_USAGE = 34,
+ GCRYCTL_IS_ALGO_ENABLED = 35,
+ GCRYCTL_DISABLE_INTERNAL_LOCKING = 36,
+ GCRYCTL_DISABLE_SECMEM = 37,
+ GCRYCTL_INITIALIZATION_FINISHED = 38,
+ GCRYCTL_INITIALIZATION_FINISHED_P = 39,
+ GCRYCTL_ANY_INITIALIZATION_P = 40,
+ GCRYCTL_SET_CBC_CTS = 41,
+ GCRYCTL_SET_CBC_MAC = 42,
+ GCRYCTL_SET_CTR = 43,
+ GCRYCTL_ENABLE_QUICK_RANDOM = 44,
+ GCRYCTL_SET_RANDOM_SEED_FILE = 45,
+ GCRYCTL_UPDATE_RANDOM_SEED_FILE = 46,
+ GCRYCTL_SET_THREAD_CBS = 47,
+ GCRYCTL_FAST_POLL = 48,
+ GCRYCTL_SET_RANDOM_DAEMON_SOCKET = 49,
+ GCRYCTL_USE_RANDOM_DAEMON = 50,
+ GCRYCTL_FAKED_RANDOM_P = 51,
+ GCRYCTL_SET_RNDEGD_SOCKET = 52,
+ GCRYCTL_PRINT_CONFIG = 53,
+ GCRYCTL_OPERATIONAL_P = 54,
+ GCRYCTL_FIPS_MODE_P = 55,
+ GCRYCTL_FORCE_FIPS_MODE = 56,
+ GCRYCTL_SELFTEST = 57,
+ /* Note: 58 .. 62 are used internally. */
+ GCRYCTL_DISABLE_HWF = 63,
+ GCRYCTL_SET_ENFORCED_FIPS_FLAG = 64
+ };
+
+/* Perform various operations defined by CMD. */
+gcry_error_t gcry_control (enum gcry_ctl_cmds CMD, ...);
+
+
+/* S-expression management. */
+
+/* The object to represent an S-expression as used with the public key
+ functions. */
+struct gcry_sexp;
+typedef struct gcry_sexp *gcry_sexp_t;
+
+#ifndef GCRYPT_NO_DEPRECATED
+typedef struct gcry_sexp *GCRY_SEXP _GCRY_GCC_ATTR_DEPRECATED;
+typedef struct gcry_sexp *GcrySexp _GCRY_GCC_ATTR_DEPRECATED;
+#endif
+
+/* The possible values for the S-expression format. */
+enum gcry_sexp_format
+ {
+ GCRYSEXP_FMT_DEFAULT = 0,
+ GCRYSEXP_FMT_CANON = 1,
+ GCRYSEXP_FMT_BASE64 = 2,
+ GCRYSEXP_FMT_ADVANCED = 3
+ };
+
+/* Create an new S-expression object from BUFFER of size LENGTH and
+ return it in RETSEXP. With AUTODETECT set to 0 the data in BUFFER
+ is expected to be in canonized format. */
+gcry_error_t gcry_sexp_new (gcry_sexp_t *retsexp,
+ const void *buffer, size_t length,
+ int autodetect);
+
+ /* Same as gcry_sexp_new but allows to pass a FREEFNC which has the
+ effect to transfer ownership of BUFFER to the created object. */
+gcry_error_t gcry_sexp_create (gcry_sexp_t *retsexp,
+ void *buffer, size_t length,
+ int autodetect, void (*freefnc) (void *));
+
+/* Scan BUFFER and return a new S-expression object in RETSEXP. This
+ function expects a printf like string in BUFFER. */
+gcry_error_t gcry_sexp_sscan (gcry_sexp_t *retsexp, size_t *erroff,
+ const char *buffer, size_t length);
+
+/* Same as gcry_sexp_sscan but expects a string in FORMAT and can thus
+ only be used for certain encodings. */
+gcry_error_t gcry_sexp_build (gcry_sexp_t *retsexp, size_t *erroff,
+ const char *format, ...);
+
+/* Like gcry_sexp_build, but uses an array instead of variable
+ function arguments. */
+gcry_error_t gcry_sexp_build_array (gcry_sexp_t *retsexp, size_t *erroff,
+ const char *format, void **arg_list);
+
+/* Release the S-expression object SEXP */
+void gcry_sexp_release (gcry_sexp_t sexp);
+
+/* Calculate the length of an canonized S-expresion in BUFFER and
+ check for a valid encoding. */
+size_t gcry_sexp_canon_len (const unsigned char *buffer, size_t length,
+ size_t *erroff, gcry_error_t *errcode);
+
+/* Copies the S-expression object SEXP into BUFFER using the format
+ specified in MODE. */
+size_t gcry_sexp_sprint (gcry_sexp_t sexp, int mode, void *buffer,
+ size_t maxlength);
+
+/* Dumps the S-expression object A in a format suitable for debugging
+ to Libgcrypt's logging stream. */
+void gcry_sexp_dump (const gcry_sexp_t a);
+
+gcry_sexp_t gcry_sexp_cons (const gcry_sexp_t a, const gcry_sexp_t b);
+gcry_sexp_t gcry_sexp_alist (const gcry_sexp_t *array);
+gcry_sexp_t gcry_sexp_vlist (const gcry_sexp_t a, ...);
+gcry_sexp_t gcry_sexp_append (const gcry_sexp_t a, const gcry_sexp_t n);
+gcry_sexp_t gcry_sexp_prepend (const gcry_sexp_t a, const gcry_sexp_t n);
+
+/* Scan the S-expression for a sublist with a type (the car of the
+ list) matching the string TOKEN. If TOKLEN is not 0, the token is
+ assumed to be raw memory of this length. The function returns a
+ newly allocated S-expression consisting of the found sublist or
+ `NULL' when not found. */
+gcry_sexp_t gcry_sexp_find_token (gcry_sexp_t list,
+ const char *tok, size_t toklen);
+/* Return the length of the LIST. For a valid S-expression this
+ should be at least 1. */
+int gcry_sexp_length (const gcry_sexp_t list);
+
+/* Create and return a new S-expression from the element with index
+ NUMBER in LIST. Note that the first element has the index 0. If
+ there is no such element, `NULL' is returned. */
+gcry_sexp_t gcry_sexp_nth (const gcry_sexp_t list, int number);
+
+/* Create and return a new S-expression from the first element in
+ LIST; this called the "type" and should always exist and be a
+ string. `NULL' is returned in case of a problem. */
+gcry_sexp_t gcry_sexp_car (const gcry_sexp_t list);
+
+/* Create and return a new list form all elements except for the first
+ one. Note, that this function may return an invalid S-expression
+ because it is not guaranteed, that the type exists and is a string.
+ However, for parsing a complex S-expression it might be useful for
+ intermediate lists. Returns `NULL' on error. */
+gcry_sexp_t gcry_sexp_cdr (const gcry_sexp_t list);
+
+gcry_sexp_t gcry_sexp_cadr (const gcry_sexp_t list);
+
+
+/* This function is used to get data from a LIST. A pointer to the
+ actual data with index NUMBER is returned and the length of this
+ data will be stored to DATALEN. If there is no data at the given
+ index or the index represents another list, `NULL' is returned.
+ *Note:* The returned pointer is valid as long as LIST is not
+ modified or released. */
+const char *gcry_sexp_nth_data (const gcry_sexp_t list, int number,
+ size_t *datalen);
+
+/* This function is used to get and convert data from a LIST. The
+ data is assumed to be a Nul terminated string. The caller must
+ release the returned value using `gcry_free'. If there is no data
+ at the given index, the index represents a list or the value can't
+ be converted to a string, `NULL' is returned. */
+char *gcry_sexp_nth_string (gcry_sexp_t list, int number);
+
+/* This function is used to get and convert data from a LIST. This
+ data is assumed to be an MPI stored in the format described by
+ MPIFMT and returned as a standard Libgcrypt MPI. The caller must
+ release this returned value using `gcry_mpi_release'. If there is
+ no data at the given index, the index represents a list or the
+ value can't be converted to an MPI, `NULL' is returned. */
+gcry_mpi_t gcry_sexp_nth_mpi (gcry_sexp_t list, int number, int mpifmt);
+
+
+
+/*******************************************
+ * *
+ * Multi Precision Integer Functions *
+ * *
+ *******************************************/
+
+/* Different formats of external big integer representation. */
+enum gcry_mpi_format
+ {
+ GCRYMPI_FMT_NONE= 0,
+ GCRYMPI_FMT_STD = 1, /* Twos complement stored without length. */
+ GCRYMPI_FMT_PGP = 2, /* As used by OpenPGP (unsigned only). */
+ GCRYMPI_FMT_SSH = 3, /* As used by SSH (like STD but with length). */
+ GCRYMPI_FMT_HEX = 4, /* Hex format. */
+ GCRYMPI_FMT_USG = 5 /* Like STD but unsigned. */
+ };
+
+/* Flags used for creating big integers. */
+enum gcry_mpi_flag
+ {
+ GCRYMPI_FLAG_SECURE = 1, /* Allocate the number in "secure" memory. */
+ GCRYMPI_FLAG_OPAQUE = 2 /* The number is not a real one but just
+ a way to store some bytes. This is
+ useful for encrypted big integers. */
+ };
+
+
+/* Allocate a new big integer object, initialize it with 0 and
+ initially allocate memory for a number of at least NBITS. */
+gcry_mpi_t gcry_mpi_new (unsigned int nbits);
+
+/* Same as gcry_mpi_new() but allocate in "secure" memory. */
+gcry_mpi_t gcry_mpi_snew (unsigned int nbits);
+
+/* Release the number A and free all associated resources. */
+void gcry_mpi_release (gcry_mpi_t a);
+
+/* Create a new number with the same value as A. */
+gcry_mpi_t gcry_mpi_copy (const gcry_mpi_t a);
+
+/* Store the big integer value U in W. */
+gcry_mpi_t gcry_mpi_set (gcry_mpi_t w, const gcry_mpi_t u);
+
+/* Store the unsigned integer value U in W. */
+gcry_mpi_t gcry_mpi_set_ui (gcry_mpi_t w, unsigned long u);
+
+/* Swap the values of A and B. */
+void gcry_mpi_swap (gcry_mpi_t a, gcry_mpi_t b);
+
+/* Compare the big integer number U and V returning 0 for equality, a
+ positive value for U > V and a negative for U < V. */
+int gcry_mpi_cmp (const gcry_mpi_t u, const gcry_mpi_t v);
+
+/* Compare the big integer number U with the unsigned integer V
+ returning 0 for equality, a positive value for U > V and a negative
+ for U < V. */
+int gcry_mpi_cmp_ui (const gcry_mpi_t u, unsigned long v);
+
+/* Convert the external representation of an integer stored in BUFFER
+ with a length of BUFLEN into a newly create MPI returned in
+ RET_MPI. If NSCANNED is not NULL, it will receive the number of
+ bytes actually scanned after a successful operation. */
+gcry_error_t gcry_mpi_scan (gcry_mpi_t *ret_mpi, enum gcry_mpi_format format,
+ const void *buffer, size_t buflen,
+ size_t *nscanned);
+
+/* Convert the big integer A into the external representation
+ described by FORMAT and store it in the provided BUFFER which has
+ been allocated by the user with a size of BUFLEN bytes. NWRITTEN
+ receives the actual length of the external representation unless it
+ has been passed as NULL. */
+gcry_error_t gcry_mpi_print (enum gcry_mpi_format format,
+ unsigned char *buffer, size_t buflen,
+ size_t *nwritten,
+ const gcry_mpi_t a);
+
+/* Convert the big integer A int the external representation described
+ by FORMAT and store it in a newly allocated buffer which address
+ will be put into BUFFER. NWRITTEN receives the actual lengths of the
+ external representation. */
+gcry_error_t gcry_mpi_aprint (enum gcry_mpi_format format,
+ unsigned char **buffer, size_t *nwritten,
+ const gcry_mpi_t a);
+
+/* Dump the value of A in a format suitable for debugging to
+ Libgcrypt's logging stream. Note that one leading space but no
+ trailing space or linefeed will be printed. It is okay to pass
+ NULL for A. */
+void gcry_mpi_dump (const gcry_mpi_t a);
+
+
+/* W = U + V. */
+void gcry_mpi_add (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v);
+
+/* W = U + V. V is an unsigned integer. */
+void gcry_mpi_add_ui (gcry_mpi_t w, gcry_mpi_t u, unsigned long v);
+
+/* W = U + V mod M. */
+void gcry_mpi_addm (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m);
+
+/* W = U - V. */
+void gcry_mpi_sub (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v);
+
+/* W = U - V. V is an unsigned integer. */
+void gcry_mpi_sub_ui (gcry_mpi_t w, gcry_mpi_t u, unsigned long v );
+
+/* W = U - V mod M */
+void gcry_mpi_subm (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m);
+
+/* W = U * V. */
+void gcry_mpi_mul (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v);
+
+/* W = U * V. V is an unsigned integer. */
+void gcry_mpi_mul_ui (gcry_mpi_t w, gcry_mpi_t u, unsigned long v );
+
+/* W = U * V mod M. */
+void gcry_mpi_mulm (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m);
+
+/* W = U * (2 ^ CNT). */
+void gcry_mpi_mul_2exp (gcry_mpi_t w, gcry_mpi_t u, unsigned long cnt);
+
+/* Q = DIVIDEND / DIVISOR, R = DIVIDEND % DIVISOR,
+ Q or R may be passed as NULL. ROUND should be negative or 0. */
+void gcry_mpi_div (gcry_mpi_t q, gcry_mpi_t r,
+ gcry_mpi_t dividend, gcry_mpi_t divisor, int round);
+
+/* R = DIVIDEND % DIVISOR */
+void gcry_mpi_mod (gcry_mpi_t r, gcry_mpi_t dividend, gcry_mpi_t divisor);
+
+/* W = B ^ E mod M. */
+void gcry_mpi_powm (gcry_mpi_t w,
+ const gcry_mpi_t b, const gcry_mpi_t e,
+ const gcry_mpi_t m);
+
+/* Set G to the greatest common divisor of A and B.
+ Return true if the G is 1. */
+int gcry_mpi_gcd (gcry_mpi_t g, gcry_mpi_t a, gcry_mpi_t b);
+
+/* Set X to the multiplicative inverse of A mod M.
+ Return true if the value exists. */
+int gcry_mpi_invm (gcry_mpi_t x, gcry_mpi_t a, gcry_mpi_t m);
+
+
+/* Return the number of bits required to represent A. */
+unsigned int gcry_mpi_get_nbits (gcry_mpi_t a);
+
+/* Return true when bit number N (counting from 0) is set in A. */
+int gcry_mpi_test_bit (gcry_mpi_t a, unsigned int n);
+
+/* Set bit number N in A. */
+void gcry_mpi_set_bit (gcry_mpi_t a, unsigned int n);
+
+/* Clear bit number N in A. */
+void gcry_mpi_clear_bit (gcry_mpi_t a, unsigned int n);
+
+/* Set bit number N in A and clear all bits greater than N. */
+void gcry_mpi_set_highbit (gcry_mpi_t a, unsigned int n);
+
+/* Clear bit number N in A and all bits greater than N. */
+void gcry_mpi_clear_highbit (gcry_mpi_t a, unsigned int n);
+
+/* Shift the value of A by N bits to the right and store the result in X. */
+void gcry_mpi_rshift (gcry_mpi_t x, gcry_mpi_t a, unsigned int n);
+
+/* Shift the value of A by N bits to the left and store the result in X. */
+void gcry_mpi_lshift (gcry_mpi_t x, gcry_mpi_t a, unsigned int n);
+
+/* Store NBITS of the value P points to in A and mark A as an opaque
+ value. WARNING: Never use an opaque MPI for anything thing else then
+ gcry_mpi_release, gcry_mpi_get_opaque. */
+gcry_mpi_t gcry_mpi_set_opaque (gcry_mpi_t a, void *p, unsigned int nbits);
+
+/* Return a pointer to an opaque value stored in A and return its size
+ in NBITS. Note that the returned pointer is still owned by A and
+ that the function should never be used for an non-opaque MPI. */
+void *gcry_mpi_get_opaque (gcry_mpi_t a, unsigned int *nbits);
+
+/* Set the FLAG for the big integer A. Currently only the flag
+ GCRYMPI_FLAG_SECURE is allowed to convert A into an big intger
+ stored in "secure" memory. */
+void gcry_mpi_set_flag (gcry_mpi_t a, enum gcry_mpi_flag flag);
+
+/* Clear FLAG for the big integer A. Note that this function is
+ currently useless as no flags are allowed. */
+void gcry_mpi_clear_flag (gcry_mpi_t a, enum gcry_mpi_flag flag);
+
+/* Return true when the FLAG is set for A. */
+int gcry_mpi_get_flag (gcry_mpi_t a, enum gcry_mpi_flag flag);
+
+/* Unless the GCRYPT_NO_MPI_MACROS is used, provide a couple of
+ convenience macros for the big integer functions. */
+#ifndef GCRYPT_NO_MPI_MACROS
+#define mpi_new(n) gcry_mpi_new( (n) )
+#define mpi_secure_new( n ) gcry_mpi_snew( (n) )
+#define mpi_release(a) \
+ do \
+ { \
+ gcry_mpi_release ((a)); \
+ (a) = NULL; \
+ } \
+ while (0)
+
+#define mpi_copy( a ) gcry_mpi_copy( (a) )
+#define mpi_set( w, u) gcry_mpi_set( (w), (u) )
+#define mpi_set_ui( w, u) gcry_mpi_set_ui( (w), (u) )
+#define mpi_cmp( u, v ) gcry_mpi_cmp( (u), (v) )
+#define mpi_cmp_ui( u, v ) gcry_mpi_cmp_ui( (u), (v) )
+
+#define mpi_add_ui(w,u,v) gcry_mpi_add_ui((w),(u),(v))
+#define mpi_add(w,u,v) gcry_mpi_add ((w),(u),(v))
+#define mpi_addm(w,u,v,m) gcry_mpi_addm ((w),(u),(v),(m))
+#define mpi_sub_ui(w,u,v) gcry_mpi_sub_ui ((w),(u),(v))
+#define mpi_sub(w,u,v) gcry_mpi_sub ((w),(u),(v))
+#define mpi_subm(w,u,v,m) gcry_mpi_subm ((w),(u),(v),(m))
+#define mpi_mul_ui(w,u,v) gcry_mpi_mul_ui ((w),(u),(v))
+#define mpi_mul_2exp(w,u,v) gcry_mpi_mul_2exp ((w),(u),(v))
+#define mpi_mul(w,u,v) gcry_mpi_mul ((w),(u),(v))
+#define mpi_mulm(w,u,v,m) gcry_mpi_mulm ((w),(u),(v),(m))
+#define mpi_powm(w,b,e,m) gcry_mpi_powm ( (w), (b), (e), (m) )
+#define mpi_tdiv(q,r,a,m) gcry_mpi_div ( (q), (r), (a), (m), 0)
+#define mpi_fdiv(q,r,a,m) gcry_mpi_div ( (q), (r), (a), (m), -1)
+#define mpi_mod(r,a,m) gcry_mpi_mod ((r), (a), (m))
+#define mpi_gcd(g,a,b) gcry_mpi_gcd ( (g), (a), (b) )
+#define mpi_invm(g,a,b) gcry_mpi_invm ( (g), (a), (b) )
+
+#define mpi_get_nbits(a) gcry_mpi_get_nbits ((a))
+#define mpi_test_bit(a,b) gcry_mpi_test_bit ((a),(b))
+#define mpi_set_bit(a,b) gcry_mpi_set_bit ((a),(b))
+#define mpi_set_highbit(a,b) gcry_mpi_set_highbit ((a),(b))
+#define mpi_clear_bit(a,b) gcry_mpi_clear_bit ((a),(b))
+#define mpi_clear_highbit(a,b) gcry_mpi_clear_highbit ((a),(b))
+#define mpi_rshift(a,b,c) gcry_mpi_rshift ((a),(b),(c))
+#define mpi_lshift(a,b,c) gcry_mpi_lshift ((a),(b),(c))
+
+#define mpi_set_opaque(a,b,c) gcry_mpi_set_opaque( (a), (b), (c) )
+#define mpi_get_opaque(a,b) gcry_mpi_get_opaque( (a), (b) )
+#endif /* GCRYPT_NO_MPI_MACROS */
+
+
+
+/************************************
+ * *
+ * Symmetric Cipher Functions *
+ * *
+ ************************************/
+
+/* The data object used to hold a handle to an encryption object. */
+struct gcry_cipher_handle;
+typedef struct gcry_cipher_handle *gcry_cipher_hd_t;
+
+#ifndef GCRYPT_NO_DEPRECATED
+typedef struct gcry_cipher_handle *GCRY_CIPHER_HD _GCRY_GCC_ATTR_DEPRECATED;
+typedef struct gcry_cipher_handle *GcryCipherHd _GCRY_GCC_ATTR_DEPRECATED;
+#endif
+
+/* All symmetric encryption algorithms are identified by their IDs.
+ More IDs may be registered at runtime. */
+enum gcry_cipher_algos
+ {
+ GCRY_CIPHER_NONE = 0,
+ GCRY_CIPHER_IDEA = 1,
+ GCRY_CIPHER_3DES = 2,
+ GCRY_CIPHER_CAST5 = 3,
+ GCRY_CIPHER_BLOWFISH = 4,
+ GCRY_CIPHER_SAFER_SK128 = 5,
+ GCRY_CIPHER_DES_SK = 6,
+ GCRY_CIPHER_AES = 7,
+ GCRY_CIPHER_AES192 = 8,
+ GCRY_CIPHER_AES256 = 9,
+ GCRY_CIPHER_TWOFISH = 10,
+
+ /* Other cipher numbers are above 300 for OpenPGP reasons. */
+ GCRY_CIPHER_ARCFOUR = 301, /* Fully compatible with RSA's RC4 (tm). */
+ GCRY_CIPHER_DES = 302, /* Yes, this is single key 56 bit DES. */
+ GCRY_CIPHER_TWOFISH128 = 303,
+ GCRY_CIPHER_SERPENT128 = 304,
+ GCRY_CIPHER_SERPENT192 = 305,
+ GCRY_CIPHER_SERPENT256 = 306,
+ GCRY_CIPHER_RFC2268_40 = 307, /* Ron's Cipher 2 (40 bit). */
+ GCRY_CIPHER_RFC2268_128 = 308, /* Ron's Cipher 2 (128 bit). */
+ GCRY_CIPHER_SEED = 309, /* 128 bit cipher described in RFC4269. */
+ GCRY_CIPHER_CAMELLIA128 = 310,
+ GCRY_CIPHER_CAMELLIA192 = 311,
+ GCRY_CIPHER_CAMELLIA256 = 312
+ };
+
+/* The Rijndael algorithm is basically AES, so provide some macros. */
+#define GCRY_CIPHER_AES128 GCRY_CIPHER_AES
+#define GCRY_CIPHER_RIJNDAEL GCRY_CIPHER_AES
+#define GCRY_CIPHER_RIJNDAEL128 GCRY_CIPHER_AES128
+#define GCRY_CIPHER_RIJNDAEL192 GCRY_CIPHER_AES192
+#define GCRY_CIPHER_RIJNDAEL256 GCRY_CIPHER_AES256
+
+/* The supported encryption modes. Note that not all of them are
+ supported for each algorithm. */
+enum gcry_cipher_modes
+ {
+ GCRY_CIPHER_MODE_NONE = 0, /* Not yet specified. */
+ GCRY_CIPHER_MODE_ECB = 1, /* Electronic codebook. */
+ GCRY_CIPHER_MODE_CFB = 2, /* Cipher feedback. */
+ GCRY_CIPHER_MODE_CBC = 3, /* Cipher block chaining. */
+ GCRY_CIPHER_MODE_STREAM = 4, /* Used with stream ciphers. */
+ GCRY_CIPHER_MODE_OFB = 5, /* Outer feedback. */
+ GCRY_CIPHER_MODE_CTR = 6, /* Counter. */
+ GCRY_CIPHER_MODE_AESWRAP= 7 /* AES-WRAP algorithm. */
+ };
+
+/* Flags used with the open function. */
+enum gcry_cipher_flags
+ {
+ GCRY_CIPHER_SECURE = 1, /* Allocate in secure memory. */
+ GCRY_CIPHER_ENABLE_SYNC = 2, /* Enable CFB sync mode. */
+ GCRY_CIPHER_CBC_CTS = 4, /* Enable CBC cipher text stealing (CTS). */
+ GCRY_CIPHER_CBC_MAC = 8 /* Enable CBC message auth. code (MAC). */
+ };
+
+
+/* Create a handle for algorithm ALGO to be used in MODE. FLAGS may
+ be given as an bitwise OR of the gcry_cipher_flags values. */
+gcry_error_t gcry_cipher_open (gcry_cipher_hd_t *handle,
+ int algo, int mode, unsigned int flags);
+
+/* Close the cioher handle H and release all resource. */
+void gcry_cipher_close (gcry_cipher_hd_t h);
+
+/* Perform various operations on the cipher object H. */
+gcry_error_t gcry_cipher_ctl (gcry_cipher_hd_t h, int cmd, void *buffer,
+ size_t buflen);
+
+/* Retrieve various information about the cipher object H. */
+gcry_error_t gcry_cipher_info (gcry_cipher_hd_t h, int what, void *buffer,
+ size_t *nbytes);
+
+/* Retrieve various information about the cipher algorithm ALGO. */
+gcry_error_t gcry_cipher_algo_info (int algo, int what, void *buffer,
+ size_t *nbytes);
+
+/* Map the cipher algorithm whose ID is contained in ALGORITHM to a
+ string representation of the algorithm name. For unknown algorithm
+ IDs this function returns "?". */
+const char *gcry_cipher_algo_name (int algorithm) _GCRY_GCC_ATTR_PURE;
+
+/* Map the algorithm name NAME to an cipher algorithm ID. Return 0 if
+ the algorithm name is not known. */
+int gcry_cipher_map_name (const char *name) _GCRY_GCC_ATTR_PURE;
+
+/* Given an ASN.1 object identifier in standard IETF dotted decimal
+ format in STRING, return the encryption mode associated with that
+ OID or 0 if not known or applicable. */
+int gcry_cipher_mode_from_oid (const char *string) _GCRY_GCC_ATTR_PURE;
+
+/* Encrypt the plaintext of size INLEN in IN using the cipher handle H
+ into the buffer OUT which has an allocated length of OUTSIZE. For
+ most algorithms it is possible to pass NULL for in and 0 for INLEN
+ and do a in-place decryption of the data provided in OUT. */
+gcry_error_t gcry_cipher_encrypt (gcry_cipher_hd_t h,
+ void *out, size_t outsize,
+ const void *in, size_t inlen);
+
+/* The counterpart to gcry_cipher_encrypt. */
+gcry_error_t gcry_cipher_decrypt (gcry_cipher_hd_t h,
+ void *out, size_t outsize,
+ const void *in, size_t inlen);
+
+/* Set KEY of length KEYLEN bytes for the cipher handle HD. */
+gcry_error_t gcry_cipher_setkey (gcry_cipher_hd_t hd,
+ const void *key, size_t keylen);
+
+
+/* Set initialization vector IV of length IVLEN for the cipher handle HD. */
+gcry_error_t gcry_cipher_setiv (gcry_cipher_hd_t hd,
+ const void *iv, size_t ivlen);
+
+
+/* Reset the handle to the state after open. */
+#define gcry_cipher_reset(h) gcry_cipher_ctl ((h), GCRYCTL_RESET, NULL, 0)
+
+/* Perform the OpenPGP sync operation if this is enabled for the
+ cipher handle H. */
+#define gcry_cipher_sync(h) gcry_cipher_ctl( (h), GCRYCTL_CFB_SYNC, NULL, 0)
+
+/* Enable or disable CTS in future calls to gcry_encrypt(). CBC mode only. */
+#define gcry_cipher_cts(h,on) gcry_cipher_ctl( (h), GCRYCTL_SET_CBC_CTS, \
+ NULL, on )
+
+/* Set counter for CTR mode. (CTR,CTRLEN) must denote a buffer of
+ block size length, or (NULL,0) to set the CTR to the all-zero block. */
+gpg_error_t gcry_cipher_setctr (gcry_cipher_hd_t hd,
+ const void *ctr, size_t ctrlen);
+
+/* Retrieve the key length in bytes used with algorithm A. */
+size_t gcry_cipher_get_algo_keylen (int algo);
+
+/* Retrieve the block length in bytes used with algorithm A. */
+size_t gcry_cipher_get_algo_blklen (int algo);
+
+/* Return 0 if the algorithm A is available for use. */
+#define gcry_cipher_test_algo(a) \
+ gcry_cipher_algo_info( (a), GCRYCTL_TEST_ALGO, NULL, NULL )
+
+/* Get a list consisting of the IDs of the loaded cipher modules. If
+ LIST is zero, write the number of loaded cipher modules to
+ LIST_LENGTH and return. If LIST is non-zero, the first
+ *LIST_LENGTH algorithm IDs are stored in LIST, which must be of
+ according size. In case there are less cipher modules than
+ *LIST_LENGTH, *LIST_LENGTH is updated to the correct number. */
+gcry_error_t gcry_cipher_list (int *list, int *list_length);
+
+
+/************************************
+ * *
+ * Asymmetric Cipher Functions *
+ * *
+ ************************************/
+
+/* The algorithms and their IDs we support. */
+enum gcry_pk_algos
+ {
+ GCRY_PK_RSA = 1,
+ GCRY_PK_RSA_E = 2, /* (deprecated) */
+ GCRY_PK_RSA_S = 3, /* (deprecated) */
+ GCRY_PK_ELG_E = 16,
+ GCRY_PK_DSA = 17,
+ GCRY_PK_ELG = 20,
+ GCRY_PK_ECDSA = 301,
+ GCRY_PK_ECDH = 302
+ };
+
+/* Flags describing usage capabilities of a PK algorithm. */
+#define GCRY_PK_USAGE_SIGN 1 /* Good for signatures. */
+#define GCRY_PK_USAGE_ENCR 2 /* Good for encryption. */
+#define GCRY_PK_USAGE_CERT 4 /* Good to certify other keys. */
+#define GCRY_PK_USAGE_AUTH 8 /* Good for authentication. */
+#define GCRY_PK_USAGE_UNKN 128 /* Unknown usage flag. */
+
+/* Encrypt the DATA using the public key PKEY and store the result as
+ a newly created S-expression at RESULT. */
+gcry_error_t gcry_pk_encrypt (gcry_sexp_t *result,
+ gcry_sexp_t data, gcry_sexp_t pkey);
+
+/* Decrypt the DATA using the private key SKEY and store the result as
+ a newly created S-expression at RESULT. */
+gcry_error_t gcry_pk_decrypt (gcry_sexp_t *result,
+ gcry_sexp_t data, gcry_sexp_t skey);
+
+/* Sign the DATA using the private key SKEY and store the result as
+ a newly created S-expression at RESULT. */
+gcry_error_t gcry_pk_sign (gcry_sexp_t *result,
+ gcry_sexp_t data, gcry_sexp_t skey);
+
+/* Check the signature SIGVAL on DATA using the public key PKEY. */
+gcry_error_t gcry_pk_verify (gcry_sexp_t sigval,
+ gcry_sexp_t data, gcry_sexp_t pkey);
+
+/* Check that private KEY is sane. */
+gcry_error_t gcry_pk_testkey (gcry_sexp_t key);
+
+/* Generate a new key pair according to the parameters given in
+ S_PARMS. The new key pair is returned in as an S-expression in
+ R_KEY. */
+gcry_error_t gcry_pk_genkey (gcry_sexp_t *r_key, gcry_sexp_t s_parms);
+
+/* Catch all function for miscellaneous operations. */
+gcry_error_t gcry_pk_ctl (int cmd, void *buffer, size_t buflen);
+
+/* Retrieve information about the public key algorithm ALGO. */
+gcry_error_t gcry_pk_algo_info (int algo, int what,
+ void *buffer, size_t *nbytes);
+
+/* Map the public key algorithm whose ID is contained in ALGORITHM to
+ a string representation of the algorithm name. For unknown
+ algorithm IDs this functions returns "?". */
+const char *gcry_pk_algo_name (int algorithm) _GCRY_GCC_ATTR_PURE;
+
+/* Map the algorithm NAME to a public key algorithm Id. Return 0 if
+ the algorithm name is not known. */
+int gcry_pk_map_name (const char* name) _GCRY_GCC_ATTR_PURE;
+
+/* Return what is commonly referred as the key length for the given
+ public or private KEY. */
+unsigned int gcry_pk_get_nbits (gcry_sexp_t key) _GCRY_GCC_ATTR_PURE;
+
+/* Please note that keygrip is still experimental and should not be
+ used without contacting the author. */
+unsigned char *gcry_pk_get_keygrip (gcry_sexp_t key, unsigned char *array);
+
+/* Return the name of the curve matching KEY. */
+const char *gcry_pk_get_curve (gcry_sexp_t key, int iterator,
+ unsigned int *r_nbits);
+
+/* Return an S-expression with the parameters of the named ECC curve
+ NAME. ALGO must be set to an ECC algorithm. */
+gcry_sexp_t gcry_pk_get_param (int algo, const char *name);
+
+/* Return 0 if the public key algorithm A is available for use. */
+#define gcry_pk_test_algo(a) \
+ gcry_pk_algo_info( (a), GCRYCTL_TEST_ALGO, NULL, NULL )
+
+/* Get a list consisting of the IDs of the loaded pubkey modules. If
+ LIST is zero, write the number of loaded pubkey modules to
+ LIST_LENGTH and return. If LIST is non-zero, the first
+ *LIST_LENGTH algorithm IDs are stored in LIST, which must be of
+ according size. In case there are less pubkey modules than
+ *LIST_LENGTH, *LIST_LENGTH is updated to the correct number. */
+gcry_error_t gcry_pk_list (int *list, int *list_length);
+
+
+
+/************************************
+ * *
+ * Cryptograhic Hash Functions *
+ * *
+ ************************************/
+
+/* Algorithm IDs for the hash functions we know about. Not all of them
+ are implemnted. */
+enum gcry_md_algos
+ {
+ GCRY_MD_NONE = 0,
+ GCRY_MD_MD5 = 1,
+ GCRY_MD_SHA1 = 2,
+ GCRY_MD_RMD160 = 3,
+ GCRY_MD_MD2 = 5,
+ GCRY_MD_TIGER = 6, /* TIGER/192 as used by gpg <= 1.3.2. */
+ GCRY_MD_HAVAL = 7, /* HAVAL, 5 pass, 160 bit. */
+ GCRY_MD_SHA256 = 8,
+ GCRY_MD_SHA384 = 9,
+ GCRY_MD_SHA512 = 10,
+ GCRY_MD_SHA224 = 11,
+ GCRY_MD_MD4 = 301,
+ GCRY_MD_CRC32 = 302,
+ GCRY_MD_CRC32_RFC1510 = 303,
+ GCRY_MD_CRC24_RFC2440 = 304,
+ GCRY_MD_WHIRLPOOL = 305,
+ GCRY_MD_TIGER1 = 306, /* TIGER fixed. */
+ GCRY_MD_TIGER2 = 307 /* TIGER2 variant. */
+ };
+
+/* Flags used with the open function. */
+enum gcry_md_flags
+ {
+ GCRY_MD_FLAG_SECURE = 1, /* Allocate all buffers in "secure" memory. */
+ GCRY_MD_FLAG_HMAC = 2 /* Make an HMAC out of this algorithm. */
+ };
+
+/* (Forward declaration.) */
+struct gcry_md_context;
+
+/* This object is used to hold a handle to a message digest object.
+ This structure is private - only to be used by the public gcry_md_*
+ macros. */
+typedef struct gcry_md_handle
+{
+ /* Actual context. */
+ struct gcry_md_context *ctx;
+
+ /* Buffer management. */
+ int bufpos;
+ int bufsize;
+ unsigned char buf[1];
+} *gcry_md_hd_t;
+
+/* Compatibility types, do not use them. */
+#ifndef GCRYPT_NO_DEPRECATED
+typedef struct gcry_md_handle *GCRY_MD_HD _GCRY_GCC_ATTR_DEPRECATED;
+typedef struct gcry_md_handle *GcryMDHd _GCRY_GCC_ATTR_DEPRECATED;
+#endif
+
+/* Create a message digest object for algorithm ALGO. FLAGS may be
+ given as an bitwise OR of the gcry_md_flags values. ALGO may be
+ given as 0 if the algorithms to be used are later set using
+ gcry_md_enable. */
+gcry_error_t gcry_md_open (gcry_md_hd_t *h, int algo, unsigned int flags);
+
+/* Release the message digest object HD. */
+void gcry_md_close (gcry_md_hd_t hd);
+
+/* Add the message digest algorithm ALGO to the digest object HD. */
+gcry_error_t gcry_md_enable (gcry_md_hd_t hd, int algo);
+
+/* Create a new digest object as an exact copy of the object HD. */
+gcry_error_t gcry_md_copy (gcry_md_hd_t *bhd, gcry_md_hd_t ahd);
+
+/* Reset the digest object HD to its initial state. */
+void gcry_md_reset (gcry_md_hd_t hd);
+
+/* Perform various operations on the digest object HD. */
+gcry_error_t gcry_md_ctl (gcry_md_hd_t hd, int cmd,
+ void *buffer, size_t buflen);
+
+/* Pass LENGTH bytes of data in BUFFER to the digest object HD so that
+ it can update the digest values. This is the actual hash
+ function. */
+void gcry_md_write (gcry_md_hd_t hd, const void *buffer, size_t length);
+
+/* Read out the final digest from HD return the digest value for
+ algorithm ALGO. */
+unsigned char *gcry_md_read (gcry_md_hd_t hd, int algo);
+
+/* Convenience function to calculate the hash from the data in BUFFER
+ of size LENGTH using the algorithm ALGO avoiding the creating of a
+ hash object. The hash is returned in the caller provided buffer
+ DIGEST which must be large enough to hold the digest of the given
+ algorithm. */
+void gcry_md_hash_buffer (int algo, void *digest,
+ const void *buffer, size_t length);
+
+/* Retrieve the algorithm used with HD. This does not work reliable
+ if more than one algorithm is enabled in HD. */
+int gcry_md_get_algo (gcry_md_hd_t hd);
+
+/* Retrieve the length in bytes of the digest yielded by algorithm
+ ALGO. */
+unsigned int gcry_md_get_algo_dlen (int algo);
+
+/* Return true if the the algorithm ALGO is enabled in the digest
+ object A. */
+int gcry_md_is_enabled (gcry_md_hd_t a, int algo);
+
+/* Return true if the digest object A is allocated in "secure" memory. */
+int gcry_md_is_secure (gcry_md_hd_t a);
+
+/* Retrieve various information about the object H. */
+gcry_error_t gcry_md_info (gcry_md_hd_t h, int what, void *buffer,
+ size_t *nbytes);
+
+/* Retrieve various information about the algorithm ALGO. */
+gcry_error_t gcry_md_algo_info (int algo, int what, void *buffer,
+ size_t *nbytes);
+
+/* Map the digest algorithm id ALGO to a string representation of the
+ algorithm name. For unknown algorithms this function returns
+ "?". */
+const char *gcry_md_algo_name (int algo) _GCRY_GCC_ATTR_PURE;
+
+/* Map the algorithm NAME to a digest algorithm Id. Return 0 if
+ the algorithm name is not known. */
+int gcry_md_map_name (const char* name) _GCRY_GCC_ATTR_PURE;
+
+/* For use with the HMAC feature, the set MAC key to the KEY of
+ KEYLEN bytes. */
+gcry_error_t gcry_md_setkey (gcry_md_hd_t hd, const void *key, size_t keylen);
+
+/* Start or stop debugging for digest handle HD; i.e. create a file
+ named dbgmd-<n>.<suffix> while hashing. If SUFFIX is NULL,
+ debugging stops and the file will be closed. */
+void gcry_md_debug (gcry_md_hd_t hd, const char *suffix);
+
+
+/* Update the hash(s) of H with the character C. This is a buffered
+ version of the gcry_md_write function. */
+#define gcry_md_putc(h,c) \
+ do { \
+ gcry_md_hd_t h__ = (h); \
+ if( (h__)->bufpos == (h__)->bufsize ) \
+ gcry_md_write( (h__), NULL, 0 ); \
+ (h__)->buf[(h__)->bufpos++] = (c) & 0xff; \
+ } while(0)
+
+/* Finalize the digest calculation. This is not really needed because
+ gcry_md_read() does this implicitly. */
+#define gcry_md_final(a) \
+ gcry_md_ctl ((a), GCRYCTL_FINALIZE, NULL, 0)
+
+/* Return 0 if the algorithm A is available for use. */
+#define gcry_md_test_algo(a) \
+ gcry_md_algo_info( (a), GCRYCTL_TEST_ALGO, NULL, NULL )
+
+/* Return an DER encoded ASN.1 OID for the algorithm A in buffer B. N
+ must point to size_t variable with the available size of buffer B.
+ After return it will receive the actual size of the returned
+ OID. */
+#define gcry_md_get_asnoid(a,b,n) \
+ gcry_md_algo_info((a), GCRYCTL_GET_ASNOID, (b), (n))
+
+/* Enable debugging for digest object A; i.e. create files named
+ dbgmd-<n>.<string> while hashing. B is a string used as the suffix
+ for the filename. This macro is deprecated, use gcry_md_debug. */
+#ifndef GCRYPT_NO_DEPRECATED
+#define gcry_md_start_debug(a,b) \
+ gcry_md_ctl( (a), GCRYCTL_START_DUMP, (b), 0 )
+
+/* Disable the debugging of A. This macro is deprecated, use
+ gcry_md_debug. */
+#define gcry_md_stop_debug(a,b) \
+ gcry_md_ctl( (a), GCRYCTL_STOP_DUMP, (b), 0 )
+#endif
+
+/* Get a list consisting of the IDs of the loaded message digest
+ modules. If LIST is zero, write the number of loaded message
+ digest modules to LIST_LENGTH and return. If LIST is non-zero, the
+ first *LIST_LENGTH algorithm IDs are stored in LIST, which must be
+ of according size. In case there are less message digest modules
+ than *LIST_LENGTH, *LIST_LENGTH is updated to the correct
+ number. */
+gcry_error_t gcry_md_list (int *list, int *list_length);
+
+
+#if !defined(GCRYPT_NO_DEPRECATED) || defined(_GCRYPT_IN_LIBGCRYPT)
+/* Alternative interface for asymmetric cryptography. This interface
+ is deprecated. */
+
+/* The algorithm IDs. */
+typedef enum gcry_ac_id
+ {
+ GCRY_AC_RSA = 1,
+ GCRY_AC_DSA = 17,
+ GCRY_AC_ELG = 20,
+ GCRY_AC_ELG_E = 16
+ }
+gcry_ac_id_t _GCRY_ATTR_INTERNAL;
+
+/* Key types. */
+typedef enum gcry_ac_key_type
+ {
+ GCRY_AC_KEY_SECRET,
+ GCRY_AC_KEY_PUBLIC
+ }
+gcry_ac_key_type_t _GCRY_ATTR_INTERNAL;
+
+/* Encoding methods. */
+typedef enum gcry_ac_em
+ {
+ GCRY_AC_EME_PKCS_V1_5,
+ GCRY_AC_EMSA_PKCS_V1_5
+ }
+gcry_ac_em_t _GCRY_ATTR_INTERNAL;
+
+/* Encryption and Signature schemes. */
+typedef enum gcry_ac_scheme
+ {
+ GCRY_AC_ES_PKCS_V1_5,
+ GCRY_AC_SSA_PKCS_V1_5
+ }
+gcry_ac_scheme_t _GCRY_ATTR_INTERNAL;
+
+/* AC data. */
+#define GCRY_AC_FLAG_DEALLOC (1 << 0)
+#define GCRY_AC_FLAG_COPY (1 << 1)
+#define GCRY_AC_FLAG_NO_BLINDING (1 << 2)
+
+/* This type represents a `data set'. */
+typedef struct gcry_ac_data *gcry_ac_data_t _GCRY_ATTR_INTERNAL;
+
+/* This type represents a single `key', either a secret one or a
+ public one. */
+typedef struct gcry_ac_key *gcry_ac_key_t _GCRY_ATTR_INTERNAL;
+
+/* This type represents a `key pair' containing a secret and a public
+ key. */
+typedef struct gcry_ac_key_pair *gcry_ac_key_pair_t _GCRY_ATTR_INTERNAL;
+
+/* This type represents a `handle' that is needed by functions
+ performing cryptographic operations. */
+typedef struct gcry_ac_handle *gcry_ac_handle_t _GCRY_ATTR_INTERNAL;
+
+typedef gpg_error_t (*gcry_ac_data_read_cb_t) (void *opaque,
+ unsigned char *buffer,
+ size_t *buffer_n)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+typedef gpg_error_t (*gcry_ac_data_write_cb_t) (void *opaque,
+ unsigned char *buffer,
+ size_t buffer_n)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+typedef enum
+ {
+ GCRY_AC_IO_READABLE,
+ GCRY_AC_IO_WRITABLE
+ }
+gcry_ac_io_mode_t _GCRY_ATTR_INTERNAL;
+
+typedef enum
+ {
+ GCRY_AC_IO_STRING,
+ GCRY_AC_IO_CALLBACK
+ }
+gcry_ac_io_type_t _GCRY_ATTR_INTERNAL;
+
+typedef struct gcry_ac_io
+{
+ /* This is an INTERNAL structure, do NOT use manually. */
+ gcry_ac_io_mode_t mode _GCRY_ATTR_INTERNAL;
+ gcry_ac_io_type_t type _GCRY_ATTR_INTERNAL;
+ union
+ {
+ union
+ {
+ struct
+ {
+ gcry_ac_data_read_cb_t cb;
+ void *opaque;
+ } callback;
+ struct
+ {
+ unsigned char *data;
+ size_t data_n;
+ } string;
+ void *opaque;
+ } readable;
+ union
+ {
+ struct
+ {
+ gcry_ac_data_write_cb_t cb;
+ void *opaque;
+ } callback;
+ struct
+ {
+ unsigned char **data;
+ size_t *data_n;
+ } string;
+ void *opaque;
+ } writable;
+ } io _GCRY_ATTR_INTERNAL;
+}
+gcry_ac_io_t _GCRY_ATTR_INTERNAL;
+
+/* The caller of gcry_ac_key_pair_generate can provide one of these
+ structures in order to influence the key generation process in an
+ algorithm-specific way. */
+typedef struct gcry_ac_key_spec_rsa
+{
+ gcry_mpi_t e; /* E to use. */
+} gcry_ac_key_spec_rsa_t _GCRY_ATTR_INTERNAL;
+
+/* Structure used for passing data to the implementation of the
+ `EME-PKCS-V1_5' encoding method. */
+typedef struct gcry_ac_eme_pkcs_v1_5
+{
+ size_t key_size;
+} gcry_ac_eme_pkcs_v1_5_t _GCRY_ATTR_INTERNAL;
+
+typedef enum gcry_md_algos gcry_md_algo_t _GCRY_ATTR_INTERNAL;
+
+/* Structure used for passing data to the implementation of the
+ `EMSA-PKCS-V1_5' encoding method. */
+typedef struct gcry_ac_emsa_pkcs_v1_5
+{
+ gcry_md_algo_t md;
+ size_t em_n;
+} gcry_ac_emsa_pkcs_v1_5_t _GCRY_ATTR_INTERNAL;
+
+/* Structure used for passing data to the implementation of the
+ `SSA-PKCS-V1_5' signature scheme. */
+typedef struct gcry_ac_ssa_pkcs_v1_5
+{
+ gcry_md_algo_t md;
+} gcry_ac_ssa_pkcs_v1_5_t _GCRY_ATTR_INTERNAL;
+#endif /* !GCRYPT_NO_DEPRECATED || !_GCRYPT_IN_LIBGCRYPT */
+
+
+#ifndef GCRYPT_NO_DEPRECATED
+/* Returns a new, empty data set in DATA. */
+gcry_error_t gcry_ac_data_new (gcry_ac_data_t *data)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+/* Destroy the data set DATA. */
+void gcry_ac_data_destroy (gcry_ac_data_t data)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+/* Create a copy of the data set DATA and store it in DATA_CP. */
+gcry_error_t gcry_ac_data_copy (gcry_ac_data_t *data_cp,
+ gcry_ac_data_t data)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+/* Return the number of named MPI values inside of the data set
+ DATA. */
+unsigned int gcry_ac_data_length (gcry_ac_data_t data)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+/* Destroy any values contained in the data set DATA. */
+void gcry_ac_data_clear (gcry_ac_data_t data)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+/* Add the value MPI to DATA with the label NAME. If FLAGS contains
+ GCRY_AC_FLAG_DATA_COPY, the data set will contain copies of NAME
+ and MPI. If FLAGS contains GCRY_AC_FLAG_DATA_DEALLOC or
+ GCRY_AC_FLAG_DATA_COPY, the values contained in the data set will
+ be deallocated when they are to be removed from the data set. */
+gcry_error_t gcry_ac_data_set (gcry_ac_data_t data, unsigned int flags,
+ const char *name, gcry_mpi_t mpi)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+/* Store the value labelled with NAME found in DATA in MPI. If FLAGS
+ contains GCRY_AC_FLAG_COPY, store a copy of the MPI value contained
+ in the data set. MPI may be NULL. */
+gcry_error_t gcry_ac_data_get_name (gcry_ac_data_t data, unsigned int flags,
+ const char *name, gcry_mpi_t *mpi)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+/* Stores in NAME and MPI the named MPI value contained in the data
+ set DATA with the index IDX. If FLAGS contains GCRY_AC_FLAG_COPY,
+ store copies of the values contained in the data set. NAME or MPI
+ may be NULL. */
+gcry_error_t gcry_ac_data_get_index (gcry_ac_data_t data, unsigned int flags,
+ unsigned int idx,
+ const char **name, gcry_mpi_t *mpi)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+/* Convert the data set DATA into a new S-Expression, which is to be
+ stored in SEXP, according to the identifiers contained in
+ IDENTIFIERS. */
+gcry_error_t gcry_ac_data_to_sexp (gcry_ac_data_t data, gcry_sexp_t *sexp,
+ const char **identifiers)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+/* Create a new data set, which is to be stored in DATA_SET, from the
+ S-Expression SEXP, according to the identifiers contained in
+ IDENTIFIERS. */
+gcry_error_t gcry_ac_data_from_sexp (gcry_ac_data_t *data, gcry_sexp_t sexp,
+ const char **identifiers)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+/* Initialize AC_IO according to MODE, TYPE and the variable list of
+ arguments. The list of variable arguments to specify depends on
+ the given TYPE. */
+void gcry_ac_io_init (gcry_ac_io_t *ac_io, gcry_ac_io_mode_t mode,
+ gcry_ac_io_type_t type, ...)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+/* Initialize AC_IO according to MODE, TYPE and the variable list of
+ arguments AP. The list of variable arguments to specify depends on
+ the given TYPE. */
+void gcry_ac_io_init_va (gcry_ac_io_t *ac_io, gcry_ac_io_mode_t mode,
+ gcry_ac_io_type_t type, va_list ap)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+/* Create a new ac handle. */
+gcry_error_t gcry_ac_open (gcry_ac_handle_t *handle,
+ gcry_ac_id_t algorithm, unsigned int flags)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+/* Destroy an ac handle. */
+void gcry_ac_close (gcry_ac_handle_t handle)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+/* Initialize a key from a given data set. */
+gcry_error_t gcry_ac_key_init (gcry_ac_key_t *key, gcry_ac_handle_t handle,
+ gcry_ac_key_type_t type, gcry_ac_data_t data)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+/* Generates a new key pair via the handle HANDLE of NBITS bits and
+ stores it in KEY_PAIR. In case non-standard settings are wanted, a
+ pointer to a structure of type gcry_ac_key_spec_<algorithm>_t,
+ matching the selected algorithm, can be given as KEY_SPEC.
+ MISC_DATA is not used yet. */
+gcry_error_t gcry_ac_key_pair_generate (gcry_ac_handle_t handle,
+ unsigned int nbits, void *spec,
+ gcry_ac_key_pair_t *key_pair,
+ gcry_mpi_t **misc_data)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+/* Returns the key of type WHICH out of the key pair KEY_PAIR. */
+gcry_ac_key_t gcry_ac_key_pair_extract (gcry_ac_key_pair_t key_pair,
+ gcry_ac_key_type_t which)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+/* Returns the data set contained in the key KEY. */
+gcry_ac_data_t gcry_ac_key_data_get (gcry_ac_key_t key)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+/* Verifies that the key KEY is sane via HANDLE. */
+gcry_error_t gcry_ac_key_test (gcry_ac_handle_t handle, gcry_ac_key_t key)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+/* Stores the number of bits of the key KEY in NBITS via HANDLE. */
+gcry_error_t gcry_ac_key_get_nbits (gcry_ac_handle_t handle,
+ gcry_ac_key_t key, unsigned int *nbits)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+/* Writes the 20 byte long key grip of the key KEY to KEY_GRIP via
+ HANDLE. */
+gcry_error_t gcry_ac_key_get_grip (gcry_ac_handle_t handle, gcry_ac_key_t key,
+ unsigned char *key_grip)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+/* Destroy a key. */
+void gcry_ac_key_destroy (gcry_ac_key_t key)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+/* Destroy a key pair. */
+void gcry_ac_key_pair_destroy (gcry_ac_key_pair_t key_pair)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+/* Encodes a message according to the encoding method METHOD. OPTIONS
+ must be a pointer to a method-specific structure
+ (gcry_ac_em*_t). */
+gcry_error_t gcry_ac_data_encode (gcry_ac_em_t method,
+ unsigned int flags, void *options,
+ gcry_ac_io_t *io_read,
+ gcry_ac_io_t *io_write)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+/* Decodes a message according to the encoding method METHOD. OPTIONS
+ must be a pointer to a method-specific structure
+ (gcry_ac_em*_t). */
+gcry_error_t gcry_ac_data_decode (gcry_ac_em_t method,
+ unsigned int flags, void *options,
+ gcry_ac_io_t *io_read,
+ gcry_ac_io_t *io_write)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+/* Encrypt the plain text MPI value DATA_PLAIN with the key KEY under
+ the control of the flags FLAGS and store the resulting data set
+ into DATA_ENCRYPTED. */
+gcry_error_t gcry_ac_data_encrypt (gcry_ac_handle_t handle,
+ unsigned int flags,
+ gcry_ac_key_t key,
+ gcry_mpi_t data_plain,
+ gcry_ac_data_t *data_encrypted)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+/* Decrypt the decrypted data contained in the data set DATA_ENCRYPTED
+ with the key KEY under the control of the flags FLAGS and store the
+ resulting plain text MPI value in DATA_PLAIN. */
+gcry_error_t gcry_ac_data_decrypt (gcry_ac_handle_t handle,
+ unsigned int flags,
+ gcry_ac_key_t key,
+ gcry_mpi_t *data_plain,
+ gcry_ac_data_t data_encrypted)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+/* Sign the data contained in DATA with the key KEY and store the
+ resulting signature in the data set DATA_SIGNATURE. */
+gcry_error_t gcry_ac_data_sign (gcry_ac_handle_t handle,
+ gcry_ac_key_t key,
+ gcry_mpi_t data,
+ gcry_ac_data_t *data_signature)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+/* Verify that the signature contained in the data set DATA_SIGNATURE
+ is indeed the result of signing the data contained in DATA with the
+ secret key belonging to the public key KEY. */
+gcry_error_t gcry_ac_data_verify (gcry_ac_handle_t handle,
+ gcry_ac_key_t key,
+ gcry_mpi_t data,
+ gcry_ac_data_t data_signature)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+/* Encrypts the plain text readable from IO_MESSAGE through HANDLE
+ with the public key KEY according to SCHEME, FLAGS and OPTS. If
+ OPTS is not NULL, it has to be a pointer to a structure specific to
+ the chosen scheme (gcry_ac_es_*_t). The encrypted message is
+ written to IO_CIPHER. */
+gcry_error_t gcry_ac_data_encrypt_scheme (gcry_ac_handle_t handle,
+ gcry_ac_scheme_t scheme,
+ unsigned int flags, void *opts,
+ gcry_ac_key_t key,
+ gcry_ac_io_t *io_message,
+ gcry_ac_io_t *io_cipher)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+/* Decrypts the cipher text readable from IO_CIPHER through HANDLE
+ with the secret key KEY according to SCHEME, @var{flags} and OPTS.
+ If OPTS is not NULL, it has to be a pointer to a structure specific
+ to the chosen scheme (gcry_ac_es_*_t). The decrypted message is
+ written to IO_MESSAGE. */
+gcry_error_t gcry_ac_data_decrypt_scheme (gcry_ac_handle_t handle,
+ gcry_ac_scheme_t scheme,
+ unsigned int flags, void *opts,
+ gcry_ac_key_t key,
+ gcry_ac_io_t *io_cipher,
+ gcry_ac_io_t *io_message)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+/* Signs the message readable from IO_MESSAGE through HANDLE with the
+ secret key KEY according to SCHEME, FLAGS and OPTS. If OPTS is not
+ NULL, it has to be a pointer to a structure specific to the chosen
+ scheme (gcry_ac_ssa_*_t). The signature is written to
+ IO_SIGNATURE. */
+gcry_error_t gcry_ac_data_sign_scheme (gcry_ac_handle_t handle,
+ gcry_ac_scheme_t scheme,
+ unsigned int flags, void *opts,
+ gcry_ac_key_t key,
+ gcry_ac_io_t *io_message,
+ gcry_ac_io_t *io_signature)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+/* Verifies through HANDLE that the signature readable from
+ IO_SIGNATURE is indeed the result of signing the message readable
+ from IO_MESSAGE with the secret key belonging to the public key KEY
+ according to SCHEME and OPTS. If OPTS is not NULL, it has to be an
+ anonymous structure (gcry_ac_ssa_*_t) specific to the chosen
+ scheme. */
+gcry_error_t gcry_ac_data_verify_scheme (gcry_ac_handle_t handle,
+ gcry_ac_scheme_t scheme,
+ unsigned int flags, void *opts,
+ gcry_ac_key_t key,
+ gcry_ac_io_t *io_message,
+ gcry_ac_io_t *io_signature)
+ /* */ _GCRY_ATTR_INTERNAL;
+
+/* Store the textual representation of the algorithm whose id is given
+ in ALGORITHM in NAME. This function is deprecated; use
+ gcry_pk_algo_name. */
+gcry_error_t gcry_ac_id_to_name (gcry_ac_id_t algorithm,
+ const char **name)
+ /* */ _GCRY_GCC_ATTR_DEPRECATED;
+/* Store the numeric ID of the algorithm whose textual representation
+ is contained in NAME in ALGORITHM. This function is deprecated;
+ use gcry_pk_map_name. */
+gcry_error_t gcry_ac_name_to_id (const char *name,
+ gcry_ac_id_t *algorithm)
+ /* */ _GCRY_GCC_ATTR_DEPRECATED;
+#endif /*GCRYPT_NO_DEPRECATED*/
+
+
+/******************************
+ * *
+ * Key Derivation Functions *
+ * *
+ ******************************/
+
+/* Algorithm IDs for the KDFs. */
+enum gcry_kdf_algos
+ {
+ GCRY_KDF_NONE = 0,
+ GCRY_KDF_SIMPLE_S2K = 16,
+ GCRY_KDF_SALTED_S2K = 17,
+ GCRY_KDF_ITERSALTED_S2K = 19,
+ GCRY_KDF_PBKDF1 = 33,
+ GCRY_KDF_PBKDF2 = 34
+ };
+
+/* Derive a key from a passphrase. */
+gpg_error_t gcry_kdf_derive (const void *passphrase, size_t passphraselen,
+ int algo, int subalgo,
+ const void *salt, size_t saltlen,
+ unsigned long iterations,
+ size_t keysize, void *keybuffer);
+
+
+
+
+/************************************
+ * *
+ * Random Generating Functions *
+ * *
+ ************************************/
+
+/* The possible values for the random quality. The rule of thumb is
+ to use STRONG for session keys and VERY_STRONG for key material.
+ WEAK is usually an alias for STRONG and should not be used anymore
+ (except with gcry_mpi_randomize); use gcry_create_nonce instead. */
+typedef enum gcry_random_level
+ {
+ GCRY_WEAK_RANDOM = 0,
+ GCRY_STRONG_RANDOM = 1,
+ GCRY_VERY_STRONG_RANDOM = 2
+ }
+gcry_random_level_t;
+
+/* Fill BUFFER with LENGTH bytes of random, using random numbers of
+ quality LEVEL. */
+void gcry_randomize (void *buffer, size_t length,
+ enum gcry_random_level level);
+
+/* Add the external random from BUFFER with LENGTH bytes into the
+ pool. QUALITY should either be -1 for unknown or in the range of 0
+ to 100 */
+gcry_error_t gcry_random_add_bytes (const void *buffer, size_t length,
+ int quality);
+
+/* If random numbers are used in an application, this macro should be
+ called from time to time so that new stuff gets added to the
+ internal pool of the RNG. */
+#define gcry_fast_random_poll() gcry_control (GCRYCTL_FAST_POLL, NULL)
+
+
+/* Return NBYTES of allocated random using a random numbers of quality
+ LEVEL. */
+void *gcry_random_bytes (size_t nbytes, enum gcry_random_level level)
+ _GCRY_GCC_ATTR_MALLOC;
+
+/* Return NBYTES of allocated random using a random numbers of quality
+ LEVEL. The random numbers are created returned in "secure"
+ memory. */
+void *gcry_random_bytes_secure (size_t nbytes, enum gcry_random_level level)
+ _GCRY_GCC_ATTR_MALLOC;
+
+
+/* Set the big integer W to a random value of NBITS using a random
+ generator with quality LEVEL. Note that by using a level of
+ GCRY_WEAK_RANDOM gcry_create_nonce is used internally. */
+void gcry_mpi_randomize (gcry_mpi_t w,
+ unsigned int nbits, enum gcry_random_level level);
+
+
+/* Create an unpredicable nonce of LENGTH bytes in BUFFER. */
+void gcry_create_nonce (void *buffer, size_t length);
+
+
+
+
+
+/*******************************/
+/* */
+/* Prime Number Functions */
+/* */
+/*******************************/
+
+/* Mode values passed to a gcry_prime_check_func_t. */
+#define GCRY_PRIME_CHECK_AT_FINISH 0
+#define GCRY_PRIME_CHECK_AT_GOT_PRIME 1
+#define GCRY_PRIME_CHECK_AT_MAYBE_PRIME 2
+
+/* The function should return 1 if the operation shall continue, 0 to
+ reject the prime candidate. */
+typedef int (*gcry_prime_check_func_t) (void *arg, int mode,
+ gcry_mpi_t candidate);
+
+/* Flags for gcry_prime_generate(): */
+
+/* Allocate prime numbers and factors in secure memory. */
+#define GCRY_PRIME_FLAG_SECRET (1 << 0)
+
+/* Make sure that at least one prime factor is of size
+ `FACTOR_BITS'. */
+#define GCRY_PRIME_FLAG_SPECIAL_FACTOR (1 << 1)
+
+/* Generate a new prime number of PRIME_BITS bits and store it in
+ PRIME. If FACTOR_BITS is non-zero, one of the prime factors of
+ (prime - 1) / 2 must be FACTOR_BITS bits long. If FACTORS is
+ non-zero, allocate a new, NULL-terminated array holding the prime
+ factors and store it in FACTORS. FLAGS might be used to influence
+ the prime number generation process. */
+gcry_error_t gcry_prime_generate (gcry_mpi_t *prime,
+ unsigned int prime_bits,
+ unsigned int factor_bits,
+ gcry_mpi_t **factors,
+ gcry_prime_check_func_t cb_func,
+ void *cb_arg,
+ gcry_random_level_t random_level,
+ unsigned int flags);
+
+/* Find a generator for PRIME where the factorization of (prime-1) is
+ in the NULL terminated array FACTORS. Return the generator as a
+ newly allocated MPI in R_G. If START_G is not NULL, use this as
+ teh start for the search. */
+gcry_error_t gcry_prime_group_generator (gcry_mpi_t *r_g,
+ gcry_mpi_t prime,
+ gcry_mpi_t *factors,
+ gcry_mpi_t start_g);
+
+
+/* Convenience function to release the FACTORS array. */
+void gcry_prime_release_factors (gcry_mpi_t *factors);
+
+
+/* Check wether the number X is prime. */
+gcry_error_t gcry_prime_check (gcry_mpi_t x, unsigned int flags);
+
+
+
+/************************************
+ * *
+ * Miscellaneous Stuff *
+ * *
+ ************************************/
+
+/* Log levels used by the internal logging facility. */
+enum gcry_log_levels
+ {
+ GCRY_LOG_CONT = 0, /* (Continue the last log line.) */
+ GCRY_LOG_INFO = 10,
+ GCRY_LOG_WARN = 20,
+ GCRY_LOG_ERROR = 30,
+ GCRY_LOG_FATAL = 40,
+ GCRY_LOG_BUG = 50,
+ GCRY_LOG_DEBUG = 100
+ };
+
+/* Type for progress handlers. */
+typedef void (*gcry_handler_progress_t) (void *, const char *, int, int, int);
+
+/* Type for memory allocation handlers. */
+typedef void *(*gcry_handler_alloc_t) (size_t n);
+
+/* Type for secure memory check handlers. */
+typedef int (*gcry_handler_secure_check_t) (const void *);
+
+/* Type for memory reallocation handlers. */
+typedef void *(*gcry_handler_realloc_t) (void *p, size_t n);
+
+/* Type for memory free handlers. */
+typedef void (*gcry_handler_free_t) (void *);
+
+/* Type for out-of-memory handlers. */
+typedef int (*gcry_handler_no_mem_t) (void *, size_t, unsigned int);
+
+/* Type for fatal error handlers. */
+typedef void (*gcry_handler_error_t) (void *, int, const char *);
+
+/* Type for logging handlers. */
+typedef void (*gcry_handler_log_t) (void *, int, const char *, va_list);
+
+/* Certain operations can provide progress information. This function
+ is used to register a handler for retrieving these information. */
+void gcry_set_progress_handler (gcry_handler_progress_t cb, void *cb_data);
+
+
+/* Register a custom memory allocation functions. */
+void gcry_set_allocation_handler (
+ gcry_handler_alloc_t func_alloc,
+ gcry_handler_alloc_t func_alloc_secure,
+ gcry_handler_secure_check_t func_secure_check,
+ gcry_handler_realloc_t func_realloc,
+ gcry_handler_free_t func_free);
+
+/* Register a function used instead of the internal out of memory
+ handler. */
+void gcry_set_outofcore_handler (gcry_handler_no_mem_t h, void *opaque);
+
+/* Register a function used instead of the internal fatal error
+ handler. */
+void gcry_set_fatalerror_handler (gcry_handler_error_t fnc, void *opaque);
+
+/* Register a function used instead of the internal logging
+ facility. */
+void gcry_set_log_handler (gcry_handler_log_t f, void *opaque);
+
+/* Reserved for future use. */
+void gcry_set_gettext_handler (const char *(*f)(const char*));
+
+/* Libgcrypt uses its own memory allocation. It is important to use
+ gcry_free () to release memory allocated by libgcrypt. */
+void *gcry_malloc (size_t n) _GCRY_GCC_ATTR_MALLOC;
+void *gcry_calloc (size_t n, size_t m) _GCRY_GCC_ATTR_MALLOC;
+void *gcry_malloc_secure (size_t n) _GCRY_GCC_ATTR_MALLOC;
+void *gcry_calloc_secure (size_t n, size_t m) _GCRY_GCC_ATTR_MALLOC;
+void *gcry_realloc (void *a, size_t n);
+char *gcry_strdup (const char *string) _GCRY_GCC_ATTR_MALLOC;
+void *gcry_xmalloc (size_t n) _GCRY_GCC_ATTR_MALLOC;
+void *gcry_xcalloc (size_t n, size_t m) _GCRY_GCC_ATTR_MALLOC;
+void *gcry_xmalloc_secure (size_t n) _GCRY_GCC_ATTR_MALLOC;
+void *gcry_xcalloc_secure (size_t n, size_t m) _GCRY_GCC_ATTR_MALLOC;
+void *gcry_xrealloc (void *a, size_t n);
+char *gcry_xstrdup (const char * a) _GCRY_GCC_ATTR_MALLOC;
+void gcry_free (void *a);
+
+/* Return true if A is allocated in "secure" memory. */
+int gcry_is_secure (const void *a) _GCRY_GCC_ATTR_PURE;
+
+/* Return true if Libgcrypt is in FIPS mode. */
+#define gcry_fips_mode_active() !!gcry_control (GCRYCTL_FIPS_MODE_P, 0)
+
+
+/* Include support for Libgcrypt modules. */
+#include <gcrypt-module.h>
+
+#if 0 /* (Keep Emacsens' auto-indent happy.) */
+{
+#endif
+#ifdef __cplusplus
+}
+#endif
+#endif /* _GCRYPT_H */
+/*
+@emacs_local_vars_begin@
+@emacs_local_vars_read_only@
+@emacs_local_vars_end@
+*/
diff --git a/include/grub/gcrypt/gpg-error.h b/include/grub/gcrypt/gpg-error.h
new file mode 100644
index 0000000..1e42502
--- /dev/null
+++ b/include/grub/gcrypt/gpg-error.h
@@ -0,0 +1,32 @@
+#ifndef GRUB_GPG_ERROR_H
+#define GRUB_GPG_ERROR_H 1
+
+#include <grub/crypto.h>
+typedef enum
+ {
+ GPG_ERR_SOURCE_USER_1
+ }
+ gpg_err_source_t;
+#define GPG_ERR_INLINE inline
+static inline int
+gpg_err_make (gpg_err_source_t source __attribute__ ((unused)), gpg_err_code_t code)
+{
+ return code;
+}
+
+static inline gpg_err_code_t
+gpg_err_code (gpg_error_t err)
+{
+ return err;
+}
+
+static inline gpg_err_source_t
+gpg_err_source (gpg_error_t err __attribute__ ((unused)))
+{
+ return GPG_ERR_SOURCE_USER_1;
+}
+
+gcry_err_code_t
+gpg_error_from_syserror (void);
+
+#endif
diff --git a/include/grub/gdb.h b/include/grub/gdb.h
new file mode 100644
index 0000000..e73d135
--- /dev/null
+++ b/include/grub/gdb.h
@@ -0,0 +1,39 @@
+/* gdb.h - Various definitions for the remote GDB stub */
+/*
+ * Copyright (C) 2006 Lubomir Kundrak
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef GRUB_GDB_HEADER
+#define GRUB_GDB_HEADER 1
+
+#define SIGFPE 8
+#define SIGTRAP 5
+#define SIGABRT 6
+#define SIGSEGV 11
+#define SIGILL 4
+#define SIGUSR1 30
+/* We probably don't need other ones. */
+
+struct grub_serial_port;
+
+extern struct grub_serial_port *grub_gdb_port;
+
+void grub_gdb_breakpoint (void);
+unsigned int grub_gdb_trap2sig (int);
+
+#endif /* ! GRUB_GDB_HEADER */
+
diff --git a/include/grub/gfxmenu_model.h b/include/grub/gfxmenu_model.h
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/include/grub/gfxmenu_model.h
@@ -0,0 +1 @@
+
diff --git a/include/grub/gfxmenu_view.h b/include/grub/gfxmenu_view.h
new file mode 100644
index 0000000..4203c8f
--- /dev/null
+++ b/include/grub/gfxmenu_view.h
@@ -0,0 +1,124 @@
+/* gfxmenu_view.h - gfxmenu view interface. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_GFXMENU_VIEW_HEADER
+#define GRUB_GFXMENU_VIEW_HEADER 1
+
+#include <grub/types.h>
+#include <grub/err.h>
+#include <grub/menu.h>
+#include <grub/font.h>
+#include <grub/gfxwidgets.h>
+
+struct grub_gfxmenu_view; /* Forward declaration of opaque type. */
+typedef struct grub_gfxmenu_view *grub_gfxmenu_view_t;
+
+
+grub_gfxmenu_view_t grub_gfxmenu_view_new (const char *theme_path,
+ int width, int height);
+
+void grub_gfxmenu_view_destroy (grub_gfxmenu_view_t view);
+
+/* Set properties on the view based on settings from the specified
+ theme file. */
+grub_err_t grub_gfxmenu_view_load_theme (grub_gfxmenu_view_t view,
+ const char *theme_path);
+
+grub_err_t grub_gui_recreate_box (grub_gfxmenu_box_t *boxptr,
+ const char *pattern, const char *theme_dir);
+
+void grub_gfxmenu_view_draw (grub_gfxmenu_view_t view);
+
+void
+grub_gfxmenu_redraw_menu (grub_gfxmenu_view_t view);
+
+void
+grub_gfxmenu_redraw_timeout (grub_gfxmenu_view_t view);
+
+void
+grub_gfxmenu_view_redraw (grub_gfxmenu_view_t view,
+ const grub_video_rect_t *region);
+
+void
+grub_gfxmenu_clear_timeout (void *data);
+void
+grub_gfxmenu_print_timeout (int timeout, void *data);
+void
+grub_gfxmenu_set_chosen_entry (int entry, void *data);
+
+grub_err_t grub_font_draw_string (const char *str,
+ grub_font_t font,
+ grub_video_color_t color,
+ int left_x, int baseline_y);
+int grub_font_get_string_width (grub_font_t font,
+ const char *str);
+
+
+/* Implementation details -- this should not be used outside of the
+ view itself. */
+
+#include <grub/video.h>
+#include <grub/bitmap.h>
+#include <grub/bitmap_scale.h>
+#include <grub/gui.h>
+#include <grub/gfxwidgets.h>
+#include <grub/icon_manager.h>
+
+/* Definition of the private representation of the view. */
+struct grub_gfxmenu_view
+{
+ grub_video_rect_t screen;
+
+ int need_to_check_sanity;
+ grub_video_rect_t terminal_rect;
+ int terminal_border;
+
+ grub_font_t title_font;
+ grub_font_t message_font;
+ char *terminal_font_name;
+ grub_video_rgba_color_t title_color;
+ grub_video_rgba_color_t message_color;
+ grub_video_rgba_color_t message_bg_color;
+ struct grub_video_bitmap *raw_desktop_image;
+ struct grub_video_bitmap *scaled_desktop_image;
+ grub_video_bitmap_selection_method_t desktop_image_scale_method;
+ grub_video_bitmap_h_align_t desktop_image_h_align;
+ grub_video_bitmap_v_align_t desktop_image_v_align;
+ grub_video_rgba_color_t desktop_color;
+ grub_gfxmenu_box_t terminal_box;
+ char *title_text;
+ char *progress_message_text;
+ char *theme_path;
+
+ grub_gui_container_t canvas;
+
+ int double_repaint;
+
+ int selected;
+
+ grub_video_rect_t progress_message_frame;
+
+ grub_menu_t menu;
+
+ int nested;
+
+ int first_timeout;
+};
+
+#endif /* ! GRUB_GFXMENU_VIEW_HEADER */
diff --git a/include/grub/gfxterm.h b/include/grub/gfxterm.h
new file mode 100644
index 0000000..7e1ff6d
--- /dev/null
+++ b/include/grub/gfxterm.h
@@ -0,0 +1,51 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2006,2007,2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_GFXTERM_HEADER
+#define GRUB_GFXTERM_HEADER 1
+
+#include <grub/err.h>
+#include <grub/types.h>
+#include <grub/term.h>
+#include <grub/video.h>
+#include <grub/font.h>
+
+grub_err_t
+EXPORT_FUNC (grub_gfxterm_set_window) (struct grub_video_render_target *target,
+ int x, int y, int width, int height,
+ int double_repaint,
+ grub_font_t font, int border_width);
+
+void EXPORT_FUNC (grub_gfxterm_schedule_repaint) (void);
+
+extern void (*EXPORT_VAR (grub_gfxterm_decorator_hook)) (void);
+
+struct grub_gfxterm_background
+{
+ struct grub_video_bitmap *bitmap;
+ int blend_text_bg;
+ grub_video_rgba_color_t default_bg_color;
+};
+
+extern struct grub_gfxterm_background EXPORT_VAR (grub_gfxterm_background);
+
+void EXPORT_FUNC (grub_gfxterm_video_update_color) (void);
+void
+EXPORT_FUNC (grub_gfxterm_get_dimensions) (unsigned *width, unsigned *height);
+
+#endif /* ! GRUB_GFXTERM_HEADER */
diff --git a/include/grub/gfxwidgets.h b/include/grub/gfxwidgets.h
new file mode 100644
index 0000000..8ce666c
--- /dev/null
+++ b/include/grub/gfxwidgets.h
@@ -0,0 +1,50 @@
+/* gfxwidgets.h - Widgets for the graphical menu (gfxmenu). */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_GFXWIDGETS_HEADER
+#define GRUB_GFXWIDGETS_HEADER 1
+
+#include <grub/video.h>
+
+typedef struct grub_gfxmenu_box *grub_gfxmenu_box_t;
+
+struct grub_gfxmenu_box
+{
+ /* The size of the content. */
+ int content_width;
+ int content_height;
+
+ struct grub_video_bitmap **raw_pixmaps;
+ struct grub_video_bitmap **scaled_pixmaps;
+
+ void (*draw) (grub_gfxmenu_box_t self, int x, int y);
+ void (*set_content_size) (grub_gfxmenu_box_t self,
+ int width, int height);
+ int (*get_border_width) (grub_gfxmenu_box_t self);
+ int (*get_left_pad) (grub_gfxmenu_box_t self);
+ int (*get_top_pad) (grub_gfxmenu_box_t self);
+ int (*get_right_pad) (grub_gfxmenu_box_t self);
+ int (*get_bottom_pad) (grub_gfxmenu_box_t self);
+ void (*destroy) (grub_gfxmenu_box_t self);
+};
+
+grub_gfxmenu_box_t grub_gfxmenu_create_box (const char *pixmaps_prefix,
+ const char *pixmaps_suffix);
+
+#endif /* ! GRUB_GFXWIDGETS_HEADER */
diff --git a/include/grub/gpt_partition.h b/include/grub/gpt_partition.h
new file mode 100644
index 0000000..7a93f43
--- /dev/null
+++ b/include/grub/gpt_partition.h
@@ -0,0 +1,87 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2005,2006,2007,2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_GPT_PARTITION_HEADER
+#define GRUB_GPT_PARTITION_HEADER 1
+
+#include <grub/types.h>
+#include <grub/partition.h>
+
+struct grub_gpt_part_guid
+{
+ grub_uint32_t data1;
+ grub_uint16_t data2;
+ grub_uint16_t data3;
+ grub_uint8_t data4[8];
+} GRUB_PACKED;
+typedef struct grub_gpt_part_guid grub_gpt_part_guid_t;
+
+#define GRUB_GPT_PARTITION_TYPE_EMPTY \
+ { 0x0, 0x0, 0x0, \
+ { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } \
+ }
+
+#define GRUB_GPT_PARTITION_TYPE_BIOS_BOOT \
+ { grub_cpu_to_le32_compile_time (0x21686148), \
+ grub_cpu_to_le16_compile_time (0x6449), \
+ grub_cpu_to_le16_compile_time (0x6e6f), \
+ { 0x74, 0x4e, 0x65, 0x65, 0x64, 0x45, 0x46, 0x49 } \
+ }
+
+#define GRUB_GPT_PARTITION_TYPE_LDM \
+ { grub_cpu_to_le32_compile_time (0x5808C8AAU),\
+ grub_cpu_to_le16_compile_time (0x7E8F), \
+ grub_cpu_to_le16_compile_time (0x42E0), \
+ { 0x85, 0xD2, 0xE1, 0xE9, 0x04, 0x34, 0xCF, 0xB3 } \
+ }
+
+struct grub_gpt_header
+{
+ grub_uint8_t magic[8];
+ grub_uint32_t version;
+ grub_uint32_t headersize;
+ grub_uint32_t crc32;
+ grub_uint32_t unused1;
+ grub_uint64_t primary;
+ grub_uint64_t backup;
+ grub_uint64_t start;
+ grub_uint64_t end;
+ grub_uint8_t guid[16];
+ grub_uint64_t partitions;
+ grub_uint32_t maxpart;
+ grub_uint32_t partentry_size;
+ grub_uint32_t partentry_crc32;
+} GRUB_PACKED;
+
+struct grub_gpt_partentry
+{
+ grub_gpt_part_guid_t type;
+ grub_gpt_part_guid_t guid;
+ grub_uint64_t start;
+ grub_uint64_t end;
+ grub_uint64_t attrib;
+ char name[72];
+} GRUB_PACKED;
+
+grub_err_t
+grub_gpt_partition_map_iterate (grub_disk_t disk,
+ grub_partition_iterate_hook_t hook,
+ void *hook_data);
+
+
+#endif /* ! GRUB_GPT_PARTITION_HEADER */
diff --git a/include/grub/gui.h b/include/grub/gui.h
new file mode 100644
index 0000000..3657623
--- /dev/null
+++ b/include/grub/gui.h
@@ -0,0 +1,282 @@
+/* gui.h - GUI components header file. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/types.h>
+#include <grub/err.h>
+#include <grub/video.h>
+#include <grub/bitmap.h>
+#include <grub/gfxmenu_view.h>
+#include <grub/mm.h>
+
+#ifndef GRUB_GUI_H
+#define GRUB_GUI_H 1
+
+/* The component ID identifying GUI components to be updated as the timeout
+ status changes. */
+#define GRUB_GFXMENU_TIMEOUT_COMPONENT_ID "__timeout__"
+
+typedef struct grub_gui_component *grub_gui_component_t;
+typedef struct grub_gui_container *grub_gui_container_t;
+typedef struct grub_gui_list *grub_gui_list_t;
+
+typedef void (*grub_gui_component_callback) (grub_gui_component_t component,
+ void *userdata);
+
+/* Component interface. */
+
+struct grub_gui_component_ops
+{
+ void (*destroy) (void *self);
+ const char * (*get_id) (void *self);
+ int (*is_instance) (void *self, const char *type);
+ void (*paint) (void *self, const grub_video_rect_t *bounds);
+ void (*set_parent) (void *self, grub_gui_container_t parent);
+ grub_gui_container_t (*get_parent) (void *self);
+ void (*set_bounds) (void *self, const grub_video_rect_t *bounds);
+ void (*get_bounds) (void *self, grub_video_rect_t *bounds);
+ void (*get_minimal_size) (void *self, unsigned *width, unsigned *height);
+ grub_err_t (*set_property) (void *self, const char *name, const char *value);
+ void (*repaint) (void *self, int second_pass);
+};
+
+struct grub_gui_container_ops
+{
+ void (*add) (void *self, grub_gui_component_t comp);
+ void (*remove) (void *self, grub_gui_component_t comp);
+ void (*iterate_children) (void *self,
+ grub_gui_component_callback cb, void *userdata);
+};
+
+struct grub_gui_list_ops
+{
+ void (*set_view_info) (void *self,
+ grub_gfxmenu_view_t view);
+ void (*refresh_list) (void *self,
+ grub_gfxmenu_view_t view);
+};
+
+struct grub_gui_progress_ops
+{
+ void (*set_state) (void *self, int visible, int start, int current, int end);
+};
+
+typedef void (*grub_gfxmenu_set_state_t) (void *self, int visible, int start,
+ int current, int end);
+
+struct grub_gfxmenu_timeout_notify
+{
+ struct grub_gfxmenu_timeout_notify *next;
+ grub_gfxmenu_set_state_t set_state;
+ grub_gui_component_t self;
+};
+
+extern struct grub_gfxmenu_timeout_notify *grub_gfxmenu_timeout_notifications;
+
+static inline grub_err_t
+grub_gfxmenu_timeout_register (grub_gui_component_t self,
+ grub_gfxmenu_set_state_t set_state)
+{
+ struct grub_gfxmenu_timeout_notify *ne = grub_malloc (sizeof (*ne));
+ if (!ne)
+ return grub_errno;
+ ne->set_state = set_state;
+ ne->self = self;
+ ne->next = grub_gfxmenu_timeout_notifications;
+ grub_gfxmenu_timeout_notifications = ne;
+ return GRUB_ERR_NONE;
+}
+
+static inline void
+grub_gfxmenu_timeout_unregister (grub_gui_component_t self)
+{
+ struct grub_gfxmenu_timeout_notify **p, *q;
+
+ for (p = &grub_gfxmenu_timeout_notifications, q = *p;
+ q; p = &(q->next), q = q->next)
+ if (q->self == self)
+ {
+ *p = q->next;
+ grub_free (q);
+ break;
+ }
+}
+
+typedef signed grub_fixed_signed_t;
+#define GRUB_FIXED_1 0x10000
+
+/* Special care is taken to round to nearest integer and not just truncate. */
+static inline signed
+grub_divide_round (signed a, signed b)
+{
+ int neg = 0;
+ signed ret;
+ if (b < 0)
+ {
+ b = -b;
+ neg = !neg;
+ }
+ if (a < 0)
+ {
+ a = -a;
+ neg = !neg;
+ }
+ ret = (unsigned) (a + b / 2) / (unsigned) b;
+ return neg ? -ret : ret;
+}
+
+static inline signed
+grub_fixed_sfs_divide (signed a, grub_fixed_signed_t b)
+{
+ return grub_divide_round (a * GRUB_FIXED_1, b);
+}
+
+static inline grub_fixed_signed_t
+grub_fixed_fsf_divide (grub_fixed_signed_t a, signed b)
+{
+ return grub_divide_round (a, b);
+}
+
+static inline signed
+grub_fixed_sfs_multiply (signed a, grub_fixed_signed_t b)
+{
+ return (a * b) / GRUB_FIXED_1;
+}
+
+static inline signed
+grub_fixed_to_signed (grub_fixed_signed_t in)
+{
+ return in / GRUB_FIXED_1;
+}
+
+static inline grub_fixed_signed_t
+grub_signed_to_fixed (signed in)
+{
+ return in * GRUB_FIXED_1;
+}
+
+struct grub_gui_component
+{
+ struct grub_gui_component_ops *ops;
+ signed x;
+ grub_fixed_signed_t xfrac;
+ signed y;
+ grub_fixed_signed_t yfrac;
+ signed w;
+ grub_fixed_signed_t wfrac;
+ signed h;
+ grub_fixed_signed_t hfrac;
+};
+
+struct grub_gui_progress
+{
+ struct grub_gui_component component;
+ struct grub_gui_progress_ops *ops;
+};
+
+struct grub_gui_container
+{
+ struct grub_gui_component component;
+ struct grub_gui_container_ops *ops;
+};
+
+struct grub_gui_list
+{
+ struct grub_gui_component component;
+ struct grub_gui_list_ops *ops;
+};
+
+
+/* Interfaces to concrete component classes. */
+
+grub_gui_container_t grub_gui_canvas_new (void);
+grub_gui_container_t grub_gui_vbox_new (void);
+grub_gui_container_t grub_gui_hbox_new (void);
+grub_gui_component_t grub_gui_label_new (void);
+grub_gui_component_t grub_gui_image_new (void);
+grub_gui_component_t grub_gui_progress_bar_new (void);
+grub_gui_component_t grub_gui_list_new (void);
+grub_gui_component_t grub_gui_circular_progress_new (void);
+
+/* Manipulation functions. */
+
+/* Visit all components with the specified ID. */
+void grub_gui_find_by_id (grub_gui_component_t root,
+ const char *id,
+ grub_gui_component_callback cb,
+ void *userdata);
+
+/* Visit all components. */
+void grub_gui_iterate_recursively (grub_gui_component_t root,
+ grub_gui_component_callback cb,
+ void *userdata);
+
+/* Helper functions. */
+
+static __inline void
+grub_gui_save_viewport (grub_video_rect_t *r)
+{
+ grub_video_get_viewport ((unsigned *) &r->x,
+ (unsigned *) &r->y,
+ (unsigned *) &r->width,
+ (unsigned *) &r->height);
+}
+
+static __inline void
+grub_gui_restore_viewport (const grub_video_rect_t *r)
+{
+ grub_video_set_viewport (r->x, r->y, r->width, r->height);
+}
+
+/* Set a new viewport relative the the current one, saving the current
+ viewport in OLD so it can be later restored. */
+static __inline void
+grub_gui_set_viewport (const grub_video_rect_t *r, grub_video_rect_t *old)
+{
+ grub_gui_save_viewport (old);
+ grub_video_set_viewport (old->x + r->x,
+ old->y + r->y,
+ r->width,
+ r->height);
+}
+
+static inline int
+grub_video_have_common_points (const grub_video_rect_t *a,
+ const grub_video_rect_t *b)
+{
+ if (!((a->x <= b->x && b->x <= a->x + a->width)
+ || (b->x <= a->x && a->x <= b->x + b->width)))
+ return 0;
+ if (!((a->y <= b->y && b->y <= a->y + a->height)
+ || (b->y <= a->y && a->y <= b->y + b->height)))
+ return 0;
+ return 1;
+}
+
+static inline int
+grub_video_bounds_inside_region (const grub_video_rect_t *b,
+ const grub_video_rect_t *r)
+{
+ if (r->x > b->x || r->x + r->width < b->x + b->width)
+ return 0;
+ if (r->y > b->y || r->y + r->height < b->y + b->height)
+ return 0;
+ return 1;
+}
+
+#endif /* ! GRUB_GUI_H */
diff --git a/include/grub/gui_string_util.h b/include/grub/gui_string_util.h
new file mode 100644
index 0000000..34f9a09
--- /dev/null
+++ b/include/grub/gui_string_util.h
@@ -0,0 +1,33 @@
+/* gui_string_util.h - String utilities for the graphical menu interface. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_GUI_STRING_UTIL_HEADER
+#define GRUB_GUI_STRING_UTIL_HEADER 1
+
+#include <grub/types.h>
+#include <grub/gui.h>
+
+char *grub_new_substring (const char *buf,
+ grub_size_t start, grub_size_t end);
+
+char *grub_resolve_relative_path (const char *base, const char *path);
+
+char *grub_get_dirname (const char *file_path);
+
+#endif /* GRUB_GUI_STRING_UTIL_HEADER */
diff --git a/include/grub/hfs.h b/include/grub/hfs.h
new file mode 100644
index 0000000..e27993c
--- /dev/null
+++ b/include/grub/hfs.h
@@ -0,0 +1,72 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2005,2006,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_HFS_HEADER
+#define GRUB_HFS_HEADER 1
+
+#include <grub/types.h>
+
+#define GRUB_HFS_MAGIC 0x4244
+
+/* A single extent. A file consists of one or more extents. */
+struct grub_hfs_extent
+{
+ /* The first physical block. */
+ grub_uint16_t first_block;
+ grub_uint16_t count;
+} GRUB_PACKED;
+
+/* HFS stores extents in groups of 3. */
+typedef struct grub_hfs_extent grub_hfs_datarecord_t[3];
+
+/* The HFS superblock (The official name is `Master Directory
+ Block'). */
+struct grub_hfs_sblock
+{
+ grub_uint16_t magic;
+ grub_uint32_t ctime;
+ grub_uint32_t mtime;
+ grub_uint8_t unused[10];
+ grub_uint32_t blksz;
+ grub_uint8_t unused2[4];
+ grub_uint16_t first_block;
+ grub_uint8_t unused4[6];
+
+ /* A pascal style string that holds the volumename. */
+ grub_uint8_t volname[28];
+
+ grub_uint8_t unused5[28];
+
+ grub_uint32_t ppc_bootdir;
+ grub_uint32_t intel_bootfile;
+ /* Folder opened when disk is mounted. Unused by GRUB. */
+ grub_uint32_t showfolder;
+ grub_uint32_t os9folder;
+ grub_uint8_t unused6[4];
+ grub_uint32_t osxfolder;
+
+ grub_uint64_t num_serial;
+ grub_uint16_t embed_sig;
+ struct grub_hfs_extent embed_extent;
+ grub_uint8_t unused7[4];
+ grub_hfs_datarecord_t extent_recs;
+ grub_uint32_t catalog_size;
+ grub_hfs_datarecord_t catalog_recs;
+} GRUB_PACKED;
+
+#endif /* ! GRUB_HFS_HEADER */
diff --git a/include/grub/hfsplus.h b/include/grub/hfsplus.h
new file mode 100644
index 0000000..e14dd31
--- /dev/null
+++ b/include/grub/hfsplus.h
@@ -0,0 +1,259 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2005,2006,2007,2008,2009,2012,2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/types.h>
+#include <grub/disk.h>
+
+#define GRUB_HFSPLUS_MAGIC 0x482B
+#define GRUB_HFSPLUSX_MAGIC 0x4858
+#define GRUB_HFSPLUS_SBLOCK 2
+
+/* A HFS+ extent. */
+struct grub_hfsplus_extent
+{
+ /* The first block of a file on disk. */
+ grub_uint32_t start;
+ /* The amount of blocks described by this extent. */
+ grub_uint32_t count;
+} GRUB_PACKED;
+
+/* The descriptor of a fork. */
+struct grub_hfsplus_forkdata
+{
+ grub_uint64_t size;
+ grub_uint32_t clumpsize;
+ grub_uint32_t blocks;
+ struct grub_hfsplus_extent extents[8];
+} GRUB_PACKED;
+
+/* The HFS+ Volume Header. */
+struct grub_hfsplus_volheader
+{
+ grub_uint16_t magic;
+ grub_uint16_t version;
+ grub_uint32_t attributes;
+ grub_uint8_t unused1[12];
+ grub_uint32_t utime;
+ grub_uint8_t unused2[16];
+ grub_uint32_t blksize;
+ grub_uint8_t unused3[36];
+
+ grub_uint32_t ppc_bootdir;
+ grub_uint32_t intel_bootfile;
+ /* Folder opened when disk is mounted. Unused by GRUB. */
+ grub_uint32_t showfolder;
+ grub_uint32_t os9folder;
+ grub_uint8_t unused4[4];
+ grub_uint32_t osxfolder;
+
+ grub_uint64_t num_serial;
+ struct grub_hfsplus_forkdata allocations_file;
+ struct grub_hfsplus_forkdata extents_file;
+ struct grub_hfsplus_forkdata catalog_file;
+ struct grub_hfsplus_forkdata attr_file;
+ struct grub_hfsplus_forkdata startup_file;
+} GRUB_PACKED;
+
+struct grub_hfsplus_compress_index
+{
+ grub_uint32_t start;
+ grub_uint32_t size;
+};
+
+struct grub_hfsplus_file
+{
+ struct grub_hfsplus_data *data;
+ struct grub_hfsplus_extent extents[8];
+ struct grub_hfsplus_extent resource_extents[8];
+ grub_uint64_t size;
+ grub_uint64_t resource_size;
+ grub_uint32_t fileid;
+ grub_int32_t mtime;
+ int compressed;
+ char *cbuf;
+ void *file;
+ struct grub_hfsplus_compress_index *compress_index;
+ grub_uint32_t cbuf_block;
+ grub_uint32_t compress_index_size;
+};
+
+struct grub_hfsplus_btree
+{
+ grub_uint32_t root;
+ grub_size_t nodesize;
+
+ /* Catalog file node. */
+ struct grub_hfsplus_file file;
+};
+
+/* Information about a "mounted" HFS+ filesystem. */
+struct grub_hfsplus_data
+{
+ struct grub_hfsplus_volheader volheader;
+ grub_disk_t disk;
+
+ unsigned int log2blksize;
+
+ struct grub_hfsplus_btree catalog_tree;
+ struct grub_hfsplus_btree extoverflow_tree;
+ struct grub_hfsplus_btree attr_tree;
+
+ int extoverflow_tree_ready;
+
+ struct grub_hfsplus_file dirroot;
+ struct grub_hfsplus_file opened_file;
+
+ /* This is the offset into the physical disk for an embedded HFS+
+ filesystem (one inside a plain HFS wrapper). */
+ grub_disk_addr_t embedded_offset;
+ int case_sensitive;
+};
+
+/* Internal representation of a catalog key. */
+struct grub_hfsplus_catkey_internal
+{
+ grub_uint32_t parent;
+ const grub_uint16_t *name;
+ grub_size_t namelen;
+};
+
+/* Internal representation of an extent overflow key. */
+struct grub_hfsplus_extkey_internal
+{
+ grub_uint32_t fileid;
+ grub_uint32_t start;
+ grub_uint8_t type;
+};
+
+struct grub_hfsplus_attrkey
+{
+ grub_uint16_t keylen;
+ grub_uint16_t unknown1[1];
+ grub_uint32_t cnid;
+ grub_uint16_t unknown2[2];
+ grub_uint16_t namelen;
+ grub_uint16_t name[0];
+} GRUB_PACKED;
+
+struct grub_hfsplus_attrkey_internal
+{
+ grub_uint32_t cnid;
+ const grub_uint16_t *name;
+ grub_size_t namelen;
+};
+
+struct grub_hfsplus_key_internal
+{
+ union
+ {
+ struct grub_hfsplus_extkey_internal extkey;
+ struct grub_hfsplus_catkey_internal catkey;
+ struct grub_hfsplus_attrkey_internal attrkey;
+ };
+};
+
+/* The on disk layout of a catalog key. */
+struct grub_hfsplus_catkey
+{
+ grub_uint16_t keylen;
+ grub_uint32_t parent;
+ grub_uint16_t namelen;
+ grub_uint16_t name[0];
+} GRUB_PACKED;
+
+/* The on disk layout of an extent overflow file key. */
+struct grub_hfsplus_extkey
+{
+ grub_uint16_t keylen;
+ grub_uint8_t type;
+ grub_uint8_t unused;
+ grub_uint32_t fileid;
+ grub_uint32_t start;
+} GRUB_PACKED;
+
+struct grub_hfsplus_key
+{
+ union
+ {
+ struct grub_hfsplus_extkey extkey;
+ struct grub_hfsplus_catkey catkey;
+ struct grub_hfsplus_attrkey attrkey;
+ grub_uint16_t keylen;
+ };
+} GRUB_PACKED;
+
+struct grub_hfsplus_btnode
+{
+ grub_uint32_t next;
+ grub_uint32_t prev;
+ grub_int8_t type;
+ grub_uint8_t height;
+ grub_uint16_t count;
+ grub_uint16_t unused;
+} GRUB_PACKED;
+
+/* Return the offset of the record with the index INDEX, in the node
+ NODE which is part of the B+ tree BTREE. */
+static inline grub_uint16_t
+grub_hfsplus_btree_recoffset (struct grub_hfsplus_btree *btree,
+ struct grub_hfsplus_btnode *node, unsigned index)
+{
+ char *cnode = (char *) node;
+ void *recptr;
+ if (btree->nodesize < index * sizeof (grub_uint16_t) + 2)
+ index = 0;
+ recptr = (&cnode[btree->nodesize - index * sizeof (grub_uint16_t) - 2]);
+ return grub_be_to_cpu16 (grub_get_unaligned16 (recptr));
+}
+
+/* Return a pointer to the record with the index INDEX, in the node
+ NODE which is part of the B+ tree BTREE. */
+static inline struct grub_hfsplus_key *
+grub_hfsplus_btree_recptr (struct grub_hfsplus_btree *btree,
+ struct grub_hfsplus_btnode *node, unsigned index)
+{
+ char *cnode = (char *) node;
+ grub_uint16_t offset;
+ offset = grub_hfsplus_btree_recoffset (btree, node, index);
+ if (offset > btree->nodesize - sizeof (struct grub_hfsplus_key))
+ offset = 0;
+ return (struct grub_hfsplus_key *) &cnode[offset];
+}
+
+extern grub_err_t (*grub_hfsplus_open_compressed) (struct grub_hfsplus_file *node);
+extern grub_ssize_t (*grub_hfsplus_read_compressed) (struct grub_hfsplus_file *node,
+ grub_off_t pos,
+ grub_size_t len,
+ char *buf);
+
+grub_ssize_t
+grub_hfsplus_read_file (struct grub_hfsplus_file *node,
+ grub_disk_read_hook_t read_hook, void *read_hook_data,
+ grub_off_t pos, grub_size_t len, char *buf);
+grub_err_t
+grub_hfsplus_btree_search (struct grub_hfsplus_btree *btree,
+ struct grub_hfsplus_key_internal *key,
+ int (*compare_keys) (struct grub_hfsplus_key *keya,
+ struct grub_hfsplus_key_internal *keyb),
+ struct grub_hfsplus_btnode **matchnode,
+ grub_off_t *keyoffset);
+grub_err_t
+grub_mac_bless_inode (grub_device_t dev, grub_uint32_t inode, int is_dir,
+ int intel);
+grub_err_t
+grub_mac_bless_file (grub_device_t dev, const char *path_in, int intel);
diff --git a/include/grub/i18n.h b/include/grub/i18n.h
new file mode 100644
index 0000000..468602d
--- /dev/null
+++ b/include/grub/i18n.h
@@ -0,0 +1,68 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009,2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_I18N_H
+#define GRUB_I18N_H 1
+
+#include <config.h>
+#include <grub/symbol.h>
+
+/* NLS can be disabled through the configure --disable-nls option. */
+#if (defined(ENABLE_NLS) && ENABLE_NLS) || !defined (GRUB_UTIL)
+
+extern const char *(*EXPORT_VAR(grub_gettext)) (const char *s) __attribute__ ((format_arg (1)));
+
+# ifdef GRUB_UTIL
+
+# include <locale.h>
+# include <libintl.h>
+
+# endif /* GRUB_UTIL */
+
+#else /* ! (defined(ENABLE_NLS) && ENABLE_NLS) */
+
+/* Disabled NLS.
+ The casts to 'const char *' serve the purpose of producing warnings
+ for invalid uses of the value returned from these functions.
+ On pre-ANSI systems without 'const', the config.h file is supposed to
+ contain "#define const". */
+static inline const char * __attribute__ ((always_inline,format_arg (1)))
+gettext (const char *str)
+{
+ return str;
+}
+
+#endif /* (defined(ENABLE_NLS) && ENABLE_NLS) */
+
+#ifdef GRUB_UTIL
+static inline const char * __attribute__ ((always_inline,format_arg (1)))
+_ (const char *str)
+{
+ return gettext(str);
+}
+#else
+static inline const char * __attribute__ ((always_inline,format_arg (1)))
+_ (const char *str)
+{
+ return grub_gettext(str);
+}
+#endif /* GRUB_UTIL */
+
+#define N_(str) str
+
+#endif /* GRUB_I18N_H */
diff --git a/include/grub/i386/at_keyboard.h b/include/grub/i386/at_keyboard.h
new file mode 100644
index 0000000..da4e806
--- /dev/null
+++ b/include/grub/i386/at_keyboard.h
@@ -0,0 +1,25 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_CPU_AT_KEYBOARD_HEADER
+#define GRUB_CPU_AT_KEYBOARD_HEADER 1
+
+#define KEYBOARD_REG_DATA 0x60
+#define KEYBOARD_REG_STATUS 0x64
+
+#endif
diff --git a/include/grub/i386/bsd.h b/include/grub/i386/bsd.h
new file mode 100644
index 0000000..524d47a
--- /dev/null
+++ b/include/grub/i386/bsd.h
@@ -0,0 +1,128 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_BSD_CPU_HEADER
+#define GRUB_BSD_CPU_HEADER 1
+
+#include <grub/types.h>
+#include <grub/relocator.h>
+
+#include <grub/i386/freebsd_reboot.h>
+#include <grub/i386/netbsd_reboot.h>
+#include <grub/i386/openbsd_reboot.h>
+#include <grub/i386/freebsd_linker.h>
+#include <grub/i386/netbsd_bootinfo.h>
+#include <grub/i386/openbsd_bootarg.h>
+
+enum bsd_kernel_types
+ {
+ KERNEL_TYPE_NONE,
+ KERNEL_TYPE_FREEBSD,
+ KERNEL_TYPE_OPENBSD,
+ KERNEL_TYPE_NETBSD,
+ };
+
+#define GRUB_BSD_TEMP_BUFFER 0x80000
+
+#define FREEBSD_B_DEVMAGIC OPENBSD_B_DEVMAGIC
+#define FREEBSD_B_SLICESHIFT OPENBSD_B_CTRLSHIFT
+#define FREEBSD_B_UNITSHIFT OPENBSD_B_UNITSHIFT
+#define FREEBSD_B_PARTSHIFT OPENBSD_B_PARTSHIFT
+#define FREEBSD_B_TYPESHIFT OPENBSD_B_TYPESHIFT
+
+#define FREEBSD_MODTYPE_KERNEL "elf kernel"
+#define FREEBSD_MODTYPE_KERNEL64 "elf64 kernel"
+#define FREEBSD_MODTYPE_ELF_MODULE "elf module"
+#define FREEBSD_MODTYPE_ELF_MODULE_OBJ "elf obj module"
+#define FREEBSD_MODTYPE_RAW "raw"
+
+#define FREEBSD_BOOTINFO_VERSION 1
+
+struct grub_freebsd_bootinfo
+{
+ grub_uint32_t version;
+ grub_uint8_t unused1[44];
+ grub_uint32_t length;
+ grub_uint8_t unused2;
+ grub_uint8_t boot_device;
+ grub_uint8_t unused3[18];
+ grub_uint32_t kern_end;
+ grub_uint32_t environment;
+ grub_uint32_t tags;
+} GRUB_PACKED;
+
+struct freebsd_tag_header
+{
+ grub_uint32_t type;
+ grub_uint32_t len;
+};
+
+grub_err_t grub_freebsd_load_elfmodule32 (struct grub_relocator *relocator,
+ grub_file_t file, int argc,
+ char *argv[], grub_addr_t *kern_end);
+grub_err_t grub_freebsd_load_elfmodule_obj64 (struct grub_relocator *relocator,
+ grub_file_t file, int argc,
+ char *argv[],
+ grub_addr_t *kern_end);
+grub_err_t grub_freebsd_load_elf_meta32 (struct grub_relocator *relocator,
+ grub_file_t file,
+ const char *filename,
+ grub_addr_t *kern_end);
+grub_err_t grub_freebsd_load_elf_meta64 (struct grub_relocator *relocator,
+ grub_file_t file,
+ const char *filename,
+ grub_addr_t *kern_end);
+
+grub_err_t grub_netbsd_load_elf_meta32 (struct grub_relocator *relocator,
+ grub_file_t file,
+ const char *filename,
+ grub_addr_t *kern_end);
+grub_err_t grub_netbsd_load_elf_meta64 (struct grub_relocator *relocator,
+ grub_file_t file,
+ const char *filename,
+ grub_addr_t *kern_end);
+
+grub_err_t grub_bsd_add_meta (grub_uint32_t type,
+ const void *data, grub_uint32_t len);
+grub_err_t grub_freebsd_add_meta_module (const char *filename, const char *type,
+ int argc, char **argv,
+ grub_addr_t addr, grub_uint32_t size);
+
+struct grub_openbsd_ramdisk_descriptor
+{
+ grub_size_t max_size;
+ grub_uint8_t *target;
+ grub_uint32_t *size;
+};
+
+grub_err_t grub_openbsd_find_ramdisk32 (grub_file_t file,
+ const char *filename,
+ grub_addr_t kern_start,
+ void *kern_chunk_src,
+ struct grub_openbsd_ramdisk_descriptor *desc);
+grub_err_t grub_openbsd_find_ramdisk64 (grub_file_t file,
+ const char *filename,
+ grub_addr_t kern_start,
+ void *kern_chunk_src,
+ struct grub_openbsd_ramdisk_descriptor *desc);
+
+extern grub_uint8_t grub_bsd64_trampoline_start, grub_bsd64_trampoline_end;
+extern grub_uint32_t grub_bsd64_trampoline_selfjump;
+extern grub_uint32_t grub_bsd64_trampoline_gdt;
+
+#endif /* ! GRUB_BSD_CPU_HEADER */
diff --git a/include/grub/i386/cmos.h b/include/grub/i386/cmos.h
new file mode 100644
index 0000000..27a2b21
--- /dev/null
+++ b/include/grub/i386/cmos.h
@@ -0,0 +1,30 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_CPU_CMOS_H
+#define GRUB_CPU_CMOS_H 1
+
+#include <grub/types.h>
+#include <grub/cpu/io.h>
+
+#define GRUB_CMOS_ADDR_REG 0x70
+#define GRUB_CMOS_DATA_REG 0x71
+#define GRUB_CMOS_ADDR_REG_HI 0x72
+#define GRUB_CMOS_DATA_REG_HI 0x73
+
+#endif /* GRUB_CPU_CMOS_H */
diff --git a/include/grub/i386/coreboot/boot.h b/include/grub/i386/coreboot/boot.h
new file mode 100644
index 0000000..6cd23aa
--- /dev/null
+++ b/include/grub/i386/coreboot/boot.h
@@ -0,0 +1 @@
+#include <grub/i386/pc/boot.h>
diff --git a/include/grub/i386/coreboot/console.h b/include/grub/i386/coreboot/console.h
new file mode 100644
index 0000000..9cfa247
--- /dev/null
+++ b/include/grub/i386/coreboot/console.h
@@ -0,0 +1,32 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MACHINE_CONSOLE_HEADER
+#define GRUB_MACHINE_CONSOLE_HEADER 1
+
+void grub_vga_text_init (void);
+void grub_vga_text_fini (void);
+
+void grub_video_coreboot_fb_init (void);
+void grub_video_coreboot_fb_early_init (void);
+void grub_video_coreboot_fb_late_init (void);
+void grub_video_coreboot_fb_fini (void);
+
+extern struct grub_linuxbios_table_framebuffer *grub_video_coreboot_fbtable;
+
+#endif /* ! GRUB_MACHINE_CONSOLE_HEADER */
diff --git a/include/grub/i386/coreboot/kernel.h b/include/grub/i386/coreboot/kernel.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/include/grub/i386/coreboot/kernel.h
diff --git a/include/grub/i386/coreboot/memory.h b/include/grub/i386/coreboot/memory.h
new file mode 100644
index 0000000..1501772
--- /dev/null
+++ b/include/grub/i386/coreboot/memory.h
@@ -0,0 +1,54 @@
+/* memory.h - describe the memory map */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _GRUB_MEMORY_MACHINE_LB_HEADER
+#define _GRUB_MEMORY_MACHINE_LB_HEADER 1
+
+#include <grub/symbol.h>
+
+#ifndef ASM_FILE
+#include <grub/err.h>
+#include <grub/types.h>
+#include <grub/memory.h>
+#endif
+
+#include <grub/i386/memory.h>
+#include <grub/i386/memory_raw.h>
+
+#ifndef ASM_FILE
+
+void grub_machine_mmap_init (void);
+
+static inline grub_err_t
+grub_machine_mmap_register (grub_uint64_t start __attribute__ ((unused)),
+ grub_uint64_t size __attribute__ ((unused)),
+ int type __attribute__ ((unused)),
+ int handle __attribute__ ((unused)))
+{
+ return GRUB_ERR_NONE;
+}
+static inline grub_err_t
+grub_machine_mmap_unregister (int handle __attribute__ ((unused)))
+{
+ return GRUB_ERR_NONE;
+}
+
+#endif
+
+#endif /* ! _GRUB_MEMORY_MACHINE_HEADER */
diff --git a/include/grub/i386/coreboot/serial.h b/include/grub/i386/coreboot/serial.h
new file mode 100644
index 0000000..b6819d5
--- /dev/null
+++ b/include/grub/i386/coreboot/serial.h
@@ -0,0 +1,24 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MACHINE_SERIAL_HEADER
+#define GRUB_MACHINE_SERIAL_HEADER 1
+
+#define GRUB_MACHINE_SERIAL_PORTS { 0x3f8, 0x2f8, 0x3e8, 0x2e8 }
+
+#endif
diff --git a/include/grub/i386/coreboot/time.h b/include/grub/i386/coreboot/time.h
new file mode 100644
index 0000000..2298ee8
--- /dev/null
+++ b/include/grub/i386/coreboot/time.h
@@ -0,0 +1 @@
+#include <grub/i386/pc/time.h>
diff --git a/include/grub/i386/cpuid.h b/include/grub/i386/cpuid.h
new file mode 100644
index 0000000..f7ae4b0
--- /dev/null
+++ b/include/grub/i386/cpuid.h
@@ -0,0 +1,85 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_CPU_CPUID_HEADER
+#define GRUB_CPU_CPUID_HEADER 1
+
+extern unsigned char grub_cpuid_has_longmode;
+extern unsigned char grub_cpuid_has_pae;
+
+#ifdef __x86_64__
+
+static __inline int
+grub_cpu_is_cpuid_supported (void)
+{
+ grub_uint64_t id_supported;
+
+ __asm__ ("pushfq\n\t"
+ "popq %%rax /* Get EFLAGS into EAX */\n\t"
+ "movq %%rax, %%rcx /* Save original flags in ECX */\n\t"
+ "xorq $0x200000, %%rax /* Flip ID bit in EFLAGS */\n\t"
+ "pushq %%rax /* Store modified EFLAGS on stack */\n\t"
+ "popfq /* Replace current EFLAGS */\n\t"
+ "pushfq /* Read back the EFLAGS */\n\t"
+ "popq %%rax /* Get EFLAGS into EAX */\n\t"
+ "xorq %%rcx, %%rax /* Check if flag could be modified */\n\t"
+ : "=a" (id_supported)
+ : /* No inputs. */
+ : /* Clobbered: */ "%rcx");
+
+ return id_supported != 0;
+}
+
+#else
+
+static __inline int
+grub_cpu_is_cpuid_supported (void)
+{
+ grub_uint32_t id_supported;
+
+ __asm__ ("pushfl\n\t"
+ "popl %%eax /* Get EFLAGS into EAX */\n\t"
+ "movl %%eax, %%ecx /* Save original flags in ECX */\n\t"
+ "xorl $0x200000, %%eax /* Flip ID bit in EFLAGS */\n\t"
+ "pushl %%eax /* Store modified EFLAGS on stack */\n\t"
+ "popfl /* Replace current EFLAGS */\n\t"
+ "pushfl /* Read back the EFLAGS */\n\t"
+ "popl %%eax /* Get EFLAGS into EAX */\n\t"
+ "xorl %%ecx, %%eax /* Check if flag could be modified */\n\t"
+ : "=a" (id_supported)
+ : /* No inputs. */
+ : /* Clobbered: */ "%rcx");
+
+ return id_supported != 0;
+}
+
+#endif
+
+#ifdef __PIC__
+#define grub_cpuid(num,a,b,c,d) \
+ asm volatile ("xchgl %%ebx, %1; cpuid; xchgl %%ebx, %1" \
+ : "=a" (a), "=r" (b), "=c" (c), "=d" (d) \
+ : "0" (num))
+#else
+#define grub_cpuid(num,a,b,c,d) \
+ asm volatile ("cpuid" \
+ : "=a" (a), "=b" (b), "=c" (c), "=d" (d) \
+ : "0" (num))
+#endif
+
+#endif
diff --git a/include/grub/i386/efi/kernel.h b/include/grub/i386/efi/kernel.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/include/grub/i386/efi/kernel.h
diff --git a/include/grub/i386/efi/memory.h b/include/grub/i386/efi/memory.h
new file mode 100644
index 0000000..2c64918
--- /dev/null
+++ b/include/grub/i386/efi/memory.h
@@ -0,0 +1,6 @@
+#ifndef GRUB_MEMORY_CPU_HEADER
+#include <grub/efi/memory.h>
+
+#define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffff
+
+#endif /* ! GRUB_MEMORY_CPU_HEADER */
diff --git a/include/grub/i386/efi/serial.h b/include/grub/i386/efi/serial.h
new file mode 100644
index 0000000..2d85634
--- /dev/null
+++ b/include/grub/i386/efi/serial.h
@@ -0,0 +1 @@
+#include <grub/i386/coreboot/serial.h>
diff --git a/include/grub/i386/efiemu.h b/include/grub/i386/efiemu.h
new file mode 100644
index 0000000..edb13ff
--- /dev/null
+++ b/include/grub/i386/efiemu.h
@@ -0,0 +1,33 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_ARCH_EFI_EMU_HEADER
+#define GRUB_ARCH_EFI_EMU_HEADER 1
+
+grub_err_t
+grub_arch_efiemu_relocate_symbols32 (grub_efiemu_segment_t segs,
+ struct grub_efiemu_elf_sym *elfsyms,
+ void *ehdr);
+grub_err_t
+grub_arch_efiemu_relocate_symbols64 (grub_efiemu_segment_t segs,
+ struct grub_efiemu_elf_sym *elfsyms,
+ void *ehdr);
+
+int grub_arch_efiemu_check_header32 (void *ehdr);
+int grub_arch_efiemu_check_header64 (void *ehdr);
+#endif
diff --git a/include/grub/i386/floppy.h b/include/grub/i386/floppy.h
new file mode 100644
index 0000000..0e36905
--- /dev/null
+++ b/include/grub/i386/floppy.h
@@ -0,0 +1,36 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_FLOPPY_CPU_HEADER
+#define GRUB_FLOPPY_CPU_HEADER 1
+
+#define GRUB_FLOPPY_REG_DIGITAL_OUTPUT 0x3f2
+
+#ifndef ASM_FILE
+#include <grub/cpu/io.h>
+
+/* Stop the floppy drive from spinning, so that other software is
+ jumped to with a known state. */
+static inline void
+grub_stop_floppy (void)
+{
+ grub_outb (0, GRUB_FLOPPY_REG_DIGITAL_OUTPUT);
+}
+#endif
+
+#endif
diff --git a/include/grub/i386/freebsd_linker.h b/include/grub/i386/freebsd_linker.h
new file mode 100644
index 0000000..3c1eb64
--- /dev/null
+++ b/include/grub/i386/freebsd_linker.h
@@ -0,0 +1,74 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*-
+ * Copyright (c) 1997-2000 Doug Rabson
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: stable/8/sys/sys/linker.h 199583 2009-11-20 15:27:52Z jhb $
+ */
+
+#ifndef GRUB_FREEBSD_LINKER_CPU_HEADER
+#define GRUB_FREEBSD_LINKER_CPU_HEADER 1
+
+#define FREEBSD_MODINFO_END 0x0000 /* End of list */
+#define FREEBSD_MODINFO_NAME 0x0001 /* Name of module (string) */
+#define FREEBSD_MODINFO_TYPE 0x0002 /* Type of module (string) */
+#define FREEBSD_MODINFO_ADDR 0x0003 /* Loaded address */
+#define FREEBSD_MODINFO_SIZE 0x0004 /* Size of module */
+#define FREEBSD_MODINFO_EMPTY 0x0005 /* Has been deleted */
+#define FREEBSD_MODINFO_ARGS 0x0006 /* Parameters string */
+#define FREEBSD_MODINFO_METADATA 0x8000 /* Module-specfic */
+
+#define FREEBSD_MODINFOMD_AOUTEXEC 0x0001 /* a.out exec header */
+#define FREEBSD_MODINFOMD_ELFHDR 0x0002 /* ELF header */
+#define FREEBSD_MODINFOMD_SSYM 0x0003 /* start of symbols */
+#define FREEBSD_MODINFOMD_ESYM 0x0004 /* end of symbols */
+#define FREEBSD_MODINFOMD_DYNAMIC 0x0005 /* _DYNAMIC pointer */
+#define FREEBSD_MODINFOMD_ENVP 0x0006 /* envp[] */
+#define FREEBSD_MODINFOMD_HOWTO 0x0007 /* boothowto */
+#define FREEBSD_MODINFOMD_KERNEND 0x0008 /* kernend */
+#define FREEBSD_MODINFOMD_SHDR 0x0009 /* section header table */
+#define FREEBSD_MODINFOMD_NOCOPY 0x8000 /* don't copy this metadata to the kernel */
+
+#define FREEBSD_MODINFOMD_SMAP 0x1001
+
+#define FREEBSD_MODINFOMD_DEPLIST (0x4001 | FREEBSD_MODINFOMD_NOCOPY) /* depends on */
+
+#endif
diff --git a/include/grub/i386/freebsd_reboot.h b/include/grub/i386/freebsd_reboot.h
new file mode 100644
index 0000000..9c17f6e
--- /dev/null
+++ b/include/grub/i386/freebsd_reboot.h
@@ -0,0 +1,77 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*-
+ * Copyright (c) 1982, 1986, 1988, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)reboot.h 8.3 (Berkeley) 12/13/94
+ * $FreeBSD: stable/8/sys/sys/reboot.h 199583 2009-11-20 15:27:52Z jhb $
+ */
+
+#ifndef GRUB_FREEBSD_REBOOT_CPU_HEADER
+#define GRUB_FREEBSD_REBOOT_CPU_HEADER 1
+
+#define FREEBSD_RB_ASKNAME (1 << 0) /* ask for file name to reboot from */
+#define FREEBSD_RB_SINGLE (1 << 1) /* reboot to single user only */
+#define FREEBSD_RB_NOSYNC (1 << 2) /* dont sync before reboot */
+#define FREEBSD_RB_HALT (1 << 3) /* don't reboot, just halt */
+#define FREEBSD_RB_INITNAME (1 << 4) /* name given for /etc/init (unused) */
+#define FREEBSD_RB_DFLTROOT (1 << 5) /* use compiled-in rootdev */
+#define FREEBSD_RB_KDB (1 << 6) /* give control to kernel debugger */
+#define FREEBSD_RB_RDONLY (1 << 7) /* mount root fs read-only */
+#define FREEBSD_RB_DUMP (1 << 8) /* dump kernel memory before reboot */
+#define FREEBSD_RB_MINIROOT (1 << 9) /* mini-root present in memory at boot time */
+#define FREEBSD_RB_CONFIG (1 << 10) /* invoke user configuration routing */
+#define FREEBSD_RB_VERBOSE (1 << 11) /* print all potentially useful info */
+#define FREEBSD_RB_SERIAL (1 << 12) /* user serial port as console */
+#define FREEBSD_RB_CDROM (1 << 13) /* use cdrom as root */
+#define FREEBSD_RB_GDB (1 << 15) /* use GDB remote debugger instead of DDB */
+#define FREEBSD_RB_MUTE (1 << 16) /* Come up with the console muted */
+#define FREEBSD_RB_PAUSE (1 << 20)
+#define FREEBSD_RB_QUIET (1 << 21)
+#define FREEBSD_RB_NOINTR (1 << 28)
+#define FREENSD_RB_MULTIPLE (1 << 29) /* Use multiple consoles */
+#define FREEBSD_RB_DUAL FREENSD_RB_MULTIPLE
+#define FREEBSD_RB_BOOTINFO (1 << 31) /* have `struct bootinfo *' arg */
+
+#endif
diff --git a/include/grub/i386/gdb.h b/include/grub/i386/gdb.h
new file mode 100644
index 0000000..92d2dac
--- /dev/null
+++ b/include/grub/i386/gdb.h
@@ -0,0 +1,78 @@
+/* i386/gdb.h - i386 specific definitions for the remote GDB stub */
+/*
+ * Copyright (C) 2006 Lubomir Kundrak
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef GRUB_GDB_CPU_HEADER
+#define GRUB_GDB_CPU_HEADER 1
+
+#define GRUB_GDB_LAST_TRAP 31
+/* You may have to edit the bottom of machdep.S when adjusting
+ GRUB_GDB_LAST_TRAP. */
+#define GRUB_MACHINE_NR_REGS 16
+
+#define EAX 0
+#define ECX 1
+#define EDX 2
+#define EBX 3
+#define ESP 4
+#define EBP 5
+#define ESI 6
+#define EDI 7
+#define EIP 8
+#define EFLAGS 9
+#define CS 10
+#define SS 11
+#define DS 12
+#define ES 13
+#define FS 14
+#define GS 15
+
+#define PC EIP
+#define FP EBP
+#define SP ESP
+#define PS EFLAGS
+
+#ifndef ASM_FILE
+
+#include <grub/gdb.h>
+
+#define GRUB_CPU_TRAP_GATE 15
+
+struct grub_cpu_interrupt_gate
+{
+ grub_uint16_t offset_lo;
+ grub_uint16_t selector;
+ grub_uint8_t unused;
+ grub_uint8_t gate;
+ grub_uint16_t offset_hi;
+} GRUB_PACKED;
+
+struct grub_cpu_idt_descriptor
+{
+ grub_uint16_t limit;
+ grub_uint32_t base;
+} GRUB_PACKED;
+
+extern void (*grub_gdb_trapvec[]) (void);
+void grub_gdb_idtinit (void);
+void grub_gdb_idtrestore (void);
+void grub_gdb_trap (int trap_no) __attribute__ ((regparm(3)));
+
+#endif /* ! ASM */
+#endif /* ! GRUB_GDB_CPU_HEADER */
+
diff --git a/include/grub/i386/ieee1275/ieee1275.h b/include/grub/i386/ieee1275/ieee1275.h
new file mode 100644
index 0000000..2625f02
--- /dev/null
+++ b/include/grub/i386/ieee1275/ieee1275.h
@@ -0,0 +1 @@
+#include <grub/powerpc/ieee1275/ieee1275.h>
diff --git a/include/grub/i386/ieee1275/kernel.h b/include/grub/i386/ieee1275/kernel.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/include/grub/i386/ieee1275/kernel.h
diff --git a/include/grub/i386/ieee1275/memory.h b/include/grub/i386/ieee1275/memory.h
new file mode 100644
index 0000000..8dd6f7c
--- /dev/null
+++ b/include/grub/i386/ieee1275/memory.h
@@ -0,0 +1 @@
+#include <grub/i386/coreboot/memory.h>
diff --git a/include/grub/i386/ieee1275/serial.h b/include/grub/i386/ieee1275/serial.h
new file mode 100644
index 0000000..2d85634
--- /dev/null
+++ b/include/grub/i386/ieee1275/serial.h
@@ -0,0 +1 @@
+#include <grub/i386/coreboot/serial.h>
diff --git a/include/grub/i386/io.h b/include/grub/i386/io.h
new file mode 100644
index 0000000..e9cd809
--- /dev/null
+++ b/include/grub/i386/io.h
@@ -0,0 +1,72 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 1996,2000,2002,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* Based on sys/io.h from GNU libc. */
+
+#ifndef GRUB_IO_H
+#define GRUB_IO_H 1
+
+typedef unsigned short int grub_port_t;
+
+static __inline unsigned char
+grub_inb (unsigned short int port)
+{
+ unsigned char _v;
+
+ asm volatile ("inb %w1,%0":"=a" (_v):"Nd" (port));
+ return _v;
+}
+
+static __inline unsigned short int
+grub_inw (unsigned short int port)
+{
+ unsigned short _v;
+
+ asm volatile ("inw %w1,%0":"=a" (_v):"Nd" (port));
+ return _v;
+}
+
+static __inline unsigned int
+grub_inl (unsigned short int port)
+{
+ unsigned int _v;
+
+ asm volatile ("inl %w1,%0":"=a" (_v):"Nd" (port));
+ return _v;
+}
+
+static __inline void
+grub_outb (unsigned char value, unsigned short int port)
+{
+ asm volatile ("outb %b0,%w1": :"a" (value), "Nd" (port));
+}
+
+static __inline void
+grub_outw (unsigned short int value, unsigned short int port)
+{
+ asm volatile ("outw %w0,%w1": :"a" (value), "Nd" (port));
+
+}
+
+static __inline void
+grub_outl (unsigned int value, unsigned short int port)
+{
+ asm volatile ("outl %0,%w1": :"a" (value), "Nd" (port));
+}
+
+#endif /* _SYS_IO_H */
diff --git a/include/grub/i386/linux.h b/include/grub/i386/linux.h
new file mode 100644
index 0000000..eddf925
--- /dev/null
+++ b/include/grub/i386/linux.h
@@ -0,0 +1,336 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 1999,2000,2001,2002,2003,2004,2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_I386_LINUX_HEADER
+#define GRUB_I386_LINUX_HEADER 1
+
+#include <grub/types.h>
+
+#define GRUB_LINUX_I386_MAGIC_SIGNATURE 0x53726448 /* "HdrS" */
+#define GRUB_LINUX_DEFAULT_SETUP_SECTS 4
+#define GRUB_LINUX_INITRD_MAX_ADDRESS 0x37FFFFFF
+#define GRUB_LINUX_MAX_SETUP_SECTS 64
+#define GRUB_LINUX_BOOT_LOADER_TYPE 0x72
+#define GRUB_LINUX_HEAP_END_OFFSET (0x9000 - 0x200)
+
+#define GRUB_LINUX_BZIMAGE_ADDR 0x100000
+#define GRUB_LINUX_ZIMAGE_ADDR 0x10000
+#define GRUB_LINUX_OLD_REAL_MODE_ADDR 0x90000
+#define GRUB_LINUX_SETUP_STACK 0x9000
+
+#define GRUB_LINUX_FLAG_BIG_KERNEL 0x1
+#define GRUB_LINUX_FLAG_QUIET 0x20
+#define GRUB_LINUX_FLAG_CAN_USE_HEAP 0x80
+
+/* Linux's video mode selection support. Actually I hate it! */
+#define GRUB_LINUX_VID_MODE_NORMAL 0xFFFF
+#define GRUB_LINUX_VID_MODE_EXTENDED 0xFFFE
+#define GRUB_LINUX_VID_MODE_ASK 0xFFFD
+#define GRUB_LINUX_VID_MODE_VESA_START 0x0300
+
+#define GRUB_LINUX_CL_MAGIC 0xA33F
+
+#define VIDEO_CAPABILITY_SKIP_QUIRKS (1 << 0)
+#define VIDEO_CAPABILITY_64BIT_BASE (1 << 1) /* Frame buffer base is 64-bit. */
+
+/* Maximum number of MBR signatures to store. */
+#define EDD_MBR_SIG_MAX 16
+
+#ifdef __x86_64__
+
+#define GRUB_LINUX_EFI_SIGNATURE \
+ ('4' << 24 | '6' << 16 | 'L' << 8 | 'E')
+
+#else
+
+#define GRUB_LINUX_EFI_SIGNATURE \
+ ('2' << 24 | '3' << 16 | 'L' << 8 | 'E')
+
+#endif
+
+#define GRUB_LINUX_EFI_SIGNATURE_0204 \
+ ('L' << 24 | 'I' << 16 | 'F' << 8 | 'E')
+
+#define GRUB_LINUX_OFW_SIGNATURE \
+ (' ' << 24 | 'W' << 16 | 'F' << 8 | 'O')
+
+#ifndef ASM_FILE
+
+#define GRUB_E820_RAM 1
+#define GRUB_E820_RESERVED 2
+#define GRUB_E820_ACPI 3
+#define GRUB_E820_NVS 4
+#define GRUB_E820_BADRAM 5
+
+struct grub_e820_mmap
+{
+ grub_uint64_t addr;
+ grub_uint64_t size;
+ grub_uint32_t type;
+} GRUB_PACKED;
+
+enum
+ {
+ GRUB_VIDEO_LINUX_TYPE_TEXT = 0x01,
+ GRUB_VIDEO_LINUX_TYPE_VESA = 0x23, /* VESA VGA in graphic mode. */
+ GRUB_VIDEO_LINUX_TYPE_EFIFB = 0x70, /* EFI Framebuffer. */
+ GRUB_VIDEO_LINUX_TYPE_SIMPLE = 0x70 /* Linear framebuffer without any additional functions. */
+ };
+
+/* For the Linux/i386 boot protocol version 2.10. */
+struct linux_i386_kernel_header
+{
+ grub_uint8_t code1[0x0020];
+ grub_uint16_t cl_magic; /* Magic number 0xA33F */
+ grub_uint16_t cl_offset; /* The offset of command line */
+ grub_uint8_t code2[0x01F1 - 0x0020 - 2 - 2];
+ grub_uint8_t setup_sects; /* The size of the setup in sectors */
+ grub_uint16_t root_flags; /* If the root is mounted readonly */
+ grub_uint16_t syssize; /* obsolete */
+ grub_uint16_t swap_dev; /* obsolete */
+ grub_uint16_t ram_size; /* obsolete */
+ grub_uint16_t vid_mode; /* Video mode control */
+ grub_uint16_t root_dev; /* Default root device number */
+ grub_uint16_t boot_flag; /* 0xAA55 magic number */
+ grub_uint16_t jump; /* Jump instruction */
+ grub_uint32_t header; /* Magic signature "HdrS" */
+ grub_uint16_t version; /* Boot protocol version supported */
+ grub_uint32_t realmode_swtch; /* Boot loader hook */
+ grub_uint16_t start_sys; /* The load-low segment (obsolete) */
+ grub_uint16_t kernel_version; /* Points to kernel version string */
+ grub_uint8_t type_of_loader; /* Boot loader identifier */
+#define LINUX_LOADER_ID_LILO 0x0
+#define LINUX_LOADER_ID_LOADLIN 0x1
+#define LINUX_LOADER_ID_BOOTSECT 0x2
+#define LINUX_LOADER_ID_SYSLINUX 0x3
+#define LINUX_LOADER_ID_ETHERBOOT 0x4
+#define LINUX_LOADER_ID_ELILO 0x5
+#define LINUX_LOADER_ID_GRUB 0x7
+#define LINUX_LOADER_ID_UBOOT 0x8
+#define LINUX_LOADER_ID_XEN 0x9
+#define LINUX_LOADER_ID_GUJIN 0xa
+#define LINUX_LOADER_ID_QEMU 0xb
+ grub_uint8_t loadflags; /* Boot protocol option flags */
+ grub_uint16_t setup_move_size; /* Move to high memory size */
+ grub_uint32_t code32_start; /* Boot loader hook */
+ grub_uint32_t ramdisk_image; /* initrd load address */
+ grub_uint32_t ramdisk_size; /* initrd size */
+ grub_uint32_t bootsect_kludge; /* obsolete */
+ grub_uint16_t heap_end_ptr; /* Free memory after setup end */
+ grub_uint16_t pad1; /* Unused */
+ grub_uint32_t cmd_line_ptr; /* Points to the kernel command line */
+ grub_uint32_t initrd_addr_max; /* Highest address for initrd */
+ grub_uint32_t kernel_alignment;
+ grub_uint8_t relocatable;
+ grub_uint8_t min_alignment;
+ grub_uint8_t pad[2];
+ grub_uint32_t cmdline_size;
+ grub_uint32_t hardware_subarch;
+ grub_uint64_t hardware_subarch_data;
+ grub_uint32_t payload_offset;
+ grub_uint32_t payload_length;
+ grub_uint64_t setup_data;
+ grub_uint64_t pref_address;
+ grub_uint32_t init_size;
+ grub_uint32_t handover_offset;
+} GRUB_PACKED;
+
+/* Boot parameters for Linux based on 2.6.12. This is used by the setup
+ sectors of Linux, and must be simulated by GRUB on EFI, because
+ the setup sectors depend on BIOS. */
+struct linux_kernel_params
+{
+ grub_uint8_t video_cursor_x; /* 0 */
+ grub_uint8_t video_cursor_y;
+
+ grub_uint16_t ext_mem; /* 2 */
+
+ grub_uint16_t video_page; /* 4 */
+ grub_uint8_t video_mode; /* 6 */
+ grub_uint8_t video_width; /* 7 */
+
+ grub_uint8_t padding1[0xa - 0x8];
+
+ grub_uint16_t video_ega_bx; /* a */
+
+ grub_uint8_t padding2[0xe - 0xc];
+
+ grub_uint8_t video_height; /* e */
+ grub_uint8_t have_vga; /* f */
+ grub_uint16_t font_size; /* 10 */
+
+ grub_uint16_t lfb_width; /* 12 */
+ grub_uint16_t lfb_height; /* 14 */
+ grub_uint16_t lfb_depth; /* 16 */
+ grub_uint32_t lfb_base; /* 18 */
+ grub_uint32_t lfb_size; /* 1c */
+
+ grub_uint16_t cl_magic; /* 20 */
+ grub_uint16_t cl_offset;
+
+ grub_uint16_t lfb_line_len; /* 24 */
+ grub_uint8_t red_mask_size; /* 26 */
+ grub_uint8_t red_field_pos;
+ grub_uint8_t green_mask_size;
+ grub_uint8_t green_field_pos;
+ grub_uint8_t blue_mask_size;
+ grub_uint8_t blue_field_pos;
+ grub_uint8_t reserved_mask_size;
+ grub_uint8_t reserved_field_pos;
+ grub_uint16_t vesapm_segment; /* 2e */
+ grub_uint16_t vesapm_offset; /* 30 */
+ grub_uint16_t lfb_pages; /* 32 */
+ grub_uint16_t vesa_attrib; /* 34 */
+ grub_uint32_t capabilities; /* 36 */
+ grub_uint32_t ext_lfb_base; /* 3a */
+
+ grub_uint8_t padding3[0x40 - 0x3e];
+
+ grub_uint16_t apm_version; /* 40 */
+ grub_uint16_t apm_code_segment; /* 42 */
+ grub_uint32_t apm_entry; /* 44 */
+ grub_uint16_t apm_16bit_code_segment; /* 48 */
+ grub_uint16_t apm_data_segment; /* 4a */
+ grub_uint16_t apm_flags; /* 4c */
+ grub_uint32_t apm_code_len; /* 4e */
+ grub_uint16_t apm_data_len; /* 52 */
+
+ grub_uint8_t padding4[0x60 - 0x54];
+
+ grub_uint32_t ist_signature; /* 60 */
+ grub_uint32_t ist_command; /* 64 */
+ grub_uint32_t ist_event; /* 68 */
+ grub_uint32_t ist_perf_level; /* 6c */
+ grub_uint64_t acpi_rsdp_addr; /* 70 */
+
+ grub_uint8_t padding5[0x80 - 0x78];
+
+ grub_uint8_t hd0_drive_info[0x10]; /* 80 */
+ grub_uint8_t hd1_drive_info[0x10]; /* 90 */
+ grub_uint16_t rom_config_len; /* a0 */
+
+ grub_uint8_t padding6[0xb0 - 0xa2];
+
+ grub_uint32_t ofw_signature; /* b0 */
+ grub_uint32_t ofw_num_items; /* b4 */
+ grub_uint32_t ofw_cif_handler; /* b8 */
+ grub_uint32_t ofw_idt; /* bc */
+
+ grub_uint8_t padding7[0x1b8 - 0xc0];
+
+ union
+ {
+ struct
+ {
+ grub_uint32_t efi_system_table; /* 1b8 */
+ grub_uint32_t padding7_1; /* 1bc */
+ grub_uint32_t efi_signature; /* 1c0 */
+ grub_uint32_t efi_mem_desc_size; /* 1c4 */
+ grub_uint32_t efi_mem_desc_version; /* 1c8 */
+ grub_uint32_t efi_mmap_size; /* 1cc */
+ grub_uint32_t efi_mmap; /* 1d0 */
+ } v0204;
+ struct
+ {
+ grub_uint32_t padding7_1; /* 1b8 */
+ grub_uint32_t padding7_2; /* 1bc */
+ grub_uint32_t efi_signature; /* 1c0 */
+ grub_uint32_t efi_system_table; /* 1c4 */
+ grub_uint32_t efi_mem_desc_size; /* 1c8 */
+ grub_uint32_t efi_mem_desc_version; /* 1cc */
+ grub_uint32_t efi_mmap; /* 1d0 */
+ grub_uint32_t efi_mmap_size; /* 1d4 */
+ } v0206;
+ struct
+ {
+ grub_uint32_t padding7_1; /* 1b8 */
+ grub_uint32_t padding7_2; /* 1bc */
+ grub_uint32_t efi_signature; /* 1c0 */
+ grub_uint32_t efi_system_table; /* 1c4 */
+ grub_uint32_t efi_mem_desc_size; /* 1c8 */
+ grub_uint32_t efi_mem_desc_version; /* 1cc */
+ grub_uint32_t efi_mmap; /* 1d0 */
+ grub_uint32_t efi_mmap_size; /* 1d4 */
+ grub_uint32_t efi_system_table_hi; /* 1d8 */
+ grub_uint32_t efi_mmap_hi; /* 1dc */
+ } v0208;
+ };
+
+ grub_uint32_t alt_mem; /* 1e0 */
+
+ grub_uint8_t padding8[0x1e8 - 0x1e4];
+
+ grub_uint8_t mmap_size; /* 1e8 */
+
+ grub_uint8_t padding9[0x1ec - 0x1e9];
+
+ grub_uint8_t secure_boot; /* 1ec */
+
+ grub_uint8_t padding10[0x1f1 - 0x1ed];
+
+ /* Linux setup header copy - BEGIN. */
+ grub_uint8_t setup_sects; /* The size of the setup in sectors */
+ grub_uint16_t root_flags; /* If the root is mounted readonly */
+ grub_uint16_t syssize; /* obsolete */
+ grub_uint16_t swap_dev; /* obsolete */
+ grub_uint16_t ram_size; /* obsolete */
+ grub_uint16_t vid_mode; /* Video mode control */
+ grub_uint16_t root_dev; /* Default root device number */
+
+ grub_uint8_t padding11; /* 1fe */
+ grub_uint8_t ps_mouse; /* 1ff */
+
+ grub_uint16_t jump; /* Jump instruction */
+ grub_uint32_t header; /* Magic signature "HdrS" */
+ grub_uint16_t version; /* Boot protocol version supported */
+ grub_uint32_t realmode_swtch; /* Boot loader hook */
+ grub_uint16_t start_sys; /* The load-low segment (obsolete) */
+ grub_uint16_t kernel_version; /* Points to kernel version string */
+ grub_uint8_t type_of_loader; /* Boot loader identifier */
+ grub_uint8_t loadflags; /* Boot protocol option flags */
+ grub_uint16_t setup_move_size; /* Move to high memory size */
+ grub_uint32_t code32_start; /* Boot loader hook */
+ grub_uint32_t ramdisk_image; /* initrd load address */
+ grub_uint32_t ramdisk_size; /* initrd size */
+ grub_uint32_t bootsect_kludge; /* obsolete */
+ grub_uint16_t heap_end_ptr; /* Free memory after setup end */
+ grub_uint8_t ext_loader_ver; /* Extended loader version */
+ grub_uint8_t ext_loader_type; /* Extended loader type */
+ grub_uint32_t cmd_line_ptr; /* Points to the kernel command line */
+ grub_uint32_t initrd_addr_max; /* Maximum initrd address */
+ grub_uint32_t kernel_alignment; /* Alignment of the kernel */
+ grub_uint8_t relocatable_kernel; /* Is the kernel relocatable */
+ grub_uint8_t pad1[3];
+ grub_uint32_t cmdline_size; /* Size of the kernel command line */
+ grub_uint32_t hardware_subarch;
+ grub_uint64_t hardware_subarch_data;
+ grub_uint32_t payload_offset;
+ grub_uint32_t payload_length;
+ grub_uint64_t setup_data;
+ grub_uint64_t pref_address;
+ grub_uint32_t init_size;
+ grub_uint32_t handover_offset;
+ /* Linux setup header copy - END. */
+
+ grub_uint8_t _pad7[40];
+ grub_uint32_t edd_mbr_sig_buffer[EDD_MBR_SIG_MAX]; /* 290 */
+ struct grub_e820_mmap e820_map[(0x400 - 0x2d0) / 20]; /* 2d0 */
+} GRUB_PACKED;
+#endif /* ! ASM_FILE */
+
+#endif /* ! GRUB_I386_LINUX_HEADER */
diff --git a/include/grub/i386/macho.h b/include/grub/i386/macho.h
new file mode 100644
index 0000000..e15167a
--- /dev/null
+++ b/include/grub/i386/macho.h
@@ -0,0 +1,32 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_CPU_MACHO_H
+#define GRUB_CPU_MACHO_H 1
+
+#include <grub/macho.h>
+
+#define GRUB_MACHO_CPUTYPE_IS_HOST32(x) ((x) == GRUB_MACHO_CPUTYPE_IA32)
+#define GRUB_MACHO_CPUTYPE_IS_HOST64(x) ((x) == GRUB_MACHO_CPUTYPE_AMD64)
+#ifdef __x86_64__
+#define GRUB_MACHO_CPUTYPE_IS_HOST_CURRENT(x) ((x) == GRUB_MACHO_CPUTYPE_AMD64)
+#else
+#define GRUB_MACHO_CPUTYPE_IS_HOST_CURRENT(x) ((x) == GRUB_MACHO_CPUTYPE_IA32)
+#endif
+
+#endif
diff --git a/include/grub/i386/memory.h b/include/grub/i386/memory.h
new file mode 100644
index 0000000..5cb607f
--- /dev/null
+++ b/include/grub/i386/memory.h
@@ -0,0 +1,80 @@
+/* memory.h - describe the memory map */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MEMORY_CPU_HEADER
+#define GRUB_MEMORY_CPU_HEADER 1
+
+#define PAGE_SHIFT 12
+
+/* The flag for protected mode. */
+#define GRUB_MEMORY_CPU_CR0_PE_ON 0x1
+#define GRUB_MEMORY_CPU_CR4_PAE_ON 0x00000020
+#define GRUB_MEMORY_CPU_CR4_PSE_ON 0x00000010
+#define GRUB_MEMORY_CPU_CR0_PAGING_ON 0x80000000
+#define GRUB_MEMORY_CPU_AMD64_MSR 0xc0000080
+#define GRUB_MEMORY_CPU_AMD64_MSR_ON 0x00000100
+
+#define GRUB_MEMORY_MACHINE_UPPER_START 0x100000 /* 1 MiB */
+#define GRUB_MEMORY_MACHINE_LOWER_SIZE GRUB_MEMORY_MACHINE_UPPER_START
+
+/* Some PTE definitions. */
+#define GRUB_PAGE_PRESENT 0x00000001
+#define GRUB_PAGE_RW 0x00000002
+#define GRUB_PAGE_USER 0x00000004
+
+#ifndef ASM_FILE
+
+#define GRUB_MMAP_MALLOC_LOW 1
+
+#include <grub/types.h>
+
+struct grub_e820_mmap_entry
+{
+ grub_uint64_t addr;
+ grub_uint64_t len;
+ grub_uint32_t type;
+} GRUB_PACKED;
+
+grub_uint64_t grub_mmap_get_upper (void);
+grub_uint64_t grub_mmap_get_lower (void);
+grub_uint64_t grub_mmap_get_post64 (void);
+
+typedef grub_addr_t grub_phys_addr_t;
+
+static inline grub_phys_addr_t
+grub_vtop (void *a)
+{
+ return (grub_phys_addr_t) a;
+}
+
+static inline void *
+grub_map_memory (grub_phys_addr_t a, grub_size_t size __attribute__ ((unused)))
+{
+ return (void *) a;
+}
+
+static inline void
+grub_unmap_memory (void *a __attribute__ ((unused)),
+ grub_size_t size __attribute__ ((unused)))
+{
+}
+
+#endif
+
+#endif /* ! GRUB_MEMORY_CPU_HEADER */
diff --git a/include/grub/i386/memory_raw.h b/include/grub/i386/memory_raw.h
new file mode 100644
index 0000000..1292ba7
--- /dev/null
+++ b/include/grub/i386/memory_raw.h
@@ -0,0 +1,58 @@
+/* memory_raw.h - describe the memory map on qemu/coreboot/multiboot/pc */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2007,2008,2009,2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MEMORY_CPU_RAW_HEADER
+#define GRUB_MEMORY_CPU_RAW_HEADER 1
+
+/* The scratch buffer used in real mode code. */
+#define GRUB_MEMORY_MACHINE_SCRATCH_ADDR 0x68000
+#define GRUB_MEMORY_MACHINE_SCRATCH_SEG (GRUB_MEMORY_MACHINE_SCRATCH_ADDR >> 4)
+#define GRUB_MEMORY_MACHINE_SCRATCH_SIZE 0x9000
+
+/* The real mode stack. */
+#define GRUB_MEMORY_MACHINE_REAL_STACK (0x2000 - 0x10)
+
+/* The size of the protect mode stack. */
+#define GRUB_MEMORY_MACHINE_PROT_STACK_SIZE 0xf000
+
+/* The protected mode stack. */
+#define GRUB_MEMORY_MACHINE_PROT_STACK \
+ (GRUB_MEMORY_MACHINE_SCRATCH_ADDR + GRUB_MEMORY_MACHINE_SCRATCH_SIZE \
+ + GRUB_MEMORY_MACHINE_PROT_STACK_SIZE - 0x10)
+
+/* The memory area where GRUB uses its own purpose. This part is not added
+ into free memory for dynamic allocations. */
+#define GRUB_MEMORY_MACHINE_RESERVED_START \
+ GRUB_MEMORY_MACHINE_SCRATCH_ADDR
+#define GRUB_MEMORY_MACHINE_RESERVED_END \
+ (GRUB_MEMORY_MACHINE_PROT_STACK + 0x10)
+
+/* The code segment of the protected mode. */
+#define GRUB_MEMORY_MACHINE_PROT_MODE_CSEG 0x8
+
+/* The data segment of the protected mode. */
+#define GRUB_MEMORY_MACHINE_PROT_MODE_DSEG 0x10
+
+/* The code segment of the pseudo real mode. */
+#define GRUB_MEMORY_MACHINE_PSEUDO_REAL_CSEG 0x18
+
+/* The data segment of the pseudo real mode. */
+#define GRUB_MEMORY_MACHINE_PSEUDO_REAL_DSEG 0x20
+
+#endif
diff --git a/include/grub/i386/multiboot.h b/include/grub/i386/multiboot.h
new file mode 100644
index 0000000..0b596fc
--- /dev/null
+++ b/include/grub/i386/multiboot.h
@@ -0,0 +1,58 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2003,2004,2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MULTIBOOT_CPU_HEADER
+#define GRUB_MULTIBOOT_CPU_HEADER 1
+
+#define MULTIBOOT2_INITIAL_STATE { .eax = MULTIBOOT2_BOOTLOADER_MAGIC, \
+ .ecx = 0, \
+ .edx = 0, \
+ /* Set esp to some random location in low memory to avoid breaking */ \
+ /* non-compliant kernels. */ \
+ .esp = 0x7ff00 \
+ }
+#define MULTIBOOT_INITIAL_STATE { .eax = MULTIBOOT_BOOTLOADER_MAGIC, \
+ .ecx = 0, \
+ .edx = 0, \
+ /* Set esp to some random location in low memory to avoid breaking */ \
+ /* non-compliant kernels. */ \
+ .esp = 0x7ff00 \
+ }
+#define MULTIBOOT_ENTRY_REGISTER eip
+#define MULTIBOOT_MBI_REGISTER ebx
+#define MULTIBOOT2_ARCHITECTURE_CURRENT MULTIBOOT2_ARCHITECTURE_I386
+
+#ifdef GRUB_MACHINE_EFI
+#ifdef __x86_64__
+#define MULTIBOOT_EFI_INITIAL_STATE { .rax = MULTIBOOT_BOOTLOADER_MAGIC, \
+ .rcx = 0, \
+ .rdx = 0, \
+ }
+#define MULTIBOOT2_EFI_INITIAL_STATE { .rax = MULTIBOOT2_BOOTLOADER_MAGIC, \
+ .rcx = 0, \
+ .rdx = 0, \
+ }
+#define MULTIBOOT_EFI_ENTRY_REGISTER rip
+#define MULTIBOOT_EFI_MBI_REGISTER rbx
+#endif
+#endif
+
+#define MULTIBOOT_ELF32_MACHINE EM_386
+#define MULTIBOOT_ELF64_MACHINE EM_X86_64
+
+#endif /* ! GRUB_MULTIBOOT_CPU_HEADER */
diff --git a/include/grub/i386/multiboot/boot.h b/include/grub/i386/multiboot/boot.h
new file mode 100644
index 0000000..c33f9ba
--- /dev/null
+++ b/include/grub/i386/multiboot/boot.h
@@ -0,0 +1 @@
+#include <grub/i386/coreboot/boot.h>
diff --git a/include/grub/i386/multiboot/console.h b/include/grub/i386/multiboot/console.h
new file mode 100644
index 0000000..774399a
--- /dev/null
+++ b/include/grub/i386/multiboot/console.h
@@ -0,0 +1 @@
+#include <grub/i386/coreboot/console.h>
diff --git a/include/grub/i386/multiboot/kernel.h b/include/grub/i386/multiboot/kernel.h
new file mode 100644
index 0000000..b41e86e
--- /dev/null
+++ b/include/grub/i386/multiboot/kernel.h
@@ -0,0 +1 @@
+#include <grub/i386/coreboot/kernel.h>
diff --git a/include/grub/i386/multiboot/memory.h b/include/grub/i386/multiboot/memory.h
new file mode 100644
index 0000000..8dd6f7c
--- /dev/null
+++ b/include/grub/i386/multiboot/memory.h
@@ -0,0 +1 @@
+#include <grub/i386/coreboot/memory.h>
diff --git a/include/grub/i386/multiboot/serial.h b/include/grub/i386/multiboot/serial.h
new file mode 100644
index 0000000..2d85634
--- /dev/null
+++ b/include/grub/i386/multiboot/serial.h
@@ -0,0 +1 @@
+#include <grub/i386/coreboot/serial.h>
diff --git a/include/grub/i386/multiboot/time.h b/include/grub/i386/multiboot/time.h
new file mode 100644
index 0000000..7177c74
--- /dev/null
+++ b/include/grub/i386/multiboot/time.h
@@ -0,0 +1 @@
+#include <grub/i386/coreboot/time.h>
diff --git a/include/grub/i386/netbsd_bootinfo.h b/include/grub/i386/netbsd_bootinfo.h
new file mode 100644
index 0000000..9b4f460
--- /dev/null
+++ b/include/grub/i386/netbsd_bootinfo.h
@@ -0,0 +1,156 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* $NetBSD: bootinfo.h,v 1.16 2009/08/24 02:15:46 jmcneill Exp $ */
+
+/*
+ * Copyright (c) 1997
+ * Matthias Drochner. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef GRUB_NETBSD_BOOTINFO_CPU_HEADER
+#define GRUB_NETBSD_BOOTINFO_CPU_HEADER 1
+
+#include <grub/types.h>
+
+#define NETBSD_BTINFO_BOOTPATH 0
+#define NETBSD_BTINFO_ROOTDEVICE 1
+#define NETBSD_BTINFO_BOOTDISK 3
+#define NETBSD_BTINFO_CONSOLE 6
+#define NETBSD_BTINFO_SYMTAB 8
+#define NETBSD_BTINFO_MEMMAP 9
+#define NETBSD_BTINFO_BOOTWEDGE 10
+#define NETBSD_BTINFO_MODULES 11
+#define NETBSD_BTINFO_FRAMEBUF 12
+#define NETBSD_BTINFO_USERCONFCOMMANDS 13
+#define NETBSD_BTINFO_EFI 14
+
+struct grub_netbsd_bootinfo
+{
+ grub_uint32_t bi_count;
+ grub_uint32_t bi_data[0];
+};
+
+struct grub_netbsd_btinfo_common
+{
+ grub_uint32_t len;
+ grub_uint32_t type;
+};
+
+#define GRUB_NETBSD_MAX_BOOTPATH_LEN 80
+
+struct grub_netbsd_btinfo_bootdisk
+{
+ grub_uint32_t labelsector; /* label valid if != 0xffffffff */
+ struct
+ {
+ grub_uint16_t type, checksum;
+ char packname[16];
+ } label;
+ grub_uint32_t biosdev;
+ grub_uint32_t partition;
+};
+
+struct grub_netbsd_btinfo_bootwedge {
+ grub_uint32_t biosdev;
+ grub_disk_addr_t startblk;
+ grub_uint64_t nblks;
+ grub_disk_addr_t matchblk;
+ grub_uint64_t matchnblks;
+ grub_uint8_t matchhash[16]; /* MD5 hash */
+} GRUB_PACKED;
+
+struct grub_netbsd_btinfo_symtab
+{
+ grub_uint32_t nsyms;
+ grub_uint32_t ssyms;
+ grub_uint32_t esyms;
+};
+
+
+struct grub_netbsd_btinfo_serial
+{
+ char devname[16];
+ grub_uint32_t addr;
+ grub_uint32_t speed;
+};
+
+struct grub_netbsd_btinfo_modules
+{
+ grub_uint32_t num;
+ grub_uint32_t last_addr;
+ struct grub_netbsd_btinfo_module
+ {
+ char name[80];
+#define GRUB_NETBSD_MODULE_RAW 0
+#define GRUB_NETBSD_MODULE_ELF 1
+ grub_uint32_t type;
+ grub_uint32_t size;
+ grub_uint32_t addr;
+ } mods[0];
+};
+
+struct grub_netbsd_btinfo_framebuf
+{
+ grub_uint64_t fbaddr;
+ grub_uint32_t flags;
+ grub_uint32_t width;
+ grub_uint32_t height;
+ grub_uint16_t pitch;
+ grub_uint8_t bpp;
+
+ grub_uint8_t red_mask_size;
+ grub_uint8_t green_mask_size;
+ grub_uint8_t blue_mask_size;
+
+ grub_uint8_t red_field_pos;
+ grub_uint8_t green_field_pos;
+ grub_uint8_t blue_field_pos;
+
+ grub_uint8_t reserved[16];
+};
+
+#define GRUB_NETBSD_MAX_ROOTDEVICE_LEN 16
+
+struct grub_netbsd_btinfo_efi
+{
+ void *pa_systbl; /* Physical address of the EFI System Table */
+};
+
+#endif
diff --git a/include/grub/i386/netbsd_reboot.h b/include/grub/i386/netbsd_reboot.h
new file mode 100644
index 0000000..ee82455
--- /dev/null
+++ b/include/grub/i386/netbsd_reboot.h
@@ -0,0 +1,81 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* $NetBSD: reboot.h,v 1.25 2007/12/25 18:33:48 perry Exp $ */
+
+/*
+ * Copyright (c) 1982, 1986, 1988, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)reboot.h 8.3 (Berkeley) 12/13/94
+ */
+
+#ifndef GRUB_NETBSD_REBOOT_CPU_HEADER
+#define GRUB_NETBSD_REBOOT_CPU_HEADER 1
+
+#define NETBSD_RB_AUTOBOOT 0 /* flags for system auto-booting itself */
+
+#define NETBSD_RB_ASKNAME (1 << 0) /* ask for file name to reboot from */
+#define NETBSD_RB_SINGLE (1 << 1) /* reboot to single user only */
+#define NETBSD_RB_NOSYNC (1 << 2) /* dont sync before reboot */
+#define NETBSD_RB_HALT (1 << 3) /* don't reboot, just halt */
+#define NETBSD_RB_INITNAME (1 << 4) /* name given for /etc/init (unused) */
+#define NETBSD_RB_UNUSED1 (1 << 5) /* was RB_DFLTROOT, obsolete */
+#define NETBSD_RB_KDB (1 << 6) /* give control to kernel debugger */
+#define NETBSD_RB_RDONLY (1 << 7) /* mount root fs read-only */
+#define NETBSD_RB_DUMP (1 << 8) /* dump kernel memory before reboot */
+#define NETBSD_RB_MINIROOT (1 << 9) /* mini-root present in memory at boot time */
+#define NETBSD_RB_STRING (1 << 10) /* use provided bootstr */
+#define NETBSD_RB_POWERDOWN ((1 << 11) | RB_HALT) /* turn power off (or at least halt) */
+#define NETBSD_RB_USERCONFIG (1 << 12) /* change configured devices */
+
+#define NETBSD_AB_NORMAL 0 /* boot normally (default) */
+
+#define NETBSD_AB_QUIET (1 << 16) /* boot quietly */
+#define NETBSD_AB_VERBOSE (1 << 17) /* boot verbosely */
+#define NETBSD_AB_SILENT (1 << 18) /* boot silently */
+#define NETBSD_AB_DEBUG (1 << 19) /* boot with debug messages */
+#define NETBSD_AB_NOSMP (1 << 28) /* Boot without SMP support. */
+#define NETBSD_AB_NOACPI (1 << 29) /* Boot without ACPI support. */
+
+
+#endif
diff --git a/include/grub/i386/openbsd_bootarg.h b/include/grub/i386/openbsd_bootarg.h
new file mode 100644
index 0000000..9ebe6b4
--- /dev/null
+++ b/include/grub/i386/openbsd_bootarg.h
@@ -0,0 +1,93 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* $OpenBSD: bootarg.h,v 1.11 2003/06/02 20:20:54 mickey Exp $ */
+
+/*
+ * Copyright (c) 1996-1999 Michael Shalayeff
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef GRUB_OPENBSD_BOOTARG_CPU_HEADER
+#define GRUB_OPENBSD_BOOTARG_CPU_HEADER 1
+
+#define OPENBSD_BOOTARG_APIVER (OPENBSD_BAPIV_VECTOR | \
+ OPENBSD_BAPIV_ENV | \
+ OPENBSD_BAPIV_BMEMMAP)
+
+#define OPENBSD_BAPIV_ANCIENT 0x0 /* MD old i386 bootblocks */
+#define OPENBSD_BAPIV_VARS 0x1 /* MD structure w/ add info passed */
+#define OPENBSD_BAPIV_VECTOR 0x2 /* MI vector of MD structures passed */
+#define OPENBSD_BAPIV_ENV 0x4 /* MI environment vars vector */
+#define OPENBSD_BAPIV_BMEMMAP 0x8 /* MI memory map passed is in bytes */
+
+#define OPENBSD_BOOTARG_ENV 0x1000
+#define OPENBSD_BOOTARG_END -1
+
+#define OPENBSD_BOOTARG_MMAP 0
+#define OPENBSD_BOOTARG_PCIBIOS 4
+#define OPENBSD_BOOTARG_CONSOLE 5
+
+struct grub_openbsd_bootargs
+{
+ grub_uint32_t ba_type;
+ grub_uint32_t ba_size;
+ grub_uint32_t ba_next;
+} GRUB_PACKED;
+
+struct grub_openbsd_bootarg_console
+{
+ grub_uint32_t device;
+ grub_uint32_t speed;
+ grub_uint32_t addr;
+ grub_uint32_t frequency;
+};
+
+struct grub_openbsd_bootarg_pcibios
+{
+ grub_uint32_t characteristics;
+ grub_uint32_t revision;
+ grub_uint32_t pm_entry;
+ grub_uint32_t last_bus;
+};
+
+#define GRUB_OPENBSD_COM_MAJOR 8
+#define GRUB_OPENBSD_VGA_MAJOR 12
+
+#endif
diff --git a/include/grub/i386/openbsd_reboot.h b/include/grub/i386/openbsd_reboot.h
new file mode 100644
index 0000000..3f6571a
--- /dev/null
+++ b/include/grub/i386/openbsd_reboot.h
@@ -0,0 +1,79 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* $OpenBSD: reboot.h,v 1.13 2004/03/10 23:02:53 tom Exp $ */
+/* $NetBSD: reboot.h,v 1.9 1996/04/22 01:23:25 christos Exp $ */
+
+/*
+ * Copyright (c) 1982, 1986, 1988, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)reboot.h 8.2 (Berkeley) 7/10/94
+ */
+
+#ifndef GRUB_OPENBSD_REBOOT_CPU_HEADER
+#define GRUB_OPENBSD_REBOOT_CPU_HEADER 1
+
+#define OPENBSD_RB_ASKNAME (1 << 0) /* ask for file name to reboot from */
+#define OPENBSD_RB_SINGLE (1 << 1) /* reboot to single user only */
+#define OPENBSD_RB_NOSYNC (1 << 2) /* dont sync before reboot */
+#define OPENBSD_RB_HALT (1 << 3) /* don't reboot, just halt */
+#define OPENBSD_RB_INITNAME (1 << 4) /* name given for /etc/init (unused) */
+#define OPENBSD_RB_DFLTROOT (1 << 5) /* use compiled-in rootdev */
+#define OPENBSD_RB_KDB (1 << 6) /* give control to kernel debugger */
+#define OPENBSD_RB_RDONLY (1 << 7) /* mount root fs read-only */
+#define OPENBSD_RB_DUMP (1 << 8) /* dump kernel memory before reboot */
+#define OPENBSD_RB_MINIROOT (1 << 9) /* mini-root present in memory at boot time */
+#define OPENBSD_RB_CONFIG (1 << 10) /* change configured devices */
+#define OPENBSD_RB_TIMEBAD (1 << 11) /* don't call resettodr() in boot() */
+#define OPENBSD_RB_POWERDOWN (1 << 12) /* attempt to power down machine */
+#define OPENBSD_RB_SERCONS (1 << 13) /* use serial console if available */
+#define OPENBSD_RB_USERREQ (1 << 14) /* boot() called at user request (e.g. ddb) */
+
+#define OPENBSD_B_DEVMAGIC 0xa0000000
+#define OPENBSD_B_ADAPTORSHIFT 24
+#define OPENBSD_B_CTRLSHIFT 20
+#define OPENBSD_B_UNITSHIFT 16
+#define OPENBSD_B_PARTSHIFT 8
+#define OPENBSD_B_TYPESHIFT 0
+
+#endif
diff --git a/include/grub/i386/pc/apm.h b/include/grub/i386/pc/apm.h
new file mode 100644
index 0000000..6d9e8c6
--- /dev/null
+++ b/include/grub/i386/pc/apm.h
@@ -0,0 +1,48 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_APM_MACHINE_HEADER
+#define GRUB_APM_MACHINE_HEADER 1
+
+#include <grub/types.h>
+
+struct grub_apm_info
+{
+ grub_uint16_t cseg;
+ grub_uint32_t offset;
+ grub_uint16_t cseg_16;
+ grub_uint16_t dseg;
+ grub_uint16_t flags;
+ grub_uint16_t cseg_len;
+ grub_uint16_t cseg_16_len;
+ grub_uint16_t dseg_len;
+ grub_uint16_t version;
+};
+
+enum
+ {
+ GRUB_APM_FLAGS_16BITPROTECTED_SUPPORTED = 1,
+ GRUB_APM_FLAGS_32BITPROTECTED_SUPPORTED = 2,
+ GRUB_APM_FLAGS_CPUIDLE_SLOWS_DOWN = 4,
+ GRUB_APM_FLAGS_DISABLED = 8,
+ GRUB_APM_FLAGS_DISENGAGED = 16,
+ };
+
+int grub_apm_get_info (struct grub_apm_info *info);
+
+#endif
diff --git a/include/grub/i386/pc/biosdisk.h b/include/grub/i386/pc/biosdisk.h
new file mode 100644
index 0000000..3d80716
--- /dev/null
+++ b/include/grub/i386/pc/biosdisk.h
@@ -0,0 +1,109 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2005,2007,2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_BIOSDISK_MACHINE_HEADER
+#define GRUB_BIOSDISK_MACHINE_HEADER 1
+
+#include <grub/symbol.h>
+#include <grub/types.h>
+
+#define GRUB_BIOSDISK_FLAG_LBA 1
+#define GRUB_BIOSDISK_FLAG_CDROM 2
+
+#define GRUB_BIOSDISK_CDTYPE_NO_EMUL 0
+#define GRUB_BIOSDISK_CDTYPE_1_2_M 1
+#define GRUB_BIOSDISK_CDTYPE_1_44_M 2
+#define GRUB_BIOSDISK_CDTYPE_2_88_M 3
+#define GRUB_BIOSDISK_CDTYPE_HARDDISK 4
+
+#define GRUB_BIOSDISK_CDTYPE_MASK 0xF
+
+struct grub_biosdisk_data
+{
+ int drive;
+ unsigned long cylinders;
+ unsigned long heads;
+ unsigned long sectors;
+ unsigned long flags;
+};
+
+/* Drive Parameters. */
+struct grub_biosdisk_drp
+{
+ grub_uint16_t size;
+ grub_uint16_t flags;
+ grub_uint32_t cylinders;
+ grub_uint32_t heads;
+ grub_uint32_t sectors;
+ grub_uint64_t total_sectors;
+ grub_uint16_t bytes_per_sector;
+ /* ver 2.0 or higher */
+
+ union
+ {
+ grub_uint32_t EDD_configuration_parameters;
+
+ /* Pointer to the Device Parameter Table Extension (ver 3.0+). */
+ grub_uint32_t dpte_pointer;
+ };
+
+ /* ver 3.0 or higher */
+ grub_uint16_t signature_dpi;
+ grub_uint8_t length_dpi;
+ grub_uint8_t reserved[3];
+ grub_uint8_t name_of_host_bus[4];
+ grub_uint8_t name_of_interface_type[8];
+ grub_uint8_t interface_path[8];
+ grub_uint8_t device_path[16];
+ grub_uint8_t reserved2;
+ grub_uint8_t checksum;
+
+ /* XXX: This is necessary, because the BIOS of Thinkpad X20
+ writes a garbage to the tail of drive parameters,
+ regardless of a size specified in a caller. */
+ grub_uint8_t dummy[16];
+} GRUB_PACKED;
+
+struct grub_biosdisk_cdrp
+{
+ grub_uint8_t size;
+ grub_uint8_t media_type;
+ grub_uint8_t drive_no;
+ grub_uint8_t controller_no;
+ grub_uint32_t image_lba;
+ grub_uint16_t device_spec;
+ grub_uint16_t cache_seg;
+ grub_uint16_t load_seg;
+ grub_uint16_t length_sec512;
+ grub_uint8_t cylinders;
+ grub_uint8_t sectors;
+ grub_uint8_t heads;
+ grub_uint8_t dummy[16];
+} GRUB_PACKED;
+
+/* Disk Address Packet. */
+struct grub_biosdisk_dap
+{
+ grub_uint8_t length;
+ grub_uint8_t reserved;
+ grub_uint16_t blocks;
+ grub_uint32_t buffer;
+ grub_uint64_t block;
+} GRUB_PACKED;
+
+#endif /* ! GRUB_BIOSDISK_MACHINE_HEADER */
diff --git a/include/grub/i386/pc/biosnum.h b/include/grub/i386/pc/biosnum.h
new file mode 100644
index 0000000..29c8ecc
--- /dev/null
+++ b/include/grub/i386/pc/biosnum.h
@@ -0,0 +1,6 @@
+#ifndef GRUB_BIOSNUM_MACHINE_HEADER
+#define GRUB_BIOSNUM_MACHINE_HEADER 1
+
+extern int (*grub_get_root_biosnumber) (void);
+
+#endif
diff --git a/include/grub/i386/pc/boot.h b/include/grub/i386/pc/boot.h
new file mode 100644
index 0000000..a4d42ff
--- /dev/null
+++ b/include/grub/i386/pc/boot.h
@@ -0,0 +1,73 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 1999,2000,2002,2005,2006,2007,2008,2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_BOOT_MACHINE_HEADER
+#define GRUB_BOOT_MACHINE_HEADER 1
+
+#include <grub/offsets.h>
+
+/* The signature for bootloader. */
+#define GRUB_BOOT_MACHINE_SIGNATURE 0xaa55
+
+/* The offset of the start of BPB (BIOS Parameter Block). */
+#define GRUB_BOOT_MACHINE_BPB_START 0x3
+
+/* The offset of the end of BPB (BIOS Parameter Block). */
+#define GRUB_BOOT_MACHINE_BPB_END 0x5a
+
+/* The offset of KERNEL_SECTOR. */
+#define GRUB_BOOT_MACHINE_KERNEL_SECTOR 0x5c
+
+/* The offset of BOOT_DRIVE. */
+#define GRUB_BOOT_MACHINE_BOOT_DRIVE 0x64
+
+/* The offset of BOOT_DRIVE_CHECK. */
+#define GRUB_BOOT_MACHINE_DRIVE_CHECK 0x66
+
+/* The offset of a magic number used by Windows NT. */
+#define GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC 0x1b8
+
+/* The offset of the start of the partition table. */
+#define GRUB_BOOT_MACHINE_PART_START 0x1be
+
+/* The offset of the end of the partition table. */
+#define GRUB_BOOT_MACHINE_PART_END 0x1fe
+
+/* The stack segment. */
+#define GRUB_BOOT_MACHINE_STACK_SEG 0x2000
+
+/* The segment of disk buffer. The disk buffer MUST be 32K long and
+ cannot straddle a 64K boundary. */
+#define GRUB_BOOT_MACHINE_BUFFER_SEG 0x7000
+
+/* The flag for BIOS drive number to designate a hard disk vs. a
+ floppy. */
+#define GRUB_BOOT_MACHINE_BIOS_HD_FLAG 0x80
+
+/* The address where the kernel is loaded. */
+#define GRUB_BOOT_MACHINE_KERNEL_ADDR (GRUB_BOOT_MACHINE_KERNEL_SEG << 4)
+
+/* The size of a block list used in the kernel startup code. */
+#define GRUB_BOOT_MACHINE_LIST_SIZE 12
+
+#define GRUB_BOOT_MACHINE_PXE_DL 0x7f
+
+/* This is the blocklist used in the diskboot image. */
+#define grub_boot_blocklist grub_pc_bios_boot_blocklist
+
+#endif /* ! BOOT_MACHINE_HEADER */
diff --git a/include/grub/i386/pc/chainloader.h b/include/grub/i386/pc/chainloader.h
new file mode 100644
index 0000000..4776b18
--- /dev/null
+++ b/include/grub/i386/pc/chainloader.h
@@ -0,0 +1,27 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2004,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_CHAINLOADER_MACHINE_HEADER
+#define GRUB_CHAINLOADER_MACHINE_HEADER 1
+
+#include <grub/dl.h>
+
+void
+grub_chainloader_patch_bpb (void *bs, grub_device_t dev, grub_uint8_t dl);
+
+#endif /* GRUB_CHAINLOADER_MACHINE_HEADER */
diff --git a/include/grub/i386/pc/console.h b/include/grub/i386/pc/console.h
new file mode 100644
index 0000000..191964f
--- /dev/null
+++ b/include/grub/i386/pc/console.h
@@ -0,0 +1,36 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2005,2007,2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_CONSOLE_MACHINE_HEADER
+#define GRUB_CONSOLE_MACHINE_HEADER 1
+
+#ifndef ASM_FILE
+
+#include <grub/types.h>
+#include <grub/symbol.h>
+#include <grub/term.h>
+
+/* Initialize the console system. */
+void grub_console_init (void);
+
+/* Finish the console system. */
+void grub_console_fini (void);
+
+#endif
+
+#endif /* ! GRUB_CONSOLE_MACHINE_HEADER */
diff --git a/include/grub/i386/pc/int.h b/include/grub/i386/pc/int.h
new file mode 100644
index 0000000..a601040
--- /dev/null
+++ b/include/grub/i386/pc/int.h
@@ -0,0 +1,33 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_INTERRUPT_MACHINE_HEADER
+#define GRUB_INTERRUPT_MACHINE_HEADER 1
+
+#include <grub/symbol.h>
+#include <grub/i386/pc/int_types.h>
+
+void EXPORT_FUNC (grub_bios_interrupt) (grub_uint8_t intno,
+ struct grub_bios_int_registers *regs)
+ __attribute__ ((regparm(3)));
+
+#ifdef GRUB_MACHINE_PCBIOS
+extern struct grub_i386_idt *EXPORT_VAR(grub_realidt);
+#endif
+
+#endif
diff --git a/include/grub/i386/pc/int_types.h b/include/grub/i386/pc/int_types.h
new file mode 100644
index 0000000..2c5a69b
--- /dev/null
+++ b/include/grub/i386/pc/int_types.h
@@ -0,0 +1,59 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2018 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_INTERRUPT_TYPES_MACHINE_HEADER
+#define GRUB_INTERRUPT_TYPES_MACHINE_HEADER 1
+
+#include <grub/types.h>
+
+#define GRUB_CPU_INT_FLAGS_CARRY 0x1
+#define GRUB_CPU_INT_FLAGS_PARITY 0x4
+#define GRUB_CPU_INT_FLAGS_ADJUST 0x10
+#define GRUB_CPU_INT_FLAGS_ZERO 0x40
+#define GRUB_CPU_INT_FLAGS_SIGN 0x80
+#define GRUB_CPU_INT_FLAGS_TRAP 0x100
+#define GRUB_CPU_INT_FLAGS_INTERRUPT 0x200
+#define GRUB_CPU_INT_FLAGS_DIRECTION 0x400
+#define GRUB_CPU_INT_FLAGS_OVERFLOW 0x800
+#ifdef GRUB_MACHINE_PCBIOS
+#define GRUB_CPU_INT_FLAGS_DEFAULT GRUB_CPU_INT_FLAGS_INTERRUPT
+#else
+#define GRUB_CPU_INT_FLAGS_DEFAULT 0
+#endif
+
+struct grub_bios_int_registers
+{
+ grub_uint32_t eax;
+ grub_uint16_t es;
+ grub_uint16_t ds;
+ grub_uint16_t flags;
+ grub_uint16_t dummy;
+ grub_uint32_t ebx;
+ grub_uint32_t ecx;
+ grub_uint32_t edi;
+ grub_uint32_t esi;
+ grub_uint32_t edx;
+};
+
+struct grub_i386_idt
+{
+ grub_uint16_t limit;
+ grub_uint32_t base;
+} GRUB_PACKED;
+
+#endif
diff --git a/include/grub/i386/pc/kernel.h b/include/grub/i386/pc/kernel.h
new file mode 100644
index 0000000..4f05b74
--- /dev/null
+++ b/include/grub/i386/pc/kernel.h
@@ -0,0 +1,41 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2003,2007,2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef KERNEL_MACHINE_HEADER
+#define KERNEL_MACHINE_HEADER 1
+
+#include <grub/offsets.h>
+
+/* Enable LZMA compression */
+#define ENABLE_LZMA 1
+
+#ifndef ASM_FILE
+
+#include <grub/symbol.h>
+#include <grub/types.h>
+
+/* The total size of module images following the kernel. */
+extern grub_int32_t grub_total_module_size;
+
+extern grub_uint32_t EXPORT_VAR(grub_boot_device);
+
+extern void (*EXPORT_VAR(grub_pc_net_config)) (char **device, char **path);
+
+#endif /* ! ASM_FILE */
+
+#endif /* ! KERNEL_MACHINE_HEADER */
diff --git a/include/grub/i386/pc/memory.h b/include/grub/i386/pc/memory.h
new file mode 100644
index 0000000..d0c5c20
--- /dev/null
+++ b/include/grub/i386/pc/memory.h
@@ -0,0 +1,63 @@
+/* memory.h - describe the memory map */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MEMORY_MACHINE_HEADER
+#define GRUB_MEMORY_MACHINE_HEADER 1
+
+#include <grub/symbol.h>
+#ifndef ASM_FILE
+#include <grub/types.h>
+#include <grub/err.h>
+#include <grub/memory.h>
+#endif
+
+#include <grub/i386/memory.h>
+#include <grub/i386/memory_raw.h>
+
+#include <grub/offsets.h>
+
+/* The area where GRUB is decompressed at early startup. */
+#define GRUB_MEMORY_MACHINE_DECOMPRESSION_ADDR 0x100000
+
+/* The address of a partition table passed to another boot loader. */
+#define GRUB_MEMORY_MACHINE_PART_TABLE_ADDR 0x7be
+
+/* The address where another boot loader is loaded. */
+#define GRUB_MEMORY_MACHINE_BOOT_LOADER_ADDR 0x7c00
+
+#define GRUB_MEMORY_MACHINE_BIOS_DATA_AREA_ADDR 0x400
+
+#ifndef ASM_FILE
+
+/* See http://heim.ifi.uio.no/~stanisls/helppc/bios_data_area.html for a
+ description of the BIOS Data Area layout. */
+struct grub_machine_bios_data_area
+{
+ grub_uint8_t unused1[0x17];
+ grub_uint8_t keyboard_flag_lower; /* 0x17 */
+ grub_uint8_t unused2[0xf0 - 0x18];
+};
+
+grub_err_t grub_machine_mmap_register (grub_uint64_t start, grub_uint64_t size,
+ int type, int handle);
+grub_err_t grub_machine_mmap_unregister (int handle);
+
+#endif
+
+#endif /* ! GRUB_MEMORY_MACHINE_HEADER */
diff --git a/include/grub/i386/pc/pxe.h b/include/grub/i386/pc/pxe.h
new file mode 100644
index 0000000..66002bc
--- /dev/null
+++ b/include/grub/i386/pc/pxe.h
@@ -0,0 +1,292 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_CPU_PXE_H
+#define GRUB_CPU_PXE_H
+
+#include <grub/types.h>
+
+#define GRUB_PXENV_TFTP_OPEN 0x0020
+#define GRUB_PXENV_TFTP_CLOSE 0x0021
+#define GRUB_PXENV_TFTP_READ 0x0022
+#define GRUB_PXENV_TFTP_READ_FILE 0x0023
+#define GRUB_PXENV_TFTP_READ_FILE_PMODE 0x0024
+#define GRUB_PXENV_TFTP_GET_FSIZE 0x0025
+
+#define GRUB_PXENV_UDP_OPEN 0x0030
+#define GRUB_PXENV_UDP_CLOSE 0x0031
+#define GRUB_PXENV_UDP_READ 0x0032
+#define GRUB_PXENV_UDP_WRITE 0x0033
+
+#define GRUB_PXENV_START_UNDI 0x0000
+#define GRUB_PXENV_UNDI_STARTUP 0x0001
+#define GRUB_PXENV_UNDI_CLEANUP 0x0002
+#define GRUB_PXENV_UNDI_INITIALIZE 0x0003
+#define GRUB_PXENV_UNDI_RESET_NIC 0x0004
+#define GRUB_PXENV_UNDI_SHUTDOWN 0x0005
+#define GRUB_PXENV_UNDI_OPEN 0x0006
+#define GRUB_PXENV_UNDI_CLOSE 0x0007
+#define GRUB_PXENV_UNDI_TRANSMIT 0x0008
+#define GRUB_PXENV_UNDI_SET_MCAST_ADDR 0x0009
+#define GRUB_PXENV_UNDI_SET_STATION_ADDR 0x000A
+#define GRUB_PXENV_UNDI_SET_PACKET_FILTER 0x000B
+#define GRUB_PXENV_UNDI_GET_INFORMATION 0x000C
+#define GRUB_PXENV_UNDI_GET_STATISTICS 0x000D
+#define GRUB_PXENV_UNDI_CLEAR_STATISTICS 0x000E
+#define GRUB_PXENV_UNDI_INITIATE_DIAGS 0x000F
+#define GRUB_PXENV_UNDI_FORCE_INTERRUPT 0x0010
+#define GRUB_PXENV_UNDI_GET_MCAST_ADDR 0x0011
+#define GRUB_PXENV_UNDI_GET_NIC_TYPE 0x0012
+#define GRUB_PXENV_UNDI_GET_IFACE_INFO 0x0013
+#define GRUB_PXENV_UNDI_ISR 0x0014
+#define GRUB_PXENV_STOP_UNDI 0x0015
+#define GRUB_PXENV_UNDI_GET_STATE 0x0015
+
+#define GRUB_PXENV_UNLOAD_STACK 0x0070
+#define GRUB_PXENV_GET_CACHED_INFO 0x0071
+#define GRUB_PXENV_RESTART_DHCP 0x0072
+#define GRUB_PXENV_RESTART_TFTP 0x0073
+#define GRUB_PXENV_MODE_SWITCH 0x0074
+#define GRUB_PXENV_START_BASE 0x0075
+#define GRUB_PXENV_STOP_BASE 0x0076
+
+#define GRUB_PXENV_EXIT_SUCCESS 0x0000
+#define GRUB_PXENV_EXIT_FAILURE 0x0001
+
+#define GRUB_PXENV_STATUS_SUCCESS 0x00
+#define GRUB_PXENV_STATUS_FAILURE 0x01
+#define GRUB_PXENV_STATUS_BAD_FUNC 0x02
+#define GRUB_PXENV_STATUS_UNSUPPORTED 0x03
+#define GRUB_PXENV_STATUS_KEEP_UNDI 0x04
+#define GRUB_PXENV_STATUS_KEEP_ALL 0x05
+#define GRUB_PXENV_STATUS_OUT_OF_RESOURCES 0x06
+#define GRUB_PXENV_STATUS_ARP_TIMEOUT 0x11
+#define GRUB_PXENV_STATUS_UDP_CLOSED 0x18
+#define GRUB_PXENV_STATUS_UDP_OPEN 0x19
+#define GRUB_PXENV_STATUS_TFTP_CLOSED 0x1A
+#define GRUB_PXENV_STATUS_TFTP_OPEN 0x1B
+#define GRUB_PXENV_STATUS_MCOPY_PROBLEM 0x20
+#define GRUB_PXENV_STATUS_BIS_INTEGRITY_FAILURE 0x21
+#define GRUB_PXENV_STATUS_BIS_VALIDATE_FAILURE 0x22
+#define GRUB_PXENV_STATUS_BIS_INIT_FAILURE 0x23
+#define GRUB_PXENV_STATUS_BIS_SHUTDOWN_FAILURE 0x24
+#define GRUB_PXENV_STATUS_BIS_GBOA_FAILURE 0x25
+#define GRUB_PXENV_STATUS_BIS_FREE_FAILURE 0x26
+#define GRUB_PXENV_STATUS_BIS_GSI_FAILURE 0x27
+#define GRUB_PXENV_STATUS_BIS_BAD_CKSUM 0x28
+#define GRUB_PXENV_STATUS_TFTP_CANNOT_ARP_ADDRESS 0x30
+#define GRUB_PXENV_STATUS_TFTP_OPEN_TIMEOUT 0x32
+
+#define GRUB_PXENV_STATUS_TFTP_UNKNOWN_OPCODE 0x33
+#define GRUB_PXENV_STATUS_TFTP_READ_TIMEOUT 0x35
+#define GRUB_PXENV_STATUS_TFTP_ERROR_OPCODE 0x36
+#define GRUB_PXENV_STATUS_TFTP_CANNOT_OPEN_CONNECTION 0x38
+#define GRUB_PXENV_STATUS_TFTP_CANNOT_READ_FROM_CONNECTION 0x39
+#define GRUB_PXENV_STATUS_TFTP_TOO_MANY_PACKAGES 0x3A
+#define GRUB_PXENV_STATUS_TFTP_FILE_NOT_FOUND 0x3B
+#define GRUB_PXENV_STATUS_TFTP_ACCESS_VIOLATION 0x3C
+#define GRUB_PXENV_STATUS_TFTP_NO_MCAST_ADDRESS 0x3D
+#define GRUB_PXENV_STATUS_TFTP_NO_FILESIZE 0x3E
+#define GRUB_PXENV_STATUS_TFTP_INVALID_PACKET_SIZE 0x3F
+#define GRUB_PXENV_STATUS_DHCP_TIMEOUT 0x51
+#define GRUB_PXENV_STATUS_DHCP_NO_IP_ADDRESS 0x52
+#define GRUB_PXENV_STATUS_DHCP_NO_BOOTFILE_NAME 0x53
+#define GRUB_PXENV_STATUS_DHCP_BAD_IP_ADDRESS 0x54
+#define GRUB_PXENV_STATUS_UNDI_INVALID_FUNCTION 0x60
+#define GRUB_PXENV_STATUS_UNDI_MEDIATEST_FAILED 0x61
+#define GRUB_PXENV_STATUS_UNDI_CANNOT_INIT_NIC_FOR_MCAST 0x62
+#define GRUB_PXENV_STATUS_UNDI_CANNOT_INITIALIZE_NIC 0x63
+#define GRUB_PXENV_STATUS_UNDI_CANNOT_INITIALIZE_PHY 0x64
+#define GRUB_PXENV_STATUS_UNDI_CANNOT_READ_CONFIG_DATA 0x65
+#define GRUB_PXENV_STATUS_UNDI_CANNOT_READ_INIT_DATA 0x66
+#define GRUB_PXENV_STATUS_UNDI_BAD_MAC_ADDRESS 0x67
+#define GRUB_PXENV_STATUS_UNDI_BAD_EEPROM_CHECKSUM 0x68
+#define GRUB_PXENV_STATUS_UNDI_ERROR_SETTING_ISR 0x69
+#define GRUB_PXENV_STATUS_UNDI_INVALID_STATE 0x6A
+#define GRUB_PXENV_STATUS_UNDI_TRANSMIT_ERROR 0x6B
+#define GRUB_PXENV_STATUS_UNDI_INVALID_PARAMETER 0x6C
+#define GRUB_PXENV_STATUS_BSTRAP_PROMPT_MENU 0x74
+#define GRUB_PXENV_STATUS_BSTRAP_MCAST_ADDR 0x76
+#define GRUB_PXENV_STATUS_BSTRAP_MISSING_LIST 0x77
+#define GRUB_PXENV_STATUS_BSTRAP_NO_RESPONSE 0x78
+#define GRUB_PXENV_STATUS_BSTRAP_FILE_TOO_BIG 0x79
+#define GRUB_PXENV_STATUS_BINL_CANCELED_BY_KEYSTROKE 0xA0
+#define GRUB_PXENV_STATUS_BINL_NO_PXE_SERVER 0xA1
+#define GRUB_PXENV_STATUS_NOT_AVAILABLE_IN_PMODE 0xA2
+#define GRUB_PXENV_STATUS_NOT_AVAILABLE_IN_RMODE 0xA3
+#define GRUB_PXENV_STATUS_BUSD_DEVICE_NOT_SUPPORTED 0xB0
+#define GRUB_PXENV_STATUS_LOADER_NO_FREE_BASE_MEMORY 0xC0
+#define GRUB_PXENV_STATUS_LOADER_NO_BC_ROMID 0xC1
+#define GRUB_PXENV_STATUS_LOADER_BAD_BC_ROMID 0xC2
+#define GRUB_PXENV_STATUS_LOADER_BAD_BC_RUNTIME_IMAGE 0xC3
+#define GRUB_PXENV_STATUS_LOADER_NO_UNDI_ROMID 0xC4
+#define GRUB_PXENV_STATUS_LOADER_BAD_UNDI_ROMID 0xC5
+#define GRUB_PXENV_STATUS_LOADER_BAD_UNDI_DRIVER_IMAGE 0xC6
+#define GRUB_PXENV_STATUS_LOADER_NO_PXE_STRUCT 0xC8
+#define GRUB_PXENV_STATUS_LOADER_NO_PXENV_STRUCT 0xC9
+#define GRUB_PXENV_STATUS_LOADER_UNDI_START 0xCA
+#define GRUB_PXENV_STATUS_LOADER_BC_START 0xCB
+
+#define GRUB_PXENV_PACKET_TYPE_DHCP_DISCOVER 1
+#define GRUB_PXENV_PACKET_TYPE_DHCP_ACK 2
+#define GRUB_PXENV_PACKET_TYPE_CACHED_REPLY 3
+
+#define GRUB_PXE_BOOTP_REQ 1
+#define GRUB_PXE_BOOTP_REP 2
+
+#define GRUB_PXE_BOOTP_BCAST 0x8000
+
+#if 1
+#define GRUB_PXE_BOOTP_SIZE (1024 + 236) /* DHCP extended vendor field size. */
+#else
+#define GRUB_PXE_BOOTP_SIZE (312 + 236) /* DHCP standard vendor field size. */
+#endif
+
+#define GRUB_PXE_TFTP_PORT 69
+
+#define GRUB_PXE_ERR_LEN 0xFFFFFFFF
+
+#ifndef ASM_FILE
+
+#define GRUB_PXE_SIGNATURE "PXENV+"
+
+struct grub_pxenv
+{
+ grub_uint8_t signature[6]; /* 'PXENV+'. */
+ grub_uint16_t version; /* MSB = major, LSB = minor. */
+ grub_uint8_t length; /* structure length. */
+ grub_uint8_t checksum; /* checksum pad. */
+ grub_uint32_t rm_entry; /* SEG:OFF to PXE entry point. */
+ grub_uint32_t pm_offset; /* Protected mode entry. */
+ grub_uint16_t pm_selector; /* Protected mode selector. */
+ grub_uint16_t stack_seg; /* Stack segment address. */
+ grub_uint16_t stack_size; /* Stack segment size (bytes). */
+ grub_uint16_t bc_code_seg; /* BC Code segment address. */
+ grub_uint16_t bc_code_size; /* BC Code segment size (bytes). */
+ grub_uint16_t bc_data_seg; /* BC Data segment address. */
+ grub_uint16_t bc_data_size; /* BC Data segment size (bytes). */
+ grub_uint16_t undi_data_seg; /* UNDI Data segment address. */
+ grub_uint16_t undi_data_size; /* UNDI Data segment size (bytes). */
+ grub_uint16_t undi_code_seg; /* UNDI Code segment address. */
+ grub_uint16_t undi_code_size; /* UNDI Code segment size (bytes). */
+ grub_uint32_t pxe_ptr; /* SEG:OFF to !PXE struct. */
+} GRUB_PACKED;
+
+struct grub_pxe_bangpxe
+{
+ grub_uint8_t signature[4];
+#define GRUB_PXE_BANGPXE_SIGNATURE "!PXE"
+ grub_uint8_t length;
+ grub_uint8_t chksum;
+ grub_uint8_t rev;
+ grub_uint8_t reserved;
+ grub_uint32_t undiromid;
+ grub_uint32_t baseromid;
+ grub_uint32_t rm_entry;
+} GRUB_PACKED;
+
+struct grub_pxenv_get_cached_info
+{
+ grub_uint16_t status;
+ grub_uint16_t packet_type;
+ grub_uint16_t buffer_size;
+ grub_uint32_t buffer;
+ grub_uint16_t buffer_limit;
+} GRUB_PACKED;
+
+struct grub_pxenv_tftp_open
+{
+ grub_uint16_t status;
+ grub_uint32_t server_ip;
+ grub_uint32_t gateway_ip;
+ grub_uint8_t filename[128];
+ grub_uint16_t tftp_port;
+ grub_uint16_t packet_size;
+} GRUB_PACKED;
+
+struct grub_pxenv_tftp_close
+{
+ grub_uint16_t status;
+} GRUB_PACKED;
+
+struct grub_pxenv_tftp_read
+{
+ grub_uint16_t status;
+ grub_uint16_t packet_number;
+ grub_uint16_t buffer_size;
+ grub_uint32_t buffer;
+} GRUB_PACKED;
+
+struct grub_pxenv_tftp_get_fsize
+{
+ grub_uint16_t status;
+ grub_uint32_t server_ip;
+ grub_uint32_t gateway_ip;
+ grub_uint8_t filename[128];
+ grub_uint32_t file_size;
+} GRUB_PACKED;
+
+struct grub_pxenv_udp_open
+{
+ grub_uint16_t status;
+ grub_uint32_t src_ip;
+} GRUB_PACKED;
+
+struct grub_pxenv_udp_close
+{
+ grub_uint16_t status;
+} GRUB_PACKED;
+
+struct grub_pxenv_udp_write
+{
+ grub_uint16_t status;
+ grub_uint32_t ip;
+ grub_uint32_t gateway;
+ grub_uint16_t src_port;
+ grub_uint16_t dst_port;
+ grub_uint16_t buffer_size;
+ grub_uint32_t buffer;
+} GRUB_PACKED;
+
+struct grub_pxenv_udp_read
+{
+ grub_uint16_t status;
+ grub_uint32_t src_ip;
+ grub_uint32_t dst_ip;
+ grub_uint16_t src_port;
+ grub_uint16_t dst_port;
+ grub_uint16_t buffer_size;
+ grub_uint32_t buffer;
+} GRUB_PACKED;
+
+struct grub_pxenv_unload_stack
+{
+ grub_uint16_t status;
+ grub_uint8_t reserved[10];
+} GRUB_PACKED;
+
+int EXPORT_FUNC(grub_pxe_call) (int func, void * data, grub_uint32_t pxe_rm_entry) __attribute__ ((regparm(3)));
+
+extern struct grub_pxe_bangpxe *grub_pxe_pxenv;
+
+void *
+grub_pxe_get_cached (grub_uint16_t type);
+
+#endif
+
+#endif /* GRUB_CPU_PXE_H */
diff --git a/include/grub/i386/pc/time.h b/include/grub/i386/pc/time.h
new file mode 100644
index 0000000..e93320f
--- /dev/null
+++ b/include/grub/i386/pc/time.h
@@ -0,0 +1,24 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2003,2004,2005,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef KERNEL_MACHINE_TIME_HEADER
+#define KERNEL_MACHINE_TIME_HEADER 1
+
+#include <grub/symbol.h>
+
+#endif /* ! KERNEL_MACHINE_TIME_HEADER */
diff --git a/include/grub/i386/pc/vbe.h b/include/grub/i386/pc/vbe.h
new file mode 100644
index 0000000..f349b5c
--- /dev/null
+++ b/include/grub/i386/pc/vbe.h
@@ -0,0 +1,232 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2005,2006,2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_VBE_MACHINE_HEADER
+#define GRUB_VBE_MACHINE_HEADER 1
+
+#include <grub/video.h>
+
+/* Default video mode to be used. */
+#define GRUB_VBE_DEFAULT_VIDEO_MODE 0x101
+
+/* VBE status codes. */
+#define GRUB_VBE_STATUS_OK 0x004f
+
+#define GRUB_VBE_CAPABILITY_DACWIDTH (1 << 0)
+
+/* Bits from the GRUB_VBE "mode_attributes" field in the mode info struct. */
+#define GRUB_VBE_MODEATTR_SUPPORTED (1 << 0)
+#define GRUB_VBE_MODEATTR_RESERVED_1 (1 << 1)
+#define GRUB_VBE_MODEATTR_BIOS_TTY_OUTPUT_SUPPORT (1 << 2)
+#define GRUB_VBE_MODEATTR_COLOR (1 << 3)
+#define GRUB_VBE_MODEATTR_GRAPHICS (1 << 4)
+#define GRUB_VBE_MODEATTR_VGA_COMPATIBLE (1 << 5)
+#define GRUB_VBE_MODEATTR_VGA_WINDOWED_AVAIL (1 << 6)
+#define GRUB_VBE_MODEATTR_LFB_AVAIL (1 << 7)
+#define GRUB_VBE_MODEATTR_DOUBLE_SCAN_AVAIL (1 << 8)
+#define GRUB_VBE_MODEATTR_INTERLACED_AVAIL (1 << 9)
+#define GRUB_VBE_MODEATTR_TRIPLE_BUF_AVAIL (1 << 10)
+#define GRUB_VBE_MODEATTR_STEREO_AVAIL (1 << 11)
+#define GRUB_VBE_MODEATTR_DUAL_DISPLAY_START (1 << 12)
+
+/* Values for the GRUB_VBE memory_model field in the mode info struct. */
+#define GRUB_VBE_MEMORY_MODEL_TEXT 0x00
+#define GRUB_VBE_MEMORY_MODEL_CGA 0x01
+#define GRUB_VBE_MEMORY_MODEL_HERCULES 0x02
+#define GRUB_VBE_MEMORY_MODEL_PLANAR 0x03
+#define GRUB_VBE_MEMORY_MODEL_PACKED_PIXEL 0x04
+#define GRUB_VBE_MEMORY_MODEL_NONCHAIN4_256 0x05
+#define GRUB_VBE_MEMORY_MODEL_DIRECT_COLOR 0x06
+#define GRUB_VBE_MEMORY_MODEL_YUV 0x07
+
+/* Note:
+
+ Please refer to VESA BIOS Extension 3.0 Specification for more descriptive
+ meanings of following structures and how they should be used.
+
+ I have tried to maintain field name compatibility against specification
+ while following naming conventions used in GRUB. */
+
+typedef grub_uint32_t grub_vbe_farptr_t;
+typedef grub_uint32_t grub_vbe_physptr_t;
+typedef grub_uint32_t grub_vbe_status_t;
+
+struct grub_vbe_info_block
+{
+ grub_uint8_t signature[4];
+ grub_uint16_t version;
+
+ grub_vbe_farptr_t oem_string_ptr;
+ grub_uint32_t capabilities;
+ grub_vbe_farptr_t video_mode_ptr;
+ grub_uint16_t total_memory;
+
+ grub_uint16_t oem_software_rev;
+ grub_vbe_farptr_t oem_vendor_name_ptr;
+ grub_vbe_farptr_t oem_product_name_ptr;
+ grub_vbe_farptr_t oem_product_rev_ptr;
+
+ grub_uint8_t reserved[222];
+
+ grub_uint8_t oem_data[256];
+} GRUB_PACKED;
+
+struct grub_vbe_mode_info_block
+{
+ /* Mandatory information for all VBE revisions. */
+ grub_uint16_t mode_attributes;
+ grub_uint8_t win_a_attributes;
+ grub_uint8_t win_b_attributes;
+ grub_uint16_t win_granularity;
+ grub_uint16_t win_size;
+ grub_uint16_t win_a_segment;
+ grub_uint16_t win_b_segment;
+ grub_vbe_farptr_t win_func_ptr;
+ grub_uint16_t bytes_per_scan_line;
+
+ /* Mandatory information for VBE 1.2 and above. */
+ grub_uint16_t x_resolution;
+ grub_uint16_t y_resolution;
+ grub_uint8_t x_char_size;
+ grub_uint8_t y_char_size;
+ grub_uint8_t number_of_planes;
+ grub_uint8_t bits_per_pixel;
+ grub_uint8_t number_of_banks;
+ grub_uint8_t memory_model;
+ grub_uint8_t bank_size;
+ grub_uint8_t number_of_image_pages;
+ grub_uint8_t reserved;
+
+ /* Direct Color fields (required for direct/6 and YUV/7 memory models). */
+ grub_uint8_t red_mask_size;
+ grub_uint8_t red_field_position;
+ grub_uint8_t green_mask_size;
+ grub_uint8_t green_field_position;
+ grub_uint8_t blue_mask_size;
+ grub_uint8_t blue_field_position;
+ grub_uint8_t rsvd_mask_size;
+ grub_uint8_t rsvd_field_position;
+ grub_uint8_t direct_color_mode_info;
+
+ /* Mandatory information for VBE 2.0 and above. */
+ grub_vbe_physptr_t phys_base_addr;
+ grub_uint32_t reserved2;
+ grub_uint16_t reserved3;
+
+ /* Mandatory information for VBE 3.0 and above. */
+ grub_uint16_t lin_bytes_per_scan_line;
+ grub_uint8_t bnk_number_of_image_pages;
+ grub_uint8_t lin_number_of_image_pages;
+ grub_uint8_t lin_red_mask_size;
+ grub_uint8_t lin_red_field_position;
+ grub_uint8_t lin_green_mask_size;
+ grub_uint8_t lin_green_field_position;
+ grub_uint8_t lin_blue_mask_size;
+ grub_uint8_t lin_blue_field_position;
+ grub_uint8_t lin_rsvd_mask_size;
+ grub_uint8_t lin_rsvd_field_position;
+ grub_uint32_t max_pixel_clock;
+
+ /* Reserved field to make structure to be 256 bytes long, VESA BIOS
+ Extension 3.0 Specification says to reserve 189 bytes here but
+ that doesn't make structure to be 256 bytes. So additional one is
+ added here. */
+ grub_uint8_t reserved4[189 + 1];
+} GRUB_PACKED;
+
+struct grub_vbe_crtc_info_block
+{
+ grub_uint16_t horizontal_total;
+ grub_uint16_t horizontal_sync_start;
+ grub_uint16_t horizontal_sync_end;
+ grub_uint16_t vertical_total;
+ grub_uint16_t vertical_sync_start;
+ grub_uint16_t vertical_sync_end;
+ grub_uint8_t flags;
+ grub_uint32_t pixel_clock;
+ grub_uint16_t refresh_rate;
+ grub_uint8_t reserved[40];
+} GRUB_PACKED;
+
+struct grub_vbe_palette_data
+{
+ grub_uint8_t blue;
+ grub_uint8_t green;
+ grub_uint8_t red;
+ grub_uint8_t alignment;
+} GRUB_PACKED;
+
+struct grub_vbe_flat_panel_info
+{
+ grub_uint16_t horizontal_size;
+ grub_uint16_t vertical_size;
+ grub_uint16_t panel_type;
+ grub_uint8_t red_bpp;
+ grub_uint8_t green_bpp;
+ grub_uint8_t blue_bpp;
+ grub_uint8_t reserved_bpp;
+ grub_uint32_t reserved_offscreen_mem_size;
+ grub_vbe_farptr_t reserved_offscreen_mem_ptr;
+
+ grub_uint8_t reserved[14];
+} GRUB_PACKED;
+
+/* Prototypes for helper functions. */
+/* Call VESA BIOS 0x4f00 to get VBE Controller Information, return status. */
+grub_vbe_status_t
+grub_vbe_bios_get_controller_info (struct grub_vbe_info_block *controller_info);
+/* Call VESA BIOS 0x4f01 to get VBE Mode Information, return status. */
+grub_vbe_status_t
+grub_vbe_bios_get_mode_info (grub_uint32_t mode,
+ struct grub_vbe_mode_info_block *mode_info);
+/* Call VESA BIOS 0x4f03 to return current VBE Mode, return status. */
+grub_vbe_status_t
+grub_vbe_bios_get_mode (grub_uint32_t *mode);
+/* Call VESA BIOS 0x4f05 to set memory window, return status. */
+grub_vbe_status_t
+grub_vbe_bios_set_memory_window (grub_uint32_t window, grub_uint32_t position);
+/* Call VESA BIOS 0x4f05 to return memory window, return status. */
+grub_vbe_status_t
+grub_vbe_bios_get_memory_window (grub_uint32_t window,
+ grub_uint32_t *position);
+/* Call VESA BIOS 0x4f06 to set scanline length (in bytes), return status. */
+grub_vbe_status_t
+grub_vbe_bios_set_scanline_length (grub_uint32_t length);
+/* Call VESA BIOS 0x4f06 to return scanline length (in bytes), return status. */
+grub_vbe_status_t
+grub_vbe_bios_get_scanline_length (grub_uint32_t *length);
+/* Call VESA BIOS 0x4f07 to get display start, return status. */
+grub_vbe_status_t
+grub_vbe_bios_get_display_start (grub_uint32_t *x,
+ grub_uint32_t *y);
+
+grub_vbe_status_t grub_vbe_bios_getset_dac_palette_width (int set, int *width);
+
+#define grub_vbe_bios_get_dac_palette_width(width) grub_vbe_bios_getset_dac_palette_width(0, (width))
+#define grub_vbe_bios_set_dac_palette_width(width) grub_vbe_bios_getset_dac_palette_width(1, (width))
+
+grub_err_t grub_vbe_probe (struct grub_vbe_info_block *info_block);
+grub_err_t grub_vbe_get_video_mode (grub_uint32_t *mode);
+grub_err_t grub_vbe_get_video_mode_info (grub_uint32_t mode,
+ struct grub_vbe_mode_info_block *mode_info);
+grub_vbe_status_t
+grub_vbe_bios_get_pm_interface (grub_uint16_t *seg, grub_uint16_t *offset,
+ grub_uint16_t *length);
+
+
+#endif /* ! GRUB_VBE_MACHINE_HEADER */
diff --git a/include/grub/i386/pc/vesa_modes_table.h b/include/grub/i386/pc/vesa_modes_table.h
new file mode 100644
index 0000000..376ca37
--- /dev/null
+++ b/include/grub/i386/pc/vesa_modes_table.h
@@ -0,0 +1,19 @@
+#ifndef GRUB_VESA_MODE_TABLE_HEADER
+#define GRUB_VESA_MODE_TABLE_HEADER 1
+
+#include <grub/types.h>
+
+#define GRUB_VESA_MODE_TABLE_START 0x300
+#define GRUB_VESA_MODE_TABLE_END 0x373
+
+struct grub_vesa_mode_table_entry {
+ grub_uint16_t width;
+ grub_uint16_t height;
+ grub_uint8_t depth;
+};
+
+extern struct grub_vesa_mode_table_entry
+grub_vesa_mode_table[GRUB_VESA_MODE_TABLE_END
+ - GRUB_VESA_MODE_TABLE_START + 1];
+
+#endif
diff --git a/include/grub/i386/pci.h b/include/grub/i386/pci.h
new file mode 100644
index 0000000..dffeb56
--- /dev/null
+++ b/include/grub/i386/pci.h
@@ -0,0 +1,105 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_CPU_PCI_H
+#define GRUB_CPU_PCI_H 1
+
+#include <grub/types.h>
+#include <grub/i386/io.h>
+
+#define GRUB_MACHINE_PCI_IO_BASE 0
+#define GRUB_PCI_ADDR_REG 0xcf8
+#define GRUB_PCI_DATA_REG 0xcfc
+#define GRUB_PCI_NUM_BUS 256
+#define GRUB_PCI_NUM_DEVICES 32
+
+static inline grub_uint32_t
+grub_pci_read (grub_pci_address_t addr)
+{
+ grub_outl (addr, GRUB_PCI_ADDR_REG);
+ return grub_inl (GRUB_PCI_DATA_REG);
+}
+
+static inline grub_uint16_t
+grub_pci_read_word (grub_pci_address_t addr)
+{
+ grub_outl (addr & ~3, GRUB_PCI_ADDR_REG);
+ return grub_inw (GRUB_PCI_DATA_REG + (addr & 3));
+}
+
+static inline grub_uint8_t
+grub_pci_read_byte (grub_pci_address_t addr)
+{
+ grub_outl (addr & ~3, GRUB_PCI_ADDR_REG);
+ return grub_inb (GRUB_PCI_DATA_REG + (addr & 3));
+}
+
+static inline void
+grub_pci_write (grub_pci_address_t addr, grub_uint32_t data)
+{
+ grub_outl (addr, GRUB_PCI_ADDR_REG);
+ grub_outl (data, GRUB_PCI_DATA_REG);
+}
+
+static inline void
+grub_pci_write_word (grub_pci_address_t addr, grub_uint16_t data)
+{
+ grub_outl (addr & ~3, GRUB_PCI_ADDR_REG);
+ grub_outw (data, GRUB_PCI_DATA_REG + (addr & 3));
+}
+
+static inline void
+grub_pci_write_byte (grub_pci_address_t addr, grub_uint8_t data)
+{
+ grub_outl (addr & ~3, GRUB_PCI_ADDR_REG);
+ grub_outb (data, GRUB_PCI_DATA_REG + (addr & 3));
+}
+
+#ifndef GRUB_MACHINE_IEEE1275
+
+static inline volatile void *
+grub_pci_device_map_range (grub_pci_device_t dev __attribute__ ((unused)),
+ grub_addr_t base,
+ grub_size_t size __attribute__ ((unused)))
+{
+ return (volatile void *) base;
+}
+
+static inline void
+grub_pci_device_unmap_range (grub_pci_device_t dev __attribute__ ((unused)),
+ volatile void *mem __attribute__ ((unused)),
+ grub_size_t size __attribute__ ((unused)))
+{
+}
+
+#else
+
+volatile void *
+grub_pci_device_map_range (grub_pci_device_t dev,
+ grub_addr_t base,
+ grub_size_t size);
+
+void
+grub_pci_device_unmap_range (grub_pci_device_t dev,
+ volatile void *mem,
+ grub_size_t size);
+
+#endif
+
+
+#endif /* GRUB_CPU_PCI_H */
diff --git a/include/grub/i386/pit.h b/include/grub/i386/pit.h
new file mode 100644
index 0000000..4bd49d4
--- /dev/null
+++ b/include/grub/i386/pit.h
@@ -0,0 +1,103 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef KERNEL_CPU_PIT_HEADER
+#define KERNEL_CPU_PIT_HEADER 1
+
+#include <grub/types.h>
+#include <grub/err.h>
+
+enum
+ {
+ /* The PIT channel value ports. You can write to and read from them.
+ Do not mess with timer 0 or 1. */
+ GRUB_PIT_COUNTER_0 = 0x40,
+ GRUB_PIT_COUNTER_1 = 0x41,
+ GRUB_PIT_COUNTER_2 = 0x42,
+ /* The PIT control port. You can only write to it. Do not mess with
+ timer 0 or 1. */
+ GRUB_PIT_CTRL = 0x43,
+ /* The speaker port. */
+ GRUB_PIT_SPEAKER_PORT = 0x61,
+ };
+
+
+/* The speaker port. */
+enum
+ {
+ /* If 0, follow state of SPEAKER_DATA bit, otherwise enable output
+ from timer 2. */
+ GRUB_PIT_SPK_TMR2 = 0x01,
+ /* If SPEAKER_TMR2 is not set, this provides direct input into the
+ speaker. Otherwise, this enables or disables the output from the
+ timer. */
+ GRUB_PIT_SPK_DATA = 0x02,
+
+ GRUB_PIT_SPK_TMR2_LATCH = 0x20
+ };
+
+/* The PIT control port. You can only write to it. Do not mess with
+ timer 0 or 1. */
+enum
+ {
+ GRUB_PIT_CTRL_SELECT_MASK = 0xc0,
+ GRUB_PIT_CTRL_SELECT_0 = 0x00,
+ GRUB_PIT_CTRL_SELECT_1 = 0x40,
+ GRUB_PIT_CTRL_SELECT_2 = 0x80,
+
+ /* Read and load control. */
+ GRUB_PIT_CTRL_READLOAD_MASK= 0x30,
+ GRUB_PIT_CTRL_COUNTER_LATCH = 0x00, /* Hold timer value until read. */
+ GRUB_PIT_CTRL_READLOAD_LSB = 0x10, /* Read/load the LSB. */
+ GRUB_PIT_CTRL_READLOAD_MSB = 0x20, /* Read/load the MSB. */
+ GRUB_PIT_CTRL_READLOAD_WORD = 0x30, /* Read/load the LSB then the MSB. */
+
+ /* Mode control. */
+ GRUB_PIT_CTRL_MODE_MASK = 0x0e,
+ /* Interrupt on terminal count. Setting the mode sets output to low.
+ When counter is set and terminated, output is set to high. */
+ GRUB_PIT_CTRL_INTR_ON_TERM = 0x00,
+ /* Programmable one-shot. When loading counter, output is set to
+ high. When counter terminated, output is set to low. Can be
+ triggered again from that point on by setting the gate pin to
+ high. */
+ GRUB_PIT_CTRL_PROGR_ONE_SHOT = 0x02,
+
+ /* Rate generator. Output is low for one period of the counter, and
+ high for the other. */
+ GRUB_PIT_CTRL_RATE_GEN = 0x04,
+
+ /* Square wave generator. Output is low for one half of the period,
+ and high for the other half. */
+ GRUB_PIT_CTRL_SQUAREWAVE_GEN = 0x06,
+ /* Software triggered strobe. Setting the mode sets output to high.
+ When counter is set and terminated, output is set to low. */
+ GRUB_PIT_CTRL_SOFTSTROBE = 0x08,
+
+ /* Hardware triggered strobe. Like software triggered strobe, but
+ only starts the counter when the gate pin is set to high. */
+ GRUB_PIT_CTRL_HARDSTROBE = 0x0a,
+
+
+ /* Count mode. */
+ GRUB_PIT_CTRL_COUNT_MASK = 0x01,
+ GRUB_PIT_CTRL_COUNT_BINARY = 0x00, /* 16-bit binary counter. */
+ GRUB_PIT_CTRL_COUNT_BCD = 0x01 /* 4-decade BCD counter. */
+ };
+
+#endif /* ! KERNEL_CPU_PIT_HEADER */
diff --git a/include/grub/i386/pmtimer.h b/include/grub/i386/pmtimer.h
new file mode 100644
index 0000000..ac09180
--- /dev/null
+++ b/include/grub/i386/pmtimer.h
@@ -0,0 +1,37 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef KERNEL_CPU_PMTIMER_HEADER
+#define KERNEL_CPU_PMTIMER_HEADER 1
+
+#include <grub/i386/tsc.h>
+#include <grub/i386/io.h>
+
+/*
+ Preconditions:
+ * Caller has ensured that both pmtimer and tsc are supported
+ * 1 <= num_pm_ticks <= 3580
+ Return:
+ * Number of TSC ticks elapsed
+ * 0 on failure.
+*/
+grub_uint64_t
+EXPORT_FUNC(grub_pmtimer_wait_count_tsc) (grub_port_t pmtimer,
+ grub_uint16_t num_pm_ticks);
+
+#endif
diff --git a/include/grub/i386/qemu/boot.h b/include/grub/i386/qemu/boot.h
new file mode 100644
index 0000000..5f53eab
--- /dev/null
+++ b/include/grub/i386/qemu/boot.h
@@ -0,0 +1,25 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_BOOT_MACHINE_HEADER
+#define GRUB_BOOT_MACHINE_HEADER 1
+
+/* The size of boot.img. */
+#define GRUB_BOOT_MACHINE_SIZE (0x100000 - GRUB_BOOT_MACHINE_LINK_ADDR)
+
+#endif
diff --git a/include/grub/i386/qemu/console.h b/include/grub/i386/qemu/console.h
new file mode 100644
index 0000000..774399a
--- /dev/null
+++ b/include/grub/i386/qemu/console.h
@@ -0,0 +1 @@
+#include <grub/i386/coreboot/console.h>
diff --git a/include/grub/i386/qemu/kernel.h b/include/grub/i386/qemu/kernel.h
new file mode 100644
index 0000000..f34206b
--- /dev/null
+++ b/include/grub/i386/qemu/kernel.h
@@ -0,0 +1,35 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2005,2006,2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_KERNEL_MACHINE_HEADER
+#define GRUB_KERNEL_MACHINE_HEADER 1
+
+#include <grub/offsets.h>
+
+#ifndef ASM_FILE
+
+#include <grub/symbol.h>
+#include <grub/types.h>
+
+extern grub_addr_t grub_core_entry_addr;
+
+void grub_qemu_init_cirrus (void);
+
+#endif /* ! ASM_FILE */
+
+#endif /* ! GRUB_KERNEL_MACHINE_HEADER */
diff --git a/include/grub/i386/qemu/memory.h b/include/grub/i386/qemu/memory.h
new file mode 100644
index 0000000..8dd6f7c
--- /dev/null
+++ b/include/grub/i386/qemu/memory.h
@@ -0,0 +1 @@
+#include <grub/i386/coreboot/memory.h>
diff --git a/include/grub/i386/qemu/serial.h b/include/grub/i386/qemu/serial.h
new file mode 100644
index 0000000..2d85634
--- /dev/null
+++ b/include/grub/i386/qemu/serial.h
@@ -0,0 +1 @@
+#include <grub/i386/coreboot/serial.h>
diff --git a/include/grub/i386/qemu/time.h b/include/grub/i386/qemu/time.h
new file mode 100644
index 0000000..7177c74
--- /dev/null
+++ b/include/grub/i386/qemu/time.h
@@ -0,0 +1 @@
+#include <grub/i386/coreboot/time.h>
diff --git a/include/grub/i386/rdmsr.h b/include/grub/i386/rdmsr.h
new file mode 100644
index 0000000..c0a0c71
--- /dev/null
+++ b/include/grub/i386/rdmsr.h
@@ -0,0 +1,37 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2019 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_RDMSR_H
+#define GRUB_RDMSR_H 1
+
+/*
+ * TODO: Add a general protection exception handler.
+ * Accessing a reserved or unimplemented MSR address results in a GP#.
+ */
+
+static inline grub_uint64_t
+grub_msr_read (grub_uint32_t msr_id)
+{
+ grub_uint32_t low, high;
+
+ asm volatile ("rdmsr" : "=a" (low), "=d" (high) : "c" (msr_id));
+
+ return ((grub_uint64_t)high << 32) | low;
+}
+
+#endif /* GRUB_RDMSR_H */
diff --git a/include/grub/i386/reboot.h b/include/grub/i386/reboot.h
new file mode 100644
index 0000000..c2716f3
--- /dev/null
+++ b/include/grub/i386/reboot.h
@@ -0,0 +1,28 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2011 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_REBOOT_H
+#define GRUB_REBOOT_H 1
+
+#ifndef ASM_FILE
+
+extern grub_uint8_t grub_reboot_end[], grub_reboot_start[];
+
+#endif
+
+#endif
diff --git a/include/grub/i386/relocator.h b/include/grub/i386/relocator.h
new file mode 100644
index 0000000..2a56c3b
--- /dev/null
+++ b/include/grub/i386/relocator.h
@@ -0,0 +1,100 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_RELOCATOR_CPU_HEADER
+#define GRUB_RELOCATOR_CPU_HEADER 1
+
+#include <grub/types.h>
+#include <grub/err.h>
+#include <grub/relocator.h>
+
+struct grub_relocator32_state
+{
+ grub_uint32_t esp;
+ grub_uint32_t ebp;
+ grub_uint32_t eax;
+ grub_uint32_t ebx;
+ grub_uint32_t ecx;
+ grub_uint32_t edx;
+ grub_uint32_t eip;
+ grub_uint32_t esi;
+ grub_uint32_t edi;
+};
+
+struct grub_relocator16_state
+{
+ grub_uint16_t cs;
+ grub_uint16_t ds;
+ grub_uint16_t es;
+ grub_uint16_t fs;
+ grub_uint16_t gs;
+ grub_uint16_t ss;
+ grub_uint16_t sp;
+ grub_uint16_t ip;
+ grub_uint32_t ebx;
+ grub_uint32_t edx;
+ grub_uint32_t esi;
+ grub_uint32_t ebp;
+ int a20;
+};
+
+struct grub_relocator64_state
+{
+ grub_uint64_t rsp;
+ grub_uint64_t rax;
+ grub_uint64_t rbx;
+ grub_uint64_t rcx;
+ grub_uint64_t rdx;
+ grub_uint64_t rip;
+ grub_uint64_t rsi;
+ grub_addr_t cr3;
+};
+
+#ifdef GRUB_MACHINE_EFI
+#ifdef __x86_64__
+struct grub_relocator64_efi_state
+{
+ grub_uint64_t rax;
+ grub_uint64_t rbx;
+ grub_uint64_t rcx;
+ grub_uint64_t rdx;
+ grub_uint64_t rip;
+ grub_uint64_t rsi;
+};
+#endif
+#endif
+
+grub_err_t grub_relocator16_boot (struct grub_relocator *rel,
+ struct grub_relocator16_state state);
+
+grub_err_t grub_relocator32_boot (struct grub_relocator *rel,
+ struct grub_relocator32_state state,
+ int avoid_efi_bootservices);
+
+grub_err_t grub_relocator64_boot (struct grub_relocator *rel,
+ struct grub_relocator64_state state,
+ grub_addr_t min_addr, grub_addr_t max_addr);
+
+#ifdef GRUB_MACHINE_EFI
+#ifdef __x86_64__
+grub_err_t grub_relocator64_efi_boot (struct grub_relocator *rel,
+ struct grub_relocator64_efi_state state);
+#endif
+#endif
+
+#endif /* ! GRUB_RELOCATOR_CPU_HEADER */
diff --git a/include/grub/i386/relocator_private.h b/include/grub/i386/relocator_private.h
new file mode 100644
index 0000000..b7c96a6
--- /dev/null
+++ b/include/grub/i386/relocator_private.h
@@ -0,0 +1 @@
+#define GRUB_RELOCATOR16_STACK_SIZE 4096
diff --git a/include/grub/i386/setjmp.h b/include/grub/i386/setjmp.h
new file mode 100644
index 0000000..bf959a6
--- /dev/null
+++ b/include/grub/i386/setjmp.h
@@ -0,0 +1,29 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2003,2006,2007,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_SETJMP_CPU_HEADER
+#define GRUB_SETJMP_CPU_HEADER 1
+
+typedef unsigned long grub_jmp_buf[6];
+
+int grub_setjmp (grub_jmp_buf env) RETURNS_TWICE __attribute__ ((cdecl,
+ regparm (3)));
+void grub_longjmp (grub_jmp_buf env, int val) __attribute__ ((noreturn, cdecl,
+ regparm (3)));
+
+#endif /* ! GRUB_SETJMP_CPU_HEADER */
diff --git a/include/grub/i386/time.h b/include/grub/i386/time.h
new file mode 100644
index 0000000..4da5ae9
--- /dev/null
+++ b/include/grub/i386/time.h
@@ -0,0 +1,29 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef KERNEL_CPU_TIME_HEADER
+#define KERNEL_CPU_TIME_HEADER 1
+
+static __inline void
+grub_cpu_idle (void)
+{
+ /* FIXME: this can't work until we handle interrupts. */
+/* asm volatile ("hlt"); */
+}
+
+#endif /* ! KERNEL_CPU_TIME_HEADER */
diff --git a/include/grub/i386/tsc.h b/include/grub/i386/tsc.h
new file mode 100644
index 0000000..947e62f
--- /dev/null
+++ b/include/grub/i386/tsc.h
@@ -0,0 +1,70 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef KERNEL_CPU_TSC_HEADER
+#define KERNEL_CPU_TSC_HEADER 1
+
+#include <grub/types.h>
+#include <grub/i386/cpuid.h>
+
+void grub_tsc_init (void);
+/* In ms per 2^32 ticks. */
+extern grub_uint32_t EXPORT_VAR(grub_tsc_rate);
+int
+grub_tsc_calibrate_from_xen (void);
+int
+grub_tsc_calibrate_from_efi (void);
+int
+grub_tsc_calibrate_from_pmtimer (void);
+int
+grub_tsc_calibrate_from_pit (void);
+
+/* Read the TSC value, which increments with each CPU clock cycle. */
+static __inline grub_uint64_t
+grub_get_tsc (void)
+{
+ grub_uint32_t lo, hi;
+ grub_uint32_t a,b,c,d;
+
+ /* The CPUID instruction is a 'serializing' instruction, and
+ avoids out-of-order execution of the RDTSC instruction. */
+ grub_cpuid (0,a,b,c,d);
+ /* Read TSC value. We cannot use "=A", since this would use
+ %rax on x86_64. */
+ asm volatile ("rdtsc":"=a" (lo), "=d" (hi));
+
+ return (((grub_uint64_t) hi) << 32) | lo;
+}
+
+static __inline int
+grub_cpu_is_tsc_supported (void)
+{
+#if !defined(GRUB_MACHINE_XEN) && !defined(GRUB_MACHINE_XEN_PVH)
+ grub_uint32_t a,b,c,d;
+ if (! grub_cpu_is_cpuid_supported ())
+ return 0;
+
+ grub_cpuid(1,a,b,c,d);
+
+ return (d & (1 << 4)) != 0;
+#else
+ return 1;
+#endif
+}
+
+#endif /* ! KERNEL_CPU_TSC_HEADER */
diff --git a/include/grub/i386/types.h b/include/grub/i386/types.h
new file mode 100644
index 0000000..c20063f
--- /dev/null
+++ b/include/grub/i386/types.h
@@ -0,0 +1,33 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2006,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_TYPES_CPU_HEADER
+#define GRUB_TYPES_CPU_HEADER 1
+
+/* The size of void *. */
+#define GRUB_TARGET_SIZEOF_VOID_P 4
+
+/* The size of long. */
+#define GRUB_TARGET_SIZEOF_LONG 4
+
+/* i386 is little-endian. */
+#undef GRUB_TARGET_WORDS_BIGENDIAN
+
+#define GRUB_HAVE_UNALIGNED_ACCESS 1
+
+#endif /* ! GRUB_TYPES_CPU_HEADER */
diff --git a/include/grub/i386/wrmsr.h b/include/grub/i386/wrmsr.h
new file mode 100644
index 0000000..dea60ae
--- /dev/null
+++ b/include/grub/i386/wrmsr.h
@@ -0,0 +1,35 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2019 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_WRMSR_H
+#define GRUB_WRMSR_H 1
+
+/*
+ * TODO: Add a general protection exception handler.
+ * Accessing a reserved or unimplemented MSR address results in a GP#.
+ */
+
+static inline void
+grub_msr_write(grub_uint32_t msr_id, grub_uint64_t msr_value)
+{
+ grub_uint32_t low = msr_value, high = msr_value >> 32;
+
+ asm volatile ("wrmsr" : : "c" (msr_id), "a" (low), "d" (high));
+}
+
+#endif /* GRUB_WRMSR_H */
diff --git a/include/grub/i386/xen/hypercall.h b/include/grub/i386/xen/hypercall.h
new file mode 100644
index 0000000..4e4c12a
--- /dev/null
+++ b/include/grub/i386/xen/hypercall.h
@@ -0,0 +1,88 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_XEN_CPU_HYPERCALL_HEADER
+#define GRUB_XEN_CPU_HYPERCALL_HEADER 1
+
+#include <grub/types.h>
+
+int
+EXPORT_FUNC (grub_xen_hypercall) (grub_uint32_t callno, grub_uint32_t a0,
+ grub_uint32_t a1, grub_uint32_t a2,
+ grub_uint32_t a3, grub_uint32_t a4,
+ grub_uint32_t a5)
+#ifdef GRUB_MACHINE_XEN
+ __attribute__ ((regparm (3), cdecl))
+#endif
+ ;
+
+static inline int
+grub_xen_sched_op (int cmd, void *arg)
+{
+ return grub_xen_hypercall (__HYPERVISOR_sched_op, cmd, (grub_uint32_t) arg,
+ 0, 0, 0, 0);
+}
+
+static inline int
+grub_xen_mmu_update (const struct mmu_update *reqs,
+ unsigned count, unsigned *done_out, unsigned foreigndom)
+{
+ return grub_xen_hypercall (__HYPERVISOR_mmu_update, (grub_uint32_t) reqs,
+ (grub_uint32_t) count, (grub_uint32_t) done_out,
+ (grub_uint32_t) foreigndom, 0, 0);
+}
+
+static inline int
+grub_xen_mmuext_op (mmuext_op_t * ops,
+ unsigned int count,
+ unsigned int *pdone, unsigned int foreigndom)
+{
+ return grub_xen_hypercall (__HYPERVISOR_mmuext_op, (grub_uint32_t) ops,
+ count, (grub_uint32_t) pdone, foreigndom, 0, 0);
+}
+
+static inline int
+grub_xen_event_channel_op (int op, void *arg)
+{
+ return grub_xen_hypercall (__HYPERVISOR_event_channel_op, op,
+ (grub_uint32_t) arg, 0, 0, 0, 0);
+}
+
+
+static inline int
+grub_xen_update_va_mapping (void *addr, uint64_t pte, uint32_t flags)
+{
+ return grub_xen_hypercall (__HYPERVISOR_update_va_mapping,
+ (grub_uint32_t) addr, pte, pte >> 32, flags, 0,
+ 0);
+}
+
+static inline int
+grub_xen_grant_table_op (int a, void *b, int c)
+{
+ return grub_xen_hypercall (__HYPERVISOR_grant_table_op, a,
+ (grub_uint32_t) b, c, 0, 0, 0);
+}
+
+static inline int
+grub_xen_vm_assist (int cmd, int type)
+{
+ return grub_xen_hypercall (__HYPERVISOR_vm_assist, cmd, type, 0, 0, 0, 0);
+}
+
+#endif
diff --git a/include/grub/i386/xen/kernel.h b/include/grub/i386/xen/kernel.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/include/grub/i386/xen/kernel.h
diff --git a/include/grub/i386/xen/memory.h b/include/grub/i386/xen/memory.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/include/grub/i386/xen/memory.h
diff --git a/include/grub/i386/xen_pvh/boot.h b/include/grub/i386/xen_pvh/boot.h
new file mode 100644
index 0000000..6cd23aa
--- /dev/null
+++ b/include/grub/i386/xen_pvh/boot.h
@@ -0,0 +1 @@
+#include <grub/i386/pc/boot.h>
diff --git a/include/grub/i386/xen_pvh/console.h b/include/grub/i386/xen_pvh/console.h
new file mode 100644
index 0000000..305a46d
--- /dev/null
+++ b/include/grub/i386/xen_pvh/console.h
@@ -0,0 +1 @@
+#include <grub/i386/pc/console.h>
diff --git a/include/grub/i386/xen_pvh/int.h b/include/grub/i386/xen_pvh/int.h
new file mode 100644
index 0000000..0f1f9ee
--- /dev/null
+++ b/include/grub/i386/xen_pvh/int.h
@@ -0,0 +1 @@
+#include <grub/i386/pc/int_types.h>
diff --git a/include/grub/i386/xen_pvh/kernel.h b/include/grub/i386/xen_pvh/kernel.h
new file mode 100644
index 0000000..2b7b8a1
--- /dev/null
+++ b/include/grub/i386/xen_pvh/kernel.h
@@ -0,0 +1,30 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2018 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_KERNEL_MACHINE_HEADER
+#define GRUB_KERNEL_MACHINE_HEADER 1
+
+#ifndef ASM_FILE
+
+#define GRUB_KERNEL_USE_RSDP_ADDR 1
+
+extern grub_uint64_t EXPORT_VAR(grub_rsdp_addr);
+
+#endif /* ! ASM_FILE */
+
+#endif /* GRUB_KERNEL_MACHINE_HEADER */
diff --git a/include/grub/i386/xen_pvh/memory.h b/include/grub/i386/xen_pvh/memory.h
new file mode 100644
index 0000000..8dd6f7c
--- /dev/null
+++ b/include/grub/i386/xen_pvh/memory.h
@@ -0,0 +1 @@
+#include <grub/i386/coreboot/memory.h>
diff --git a/include/grub/i386/xen_pvh/time.h b/include/grub/i386/xen_pvh/time.h
new file mode 100644
index 0000000..2298ee8
--- /dev/null
+++ b/include/grub/i386/xen_pvh/time.h
@@ -0,0 +1 @@
+#include <grub/i386/pc/time.h>
diff --git a/include/grub/i386/xnu.h b/include/grub/i386/xnu.h
new file mode 100644
index 0000000..062a7dd
--- /dev/null
+++ b/include/grub/i386/xnu.h
@@ -0,0 +1,149 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_CPU_XNU_H
+#define GRUB_CPU_XNU_H 1
+
+#include <grub/err.h>
+#include <grub/efi/api.h>
+#include <grub/cpu/relocator.h>
+
+#define XNU_RELOCATOR(x) (grub_relocator32_ ## x)
+
+#define GRUB_XNU_PAGESIZE 4096
+typedef grub_uint32_t grub_xnu_ptr_t;
+
+struct grub_xnu_boot_params_common
+{
+ /* Command line passed to xnu. */
+ grub_uint8_t cmdline[1024];
+
+ /* Later are the same as EFI's get_memory_map (). */
+ grub_xnu_ptr_t efi_mmap;
+ grub_uint32_t efi_mmap_size;
+ grub_uint32_t efi_mem_desc_size;
+ grub_uint32_t efi_mem_desc_version;
+
+ /* Later are video parameters. */
+ grub_xnu_ptr_t lfb_base;
+#define GRUB_XNU_VIDEO_SPLASH 1
+#define GRUB_XNU_VIDEO_TEXT_IN_VIDEO 2
+ grub_uint32_t lfb_mode;
+ grub_uint32_t lfb_line_len;
+ grub_uint32_t lfb_width;
+ grub_uint32_t lfb_height;
+ grub_uint32_t lfb_depth;
+
+ /* Pointer to device tree and its len. */
+ grub_xnu_ptr_t devtree;
+ grub_uint32_t devtreelen;
+
+ /* First used address by kernel or boot structures. */
+ grub_xnu_ptr_t heap_start;
+ /* Last used address by kernel or boot structures minus previous value. */
+ grub_uint32_t heap_size;
+ /* First memory page containing runtime code or data. */
+ grub_uint32_t efi_runtime_first_page;
+ /* First memory page containing runtime code or data minus previous value. */
+ grub_uint32_t efi_runtime_npages;
+} GRUB_PACKED;
+
+struct grub_xnu_boot_params_v1
+{
+ grub_uint16_t verminor;
+ grub_uint16_t vermajor;
+ struct grub_xnu_boot_params_common common;
+
+ grub_uint32_t efi_system_table;
+ /* Size of grub_efi_uintn_t in bits. */
+ grub_uint8_t efi_uintnbits;
+} GRUB_PACKED;
+#define GRUB_XNU_BOOTARGSV1_VERMINOR 5
+#define GRUB_XNU_BOOTARGSV1_VERMAJOR 1
+
+struct grub_xnu_boot_params_v2
+{
+ grub_uint16_t verminor;
+ grub_uint16_t vermajor;
+
+ /* Size of grub_efi_uintn_t in bits. */
+ grub_uint8_t efi_uintnbits;
+ grub_uint8_t unused[3];
+
+ struct grub_xnu_boot_params_common common;
+
+ grub_uint64_t efi_runtime_first_page_virtual;
+ grub_uint32_t efi_system_table;
+ grub_uint32_t unused2[9];
+ grub_uint64_t ram_size;
+ grub_uint64_t fsbfreq;
+ grub_uint32_t unused3[734];
+} GRUB_PACKED;
+#define GRUB_XNU_BOOTARGSV2_VERMINOR 0
+#define GRUB_XNU_BOOTARGSV2_VERMAJOR 2
+
+union grub_xnu_boot_params_any
+{
+ struct grub_xnu_boot_params_v1 v1;
+ struct grub_xnu_boot_params_v2 v2;
+};
+
+struct grub_xnu_devprop_header
+{
+ grub_uint32_t length;
+ /* Always set to 1. Version? */
+ grub_uint32_t alwaysone;
+ grub_uint32_t num_devices;
+};
+
+struct grub_xnu_devprop_device_header
+{
+ grub_uint32_t length;
+ grub_uint32_t num_values;
+};
+
+void grub_cpu_xnu_unload (void);
+
+struct grub_xnu_devprop_device_descriptor;
+
+struct grub_xnu_devprop_device_descriptor *
+grub_xnu_devprop_add_device (struct grub_efi_device_path *path, int length);
+grub_err_t
+grub_xnu_devprop_remove_device (struct grub_xnu_devprop_device_descriptor *dev);
+grub_err_t
+grub_xnu_devprop_remove_property (struct grub_xnu_devprop_device_descriptor *dev,
+ char *name);
+grub_err_t
+grub_xnu_devprop_add_property_utf8 (struct grub_xnu_devprop_device_descriptor *dev,
+ char *name, void *data, int datalen);
+grub_err_t
+grub_xnu_devprop_add_property_utf16 (struct grub_xnu_devprop_device_descriptor *dev,
+ grub_uint16_t *name, int namelen,
+ void *data, int datalen);
+grub_err_t
+grub_xnu_devprop_remove_property_utf8 (struct grub_xnu_devprop_device_descriptor *dev,
+ char *name);
+void grub_cpu_xnu_init (void);
+void grub_cpu_xnu_fini (void);
+
+extern grub_uint32_t grub_xnu_entry_point;
+extern grub_uint32_t grub_xnu_stack;
+extern grub_uint32_t grub_xnu_arg1;
+extern char grub_xnu_cmdline[1024];
+grub_err_t grub_xnu_boot (void);
+#endif
diff --git a/include/grub/ia64/efi/memory.h b/include/grub/ia64/efi/memory.h
new file mode 100644
index 0000000..2c64918
--- /dev/null
+++ b/include/grub/ia64/efi/memory.h
@@ -0,0 +1,6 @@
+#ifndef GRUB_MEMORY_CPU_HEADER
+#include <grub/efi/memory.h>
+
+#define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffff
+
+#endif /* ! GRUB_MEMORY_CPU_HEADER */
diff --git a/include/grub/ia64/efi/time.h b/include/grub/ia64/efi/time.h
new file mode 100644
index 0000000..897ce9c
--- /dev/null
+++ b/include/grub/ia64/efi/time.h
@@ -0,0 +1,23 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef GRUB_MACHINE_TIME_HEADER
+#define GRUB_MACHINE_TIME_HEADER 1
+
+#include <grub/efi/time.h>
+
+#endif /* ! GRUB_MACHINE_TIME_HEADER */
diff --git a/include/grub/ia64/kernel.h b/include/grub/ia64/kernel.h
new file mode 100644
index 0000000..c5496a0
--- /dev/null
+++ b/include/grub/ia64/kernel.h
@@ -0,0 +1,25 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_CPU_KERNEL_HEADER
+#define GRUB_CPU_KERNEL_HEADER 1
+
+#define GRUB_MOD_ALIGN 0x1
+#define GRUB_MOD_GAP 0x0
+
+#endif /* ! GRUB_CPU_KERNEL_HEADER */
diff --git a/include/grub/ia64/reloc.h b/include/grub/ia64/reloc.h
new file mode 100644
index 0000000..45c8fba
--- /dev/null
+++ b/include/grub/ia64/reloc.h
@@ -0,0 +1,44 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_IA64_RELOC_H
+#define GRUB_IA64_RELOC_H 1
+
+struct grub_ia64_trampoline;
+
+void
+grub_ia64_add_value_to_slot_20b (grub_addr_t addr, grub_uint32_t value);
+void
+grub_ia64_add_value_to_slot_21 (grub_addr_t addr, grub_uint32_t value);
+void
+grub_ia64_set_immu64 (grub_addr_t addr, grub_uint64_t value);
+void
+grub_ia64_make_trampoline (struct grub_ia64_trampoline *tr, grub_uint64_t addr);
+
+struct grub_ia64_trampoline
+{
+ /* nop.m */
+ grub_uint8_t nop[5];
+ /* movl r15 = addr*/
+ grub_uint8_t addr_hi[6];
+ grub_uint8_t e0;
+ grub_uint8_t addr_lo[4];
+ grub_uint8_t jump[0x20];
+};
+
+#endif
diff --git a/include/grub/ia64/setjmp.h b/include/grub/ia64/setjmp.h
new file mode 100644
index 0000000..0a62113
--- /dev/null
+++ b/include/grub/ia64/setjmp.h
@@ -0,0 +1,28 @@
+/* Define the machine-dependent type `jmp_buf'. Linux/IA-64 version.
+ Copyright (C) 1999, 2000, 2008 Free Software Foundation, Inc.
+ Contributed by David Mosberger-Tang <davidm@hpl.hp.com>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/* User code must not depend on the internal representation of jmp_buf. */
+
+#define _JBLEN 70
+
+/* the __jmp_buf element type should be __float80 per ABI... */
+typedef long grub_jmp_buf[_JBLEN] __attribute__ ((aligned (16))); /* guarantees 128-bit alignment! */
+
+int grub_setjmp (grub_jmp_buf env) RETURNS_TWICE;
+void grub_longjmp (grub_jmp_buf env, int val) __attribute__ ((noreturn));
diff --git a/include/grub/ia64/time.h b/include/grub/ia64/time.h
new file mode 100644
index 0000000..03ee79f
--- /dev/null
+++ b/include/grub/ia64/time.h
@@ -0,0 +1,28 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2007, 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef KERNEL_CPU_TIME_HEADER
+#define KERNEL_CPU_TIME_HEADER 1
+
+static __inline void
+grub_cpu_idle (void)
+{
+ /* FIXME: not implemented */
+}
+
+#endif /* ! KERNEL_CPU_TIME_HEADER */
diff --git a/include/grub/ia64/types.h b/include/grub/ia64/types.h
new file mode 100644
index 0000000..91a546d
--- /dev/null
+++ b/include/grub/ia64/types.h
@@ -0,0 +1,32 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_TYPES_CPU_HEADER
+#define GRUB_TYPES_CPU_HEADER 1
+
+/* The size of void *. */
+#define GRUB_TARGET_SIZEOF_VOID_P 8
+
+/* The size of long. */
+#define GRUB_TARGET_SIZEOF_LONG 8
+
+/* ia64 is little-endian (usually). */
+#undef GRUB_TARGET_WORDS_BIGENDIAN
+
+
+#endif /* ! GRUB_TYPES_CPU_HEADER */
diff --git a/include/grub/icon_manager.h b/include/grub/icon_manager.h
new file mode 100644
index 0000000..81c4884
--- /dev/null
+++ b/include/grub/icon_manager.h
@@ -0,0 +1,41 @@
+/* icon_manager.h - gfxmenu icon manager. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_ICON_MANAGER_HEADER
+#define GRUB_ICON_MANAGER_HEADER 1
+
+#include <grub/menu.h>
+#include <grub/bitmap.h>
+
+/* Forward declaration of opaque structure handle type. */
+typedef struct grub_gfxmenu_icon_manager *grub_gfxmenu_icon_manager_t;
+
+grub_gfxmenu_icon_manager_t grub_gfxmenu_icon_manager_new (void);
+void grub_gfxmenu_icon_manager_destroy (grub_gfxmenu_icon_manager_t mgr);
+void grub_gfxmenu_icon_manager_clear_cache (grub_gfxmenu_icon_manager_t mgr);
+void grub_gfxmenu_icon_manager_set_theme_path (grub_gfxmenu_icon_manager_t mgr,
+ const char *path);
+void grub_gfxmenu_icon_manager_set_icon_size (grub_gfxmenu_icon_manager_t mgr,
+ int width, int height);
+struct grub_video_bitmap *
+grub_gfxmenu_icon_manager_get_icon (grub_gfxmenu_icon_manager_t mgr,
+ grub_menu_entry_t entry);
+
+#endif /* GRUB_ICON_MANAGER_HEADER */
+
diff --git a/include/grub/ieee1275/console.h b/include/grub/ieee1275/console.h
new file mode 100644
index 0000000..bdd98fe
--- /dev/null
+++ b/include/grub/ieee1275/console.h
@@ -0,0 +1,34 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_CONSOLE_MACHINE_HEADER
+#define GRUB_CONSOLE_MACHINE_HEADER 1
+
+#include <grub/symbol.h>
+
+/* Initialize the console system. */
+void grub_console_init_early (void);
+void grub_console_init_lately (void);
+
+/* Finish the console system. */
+void grub_console_fini (void);
+
+const char *
+grub_ofserial_add_port (const char *name);
+
+#endif /* ! GRUB_CONSOLE_MACHINE_HEADER */
diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h
new file mode 100644
index 0000000..73e2f46
--- /dev/null
+++ b/include/grub/ieee1275/ieee1275.h
@@ -0,0 +1,266 @@
+/* ieee1275.h - Access the Open Firmware client interface. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_IEEE1275_HEADER
+#define GRUB_IEEE1275_HEADER 1
+
+#include <grub/err.h>
+#include <grub/types.h>
+#include <grub/machine/ieee1275.h>
+
+struct grub_ieee1275_mem_region
+{
+ unsigned int start;
+ unsigned int size;
+};
+
+#define IEEE1275_MAX_PROP_LEN 8192
+#define IEEE1275_MAX_PATH_LEN 256
+
+#ifndef IEEE1275_CALL_ENTRY_FN
+#define IEEE1275_CALL_ENTRY_FN(args) (*grub_ieee1275_entry_fn) (args)
+#endif
+
+/* All backcalls to the firmware is done by calling an entry function
+ which was passed to us from the bootloader. When doing the backcall,
+ a structure is passed which specifies what the firmware should do.
+ NAME is the requested service. NR_INS and NR_OUTS is the number of
+ passed arguments and the expected number of return values, resp. */
+struct grub_ieee1275_common_hdr
+{
+ grub_ieee1275_cell_t name;
+ grub_ieee1275_cell_t nr_ins;
+ grub_ieee1275_cell_t nr_outs;
+};
+
+#define INIT_IEEE1275_COMMON(p, xname, xins, xouts) \
+ (p)->name = (grub_ieee1275_cell_t) xname; \
+ (p)->nr_ins = (grub_ieee1275_cell_t) xins; \
+ (p)->nr_outs = (grub_ieee1275_cell_t) xouts
+
+typedef grub_uint32_t grub_ieee1275_ihandle_t;
+typedef grub_uint32_t grub_ieee1275_phandle_t;
+
+#define GRUB_IEEE1275_PHANDLE_INVALID ((grub_ieee1275_phandle_t) -1)
+
+struct grub_ieee1275_devalias
+{
+ char *name;
+ char *path;
+ char *type;
+ char *parent_path;
+ grub_ieee1275_phandle_t phandle;
+ grub_ieee1275_phandle_t parent_dev;
+};
+
+extern void (*EXPORT_VAR(grub_ieee1275_net_config)) (const char *dev,
+ char **device,
+ char **path,
+ char *bootargs);
+
+/* Maps a device alias to a pathname. */
+extern grub_ieee1275_phandle_t EXPORT_VAR(grub_ieee1275_chosen);
+extern grub_ieee1275_ihandle_t EXPORT_VAR(grub_ieee1275_mmu);
+#ifdef __i386__
+#define GRUB_IEEE1275_ENTRY_FN_ATTRIBUTE __attribute__ ((regparm(3)))
+#else
+#define GRUB_IEEE1275_ENTRY_FN_ATTRIBUTE
+#endif
+
+extern int (* EXPORT_VAR(grub_ieee1275_entry_fn)) (void *) GRUB_IEEE1275_ENTRY_FN_ATTRIBUTE;
+
+/* Static heap, used only if FORCE_CLAIM is set,
+ happens on Open Hack'Ware. Should be in platform-specific
+ header but is used only on PPC anyway.
+*/
+#define GRUB_IEEE1275_STATIC_HEAP_START 0x1000000
+#define GRUB_IEEE1275_STATIC_HEAP_LEN 0x1000000
+
+
+enum grub_ieee1275_flag
+{
+ /* Old World Macintosh firmware fails seek when "dev:0" is opened. */
+ GRUB_IEEE1275_FLAG_NO_PARTITION_0,
+
+ /* Apple firmware runs in translated mode and requires use of the "map"
+ method. Other firmware runs in untranslated mode and doesn't like "map"
+ calls. */
+ GRUB_IEEE1275_FLAG_REAL_MODE,
+
+ /* CHRP specifies partitions are numbered from 1 (partition 0 refers to the
+ whole disk). However, CodeGen firmware numbers partitions from 0. */
+ GRUB_IEEE1275_FLAG_0_BASED_PARTITIONS,
+
+ /* CodeGen firmware does not correctly implement "output-device output" */
+ GRUB_IEEE1275_FLAG_BROKEN_OUTPUT,
+
+ /* OLPC / XO firmware hangs when accessing USB devices. */
+ GRUB_IEEE1275_FLAG_OFDISK_SDCARD_ONLY,
+
+ /* Open Hack'Ware stops when trying to set colors */
+ GRUB_IEEE1275_FLAG_CANNOT_SET_COLORS,
+
+ /* Open Hack'Ware stops when grub_ieee1275_interpret is used. */
+ GRUB_IEEE1275_FLAG_CANNOT_INTERPRET,
+
+ /* Open Hack'Ware has no memory map, just claim what we need. */
+ GRUB_IEEE1275_FLAG_FORCE_CLAIM,
+
+ /* Open Hack'Ware don't support the ANSI sequence. */
+ GRUB_IEEE1275_FLAG_NO_ANSI,
+
+ /* OpenFirmware hangs on qemu if one requests any memory below 1.5 MiB. */
+ GRUB_IEEE1275_FLAG_NO_PRE1_5M_CLAIM,
+
+ /* OLPC / XO firmware has the cursor ON/OFF routines. */
+ GRUB_IEEE1275_FLAG_HAS_CURSORONOFF,
+
+ /* Some PowerMacs claim to use 2 address cells but in fact use only 1.
+ Other PowerMacs claim to use only 1 and really do so. Always assume
+ 1 address cell is used on PowerMacs.
+ */
+ GRUB_IEEE1275_FLAG_BROKEN_ADDRESS_CELLS,
+
+ GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS,
+
+ GRUB_IEEE1275_FLAG_NO_OFNET_SUFFIX,
+
+ GRUB_IEEE1275_FLAG_VIRT_TO_REAL_BROKEN,
+
+ GRUB_IEEE1275_FLAG_BROKEN_REPEAT,
+
+ GRUB_IEEE1275_FLAG_CURSORONOFF_ANSI_BROKEN,
+
+ GRUB_IEEE1275_FLAG_RAW_DEVNAMES,
+};
+
+extern int EXPORT_FUNC(grub_ieee1275_test_flag) (enum grub_ieee1275_flag flag);
+extern void EXPORT_FUNC(grub_ieee1275_set_flag) (enum grub_ieee1275_flag flag);
+
+
+
+
+void EXPORT_FUNC(grub_ieee1275_init) (void);
+int EXPORT_FUNC(grub_ieee1275_finddevice) (const char *name,
+ grub_ieee1275_phandle_t *phandlep);
+int EXPORT_FUNC(grub_ieee1275_get_property) (grub_ieee1275_phandle_t phandle,
+ const char *property, void *buf,
+ grub_size_t size,
+ grub_ssize_t *actual);
+int EXPORT_FUNC(grub_ieee1275_get_integer_property) (grub_ieee1275_phandle_t phandle,
+ const char *property, grub_uint32_t *buf,
+ grub_size_t size,
+ grub_ssize_t *actual);
+int EXPORT_FUNC(grub_ieee1275_next_property) (grub_ieee1275_phandle_t phandle,
+ char *prev_prop, char *prop);
+int EXPORT_FUNC(grub_ieee1275_get_property_length)
+ (grub_ieee1275_phandle_t phandle, const char *prop, grub_ssize_t *length);
+int EXPORT_FUNC(grub_ieee1275_instance_to_package)
+ (grub_ieee1275_ihandle_t ihandle, grub_ieee1275_phandle_t *phandlep);
+int EXPORT_FUNC(grub_ieee1275_package_to_path) (grub_ieee1275_phandle_t phandle,
+ char *path, grub_size_t len,
+ grub_ssize_t *actual);
+int EXPORT_FUNC(grub_ieee1275_instance_to_path)
+ (grub_ieee1275_ihandle_t ihandle, char *path, grub_size_t len,
+ grub_ssize_t *actual);
+int EXPORT_FUNC(grub_ieee1275_write) (grub_ieee1275_ihandle_t ihandle,
+ const void *buffer, grub_size_t len,
+ grub_ssize_t *actualp);
+int EXPORT_FUNC(grub_ieee1275_read) (grub_ieee1275_ihandle_t ihandle,
+ void *buffer, grub_size_t len,
+ grub_ssize_t *actualp);
+int EXPORT_FUNC(grub_ieee1275_seek) (grub_ieee1275_ihandle_t ihandle,
+ grub_disk_addr_t pos,
+ grub_ssize_t *result);
+int EXPORT_FUNC(grub_ieee1275_peer) (grub_ieee1275_phandle_t node,
+ grub_ieee1275_phandle_t *result);
+int EXPORT_FUNC(grub_ieee1275_child) (grub_ieee1275_phandle_t node,
+ grub_ieee1275_phandle_t *result);
+int EXPORT_FUNC(grub_ieee1275_parent) (grub_ieee1275_phandle_t node,
+ grub_ieee1275_phandle_t *result);
+int EXPORT_FUNC(grub_ieee1275_interpret) (const char *command,
+ grub_ieee1275_cell_t *catch);
+int EXPORT_FUNC(grub_ieee1275_enter) (void);
+void EXPORT_FUNC(grub_ieee1275_exit) (void) __attribute__ ((noreturn));
+int EXPORT_FUNC(grub_ieee1275_open) (const char *node,
+ grub_ieee1275_ihandle_t *result);
+int EXPORT_FUNC(grub_ieee1275_close) (grub_ieee1275_ihandle_t ihandle);
+int EXPORT_FUNC(grub_ieee1275_claim) (grub_addr_t addr, grub_size_t size,
+ unsigned int align, grub_addr_t *result);
+int EXPORT_FUNC(grub_ieee1275_release) (grub_addr_t addr, grub_size_t size);
+int EXPORT_FUNC(grub_ieee1275_set_property) (grub_ieee1275_phandle_t phandle,
+ const char *propname,
+ const void *buf,
+ grub_size_t size,
+ grub_ssize_t *actual);
+int EXPORT_FUNC(grub_ieee1275_set_color) (grub_ieee1275_ihandle_t ihandle,
+ int index, int r, int g, int b);
+int EXPORT_FUNC(grub_ieee1275_milliseconds) (grub_uint32_t *msecs);
+int EXPORT_FUNC(grub_ieee1275_set_address) (grub_ieee1275_ihandle_t ihandle,
+ grub_uint32_t target,
+ grub_uint32_t lun);
+int EXPORT_FUNC(grub_ieee1275_no_data_command) (grub_ieee1275_ihandle_t ihandle,
+ const void *cmd_addr,
+ grub_ssize_t *result);
+int EXPORT_FUNC(grub_ieee1275_decode_unit4) (grub_ieee1275_ihandle_t ihandle,
+ void *addr, grub_size_t size,
+ grub_uint32_t *phy_lo,
+ grub_uint32_t *phy_hi,
+ grub_uint32_t *lun_lo,
+ grub_uint32_t *lun_hi);
+char *EXPORT_FUNC(grub_ieee1275_encode_uint4) (grub_ieee1275_ihandle_t ihandle,
+ grub_uint32_t phy_lo,
+ grub_uint32_t phy_hi,
+ grub_uint32_t lun_lo,
+ grub_uint32_t lun_hi,
+ grub_size_t *size);
+int EXPORT_FUNC(grub_ieee1275_get_block_size) (grub_ieee1275_ihandle_t ihandle);
+
+grub_err_t EXPORT_FUNC(grub_claimmap) (grub_addr_t addr, grub_size_t size);
+
+int
+EXPORT_FUNC(grub_ieee1275_map) (grub_addr_t phys, grub_addr_t virt,
+ grub_size_t size, grub_uint32_t mode);
+
+char *EXPORT_FUNC(grub_ieee1275_encode_devname) (const char *path);
+char *EXPORT_FUNC(grub_ieee1275_get_filename) (const char *path);
+int EXPORT_FUNC(grub_ieee1275_devices_iterate) (int (*hook)
+ (struct grub_ieee1275_devalias *
+ alias));
+char *EXPORT_FUNC(grub_ieee1275_get_aliasdevname) (const char *path);
+char *EXPORT_FUNC(grub_ieee1275_canonicalise_devname) (const char *path);
+char *EXPORT_FUNC(grub_ieee1275_get_device_type) (const char *path);
+char *EXPORT_FUNC(grub_ieee1275_get_devname) (const char *path);
+
+void EXPORT_FUNC(grub_ieee1275_devalias_init_iterator) (struct grub_ieee1275_devalias *alias);
+void EXPORT_FUNC(grub_ieee1275_devalias_free) (struct grub_ieee1275_devalias *alias);
+int EXPORT_FUNC(grub_ieee1275_devalias_next) (struct grub_ieee1275_devalias *alias);
+void EXPORT_FUNC(grub_ieee1275_children_peer) (struct grub_ieee1275_devalias *alias);
+void EXPORT_FUNC(grub_ieee1275_children_first) (const char *devpath,
+ struct grub_ieee1275_devalias *alias);
+
+char *EXPORT_FUNC(grub_ieee1275_get_boot_dev) (void);
+
+#define FOR_IEEE1275_DEVALIASES(alias) for (grub_ieee1275_devalias_init_iterator (&(alias)); grub_ieee1275_devalias_next (&(alias));)
+
+#define FOR_IEEE1275_DEVCHILDREN(devpath, alias) for (grub_ieee1275_children_first ((devpath), &(alias)); \
+ (alias).name; \
+ grub_ieee1275_children_peer (&(alias)))
+
+#endif /* ! GRUB_IEEE1275_HEADER */
diff --git a/include/grub/ieee1275/obdisk.h b/include/grub/ieee1275/obdisk.h
new file mode 100644
index 0000000..5da51f8
--- /dev/null
+++ b/include/grub/ieee1275/obdisk.h
@@ -0,0 +1,25 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2019 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_OBDISK_HEADER
+#define GRUB_OBDISK_HEADER 1
+
+extern void grub_obdisk_init (void);
+extern void grub_obdisk_fini (void);
+
+#endif
diff --git a/include/grub/ieee1275/ofdisk.h b/include/grub/ieee1275/ofdisk.h
new file mode 100644
index 0000000..2f69e3f
--- /dev/null
+++ b/include/grub/ieee1275/ofdisk.h
@@ -0,0 +1,25 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2005,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_OFDISK_HEADER
+#define GRUB_OFDISK_HEADER 1
+
+extern void grub_ofdisk_init (void);
+extern void grub_ofdisk_fini (void);
+
+#endif /* ! GRUB_INIT_HEADER */
diff --git a/include/grub/kernel.h b/include/grub/kernel.h
new file mode 100644
index 0000000..abbca5e
--- /dev/null
+++ b/include/grub/kernel.h
@@ -0,0 +1,132 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_KERNEL_HEADER
+#define GRUB_KERNEL_HEADER 1
+
+#include <grub/types.h>
+#include <grub/symbol.h>
+
+enum
+{
+ OBJ_TYPE_ELF,
+ OBJ_TYPE_MEMDISK,
+ OBJ_TYPE_CONFIG,
+ OBJ_TYPE_PREFIX,
+ OBJ_TYPE_PUBKEY,
+ OBJ_TYPE_DTB,
+ OBJ_TYPE_DISABLE_SHIM_LOCK
+};
+
+/* The module header. */
+struct grub_module_header
+{
+ /* The type of object. */
+ grub_uint32_t type;
+ /* The size of object (including this header). */
+ grub_uint32_t size;
+};
+
+/* "gmim" (GRUB Module Info Magic). */
+#define GRUB_MODULE_MAGIC 0x676d696d
+
+struct grub_module_info32
+{
+ /* Magic number so we know we have modules present. */
+ grub_uint32_t magic;
+ /* The offset of the modules. */
+ grub_uint32_t offset;
+ /* The size of all modules plus this header. */
+ grub_uint32_t size;
+};
+
+struct grub_module_info64
+{
+ /* Magic number so we know we have modules present. */
+ grub_uint32_t magic;
+ grub_uint32_t padding;
+ /* The offset of the modules. */
+ grub_uint64_t offset;
+ /* The size of all modules plus this header. */
+ grub_uint64_t size;
+};
+
+#ifndef GRUB_UTIL
+/* Space isn't reusable on some platforms. */
+/* On Qemu the preload space is readonly. */
+/* On emu there is no preload space. */
+/* On ieee1275 our code assumes that heap is p=v which isn't guaranteed for module space. */
+#if defined (GRUB_MACHINE_QEMU) || defined (GRUB_MACHINE_EMU) \
+ || defined (GRUB_MACHINE_EFI) \
+ || (defined (GRUB_MACHINE_IEEE1275) && !defined (__sparc__))
+#define GRUB_KERNEL_PRELOAD_SPACE_REUSABLE 0
+#endif
+
+#if defined (GRUB_MACHINE_PCBIOS) || defined (GRUB_MACHINE_COREBOOT) \
+ || defined (GRUB_MACHINE_MULTIBOOT) || defined (GRUB_MACHINE_MIPS_QEMU_MIPS) \
+ || defined (GRUB_MACHINE_MIPS_LOONGSON) || defined (GRUB_MACHINE_ARC) \
+ || (defined (__sparc__) && defined (GRUB_MACHINE_IEEE1275)) \
+ || defined (GRUB_MACHINE_UBOOT) || defined (GRUB_MACHINE_XEN) \
+ || defined(GRUB_MACHINE_XEN_PVH)
+/* FIXME: stack is between 2 heap regions. Move it. */
+#define GRUB_KERNEL_PRELOAD_SPACE_REUSABLE 1
+#endif
+
+#ifndef GRUB_KERNEL_PRELOAD_SPACE_REUSABLE
+#error "Please check if preload space is reusable on this platform!"
+#endif
+
+#if GRUB_TARGET_SIZEOF_VOID_P == 8
+#define grub_module_info grub_module_info64
+#else
+#define grub_module_info grub_module_info32
+#endif
+
+extern grub_addr_t EXPORT_VAR (grub_modbase);
+
+#define FOR_MODULES(var) for (\
+ var = (grub_modbase && ((((struct grub_module_info *) grub_modbase)->magic) == GRUB_MODULE_MAGIC)) ? (struct grub_module_header *) \
+ (grub_modbase + (((struct grub_module_info *) grub_modbase)->offset)) : 0;\
+ var && (grub_addr_t) var \
+ < (grub_modbase + (((struct grub_module_info *) grub_modbase)->size)); \
+ var = (struct grub_module_header *) \
+ (((grub_uint32_t *) var) + ((((struct grub_module_header *) var)->size + sizeof (grub_addr_t) - 1) / sizeof (grub_addr_t)) * (sizeof (grub_addr_t) / sizeof (grub_uint32_t))))
+
+grub_addr_t grub_modules_get_end (void);
+
+#endif
+
+/* The start point of the C code. */
+void grub_main (void) __attribute__ ((noreturn));
+
+/* The machine-specific initialization. This must initialize memory. */
+void grub_machine_init (void);
+
+/* The machine-specific finalization. */
+void EXPORT_FUNC(grub_machine_fini) (int flags);
+
+/* The machine-specific prefix initialization. */
+void
+grub_machine_get_bootlocation (char **device, char **path);
+
+/* Register all the exported symbols. This is automatically generated. */
+void grub_register_exported_symbols (void);
+
+extern void (*EXPORT_VAR(grub_net_poll_cards_idle)) (void);
+
+#endif /* ! GRUB_KERNEL_HEADER */
diff --git a/include/grub/keyboard_layouts.h b/include/grub/keyboard_layouts.h
new file mode 100644
index 0000000..1bad286
--- /dev/null
+++ b/include/grub/keyboard_layouts.h
@@ -0,0 +1,150 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_KEYBOARD_LAYOUTS_H
+#define GRUB_KEYBOARD_LAYOUTS_H 1
+
+#define GRUB_KEYBOARD_LAYOUTS_FILEMAGIC "GRUBLAYO"
+#define GRUB_KEYBOARD_LAYOUTS_FILEMAGIC_SIZE (sizeof(GRUB_KEYBOARD_LAYOUTS_FILEMAGIC) - 1)
+#define GRUB_KEYBOARD_LAYOUTS_VERSION 10
+
+#define GRUB_KEYBOARD_LAYOUTS_ARRAY_SIZE 160
+
+struct grub_keyboard_layout
+{
+ grub_uint32_t keyboard_map[GRUB_KEYBOARD_LAYOUTS_ARRAY_SIZE];
+ grub_uint32_t keyboard_map_shift[GRUB_KEYBOARD_LAYOUTS_ARRAY_SIZE];
+ grub_uint32_t keyboard_map_l3[GRUB_KEYBOARD_LAYOUTS_ARRAY_SIZE];
+ grub_uint32_t keyboard_map_shift_l3[GRUB_KEYBOARD_LAYOUTS_ARRAY_SIZE];
+};
+
+typedef enum grub_keyboard_key
+ {
+ GRUB_KEYBOARD_KEY_A = 0x04,
+ GRUB_KEYBOARD_KEY_B = 0x05,
+ GRUB_KEYBOARD_KEY_C = 0x06,
+ GRUB_KEYBOARD_KEY_D = 0x07,
+ GRUB_KEYBOARD_KEY_E = 0x08,
+ GRUB_KEYBOARD_KEY_F = 0x09,
+ GRUB_KEYBOARD_KEY_G = 0x0a,
+ GRUB_KEYBOARD_KEY_H = 0x0b,
+ GRUB_KEYBOARD_KEY_I = 0x0c,
+ GRUB_KEYBOARD_KEY_J = 0x0d,
+ GRUB_KEYBOARD_KEY_K = 0x0e,
+ GRUB_KEYBOARD_KEY_L = 0x0f,
+ GRUB_KEYBOARD_KEY_M = 0x10,
+ GRUB_KEYBOARD_KEY_N = 0x11,
+ GRUB_KEYBOARD_KEY_O = 0x12,
+ GRUB_KEYBOARD_KEY_P = 0x13,
+ GRUB_KEYBOARD_KEY_Q = 0x14,
+ GRUB_KEYBOARD_KEY_R = 0x15,
+ GRUB_KEYBOARD_KEY_S = 0x16,
+ GRUB_KEYBOARD_KEY_T = 0x17,
+ GRUB_KEYBOARD_KEY_U = 0x18,
+ GRUB_KEYBOARD_KEY_V = 0x19,
+ GRUB_KEYBOARD_KEY_W = 0x1a,
+ GRUB_KEYBOARD_KEY_X = 0x1b,
+ GRUB_KEYBOARD_KEY_Y = 0x1c,
+ GRUB_KEYBOARD_KEY_Z = 0x1d,
+ GRUB_KEYBOARD_KEY_1 = 0x1e,
+ GRUB_KEYBOARD_KEY_2 = 0x1f,
+ GRUB_KEYBOARD_KEY_3 = 0x20,
+ GRUB_KEYBOARD_KEY_4 = 0x21,
+ GRUB_KEYBOARD_KEY_5 = 0x22,
+ GRUB_KEYBOARD_KEY_6 = 0x23,
+ GRUB_KEYBOARD_KEY_7 = 0x24,
+ GRUB_KEYBOARD_KEY_8 = 0x25,
+ GRUB_KEYBOARD_KEY_9 = 0x26,
+ GRUB_KEYBOARD_KEY_0 = 0x27,
+ GRUB_KEYBOARD_KEY_ENTER = 0x28,
+ GRUB_KEYBOARD_KEY_ESCAPE = 0x29,
+ GRUB_KEYBOARD_KEY_BACKSPACE = 0x2a,
+ GRUB_KEYBOARD_KEY_TAB = 0x2b,
+ GRUB_KEYBOARD_KEY_SPACE = 0x2c,
+ GRUB_KEYBOARD_KEY_DASH = 0x2d,
+ GRUB_KEYBOARD_KEY_EQUAL = 0x2e,
+ GRUB_KEYBOARD_KEY_LBRACKET = 0x2f,
+ GRUB_KEYBOARD_KEY_RBRACKET = 0x30,
+ GRUB_KEYBOARD_KEY_BACKSLASH = 0x32,
+ GRUB_KEYBOARD_KEY_SEMICOLON = 0x33,
+ GRUB_KEYBOARD_KEY_DQUOTE = 0x34,
+ GRUB_KEYBOARD_KEY_RQUOTE = 0x35,
+ GRUB_KEYBOARD_KEY_COMMA = 0x36,
+ GRUB_KEYBOARD_KEY_DOT = 0x37,
+ GRUB_KEYBOARD_KEY_SLASH = 0x38,
+ GRUB_KEYBOARD_KEY_CAPS_LOCK = 0x39,
+ GRUB_KEYBOARD_KEY_F1 = 0x3a,
+ GRUB_KEYBOARD_KEY_F2 = 0x3b,
+ GRUB_KEYBOARD_KEY_F3 = 0x3c,
+ GRUB_KEYBOARD_KEY_F4 = 0x3d,
+ GRUB_KEYBOARD_KEY_F5 = 0x3e,
+ GRUB_KEYBOARD_KEY_F6 = 0x3f,
+ GRUB_KEYBOARD_KEY_F7 = 0x40,
+ GRUB_KEYBOARD_KEY_F8 = 0x41,
+ GRUB_KEYBOARD_KEY_F9 = 0x42,
+ GRUB_KEYBOARD_KEY_F10 = 0x43,
+ GRUB_KEYBOARD_KEY_F11 = 0x44,
+ GRUB_KEYBOARD_KEY_F12 = 0x45,
+ GRUB_KEYBOARD_KEY_SCROLL_LOCK = 0x47,
+ GRUB_KEYBOARD_KEY_INSERT = 0x49,
+ GRUB_KEYBOARD_KEY_HOME = 0x4a,
+ GRUB_KEYBOARD_KEY_PPAGE = 0x4b,
+ GRUB_KEYBOARD_KEY_DELETE = 0x4c,
+ GRUB_KEYBOARD_KEY_END = 0x4d,
+ GRUB_KEYBOARD_KEY_NPAGE = 0x4e,
+ GRUB_KEYBOARD_KEY_RIGHT = 0x4f,
+ GRUB_KEYBOARD_KEY_LEFT = 0x50,
+ GRUB_KEYBOARD_KEY_DOWN = 0x51,
+ GRUB_KEYBOARD_KEY_UP = 0x52,
+ GRUB_KEYBOARD_KEY_NUM_LOCK = 0x53,
+ GRUB_KEYBOARD_KEY_NUMSLASH = 0x54,
+ GRUB_KEYBOARD_KEY_NUMMUL = 0x55,
+ GRUB_KEYBOARD_KEY_NUMMINUS = 0x56,
+ GRUB_KEYBOARD_KEY_NUMPLUS = 0x57,
+ GRUB_KEYBOARD_KEY_NUMENTER = 0x58,
+ GRUB_KEYBOARD_KEY_NUM1 = 0x59,
+ GRUB_KEYBOARD_KEY_NUM2 = 0x5a,
+ GRUB_KEYBOARD_KEY_NUM3 = 0x5b,
+ GRUB_KEYBOARD_KEY_NUM4 = 0x5c,
+ GRUB_KEYBOARD_KEY_NUM5 = 0x5d,
+ GRUB_KEYBOARD_KEY_NUM6 = 0x5e,
+ GRUB_KEYBOARD_KEY_NUM7 = 0x5f,
+ GRUB_KEYBOARD_KEY_NUM8 = 0x60,
+ GRUB_KEYBOARD_KEY_NUM9 = 0x61,
+ GRUB_KEYBOARD_KEY_NUM0 = 0x62,
+ GRUB_KEYBOARD_KEY_NUMDOT = 0x63,
+ GRUB_KEYBOARD_KEY_102ND = 0x64,
+ GRUB_KEYBOARD_KEY_KPCOMMA = 0x85,
+ GRUB_KEYBOARD_KEY_JP_RO = 0x87,
+ GRUB_KEYBOARD_KEY_JP_YEN = 0x89,
+ GRUB_KEYBOARD_KEY_LEFT_CTRL = 0xe0,
+ GRUB_KEYBOARD_KEY_LEFT_SHIFT = 0xe1,
+ GRUB_KEYBOARD_KEY_LEFT_ALT = 0xe2,
+ GRUB_KEYBOARD_KEY_RIGHT_CTRL = 0xe4,
+ GRUB_KEYBOARD_KEY_RIGHT_SHIFT = 0xe5,
+ GRUB_KEYBOARD_KEY_RIGHT_ALT = 0xe6,
+ } grub_keyboard_key_t;
+
+unsigned EXPORT_FUNC(grub_term_map_key) (grub_keyboard_key_t code, int status);
+
+#ifndef GRUB_MACHINE_EMU
+extern void grub_keylayouts_init (void);
+extern void grub_keylayouts_fini (void);
+#endif
+
+#endif /* GRUB_KEYBOARD_LAYOUTS */
diff --git a/include/grub/legacy_parse.h b/include/grub/legacy_parse.h
new file mode 100644
index 0000000..7519505
--- /dev/null
+++ b/include/grub/legacy_parse.h
@@ -0,0 +1,32 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_LEGACY_PARSE_HEADER
+#define GRUB_LEGACY_PARSE_HEADER 1
+
+#include <grub/types.h>
+
+char *grub_legacy_parse (const char *buf, char **entryname, char **suffix);
+char *grub_legacy_escape (const char *in, grub_size_t len);
+
+/* Entered has to be GRUB_AUTH_MAX_PASSLEN long, zero-padded. */
+int
+grub_legacy_check_md5_password (int argc, char **args,
+ char *entered);
+
+#endif
diff --git a/include/grub/lib/LzFind.h b/include/grub/lib/LzFind.h
new file mode 100644
index 0000000..69447b6
--- /dev/null
+++ b/include/grub/lib/LzFind.h
@@ -0,0 +1,130 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (c) 1999-2008 Igor Pavlov
+ * Copyright (C) 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * This code was taken from LZMA SDK 4.58 beta, and was slightly modified
+ * to adapt it to GRUB's requirement.
+ *
+ * See <http://www.7-zip.org>, for more information about LZMA.
+ */
+
+#ifndef __LZFIND_H
+#define __LZFIND_H
+
+#include <grub/lib/LzmaTypes.h>
+
+typedef UInt32 CLzRef;
+
+typedef struct _CMatchFinder
+{
+ Byte *buffer;
+ UInt32 pos;
+ UInt32 posLimit;
+ UInt32 streamPos;
+ UInt32 lenLimit;
+
+ UInt32 cyclicBufferPos;
+ UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */
+
+ UInt32 matchMaxLen;
+ CLzRef *hash;
+ CLzRef *son;
+ UInt32 hashMask;
+ UInt32 cutValue;
+
+ Byte *bufferBase;
+ ISeqInStream *stream;
+ int streamEndWasReached;
+
+ UInt32 blockSize;
+ UInt32 keepSizeBefore;
+ UInt32 keepSizeAfter;
+
+ UInt32 numHashBytes;
+ int directInput;
+ int btMode;
+ /* int skipModeBits; */
+ int bigHash;
+ UInt32 historySize;
+ UInt32 fixedHashSize;
+ UInt32 hashSizeSum;
+ UInt32 numSons;
+ SRes result;
+ UInt32 crc[256];
+} CMatchFinder;
+
+#define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)
+#define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(Int32)(index)])
+
+#define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)
+
+int MatchFinder_NeedMove(CMatchFinder *p);
+Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);
+void MatchFinder_MoveBlock(CMatchFinder *p);
+void MatchFinder_ReadIfRequired(CMatchFinder *p);
+
+void MatchFinder_Construct(CMatchFinder *p);
+
+/* Conditions:
+ historySize <= 3 GB
+ keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB
+*/
+int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
+ UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
+ ISzAlloc *alloc);
+void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);
+void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems);
+void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);
+
+UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,
+ UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
+ UInt32 *distances, UInt32 maxLen);
+
+/*
+Conditions:
+ Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.
+ Mf_GetPointerToCurrentPos_Func's result must be used only before any other function
+*/
+
+typedef void (*Mf_Init_Func)(void *object);
+typedef Byte (*Mf_GetIndexByte_Func)(void *object, Int32 index);
+typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object);
+typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object);
+typedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances);
+typedef void (*Mf_Skip_Func)(void *object, UInt32);
+
+typedef struct _IMatchFinder
+{
+ Mf_Init_Func Init;
+ Mf_GetIndexByte_Func GetIndexByte;
+ Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;
+ Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;
+ Mf_GetMatches_Func GetMatches;
+ Mf_Skip_Func Skip;
+} IMatchFinder;
+
+void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);
+
+void MatchFinder_Init(CMatchFinder *p);
+UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
+UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
+void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
+void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
+
+#endif
diff --git a/include/grub/lib/LzHash.h b/include/grub/lib/LzHash.h
new file mode 100644
index 0000000..c3d5586
--- /dev/null
+++ b/include/grub/lib/LzHash.h
@@ -0,0 +1,77 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (c) 1999-2008 Igor Pavlov
+ * Copyright (C) 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * This code was taken from LZMA SDK 4.58 beta, and was slightly modified
+ * to adapt it to GRUB's requirement.
+ *
+ * See <http://www.7-zip.org>, for more information about LZMA.
+ */
+
+#ifndef __LZHASH_H
+#define __LZHASH_H
+
+#define kHash2Size (1 << 10)
+#define kHash3Size (1 << 16)
+#define kHash4Size (1 << 20)
+
+#define kFix3HashSize (kHash2Size)
+#define kFix4HashSize (kHash2Size + kHash3Size)
+#define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)
+
+#define HASH2_CALC hashValue = cur[0] | ((UInt32)cur[1] << 8);
+
+#define HASH3_CALC { \
+ UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
+ hash2Value = temp & (kHash2Size - 1); \
+ hashValue = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; }
+
+#define HASH4_CALC { \
+ UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
+ hash2Value = temp & (kHash2Size - 1); \
+ hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
+ hashValue = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & p->hashMask; }
+
+#define HASH5_CALC { \
+ UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
+ hash2Value = temp & (kHash2Size - 1); \
+ hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
+ hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)); \
+ hashValue = (hash4Value ^ (p->crc[cur[4]] << 3)) & p->hashMask; \
+ hash4Value &= (kHash4Size - 1); }
+
+/* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */
+#define HASH_ZIP_CALC hashValue = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;
+
+
+#define MT_HASH2_CALC \
+ hash2Value = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1);
+
+#define MT_HASH3_CALC { \
+ UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
+ hash2Value = temp & (kHash2Size - 1); \
+ hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }
+
+#define MT_HASH4_CALC { \
+ UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
+ hash2Value = temp & (kHash2Size - 1); \
+ hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
+ hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); }
+
+#endif
diff --git a/include/grub/lib/LzmaDec.h b/include/grub/lib/LzmaDec.h
new file mode 100644
index 0000000..16914c9
--- /dev/null
+++ b/include/grub/lib/LzmaDec.h
@@ -0,0 +1,246 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (c) 1999-2008 Igor Pavlov
+ * Copyright (C) 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * This code was taken from LZMA SDK 4.58 beta, and was slightly modified
+ * to adapt it to GRUB's requirement.
+ *
+ * See <http://www.7-zip.org>, for more information about LZMA.
+ */
+
+#ifndef __LZMADEC_H
+#define __LZMADEC_H
+
+#include "LzmaTypes.h"
+
+/* #define _LZMA_PROB32 */
+/* _LZMA_PROB32 can increase the speed on some CPUs,
+ but memory usage for CLzmaDec::probs will be doubled in that case */
+
+#ifdef _LZMA_PROB32
+#define CLzmaProb UInt32
+#else
+#define CLzmaProb UInt16
+#endif
+
+
+/* ---------- LZMA Properties ---------- */
+
+#define LZMA_PROPS_SIZE 5
+
+typedef struct _CLzmaProps
+{
+ unsigned lc, lp, pb;
+ UInt32 dicSize;
+} CLzmaProps;
+
+/* LzmaProps_Decode - decodes properties
+Returns:
+ SZ_OK
+ SZ_ERROR_UNSUPPORTED - Unsupported properties
+*/
+
+SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);
+
+
+/* ---------- LZMA Decoder state ---------- */
+
+/* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.
+ Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */
+
+#define LZMA_REQUIRED_INPUT_MAX 20
+
+typedef struct
+{
+ CLzmaProps prop;
+ CLzmaProb *probs;
+ Byte *dic;
+ const Byte *buf;
+ UInt32 range, code;
+ SizeT dicPos;
+ SizeT dicBufSize;
+ UInt32 processedPos;
+ UInt32 checkDicSize;
+ unsigned state;
+ UInt32 reps[4];
+ unsigned remainLen;
+ int needFlush;
+ int needInitState;
+ UInt32 numProbs;
+ unsigned tempBufSize;
+ Byte tempBuf[LZMA_REQUIRED_INPUT_MAX];
+} CLzmaDec;
+
+#define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }
+
+void LzmaDec_Init(CLzmaDec *p);
+
+/* There are two types of LZMA streams:
+ 0) Stream with end mark. That end mark adds about 6 bytes to compressed size.
+ 1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */
+
+typedef enum
+{
+ LZMA_FINISH_ANY, /* finish at any point */
+ LZMA_FINISH_END /* block must be finished at the end */
+} ELzmaFinishMode;
+
+/* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!
+
+ You must use LZMA_FINISH_END, when you know that current output buffer
+ covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.
+
+ If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,
+ and output value of destLen will be less than output buffer size limit.
+ You can check status result also.
+
+ You can use multiple checks to test data integrity after full decompression:
+ 1) Check Result and "status" variable.
+ 2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.
+ 3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
+ You must use correct finish mode in that case. */
+
+typedef enum
+{
+ LZMA_STATUS_NOT_SPECIFIED, /* use main error code instead */
+ LZMA_STATUS_FINISHED_WITH_MARK, /* stream was finished with end mark. */
+ LZMA_STATUS_NOT_FINISHED, /* stream was not finished */
+ LZMA_STATUS_NEEDS_MORE_INPUT, /* you must provide more input bytes */
+ LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK /* there is probability that stream was finished without end mark */
+} ELzmaStatus;
+
+/* ELzmaStatus is used only as output value for function call */
+
+
+/* ---------- Interfaces ---------- */
+
+/* There are 3 levels of interfaces:
+ 1) Dictionary Interface
+ 2) Buffer Interface
+ 3) One Call Interface
+ You can select any of these interfaces, but don't mix functions from different
+ groups for same object. */
+
+
+/* There are two variants to allocate state for Dictionary Interface:
+ 1) LzmaDec_Allocate / LzmaDec_Free
+ 2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs
+ You can use variant 2, if you set dictionary buffer manually.
+ For Buffer Interface you must always use variant 1.
+
+LzmaDec_Allocate* can return:
+ SZ_OK
+ SZ_ERROR_MEM - Memory allocation error
+ SZ_ERROR_UNSUPPORTED - Unsupported properties
+*/
+
+SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc);
+void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc);
+
+SRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc);
+void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc);
+
+/* ---------- Dictionary Interface ---------- */
+
+/* You can use it, if you want to eliminate the overhead for data copying from
+ dictionary to some other external buffer.
+ You must work with CLzmaDec variables directly in this interface.
+
+ STEPS:
+ LzmaDec_Constr()
+ LzmaDec_Allocate()
+ for (each new stream)
+ {
+ LzmaDec_Init()
+ while (it needs more decompression)
+ {
+ LzmaDec_DecodeToDic()
+ use data from CLzmaDec::dic and update CLzmaDec::dicPos
+ }
+ }
+ LzmaDec_Free()
+*/
+
+/* LzmaDec_DecodeToDic
+
+ The decoding to internal dictionary buffer (CLzmaDec::dic).
+ You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!
+
+finishMode:
+ It has meaning only if the decoding reaches output limit (dicLimit).
+ LZMA_FINISH_ANY - Decode just dicLimit bytes.
+ LZMA_FINISH_END - Stream must be finished after dicLimit.
+
+Returns:
+ SZ_OK
+ status:
+ LZMA_STATUS_FINISHED_WITH_MARK
+ LZMA_STATUS_NOT_FINISHED
+ LZMA_STATUS_NEEDS_MORE_INPUT
+ LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
+ SZ_ERROR_DATA - Data error
+*/
+
+SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,
+ const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
+
+
+/* ---------- Buffer Interface ---------- */
+
+/* It's zlib-like interface.
+ See LzmaDec_DecodeToDic description for information about STEPS and return results,
+ but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need
+ to work with CLzmaDec variables manually.
+
+finishMode:
+ It has meaning only if the decoding reaches output limit (*destLen).
+ LZMA_FINISH_ANY - Decode just destLen bytes.
+ LZMA_FINISH_END - Stream must be finished after (*destLen).
+*/
+
+SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,
+ const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
+
+
+/* ---------- One Call Interface ---------- */
+
+/* LzmaDecode
+
+finishMode:
+ It has meaning only if the decoding reaches output limit (*destLen).
+ LZMA_FINISH_ANY - Decode just destLen bytes.
+ LZMA_FINISH_END - Stream must be finished after (*destLen).
+
+Returns:
+ SZ_OK
+ status:
+ LZMA_STATUS_FINISHED_WITH_MARK
+ LZMA_STATUS_NOT_FINISHED
+ LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
+ SZ_ERROR_DATA - Data error
+ SZ_ERROR_MEM - Memory allocation error
+ SZ_ERROR_UNSUPPORTED - Unsupported properties
+ SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
+*/
+
+SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
+ const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
+ ELzmaStatus *status, ISzAlloc *alloc);
+
+#endif
diff --git a/include/grub/lib/LzmaEnc.h b/include/grub/lib/LzmaEnc.h
new file mode 100644
index 0000000..fc156a4
--- /dev/null
+++ b/include/grub/lib/LzmaEnc.h
@@ -0,0 +1,95 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (c) 1999-2008 Igor Pavlov
+ * Copyright (C) 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * This code was taken from LZMA SDK 4.58 beta, and was slightly modified
+ * to adapt it to GRUB's requirement.
+ *
+ * See <http://www.7-zip.org>, for more information about LZMA.
+ */
+
+#ifndef __LZMAENC_H
+#define __LZMAENC_H
+
+#include "LzmaTypes.h"
+
+#define LZMA_PROPS_SIZE 5
+
+typedef struct _CLzmaEncProps
+{
+ int level; /* 0 <= level <= 9 */
+ UInt32 dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version
+ (1 << 12) <= dictSize <= (1 << 30) for 64-bit version
+ default = (1 << 24) */
+ int lc; /* 0 <= lc <= 8, default = 3 */
+ int lp; /* 0 <= lp <= 4, default = 0 */
+ int pb; /* 0 <= pb <= 4, default = 2 */
+ int algo; /* 0 - fast, 1 - normal, default = 1 */
+ int fb; /* 5 <= fb <= 273, default = 32 */
+ int btMode; /* 0 - hashChain Mode, 1 - binTree mode - normal, default = 1 */
+ int numHashBytes; /* 2, 3 or 4, default = 4 */
+ UInt32 mc; /* 1 <= mc <= (1 << 30), default = 32 */
+ unsigned writeEndMark; /* 0 - do not write EOPM, 1 - write EOPM, default = 0 */
+ int numThreads; /* 1 or 2, default = 2 */
+} CLzmaEncProps;
+
+void LzmaEncProps_Init(CLzmaEncProps *p);
+void LzmaEncProps_Normalize(CLzmaEncProps *p);
+UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2);
+
+
+/* ---------- CLzmaEncHandle Interface ---------- */
+
+/* LzmaEnc_* functions can return the following exit codes:
+Returns:
+ SZ_OK - OK
+ SZ_ERROR_MEM - Memory allocation error
+ SZ_ERROR_PARAM - Incorrect parameter in props
+ SZ_ERROR_WRITE - Write callback error.
+ SZ_ERROR_PROGRESS - some break from progress callback
+ SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
+*/
+
+typedef void * CLzmaEncHandle;
+
+CLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc);
+void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig);
+SRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props);
+SRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size);
+SRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream,
+ ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
+SRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
+ int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
+
+/* ---------- One Call Interface ---------- */
+
+/* LzmaEncode
+Return code:
+ SZ_OK - OK
+ SZ_ERROR_MEM - Memory allocation error
+ SZ_ERROR_PARAM - Incorrect parameter
+ SZ_ERROR_OUTPUT_EOF - output buffer overflow
+ SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
+*/
+
+SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
+ const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
+ ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
+
+#endif
diff --git a/include/grub/lib/LzmaTypes.h b/include/grub/lib/LzmaTypes.h
new file mode 100644
index 0000000..1e783a2
--- /dev/null
+++ b/include/grub/lib/LzmaTypes.h
@@ -0,0 +1,151 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (c) 1999-2008 Igor Pavlov
+ * Copyright (C) 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * This code was taken from LZMA SDK 4.58 beta, and was slightly modified
+ * to adapt it to GRUB's requirement.
+ *
+ * See <http://www.7-zip.org>, for more information about LZMA.
+ */
+
+#ifndef __7Z_TYPES_H
+#define __7Z_TYPES_H
+
+#define SZ_OK 0
+
+#define SZ_ERROR_DATA 1
+#define SZ_ERROR_MEM 2
+#define SZ_ERROR_CRC 3
+#define SZ_ERROR_UNSUPPORTED 4
+#define SZ_ERROR_PARAM 5
+#define SZ_ERROR_INPUT_EOF 6
+#define SZ_ERROR_OUTPUT_EOF 7
+#define SZ_ERROR_READ 8
+#define SZ_ERROR_WRITE 9
+#define SZ_ERROR_PROGRESS 10
+#define SZ_ERROR_FAIL 11
+#define SZ_ERROR_THREAD 12
+
+#define SZ_ERROR_ARCHIVE 16
+#define SZ_ERROR_NO_ARCHIVE 17
+
+typedef int SRes;
+
+#ifndef RINOK
+#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
+#endif
+
+typedef unsigned char Byte;
+typedef short Int16;
+typedef unsigned short UInt16;
+
+#ifdef _LZMA_UINT32_IS_ULONG
+typedef long Int32;
+typedef unsigned long UInt32;
+#else
+typedef int Int32;
+typedef unsigned int UInt32;
+#endif
+
+/* #define _SZ_NO_INT_64 */
+/* define it if your compiler doesn't support 64-bit integers */
+
+#ifdef _SZ_NO_INT_64
+
+typedef long Int64;
+typedef unsigned long UInt64;
+
+#else
+
+#if defined(_MSC_VER) || defined(__BORLANDC__)
+typedef __int64 Int64;
+typedef unsigned __int64 UInt64;
+#else
+typedef long long int Int64;
+typedef unsigned long long int UInt64;
+#endif
+
+#endif
+
+#ifdef _LZMA_NO_SYSTEM_SIZE_T
+typedef UInt32 SizeT;
+#else
+#include <stddef.h>
+typedef size_t SizeT;
+#endif
+
+typedef int Bool;
+#define True 1
+#define False 0
+
+
+#ifdef _MSC_VER
+
+#if _MSC_VER >= 1300
+#define MY_NO_INLINE __declspec(noinline)
+#else
+#define MY_NO_INLINE
+#endif
+
+#define MY_CDECL __cdecl
+#define MY_STD_CALL __stdcall
+#define MY_FAST_CALL MY_NO_INLINE __fastcall
+
+#else
+
+#define MY_CDECL
+#define MY_STD_CALL
+#define MY_FAST_CALL
+
+#endif
+
+
+/* The following interfaces use first parameter as pointer to structure */
+
+typedef struct
+{
+ SRes (*Read)(void *p, void *buf, size_t *size);
+ /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
+ (output(*size) < input(*size)) is allowed */
+} ISeqInStream;
+
+typedef struct
+{
+ size_t (*Write)(void *p, const void *buf, size_t size);
+ /* Returns: result - the number of actually written bytes.
+ (result < size) means error */
+} ISeqOutStream;
+
+typedef struct
+{
+ SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);
+ /* Returns: result. (result != SZ_OK) means break.
+ Value (UInt64)(Int64)-1 for size means unknown value. */
+} ICompressProgress;
+
+typedef struct
+{
+ void *(*Alloc)(void *p, size_t size);
+ void (*Free)(void *p, void *address); /* address can be 0 */
+} ISzAlloc;
+
+#define IAlloc_Alloc(p, size) (p)->Alloc((p), size)
+#define IAlloc_Free(p, a) (p)->Free((p), a)
+
+#endif
diff --git a/include/grub/lib/arg.h b/include/grub/lib/arg.h
new file mode 100644
index 0000000..f81af85
--- /dev/null
+++ b/include/grub/lib/arg.h
@@ -0,0 +1,79 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2003,2005,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_ARG_HEADER
+#define GRUB_ARG_HEADER 1
+
+#include <grub/symbol.h>
+#include <grub/err.h>
+#include <grub/types.h>
+
+enum grub_arg_type
+ {
+ ARG_TYPE_NONE,
+ ARG_TYPE_STRING,
+ ARG_TYPE_INT,
+ ARG_TYPE_DEVICE,
+ ARG_TYPE_FILE,
+ ARG_TYPE_DIR,
+ ARG_TYPE_PATHNAME
+ };
+
+typedef enum grub_arg_type grub_arg_type_t;
+
+/* Flags for the option field op grub_arg_option. */
+#define GRUB_ARG_OPTION_OPTIONAL (1 << 1)
+/* Flags for an option that can appear multiple times. */
+#define GRUB_ARG_OPTION_REPEATABLE (1 << 2)
+
+enum grub_key_type
+ {
+ GRUB_KEY_ARG = -1,
+ GRUB_KEY_END = -2
+ };
+typedef enum grub_key_type grub_arg_key_type_t;
+
+struct grub_arg_option
+{
+ const char *longarg;
+ int shortarg;
+ int flags;
+ const char *doc;
+ const char *arg;
+ grub_arg_type_t type;
+};
+
+struct grub_arg_list
+{
+ int set;
+ union {
+ char *arg;
+ char **args;
+ };
+};
+
+struct grub_extcmd;
+
+int grub_arg_parse (struct grub_extcmd *cmd, int argc, char **argv,
+ struct grub_arg_list *usr, char ***args, int *argnum);
+
+void EXPORT_FUNC(grub_arg_show_help) (struct grub_extcmd *cmd);
+struct grub_arg_list* grub_arg_list_alloc (struct grub_extcmd *cmd,
+ int argc, char *argv[]);
+
+#endif /* ! GRUB_ARG_HEADER */
diff --git a/include/grub/lib/cmdline.h b/include/grub/lib/cmdline.h
new file mode 100644
index 0000000..cdca09b
--- /dev/null
+++ b/include/grub/lib/cmdline.h
@@ -0,0 +1,32 @@
+/* cmdline.h - linux command line handling */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_CMDLINE_HEADER
+#define GRUB_CMDLINE_HEADER 1
+
+#include <grub/types.h>
+#include <grub/verify.h>
+
+#define LINUX_IMAGE "BOOT_IMAGE="
+
+unsigned int grub_loader_cmdline_size (int argc, char *argv[]);
+grub_err_t grub_create_loader_cmdline (int argc, char *argv[], char *buf,
+ grub_size_t size, enum grub_verify_string_type type);
+
+#endif /* ! GRUB_CMDLINE_HEADER */
diff --git a/include/grub/lib/crc.h b/include/grub/lib/crc.h
new file mode 100644
index 0000000..c5098a8
--- /dev/null
+++ b/include/grub/lib/crc.h
@@ -0,0 +1,25 @@
+/* crc.h - prototypes for crc */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_CRC_H
+#define GRUB_CRC_H 1
+
+grub_uint32_t grub_getcrc32c (grub_uint32_t crc, const void *buf, int size);
+
+#endif /* ! GRUB_CRC_H */
diff --git a/include/grub/lib/envblk.h b/include/grub/lib/envblk.h
new file mode 100644
index 0000000..c3e6559
--- /dev/null
+++ b/include/grub/lib/envblk.h
@@ -0,0 +1,56 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_ENVBLK_HEADER
+#define GRUB_ENVBLK_HEADER 1
+
+#define GRUB_ENVBLK_SIGNATURE "# GRUB Environment Block\n"
+#define GRUB_ENVBLK_DEFCFG "grubenv"
+
+#ifndef ASM_FILE
+
+struct grub_envblk
+{
+ char *buf;
+ grub_size_t size;
+};
+typedef struct grub_envblk *grub_envblk_t;
+
+grub_envblk_t grub_envblk_open (char *buf, grub_size_t size);
+int grub_envblk_set (grub_envblk_t envblk, const char *name, const char *value);
+void grub_envblk_delete (grub_envblk_t envblk, const char *name);
+void grub_envblk_iterate (grub_envblk_t envblk,
+ void *hook_data,
+ int hook (const char *name, const char *value, void *hook_data));
+void grub_envblk_close (grub_envblk_t envblk);
+
+static inline char *
+grub_envblk_buffer (const grub_envblk_t envblk)
+{
+ return envblk->buf;
+}
+
+static inline grub_size_t
+grub_envblk_size (const grub_envblk_t envblk)
+{
+ return envblk->size;
+}
+
+#endif /* ! ASM_FILE */
+
+#endif /* ! GRUB_ENVBLK_HEADER */
diff --git a/include/grub/lib/hexdump.h b/include/grub/lib/hexdump.h
new file mode 100644
index 0000000..23c6fa6
--- /dev/null
+++ b/include/grub/lib/hexdump.h
@@ -0,0 +1,25 @@
+/* hexdump.h - prototypes for dump */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_HEXDUMP_H
+#define GRUB_HEXDUMP_H 1
+
+void hexdump (unsigned long bse,char* buf,int len);
+
+#endif /* ! GRUB_HEXDUMP_H */
diff --git a/include/grub/libpciaccess.h b/include/grub/libpciaccess.h
new file mode 100644
index 0000000..4d2b3bd
--- /dev/null
+++ b/include/grub/libpciaccess.h
@@ -0,0 +1,26 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+void EXPORT_FUNC (pci_slot_match_iterator_create) (void);
+void EXPORT_FUNC (pci_system_cleanup) (void);
+void EXPORT_FUNC (pci_device_unmap_range) (void);
+void EXPORT_FUNC (pci_iterator_destroy) (void);
+void EXPORT_FUNC (pci_device_map_range) (void);
+void EXPORT_FUNC (pci_device_cfg_read_u32) (void);
+void EXPORT_FUNC (pci_device_next) (void);
+void EXPORT_FUNC (pci_system_init) (void);
diff --git a/include/grub/linux.h b/include/grub/linux.h
new file mode 100644
index 0000000..594a3f3
--- /dev/null
+++ b/include/grub/linux.h
@@ -0,0 +1,24 @@
+#include <grub/file.h>
+
+struct grub_linux_initrd_component;
+
+struct grub_linux_initrd_context
+{
+ int nfiles;
+ struct grub_linux_initrd_component *components;
+ grub_size_t size;
+};
+
+grub_err_t
+grub_initrd_init (int argc, char *argv[],
+ struct grub_linux_initrd_context *ctx);
+
+grub_size_t
+grub_get_initrd_size (struct grub_linux_initrd_context *ctx);
+
+void
+grub_initrd_close (struct grub_linux_initrd_context *initrd_ctx);
+
+grub_err_t
+grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx,
+ char *argv[], void *target);
diff --git a/include/grub/list.h b/include/grub/list.h
new file mode 100644
index 0000000..b13acb9
--- /dev/null
+++ b/include/grub/list.h
@@ -0,0 +1,88 @@
+/* list.h - header for grub list */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_LIST_HEADER
+#define GRUB_LIST_HEADER 1
+
+#include <grub/symbol.h>
+#include <grub/err.h>
+#include <grub/compiler.h>
+
+struct grub_list
+{
+ struct grub_list *next;
+ struct grub_list **prev;
+};
+typedef struct grub_list *grub_list_t;
+
+void EXPORT_FUNC(grub_list_push) (grub_list_t *head, grub_list_t item);
+void EXPORT_FUNC(grub_list_remove) (grub_list_t item);
+
+#define FOR_LIST_ELEMENTS(var, list) for ((var) = (list); (var); (var) = (var)->next)
+#define FOR_LIST_ELEMENTS_NEXT(var, list) for ((var) = (var)->next; (var); (var) = (var)->next)
+#define FOR_LIST_ELEMENTS_SAFE(var, nxt, list) for ((var) = (list), (nxt) = ((var) ? (var)->next : 0); (var); (var) = (nxt), ((nxt) = (var) ? (var)->next : 0))
+
+static inline void *
+grub_bad_type_cast_real (int line, const char *file)
+ ATTRIBUTE_ERROR ("bad type cast between incompatible grub types");
+
+static inline void *
+grub_bad_type_cast_real (int line, const char *file)
+{
+ grub_fatal ("error:%s:%u: bad type cast between incompatible grub types",
+ file, line);
+}
+
+#define grub_bad_type_cast() grub_bad_type_cast_real(__LINE__, GRUB_FILE)
+
+#define GRUB_FIELD_MATCH(ptr, type, field) \
+ ((char *) &(ptr)->field == (char *) &((type) (ptr))->field)
+
+#define GRUB_AS_LIST(ptr) \
+ (GRUB_FIELD_MATCH (ptr, grub_list_t, next) && GRUB_FIELD_MATCH (ptr, grub_list_t, prev) ? \
+ (grub_list_t) ptr : (grub_list_t) grub_bad_type_cast ())
+
+#define GRUB_AS_LIST_P(pptr) \
+ (GRUB_FIELD_MATCH (*pptr, grub_list_t, next) && GRUB_FIELD_MATCH (*pptr, grub_list_t, prev) ? \
+ (grub_list_t *) (void *) pptr : (grub_list_t *) grub_bad_type_cast ())
+
+struct grub_named_list
+{
+ struct grub_named_list *next;
+ struct grub_named_list **prev;
+ char *name;
+};
+typedef struct grub_named_list *grub_named_list_t;
+
+void * EXPORT_FUNC(grub_named_list_find) (grub_named_list_t head,
+ const char *name);
+
+#define GRUB_AS_NAMED_LIST(ptr) \
+ ((GRUB_FIELD_MATCH (ptr, grub_named_list_t, next) \
+ && GRUB_FIELD_MATCH (ptr, grub_named_list_t, prev) \
+ && GRUB_FIELD_MATCH (ptr, grub_named_list_t, name))? \
+ (grub_named_list_t) ptr : (grub_named_list_t) grub_bad_type_cast ())
+
+#define GRUB_AS_NAMED_LIST_P(pptr) \
+ ((GRUB_FIELD_MATCH (*pptr, grub_named_list_t, next) \
+ && GRUB_FIELD_MATCH (*pptr, grub_named_list_t, prev) \
+ && GRUB_FIELD_MATCH (*pptr, grub_named_list_t, name))? \
+ (grub_named_list_t *) (void *) pptr : (grub_named_list_t *) grub_bad_type_cast ())
+
+#endif /* ! GRUB_LIST_HEADER */
diff --git a/include/grub/loader.h b/include/grub/loader.h
new file mode 100644
index 0000000..b208642
--- /dev/null
+++ b/include/grub/loader.h
@@ -0,0 +1,79 @@
+/* loader.h - OS loaders */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2003,2004,2006,2007,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_LOADER_HEADER
+#define GRUB_LOADER_HEADER 1
+
+#include <grub/file.h>
+#include <grub/symbol.h>
+#include <grub/err.h>
+#include <grub/types.h>
+
+/* Check if a loader is loaded. */
+int EXPORT_FUNC (grub_loader_is_loaded) (void);
+
+/* Set loader functions. */
+enum
+{
+ GRUB_LOADER_FLAG_NORETURN = 1,
+ GRUB_LOADER_FLAG_PXE_NOT_UNLOAD = 2,
+ GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY = 4,
+};
+
+void EXPORT_FUNC (grub_loader_set) (grub_err_t (*boot) (void),
+ grub_err_t (*unload) (void),
+ int flags);
+
+/* Unset current loader, if any. */
+void EXPORT_FUNC (grub_loader_unset) (void);
+
+/* Call the boot hook in current loader. This may or may not return,
+ depending on the setting by grub_loader_set. */
+grub_err_t grub_loader_boot (void);
+
+/* The space between numbers is intentional for the simplicity of adding new
+ values even if external modules use them. */
+typedef enum {
+ /* A preboot hook which can use everything and turns nothing off. */
+ GRUB_LOADER_PREBOOT_HOOK_PRIO_NORMAL = 400,
+ /* A preboot hook which can't use disks and may stop disks. */
+ GRUB_LOADER_PREBOOT_HOOK_PRIO_DISK = 300,
+ /* A preboot hook which can't use disks or console and may stop console. */
+ GRUB_LOADER_PREBOOT_HOOK_PRIO_CONSOLE = 200,
+ /* A preboot hook which can't use disks or console, can't modify memory map
+ and may stop memory services or finalize memory map. */
+ GRUB_LOADER_PREBOOT_HOOK_PRIO_MEMORY = 100,
+} grub_loader_preboot_hook_prio_t;
+
+/* Register a preboot hook. */
+struct grub_preboot;
+
+struct grub_preboot *EXPORT_FUNC(grub_loader_register_preboot_hook) (grub_err_t (*preboot_func) (int noret),
+ grub_err_t (*preboot_rest_func) (void),
+ grub_loader_preboot_hook_prio_t prio);
+
+/* Unregister given preboot hook. */
+void EXPORT_FUNC (grub_loader_unregister_preboot_hook) (struct grub_preboot *hnd);
+
+#ifndef GRUB_MACHINE_EMU
+void grub_boot_init (void);
+void grub_boot_fini (void);
+#endif
+
+#endif /* ! GRUB_LOADER_HEADER */
diff --git a/include/grub/lockdown.h b/include/grub/lockdown.h
new file mode 100644
index 0000000..40531fa
--- /dev/null
+++ b/include/grub/lockdown.h
@@ -0,0 +1,44 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2020 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_LOCKDOWN_H
+#define GRUB_LOCKDOWN_H 1
+
+#include <grub/symbol.h>
+
+#define GRUB_LOCKDOWN_DISABLED 0
+#define GRUB_LOCKDOWN_ENABLED 1
+
+#ifdef GRUB_MACHINE_EFI
+extern void
+EXPORT_FUNC (grub_lockdown) (void);
+extern int
+EXPORT_FUNC (grub_is_lockdown) (void);
+#else
+static inline void
+grub_lockdown (void)
+{
+}
+
+static inline int
+grub_is_lockdown (void)
+{
+ return GRUB_LOCKDOWN_DISABLED;
+}
+#endif
+#endif /* ! GRUB_LOCKDOWN_H */
diff --git a/include/grub/lvm.h b/include/grub/lvm.h
new file mode 100644
index 0000000..30a609c
--- /dev/null
+++ b/include/grub/lvm.h
@@ -0,0 +1,90 @@
+/* lvm.h - On disk structures for LVM. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2006,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_LVM_H
+#define GRUB_LVM_H 1
+
+#include <grub/types.h>
+#include <grub/diskfilter.h>
+
+/* Length of ID string, excluding terminating zero. */
+#define GRUB_LVM_ID_STRLEN 38
+
+#define GRUB_LVM_LABEL_SIZE GRUB_DISK_SECTOR_SIZE
+#define GRUB_LVM_LABEL_SCAN_SECTORS 4L
+
+#define GRUB_LVM_LABEL_ID "LABELONE"
+#define GRUB_LVM_LVM2_LABEL "LVM2 001"
+
+#define GRUB_LVM_ID_LEN 32
+
+/* On disk - 32 bytes */
+struct grub_lvm_label_header {
+ grub_int8_t id[8]; /* LABELONE */
+ grub_uint64_t sector_xl; /* Sector number of this label */
+ grub_uint32_t crc_xl; /* From next field to end of sector */
+ grub_uint32_t offset_xl; /* Offset from start of struct to contents */
+ grub_int8_t type[8]; /* LVM2 001 */
+} GRUB_PACKED;
+
+/* On disk */
+struct grub_lvm_disk_locn {
+ grub_uint64_t offset; /* Offset in bytes to start sector */
+ grub_uint64_t size; /* Bytes */
+} GRUB_PACKED;
+
+/* Fields with the suffix _xl should be xlate'd wherever they appear */
+/* On disk */
+struct grub_lvm_pv_header {
+ grub_int8_t pv_uuid[GRUB_LVM_ID_LEN];
+
+ /* This size can be overridden if PV belongs to a VG */
+ grub_uint64_t device_size_xl; /* Bytes */
+
+ /* NULL-terminated list of data areas followed by */
+ /* NULL-terminated list of metadata area headers */
+ struct grub_lvm_disk_locn disk_areas_xl[0]; /* Two lists */
+} GRUB_PACKED;
+
+#define GRUB_LVM_FMTT_MAGIC "\040\114\126\115\062\040\170\133\065\101\045\162\060\116\052\076"
+#define GRUB_LVM_FMTT_VERSION 1
+#define GRUB_LVM_MDA_HEADER_SIZE 512
+
+/* On disk */
+struct grub_lvm_raw_locn {
+ grub_uint64_t offset; /* Offset in bytes to start sector */
+ grub_uint64_t size; /* Bytes */
+ grub_uint32_t checksum;
+ grub_uint32_t filler;
+} GRUB_PACKED;
+
+/* On disk */
+/* Structure size limited to one sector */
+struct grub_lvm_mda_header {
+ grub_uint32_t checksum_xl; /* Checksum of rest of mda_header */
+ grub_int8_t magic[16]; /* To aid scans for metadata */
+ grub_uint32_t version;
+ grub_uint64_t start; /* Absolute start byte of mda_header */
+ grub_uint64_t size; /* Size of metadata area */
+
+ struct grub_lvm_raw_locn raw_locns[0]; /* NULL-terminated list */
+} GRUB_PACKED;
+
+
+#endif /* ! GRUB_LVM_H */
diff --git a/include/grub/macho.h b/include/grub/macho.h
new file mode 100644
index 0000000..2dea625
--- /dev/null
+++ b/include/grub/macho.h
@@ -0,0 +1,166 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MACHO_H
+#define GRUB_MACHO_H 1
+#include <grub/types.h>
+
+/* Multi-architecture header. Always in big-endian. */
+struct grub_macho_fat_header
+{
+ grub_uint32_t magic;
+ grub_uint32_t nfat_arch;
+} GRUB_PACKED;
+
+enum
+ {
+ GRUB_MACHO_CPUTYPE_IA32 = 0x00000007,
+ GRUB_MACHO_CPUTYPE_AMD64 = 0x01000007
+ };
+
+#define GRUB_MACHO_FAT_MAGIC 0xcafebabe
+#define GRUB_MACHO_FAT_EFI_MAGIC 0x0ef1fab9U
+
+typedef grub_uint32_t grub_macho_cpu_type_t;
+typedef grub_uint32_t grub_macho_cpu_subtype_t;
+
+/* Architecture descriptor. Always in big-endian. */
+struct grub_macho_fat_arch
+{
+ grub_macho_cpu_type_t cputype;
+ grub_macho_cpu_subtype_t cpusubtype;
+ grub_uint32_t offset;
+ grub_uint32_t size;
+ grub_uint32_t align;
+} GRUB_PACKED;
+
+/* File header for 32-bit. Always in native-endian. */
+struct grub_macho_header32
+{
+#define GRUB_MACHO_MAGIC32 0xfeedface
+ grub_uint32_t magic;
+ grub_macho_cpu_type_t cputype;
+ grub_macho_cpu_subtype_t cpusubtype;
+ grub_uint32_t filetype;
+ grub_uint32_t ncmds;
+ grub_uint32_t sizeofcmds;
+ grub_uint32_t flags;
+} GRUB_PACKED;
+
+/* File header for 64-bit. Always in native-endian. */
+struct grub_macho_header64
+{
+#define GRUB_MACHO_MAGIC64 0xfeedfacf
+ grub_uint32_t magic;
+ grub_macho_cpu_type_t cputype;
+ grub_macho_cpu_subtype_t cpusubtype;
+ grub_uint32_t filetype;
+ grub_uint32_t ncmds;
+ grub_uint32_t sizeofcmds;
+ grub_uint32_t flags;
+ grub_uint32_t reserved;
+} GRUB_PACKED;
+
+/* Common header of Mach-O commands. */
+struct grub_macho_cmd
+{
+ grub_uint32_t cmd;
+ grub_uint32_t cmdsize;
+} GRUB_PACKED;
+
+typedef grub_uint32_t grub_macho_vmprot_t;
+
+/* 32-bit segment command. */
+struct grub_macho_segment32
+{
+#define GRUB_MACHO_CMD_SEGMENT32 1
+ grub_uint32_t cmd;
+ grub_uint32_t cmdsize;
+ grub_uint8_t segname[16];
+ grub_uint32_t vmaddr;
+ grub_uint32_t vmsize;
+ grub_uint32_t fileoff;
+ grub_uint32_t filesize;
+ grub_macho_vmprot_t maxprot;
+ grub_macho_vmprot_t initprot;
+ grub_uint32_t nsects;
+ grub_uint32_t flags;
+} GRUB_PACKED;
+
+/* 64-bit segment command. */
+struct grub_macho_segment64
+{
+#define GRUB_MACHO_CMD_SEGMENT64 0x19
+ grub_uint32_t cmd;
+ grub_uint32_t cmdsize;
+ grub_uint8_t segname[16];
+ grub_uint64_t vmaddr;
+ grub_uint64_t vmsize;
+ grub_uint64_t fileoff;
+ grub_uint64_t filesize;
+ grub_macho_vmprot_t maxprot;
+ grub_macho_vmprot_t initprot;
+ grub_uint32_t nsects;
+ grub_uint32_t flags;
+} GRUB_PACKED;
+
+#define GRUB_MACHO_CMD_THREAD 5
+
+struct grub_macho_lzss_header
+{
+ char magic[8];
+#define GRUB_MACHO_LZSS_MAGIC "complzss"
+ grub_uint32_t unused;
+ grub_uint32_t uncompressed_size;
+ grub_uint32_t compressed_size;
+};
+
+/* Convenience union. What do we need to load to identify the file type. */
+union grub_macho_filestart
+{
+ struct grub_macho_fat_header fat;
+ struct grub_macho_header32 thin32;
+ struct grub_macho_header64 thin64;
+ struct grub_macho_lzss_header lzss;
+} GRUB_PACKED;
+
+struct grub_macho_thread32
+{
+ grub_uint32_t cmd;
+ grub_uint32_t cmdsize;
+ grub_uint8_t unknown1[48];
+ grub_uint32_t entry_point;
+ grub_uint8_t unknown2[20];
+} GRUB_PACKED;
+
+struct grub_macho_thread64
+{
+ grub_uint32_t cmd;
+ grub_uint32_t cmdsize;
+ grub_uint8_t unknown1[0x88];
+ grub_uint64_t entry_point;
+ grub_uint8_t unknown2[0x20];
+} GRUB_PACKED;
+
+#define GRUB_MACHO_LZSS_OFFSET 0x180
+
+grub_size_t
+grub_decompress_lzss (grub_uint8_t *dst, grub_uint8_t *dstend,
+ grub_uint8_t *src, grub_uint8_t *srcend);
+
+#endif
diff --git a/include/grub/machoload.h b/include/grub/machoload.h
new file mode 100644
index 0000000..f1157f4
--- /dev/null
+++ b/include/grub/machoload.h
@@ -0,0 +1,89 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MACHOLOAD_HEADER
+#define GRUB_MACHOLOAD_HEADER 1
+
+#include <grub/err.h>
+#include <grub/elf.h>
+#include <grub/file.h>
+#include <grub/symbol.h>
+#include <grub/types.h>
+
+struct grub_macho_file
+{
+ grub_file_t file;
+ grub_ssize_t offset32;
+ grub_ssize_t end32;
+ int ncmds32;
+ grub_size_t cmdsize32;
+ grub_uint8_t *cmds32;
+ grub_uint8_t *uncompressed32;
+ int compressed32;
+ grub_size_t compressed_size32;
+ grub_size_t uncompressed_size32;
+ grub_ssize_t offset64;
+ grub_ssize_t end64;
+ int ncmds64;
+ grub_size_t cmdsize64;
+ grub_uint8_t *cmds64;
+ grub_uint8_t *uncompressed64;
+ int compressed64;
+ grub_size_t compressed_size64;
+ grub_size_t uncompressed_size64;
+};
+typedef struct grub_macho_file *grub_macho_t;
+
+grub_macho_t grub_macho_open (const char *, enum grub_file_type type,
+ int is_64bit);
+grub_macho_t grub_macho_file (grub_file_t file, const char *filename,
+ int is_64bit);
+grub_err_t grub_macho_close (grub_macho_t);
+
+grub_err_t grub_macho_size32 (grub_macho_t macho, grub_uint32_t *segments_start,
+ grub_uint32_t *segments_end, int flags,
+ const char *filename);
+grub_uint32_t grub_macho_get_entry_point32 (grub_macho_t macho,
+ const char *filename);
+
+grub_err_t grub_macho_size64 (grub_macho_t macho, grub_uint64_t *segments_start,
+ grub_uint64_t *segments_end, int flags,
+ const char *filename);
+grub_uint64_t grub_macho_get_entry_point64 (grub_macho_t macho,
+ const char *filename);
+
+/* Ignore BSS segments when loading. */
+#define GRUB_MACHO_NOBSS 0x1
+grub_err_t grub_macho_load32 (grub_macho_t macho, const char *filename,
+ char *offset, int flags, int *darwin_version);
+grub_err_t grub_macho_load64 (grub_macho_t macho, const char *filename,
+ char *offset, int flags, int *darwin_version);
+
+/* Like filesize and file_read but take only 32-bit part
+ for current architecture. */
+grub_size_t grub_macho_filesize32 (grub_macho_t macho);
+grub_err_t grub_macho_readfile32 (grub_macho_t macho, const char *filename,
+ void *dest);
+grub_size_t grub_macho_filesize64 (grub_macho_t macho);
+grub_err_t grub_macho_readfile64 (grub_macho_t macho, const char *filename,
+ void *dest);
+
+void grub_macho_parse32 (grub_macho_t macho, const char *filename);
+void grub_macho_parse64 (grub_macho_t macho, const char *filename);
+
+#endif /* ! GRUB_MACHOLOAD_HEADER */
diff --git a/include/grub/memory.h b/include/grub/memory.h
new file mode 100644
index 0000000..6da114a
--- /dev/null
+++ b/include/grub/memory.h
@@ -0,0 +1,87 @@
+/* memory.h - describe the memory map */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2007,2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MEMORY_HEADER
+#define GRUB_MEMORY_HEADER 1
+
+#include <grub/types.h>
+#include <grub/err.h>
+
+typedef enum grub_memory_type
+ {
+ GRUB_MEMORY_AVAILABLE = 1,
+ GRUB_MEMORY_RESERVED = 2,
+ GRUB_MEMORY_ACPI = 3,
+ GRUB_MEMORY_NVS = 4,
+ GRUB_MEMORY_BADRAM = 5,
+ GRUB_MEMORY_PERSISTENT = 7,
+ GRUB_MEMORY_PERSISTENT_LEGACY = 12,
+ GRUB_MEMORY_COREBOOT_TABLES = 16,
+ GRUB_MEMORY_CODE = 20,
+ /* This one is special: it's used internally but is never reported
+ by firmware. Don't use -1 as it's used internally for other purposes. */
+ GRUB_MEMORY_HOLE = -2,
+ GRUB_MEMORY_MAX = 0x10000
+ } grub_memory_type_t;
+
+typedef int (*grub_memory_hook_t) (grub_uint64_t,
+ grub_uint64_t,
+ grub_memory_type_t,
+ void *);
+
+grub_err_t grub_mmap_iterate (grub_memory_hook_t hook, void *hook_data);
+
+#ifdef GRUB_MACHINE_EFI
+grub_err_t
+grub_efi_mmap_iterate (grub_memory_hook_t hook, void *hook_data,
+ int avoid_efi_boot_services);
+#endif
+
+#if !defined (GRUB_MACHINE_EMU) && !defined (GRUB_MACHINE_EFI)
+grub_err_t EXPORT_FUNC(grub_machine_mmap_iterate) (grub_memory_hook_t hook,
+ void *hook_data);
+#else
+grub_err_t grub_machine_mmap_iterate (grub_memory_hook_t hook,
+ void *hook_data);
+#endif
+
+int grub_mmap_register (grub_uint64_t start, grub_uint64_t size, int type);
+grub_err_t grub_mmap_unregister (int handle);
+
+void *grub_mmap_malign_and_register (grub_uint64_t align, grub_uint64_t size,
+ int *handle, int type, int flags);
+
+void grub_mmap_free_and_unregister (int handle);
+
+#ifndef GRUB_MMAP_REGISTER_BY_FIRMWARE
+
+struct grub_mmap_region
+{
+ struct grub_mmap_region *next;
+ grub_uint64_t start;
+ grub_uint64_t end;
+ grub_memory_type_t type;
+ int handle;
+ int priority;
+};
+
+extern struct grub_mmap_region *grub_mmap_overlays;
+#endif
+
+#endif /* ! GRUB_MEMORY_HEADER */
diff --git a/include/grub/menu.h b/include/grub/menu.h
new file mode 100644
index 0000000..ee2b5e9
--- /dev/null
+++ b/include/grub/menu.h
@@ -0,0 +1,106 @@
+/* menu.h - Menu model function prototypes and data structures. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MENU_HEADER
+#define GRUB_MENU_HEADER 1
+
+struct grub_menu_entry_class
+{
+ char *name;
+ struct grub_menu_entry_class *next;
+};
+
+/* The menu entry. */
+struct grub_menu_entry
+{
+ /* The title name. */
+ const char *title;
+
+ /* The identifier. */
+ const char *id;
+
+ /* If set means not everybody is allowed to boot this entry. */
+ int restricted;
+
+ /* Allowed users. */
+ const char *users;
+
+ /* The classes associated with the menu entry:
+ used to choose an icon or other style attributes.
+ This is a dummy head node for the linked list, so for an entry E,
+ E.classes->next is the first class if it is not NULL. */
+ struct grub_menu_entry_class *classes;
+
+ /* The sourcecode of the menu entry, used by the editor. */
+ const char *sourcecode;
+
+ /* Parameters to be passed to menu definition. */
+ int argc;
+ char **args;
+
+ int hotkey;
+
+ int submenu;
+
+ /* The next element. */
+ struct grub_menu_entry *next;
+};
+typedef struct grub_menu_entry *grub_menu_entry_t;
+
+/* The menu. */
+struct grub_menu
+{
+ /* The size of a menu. */
+ int size;
+
+ /* The list of menu entries. */
+ grub_menu_entry_t entry_list;
+};
+typedef struct grub_menu *grub_menu_t;
+
+/* Callback structure menu viewers can use to provide user feedback when
+ default entries are executed, possibly including fallback entries. */
+typedef struct grub_menu_execute_callback
+{
+ /* Called immediately before ENTRY is booted. */
+ void (*notify_booting) (grub_menu_entry_t entry, void *userdata);
+
+ /* Called when executing one entry has failed, and another entry, ENTRY, will
+ be executed as a fallback. The implementation of this function should
+ delay for a period of at least 2 seconds before returning in order to
+ allow the user time to read the information before it can be lost by
+ executing ENTRY. */
+ void (*notify_fallback) (grub_menu_entry_t entry, void *userdata);
+
+ /* Called when an entry has failed to execute and there is no remaining
+ fallback entry to attempt. */
+ void (*notify_failure) (void *userdata);
+}
+*grub_menu_execute_callback_t;
+
+grub_menu_entry_t grub_menu_get_entry (grub_menu_t menu, int no);
+int grub_menu_get_timeout (void);
+void grub_menu_set_timeout (int timeout);
+void grub_menu_entry_run (grub_menu_entry_t entry);
+int grub_menu_get_default_entry_index (grub_menu_t menu);
+
+void grub_menu_init (void);
+void grub_menu_fini (void);
+
+#endif /* GRUB_MENU_HEADER */
diff --git a/include/grub/menu_viewer.h b/include/grub/menu_viewer.h
new file mode 100644
index 0000000..c6513c4
--- /dev/null
+++ b/include/grub/menu_viewer.h
@@ -0,0 +1,48 @@
+/* menu_viewer.h - Interface to menu viewer implementations. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MENU_VIEWER_HEADER
+#define GRUB_MENU_VIEWER_HEADER 1
+
+#include <grub/err.h>
+#include <grub/symbol.h>
+#include <grub/types.h>
+#include <grub/menu.h>
+#include <grub/term.h>
+
+struct grub_menu_viewer
+{
+ struct grub_menu_viewer *next;
+ void *data;
+ void (*set_chosen_entry) (int entry, void *data);
+ void (*print_timeout) (int timeout, void *data);
+ void (*clear_timeout) (void *data);
+ void (*fini) (void *fini);
+};
+
+void grub_menu_register_viewer (struct grub_menu_viewer *viewer);
+
+grub_err_t
+grub_menu_try_text (struct grub_term_output *term,
+ int entry, grub_menu_t menu, int nested);
+
+extern grub_err_t (*grub_gfxmenu_try_hook) (int entry, grub_menu_t menu,
+ int nested);
+
+#endif /* GRUB_MENU_VIEWER_HEADER */
diff --git a/include/grub/mips/arc/kernel.h b/include/grub/mips/arc/kernel.h
new file mode 100644
index 0000000..5069486
--- /dev/null
+++ b/include/grub/mips/arc/kernel.h
@@ -0,0 +1,2 @@
+#include <grub/cpu/kernel.h>
+
diff --git a/include/grub/mips/arc/memory.h b/include/grub/mips/arc/memory.h
new file mode 100644
index 0000000..77bb03d
--- /dev/null
+++ b/include/grub/mips/arc/memory.h
@@ -0,0 +1,46 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MEMORY_MACHINE_HEADER
+#define GRUB_MEMORY_MACHINE_HEADER 1
+
+#ifdef GRUB_CPU_MIPSEL
+#define GRUB_MACHINE_MEMORY_STACK_HIGH 0x806ffff0
+#else
+#define GRUB_MACHINE_MEMORY_STACK_HIGH 0x881ffff0
+#endif
+
+#ifndef ASM_FILE
+
+static inline grub_err_t
+grub_machine_mmap_register (grub_uint64_t start __attribute__ ((unused)),
+ grub_uint64_t size __attribute__ ((unused)),
+ int type __attribute__ ((unused)),
+ int handle __attribute__ ((unused)))
+{
+ return GRUB_ERR_NONE;
+}
+static inline grub_err_t
+grub_machine_mmap_unregister (int handle __attribute__ ((unused)))
+{
+ return GRUB_ERR_NONE;
+}
+
+#endif
+
+#endif
diff --git a/include/grub/mips/arc/time.h b/include/grub/mips/arc/time.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/include/grub/mips/arc/time.h
diff --git a/include/grub/mips/asm.h b/include/grub/mips/asm.h
new file mode 100644
index 0000000..4c397f4
--- /dev/null
+++ b/include/grub/mips/asm.h
@@ -0,0 +1,18 @@
+#ifndef GRUB_MIPS_ASM_HEADER
+#define GRUB_MIPS_ASM_HEADER 1
+
+#if defined(_MIPS_SIM) && defined(_ABIN32) && _MIPS_SIM == _ABIN32
+#define GRUB_ASM_T4 $a4
+#define GRUB_ASM_T5 $a5
+#define GRUB_ASM_SZREG 8
+#define GRUB_ASM_REG_S sd
+#define GRUB_ASM_REG_L ld
+#else
+#define GRUB_ASM_T4 $t4
+#define GRUB_ASM_T5 $t5
+#define GRUB_ASM_SZREG 4
+#define GRUB_ASM_REG_S sw
+#define GRUB_ASM_REG_L lw
+#endif
+
+#endif
diff --git a/include/grub/mips/at_keyboard.h b/include/grub/mips/at_keyboard.h
new file mode 100644
index 0000000..0c30753
--- /dev/null
+++ b/include/grub/mips/at_keyboard.h
@@ -0,0 +1 @@
+#include <grub/machine/at_keyboard.h>
diff --git a/include/grub/mips/cmos.h b/include/grub/mips/cmos.h
new file mode 100644
index 0000000..79a7a4c
--- /dev/null
+++ b/include/grub/mips/cmos.h
@@ -0,0 +1 @@
+#include <grub/machine/cmos.h>
diff --git a/include/grub/mips/io.h b/include/grub/mips/io.h
new file mode 100644
index 0000000..dee76bd
--- /dev/null
+++ b/include/grub/mips/io.h
@@ -0,0 +1,62 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_IO_H
+#define GRUB_IO_H 1
+
+#include <grub/types.h>
+
+typedef grub_addr_t grub_port_t;
+
+static __inline unsigned char
+grub_inb (grub_port_t port)
+{
+ return *(volatile grub_uint8_t *) port;
+}
+
+static __inline unsigned short int
+grub_inw (grub_port_t port)
+{
+ return *(volatile grub_uint16_t *) port;
+}
+
+static __inline unsigned int
+grub_inl (grub_port_t port)
+{
+ return *(volatile grub_uint32_t *) port;
+}
+
+static __inline void
+grub_outb (unsigned char value, grub_port_t port)
+{
+ *(volatile grub_uint8_t *) port = value;
+}
+
+static __inline void
+grub_outw (unsigned short int value, grub_port_t port)
+{
+ *(volatile grub_uint16_t *) port = value;
+}
+
+static __inline void
+grub_outl (unsigned int value, grub_port_t port)
+{
+ *(volatile grub_uint32_t *) port = value;
+}
+
+#endif /* _SYS_IO_H */
diff --git a/include/grub/mips/kernel.h b/include/grub/mips/kernel.h
new file mode 100644
index 0000000..07b0884
--- /dev/null
+++ b/include/grub/mips/kernel.h
@@ -0,0 +1,24 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2005,2006,2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_KERNEL_CPU_HEADER
+#define GRUB_KERNEL_CPU_HEADER 1
+
+#include <grub/symbol.h>
+
+#endif /* ! GRUB_KERNEL_MACHINE_HEADER */
diff --git a/include/grub/mips/loongson.h b/include/grub/mips/loongson.h
new file mode 100644
index 0000000..e6f0241
--- /dev/null
+++ b/include/grub/mips/loongson.h
@@ -0,0 +1,86 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_LOONGSON_CPU_HEADER
+#define GRUB_LOONGSON_CPU_HEADER 1
+
+#include <grub/cpu/mips.h>
+
+#define GRUB_CPU_LOONGSON_FLASH_START 0xbfc00000
+#define GRUB_CPU_LOONGSON_FLASH_TLB_REFILL 0xbfc00200
+#define GRUB_CPU_LOONGSON_FLASH_CACHE_ERROR 0xbfc00300
+#define GRUB_CPU_LOONGSON_FLASH_OTHER_EXCEPTION 0xbfc00380
+
+#define GRUB_CPU_LOONGSON_DDR2_BASE 0xaffffe00
+#define GRUB_CPU_LOONGSON_DDR2_REG1_HI_8BANKS 0x00000001
+#define GRUB_CPU_LOONGSON_DDR2_REG_SIZE 0x8
+#define GRUB_CPU_LOONGSON_DDR2_REG_STEP 0x10
+
+#define GRUB_CPU_LOONGSON_COP0_CACHE_CONFIG GRUB_CPU_REGISTER_WRAP($16)
+#define GRUB_CPU_LOONGSON_COP0_CACHE_CONFIG_ILINESIZE 0x10
+#define GRUB_CPU_LOONGSON_COP0_CACHE_CONFIG_DLINESIZE 0x8
+#define GRUB_CPU_LOONGSON_COP0_CACHE_DSIZE_SHIFT 6
+#define GRUB_CPU_LOONGSON_COP0_CACHE_ISIZE_SHIFT 9
+#define GRUB_CPU_LOONGSON_COP0_CACHE_SIZE_MASK 0x7
+#define GRUB_CPU_LOONGSON_COP0_CACHE_SIZE_OFFSET 12
+
+#define GRUB_CPU_LOONGSON_COP0_I_INDEX_INVALIDATE 0
+#define GRUB_CPU_LOONGSON_COP0_D_INDEX_TAG_STORE 9
+#define GRUB_CPU_LOONGSON_COP0_S_INDEX_TAG_STORE 11
+
+#define GRUB_CPU_LOONGSON_COP0_I_INDEX_BIT_OFFSET 5
+#define GRUB_CPU_LOONGSON_COP0_D_INDEX_BIT_OFFSET 5
+#define GRUB_CPU_LOONGSON_COP0_S_INDEX_BIT_OFFSET 5
+
+#define GRUB_CPU_LOONGSON_CACHE_ACCELERATED 7
+#define GRUB_CPU_LOONGSON_CACHE_UNCACHED 2
+#define GRUB_CPU_LOONGSON_CACHE_CACHED 3
+#define GRUB_CPU_LOONGSON_CACHE_TYPE_MASK 7
+#define GRUB_CPU_LOONGSON_CACHE_LINE_SIZE_LOG_SMALL 4
+#define GRUB_CPU_LOONGSON_CACHE_LINE_SIZE_LOG_BIG 5
+#define GRUB_CPU_LOONGSON_CACHE_LINE_SIZE_SMALL 16
+#define GRUB_CPU_LOONGSON_CACHE_LINE_SIZE_BIG 32
+
+#define GRUB_CPU_LOONGSON_I_CACHE_LOG_WAYS 2
+#define GRUB_CPU_LOONGSON_D_CACHE_LOG_WAYS 2
+#define GRUB_CPU_LOONGSON_S_CACHE_LOG_WAYS 2
+
+/* FIXME: determine dynamically. */
+#define GRUB_CPU_LOONGSON_SECONDARY_CACHE_LOG_SIZE 19
+
+#define GRUB_CPU_LOONGSON_COP0_BADVADDR GRUB_CPU_REGISTER_WRAP($8)
+#define GRUB_CPU_LOONGSON_COP0_CAUSE GRUB_CPU_REGISTER_WRAP($13)
+#define GRUB_CPU_LOONGSON_COP0_EPC GRUB_CPU_REGISTER_WRAP($14)
+#define GRUB_CPU_LOONGSON_COP0_PRID GRUB_CPU_REGISTER_WRAP($15)
+#define GRUB_CPU_LOONGSON_COP0_CACHE_TAGLO GRUB_CPU_REGISTER_WRAP($28)
+#define GRUB_CPU_LOONGSON_COP0_CACHE_TAGHI GRUB_CPU_REGISTER_WRAP($29)
+
+#define GRUB_CPU_LOONGSON_LIOCFG 0xbfe00108
+#define GRUB_CPU_LOONGSON_ROM_DELAY_OFFSET 2
+#define GRUB_CPU_LOONGSON_ROM_DELAY_MASK 0x1f
+#define GRUB_CPU_LOONGSON_CORECFG 0xbfe00180
+#define GRUB_CPU_LOONGSON_CORECFG_DISABLE_DDR2_SPACE 0x100
+#define GRUB_CPU_LOONGSON_CORECFG_BUFFER_CPU 0x200
+
+#define GRUB_CPU_LOONGSON_PCI_HIT1_SEL_LO 0xbfe00150
+#define GRUB_CPU_LOONGSON_PCI_HIT1_SEL_HI 0xbfe00154
+
+#define GRUB_CPU_LOONGSON_GPIOCFG 0xbfe00120
+#define GRUB_CPU_YEELOONG_SHUTDOWN_GPIO 1
+
+#endif
diff --git a/include/grub/mips/loongson/at_keyboard.h b/include/grub/mips/loongson/at_keyboard.h
new file mode 100644
index 0000000..8e58cfb
--- /dev/null
+++ b/include/grub/mips/loongson/at_keyboard.h
@@ -0,0 +1,27 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MACHINE_AT_KEYBOARD_HEADER
+#define GRUB_MACHINE_AT_KEYBOARD_HEADER 1
+
+#include <grub/pci.h>
+
+#define KEYBOARD_REG_DATA (GRUB_MACHINE_PCI_IO_BASE | 0x60)
+#define KEYBOARD_REG_STATUS (GRUB_MACHINE_PCI_IO_BASE | 0x64)
+
+#endif
diff --git a/include/grub/mips/loongson/cmos.h b/include/grub/mips/loongson/cmos.h
new file mode 100644
index 0000000..0c8cc8d
--- /dev/null
+++ b/include/grub/mips/loongson/cmos.h
@@ -0,0 +1,30 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_CPU_CMOS_H
+#define GRUB_CPU_CMOS_H 1
+
+#include <grub/types.h>
+#include <grub/cpu/io.h>
+
+#define GRUB_CMOS_ADDR_REG 0xbfd00070
+#define GRUB_CMOS_DATA_REG 0xbfd00071
+#define GRUB_CMOS_ADDR_REG_HI 0xbfd00072
+#define GRUB_CMOS_DATA_REG_HI 0xbfd00073
+
+#endif /* GRUB_CPU_CMOS_H */
diff --git a/include/grub/mips/loongson/ec.h b/include/grub/mips/loongson/ec.h
new file mode 100644
index 0000000..3f8ff99
--- /dev/null
+++ b/include/grub/mips/loongson/ec.h
@@ -0,0 +1,45 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_EC_MACHINE_HEADER
+#define GRUB_EC_MACHINE_HEADER 1
+
+#include <grub/types.h>
+#include <grub/cpu/io.h>
+#include <grub/pci.h>
+
+#define GRUB_MACHINE_EC_MAGIC_PORT1 0x381
+#define GRUB_MACHINE_EC_MAGIC_PORT2 0x382
+#define GRUB_MACHINE_EC_DATA_PORT 0x383
+
+#define GRUB_MACHINE_EC_MAGIC_VAL1 0xf4
+#define GRUB_MACHINE_EC_MAGIC_VAL2 0xec
+
+#define GRUB_MACHINE_EC_COMMAND_REBOOT 1
+
+static inline void
+grub_write_ec (grub_uint8_t value)
+{
+ grub_outb (GRUB_MACHINE_EC_MAGIC_VAL1,
+ GRUB_MACHINE_PCI_IO_BASE + GRUB_MACHINE_EC_MAGIC_PORT1);
+ grub_outb (GRUB_MACHINE_EC_MAGIC_VAL2,
+ GRUB_MACHINE_PCI_IO_BASE + GRUB_MACHINE_EC_MAGIC_PORT2);
+ grub_outb (value, GRUB_MACHINE_PCI_IO_BASE + GRUB_MACHINE_EC_DATA_PORT);
+}
+
+#endif
diff --git a/include/grub/mips/loongson/kernel.h b/include/grub/mips/loongson/kernel.h
new file mode 100644
index 0000000..0587191
--- /dev/null
+++ b/include/grub/mips/loongson/kernel.h
@@ -0,0 +1,36 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2005,2006,2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_KERNEL_MACHINE_HEADER
+#define GRUB_KERNEL_MACHINE_HEADER 1
+
+#include <grub/symbol.h>
+#include <grub/cpu/kernel.h>
+
+#define GRUB_ARCH_MACHINE_YEELOONG 0
+#define GRUB_ARCH_MACHINE_FULOONG2F 1
+#define GRUB_ARCH_MACHINE_FULOONG2E 2
+#define GRUB_ARCH_MACHINE_YEELOONG_3A 3
+
+#ifndef ASM_FILE
+
+extern grub_uint32_t EXPORT_VAR (grub_arch_machine) __attribute__ ((section(".text")));
+
+#endif
+
+#endif /* ! GRUB_KERNEL_MACHINE_HEADER */
diff --git a/include/grub/mips/loongson/memory.h b/include/grub/mips/loongson/memory.h
new file mode 100644
index 0000000..aa41fa6
--- /dev/null
+++ b/include/grub/mips/loongson/memory.h
@@ -0,0 +1,51 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MEMORY_MACHINE_HEADER
+#define GRUB_MEMORY_MACHINE_HEADER 1
+
+#ifndef ASM_FILE
+#include <grub/symbol.h>
+#include <grub/err.h>
+#include <grub/types.h>
+#endif
+
+#define GRUB_MACHINE_MEMORY_STACK_HIGH 0x801ffff0
+
+#ifndef ASM_FILE
+
+static inline grub_err_t
+grub_machine_mmap_register (grub_uint64_t start __attribute__ ((unused)),
+ grub_uint64_t size __attribute__ ((unused)),
+ int type __attribute__ ((unused)),
+ int handle __attribute__ ((unused)))
+{
+ return GRUB_ERR_NONE;
+}
+static inline grub_err_t
+grub_machine_mmap_unregister (int handle __attribute__ ((unused)))
+{
+ return GRUB_ERR_NONE;
+}
+
+extern grub_uint32_t EXPORT_VAR (grub_arch_memsize) __attribute__ ((section(".text")));
+extern grub_uint32_t EXPORT_VAR (grub_arch_highmemsize) __attribute__ ((section(".text")));
+
+#endif
+
+#endif
diff --git a/include/grub/mips/loongson/pci.h b/include/grub/mips/loongson/pci.h
new file mode 100644
index 0000000..b3272e9
--- /dev/null
+++ b/include/grub/mips/loongson/pci.h
@@ -0,0 +1,110 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MACHINE_PCI_H
+#define GRUB_MACHINE_PCI_H 1
+
+#ifndef ASM_FILE
+#include <grub/types.h>
+#include <grub/cpu/io.h>
+#endif
+
+#define GRUB_LOONGSON_OHCI_PCIID 0x00351033
+#define GRUB_LOONGSON_EHCI_PCIID 0x00e01033
+
+#define GRUB_MACHINE_PCI_IO_BASE_2F 0xbfd00000
+#define GRUB_MACHINE_PCI_IO_BASE_3A 0xb8000000
+#define GRUB_MACHINE_PCI_CONFSPACE_2F 0xbfe80000
+#define GRUB_MACHINE_PCI_CONFSPACE_3A 0xba000000
+#define GRUB_MACHINE_PCI_CONFSPACE_3A_EXT 0xbb000000
+#define GRUB_MACHINE_PCI_CONTROLLER_HEADER 0xbfe00000
+
+#define GRUB_MACHINE_PCI_CONF_CTRL_REG_ADDR_2F 0xbfe00118
+
+#define GRUB_PCI_NUM_DEVICES_2F 16
+
+#ifndef ASM_FILE
+
+typedef enum { GRUB_BONITO_2F, GRUB_BONITO_3A } grub_bonito_type_t;
+extern grub_bonito_type_t EXPORT_VAR (grub_bonito_type);
+
+#define GRUB_PCI_NUM_DEVICES (grub_bonito_type ? 32 \
+ : GRUB_PCI_NUM_DEVICES_2F)
+#define GRUB_PCI_NUM_BUS (grub_bonito_type ? 256 : 1)
+
+#define GRUB_MACHINE_PCI_IO_BASE (grub_bonito_type \
+ ? GRUB_MACHINE_PCI_IO_BASE_3A \
+ : GRUB_MACHINE_PCI_IO_BASE_2F)
+
+#define GRUB_MACHINE_PCI_CONF_CTRL_REG_2F (*(volatile grub_uint32_t *) \
+ GRUB_MACHINE_PCI_CONF_CTRL_REG_ADDR_2F)
+#define GRUB_MACHINE_PCI_IO_CTRL_REG_2F (*(volatile grub_uint32_t *) 0xbfe00110)
+#define GRUB_MACHINE_PCI_CONF_CTRL_REG_3A (*(volatile grub_uint32_t *) \
+ 0xbfe00118)
+
+#endif
+#define GRUB_MACHINE_PCI_WIN_MASK_SIZE 6
+#define GRUB_MACHINE_PCI_WIN_MASK ((1 << GRUB_MACHINE_PCI_WIN_MASK_SIZE) - 1)
+
+/* We have 3 PCI windows. */
+#define GRUB_MACHINE_PCI_NUM_WIN 3
+/* Each window is 64MiB. */
+#define GRUB_MACHINE_PCI_WIN_SHIFT 26
+#define GRUB_MACHINE_PCI_WIN_OFFSET_MASK ((1 << GRUB_MACHINE_PCI_WIN_SHIFT) - 1)
+
+#define GRUB_MACHINE_PCI_WIN_SIZE 0x04000000
+/* Graphical acceleration takes 1 MiB away. */
+#define GRUB_MACHINE_PCI_WIN1_SIZE 0x03f00000
+
+#define GRUB_MACHINE_PCI_WIN1_ADDR 0xb0000000
+#define GRUB_MACHINE_PCI_WIN2_ADDR 0xb4000000
+#define GRUB_MACHINE_PCI_WIN3_ADDR 0xb8000000
+
+#ifndef ASM_FILE
+grub_uint32_t
+EXPORT_FUNC (grub_pci_read) (grub_pci_address_t addr);
+
+grub_uint16_t
+EXPORT_FUNC (grub_pci_read_word) (grub_pci_address_t addr);
+
+grub_uint8_t
+EXPORT_FUNC (grub_pci_read_byte) (grub_pci_address_t addr);
+
+void
+EXPORT_FUNC (grub_pci_write) (grub_pci_address_t addr, grub_uint32_t data);
+
+void
+EXPORT_FUNC (grub_pci_write_word) (grub_pci_address_t addr, grub_uint16_t data);
+
+void
+EXPORT_FUNC (grub_pci_write_byte) (grub_pci_address_t addr, grub_uint8_t data);
+
+volatile void *
+EXPORT_FUNC (grub_pci_device_map_range) (grub_pci_device_t dev,
+ grub_addr_t base, grub_size_t size);
+void *
+EXPORT_FUNC (grub_pci_device_map_range_cached) (grub_pci_device_t dev,
+ grub_addr_t base,
+ grub_size_t size);
+void
+EXPORT_FUNC (grub_pci_device_unmap_range) (grub_pci_device_t dev,
+ volatile void *mem,
+ grub_size_t size);
+#endif
+
+#endif /* GRUB_MACHINE_PCI_H */
diff --git a/include/grub/mips/loongson/serial.h b/include/grub/mips/loongson/serial.h
new file mode 100644
index 0000000..45e6d84
--- /dev/null
+++ b/include/grub/mips/loongson/serial.h
@@ -0,0 +1,33 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MACHINE_SERIAL_HEADER
+#define GRUB_MACHINE_SERIAL_HEADER 1
+
+#define GRUB_MACHINE_SERIAL_PORT0_DIVISOR_115200 2
+#define GRUB_MACHINE_SERIAL_PORT2_DIVISOR_115200 1
+#define GRUB_MACHINE_SERIAL_PORT0 0xbff003f8
+#define GRUB_MACHINE_SERIAL_PORT1 0xbfd003f8
+#define GRUB_MACHINE_SERIAL_PORT2 0xbfd002f8
+
+#ifndef ASM_FILE
+#define GRUB_MACHINE_SERIAL_PORTS { GRUB_MACHINE_SERIAL_PORT0, GRUB_MACHINE_SERIAL_PORT1, GRUB_MACHINE_SERIAL_PORT2 }
+#else
+#endif
+
+#endif
diff --git a/include/grub/mips/loongson/time.h b/include/grub/mips/loongson/time.h
new file mode 100644
index 0000000..0985732
--- /dev/null
+++ b/include/grub/mips/loongson/time.h
@@ -0,0 +1,27 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2003,2004,2005,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef KERNEL_MACHINE_TIME_HEADER
+#define KERNEL_MACHINE_TIME_HEADER 1
+
+#include <grub/symbol.h>
+#include <grub/cpu/time.h>
+
+extern grub_uint32_t EXPORT_VAR (grub_arch_busclock) __attribute__ ((section(".text")));
+
+#endif /* ! KERNEL_MACHINE_TIME_HEADER */
diff --git a/include/grub/mips/memory.h b/include/grub/mips/memory.h
new file mode 100644
index 0000000..a85bbe7
--- /dev/null
+++ b/include/grub/mips/memory.h
@@ -0,0 +1,60 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MEMORY_CPU_HEADER
+#define GRUB_MEMORY_CPU_HEADER 1
+
+#ifndef ASM_FILE
+#include <grub/symbol.h>
+#include <grub/err.h>
+#include <grub/types.h>
+#endif
+
+#define GRUB_ARCH_LOWMEMVSTART 0x80000000
+#define GRUB_ARCH_LOWMEMPSTART 0x00000000
+#define GRUB_ARCH_LOWMEMMAXSIZE 0x10000000
+#define GRUB_ARCH_HIGHMEMPSTART 0x10000000
+
+#ifndef ASM_FILE
+
+typedef grub_addr_t grub_phys_addr_t;
+
+static inline grub_phys_addr_t
+grub_vtop (void *a)
+{
+ return ((grub_phys_addr_t) a) & 0x1fffffff;
+}
+
+static inline void *
+grub_map_memory (grub_phys_addr_t a, grub_size_t size __attribute__ ((unused)))
+{
+ return (void *) (a | 0x80000000);
+}
+
+static inline void
+grub_unmap_memory (void *a __attribute__ ((unused)),
+ grub_size_t size __attribute__ ((unused)))
+{
+}
+
+grub_uint64_t grub_mmap_get_lower (void);
+grub_uint64_t grub_mmap_get_upper (void);
+
+#endif
+
+#endif
diff --git a/include/grub/mips/mips.h b/include/grub/mips/mips.h
new file mode 100644
index 0000000..bafb2bd
--- /dev/null
+++ b/include/grub/mips/mips.h
@@ -0,0 +1,30 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_REGISTERS_CPU_HEADER
+#define GRUB_REGISTERS_CPU_HEADER 1
+
+#ifdef ASM_FILE
+#define GRUB_CPU_REGISTER_WRAP(x) x
+#else
+#define GRUB_CPU_REGISTER_WRAP(x) #x
+#endif
+
+#define GRUB_CPU_MIPS_COP0_TIMER_COUNT GRUB_CPU_REGISTER_WRAP($9)
+
+#endif
diff --git a/include/grub/mips/multiboot.h b/include/grub/mips/multiboot.h
new file mode 100644
index 0000000..cdfb41e
--- /dev/null
+++ b/include/grub/mips/multiboot.h
@@ -0,0 +1,31 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2003,2004,2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MULTIBOOT_CPU_HEADER
+#define GRUB_MULTIBOOT_CPU_HEADER 1
+
+#define MULTIBOOT2_INITIAL_STATE { .gpr[4] = MULTIBOOT2_BOOTLOADER_MAGIC, \
+ .jumpreg = 1 }
+#define MULTIBOOT_ENTRY_REGISTER gpr[1]
+#define MULTIBOOT_MBI_REGISTER gpr[5]
+#define MULTIBOOT2_ARCHITECTURE_CURRENT MULTIBOOT2_ARCHITECTURE_MIPS32
+
+#define MULTIBOOT_ELF32_MACHINE EM_MIPS
+#define MULTIBOOT_ELF64_MACHINE EM_MIPS
+
+#endif /* ! GRUB_MULTIBOOT_CPU_HEADER */
diff --git a/include/grub/mips/pci.h b/include/grub/mips/pci.h
new file mode 100644
index 0000000..8b49d84
--- /dev/null
+++ b/include/grub/mips/pci.h
@@ -0,0 +1 @@
+#include <grub/machine/pci.h>
diff --git a/include/grub/mips/qemu_mips/at_keyboard.h b/include/grub/mips/qemu_mips/at_keyboard.h
new file mode 100644
index 0000000..37cc625
--- /dev/null
+++ b/include/grub/mips/qemu_mips/at_keyboard.h
@@ -0,0 +1,25 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MACHINE_AT_KEYBOARD_HEADER
+#define GRUB_MACHINE_AT_KEYBOARD_HEADER 1
+
+#define KEYBOARD_REG_DATA 0xb4000060
+#define KEYBOARD_REG_STATUS 0xb4000064
+
+#endif
diff --git a/include/grub/mips/qemu_mips/cmos.h b/include/grub/mips/qemu_mips/cmos.h
new file mode 100644
index 0000000..0759704
--- /dev/null
+++ b/include/grub/mips/qemu_mips/cmos.h
@@ -0,0 +1,30 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_CPU_CMOS_H
+#define GRUB_CPU_CMOS_H 1
+
+#include <grub/types.h>
+#include <grub/cpu/io.h>
+
+#define GRUB_CMOS_ADDR_REG 0xb4000070
+#define GRUB_CMOS_DATA_REG 0xb4000071
+#define GRUB_CMOS_ADDR_REG_HI 0xb4000072
+#define GRUB_CMOS_DATA_REG_HI 0xb4000073
+
+#endif /* GRUB_CPU_CMOS_H */
diff --git a/include/grub/mips/qemu_mips/console.h b/include/grub/mips/qemu_mips/console.h
new file mode 100644
index 0000000..2ffef73
--- /dev/null
+++ b/include/grub/mips/qemu_mips/console.h
@@ -0,0 +1,25 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MACHINE_CONSOLE_HEADER
+#define GRUB_MACHINE_CONSOLE_HEADER 1
+
+void grub_vga_text_init (void);
+void grub_vga_text_fini (void);
+
+#endif /* ! GRUB_MACHINE_CONSOLE_HEADER */
diff --git a/include/grub/mips/qemu_mips/kernel.h b/include/grub/mips/qemu_mips/kernel.h
new file mode 100644
index 0000000..8b8b014
--- /dev/null
+++ b/include/grub/mips/qemu_mips/kernel.h
@@ -0,0 +1,30 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2005,2006,2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_KERNEL_MACHINE_HEADER
+#define GRUB_KERNEL_MACHINE_HEADER 1
+
+#include <grub/symbol.h>
+
+#ifndef ASM_FILE
+
+void grub_qemu_init_cirrus (void);
+
+#endif
+
+#endif /* ! GRUB_KERNEL_MACHINE_HEADER */
diff --git a/include/grub/mips/qemu_mips/loader.h b/include/grub/mips/qemu_mips/loader.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/include/grub/mips/qemu_mips/loader.h
diff --git a/include/grub/mips/qemu_mips/memory.h b/include/grub/mips/qemu_mips/memory.h
new file mode 100644
index 0000000..29b04a5
--- /dev/null
+++ b/include/grub/mips/qemu_mips/memory.h
@@ -0,0 +1,50 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MEMORY_MACHINE_HEADER
+#define GRUB_MEMORY_MACHINE_HEADER 1
+
+#ifndef ASM_FILE
+#include <grub/symbol.h>
+#include <grub/err.h>
+#include <grub/types.h>
+#endif
+
+#define GRUB_MACHINE_MEMORY_STACK_HIGH 0x80f00000
+#define GRUB_MACHINE_MEMORY_USABLE 0x81000000
+
+#ifndef ASM_FILE
+
+extern grub_uint32_t grub_arch_memsize __attribute__ ((section(".text")));
+
+static inline grub_err_t
+grub_machine_mmap_register (grub_uint64_t start __attribute__ ((unused)),
+ grub_uint64_t size __attribute__ ((unused)),
+ int type __attribute__ ((unused)),
+ int handle __attribute__ ((unused)))
+{
+ return GRUB_ERR_NONE;
+}
+static inline grub_err_t
+grub_machine_mmap_unregister (int handle __attribute__ ((unused)))
+{
+ return GRUB_ERR_NONE;
+}
+#endif
+
+#endif
diff --git a/include/grub/mips/qemu_mips/serial.h b/include/grub/mips/qemu_mips/serial.h
new file mode 100644
index 0000000..1708678
--- /dev/null
+++ b/include/grub/mips/qemu_mips/serial.h
@@ -0,0 +1,24 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MACHINE_SERIAL_HEADER
+#define GRUB_MACHINE_SERIAL_HEADER 1
+
+#define GRUB_MACHINE_SERIAL_PORTS { 0xb40003f8 }
+
+#endif
diff --git a/include/grub/mips/qemu_mips/time.h b/include/grub/mips/qemu_mips/time.h
new file mode 100644
index 0000000..164b61e
--- /dev/null
+++ b/include/grub/mips/qemu_mips/time.h
@@ -0,0 +1,25 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2003,2004,2005,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef KERNEL_MACHINE_TIME_HEADER
+#define KERNEL_MACHINE_TIME_HEADER 1
+
+#include <grub/symbol.h>
+#include <grub/cpu/time.h>
+
+#endif /* ! KERNEL_MACHINE_TIME_HEADER */
diff --git a/include/grub/mips/relocator.h b/include/grub/mips/relocator.h
new file mode 100644
index 0000000..67b0a4c
--- /dev/null
+++ b/include/grub/mips/relocator.h
@@ -0,0 +1,38 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_RELOCATOR_CPU_HEADER
+#define GRUB_RELOCATOR_CPU_HEADER 1
+
+#include <grub/types.h>
+#include <grub/err.h>
+#include <grub/relocator.h>
+
+struct grub_relocator32_state
+{
+ /* gpr[0] is ignored since it's hardwired to 0. */
+ grub_uint32_t gpr[32];
+ /* Register holding target $pc. */
+ int jumpreg;
+};
+
+grub_err_t
+grub_relocator32_boot (struct grub_relocator *rel,
+ struct grub_relocator32_state state);
+
+#endif /* ! GRUB_RELOCATOR_CPU_HEADER */
diff --git a/include/grub/mips/setjmp.h b/include/grub/mips/setjmp.h
new file mode 100644
index 0000000..f8f6517
--- /dev/null
+++ b/include/grub/mips/setjmp.h
@@ -0,0 +1,27 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2004,2006,2007,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_SETJMP_CPU_HEADER
+#define GRUB_SETJMP_CPU_HEADER 1
+
+typedef grub_uint64_t grub_jmp_buf[12];
+
+int grub_setjmp (grub_jmp_buf env) RETURNS_TWICE;
+void grub_longjmp (grub_jmp_buf env, int val) __attribute__ ((noreturn));
+
+#endif /* ! GRUB_SETJMP_CPU_HEADER */
diff --git a/include/grub/mips/time.h b/include/grub/mips/time.h
new file mode 100644
index 0000000..f5c891a
--- /dev/null
+++ b/include/grub/mips/time.h
@@ -0,0 +1,37 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2003,2004,2005,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef KERNEL_CPU_TIME_HEADER
+#define KERNEL_CPU_TIME_HEADER 1
+
+#ifndef GRUB_UTIL
+
+#define GRUB_TICKS_PER_SECOND (grub_arch_cpuclock / 2)
+
+/* Return the real time in ticks. */
+grub_uint64_t EXPORT_FUNC (grub_get_rtc) (void);
+
+extern grub_uint32_t EXPORT_VAR (grub_arch_cpuclock) __attribute__ ((section(".text")));
+#endif
+
+static inline void
+grub_cpu_idle(void)
+{
+}
+
+#endif
diff --git a/include/grub/mips/types.h b/include/grub/mips/types.h
new file mode 100644
index 0000000..fe09afa
--- /dev/null
+++ b/include/grub/mips/types.h
@@ -0,0 +1,38 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2006,2007,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_TYPES_CPU_HEADER
+#define GRUB_TYPES_CPU_HEADER 1
+
+/* The size of void *. */
+#define GRUB_TARGET_SIZEOF_VOID_P 4
+
+/* The size of long. */
+#define GRUB_TARGET_SIZEOF_LONG 4
+
+#ifdef GRUB_CPU_MIPSEL
+/* mipsEL is little-endian. */
+#undef GRUB_TARGET_WORDS_BIGENDIAN
+#elif defined (GRUB_CPU_MIPS)
+/* mips is big-endian. */
+#define GRUB_TARGET_WORDS_BIGENDIAN
+#elif !defined (GRUB_SYMBOL_GENERATOR)
+#error Neither GRUB_CPU_MIPS nor GRUB_CPU_MIPSEL is defined
+#endif
+
+#endif /* ! GRUB_TYPES_CPU_HEADER */
diff --git a/include/grub/misc.h b/include/grub/misc.h
new file mode 100644
index 0000000..7d2b551
--- /dev/null
+++ b/include/grub/misc.h
@@ -0,0 +1,503 @@
+/* misc.h - prototypes for misc functions */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2003,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MISC_HEADER
+#define GRUB_MISC_HEADER 1
+
+#include <stdarg.h>
+#include <grub/types.h>
+#include <grub/symbol.h>
+#include <grub/err.h>
+#include <grub/i18n.h>
+#include <grub/compiler.h>
+
+#define ALIGN_UP(addr, align) \
+ (((addr) + (typeof (addr)) (align) - 1) & ~((typeof (addr)) (align) - 1))
+#define ALIGN_UP_OVERHEAD(addr, align) ((-(addr)) & ((typeof (addr)) (align) - 1))
+#define ALIGN_DOWN(addr, align) \
+ ((addr) & ~((typeof (addr)) (align) - 1))
+#define ARRAY_SIZE(array) (sizeof (array) / sizeof (array[0]))
+#define COMPILE_TIME_ASSERT(cond) switch (0) { case 1: case !(cond): ; }
+
+#define grub_dprintf(condition, ...) grub_real_dprintf(GRUB_FILE, __LINE__, condition, __VA_ARGS__)
+
+void *EXPORT_FUNC(grub_memmove) (void *dest, const void *src, grub_size_t n);
+char *EXPORT_FUNC(grub_strcpy) (char *dest, const char *src);
+
+static inline char *
+grub_strncpy (char *dest, const char *src, int c)
+{
+ char *p = dest;
+
+ while ((*p++ = *src++) != '\0' && --c)
+ ;
+
+ return dest;
+}
+
+static inline char *
+grub_stpcpy (char *dest, const char *src)
+{
+ char *d = dest;
+ const char *s = src;
+
+ do
+ *d++ = *s;
+ while (*s++ != '\0');
+
+ return d - 1;
+}
+
+/* XXX: If grub_memmove is too slow, we must implement grub_memcpy. */
+static inline void *
+grub_memcpy (void *dest, const void *src, grub_size_t n)
+{
+ return grub_memmove (dest, src, n);
+}
+
+#if defined(__x86_64__) && !defined (GRUB_UTIL)
+#if defined (__MINGW32__) || defined (__CYGWIN__) || defined (__MINGW64__)
+#define GRUB_ASM_ATTR __attribute__ ((sysv_abi))
+#else
+#define GRUB_ASM_ATTR
+#endif
+#endif
+
+int EXPORT_FUNC(grub_memcmp) (const void *s1, const void *s2, grub_size_t n);
+int EXPORT_FUNC(grub_strcmp) (const char *s1, const char *s2);
+int EXPORT_FUNC(grub_strncmp) (const char *s1, const char *s2, grub_size_t n);
+
+char *EXPORT_FUNC(grub_strchr) (const char *s, int c);
+char *EXPORT_FUNC(grub_strrchr) (const char *s, int c);
+int EXPORT_FUNC(grub_strword) (const char *s, const char *w);
+
+/* Copied from gnulib.
+ Written by Bruno Haible <bruno@clisp.org>, 2005. */
+static inline char *
+grub_strstr (const char *haystack, const char *needle)
+{
+ /* Be careful not to look at the entire extent of haystack or needle
+ until needed. This is useful because of these two cases:
+ - haystack may be very long, and a match of needle found early,
+ - needle may be very long, and not even a short initial segment of
+ needle may be found in haystack. */
+ if (*needle != '\0')
+ {
+ /* Speed up the following searches of needle by caching its first
+ character. */
+ char b = *needle++;
+
+ for (;; haystack++)
+ {
+ if (*haystack == '\0')
+ /* No match. */
+ return 0;
+ if (*haystack == b)
+ /* The first character matches. */
+ {
+ const char *rhaystack = haystack + 1;
+ const char *rneedle = needle;
+
+ for (;; rhaystack++, rneedle++)
+ {
+ if (*rneedle == '\0')
+ /* Found a match. */
+ return (char *) haystack;
+ if (*rhaystack == '\0')
+ /* No match. */
+ return 0;
+ if (*rhaystack != *rneedle)
+ /* Nothing in this round. */
+ break;
+ }
+ }
+ }
+ }
+ else
+ return (char *) haystack;
+}
+
+int EXPORT_FUNC(grub_isspace) (int c);
+
+static inline int
+grub_isprint (int c)
+{
+ return (c >= ' ' && c <= '~');
+}
+
+static inline int
+grub_iscntrl (int c)
+{
+ return (c >= 0x00 && c <= 0x1F) || c == 0x7F;
+}
+
+static inline int
+grub_isalpha (int c)
+{
+ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
+}
+
+static inline int
+grub_islower (int c)
+{
+ return (c >= 'a' && c <= 'z');
+}
+
+static inline int
+grub_isupper (int c)
+{
+ return (c >= 'A' && c <= 'Z');
+}
+
+static inline int
+grub_isgraph (int c)
+{
+ return (c >= '!' && c <= '~');
+}
+
+static inline int
+grub_isdigit (int c)
+{
+ return (c >= '0' && c <= '9');
+}
+
+static inline int
+grub_isxdigit (int c)
+{
+ return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
+}
+
+static inline int
+grub_isalnum (int c)
+{
+ return grub_isalpha (c) || grub_isdigit (c);
+}
+
+static inline int
+grub_tolower (int c)
+{
+ if (c >= 'A' && c <= 'Z')
+ return c - 'A' + 'a';
+
+ return c;
+}
+
+static inline int
+grub_toupper (int c)
+{
+ if (c >= 'a' && c <= 'z')
+ return c - 'a' + 'A';
+
+ return c;
+}
+
+static inline int
+grub_strcasecmp (const char *s1, const char *s2)
+{
+ while (*s1 && *s2)
+ {
+ if (grub_tolower ((grub_uint8_t) *s1)
+ != grub_tolower ((grub_uint8_t) *s2))
+ break;
+
+ s1++;
+ s2++;
+ }
+
+ return (int) grub_tolower ((grub_uint8_t) *s1)
+ - (int) grub_tolower ((grub_uint8_t) *s2);
+}
+
+static inline int
+grub_strncasecmp (const char *s1, const char *s2, grub_size_t n)
+{
+ if (n == 0)
+ return 0;
+
+ while (*s1 && *s2 && --n)
+ {
+ if (grub_tolower (*s1) != grub_tolower (*s2))
+ break;
+
+ s1++;
+ s2++;
+ }
+
+ return (int) grub_tolower ((grub_uint8_t) *s1)
+ - (int) grub_tolower ((grub_uint8_t) *s2);
+}
+
+/*
+ * Note that these differ from the C standard's definitions of strtol,
+ * strtoul(), and strtoull() by the addition of two const qualifiers on the end
+ * pointer, which make the declaration match the *semantic* requirements of
+ * their behavior. This means that instead of:
+ *
+ * char *s = "1234 abcd";
+ * char *end;
+ * unsigned long l;
+ *
+ * l = grub_strtoul(s, &end, 10);
+ *
+ * We must one of:
+ *
+ * const char *end;
+ * ... or ...
+ * l = grub_strtoul(s, (const char ** const)&end, 10);
+ */
+unsigned long EXPORT_FUNC(grub_strtoul) (const char * restrict str, const char ** const restrict end, int base);
+unsigned long long EXPORT_FUNC(grub_strtoull) (const char * restrict str, const char ** const restrict end, int base);
+
+static inline long
+grub_strtol (const char * restrict str, const char ** const restrict end, int base)
+{
+ int negative = 0;
+ unsigned long long magnitude;
+
+ while (*str && grub_isspace (*str))
+ str++;
+
+ if (*str == '-')
+ {
+ negative = 1;
+ str++;
+ }
+
+ magnitude = grub_strtoull (str, end, base);
+ if (negative)
+ {
+ if (magnitude > (unsigned long) GRUB_LONG_MAX + 1)
+ {
+ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected"));
+ return GRUB_LONG_MIN;
+ }
+ return -((long) magnitude);
+ }
+ else
+ {
+ if (magnitude > GRUB_LONG_MAX)
+ {
+ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected"));
+ return GRUB_LONG_MAX;
+ }
+ return (long) magnitude;
+ }
+}
+
+char *EXPORT_FUNC(grub_strdup) (const char *s) WARN_UNUSED_RESULT;
+char *EXPORT_FUNC(grub_strndup) (const char *s, grub_size_t n) WARN_UNUSED_RESULT;
+void *EXPORT_FUNC(grub_memset) (void *s, int c, grub_size_t n);
+grub_size_t EXPORT_FUNC(grub_strlen) (const char *s) WARN_UNUSED_RESULT;
+int EXPORT_FUNC(grub_printf) (const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 1, 2)));
+int EXPORT_FUNC(grub_printf_) (const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 1, 2)));
+
+/* Replace all `ch' characters of `input' with `with' and copy the
+ result into `output'; return EOS address of `output'. */
+static inline char *
+grub_strchrsub (char *output, const char *input, char ch, const char *with)
+{
+ while (*input)
+ {
+ if (*input == ch)
+ {
+ grub_strcpy (output, with);
+ output += grub_strlen (with);
+ input++;
+ continue;
+ }
+ *output++ = *input++;
+ }
+ *output = '\0';
+ return output;
+}
+
+extern void (*EXPORT_VAR (grub_xputs)) (const char *str);
+
+static inline int
+grub_puts (const char *s)
+{
+ const char nl[2] = "\n";
+ grub_xputs (s);
+ grub_xputs (nl);
+
+ return 1; /* Cannot fail. */
+}
+
+int EXPORT_FUNC(grub_puts_) (const char *s);
+int EXPORT_FUNC(grub_debug_enabled) (const char *condition);
+void EXPORT_FUNC(grub_real_dprintf) (const char *file,
+ const int line,
+ const char *condition,
+ const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 4, 5)));
+int EXPORT_FUNC(grub_vprintf) (const char *fmt, va_list args);
+int EXPORT_FUNC(grub_snprintf) (char *str, grub_size_t n, const char *fmt, ...)
+ __attribute__ ((format (GNU_PRINTF, 3, 4)));
+int EXPORT_FUNC(grub_vsnprintf) (char *str, grub_size_t n, const char *fmt,
+ va_list args);
+char *EXPORT_FUNC(grub_xasprintf) (const char *fmt, ...)
+ __attribute__ ((format (GNU_PRINTF, 1, 2))) WARN_UNUSED_RESULT;
+char *EXPORT_FUNC(grub_xvasprintf) (const char *fmt, va_list args) WARN_UNUSED_RESULT;
+void EXPORT_FUNC(grub_exit) (void) __attribute__ ((noreturn));
+grub_uint64_t EXPORT_FUNC(grub_divmod64) (grub_uint64_t n,
+ grub_uint64_t d,
+ grub_uint64_t *r);
+
+/* Must match softdiv group in gentpl.py. */
+#if !defined(GRUB_MACHINE_EMU) && (defined(__arm__) || defined(__ia64__) || \
+ (defined(__riscv) && (__riscv_xlen == 32)))
+#define GRUB_DIVISION_IN_SOFTWARE 1
+#else
+#define GRUB_DIVISION_IN_SOFTWARE 0
+#endif
+
+/* Some division functions need to be in kernel if compiler generates calls
+ to them. Otherwise we still need them for consistent tests but they go
+ into a separate module. */
+#if GRUB_DIVISION_IN_SOFTWARE
+#define EXPORT_FUNC_IF_SOFTDIV EXPORT_FUNC
+#else
+#define EXPORT_FUNC_IF_SOFTDIV(x) x
+#endif
+
+grub_int64_t
+EXPORT_FUNC_IF_SOFTDIV(grub_divmod64s) (grub_int64_t n,
+ grub_int64_t d,
+ grub_int64_t *r);
+
+grub_uint32_t
+EXPORT_FUNC_IF_SOFTDIV (grub_divmod32) (grub_uint32_t n,
+ grub_uint32_t d,
+ grub_uint32_t *r);
+
+grub_int32_t
+EXPORT_FUNC_IF_SOFTDIV (grub_divmod32s) (grub_int32_t n,
+ grub_int32_t d,
+ grub_int32_t *r);
+
+/* Inline functions. */
+
+static inline char *
+grub_memchr (const void *p, int c, grub_size_t len)
+{
+ const char *s = (const char *) p;
+ const char *e = s + len;
+
+ for (; s < e; s++)
+ if (*s == c)
+ return (char *) s;
+
+ return 0;
+}
+
+
+static inline unsigned int
+grub_abs (int x)
+{
+ if (x < 0)
+ return (unsigned int) (-x);
+ else
+ return (unsigned int) x;
+}
+
+/* Reboot the machine. */
+#if defined (GRUB_MACHINE_EMU) || defined (GRUB_MACHINE_QEMU_MIPS) || \
+ defined (GRUB_MACHINE_EFI)
+void EXPORT_FUNC(grub_reboot) (void) __attribute__ ((noreturn));
+#else
+void grub_reboot (void) __attribute__ ((noreturn));
+#endif
+
+#if defined (__clang__) && !defined (GRUB_UTIL)
+void __attribute__ ((noreturn)) EXPORT_FUNC (abort) (void);
+#endif
+
+#ifdef GRUB_MACHINE_PCBIOS
+/* Halt the system, using APM if possible. If NO_APM is true, don't
+ * use APM even if it is available. */
+void grub_halt (int no_apm) __attribute__ ((noreturn));
+#elif defined (__mips__) && !defined (GRUB_MACHINE_EMU)
+void EXPORT_FUNC (grub_halt) (void) __attribute__ ((noreturn));
+#else
+void grub_halt (void) __attribute__ ((noreturn));
+#endif
+
+#ifdef GRUB_MACHINE_EMU
+/* Flag to check if module loading is available. */
+extern const int EXPORT_VAR(grub_no_modules);
+#else
+#define grub_no_modules 0
+#endif
+
+static inline void
+grub_error_save (struct grub_error_saved *save)
+{
+ grub_memcpy (save->errmsg, grub_errmsg, sizeof (save->errmsg));
+ save->grub_errno = grub_errno;
+ grub_errno = GRUB_ERR_NONE;
+}
+
+static inline void
+grub_error_load (const struct grub_error_saved *save)
+{
+ grub_memcpy (grub_errmsg, save->errmsg, sizeof (grub_errmsg));
+ grub_errno = save->grub_errno;
+}
+
+/*
+ * grub_printf_fmt_checks() a fmt string for printf() against an expected
+ * format. It is intended for cases where the fmt string could come from
+ * an outside source and cannot be trusted.
+ *
+ * While expected fmt accepts a printf() format string it should be kept
+ * as simple as possible. The printf() format strings with positional
+ * parameters are NOT accepted, neither for fmt nor for fmt_expected.
+ *
+ * The fmt is accepted if it has equal or less arguments than fmt_expected
+ * and if the type of all arguments match.
+ *
+ * Returns GRUB_ERR_NONE if fmt is acceptable.
+ */
+grub_err_t EXPORT_FUNC (grub_printf_fmt_check) (const char *fmt, const char *fmt_expected);
+
+#if BOOT_TIME_STATS
+struct grub_boot_time
+{
+ struct grub_boot_time *next;
+ grub_uint64_t tp;
+ const char *file;
+ int line;
+ char *msg;
+};
+
+extern struct grub_boot_time *EXPORT_VAR(grub_boot_time_head);
+
+void EXPORT_FUNC(grub_real_boot_time) (const char *file,
+ const int line,
+ const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 3, 4)));
+#define grub_boot_time(...) grub_real_boot_time(GRUB_FILE, __LINE__, __VA_ARGS__)
+#else
+#define grub_boot_time(...)
+#endif
+
+#define grub_max(a, b) (((a) > (b)) ? (a) : (b))
+#define grub_min(a, b) (((a) < (b)) ? (a) : (b))
+
+#define grub_log2ull(n) (GRUB_TYPE_BITS (grub_uint64_t) - __builtin_clzll (n) - 1)
+
+#endif /* ! GRUB_MISC_HEADER */
diff --git a/include/grub/mm.h b/include/grub/mm.h
new file mode 100644
index 0000000..9c38dd3
--- /dev/null
+++ b/include/grub/mm.h
@@ -0,0 +1,83 @@
+/* mm.h - prototypes and declarations for memory manager */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MM_H
+#define GRUB_MM_H 1
+
+#include <grub/types.h>
+#include <grub/symbol.h>
+#include <config.h>
+
+#ifndef NULL
+# define NULL ((void *) 0)
+#endif
+
+void grub_mm_init_region (void *addr, grub_size_t size);
+void *EXPORT_FUNC(grub_calloc) (grub_size_t nmemb, grub_size_t size);
+void *EXPORT_FUNC(grub_malloc) (grub_size_t size);
+void *EXPORT_FUNC(grub_zalloc) (grub_size_t size);
+void EXPORT_FUNC(grub_free) (void *ptr);
+void *EXPORT_FUNC(grub_realloc) (void *ptr, grub_size_t size);
+#ifndef GRUB_MACHINE_EMU
+void *EXPORT_FUNC(grub_memalign) (grub_size_t align, grub_size_t size);
+#endif
+
+void grub_mm_check_real (const char *file, int line);
+#define grub_mm_check() grub_mm_check_real (GRUB_FILE, __LINE__);
+
+/* For debugging. */
+#if defined(MM_DEBUG) && !defined(GRUB_UTIL) && !defined (GRUB_MACHINE_EMU)
+/* Set this variable to 1 when you want to trace all memory function calls. */
+extern int EXPORT_VAR(grub_mm_debug);
+
+void grub_mm_dump_free (void);
+void grub_mm_dump (unsigned lineno);
+
+#define grub_calloc(nmemb, size) \
+ grub_debug_calloc (GRUB_FILE, __LINE__, nmemb, size)
+
+#define grub_malloc(size) \
+ grub_debug_malloc (GRUB_FILE, __LINE__, size)
+
+#define grub_zalloc(size) \
+ grub_debug_zalloc (GRUB_FILE, __LINE__, size)
+
+#define grub_realloc(ptr,size) \
+ grub_debug_realloc (GRUB_FILE, __LINE__, ptr, size)
+
+#define grub_memalign(align,size) \
+ grub_debug_memalign (GRUB_FILE, __LINE__, align, size)
+
+#define grub_free(ptr) \
+ grub_debug_free (GRUB_FILE, __LINE__, ptr)
+
+void *EXPORT_FUNC(grub_debug_calloc) (const char *file, int line,
+ grub_size_t nmemb, grub_size_t size);
+void *EXPORT_FUNC(grub_debug_malloc) (const char *file, int line,
+ grub_size_t size);
+void *EXPORT_FUNC(grub_debug_zalloc) (const char *file, int line,
+ grub_size_t size);
+void EXPORT_FUNC(grub_debug_free) (const char *file, int line, void *ptr);
+void *EXPORT_FUNC(grub_debug_realloc) (const char *file, int line, void *ptr,
+ grub_size_t size);
+void *EXPORT_FUNC(grub_debug_memalign) (const char *file, int line,
+ grub_size_t align, grub_size_t size);
+#endif /* MM_DEBUG && ! GRUB_UTIL */
+
+#endif /* ! GRUB_MM_H */
diff --git a/include/grub/mm_private.h b/include/grub/mm_private.h
new file mode 100644
index 0000000..c2c4cb1
--- /dev/null
+++ b/include/grub/mm_private.h
@@ -0,0 +1,64 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MM_PRIVATE_H
+#define GRUB_MM_PRIVATE_H 1
+
+#include <grub/mm.h>
+
+/* Magic words. */
+#define GRUB_MM_FREE_MAGIC 0x2d3c2808
+#define GRUB_MM_ALLOC_MAGIC 0x6db08fa4
+
+typedef struct grub_mm_header
+{
+ struct grub_mm_header *next;
+ grub_size_t size;
+ grub_size_t magic;
+#if GRUB_CPU_SIZEOF_VOID_P == 4
+ char padding[4];
+#elif GRUB_CPU_SIZEOF_VOID_P == 8
+ char padding[8];
+#else
+# error "unknown word size"
+#endif
+}
+*grub_mm_header_t;
+
+#if GRUB_CPU_SIZEOF_VOID_P == 4
+# define GRUB_MM_ALIGN_LOG2 4
+#elif GRUB_CPU_SIZEOF_VOID_P == 8
+# define GRUB_MM_ALIGN_LOG2 5
+#endif
+
+#define GRUB_MM_ALIGN (1 << GRUB_MM_ALIGN_LOG2)
+
+typedef struct grub_mm_region
+{
+ struct grub_mm_header *first;
+ struct grub_mm_region *next;
+ grub_size_t pre_size;
+ grub_size_t size;
+}
+*grub_mm_region_t;
+
+#ifndef GRUB_MACHINE_EMU
+extern grub_mm_region_t EXPORT_VAR (grub_mm_base);
+#endif
+
+#endif
diff --git a/include/grub/module_verifier.h b/include/grub/module_verifier.h
new file mode 100644
index 0000000..ba21c75
--- /dev/null
+++ b/include/grub/module_verifier.h
@@ -0,0 +1,20 @@
+#include <stdint.h>
+#include <stdlib.h>
+
+#include <grub/types.h>
+
+#define GRUB_MODULE_VERIFY_SUPPORTS_REL 1
+#define GRUB_MODULE_VERIFY_SUPPORTS_RELA 2
+
+struct grub_module_verifier_arch {
+ const char *name;
+ int voidp_sizeof;
+ int bigendian;
+ int machine;
+ int flags;
+ const int *supported_relocations;
+ const int *short_relocations;
+};
+
+void grub_module_verify64(const char * const filename, void *module_img, size_t module_size, const struct grub_module_verifier_arch *arch, const char **whitelist_empty);
+void grub_module_verify32(const char * const filename, void *module_img, size_t module_size, const struct grub_module_verifier_arch *arch, const char **whitelist_empty);
diff --git a/include/grub/msdos_partition.h b/include/grub/msdos_partition.h
new file mode 100644
index 0000000..fdc2904
--- /dev/null
+++ b/include/grub/msdos_partition.h
@@ -0,0 +1,127 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 1999,2000,2001,2002,2004,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_PC_PARTITION_HEADER
+#define GRUB_PC_PARTITION_HEADER 1
+
+#include <grub/symbol.h>
+#include <grub/types.h>
+#include <grub/err.h>
+#include <grub/disk.h>
+#include <grub/partition.h>
+
+/* The signature. */
+#define GRUB_PC_PARTITION_SIGNATURE 0xaa55
+
+/* This is not a flag actually, but used as if it were a flag. */
+#define GRUB_PC_PARTITION_TYPE_HIDDEN_FLAG 0x10
+
+/* DOS partition types. */
+#define GRUB_PC_PARTITION_TYPE_NONE 0
+#define GRUB_PC_PARTITION_TYPE_FAT12 1
+#define GRUB_PC_PARTITION_TYPE_FAT16_LT32M 4
+#define GRUB_PC_PARTITION_TYPE_EXTENDED 5
+#define GRUB_PC_PARTITION_TYPE_FAT16_GT32M 6
+#define GRUB_PC_PARTITION_TYPE_NTFS 7
+#define GRUB_PC_PARTITION_TYPE_FAT32 0xb
+#define GRUB_PC_PARTITION_TYPE_FAT32_LBA 0xc
+#define GRUB_PC_PARTITION_TYPE_FAT16_LBA 0xe
+#define GRUB_PC_PARTITION_TYPE_WIN95_EXTENDED 0xf
+#define GRUB_PC_PARTITION_TYPE_PLAN9 0x39
+#define GRUB_PC_PARTITION_TYPE_LDM 0x42
+#define GRUB_PC_PARTITION_TYPE_EZD 0x55
+#define GRUB_PC_PARTITION_TYPE_MINIX 0x80
+#define GRUB_PC_PARTITION_TYPE_LINUX_MINIX 0x81
+#define GRUB_PC_PARTITION_TYPE_LINUX_SWAP 0x82
+#define GRUB_PC_PARTITION_TYPE_EXT2FS 0x83
+#define GRUB_PC_PARTITION_TYPE_LINUX_EXTENDED 0x85
+#define GRUB_PC_PARTITION_TYPE_VSTAFS 0x9e
+#define GRUB_PC_PARTITION_TYPE_FREEBSD 0xa5
+#define GRUB_PC_PARTITION_TYPE_OPENBSD 0xa6
+#define GRUB_PC_PARTITION_TYPE_NETBSD 0xa9
+#define GRUB_PC_PARTITION_TYPE_HFS 0xaf
+#define GRUB_PC_PARTITION_TYPE_GPT_DISK 0xee
+#define GRUB_PC_PARTITION_TYPE_LINUX_RAID 0xfd
+
+/* The partition entry. */
+struct grub_msdos_partition_entry
+{
+ /* If active, 0x80, otherwise, 0x00. */
+ grub_uint8_t flag;
+
+ /* The head of the start. */
+ grub_uint8_t start_head;
+
+ /* (S | ((C >> 2) & 0xC0)) where S is the sector of the start and C
+ is the cylinder of the start. Note that S is counted from one. */
+ grub_uint8_t start_sector;
+
+ /* (C & 0xFF) where C is the cylinder of the start. */
+ grub_uint8_t start_cylinder;
+
+ /* The partition type. */
+ grub_uint8_t type;
+
+ /* The end versions of start_head, start_sector and start_cylinder,
+ respectively. */
+ grub_uint8_t end_head;
+ grub_uint8_t end_sector;
+ grub_uint8_t end_cylinder;
+
+ /* The start sector. Note that this is counted from zero. */
+ grub_uint32_t start;
+
+ /* The length in sector units. */
+ grub_uint32_t length;
+} GRUB_PACKED;
+
+/* The structure of MBR. */
+struct grub_msdos_partition_mbr
+{
+ /* The code area (actually, including BPB). */
+ grub_uint8_t code[446];
+
+ /* Four partition entries. */
+ struct grub_msdos_partition_entry entries[4];
+
+ /* The signature 0xaa55. */
+ grub_uint16_t signature;
+} GRUB_PACKED;
+
+
+
+static inline int
+grub_msdos_partition_is_empty (int type)
+{
+ return (type == GRUB_PC_PARTITION_TYPE_NONE);
+}
+
+static inline int
+grub_msdos_partition_is_extended (int type)
+{
+ return (type == GRUB_PC_PARTITION_TYPE_EXTENDED
+ || type == GRUB_PC_PARTITION_TYPE_WIN95_EXTENDED
+ || type == GRUB_PC_PARTITION_TYPE_LINUX_EXTENDED);
+}
+
+grub_err_t
+grub_partition_msdos_iterate (grub_disk_t disk,
+ grub_partition_iterate_hook_t hook,
+ void *hook_data);
+
+#endif /* ! GRUB_PC_PARTITION_HEADER */
diff --git a/include/grub/multiboot.h b/include/grub/multiboot.h
new file mode 100644
index 0000000..bd0a987
--- /dev/null
+++ b/include/grub/multiboot.h
@@ -0,0 +1,112 @@
+/* multiboot.h - multiboot header file with grub definitions. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2003,2007,2008,2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MULTIBOOT_HEADER
+#define GRUB_MULTIBOOT_HEADER 1
+
+#include <grub/file.h>
+
+#include <multiboot.h>
+
+#include <grub/types.h>
+#include <grub/err.h>
+
+typedef enum
+ {
+ GRUB_MULTIBOOT_QUIRKS_NONE = 0,
+ GRUB_MULTIBOOT_QUIRK_BAD_KLUDGE = 1,
+ GRUB_MULTIBOOT_QUIRK_MODULES_AFTER_KERNEL = 2
+ } grub_multiboot_quirks_t;
+extern grub_multiboot_quirks_t grub_multiboot_quirks;
+
+extern struct grub_relocator *grub_multiboot_relocator;
+
+void grub_multiboot (int argc, char *argv[]);
+void grub_module (int argc, char *argv[]);
+
+void grub_multiboot_set_accepts_video (int val);
+grub_err_t grub_multiboot_make_mbi (grub_uint32_t *target);
+void grub_multiboot_free_mbi (void);
+grub_err_t grub_multiboot_init_mbi (int argc, char *argv[]);
+grub_err_t grub_multiboot_add_module (grub_addr_t start, grub_size_t size,
+ int argc, char *argv[]);
+void grub_multiboot_set_bootdev (void);
+void
+grub_multiboot_add_elfsyms (grub_size_t num, grub_size_t entsize,
+ unsigned shndx, void *data);
+
+grub_uint32_t grub_multiboot_get_mmap_count (void);
+grub_err_t grub_multiboot_set_video_mode (void);
+
+/* FIXME: support coreboot as well. */
+#if defined (GRUB_MACHINE_PCBIOS)
+#define GRUB_MACHINE_HAS_VBE 1
+#else
+#define GRUB_MACHINE_HAS_VBE 0
+#endif
+
+#if defined (GRUB_MACHINE_PCBIOS) || defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_MULTIBOOT) || defined (GRUB_MACHINE_QEMU)
+#define GRUB_MACHINE_HAS_VGA_TEXT 1
+#else
+#define GRUB_MACHINE_HAS_VGA_TEXT 0
+#endif
+
+#if defined (GRUB_MACHINE_EFI) || defined (GRUB_MACHINE_PCBIOS) || defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_MULTIBOOT)
+#define GRUB_MACHINE_HAS_ACPI 1
+#else
+#define GRUB_MACHINE_HAS_ACPI 0
+#endif
+
+#define GRUB_MULTIBOOT_CONSOLE_EGA_TEXT 1
+#define GRUB_MULTIBOOT_CONSOLE_FRAMEBUFFER 2
+
+grub_err_t
+grub_multiboot_set_console (int console_type, int accepted_consoles,
+ int width, int height, int depth,
+ int console_required);
+grub_err_t
+grub_multiboot_load (grub_file_t file, const char *filename);
+
+struct mbi_load_data
+{
+ grub_file_t file;
+ const char *filename;
+ void *buffer;
+ unsigned int mbi_ver;
+ int relocatable;
+ grub_uint32_t min_addr;
+ grub_uint32_t max_addr;
+ grub_size_t align;
+ grub_uint32_t preference;
+ grub_uint32_t link_base_addr;
+ grub_uint32_t load_base_addr;
+ int avoid_efi_boot_services;
+};
+typedef struct mbi_load_data mbi_load_data_t;
+
+/* Load ELF32 or ELF64. */
+grub_err_t
+grub_multiboot_load_elf (mbi_load_data_t *mld);
+
+extern grub_size_t grub_multiboot_pure_size;
+extern grub_size_t grub_multiboot_alloc_mbi;
+extern grub_uint32_t grub_multiboot_payload_eip;
+
+
+#endif /* ! GRUB_MULTIBOOT_HEADER */
diff --git a/include/grub/multiboot2.h b/include/grub/multiboot2.h
new file mode 100644
index 0000000..502d34e
--- /dev/null
+++ b/include/grub/multiboot2.h
@@ -0,0 +1,104 @@
+/* multiboot.h - multiboot header file with grub definitions. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2003,2007,2008,2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MULTIBOOT2_HEADER
+#define GRUB_MULTIBOOT2_HEADER 1
+
+#include <grub/file.h>
+
+#include <multiboot2.h>
+
+#include <grub/types.h>
+#include <grub/err.h>
+
+extern struct grub_relocator *grub_multiboot2_relocator;
+
+void grub_multiboot2 (int argc, char *argv[]);
+void grub_module2 (int argc, char *argv[]);
+
+void grub_multiboot2_set_accepts_video (int val);
+grub_err_t grub_multiboot2_make_mbi (grub_uint32_t *target);
+void grub_multiboot2_free_mbi (void);
+grub_err_t grub_multiboot2_init_mbi (int argc, char *argv[]);
+grub_err_t grub_multiboot2_add_module (grub_addr_t start, grub_size_t size,
+ int argc, char *argv[]);
+void grub_multiboot2_set_bootdev (void);
+void
+grub_multiboot2_add_elfsyms (grub_size_t num, grub_size_t entsize,
+ unsigned shndx, void *data);
+
+grub_uint32_t grub_multiboot2_get_mmap_count (void);
+grub_err_t grub_multiboot2_set_video_mode (void);
+
+/* FIXME: support coreboot as well. */
+#if defined (GRUB_MACHINE_PCBIOS)
+#define GRUB_MACHINE_HAS_VBE 1
+#else
+#define GRUB_MACHINE_HAS_VBE 0
+#endif
+
+#if defined (GRUB_MACHINE_PCBIOS) || defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_MULTIBOOT) || defined (GRUB_MACHINE_QEMU)
+#define GRUB_MACHINE_HAS_VGA_TEXT 1
+#else
+#define GRUB_MACHINE_HAS_VGA_TEXT 0
+#endif
+
+#if defined (GRUB_MACHINE_EFI) || defined (GRUB_MACHINE_PCBIOS) || defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_MULTIBOOT)
+#define GRUB_MACHINE_HAS_ACPI 1
+#else
+#define GRUB_MACHINE_HAS_ACPI 0
+#endif
+
+#define GRUB_MULTIBOOT2_CONSOLE_EGA_TEXT 1
+#define GRUB_MULTIBOOT2_CONSOLE_FRAMEBUFFER 2
+
+grub_err_t
+grub_multiboot2_set_console (int console_type, int accepted_consoles,
+ int width, int height, int depth,
+ int console_required);
+grub_err_t
+grub_multiboot2_load (grub_file_t file, const char *filename);
+
+struct mbi_load_data
+{
+ grub_file_t file;
+ const char *filename;
+ void *buffer;
+ unsigned int mbi_ver;
+ int relocatable;
+ grub_uint32_t min_addr;
+ grub_uint32_t max_addr;
+ grub_size_t align;
+ grub_uint32_t preference;
+ grub_uint32_t link_base_addr;
+ grub_uint32_t load_base_addr;
+ int avoid_efi_boot_services;
+};
+typedef struct mbi_load_data mbi_load_data_t;
+
+/* Load ELF32 or ELF64. */
+grub_err_t
+grub_multiboot2_load_elf (mbi_load_data_t *mld);
+
+extern grub_size_t grub_multiboot2_pure_size;
+extern grub_size_t grub_multiboot2_alloc_mbi;
+extern grub_uint32_t grub_multiboot2_payload_eip;
+
+
+#endif /* ! GRUB_MULTIBOOT_HEADER */
diff --git a/include/grub/multiboot_loader.h b/include/grub/multiboot_loader.h
new file mode 100644
index 0000000..bf1c130
--- /dev/null
+++ b/include/grub/multiboot_loader.h
@@ -0,0 +1,28 @@
+/* multiboot_loader.h - multiboot loader header file. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2005,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef GRUB_MULTIBOOT_LOADER_HEADER
+#define GRUB_MULTIBOOT_LOADER_HEADER 1
+
+/* Provided by the core ("rescue mode"). */
+void grub_rescue_cmd_multiboot_loader (int argc, char *argv[]);
+void grub_rescue_cmd_module_loader (int argc, char *argv[]);
+
+#endif /* ! GRUB_MULTIBOOT_LOADER_HEADER */
diff --git a/include/grub/net.h b/include/grub/net.h
new file mode 100644
index 0000000..7ae4b6b
--- /dev/null
+++ b/include/grub/net.h
@@ -0,0 +1,583 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010,2011 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_NET_HEADER
+#define GRUB_NET_HEADER 1
+
+#include <grub/types.h>
+#include <grub/err.h>
+#include <grub/list.h>
+#include <grub/fs.h>
+#include <grub/file.h>
+#include <grub/mm.h>
+#include <grub/net/netbuff.h>
+
+enum
+ {
+ GRUB_NET_MAX_LINK_HEADER_SIZE = 64,
+ GRUB_NET_UDP_HEADER_SIZE = 8,
+ GRUB_NET_TCP_HEADER_SIZE = 20,
+ GRUB_NET_OUR_IPV4_HEADER_SIZE = 20,
+ GRUB_NET_OUR_IPV6_HEADER_SIZE = 40,
+ GRUB_NET_OUR_MAX_IP_HEADER_SIZE = 40,
+ GRUB_NET_TCP_RESERVE_SIZE = GRUB_NET_TCP_HEADER_SIZE
+ + GRUB_NET_OUR_IPV4_HEADER_SIZE
+ + GRUB_NET_MAX_LINK_HEADER_SIZE
+ };
+
+typedef enum grub_link_level_protocol_id
+{
+ GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET
+} grub_link_level_protocol_id_t;
+
+typedef struct grub_net_link_level_address
+{
+ grub_link_level_protocol_id_t type;
+ union
+ {
+ grub_uint8_t mac[6];
+ };
+} grub_net_link_level_address_t;
+
+typedef enum grub_net_interface_flags
+ {
+ GRUB_NET_INTERFACE_HWADDRESS_IMMUTABLE = 1,
+ GRUB_NET_INTERFACE_ADDRESS_IMMUTABLE = 2,
+ GRUB_NET_INTERFACE_PERMANENT = 4
+ } grub_net_interface_flags_t;
+
+typedef enum grub_net_card_flags
+ {
+ GRUB_NET_CARD_HWADDRESS_IMMUTABLE = 1,
+ GRUB_NET_CARD_NO_MANUAL_INTERFACES = 2
+ } grub_net_card_flags_t;
+
+struct grub_net_card;
+
+struct grub_net_card_driver
+{
+ struct grub_net_card_driver *next;
+ struct grub_net_card_driver **prev;
+ const char *name;
+ grub_err_t (*open) (struct grub_net_card *dev);
+ void (*close) (struct grub_net_card *dev);
+ grub_err_t (*send) (struct grub_net_card *dev,
+ struct grub_net_buff *buf);
+ struct grub_net_buff * (*recv) (struct grub_net_card *dev);
+};
+
+typedef struct grub_net_packet
+{
+ struct grub_net_packet *next;
+ struct grub_net_packet *prev;
+ struct grub_net_packets *up;
+ struct grub_net_buff *nb;
+} grub_net_packet_t;
+
+typedef struct grub_net_packets
+{
+ grub_net_packet_t *first;
+ grub_net_packet_t *last;
+ grub_size_t count;
+} grub_net_packets_t;
+
+#ifdef GRUB_MACHINE_EFI
+#include <grub/efi/api.h>
+#endif
+
+struct grub_net_slaac_mac_list
+{
+ struct grub_net_slaac_mac_list *next;
+ struct grub_net_slaac_mac_list **prev;
+ grub_net_link_level_address_t address;
+ int slaac_counter;
+ char *name;
+};
+
+struct grub_net_link_layer_entry;
+
+struct grub_net_card
+{
+ struct grub_net_card *next;
+ struct grub_net_card **prev;
+ const char *name;
+ struct grub_net_card_driver *driver;
+ grub_net_link_level_address_t default_address;
+ grub_net_card_flags_t flags;
+ int num_ifaces;
+ int opened;
+ unsigned idle_poll_delay_ms;
+ grub_uint64_t last_poll;
+ grub_size_t mtu;
+ struct grub_net_slaac_mac_list *slaac_list;
+ grub_ssize_t new_ll_entry;
+ struct grub_net_link_layer_entry *link_layer_table;
+ void *txbuf;
+ void *rcvbuf;
+ grub_size_t rcvbufsize;
+ grub_size_t txbufsize;
+ int txbusy;
+ union
+ {
+#ifdef GRUB_MACHINE_EFI
+ struct
+ {
+ struct grub_efi_simple_network *efi_net;
+ grub_efi_handle_t efi_handle;
+ grub_size_t last_pkt_size;
+ };
+#endif
+ void *data;
+ int data_num;
+ };
+};
+
+struct grub_net_network_level_interface;
+
+typedef enum grub_network_level_protocol_id
+{
+ GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV,
+ GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4,
+ GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6
+} grub_network_level_protocol_id_t;
+
+typedef enum
+{
+ DNS_OPTION_IPV4,
+ DNS_OPTION_IPV6,
+ DNS_OPTION_PREFER_IPV4,
+ DNS_OPTION_PREFER_IPV6
+} grub_dns_option_t;
+
+typedef struct grub_net_network_level_address
+{
+ grub_network_level_protocol_id_t type;
+ union
+ {
+ grub_uint32_t ipv4;
+ grub_uint64_t ipv6[2];
+ };
+ grub_dns_option_t option;
+} grub_net_network_level_address_t;
+
+typedef struct grub_net_network_level_netaddress
+{
+ grub_network_level_protocol_id_t type;
+ union
+ {
+ struct {
+ grub_uint32_t base;
+ int masksize;
+ } ipv4;
+ struct {
+ grub_uint64_t base[2];
+ int masksize;
+ } ipv6;
+ };
+} grub_net_network_level_netaddress_t;
+
+struct grub_net_route
+{
+ struct grub_net_route *next;
+ struct grub_net_route **prev;
+ grub_net_network_level_netaddress_t target;
+ char *name;
+ struct grub_net_network_level_protocol *prot;
+ int is_gateway;
+ struct grub_net_network_level_interface *interface;
+ grub_net_network_level_address_t gw;
+};
+
+#define FOR_PACKETS(cont,var) for (var = (cont).first; var; var = var->next)
+
+static inline grub_err_t
+grub_net_put_packet (grub_net_packets_t *pkts, struct grub_net_buff *nb)
+{
+ struct grub_net_packet *n;
+
+ n = grub_malloc (sizeof (*n));
+ if (!n)
+ return grub_errno;
+
+ n->nb = nb;
+ n->next = NULL;
+ n->prev = NULL;
+ n->up = pkts;
+ if (pkts->first)
+ {
+ pkts->last->next = n;
+ pkts->last = n;
+ n->prev = pkts->last;
+ }
+ else
+ pkts->first = pkts->last = n;
+
+ pkts->count++;
+
+ return GRUB_ERR_NONE;
+}
+
+static inline void
+grub_net_remove_packet (grub_net_packet_t *pkt)
+{
+ pkt->up->count--;
+
+ if (pkt->prev)
+ pkt->prev->next = pkt->next;
+ else
+ pkt->up->first = pkt->next;
+ if (pkt->next)
+ pkt->next->prev = pkt->prev;
+ else
+ pkt->up->last = pkt->prev;
+ grub_free (pkt);
+}
+
+typedef struct grub_net_app_protocol *grub_net_app_level_t;
+
+typedef struct grub_net_socket *grub_net_socket_t;
+
+struct grub_net_app_protocol
+{
+ struct grub_net_app_protocol *next;
+ struct grub_net_app_protocol **prev;
+ const char *name;
+ grub_err_t (*dir) (grub_device_t device, const char *path,
+ int (*hook) (const char *filename,
+ const struct grub_dirhook_info *info));
+ grub_err_t (*open) (struct grub_file *file, const char *filename);
+ grub_err_t (*seek) (struct grub_file *file, grub_off_t off);
+ grub_err_t (*close) (struct grub_file *file);
+ grub_err_t (*packets_pulled) (struct grub_file *file);
+};
+
+typedef struct grub_net
+{
+ char *server;
+ char *name;
+ grub_net_app_level_t protocol;
+ grub_net_packets_t packs;
+ grub_off_t offset;
+ grub_fs_t fs;
+ int eof;
+ int stall;
+} *grub_net_t;
+
+extern grub_net_t (*EXPORT_VAR (grub_net_open)) (const char *name);
+
+struct grub_net_network_level_interface
+{
+ struct grub_net_network_level_interface *next;
+ struct grub_net_network_level_interface **prev;
+ char *name;
+ struct grub_net_card *card;
+ grub_net_network_level_address_t address;
+ grub_net_link_level_address_t hwaddress;
+ grub_net_interface_flags_t flags;
+ struct grub_net_bootp_packet *dhcp_ack;
+ grub_size_t dhcp_acklen;
+ grub_uint16_t vlantag;
+ grub_uint32_t xid; /* DHCPv4 transaction id */
+ grub_uint32_t srv_id; /* DHCPv4 server_identifier */
+ grub_uint32_t my_ip; /* DHCPv4 offered IP address */
+ unsigned dhcp_tmo_left; /* DHCPv4 running retransmission timeout */
+ unsigned dhcp_tmo; /* DHCPv4 current retransmission timeout */
+ void *data;
+};
+
+struct grub_net_session;
+
+struct grub_net_session_level_protocol
+{
+ void (*close) (struct grub_net_session *session);
+ grub_ssize_t (*recv) (struct grub_net_session *session, void *buf,
+ grub_size_t size);
+ grub_err_t (*send) (struct grub_net_session *session, void *buf,
+ grub_size_t size);
+};
+
+struct grub_net_session
+{
+ struct grub_net_session_level_protocol *protocol;
+ void *data;
+};
+
+static inline void
+grub_net_session_close (struct grub_net_session *session)
+{
+ session->protocol->close (session);
+}
+
+static inline grub_err_t
+grub_net_session_send (struct grub_net_session *session, void *buf,
+ grub_size_t size)
+{
+ return session->protocol->send (session, buf, size);
+}
+
+static inline grub_ssize_t
+grub_net_session_recv (struct grub_net_session *session, void *buf,
+ grub_size_t size)
+{
+ return session->protocol->recv (session, buf, size);
+}
+
+struct grub_net_network_level_interface *
+grub_net_add_addr (const char *name,
+ struct grub_net_card *card,
+ const grub_net_network_level_address_t *addr,
+ const grub_net_link_level_address_t *hwaddress,
+ grub_net_interface_flags_t flags);
+
+extern struct grub_net_network_level_interface *grub_net_network_level_interfaces;
+#define FOR_NET_NETWORK_LEVEL_INTERFACES(var) for (var = grub_net_network_level_interfaces; var; var = var->next)
+#define FOR_NET_NETWORK_LEVEL_INTERFACES_SAFE(var,next) for (var = grub_net_network_level_interfaces, next = (var ? var->next : 0); var; var = next, next = (var ? var->next : 0))
+
+
+extern grub_net_app_level_t grub_net_app_level_list;
+
+#ifndef GRUB_LST_GENERATOR
+static inline void
+grub_net_app_level_register (grub_net_app_level_t proto)
+{
+ grub_list_push (GRUB_AS_LIST_P (&grub_net_app_level_list),
+ GRUB_AS_LIST (proto));
+}
+#endif
+
+static inline void
+grub_net_app_level_unregister (grub_net_app_level_t proto)
+{
+ grub_list_remove (GRUB_AS_LIST (proto));
+}
+
+#define FOR_NET_APP_LEVEL(var) FOR_LIST_ELEMENTS((var), \
+ (grub_net_app_level_list))
+
+extern struct grub_net_card *grub_net_cards;
+
+static inline void
+grub_net_card_register (struct grub_net_card *card)
+{
+ grub_list_push (GRUB_AS_LIST_P (&grub_net_cards),
+ GRUB_AS_LIST (card));
+}
+
+void
+grub_net_card_unregister (struct grub_net_card *card);
+
+#define FOR_NET_CARDS(var) for (var = grub_net_cards; var; var = var->next)
+#define FOR_NET_CARDS_SAFE(var, next) for (var = grub_net_cards, next = (var ? var->next : 0); var; var = next, next = (var ? var->next : 0))
+
+
+extern struct grub_net_route *grub_net_routes;
+
+static inline void
+grub_net_route_register (struct grub_net_route *route)
+{
+ grub_list_push (GRUB_AS_LIST_P (&grub_net_routes),
+ GRUB_AS_LIST (route));
+}
+
+#define FOR_NET_ROUTES(var) for (var = grub_net_routes; var; var = var->next)
+struct grub_net_session *
+grub_net_open_tcp (char *address, grub_uint16_t port);
+
+grub_err_t
+grub_net_resolve_address (const char *name,
+ grub_net_network_level_address_t *addr);
+
+grub_err_t
+grub_net_resolve_net_address (const char *name,
+ grub_net_network_level_netaddress_t *addr);
+
+grub_err_t
+grub_net_route_address (grub_net_network_level_address_t addr,
+ grub_net_network_level_address_t *gateway,
+ struct grub_net_network_level_interface **interf);
+
+
+grub_err_t
+grub_net_add_route (const char *name,
+ grub_net_network_level_netaddress_t target,
+ struct grub_net_network_level_interface *inter);
+
+grub_err_t
+grub_net_add_route_gw (const char *name,
+ grub_net_network_level_netaddress_t target,
+ grub_net_network_level_address_t gw,
+ struct grub_net_network_level_interface *inter);
+
+
+#define GRUB_NET_BOOTP_MAC_ADDR_LEN 16
+
+typedef grub_uint8_t grub_net_bootp_mac_addr_t[GRUB_NET_BOOTP_MAC_ADDR_LEN];
+
+struct grub_net_bootp_packet
+{
+ grub_uint8_t opcode;
+ grub_uint8_t hw_type; /* hardware type. */
+ grub_uint8_t hw_len; /* hardware addr len. */
+ grub_uint8_t gate_hops; /* zero it. */
+ grub_uint32_t ident; /* random number chosen by client. */
+ grub_uint16_t seconds; /* seconds since did initial bootstrap. */
+ grub_uint16_t flags;
+ grub_uint32_t client_ip;
+ grub_uint32_t your_ip;
+ grub_uint32_t server_ip;
+ grub_uint32_t gateway_ip;
+ grub_net_bootp_mac_addr_t mac_addr;
+ char server_name[64];
+ char boot_file[128];
+ grub_uint8_t vendor[0];
+} GRUB_PACKED;
+
+#define GRUB_NET_BOOTP_RFC1048_MAGIC_0 0x63
+#define GRUB_NET_BOOTP_RFC1048_MAGIC_1 0x82
+#define GRUB_NET_BOOTP_RFC1048_MAGIC_2 0x53
+#define GRUB_NET_BOOTP_RFC1048_MAGIC_3 0x63
+
+enum
+ {
+ GRUB_NET_BOOTP_PAD = 0,
+ GRUB_NET_BOOTP_NETMASK = 1,
+ GRUB_NET_BOOTP_ROUTER = 3,
+ GRUB_NET_BOOTP_DNS = 6,
+ GRUB_NET_BOOTP_HOSTNAME = 12,
+ GRUB_NET_BOOTP_DOMAIN = 15,
+ GRUB_NET_BOOTP_ROOT_PATH = 17,
+ GRUB_NET_BOOTP_EXTENSIONS_PATH = 18,
+ GRUB_NET_DHCP_REQUESTED_IP_ADDRESS = 50,
+ GRUB_NET_DHCP_OVERLOAD = 52,
+ GRUB_NET_DHCP_MESSAGE_TYPE = 53,
+ GRUB_NET_DHCP_SERVER_IDENTIFIER = 54,
+ GRUB_NET_DHCP_PARAMETER_REQUEST_LIST = 55,
+ GRUB_NET_BOOTP_CLIENT_ID = 61,
+ GRUB_NET_DHCP_TFTP_SERVER_NAME = 66,
+ GRUB_NET_DHCP_BOOTFILE_NAME = 67,
+ GRUB_NET_BOOTP_CLIENT_UUID = 97,
+ GRUB_NET_BOOTP_END = 255
+ };
+
+struct grub_net_network_level_interface *
+grub_net_configure_by_dhcp_ack (const char *name,
+ struct grub_net_card *card,
+ grub_net_interface_flags_t flags,
+ const struct grub_net_bootp_packet *bp,
+ grub_size_t size,
+ int is_def, char **device, char **path);
+
+grub_err_t
+grub_net_add_ipv4_local (struct grub_net_network_level_interface *inf,
+ int mask);
+
+void
+grub_net_process_dhcp (struct grub_net_buff *nb,
+ struct grub_net_network_level_interface *iface);
+
+int
+grub_net_hwaddr_cmp (const grub_net_link_level_address_t *a,
+ const grub_net_link_level_address_t *b);
+int
+grub_net_addr_cmp (const grub_net_network_level_address_t *a,
+ const grub_net_network_level_address_t *b);
+
+
+/*
+ Currently supported adresses:
+ IPv4: XXX.XXX.XXX.XXX
+ IPv6: XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX
+ */
+#define GRUB_NET_MAX_STR_ADDR_LEN sizeof ("XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX")
+
+/*
+ Currently suppoerted adresses:
+ ethernet: XX:XX:XX:XX:XX:XX
+ */
+
+#define GRUB_NET_MAX_STR_HWADDR_LEN (sizeof ("XX:XX:XX:XX:XX:XX"))
+
+void
+grub_net_addr_to_str (const grub_net_network_level_address_t *target,
+ char *buf);
+void
+grub_net_hwaddr_to_str (const grub_net_link_level_address_t *addr, char *str);
+
+grub_err_t
+grub_env_set_net_property (const char *intername, const char *suffix,
+ const char *value, grub_size_t len);
+
+void
+grub_net_poll_cards (unsigned time, int *stop_condition);
+
+void grub_bootp_init (void);
+void grub_bootp_fini (void);
+
+void grub_dns_init (void);
+void grub_dns_fini (void);
+
+static inline void
+grub_net_network_level_interface_unregister (struct grub_net_network_level_interface *inter)
+{
+ inter->card->num_ifaces--;
+ *inter->prev = inter->next;
+ if (inter->next)
+ inter->next->prev = inter->prev;
+ inter->next = 0;
+ inter->prev = 0;
+}
+
+void
+grub_net_tcp_retransmit (void);
+
+void
+grub_net_link_layer_add_address (struct grub_net_card *card,
+ const grub_net_network_level_address_t *nl,
+ const grub_net_link_level_address_t *ll,
+ int override);
+int
+grub_net_link_layer_resolve_check (struct grub_net_network_level_interface *inf,
+ const grub_net_network_level_address_t *proto_addr);
+grub_err_t
+grub_net_link_layer_resolve (struct grub_net_network_level_interface *inf,
+ const grub_net_network_level_address_t *proto_addr,
+ grub_net_link_level_address_t *hw_addr);
+grub_err_t
+grub_net_dns_lookup (const char *name,
+ const struct grub_net_network_level_address *servers,
+ grub_size_t n_servers,
+ grub_size_t *naddresses,
+ struct grub_net_network_level_address **addresses,
+ int cache);
+grub_err_t
+grub_net_add_dns_server (const struct grub_net_network_level_address *s);
+void
+grub_net_remove_dns_server (const struct grub_net_network_level_address *s);
+
+grub_err_t
+grub_net_search_config_file (char *config);
+
+extern char *grub_net_default_server;
+
+#define GRUB_NET_TRIES 40
+#define GRUB_NET_INTERVAL 400
+#define GRUB_NET_INTERVAL_ADDITION 20
+
+#define VLANTAG_IDENTIFIER 0x8100
+
+#endif /* ! GRUB_NET_HEADER */
diff --git a/include/grub/net/arp.h b/include/grub/net/arp.h
new file mode 100644
index 0000000..8d9d081
--- /dev/null
+++ b/include/grub/net/arp.h
@@ -0,0 +1,32 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010,2011 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_NET_ARP_HEADER
+#define GRUB_NET_ARP_HEADER 1
+#include <grub/misc.h>
+#include <grub/net.h>
+
+extern grub_err_t grub_net_arp_receive (struct grub_net_buff *nb,
+ struct grub_net_card *card,
+ grub_uint16_t *vlantag);
+
+grub_err_t
+grub_net_arp_send_request (struct grub_net_network_level_interface *inf,
+ const grub_net_network_level_address_t *proto_addr);
+
+#endif
diff --git a/include/grub/net/ethernet.h b/include/grub/net/ethernet.h
new file mode 100644
index 0000000..23a935e
--- /dev/null
+++ b/include/grub/net/ethernet.h
@@ -0,0 +1,41 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010,2011 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_NET_ETHERNET_HEADER
+#define GRUB_NET_ETHERNET_HEADER 1
+#include <grub/types.h>
+#include <grub/net.h>
+
+/* IANA Ethertype */
+typedef enum
+ {
+ GRUB_NET_ETHERTYPE_IP = 0x0800,
+ GRUB_NET_ETHERTYPE_ARP = 0x0806,
+ GRUB_NET_ETHERTYPE_IP6 = 0x86DD,
+ } grub_net_ethertype_t;
+
+grub_err_t
+send_ethernet_packet (struct grub_net_network_level_interface *inf,
+ struct grub_net_buff *nb,
+ grub_net_link_level_address_t target_addr,
+ grub_net_ethertype_t ethertype);
+grub_err_t
+grub_net_recv_ethernet_packet (struct grub_net_buff *nb,
+ struct grub_net_card *card);
+
+#endif
diff --git a/include/grub/net/ip.h b/include/grub/net/ip.h
new file mode 100644
index 0000000..ab9d68f
--- /dev/null
+++ b/include/grub/net/ip.h
@@ -0,0 +1,98 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010,2011 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_NET_IP_HEADER
+#define GRUB_NET_IP_HEADER 1
+#include <grub/misc.h>
+#include <grub/net.h>
+
+typedef enum grub_net_ip_protocol
+ {
+ GRUB_NET_IP_ICMP = 1,
+ GRUB_NET_IP_TCP = 6,
+ GRUB_NET_IP_UDP = 17,
+ GRUB_NET_IP_ICMPV6 = 58
+ } grub_net_ip_protocol_t;
+#define GRUB_NET_IP_BROADCAST 0xFFFFFFFF
+
+static inline grub_uint64_t
+grub_net_ipv6_get_id (const grub_net_link_level_address_t *addr)
+{
+ return grub_cpu_to_be64 (((grub_uint64_t) (addr->mac[0] ^ 2) << 56)
+ | ((grub_uint64_t) addr->mac[1] << 48)
+ | ((grub_uint64_t) addr->mac[2] << 40)
+ | 0xfffe000000ULL
+ | ((grub_uint64_t) addr->mac[3] << 16)
+ | ((grub_uint64_t) addr->mac[4] << 8)
+ | ((grub_uint64_t) addr->mac[5]));
+}
+
+grub_uint16_t grub_net_ip_chksum(void *ipv, grub_size_t len);
+
+grub_err_t
+grub_net_recv_ip_packets (struct grub_net_buff *nb,
+ struct grub_net_card *card,
+ const grub_net_link_level_address_t *hwaddress,
+ const grub_net_link_level_address_t *src_hwaddress,
+ grub_uint16_t *vlantag);
+
+grub_err_t
+grub_net_send_ip_packet (struct grub_net_network_level_interface *inf,
+ const grub_net_network_level_address_t *target,
+ const grub_net_link_level_address_t *ll_target_addr,
+ struct grub_net_buff *nb,
+ grub_net_ip_protocol_t proto);
+
+grub_err_t
+grub_net_recv_icmp_packet (struct grub_net_buff *nb,
+ struct grub_net_network_level_interface *inf,
+ const grub_net_link_level_address_t *ll_src,
+ const grub_net_network_level_address_t *src);
+grub_err_t
+grub_net_recv_icmp6_packet (struct grub_net_buff *nb,
+ struct grub_net_card *card,
+ struct grub_net_network_level_interface *inf,
+ const grub_net_link_level_address_t *ll_src,
+ const grub_net_network_level_address_t *source,
+ const grub_net_network_level_address_t *dest,
+ grub_uint8_t ttl);
+grub_err_t
+grub_net_recv_udp_packet (struct grub_net_buff *nb,
+ struct grub_net_network_level_interface *inf,
+ const grub_net_network_level_address_t *src);
+grub_err_t
+grub_net_recv_tcp_packet (struct grub_net_buff *nb,
+ struct grub_net_network_level_interface *inf,
+ const grub_net_network_level_address_t *source);
+
+grub_uint16_t
+grub_net_ip_transport_checksum (struct grub_net_buff *nb,
+ grub_uint16_t proto,
+ const grub_net_network_level_address_t *src,
+ const grub_net_network_level_address_t *dst);
+
+struct grub_net_network_level_interface *
+grub_net_ipv6_get_link_local (struct grub_net_card *card,
+ const grub_net_link_level_address_t *hwaddr);
+grub_err_t
+grub_net_icmp6_send_request (struct grub_net_network_level_interface *inf,
+ const grub_net_network_level_address_t *proto_addr);
+
+grub_err_t
+grub_net_icmp6_send_router_solicit (struct grub_net_network_level_interface *inf);
+#endif
diff --git a/include/grub/net/netbuff.h b/include/grub/net/netbuff.h
new file mode 100644
index 0000000..1177c12
--- /dev/null
+++ b/include/grub/net/netbuff.h
@@ -0,0 +1,31 @@
+#ifndef GRUB_NETBUFF_HEADER
+#define GRUB_NETBUFF_HEADER
+
+#include <grub/misc.h>
+
+#define NETBUFF_ALIGN 2048
+#define NETBUFFMINLEN 64
+
+struct grub_net_buff
+{
+ /* Pointer to the start of the buffer. */
+ grub_uint8_t *head;
+ /* Pointer to the data. */
+ grub_uint8_t *data;
+ /* Pointer to the tail. */
+ grub_uint8_t *tail;
+ /* Pointer to the end of the buffer. */
+ grub_uint8_t *end;
+};
+
+grub_err_t grub_netbuff_put (struct grub_net_buff *net_buff, grub_size_t len);
+grub_err_t grub_netbuff_unput (struct grub_net_buff *net_buff, grub_size_t len);
+grub_err_t grub_netbuff_push (struct grub_net_buff *net_buff, grub_size_t len);
+grub_err_t grub_netbuff_pull (struct grub_net_buff *net_buff, grub_size_t len);
+grub_err_t grub_netbuff_reserve (struct grub_net_buff *net_buff, grub_size_t len);
+grub_err_t grub_netbuff_clear (struct grub_net_buff *net_buff);
+struct grub_net_buff * grub_netbuff_alloc (grub_size_t len);
+struct grub_net_buff * grub_netbuff_make_pkt (grub_size_t len);
+void grub_netbuff_free (struct grub_net_buff *net_buff);
+
+#endif
diff --git a/include/grub/net/tcp.h b/include/grub/net/tcp.h
new file mode 100644
index 0000000..5a9305a
--- /dev/null
+++ b/include/grub/net/tcp.h
@@ -0,0 +1,85 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010,2011 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_NET_TCP_HEADER
+#define GRUB_NET_TCP_HEADER 1
+#include <grub/types.h>
+#include <grub/net.h>
+
+struct grub_net_tcp_socket;
+typedef struct grub_net_tcp_socket *grub_net_tcp_socket_t;
+
+struct grub_net_tcp_listen;
+typedef struct grub_net_tcp_listen *grub_net_tcp_listen_t;
+
+grub_net_tcp_socket_t
+grub_net_tcp_open (char *server,
+ grub_uint16_t out_port,
+ grub_err_t (*recv_hook) (grub_net_tcp_socket_t sock,
+ struct grub_net_buff *nb,
+ void *data),
+ void (*error_hook) (grub_net_tcp_socket_t sock,
+ void *data),
+ void (*fin_hook) (grub_net_tcp_socket_t sock,
+ void *data),
+ void *hook_data);
+
+grub_net_tcp_listen_t
+grub_net_tcp_listen (grub_uint16_t port,
+ const struct grub_net_network_level_interface *inf,
+ grub_err_t (*listen_hook) (grub_net_tcp_listen_t listen,
+ grub_net_tcp_socket_t sock,
+ void *data),
+ void *hook_data);
+
+void
+grub_net_tcp_stop_listen (grub_net_tcp_listen_t listen);
+
+grub_err_t
+grub_net_send_tcp_packet (const grub_net_tcp_socket_t socket,
+ struct grub_net_buff *nb,
+ int push);
+
+enum
+ {
+ GRUB_NET_TCP_CONTINUE_RECEIVING,
+ GRUB_NET_TCP_DISCARD,
+ GRUB_NET_TCP_ABORT
+ };
+
+void
+grub_net_tcp_close (grub_net_tcp_socket_t sock, int discard_received);
+
+grub_err_t
+grub_net_tcp_accept (grub_net_tcp_socket_t sock,
+ grub_err_t (*recv_hook) (grub_net_tcp_socket_t sock,
+ struct grub_net_buff *nb,
+ void *data),
+ void (*error_hook) (grub_net_tcp_socket_t sock,
+ void *data),
+ void (*fin_hook) (grub_net_tcp_socket_t sock,
+ void *data),
+ void *hook_data);
+
+void
+grub_net_tcp_stall (grub_net_tcp_socket_t sock);
+
+void
+grub_net_tcp_unstall (grub_net_tcp_socket_t sock);
+
+#endif
diff --git a/include/grub/net/udp.h b/include/grub/net/udp.h
new file mode 100644
index 0000000..17f38cf
--- /dev/null
+++ b/include/grub/net/udp.h
@@ -0,0 +1,51 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010,2011 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_NET_UDP_HEADER
+#define GRUB_NET_UDP_HEADER 1
+#include <grub/types.h>
+#include <grub/net.h>
+
+struct udphdr
+{
+ grub_uint16_t src;
+ grub_uint16_t dst;
+ grub_uint16_t len;
+ grub_uint16_t chksum;
+} GRUB_PACKED;
+
+struct grub_net_udp_socket;
+typedef struct grub_net_udp_socket *grub_net_udp_socket_t;
+
+grub_net_udp_socket_t
+grub_net_udp_open (grub_net_network_level_address_t addr,
+ grub_uint16_t out_port,
+ grub_err_t (*recv_hook) (grub_net_udp_socket_t sock,
+ struct grub_net_buff *nb,
+ void *data),
+ void *recv_hook_data);
+
+void
+grub_net_udp_close (grub_net_udp_socket_t sock);
+
+grub_err_t
+grub_net_send_udp_packet (const grub_net_udp_socket_t socket,
+ struct grub_net_buff *nb);
+
+
+#endif
diff --git a/include/grub/normal.h b/include/grub/normal.h
new file mode 100644
index 0000000..218cbab
--- /dev/null
+++ b/include/grub/normal.h
@@ -0,0 +1,177 @@
+/* normal.h - prototypes for the normal mode */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2003,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_NORMAL_HEADER
+#define GRUB_NORMAL_HEADER 1
+
+#include <grub/term.h>
+#include <grub/symbol.h>
+#include <grub/err.h>
+#include <grub/env.h>
+#include <grub/menu.h>
+#include <grub/command.h>
+#include <grub/file.h>
+
+/* The standard left and right margin for some messages. */
+#define STANDARD_MARGIN 6
+
+/* The type of a completion item. */
+enum grub_completion_type
+ {
+ GRUB_COMPLETION_TYPE_COMMAND,
+ GRUB_COMPLETION_TYPE_DEVICE,
+ GRUB_COMPLETION_TYPE_PARTITION,
+ GRUB_COMPLETION_TYPE_FILE,
+ GRUB_COMPLETION_TYPE_ARGUMENT
+ };
+typedef enum grub_completion_type grub_completion_type_t;
+
+extern struct grub_menu_viewer grub_normal_text_menu_viewer;
+extern int grub_normal_exit_level;
+
+/* Defined in `main.c'. */
+void grub_enter_normal_mode (const char *config);
+void grub_normal_execute (const char *config, int nested, int batch);
+struct grub_term_screen_geometry
+{
+ /* The number of entries shown at a time. */
+ int num_entries;
+ int first_entry_y;
+ int first_entry_x;
+ int entry_width;
+ int timeout_y;
+ int timeout_lines;
+ int border;
+ int right_margin;
+};
+
+void grub_menu_init_page (int nested, int edit,
+ struct grub_term_screen_geometry *geo,
+ struct grub_term_output *term);
+void grub_normal_init_page (struct grub_term_output *term, int y);
+char *grub_file_getline (grub_file_t file);
+void grub_cmdline_run (int nested, int force_auth);
+
+/* Defined in `cmdline.c'. */
+char *grub_cmdline_get (const char *prompt);
+grub_err_t grub_set_history (int newsize);
+
+/* Defined in `completion.c'. */
+char *grub_normal_do_completion (char *buf, int *restore,
+ void (*hook) (const char *item, grub_completion_type_t type, int count));
+
+/* Defined in `misc.c'. */
+grub_err_t grub_normal_print_device_info (const char *name);
+
+/* Defined in `color.c'. */
+char *grub_env_write_color_normal (struct grub_env_var *var, const char *val);
+char *grub_env_write_color_highlight (struct grub_env_var *var, const char *val);
+int grub_parse_color_name_pair (grub_uint8_t *ret, const char *name);
+
+/* Defined in `menu_text.c'. */
+void grub_wait_after_message (void);
+void
+grub_print_ucs4 (const grub_uint32_t * str,
+ const grub_uint32_t * last_position,
+ int margin_left, int margin_right,
+ struct grub_term_output *term);
+
+void
+grub_print_ucs4_menu (const grub_uint32_t * str,
+ const grub_uint32_t * last_position,
+ int margin_left, int margin_right,
+ struct grub_term_output *term,
+ int skip_lines, int max_lines, grub_uint32_t contchar,
+ struct grub_term_pos *pos);
+int
+grub_ucs4_count_lines (const grub_uint32_t * str,
+ const grub_uint32_t * last_position,
+ int margin_left, int margin_right,
+ struct grub_term_output *term);
+grub_size_t grub_getstringwidth (grub_uint32_t * str,
+ const grub_uint32_t * last_position,
+ struct grub_term_output *term);
+void grub_print_message_indented (const char *msg, int margin_left,
+ int margin_right,
+ struct grub_term_output *term);
+void
+grub_menu_text_register_instances (int entry, grub_menu_t menu, int nested);
+grub_err_t
+grub_show_menu (grub_menu_t menu, int nested, int autobooted);
+
+/* Defined in `handler.c'. */
+void read_handler_list (void);
+void free_handler_list (void);
+
+/* Defined in `dyncmd.c'. */
+void read_command_list (const char *prefix);
+
+/* Defined in `autofs.c'. */
+void read_fs_list (const char *prefix);
+
+void grub_context_init (void);
+void grub_context_fini (void);
+
+void read_crypto_list (const char *prefix);
+
+void read_terminal_list (const char *prefix);
+
+void grub_set_more (int onoff);
+
+void grub_normal_reset_more (void);
+
+void grub_xputs_normal (const char *str);
+
+extern int grub_extractor_level;
+
+grub_err_t
+grub_normal_add_menu_entry (int argc, const char **args, char **classes,
+ const char *id,
+ const char *users, const char *hotkey,
+ const char *prefix, const char *sourcecode,
+ int submenu);
+
+grub_err_t
+grub_normal_set_password (const char *user, const char *password);
+
+void grub_normal_free_menu (grub_menu_t menu);
+
+void grub_normal_auth_init (void);
+void grub_normal_auth_fini (void);
+
+void
+grub_xnputs (const char *str, grub_size_t msg_len);
+
+grub_command_t
+grub_dyncmd_get_cmd (grub_command_t cmd);
+
+void
+grub_gettext_reread_prefix (const char *val);
+
+enum grub_human_size_type
+ {
+ GRUB_HUMAN_SIZE_NORMAL,
+ GRUB_HUMAN_SIZE_SHORT,
+ GRUB_HUMAN_SIZE_SPEED,
+ };
+
+const char *
+grub_get_human_size (grub_uint64_t size, enum grub_human_size_type type);
+
+#endif /* ! GRUB_NORMAL_HEADER */
diff --git a/include/grub/ns8250.h b/include/grub/ns8250.h
new file mode 100644
index 0000000..7947ba9
--- /dev/null
+++ b/include/grub/ns8250.h
@@ -0,0 +1,80 @@
+/* serial.h - serial device interface */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2000,2001,2002,2005,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_NS8250_HEADER
+#define GRUB_NS8250_HEADER 1
+
+/* Macros. */
+
+/* The offsets of UART registers. */
+#define UART_TX 0
+#define UART_RX 0
+#define UART_DLL 0
+#define UART_IER 1
+#define UART_DLH 1
+#define UART_IIR 2
+#define UART_FCR 2
+#define UART_LCR 3
+#define UART_MCR 4
+#define UART_LSR 5
+#define UART_MSR 6
+#define UART_SR 7
+
+/* For LSR bits. */
+#define UART_DATA_READY 0x01
+#define UART_EMPTY_TRANSMITTER 0x20
+
+/* The type of parity. */
+#define UART_NO_PARITY 0x00
+#define UART_ODD_PARITY 0x08
+#define UART_EVEN_PARITY 0x18
+
+/* The type of word length. */
+#define UART_5BITS_WORD 0x00
+#define UART_6BITS_WORD 0x01
+#define UART_7BITS_WORD 0x02
+#define UART_8BITS_WORD 0x03
+
+/* The type of the length of stop bit. */
+#define UART_1_STOP_BIT 0x00
+#define UART_2_STOP_BITS 0x04
+
+/* the switch of DLAB. */
+#define UART_DLAB 0x80
+
+/* Enable the FIFO. */
+#define UART_ENABLE_FIFO_TRIGGER14 0xC7
+
+/* Enable the FIFO. */
+#define UART_ENABLE_FIFO_TRIGGER1 0x07
+
+/* Turn on DTR, RTS, and OUT2. */
+#define UART_ENABLE_DTRRTS 0x03
+
+/* Turn on DTR, RTS, and OUT2. */
+#define UART_ENABLE_OUT2 0x08
+
+#ifndef ASM_FILE
+#include <grub/cpu/io.h>
+
+grub_port_t
+grub_ns8250_hw_get_port (const unsigned int unit);
+#endif
+
+#endif /* ! GRUB_SERIAL_MACHINE_HEADER */
diff --git a/include/grub/ntfs.h b/include/grub/ntfs.h
new file mode 100644
index 0000000..d1a6af6
--- /dev/null
+++ b/include/grub/ntfs.h
@@ -0,0 +1,198 @@
+/* ntfs.h - header for the NTFS filesystem */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2007,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_NTFS_H
+#define GRUB_NTFS_H 1
+
+enum
+ {
+ GRUB_NTFS_FILE_MFT = 0,
+ GRUB_NTFS_FILE_MFTMIRR = 1,
+ GRUB_NTFS_FILE_LOGFILE = 2,
+ GRUB_NTFS_FILE_VOLUME = 3,
+ GRUB_NTFS_FILE_ATTRDEF = 4,
+ GRUB_NTFS_FILE_ROOT = 5,
+ GRUB_NTFS_FILE_BITMAP = 6,
+ GRUB_NTFS_FILE_BOOT = 7,
+ GRUB_NTFS_FILE_BADCLUS = 8,
+ GRUB_NTFS_FILE_QUOTA = 9,
+ GRUB_NTFS_FILE_UPCASE = 10,
+ };
+
+enum
+ {
+ GRUB_NTFS_AT_STANDARD_INFORMATION = 0x10,
+ GRUB_NTFS_AT_ATTRIBUTE_LIST = 0x20,
+ GRUB_NTFS_AT_FILENAME = 0x30,
+ GRUB_NTFS_AT_OBJECT_ID = 0x40,
+ GRUB_NTFS_AT_SECURITY_DESCRIPTOR = 0x50,
+ GRUB_NTFS_AT_VOLUME_NAME = 0x60,
+ GRUB_NTFS_AT_VOLUME_INFORMATION = 0x70,
+ GRUB_NTFS_AT_DATA = 0x80,
+ GRUB_NTFS_AT_INDEX_ROOT = 0x90,
+ GRUB_NTFS_AT_INDEX_ALLOCATION = 0xA0,
+ GRUB_NTFS_AT_BITMAP = 0xB0,
+ GRUB_NTFS_AT_SYMLINK = 0xC0,
+ GRUB_NTFS_AT_EA_INFORMATION = 0xD0,
+ GRUB_NTFS_AT_EA = 0xE0,
+ };
+
+enum
+ {
+ GRUB_NTFS_ATTR_READ_ONLY = 0x1,
+ GRUB_NTFS_ATTR_HIDDEN = 0x2,
+ GRUB_NTFS_ATTR_SYSTEM = 0x4,
+ GRUB_NTFS_ATTR_ARCHIVE = 0x20,
+ GRUB_NTFS_ATTR_DEVICE = 0x40,
+ GRUB_NTFS_ATTR_NORMAL = 0x80,
+ GRUB_NTFS_ATTR_TEMPORARY = 0x100,
+ GRUB_NTFS_ATTR_SPARSE = 0x200,
+ GRUB_NTFS_ATTR_REPARSE = 0x400,
+ GRUB_NTFS_ATTR_COMPRESSED = 0x800,
+ GRUB_NTFS_ATTR_OFFLINE = 0x1000,
+ GRUB_NTFS_ATTR_NOT_INDEXED = 0x2000,
+ GRUB_NTFS_ATTR_ENCRYPTED = 0x4000,
+ GRUB_NTFS_ATTR_DIRECTORY = 0x10000000,
+ GRUB_NTFS_ATTR_INDEX_VIEW = 0x20000000
+ };
+
+enum
+ {
+ GRUB_NTFS_FLAG_COMPRESSED = 1,
+ GRUB_NTFS_FLAG_ENCRYPTED = 0x4000,
+ GRUB_NTFS_FLAG_SPARSE = 0x8000
+ };
+
+#define GRUB_NTFS_BLK_SHR GRUB_DISK_SECTOR_BITS
+
+#define GRUB_NTFS_MAX_MFT (4096 >> GRUB_NTFS_BLK_SHR)
+#define GRUB_NTFS_MAX_IDX (16384 >> GRUB_NTFS_BLK_SHR)
+
+#define GRUB_NTFS_COM_LEN 4096
+#define GRUB_NTFS_COM_LOG_LEN 12
+#define GRUB_NTFS_COM_SEC (GRUB_NTFS_COM_LEN >> GRUB_NTFS_BLK_SHR)
+#define GRUB_NTFS_LOG_COM_SEC (GRUB_NTFS_COM_LOG_LEN - GRUB_NTFS_BLK_SHR)
+
+enum
+ {
+ GRUB_NTFS_AF_ALST = 1,
+ GRUB_NTFS_AF_MMFT = 2,
+ GRUB_NTFS_AF_GPOS = 4,
+ };
+
+enum
+ {
+ GRUB_NTFS_RF_BLNK = 1
+ };
+
+struct grub_ntfs_bpb
+{
+ grub_uint8_t jmp_boot[3];
+ grub_uint8_t oem_name[8];
+ grub_uint16_t bytes_per_sector;
+ grub_uint8_t sectors_per_cluster;
+ grub_uint8_t reserved_1[7];
+ grub_uint8_t media;
+ grub_uint16_t reserved_2;
+ grub_uint16_t sectors_per_track;
+ grub_uint16_t num_heads;
+ grub_uint32_t num_hidden_sectors;
+ grub_uint32_t reserved_3;
+ grub_uint8_t bios_drive;
+ grub_uint8_t reserved_4[3];
+ grub_uint64_t num_total_sectors;
+ grub_uint64_t mft_lcn;
+ grub_uint64_t mft_mirr_lcn;
+ grub_int8_t clusters_per_mft;
+ grub_int8_t reserved_5[3];
+ grub_int8_t clusters_per_index;
+ grub_int8_t reserved_6[3];
+ grub_uint64_t num_serial;
+ grub_uint32_t checksum;
+} GRUB_PACKED;
+
+struct grub_ntfs_attr
+{
+ int flags;
+ grub_uint8_t *emft_buf, *edat_buf;
+ grub_uint8_t *attr_cur, *attr_nxt, *attr_end;
+ grub_uint32_t save_pos;
+ grub_uint8_t *sbuf;
+ struct grub_ntfs_file *mft;
+};
+
+struct grub_ntfs_file
+{
+ struct grub_ntfs_data *data;
+ grub_uint8_t *buf;
+ grub_uint64_t size;
+ grub_uint64_t mtime;
+ grub_uint64_t ino;
+ int inode_read;
+ struct grub_ntfs_attr attr;
+};
+
+struct grub_ntfs_data
+{
+ struct grub_ntfs_file cmft;
+ struct grub_ntfs_file mmft;
+ grub_disk_t disk;
+ grub_uint64_t mft_size;
+ grub_uint64_t idx_size;
+ int log_spc;
+ grub_uint64_t mft_start;
+ grub_uint64_t uuid;
+};
+
+struct grub_ntfs_comp_table_element
+{
+ grub_uint32_t next_vcn;
+ grub_uint32_t next_lcn;
+};
+
+struct grub_ntfs_comp
+{
+ grub_disk_t disk;
+ int comp_head, comp_tail;
+ struct grub_ntfs_comp_table_element comp_table[16];
+ grub_uint32_t cbuf_ofs, cbuf_vcn;
+ int log_spc;
+ grub_uint8_t *cbuf;
+};
+
+struct grub_ntfs_rlst
+{
+ int flags;
+ grub_disk_addr_t target_vcn, curr_vcn, next_vcn, curr_lcn;
+ grub_uint8_t *cur_run;
+ struct grub_ntfs_attr *attr;
+ struct grub_ntfs_comp comp;
+ void *file;
+};
+
+typedef grub_err_t (*grub_ntfscomp_func_t) (grub_uint8_t *dest,
+ grub_disk_addr_t ofs,
+ grub_size_t len,
+ struct grub_ntfs_rlst * ctx);
+
+extern grub_ntfscomp_func_t grub_ntfscomp_func;
+
+grub_err_t grub_ntfs_read_run_list (struct grub_ntfs_rlst *ctx);
+
+#endif /* ! GRUB_NTFS_H */
diff --git a/include/grub/offsets.h b/include/grub/offsets.h
new file mode 100644
index 0000000..871e1cd
--- /dev/null
+++ b/include/grub/offsets.h
@@ -0,0 +1,168 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2003,2007,2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef OFFSETS_HEADER
+#define OFFSETS_HEADER 1
+
+/* The offset of GRUB_COMPRESSED_SIZE. */
+#define GRUB_DECOMPRESSOR_I386_PC_COMPRESSED_SIZE 0x08
+
+/* The offset of GRUB_COMPRESSED_SIZE. */
+#define GRUB_DECOMPRESSOR_I386_PC_UNCOMPRESSED_SIZE 0x0c
+
+/* Offset of reed_solomon_redundancy. */
+#define GRUB_KERNEL_I386_PC_REED_SOLOMON_REDUNDANCY 0x10
+
+/* Offset of field holding no reed solomon length. */
+#define GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_LENGTH 0x14
+
+#define GRUB_DECOMPRESSOR_I386_PC_BOOT_DEVICE 0x18
+
+#define GRUB_DECOMPRESSOR_I386_PC_MAX_DECOMPRESSOR_SIZE (0x9000-0x8200)
+
+/* The segment where the kernel is loaded. */
+#define GRUB_BOOT_I386_PC_KERNEL_SEG 0x800
+
+#define GRUB_KERNEL_I386_PC_LINK_ADDR 0x9000
+#define GRUB_KERNEL_I386_XEN_PVH_LINK_ADDR 0x100000
+
+/* The upper memory area (starting at 640 kiB). */
+#define GRUB_MEMORY_I386_PC_UPPER 0xa0000
+#define GRUB_MEMORY_I386_QEMU_UPPER GRUB_MEMORY_I386_PC_UPPER
+
+/* The offset of GRUB_CORE_ENTRY_ADDR. */
+#define GRUB_BOOT_I386_QEMU_CORE_ENTRY_ADDR 0x4
+
+/* The offset of GRUB_CORE_ENTRY_ADDR. */
+#define GRUB_KERNEL_I386_QEMU_CORE_ENTRY_ADDR 0x8
+
+#define GRUB_KERNEL_I386_QEMU_LINK_ADDR 0x9000
+
+/* The offset of GRUB_TOTAL_MODULE_SIZE. */
+#define GRUB_KERNEL_SPARC64_IEEE1275_TOTAL_MODULE_SIZE 0x8
+#define GRUB_KERNEL_ARM_STACK_SIZE 0x40000
+
+#define GRUB_BOOT_SPARC64_IEEE1275_LIST_SIZE 12
+
+#define GRUB_BOOT_SPARC64_IEEE1275_IMAGE_ADDRESS 0x4400
+#define GRUB_KERNEL_SPARC64_IEEE1275_LINK_ADDR 0x4400
+
+#define GRUB_KERNEL_POWERPC_IEEE1275_LINK_ALIGN 4
+#define GRUB_KERNEL_POWERPC_IEEE1275_LINK_ADDR 0x200000
+
+#define GRUB_KERNEL_MIPS_LOONGSON_LINK_ADDR 0x80200000
+
+#define GRUB_KERNEL_MIPS_LOONGSON_LINK_ALIGN 32
+
+#define GRUB_DECOMPRESSOR_MIPS_LOONGSON_COMPRESSED_SIZE 0x8
+#define GRUB_DECOMPRESSOR_MIPS_LOONGSON_UNCOMPRESSED_SIZE 0xc
+#define GRUB_DECOMPRESSOR_MIPS_LOONGSON_UNCOMPRESSED_ADDR 0x10
+
+#define GRUB_KERNEL_MIPS_LOONGSON_TOTAL_MODULE_SIZE 0x08
+
+#define GRUB_KERNEL_MIPS_QEMU_MIPS_LINK_ADDR 0x80200000
+#define GRUB_KERNEL_MIPS_QEMU_MIPS_LINK_ALIGN 32
+#define GRUB_DECOMPRESSOR_MIPS_QEMU_MIPS_COMPRESSED_SIZE 0x8
+#define GRUB_DECOMPRESSOR_MIPS_QEMU_MIPS_UNCOMPRESSED_SIZE 0xc
+#define GRUB_DECOMPRESSOR_MIPS_QEMU_MIPS_UNCOMPRESSED_ADDR 0x10
+#define GRUB_KERNEL_MIPS_QEMU_MIPS_TOTAL_MODULE_SIZE 0x08
+
+#define GRUB_KERNEL_MIPS_ARC_LINK_ADDR 0x88200000
+#define GRUB_KERNEL_MIPSEL_ARC_LINK_ADDR 0x80700000
+#define GRUB_KERNEL_MIPS_ARC_LINK_ALIGN 32
+
+#define GRUB_DECOMPRESSOR_MIPS_ARC_COMPRESSED_SIZE 0x8
+#define GRUB_DECOMPRESSOR_MIPS_ARC_UNCOMPRESSED_SIZE 0xc
+#define GRUB_DECOMPRESSOR_MIPS_ARC_UNCOMPRESSED_ADDR 0x10
+
+#define GRUB_KERNEL_MIPS_ARC_TOTAL_MODULE_SIZE 0x08
+
+#define GRUB_KERNEL_I386_COREBOOT_LINK_ADDR 0x9000
+#define GRUB_KERNEL_I386_COREBOOT_MODULES_ADDR 0x100000
+
+#define GRUB_KERNEL_I386_IEEE1275_LINK_ADDR 0x10000
+
+#define GRUB_KERNEL_I386_IEEE1275_MOD_ALIGN 0x1000
+#define GRUB_KERNEL_I386_COREBOOT_MOD_ALIGN 0x1
+#define GRUB_KERNEL_I386_MULTIBOOT_MOD_ALIGN GRUB_KERNEL_I386_COREBOOT_MOD_ALIGN
+
+#define GRUB_KERNEL_X86_64_XEN_MOD_ALIGN 0x8
+#define GRUB_KERNEL_I386_XEN_MOD_ALIGN 0x8
+#define GRUB_KERNEL_I386_XEN_PVH_MOD_ALIGN 0x8
+
+/* Non-zero value is only needed for PowerMacs. */
+#define GRUB_KERNEL_X86_64_XEN_MOD_GAP 0x0
+#define GRUB_KERNEL_I386_XEN_MOD_GAP 0x0
+#define GRUB_KERNEL_I386_XEN_PVH_MOD_GAP 0x0
+#define GRUB_KERNEL_I386_IEEE1275_MOD_GAP 0x0
+#define GRUB_KERNEL_I386_COREBOOT_MOD_GAP 0x0
+#define GRUB_KERNEL_SPARC64_IEEE1275_MOD_GAP 0x0
+#define GRUB_KERNEL_ARM_UBOOT_MOD_GAP 0x0
+
+#define GRUB_KERNEL_POWERPC_IEEE1275_MOD_ALIGN 0x1000
+#define GRUB_KERNEL_SPARC64_IEEE1275_LOG_MOD_ALIGN 3
+#define GRUB_KERNEL_SPARC64_IEEE1275_MOD_ALIGN (1 << GRUB_KERNEL_SPARC64_IEEE1275_LOG_MOD_ALIGN)
+
+#define GRUB_KERNEL_MIPS_LOONGSON_MOD_ALIGN 0x1
+#define GRUB_KERNEL_MIPS_ARC_MOD_ALIGN 0x1
+#define GRUB_KERNEL_MIPS_QEMU_MIPS_MOD_ALIGN 0x1
+
+#define GRUB_KERNEL_ARM_UBOOT_MOD_ALIGN 0x8
+#define GRUB_KERNEL_ARM_UBOOT_TOTAL_MODULE_SIZE 0x4
+
+#define GRUB_KERNEL_ARM_COREBOOT_MOD_ALIGN 0x8
+#define GRUB_KERNEL_ARM_COREBOOT_TOTAL_MODULE_SIZE 0x4
+
+#define GRUB_KERNEL_ARM_STACK_SIZE 0x40000
+#define GRUB_KERNEL_ARM_COREBOOT_MOD_GAP (GRUB_KERNEL_ARM_STACK_SIZE + 1024)
+
+/* Minimal gap between _end and the start of the modules. It's a hack
+ for PowerMac to prevent "CLAIM failed" error. The real fix is to
+ rewrite grub-mkimage to generate valid ELF files. */
+#define GRUB_KERNEL_POWERPC_IEEE1275_MOD_GAP 0x8000
+
+#ifdef GRUB_MACHINE
+#define GRUB_OFFSETS_CONCAT_(a,b,c) a ## b ## c
+#define GRUB_OFFSETS_CONCAT(a,b,c) GRUB_OFFSETS_CONCAT_(a,b,c)
+#define GRUB_KERNEL_MACHINE_MOD_ALIGN GRUB_OFFSETS_CONCAT (GRUB_KERNEL_, GRUB_MACHINE, _MOD_ALIGN)
+#define GRUB_KERNEL_MACHINE_MOD_GAP GRUB_OFFSETS_CONCAT (GRUB_KERNEL_, GRUB_MACHINE, _MOD_GAP)
+#define GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE GRUB_OFFSETS_CONCAT (GRUB_KERNEL_, GRUB_MACHINE, _TOTAL_MODULE_SIZE)
+
+#define GRUB_BOOT_MACHINE_KERNEL_SEG GRUB_OFFSETS_CONCAT (GRUB_BOOT_, GRUB_MACHINE, _KERNEL_SEG)
+#define GRUB_MEMORY_MACHINE_UPPER GRUB_OFFSETS_CONCAT (GRUB_MEMORY_, GRUB_MACHINE, _UPPER)
+#if defined (GRUB_MACHINE_ARC) && defined (GRUB_CPU_MIPSEL)
+#define GRUB_MACHINE_LINK_ADDR GRUB_KERNEL_MIPSEL_ARC_LINK_ADDR
+#else
+#define GRUB_MACHINE_LINK_ADDR GRUB_OFFSETS_CONCAT (GRUB_KERNEL_, GRUB_MACHINE, _LINK_ADDR)
+#endif
+
+#define GRUB_DECOMPRESSOR_MACHINE_COMPRESSED_SIZE GRUB_OFFSETS_CONCAT (GRUB_DECOMPRESSOR_, GRUB_MACHINE, _COMPRESSED_SIZE)
+#define GRUB_DECOMPRESSOR_MACHINE_UNCOMPRESSED_SIZE GRUB_OFFSETS_CONCAT (GRUB_DECOMPRESSOR_, GRUB_MACHINE, _UNCOMPRESSED_SIZE)
+#define GRUB_DECOMPRESSOR_MACHINE_UNCOMPRESSED_ADDR GRUB_OFFSETS_CONCAT (GRUB_DECOMPRESSOR_, GRUB_MACHINE, _UNCOMPRESSED_ADDR)
+#endif
+
+#ifndef ASM_FILE
+struct grub_pc_bios_boot_blocklist
+{
+ grub_uint64_t start;
+ grub_uint16_t len;
+ grub_uint16_t segment;
+} GRUB_PACKED;
+#endif
+
+#endif
diff --git a/include/grub/osdep/hostfile.h b/include/grub/osdep/hostfile.h
new file mode 100644
index 0000000..6d9f75b
--- /dev/null
+++ b/include/grub/osdep/hostfile.h
@@ -0,0 +1,7 @@
+#if defined (__AROS__)
+#include "hostfile_aros.h"
+#elif defined (__CYGWIN__) || defined (__MINGW32__)
+#include "hostfile_windows.h"
+#else
+#include "hostfile_unix.h"
+#endif
diff --git a/include/grub/osdep/hostfile_aros.h b/include/grub/osdep/hostfile_aros.h
new file mode 100644
index 0000000..161fbb7
--- /dev/null
+++ b/include/grub/osdep/hostfile_aros.h
@@ -0,0 +1,119 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010,2011,2012,2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_EMU_HOSTFILE_H
+#define GRUB_EMU_HOSTFILE_H 1
+
+#include <config.h>
+#include <stdarg.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <stdio.h>
+
+typedef struct dirent *grub_util_fd_dirent_t;
+typedef DIR *grub_util_fd_dir_t;
+
+static inline grub_util_fd_dir_t
+grub_util_fd_opendir (const char *name)
+{
+ return opendir (name);
+}
+
+static inline void
+grub_util_fd_closedir (grub_util_fd_dir_t dirp)
+{
+ closedir (dirp);
+}
+
+static inline grub_util_fd_dirent_t
+grub_util_fd_readdir (grub_util_fd_dir_t dirp)
+{
+ return readdir (dirp);
+}
+
+static inline int
+grub_util_rmdir (const char *pathname)
+{
+ return rmdir (pathname);
+}
+
+static inline int
+grub_util_unlink (const char *pathname)
+{
+ return unlink (pathname);
+}
+
+static inline int
+grub_util_rename (const char *from, const char *to)
+{
+ return rename (from, to);
+}
+
+static inline ssize_t
+grub_util_readlink (const char *name, char *buf, size_t bufsize)
+{
+ return readlink(name, buf, bufsize);
+}
+
+#define grub_util_mkdir(a) mkdir ((a), 0755)
+
+struct grub_util_fd
+{
+ enum { GRUB_UTIL_FD_FILE, GRUB_UTIL_FD_DISK } type;
+ grub_uint64_t off;
+ union
+ {
+ int fd;
+ struct {
+ struct IOExtTD *ioreq;
+ struct MsgPort *mp;
+ unsigned int is_floppy:1;
+ unsigned int is_64:1;
+ };
+ };
+};
+typedef struct grub_util_fd *grub_util_fd_t;
+
+enum grub_util_fd_open_flags_t
+ {
+ GRUB_UTIL_FD_O_RDONLY = O_RDONLY,
+ GRUB_UTIL_FD_O_WRONLY = O_WRONLY,
+ GRUB_UTIL_FD_O_RDWR = O_RDWR,
+ GRUB_UTIL_FD_O_CREATTRUNC = O_CREAT | O_TRUNC,
+ GRUB_UTIL_FD_O_SYNC = (0
+#ifdef O_SYNC
+ | O_SYNC
+#endif
+#ifdef O_FSYNC
+ | O_FSYNC
+#endif
+ )
+ };
+
+#define GRUB_UTIL_FD_INVALID NULL
+#define GRUB_UTIL_FD_IS_VALID(x) ((x) != GRUB_UTIL_FD_INVALID)
+#define GRUB_UTIL_FD_STAT_IS_FUNCTIONAL 0
+
+#define DEFAULT_DIRECTORY "SYS:" GRUB_BOOT_DIR_NAME "/" GRUB_DIR_NAME
+#define DEFAULT_DEVICE_MAP DEFAULT_DIRECTORY "/device.map"
+
+#endif
diff --git a/include/grub/osdep/hostfile_unix.h b/include/grub/osdep/hostfile_unix.h
new file mode 100644
index 0000000..17cd3aa
--- /dev/null
+++ b/include/grub/osdep/hostfile_unix.h
@@ -0,0 +1,118 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010,2011,2012,2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_EMU_HOSTFILE_H
+#define GRUB_EMU_HOSTFILE_H 1
+
+#include <config.h>
+#include <stdarg.h>
+
+#include <grub/symbol.h>
+#include <grub/types.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <stdio.h>
+
+typedef struct dirent *grub_util_fd_dirent_t;
+typedef DIR *grub_util_fd_dir_t;
+
+static inline grub_util_fd_dir_t
+grub_util_fd_opendir (const char *name)
+{
+ return opendir (name);
+}
+
+static inline void
+grub_util_fd_closedir (grub_util_fd_dir_t dirp)
+{
+ closedir (dirp);
+}
+
+static inline grub_util_fd_dirent_t
+grub_util_fd_readdir (grub_util_fd_dir_t dirp)
+{
+ return readdir (dirp);
+}
+
+static inline int
+grub_util_unlink (const char *pathname)
+{
+ return unlink (pathname);
+}
+
+static inline int
+grub_util_rmdir (const char *pathname)
+{
+ return rmdir (pathname);
+}
+
+static inline int
+grub_util_rename (const char *from, const char *to)
+{
+ return rename (from, to);
+}
+
+static inline ssize_t
+grub_util_readlink (const char *name, char *buf, size_t bufsize)
+{
+ return readlink(name, buf, bufsize);
+}
+
+#define grub_util_mkdir(a) mkdir ((a), 0755)
+
+#if defined (__NetBSD__)
+/* NetBSD uses /boot for its boot block. */
+# define DEFAULT_DIRECTORY "/"GRUB_DIR_NAME
+#else
+# define DEFAULT_DIRECTORY "/"GRUB_BOOT_DIR_NAME"/"GRUB_DIR_NAME
+#endif
+
+enum grub_util_fd_open_flags_t
+ {
+ GRUB_UTIL_FD_O_RDONLY = O_RDONLY,
+ GRUB_UTIL_FD_O_WRONLY = O_WRONLY,
+ GRUB_UTIL_FD_O_RDWR = O_RDWR,
+ GRUB_UTIL_FD_O_CREATTRUNC = O_CREAT | O_TRUNC,
+ GRUB_UTIL_FD_O_SYNC = (0
+#ifdef O_SYNC
+ | O_SYNC
+#endif
+#ifdef O_FSYNC
+ | O_FSYNC
+#endif
+ )
+ };
+
+#define DEFAULT_DEVICE_MAP DEFAULT_DIRECTORY "/device.map"
+
+typedef int grub_util_fd_t;
+#define GRUB_UTIL_FD_INVALID -1
+#define GRUB_UTIL_FD_IS_VALID(x) ((x) >= 0)
+#define GRUB_UTIL_FD_STAT_IS_FUNCTIONAL 1
+
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__) || defined(__NetBSD__) || defined (__sun__) || defined(__OpenBSD__) || defined(__HAIKU__)
+#define GRUB_DISK_DEVS_ARE_CHAR 1
+#else
+#define GRUB_DISK_DEVS_ARE_CHAR 0
+#endif
+
+#endif
diff --git a/include/grub/osdep/hostfile_windows.h b/include/grub/osdep/hostfile_windows.h
new file mode 100644
index 0000000..bf6451b
--- /dev/null
+++ b/include/grub/osdep/hostfile_windows.h
@@ -0,0 +1,85 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010,2011,2012,2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_EMU_HOSTFILE_H
+#define GRUB_EMU_HOSTFILE_H 1
+
+#include <config.h>
+#include <stdarg.h>
+
+#include <windows.h>
+typedef HANDLE grub_util_fd_t;
+#define GRUB_UTIL_FD_INVALID INVALID_HANDLE_VALUE
+#define GRUB_UTIL_FD_IS_VALID(x) ((x) != GRUB_UTIL_FD_INVALID)
+#define GRUB_UTIL_FD_STAT_IS_FUNCTIONAL 0
+
+#define DEFAULT_DIRECTORY "C:\\"GRUB_BOOT_DIR_NAME"\\"GRUB_DIR_NAME
+#define DEFAULT_DEVICE_MAP DEFAULT_DIRECTORY "/device.map"
+
+struct grub_util_fd_dirent
+{
+ char d_name[0];
+};
+struct grub_util_fd_dir;
+typedef struct grub_util_fd_dirent *grub_util_fd_dirent_t;
+typedef struct grub_util_fd_dir *grub_util_fd_dir_t;
+
+int
+grub_util_rename (const char *from, const char *to);
+int
+grub_util_unlink (const char *name);
+void
+grub_util_mkdir (const char *dir);
+
+grub_util_fd_dir_t
+grub_util_fd_opendir (const char *name);
+
+void
+grub_util_fd_closedir (grub_util_fd_dir_t dirp);
+
+grub_util_fd_dirent_t
+grub_util_fd_readdir (grub_util_fd_dir_t dirp);
+
+int
+grub_util_rmdir (const char *pathname);
+
+enum grub_util_fd_open_flags_t
+ {
+ GRUB_UTIL_FD_O_RDONLY = 1,
+ GRUB_UTIL_FD_O_WRONLY = 2,
+ GRUB_UTIL_FD_O_RDWR = 3,
+ GRUB_UTIL_FD_O_CREATTRUNC = 4,
+ GRUB_UTIL_FD_O_SYNC = 0,
+ };
+
+#if defined (__MINGW32__) && !defined (__MINGW64__)
+
+/* 32 bit on Mingw-w64 already redefines them if _FILE_OFFSET_BITS=64 */
+#ifndef _W64
+#define fseeko fseeko64
+#define ftello ftello64
+#endif
+
+#endif
+
+LPTSTR
+grub_util_utf8_to_tchar (const char *in);
+char *
+grub_util_tchar_to_utf8 (LPCTSTR in);
+
+#endif
diff --git a/include/grub/parser.h b/include/grub/parser.h
new file mode 100644
index 0000000..64f9f5c
--- /dev/null
+++ b/include/grub/parser.h
@@ -0,0 +1,96 @@
+/* parser.h - prototypes for the command line parser. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2005,2007,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_PARSER_HEADER
+#define GRUB_PARSER_HEADER 1
+
+#include <grub/types.h>
+#include <grub/err.h>
+#include <grub/reader.h>
+
+/* All the states for the command line. */
+typedef enum
+ {
+ GRUB_PARSER_STATE_TEXT = 1,
+ GRUB_PARSER_STATE_ESC,
+ GRUB_PARSER_STATE_QUOTE,
+ GRUB_PARSER_STATE_DQUOTE,
+ GRUB_PARSER_STATE_VAR,
+ GRUB_PARSER_STATE_VARNAME,
+ GRUB_PARSER_STATE_VARNAME2,
+ GRUB_PARSER_STATE_QVAR,
+ GRUB_PARSER_STATE_QVARNAME,
+ GRUB_PARSER_STATE_QVARNAME2
+ } grub_parser_state_t;
+
+/* A single state transition. */
+struct grub_parser_state_transition
+{
+ /* The state that is looked up. */
+ grub_parser_state_t from_state;
+
+ /* The next state, determined by FROM_STATE and INPUT. */
+ grub_parser_state_t to_state;
+
+ /* The input that will determine the next state from FROM_STATE. */
+ char input;
+
+ /* If set to 1, the input is valid and should be used. */
+ int keep_value;
+};
+
+/* Determines the state following STATE, determined by C. */
+grub_parser_state_t
+EXPORT_FUNC (grub_parser_cmdline_state) (grub_parser_state_t state,
+ char c, char *result);
+
+grub_err_t
+EXPORT_FUNC (grub_parser_split_cmdline) (const char *cmdline,
+ grub_reader_getline_t getline_func,
+ void *getline_func_data,
+ int *argc, char ***argv);
+
+struct grub_parser
+{
+ /* The next parser. */
+ struct grub_parser *next;
+
+ /* The parser name. */
+ const char *name;
+
+ /* Initialize the parser. */
+ grub_err_t (*init) (void);
+
+ /* Clean up the parser. */
+ grub_err_t (*fini) (void);
+
+ grub_err_t (*parse_line) (char *line,
+ grub_reader_getline_t getline_func,
+ void *getline_func_data);
+};
+typedef struct grub_parser *grub_parser_t;
+
+grub_err_t grub_parser_execute (char *source);
+
+grub_err_t
+grub_rescue_parse_line (char *line,
+ grub_reader_getline_t getline_func,
+ void *getline_func_data);
+
+#endif /* ! GRUB_PARSER_HEADER */
diff --git a/include/grub/partition.h b/include/grub/partition.h
new file mode 100644
index 0000000..8208cc7
--- /dev/null
+++ b/include/grub/partition.h
@@ -0,0 +1,141 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 1999,2000,2001,2002,2004,2006,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_PART_HEADER
+#define GRUB_PART_HEADER 1
+
+#include <grub/dl.h>
+#include <grub/list.h>
+
+struct grub_disk;
+
+typedef struct grub_partition *grub_partition_t;
+
+#ifdef GRUB_UTIL
+typedef enum
+{
+ GRUB_EMBED_PCBIOS
+} grub_embed_type_t;
+#endif
+
+typedef int (*grub_partition_iterate_hook_t) (struct grub_disk *disk,
+ const grub_partition_t partition,
+ void *data);
+
+/* Partition map type. */
+struct grub_partition_map
+{
+ /* The next partition map type. */
+ struct grub_partition_map *next;
+ struct grub_partition_map **prev;
+
+ /* The name of the partition map type. */
+ const char *name;
+
+ /* Call HOOK with each partition, until HOOK returns non-zero. */
+ grub_err_t (*iterate) (struct grub_disk *disk,
+ grub_partition_iterate_hook_t hook, void *hook_data);
+#ifdef GRUB_UTIL
+#define GRUB_MIN_RECOMMENDED_MBR_GAP 1900
+
+ /* Determine sectors available for embedding. */
+ grub_err_t (*embed) (struct grub_disk *disk, unsigned int *nsectors,
+ unsigned int max_nsectors,
+ grub_embed_type_t embed_type,
+ grub_disk_addr_t **sectors,
+ int warn_short);
+#endif
+};
+typedef struct grub_partition_map *grub_partition_map_t;
+
+/* Partition description. */
+struct grub_partition
+{
+ /* The partition number. */
+ int number;
+
+ /* The start sector (relative to parent). */
+ grub_disk_addr_t start;
+
+ /* The length in sector units. */
+ grub_uint64_t len;
+
+ /* The offset of the partition table. */
+ grub_disk_addr_t offset;
+
+ /* The index of this partition in the partition table. */
+ int index;
+
+ /* Parent partition (physically contains this partition). */
+ struct grub_partition *parent;
+
+ /* The type partition map. */
+ grub_partition_map_t partmap;
+
+ /* The type of partition whne it's on MSDOS.
+ Used for embedding detection. */
+ grub_uint8_t msdostype;
+};
+
+grub_partition_t EXPORT_FUNC(grub_partition_probe) (struct grub_disk *disk,
+ const char *str);
+int EXPORT_FUNC(grub_partition_iterate) (struct grub_disk *disk,
+ grub_partition_iterate_hook_t hook,
+ void *hook_data);
+char *EXPORT_FUNC(grub_partition_get_name) (const grub_partition_t partition);
+
+
+extern grub_partition_map_t EXPORT_VAR(grub_partition_map_list);
+
+#ifndef GRUB_LST_GENERATOR
+static inline void
+grub_partition_map_register (grub_partition_map_t partmap)
+{
+ grub_list_push (GRUB_AS_LIST_P (&grub_partition_map_list),
+ GRUB_AS_LIST (partmap));
+}
+#endif
+
+static inline void
+grub_partition_map_unregister (grub_partition_map_t partmap)
+{
+ grub_list_remove (GRUB_AS_LIST (partmap));
+}
+
+#define FOR_PARTITION_MAPS(var) FOR_LIST_ELEMENTS((var), (grub_partition_map_list))
+
+
+static inline grub_disk_addr_t
+grub_partition_get_start (const grub_partition_t p)
+{
+ grub_partition_t part;
+ grub_uint64_t part_start = 0;
+
+ for (part = p; part; part = part->parent)
+ part_start += part->start;
+
+ return part_start;
+}
+
+static inline grub_uint64_t
+grub_partition_get_len (const grub_partition_t p)
+{
+ return p->len;
+}
+
+#endif /* ! GRUB_PART_HEADER */
diff --git a/include/grub/parttool.h b/include/grub/parttool.h
new file mode 100644
index 0000000..4e8f8d5
--- /dev/null
+++ b/include/grub/parttool.h
@@ -0,0 +1,58 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_PARTTOOL_HEADER
+#define GRUB_PARTTOOL_HEADER 1
+
+struct grub_parttool_argdesc
+{
+ const char *name;
+ const char *desc;
+ enum {GRUB_PARTTOOL_ARG_END, GRUB_PARTTOOL_ARG_BOOL, GRUB_PARTTOOL_ARG_VAL}
+ type;
+};
+
+struct grub_parttool_args
+{
+ int set;
+ union
+ {
+ int bool;
+ char *str;
+ };
+};
+
+typedef grub_err_t (*grub_parttool_function_t) (const grub_device_t dev,
+ const struct grub_parttool_args *args);
+
+struct grub_parttool
+{
+ struct grub_parttool *next;
+ char *name;
+ int handle;
+ int nargs;
+ struct grub_parttool_argdesc *args;
+ grub_parttool_function_t func;
+};
+
+int grub_parttool_register(const char *part_name,
+ const grub_parttool_function_t func,
+ const struct grub_parttool_argdesc *args);
+void grub_parttool_unregister (int handle);
+
+#endif /* ! GRUB_PARTTOOL_HEADER*/
diff --git a/include/grub/pci.h b/include/grub/pci.h
new file mode 100644
index 0000000..262c89b
--- /dev/null
+++ b/include/grub/pci.h
@@ -0,0 +1,152 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_PCI_H
+#define GRUB_PCI_H 1
+
+#ifndef ASM_FILE
+#include <grub/types.h>
+#include <grub/symbol.h>
+#endif
+
+#define GRUB_PCI_ADDR_SPACE_MASK 0x01
+#define GRUB_PCI_ADDR_SPACE_MEMORY 0x00
+#define GRUB_PCI_ADDR_SPACE_IO 0x01
+
+#define GRUB_PCI_ADDR_MEM_TYPE_MASK 0x06
+#define GRUB_PCI_ADDR_MEM_TYPE_32 0x00 /* 32 bit address */
+#define GRUB_PCI_ADDR_MEM_TYPE_1M 0x02 /* Below 1M [obsolete] */
+#define GRUB_PCI_ADDR_MEM_TYPE_64 0x04 /* 64 bit address */
+#define GRUB_PCI_ADDR_MEM_PREFETCH 0x08 /* prefetchable */
+
+#define GRUB_PCI_ADDR_MEM_MASK ~0xf
+#define GRUB_PCI_ADDR_IO_MASK ~0x03
+
+#define GRUB_PCI_REG_PCI_ID 0x00
+#define GRUB_PCI_REG_VENDOR 0x00
+#define GRUB_PCI_REG_DEVICE 0x02
+#define GRUB_PCI_REG_COMMAND 0x04
+#define GRUB_PCI_REG_STATUS 0x06
+#define GRUB_PCI_REG_REVISION 0x08
+#define GRUB_PCI_REG_CLASS 0x08
+#define GRUB_PCI_REG_CACHELINE 0x0c
+#define GRUB_PCI_REG_LAT_TIMER 0x0d
+#define GRUB_PCI_REG_HEADER_TYPE 0x0e
+#define GRUB_PCI_REG_BIST 0x0f
+#define GRUB_PCI_REG_ADDRESSES 0x10
+
+/* Beware that 64-bit address takes 2 registers. */
+#define GRUB_PCI_REG_ADDRESS_REG0 0x10
+#define GRUB_PCI_REG_ADDRESS_REG1 0x14
+#define GRUB_PCI_REG_ADDRESS_REG2 0x18
+#define GRUB_PCI_REG_ADDRESS_REG3 0x1c
+#define GRUB_PCI_REG_ADDRESS_REG4 0x20
+#define GRUB_PCI_REG_ADDRESS_REG5 0x24
+
+#define GRUB_PCI_REG_CIS_POINTER 0x28
+#define GRUB_PCI_REG_SUBVENDOR 0x2c
+#define GRUB_PCI_REG_SUBSYSTEM 0x2e
+#define GRUB_PCI_REG_ROM_ADDRESS 0x30
+#define GRUB_PCI_REG_CAP_POINTER 0x34
+#define GRUB_PCI_REG_IRQ_LINE 0x3c
+#define GRUB_PCI_REG_IRQ_PIN 0x3d
+#define GRUB_PCI_REG_MIN_GNT 0x3e
+#define GRUB_PCI_REG_MAX_LAT 0x3f
+
+#define GRUB_PCI_COMMAND_IO_ENABLED 0x0001
+#define GRUB_PCI_COMMAND_MEM_ENABLED 0x0002
+#define GRUB_PCI_COMMAND_BUS_MASTER 0x0004
+#define GRUB_PCI_COMMAND_PARITY_ERROR 0x0040
+#define GRUB_PCI_COMMAND_SERR_ENABLE 0x0100
+
+#define GRUB_PCI_STATUS_CAPABILITIES 0x0010
+#define GRUB_PCI_STATUS_66MHZ_CAPABLE 0x0020
+#define GRUB_PCI_STATUS_FAST_B2B_CAPABLE 0x0080
+
+#define GRUB_PCI_STATUS_DEVSEL_TIMING_SHIFT 9
+#define GRUB_PCI_STATUS_DEVSEL_TIMING_MASK 0x0600
+#define GRUB_PCI_CLASS_SUBCLASS_VGA 0x0300
+#define GRUB_PCI_CLASS_SUBCLASS_USB 0x0c03
+
+#ifndef ASM_FILE
+
+enum
+ {
+ GRUB_PCI_CLASS_NETWORK = 0x02
+ };
+enum
+ {
+ GRUB_PCI_CAP_POWER_MANAGEMENT = 0x01
+ };
+
+enum
+ {
+ GRUB_PCI_VENDOR_BROADCOM = 0x14e4
+ };
+
+
+typedef grub_uint32_t grub_pci_id_t;
+
+#ifdef GRUB_MACHINE_EMU
+#include <grub/pciutils.h>
+#else
+typedef grub_uint32_t grub_pci_address_t;
+struct grub_pci_device
+{
+ int bus;
+ int device;
+ int function;
+};
+typedef struct grub_pci_device grub_pci_device_t;
+static inline int
+grub_pci_get_bus (grub_pci_device_t dev)
+{
+ return dev.bus;
+}
+
+static inline int
+grub_pci_get_device (grub_pci_device_t dev)
+{
+ return dev.device;
+}
+
+static inline int
+grub_pci_get_function (grub_pci_device_t dev)
+{
+ return dev.function;
+}
+#include <grub/cpu/pci.h>
+#endif
+
+typedef int (*grub_pci_iteratefunc_t)
+ (grub_pci_device_t dev, grub_pci_id_t pciid, void *data);
+
+grub_pci_address_t EXPORT_FUNC(grub_pci_make_address) (grub_pci_device_t dev,
+ int reg);
+
+void EXPORT_FUNC(grub_pci_iterate) (grub_pci_iteratefunc_t hook,
+ void *hook_data);
+
+#include <grub/dma.h>
+
+grub_uint8_t
+EXPORT_FUNC (grub_pci_find_capability) (grub_pci_device_t dev, grub_uint8_t cap);
+
+#endif
+
+#endif /* GRUB_PCI_H */
diff --git a/include/grub/pciutils.h b/include/grub/pciutils.h
new file mode 100644
index 0000000..36d47e5
--- /dev/null
+++ b/include/grub/pciutils.h
@@ -0,0 +1,103 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_PCIUTILS_H
+#define GRUB_PCIUTILS_H 1
+
+#include <pciaccess.h>
+
+typedef struct pci_device *grub_pci_device_t;
+
+static inline int
+grub_pci_get_bus (grub_pci_device_t dev)
+{
+ return dev->bus;
+}
+
+static inline int
+grub_pci_get_device (grub_pci_device_t dev)
+{
+ return dev->dev;
+}
+
+static inline int
+grub_pci_get_function (grub_pci_device_t dev)
+{
+ return dev->func;
+}
+
+struct grub_pci_address
+{
+ grub_pci_device_t dev;
+ int pos;
+};
+
+typedef struct grub_pci_address grub_pci_address_t;
+
+static inline grub_uint32_t
+grub_pci_read (grub_pci_address_t addr)
+{
+ grub_uint32_t ret;
+ pci_device_cfg_read_u32 (addr.dev, &ret, addr.pos);
+ return ret;
+}
+
+static inline grub_uint16_t
+grub_pci_read_word (grub_pci_address_t addr)
+{
+ grub_uint16_t ret;
+ pci_device_cfg_read_u16 (addr.dev, &ret, addr.pos);
+ return ret;
+}
+
+static inline grub_uint8_t
+grub_pci_read_byte (grub_pci_address_t addr)
+{
+ grub_uint8_t ret;
+ pci_device_cfg_read_u8 (addr.dev, &ret, addr.pos);
+ return ret;
+}
+
+static inline void
+grub_pci_write (grub_pci_address_t addr, grub_uint32_t data)
+{
+ pci_device_cfg_write_u32 (addr.dev, data, addr.pos);
+}
+
+static inline void
+grub_pci_write_word (grub_pci_address_t addr, grub_uint16_t data)
+{
+ pci_device_cfg_write_u16 (addr.dev, data, addr.pos);
+}
+
+static inline void
+grub_pci_write_byte (grub_pci_address_t addr, grub_uint8_t data)
+{
+ pci_device_cfg_write_u8 (addr.dev, data, addr.pos);
+}
+
+void *
+grub_pci_device_map_range (grub_pci_device_t dev, grub_addr_t base,
+ grub_size_t size);
+
+void
+grub_pci_device_unmap_range (grub_pci_device_t dev, void *mem,
+ grub_size_t size);
+
+
+#endif /* GRUB_PCIUTILS_H */
diff --git a/include/grub/powerpc/ieee1275/ieee1275.h b/include/grub/powerpc/ieee1275/ieee1275.h
new file mode 100644
index 0000000..3c7683f
--- /dev/null
+++ b/include/grub/powerpc/ieee1275/ieee1275.h
@@ -0,0 +1,28 @@
+/* ieee1275.h - Access the Open Firmware client interface. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2003,2004,2005,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_IEEE1275_MACHINE_HEADER
+#define GRUB_IEEE1275_MACHINE_HEADER 1
+
+#include <grub/types.h>
+
+#define GRUB_IEEE1275_CELL_SIZEOF 4
+typedef grub_uint32_t grub_ieee1275_cell_t;
+
+#endif /* ! GRUB_IEEE1275_MACHINE_HEADER */
diff --git a/include/grub/powerpc/kernel.h b/include/grub/powerpc/kernel.h
new file mode 100644
index 0000000..3fc0b9e
--- /dev/null
+++ b/include/grub/powerpc/kernel.h
@@ -0,0 +1,22 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2005,2006,2007,2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_KERNEL_CPU_HEADER
+#define GRUB_KERNEL_CPU_HEADER 1
+
+#endif
diff --git a/include/grub/powerpc/memory.h b/include/grub/powerpc/memory.h
new file mode 100644
index 0000000..b748f33
--- /dev/null
+++ b/include/grub/powerpc/memory.h
@@ -0,0 +1,47 @@
+/* memory.h - describe the memory map */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MEMORY_CPU_HEADER
+#define GRUB_MEMORY_CPU_HEADER 1
+
+#ifndef ASM_FILE
+
+typedef grub_addr_t grub_phys_addr_t;
+
+static inline grub_phys_addr_t
+grub_vtop (void *a)
+{
+ return (grub_phys_addr_t) a;
+}
+
+static inline void *
+grub_map_memory (grub_phys_addr_t a, grub_size_t size __attribute__ ((unused)))
+{
+ return (void *) a;
+}
+
+static inline void
+grub_unmap_memory (void *a __attribute__ ((unused)),
+ grub_size_t size __attribute__ ((unused)))
+{
+}
+
+#endif
+
+#endif /* ! GRUB_MEMORY_CPU_HEADER */
diff --git a/include/grub/powerpc/relocator.h b/include/grub/powerpc/relocator.h
new file mode 100644
index 0000000..c2780bb
--- /dev/null
+++ b/include/grub/powerpc/relocator.h
@@ -0,0 +1,37 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009,2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_RELOCATOR_CPU_HEADER
+#define GRUB_RELOCATOR_CPU_HEADER 1
+
+#include <grub/types.h>
+#include <grub/err.h>
+#include <grub/relocator.h>
+
+#define GRUB_PPC_JUMP_REGISTER 31
+
+struct grub_relocator32_state
+{
+ grub_uint32_t gpr[32];
+};
+
+grub_err_t
+grub_relocator32_boot (struct grub_relocator *rel,
+ struct grub_relocator32_state state);
+
+#endif /* ! GRUB_RELOCATOR_CPU_HEADER */
diff --git a/include/grub/powerpc/setjmp.h b/include/grub/powerpc/setjmp.h
new file mode 100644
index 0000000..7c2d184
--- /dev/null
+++ b/include/grub/powerpc/setjmp.h
@@ -0,0 +1,27 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2004,2006,2007,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_SETJMP_CPU_HEADER
+#define GRUB_SETJMP_CPU_HEADER 1
+
+typedef unsigned long grub_jmp_buf[21];
+
+int grub_setjmp (grub_jmp_buf env) RETURNS_TWICE;
+void grub_longjmp (grub_jmp_buf env, int val) __attribute__ ((noreturn));
+
+#endif /* ! GRUB_SETJMP_CPU_HEADER */
diff --git a/include/grub/powerpc/time.h b/include/grub/powerpc/time.h
new file mode 100644
index 0000000..5db7ff4
--- /dev/null
+++ b/include/grub/powerpc/time.h
@@ -0,0 +1,28 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef KERNEL_CPU_TIME_HEADER
+#define KERNEL_CPU_TIME_HEADER 1
+
+static __inline void
+grub_cpu_idle (void)
+{
+ /* FIXME: not implemented */
+}
+
+#endif /* ! KERNEL_CPU_TIME_HEADER */
diff --git a/include/grub/powerpc/types.h b/include/grub/powerpc/types.h
new file mode 100644
index 0000000..a098ae6
--- /dev/null
+++ b/include/grub/powerpc/types.h
@@ -0,0 +1,32 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2004,2006,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_TYPES_CPU_HEADER
+#define GRUB_TYPES_CPU_HEADER 1
+
+/* The size of void *. */
+#define GRUB_TARGET_SIZEOF_VOID_P 4
+
+/* The size of long. */
+#define GRUB_TARGET_SIZEOF_LONG 4
+
+/* powerpc is big-endian. */
+#define GRUB_TARGET_WORDS_BIGENDIAN 1
+
+
+#endif /* ! GRUB_TYPES_CPU_HEADER */
diff --git a/include/grub/priority_queue.h b/include/grub/priority_queue.h
new file mode 100644
index 0000000..64cbc45
--- /dev/null
+++ b/include/grub/priority_queue.h
@@ -0,0 +1,44 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2011 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_PRIORITY_QUEUE_HEADER
+#define GRUB_PRIORITY_QUEUE_HEADER 1
+
+#include <grub/misc.h>
+#include <grub/err.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct grub_priority_queue;
+typedef struct grub_priority_queue *grub_priority_queue_t;
+typedef int (*grub_comparator_t) (const void *a, const void *b);
+
+grub_priority_queue_t grub_priority_queue_new (grub_size_t elsize,
+ grub_comparator_t cmp);
+void grub_priority_queue_destroy (grub_priority_queue_t pq);
+void *grub_priority_queue_top (grub_priority_queue_t pq);
+void grub_priority_queue_pop (grub_priority_queue_t pq);
+grub_err_t grub_priority_queue_push (grub_priority_queue_t pq, const void *el);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/include/grub/procfs.h b/include/grub/procfs.h
new file mode 100644
index 0000000..8cc331d
--- /dev/null
+++ b/include/grub/procfs.h
@@ -0,0 +1,51 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_PROCFS_HEADER
+#define GRUB_PROCFS_HEADER 1
+
+#include <grub/list.h>
+#include <grub/types.h>
+
+struct grub_procfs_entry
+{
+ struct grub_procfs_entry *next;
+ struct grub_procfs_entry **prev;
+
+ const char *name;
+ char * (*get_contents) (grub_size_t *sz);
+};
+
+extern struct grub_procfs_entry *grub_procfs_entries;
+
+static inline void
+grub_procfs_register (const char *name __attribute__ ((unused)),
+ struct grub_procfs_entry *entry)
+{
+ grub_list_push (GRUB_AS_LIST_P (&grub_procfs_entries),
+ GRUB_AS_LIST (entry));
+}
+
+static inline void
+grub_procfs_unregister (struct grub_procfs_entry *entry)
+{
+ grub_list_remove (GRUB_AS_LIST (entry));
+}
+
+
+#endif
diff --git a/include/grub/ps2.h b/include/grub/ps2.h
new file mode 100644
index 0000000..4f2e527
--- /dev/null
+++ b/include/grub/ps2.h
@@ -0,0 +1,43 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_PS2_HEADER
+#define GRUB_PS2_HEADER 1
+
+#include <grub/types.h>
+
+#define GRUB_AT_ACK 0xfa
+#define GRUB_AT_NACK 0xfe
+#define GRUB_AT_TRIES 5
+
+/* Make sure it's zeroed-out and set current_set at init. */
+struct grub_ps2_state
+{
+ int e0_received;
+ int f0_received;
+ grub_uint8_t led_status;
+ short at_keyboard_status;
+ grub_uint8_t current_set;
+};
+
+/* If there is a key pending, return it; otherwise return GRUB_TERM_NO_KEY. */
+int
+grub_ps2_process_incoming_byte (struct grub_ps2_state *ps2_state,
+ grub_uint8_t data);
+
+#endif
diff --git a/include/grub/pubkey.h b/include/grub/pubkey.h
new file mode 100644
index 0000000..fb8be9c
--- /dev/null
+++ b/include/grub/pubkey.h
@@ -0,0 +1,38 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_PUBKEY_HEADER
+#define GRUB_PUBKEY_HEADER 1
+
+#include <grub/crypto.h>
+
+struct grub_public_key *
+grub_load_public_key (grub_file_t f);
+
+grub_err_t
+grub_verify_signature (grub_file_t f, const char *fsig,
+ struct grub_public_key *pk);
+
+
+struct grub_public_subkey *
+grub_crypto_pk_locate_subkey (grub_uint64_t keyid, struct grub_public_key *pkey);
+
+struct grub_public_subkey *
+grub_crypto_pk_locate_subkey_in_trustdb (grub_uint64_t keyid);
+
+#endif
diff --git a/include/grub/random.h b/include/grub/random.h
new file mode 100644
index 0000000..4b75c0e
--- /dev/null
+++ b/include/grub/random.h
@@ -0,0 +1,33 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2016 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_RANDOM_HEADER
+#define GRUB_RANDOM_HEADER 1
+
+#include <grub/types.h>
+#include <grub/err.h>
+
+/* Not peer-reviewed. May not be any better than string of zeros. */
+grub_err_t
+grub_crypto_get_random (void *buffer, grub_size_t sz);
+
+/* Do not use directly. Use grub_crypto_get_random instead. */
+int
+grub_crypto_arch_get_random (void *buffer, grub_size_t sz);
+
+#endif
diff --git a/include/grub/reader.h b/include/grub/reader.h
new file mode 100644
index 0000000..fd86b20
--- /dev/null
+++ b/include/grub/reader.h
@@ -0,0 +1,29 @@
+/* reader.h - prototypes for command line reader. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_READER_HEADER
+#define GRUB_READER_HEADER 1
+
+#include <grub/err.h>
+
+typedef grub_err_t (*grub_reader_getline_t) (char **, int, void *);
+
+void grub_rescue_run (void) __attribute__ ((noreturn));
+
+#endif /* ! GRUB_READER_HEADER */
diff --git a/include/grub/reed_solomon.h b/include/grub/reed_solomon.h
new file mode 100644
index 0000000..596dff2
--- /dev/null
+++ b/include/grub/reed_solomon.h
@@ -0,0 +1,30 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_REED_SOLOMON_HEADER
+#define GRUB_REED_SOLOMON_HEADER 1
+
+void
+grub_reed_solomon_add_redundancy (void *buffer, grub_size_t data_size,
+ grub_size_t redundancy);
+
+void
+grub_reed_solomon_recover (void *buffer, grub_size_t data_size,
+ grub_size_t redundancy);
+
+#endif
diff --git a/include/grub/relocator.h b/include/grub/relocator.h
new file mode 100644
index 0000000..1b3bdd9
--- /dev/null
+++ b/include/grub/relocator.h
@@ -0,0 +1,88 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_RELOCATOR_HEADER
+#define GRUB_RELOCATOR_HEADER 1
+
+#include <grub/types.h>
+#include <grub/err.h>
+#include <grub/memory.h>
+#include <grub/cpu/memory.h>
+
+struct grub_relocator;
+struct grub_relocator_chunk;
+typedef const struct grub_relocator_chunk *grub_relocator_chunk_t;
+
+struct grub_relocator *grub_relocator_new (void);
+
+grub_err_t
+grub_relocator_alloc_chunk_addr (struct grub_relocator *rel,
+ grub_relocator_chunk_t *out,
+ grub_phys_addr_t target, grub_size_t size);
+
+void *
+get_virtual_current_address (grub_relocator_chunk_t in);
+grub_phys_addr_t
+get_physical_target_address (grub_relocator_chunk_t in);
+
+grub_err_t
+grub_relocator_alloc_chunk_align (struct grub_relocator *rel,
+ grub_relocator_chunk_t *out,
+ grub_phys_addr_t min_addr,
+ grub_phys_addr_t max_addr,
+ grub_size_t size, grub_size_t align,
+ int preference,
+ int avoid_efi_boot_services);
+
+/*
+ * Wrapper for grub_relocator_alloc_chunk_align() with purpose of
+ * protecting against integer underflow.
+ *
+ * Compare to its callee, max_addr has different meaning here.
+ * It covers entire chunk and not just start address of the chunk.
+ */
+static inline grub_err_t
+grub_relocator_alloc_chunk_align_safe (struct grub_relocator *rel,
+ grub_relocator_chunk_t *out,
+ grub_phys_addr_t min_addr,
+ grub_phys_addr_t max_addr,
+ grub_size_t size, grub_size_t align,
+ int preference,
+ int avoid_efi_boot_services)
+{
+ /* Sanity check and ensure following equation (max_addr - size) is safe. */
+ if (max_addr < size || (max_addr - size) < min_addr)
+ return GRUB_ERR_OUT_OF_RANGE;
+
+ return grub_relocator_alloc_chunk_align (rel, out, min_addr,
+ max_addr - size,
+ size, align, preference,
+ avoid_efi_boot_services);
+}
+
+/* Top 32-bit address minus s bytes and plus 1 byte. */
+#define UP_TO_TOP32(s) ((~(s) & 0xffffffff) + 1)
+
+#define GRUB_RELOCATOR_PREFERENCE_NONE 0
+#define GRUB_RELOCATOR_PREFERENCE_LOW 1
+#define GRUB_RELOCATOR_PREFERENCE_HIGH 2
+
+void
+grub_relocator_unload (struct grub_relocator *rel);
+
+#endif
diff --git a/include/grub/relocator_private.h b/include/grub/relocator_private.h
new file mode 100644
index 0000000..1c563cb
--- /dev/null
+++ b/include/grub/relocator_private.h
@@ -0,0 +1,113 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_RELOCATOR_PRIVATE_HEADER
+#define GRUB_RELOCATOR_PRIVATE_HEADER 1
+
+#include <grub/types.h>
+#include <grub/err.h>
+#include <grub/mm_private.h>
+
+extern grub_size_t grub_relocator_align;
+extern grub_size_t grub_relocator_forward_size;
+extern grub_size_t grub_relocator_backward_size;
+extern grub_size_t grub_relocator_jumper_size;
+
+void
+grub_cpu_relocator_init (void);
+grub_err_t
+grub_relocator_prepare_relocs (struct grub_relocator *rel,
+ grub_addr_t addr,
+ void **relstart, grub_size_t *relsize);
+void grub_cpu_relocator_forward (void *rels, void *src, void *tgt,
+ grub_size_t size);
+void grub_cpu_relocator_backward (void *rels, void *src, void *tgt,
+ grub_size_t size);
+void grub_cpu_relocator_jumper (void *rels, grub_addr_t addr);
+
+/* Remark: GRUB_RELOCATOR_FIRMWARE_REQUESTS_QUANT_LOG = 1 or 2
+ aren't supported. */
+#ifdef GRUB_MACHINE_IEEE1275
+#define GRUB_RELOCATOR_HAVE_FIRMWARE_REQUESTS 1
+#define GRUB_RELOCATOR_FIRMWARE_REQUESTS_QUANT_LOG 0
+#elif defined (GRUB_MACHINE_EFI)
+#define GRUB_RELOCATOR_HAVE_FIRMWARE_REQUESTS 1
+#define GRUB_RELOCATOR_FIRMWARE_REQUESTS_QUANT_LOG 12
+#else
+#define GRUB_RELOCATOR_HAVE_FIRMWARE_REQUESTS 0
+#endif
+
+#if GRUB_RELOCATOR_HAVE_FIRMWARE_REQUESTS && GRUB_RELOCATOR_FIRMWARE_REQUESTS_QUANT_LOG != 0
+#define GRUB_RELOCATOR_HAVE_LEFTOVERS 1
+#else
+#define GRUB_RELOCATOR_HAVE_LEFTOVERS 0
+#endif
+
+#if GRUB_RELOCATOR_HAVE_FIRMWARE_REQUESTS
+#define GRUB_RELOCATOR_FIRMWARE_REQUESTS_QUANT (1 << GRUB_RELOCATOR_FIRMWARE_REQUESTS_QUANT_LOG)
+#endif
+
+struct grub_relocator_mmap_event
+{
+ enum {
+ IN_REG_START = 0,
+ IN_REG_END = 1,
+ REG_BEG_START = 2,
+ REG_BEG_END = REG_BEG_START | 1,
+#if GRUB_RELOCATOR_HAVE_FIRMWARE_REQUESTS
+ REG_FIRMWARE_START = 4,
+ REG_FIRMWARE_END = REG_FIRMWARE_START | 1,
+ /* To track the regions already in heap. */
+ FIRMWARE_BLOCK_START = 6,
+ FIRMWARE_BLOCK_END = FIRMWARE_BLOCK_START | 1,
+#endif
+#if GRUB_RELOCATOR_HAVE_LEFTOVERS
+ REG_LEFTOVER_START = 8,
+ REG_LEFTOVER_END = REG_LEFTOVER_START | 1,
+#endif
+ COLLISION_START = 10,
+ COLLISION_END = COLLISION_START | 1
+ } type;
+ grub_phys_addr_t pos;
+ union
+ {
+ struct
+ {
+ grub_mm_region_t reg;
+ grub_mm_header_t hancestor;
+ grub_mm_region_t *regancestor;
+ grub_mm_header_t head;
+ };
+#if GRUB_RELOCATOR_HAVE_FIRMWARE_REQUESTS
+ struct grub_relocator_fw_leftover *leftover;
+#endif
+ };
+};
+
+/* Return 0 on failure, 1 on success. The failure here
+ can be very time-expensive, so please make sure fill events is accurate. */
+#if GRUB_RELOCATOR_HAVE_FIRMWARE_REQUESTS
+int grub_relocator_firmware_alloc_region (grub_phys_addr_t start,
+ grub_size_t size);
+unsigned grub_relocator_firmware_fill_events (struct grub_relocator_mmap_event *events);
+unsigned grub_relocator_firmware_get_max_events (void);
+void grub_relocator_firmware_free_region (grub_phys_addr_t start,
+ grub_size_t size);
+#endif
+
+#endif
diff --git a/include/grub/riscv32/efi/memory.h b/include/grub/riscv32/efi/memory.h
new file mode 100644
index 0000000..e61c474
--- /dev/null
+++ b/include/grub/riscv32/efi/memory.h
@@ -0,0 +1,6 @@
+#ifndef GRUB_MEMORY_CPU_HEADER
+#include <grub/efi/memory.h>
+
+#define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffffUL
+
+#endif /* ! GRUB_MEMORY_CPU_HEADER */
diff --git a/include/grub/riscv32/linux.h b/include/grub/riscv32/linux.h
new file mode 100644
index 0000000..512b777
--- /dev/null
+++ b/include/grub/riscv32/linux.h
@@ -0,0 +1,41 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2018 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_RISCV32_LINUX_HEADER
+#define GRUB_RISCV32_LINUX_HEADER 1
+
+#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x52534356 /* 'RSCV' */
+
+/* From linux/Documentation/riscv/booting.txt */
+struct linux_riscv_kernel_header
+{
+ grub_uint32_t code0; /* Executable code */
+ grub_uint32_t code1; /* Executable code */
+ grub_uint64_t text_offset; /* Image load offset */
+ grub_uint64_t res0; /* reserved */
+ grub_uint64_t res1; /* reserved */
+ grub_uint64_t res2; /* reserved */
+ grub_uint64_t res3; /* reserved */
+ grub_uint64_t res4; /* reserved */
+ grub_uint32_t magic; /* Magic number, little endian, "RSCV" */
+ grub_uint32_t hdr_offset; /* Offset of PE/COFF header */
+};
+
+#define linux_arch_kernel_header linux_riscv_kernel_header
+
+#endif /* ! GRUB_RISCV32_LINUX_HEADER */
diff --git a/include/grub/riscv32/setjmp.h b/include/grub/riscv32/setjmp.h
new file mode 100644
index 0000000..5a21238
--- /dev/null
+++ b/include/grub/riscv32/setjmp.h
@@ -0,0 +1,27 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2018 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_SETJMP_CPU_HEADER
+#define GRUB_SETJMP_CPU_HEADER 1
+
+typedef unsigned long long grub_jmp_buf[14];
+
+int grub_setjmp (grub_jmp_buf env) RETURNS_TWICE;
+void grub_longjmp (grub_jmp_buf env, int val) __attribute__ ((noreturn));
+
+#endif /* ! GRUB_SETJMP_CPU_HEADER */
diff --git a/include/grub/riscv32/time.h b/include/grub/riscv32/time.h
new file mode 100644
index 0000000..20abd64
--- /dev/null
+++ b/include/grub/riscv32/time.h
@@ -0,0 +1,28 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2018 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef KERNEL_CPU_TIME_HEADER
+#define KERNEL_CPU_TIME_HEADER 1
+
+static __inline void
+grub_cpu_idle (void)
+{
+ /* TODO */
+}
+
+#endif /* ! KERNEL_CPU_TIME_HEADER */
diff --git a/include/grub/riscv32/types.h b/include/grub/riscv32/types.h
new file mode 100644
index 0000000..fac57a7
--- /dev/null
+++ b/include/grub/riscv32/types.h
@@ -0,0 +1,34 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2018 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_TYPES_CPU_HEADER
+#define GRUB_TYPES_CPU_HEADER 1
+
+/* The size of void *. */
+#define GRUB_TARGET_SIZEOF_VOID_P 4
+
+/* The size of long. */
+#define GRUB_TARGET_SIZEOF_LONG 4
+
+/* currently only support little-endian. */
+#undef GRUB_TARGET_WORDS_BIGENDIAN
+
+/* Unaligned accesses can be very slow, so avoid them */
+#undef GRUB_HAVE_UNALIGNED_ACCESS
+
+#endif /* ! GRUB_TYPES_CPU_HEADER */
diff --git a/include/grub/riscv64/efi/memory.h b/include/grub/riscv64/efi/memory.h
new file mode 100644
index 0000000..c6cb324
--- /dev/null
+++ b/include/grub/riscv64/efi/memory.h
@@ -0,0 +1,6 @@
+#ifndef GRUB_MEMORY_CPU_HEADER
+#include <grub/efi/memory.h>
+
+#define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffffffffULL
+
+#endif /* ! GRUB_MEMORY_CPU_HEADER */
diff --git a/include/grub/riscv64/linux.h b/include/grub/riscv64/linux.h
new file mode 100644
index 0000000..3630c30
--- /dev/null
+++ b/include/grub/riscv64/linux.h
@@ -0,0 +1,43 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2018 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_RISCV64_LINUX_HEADER
+#define GRUB_RISCV64_LINUX_HEADER 1
+
+#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x52534356 /* 'RSCV' */
+
+#define GRUB_EFI_PE_MAGIC 0x5A4D
+
+/* From linux/Documentation/riscv/booting.txt */
+struct linux_riscv_kernel_header
+{
+ grub_uint32_t code0; /* Executable code */
+ grub_uint32_t code1; /* Executable code */
+ grub_uint64_t text_offset; /* Image load offset */
+ grub_uint64_t res0; /* reserved */
+ grub_uint64_t res1; /* reserved */
+ grub_uint64_t res2; /* reserved */
+ grub_uint64_t res3; /* reserved */
+ grub_uint64_t res4; /* reserved */
+ grub_uint32_t magic; /* Magic number, little endian, "RSCV" */
+ grub_uint32_t hdr_offset; /* Offset of PE/COFF header */
+};
+
+#define linux_arch_kernel_header linux_riscv_kernel_header
+
+#endif /* ! GRUB_RISCV64_LINUX_HEADER */
diff --git a/include/grub/riscv64/setjmp.h b/include/grub/riscv64/setjmp.h
new file mode 100644
index 0000000..5a21238
--- /dev/null
+++ b/include/grub/riscv64/setjmp.h
@@ -0,0 +1,27 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2018 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_SETJMP_CPU_HEADER
+#define GRUB_SETJMP_CPU_HEADER 1
+
+typedef unsigned long long grub_jmp_buf[14];
+
+int grub_setjmp (grub_jmp_buf env) RETURNS_TWICE;
+void grub_longjmp (grub_jmp_buf env, int val) __attribute__ ((noreturn));
+
+#endif /* ! GRUB_SETJMP_CPU_HEADER */
diff --git a/include/grub/riscv64/time.h b/include/grub/riscv64/time.h
new file mode 100644
index 0000000..20abd64
--- /dev/null
+++ b/include/grub/riscv64/time.h
@@ -0,0 +1,28 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2018 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef KERNEL_CPU_TIME_HEADER
+#define KERNEL_CPU_TIME_HEADER 1
+
+static __inline void
+grub_cpu_idle (void)
+{
+ /* TODO */
+}
+
+#endif /* ! KERNEL_CPU_TIME_HEADER */
diff --git a/include/grub/riscv64/types.h b/include/grub/riscv64/types.h
new file mode 100644
index 0000000..c6bcad4
--- /dev/null
+++ b/include/grub/riscv64/types.h
@@ -0,0 +1,34 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2018 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_TYPES_CPU_HEADER
+#define GRUB_TYPES_CPU_HEADER 1
+
+/* The size of void *. */
+#define GRUB_TARGET_SIZEOF_VOID_P 8
+
+/* The size of long. */
+#define GRUB_TARGET_SIZEOF_LONG 8
+
+/* currently only support little-endian. */
+#undef GRUB_TARGET_WORDS_BIGENDIAN
+
+/* Unaligned accesses can be very slow, so avoid them */
+#undef GRUB_HAVE_UNALIGNED_ACCESS
+
+#endif /* ! GRUB_TYPES_CPU_HEADER */
diff --git a/include/grub/safemath.h b/include/grub/safemath.h
new file mode 100644
index 0000000..c17b89b
--- /dev/null
+++ b/include/grub/safemath.h
@@ -0,0 +1,37 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2020 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Arithmetic operations that protect against overflow.
+ */
+
+#ifndef GRUB_SAFEMATH_H
+#define GRUB_SAFEMATH_H 1
+
+#include <grub/compiler.h>
+
+/* These appear in gcc 5.1 and clang 3.8. */
+#if GNUC_PREREQ(5, 1) || CLANG_PREREQ(3, 8)
+
+#define grub_add(a, b, res) __builtin_add_overflow(a, b, res)
+#define grub_sub(a, b, res) __builtin_sub_overflow(a, b, res)
+#define grub_mul(a, b, res) __builtin_mul_overflow(a, b, res)
+
+#else
+#error gcc 5.1 or newer or clang 3.8 or newer is required
+#endif
+
+#endif /* GRUB_SAFEMATH_H */
diff --git a/include/grub/script_sh.h b/include/grub/script_sh.h
new file mode 100644
index 0000000..e5b4d84
--- /dev/null
+++ b/include/grub/script_sh.h
@@ -0,0 +1,410 @@
+/* normal_parser.h */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2005,2007,2009,2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_NORMAL_PARSER_HEADER
+#define GRUB_NORMAL_PARSER_HEADER 1
+
+#include <grub/types.h>
+#include <grub/err.h>
+#include <grub/parser.h>
+#include <grub/command.h>
+
+struct grub_script_mem;
+
+/* The generic header for each scripting command or structure. */
+struct grub_script_cmd
+{
+ /* This function is called to execute the command. */
+ grub_err_t (*exec) (struct grub_script_cmd *cmd);
+
+ /* The next command. This can be used by the parent to form a chain
+ of commands. */
+ struct grub_script_cmd *next;
+};
+
+struct grub_script
+{
+ unsigned refcnt;
+ struct grub_script_mem *mem;
+ struct grub_script_cmd *cmd;
+
+ /* grub_scripts from block arguments. */
+ struct grub_script *next_siblings;
+ struct grub_script *children;
+};
+
+typedef enum
+{
+ GRUB_SCRIPT_ARG_TYPE_VAR,
+ GRUB_SCRIPT_ARG_TYPE_TEXT,
+ GRUB_SCRIPT_ARG_TYPE_GETTEXT,
+ GRUB_SCRIPT_ARG_TYPE_DQVAR,
+ GRUB_SCRIPT_ARG_TYPE_DQSTR,
+ GRUB_SCRIPT_ARG_TYPE_SQSTR,
+ GRUB_SCRIPT_ARG_TYPE_BLOCK
+} grub_script_arg_type_t;
+
+/* A part of an argument. */
+struct grub_script_arg
+{
+ grub_script_arg_type_t type;
+
+ char *str;
+
+ /* Parsed block argument. */
+ struct grub_script *script;
+
+ /* Next argument part. */
+ struct grub_script_arg *next;
+};
+
+/* An argument vector. */
+struct grub_script_argv
+{
+ unsigned argc;
+ char **args;
+ struct grub_script *script;
+};
+
+/* Pluggable wildcard translator. */
+struct grub_script_wildcard_translator
+{
+ grub_err_t (*expand) (const char *str, char ***expansions);
+};
+extern struct grub_script_wildcard_translator *grub_wildcard_translator;
+extern struct grub_script_wildcard_translator grub_filename_translator;
+
+/* A complete argument. It consists of a list of one or more `struct
+ grub_script_arg's. */
+struct grub_script_arglist
+{
+ struct grub_script_arglist *next;
+ struct grub_script_arg *arg;
+ /* Only stored in the first link. */
+ int argcount;
+};
+
+/* A single command line. */
+struct grub_script_cmdline
+{
+ struct grub_script_cmd cmd;
+
+ /* The arguments for this command. */
+ struct grub_script_arglist *arglist;
+};
+
+/* An if statement. */
+struct grub_script_cmdif
+{
+ struct grub_script_cmd cmd;
+
+ /* The command used to check if the 'if' is true or false. */
+ struct grub_script_cmd *exec_to_evaluate;
+
+ /* The code executed in case the result of 'if' was true. */
+ struct grub_script_cmd *exec_on_true;
+
+ /* The code executed in case the result of 'if' was false. */
+ struct grub_script_cmd *exec_on_false;
+};
+
+/* A for statement. */
+struct grub_script_cmdfor
+{
+ struct grub_script_cmd cmd;
+
+ /* The name used as looping variable. */
+ struct grub_script_arg *name;
+
+ /* The words loop iterates over. */
+ struct grub_script_arglist *words;
+
+ /* The command list executed in each loop. */
+ struct grub_script_cmd *list;
+};
+
+/* A while/until command. */
+struct grub_script_cmdwhile
+{
+ struct grub_script_cmd cmd;
+
+ /* The command list used as condition. */
+ struct grub_script_cmd *cond;
+
+ /* The command list executed in each loop. */
+ struct grub_script_cmd *list;
+
+ /* The flag to indicate this as "until" loop. */
+ int until;
+};
+
+/* State of the lexer as passed to the lexer. */
+struct grub_lexer_param
+{
+ /* Function used by the lexer to get a new line when more input is
+ expected, but not available. */
+ grub_reader_getline_t getline;
+
+ /* Caller-supplied data passed to `getline'. */
+ void *getline_data;
+
+ /* A reference counter. If this is >0 it means that the parser
+ expects more tokens and `getline' should be called to fetch more.
+ Otherwise the lexer can stop processing if the current buffer is
+ depleted. */
+ int refs;
+
+ /* While walking through the databuffer, `record' the characters to
+ this other buffer. It can be used to edit the menu entry at a
+ later moment. */
+
+ /* If true, recording is enabled. */
+ int record;
+
+ /* Points to the recording. */
+ char *recording;
+
+ /* index in the RECORDING. */
+ int recordpos;
+
+ /* Size of RECORDING. */
+ int recordlen;
+
+ /* End of file reached. */
+ int eof;
+
+ /* Merge multiple word tokens. */
+ int merge_start;
+ int merge_end;
+
+ /* Part of a multi-part token. */
+ char *text;
+ unsigned used;
+ unsigned size;
+
+ /* Type of text. */
+ grub_script_arg_type_t type;
+
+ /* Flag to indicate resplit in progres. */
+ unsigned resplit;
+
+ /* Text that is unput. */
+ char *prefix;
+
+ /* Flex scanner. */
+ void *yyscanner;
+
+ /* Flex scanner buffer. */
+ void *buffer;
+};
+
+#define GRUB_LEXER_INITIAL_TEXT_SIZE 32
+#define GRUB_LEXER_INITIAL_RECORD_SIZE 256
+
+/* State of the parser as passes to the parser. */
+struct grub_parser_param
+{
+ /* Keep track of the memory allocated for this specific
+ function. */
+ struct grub_script_mem *func_mem;
+
+ /* When set to 0, no errors have occurred during parsing. */
+ int err;
+
+ /* The memory that was used while parsing and scanning. */
+ struct grub_script_mem *memused;
+
+ /* The block argument scripts. */
+ struct grub_script *scripts;
+
+ /* The result of the parser. */
+ struct grub_script_cmd *parsed;
+
+ struct grub_lexer_param *lexerstate;
+};
+
+void grub_script_init (void);
+void grub_script_fini (void);
+
+void grub_script_mem_free (struct grub_script_mem *mem);
+
+void grub_script_argv_free (struct grub_script_argv *argv);
+int grub_script_argv_make (struct grub_script_argv *argv, int argc, char **args);
+int grub_script_argv_next (struct grub_script_argv *argv);
+int grub_script_argv_append (struct grub_script_argv *argv, const char *s,
+ grub_size_t slen);
+int grub_script_argv_split_append (struct grub_script_argv *argv, const char *s);
+
+struct grub_script_arglist *
+grub_script_create_arglist (struct grub_parser_param *state);
+
+struct grub_script_arglist *
+grub_script_add_arglist (struct grub_parser_param *state,
+ struct grub_script_arglist *list,
+ struct grub_script_arg *arg);
+struct grub_script_cmd *
+grub_script_create_cmdline (struct grub_parser_param *state,
+ struct grub_script_arglist *arglist);
+
+struct grub_script_cmd *
+grub_script_create_cmdif (struct grub_parser_param *state,
+ struct grub_script_cmd *exec_to_evaluate,
+ struct grub_script_cmd *exec_on_true,
+ struct grub_script_cmd *exec_on_false);
+
+struct grub_script_cmd *
+grub_script_create_cmdfor (struct grub_parser_param *state,
+ struct grub_script_arg *name,
+ struct grub_script_arglist *words,
+ struct grub_script_cmd *list);
+
+struct grub_script_cmd *
+grub_script_create_cmdwhile (struct grub_parser_param *state,
+ struct grub_script_cmd *cond,
+ struct grub_script_cmd *list,
+ int is_an_until_loop);
+
+struct grub_script_cmd *
+grub_script_append_cmd (struct grub_parser_param *state,
+ struct grub_script_cmd *list,
+ struct grub_script_cmd *last);
+struct grub_script_arg *
+grub_script_arg_add (struct grub_parser_param *state,
+ struct grub_script_arg *arg,
+ grub_script_arg_type_t type, char *str);
+
+struct grub_script *grub_script_parse (char *script,
+ grub_reader_getline_t getline_func,
+ void *getline_func_data);
+void grub_script_free (struct grub_script *script);
+struct grub_script *grub_script_create (struct grub_script_cmd *cmd,
+ struct grub_script_mem *mem);
+
+struct grub_lexer_param *grub_script_lexer_init (struct grub_parser_param *parser,
+ char *script,
+ grub_reader_getline_t getline_func,
+ void *getline_func_data);
+void grub_script_lexer_fini (struct grub_lexer_param *);
+void grub_script_lexer_ref (struct grub_lexer_param *);
+void grub_script_lexer_deref (struct grub_lexer_param *);
+unsigned grub_script_lexer_record_start (struct grub_parser_param *);
+char *grub_script_lexer_record_stop (struct grub_parser_param *, unsigned);
+int grub_script_lexer_yywrap (struct grub_parser_param *, const char *input);
+void grub_script_lexer_record (struct grub_parser_param *, char *);
+
+/* Functions to track allocated memory. */
+struct grub_script_mem *grub_script_mem_record (struct grub_parser_param *state);
+struct grub_script_mem *grub_script_mem_record_stop (struct grub_parser_param *state,
+ struct grub_script_mem *restore);
+void *grub_script_malloc (struct grub_parser_param *state, grub_size_t size);
+
+/* Functions used by bison. */
+union YYSTYPE;
+int grub_script_yylex (union YYSTYPE *, struct grub_parser_param *);
+int grub_script_yyparse (struct grub_parser_param *);
+void grub_script_yyerror (struct grub_parser_param *, const char *);
+
+/* Commands to execute, don't use these directly. */
+grub_err_t grub_script_execute_cmdline (struct grub_script_cmd *cmd);
+grub_err_t grub_script_execute_cmdlist (struct grub_script_cmd *cmd);
+grub_err_t grub_script_execute_cmdif (struct grub_script_cmd *cmd);
+grub_err_t grub_script_execute_cmdfor (struct grub_script_cmd *cmd);
+grub_err_t grub_script_execute_cmdwhile (struct grub_script_cmd *cmd);
+
+/* Execute any GRUB pre-parsed command or script. */
+grub_err_t grub_script_execute (struct grub_script *script);
+grub_err_t grub_script_execute_sourcecode (const char *source);
+grub_err_t grub_script_execute_new_scope (const char *source, int argc, char **args);
+
+/* Break command for loops. */
+grub_err_t grub_script_break (grub_command_t cmd, int argc, char *argv[]);
+
+/* SHIFT command for GRUB script. */
+grub_err_t grub_script_shift (grub_command_t cmd, int argc, char *argv[]);
+
+/* SETPARAMS command for GRUB script functions. */
+grub_err_t grub_script_setparams (grub_command_t cmd, int argc, char *argv[]);
+
+/* RETURN command for functions. */
+grub_err_t grub_script_return (grub_command_t cmd, int argc, char *argv[]);
+
+/* This variable points to the parsed command. This is used to
+ communicate with the bison code. */
+extern struct grub_script_cmd *grub_script_parsed;
+
+
+
+/* The function description. */
+struct grub_script_function
+{
+ /* The name. */
+ char *name;
+
+ /* The script function. */
+ struct grub_script *func;
+
+ /* The next element. */
+ struct grub_script_function *next;
+
+ unsigned executing;
+};
+typedef struct grub_script_function *grub_script_function_t;
+
+extern grub_script_function_t grub_script_function_list;
+
+#define FOR_SCRIPT_FUNCTIONS(var) for((var) = grub_script_function_list; \
+ (var); (var) = (var)->next)
+
+grub_script_function_t grub_script_function_create (struct grub_script_arg *functionname,
+ struct grub_script *cmd);
+void grub_script_function_remove (const char *name);
+grub_script_function_t grub_script_function_find (char *functionname);
+
+grub_err_t grub_script_function_call (grub_script_function_t func,
+ int argc, char **args);
+
+char **
+grub_script_execute_arglist_to_argv (struct grub_script_arglist *arglist, int *count);
+
+grub_err_t
+grub_normal_parse_line (char *line,
+ grub_reader_getline_t getline_func,
+ void *getline_func_data);
+
+static inline struct grub_script *
+grub_script_ref (struct grub_script *script)
+{
+ if (script)
+ script->refcnt++;
+ return script;
+}
+
+static inline void
+grub_script_unref (struct grub_script *script)
+{
+ if (! script)
+ return;
+
+ if (script->refcnt == 0)
+ grub_script_free (script);
+ else
+ script->refcnt--;
+}
+
+#endif /* ! GRUB_NORMAL_PARSER_HEADER */
diff --git a/include/grub/scsi.h b/include/grub/scsi.h
new file mode 100644
index 0000000..a919a7c
--- /dev/null
+++ b/include/grub/scsi.h
@@ -0,0 +1,111 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_SCSI_H
+#define GRUB_SCSI_H 1
+
+#include <grub/disk.h>
+
+typedef struct grub_scsi_dev *grub_scsi_dev_t;
+
+void grub_scsi_dev_register (grub_scsi_dev_t dev);
+void grub_scsi_dev_unregister (grub_scsi_dev_t dev);
+
+struct grub_scsi;
+
+enum
+ {
+ GRUB_SCSI_SUBSYSTEM_USBMS,
+ GRUB_SCSI_SUBSYSTEM_PATA,
+ GRUB_SCSI_SUBSYSTEM_AHCI,
+ GRUB_SCSI_NUM_SUBSYSTEMS
+ };
+
+extern const char grub_scsi_names[GRUB_SCSI_NUM_SUBSYSTEMS][5];
+
+#define GRUB_SCSI_ID_SUBSYSTEM_SHIFT 24
+#define GRUB_SCSI_ID_BUS_SHIFT 8
+#define GRUB_SCSI_ID_LUN_SHIFT 0
+
+static inline grub_uint32_t
+grub_make_scsi_id (int subsystem, int bus, int lun)
+{
+ return (subsystem << GRUB_SCSI_ID_SUBSYSTEM_SHIFT)
+ | (bus << GRUB_SCSI_ID_BUS_SHIFT) | (lun << GRUB_SCSI_ID_LUN_SHIFT);
+}
+
+typedef int (*grub_scsi_dev_iterate_hook_t) (int id, int bus, int luns,
+ void *data);
+
+struct grub_scsi_dev
+{
+ /* Call HOOK with each device name, until HOOK returns non-zero. */
+ int (*iterate) (grub_scsi_dev_iterate_hook_t hook, void *hook_data,
+ grub_disk_pull_t pull);
+
+ /* Open the device named NAME, and set up SCSI. */
+ grub_err_t (*open) (int id, int bus, struct grub_scsi *scsi);
+
+ /* Close the scsi device SCSI. */
+ void (*close) (struct grub_scsi *scsi);
+
+ /* Read SIZE bytes from the device SCSI into BUF after sending the
+ command CMD of size CMDSIZE. */
+ grub_err_t (*read) (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd,
+ grub_size_t size, char *buf);
+
+ /* Write SIZE bytes from BUF to the device SCSI after sending the
+ command CMD of size CMDSIZE. */
+ grub_err_t (*write) (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd,
+ grub_size_t size, const char *buf);
+
+ /* The next scsi device. */
+ struct grub_scsi_dev *next;
+};
+
+struct grub_scsi
+{
+ /* The underlying scsi device. */
+ grub_scsi_dev_t dev;
+
+ /* Type of SCSI device. XXX: Make enum. */
+ grub_uint8_t devtype;
+
+ int bus;
+
+ /* Number of LUNs. */
+ int luns;
+
+ /* LUN for this `struct grub_scsi'. */
+ int lun;
+
+ /* Set to 0 when not removable, 1 when removable. */
+ int removable;
+
+ /* Size of the device in blocks - 1. */
+ grub_uint64_t last_block;
+
+ /* Size of one block. */
+ grub_uint32_t blocksize;
+
+ /* Device-specific data. */
+ void *data;
+};
+typedef struct grub_scsi *grub_scsi_t;
+
+#endif /* GRUB_SCSI_H */
diff --git a/include/grub/scsicmd.h b/include/grub/scsicmd.h
new file mode 100644
index 0000000..3f1e6d2
--- /dev/null
+++ b/include/grub/scsicmd.h
@@ -0,0 +1,206 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_SCSICMD_H
+#define GRUB_SCSICMD_H 1
+
+#include <grub/types.h>
+
+#define GRUB_SCSI_DEVTYPE_MASK 31
+#define GRUB_SCSI_REMOVABLE_BIT 7
+#define GRUB_SCSI_LUN_SHIFT 5
+
+struct grub_scsi_test_unit_ready
+{
+ grub_uint8_t opcode;
+ grub_uint8_t lun; /* 7-5 LUN, 4-0 reserved */
+ grub_uint8_t reserved1;
+ grub_uint8_t reserved2;
+ grub_uint8_t reserved3;
+ grub_uint8_t control;
+ grub_uint8_t pad[6]; /* To be ATAPI compatible */
+} GRUB_PACKED;
+
+struct grub_scsi_inquiry
+{
+ grub_uint8_t opcode;
+ grub_uint8_t lun; /* 7-5 LUN, 4-1 reserved, 0 EVPD */
+ grub_uint8_t page; /* page code if EVPD=1 */
+ grub_uint8_t reserved;
+ grub_uint8_t alloc_length;
+ grub_uint8_t control;
+ grub_uint8_t pad[6]; /* To be ATAPI compatible */
+} GRUB_PACKED;
+
+struct grub_scsi_inquiry_data
+{
+ grub_uint8_t devtype;
+ grub_uint8_t rmb;
+ grub_uint16_t reserved;
+ grub_uint8_t length;
+ grub_uint8_t reserved2[3];
+ char vendor[8];
+ char prodid[16];
+ char prodrev[4];
+} GRUB_PACKED;
+
+struct grub_scsi_request_sense
+{
+ grub_uint8_t opcode;
+ grub_uint8_t lun; /* 7-5 LUN, 4-0 reserved */
+ grub_uint8_t reserved1;
+ grub_uint8_t reserved2;
+ grub_uint8_t alloc_length;
+ grub_uint8_t control;
+ grub_uint8_t pad[6]; /* To be ATAPI compatible */
+} GRUB_PACKED;
+
+struct grub_scsi_request_sense_data
+{
+ grub_uint8_t error_code; /* 7 Valid, 6-0 Err. code */
+ grub_uint8_t segment_number;
+ grub_uint8_t sense_key; /*7 FileMark, 6 EndOfMedia, 5 ILI, 4-0 sense key */
+ grub_uint32_t information;
+ grub_uint8_t additional_sense_length;
+ grub_uint32_t cmd_specific_info;
+ grub_uint8_t additional_sense_code;
+ grub_uint8_t additional_sense_code_qualifier;
+ grub_uint8_t field_replaceable_unit_code;
+ grub_uint8_t sense_key_specific[3];
+ /* there can be additional sense field */
+} GRUB_PACKED;
+
+struct grub_scsi_read_capacity10
+{
+ grub_uint8_t opcode;
+ grub_uint8_t lun; /* 7-5 LUN, 4-1 reserved, 0 reserved */
+ grub_uint32_t logical_block_addr; /* only if PMI=1 */
+ grub_uint8_t reserved1;
+ grub_uint8_t reserved2;
+ grub_uint8_t PMI;
+ grub_uint8_t control;
+ grub_uint16_t pad; /* To be ATAPI compatible */
+} GRUB_PACKED;
+
+struct grub_scsi_read_capacity10_data
+{
+ grub_uint32_t last_block;
+ grub_uint32_t blocksize;
+} GRUB_PACKED;
+
+struct grub_scsi_read_capacity16
+{
+ grub_uint8_t opcode;
+ grub_uint8_t lun; /* 7-5 LUN, 4-0 0x10 */
+ grub_uint64_t logical_block_addr; /* only if PMI=1 */
+ grub_uint32_t alloc_len;
+ grub_uint8_t PMI;
+ grub_uint8_t control;
+} GRUB_PACKED;
+
+struct grub_scsi_read_capacity16_data
+{
+ grub_uint64_t last_block;
+ grub_uint32_t blocksize;
+ grub_uint8_t pad[20];
+} GRUB_PACKED;
+
+struct grub_scsi_read10
+{
+ grub_uint8_t opcode;
+ grub_uint8_t lun;
+ grub_uint32_t lba;
+ grub_uint8_t reserved;
+ grub_uint16_t size;
+ grub_uint8_t reserved2;
+ grub_uint16_t pad;
+} GRUB_PACKED;
+
+struct grub_scsi_read12
+{
+ grub_uint8_t opcode;
+ grub_uint8_t lun;
+ grub_uint32_t lba;
+ grub_uint32_t size;
+ grub_uint8_t reserved;
+ grub_uint8_t control;
+} GRUB_PACKED;
+
+struct grub_scsi_read16
+{
+ grub_uint8_t opcode;
+ grub_uint8_t lun;
+ grub_uint64_t lba;
+ grub_uint32_t size;
+ grub_uint8_t reserved;
+ grub_uint8_t control;
+} GRUB_PACKED;
+
+struct grub_scsi_write10
+{
+ grub_uint8_t opcode;
+ grub_uint8_t lun;
+ grub_uint32_t lba;
+ grub_uint8_t reserved;
+ grub_uint16_t size;
+ grub_uint8_t reserved2;
+ grub_uint16_t pad;
+} GRUB_PACKED;
+
+struct grub_scsi_write12
+{
+ grub_uint8_t opcode;
+ grub_uint8_t lun;
+ grub_uint32_t lba;
+ grub_uint32_t size;
+ grub_uint8_t reserved;
+ grub_uint8_t control;
+} GRUB_PACKED;
+
+struct grub_scsi_write16
+{
+ grub_uint8_t opcode;
+ grub_uint8_t lun;
+ grub_uint64_t lba;
+ grub_uint32_t size;
+ grub_uint8_t reserved;
+ grub_uint8_t control;
+} GRUB_PACKED;
+
+typedef enum
+ {
+ grub_scsi_cmd_test_unit_ready = 0x00,
+ grub_scsi_cmd_request_sense = 0x03,
+ grub_scsi_cmd_inquiry = 0x12,
+ grub_scsi_cmd_read_capacity10 = 0x25,
+ grub_scsi_cmd_read10 = 0x28,
+ grub_scsi_cmd_write10 = 0x2a,
+ grub_scsi_cmd_read16 = 0x88,
+ grub_scsi_cmd_write16 = 0x8a,
+ grub_scsi_cmd_read_capacity16 = 0x9e,
+ grub_scsi_cmd_read12 = 0xa8,
+ grub_scsi_cmd_write12 = 0xaa,
+ } grub_scsi_cmd_t;
+
+typedef enum
+ {
+ grub_scsi_devtype_direct = 0x00,
+ grub_scsi_devtype_cdrom = 0x05
+ } grub_scsi_devtype_t;
+
+#endif /* GRUB_SCSICMD_H */
diff --git a/include/grub/sdl.h b/include/grub/sdl.h
new file mode 100644
index 0000000..e4efdc9
--- /dev/null
+++ b/include/grub/sdl.h
@@ -0,0 +1,24 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+void EXPORT_FUNC (SDL_Quit) (void);
+void EXPORT_FUNC (SDL_SetColors) (void);
+void EXPORT_FUNC (SDL_Init) (void);
+void EXPORT_FUNC (SDL_GetError) (void);
+void EXPORT_FUNC (SDL_Flip) (void);
+void EXPORT_FUNC (SDL_SetVideoMode) (void);
diff --git a/include/grub/search.h b/include/grub/search.h
new file mode 100644
index 0000000..d80347d
--- /dev/null
+++ b/include/grub/search.h
@@ -0,0 +1,29 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_SEARCH_HEADER
+#define GRUB_SEARCH_HEADER 1
+
+void grub_search_fs_file (const char *key, const char *var, int no_floppy,
+ char **hints, unsigned nhints);
+void grub_search_fs_uuid (const char *key, const char *var, int no_floppy,
+ char **hints, unsigned nhints);
+void grub_search_label (const char *key, const char *var, int no_floppy,
+ char **hints, unsigned nhints);
+
+#endif
diff --git a/include/grub/serial.h b/include/grub/serial.h
new file mode 100644
index 0000000..67379de
--- /dev/null
+++ b/include/grub/serial.h
@@ -0,0 +1,205 @@
+/* serial.h - serial device interface */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_SERIAL_HEADER
+#define GRUB_SERIAL_HEADER 1
+
+#include <grub/types.h>
+#if defined(__mips__) || defined (__i386__) || defined (__x86_64__)
+#include <grub/cpu/io.h>
+#endif
+#include <grub/usb.h>
+#include <grub/list.h>
+#include <grub/term.h>
+#ifdef GRUB_MACHINE_IEEE1275
+#include <grub/ieee1275/ieee1275.h>
+#endif
+#ifdef GRUB_MACHINE_ARC
+#include <grub/arc/arc.h>
+#endif
+
+struct grub_serial_port;
+struct grub_serial_config;
+
+struct grub_serial_driver
+{
+ grub_err_t (*configure) (struct grub_serial_port *port,
+ struct grub_serial_config *config);
+ int (*fetch) (struct grub_serial_port *port);
+ void (*put) (struct grub_serial_port *port, const int c);
+ void (*fini) (struct grub_serial_port *port);
+};
+
+/* The type of parity. */
+typedef enum
+ {
+ GRUB_SERIAL_PARITY_NONE,
+ GRUB_SERIAL_PARITY_ODD,
+ GRUB_SERIAL_PARITY_EVEN,
+ } grub_serial_parity_t;
+
+typedef enum
+ {
+ GRUB_SERIAL_STOP_BITS_1,
+ GRUB_SERIAL_STOP_BITS_1_5,
+ GRUB_SERIAL_STOP_BITS_2,
+ } grub_serial_stop_bits_t;
+
+struct grub_serial_config
+{
+ unsigned speed;
+ int word_len;
+ grub_serial_parity_t parity;
+ grub_serial_stop_bits_t stop_bits;
+ grub_uint64_t base_clock;
+ int rtscts;
+};
+
+struct grub_serial_port
+{
+ struct grub_serial_port *next;
+ struct grub_serial_port **prev;
+ char *name;
+ struct grub_serial_driver *driver;
+ struct grub_serial_config config;
+ int configured;
+ int broken;
+
+ /* This should be void *data but since serial is useful as an early console
+ when malloc isn't available it's a union.
+ */
+ union
+ {
+#if defined(__mips__) || defined (__i386__) || defined (__x86_64__)
+ grub_port_t port;
+#endif
+ struct
+ {
+ grub_usb_device_t usbdev;
+ int configno;
+ int interfno;
+ char buf[64];
+ int bufstart, bufend;
+ struct grub_usb_desc_endp *in_endp;
+ struct grub_usb_desc_endp *out_endp;
+ };
+ struct grub_escc_descriptor *escc_desc;
+#ifdef GRUB_MACHINE_IEEE1275
+ struct
+ {
+ grub_ieee1275_ihandle_t handle;
+ struct ofserial_hash_ent *elem;
+ };
+#endif
+#ifdef GRUB_MACHINE_EFI
+ struct grub_efi_serial_io_interface *interface;
+#endif
+#ifdef GRUB_MACHINE_ARC
+ struct
+ {
+ grub_arc_fileno_t handle;
+ int handle_valid;
+ };
+#endif
+ };
+ grub_term_output_t term_out;
+ grub_term_input_t term_in;
+};
+
+grub_err_t EXPORT_FUNC(grub_serial_register) (struct grub_serial_port *port);
+
+void EXPORT_FUNC(grub_serial_unregister) (struct grub_serial_port *port);
+
+ /* Convenience functions to perform primitive operations on a port. */
+static inline grub_err_t
+grub_serial_port_configure (struct grub_serial_port *port,
+ struct grub_serial_config *config)
+{
+ return port->driver->configure (port, config);
+}
+
+static inline int
+grub_serial_port_fetch (struct grub_serial_port *port)
+{
+ return port->driver->fetch (port);
+}
+
+static inline void
+grub_serial_port_put (struct grub_serial_port *port, const int c)
+{
+ port->driver->put (port, c);
+}
+
+static inline void
+grub_serial_port_fini (struct grub_serial_port *port)
+{
+ port->driver->fini (port);
+}
+
+ /* Set default settings. */
+static inline grub_err_t
+grub_serial_config_defaults (struct grub_serial_port *port)
+{
+ struct grub_serial_config config =
+ {
+#ifdef GRUB_MACHINE_MIPS_LOONGSON
+ .speed = 115200,
+ /* On Loongson machines serial port has only 3 wires. */
+ .rtscts = 0,
+#else
+ .speed = 9600,
+ .rtscts = 1,
+#endif
+ .word_len = 8,
+ .parity = GRUB_SERIAL_PARITY_NONE,
+ .stop_bits = GRUB_SERIAL_STOP_BITS_1,
+ .base_clock = 0
+ };
+
+ return port->driver->configure (port, &config);
+}
+
+#if defined(__mips__) || defined (__i386__) || defined (__x86_64__)
+void grub_ns8250_init (void);
+char *grub_serial_ns8250_add_port (grub_port_t port);
+#endif
+#ifdef GRUB_MACHINE_IEEE1275
+void grub_ofserial_init (void);
+#endif
+#ifdef GRUB_MACHINE_EFI
+void
+grub_efiserial_init (void);
+#endif
+#ifdef GRUB_MACHINE_ARC
+void
+grub_arcserial_init (void);
+const char *
+grub_arcserial_add_port (const char *path);
+#endif
+
+struct grub_serial_port *grub_serial_find (const char *name);
+extern struct grub_serial_driver grub_ns8250_driver;
+void EXPORT_FUNC(grub_serial_unregister_driver) (struct grub_serial_driver *driver);
+
+#ifndef GRUB_MACHINE_EMU
+extern void grub_serial_init (void);
+extern void grub_serial_fini (void);
+#endif
+
+#endif
diff --git a/include/grub/setjmp.h b/include/grub/setjmp.h
new file mode 100644
index 0000000..4bba034
--- /dev/null
+++ b/include/grub/setjmp.h
@@ -0,0 +1,42 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2003,2006,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_SETJMP_HEADER
+#define GRUB_SETJMP_HEADER 1
+
+#if defined(GRUB_UTIL)
+#include <setjmp.h>
+typedef jmp_buf grub_jmp_buf;
+#define grub_setjmp setjmp
+#define grub_longjmp longjmp
+#else
+
+#include <grub/misc.h>
+
+#if GNUC_PREREQ(4,0)
+#define RETURNS_TWICE __attribute__ ((returns_twice))
+#else
+#define RETURNS_TWICE
+#endif
+
+/* This must define grub_jmp_buf, and declare grub_setjmp and
+ grub_longjmp. */
+# include <grub/cpu/setjmp.h>
+#endif
+
+#endif /* ! GRUB_SETJMP_HEADER */
diff --git a/include/grub/smbios.h b/include/grub/smbios.h
new file mode 100644
index 0000000..15ec260
--- /dev/null
+++ b/include/grub/smbios.h
@@ -0,0 +1,69 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2019 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_SMBIOS_HEADER
+#define GRUB_SMBIOS_HEADER 1
+
+#include <grub/symbol.h>
+#include <grub/types.h>
+
+#define GRUB_SMBIOS_TYPE_END_OF_TABLE ((grub_uint8_t)127)
+
+struct grub_smbios_ieps
+{
+ grub_uint8_t anchor[5]; /* "_DMI_" */
+ grub_uint8_t checksum;
+ grub_uint16_t table_length;
+ grub_uint32_t table_address;
+ grub_uint16_t structures;
+ grub_uint8_t revision;
+} GRUB_PACKED;
+
+struct grub_smbios_eps
+{
+ grub_uint8_t anchor[4]; /* "_SM_" */
+ grub_uint8_t checksum;
+ grub_uint8_t length; /* 0x1f */
+ grub_uint8_t version_major;
+ grub_uint8_t version_minor;
+ grub_uint16_t maximum_structure_size;
+ grub_uint8_t revision;
+ grub_uint8_t formatted[5];
+ struct grub_smbios_ieps intermediate;
+} GRUB_PACKED;
+
+struct grub_smbios_eps3
+{
+ grub_uint8_t anchor[5]; /* "_SM3_" */
+ grub_uint8_t checksum;
+ grub_uint8_t length; /* 0x18 */
+ grub_uint8_t version_major;
+ grub_uint8_t version_minor;
+ grub_uint8_t docrev;
+ grub_uint8_t revision;
+ grub_uint8_t reserved;
+ grub_uint32_t maximum_table_length;
+ grub_uint64_t table_address;
+} GRUB_PACKED;
+
+extern struct grub_smbios_eps *grub_machine_smbios_get_eps (void);
+extern struct grub_smbios_eps3 *grub_machine_smbios_get_eps3 (void);
+
+extern struct grub_smbios_eps *EXPORT_FUNC (grub_smbios_get_eps) (void);
+
+#endif /* ! GRUB_SMBIOS_HEADER */
diff --git a/include/grub/smbus.h b/include/grub/smbus.h
new file mode 100644
index 0000000..0b8e671
--- /dev/null
+++ b/include/grub/smbus.h
@@ -0,0 +1,70 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_SMBUS_HEADER
+#define GRUB_SMBUS_HEADER 1
+
+#define GRUB_SMB_RAM_START_ADDR 0x50
+#define GRUB_SMB_RAM_NUM_MAX 0x08
+
+#define GRUB_SMBUS_SPD_MEMORY_TYPE_ADDR 2
+#define GRUB_SMBUS_SPD_MEMORY_TYPE_DDR2 8
+#define GRUB_SMBUS_SPD_MEMORY_NUM_BANKS_ADDR 17
+#define GRUB_SMBUS_SPD_MEMORY_NUM_ROWS_ADDR 3
+#define GRUB_SMBUS_SPD_MEMORY_NUM_COLUMNS_ADDR 4
+#define GRUB_SMBUS_SPD_MEMORY_NUM_OF_RANKS_ADDR 5
+#define GRUB_SMBUS_SPD_MEMORY_NUM_OF_RANKS_MASK 0x7
+#define GRUB_SMBUS_SPD_MEMORY_CAS_LATENCY_ADDR 18
+#define GRUB_SMBUS_SPD_MEMORY_CAS_LATENCY_MIN_VALUE 5
+#define GRUB_SMBUS_SPD_MEMORY_TRAS_ADDR 30
+#define GRUB_SMBUS_SPD_MEMORY_TRTP_ADDR 38
+
+#ifndef ASM_FILE
+
+struct grub_smbus_spd
+{
+ grub_uint8_t written_size;
+ grub_uint8_t log_total_flash_size;
+ grub_uint8_t memory_type;
+ union
+ {
+ grub_uint8_t unknown[253];
+ struct {
+ grub_uint8_t num_rows;
+ grub_uint8_t num_columns;
+ grub_uint8_t num_of_ranks;
+ grub_uint8_t unused1[12];
+ grub_uint8_t num_of_banks;
+ grub_uint8_t unused2[2];
+ grub_uint8_t cas_latency;
+ grub_uint8_t unused3[9];
+ grub_uint8_t rank_capacity;
+ grub_uint8_t unused4[1];
+ grub_uint8_t tras;
+ grub_uint8_t unused5[7];
+ grub_uint8_t trtp;
+ grub_uint8_t unused6[31];
+ grub_uint8_t part_number[18];
+ grub_uint8_t unused7[165];
+ } ddr2;
+ };
+};
+
+#endif
+
+#endif
diff --git a/include/grub/sparc64/ieee1275/boot.h b/include/grub/sparc64/ieee1275/boot.h
new file mode 100644
index 0000000..cc5a941
--- /dev/null
+++ b/include/grub/sparc64/ieee1275/boot.h
@@ -0,0 +1,62 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_BOOT_MACHINE_HEADER
+#define GRUB_BOOT_MACHINE_HEADER 1
+
+#define CIF_REG %l0
+#define CHOSEN_NODE_REG %l4
+#define STDOUT_NODE_REG %l5
+#define BOOTDEV_REG %l6
+#define PIC_REG %l7
+
+#define SCRATCH_PAD_BOOT 0x5000
+#define SCRATCH_PAD_DISKBOOT 0x4000
+#define SCRATCH_PAD_BOOT_SIZE 0x110
+
+#define GET_ABS(symbol, reg) \
+ add PIC_REG, (symbol - pic_base), reg
+#define LDUW_ABS(symbol, offset, reg) \
+ lduw [PIC_REG + (symbol - pic_base) + (offset)], reg
+#define LDX_ABS(symbol, offset, reg) \
+ ldx [PIC_REG + (symbol - pic_base) + (offset)], reg
+
+#define GRUB_BOOT_AOUT_HEADER_SIZE 32
+
+#define GRUB_BOOT_MACHINE_SIGNATURE 0xbb44aa55
+
+#define GRUB_BOOT_MACHINE_BOOT_DEVPATH 0x08
+
+#define GRUB_BOOT_MACHINE_BOOT_DEVPATH_END 0x80
+
+#define GRUB_BOOT_MACHINE_KERNEL_BYTE 0x80
+
+#define GRUB_BOOT_MACHINE_CODE_END 0x1fc
+
+#define GRUB_BOOT_MACHINE_KERNEL_ADDR 0x4200
+
+#ifndef ASM_FILE
+/* This is the blocklist used in the diskboot image. */
+struct grub_boot_blocklist
+{
+ grub_uint64_t start;
+ grub_uint32_t len;
+} GRUB_PACKED;
+#endif
+
+#endif /* ! BOOT_MACHINE_HEADER */
diff --git a/include/grub/sparc64/ieee1275/ieee1275.h b/include/grub/sparc64/ieee1275/ieee1275.h
new file mode 100644
index 0000000..4b18468
--- /dev/null
+++ b/include/grub/sparc64/ieee1275/ieee1275.h
@@ -0,0 +1,50 @@
+/* ieee1275.h - Access the Open Firmware client interface. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2003,2004,2005,2007,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_IEEE1275_MACHINE_HEADER
+#define GRUB_IEEE1275_MACHINE_HEADER 1
+
+#include <grub/types.h>
+
+#define GRUB_IEEE1275_CELL_SIZEOF 8
+typedef grub_uint64_t grub_ieee1275_cell_t;
+
+/* Encoding of 'mode' argument to grub_ieee1275_map_physical() */
+#define IEEE1275_MAP_WRITE 0x0001 /* Writable */
+#define IEEE1275_MAP_READ 0x0002 /* Readable */
+#define IEEE1275_MAP_EXEC 0x0004 /* Executable */
+#define IEEE1275_MAP_LOCKED 0x0010 /* Locked in TLB */
+#define IEEE1275_MAP_CACHED 0x0020 /* Cacheable */
+#define IEEE1275_MAP_SE 0x0040 /* Side-effects */
+#define IEEE1275_MAP_GLOBAL 0x0080 /* Global */
+#define IEEE1275_MAP_IE 0x0100 /* Invert Endianness */
+#define IEEE1275_MAP_DEFAULT (IEEE1275_MAP_WRITE | IEEE1275_MAP_READ | \
+ IEEE1275_MAP_EXEC | IEEE1275_MAP_CACHED)
+
+extern int EXPORT_FUNC(grub_ieee1275_claim_vaddr) (grub_addr_t vaddr,
+ grub_size_t size);
+extern int EXPORT_FUNC(grub_ieee1275_alloc_physmem) (grub_addr_t *paddr,
+ grub_size_t size,
+ grub_uint32_t align);
+extern grub_uint64_t EXPORT_FUNC(grub_ieee1275_num_blocks) (grub_uint32_t ihandle);
+extern grub_uint64_t EXPORT_FUNC(grub_ieee1275_num_blocks64) (grub_uint32_t ihandle);
+
+extern grub_addr_t EXPORT_VAR (grub_ieee1275_original_stack);
+
+#endif /* ! GRUB_IEEE1275_MACHINE_HEADER */
diff --git a/include/grub/sparc64/ieee1275/kernel.h b/include/grub/sparc64/ieee1275/kernel.h
new file mode 100644
index 0000000..9a00bea
--- /dev/null
+++ b/include/grub/sparc64/ieee1275/kernel.h
@@ -0,0 +1,31 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2005,2007,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_KERNEL_MACHINE_HEADER
+#define GRUB_KERNEL_MACHINE_HEADER 1
+
+#define GRUB_KERNEL_MACHINE_STACK_SIZE 0x40000
+
+#ifndef ASM_FILE
+
+#include <grub/symbol.h>
+#include <grub/types.h>
+
+#endif /* ! ASM_FILE */
+
+#endif /* ! GRUB_KERNEL_MACHINE_HEADER */
diff --git a/include/grub/sparc64/setjmp.h b/include/grub/sparc64/setjmp.h
new file mode 100644
index 0000000..00286a5
--- /dev/null
+++ b/include/grub/sparc64/setjmp.h
@@ -0,0 +1,29 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2004,2006,2007,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_SETJMP_CPU_HEADER
+#define GRUB_SETJMP_CPU_HEADER 1
+
+#include <grub/types.h>
+
+typedef grub_uint64_t grub_jmp_buf[3];
+
+int grub_setjmp (grub_jmp_buf env) RETURNS_TWICE;
+void grub_longjmp (grub_jmp_buf env, int val) __attribute__ ((noreturn));
+
+#endif /* ! GRUB_SETJMP_CPU_HEADER */
diff --git a/include/grub/sparc64/time.h b/include/grub/sparc64/time.h
new file mode 100644
index 0000000..5db7ff4
--- /dev/null
+++ b/include/grub/sparc64/time.h
@@ -0,0 +1,28 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef KERNEL_CPU_TIME_HEADER
+#define KERNEL_CPU_TIME_HEADER 1
+
+static __inline void
+grub_cpu_idle (void)
+{
+ /* FIXME: not implemented */
+}
+
+#endif /* ! KERNEL_CPU_TIME_HEADER */
diff --git a/include/grub/sparc64/types.h b/include/grub/sparc64/types.h
new file mode 100644
index 0000000..b9b0cf9
--- /dev/null
+++ b/include/grub/sparc64/types.h
@@ -0,0 +1,32 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2004,2006,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_TYPES_CPU_HEADER
+#define GRUB_TYPES_CPU_HEADER 1
+
+/* The size of void *. */
+#define GRUB_TARGET_SIZEOF_VOID_P 8
+
+/* The size of long. */
+#define GRUB_TARGET_SIZEOF_LONG 8
+
+/* sparc64 is big-endian. */
+#define GRUB_TARGET_WORDS_BIGENDIAN 1
+
+
+#endif /* ! GRUB_TYPES_CPU_HEADER */
diff --git a/include/grub/speaker.h b/include/grub/speaker.h
new file mode 100644
index 0000000..a076fcf
--- /dev/null
+++ b/include/grub/speaker.h
@@ -0,0 +1,47 @@
+#ifndef GRUB_SPEAKER_HEADER
+#define GRUB_SPEAKER_HEADER 1
+
+#include <grub/cpu/io.h>
+#include <grub/i386/pit.h>
+
+/* The frequency of the PIT clock. */
+#define GRUB_SPEAKER_PIT_FREQUENCY 0x1234dd
+
+static inline void
+grub_speaker_beep_off (void)
+{
+ unsigned char status;
+
+ status = grub_inb (GRUB_PIT_SPEAKER_PORT);
+ grub_outb (status & ~(GRUB_PIT_SPK_TMR2 | GRUB_PIT_SPK_DATA),
+ GRUB_PIT_SPEAKER_PORT);
+}
+
+static inline void
+grub_speaker_beep_on (grub_uint16_t pitch)
+{
+ unsigned char status;
+ unsigned int counter;
+
+ if (pitch < 20)
+ pitch = 20;
+ else if (pitch > 20000)
+ pitch = 20000;
+
+ counter = GRUB_SPEAKER_PIT_FREQUENCY / pitch;
+
+ /* Program timer 2. */
+ grub_outb (GRUB_PIT_CTRL_SELECT_2
+ | GRUB_PIT_CTRL_READLOAD_WORD
+ | GRUB_PIT_CTRL_SQUAREWAVE_GEN
+ | GRUB_PIT_CTRL_COUNT_BINARY, GRUB_PIT_CTRL);
+ grub_outb (counter & 0xff, GRUB_PIT_COUNTER_2); /* LSB */
+ grub_outb ((counter >> 8) & 0xff, GRUB_PIT_COUNTER_2); /* MSB */
+
+ /* Start speaker. */
+ status = grub_inb (GRUB_PIT_SPEAKER_PORT);
+ grub_outb (status | GRUB_PIT_SPK_TMR2 | GRUB_PIT_SPK_DATA,
+ GRUB_PIT_SPEAKER_PORT);
+}
+
+#endif
diff --git a/include/grub/stack_protector.h b/include/grub/stack_protector.h
new file mode 100644
index 0000000..c88dc00
--- /dev/null
+++ b/include/grub/stack_protector.h
@@ -0,0 +1,30 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2021 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_STACK_PROTECTOR_H
+#define GRUB_STACK_PROTECTOR_H 1
+
+#include <grub/symbol.h>
+#include <grub/types.h>
+
+#ifdef GRUB_STACK_PROTECTOR
+extern grub_addr_t EXPORT_VAR (__stack_chk_guard);
+extern void __attribute__ ((noreturn)) EXPORT_FUNC (__stack_chk_fail) (void);
+#endif
+
+#endif /* GRUB_STACK_PROTECTOR_H */
diff --git a/include/grub/symbol.h b/include/grub/symbol.h
new file mode 100644
index 0000000..ed19f70
--- /dev/null
+++ b/include/grub/symbol.h
@@ -0,0 +1,72 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 1999,2000,2001,2002,2006,2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_SYMBOL_HEADER
+#define GRUB_SYMBOL_HEADER 1
+
+#include <config.h>
+
+/* Apple assembler requires local labels to start with a capital L */
+#define LOCAL(sym) L_ ## sym
+
+/* Add an underscore to a C symbol in assembler code if needed. */
+#ifndef GRUB_UTIL
+
+#ifdef __APPLE__
+#define MACRO_DOLLAR(x) $$ ## x
+#else
+#define MACRO_DOLLAR(x) $ ## x
+#endif
+
+#if HAVE_ASM_USCORE
+#ifdef ASM_FILE
+# define EXT_C(sym) _ ## sym
+#else
+# define EXT_C(sym) "_" sym
+#endif
+#else
+# define EXT_C(sym) sym
+#endif
+
+#ifdef __arm__
+#define END .end
+#endif
+
+#if defined (__APPLE__)
+#define FUNCTION(x) .globl EXT_C(x) ; EXT_C(x):
+#define VARIABLE(x) .globl EXT_C(x) ; EXT_C(x):
+#elif defined (__CYGWIN__) || defined (__MINGW32__)
+/* .type not supported for non-ELF targets. XXX: Check this in configure? */
+#define FUNCTION(x) .globl EXT_C(x) ; .def EXT_C(x); .scl 2; .type 32; .endef; EXT_C(x):
+#define VARIABLE(x) .globl EXT_C(x) ; .def EXT_C(x); .scl 2; .type 0; .endef; EXT_C(x):
+#elif defined (__arm__)
+#define FUNCTION(x) .globl EXT_C(x) ; .type EXT_C(x), %function ; EXT_C(x):
+#define VARIABLE(x) .globl EXT_C(x) ; .type EXT_C(x), %object ; EXT_C(x):
+#else
+#define FUNCTION(x) .globl EXT_C(x) ; .type EXT_C(x), @function ; EXT_C(x):
+#define VARIABLE(x) .globl EXT_C(x) ; .type EXT_C(x), @object ; EXT_C(x):
+#endif
+#endif
+
+/* Mark an exported symbol. */
+#ifndef GRUB_SYMBOL_GENERATOR
+# define EXPORT_FUNC(x) x
+# define EXPORT_VAR(x) x
+#endif /* ! GRUB_SYMBOL_GENERATOR */
+
+#endif /* ! GRUB_SYMBOL_HEADER */
diff --git a/include/grub/syslinux_parse.h b/include/grub/syslinux_parse.h
new file mode 100644
index 0000000..3595763
--- /dev/null
+++ b/include/grub/syslinux_parse.h
@@ -0,0 +1,37 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_SYSLINUX_PARSE_HEADER
+#define GRUB_SYSLINUX_PARSE_HEADER 1
+
+#include <grub/types.h>
+
+typedef enum
+ {
+ GRUB_SYSLINUX_UNKNOWN,
+ GRUB_SYSLINUX_ISOLINUX,
+ GRUB_SYSLINUX_PXELINUX,
+ GRUB_SYSLINUX_SYSLINUX,
+ } grub_syslinux_flavour_t;
+
+char *
+grub_syslinux_config_file (const char *root, const char *target_root,
+ const char *cwd, const char *target_cwd,
+ const char *fname, grub_syslinux_flavour_t flav);
+
+#endif
diff --git a/include/grub/term.h b/include/grub/term.h
new file mode 100644
index 0000000..3387cb0
--- /dev/null
+++ b/include/grub/term.h
@@ -0,0 +1,469 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2003,2005,2007,2008,2009,2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_TERM_HEADER
+#define GRUB_TERM_HEADER 1
+
+#define GRUB_TERM_NO_KEY 0
+
+/* Internal codes used by GRUB to represent terminal input. */
+/* Only for keys otherwise not having shifted modification. */
+#define GRUB_TERM_SHIFT 0x01000000
+#define GRUB_TERM_CTRL 0x02000000
+#define GRUB_TERM_ALT 0x04000000
+
+/* Keys without associated character. */
+#define GRUB_TERM_EXTENDED 0x00800000
+#define GRUB_TERM_KEY_MASK 0x00ffffff
+
+#define GRUB_TERM_KEY_LEFT (GRUB_TERM_EXTENDED | 0x4b)
+#define GRUB_TERM_KEY_RIGHT (GRUB_TERM_EXTENDED | 0x4d)
+#define GRUB_TERM_KEY_UP (GRUB_TERM_EXTENDED | 0x48)
+#define GRUB_TERM_KEY_DOWN (GRUB_TERM_EXTENDED | 0x50)
+#define GRUB_TERM_KEY_HOME (GRUB_TERM_EXTENDED | 0x47)
+#define GRUB_TERM_KEY_END (GRUB_TERM_EXTENDED | 0x4f)
+#define GRUB_TERM_KEY_DC (GRUB_TERM_EXTENDED | 0x53)
+#define GRUB_TERM_KEY_PPAGE (GRUB_TERM_EXTENDED | 0x49)
+#define GRUB_TERM_KEY_NPAGE (GRUB_TERM_EXTENDED | 0x51)
+#define GRUB_TERM_KEY_F1 (GRUB_TERM_EXTENDED | 0x3b)
+#define GRUB_TERM_KEY_F2 (GRUB_TERM_EXTENDED | 0x3c)
+#define GRUB_TERM_KEY_F3 (GRUB_TERM_EXTENDED | 0x3d)
+#define GRUB_TERM_KEY_F4 (GRUB_TERM_EXTENDED | 0x3e)
+#define GRUB_TERM_KEY_F5 (GRUB_TERM_EXTENDED | 0x3f)
+#define GRUB_TERM_KEY_F6 (GRUB_TERM_EXTENDED | 0x40)
+#define GRUB_TERM_KEY_F7 (GRUB_TERM_EXTENDED | 0x41)
+#define GRUB_TERM_KEY_F8 (GRUB_TERM_EXTENDED | 0x42)
+#define GRUB_TERM_KEY_F9 (GRUB_TERM_EXTENDED | 0x43)
+#define GRUB_TERM_KEY_F10 (GRUB_TERM_EXTENDED | 0x44)
+#define GRUB_TERM_KEY_F11 (GRUB_TERM_EXTENDED | 0x57)
+#define GRUB_TERM_KEY_F12 (GRUB_TERM_EXTENDED | 0x58)
+#define GRUB_TERM_KEY_INSERT (GRUB_TERM_EXTENDED | 0x52)
+#define GRUB_TERM_KEY_CENTER (GRUB_TERM_EXTENDED | 0x4c)
+
+/* Hex value is used for ESC, since '\e' is nonstandard */
+#define GRUB_TERM_ESC 0x1b
+#define GRUB_TERM_TAB '\t'
+#define GRUB_TERM_BACKSPACE '\b'
+
+#define GRUB_PROGRESS_NO_UPDATE -1
+#define GRUB_PROGRESS_FAST 0
+#define GRUB_PROGRESS_SLOW 2
+
+#ifndef ASM_FILE
+
+#include <grub/err.h>
+#include <grub/symbol.h>
+#include <grub/types.h>
+#include <grub/unicode.h>
+#include <grub/list.h>
+
+/* These are used to represent the various color states we use. */
+typedef enum
+ {
+ /* Used for uninitialized grub_term_color_state variables */
+ GRUB_TERM_COLOR_UNDEFINED = -1,
+ /* The color used to display all text that does not use the
+ user defined colors below. */
+ GRUB_TERM_COLOR_STANDARD = 0,
+ /* The user defined colors for normal text. */
+ GRUB_TERM_COLOR_NORMAL,
+ /* The user defined colors for highlighted text. */
+ GRUB_TERM_COLOR_HIGHLIGHT
+ }
+grub_term_color_state;
+
+/* Flags for representing the capabilities of a terminal. */
+/* Some notes about the flags:
+ - These flags are used by higher-level functions but not terminals
+ themselves.
+ - If a terminal is dumb, you may assume that only putchar, getkey and
+ checkkey are called.
+ - Some fancy features (setcolorstate, setcolor and setcursor) can be set
+ to NULL. */
+
+/* Set when input characters shouldn't be echoed back. */
+#define GRUB_TERM_NO_ECHO (1 << 0)
+/* Set when the editing feature should be disabled. */
+#define GRUB_TERM_NO_EDIT (1 << 1)
+/* Set when the terminal cannot do fancy things. */
+#define GRUB_TERM_DUMB (1 << 2)
+/* Which encoding does terminal expect stream to be. */
+#define GRUB_TERM_CODE_TYPE_SHIFT 3
+#define GRUB_TERM_CODE_TYPE_MASK (7 << GRUB_TERM_CODE_TYPE_SHIFT)
+/* Only ASCII characters accepted. */
+#define GRUB_TERM_CODE_TYPE_ASCII (0 << GRUB_TERM_CODE_TYPE_SHIFT)
+/* Expects CP-437 characters (ASCII + pseudographics). */
+#define GRUB_TERM_CODE_TYPE_CP437 (1 << GRUB_TERM_CODE_TYPE_SHIFT)
+/* UTF-8 stream in logical order. Usually used for terminals
+ which just forward the stream to another computer. */
+#define GRUB_TERM_CODE_TYPE_UTF8_LOGICAL (2 << GRUB_TERM_CODE_TYPE_SHIFT)
+/* UTF-8 in visual order. Like UTF-8 logical but for buggy endpoints. */
+#define GRUB_TERM_CODE_TYPE_UTF8_VISUAL (3 << GRUB_TERM_CODE_TYPE_SHIFT)
+/* Glyph description in visual order. */
+#define GRUB_TERM_CODE_TYPE_VISUAL_GLYPHS (4 << GRUB_TERM_CODE_TYPE_SHIFT)
+
+
+/* Bitmasks for modifier keys returned by grub_getkeystatus. */
+#define GRUB_TERM_STATUS_RSHIFT (1 << 0)
+#define GRUB_TERM_STATUS_LSHIFT (1 << 1)
+#define GRUB_TERM_STATUS_RCTRL (1 << 2)
+#define GRUB_TERM_STATUS_RALT (1 << 3)
+#define GRUB_TERM_STATUS_SCROLL (1 << 4)
+#define GRUB_TERM_STATUS_NUM (1 << 5)
+#define GRUB_TERM_STATUS_CAPS (1 << 6)
+#define GRUB_TERM_STATUS_LCTRL (1 << 8)
+#define GRUB_TERM_STATUS_LALT (1 << 9)
+
+/* Menu-related geometrical constants. */
+
+/* The number of columns/lines between messages/borders/etc. */
+#define GRUB_TERM_MARGIN 1
+
+/* The number of columns of scroll information. */
+#define GRUB_TERM_SCROLL_WIDTH 1
+
+struct grub_term_input
+{
+ /* The next terminal. */
+ struct grub_term_input *next;
+ struct grub_term_input **prev;
+
+ /* The terminal name. */
+ const char *name;
+
+ /* Initialize the terminal. */
+ grub_err_t (*init) (struct grub_term_input *term);
+
+ /* Clean up the terminal. */
+ grub_err_t (*fini) (struct grub_term_input *term);
+
+ /* Get a character if any input character is available. Otherwise return -1 */
+ int (*getkey) (struct grub_term_input *term);
+
+ /* Get keyboard modifier status. */
+ int (*getkeystatus) (struct grub_term_input *term);
+
+ void *data;
+};
+typedef struct grub_term_input *grub_term_input_t;
+
+/* Made in a way to fit into uint32_t and so be passed in a register. */
+struct grub_term_coordinate
+{
+ grub_uint16_t x;
+ grub_uint16_t y;
+};
+
+struct grub_term_output
+{
+ /* The next terminal. */
+ struct grub_term_output *next;
+ struct grub_term_output **prev;
+
+ /* The terminal name. */
+ const char *name;
+
+ /* Initialize the terminal. */
+ grub_err_t (*init) (struct grub_term_output *term);
+
+ /* Clean up the terminal. */
+ grub_err_t (*fini) (struct grub_term_output *term);
+
+ /* Put a character. C is encoded in Unicode. */
+ void (*putchar) (struct grub_term_output *term,
+ const struct grub_unicode_glyph *c);
+
+ /* Get the number of columns occupied by a given character C. C is
+ encoded in Unicode. */
+ grub_size_t (*getcharwidth) (struct grub_term_output *term,
+ const struct grub_unicode_glyph *c);
+
+ /* Get the screen size. */
+ struct grub_term_coordinate (*getwh) (struct grub_term_output *term);
+
+ /* Get the cursor position. The return value is ((X << 8) | Y). */
+ struct grub_term_coordinate (*getxy) (struct grub_term_output *term);
+
+ /* Go to the position (X, Y). */
+ void (*gotoxy) (struct grub_term_output *term,
+ struct grub_term_coordinate pos);
+
+ /* Clear the screen. */
+ void (*cls) (struct grub_term_output *term);
+
+ /* Set the current color to be used */
+ void (*setcolorstate) (struct grub_term_output *term,
+ grub_term_color_state state);
+
+ /* Turn on/off the cursor. */
+ void (*setcursor) (struct grub_term_output *term, int on);
+
+ /* Update the screen. */
+ void (*refresh) (struct grub_term_output *term);
+
+ /* gfxterm only: put in fullscreen mode. */
+ grub_err_t (*fullscreen) (void);
+
+ /* The feature flags defined above. */
+ grub_uint32_t flags;
+
+ /* Progress data. */
+ grub_uint32_t progress_update_divisor;
+ grub_uint32_t progress_update_counter;
+
+ void *data;
+};
+typedef struct grub_term_output *grub_term_output_t;
+
+#define GRUB_TERM_DEFAULT_NORMAL_COLOR 0x07
+#define GRUB_TERM_DEFAULT_HIGHLIGHT_COLOR 0x70
+#define GRUB_TERM_DEFAULT_STANDARD_COLOR 0x07
+
+/* Current color state. */
+extern grub_uint8_t EXPORT_VAR(grub_term_normal_color);
+extern grub_uint8_t EXPORT_VAR(grub_term_highlight_color);
+
+extern struct grub_term_output *EXPORT_VAR(grub_term_outputs_disabled);
+extern struct grub_term_input *EXPORT_VAR(grub_term_inputs_disabled);
+extern struct grub_term_output *EXPORT_VAR(grub_term_outputs);
+extern struct grub_term_input *EXPORT_VAR(grub_term_inputs);
+
+static inline void
+grub_term_register_input (const char *name __attribute__ ((unused)),
+ grub_term_input_t term)
+{
+ if (grub_term_inputs)
+ grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs_disabled),
+ GRUB_AS_LIST (term));
+ else
+ {
+ /* If this is the first terminal, enable automatically. */
+ if (! term->init || term->init (term) == GRUB_ERR_NONE)
+ grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs), GRUB_AS_LIST (term));
+ }
+}
+
+static inline void
+grub_term_register_input_inactive (const char *name __attribute__ ((unused)),
+ grub_term_input_t term)
+{
+ grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs_disabled),
+ GRUB_AS_LIST (term));
+}
+
+static inline void
+grub_term_register_input_active (const char *name __attribute__ ((unused)),
+ grub_term_input_t term)
+{
+ if (! term->init || term->init (term) == GRUB_ERR_NONE)
+ grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs), GRUB_AS_LIST (term));
+}
+
+static inline void
+grub_term_register_output (const char *name __attribute__ ((unused)),
+ grub_term_output_t term)
+{
+ if (grub_term_outputs)
+ grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs_disabled),
+ GRUB_AS_LIST (term));
+ else
+ {
+ /* If this is the first terminal, enable automatically. */
+ if (! term->init || term->init (term) == GRUB_ERR_NONE)
+ grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs),
+ GRUB_AS_LIST (term));
+ }
+}
+
+static inline void
+grub_term_register_output_inactive (const char *name __attribute__ ((unused)),
+ grub_term_output_t term)
+{
+ grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs_disabled),
+ GRUB_AS_LIST (term));
+}
+
+static inline void
+grub_term_register_output_active (const char *name __attribute__ ((unused)),
+ grub_term_output_t term)
+{
+ if (! term->init || term->init (term) == GRUB_ERR_NONE)
+ grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs),
+ GRUB_AS_LIST (term));
+}
+
+static inline void
+grub_term_unregister_input (grub_term_input_t term)
+{
+ grub_list_remove (GRUB_AS_LIST (term));
+ grub_list_remove (GRUB_AS_LIST (term));
+}
+
+static inline void
+grub_term_unregister_output (grub_term_output_t term)
+{
+ grub_list_remove (GRUB_AS_LIST (term));
+ grub_list_remove (GRUB_AS_LIST (term));
+}
+
+#define FOR_ACTIVE_TERM_INPUTS(var) FOR_LIST_ELEMENTS((var), (grub_term_inputs))
+#define FOR_DISABLED_TERM_INPUTS(var) FOR_LIST_ELEMENTS((var), (grub_term_inputs_disabled))
+#define FOR_ACTIVE_TERM_OUTPUTS(var) FOR_LIST_ELEMENTS((var), (grub_term_outputs))
+#define FOR_DISABLED_TERM_OUTPUTS(var) FOR_LIST_ELEMENTS((var), (grub_term_outputs_disabled))
+
+void grub_putcode (grub_uint32_t code, struct grub_term_output *term);
+int EXPORT_FUNC(grub_getkey) (void);
+int EXPORT_FUNC(grub_getkey_noblock) (void);
+int EXPORT_FUNC(grub_getkeystatus) (void);
+int EXPORT_FUNC(grub_key_is_interrupt) (int key);
+void grub_cls (void);
+void EXPORT_FUNC(grub_refresh) (void);
+void grub_puts_terminal (const char *str, struct grub_term_output *term);
+struct grub_term_coordinate *grub_term_save_pos (void);
+void grub_term_restore_pos (struct grub_term_coordinate *pos);
+
+static inline unsigned grub_term_width (struct grub_term_output *term)
+{
+ return term->getwh(term).x ? : 80;
+}
+
+static inline unsigned grub_term_height (struct grub_term_output *term)
+{
+ return term->getwh(term).y ? : 24;
+}
+
+static inline struct grub_term_coordinate
+grub_term_getxy (struct grub_term_output *term)
+{
+ return term->getxy (term);
+}
+
+static inline void
+grub_term_refresh (struct grub_term_output *term)
+{
+ if (term->refresh)
+ term->refresh (term);
+}
+
+static inline void
+grub_term_gotoxy (struct grub_term_output *term, struct grub_term_coordinate pos)
+{
+ term->gotoxy (term, pos);
+}
+
+static inline void
+grub_term_setcolorstate (struct grub_term_output *term,
+ grub_term_color_state state)
+{
+ if (term->setcolorstate)
+ term->setcolorstate (term, state);
+}
+
+static inline void
+grub_setcolorstate (grub_term_color_state state)
+{
+ struct grub_term_output *term;
+
+ FOR_ACTIVE_TERM_OUTPUTS(term)
+ grub_term_setcolorstate (term, state);
+}
+
+/* Turn on/off the cursor. */
+static inline void
+grub_term_setcursor (struct grub_term_output *term, int on)
+{
+ if (term->setcursor)
+ term->setcursor (term, on);
+}
+
+static inline void
+grub_term_cls (struct grub_term_output *term)
+{
+ if (term->cls)
+ (term->cls) (term);
+ else
+ {
+ grub_putcode ('\n', term);
+ grub_term_refresh (term);
+ }
+}
+
+#if HAVE_FONT_SOURCE
+
+grub_size_t
+grub_unicode_estimate_width (const struct grub_unicode_glyph *c);
+
+#else
+
+static inline grub_size_t
+grub_unicode_estimate_width (const struct grub_unicode_glyph *c __attribute__ ((unused)))
+{
+ if (grub_unicode_get_comb_type (c->base))
+ return 0;
+ return 1;
+}
+
+#endif
+
+#define GRUB_TERM_TAB_WIDTH 8
+
+static inline grub_size_t
+grub_term_getcharwidth (struct grub_term_output *term,
+ const struct grub_unicode_glyph *c)
+{
+ if (c->base == '\t')
+ return GRUB_TERM_TAB_WIDTH;
+
+ if (term->getcharwidth)
+ return term->getcharwidth (term, c);
+ else if (((term->flags & GRUB_TERM_CODE_TYPE_MASK)
+ == GRUB_TERM_CODE_TYPE_UTF8_LOGICAL)
+ || ((term->flags & GRUB_TERM_CODE_TYPE_MASK)
+ == GRUB_TERM_CODE_TYPE_UTF8_VISUAL)
+ || ((term->flags & GRUB_TERM_CODE_TYPE_MASK)
+ == GRUB_TERM_CODE_TYPE_VISUAL_GLYPHS))
+ return grub_unicode_estimate_width (c);
+ else
+ return 1;
+}
+
+struct grub_term_autoload
+{
+ struct grub_term_autoload *next;
+ char *name;
+ char *modname;
+};
+
+extern struct grub_term_autoload *grub_term_input_autoload;
+extern struct grub_term_autoload *grub_term_output_autoload;
+
+static inline void
+grub_print_spaces (struct grub_term_output *term, int number_spaces)
+{
+ while (--number_spaces >= 0)
+ grub_putcode (' ', term);
+}
+
+extern void (*EXPORT_VAR (grub_term_poll_usb)) (int wait_for_completion);
+
+#define GRUB_TERM_REPEAT_PRE_INTERVAL 400
+#define GRUB_TERM_REPEAT_INTERVAL 50
+
+#endif /* ! ASM_FILE */
+
+#endif /* ! GRUB_TERM_HEADER */
diff --git a/include/grub/terminfo.h b/include/grub/terminfo.h
new file mode 100644
index 0000000..8a109ec
--- /dev/null
+++ b/include/grub/terminfo.h
@@ -0,0 +1,87 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2003,2005,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_TERMINFO_HEADER
+#define GRUB_TERMINFO_HEADER 1
+
+#include <grub/err.h>
+#include <grub/types.h>
+#include <grub/term.h>
+
+char *EXPORT_FUNC(grub_terminfo_get_current) (struct grub_term_output *term);
+grub_err_t EXPORT_FUNC(grub_terminfo_set_current) (struct grub_term_output *term,
+ const char *);
+
+#define GRUB_TERMINFO_READKEY_MAX_LEN 6
+struct grub_terminfo_input_state
+{
+ int input_buf[GRUB_TERMINFO_READKEY_MAX_LEN];
+ int npending;
+#if defined(__powerpc__) && defined(GRUB_MACHINE_IEEE1275)
+ int last_key;
+ grub_uint64_t last_key_time;
+#endif
+ int (*readkey) (struct grub_term_input *term);
+};
+
+struct grub_terminfo_output_state
+{
+ struct grub_term_output *next;
+
+ char *name;
+
+ char *gotoxy;
+ char *cls;
+ char *reverse_video_on;
+ char *reverse_video_off;
+ char *cursor_on;
+ char *cursor_off;
+ char *setcolor;
+
+ struct grub_term_coordinate size;
+ struct grub_term_coordinate pos;
+
+ void (*put) (struct grub_term_output *term, const int c);
+};
+
+grub_err_t EXPORT_FUNC(grub_terminfo_output_init) (struct grub_term_output *term);
+void EXPORT_FUNC(grub_terminfo_gotoxy) (grub_term_output_t term,
+ struct grub_term_coordinate pos);
+void EXPORT_FUNC(grub_terminfo_cls) (grub_term_output_t term);
+struct grub_term_coordinate EXPORT_FUNC (grub_terminfo_getxy) (struct grub_term_output *term);
+void EXPORT_FUNC (grub_terminfo_setcursor) (struct grub_term_output *term,
+ const int on);
+void EXPORT_FUNC (grub_terminfo_setcolorstate) (struct grub_term_output *term,
+ const grub_term_color_state state);
+
+
+grub_err_t EXPORT_FUNC (grub_terminfo_input_init) (struct grub_term_input *term);
+int EXPORT_FUNC (grub_terminfo_getkey) (struct grub_term_input *term);
+void EXPORT_FUNC (grub_terminfo_putchar) (struct grub_term_output *term,
+ const struct grub_unicode_glyph *c);
+struct grub_term_coordinate EXPORT_FUNC (grub_terminfo_getwh) (struct grub_term_output *term);
+
+
+grub_err_t EXPORT_FUNC (grub_terminfo_output_register) (struct grub_term_output *term,
+ const char *type);
+grub_err_t EXPORT_FUNC (grub_terminfo_output_unregister) (struct grub_term_output *term);
+
+void grub_terminfo_init (void);
+void grub_terminfo_fini (void);
+
+#endif /* ! GRUB_TERMINFO_HEADER */
diff --git a/include/grub/test.h b/include/grub/test.h
new file mode 100644
index 0000000..b83bdb1
--- /dev/null
+++ b/include/grub/test.h
@@ -0,0 +1,125 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_TEST_HEADER
+#define GRUB_TEST_HEADER
+
+#include <grub/dl.h>
+#include <grub/list.h>
+#include <grub/misc.h>
+#include <grub/types.h>
+#include <grub/symbol.h>
+
+#include <grub/video.h>
+#include <grub/video_fb.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct grub_test
+{
+ /* The next test. */
+ struct grub_test *next;
+ struct grub_test **prev;
+
+ /* The test name. */
+ char *name;
+
+ /* The test main function. */
+ void (*main) (void);
+};
+typedef struct grub_test *grub_test_t;
+
+extern grub_test_t grub_test_list;
+
+void grub_test_register (const char *name, void (*test) (void));
+void grub_test_unregister (const char *name);
+
+/* Execute a test and print results. */
+int grub_test_run (grub_test_t test);
+
+/* Test `cond' for nonzero; log failure otherwise. */
+void grub_test_nonzero (int cond, const char *file,
+ const char *func, grub_uint32_t line,
+ const char *fmt, ...)
+ __attribute__ ((format (GNU_PRINTF, 5, 6)));
+
+/* Macro to fill in location details and an optional error message. */
+void grub_test_assert_helper (int cond, const char *file,
+ const char *func, grub_uint32_t line,
+ const char *condstr, const char *fmt, ...)
+ __attribute__ ((format (GNU_PRINTF, 6, 7)));
+
+#define grub_test_assert(cond, ...) \
+ grub_test_assert_helper(cond, GRUB_FILE, __FUNCTION__, __LINE__, \
+ #cond, ## __VA_ARGS__);
+
+void grub_unit_test_init (void);
+void grub_unit_test_fini (void);
+
+/* Macro to define a unit test. */
+#define GRUB_UNIT_TEST(name, funp) \
+ void grub_unit_test_init (void) \
+ { \
+ grub_test_register (name, funp); \
+ } \
+ \
+ void grub_unit_test_fini (void) \
+ { \
+ grub_test_unregister (name); \
+ }
+
+/* Macro to define a functional test. */
+#define GRUB_FUNCTIONAL_TEST(name, funp) \
+ GRUB_MOD_INIT(name) \
+ { \
+ grub_test_register (#name, funp); \
+ } \
+ \
+ GRUB_MOD_FINI(name) \
+ { \
+ grub_test_unregister (#name); \
+ }
+
+void
+grub_video_checksum (const char *basename_in);
+void
+grub_video_checksum_end (void);
+void
+grub_terminal_input_fake_sequence (int *seq_in, int nseq_in);
+void
+grub_terminal_input_fake_sequence_end (void);
+const char *
+grub_video_checksum_get_modename (void);
+
+
+#define GRUB_TEST_VIDEO_SMALL_N_MODES 7
+#define GRUB_TEST_VIDEO_ALL_N_MODES 31
+
+extern struct grub_video_mode_info grub_test_video_modes[GRUB_TEST_VIDEO_ALL_N_MODES];
+
+int
+grub_test_use_gfxterm (void);
+void grub_test_use_gfxterm_end (void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ! GRUB_TEST_HEADER */
diff --git a/include/grub/time.h b/include/grub/time.h
new file mode 100644
index 0000000..32f0afa
--- /dev/null
+++ b/include/grub/time.h
@@ -0,0 +1,48 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2007, 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef KERNEL_TIME_HEADER
+#define KERNEL_TIME_HEADER 1
+
+#include <grub/types.h>
+#include <grub/symbol.h>
+#if !defined(GRUB_MACHINE_EMU) && !defined(GRUB_UTIL)
+#include <grub/cpu/time.h>
+#else
+static inline void
+grub_cpu_idle(void)
+{
+}
+#endif
+
+#define NSEC_PER_SEC ((grub_int64_t) 1000000000)
+
+void EXPORT_FUNC(grub_millisleep) (grub_uint32_t ms);
+grub_uint64_t EXPORT_FUNC(grub_get_time_ms) (void);
+
+grub_uint64_t grub_rtc_get_time_ms (void);
+
+static __inline void
+grub_sleep (grub_uint32_t s)
+{
+ grub_millisleep (1000 * s);
+}
+
+void grub_install_get_time_ms (grub_uint64_t (*get_time_ms_func) (void));
+
+#endif /* ! KERNEL_TIME_HEADER */
diff --git a/include/grub/tparm.h b/include/grub/tparm.h
new file mode 100644
index 0000000..0c6f9e0
--- /dev/null
+++ b/include/grub/tparm.h
@@ -0,0 +1,26 @@
+/* tparm.h - parameter formatting of terminfo */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2005,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_TPARM_HEADER
+#define GRUB_TPARM_HEADER 1
+
+/* Function prototypes. */
+const char *grub_terminfo_tparm (const char *string, ...);
+
+#endif /* ! GRUB_TPARM_HEADER */
diff --git a/include/grub/tpm.h b/include/grub/tpm.h
new file mode 100644
index 0000000..5c285cb
--- /dev/null
+++ b/include/grub/tpm.h
@@ -0,0 +1,39 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2018 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_TPM_HEADER
+#define GRUB_TPM_HEADER 1
+
+#define GRUB_STRING_PCR 8
+#define GRUB_BINARY_PCR 9
+
+#define SHA1_DIGEST_SIZE 20
+
+#define TPM_BASE 0x0
+#define TPM_SUCCESS TPM_BASE
+#define TPM_AUTHFAIL (TPM_BASE + 0x1)
+#define TPM_BADINDEX (TPM_BASE + 0x2)
+
+#define TPM_TAG_RQU_COMMAND 0x00C1
+#define TPM_ORD_Extend 0x14
+
+#define EV_IPL 0x0d
+
+grub_err_t grub_tpm_measure (unsigned char *buf, grub_size_t size,
+ grub_uint8_t pcr, const char *description);
+#endif
diff --git a/include/grub/trig.h b/include/grub/trig.h
new file mode 100644
index 0000000..f19617c
--- /dev/null
+++ b/include/grub/trig.h
@@ -0,0 +1,44 @@
+/* trig.h - Trigonometric function support. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_TRIG_HEADER
+#define GRUB_TRIG_HEADER 1
+
+#define GRUB_TRIG_ANGLE_MAX 256
+#define GRUB_TRIG_ANGLE_MASK 255
+#define GRUB_TRIG_FRACTION_SCALE 16384
+
+extern const short grub_trig_sintab[];
+extern const short grub_trig_costab[];
+
+static __inline int
+grub_sin (int x)
+{
+ x &= GRUB_TRIG_ANGLE_MASK;
+ return grub_trig_sintab[x];
+}
+
+static __inline int
+grub_cos (int x)
+{
+ x &= GRUB_TRIG_ANGLE_MASK;
+ return grub_trig_costab[x];
+}
+
+#endif /* ! GRUB_TRIG_HEADER */
diff --git a/include/grub/types.h b/include/grub/types.h
new file mode 100644
index 0000000..0a3ff15
--- /dev/null
+++ b/include/grub/types.h
@@ -0,0 +1,343 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_TYPES_HEADER
+#define GRUB_TYPES_HEADER 1
+
+#include <config.h>
+#ifndef GRUB_UTIL
+#include <grub/cpu/types.h>
+#endif
+
+#ifdef __MINGW32__
+#define GRUB_PACKED __attribute__ ((packed,gcc_struct))
+#else
+#define GRUB_PACKED __attribute__ ((packed))
+#endif
+
+#ifdef GRUB_BUILD
+# define GRUB_CPU_SIZEOF_VOID_P BUILD_SIZEOF_VOID_P
+# define GRUB_CPU_SIZEOF_LONG BUILD_SIZEOF_LONG
+# if BUILD_WORDS_BIGENDIAN
+# define GRUB_CPU_WORDS_BIGENDIAN 1
+# else
+# undef GRUB_CPU_WORDS_BIGENDIAN
+# endif
+#elif defined (GRUB_UTIL)
+# define GRUB_CPU_SIZEOF_VOID_P SIZEOF_VOID_P
+# define GRUB_CPU_SIZEOF_LONG SIZEOF_LONG
+# ifdef WORDS_BIGENDIAN
+# define GRUB_CPU_WORDS_BIGENDIAN 1
+# else
+# undef GRUB_CPU_WORDS_BIGENDIAN
+# endif
+#else /* ! GRUB_UTIL */
+# define GRUB_CPU_SIZEOF_VOID_P GRUB_TARGET_SIZEOF_VOID_P
+# define GRUB_CPU_SIZEOF_LONG GRUB_TARGET_SIZEOF_LONG
+# ifdef GRUB_TARGET_WORDS_BIGENDIAN
+# define GRUB_CPU_WORDS_BIGENDIAN 1
+# else
+# undef GRUB_CPU_WORDS_BIGENDIAN
+# endif
+#endif /* ! GRUB_UTIL */
+
+#if GRUB_CPU_SIZEOF_VOID_P != 4 && GRUB_CPU_SIZEOF_VOID_P != 8
+# error "This architecture is not supported because sizeof(void *) != 4 and sizeof(void *) != 8"
+#endif
+
+#if GRUB_CPU_SIZEOF_LONG != 4 && GRUB_CPU_SIZEOF_LONG != 8
+# error "This architecture is not supported because sizeof(long) != 4 and sizeof(long) != 8"
+#endif
+
+#if !defined (GRUB_UTIL) && !defined (GRUB_TARGET_WORDSIZE)
+# if GRUB_TARGET_SIZEOF_VOID_P == 4
+# define GRUB_TARGET_WORDSIZE 32
+# elif GRUB_TARGET_SIZEOF_VOID_P == 8
+# define GRUB_TARGET_WORDSIZE 64
+# endif
+#endif
+
+#ifndef __CHAR_BIT__
+# error __CHAR_BIT__ is not defined
+#elif __CHAR_BIT__ != 8
+# error __CHAR_BIT__ is not equal 8
+#else
+# define GRUB_CHAR_BIT __CHAR_BIT__
+#endif
+
+#define GRUB_TYPE_BITS(type) (sizeof(type) * GRUB_CHAR_BIT)
+
+/* Define various wide integers. */
+typedef signed char grub_int8_t;
+typedef short grub_int16_t;
+typedef int grub_int32_t;
+# define PRIxGRUB_INT32_T "x"
+# define PRIdGRUB_INT32_T "d"
+#if GRUB_CPU_SIZEOF_LONG == 8
+typedef long grub_int64_t;
+# define PRIxGRUB_INT64_T "lx"
+# define PRIdGRUB_INT64_T "ld"
+#else
+typedef long long grub_int64_t;
+# define PRIxGRUB_INT64_T "llx"
+# define PRIdGRUB_INT64_T "lld"
+#endif
+
+typedef unsigned char grub_uint8_t;
+typedef unsigned short grub_uint16_t;
+typedef unsigned grub_uint32_t;
+# define PRIxGRUB_UINT32_T "x"
+# define PRIuGRUB_UINT32_T "u"
+#if GRUB_CPU_SIZEOF_LONG == 8
+typedef unsigned long grub_uint64_t;
+# define PRIxGRUB_UINT64_T "lx"
+# define PRIuGRUB_UINT64_T "lu"
+#else
+typedef unsigned long long grub_uint64_t;
+# define PRIxGRUB_UINT64_T "llx"
+# define PRIuGRUB_UINT64_T "llu"
+#endif
+
+/* Misc types. */
+
+#if GRUB_CPU_SIZEOF_VOID_P == 8
+typedef grub_uint64_t grub_addr_t;
+typedef grub_uint64_t grub_size_t;
+typedef grub_int64_t grub_ssize_t;
+
+# define GRUB_SIZE_MAX 18446744073709551615UL
+
+# if GRUB_CPU_SIZEOF_LONG == 8
+# define PRIxGRUB_SIZE "lx"
+# define PRIxGRUB_ADDR "lx"
+# define PRIuGRUB_SIZE "lu"
+# define PRIdGRUB_SSIZE "ld"
+# else
+# define PRIxGRUB_SIZE "llx"
+# define PRIxGRUB_ADDR "llx"
+# define PRIuGRUB_SIZE "llu"
+# define PRIdGRUB_SSIZE "lld"
+# endif
+#else
+typedef grub_uint32_t grub_addr_t;
+typedef grub_uint32_t grub_size_t;
+typedef grub_int32_t grub_ssize_t;
+
+# define GRUB_SIZE_MAX 4294967295UL
+
+# define PRIxGRUB_SIZE "x"
+# define PRIxGRUB_ADDR "x"
+# define PRIuGRUB_SIZE "u"
+# define PRIdGRUB_SSIZE "d"
+#endif
+
+#define GRUB_SCHAR_MAX 127
+#define GRUB_SCHAR_MIN (-GRUB_SCHAR_MAX - 1)
+#define GRUB_UCHAR_MAX 0xFF
+#define GRUB_USHRT_MAX 65535
+#define GRUB_SHRT_MAX 0x7fff
+#define GRUB_SHRT_MIN (-GRUB_SHRT_MAX - 1)
+#define GRUB_UINT_MAX 4294967295U
+#define GRUB_INT_MAX 0x7fffffff
+#define GRUB_INT_MIN (-GRUB_INT_MAX - 1)
+#define GRUB_INT32_MAX 2147483647
+#define GRUB_INT32_MIN (-GRUB_INT32_MAX - 1)
+
+#if GRUB_CPU_SIZEOF_LONG == 8
+# define GRUB_ULONG_MAX 18446744073709551615UL
+# define GRUB_LONG_MAX 9223372036854775807L
+#else
+# define GRUB_ULONG_MAX 4294967295UL
+# define GRUB_LONG_MAX 2147483647L
+#endif
+# define GRUB_LONG_MIN (-GRUB_LONG_MAX - 1)
+
+/*
+ * Cast to unsigned long long so that the "return value" is always a consistent
+ * type and to ensure an unsigned value regardless of type parameter.
+ */
+#define GRUB_TYPE_U_MAX(type) ((unsigned long long)((typeof (type))(~0)))
+#define GRUB_TYPE_U_MIN(type) 0ULL
+
+typedef grub_uint64_t grub_properly_aligned_t;
+
+#define GRUB_PROPERLY_ALIGNED_ARRAY(name, size) grub_properly_aligned_t name[((size) + sizeof (grub_properly_aligned_t) - 1) / sizeof (grub_properly_aligned_t)]
+
+/* The type for representing a file offset. */
+typedef grub_uint64_t grub_off_t;
+
+/* The type for representing a disk block address. */
+typedef grub_uint64_t grub_disk_addr_t;
+
+/* Byte-orders. */
+static inline grub_uint16_t grub_swap_bytes16(grub_uint16_t _x)
+{
+ return (grub_uint16_t) ((_x << 8) | (_x >> 8));
+}
+
+#define grub_swap_bytes16_compile_time(x) ((((x) & 0xff) << 8) | (((x) & 0xff00) >> 8))
+#define grub_swap_bytes32_compile_time(x) ((((x) & 0xff) << 24) | (((x) & 0xff00) << 8) | (((x) & 0xff0000) >> 8) | (((x) & 0xff000000UL) >> 24))
+#define grub_swap_bytes64_compile_time(x) \
+({ \
+ grub_uint64_t _x = (x); \
+ (grub_uint64_t) ((_x << 56) \
+ | ((_x & (grub_uint64_t) 0xFF00ULL) << 40) \
+ | ((_x & (grub_uint64_t) 0xFF0000ULL) << 24) \
+ | ((_x & (grub_uint64_t) 0xFF000000ULL) << 8) \
+ | ((_x & (grub_uint64_t) 0xFF00000000ULL) >> 8) \
+ | ((_x & (grub_uint64_t) 0xFF0000000000ULL) >> 24) \
+ | ((_x & (grub_uint64_t) 0xFF000000000000ULL) >> 40) \
+ | (_x >> 56)); \
+})
+
+#if (defined(__GNUC__) && (__GNUC__ > 3) && (__GNUC__ > 4 || __GNUC_MINOR__ >= 3)) || defined(__clang__)
+static inline grub_uint32_t grub_swap_bytes32(grub_uint32_t x)
+{
+ return __builtin_bswap32(x);
+}
+
+static inline grub_uint64_t grub_swap_bytes64(grub_uint64_t x)
+{
+ return __builtin_bswap64(x);
+}
+#else /* not gcc 4.3 or newer */
+static inline grub_uint32_t grub_swap_bytes32(grub_uint32_t _x)
+{
+ return ((_x << 24)
+ | ((_x & (grub_uint32_t) 0xFF00UL) << 8)
+ | ((_x & (grub_uint32_t) 0xFF0000UL) >> 8)
+ | (_x >> 24));
+}
+
+static inline grub_uint64_t grub_swap_bytes64(grub_uint64_t _x)
+{
+ return ((_x << 56)
+ | ((_x & (grub_uint64_t) 0xFF00ULL) << 40)
+ | ((_x & (grub_uint64_t) 0xFF0000ULL) << 24)
+ | ((_x & (grub_uint64_t) 0xFF000000ULL) << 8)
+ | ((_x & (grub_uint64_t) 0xFF00000000ULL) >> 8)
+ | ((_x & (grub_uint64_t) 0xFF0000000000ULL) >> 24)
+ | ((_x & (grub_uint64_t) 0xFF000000000000ULL) >> 40)
+ | (_x >> 56));
+}
+#endif /* not gcc 4.3 or newer */
+
+#ifdef GRUB_CPU_WORDS_BIGENDIAN
+# define grub_cpu_to_le16(x) grub_swap_bytes16(x)
+# define grub_cpu_to_le32(x) grub_swap_bytes32(x)
+# define grub_cpu_to_le64(x) grub_swap_bytes64(x)
+# define grub_le_to_cpu16(x) grub_swap_bytes16(x)
+# define grub_le_to_cpu32(x) grub_swap_bytes32(x)
+# define grub_le_to_cpu64(x) grub_swap_bytes64(x)
+# define grub_cpu_to_be16(x) ((grub_uint16_t) (x))
+# define grub_cpu_to_be32(x) ((grub_uint32_t) (x))
+# define grub_cpu_to_be64(x) ((grub_uint64_t) (x))
+# define grub_be_to_cpu16(x) ((grub_uint16_t) (x))
+# define grub_be_to_cpu32(x) ((grub_uint32_t) (x))
+# define grub_be_to_cpu64(x) ((grub_uint64_t) (x))
+# define grub_cpu_to_be16_compile_time(x) ((grub_uint16_t) (x))
+# define grub_cpu_to_be32_compile_time(x) ((grub_uint32_t) (x))
+# define grub_cpu_to_be64_compile_time(x) ((grub_uint64_t) (x))
+# define grub_be_to_cpu64_compile_time(x) ((grub_uint64_t) (x))
+# define grub_cpu_to_le32_compile_time(x) grub_swap_bytes32_compile_time(x)
+# define grub_cpu_to_le64_compile_time(x) grub_swap_bytes64_compile_time(x)
+# define grub_cpu_to_le16_compile_time(x) grub_swap_bytes16_compile_time(x)
+#else /* ! WORDS_BIGENDIAN */
+# define grub_cpu_to_le16(x) ((grub_uint16_t) (x))
+# define grub_cpu_to_le32(x) ((grub_uint32_t) (x))
+# define grub_cpu_to_le64(x) ((grub_uint64_t) (x))
+# define grub_le_to_cpu16(x) ((grub_uint16_t) (x))
+# define grub_le_to_cpu32(x) ((grub_uint32_t) (x))
+# define grub_le_to_cpu64(x) ((grub_uint64_t) (x))
+# define grub_cpu_to_be16(x) grub_swap_bytes16(x)
+# define grub_cpu_to_be32(x) grub_swap_bytes32(x)
+# define grub_cpu_to_be64(x) grub_swap_bytes64(x)
+# define grub_be_to_cpu16(x) grub_swap_bytes16(x)
+# define grub_be_to_cpu32(x) grub_swap_bytes32(x)
+# define grub_be_to_cpu64(x) grub_swap_bytes64(x)
+# define grub_cpu_to_be16_compile_time(x) grub_swap_bytes16_compile_time(x)
+# define grub_cpu_to_be32_compile_time(x) grub_swap_bytes32_compile_time(x)
+# define grub_cpu_to_be64_compile_time(x) grub_swap_bytes64_compile_time(x)
+# define grub_be_to_cpu64_compile_time(x) grub_swap_bytes64_compile_time(x)
+# define grub_cpu_to_le16_compile_time(x) ((grub_uint16_t) (x))
+# define grub_cpu_to_le32_compile_time(x) ((grub_uint32_t) (x))
+# define grub_cpu_to_le64_compile_time(x) ((grub_uint64_t) (x))
+
+#endif /* ! WORDS_BIGENDIAN */
+
+struct grub_unaligned_uint16
+{
+ grub_uint16_t val;
+} GRUB_PACKED;
+struct grub_unaligned_uint32
+{
+ grub_uint32_t val;
+} GRUB_PACKED;
+struct grub_unaligned_uint64
+{
+ grub_uint64_t val;
+} GRUB_PACKED;
+
+typedef struct grub_unaligned_uint16 grub_unaligned_uint16_t;
+typedef struct grub_unaligned_uint32 grub_unaligned_uint32_t;
+typedef struct grub_unaligned_uint64 grub_unaligned_uint64_t;
+
+static inline grub_uint16_t grub_get_unaligned16 (const void *ptr)
+{
+ const struct grub_unaligned_uint16 *dd
+ = (const struct grub_unaligned_uint16 *) ptr;
+ return dd->val;
+}
+
+static inline void grub_set_unaligned16 (void *ptr, grub_uint16_t val)
+{
+ struct grub_unaligned_uint16 *dd = (struct grub_unaligned_uint16 *) ptr;
+ dd->val = val;
+}
+
+static inline grub_uint32_t grub_get_unaligned32 (const void *ptr)
+{
+ const struct grub_unaligned_uint32 *dd
+ = (const struct grub_unaligned_uint32 *) ptr;
+ return dd->val;
+}
+
+static inline void grub_set_unaligned32 (void *ptr, grub_uint32_t val)
+{
+ struct grub_unaligned_uint32 *dd = (struct grub_unaligned_uint32 *) ptr;
+ dd->val = val;
+}
+
+static inline grub_uint64_t grub_get_unaligned64 (const void *ptr)
+{
+ const struct grub_unaligned_uint64 *dd
+ = (const struct grub_unaligned_uint64 *) ptr;
+ return dd->val;
+}
+
+static inline void grub_set_unaligned64 (void *ptr, grub_uint64_t val)
+{
+ struct grub_unaligned_uint64_t
+ {
+ grub_uint64_t d;
+ } GRUB_PACKED;
+ struct grub_unaligned_uint64_t *dd = (struct grub_unaligned_uint64_t *) ptr;
+ dd->d = val;
+}
+
+#endif /* ! GRUB_TYPES_HEADER */
diff --git a/include/grub/uboot/api_public.h b/include/grub/uboot/api_public.h
new file mode 100644
index 0000000..0707f5c
--- /dev/null
+++ b/include/grub/uboot/api_public.h
@@ -0,0 +1,181 @@
+/*
+ * (C) Copyright 2007-2008 Semihalf
+ *
+ * Written by: Rafal Jaworowski <raj@semihalf.com>
+ *
+ * This file is dual licensed; you can use it under the terms of
+ * either the GPL, or the BSD license, at your option.
+ *
+ * I. GPL:
+ *
+ * This file is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This file is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ * Alternatively,
+ *
+ * II. BSD license:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _API_PUBLIC_H_
+#define _API_PUBLIC_H_
+
+#define API_EINVAL 1 /* invalid argument(s) */
+#define API_ENODEV 2 /* no device */
+#define API_ENOMEM 3 /* no memory */
+#define API_EBUSY 4 /* busy, occupied etc. */
+#define API_EIO 5 /* I/O error */
+#define API_ESYSC 6 /* syscall error */
+
+typedef int (*scp_t) (int, int *, ...);
+
+#define API_SIG_VERSION 1
+#define API_SIG_MAGIC "UBootAPI"
+#define API_SIG_MAGLEN 8
+
+struct api_signature
+{
+ char magic[API_SIG_MAGLEN]; /* magic string */
+ grub_uint16_t version; /* API version */
+ grub_uint32_t checksum; /* checksum of this sig struct */
+ scp_t syscall; /* entry point to the API */
+};
+
+enum
+{
+ API_RSVD = 0,
+ API_GETC,
+ API_PUTC,
+ API_TSTC,
+ API_PUTS,
+ API_RESET,
+ API_GET_SYS_INFO,
+ API_UDELAY,
+ API_GET_TIMER,
+ API_DEV_ENUM,
+ API_DEV_OPEN,
+ API_DEV_CLOSE,
+ API_DEV_READ,
+ API_DEV_WRITE,
+ API_ENV_ENUM,
+ API_ENV_GET,
+ API_ENV_SET,
+ API_DISPLAY_GET_INFO,
+ API_DISPLAY_DRAW_BITMAP,
+ API_DISPLAY_CLEAR,
+ API_MAXCALL
+};
+
+#define MR_ATTR_FLASH 0x0001
+#define MR_ATTR_DRAM 0x0002
+#define MR_ATTR_SRAM 0x0003
+#define MR_ATTR_MASK 0x000f
+
+struct mem_region
+{
+ unsigned long start;
+ unsigned long size;
+ int flags;
+};
+
+struct sys_info
+{
+ unsigned long clk_bus;
+ unsigned long clk_cpu;
+ unsigned long bar;
+ struct mem_region *mr;
+ int mr_no; /* number of memory regions */
+};
+
+#undef CONFIG_SYS_64BIT_LBA
+#ifdef CONFIG_SYS_64BIT_LBA
+typedef u_int64_t lbasize_t;
+#else
+typedef unsigned long lbasize_t;
+#endif
+typedef unsigned long lbastart_t;
+
+#define DEV_TYP_NONE 0x0000
+#define DEV_TYP_NET 0x0001
+
+#define DEV_TYP_STOR 0x0002
+#define DT_STOR_IDE 0x0010
+#define DT_STOR_SCSI 0x0020
+#define DT_STOR_USB 0x0040
+#define DT_STOR_MMC 0x0080
+#define DT_STOR_SATA 0x0100
+
+#define DEV_STA_CLOSED 0x0000 /* invalid, closed */
+#define DEV_STA_OPEN 0x0001 /* open i.e. active */
+
+struct device_info
+{
+ int type;
+ void *cookie;
+
+ union
+ {
+ struct
+ {
+ lbasize_t block_count; /* no of blocks */
+ unsigned long block_size; /* size of one block */
+ } storage;
+
+ struct
+ {
+ unsigned char hwaddr[6];
+ } net;
+ } info;
+#define di_stor info.storage
+#define di_net info.net
+
+ int state;
+};
+
+#define DISPLAY_TYPE_LCD 0x0001
+#define DISPLAY_TYPE_VIDEO 0x0002
+
+struct display_info
+{
+ int type;
+ /* screen size in pixels */
+ int pixel_width;
+ int pixel_height;
+ /* screen size in rows and columns of text */
+ int screen_rows;
+ int screen_cols;
+};
+
+#endif /* _API_PUBLIC_H_ */
diff --git a/include/grub/uboot/console.h b/include/grub/uboot/console.h
new file mode 100644
index 0000000..993a538
--- /dev/null
+++ b/include/grub/uboot/console.h
@@ -0,0 +1,29 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_CONSOLE_MACHINE_HEADER
+#define GRUB_CONSOLE_MACHINE_HEADER 1
+
+/* Initialize the console system. */
+void grub_console_init_early (void);
+void grub_console_init_lately (void);
+
+/* Exit the console system. */
+void grub_console_fini (void);
+
+#endif /* ! GRUB_CONSOLE_MACHINE_HEADER */
diff --git a/include/grub/uboot/disk.h b/include/grub/uboot/disk.h
new file mode 100644
index 0000000..e380b4c
--- /dev/null
+++ b/include/grub/uboot/disk.h
@@ -0,0 +1,43 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_UBOOT_DISK_HEADER
+#define GRUB_UBOOT_DISK_HEADER 1
+
+#include <grub/symbol.h>
+#include <grub/disk.h>
+#include <grub/uboot/uboot.h>
+
+void grub_ubootdisk_init (void);
+void grub_ubootdisk_fini (void);
+
+enum disktype
+{ cd, fd, hd };
+
+struct ubootdisk_data
+{
+ void *cookie;
+ struct device_info *dev;
+ int opencount;
+ enum disktype type;
+ grub_uint32_t block_size;
+};
+
+grub_err_t grub_ubootdisk_register (struct device_info *newdev);
+
+#endif /* ! GRUB_UBOOT_DISK_HEADER */
diff --git a/include/grub/uboot/image.h b/include/grub/uboot/image.h
new file mode 100644
index 0000000..3e3f034
--- /dev/null
+++ b/include/grub/uboot/image.h
@@ -0,0 +1,175 @@
+/*
+ * (C) Copyright 2008 Semihalf
+ *
+ * (C) Copyright 2000-2005
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ ********************************************************************
+ * NOTE: This header file defines an interface to U-Boot. Including
+ * this (unmodified) header file in another file is considered normal
+ * use of U-Boot, and does *not* fall under the heading of "derived
+ * work".
+ ********************************************************************
+ */
+
+#ifndef __GRUB_UBOOT_IMAGE_H__
+#define __GRUB_UBOOT_IMAGE_H__
+
+/*
+ * Operating System Codes
+ */
+#define GRUB_UBOOT_IH_OS_INVALID 0 /* Invalid OS */
+#define GRUB_UBOOT_IH_OS_OPENBSD 1 /* OpenBSD */
+#define GRUB_UBOOT_IH_OS_NETBSD 2 /* NetBSD */
+#define GRUB_UBOOT_IH_OS_FREEBSD 3 /* FreeBSD */
+#define GRUB_UBOOT_IH_OS_4_4BSD 4 /* 4.4BSD */
+#define GRUB_UBOOT_IH_OS_LINUX 5 /* Linux */
+#define GRUB_UBOOT_IH_OS_SVR4 6 /* SVR4 */
+#define GRUB_UBOOT_IH_OS_ESIX 7 /* Esix */
+#define GRUB_UBOOT_IH_OS_SOLARIS 8 /* Solaris */
+#define GRUB_UBOOT_IH_OS_IRIX 9 /* Irix */
+#define GRUB_UBOOT_IH_OS_SCO 10 /* SCO */
+#define GRUB_UBOOT_IH_OS_DELL 11 /* Dell */
+#define GRUB_UBOOT_IH_OS_NCR 12 /* NCR */
+#define GRUB_UBOOT_IH_OS_LYNXOS 13 /* LynxOS */
+#define GRUB_UBOOT_IH_OS_VXWORKS 14 /* VxWorks */
+#define GRUB_UBOOT_IH_OS_PSOS 15 /* pSOS */
+#define GRUB_UBOOT_IH_OS_QNX 16 /* QNX */
+#define GRUB_UBOOT_IH_OS_U_BOOT 17 /* Firmware */
+#define GRUB_UBOOT_IH_OS_RTEMS 18 /* RTEMS */
+#define GRUB_UBOOT_IH_OS_ARTOS 19 /* ARTOS */
+#define GRUB_UBOOT_IH_OS_UNITY 20 /* Unity OS */
+#define GRUB_UBOOT_IH_OS_INTEGRITY 21 /* INTEGRITY */
+#define GRUB_UBOOT_IH_OS_OSE 22 /* OSE */
+
+/*
+ * CPU Architecture Codes (supported by Linux)
+ */
+#define GRUB_UBOOT_IH_ARCH_INVALID 0 /* Invalid CPU */
+#define GRUB_UBOOT_IH_ARCH_ALPHA 1 /* Alpha */
+#define GRUB_UBOOT_IH_ARCH_ARM 2 /* ARM */
+#define GRUB_UBOOT_IH_ARCH_I386 3 /* Intel x86 */
+#define GRUB_UBOOT_IH_ARCH_IA64 4 /* IA64 */
+#define GRUB_UBOOT_IH_ARCH_MIPS 5 /* MIPS */
+#define GRUB_UBOOT_IH_ARCH_MIPS64 6 /* MIPS 64 Bit */
+#define GRUB_UBOOT_IH_ARCH_PPC 7 /* PowerPC */
+#define GRUB_UBOOT_IH_ARCH_S390 8 /* IBM S390 */
+#define GRUB_UBOOT_IH_ARCH_SH 9 /* SuperH */
+#define GRUB_UBOOT_IH_ARCH_SPARC 10 /* Sparc */
+#define GRUB_UBOOT_IH_ARCH_SPARC64 11 /* Sparc 64 Bit */
+#define GRUB_UBOOT_IH_ARCH_M68K 12 /* M68K */
+#define GRUB_UBOOT_IH_ARCH_MICROBLAZE 14 /* MicroBlaze */
+#define GRUB_UBOOT_IH_ARCH_NIOS2 15 /* Nios-II */
+#define GRUB_UBOOT_IH_ARCH_BLACKFIN 16 /* Blackfin */
+#define GRUB_UBOOT_IH_ARCH_AVR32 17 /* AVR32 */
+#define GRUB_UBOOT_IH_ARCH_ST200 18 /* STMicroelectronics ST200 */
+#define GRUB_UBOOT_IH_ARCH_SANDBOX 19 /* Sandbox architecture (test only) */
+#define GRUB_UBOOT_IH_ARCH_NDS32 20 /* ANDES Technology - NDS32 */
+#define GRUB_UBOOT_IH_ARCH_OPENRISC 21 /* OpenRISC 1000 */
+
+/*
+ * Image Types
+ *
+ * "Standalone Programs" are directly runnable in the environment
+ * provided by U-Boot; it is expected that (if they behave
+ * well) you can continue to work in U-Boot after return from
+ * the Standalone Program.
+ * "OS Kernel Images" are usually images of some Embedded OS which
+ * will take over control completely. Usually these programs
+ * will install their own set of exception handlers, device
+ * drivers, set up the MMU, etc. - this means, that you cannot
+ * expect to re-enter U-Boot except by resetting the CPU.
+ * "RAMDisk Images" are more or less just data blocks, and their
+ * parameters (address, size) are passed to an OS kernel that is
+ * being started.
+ * "Multi-File Images" contain several images, typically an OS
+ * (Linux) kernel image and one or more data images like
+ * RAMDisks. This construct is useful for instance when you want
+ * to boot over the network using BOOTP etc., where the boot
+ * server provides just a single image file, but you want to get
+ * for instance an OS kernel and a RAMDisk image.
+ *
+ * "Multi-File Images" start with a list of image sizes, each
+ * image size (in bytes) specified by an "uint32_t" in network
+ * byte order. This list is terminated by an "(uint32_t)0".
+ * Immediately after the terminating 0 follow the images, one by
+ * one, all aligned on "uint32_t" boundaries (size rounded up to
+ * a multiple of 4 bytes - except for the last file).
+ *
+ * "Firmware Images" are binary images containing firmware (like
+ * U-Boot or FPGA images) which usually will be programmed to
+ * flash memory.
+ *
+ * "Script files" are command sequences that will be executed by
+ * U-Boot's command interpreter; this feature is especially
+ * useful when you configure U-Boot to use a real shell (hush)
+ * as command interpreter (=> Shell Scripts).
+ */
+
+#define GRUB_UBOOT_IH_TYPE_INVALID 0 /* Invalid Image */
+#define GRUB_UBOOT_IH_TYPE_STANDALONE 1 /* Standalone Program */
+#define GRUB_UBOOT_IH_TYPE_KERNEL 2 /* OS Kernel Image */
+#define GRUB_UBOOT_IH_TYPE_RAMDISK 3 /* RAMDisk Image */
+#define GRUB_UBOOT_IH_TYPE_MULTI 4 /* Multi-File Image */
+#define GRUB_UBOOT_IH_TYPE_FIRMWARE 5 /* Firmware Image */
+#define GRUB_UBOOT_IH_TYPE_SCRIPT 6 /* Script file */
+#define GRUB_UBOOT_IH_TYPE_FILESYSTEM 7 /* Filesystem Image (any type) */
+#define GRUB_UBOOT_IH_TYPE_FLATDT 8 /* Binary Flat Device Tree Blob */
+#define GRUB_UBOOT_IH_TYPE_KWBIMAGE 9 /* Kirkwood Boot Image */
+#define GRUB_UBOOT_IH_TYPE_IMXIMAGE 10 /* Freescale IMXBoot Image */
+#define GRUB_UBOOT_IH_TYPE_UBLIMAGE 11 /* Davinci UBL Image */
+#define GRUB_UBOOT_IH_TYPE_OMAPIMAGE 12 /* TI OMAP Config Header Image */
+#define GRUB_UBOOT_IH_TYPE_AISIMAGE 13 /* TI Davinci AIS Image */
+#define GRUB_UBOOT_IH_TYPE_KERNEL_NOLOAD 14 /* OS Kernel Image, can run from any load address */
+#define GRUB_UBOOT_IH_TYPE_PBLIMAGE 15 /* Freescale PBL Boot Image */
+
+/*
+ * Compression Types
+ */
+#define GRUB_UBOOT_IH_COMP_NONE 0 /* No Compression Used */
+#define GRUB_UBOOT_IH_COMP_GZIP 1 /* gzip Compression Used */
+#define GRUB_UBOOT_IH_COMP_BZIP2 2 /* bzip2 Compression Used */
+#define GRUB_UBOOT_IH_COMP_LZMA 3 /* lzma Compression Used */
+#define GRUB_UBOOT_IH_COMP_LZO 4 /* lzo Compression Used */
+
+#define GRUB_UBOOT_IH_MAGIC 0x27051956 /* Image Magic Number */
+#define GRUB_UBOOT_IH_NMLEN 32 /* Image Name Length */
+
+/*
+ * Legacy format image header,
+ * all data in network byte order (aka natural aka bigendian).
+ */
+struct grub_uboot_image_header {
+ grub_uint32_t ih_magic; /* Image Header Magic Number */
+ grub_uint32_t ih_hcrc; /* Image Header CRC Checksum */
+ grub_uint32_t ih_time; /* Image Creation Timestamp */
+ grub_uint32_t ih_size; /* Image Data Size */
+ grub_uint32_t ih_load; /* Data Load Address */
+ grub_uint32_t ih_ep; /* Entry Point Address */
+ grub_uint32_t ih_dcrc; /* Image Data CRC Checksum */
+ grub_uint8_t ih_os; /* Operating System */
+ grub_uint8_t ih_arch; /* CPU architecture */
+ grub_uint8_t ih_type; /* Image Type */
+ grub_uint8_t ih_comp; /* Compression Type */
+ grub_uint8_t ih_name[GRUB_UBOOT_IH_NMLEN]; /* Image Name */
+};
+
+#endif /* __IMAGE_H__ */
diff --git a/include/grub/uboot/uboot.h b/include/grub/uboot/uboot.h
new file mode 100644
index 0000000..1941303
--- /dev/null
+++ b/include/grub/uboot/uboot.h
@@ -0,0 +1,87 @@
+/* uboot.h - declare variables and functions for U-Boot support */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_UBOOT_UBOOT_HEADER
+#define GRUB_UBOOT_UBOOT_HEADER 1
+
+#include <grub/types.h>
+#include <grub/dl.h>
+
+/* Functions. */
+void grub_uboot_mm_init (void);
+void grub_uboot_init (void);
+void grub_uboot_fini (void);
+
+void grub_uboot_return (int) __attribute__ ((noreturn));
+
+grub_addr_t grub_uboot_get_real_bss_start (void);
+
+grub_err_t grub_uboot_probe_hardware (void);
+
+extern grub_addr_t EXPORT_VAR (start_of_ram);
+
+grub_uint32_t EXPORT_FUNC (grub_uboot_get_machine_type) (void);
+grub_addr_t EXPORT_FUNC (grub_uboot_get_boot_data) (void);
+
+
+/*
+ * The U-Boot API operates through a "syscall" interface, consisting of an
+ * entry point address and a set of syscall numbers. The location of this
+ * entry point is described in a structure allocated on the U-Boot heap.
+ * We scan through a defined region around the hint address passed to us
+ * from U-Boot.
+ */
+
+#define UBOOT_API_SEARCH_LEN (3 * 1024 * 1024)
+int grub_uboot_api_init (void);
+
+/*
+ * All functions below are wrappers around the uboot_syscall() function,
+ * implemented in grub-core/kern/uboot/uboot.c
+*/
+
+int grub_uboot_getc (void);
+int grub_uboot_tstc (void);
+void grub_uboot_putc (int c);
+void grub_uboot_puts (const char *s);
+
+void EXPORT_FUNC (grub_uboot_reset) (void);
+
+struct sys_info *grub_uboot_get_sys_info (void);
+
+void grub_uboot_udelay (grub_uint32_t usec);
+grub_uint32_t grub_uboot_get_timer (grub_uint32_t base);
+
+int EXPORT_FUNC (grub_uboot_dev_enum) (void);
+struct device_info * EXPORT_FUNC (grub_uboot_dev_get) (int index);
+int EXPORT_FUNC (grub_uboot_dev_open) (struct device_info *dev);
+int EXPORT_FUNC (grub_uboot_dev_close) (struct device_info *dev);
+int grub_uboot_dev_write (struct device_info *dev, const void *buf,
+ grub_size_t blocks, grub_uint32_t start);
+int grub_uboot_dev_read (struct device_info *dev, void *buf, grub_size_t blocks,
+ grub_uint32_t start, grub_size_t * real_blocks);
+int EXPORT_FUNC (grub_uboot_dev_recv) (struct device_info *dev, void *buf,
+ int size, int *real_size);
+int EXPORT_FUNC (grub_uboot_dev_send) (struct device_info *dev, void *buf,
+ int size);
+
+char *grub_uboot_env_get (const char *name);
+void grub_uboot_env_set (const char *name, const char *value);
+
+#endif /* ! GRUB_UBOOT_UBOOT_HEADER */
diff --git a/include/grub/udf.h b/include/grub/udf.h
new file mode 100644
index 0000000..9053069
--- /dev/null
+++ b/include/grub/udf.h
@@ -0,0 +1,30 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_UDF_H
+#define GRUB_UDF_H 1
+
+#include <grub/types.h>
+
+#ifdef GRUB_UTIL
+#include <grub/disk.h>
+
+grub_disk_addr_t
+grub_udf_get_cluster_sector (grub_disk_t disk, grub_uint64_t *sec_per_lcn);
+#endif
+#endif
diff --git a/include/grub/unicode.h b/include/grub/unicode.h
new file mode 100644
index 0000000..4de986a
--- /dev/null
+++ b/include/grub/unicode.h
@@ -0,0 +1,360 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_BIDI_HEADER
+#define GRUB_BIDI_HEADER 1
+
+#include <grub/types.h>
+#include <grub/mm.h>
+#include <grub/misc.h>
+
+struct grub_unicode_bidi_pair
+{
+ grub_uint32_t key;
+ grub_uint32_t replace;
+};
+
+struct grub_unicode_compact_range
+{
+ unsigned start:21;
+ unsigned len:9;
+ unsigned bidi_type:5;
+ unsigned comb_type:8;
+ unsigned bidi_mirror:1;
+ unsigned join_type:3;
+} GRUB_PACKED;
+
+/* Old-style Arabic shaping. Used for "visual UTF-8" and
+ in grub-mkfont to find variant glyphs in absence of GPOS tables. */
+struct grub_unicode_arabic_shape
+{
+ grub_uint32_t code;
+ grub_uint32_t isolated;
+ grub_uint32_t right_linked;
+ grub_uint32_t both_linked;
+ grub_uint32_t left_linked;
+};
+
+extern struct grub_unicode_arabic_shape grub_unicode_arabic_shapes[];
+
+enum grub_bidi_type
+ {
+ GRUB_BIDI_TYPE_L = 0,
+ GRUB_BIDI_TYPE_LRE,
+ GRUB_BIDI_TYPE_LRO,
+ GRUB_BIDI_TYPE_R,
+ GRUB_BIDI_TYPE_AL,
+ GRUB_BIDI_TYPE_RLE,
+ GRUB_BIDI_TYPE_RLO,
+ GRUB_BIDI_TYPE_PDF,
+ GRUB_BIDI_TYPE_EN,
+ GRUB_BIDI_TYPE_ES,
+ GRUB_BIDI_TYPE_ET,
+ GRUB_BIDI_TYPE_AN,
+ GRUB_BIDI_TYPE_CS,
+ GRUB_BIDI_TYPE_NSM,
+ GRUB_BIDI_TYPE_BN,
+ GRUB_BIDI_TYPE_B,
+ GRUB_BIDI_TYPE_S,
+ GRUB_BIDI_TYPE_WS,
+ GRUB_BIDI_TYPE_ON
+ };
+
+enum grub_join_type
+ {
+ GRUB_JOIN_TYPE_NONJOINING = 0,
+ GRUB_JOIN_TYPE_LEFT = 1,
+ GRUB_JOIN_TYPE_RIGHT = 2,
+ GRUB_JOIN_TYPE_DUAL = 3,
+ GRUB_JOIN_TYPE_CAUSING = 4,
+ GRUB_JOIN_TYPE_TRANSPARENT = 5
+ };
+
+enum grub_comb_type
+ {
+ GRUB_UNICODE_COMB_NONE = 0,
+ GRUB_UNICODE_COMB_OVERLAY = 1,
+ GRUB_UNICODE_COMB_HEBREW_SHEVA = 10,
+ GRUB_UNICODE_COMB_HEBREW_HATAF_SEGOL = 11,
+ GRUB_UNICODE_COMB_HEBREW_HATAF_PATAH = 12,
+ GRUB_UNICODE_COMB_HEBREW_HATAF_QAMATS = 13,
+ GRUB_UNICODE_COMB_HEBREW_HIRIQ = 14,
+ GRUB_UNICODE_COMB_HEBREW_TSERE = 15,
+ GRUB_UNICODE_COMB_HEBREW_SEGOL = 16,
+ GRUB_UNICODE_COMB_HEBREW_PATAH = 17,
+ GRUB_UNICODE_COMB_HEBREW_QAMATS = 18,
+ GRUB_UNICODE_COMB_HEBREW_HOLAM = 19,
+ GRUB_UNICODE_COMB_HEBREW_QUBUTS = 20,
+ GRUB_UNICODE_COMB_HEBREW_DAGESH = 21,
+ GRUB_UNICODE_COMB_HEBREW_METEG = 22,
+ GRUB_UNICODE_COMB_HEBREW_RAFE = 23,
+ GRUB_UNICODE_COMB_HEBREW_SHIN_DOT = 24,
+ GRUB_UNICODE_COMB_HEBREW_SIN_DOT = 25,
+ GRUB_UNICODE_COMB_HEBREW_VARIKA = 26,
+ GRUB_UNICODE_COMB_ARABIC_FATHATAN = 27,
+ GRUB_UNICODE_COMB_ARABIC_DAMMATAN = 28,
+ GRUB_UNICODE_COMB_ARABIC_KASRATAN = 29,
+ GRUB_UNICODE_COMB_ARABIC_FATHAH = 30,
+ GRUB_UNICODE_COMB_ARABIC_DAMMAH = 31,
+ GRUB_UNICODE_COMB_ARABIC_KASRA = 32,
+ GRUB_UNICODE_COMB_ARABIC_SHADDA = 33,
+ GRUB_UNICODE_COMB_ARABIC_SUKUN = 34,
+ GRUB_UNICODE_COMB_ARABIC_SUPERSCRIPT_ALIF = 35,
+ GRUB_UNICODE_COMB_SYRIAC_SUPERSCRIPT_ALAPH = 36,
+ GRUB_UNICODE_STACK_ATTACHED_BELOW = 202,
+ GRUB_UNICODE_STACK_ATTACHED_ABOVE = 214,
+ GRUB_UNICODE_COMB_ATTACHED_ABOVE_RIGHT = 216,
+ GRUB_UNICODE_STACK_BELOW = 220,
+ GRUB_UNICODE_COMB_BELOW_RIGHT = 222,
+ GRUB_UNICODE_COMB_ABOVE_LEFT = 228,
+ GRUB_UNICODE_STACK_ABOVE = 230,
+ GRUB_UNICODE_COMB_ABOVE_RIGHT = 232,
+ GRUB_UNICODE_COMB_YPOGEGRAMMENI = 240,
+ /* If combining nature is indicated only by class and
+ not "combining type". */
+ GRUB_UNICODE_COMB_ME = 253,
+ GRUB_UNICODE_COMB_MC = 254,
+ GRUB_UNICODE_COMB_MN = 255,
+ };
+
+struct grub_unicode_combining
+{
+ grub_uint32_t code:21;
+ enum grub_comb_type type:8;
+};
+/* This structure describes a glyph as opposed to character. */
+struct grub_unicode_glyph
+{
+ grub_uint32_t base:23; /* minimum: 21 */
+ grub_uint16_t variant:9; /* minimum: 9 */
+
+ grub_uint8_t attributes:5; /* minimum: 5 */
+ grub_uint8_t bidi_level:6; /* minimum: 6 */
+ enum grub_bidi_type bidi_type:5; /* minimum: :5 */
+
+ unsigned ncomb:8;
+ /* Hint by unicode subsystem how wide this character usually is.
+ Real width is determined by font. Set only in UTF-8 stream. */
+ int estimated_width:8;
+
+ grub_size_t orig_pos;
+ union
+ {
+ struct grub_unicode_combining combining_inline[sizeof (void *)
+ / sizeof (struct grub_unicode_combining)];
+ struct grub_unicode_combining *combining_ptr;
+ };
+};
+
+#define GRUB_UNICODE_GLYPH_ATTRIBUTE_MIRROR 0x1
+#define GRUB_UNICODE_GLYPH_ATTRIBUTES_JOIN_LEFT_TO_RIGHT_SHIFT 1
+#define GRUB_UNICODE_GLYPH_ATTRIBUTE_LEFT_JOINED 0x2
+#define GRUB_UNICODE_GLYPH_ATTRIBUTE_RIGHT_JOINED \
+ (GRUB_UNICODE_GLYPH_ATTRIBUTE_LEFT_JOINED \
+ << GRUB_UNICODE_GLYPH_ATTRIBUTES_JOIN_LEFT_TO_RIGHT_SHIFT)
+/* Set iff the corresponding joining flags come from ZWJ or ZWNJ. */
+#define GRUB_UNICODE_GLYPH_ATTRIBUTE_LEFT_JOINED_EXPLICIT 0x8
+#define GRUB_UNICODE_GLYPH_ATTRIBUTE_RIGHT_JOINED_EXPLICIT \
+ (GRUB_UNICODE_GLYPH_ATTRIBUTE_LEFT_JOINED_EXPLICIT \
+ << GRUB_UNICODE_GLYPH_ATTRIBUTES_JOIN_LEFT_TO_RIGHT_SHIFT)
+#define GRUB_UNICODE_GLYPH_ATTRIBUTES_JOIN \
+ (GRUB_UNICODE_GLYPH_ATTRIBUTE_LEFT_JOINED \
+ | GRUB_UNICODE_GLYPH_ATTRIBUTE_RIGHT_JOINED \
+ | GRUB_UNICODE_GLYPH_ATTRIBUTE_LEFT_JOINED_EXPLICIT \
+ | GRUB_UNICODE_GLYPH_ATTRIBUTE_RIGHT_JOINED_EXPLICIT)
+
+enum
+ {
+ GRUB_UNICODE_DOTLESS_LOWERCASE_I = 0x0131,
+ GRUB_UNICODE_DOTLESS_LOWERCASE_J = 0x0237,
+ GRUB_UNICODE_COMBINING_GRAPHEME_JOINER = 0x034f,
+ GRUB_UNICODE_HEBREW_WAW = 0x05d5,
+ GRUB_UNICODE_ARABIC_START = 0x0600,
+ GRUB_UNICODE_ARABIC_END = 0x0700,
+ GRUB_UNICODE_THAANA_ABAFILI = 0x07a6,
+ GRUB_UNICODE_THAANA_AABAAFILI = 0x07a7,
+ GRUB_UNICODE_THAANA_IBIFILI = 0x07a8,
+ GRUB_UNICODE_THAANA_EEBEEFILI = 0x07a9,
+ GRUB_UNICODE_THAANA_UBUFILI = 0x07aa,
+ GRUB_UNICODE_THAANA_OOBOOFILI = 0x07ab,
+ GRUB_UNICODE_THAANA_EBEFILI = 0x07ac,
+ GRUB_UNICODE_THAANA_EYBEYFILI = 0x07ad,
+ GRUB_UNICODE_THAANA_OBOFILI = 0x07ae,
+ GRUB_UNICODE_THAANA_OABOAFILI = 0x07af,
+ GRUB_UNICODE_THAANA_SUKUN = 0x07b0,
+ GRUB_UNICODE_ZWNJ = 0x200c,
+ GRUB_UNICODE_ZWJ = 0x200d,
+ GRUB_UNICODE_LRM = 0x200e,
+ GRUB_UNICODE_RLM = 0x200f,
+ GRUB_UNICODE_LRE = 0x202a,
+ GRUB_UNICODE_RLE = 0x202b,
+ GRUB_UNICODE_PDF = 0x202c,
+ GRUB_UNICODE_LRO = 0x202d,
+ GRUB_UNICODE_RLO = 0x202e,
+ GRUB_UNICODE_LEFTARROW = 0x2190,
+ GRUB_UNICODE_UPARROW = 0x2191,
+ GRUB_UNICODE_RIGHTARROW = 0x2192,
+ GRUB_UNICODE_DOWNARROW = 0x2193,
+ GRUB_UNICODE_UPDOWNARROW = 0x2195,
+ GRUB_UNICODE_LIGHT_HLINE = 0x2500,
+ GRUB_UNICODE_HLINE = 0x2501,
+ GRUB_UNICODE_LIGHT_VLINE = 0x2502,
+ GRUB_UNICODE_VLINE = 0x2503,
+ GRUB_UNICODE_LIGHT_CORNER_UL = 0x250c,
+ GRUB_UNICODE_CORNER_UL = 0x250f,
+ GRUB_UNICODE_LIGHT_CORNER_UR = 0x2510,
+ GRUB_UNICODE_CORNER_UR = 0x2513,
+ GRUB_UNICODE_LIGHT_CORNER_LL = 0x2514,
+ GRUB_UNICODE_CORNER_LL = 0x2517,
+ GRUB_UNICODE_LIGHT_CORNER_LR = 0x2518,
+ GRUB_UNICODE_CORNER_LR = 0x251b,
+ GRUB_UNICODE_BLACK_UP_TRIANGLE = 0x25b2,
+ GRUB_UNICODE_BLACK_RIGHT_TRIANGLE = 0x25ba,
+ GRUB_UNICODE_BLACK_DOWN_TRIANGLE = 0x25bc,
+ GRUB_UNICODE_BLACK_LEFT_TRIANGLE = 0x25c4,
+ GRUB_UNICODE_VARIATION_SELECTOR_1 = 0xfe00,
+ GRUB_UNICODE_VARIATION_SELECTOR_16 = 0xfe0f,
+ GRUB_UNICODE_TAG_START = 0xe0000,
+ GRUB_UNICODE_TAG_END = 0xe007f,
+ GRUB_UNICODE_VARIATION_SELECTOR_17 = 0xe0100,
+ GRUB_UNICODE_VARIATION_SELECTOR_256 = 0xe01ef,
+ GRUB_UNICODE_LAST_VALID = 0x10ffff
+ };
+
+extern struct grub_unicode_compact_range grub_unicode_compact[];
+extern struct grub_unicode_bidi_pair grub_unicode_bidi_pairs[];
+
+#define GRUB_UNICODE_MAX_CACHED_CHAR 0x20000
+/* Unicode mandates an arbitrary limit. */
+#define GRUB_BIDI_MAX_EXPLICIT_LEVEL 61
+
+struct grub_term_pos
+{
+ unsigned valid:1;
+ unsigned x:15, y:16;
+};
+
+grub_ssize_t
+grub_bidi_logical_to_visual (const grub_uint32_t *logical,
+ grub_size_t logical_len,
+ struct grub_unicode_glyph **visual_out,
+ grub_size_t (*getcharwidth) (const struct grub_unicode_glyph *visual, void *getcharwidth_arg),
+ void *getcharwidth_arg,
+ grub_size_t max_width,
+ grub_size_t start_width, grub_uint32_t codechar,
+ struct grub_term_pos *pos,
+ int primitive_wrap);
+
+enum grub_comb_type
+grub_unicode_get_comb_type (grub_uint32_t c);
+grub_size_t
+grub_unicode_aglomerate_comb (const grub_uint32_t *in, grub_size_t inlen,
+ struct grub_unicode_glyph *out);
+
+static inline const struct grub_unicode_combining *
+grub_unicode_get_comb (const struct grub_unicode_glyph *in)
+{
+ if (in->ncomb == 0)
+ return NULL;
+ if (in->ncomb > ARRAY_SIZE (in->combining_inline))
+ return in->combining_ptr;
+ return in->combining_inline;
+}
+
+static inline void
+grub_unicode_destroy_glyph (struct grub_unicode_glyph *glyph)
+{
+ if (glyph->ncomb > ARRAY_SIZE (glyph->combining_inline))
+ grub_free (glyph->combining_ptr);
+ glyph->ncomb = 0;
+}
+
+static inline struct grub_unicode_glyph *
+grub_unicode_glyph_dup (const struct grub_unicode_glyph *in)
+{
+ struct grub_unicode_glyph *out = grub_malloc (sizeof (*out));
+ if (!out)
+ return NULL;
+ grub_memcpy (out, in, sizeof (*in));
+ if (in->ncomb > ARRAY_SIZE (out->combining_inline))
+ {
+ out->combining_ptr = grub_calloc (in->ncomb, sizeof (out->combining_ptr[0]));
+ if (!out->combining_ptr)
+ {
+ grub_free (out);
+ return NULL;
+ }
+ grub_memcpy (out->combining_ptr, in->combining_ptr,
+ in->ncomb * sizeof (out->combining_ptr[0]));
+ }
+ else
+ grub_memcpy (&out->combining_inline, &in->combining_inline,
+ sizeof (out->combining_inline));
+ return out;
+}
+
+static inline void
+grub_unicode_set_glyph (struct grub_unicode_glyph *out,
+ const struct grub_unicode_glyph *in)
+{
+ grub_memcpy (out, in, sizeof (*in));
+ if (in->ncomb > ARRAY_SIZE (out->combining_inline))
+ {
+ out->combining_ptr = grub_calloc (in->ncomb, sizeof (out->combining_ptr[0]));
+ if (!out->combining_ptr)
+ return;
+ grub_memcpy (out->combining_ptr, in->combining_ptr,
+ in->ncomb * sizeof (out->combining_ptr[0]));
+ }
+ else
+ grub_memcpy (&out->combining_inline, &in->combining_inline,
+ sizeof (out->combining_inline));
+}
+
+static inline struct grub_unicode_glyph *
+grub_unicode_glyph_from_code (grub_uint32_t code)
+{
+ struct grub_unicode_glyph *ret;
+ ret = grub_zalloc (sizeof (*ret));
+ if (!ret)
+ return NULL;
+
+ ret->base = code;
+
+ return ret;
+}
+
+static inline void
+grub_unicode_set_glyph_from_code (struct grub_unicode_glyph *glyph,
+ grub_uint32_t code)
+{
+ grub_memset (glyph, 0, sizeof (*glyph));
+
+ glyph->base = code;
+}
+
+grub_uint32_t
+grub_unicode_mirror_code (grub_uint32_t in);
+grub_uint32_t
+grub_unicode_shape_code (grub_uint32_t in, grub_uint8_t attr);
+
+const grub_uint32_t *
+grub_unicode_get_comb_end (const grub_uint32_t *end,
+ const grub_uint32_t *cur);
+
+#endif
diff --git a/include/grub/usb.h b/include/grub/usb.h
new file mode 100644
index 0000000..6475c55
--- /dev/null
+++ b/include/grub/usb.h
@@ -0,0 +1,333 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_USB_H
+#define GRUB_USB_H 1
+
+#include <grub/err.h>
+#include <grub/usbdesc.h>
+#include <grub/usbtrans.h>
+
+#define GRUB_USB_MAX_CONF 8
+#define GRUB_USB_MAX_IF 32
+#define GRUB_USB_MAX_TOGGLE 256
+
+typedef struct grub_usb_device *grub_usb_device_t;
+typedef struct grub_usb_controller *grub_usb_controller_t;
+typedef struct grub_usb_controller_dev *grub_usb_controller_dev_t;
+
+typedef enum
+ {
+ GRUB_USB_ERR_NONE,
+ GRUB_USB_ERR_WAIT,
+ GRUB_USB_ERR_INTERNAL,
+ GRUB_USB_ERR_STALL,
+ GRUB_USB_ERR_DATA,
+ GRUB_USB_ERR_NAK,
+ GRUB_USB_ERR_BABBLE,
+ GRUB_USB_ERR_TIMEOUT,
+ GRUB_USB_ERR_BITSTUFF,
+ GRUB_USB_ERR_UNRECOVERABLE,
+ GRUB_USB_ERR_BADDEVICE
+ } grub_usb_err_t;
+
+typedef enum
+ {
+ GRUB_USB_SPEED_NONE,
+ GRUB_USB_SPEED_LOW,
+ GRUB_USB_SPEED_FULL,
+ GRUB_USB_SPEED_HIGH
+ } grub_usb_speed_t;
+
+typedef int (*grub_usb_iterate_hook_t) (grub_usb_device_t dev, void *data);
+typedef int (*grub_usb_controller_iterate_hook_t) (grub_usb_controller_t dev,
+ void *data);
+
+/* Call HOOK with each device, until HOOK returns non-zero. */
+int grub_usb_iterate (grub_usb_iterate_hook_t hook, void *hook_data);
+
+grub_usb_err_t grub_usb_device_initialize (grub_usb_device_t dev);
+
+grub_usb_err_t grub_usb_get_descriptor (grub_usb_device_t dev,
+ grub_uint8_t type, grub_uint8_t index,
+ grub_size_t size, char *data);
+
+grub_usb_err_t grub_usb_clear_halt (grub_usb_device_t dev, int endpoint);
+
+
+grub_usb_err_t grub_usb_set_configuration (grub_usb_device_t dev,
+ int configuration);
+
+void grub_usb_controller_dev_register (grub_usb_controller_dev_t usb);
+
+void grub_usb_controller_dev_unregister (grub_usb_controller_dev_t usb);
+
+int grub_usb_controller_iterate (grub_usb_controller_iterate_hook_t hook,
+ void *hook_data);
+
+
+grub_usb_err_t grub_usb_control_msg (grub_usb_device_t dev, grub_uint8_t reqtype,
+ grub_uint8_t request, grub_uint16_t value,
+ grub_uint16_t index, grub_size_t size,
+ char *data);
+
+grub_usb_err_t
+grub_usb_bulk_read (grub_usb_device_t dev,
+ struct grub_usb_desc_endp *endpoint,
+ grub_size_t size, char *data);
+grub_usb_err_t
+grub_usb_bulk_write (grub_usb_device_t dev,
+ struct grub_usb_desc_endp *endpoint,
+ grub_size_t size, char *data);
+
+grub_usb_err_t
+grub_usb_root_hub (grub_usb_controller_t controller);
+
+
+
+/* XXX: All handled by libusb for now. */
+struct grub_usb_controller_dev
+{
+ /* The device name. */
+ const char *name;
+
+ int (*iterate) (grub_usb_controller_iterate_hook_t hook, void *hook_data);
+
+ grub_usb_err_t (*setup_transfer) (grub_usb_controller_t dev,
+ grub_usb_transfer_t transfer);
+
+ grub_usb_err_t (*check_transfer) (grub_usb_controller_t dev,
+ grub_usb_transfer_t transfer,
+ grub_size_t *actual);
+
+ grub_usb_err_t (*cancel_transfer) (grub_usb_controller_t dev,
+ grub_usb_transfer_t transfer);
+
+ int (*hubports) (grub_usb_controller_t dev);
+
+ grub_usb_err_t (*portstatus) (grub_usb_controller_t dev, unsigned int port,
+ unsigned int enable);
+
+ grub_usb_speed_t (*detect_dev) (grub_usb_controller_t dev, int port, int *changed);
+
+ /* Per controller flag - port reset pending, don't do another reset */
+ grub_uint64_t pending_reset;
+
+ /* Max. number of transfer descriptors used per one bulk transfer */
+ /* The reason is to prevent "exhausting" of TD by large bulk */
+ /* transfer - number of TD is limited in USB host driver */
+ /* Value is calculated/estimated in driver - some TDs should be */
+ /* reserved for posible concurrent control or "interrupt" transfers */
+ grub_size_t max_bulk_tds;
+
+ /* The next host controller. */
+ struct grub_usb_controller_dev *next;
+};
+
+struct grub_usb_controller
+{
+ /* The underlying USB Host Controller device. */
+ grub_usb_controller_dev_t dev;
+
+ /* Data used by the USB Host Controller Driver. */
+ void *data;
+};
+
+
+struct grub_usb_interface
+{
+ struct grub_usb_desc_if *descif;
+
+ struct grub_usb_desc_endp *descendp;
+
+ /* A driver is handling this interface. Do we need to support multiple drivers
+ for single interface?
+ */
+ int attached;
+
+ void (*detach_hook) (struct grub_usb_device *dev, int config, int interface);
+
+ void *detach_data;
+};
+
+struct grub_usb_configuration
+{
+ /* Configuration descriptors . */
+ struct grub_usb_desc_config *descconf;
+
+ /* Interfaces associated to this configuration. */
+ struct grub_usb_interface interf[GRUB_USB_MAX_IF];
+};
+
+struct grub_usb_hub_port
+{
+ grub_uint64_t soft_limit_time;
+ grub_uint64_t hard_limit_time;
+ enum {
+ PORT_STATE_NORMAL = 0,
+ PORT_STATE_WAITING_FOR_STABLE_POWER = 1,
+ PORT_STATE_FAILED_DEVICE = 2,
+ PORT_STATE_STABLE_POWER = 3,
+ } state;
+};
+
+struct grub_usb_device
+{
+ /* The device descriptor of this device. */
+ struct grub_usb_desc_device descdev;
+
+ /* The controller the device is connected to. */
+ struct grub_usb_controller controller;
+
+ /* Device configurations (after opening the device). */
+ struct grub_usb_configuration config[GRUB_USB_MAX_CONF];
+
+ /* Device address. */
+ int addr;
+
+ /* Device speed. */
+ grub_usb_speed_t speed;
+
+ /* All descriptors are read if this is set to 1. */
+ int initialized;
+
+ /* Data toggle values (used for bulk transfers only). */
+ int toggle[GRUB_USB_MAX_TOGGLE];
+
+ /* Used by libusb wrapper. Schedulded for removal. */
+ void *data;
+
+ /* Hub information. */
+
+ /* Array of children for a hub. */
+ grub_usb_device_t *children;
+
+ /* Number of hub ports. */
+ unsigned nports;
+
+ struct grub_usb_hub_port *ports;
+
+ grub_usb_transfer_t hub_transfer;
+
+ grub_uint32_t statuschange;
+
+ struct grub_usb_desc_endp *hub_endpoint;
+
+ /* EHCI Split Transfer information */
+ int split_hubport;
+
+ int split_hubaddr;
+};
+
+
+
+typedef enum grub_usb_ep_type
+ {
+ GRUB_USB_EP_CONTROL,
+ GRUB_USB_EP_ISOCHRONOUS,
+ GRUB_USB_EP_BULK,
+ GRUB_USB_EP_INTERRUPT
+ } grub_usb_ep_type_t;
+
+static inline enum grub_usb_ep_type
+grub_usb_get_ep_type (struct grub_usb_desc_endp *ep)
+{
+ return ep->attrib & 3;
+}
+
+typedef enum
+ {
+ GRUB_USB_CLASS_NOTHERE,
+ GRUB_USB_CLASS_AUDIO,
+ GRUB_USB_CLASS_COMMUNICATION,
+ GRUB_USB_CLASS_HID,
+ GRUB_USB_CLASS_XXX,
+ GRUB_USB_CLASS_PHYSICAL,
+ GRUB_USB_CLASS_IMAGE,
+ GRUB_USB_CLASS_PRINTER,
+ GRUB_USB_CLASS_MASS_STORAGE,
+ GRUB_USB_CLASS_HUB,
+ GRUB_USB_CLASS_DATA_INTERFACE,
+ GRUB_USB_CLASS_SMART_CARD,
+ GRUB_USB_CLASS_CONTENT_SECURITY,
+ GRUB_USB_CLASS_VIDEO
+ } grub_usb_classes_t;
+
+typedef enum
+ {
+ GRUB_USBMS_SUBCLASS_BULK = 0x06,
+ /* Experimental support for non-pure SCSI devices */
+ GRUB_USBMS_SUBCLASS_RBC = 0x01,
+ GRUB_USBMS_SUBCLASS_MMC2 = 0x02,
+ GRUB_USBMS_SUBCLASS_UFI = 0x04,
+ GRUB_USBMS_SUBCLASS_SFF8070 = 0x05
+ } grub_usbms_subclass_t;
+
+typedef enum
+ {
+ GRUB_USBMS_PROTOCOL_BULK = 0x50,
+ /* Experimental support for Control/Bulk/Interrupt (CBI) devices */
+ GRUB_USBMS_PROTOCOL_CBI = 0x00, /* CBI with interrupt */
+ GRUB_USBMS_PROTOCOL_CB = 0x01 /* CBI wthout interrupt */
+ } grub_usbms_protocol_t;
+
+static inline struct grub_usb_desc_if *
+grub_usb_get_config_interface (struct grub_usb_desc_config *config)
+{
+ struct grub_usb_desc_if *interf;
+
+ interf = (struct grub_usb_desc_if *) (sizeof (*config) + (char *) config);
+ return interf;
+}
+
+typedef int (*grub_usb_attach_hook_class) (grub_usb_device_t usbdev,
+ int configno, int interfno);
+
+struct grub_usb_attach_desc
+{
+ struct grub_usb_attach_desc *next;
+ struct grub_usb_attach_desc **prev;
+ int class;
+ grub_usb_attach_hook_class hook;
+};
+
+void grub_usb_register_attach_hook_class (struct grub_usb_attach_desc *desc);
+void grub_usb_unregister_attach_hook_class (struct grub_usb_attach_desc *desc);
+
+void grub_usb_poll_devices (int wait_for_completion);
+
+void grub_usb_device_attach (grub_usb_device_t dev);
+grub_usb_err_t
+grub_usb_bulk_read_extended (grub_usb_device_t dev,
+ struct grub_usb_desc_endp *endpoint,
+ grub_size_t size, char *data,
+ int timeout, grub_size_t *actual);
+grub_usb_transfer_t
+grub_usb_bulk_read_background (grub_usb_device_t dev,
+ struct grub_usb_desc_endp *endpoint,
+ grub_size_t size, void *data);
+grub_usb_err_t
+grub_usb_check_transfer (grub_usb_transfer_t trans, grub_size_t *actual);
+void
+grub_usb_cancel_transfer (grub_usb_transfer_t trans);
+void
+grub_ehci_init_device (volatile void *regs);
+void
+grub_ehci_pci_scan (void);
+
+#endif /* GRUB_USB_H */
diff --git a/include/grub/usbdesc.h b/include/grub/usbdesc.h
new file mode 100644
index 0000000..aac5ab0
--- /dev/null
+++ b/include/grub/usbdesc.h
@@ -0,0 +1,134 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_USBDESC_H
+#define GRUB_USBDESC_H 1
+
+#include <grub/types.h>
+#include <grub/symbol.h>
+
+typedef enum {
+ GRUB_USB_DESCRIPTOR_DEVICE = 1,
+ GRUB_USB_DESCRIPTOR_CONFIG,
+ GRUB_USB_DESCRIPTOR_STRING,
+ GRUB_USB_DESCRIPTOR_INTERFACE,
+ GRUB_USB_DESCRIPTOR_ENDPOINT,
+ GRUB_USB_DESCRIPTOR_DEBUG = 10,
+ GRUB_USB_DESCRIPTOR_HUB = 0x29
+} grub_usb_descriptor_t;
+
+struct grub_usb_desc
+{
+ grub_uint8_t length;
+ grub_uint8_t type;
+} GRUB_PACKED;
+
+struct grub_usb_desc_device
+{
+ grub_uint8_t length;
+ grub_uint8_t type;
+ grub_uint16_t usbrel;
+ grub_uint8_t class;
+ grub_uint8_t subclass;
+ grub_uint8_t protocol;
+ grub_uint8_t maxsize0;
+ grub_uint16_t vendorid;
+ grub_uint16_t prodid;
+ grub_uint16_t devrel;
+ grub_uint8_t strvendor;
+ grub_uint8_t strprod;
+ grub_uint8_t strserial;
+ grub_uint8_t configcnt;
+} GRUB_PACKED;
+
+struct grub_usb_desc_config
+{
+ grub_uint8_t length;
+ grub_uint8_t type;
+ grub_uint16_t totallen;
+ grub_uint8_t numif;
+ grub_uint8_t config;
+ grub_uint8_t strconfig;
+ grub_uint8_t attrib;
+ grub_uint8_t maxpower;
+} GRUB_PACKED;
+
+#if 0
+struct grub_usb_desc_if_association
+{
+ grub_uint8_t length;
+ grub_uint8_t type;
+ grub_uint8_t firstif;
+ grub_uint8_t ifcnt;
+ grub_uint8_t class;
+ grub_uint8_t subclass;
+ grub_uint8_t protocol;
+ grub_uint8_t function;
+} GRUB_PACKED;
+#endif
+
+struct grub_usb_desc_if
+{
+ grub_uint8_t length;
+ grub_uint8_t type;
+ grub_uint8_t ifnum;
+ grub_uint8_t altsetting;
+ grub_uint8_t endpointcnt;
+ grub_uint8_t class;
+ grub_uint8_t subclass;
+ grub_uint8_t protocol;
+ grub_uint8_t strif;
+} GRUB_PACKED;
+
+struct grub_usb_desc_endp
+{
+ grub_uint8_t length;
+ grub_uint8_t type;
+ grub_uint8_t endp_addr;
+ grub_uint8_t attrib;
+ grub_uint16_t maxpacket;
+ grub_uint8_t interval;
+} GRUB_PACKED;
+
+struct grub_usb_desc_str
+{
+ grub_uint8_t length;
+ grub_uint8_t type;
+ grub_uint16_t str[0];
+} GRUB_PACKED;
+
+struct grub_usb_desc_debug
+{
+ grub_uint8_t length;
+ grub_uint8_t type;
+ grub_uint8_t in_endp;
+ grub_uint8_t out_endp;
+} GRUB_PACKED;
+
+struct grub_usb_usb_hubdesc
+{
+ grub_uint8_t length;
+ grub_uint8_t type;
+ grub_uint8_t portcnt;
+ grub_uint16_t characteristics;
+ grub_uint8_t pwdgood;
+ grub_uint8_t current;
+ /* Removable and power control bits follow. */
+} GRUB_PACKED;
+
+#endif /* GRUB_USBDESC_H */
diff --git a/include/grub/usbserial.h b/include/grub/usbserial.h
new file mode 100644
index 0000000..f81f97a
--- /dev/null
+++ b/include/grub/usbserial.h
@@ -0,0 +1,39 @@
+/* serial.h - serial device interface */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_USBSERIAL_HEADER
+#define GRUB_USBSERIAL_HEADER 1
+
+void grub_usbserial_fini (struct grub_serial_port *port);
+
+void grub_usbserial_detach (grub_usb_device_t usbdev, int configno,
+ int interfno);
+
+int
+grub_usbserial_attach (grub_usb_device_t usbdev, int configno, int interfno,
+ struct grub_serial_driver *driver, int in_endp,
+ int out_endp);
+enum
+ {
+ GRUB_USB_SERIAL_ENDPOINT_LAST_MATCHING = -1
+ };
+int
+grub_usbserial_fetch (struct grub_serial_port *port, grub_size_t header_size);
+
+#endif
diff --git a/include/grub/usbtrans.h b/include/grub/usbtrans.h
new file mode 100644
index 0000000..aef482c
--- /dev/null
+++ b/include/grub/usbtrans.h
@@ -0,0 +1,155 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_USBTRANS_H
+#define GRUB_USBTRANS_H 1
+
+#define MAX_USB_TRANSFER_LEN 0x0800
+
+typedef enum
+ {
+ GRUB_USB_TRANSFER_TYPE_IN,
+ GRUB_USB_TRANSFER_TYPE_OUT,
+ GRUB_USB_TRANSFER_TYPE_SETUP
+ } grub_transfer_type_t;
+
+typedef enum
+ {
+ GRUB_USB_TRANSACTION_TYPE_CONTROL,
+ GRUB_USB_TRANSACTION_TYPE_BULK
+ } grub_transaction_type_t;
+
+struct grub_usb_transaction
+{
+ int size;
+ int toggle;
+ grub_transfer_type_t pid;
+ grub_uint32_t data;
+ grub_size_t preceding;
+};
+typedef struct grub_usb_transaction *grub_usb_transaction_t;
+
+struct grub_usb_transfer
+{
+ int devaddr;
+
+ int endpoint;
+
+ int size;
+
+ int transcnt;
+
+ int max;
+
+ grub_transaction_type_t type;
+
+ grub_transfer_type_t dir;
+
+ struct grub_usb_device *dev;
+
+ struct grub_usb_transaction *transactions;
+
+ int last_trans;
+ /* Index of last processed transaction in OHCI/UHCI driver. */
+
+ void *controller_data;
+
+ /* Used when finishing transfer to copy data back. */
+ struct grub_pci_dma_chunk *data_chunk;
+ void *data;
+};
+typedef struct grub_usb_transfer *grub_usb_transfer_t;
+
+
+
+enum
+ {
+ GRUB_USB_REQTYPE_TARGET_DEV = (0 << 0),
+ GRUB_USB_REQTYPE_TARGET_INTERF = (1 << 0),
+ GRUB_USB_REQTYPE_TARGET_ENDP = (2 << 0),
+ GRUB_USB_REQTYPE_TARGET_OTHER = (3 << 0),
+ GRUB_USB_REQTYPE_STANDARD = (0 << 5),
+ GRUB_USB_REQTYPE_CLASS = (1 << 5),
+ GRUB_USB_REQTYPE_VENDOR = (2 << 5),
+ GRUB_USB_REQTYPE_OUT = (0 << 7),
+ GRUB_USB_REQTYPE_IN = (1 << 7),
+ GRUB_USB_REQTYPE_CLASS_INTERFACE_OUT = GRUB_USB_REQTYPE_TARGET_INTERF
+ | GRUB_USB_REQTYPE_CLASS | GRUB_USB_REQTYPE_OUT,
+ GRUB_USB_REQTYPE_VENDOR_OUT = GRUB_USB_REQTYPE_VENDOR | GRUB_USB_REQTYPE_OUT,
+ GRUB_USB_REQTYPE_CLASS_INTERFACE_IN = GRUB_USB_REQTYPE_TARGET_INTERF
+ | GRUB_USB_REQTYPE_CLASS | GRUB_USB_REQTYPE_IN,
+ GRUB_USB_REQTYPE_VENDOR_IN = GRUB_USB_REQTYPE_VENDOR | GRUB_USB_REQTYPE_IN
+ };
+
+enum
+ {
+ GRUB_USB_REQ_GET_STATUS = 0x00,
+ GRUB_USB_REQ_CLEAR_FEATURE = 0x01,
+ GRUB_USB_REQ_SET_FEATURE = 0x03,
+ GRUB_USB_REQ_SET_ADDRESS = 0x05,
+ GRUB_USB_REQ_GET_DESCRIPTOR = 0x06,
+ GRUB_USB_REQ_SET_DESCRIPTOR = 0x07,
+ GRUB_USB_REQ_GET_CONFIGURATION = 0x08,
+ GRUB_USB_REQ_SET_CONFIGURATION = 0x09,
+ GRUB_USB_REQ_GET_INTERFACE = 0x0A,
+ GRUB_USB_REQ_SET_INTERFACE = 0x0B,
+ GRUB_USB_REQ_SYNC_FRAME = 0x0C
+ };
+
+#define GRUB_USB_FEATURE_ENDP_HALT 0x00
+#define GRUB_USB_FEATURE_DEV_REMOTE_WU 0x01
+#define GRUB_USB_FEATURE_TEST_MODE 0x02
+
+enum
+ {
+ GRUB_USB_HUB_FEATURE_PORT_RESET = 0x04,
+ GRUB_USB_HUB_FEATURE_PORT_POWER = 0x08,
+ GRUB_USB_HUB_FEATURE_C_PORT_CONNECTED = 0x10,
+ GRUB_USB_HUB_FEATURE_C_PORT_ENABLED = 0x11,
+ GRUB_USB_HUB_FEATURE_C_PORT_SUSPEND = 0x12,
+ GRUB_USB_HUB_FEATURE_C_PORT_OVERCURRENT = 0x13,
+ GRUB_USB_HUB_FEATURE_C_PORT_RESET = 0x14
+ };
+
+enum
+ {
+ GRUB_USB_HUB_STATUS_PORT_CONNECTED = (1 << 0),
+ GRUB_USB_HUB_STATUS_PORT_ENABLED = (1 << 1),
+ GRUB_USB_HUB_STATUS_PORT_SUSPEND = (1 << 2),
+ GRUB_USB_HUB_STATUS_PORT_OVERCURRENT = (1 << 3),
+ GRUB_USB_HUB_STATUS_PORT_POWERED = (1 << 8),
+ GRUB_USB_HUB_STATUS_PORT_LOWSPEED = (1 << 9),
+ GRUB_USB_HUB_STATUS_PORT_HIGHSPEED = (1 << 10),
+ GRUB_USB_HUB_STATUS_C_PORT_CONNECTED = (1 << 16),
+ GRUB_USB_HUB_STATUS_C_PORT_ENABLED = (1 << 17),
+ GRUB_USB_HUB_STATUS_C_PORT_SUSPEND = (1 << 18),
+ GRUB_USB_HUB_STATUS_C_PORT_OVERCURRENT = (1 << 19),
+ GRUB_USB_HUB_STATUS_C_PORT_RESET = (1 << 20)
+ };
+
+struct grub_usb_packet_setup
+{
+ grub_uint8_t reqtype;
+ grub_uint8_t request;
+ grub_uint16_t value;
+ grub_uint16_t index;
+ grub_uint16_t length;
+} GRUB_PACKED;
+
+
+#endif /* GRUB_USBTRANS_H */
diff --git a/include/grub/util/install.h b/include/grub/util/install.h
new file mode 100644
index 0000000..7df3191
--- /dev/null
+++ b/include/grub/util/install.h
@@ -0,0 +1,299 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_UTIL_INSTALL_HEADER
+#define GRUB_UTIL_INSTALL_HEADER 1
+
+#include <sys/types.h>
+#include <stdio.h>
+
+#include <grub/device.h>
+#include <grub/disk.h>
+#include <grub/emu/hostfile.h>
+
+#define GRUB_INSTALL_OPTIONS \
+ { "modules", GRUB_INSTALL_OPTIONS_MODULES, N_("MODULES"), \
+ 0, N_("pre-load specified modules MODULES"), 1 }, \
+ { "dtb", GRUB_INSTALL_OPTIONS_DTB, N_("FILE"), \
+ 0, N_("embed a specific DTB"), 1 }, \
+ { "install-modules", GRUB_INSTALL_OPTIONS_INSTALL_MODULES, \
+ N_("MODULES"), 0, \
+ N_("install only MODULES and their dependencies [default=all]"), 1 }, \
+ { "themes", GRUB_INSTALL_OPTIONS_INSTALL_THEMES, N_("THEMES"), \
+ 0, N_("install THEMES [default=%s]"), 1 }, \
+ { "fonts", GRUB_INSTALL_OPTIONS_INSTALL_FONTS, N_("FONTS"), \
+ 0, N_("install FONTS [default=%s]"), 1 }, \
+ { "locales", GRUB_INSTALL_OPTIONS_INSTALL_LOCALES, N_("LOCALES"),\
+ 0, N_("install only LOCALES [default=all]"), 1 }, \
+ { "compress", GRUB_INSTALL_OPTIONS_INSTALL_COMPRESS, \
+ "no|xz|gz|lzo", 0, \
+ N_("compress GRUB files [optional]"), 1 }, \
+ {"core-compress", GRUB_INSTALL_OPTIONS_INSTALL_CORE_COMPRESS, \
+ "xz|none|auto", \
+ 0, N_("choose the compression to use for core image"), 2}, \
+ /* TRANSLATORS: platform here isn't identifier. It can be translated. */ \
+ { "directory", 'd', N_("DIR"), 0, \
+ N_("use images and modules under DIR [default=%s/<platform>]"), 1 }, \
+ { "override-directory", GRUB_INSTALL_OPTIONS_DIRECTORY2, \
+ N_("DIR"), OPTION_HIDDEN, \
+ N_("use images and modules under DIR [default=%s/<platform>]"), 1 }, \
+ { "locale-directory", GRUB_INSTALL_OPTIONS_LOCALE_DIRECTORY, \
+ N_("DIR"), 0, \
+ N_("use translations under DIR [default=%s]"), 1 }, \
+ { "themes-directory", GRUB_INSTALL_OPTIONS_THEMES_DIRECTORY, \
+ N_("DIR"), OPTION_HIDDEN, \
+ N_("use themes under DIR [default=%s]"), 1 }, \
+ { "grub-mkimage", GRUB_INSTALL_OPTIONS_GRUB_MKIMAGE, \
+ "FILE", OPTION_HIDDEN, 0, 1 }, \
+ /* TRANSLATORS: "embed" is a verb (command description). "*/ \
+ { "pubkey", 'k', N_("FILE"), 0, \
+ N_("embed FILE as public key for signature checking"), 0}, \
+ { "sbat", GRUB_INSTALL_OPTIONS_SBAT, N_("FILE"), 0, \
+ N_("SBAT metadata"), 0 }, \
+ { "disable-shim-lock", GRUB_INSTALL_OPTIONS_DISABLE_SHIM_LOCK, 0, 0, \
+ N_("disable shim_lock verifier"), 0 }, \
+ { "verbose", 'v', 0, 0, \
+ N_("print verbose messages."), 1 }
+
+int
+grub_install_parse (int key, char *arg);
+
+void
+grub_install_push_module (const char *val);
+
+void
+grub_install_pop_module (void);
+
+char *
+grub_install_help_filter (int key, const char *text,
+ void *input __attribute__ ((unused)));
+
+enum grub_install_plat
+ {
+ GRUB_INSTALL_PLATFORM_I386_PC,
+ GRUB_INSTALL_PLATFORM_I386_EFI,
+ GRUB_INSTALL_PLATFORM_I386_QEMU,
+ GRUB_INSTALL_PLATFORM_I386_COREBOOT,
+ GRUB_INSTALL_PLATFORM_I386_MULTIBOOT,
+ GRUB_INSTALL_PLATFORM_I386_IEEE1275,
+ GRUB_INSTALL_PLATFORM_X86_64_EFI,
+ GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON,
+ GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275,
+ GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275,
+ GRUB_INSTALL_PLATFORM_MIPSEL_ARC,
+ GRUB_INSTALL_PLATFORM_MIPS_ARC,
+ GRUB_INSTALL_PLATFORM_IA64_EFI,
+ GRUB_INSTALL_PLATFORM_ARM_UBOOT,
+ GRUB_INSTALL_PLATFORM_ARM_EFI,
+ GRUB_INSTALL_PLATFORM_MIPSEL_QEMU_MIPS,
+ GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS,
+ GRUB_INSTALL_PLATFORM_I386_XEN,
+ GRUB_INSTALL_PLATFORM_X86_64_XEN,
+ GRUB_INSTALL_PLATFORM_I386_XEN_PVH,
+ GRUB_INSTALL_PLATFORM_ARM64_EFI,
+ GRUB_INSTALL_PLATFORM_ARM_COREBOOT,
+ GRUB_INSTALL_PLATFORM_RISCV32_EFI,
+ GRUB_INSTALL_PLATFORM_RISCV64_EFI,
+ GRUB_INSTALL_PLATFORM_MAX
+ };
+
+enum grub_install_options {
+ GRUB_INSTALL_OPTIONS_DIRECTORY = 'd',
+ GRUB_INSTALL_OPTIONS_VERBOSITY = 'v',
+ GRUB_INSTALL_OPTIONS_MODULES = 0x201,
+ GRUB_INSTALL_OPTIONS_INSTALL_MODULES,
+ GRUB_INSTALL_OPTIONS_INSTALL_THEMES,
+ GRUB_INSTALL_OPTIONS_INSTALL_FONTS,
+ GRUB_INSTALL_OPTIONS_INSTALL_LOCALES,
+ GRUB_INSTALL_OPTIONS_INSTALL_COMPRESS,
+ GRUB_INSTALL_OPTIONS_DIRECTORY2,
+ GRUB_INSTALL_OPTIONS_LOCALE_DIRECTORY,
+ GRUB_INSTALL_OPTIONS_THEMES_DIRECTORY,
+ GRUB_INSTALL_OPTIONS_GRUB_MKIMAGE,
+ GRUB_INSTALL_OPTIONS_INSTALL_CORE_COMPRESS,
+ GRUB_INSTALL_OPTIONS_DTB,
+ GRUB_INSTALL_OPTIONS_SBAT,
+ GRUB_INSTALL_OPTIONS_DISABLE_SHIM_LOCK
+};
+
+extern char *grub_install_source_directory;
+
+enum grub_install_plat
+grub_install_get_target (const char *src);
+void
+grub_install_mkdir_p (const char *dst);
+
+void
+grub_install_copy_files (const char *src,
+ const char *dst,
+ enum grub_install_plat platid);
+char *
+grub_install_get_platform_name (enum grub_install_plat platid);
+
+const char *
+grub_install_get_platform_cpu (enum grub_install_plat platid);
+
+const char *
+grub_install_get_platform_platform (enum grub_install_plat platid);
+
+char *
+grub_install_get_platforms_string (void);
+
+typedef enum {
+ GRUB_COMPRESSION_AUTO,
+ GRUB_COMPRESSION_NONE,
+ GRUB_COMPRESSION_XZ,
+ GRUB_COMPRESSION_LZMA
+} grub_compression_t;
+
+void
+grub_install_make_image_wrap (const char *dir, const char *prefix,
+ const char *outname, char *memdisk_path,
+ char *config_path,
+ const char *format, int note);
+void
+grub_install_make_image_wrap_file (const char *dir, const char *prefix,
+ FILE *fp, const char *outname,
+ char *memdisk_path,
+ char *config_path,
+ const char *mkimage_target, int note);
+
+int
+grub_install_copy_file (const char *src,
+ const char *dst,
+ int is_critical);
+
+struct grub_install_image_target_desc;
+
+void
+grub_install_generate_image (const char *dir, const char *prefix,
+ FILE *out,
+ const char *outname, char *mods[],
+ char *memdisk_path, char **pubkey_paths,
+ size_t npubkeys,
+ char *config_path,
+ const struct grub_install_image_target_desc *image_target,
+ int note,
+ grub_compression_t comp, const char *dtb_file,
+ const char *sbat_path, const int disable_shim_lock);
+
+const struct grub_install_image_target_desc *
+grub_install_get_image_target (const char *arg);
+
+void
+grub_util_bios_setup (const char *dir,
+ const char *boot_file, const char *core_file,
+ const char *dest, int force,
+ int fs_probe, int allow_floppy,
+ int add_rs_codes, int warn_short_mbr_gap);
+void
+grub_util_sparc_setup (const char *dir,
+ const char *boot_file, const char *core_file,
+ const char *dest, int force,
+ int fs_probe, int allow_floppy,
+ int add_rs_codes, int warn_short_mbr_gap);
+
+char *
+grub_install_get_image_targets_string (void);
+
+const char *
+grub_util_get_target_dirname (const struct grub_install_image_target_desc *t);
+
+void
+grub_install_create_envblk_file (const char *name);
+
+const char *
+grub_install_get_default_arm_platform (void);
+
+const char *
+grub_install_get_default_x86_platform (void);
+
+int
+grub_install_register_efi (grub_device_t efidir_grub_dev,
+ const char *efifile_path,
+ const char *efi_distributor);
+
+void
+grub_install_register_ieee1275 (int is_prep, const char *install_device,
+ int partno, const char *relpath);
+
+void
+grub_install_sgi_setup (const char *install_device,
+ const char *imgfile, const char *destname);
+
+int
+grub_install_compress_gzip (const char *src, const char *dest);
+int
+grub_install_compress_lzop (const char *src, const char *dest);
+int
+grub_install_compress_xz (const char *src, const char *dest);
+
+void
+grub_install_get_blocklist (grub_device_t root_dev,
+ const char *core_path, const char *core_img,
+ size_t core_size,
+ void (*callback) (grub_disk_addr_t sector,
+ unsigned offset,
+ unsigned length,
+ void *data),
+ void *hook_data);
+
+void
+grub_util_create_envblk_file (const char *name);
+
+void
+grub_util_glue_efi (const char *file32, const char *file64, const char *out);
+
+void
+grub_util_render_label (const char *label_font,
+ const char *label_bgcolor,
+ const char *label_color,
+ const char *label_string,
+ const char *label);
+
+const char *
+grub_util_get_target_name (const struct grub_install_image_target_desc *t);
+
+extern char *grub_install_copy_buffer;
+#define GRUB_INSTALL_COPY_BUFFER_SIZE 1048576
+
+int
+grub_install_is_short_mbrgap_supported (void);
+
+/*
+ * grub-install-common tries to make backups of modules & auxiliary files,
+ * and restore the backup upon failure to install core.img. There are
+ * platforms with additional actions after modules & core got installed
+ * in place. It is a point of no return, as core.img cannot be reverted
+ * from this point onwards, and new modules should be kept installed.
+ * Before performing these additional actions call grub_set_install_backup_ponr()
+ * to set the grub_install_backup_ponr flag. This way failure to perform
+ * subsequent actions will not result in reverting new modules to the
+ * old ones, e.g. in case efivars updates fails.
+ */
+#ifdef HAVE_ATEXIT
+extern void
+grub_set_install_backup_ponr (void);
+#else
+static inline void
+grub_set_install_backup_ponr (void)
+{
+}
+#endif
+
+#endif
diff --git a/include/grub/util/libnvpair.h b/include/grub/util/libnvpair.h
new file mode 100644
index 0000000..573c7ea
--- /dev/null
+++ b/include/grub/util/libnvpair.h
@@ -0,0 +1,38 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_LIBNVPAIR_UTIL_HEADER
+#define GRUB_LIBNVPAIR_UTIL_HEADER 1
+
+#include <config.h>
+
+#ifdef HAVE_LIBNVPAIR_H
+#include <libnvpair.h>
+#else /* ! HAVE_LIBNVPAIR_H */
+
+#include <stdio.h> /* FILE */
+
+typedef void nvlist_t;
+
+int nvlist_lookup_string (nvlist_t *, const char *, char **);
+int nvlist_lookup_nvlist (nvlist_t *, const char *, nvlist_t **);
+int nvlist_lookup_nvlist_array (nvlist_t *, const char *, nvlist_t ***, unsigned int *);
+
+#endif /* ! HAVE_LIBNVPAIR_H */
+
+#endif
diff --git a/include/grub/util/libzfs.h b/include/grub/util/libzfs.h
new file mode 100644
index 0000000..a02caa3
--- /dev/null
+++ b/include/grub/util/libzfs.h
@@ -0,0 +1,47 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_LIBZFS_UTIL_HEADER
+#define GRUB_LIBZFS_UTIL_HEADER 1
+
+#include <config.h>
+
+#ifdef HAVE_LIBZFS_H
+#include <libzfs.h>
+#else /* ! HAVE_LIBZFS_H */
+
+#include <grub/util/libnvpair.h>
+
+typedef void libzfs_handle_t;
+typedef void zpool_handle_t;
+
+extern libzfs_handle_t *libzfs_init (void);
+extern void libzfs_fini (libzfs_handle_t *);
+
+extern zpool_handle_t *zpool_open (libzfs_handle_t *, const char *);
+extern void zpool_close (zpool_handle_t *);
+
+extern int zpool_get_physpath (zpool_handle_t *, const char *);
+
+extern nvlist_t *zpool_get_config (zpool_handle_t *, nvlist_t **);
+
+#endif /* ! HAVE_LIBZFS_H */
+
+libzfs_handle_t *grub_get_libzfs_handle (void);
+
+#endif
diff --git a/include/grub/util/misc.h b/include/grub/util/misc.h
new file mode 100644
index 0000000..e9e0a67
--- /dev/null
+++ b/include/grub/util/misc.h
@@ -0,0 +1,52 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2003,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_UTIL_MISC_HEADER
+#define GRUB_UTIL_MISC_HEADER 1
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <setjmp.h>
+#include <unistd.h>
+
+#include <config.h>
+#include <grub/types.h>
+#include <grub/symbol.h>
+#include <grub/emu/misc.h>
+
+char *grub_util_get_path (const char *dir, const char *file);
+size_t grub_util_get_image_size (const char *path);
+char *grub_util_read_image (const char *path);
+void grub_util_load_image (const char *path, char *buf);
+void grub_util_write_image (const char *img, size_t size, FILE *out,
+ const char *name);
+void grub_util_write_image_at (const void *img, size_t size, off_t offset,
+ FILE *out, const char *name);
+
+char *make_system_path_relative_to_its_root (const char *path);
+
+char *grub_canonicalize_file_name (const char *path);
+
+void grub_util_init_nls (void);
+
+void grub_util_host_init (int *argc, char ***argv);
+
+int grub_qsort_strcmp (const void *, const void *);
+
+#endif /* ! GRUB_UTIL_MISC_HEADER */
diff --git a/include/grub/util/mkimage.h b/include/grub/util/mkimage.h
new file mode 100644
index 0000000..3819a67
--- /dev/null
+++ b/include/grub/util/mkimage.h
@@ -0,0 +1,187 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_UTIL_MKIMAGE_HEADER
+#define GRUB_UTIL_MKIMAGE_HEADER 1
+
+struct grub_mkimage_layout
+{
+ size_t exec_size;
+ size_t kernel_size;
+ size_t bss_size;
+ size_t sbat_size;
+ grub_uint64_t start_address;
+ void *reloc_section;
+ size_t reloc_size;
+ size_t align;
+ grub_size_t ia64jmp_off;
+ grub_size_t tramp_off;
+ grub_size_t got_off;
+ grub_size_t got_size;
+ unsigned ia64jmpnum;
+ grub_uint32_t bss_start;
+ grub_uint32_t end;
+};
+
+/* Private header. Use only in mkimage-related sources. */
+char *
+grub_mkimage_load_image32 (const char *kernel_path,
+ size_t total_module_size,
+ struct grub_mkimage_layout *layout,
+ const struct grub_install_image_target_desc *image_target);
+char *
+grub_mkimage_load_image64 (const char *kernel_path,
+ size_t total_module_size,
+ struct grub_mkimage_layout *layout,
+ const struct grub_install_image_target_desc *image_target);
+void
+grub_mkimage_generate_elf32 (const struct grub_install_image_target_desc *image_target,
+ int note, char **core_img, size_t *core_size,
+ Elf32_Addr target_addr,
+ struct grub_mkimage_layout *layout);
+void
+grub_mkimage_generate_elf64 (const struct grub_install_image_target_desc *image_target,
+ int note, char **core_img, size_t *core_size,
+ Elf64_Addr target_addr,
+ struct grub_mkimage_layout *layout);
+
+struct grub_install_image_target_desc
+{
+ const char *dirname;
+ const char *names[6];
+ grub_size_t voidp_sizeof;
+ int bigendian;
+ enum {
+ IMAGE_I386_PC, IMAGE_EFI, IMAGE_COREBOOT,
+ IMAGE_SPARC64_AOUT, IMAGE_SPARC64_RAW, IMAGE_SPARC64_CDCORE,
+ IMAGE_I386_IEEE1275,
+ IMAGE_LOONGSON_ELF, IMAGE_QEMU, IMAGE_PPC, IMAGE_YEELOONG_FLASH,
+ IMAGE_FULOONG2F_FLASH, IMAGE_I386_PC_PXE, IMAGE_MIPS_ARC,
+ IMAGE_QEMU_MIPS_FLASH, IMAGE_UBOOT, IMAGE_XEN, IMAGE_I386_PC_ELTORITO,
+ IMAGE_XEN_PVH
+ } id;
+ enum
+ {
+ PLATFORM_FLAGS_NONE = 0,
+ PLATFORM_FLAGS_DECOMPRESSORS = 2,
+ PLATFORM_FLAGS_MODULES_BEFORE_KERNEL = 4,
+ } flags;
+ unsigned total_module_size;
+ unsigned decompressor_compressed_size;
+ unsigned decompressor_uncompressed_size;
+ unsigned decompressor_uncompressed_addr;
+ unsigned reloc_table_offset;
+ unsigned link_align;
+ grub_uint16_t elf_target;
+ unsigned section_align;
+ signed vaddr_offset;
+ grub_uint64_t link_addr;
+ unsigned mod_gap, mod_align;
+ grub_compression_t default_compression;
+ grub_uint16_t pe_target;
+};
+
+#define grub_target_to_host32(x) (grub_target_to_host32_real (image_target, (x)))
+#define grub_host_to_target32(x) (grub_host_to_target32_real (image_target, (x)))
+#define grub_target_to_host64(x) (grub_target_to_host64_real (image_target, (x)))
+#define grub_host_to_target64(x) (grub_host_to_target64_real (image_target, (x)))
+#define grub_host_to_target_addr(x) (grub_host_to_target_addr_real (image_target, (x)))
+#define grub_target_to_host16(x) (grub_target_to_host16_real (image_target, (x)))
+#define grub_host_to_target16(x) (grub_host_to_target16_real (image_target, (x)))
+
+static inline grub_uint32_t
+grub_target_to_host32_real (const struct grub_install_image_target_desc *image_target,
+ grub_uint32_t in)
+{
+ if (image_target->bigendian)
+ return grub_be_to_cpu32 (in);
+ else
+ return grub_le_to_cpu32 (in);
+}
+
+static inline grub_uint64_t
+grub_target_to_host64_real (const struct grub_install_image_target_desc *image_target,
+ grub_uint64_t in)
+{
+ if (image_target->bigendian)
+ return grub_be_to_cpu64 (in);
+ else
+ return grub_le_to_cpu64 (in);
+}
+
+static inline grub_uint64_t
+grub_host_to_target64_real (const struct grub_install_image_target_desc *image_target,
+ grub_uint64_t in)
+{
+ if (image_target->bigendian)
+ return grub_cpu_to_be64 (in);
+ else
+ return grub_cpu_to_le64 (in);
+}
+
+static inline grub_uint32_t
+grub_host_to_target32_real (const struct grub_install_image_target_desc *image_target,
+ grub_uint32_t in)
+{
+ if (image_target->bigendian)
+ return grub_cpu_to_be32 (in);
+ else
+ return grub_cpu_to_le32 (in);
+}
+
+static inline grub_uint16_t
+grub_target_to_host16_real (const struct grub_install_image_target_desc *image_target,
+ grub_uint16_t in)
+{
+ if (image_target->bigendian)
+ return grub_be_to_cpu16 (in);
+ else
+ return grub_le_to_cpu16 (in);
+}
+
+static inline grub_uint16_t
+grub_host_to_target16_real (const struct grub_install_image_target_desc *image_target,
+ grub_uint16_t in)
+{
+ if (image_target->bigendian)
+ return grub_cpu_to_be16 (in);
+ else
+ return grub_cpu_to_le16 (in);
+}
+
+static inline grub_uint64_t
+grub_host_to_target_addr_real (const struct grub_install_image_target_desc *image_target, grub_uint64_t in)
+{
+ if (image_target->voidp_sizeof == 8)
+ return grub_host_to_target64_real (image_target, in);
+ else
+ return grub_host_to_target32_real (image_target, in);
+}
+
+static inline grub_uint64_t
+grub_target_to_host_real (const struct grub_install_image_target_desc *image_target, grub_uint64_t in)
+{
+ if (image_target->voidp_sizeof == 8)
+ return grub_target_to_host64_real (image_target, in);
+ else
+ return grub_target_to_host32_real (image_target, in);
+}
+
+#define grub_target_to_host(val) grub_target_to_host_real(image_target, (val))
+
+#endif
diff --git a/include/grub/util/ofpath.h b/include/grub/util/ofpath.h
new file mode 100644
index 0000000..b43c523
--- /dev/null
+++ b/include/grub/util/ofpath.h
@@ -0,0 +1,6 @@
+#ifndef GRUB_OFPATH_MACHINE_UTIL_HEADER
+#define GRUB_OFPATH_MACHINE_UTIL_HEADER 1
+
+char *grub_util_devname_to_ofpath (const char *devname);
+
+#endif /* ! GRUB_OFPATH_MACHINE_UTIL_HEADER */
diff --git a/include/grub/util/resolve.h b/include/grub/util/resolve.h
new file mode 100644
index 0000000..8923a6e
--- /dev/null
+++ b/include/grub/util/resolve.h
@@ -0,0 +1,36 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_UTIL_RESOLVE_HEADER
+#define GRUB_UTIL_RESOLVE_HEADER 1
+
+struct grub_util_path_list
+{
+ const char *name;
+ struct grub_util_path_list *next;
+};
+
+/* Resolve the dependencies of the modules MODULES using the information
+ in the file DEP_LIST_FILE. The directory PREFIX is used to find files. */
+struct grub_util_path_list *
+grub_util_resolve_dependencies (const char *prefix,
+ const char *dep_list_file,
+ char *modules[]);
+void grub_util_free_path_list (struct grub_util_path_list *path_list);
+
+#endif /* ! GRUB_UTIL_RESOLVE_HEADER */
diff --git a/include/grub/util/windows.h b/include/grub/util/windows.h
new file mode 100644
index 0000000..6309483
--- /dev/null
+++ b/include/grub/util/windows.h
@@ -0,0 +1,33 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_WINDOWS_UTIL_HEADER
+#define GRUB_WINDOWS_UTIL_HEADER 1
+
+#include <windows.h>
+
+LPTSTR
+grub_util_get_windows_path (const char *unix_path);
+
+char *
+grub_util_tchar_to_utf8 (LPCTSTR in);
+
+TCHAR *
+grub_get_mount_point (const TCHAR *path);
+
+#endif
diff --git a/include/grub/verify.h b/include/grub/verify.h
new file mode 100644
index 0000000..cd129c3
--- /dev/null
+++ b/include/grub/verify.h
@@ -0,0 +1,87 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2017 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_VERIFY_HEADER
+#define GRUB_VERIFY_HEADER 1
+
+#include <grub/file.h>
+#include <grub/list.h>
+
+enum grub_verify_flags
+ {
+ GRUB_VERIFY_FLAGS_SKIP_VERIFICATION = 1,
+ GRUB_VERIFY_FLAGS_SINGLE_CHUNK = 2,
+ /* Defer verification to another authority. */
+ GRUB_VERIFY_FLAGS_DEFER_AUTH = 4
+ };
+
+enum grub_verify_string_type
+ {
+ GRUB_VERIFY_KERNEL_CMDLINE,
+ GRUB_VERIFY_MODULE_CMDLINE,
+ GRUB_VERIFY_COMMAND,
+ };
+
+struct grub_file_verifier
+{
+ struct grub_file_verifier *next;
+ struct grub_file_verifier **prev;
+
+ const char *name;
+
+ /*
+ * Check if file needs to be verified and set up context.
+ * init/read/fini is structured in the same way as hash interface.
+ */
+ grub_err_t (*init) (grub_file_t io, enum grub_file_type type,
+ void **context, enum grub_verify_flags *flags);
+
+ /*
+ * Right now we pass the whole file in one call but it may
+ * change in the future. If you insist on single buffer you
+ * need to set GRUB_VERIFY_FLAGS_SINGLE_CHUNK in verify_flags.
+ */
+ grub_err_t (*write) (void *context, void *buf, grub_size_t size);
+
+ grub_err_t (*fini) (void *context);
+ void (*close) (void *context);
+
+ grub_err_t (*verify_string) (char *str, enum grub_verify_string_type type);
+};
+
+extern struct grub_file_verifier *EXPORT_VAR (grub_file_verifiers);
+
+extern void
+grub_verifiers_init (void);
+
+static inline void
+grub_verifier_register (struct grub_file_verifier *ver)
+{
+ grub_list_push (GRUB_AS_LIST_P (&grub_file_verifiers), GRUB_AS_LIST (ver));
+}
+
+static inline void
+grub_verifier_unregister (struct grub_file_verifier *ver)
+{
+ grub_list_remove (GRUB_AS_LIST (ver));
+}
+
+extern grub_err_t
+EXPORT_FUNC (grub_verify_string) (char *str, enum grub_verify_string_type type);
+
+#endif /* ! GRUB_VERIFY_HEADER */
diff --git a/include/grub/vga.h b/include/grub/vga.h
new file mode 100644
index 0000000..1d8449c
--- /dev/null
+++ b/include/grub/vga.h
@@ -0,0 +1,129 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_VGA_HEADER
+#define GRUB_VGA_HEADER 1
+
+#ifndef GRUB_MACHINE_MIPS_QEMU_MIPS
+#include <grub/pci.h>
+#else
+#include <grub/cpu/io.h>
+#define GRUB_MACHINE_PCI_IO_BASE 0xb4000000
+#endif
+
+#include <grub/vgaregs.h>
+
+static inline void
+grub_vga_gr_write (grub_uint8_t val, grub_uint8_t addr)
+{
+ grub_outb (addr, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_GR_INDEX);
+ grub_outb (val, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_GR_DATA);
+}
+
+static inline grub_uint8_t
+grub_vga_gr_read (grub_uint8_t addr)
+{
+ grub_outb (addr, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_GR_INDEX);
+ return grub_inb (GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_GR_DATA);
+}
+
+static inline void
+grub_vga_cr_write (grub_uint8_t val, grub_uint8_t addr)
+{
+ grub_outb (addr, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_CR_INDEX);
+ grub_outb (val, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_CR_DATA);
+}
+
+static inline grub_uint8_t
+grub_vga_cr_read (grub_uint8_t addr)
+{
+ grub_outb (addr, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_CR_INDEX);
+ return grub_inb (GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_CR_DATA);
+}
+
+static inline void
+grub_vga_cr_bw_write (grub_uint8_t val, grub_uint8_t addr)
+{
+ grub_outb (addr, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_CR_BW_INDEX);
+ grub_outb (val, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_CR_BW_DATA);
+}
+
+static inline grub_uint8_t
+grub_vga_cr_bw_read (grub_uint8_t addr)
+{
+ grub_outb (addr, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_CR_BW_INDEX);
+ return grub_inb (GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_CR_BW_DATA);
+}
+
+static inline void
+grub_vga_sr_write (grub_uint8_t val, grub_uint8_t addr)
+{
+ grub_outb (addr, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_SR_INDEX);
+ grub_outb (val, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_SR_DATA);
+}
+
+static inline grub_uint8_t
+grub_vga_sr_read (grub_uint8_t addr)
+{
+ grub_outb (addr, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_SR_INDEX);
+ return grub_inb (GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_SR_DATA);
+}
+
+static inline void
+grub_vga_palette_read (grub_uint8_t addr, grub_uint8_t *r, grub_uint8_t *g,
+ grub_uint8_t *b)
+{
+ grub_outb (addr, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_PALLETTE_READ_INDEX);
+ *r = grub_inb (GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_PALLETTE_DATA);
+ *g = grub_inb (GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_PALLETTE_DATA);
+ *b = grub_inb (GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_PALLETTE_DATA);
+}
+
+static inline void
+grub_vga_palette_write (grub_uint8_t addr, grub_uint8_t r, grub_uint8_t g,
+ grub_uint8_t b)
+{
+ grub_outb (addr, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_PALLETTE_WRITE_INDEX);
+ grub_outb (r, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_PALLETTE_DATA);
+ grub_outb (g, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_PALLETTE_DATA);
+ grub_outb (b, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_PALLETTE_DATA);
+}
+
+static inline void
+grub_vga_write_arx (grub_uint8_t val, grub_uint8_t addr)
+{
+ grub_inb (GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_INPUT_STATUS1_REGISTER);
+ grub_inb (GRUB_MACHINE_PCI_IO_BASE + 0x3ba);
+
+ grub_outb (addr, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_ARX);
+ grub_inb (GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_ARX_READ);
+ grub_outb (val, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_ARX);
+}
+
+static inline grub_uint8_t
+grub_vga_read_arx (grub_uint8_t addr)
+{
+ grub_uint8_t val;
+ grub_inb (GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_INPUT_STATUS1_REGISTER);
+ grub_outb (addr, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_ARX);
+ val = grub_inb (GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_ARX_READ);
+ grub_outb (val, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_ARX);
+ return val;
+}
+
+#endif
diff --git a/include/grub/vgaregs.h b/include/grub/vgaregs.h
new file mode 100644
index 0000000..1a666a1
--- /dev/null
+++ b/include/grub/vgaregs.h
@@ -0,0 +1,307 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_VGAREGS_HEADER
+#define GRUB_VGAREGS_HEADER 1
+
+#ifdef ASM_FILE
+#define GRUB_VGA_IO_SR_INDEX 0x3c4
+#define GRUB_VGA_IO_SR_DATA 0x3c5
+#else
+
+enum
+ {
+ GRUB_VGA_IO_CR_BW_INDEX = 0x3b4,
+ GRUB_VGA_IO_CR_BW_DATA = 0x3b5,
+ GRUB_VGA_IO_ARX = 0x3c0,
+ GRUB_VGA_IO_ARX_READ = 0x3c1,
+ GRUB_VGA_IO_MISC_WRITE = 0x3c2,
+ GRUB_VGA_IO_SR_INDEX = 0x3c4,
+ GRUB_VGA_IO_SR_DATA = 0x3c5,
+ GRUB_VGA_IO_PIXEL_MASK = 0x3c6,
+ GRUB_VGA_IO_PALLETTE_READ_INDEX = 0x3c7,
+ GRUB_VGA_IO_PALLETTE_WRITE_INDEX = 0x3c8,
+ GRUB_VGA_IO_PALLETTE_DATA = 0x3c9,
+ GRUB_VGA_IO_GR_INDEX = 0x3ce,
+ GRUB_VGA_IO_GR_DATA = 0x3cf,
+ GRUB_VGA_IO_CR_INDEX = 0x3d4,
+ GRUB_VGA_IO_CR_DATA = 0x3d5,
+ GRUB_VGA_IO_INPUT_STATUS1_REGISTER = 0x3da
+ };
+
+#define GRUB_VGA_IO_INPUT_STATUS1_VERTR_BIT 0x08
+
+enum
+ {
+ GRUB_VGA_CR_HTOTAL = 0x00,
+ GRUB_VGA_CR_HORIZ_END = 0x01,
+ GRUB_VGA_CR_HBLANK_START = 0x02,
+ GRUB_VGA_CR_HBLANK_END = 0x03,
+ GRUB_VGA_CR_HORIZ_SYNC_PULSE_START = 0x04,
+ GRUB_VGA_CR_HORIZ_SYNC_PULSE_END = 0x05,
+ GRUB_VGA_CR_VERT_TOTAL = 0x06,
+ GRUB_VGA_CR_OVERFLOW = 0x07,
+ GRUB_VGA_CR_BYTE_PANNING = 0x08,
+ GRUB_VGA_CR_CELL_HEIGHT = 0x09,
+ GRUB_VGA_CR_CURSOR_START = 0x0a,
+ GRUB_VGA_CR_CURSOR_END = 0x0b,
+ GRUB_VGA_CR_START_ADDR_HIGH_REGISTER = 0x0c,
+ GRUB_VGA_CR_START_ADDR_LOW_REGISTER = 0x0d,
+ GRUB_VGA_CR_CURSOR_ADDR_HIGH = 0x0e,
+ GRUB_VGA_CR_CURSOR_ADDR_LOW = 0x0f,
+ GRUB_VGA_CR_VSYNC_START = 0x10,
+ GRUB_VGA_CR_VSYNC_END = 0x11,
+ GRUB_VGA_CR_VDISPLAY_END = 0x12,
+ GRUB_VGA_CR_PITCH = 0x13,
+ GRUB_VGA_CR_UNDERLINE_LOCATION = 0x14,
+ GRUB_VGA_CR_VERTICAL_BLANK_START = 0x15,
+ GRUB_VGA_CR_VERTICAL_BLANK_END = 0x16,
+ GRUB_VGA_CR_MODE = 0x17,
+ GRUB_VGA_CR_LINE_COMPARE = 0x18,
+ };
+
+enum
+ {
+ GRUB_VGA_CR_BYTE_PANNING_NORMAL = 0
+ };
+
+enum
+ {
+ GRUB_VGA_CR_UNDERLINE_LOCATION_DWORD_MODE = 0x40
+ };
+
+enum
+ {
+ GRUB_VGA_IO_MISC_COLOR = 0x01,
+ GRUB_VGA_IO_MISC_ENABLE_VRAM_ACCESS = 0x02,
+ GRUB_VGA_IO_MISC_28MHZ = 0x04,
+ GRUB_VGA_IO_MISC_EXTERNAL_CLOCK_0 = 0x08,
+ GRUB_VGA_IO_MISC_UPPER_64K = 0x20,
+ GRUB_VGA_IO_MISC_NEGATIVE_HORIZ_POLARITY = 0x40,
+ GRUB_VGA_IO_MISC_NEGATIVE_VERT_POLARITY = 0x80,
+ };
+
+enum
+ {
+ GRUB_VGA_ARX_MODE = 0x10,
+ GRUB_VGA_ARX_OVERSCAN = 0x11,
+ GRUB_VGA_ARX_COLOR_PLANE_ENABLE = 0x12,
+ GRUB_VGA_ARX_HORIZONTAL_PANNING = 0x13,
+ GRUB_VGA_ARX_COLOR_SELECT = 0x14
+ };
+
+enum
+ {
+ GRUB_VGA_ARX_MODE_TEXT = 0x00,
+ GRUB_VGA_ARX_MODE_GRAPHICS = 0x01,
+ GRUB_VGA_ARX_MODE_ENABLE_256COLOR = 0x40
+ };
+
+#define GRUB_VGA_CR_WIDTH_DIVISOR 8
+
+#define GRUB_VGA_CR_OVERFLOW_VERT_DISPLAY_ENABLE_END1_SHIFT 7
+#define GRUB_VGA_CR_OVERFLOW_VERT_DISPLAY_ENABLE_END1_MASK 0x02
+#define GRUB_VGA_CR_OVERFLOW_VERT_DISPLAY_ENABLE_END2_SHIFT 3
+#define GRUB_VGA_CR_OVERFLOW_VERT_DISPLAY_ENABLE_END2_MASK 0x40
+
+#define GRUB_VGA_CR_OVERFLOW_VERT_TOTAL1_SHIFT 8
+#define GRUB_VGA_CR_OVERFLOW_VERT_TOTAL1_MASK 0x01
+#define GRUB_VGA_CR_OVERFLOW_VERT_TOTAL2_SHIFT 4
+#define GRUB_VGA_CR_OVERFLOW_VERT_TOTAL2_MASK 0x20
+
+#define GRUB_VGA_CR_OVERFLOW_VSYNC_START1_SHIFT 6
+#define GRUB_VGA_CR_OVERFLOW_VSYNC_START1_MASK 0x04
+#define GRUB_VGA_CR_OVERFLOW_VSYNC_START2_SHIFT 2
+#define GRUB_VGA_CR_OVERFLOW_VSYNC_START2_MASK 0x80
+
+#define GRUB_VGA_CR_OVERFLOW_HEIGHT1_SHIFT 7
+#define GRUB_VGA_CR_OVERFLOW_HEIGHT1_MASK 0x02
+#define GRUB_VGA_CR_OVERFLOW_HEIGHT2_SHIFT 3
+#define GRUB_VGA_CR_OVERFLOW_HEIGHT2_MASK 0xc0
+#define GRUB_VGA_CR_OVERFLOW_LINE_COMPARE_SHIFT 4
+#define GRUB_VGA_CR_OVERFLOW_LINE_COMPARE_MASK 0x10
+
+#define GRUB_VGA_CR_CELL_HEIGHT_LINE_COMPARE_MASK 0x40
+#define GRUB_VGA_CR_CELL_HEIGHT_LINE_COMPARE_SHIFT 3
+#define GRUB_VGA_CR_CELL_HEIGHT_VERTICAL_BLANK_MASK 0x20
+#define GRUB_VGA_CR_CELL_HEIGHT_VERTICAL_BLANK_SHIFT 4
+#define GRUB_VGA_CR_CELL_HEIGHT_DOUBLE_SCAN 0x80
+enum
+ {
+ GRUB_VGA_CR_CURSOR_START_DISABLE = (1 << 5)
+ };
+
+#define GRUB_VGA_CR_PITCH_DIVISOR 8
+
+enum
+ {
+ GRUB_VGA_CR_MODE_NO_CGA = 0x01,
+ GRUB_VGA_CR_MODE_NO_HERCULES = 0x02,
+ GRUB_VGA_CR_MODE_ADDRESS_WRAP = 0x20,
+ GRUB_VGA_CR_MODE_BYTE_MODE = 0x40,
+ GRUB_VGA_CR_MODE_TIMING_ENABLE = 0x80
+ };
+
+enum
+ {
+ GRUB_VGA_SR_RESET = 0,
+ GRUB_VGA_SR_CLOCKING_MODE = 1,
+ GRUB_VGA_SR_MAP_MASK_REGISTER = 2,
+ GRUB_VGA_SR_CHAR_MAP_SELECT = 3,
+ GRUB_VGA_SR_MEMORY_MODE = 4,
+ };
+
+enum
+ {
+ GRUB_VGA_SR_RESET_ASYNC = 1,
+ GRUB_VGA_SR_RESET_SYNC = 2
+ };
+
+enum
+ {
+ GRUB_VGA_SR_CLOCKING_MODE_8_DOT_CLOCK = 1
+ };
+
+enum
+ {
+ GRUB_VGA_SR_MEMORY_MODE_NORMAL = 0,
+ GRUB_VGA_SR_MEMORY_MODE_EXTERNAL_VIDEO_MEMORY = 2,
+ GRUB_VGA_SR_MEMORY_MODE_SEQUENTIAL_ADDRESSING = 4,
+ GRUB_VGA_SR_MEMORY_MODE_CHAIN4 = 8,
+ };
+
+enum
+ {
+ GRUB_VGA_GR_SET_RESET_PLANE = 0,
+ GRUB_VGA_GR_SET_RESET_PLANE_ENABLE = 1,
+ GRUB_VGA_GR_COLOR_COMPARE = 2,
+ GRUB_VGA_GR_DATA_ROTATE = 3,
+ GRUB_VGA_GR_READ_MAP_REGISTER = 4,
+ GRUB_VGA_GR_MODE = 5,
+ GRUB_VGA_GR_GR6 = 6,
+ GRUB_VGA_GR_COLOR_COMPARE_DISABLE = 7,
+ GRUB_VGA_GR_BITMASK = 8,
+ GRUB_VGA_GR_MAX
+ };
+
+#define GRUB_VGA_ALL_PLANES 0xf
+#define GRUB_VGA_NO_PLANES 0x0
+
+enum
+ {
+ GRUB_VGA_GR_DATA_ROTATE_NOP = 0
+ };
+
+enum
+ {
+ GRUB_VGA_TEXT_TEXT_PLANE = 0,
+ GRUB_VGA_TEXT_ATTR_PLANE = 1,
+ GRUB_VGA_TEXT_FONT_PLANE = 2
+ };
+
+enum
+ {
+ GRUB_VGA_GR_GR6_GRAPHICS_MODE = 1,
+ GRUB_VGA_GR_GR6_MMAP_A0 = (1 << 2),
+ GRUB_VGA_GR_GR6_MMAP_CGA = (3 << 2)
+ };
+
+enum
+ {
+ GRUB_VGA_GR_MODE_READ_MODE1 = 0x08,
+ GRUB_VGA_GR_MODE_ODD_EVEN = 0x10,
+ GRUB_VGA_GR_MODE_ODD_EVEN_SHIFT = 0x20,
+ GRUB_VGA_GR_MODE_256_COLOR = 0x40
+ };
+
+struct grub_video_hw_config
+{
+ unsigned vertical_total;
+ unsigned vertical_blank_start;
+ unsigned vertical_blank_end;
+ unsigned vertical_sync_start;
+ unsigned vertical_sync_end;
+ unsigned line_compare;
+ unsigned vdisplay_end;
+ unsigned pitch;
+ unsigned horizontal_total;
+ unsigned horizontal_blank_start;
+ unsigned horizontal_blank_end;
+ unsigned horizontal_sync_pulse_start;
+ unsigned horizontal_sync_pulse_end;
+ unsigned horizontal_end;
+};
+
+static inline void
+grub_vga_set_geometry (struct grub_video_hw_config *config,
+ void (*cr_write) (grub_uint8_t val, grub_uint8_t addr))
+{
+ unsigned vertical_total = config->vertical_total - 2;
+ unsigned vertical_blank_start = config->vertical_blank_start - 1;
+ unsigned vdisplay_end = config->vdisplay_end - 1;
+ grub_uint8_t overflow, cell_height_reg;
+
+ /* Disable CR0-7 write protection. */
+ cr_write (0, GRUB_VGA_CR_VSYNC_END);
+
+ overflow = ((vertical_total >> GRUB_VGA_CR_OVERFLOW_VERT_TOTAL1_SHIFT)
+ & GRUB_VGA_CR_OVERFLOW_VERT_TOTAL1_MASK)
+ | ((vertical_total >> GRUB_VGA_CR_OVERFLOW_VERT_TOTAL2_SHIFT)
+ & GRUB_VGA_CR_OVERFLOW_VERT_TOTAL2_MASK)
+ | ((config->vertical_sync_start >> GRUB_VGA_CR_OVERFLOW_VSYNC_START2_SHIFT)
+ & GRUB_VGA_CR_OVERFLOW_VSYNC_START2_MASK)
+ | ((config->vertical_sync_start >> GRUB_VGA_CR_OVERFLOW_VSYNC_START1_SHIFT)
+ & GRUB_VGA_CR_OVERFLOW_VSYNC_START1_MASK)
+ | ((vdisplay_end >> GRUB_VGA_CR_OVERFLOW_VERT_DISPLAY_ENABLE_END1_SHIFT)
+ & GRUB_VGA_CR_OVERFLOW_VERT_DISPLAY_ENABLE_END1_MASK)
+ | ((vdisplay_end >> GRUB_VGA_CR_OVERFLOW_VERT_DISPLAY_ENABLE_END2_SHIFT)
+ & GRUB_VGA_CR_OVERFLOW_VERT_DISPLAY_ENABLE_END2_MASK)
+ | ((config->vertical_sync_start >> GRUB_VGA_CR_OVERFLOW_VSYNC_START1_SHIFT)
+ & GRUB_VGA_CR_OVERFLOW_VSYNC_START1_MASK)
+ | ((config->line_compare >> GRUB_VGA_CR_OVERFLOW_LINE_COMPARE_SHIFT)
+ & GRUB_VGA_CR_OVERFLOW_LINE_COMPARE_MASK);
+
+ cell_height_reg = ((vertical_blank_start
+ >> GRUB_VGA_CR_CELL_HEIGHT_VERTICAL_BLANK_SHIFT)
+ & GRUB_VGA_CR_CELL_HEIGHT_VERTICAL_BLANK_MASK)
+ | ((config->line_compare >> GRUB_VGA_CR_CELL_HEIGHT_LINE_COMPARE_SHIFT)
+ & GRUB_VGA_CR_CELL_HEIGHT_LINE_COMPARE_MASK);
+
+ cr_write (config->horizontal_total - 1, GRUB_VGA_CR_HTOTAL);
+ cr_write (config->horizontal_end - 1, GRUB_VGA_CR_HORIZ_END);
+ cr_write (config->horizontal_blank_start - 1, GRUB_VGA_CR_HBLANK_START);
+ cr_write (config->horizontal_blank_end, GRUB_VGA_CR_HBLANK_END);
+ cr_write (config->horizontal_sync_pulse_start,
+ GRUB_VGA_CR_HORIZ_SYNC_PULSE_START);
+ cr_write (config->horizontal_sync_pulse_end,
+ GRUB_VGA_CR_HORIZ_SYNC_PULSE_END);
+ cr_write (vertical_total & 0xff, GRUB_VGA_CR_VERT_TOTAL);
+ cr_write (overflow, GRUB_VGA_CR_OVERFLOW);
+ cr_write (cell_height_reg, GRUB_VGA_CR_CELL_HEIGHT);
+ cr_write (config->vertical_sync_start & 0xff, GRUB_VGA_CR_VSYNC_START);
+ cr_write (config->vertical_sync_end & 0x0f, GRUB_VGA_CR_VSYNC_END);
+ cr_write (vdisplay_end & 0xff, GRUB_VGA_CR_VDISPLAY_END);
+ cr_write (config->pitch & 0xff, GRUB_VGA_CR_PITCH);
+ cr_write (vertical_blank_start & 0xff, GRUB_VGA_CR_VERTICAL_BLANK_START);
+ cr_write (config->vertical_blank_end & 0xff, GRUB_VGA_CR_VERTICAL_BLANK_END);
+ cr_write (config->line_compare & 0xff, GRUB_VGA_CR_LINE_COMPARE);
+}
+
+#endif
+
+#endif
diff --git a/include/grub/video.h b/include/grub/video.h
new file mode 100644
index 0000000..52c3fd7
--- /dev/null
+++ b/include/grub/video.h
@@ -0,0 +1,704 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_VIDEO_HEADER
+#define GRUB_VIDEO_HEADER 1
+
+#include <grub/err.h>
+#include <grub/types.h>
+#include <grub/list.h>
+
+/* Video color in hardware dependent format. Users should not assume any
+ specific coding format. */
+typedef grub_uint32_t grub_video_color_t;
+
+/* Video color in hardware independent format. */
+typedef struct grub_video_rgba_color
+{
+ grub_uint8_t red;
+ grub_uint8_t green;
+ grub_uint8_t blue;
+ grub_uint8_t alpha;
+} grub_video_rgba_color_t;
+
+/* This structure is driver specific and should not be accessed directly by
+ outside code. */
+struct grub_video_render_target;
+
+/* Forward declarations for used data structures. */
+struct grub_video_bitmap;
+
+/* Defines used to describe video mode or rendering target. */
+/* If following is set render target contains currenly displayed image
+ after swapping buffers (otherwise it contains previously displayed image).
+ */
+typedef enum grub_video_mode_type
+ {
+ GRUB_VIDEO_MODE_TYPE_RGB = 0x00000001,
+ GRUB_VIDEO_MODE_TYPE_INDEX_COLOR = 0x00000002,
+ GRUB_VIDEO_MODE_TYPE_1BIT_BITMAP = 0x00000004,
+ GRUB_VIDEO_MODE_TYPE_YUV = 0x00000008,
+
+ /* Defines used to mask flags. */
+ GRUB_VIDEO_MODE_TYPE_COLOR_MASK = 0x0000000F,
+
+ GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED = 0x00000010,
+ GRUB_VIDEO_MODE_TYPE_ALPHA = 0x00000020,
+ GRUB_VIDEO_MODE_TYPE_PURE_TEXT = 0x00000040,
+ GRUB_VIDEO_MODE_TYPE_UPDATING_SWAP = 0x00000080,
+ GRUB_VIDEO_MODE_TYPE_OPERATIONAL_MASK = 0x000000F0,
+
+ /* Defines used to specify requested bit depth. */
+ GRUB_VIDEO_MODE_TYPE_DEPTH_MASK = 0x0000FF00,
+#define GRUB_VIDEO_MODE_TYPE_DEPTH_POS 8
+
+ GRUB_VIDEO_MODE_TYPE_UNKNOWN = 0x00010000,
+ GRUB_VIDEO_MODE_TYPE_HERCULES = 0x00020000,
+ GRUB_VIDEO_MODE_TYPE_PLANAR = 0x00040000,
+ GRUB_VIDEO_MODE_TYPE_NONCHAIN4 = 0x00080000,
+ GRUB_VIDEO_MODE_TYPE_CGA = 0x00100000,
+ GRUB_VIDEO_MODE_TYPE_INFO_MASK = 0x00FF0000,
+ } grub_video_mode_type_t;
+
+/* The basic render target representing the whole display. This always
+ renders to the back buffer when double-buffering is in use. */
+#define GRUB_VIDEO_RENDER_TARGET_DISPLAY \
+ ((struct grub_video_render_target *) 0)
+
+/* Defined blitting formats. */
+enum grub_video_blit_format
+ {
+ /* Generic RGBA, use fields & masks. */
+ GRUB_VIDEO_BLIT_FORMAT_RGBA,
+
+ /* Optimized RGBA's. */
+ GRUB_VIDEO_BLIT_FORMAT_RGBA_8888,
+ GRUB_VIDEO_BLIT_FORMAT_BGRA_8888,
+
+ /* Generic RGB, use fields & masks. */
+ GRUB_VIDEO_BLIT_FORMAT_RGB,
+
+ /* Optimized RGB's. */
+ GRUB_VIDEO_BLIT_FORMAT_RGB_888,
+ GRUB_VIDEO_BLIT_FORMAT_BGR_888,
+ GRUB_VIDEO_BLIT_FORMAT_RGB_565,
+ GRUB_VIDEO_BLIT_FORMAT_BGR_565,
+
+ /* When needed, decode color or just use value as is. */
+ GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR,
+ /* Like index but only 16-colors and F0 is a special value for transparency.
+ Could be extended to 4 bits of alpha and 4 bits of color if necessary.
+ Used internally for text rendering.
+ */
+ GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR_ALPHA,
+
+ /* Two color bitmap; bits packed: rows are not padded to byte boundary. */
+ GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED
+ };
+
+/* Define blitting operators. */
+enum grub_video_blit_operators
+ {
+ /* Replace target bitmap data with source. */
+ GRUB_VIDEO_BLIT_REPLACE,
+ /* Blend target and source based on source's alpha value. */
+ GRUB_VIDEO_BLIT_BLEND
+ };
+
+struct grub_video_mode_info
+{
+ /* Width of the screen. */
+ unsigned int width;
+
+ /* Height of the screen. */
+ unsigned int height;
+
+ /* Mode type bitmask. Contains information like is it Index color or
+ RGB mode. */
+ grub_video_mode_type_t mode_type;
+
+ /* Bits per pixel. */
+ unsigned int bpp;
+
+ /* Bytes per pixel. */
+ unsigned int bytes_per_pixel;
+
+ /* Pitch of one scanline. How many bytes there are for scanline. */
+ unsigned int pitch;
+
+ /* In index color mode, number of colors. In RGB mode this is 256. */
+ unsigned int number_of_colors;
+
+ unsigned int mode_number;
+#define GRUB_VIDEO_MODE_NUMBER_INVALID 0xffffffff
+
+ /* Optimization hint how binary data is coded. */
+ enum grub_video_blit_format blit_format;
+
+ /* How many bits are reserved for red color. */
+ unsigned int red_mask_size;
+
+ /* What is location of red color bits. In Index Color mode, this is 0. */
+ unsigned int red_field_pos;
+
+ /* How many bits are reserved for green color. */
+ unsigned int green_mask_size;
+
+ /* What is location of green color bits. In Index Color mode, this is 0. */
+ unsigned int green_field_pos;
+
+ /* How many bits are reserved for blue color. */
+ unsigned int blue_mask_size;
+
+ /* What is location of blue color bits. In Index Color mode, this is 0. */
+ unsigned int blue_field_pos;
+
+ /* How many bits are reserved in color. */
+ unsigned int reserved_mask_size;
+
+ /* What is location of reserved color bits. In Index Color mode,
+ this is 0. */
+ unsigned int reserved_field_pos;
+
+ /* For 1-bit bitmaps, the background color. Used for bits = 0. */
+ grub_uint8_t bg_red;
+ grub_uint8_t bg_green;
+ grub_uint8_t bg_blue;
+ grub_uint8_t bg_alpha;
+
+ /* For 1-bit bitmaps, the foreground color. Used for bits = 1. */
+ grub_uint8_t fg_red;
+ grub_uint8_t fg_green;
+ grub_uint8_t fg_blue;
+ grub_uint8_t fg_alpha;
+};
+
+/* A 2D rectangle type. */
+struct grub_video_rect
+{
+ unsigned x;
+ unsigned y;
+ unsigned width;
+ unsigned height;
+};
+typedef struct grub_video_rect grub_video_rect_t;
+
+struct grub_video_signed_rect
+{
+ signed x;
+ signed y;
+ unsigned width;
+ unsigned height;
+};
+typedef struct grub_video_signed_rect grub_video_signed_rect_t;
+
+struct grub_video_palette_data
+{
+ grub_uint8_t r; /* Red color value (0-255). */
+ grub_uint8_t g; /* Green color value (0-255). */
+ grub_uint8_t b; /* Blue color value (0-255). */
+ grub_uint8_t a; /* Reserved bits value (0-255). */
+};
+
+struct grub_video_edid_info
+{
+ grub_uint8_t header[8];
+ grub_uint16_t manufacturer_id;
+ grub_uint16_t product_id;
+ grub_uint32_t serial_number;
+ grub_uint8_t week_of_manufacture;
+ grub_uint8_t year_of_manufacture;
+ grub_uint8_t version;
+ grub_uint8_t revision;
+
+ grub_uint8_t video_input_definition;
+ grub_uint8_t max_horizontal_image_size;
+ grub_uint8_t max_vertical_image_size;
+ grub_uint8_t display_gamma;
+ grub_uint8_t feature_support;
+#define GRUB_VIDEO_EDID_FEATURE_PREFERRED_TIMING_MODE (1 << 1)
+
+ grub_uint8_t red_green_lo;
+ grub_uint8_t blue_white_lo;
+ grub_uint8_t red_x_hi;
+ grub_uint8_t red_y_hi;
+ grub_uint8_t green_x_hi;
+ grub_uint8_t green_y_hi;
+ grub_uint8_t blue_x_hi;
+ grub_uint8_t blue_y_hi;
+ grub_uint8_t white_x_hi;
+ grub_uint8_t white_y_hi;
+
+ grub_uint8_t established_timings_1;
+ grub_uint8_t established_timings_2;
+ grub_uint8_t manufacturer_reserved_timings;
+
+ grub_uint16_t standard_timings[8];
+
+ struct {
+ grub_uint16_t pixel_clock;
+ /* Only valid if the pixel clock is non-null. */
+ grub_uint8_t horizontal_active_lo;
+ grub_uint8_t horizontal_blanking_lo;
+ grub_uint8_t horizontal_hi;
+ grub_uint8_t vertical_active_lo;
+ grub_uint8_t vertical_blanking_lo;
+ grub_uint8_t vertical_hi;
+ grub_uint8_t horizontal_sync_offset_lo;
+ grub_uint8_t horizontal_sync_pulse_width_lo;
+ grub_uint8_t vertical_sync_lo;
+ grub_uint8_t sync_hi;
+ grub_uint8_t horizontal_image_size_lo;
+ grub_uint8_t vertical_image_size_lo;
+ grub_uint8_t image_size_hi;
+ grub_uint8_t horizontal_border;
+ grub_uint8_t vertical_border;
+ grub_uint8_t flags;
+ } detailed_timings[4];
+
+ grub_uint8_t extension_flag;
+ grub_uint8_t checksum;
+} GRUB_PACKED;
+
+typedef enum grub_video_driver_id
+ {
+ GRUB_VIDEO_DRIVER_NONE,
+ GRUB_VIDEO_DRIVER_VBE,
+ GRUB_VIDEO_DRIVER_EFI_UGA,
+ GRUB_VIDEO_DRIVER_EFI_GOP,
+ GRUB_VIDEO_DRIVER_SM712,
+ GRUB_VIDEO_DRIVER_VGA,
+ GRUB_VIDEO_DRIVER_CIRRUS,
+ GRUB_VIDEO_DRIVER_BOCHS,
+ GRUB_VIDEO_DRIVER_SDL,
+ GRUB_VIDEO_DRIVER_SIS315PRO,
+ GRUB_VIDEO_DRIVER_RADEON_FULOONG2E,
+ GRUB_VIDEO_DRIVER_COREBOOT,
+ GRUB_VIDEO_DRIVER_IEEE1275,
+ GRUB_VIDEO_ADAPTER_CAPTURE,
+ GRUB_VIDEO_DRIVER_XEN,
+ GRUB_VIDEO_DRIVER_RADEON_YEELOONG3A
+ } grub_video_driver_id_t;
+
+typedef enum grub_video_adapter_prio
+ {
+ GRUB_VIDEO_ADAPTER_PRIO_FALLBACK = 60,
+ GRUB_VIDEO_ADAPTER_PRIO_FIRMWARE_DIRTY = 70,
+ GRUB_VIDEO_ADAPTER_PRIO_FIRMWARE = 80,
+ GRUB_VIDEO_ADAPTER_PRIO_NATIVE = 100
+ } grub_video_adapter_prio_t;
+
+typedef enum grub_video_area_status
+ {
+ GRUB_VIDEO_AREA_DISABLED,
+ GRUB_VIDEO_AREA_ENABLED
+ } grub_video_area_status_t;
+
+struct grub_video_adapter
+{
+ /* The next video adapter. */
+ struct grub_video_adapter *next;
+ struct grub_video_adapter **prev;
+
+ /* The video adapter name. */
+ const char *name;
+ grub_video_driver_id_t id;
+
+ grub_video_adapter_prio_t prio;
+
+ /* Initialize the video adapter. */
+ grub_err_t (*init) (void);
+
+ /* Clean up the video adapter. */
+ grub_err_t (*fini) (void);
+
+ grub_err_t (*setup) (unsigned int width, unsigned int height,
+ grub_video_mode_type_t mode_type,
+ grub_video_mode_type_t mode_mask);
+
+ grub_err_t (*get_info) (struct grub_video_mode_info *mode_info);
+
+ grub_err_t (*get_info_and_fini) (struct grub_video_mode_info *mode_info,
+ void **framebuffer);
+
+ grub_err_t (*set_palette) (unsigned int start, unsigned int count,
+ struct grub_video_palette_data *palette_data);
+
+ grub_err_t (*get_palette) (unsigned int start, unsigned int count,
+ struct grub_video_palette_data *palette_data);
+
+ grub_err_t (*set_viewport) (unsigned int x, unsigned int y,
+ unsigned int width, unsigned int height);
+
+ grub_err_t (*get_viewport) (unsigned int *x, unsigned int *y,
+ unsigned int *width, unsigned int *height);
+
+ grub_err_t (*set_region) (unsigned int x, unsigned int y,
+ unsigned int width, unsigned int height);
+
+ grub_err_t (*get_region) (unsigned int *x, unsigned int *y,
+ unsigned int *width, unsigned int *height);
+
+ grub_err_t (*set_area_status) (grub_video_area_status_t area_status);
+
+ grub_err_t (*get_area_status) (grub_video_area_status_t *area_status);
+
+ grub_video_color_t (*map_color) (grub_uint32_t color_name);
+
+ grub_video_color_t (*map_rgb) (grub_uint8_t red, grub_uint8_t green,
+ grub_uint8_t blue);
+
+ grub_video_color_t (*map_rgba) (grub_uint8_t red, grub_uint8_t green,
+ grub_uint8_t blue, grub_uint8_t alpha);
+
+ grub_err_t (*unmap_color) (grub_video_color_t color,
+ grub_uint8_t *red, grub_uint8_t *green,
+ grub_uint8_t *blue, grub_uint8_t *alpha);
+
+ grub_err_t (*fill_rect) (grub_video_color_t color, int x, int y,
+ unsigned int width, unsigned int height);
+
+ grub_err_t (*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);
+
+ grub_err_t (*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);
+
+ grub_err_t (*scroll) (grub_video_color_t color, int dx, int dy);
+
+ grub_err_t (*swap_buffers) (void);
+
+ grub_err_t (*create_render_target) (struct grub_video_render_target **result,
+ unsigned int width, unsigned int height,
+ unsigned int mode_type);
+
+ grub_err_t (*delete_render_target) (struct grub_video_render_target *target);
+
+ grub_err_t (*set_active_render_target) (struct grub_video_render_target *target);
+
+ grub_err_t (*get_active_render_target) (struct grub_video_render_target **target);
+
+ int (*iterate) (int (*hook) (const struct grub_video_mode_info *info, void *hook_arg), void *hook_arg);
+
+ grub_err_t (*get_edid) (struct grub_video_edid_info *edid_info);
+
+ void (*print_adapter_specific_info) (void);
+};
+typedef struct grub_video_adapter *grub_video_adapter_t;
+
+extern grub_video_adapter_t EXPORT_VAR(grub_video_adapter_list);
+
+#ifndef GRUB_LST_GENERATOR
+/* Register video driver. */
+static inline void
+grub_video_register (grub_video_adapter_t adapter)
+{
+ grub_video_adapter_t *p;
+ for (p = &grub_video_adapter_list; *p && (*p)->prio > adapter->prio;
+ p = &((*p)->next));
+ adapter->next = *p;
+ *p = adapter;
+
+ adapter->prev = p;
+ if (adapter->next)
+ adapter->next->prev = &adapter->next;
+}
+#endif
+
+/* Unregister video driver. */
+static inline void
+grub_video_unregister (grub_video_adapter_t adapter)
+{
+ grub_list_remove (GRUB_AS_LIST (adapter));
+}
+
+#define FOR_VIDEO_ADAPTERS(var) FOR_LIST_ELEMENTS((var), (grub_video_adapter_list))
+
+grub_err_t EXPORT_FUNC (grub_video_restore) (void);
+
+grub_err_t EXPORT_FUNC (grub_video_get_info) (struct grub_video_mode_info *mode_info);
+
+/* Framebuffer address may change as a part of normal operation
+ (e.g. double buffering). That's why you need to stop video subsystem to be
+ sure that framebuffer address doesn't change. To ensure this abstraction
+ grub_video_get_info_and_fini is the only function supplying framebuffer
+ address. */
+grub_err_t EXPORT_FUNC (grub_video_get_info_and_fini) (struct grub_video_mode_info *mode_info,
+ void **framebuffer);
+
+enum grub_video_blit_format EXPORT_FUNC(grub_video_get_blit_format) (struct grub_video_mode_info *mode_info);
+
+grub_err_t grub_video_set_palette (unsigned int start, unsigned int count,
+ struct grub_video_palette_data *palette_data);
+
+grub_err_t EXPORT_FUNC (grub_video_get_palette) (unsigned int start,
+ unsigned int count,
+ struct grub_video_palette_data *palette_data);
+
+grub_err_t EXPORT_FUNC (grub_video_set_viewport) (unsigned int x,
+ unsigned int y,
+ unsigned int width,
+ unsigned int height);
+
+grub_err_t EXPORT_FUNC (grub_video_get_viewport) (unsigned int *x,
+ unsigned int *y,
+ unsigned int *width,
+ unsigned int *height);
+
+grub_err_t EXPORT_FUNC (grub_video_set_region) (unsigned int x,
+ unsigned int y,
+ unsigned int width,
+ unsigned int height);
+
+grub_err_t EXPORT_FUNC (grub_video_get_region) (unsigned int *x,
+ unsigned int *y,
+ unsigned int *width,
+ unsigned int *height);
+
+grub_err_t EXPORT_FUNC (grub_video_set_area_status)
+ (grub_video_area_status_t area_status);
+
+grub_err_t EXPORT_FUNC (grub_video_get_area_status)
+ (grub_video_area_status_t *area_status);
+
+grub_video_color_t EXPORT_FUNC (grub_video_map_color) (grub_uint32_t color_name);
+
+grub_video_color_t EXPORT_FUNC (grub_video_map_rgb) (grub_uint8_t red,
+ grub_uint8_t green,
+ grub_uint8_t blue);
+
+grub_video_color_t EXPORT_FUNC (grub_video_map_rgba) (grub_uint8_t red,
+ grub_uint8_t green,
+ grub_uint8_t blue,
+ grub_uint8_t alpha);
+
+grub_err_t EXPORT_FUNC (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);
+
+grub_err_t EXPORT_FUNC (grub_video_fill_rect) (grub_video_color_t color,
+ int x, int y,
+ unsigned int width,
+ unsigned int height);
+
+grub_err_t EXPORT_FUNC (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);
+
+grub_err_t EXPORT_FUNC (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);
+
+grub_err_t grub_video_scroll (grub_video_color_t color, int dx, int dy);
+
+grub_err_t EXPORT_FUNC (grub_video_swap_buffers) (void);
+
+grub_err_t EXPORT_FUNC (grub_video_create_render_target) (struct grub_video_render_target **result,
+ unsigned int width,
+ unsigned int height,
+ unsigned int mode_type);
+
+grub_err_t EXPORT_FUNC (grub_video_delete_render_target) (struct grub_video_render_target *target);
+
+grub_err_t EXPORT_FUNC (grub_video_set_active_render_target) (struct grub_video_render_target *target);
+
+grub_err_t grub_video_get_active_render_target (struct grub_video_render_target **target);
+
+grub_err_t EXPORT_FUNC (grub_video_edid_checksum) (struct grub_video_edid_info *edid_info);
+grub_err_t EXPORT_FUNC (grub_video_edid_preferred_mode) (struct grub_video_edid_info *edid_info,
+ unsigned int *width,
+ unsigned int *height);
+
+grub_err_t EXPORT_FUNC (grub_video_set_mode) (const char *modestring,
+ unsigned int modemask,
+ unsigned int modevalue);
+
+static inline int
+grub_video_check_mode_flag (grub_video_mode_type_t flags,
+ grub_video_mode_type_t mask,
+ grub_video_mode_type_t flag, int def)
+{
+ return (flag & mask) ? !! (flags & flag) : def;
+}
+
+grub_video_driver_id_t EXPORT_FUNC (grub_video_get_driver_id) (void);
+
+static __inline grub_video_rgba_color_t
+grub_video_rgba_color_rgb (grub_uint8_t r, grub_uint8_t g, grub_uint8_t b)
+{
+ grub_video_rgba_color_t c;
+ c.red = r;
+ c.green = g;
+ c.blue = b;
+ c.alpha = 255;
+ return c;
+}
+
+static __inline grub_video_color_t
+grub_video_map_rgba_color (grub_video_rgba_color_t c)
+{
+ return grub_video_map_rgba (c.red, c.green, c.blue, c.alpha);
+}
+
+#ifndef GRUB_MACHINE_EMU
+extern void grub_font_init (void);
+extern void grub_font_fini (void);
+extern void grub_gfxterm_init (void);
+extern void grub_gfxterm_fini (void);
+extern void grub_video_sm712_init (void);
+extern void grub_video_sm712_fini (void);
+extern void grub_video_sis315pro_init (void);
+extern void grub_video_radeon_fuloong2e_init (void);
+extern void grub_video_sis315pro_fini (void);
+extern void grub_video_radeon_fuloong2e_fini (void);
+extern void grub_video_radeon_yeeloong3a_init (void);
+extern void grub_video_radeon_yeeloong3a_fini (void);
+#endif
+
+void
+grub_video_set_adapter (grub_video_adapter_t adapter);
+grub_video_adapter_t
+grub_video_get_adapter (void);
+grub_err_t
+grub_video_capture_start (const struct grub_video_mode_info *mode_info,
+ struct grub_video_palette_data *palette,
+ unsigned int palette_size);
+void
+grub_video_capture_end (void);
+
+void *
+grub_video_capture_get_framebuffer (void);
+
+extern grub_video_adapter_t EXPORT_VAR (grub_video_adapter_active);
+extern void (*grub_video_capture_refresh_cb) (void);
+
+#define GRUB_VIDEO_MI_RGB555(x) \
+ x.mode_type = GRUB_VIDEO_MODE_TYPE_RGB, \
+ x.bpp = 15, \
+ x.bytes_per_pixel = 2, \
+ x.number_of_colors = 256, \
+ x.red_mask_size = 5, \
+ x.red_field_pos = 10, \
+ x.green_mask_size = 5, \
+ x.green_field_pos = 5, \
+ x.blue_mask_size = 5, \
+ x.blue_field_pos = 0
+
+#define GRUB_VIDEO_MI_RGB565(x) \
+ x.mode_type = GRUB_VIDEO_MODE_TYPE_RGB, \
+ x.bpp = 16, \
+ x.bytes_per_pixel = 2, \
+ x.number_of_colors = 256, \
+ x.red_mask_size = 5, \
+ x.red_field_pos = 11, \
+ x.green_mask_size = 6, \
+ x.green_field_pos = 5, \
+ x.blue_mask_size = 5, \
+ x.blue_field_pos = 0
+
+#define GRUB_VIDEO_MI_RGB888(x) \
+ x.mode_type = GRUB_VIDEO_MODE_TYPE_RGB, \
+ x.bpp = 24, \
+ x.bytes_per_pixel = 3, \
+ x.number_of_colors = 256, \
+ x.red_mask_size = 8, \
+ x.red_field_pos = 16, \
+ x.green_mask_size = 8, \
+ x.green_field_pos = 8, \
+ x.blue_mask_size = 8, \
+ x.blue_field_pos = 0
+
+#define GRUB_VIDEO_MI_RGBA8888(x) \
+ x.mode_type = GRUB_VIDEO_MODE_TYPE_RGB, \
+ x.bpp = 32, \
+ x.bytes_per_pixel = 4, \
+ x.number_of_colors = 256, \
+ x.reserved_mask_size = 8, \
+ x.reserved_field_pos = 24, \
+ x.red_mask_size = 8, \
+ x.red_field_pos = 16, \
+ x.green_mask_size = 8, \
+ x.green_field_pos = 8, \
+ x.blue_mask_size = 8, \
+ x.blue_field_pos = 0
+
+
+#define GRUB_VIDEO_MI_BGR555(x) \
+ x.mode_type = GRUB_VIDEO_MODE_TYPE_RGB, \
+ x.bpp = 15, \
+ x.bytes_per_pixel = 2, \
+ x.number_of_colors = 256, \
+ x.red_mask_size = 5, \
+ x.red_field_pos = 0, \
+ x.green_mask_size = 5, \
+ x.green_field_pos = 5, \
+ x.blue_mask_size = 5, \
+ x.blue_field_pos = 10
+
+#define GRUB_VIDEO_MI_BGR565(x) \
+ x.mode_type = GRUB_VIDEO_MODE_TYPE_RGB, \
+ x.bpp = 16, \
+ x.bytes_per_pixel = 2, \
+ x.number_of_colors = 256, \
+ x.red_mask_size = 5, \
+ x.red_field_pos = 0, \
+ x.green_mask_size = 6, \
+ x.green_field_pos = 5, \
+ x.blue_mask_size = 5, \
+ x.blue_field_pos = 11
+
+#define GRUB_VIDEO_MI_BGR888(x) \
+ x.mode_type = GRUB_VIDEO_MODE_TYPE_RGB, \
+ x.bpp = 24, \
+ x.bytes_per_pixel = 3, \
+ x.number_of_colors = 256, \
+ x.red_mask_size = 8, \
+ x.red_field_pos = 0, \
+ x.green_mask_size = 8, \
+ x.green_field_pos = 8, \
+ x.blue_mask_size = 8, \
+ x.blue_field_pos = 16
+
+#define GRUB_VIDEO_MI_BGRA8888(x) \
+ x.mode_type = GRUB_VIDEO_MODE_TYPE_RGB, \
+ x.bpp = 32, \
+ x.bytes_per_pixel = 4, \
+ x.number_of_colors = 256, \
+ x.reserved_mask_size = 8, \
+ x.reserved_field_pos = 24, \
+ x.red_mask_size = 8, \
+ x.red_field_pos = 0, \
+ x.green_mask_size = 8, \
+ x.green_field_pos = 8, \
+ x.blue_mask_size = 8, \
+ x.blue_field_pos = 16
+
+#endif /* ! GRUB_VIDEO_HEADER */
diff --git a/include/grub/video_fb.h b/include/grub/video_fb.h
new file mode 100644
index 0000000..4a64fb8
--- /dev/null
+++ b/include/grub/video_fb.h
@@ -0,0 +1,151 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2005,2006,2007,2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_VIDEO_FB_HEADER
+#define GRUB_VIDEO_FB_HEADER 1
+
+#include <grub/symbol.h>
+#include <grub/types.h>
+#include <grub/err.h>
+#include <grub/video.h>
+
+/* FB module internal prototype (should not be used from elsewhere). */
+
+struct grub_video_fbblit_info;
+
+struct grub_video_fbrender_target;
+
+#define GRUB_VIDEO_FBSTD_NUMCOLORS 16
+#define GRUB_VIDEO_FBSTD_EXT_NUMCOLORS 256
+
+extern struct grub_video_palette_data EXPORT_VAR(grub_video_fbstd_colors)[GRUB_VIDEO_FBSTD_EXT_NUMCOLORS];
+
+grub_err_t
+EXPORT_FUNC(grub_video_fb_init) (void);
+
+grub_err_t
+EXPORT_FUNC(grub_video_fb_fini) (void);
+
+grub_err_t
+EXPORT_FUNC(grub_video_fb_get_info) (struct grub_video_mode_info *mode_info);
+
+grub_err_t
+EXPORT_FUNC(grub_video_fb_get_palette) (unsigned int start, unsigned int count,
+ struct grub_video_palette_data *palette_data);
+grub_err_t
+EXPORT_FUNC(grub_video_fb_set_palette) (unsigned int start, unsigned int count,
+ struct grub_video_palette_data *palette_data);
+grub_err_t
+EXPORT_FUNC(grub_video_fb_set_viewport) (unsigned int x, unsigned int y,
+ unsigned int width, unsigned int height);
+grub_err_t
+EXPORT_FUNC(grub_video_fb_get_viewport) (unsigned int *x, unsigned int *y,
+ unsigned int *width,
+ unsigned int *height);
+
+grub_err_t
+EXPORT_FUNC(grub_video_fb_set_region) (unsigned int x, unsigned int y,
+ unsigned int width, unsigned int height);
+grub_err_t
+EXPORT_FUNC(grub_video_fb_get_region) (unsigned int *x, unsigned int *y,
+ unsigned int *width,
+ unsigned int *height);
+
+grub_err_t
+EXPORT_FUNC(grub_video_fb_set_area_status)
+ (grub_video_area_status_t area_status);
+
+grub_err_t
+EXPORT_FUNC(grub_video_fb_get_area_status)
+ (grub_video_area_status_t *area_status);
+
+grub_video_color_t
+EXPORT_FUNC(grub_video_fb_map_color) (grub_uint32_t color_name);
+
+grub_video_color_t
+EXPORT_FUNC(grub_video_fb_map_rgb) (grub_uint8_t red, grub_uint8_t green,
+ grub_uint8_t blue);
+
+grub_video_color_t
+EXPORT_FUNC(grub_video_fb_map_rgba) (grub_uint8_t red, grub_uint8_t green,
+ grub_uint8_t blue, grub_uint8_t alpha);
+
+grub_err_t
+EXPORT_FUNC(grub_video_fb_unmap_color) (grub_video_color_t color,
+ grub_uint8_t *red, grub_uint8_t *green,
+ grub_uint8_t *blue, grub_uint8_t *alpha);
+
+void
+grub_video_fb_unmap_color_int (struct grub_video_fbblit_info * source,
+ grub_video_color_t color,
+ grub_uint8_t *red, grub_uint8_t *green,
+ grub_uint8_t *blue, grub_uint8_t *alpha);
+
+grub_err_t
+EXPORT_FUNC(grub_video_fb_fill_rect) (grub_video_color_t color, int x, int y,
+ unsigned int width, unsigned int height);
+
+grub_err_t
+EXPORT_FUNC(grub_video_fb_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);
+
+grub_err_t
+EXPORT_FUNC(grub_video_fb_blit_render_target) (struct grub_video_fbrender_target *source,
+ enum grub_video_blit_operators oper,
+ int x, int y, int offset_x, int offset_y,
+ unsigned int width, unsigned int height);
+
+grub_err_t
+EXPORT_FUNC(grub_video_fb_scroll) (grub_video_color_t color, int dx, int dy);
+
+grub_err_t
+EXPORT_FUNC(grub_video_fb_create_render_target) (struct grub_video_fbrender_target **result,
+ unsigned int width, unsigned int height,
+ unsigned int mode_type __attribute__ ((unused)));
+
+grub_err_t
+EXPORT_FUNC(grub_video_fb_create_render_target_from_pointer) (struct grub_video_fbrender_target **result,
+ const struct grub_video_mode_info *mode_info,
+ void *ptr);
+
+grub_err_t
+EXPORT_FUNC(grub_video_fb_delete_render_target) (struct grub_video_fbrender_target *target);
+
+grub_err_t
+EXPORT_FUNC(grub_video_fb_get_active_render_target) (struct grub_video_fbrender_target **target);
+
+grub_err_t
+EXPORT_FUNC(grub_video_fb_set_active_render_target) (struct grub_video_fbrender_target *target);
+
+typedef grub_err_t (*grub_video_fb_set_page_t) (int page);
+
+grub_err_t
+EXPORT_FUNC (grub_video_fb_setup) (unsigned int mode_type, unsigned int mode_mask,
+ struct grub_video_mode_info *mode_info,
+ volatile void *page0_ptr,
+ grub_video_fb_set_page_t set_page_in,
+ volatile void *page1_ptr);
+grub_err_t
+EXPORT_FUNC (grub_video_fb_swap_buffers) (void);
+grub_err_t
+EXPORT_FUNC (grub_video_fb_get_info_and_fini) (struct grub_video_mode_info *mode_info,
+ void **framebuf);
+
+#endif /* ! GRUB_VIDEO_FB_HEADER */
diff --git a/include/grub/x86_64/at_keyboard.h b/include/grub/x86_64/at_keyboard.h
new file mode 100644
index 0000000..c632aa8
--- /dev/null
+++ b/include/grub/x86_64/at_keyboard.h
@@ -0,0 +1 @@
+#include <grub/i386/at_keyboard.h>
diff --git a/include/grub/x86_64/efi/boot.h b/include/grub/x86_64/efi/boot.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/include/grub/x86_64/efi/boot.h
diff --git a/include/grub/x86_64/efi/kernel.h b/include/grub/x86_64/efi/kernel.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/include/grub/x86_64/efi/kernel.h
diff --git a/include/grub/x86_64/efi/loader.h b/include/grub/x86_64/efi/loader.h
new file mode 100644
index 0000000..7c302e8
--- /dev/null
+++ b/include/grub/x86_64/efi/loader.h
@@ -0,0 +1,26 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002,2003,2004,2006,2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_LOADER_MACHINE_HEADER
+#define GRUB_LOADER_MACHINE_HEADER 1
+
+#include <grub/types.h>
+#include <grub/symbol.h>
+
+
+#endif /* ! GRUB_LOADER_MACHINE_HEADER */
diff --git a/include/grub/x86_64/efi/memory.h b/include/grub/x86_64/efi/memory.h
new file mode 100644
index 0000000..46e9145
--- /dev/null
+++ b/include/grub/x86_64/efi/memory.h
@@ -0,0 +1,10 @@
+#ifndef GRUB_MEMORY_CPU_HEADER
+#include <grub/efi/memory.h>
+
+#if defined (__code_model_large__)
+#define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffff
+#else
+#define GRUB_EFI_MAX_USABLE_ADDRESS 0x7fffffff
+#endif
+
+#endif /* ! GRUB_MEMORY_CPU_HEADER */
diff --git a/include/grub/x86_64/efi/serial.h b/include/grub/x86_64/efi/serial.h
new file mode 100644
index 0000000..2d85634
--- /dev/null
+++ b/include/grub/x86_64/efi/serial.h
@@ -0,0 +1 @@
+#include <grub/i386/coreboot/serial.h>
diff --git a/include/grub/x86_64/io.h b/include/grub/x86_64/io.h
new file mode 100644
index 0000000..9f465bc
--- /dev/null
+++ b/include/grub/x86_64/io.h
@@ -0,0 +1,19 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/i386/io.h>
diff --git a/include/grub/x86_64/linux.h b/include/grub/x86_64/linux.h
new file mode 100644
index 0000000..19ea936
--- /dev/null
+++ b/include/grub/x86_64/linux.h
@@ -0,0 +1,19 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/i386/linux.h>
diff --git a/include/grub/x86_64/macho.h b/include/grub/x86_64/macho.h
new file mode 100644
index 0000000..165b8da
--- /dev/null
+++ b/include/grub/x86_64/macho.h
@@ -0,0 +1 @@
+#include <grub/i386/macho.h>
diff --git a/include/grub/x86_64/memory.h b/include/grub/x86_64/memory.h
new file mode 100644
index 0000000..27fcd25
--- /dev/null
+++ b/include/grub/x86_64/memory.h
@@ -0,0 +1 @@
+#include <grub/i386/memory.h>
diff --git a/include/grub/x86_64/multiboot.h b/include/grub/x86_64/multiboot.h
new file mode 100644
index 0000000..957c7a5
--- /dev/null
+++ b/include/grub/x86_64/multiboot.h
@@ -0,0 +1 @@
+#include <grub/i386/multiboot.h>
diff --git a/include/grub/x86_64/pci.h b/include/grub/x86_64/pci.h
new file mode 100644
index 0000000..91a9924
--- /dev/null
+++ b/include/grub/x86_64/pci.h
@@ -0,0 +1,19 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/i386/pci.h>
diff --git a/include/grub/x86_64/relocator.h b/include/grub/x86_64/relocator.h
new file mode 100644
index 0000000..247e7a1
--- /dev/null
+++ b/include/grub/x86_64/relocator.h
@@ -0,0 +1 @@
+#include <grub/i386/relocator.h>
diff --git a/include/grub/x86_64/setjmp.h b/include/grub/x86_64/setjmp.h
new file mode 100644
index 0000000..6df8a12
--- /dev/null
+++ b/include/grub/x86_64/setjmp.h
@@ -0,0 +1,27 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2003,2006,2007,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_SETJMP_CPU_HEADER
+#define GRUB_SETJMP_CPU_HEADER 1
+
+typedef unsigned long grub_jmp_buf[8];
+
+int grub_setjmp (grub_jmp_buf env) RETURNS_TWICE GRUB_ASM_ATTR;
+void grub_longjmp (grub_jmp_buf env, int val) __attribute__ ((noreturn)) GRUB_ASM_ATTR;
+
+#endif /* ! GRUB_SETJMP_CPU_HEADER */
diff --git a/include/grub/x86_64/time.h b/include/grub/x86_64/time.h
new file mode 100644
index 0000000..4da5ae9
--- /dev/null
+++ b/include/grub/x86_64/time.h
@@ -0,0 +1,29 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2007 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef KERNEL_CPU_TIME_HEADER
+#define KERNEL_CPU_TIME_HEADER 1
+
+static __inline void
+grub_cpu_idle (void)
+{
+ /* FIXME: this can't work until we handle interrupts. */
+/* asm volatile ("hlt"); */
+}
+
+#endif /* ! KERNEL_CPU_TIME_HEADER */
diff --git a/include/grub/x86_64/types.h b/include/grub/x86_64/types.h
new file mode 100644
index 0000000..0bbdc6d
--- /dev/null
+++ b/include/grub/x86_64/types.h
@@ -0,0 +1,41 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_TYPES_CPU_HEADER
+#define GRUB_TYPES_CPU_HEADER 1
+
+/* The size of void *. */
+#ifdef __ILP32__
+#define GRUB_TARGET_SIZEOF_VOID_P 4
+#else
+#define GRUB_TARGET_SIZEOF_VOID_P 8
+#endif
+
+/* The size of long. */
+#if defined(__MINGW32__) || defined(__ILP32__)
+#define GRUB_TARGET_SIZEOF_LONG 4
+#else
+#define GRUB_TARGET_SIZEOF_LONG 8
+#endif
+
+/* x86_64 is little-endian. */
+#undef GRUB_TARGET_WORDS_BIGENDIAN
+
+#define GRUB_HAVE_UNALIGNED_ACCESS 1
+
+#endif /* ! GRUB_TYPES_CPU_HEADER */
diff --git a/include/grub/x86_64/xen/hypercall.h b/include/grub/x86_64/xen/hypercall.h
new file mode 100644
index 0000000..90dd900
--- /dev/null
+++ b/include/grub/x86_64/xen/hypercall.h
@@ -0,0 +1,36 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_XEN_CPU_HYPERCALL_HEADER
+#define GRUB_XEN_CPU_HYPERCALL_HEADER 1
+
+#include <grub/misc.h>
+
+int EXPORT_FUNC (grub_xen_sched_op) (int cmd, void *arg) GRUB_ASM_ATTR;
+int grub_xen_update_va_mapping (void *addr, uint64_t pte, uint64_t flags) GRUB_ASM_ATTR;
+int EXPORT_FUNC (grub_xen_event_channel_op) (int op, void *arg) GRUB_ASM_ATTR;
+
+int grub_xen_mmuext_op (mmuext_op_t * ops,
+ unsigned int count,
+ unsigned int *pdone, unsigned int foreigndom) GRUB_ASM_ATTR;
+int EXPORT_FUNC (grub_xen_mmu_update) (const struct mmu_update * reqs,
+ unsigned count, unsigned *done_out,
+ unsigned foreigndom) GRUB_ASM_ATTR;
+int EXPORT_FUNC (grub_xen_grant_table_op) (int, void *, int) GRUB_ASM_ATTR;
+
+#endif
diff --git a/include/grub/x86_64/xnu.h b/include/grub/x86_64/xnu.h
new file mode 100644
index 0000000..ae61733
--- /dev/null
+++ b/include/grub/x86_64/xnu.h
@@ -0,0 +1 @@
+#include <grub/i386/xnu.h>
diff --git a/include/grub/xen.h b/include/grub/xen.h
new file mode 100644
index 0000000..91cb7cf
--- /dev/null
+++ b/include/grub/xen.h
@@ -0,0 +1,105 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_XEN_HEADER
+#define GRUB_XEN_HEADER 1
+
+#define __XEN_INTERFACE_VERSION__ 0x0003020a
+
+#define memset grub_memset
+
+#ifdef ASM_FILE
+#define __ASSEMBLY__
+#include <xen/xen.h>
+#else
+
+#include <grub/symbol.h>
+#include <grub/types.h>
+#include <grub/err.h>
+
+#ifndef GRUB_SYMBOL_GENERATOR
+typedef grub_int8_t int8_t;
+typedef grub_int16_t int16_t;
+typedef grub_uint8_t uint8_t;
+typedef grub_uint16_t uint16_t;
+typedef grub_uint32_t uint32_t;
+typedef grub_uint64_t uint64_t;
+#include <xen/xen.h>
+
+#include <xen/sched.h>
+#include <xen/grant_table.h>
+#include <xen/io/console.h>
+#include <xen/io/xs_wire.h>
+#include <xen/io/xenbus.h>
+#include <xen/io/protocols.h>
+#endif
+
+#include <grub/cpu/xen/hypercall.h>
+
+extern grub_size_t EXPORT_VAR (grub_xen_n_allocated_shared_pages);
+
+
+#define GRUB_XEN_LOG_PAGE_SIZE 12
+#define GRUB_XEN_PAGE_SIZE (1 << GRUB_XEN_LOG_PAGE_SIZE)
+
+extern volatile struct xencons_interface *grub_xen_xcons;
+extern volatile struct shared_info *EXPORT_VAR (grub_xen_shared_info);
+extern volatile struct xenstore_domain_interface *grub_xen_xenstore;
+extern volatile grant_entry_v1_t *grub_xen_grant_table;
+
+void EXPORT_FUNC (grub_xen_store_send) (const void *buf_, grub_size_t len);
+void EXPORT_FUNC (grub_xen_store_recv) (void *buf_, grub_size_t len);
+grub_err_t
+EXPORT_FUNC (grub_xenstore_dir) (const char *dir,
+ int (*hook) (const char *dir,
+ void *hook_data),
+ void *hook_data);
+void *EXPORT_FUNC (grub_xenstore_get_file) (const char *dir,
+ grub_size_t * len);
+grub_err_t EXPORT_FUNC (grub_xenstore_write_file) (const char *dir,
+ const void *buf,
+ grub_size_t len);
+
+typedef unsigned int grub_xen_grant_t;
+
+void *EXPORT_FUNC (grub_xen_alloc_shared_page) (domid_t dom,
+ grub_xen_grant_t * grnum);
+void EXPORT_FUNC (grub_xen_free_shared_page) (void *ptr);
+
+#define mb() asm volatile("mfence;sfence;" : : : "memory");
+extern struct start_info *EXPORT_VAR (grub_xen_start_page_addr);
+
+void grub_console_init (void);
+
+void grub_xendisk_fini (void);
+void grub_xendisk_init (void);
+
+#ifdef __x86_64__
+typedef grub_uint64_t grub_xen_mfn_t;
+#else
+typedef grub_uint32_t grub_xen_mfn_t;
+#endif
+typedef unsigned int grub_xen_evtchn_t;
+
+#ifdef GRUB_MACHINE_XEN_PVH
+extern struct hvm_start_info *pvh_start_info;
+void grub_xen_setup_pvh (void);
+#endif
+#endif
+
+#endif
diff --git a/include/grub/xen/relocator.h b/include/grub/xen/relocator.h
new file mode 100644
index 0000000..35a0ad9
--- /dev/null
+++ b/include/grub/xen/relocator.h
@@ -0,0 +1,46 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_RELOCATOR_XEN_HEADER
+#define GRUB_RELOCATOR_XEN_HEADER 1
+
+#include <grub/types.h>
+#include <grub/err.h>
+#include <grub/relocator.h>
+
+#define XEN_MAX_MAPPINGS 3
+
+struct grub_relocator_xen_state
+{
+ grub_addr_t start_info;
+ grub_addr_t paging_start[XEN_MAX_MAPPINGS];
+ grub_addr_t paging_size[XEN_MAX_MAPPINGS];
+ grub_addr_t mfn_list;
+ grub_addr_t stack;
+ grub_addr_t entry_point;
+};
+
+grub_err_t
+grub_relocator_xen_boot (struct grub_relocator *rel,
+ struct grub_relocator_xen_state state,
+ grub_uint64_t remapper_pfn,
+ grub_addr_t remapper_virt,
+ grub_uint64_t trampoline_pfn,
+ grub_addr_t trampoline_virt);
+
+#endif
diff --git a/include/grub/xen_file.h b/include/grub/xen_file.h
new file mode 100644
index 0000000..6587999
--- /dev/null
+++ b/include/grub/xen_file.h
@@ -0,0 +1,57 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_XEN_FILE_HEADER
+#define GRUB_XEN_FILE_HEADER 1
+
+#include <grub/types.h>
+#include <grub/elf.h>
+#include <grub/elfload.h>
+
+grub_elf_t grub_xen_file (grub_file_t file);
+
+struct grub_xen_file_info
+{
+ grub_uint64_t kern_start, kern_end;
+ grub_uint64_t virt_base;
+ grub_uint64_t entry_point;
+ grub_uint64_t hypercall_page;
+ grub_uint64_t paddr_offset;
+ grub_uint64_t p2m_base;
+ int has_hypercall_page;
+ int has_note;
+ int has_xen_guest;
+ int has_p2m_base;
+ int extended_cr3;
+ int unmapped_initrd;
+ enum
+ {
+ GRUB_XEN_FILE_I386 = 1,
+ GRUB_XEN_FILE_I386_PAE = 2,
+ GRUB_XEN_FILE_I386_PAE_BIMODE = 3,
+ GRUB_XEN_FILE_X86_64 = 4
+ } arch;
+};
+
+grub_err_t
+grub_xen_get_info32 (grub_elf_t elf, struct grub_xen_file_info *xi);
+grub_err_t
+grub_xen_get_info64 (grub_elf_t elf, struct grub_xen_file_info *xi);
+grub_err_t grub_xen_get_info (grub_elf_t elf, struct grub_xen_file_info *xi);
+
+#endif
diff --git a/include/grub/xnu.h b/include/grub/xnu.h
new file mode 100644
index 0000000..b7a7f45
--- /dev/null
+++ b/include/grub/xnu.h
@@ -0,0 +1,119 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_XNU_H
+#define GRUB_XNU_H 1
+
+#include <grub/bitmap.h>
+
+/* Header of a hibernation image. */
+struct grub_xnu_hibernate_header
+{
+ /* Size of the image. Notice that file containing image is usually bigger. */
+ grub_uint64_t image_size;
+ grub_uint8_t unknown1[8];
+ /* Where to copy launchcode? */
+ grub_uint32_t launchcode_target_page;
+ /* How many pages of launchcode? */
+ grub_uint32_t launchcode_numpages;
+ /* Where to jump? */
+ grub_uint32_t entry_point;
+ /* %esp at start. */
+ grub_uint32_t stack;
+ grub_uint8_t unknown2[44];
+#define GRUB_XNU_HIBERNATE_MAGIC 0x73696d65
+ grub_uint32_t magic;
+ grub_uint8_t unknown3[28];
+ /* This value is non-zero if page is encrypted. Unsupported. */
+ grub_uint64_t encoffset;
+ grub_uint8_t unknown4[360];
+ /* The size of additional header used to locate image without parsing FS.
+ Used only to skip it.
+ */
+ grub_uint32_t extmapsize;
+} GRUB_PACKED;
+
+/* In-memory structure for temporary keeping device tree. */
+struct grub_xnu_devtree_key
+{
+ char *name;
+ int datasize; /* -1 for not leaves. */
+ union
+ {
+ struct grub_xnu_devtree_key *first_child;
+ void *data;
+ };
+ struct grub_xnu_devtree_key *next;
+};
+
+/* A structure used in memory-map values. */
+struct
+grub_xnu_extdesc
+{
+ grub_uint32_t addr;
+ grub_uint32_t size;
+} GRUB_PACKED;
+
+/* Header describing extension in the memory. */
+struct grub_xnu_extheader
+{
+ grub_uint32_t infoplistaddr;
+ grub_uint32_t infoplistsize;
+ grub_uint32_t binaryaddr;
+ grub_uint32_t binarysize;
+ grub_uint32_t nameaddr;
+ grub_uint32_t namesize;
+} GRUB_PACKED;
+
+struct grub_xnu_devtree_key *grub_xnu_create_key (struct grub_xnu_devtree_key **parent,
+ const char *name);
+
+extern struct grub_xnu_devtree_key *grub_xnu_devtree_root;
+
+void grub_xnu_free_devtree (struct grub_xnu_devtree_key *cur);
+
+grub_err_t grub_xnu_writetree_toheap (grub_addr_t *target, grub_size_t *size);
+struct grub_xnu_devtree_key *grub_xnu_create_value (struct grub_xnu_devtree_key **parent,
+ const char *name);
+
+void grub_xnu_lock (void);
+void grub_xnu_unlock (void);
+grub_err_t grub_xnu_resume (char *imagename);
+grub_err_t grub_xnu_boot_resume (void);
+struct grub_xnu_devtree_key *grub_xnu_find_key (struct grub_xnu_devtree_key *parent,
+ const char *name);
+grub_err_t grub_xnu_align_heap (int align);
+grub_err_t grub_xnu_scan_dir_for_kexts (char *dirname,
+ const char *osbundlerequired,
+ int maxrecursion);
+grub_err_t grub_xnu_load_kext_from_dir (char *dirname,
+ const char *osbundlerequired,
+ int maxrecursion);
+grub_err_t grub_xnu_heap_malloc (int size, void **src, grub_addr_t *target);
+grub_err_t grub_xnu_fill_devicetree (void);
+extern struct grub_relocator *grub_xnu_relocator;
+
+extern grub_size_t grub_xnu_heap_size;
+extern struct grub_video_bitmap *grub_xnu_bitmap;
+typedef enum {GRUB_XNU_BITMAP_CENTER, GRUB_XNU_BITMAP_STRETCH}
+ grub_xnu_bitmap_mode_t;
+extern grub_xnu_bitmap_mode_t grub_xnu_bitmap_mode;
+extern int grub_xnu_is_64bit;
+extern grub_addr_t grub_xnu_heap_target_start;
+extern int grub_xnu_darwin_version;
+#endif
diff --git a/include/grub/zfs/dmu.h b/include/grub/zfs/dmu.h
new file mode 100644
index 0000000..4ad616c
--- /dev/null
+++ b/include/grub/zfs/dmu.h
@@ -0,0 +1,164 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
+ *
+ * GRUB is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+/*
+ * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef _SYS_DMU_H
+#define _SYS_DMU_H
+#define B_FALSE 0
+#define B_TRUE 1
+
+#define DMU_OT_NEWTYPE 0x80
+#define DMU_OT_METADATA 0x40
+#define DMU_OT_BYTESWAP_MASK 0x3f
+
+#define DMU_OT(byteswap, metadata) \
+ (DMU_OT_NEWTYPE | \
+ ((metadata) ? DMU_OT_METADATA : 0) | \
+ ((byteswap) & DMU_OT_BYTESWAP_MASK))
+
+#define DMU_OT_IS_VALID(ot) (((ot) & DMU_OT_NEWTYPE) ? \
+ ((ot) & DMU_OT_BYTESWAP_MASK) < DMU_BSWAP_NUMFUNCS : \
+ (ot) < DMU_OT_NUMTYPES)
+
+#define DMU_OT_IS_METADATA(ot) (((ot) & DMU_OT_NEWTYPE) ? \
+ ((ot) & DMU_OT_METADATA) : \
+ dmu_ot[(ot)].ot_metadata)
+
+typedef enum dmu_object_byteswap {
+ DMU_BSWAP_UINT8,
+ DMU_BSWAP_UINT16,
+ DMU_BSWAP_UINT32,
+ DMU_BSWAP_UINT64,
+ DMU_BSWAP_ZAP,
+ DMU_BSWAP_DNODE,
+ DMU_BSWAP_OBJSET,
+ DMU_BSWAP_ZNODE,
+ DMU_BSWAP_OLDACL,
+ DMU_BSWAP_ACL,
+ DMU_BSWAP_NUMFUNCS
+} dmu_object_byteswap_t;
+
+/*
+ * This file describes the interface that the DMU provides for its
+ * consumers.
+ *
+ * The DMU also interacts with the SPA. That interface is described in
+ * dmu_spa.h.
+ */
+typedef enum dmu_object_type {
+ DMU_OT_NONE,
+ /* general: */
+ DMU_OT_OBJECT_DIRECTORY, /* ZAP */
+ DMU_OT_OBJECT_ARRAY, /* UINT64 */
+ DMU_OT_PACKED_NVLIST, /* UINT8 (XDR by nvlist_pack/unpack) */
+ DMU_OT_PACKED_NVLIST_SIZE, /* UINT64 */
+ DMU_OT_BPLIST, /* UINT64 */
+ DMU_OT_BPLIST_HDR, /* UINT64 */
+ /* spa: */
+ DMU_OT_SPACE_MAP_HEADER, /* UINT64 */
+ DMU_OT_SPACE_MAP, /* UINT64 */
+ /* zil: */
+ DMU_OT_INTENT_LOG, /* UINT64 */
+ /* dmu: */
+ DMU_OT_DNODE, /* DNODE */
+ DMU_OT_OBJSET, /* OBJSET */
+ /* dsl: */
+ DMU_OT_DSL_DIR, /* UINT64 */
+ DMU_OT_DSL_DIR_CHILD_MAP, /* ZAP */
+ DMU_OT_DSL_DS_SNAP_MAP, /* ZAP */
+ DMU_OT_DSL_PROPS, /* ZAP */
+ DMU_OT_DSL_DATASET, /* UINT64 */
+ /* zpl: */
+ DMU_OT_ZNODE, /* ZNODE */
+ DMU_OT_OLDACL, /* OLD ACL */
+ DMU_OT_PLAIN_FILE_CONTENTS, /* UINT8 */
+ DMU_OT_DIRECTORY_CONTENTS, /* ZAP */
+ DMU_OT_MASTER_NODE, /* ZAP */
+ DMU_OT_UNLINKED_SET, /* ZAP */
+ /* zvol: */
+ DMU_OT_ZVOL, /* UINT8 */
+ DMU_OT_ZVOL_PROP, /* ZAP */
+ /* other; for testing only! */
+ DMU_OT_PLAIN_OTHER, /* UINT8 */
+ DMU_OT_UINT64_OTHER, /* UINT64 */
+ DMU_OT_ZAP_OTHER, /* ZAP */
+ /* new object types: */
+ DMU_OT_ERROR_LOG, /* ZAP */
+ DMU_OT_SPA_HISTORY, /* UINT8 */
+ DMU_OT_SPA_HISTORY_OFFSETS, /* spa_his_phys_t */
+ DMU_OT_POOL_PROPS, /* ZAP */
+ DMU_OT_DSL_PERMS, /* ZAP */
+ DMU_OT_ACL, /* ACL */
+ DMU_OT_SYSACL, /* SYSACL */
+ DMU_OT_FUID, /* FUID table (Packed NVLIST UINT8) */
+ DMU_OT_FUID_SIZE, /* FUID table size UINT64 */
+ DMU_OT_NEXT_CLONES, /* ZAP */
+ DMU_OT_SCRUB_QUEUE, /* ZAP */
+ DMU_OT_USERGROUP_USED, /* ZAP */
+ DMU_OT_USERGROUP_QUOTA, /* ZAP */
+ DMU_OT_USERREFS, /* ZAP */
+ DMU_OT_DDT_ZAP, /* ZAP */
+ DMU_OT_DDT_STATS, /* ZAP */
+ DMU_OT_SA, /* System attr */
+ DMU_OT_SA_MASTER_NODE, /* ZAP */
+ DMU_OT_SA_ATTR_REGISTRATION, /* ZAP */
+ DMU_OT_SA_ATTR_LAYOUTS, /* ZAP */
+ DMU_OT_DSL_KEYCHAIN = 54,
+ DMU_OT_NUMTYPES,
+ DMU_OTN_UINT8_DATA = DMU_OT(DMU_BSWAP_UINT8, B_FALSE),
+ DMU_OTN_UINT8_METADATA = DMU_OT(DMU_BSWAP_UINT8, B_TRUE),
+ DMU_OTN_UINT16_DATA = DMU_OT(DMU_BSWAP_UINT16, B_FALSE),
+ DMU_OTN_UINT16_METADATA = DMU_OT(DMU_BSWAP_UINT16, B_TRUE),
+ DMU_OTN_UINT32_DATA = DMU_OT(DMU_BSWAP_UINT32, B_FALSE),
+ DMU_OTN_UINT32_METADATA = DMU_OT(DMU_BSWAP_UINT32, B_TRUE),
+ DMU_OTN_UINT64_DATA = DMU_OT(DMU_BSWAP_UINT64, B_FALSE),
+ DMU_OTN_UINT64_METADATA = DMU_OT(DMU_BSWAP_UINT64, B_TRUE),
+ DMU_OTN_ZAP_DATA = DMU_OT(DMU_BSWAP_ZAP, B_FALSE),
+ DMU_OTN_ZAP_METADATA = DMU_OT(DMU_BSWAP_ZAP, B_TRUE),
+} dmu_object_type_t;
+
+typedef enum dmu_objset_type {
+ DMU_OST_NONE,
+ DMU_OST_META,
+ DMU_OST_ZFS,
+ DMU_OST_ZVOL,
+ DMU_OST_OTHER, /* For testing only! */
+ DMU_OST_ANY, /* Be careful! */
+ DMU_OST_NUMTYPES
+} dmu_objset_type_t;
+
+/*
+ * The names of zap entries in the DIRECTORY_OBJECT of the MOS.
+ */
+#define DMU_POOL_DIRECTORY_OBJECT 1
+#define DMU_POOL_CONFIG "config"
+#define DMU_POOL_ROOT_DATASET "root_dataset"
+#define DMU_POOL_SYNC_BPLIST "sync_bplist"
+#define DMU_POOL_ERRLOG_SCRUB "errlog_scrub"
+#define DMU_POOL_ERRLOG_LAST "errlog_last"
+#define DMU_POOL_SPARES "spares"
+#define DMU_POOL_DEFLATE "deflate"
+#define DMU_POOL_HISTORY "history"
+#define DMU_POOL_PROPS "pool_props"
+#define DMU_POOL_L2CACHE "l2cache"
+#define DMU_POOL_FEATURES_FOR_READ "features_for_read"
+
+#endif /* _SYS_DMU_H */
diff --git a/include/grub/zfs/dmu_objset.h b/include/grub/zfs/dmu_objset.h
new file mode 100644
index 0000000..57d21db
--- /dev/null
+++ b/include/grub/zfs/dmu_objset.h
@@ -0,0 +1,43 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
+ * Copyright (C) 2010 Robert Millan <rmh@gnu.org>
+ *
+ * GRUB is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+/*
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef _SYS_DMU_OBJSET_H
+#define _SYS_DMU_OBJSET_H
+
+#include <grub/zfs/zil.h>
+
+#define OBJSET_PHYS_SIZE 2048
+#define OBJSET_PHYS_SIZE_V14 1024
+
+typedef struct objset_phys {
+ dnode_phys_t os_meta_dnode;
+ zil_header_t os_zil_header;
+ grub_uint64_t os_type;
+ grub_uint64_t os_flags;
+ char os_pad[OBJSET_PHYS_SIZE - sizeof (dnode_phys_t)*3 -
+ sizeof (zil_header_t) - sizeof (grub_uint64_t)*2];
+ dnode_phys_t os_userused_dnode;
+ dnode_phys_t os_groupused_dnode;
+} objset_phys_t;
+
+#endif /* _SYS_DMU_OBJSET_H */
diff --git a/include/grub/zfs/dnode.h b/include/grub/zfs/dnode.h
new file mode 100644
index 0000000..e4993df
--- /dev/null
+++ b/include/grub/zfs/dnode.h
@@ -0,0 +1,74 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
+ *
+ * GRUB is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+/*
+ * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef _SYS_DNODE_H
+#define _SYS_DNODE_H
+
+#include <grub/zfs/spa.h>
+
+/*
+ * Fixed constants.
+ */
+#define DNODE_SHIFT 9 /* 512 bytes */
+#define DNODE_BLOCK_SHIFT 14 /* 16k */
+#define DNODE_CORE_SIZE 64 /* 64 bytes for dnode sans blkptrs */
+
+/*
+ * Derived constants.
+ */
+#define DNODE_SIZE (1 << DNODE_SHIFT)
+#define DN_MAX_NBLKPTR ((DNODE_SIZE - DNODE_CORE_SIZE) >> SPA_BLKPTRSHIFT)
+#define DN_MAX_BONUSLEN (DNODE_SIZE - DNODE_CORE_SIZE - (1 << SPA_BLKPTRSHIFT))
+
+#define DNODES_PER_BLOCK_SHIFT (DNODE_BLOCK_SHIFT - DNODE_SHIFT)
+#define DNODES_PER_BLOCK (1ULL << DNODES_PER_BLOCK_SHIFT)
+
+#define DNODE_FLAG_SPILL_BLKPTR (1<<2)
+
+#define DN_BONUS(dnp) ((void*)((dnp)->dn_bonus + \
+ (((dnp)->dn_nblkptr - 1) * sizeof (blkptr_t))))
+
+typedef struct dnode_phys {
+ grub_uint8_t dn_type; /* dmu_object_type_t */
+ grub_uint8_t dn_indblkshift; /* ln2(indirect block size) */
+ grub_uint8_t dn_nlevels; /* 1=dn_blkptr->data blocks */
+ grub_uint8_t dn_nblkptr; /* length of dn_blkptr */
+ grub_uint8_t dn_bonustype; /* type of data in bonus buffer */
+ grub_uint8_t dn_checksum; /* ZIO_CHECKSUM type */
+ grub_uint8_t dn_compress; /* ZIO_COMPRESS type */
+ grub_uint8_t dn_flags; /* DNODE_FLAG_* */
+ grub_uint16_t dn_datablkszsec; /* data block size in 512b sectors */
+ grub_uint16_t dn_bonuslen; /* length of dn_bonus */
+ grub_uint8_t dn_pad2[4];
+
+ /* accounting is protected by dn_dirty_mtx */
+ grub_uint64_t dn_maxblkid; /* largest allocated block ID */
+ grub_uint64_t dn_used; /* bytes (or sectors) of disk space */
+
+ grub_uint64_t dn_pad3[4];
+
+ blkptr_t dn_blkptr[1];
+ grub_uint8_t dn_bonus[DN_MAX_BONUSLEN - sizeof (blkptr_t)];
+ blkptr_t dn_spill;
+} dnode_phys_t;
+
+#endif /* _SYS_DNODE_H */
diff --git a/include/grub/zfs/dsl_dataset.h b/include/grub/zfs/dsl_dataset.h
new file mode 100644
index 0000000..c17bf80
--- /dev/null
+++ b/include/grub/zfs/dsl_dataset.h
@@ -0,0 +1,52 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
+ *
+ * GRUB is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef _SYS_DSL_DATASET_H
+#define _SYS_DSL_DATASET_H
+
+typedef struct dsl_dataset_phys {
+ grub_uint64_t ds_dir_obj;
+ grub_uint64_t ds_prev_snap_obj;
+ grub_uint64_t ds_prev_snap_txg;
+ grub_uint64_t ds_next_snap_obj;
+ grub_uint64_t ds_snapnames_zapobj; /* zap obj of snaps; ==0 for snaps */
+ grub_uint64_t ds_num_children; /* clone/snap children; ==0 for head */
+ grub_uint64_t ds_creation_time; /* seconds since 1970 */
+ grub_uint64_t ds_creation_txg;
+ grub_uint64_t ds_deadlist_obj;
+ grub_uint64_t ds_used_bytes;
+ grub_uint64_t ds_compressed_bytes;
+ grub_uint64_t ds_uncompressed_bytes;
+ grub_uint64_t ds_unique_bytes; /* only relevant to snapshots */
+ /*
+ * The ds_fsid_guid is a 56-bit ID that can change to avoid
+ * collisions. The ds_guid is a 64-bit ID that will never
+ * change, so there is a small probability that it will collide.
+ */
+ grub_uint64_t ds_fsid_guid;
+ grub_uint64_t ds_guid;
+ grub_uint64_t ds_flags;
+ blkptr_t ds_bp;
+ grub_uint64_t ds_pad[8]; /* pad out to 320 bytes for good measure */
+} dsl_dataset_phys_t;
+
+#endif /* _SYS_DSL_DATASET_H */
diff --git a/include/grub/zfs/dsl_dir.h b/include/grub/zfs/dsl_dir.h
new file mode 100644
index 0000000..6542a77
--- /dev/null
+++ b/include/grub/zfs/dsl_dir.h
@@ -0,0 +1,50 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
+ *
+ * GRUB is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef _SYS_DSL_DIR_H
+#define _SYS_DSL_DIR_H
+
+typedef struct dsl_dir_phys {
+ grub_uint64_t dd_creation_time; /* not actually used */
+ grub_uint64_t dd_head_dataset_obj;
+ grub_uint64_t dd_parent_obj;
+ grub_uint64_t dd_clone_parent_obj;
+ grub_uint64_t dd_child_dir_zapobj;
+ /*
+ * how much space our children are accounting for; for leaf
+ * datasets, == physical space used by fs + snaps
+ */
+ grub_uint64_t dd_used_bytes;
+ grub_uint64_t dd_compressed_bytes;
+ grub_uint64_t dd_uncompressed_bytes;
+ /* Administrative quota setting */
+ grub_uint64_t dd_quota;
+ /* Administrative reservation setting */
+ grub_uint64_t dd_reserved;
+ grub_uint64_t dd_props_zapobj;
+ grub_uint64_t dd_deleg_zapobj; /* dataset permissions */
+ grub_uint64_t unused[7];
+ grub_uint64_t keychain;
+ grub_uint64_t unused2[12];
+} dsl_dir_phys_t;
+
+#endif /* _SYS_DSL_DIR_H */
diff --git a/include/grub/zfs/sa_impl.h b/include/grub/zfs/sa_impl.h
new file mode 100644
index 0000000..0845d12
--- /dev/null
+++ b/include/grub/zfs/sa_impl.h
@@ -0,0 +1,37 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
+ *
+ * GRUB is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+/*
+ * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+#ifndef _SYS_SA_IMPL_H
+#define _SYS_SA_IMPL_H
+
+typedef struct sa_hdr_phys {
+ grub_uint32_t sa_magic;
+ grub_uint16_t sa_layout_info;
+ grub_uint16_t sa_lengths[1];
+} sa_hdr_phys_t;
+
+#define SA_HDR_SIZE(hdr) BF32_GET_SB(hdr->sa_layout_info, 10, 16, 3, 0)
+#define SA_TYPE_OFFSET 0x0
+#define SA_SIZE_OFFSET 0x8
+#define SA_MTIME_OFFSET 0x38
+#define SA_SYMLINK_OFFSET 0xa0
+
+#endif /* _SYS_SA_IMPL_H */
diff --git a/include/grub/zfs/spa.h b/include/grub/zfs/spa.h
new file mode 100644
index 0000000..8dd1fa8
--- /dev/null
+++ b/include/grub/zfs/spa.h
@@ -0,0 +1,328 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 1999,2000,2001,2002,2003,2004,2009 Free Software Foundation, Inc.
+ * Copyright 2010 Sun Microsystems, Inc.
+ *
+ * GRUB is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_ZFS_SPA_HEADER
+#define GRUB_ZFS_SPA_HEADER 1
+
+#define grub_zfs_to_cpu16(x,a) (((a) == GRUB_ZFS_BIG_ENDIAN) ? \
+ grub_be_to_cpu16(x) \
+ : grub_le_to_cpu16(x))
+#define grub_cpu_to_zfs16(x,a) (((a) == GRUB_ZFS_BIG_ENDIAN) ? \
+ grub_cpu_to_be16(x) \
+ : grub_cpu_to_le16(x))
+
+#define grub_zfs_to_cpu32(x,a) (((a) == GRUB_ZFS_BIG_ENDIAN) ? \
+ grub_be_to_cpu32(x) \
+ : grub_le_to_cpu32(x))
+#define grub_cpu_to_zfs32(x,a) (((a) == GRUB_ZFS_BIG_ENDIAN) ? \
+ grub_cpu_to_be32(x) \
+ : grub_cpu_to_le32(x))
+
+#define grub_zfs_to_cpu64(x,a) (((a) == GRUB_ZFS_BIG_ENDIAN) \
+ ? grub_be_to_cpu64(x) \
+ : grub_le_to_cpu64(x))
+#define grub_cpu_to_zfs64(x,a) (((a) == GRUB_ZFS_BIG_ENDIAN) ? grub_cpu_to_be64(x) \
+ : grub_cpu_to_le64(x))
+
+/*
+ * General-purpose 32-bit and 64-bit bitfield encodings.
+ */
+#define BF32_DECODE(x, low, len) P2PHASE((x) >> (low), 1U << (len))
+#define BF64_DECODE(x, low, len) P2PHASE((x) >> (low), 1ULL << (len))
+#define BF32_ENCODE(x, low, len) (P2PHASE((x), 1U << (len)) << (low))
+#define BF64_ENCODE(x, low, len) (P2PHASE((x), 1ULL << (len)) << (low))
+
+#define BF32_GET(x, low, len) BF32_DECODE(x, low, len)
+#define BF64_GET(x, low, len) BF64_DECODE(x, low, len)
+
+#define BF32_SET(x, low, len, val) \
+ ((x) ^= BF32_ENCODE((x >> low) ^ (val), low, len))
+#define BF64_SET(x, low, len, val) \
+ ((x) ^= BF64_ENCODE((x >> low) ^ (val), low, len))
+
+#define BF32_GET_SB(x, low, len, shift, bias) \
+ ((BF32_GET(x, low, len) + (bias)) << (shift))
+#define BF64_GET_SB(x, low, len, shift, bias) \
+ ((BF64_GET(x, low, len) + (bias)) << (shift))
+
+#define BF32_SET_SB(x, low, len, shift, bias, val) \
+ BF32_SET(x, low, len, ((val) >> (shift)) - (bias))
+#define BF64_SET_SB(x, low, len, shift, bias, val) \
+ BF64_SET(x, low, len, ((val) >> (shift)) - (bias))
+
+#define SPA_MINBLOCKSHIFT 9
+#define SPA_MINBLOCKSIZE (1ULL << SPA_MINBLOCKSHIFT)
+
+/*
+ * Size of block to hold the configuration data (a packed nvlist)
+ */
+#define SPA_CONFIG_BLOCKSIZE (1 << 14)
+
+/*
+ * The DVA size encodings for LSIZE and PSIZE support blocks up to 32MB.
+ * The ASIZE encoding should be at least 64 times larger (6 more bits)
+ * to support up to 4-way RAID-Z mirror mode with worst-case gang block
+ * overhead, three DVAs per bp, plus one more bit in case we do anything
+ * else that expands the ASIZE.
+ */
+#define SPA_LSIZEBITS 16 /* LSIZE up to 32M (2^16 * 512) */
+#define SPA_PSIZEBITS 16 /* PSIZE up to 32M (2^16 * 512) */
+#define SPA_ASIZEBITS 24 /* ASIZE up to 64 times larger */
+
+/*
+ * All SPA data is represented by 128-bit data virtual addresses (DVAs).
+ * The members of the dva_t should be considered opaque outside the SPA.
+ */
+typedef struct dva {
+ grub_uint64_t dva_word[2];
+} dva_t;
+
+/*
+ * Each block has a 256-bit checksum -- strong enough for cryptographic hashes.
+ */
+typedef struct zio_cksum {
+ union
+ {
+ grub_uint64_t zc_word[4];
+ struct
+ {
+ grub_uint32_t zc_cut_cksum[5];
+ grub_uint32_t zc_mac[3];
+ };
+ };
+} zio_cksum_t;
+
+/*
+ * Each block is described by its DVAs, time of birth, checksum, etc.
+ * The word-by-word, bit-by-bit layout of the blkptr is as follows:
+ *
+ * 64 56 48 40 32 24 16 8 0
+ * +-------+-------+-------+-------+-------+-------+-------+-------+
+ * 0 | vdev1 | GRID | ASIZE |
+ * +-------+-------+-------+-------+-------+-------+-------+-------+
+ * 1 |G| offset1 |
+ * +-------+-------+-------+-------+-------+-------+-------+-------+
+ * 2 | vdev2 | GRID | ASIZE |
+ * +-------+-------+-------+-------+-------+-------+-------+-------+
+ * 3 |G| offset2 |
+ * +-------+-------+-------+-------+-------+-------+-------+-------+
+ * 4 | vdev3 | GRID | ASIZE |
+ * +-------+-------+-------+-------+-------+-------+-------+-------+
+ * 5 |G| offset3 |
+ * +-------+-------+-------+-------+-------+-------+-------+-------+
+ * 6 |BDX|lvl| type | cksum |E| comp| PSIZE | LSIZE |
+ * +-------+-------+-------+-------+-------+-------+-------+-------+
+ * 7 | padding |
+ * +-------+-------+-------+-------+-------+-------+-------+-------+
+ * 8 | padding |
+ * +-------+-------+-------+-------+-------+-------+-------+-------+
+ * 9 | physical birth txg |
+ * +-------+-------+-------+-------+-------+-------+-------+-------+
+ * a | logical birth txg |
+ * +-------+-------+-------+-------+-------+-------+-------+-------+
+ * b | fill count |
+ * +-------+-------+-------+-------+-------+-------+-------+-------+
+ * c | checksum[0] |
+ * +-------+-------+-------+-------+-------+-------+-------+-------+
+ * d | checksum[1] |
+ * +-------+-------+-------+-------+-------+-------+-------+-------+
+ * e | checksum[2] |
+ * +-------+-------+-------+-------+-------+-------+-------+-------+
+ * f | checksum[3] |
+ * +-------+-------+-------+-------+-------+-------+-------+-------+
+ *
+ * Legend:
+ *
+ * vdev virtual device ID
+ * offset offset into virtual device
+ * LSIZE logical size
+ * PSIZE physical size (after compression)
+ * ASIZE allocated size (including RAID-Z parity and gang block headers)
+ * GRID RAID-Z layout information (reserved for future use)
+ * cksum checksum function
+ * comp compression function
+ * G gang block indicator
+ * B byteorder (endianness)
+ * D dedup
+ * X encryption
+ * E blkptr_t contains embedded data
+ * lvl level of indirection
+ * type DMU object type
+ * phys birth txg of block allocation; zero if same as logical birth txg
+ * log. birth transaction group in which the block was logically born
+ * fill count number of non-zero blocks under this bp
+ * checksum[4] 256-bit checksum of the data this bp describes
+ */
+#define SPA_BLKPTRSHIFT 7 /* blkptr_t is 128 bytes */
+#define SPA_DVAS_PER_BP 3 /* Number of DVAs in a bp */
+
+typedef struct blkptr {
+ dva_t blk_dva[SPA_DVAS_PER_BP]; /* Data Virtual Addresses */
+ grub_uint64_t blk_prop; /* size, compression, type, etc */
+ grub_uint64_t blk_pad[2]; /* Extra space for the future */
+ grub_uint64_t blk_phys_birth; /* txg when block was allocated */
+ grub_uint64_t blk_birth; /* transaction group at birth */
+ grub_uint64_t blk_fill; /* fill count */
+ zio_cksum_t blk_cksum; /* 256-bit checksum */
+} blkptr_t;
+
+/*
+ * Macros to get and set fields in a bp or DVA.
+ */
+#define DVA_GET_ASIZE(dva) \
+ BF64_GET_SB((dva)->dva_word[0], 0, 24, SPA_MINBLOCKSHIFT, 0)
+#define DVA_SET_ASIZE(dva, x) \
+ BF64_SET_SB((dva)->dva_word[0], 0, 24, SPA_MINBLOCKSHIFT, 0, x)
+
+#define DVA_GET_GRID(dva) BF64_GET((dva)->dva_word[0], 24, 8)
+#define DVA_SET_GRID(dva, x) BF64_SET((dva)->dva_word[0], 24, 8, x)
+
+#define DVA_GET_VDEV(dva) BF64_GET((dva)->dva_word[0], 32, 32)
+#define DVA_SET_VDEV(dva, x) BF64_SET((dva)->dva_word[0], 32, 32, x)
+
+#define DVA_GET_GANG(dva) BF64_GET((dva)->dva_word[1], 63, 1)
+#define DVA_SET_GANG(dva, x) BF64_SET((dva)->dva_word[1], 63, 1, x)
+
+#define BP_GET_LSIZE(bp) \
+ BF64_GET_SB((bp)->blk_prop, 0, 16, SPA_MINBLOCKSHIFT, 1)
+#define BP_SET_LSIZE(bp, x) \
+ BF64_SET_SB((bp)->blk_prop, 0, 16, SPA_MINBLOCKSHIFT, 1, x)
+
+#define BP_GET_COMPRESS(bp) BF64_GET((bp)->blk_prop, 32, 7)
+#define BP_SET_COMPRESS(bp, x) BF64_SET((bp)->blk_prop, 32, 7, x)
+
+#define BP_GET_CHECKSUM(bp) BF64_GET((bp)->blk_prop, 40, 8)
+#define BP_SET_CHECKSUM(bp, x) BF64_SET((bp)->blk_prop, 40, 8, x)
+
+#define BP_GET_TYPE(bp) BF64_GET((bp)->blk_prop, 48, 8)
+#define BP_SET_TYPE(bp, x) BF64_SET((bp)->blk_prop, 48, 8, x)
+
+#define BP_GET_LEVEL(bp) BF64_GET((bp)->blk_prop, 56, 5)
+#define BP_SET_LEVEL(bp, x) BF64_SET((bp)->blk_prop, 56, 5, x)
+
+#define BP_IS_EMBEDDED(bp) BF64_GET((bp)->blk_prop, 39, 1)
+
+#define BP_GET_PROP_BIT_61(bp) BF64_GET((bp)->blk_prop, 61, 1)
+#define BP_SET_PROP_BIT_61(bp, x) BF64_SET((bp)->blk_prop, 61, 1, x)
+
+#define BP_GET_DEDUP(bp) BF64_GET((bp)->blk_prop, 62, 1)
+#define BP_SET_DEDUP(bp, x) BF64_SET((bp)->blk_prop, 62, 1, x)
+
+#define BP_GET_BYTEORDER(bp) (0 - BF64_GET((bp)->blk_prop, 63, 1))
+#define BP_SET_BYTEORDER(bp, x) BF64_SET((bp)->blk_prop, 63, 1, x)
+
+#define BP_PHYSICAL_BIRTH(bp) \
+ ((bp)->blk_phys_birth ? (bp)->blk_phys_birth : (bp)->blk_birth)
+
+#define BP_SET_BIRTH(bp, logical, physical) \
+{ \
+ (bp)->blk_birth = (logical); \
+ (bp)->blk_phys_birth = ((logical) == (physical) ? 0 : (physical)); \
+}
+
+#define BP_GET_ASIZE(bp) \
+ (DVA_GET_ASIZE(&(bp)->blk_dva[0]) + DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \
+ DVA_GET_ASIZE(&(bp)->blk_dva[2]))
+
+#define BP_GET_UCSIZE(bp) \
+ ((BP_GET_LEVEL(bp) > 0 || dmu_ot[BP_GET_TYPE(bp)].ot_metadata) ? \
+ BP_GET_PSIZE(bp) : BP_GET_LSIZE(bp));
+
+#define BP_GET_NDVAS(bp) \
+ (!!DVA_GET_ASIZE(&(bp)->blk_dva[0]) + \
+ !!DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \
+ !!DVA_GET_ASIZE(&(bp)->blk_dva[2]))
+
+#define BP_COUNT_GANG(bp) \
+ (DVA_GET_GANG(&(bp)->blk_dva[0]) + \
+ DVA_GET_GANG(&(bp)->blk_dva[1]) + \
+ DVA_GET_GANG(&(bp)->blk_dva[2]))
+
+#define DVA_EQUAL(dva1, dva2) \
+ ((dva1)->dva_word[1] == (dva2)->dva_word[1] && \
+ (dva1)->dva_word[0] == (dva2)->dva_word[0])
+
+#define BP_EQUAL(bp1, bp2) \
+ (BP_PHYSICAL_BIRTH(bp1) == BP_PHYSICAL_BIRTH(bp2) && \
+ DVA_EQUAL(&(bp1)->blk_dva[0], &(bp2)->blk_dva[0]) && \
+ DVA_EQUAL(&(bp1)->blk_dva[1], &(bp2)->blk_dva[1]) && \
+ DVA_EQUAL(&(bp1)->blk_dva[2], &(bp2)->blk_dva[2]))
+
+#define ZIO_CHECKSUM_EQUAL(zc1, zc2) \
+ (0 == (((zc1).zc_word[0] - (zc2).zc_word[0]) | \
+ ((zc1).zc_word[1] - (zc2).zc_word[1]) | \
+ ((zc1).zc_word[2] - (zc2).zc_word[2]) | \
+ ((zc1).zc_word[3] - (zc2).zc_word[3])))
+
+#define DVA_IS_VALID(dva) (DVA_GET_ASIZE(dva) != 0)
+
+#define ZIO_SET_CHECKSUM(zcp, w0, w1, w2, w3) \
+{ \
+ (zcp)->zc_word[0] = w0; \
+ (zcp)->zc_word[1] = w1; \
+ (zcp)->zc_word[2] = w2; \
+ (zcp)->zc_word[3] = w3; \
+}
+
+#define BPE_GET_ETYPE(bp) BP_GET_CHECKSUM(bp)
+#define BPE_GET_LSIZE(bp) \
+ BF64_GET_SB((bp)->blk_prop, 0, 25, 0, 1)
+#define BPE_GET_PSIZE(bp) \
+ BF64_GET_SB((bp)->blk_prop, 25, 7, 0, 1)
+
+typedef enum bp_embedded_type {
+ BP_EMBEDDED_TYPE_DATA,
+ NUM_BP_EMBEDDED_TYPES
+} bp_embedded_type_t;
+
+#define BPE_NUM_WORDS 14
+#define BPE_PAYLOAD_SIZE (BPE_NUM_WORDS * sizeof(grub_uint64_t))
+#define BPE_IS_PAYLOADWORD(bp, wp) \
+ ((wp) != &(bp)->blk_prop && (wp) != &(bp)->blk_birth)
+
+#define BP_IDENTITY(bp) (&(bp)->blk_dva[0])
+#define BP_IS_GANG(bp) DVA_GET_GANG(BP_IDENTITY(bp))
+#define DVA_IS_EMPTY(dva) ((dva)->dva_word[0] == 0ULL && \
+ (dva)->dva_word[1] == 0ULL)
+#define BP_IS_HOLE(bp) DVA_IS_EMPTY(BP_IDENTITY(bp))
+
+/* BP_IS_RAIDZ(bp) assumes no block compression */
+#define BP_IS_RAIDZ(bp) (DVA_GET_ASIZE(&(bp)->blk_dva[0]) > \
+ BP_GET_PSIZE(bp))
+
+#define BP_ZERO(bp) \
+{ \
+ (bp)->blk_dva[0].dva_word[0] = 0; \
+ (bp)->blk_dva[0].dva_word[1] = 0; \
+ (bp)->blk_dva[1].dva_word[0] = 0; \
+ (bp)->blk_dva[1].dva_word[1] = 0; \
+ (bp)->blk_dva[2].dva_word[0] = 0; \
+ (bp)->blk_dva[2].dva_word[1] = 0; \
+ (bp)->blk_prop = 0; \
+ (bp)->blk_pad[0] = 0; \
+ (bp)->blk_pad[1] = 0; \
+ (bp)->blk_phys_birth = 0; \
+ (bp)->blk_birth = 0; \
+ (bp)->blk_fill = 0; \
+ ZIO_SET_CHECKSUM(&(bp)->blk_cksum, 0, 0, 0, 0); \
+}
+
+#define BP_SPRINTF_LEN 320
+
+#endif /* ! GRUB_ZFS_SPA_HEADER */
diff --git a/include/grub/zfs/uberblock_impl.h b/include/grub/zfs/uberblock_impl.h
new file mode 100644
index 0000000..1bf7f2b
--- /dev/null
+++ b/include/grub/zfs/uberblock_impl.h
@@ -0,0 +1,60 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
+ *
+ * GRUB is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+/*
+ * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef _SYS_UBERBLOCK_IMPL_H
+#define _SYS_UBERBLOCK_IMPL_H
+
+/*
+ * The uberblock version is incremented whenever an incompatible on-disk
+ * format change is made to the SPA, DMU, or ZAP.
+ *
+ * Note: the first two fields should never be moved. When a storage pool
+ * is opened, the uberblock must be read off the disk before the version
+ * can be checked. If the ub_version field is moved, we may not detect
+ * version mismatch. If the ub_magic field is moved, applications that
+ * expect the magic number in the first word won't work.
+ */
+#define UBERBLOCK_MAGIC 0x00bab10c /* oo-ba-bloc! */
+#define UBERBLOCK_SHIFT 10 /* up to 1K */
+
+typedef struct uberblock {
+ grub_uint64_t ub_magic; /* UBERBLOCK_MAGIC */
+ grub_uint64_t ub_version; /* ZFS_VERSION */
+ grub_uint64_t ub_txg; /* txg of last sync */
+ grub_uint64_t ub_guid_sum; /* sum of all vdev guids */
+ grub_uint64_t ub_timestamp; /* UTC time of last sync */
+ blkptr_t ub_rootbp; /* MOS objset_phys_t */
+} uberblock_t;
+
+#define UBERBLOCK_SIZE (1ULL << UBERBLOCK_SHIFT)
+#define VDEV_UBERBLOCK_SHIFT UBERBLOCK_SHIFT
+
+/* XXX Uberblock_phys_t is no longer in the kernel zfs */
+typedef struct uberblock_phys {
+ uberblock_t ubp_uberblock;
+ char ubp_pad[UBERBLOCK_SIZE - sizeof (uberblock_t) -
+ sizeof (zio_eck_t)];
+ zio_eck_t ubp_zec;
+} uberblock_phys_t;
+
+
+#endif /* _SYS_UBERBLOCK_IMPL_H */
diff --git a/include/grub/zfs/vdev_impl.h b/include/grub/zfs/vdev_impl.h
new file mode 100644
index 0000000..9b5f0a7
--- /dev/null
+++ b/include/grub/zfs/vdev_impl.h
@@ -0,0 +1,69 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
+ *
+ * GRUB is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+/*
+ * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef _SYS_VDEV_IMPL_H
+#define _SYS_VDEV_IMPL_H
+
+#define VDEV_SKIP_SIZE (8 << 10)
+#define VDEV_BOOT_HEADER_SIZE (8 << 10)
+#define VDEV_PHYS_SIZE (112 << 10)
+#define VDEV_UBERBLOCK_RING (128 << 10)
+
+/* ZFS boot block */
+#define VDEV_BOOT_MAGIC 0x2f5b007b10cULL
+#define VDEV_BOOT_VERSION 1 /* version number */
+
+typedef struct vdev_boot_header {
+ grub_uint64_t vb_magic; /* VDEV_BOOT_MAGIC */
+ grub_uint64_t vb_version; /* VDEV_BOOT_VERSION */
+ grub_uint64_t vb_offset; /* start offset (bytes) */
+ grub_uint64_t vb_size; /* size (bytes) */
+ char vb_pad[VDEV_BOOT_HEADER_SIZE - 4 * sizeof (grub_uint64_t)];
+} vdev_boot_header_t;
+
+typedef struct vdev_phys {
+ char vp_nvlist[VDEV_PHYS_SIZE - sizeof (zio_eck_t)];
+ zio_eck_t vp_zbt;
+} vdev_phys_t;
+
+typedef struct vdev_label {
+ char vl_pad[VDEV_SKIP_SIZE]; /* 8K */
+ vdev_boot_header_t vl_boot_header; /* 8K */
+ vdev_phys_t vl_vdev_phys; /* 112K */
+ char vl_uberblock[VDEV_UBERBLOCK_RING]; /* 128K */
+} vdev_label_t; /* 256K total */
+
+/*
+ * Size and offset of embedded boot loader region on each label.
+ * The total size of the first two labels plus the boot area is 4MB.
+ */
+#define VDEV_BOOT_OFFSET (2 * sizeof (vdev_label_t))
+#define VDEV_BOOT_SIZE (7ULL << 19) /* 3.5M */
+
+/*
+ * Size of label regions at the start and end of each leaf device.
+ */
+#define VDEV_LABEL_START_SIZE (2 * sizeof (vdev_label_t) + VDEV_BOOT_SIZE)
+#define VDEV_LABEL_END_SIZE (2 * sizeof (vdev_label_t))
+#define VDEV_LABELS 4
+
+#endif /* _SYS_VDEV_IMPL_H */
diff --git a/include/grub/zfs/zap_impl.h b/include/grub/zfs/zap_impl.h
new file mode 100644
index 0000000..0e985d9
--- /dev/null
+++ b/include/grub/zfs/zap_impl.h
@@ -0,0 +1,109 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
+ *
+ * GRUB is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+/*
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef _SYS_ZAP_IMPL_H
+#define _SYS_ZAP_IMPL_H
+
+#define ZAP_MAGIC 0x2F52AB2ABULL
+
+#define ZAP_HASHBITS 28
+#define MZAP_ENT_LEN 64
+#define MZAP_NAME_LEN (MZAP_ENT_LEN - 8 - 4 - 2)
+
+typedef struct mzap_ent_phys {
+ grub_uint64_t mze_value;
+ grub_uint32_t mze_cd;
+ grub_uint16_t mze_pad; /* in case we want to chain them someday */
+ char mze_name[MZAP_NAME_LEN];
+} mzap_ent_phys_t;
+
+typedef struct mzap_phys {
+ grub_uint64_t mz_block_type; /* ZBT_MICRO */
+ grub_uint64_t mz_salt;
+ grub_uint64_t mz_pad[6];
+ mzap_ent_phys_t mz_chunk[1];
+ /* actually variable size depending on block size */
+} mzap_phys_t;
+
+/*
+ * The (fat) zap is stored in one object. It is an array of
+ * 1<<FZAP_BLOCK_SHIFT byte blocks. The layout looks like one of:
+ *
+ * ptrtbl fits in first block:
+ * [zap_phys_t zap_ptrtbl_shift < 6] [zap_leaf_t] ...
+ *
+ * ptrtbl too big for first block:
+ * [zap_phys_t zap_ptrtbl_shift >= 6] [zap_leaf_t] [ptrtbl] ...
+ *
+ */
+
+#define ZBT_LEAF ((1ULL << 63) + 0)
+#define ZBT_HEADER ((1ULL << 63) + 1)
+#define ZBT_MICRO ((1ULL << 63) + 3)
+/* any other values are ptrtbl blocks */
+
+/*
+ * the embedded pointer table takes up half a block:
+ * block size / entry size (2^3) / 2
+ */
+#define ZAP_EMBEDDED_PTRTBL_SHIFT(zap) (FZAP_BLOCK_SHIFT(zap) - 3 - 1)
+
+/*
+ * The embedded pointer table starts half-way through the block. Since
+ * the pointer table itself is half the block, it starts at (64-bit)
+ * word number (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap)).
+ */
+#define ZAP_EMBEDDED_PTRTBL_ENT(zap, idx) \
+ ((grub_uint64_t *)(zap)->zap_f.zap_phys) \
+ [(idx) + (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap))]
+
+/*
+ * TAKE NOTE:
+ * If zap_phys_t is modified, zap_byteswap() must be modified.
+ */
+typedef struct zap_phys {
+ grub_uint64_t zap_block_type; /* ZBT_HEADER */
+ grub_uint64_t zap_magic; /* ZAP_MAGIC */
+
+ struct zap_table_phys {
+ grub_uint64_t zt_blk; /* starting block number */
+ grub_uint64_t zt_numblks; /* number of blocks */
+ grub_uint64_t zt_shift; /* bits to index it */
+ grub_uint64_t zt_nextblk; /* next (larger) copy start block */
+ grub_uint64_t zt_blks_copied; /* number source blocks copied */
+ } zap_ptrtbl;
+
+ grub_uint64_t zap_freeblk; /* the next free block */
+ grub_uint64_t zap_num_leafs; /* number of leafs */
+ grub_uint64_t zap_num_entries; /* number of entries */
+ grub_uint64_t zap_salt; /* salt to stir into hash function */
+ grub_uint64_t zap_normflags; /* flags for u8_textprep_str() */
+ grub_uint64_t zap_flags; /* zap_flag_t */
+ /*
+ * This structure is followed by padding, and then the embedded
+ * pointer table. The embedded pointer table takes up second
+ * half of the block. It is accessed using the
+ * ZAP_EMBEDDED_PTRTBL_ENT() macro.
+ */
+} zap_phys_t;
+
+#endif /* _SYS_ZAP_IMPL_H */
diff --git a/include/grub/zfs/zap_leaf.h b/include/grub/zfs/zap_leaf.h
new file mode 100644
index 0000000..11447c1
--- /dev/null
+++ b/include/grub/zfs/zap_leaf.h
@@ -0,0 +1,103 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
+ *
+ * GRUB is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef _SYS_ZAP_LEAF_H
+#define _SYS_ZAP_LEAF_H
+
+#define ZAP_LEAF_MAGIC 0x2AB1EAF
+
+/* chunk size = 24 bytes */
+#define ZAP_LEAF_CHUNKSIZE 24
+
+/*
+ * The amount of space within the chunk available for the array is:
+ * chunk size - space for type (1) - space for next pointer (2)
+ */
+#define ZAP_LEAF_ARRAY_BYTES (ZAP_LEAF_CHUNKSIZE - 3)
+
+typedef enum zap_chunk_type {
+ ZAP_CHUNK_FREE = 253,
+ ZAP_CHUNK_ENTRY = 252,
+ ZAP_CHUNK_ARRAY = 251,
+ ZAP_CHUNK_TYPE_MAX = 250
+} zap_chunk_type_t;
+
+/*
+ * TAKE NOTE:
+ * If zap_leaf_phys_t is modified, zap_leaf_byteswap() must be modified.
+ */
+typedef struct zap_leaf_phys {
+ struct zap_leaf_header {
+ grub_uint64_t lh_block_type; /* ZBT_LEAF */
+ grub_uint64_t lh_pad1;
+ grub_uint64_t lh_prefix; /* hash prefix of this leaf */
+ grub_uint32_t lh_magic; /* ZAP_LEAF_MAGIC */
+ grub_uint16_t lh_nfree; /* number free chunks */
+ grub_uint16_t lh_nentries; /* number of entries */
+ grub_uint16_t lh_prefix_len; /* num bits used to id this */
+
+/* above is accessable to zap, below is zap_leaf private */
+
+ grub_uint16_t lh_freelist; /* chunk head of free list */
+ grub_uint8_t lh_pad2[12];
+ } l_hdr; /* 2 24-byte chunks */
+
+ /*
+ * The header is followed by a hash table with
+ * ZAP_LEAF_HASH_NUMENTRIES(zap) entries. The hash table is
+ * followed by an array of ZAP_LEAF_NUMCHUNKS(zap)
+ * zap_leaf_chunk structures. These structures are accessed
+ * with the ZAP_LEAF_CHUNK() macro.
+ */
+
+ grub_uint16_t l_hash[0];
+} zap_leaf_phys_t;
+
+typedef union zap_leaf_chunk {
+ struct zap_leaf_entry {
+ grub_uint8_t le_type; /* always ZAP_CHUNK_ENTRY */
+ grub_uint8_t le_int_size; /* size of ints */
+ grub_uint16_t le_next; /* next entry in hash chain */
+ grub_uint16_t le_name_chunk; /* first chunk of the name */
+ grub_uint16_t le_name_length; /* bytes in name, incl null */
+ grub_uint16_t le_value_chunk; /* first chunk of the value */
+ grub_uint16_t le_value_length; /* value length in ints */
+ grub_uint32_t le_cd; /* collision differentiator */
+ grub_uint64_t le_hash; /* hash value of the name */
+ } l_entry;
+ struct zap_leaf_array {
+ grub_uint8_t la_type; /* always ZAP_CHUNK_ARRAY */
+ union
+ {
+ grub_uint8_t la_array[ZAP_LEAF_ARRAY_BYTES];
+ grub_uint64_t la_array64;
+ } GRUB_PACKED;
+ grub_uint16_t la_next; /* next blk or CHAIN_END */
+ } l_array;
+ struct zap_leaf_free {
+ grub_uint8_t lf_type; /* always ZAP_CHUNK_FREE */
+ grub_uint8_t lf_pad[ZAP_LEAF_ARRAY_BYTES];
+ grub_uint16_t lf_next; /* next in free list, or CHAIN_END */
+ } l_free;
+} zap_leaf_chunk_t;
+
+#endif /* _SYS_ZAP_LEAF_H */
diff --git a/include/grub/zfs/zfs.h b/include/grub/zfs/zfs.h
new file mode 100644
index 0000000..4ee5138
--- /dev/null
+++ b/include/grub/zfs/zfs.h
@@ -0,0 +1,158 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 1999,2000,2001,2002,2003,2004,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+ /*
+ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
+ */
+
+#ifndef GRUB_ZFS_HEADER
+#define GRUB_ZFS_HEADER 1
+
+#include <grub/err.h>
+#include <grub/disk.h>
+#include <grub/crypto.h>
+
+typedef enum grub_zfs_endian
+ {
+ GRUB_ZFS_UNKNOWN_ENDIAN = -2,
+ GRUB_ZFS_LITTLE_ENDIAN = -1,
+ GRUB_ZFS_BIG_ENDIAN = 0
+ } grub_zfs_endian_t;
+
+/*
+ * On-disk version number.
+ */
+#define SPA_VERSION_INITIAL 1ULL
+#define SPA_VERSION_BEFORE_FEATURES 33ULL
+#define SPA_VERSION_FEATURES 5000ULL
+#define SPA_VERSION_IS_SUPPORTED(v) \
+ (((v) >= SPA_VERSION_INITIAL && (v) <= SPA_VERSION_BEFORE_FEATURES) || \
+ ((v) == SPA_VERSION_FEATURES))
+/*
+ * The following are configuration names used in the nvlist describing a pool's
+ * configuration.
+ */
+#define ZPOOL_CONFIG_VERSION "version"
+#define ZPOOL_CONFIG_POOL_NAME "name"
+#define ZPOOL_CONFIG_POOL_STATE "state"
+#define ZPOOL_CONFIG_POOL_TXG "txg"
+#define ZPOOL_CONFIG_POOL_GUID "pool_guid"
+#define ZPOOL_CONFIG_CREATE_TXG "create_txg"
+#define ZPOOL_CONFIG_TOP_GUID "top_guid"
+#define ZPOOL_CONFIG_VDEV_TREE "vdev_tree"
+#define ZPOOL_CONFIG_TYPE "type"
+#define ZPOOL_CONFIG_CHILDREN "children"
+#define ZPOOL_CONFIG_ID "id"
+#define ZPOOL_CONFIG_GUID "guid"
+#define ZPOOL_CONFIG_PATH "path"
+#define ZPOOL_CONFIG_DEVID "devid"
+#define ZPOOL_CONFIG_METASLAB_ARRAY "metaslab_array"
+#define ZPOOL_CONFIG_METASLAB_SHIFT "metaslab_shift"
+#define ZPOOL_CONFIG_ASHIFT "ashift"
+#define ZPOOL_CONFIG_ASIZE "asize"
+#define ZPOOL_CONFIG_DTL "DTL"
+#define ZPOOL_CONFIG_STATS "stats"
+#define ZPOOL_CONFIG_WHOLE_DISK "whole_disk"
+#define ZPOOL_CONFIG_ERRCOUNT "error_count"
+#define ZPOOL_CONFIG_NOT_PRESENT "not_present"
+#define ZPOOL_CONFIG_SPARES "spares"
+#define ZPOOL_CONFIG_IS_SPARE "is_spare"
+#define ZPOOL_CONFIG_NPARITY "nparity"
+#define ZPOOL_CONFIG_PHYS_PATH "phys_path"
+#define ZPOOL_CONFIG_L2CACHE "l2cache"
+#define ZPOOL_CONFIG_HOLE_ARRAY "hole_array"
+#define ZPOOL_CONFIG_VDEV_CHILDREN "vdev_children"
+#define ZPOOL_CONFIG_IS_HOLE "is_hole"
+#define ZPOOL_CONFIG_DDT_HISTOGRAM "ddt_histogram"
+#define ZPOOL_CONFIG_DDT_OBJ_STATS "ddt_object_stats"
+#define ZPOOL_CONFIG_DDT_STATS "ddt_stats"
+#define ZPOOL_CONFIG_FEATURES_FOR_READ "features_for_read"
+/*
+ * The persistent vdev state is stored as separate values rather than a single
+ * 'vdev_state' entry. This is because a device can be in multiple states, such
+ * as offline and degraded.
+ */
+#define ZPOOL_CONFIG_OFFLINE "offline"
+#define ZPOOL_CONFIG_FAULTED "faulted"
+#define ZPOOL_CONFIG_DEGRADED "degraded"
+#define ZPOOL_CONFIG_REMOVED "removed"
+
+#define VDEV_TYPE_ROOT "root"
+#define VDEV_TYPE_MIRROR "mirror"
+#define VDEV_TYPE_REPLACING "replacing"
+#define VDEV_TYPE_RAIDZ "raidz"
+#define VDEV_TYPE_DISK "disk"
+#define VDEV_TYPE_FILE "file"
+#define VDEV_TYPE_MISSING "missing"
+#define VDEV_TYPE_HOLE "hole"
+#define VDEV_TYPE_SPARE "spare"
+#define VDEV_TYPE_L2CACHE "l2cache"
+
+/*
+ * pool state. The following states are written to disk as part of the normal
+ * SPA lifecycle: ACTIVE, EXPORTED, DESTROYED, SPARE, L2CACHE. The remaining
+ * states are software abstractions used at various levels to communicate pool
+ * state.
+ */
+typedef enum pool_state {
+ POOL_STATE_ACTIVE = 0, /* In active use */
+ POOL_STATE_EXPORTED, /* Explicitly exported */
+ POOL_STATE_DESTROYED, /* Explicitly destroyed */
+ POOL_STATE_SPARE, /* Reserved for hot spare use */
+ POOL_STATE_L2CACHE, /* Level 2 ARC device */
+ POOL_STATE_UNINITIALIZED, /* Internal spa_t state */
+ POOL_STATE_UNAVAIL, /* Internal libzfs state */
+ POOL_STATE_POTENTIALLY_ACTIVE /* Internal libzfs state */
+} pool_state_t;
+
+struct grub_zfs_data;
+
+grub_err_t grub_zfs_fetch_nvlist (grub_device_t dev, char **nvlist);
+grub_err_t grub_zfs_getmdnobj (grub_device_t dev, const char *fsfilename,
+ grub_uint64_t *mdnobj);
+
+char *grub_zfs_nvlist_lookup_string (const char *nvlist, const char *name);
+char *grub_zfs_nvlist_lookup_nvlist (const char *nvlist, const char *name);
+int grub_zfs_nvlist_lookup_uint64 (const char *nvlist, const char *name,
+ grub_uint64_t *out);
+char *grub_zfs_nvlist_lookup_nvlist_array (const char *nvlist,
+ const char *name,
+ grub_size_t array_index);
+int grub_zfs_nvlist_lookup_nvlist_array_get_nelm (const char *nvlist,
+ const char *name);
+grub_err_t
+grub_zfs_add_key (grub_uint8_t *key_in,
+ grub_size_t keylen,
+ int passphrase);
+
+extern grub_err_t (*grub_zfs_decrypt) (grub_crypto_cipher_handle_t cipher,
+ grub_uint64_t algo,
+ void *nonce,
+ char *buf, grub_size_t size,
+ const grub_uint32_t *expected_mac,
+ grub_zfs_endian_t endian);
+
+struct grub_zfs_key;
+
+extern grub_crypto_cipher_handle_t (*grub_zfs_load_key) (const struct grub_zfs_key *key,
+ grub_size_t keysize,
+ grub_uint64_t salt,
+ grub_uint64_t algo);
+
+
+
+#endif /* ! GRUB_ZFS_HEADER */
diff --git a/include/grub/zfs/zfs_acl.h b/include/grub/zfs/zfs_acl.h
new file mode 100644
index 0000000..2777382
--- /dev/null
+++ b/include/grub/zfs/zfs_acl.h
@@ -0,0 +1,59 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
+ *
+ * GRUB is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef _SYS_FS_ZFS_ACL_H
+#define _SYS_FS_ZFS_ACL_H
+
+#ifndef _UID_T
+#define _UID_T
+typedef unsigned int uid_t; /* UID type */
+#endif /* _UID_T */
+
+typedef struct zfs_oldace {
+ grub_uint32_t z_fuid; /* "who" */
+ grub_uint32_t z_access_mask; /* access mask */
+ grub_uint16_t z_flags; /* flags, i.e inheritance */
+ grub_uint16_t z_type; /* type of entry allow/deny */
+} zfs_oldace_t;
+
+#define ACE_SLOT_CNT 6
+
+typedef struct zfs_znode_acl_v0 {
+ grub_uint64_t z_acl_extern_obj; /* ext acl pieces */
+ grub_uint32_t z_acl_count; /* Number of ACEs */
+ grub_uint16_t z_acl_version; /* acl version */
+ grub_uint16_t z_acl_pad; /* pad */
+ zfs_oldace_t z_ace_data[ACE_SLOT_CNT]; /* 6 standard ACEs */
+} zfs_znode_acl_v0_t;
+
+#define ZFS_ACE_SPACE (sizeof (zfs_oldace_t) * ACE_SLOT_CNT)
+
+typedef struct zfs_znode_acl {
+ grub_uint64_t z_acl_extern_obj; /* ext acl pieces */
+ grub_uint32_t z_acl_size; /* Number of bytes in ACL */
+ grub_uint16_t z_acl_version; /* acl version */
+ grub_uint16_t z_acl_count; /* ace count */
+ grub_uint8_t z_ace_data[ZFS_ACE_SPACE]; /* space for embedded ACEs */
+} zfs_znode_acl_t;
+
+
+#endif /* _SYS_FS_ZFS_ACL_H */
diff --git a/include/grub/zfs/zfs_znode.h b/include/grub/zfs/zfs_znode.h
new file mode 100644
index 0000000..efd6d10
--- /dev/null
+++ b/include/grub/zfs/zfs_znode.h
@@ -0,0 +1,70 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
+ *
+ * GRUB is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+/*
+ * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef _SYS_FS_ZFS_ZNODE_H
+#define _SYS_FS_ZFS_ZNODE_H
+
+#include <grub/zfs/zfs_acl.h>
+
+#define MASTER_NODE_OBJ 1
+#define ZFS_ROOT_OBJ "ROOT"
+#define ZPL_VERSION_STR "VERSION"
+#define ZFS_SA_ATTRS "SA_ATTRS"
+
+#define ZPL_VERSION 5ULL
+
+#define ZFS_DIRENT_OBJ(de) BF64_GET(de, 0, 48)
+
+/*
+ * This is the persistent portion of the znode. It is stored
+ * in the "bonus buffer" of the file. Short symbolic links
+ * are also stored in the bonus buffer.
+ */
+typedef struct znode_phys {
+ grub_uint64_t zp_atime[2]; /* 0 - last file access time */
+ grub_uint64_t zp_mtime[2]; /* 16 - last file modification time */
+ grub_uint64_t zp_ctime[2]; /* 32 - last file change time */
+ grub_uint64_t zp_crtime[2]; /* 48 - creation time */
+ grub_uint64_t zp_gen; /* 64 - generation (txg of creation) */
+ grub_uint64_t zp_mode; /* 72 - file mode bits */
+ grub_uint64_t zp_size; /* 80 - size of file */
+ grub_uint64_t zp_parent; /* 88 - directory parent (`..') */
+ grub_uint64_t zp_links; /* 96 - number of links to file */
+ grub_uint64_t zp_xattr; /* 104 - DMU object for xattrs */
+ grub_uint64_t zp_rdev; /* 112 - dev_t for VBLK & VCHR files */
+ grub_uint64_t zp_flags; /* 120 - persistent flags */
+ grub_uint64_t zp_uid; /* 128 - file owner */
+ grub_uint64_t zp_gid; /* 136 - owning group */
+ grub_uint64_t zp_pad[4]; /* 144 - future */
+ zfs_znode_acl_t zp_acl; /* 176 - 263 ACL */
+ /*
+ * Data may pad out any remaining bytes in the znode buffer, eg:
+ *
+ * |<---------------------- dnode_phys (512) ------------------------>|
+ * |<-- dnode (192) --->|<----------- "bonus" buffer (320) ---------->|
+ * |<---- znode (264) ---->|<---- data (56) ---->|
+ *
+ * At present, we only use this space to store symbolic links.
+ */
+} znode_phys_t;
+
+#endif /* _SYS_FS_ZFS_ZNODE_H */
diff --git a/include/grub/zfs/zil.h b/include/grub/zfs/zil.h
new file mode 100644
index 0000000..45d16f4
--- /dev/null
+++ b/include/grub/zfs/zil.h
@@ -0,0 +1,56 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
+ *
+ * GRUB is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+/*
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef _SYS_ZIL_H
+#define _SYS_ZIL_H
+
+/*
+ * Intent log format:
+ *
+ * Each objset has its own intent log. The log header (zil_header_t)
+ * for objset N's intent log is kept in the Nth object of the SPA's
+ * intent_log objset. The log header points to a chain of log blocks,
+ * each of which contains log records (i.e., transactions) followed by
+ * a log block trailer (zil_trailer_t). The format of a log record
+ * depends on the record (or transaction) type, but all records begin
+ * with a common structure that defines the type, length, and txg.
+ */
+
+/*
+ * Intent log header - this on disk structure holds fields to manage
+ * the log. All fields are 64 bit to easily handle cross architectures.
+ */
+typedef struct zil_header {
+ grub_uint64_t zh_claim_txg; /* txg in which log blocks were claimed */
+ grub_uint64_t zh_replay_seq; /* highest replayed sequence number */
+ blkptr_t zh_log; /* log chain */
+ grub_uint64_t zh_claim_seq; /* highest claimed sequence number */
+ grub_uint64_t zh_flags; /* header flags */
+ grub_uint64_t zh_pad[4];
+} zil_header_t;
+
+/*
+ * zh_flags bit settings
+ */
+#define ZIL_REPLAY_NEEDED 0x1 /* replay needed - internal only */
+
+#endif /* _SYS_ZIL_H */
diff --git a/include/grub/zfs/zio.h b/include/grub/zfs/zio.h
new file mode 100644
index 0000000..19ce136
--- /dev/null
+++ b/include/grub/zfs/zio.h
@@ -0,0 +1,95 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
+ *
+ * GRUB is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+/*
+ * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef _ZIO_H
+#define _ZIO_H
+
+#include <grub/zfs/spa.h>
+
+#define ZEC_MAGIC 0x210da7ab10c7a11ULL /* zio data bloc tail */
+
+typedef struct zio_eck {
+ grub_uint64_t zec_magic; /* for validation, endianness */
+ zio_cksum_t zec_cksum; /* 256-bit checksum */
+} GRUB_PACKED zio_eck_t;
+
+/*
+ * Gang block headers are self-checksumming and contain an array
+ * of block pointers.
+ */
+#define SPA_GANGBLOCKSIZE SPA_MINBLOCKSIZE
+#define SPA_GBH_NBLKPTRS ((SPA_GANGBLOCKSIZE - \
+ sizeof (zio_eck_t)) / sizeof (blkptr_t))
+#define SPA_GBH_FILLER ((SPA_GANGBLOCKSIZE - \
+ sizeof (zio_eck_t) - \
+ (SPA_GBH_NBLKPTRS * sizeof (blkptr_t))) /\
+ sizeof (grub_uint64_t))
+
+#define ZIO_GET_IOSIZE(zio) \
+ (BP_IS_GANG((zio)->io_bp) ? \
+ SPA_GANGBLOCKSIZE : BP_GET_PSIZE((zio)->io_bp))
+
+typedef struct zio_gbh {
+ blkptr_t zg_blkptr[SPA_GBH_NBLKPTRS];
+ grub_uint64_t zg_filler[SPA_GBH_FILLER];
+ zio_eck_t zg_tail;
+} zio_gbh_phys_t;
+
+enum zio_checksum {
+ ZIO_CHECKSUM_INHERIT = 0,
+ ZIO_CHECKSUM_ON,
+ ZIO_CHECKSUM_OFF,
+ ZIO_CHECKSUM_LABEL,
+ ZIO_CHECKSUM_GANG_HEADER,
+ ZIO_CHECKSUM_ZILOG,
+ ZIO_CHECKSUM_FLETCHER_2,
+ ZIO_CHECKSUM_FLETCHER_4,
+ ZIO_CHECKSUM_SHA256,
+ ZIO_CHECKSUM_ZILOG2,
+ ZIO_CHECKSUM_SHA256_MAC,
+ ZIO_CHECKSUM_FUNCTIONS
+};
+
+#define ZIO_CHECKSUM_ON_VALUE ZIO_CHECKSUM_FLETCHER_2
+#define ZIO_CHECKSUM_DEFAULT ZIO_CHECKSUM_ON
+
+enum zio_compress {
+ ZIO_COMPRESS_INHERIT = 0,
+ ZIO_COMPRESS_ON,
+ ZIO_COMPRESS_OFF,
+ ZIO_COMPRESS_LZJB,
+ ZIO_COMPRESS_EMPTY,
+ ZIO_COMPRESS_GZIP1,
+ ZIO_COMPRESS_GZIP2,
+ ZIO_COMPRESS_GZIP3,
+ ZIO_COMPRESS_GZIP4,
+ ZIO_COMPRESS_GZIP5,
+ ZIO_COMPRESS_GZIP6,
+ ZIO_COMPRESS_GZIP7,
+ ZIO_COMPRESS_GZIP8,
+ ZIO_COMPRESS_GZIP9,
+ ZIO_COMPRESS_ZLE,
+ ZIO_COMPRESS_LZ4,
+ ZIO_COMPRESS_FUNCTIONS
+};
+
+#endif /* _ZIO_H */
diff --git a/include/grub/zfs/zio_checksum.h b/include/grub/zfs/zio_checksum.h
new file mode 100644
index 0000000..e03c85a
--- /dev/null
+++ b/include/grub/zfs/zio_checksum.h
@@ -0,0 +1,33 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
+ *
+ * GRUB is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+/*
+ * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef _SYS_ZIO_CHECKSUM_H
+#define _SYS_ZIO_CHECKSUM_H
+
+extern void zio_checksum_SHA256 (const void *, grub_uint64_t,
+ grub_zfs_endian_t endian, zio_cksum_t *);
+extern void fletcher_2 (const void *, grub_uint64_t, grub_zfs_endian_t endian,
+ zio_cksum_t *);
+extern void fletcher_4 (const void *, grub_uint64_t, grub_zfs_endian_t endian,
+ zio_cksum_t *);
+
+#endif /* _SYS_ZIO_CHECKSUM_H */
diff --git a/include/multiboot.h b/include/multiboot.h
new file mode 100644
index 0000000..7e5ac69
--- /dev/null
+++ b/include/multiboot.h
@@ -0,0 +1,274 @@
+/* multiboot.h - Multiboot header file. */
+/* Copyright (C) 1999,2003,2007,2008,2009,2010 Free Software Foundation, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ANY
+ * DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+ * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef MULTIBOOT_HEADER
+#define MULTIBOOT_HEADER 1
+
+/* How many bytes from the start of the file we search for the header. */
+#define MULTIBOOT_SEARCH 8192
+#define MULTIBOOT_HEADER_ALIGN 4
+
+/* The magic field should contain this. */
+#define MULTIBOOT_HEADER_MAGIC 0x1BADB002
+
+/* This should be in %eax. */
+#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002
+
+/* Alignment of multiboot modules. */
+#define MULTIBOOT_MOD_ALIGN 0x00001000
+
+/* Alignment of the multiboot info structure. */
+#define MULTIBOOT_INFO_ALIGN 0x00000004
+
+/* Flags set in the 'flags' member of the multiboot header. */
+
+/* Align all boot modules on i386 page (4KB) boundaries. */
+#define MULTIBOOT_PAGE_ALIGN 0x00000001
+
+/* Must pass memory information to OS. */
+#define MULTIBOOT_MEMORY_INFO 0x00000002
+
+/* Must pass video information to OS. */
+#define MULTIBOOT_VIDEO_MODE 0x00000004
+
+/* This flag indicates the use of the address fields in the header. */
+#define MULTIBOOT_AOUT_KLUDGE 0x00010000
+
+/* Flags to be set in the 'flags' member of the multiboot info structure. */
+
+/* is there basic lower/upper memory information? */
+#define MULTIBOOT_INFO_MEMORY 0x00000001
+/* is there a boot device set? */
+#define MULTIBOOT_INFO_BOOTDEV 0x00000002
+/* is the command-line defined? */
+#define MULTIBOOT_INFO_CMDLINE 0x00000004
+/* are there modules to do something with? */
+#define MULTIBOOT_INFO_MODS 0x00000008
+
+/* These next two are mutually exclusive */
+
+/* is there a symbol table loaded? */
+#define MULTIBOOT_INFO_AOUT_SYMS 0x00000010
+/* is there an ELF section header table? */
+#define MULTIBOOT_INFO_ELF_SHDR 0X00000020
+
+/* is there a full memory map? */
+#define MULTIBOOT_INFO_MEM_MAP 0x00000040
+
+/* Is there drive info? */
+#define MULTIBOOT_INFO_DRIVE_INFO 0x00000080
+
+/* Is there a config table? */
+#define MULTIBOOT_INFO_CONFIG_TABLE 0x00000100
+
+/* Is there a boot loader name? */
+#define MULTIBOOT_INFO_BOOT_LOADER_NAME 0x00000200
+
+/* Is there a APM table? */
+#define MULTIBOOT_INFO_APM_TABLE 0x00000400
+
+/* Is there video information? */
+#define MULTIBOOT_INFO_VBE_INFO 0x00000800
+#define MULTIBOOT_INFO_FRAMEBUFFER_INFO 0x00001000
+
+#ifndef ASM_FILE
+
+typedef unsigned char multiboot_uint8_t;
+typedef unsigned short multiboot_uint16_t;
+typedef unsigned int multiboot_uint32_t;
+typedef unsigned long long multiboot_uint64_t;
+
+struct multiboot_header
+{
+ /* Must be MULTIBOOT_MAGIC - see above. */
+ multiboot_uint32_t magic;
+
+ /* Feature flags. */
+ multiboot_uint32_t flags;
+
+ /* The above fields plus this one must equal 0 mod 2^32. */
+ multiboot_uint32_t checksum;
+
+ /* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */
+ multiboot_uint32_t header_addr;
+ multiboot_uint32_t load_addr;
+ multiboot_uint32_t load_end_addr;
+ multiboot_uint32_t bss_end_addr;
+ multiboot_uint32_t entry_addr;
+
+ /* These are only valid if MULTIBOOT_VIDEO_MODE is set. */
+ multiboot_uint32_t mode_type;
+ multiboot_uint32_t width;
+ multiboot_uint32_t height;
+ multiboot_uint32_t depth;
+};
+
+/* The symbol table for a.out. */
+struct multiboot_aout_symbol_table
+{
+ multiboot_uint32_t tabsize;
+ multiboot_uint32_t strsize;
+ multiboot_uint32_t addr;
+ multiboot_uint32_t reserved;
+};
+typedef struct multiboot_aout_symbol_table multiboot_aout_symbol_table_t;
+
+/* The section header table for ELF. */
+struct multiboot_elf_section_header_table
+{
+ multiboot_uint32_t num;
+ multiboot_uint32_t size;
+ multiboot_uint32_t addr;
+ multiboot_uint32_t shndx;
+};
+typedef struct multiboot_elf_section_header_table multiboot_elf_section_header_table_t;
+
+struct multiboot_info
+{
+ /* Multiboot info version number */
+ multiboot_uint32_t flags;
+
+ /* Available memory from BIOS */
+ multiboot_uint32_t mem_lower;
+ multiboot_uint32_t mem_upper;
+
+ /* "root" partition */
+ multiboot_uint32_t boot_device;
+
+ /* Kernel command line */
+ multiboot_uint32_t cmdline;
+
+ /* Boot-Module list */
+ multiboot_uint32_t mods_count;
+ multiboot_uint32_t mods_addr;
+
+ union
+ {
+ multiboot_aout_symbol_table_t aout_sym;
+ multiboot_elf_section_header_table_t elf_sec;
+ } u;
+
+ /* Memory Mapping buffer */
+ multiboot_uint32_t mmap_length;
+ multiboot_uint32_t mmap_addr;
+
+ /* Drive Info buffer */
+ multiboot_uint32_t drives_length;
+ multiboot_uint32_t drives_addr;
+
+ /* ROM configuration table */
+ multiboot_uint32_t config_table;
+
+ /* Boot Loader Name */
+ multiboot_uint32_t boot_loader_name;
+
+ /* APM table */
+ multiboot_uint32_t apm_table;
+
+ /* Video */
+ multiboot_uint32_t vbe_control_info;
+ multiboot_uint32_t vbe_mode_info;
+ multiboot_uint16_t vbe_mode;
+ multiboot_uint16_t vbe_interface_seg;
+ multiboot_uint16_t vbe_interface_off;
+ multiboot_uint16_t vbe_interface_len;
+
+ multiboot_uint64_t framebuffer_addr;
+ multiboot_uint32_t framebuffer_pitch;
+ multiboot_uint32_t framebuffer_width;
+ multiboot_uint32_t framebuffer_height;
+ multiboot_uint8_t framebuffer_bpp;
+#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0
+#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1
+#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2
+ multiboot_uint8_t framebuffer_type;
+ union
+ {
+ struct
+ {
+ multiboot_uint32_t framebuffer_palette_addr;
+ multiboot_uint16_t framebuffer_palette_num_colors;
+ };
+ struct
+ {
+ multiboot_uint8_t framebuffer_red_field_position;
+ multiboot_uint8_t framebuffer_red_mask_size;
+ multiboot_uint8_t framebuffer_green_field_position;
+ multiboot_uint8_t framebuffer_green_mask_size;
+ multiboot_uint8_t framebuffer_blue_field_position;
+ multiboot_uint8_t framebuffer_blue_mask_size;
+ };
+ };
+};
+typedef struct multiboot_info multiboot_info_t;
+
+struct multiboot_color
+{
+ multiboot_uint8_t red;
+ multiboot_uint8_t green;
+ multiboot_uint8_t blue;
+};
+
+struct multiboot_mmap_entry
+{
+ multiboot_uint32_t size;
+ multiboot_uint64_t addr;
+ multiboot_uint64_t len;
+#define MULTIBOOT_MEMORY_AVAILABLE 1
+#define MULTIBOOT_MEMORY_RESERVED 2
+#define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3
+#define MULTIBOOT_MEMORY_NVS 4
+#define MULTIBOOT_MEMORY_BADRAM 5
+ multiboot_uint32_t type;
+} GRUB_PACKED;
+typedef struct multiboot_mmap_entry multiboot_memory_map_t;
+
+struct multiboot_mod_list
+{
+ /* the memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive */
+ multiboot_uint32_t mod_start;
+ multiboot_uint32_t mod_end;
+
+ /* Module command line */
+ multiboot_uint32_t cmdline;
+
+ /* padding to take it to 16 bytes (must be zero) */
+ multiboot_uint32_t pad;
+};
+typedef struct multiboot_mod_list multiboot_module_t;
+
+/* APM BIOS info. */
+struct multiboot_apm_info
+{
+ grub_uint16_t version;
+ grub_uint16_t cseg;
+ grub_uint32_t offset;
+ grub_uint16_t cseg_16;
+ grub_uint16_t dseg;
+ grub_uint16_t flags;
+ grub_uint16_t cseg_len;
+ grub_uint16_t cseg_16_len;
+ grub_uint16_t dseg_len;
+};
+
+#endif /* ! ASM_FILE */
+
+#endif /* ! MULTIBOOT_HEADER */
diff --git a/include/multiboot2.h b/include/multiboot2.h
new file mode 100644
index 0000000..5693923
--- /dev/null
+++ b/include/multiboot2.h
@@ -0,0 +1,416 @@
+/* multiboot2.h - Multiboot 2 header file. */
+/* Copyright (C) 1999,2003,2007,2008,2009,2010 Free Software Foundation, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ANY
+ * DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+ * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef MULTIBOOT_HEADER
+#define MULTIBOOT_HEADER 1
+
+/* How many bytes from the start of the file we search for the header. */
+#define MULTIBOOT_SEARCH 32768
+#define MULTIBOOT_HEADER_ALIGN 8
+
+/* The magic field should contain this. */
+#define MULTIBOOT2_HEADER_MAGIC 0xe85250d6
+
+/* This should be in %eax. */
+#define MULTIBOOT2_BOOTLOADER_MAGIC 0x36d76289
+
+/* Alignment of multiboot modules. */
+#define MULTIBOOT_MOD_ALIGN 0x00001000
+
+/* Alignment of the multiboot info structure. */
+#define MULTIBOOT_INFO_ALIGN 0x00000008
+
+/* Flags set in the 'flags' member of the multiboot header. */
+
+#define MULTIBOOT_TAG_ALIGN 8
+#define MULTIBOOT_TAG_TYPE_END 0
+#define MULTIBOOT_TAG_TYPE_CMDLINE 1
+#define MULTIBOOT_TAG_TYPE_BOOT_LOADER_NAME 2
+#define MULTIBOOT_TAG_TYPE_MODULE 3
+#define MULTIBOOT_TAG_TYPE_BASIC_MEMINFO 4
+#define MULTIBOOT_TAG_TYPE_BOOTDEV 5
+#define MULTIBOOT_TAG_TYPE_MMAP 6
+#define MULTIBOOT_TAG_TYPE_VBE 7
+#define MULTIBOOT_TAG_TYPE_FRAMEBUFFER 8
+#define MULTIBOOT_TAG_TYPE_ELF_SECTIONS 9
+#define MULTIBOOT_TAG_TYPE_APM 10
+#define MULTIBOOT_TAG_TYPE_EFI32 11
+#define MULTIBOOT_TAG_TYPE_EFI64 12
+#define MULTIBOOT_TAG_TYPE_SMBIOS 13
+#define MULTIBOOT_TAG_TYPE_ACPI_OLD 14
+#define MULTIBOOT_TAG_TYPE_ACPI_NEW 15
+#define MULTIBOOT_TAG_TYPE_NETWORK 16
+#define MULTIBOOT_TAG_TYPE_EFI_MMAP 17
+#define MULTIBOOT_TAG_TYPE_EFI_BS 18
+#define MULTIBOOT_TAG_TYPE_EFI32_IH 19
+#define MULTIBOOT_TAG_TYPE_EFI64_IH 20
+#define MULTIBOOT_TAG_TYPE_LOAD_BASE_ADDR 21
+
+#define MULTIBOOT_HEADER_TAG_END 0
+#define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST 1
+#define MULTIBOOT_HEADER_TAG_ADDRESS 2
+#define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS 3
+#define MULTIBOOT_HEADER_TAG_CONSOLE_FLAGS 4
+#define MULTIBOOT_HEADER_TAG_FRAMEBUFFER 5
+#define MULTIBOOT_HEADER_TAG_MODULE_ALIGN 6
+#define MULTIBOOT_HEADER_TAG_EFI_BS 7
+#define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64 9
+#define MULTIBOOT_HEADER_TAG_RELOCATABLE 10
+
+#define MULTIBOOT2_ARCHITECTURE_I386 0
+#define MULTIBOOT2_ARCHITECTURE_MIPS32 4
+#define MULTIBOOT_HEADER_TAG_OPTIONAL 1
+
+#define MULTIBOOT_LOAD_PREFERENCE_NONE 0
+#define MULTIBOOT_LOAD_PREFERENCE_LOW 1
+#define MULTIBOOT_LOAD_PREFERENCE_HIGH 2
+
+#define MULTIBOOT_CONSOLE_FLAGS_CONSOLE_REQUIRED 1
+#define MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED 2
+
+#ifndef ASM_FILE
+
+typedef unsigned char multiboot_uint8_t;
+typedef unsigned short multiboot_uint16_t;
+typedef unsigned int multiboot_uint32_t;
+typedef unsigned long long multiboot_uint64_t;
+
+struct multiboot_header
+{
+ /* Must be MULTIBOOT_MAGIC - see above. */
+ multiboot_uint32_t magic;
+
+ /* ISA */
+ multiboot_uint32_t architecture;
+
+ /* Total header length. */
+ multiboot_uint32_t header_length;
+
+ /* The above fields plus this one must equal 0 mod 2^32. */
+ multiboot_uint32_t checksum;
+};
+
+struct multiboot_header_tag
+{
+ multiboot_uint16_t type;
+ multiboot_uint16_t flags;
+ multiboot_uint32_t size;
+};
+
+struct multiboot_header_tag_information_request
+{
+ multiboot_uint16_t type;
+ multiboot_uint16_t flags;
+ multiboot_uint32_t size;
+ multiboot_uint32_t requests[0];
+};
+
+struct multiboot_header_tag_address
+{
+ multiboot_uint16_t type;
+ multiboot_uint16_t flags;
+ multiboot_uint32_t size;
+ multiboot_uint32_t header_addr;
+ multiboot_uint32_t load_addr;
+ multiboot_uint32_t load_end_addr;
+ multiboot_uint32_t bss_end_addr;
+};
+
+struct multiboot_header_tag_entry_address
+{
+ multiboot_uint16_t type;
+ multiboot_uint16_t flags;
+ multiboot_uint32_t size;
+ multiboot_uint32_t entry_addr;
+};
+
+struct multiboot_header_tag_console_flags
+{
+ multiboot_uint16_t type;
+ multiboot_uint16_t flags;
+ multiboot_uint32_t size;
+ multiboot_uint32_t console_flags;
+};
+
+struct multiboot_header_tag_framebuffer
+{
+ multiboot_uint16_t type;
+ multiboot_uint16_t flags;
+ multiboot_uint32_t size;
+ multiboot_uint32_t width;
+ multiboot_uint32_t height;
+ multiboot_uint32_t depth;
+};
+
+struct multiboot_header_tag_module_align
+{
+ multiboot_uint16_t type;
+ multiboot_uint16_t flags;
+ multiboot_uint32_t size;
+};
+
+struct multiboot_header_tag_relocatable
+{
+ multiboot_uint16_t type;
+ multiboot_uint16_t flags;
+ multiboot_uint32_t size;
+ multiboot_uint32_t min_addr;
+ multiboot_uint32_t max_addr;
+ multiboot_uint32_t align;
+ multiboot_uint32_t preference;
+};
+
+struct multiboot_color
+{
+ multiboot_uint8_t red;
+ multiboot_uint8_t green;
+ multiboot_uint8_t blue;
+};
+
+struct multiboot_mmap_entry
+{
+ multiboot_uint64_t addr;
+ multiboot_uint64_t len;
+#define MULTIBOOT_MEMORY_AVAILABLE 1
+#define MULTIBOOT_MEMORY_RESERVED 2
+#define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3
+#define MULTIBOOT_MEMORY_NVS 4
+#define MULTIBOOT_MEMORY_BADRAM 5
+ multiboot_uint32_t type;
+ multiboot_uint32_t zero;
+};
+typedef struct multiboot_mmap_entry multiboot_memory_map_t;
+
+struct multiboot_tag
+{
+ multiboot_uint32_t type;
+ multiboot_uint32_t size;
+};
+
+struct multiboot_tag_string
+{
+ multiboot_uint32_t type;
+ multiboot_uint32_t size;
+ char string[0];
+};
+
+struct multiboot_tag_module
+{
+ multiboot_uint32_t type;
+ multiboot_uint32_t size;
+ multiboot_uint32_t mod_start;
+ multiboot_uint32_t mod_end;
+ char cmdline[0];
+};
+
+struct multiboot_tag_basic_meminfo
+{
+ multiboot_uint32_t type;
+ multiboot_uint32_t size;
+ multiboot_uint32_t mem_lower;
+ multiboot_uint32_t mem_upper;
+};
+
+struct multiboot_tag_bootdev
+{
+ multiboot_uint32_t type;
+ multiboot_uint32_t size;
+ multiboot_uint32_t biosdev;
+ multiboot_uint32_t slice;
+ multiboot_uint32_t part;
+};
+
+struct multiboot_tag_mmap
+{
+ multiboot_uint32_t type;
+ multiboot_uint32_t size;
+ multiboot_uint32_t entry_size;
+ multiboot_uint32_t entry_version;
+ struct multiboot_mmap_entry entries[0];
+};
+
+struct multiboot_vbe_info_block
+{
+ multiboot_uint8_t external_specification[512];
+};
+
+struct multiboot_vbe_mode_info_block
+{
+ multiboot_uint8_t external_specification[256];
+};
+
+struct multiboot_tag_vbe
+{
+ multiboot_uint32_t type;
+ multiboot_uint32_t size;
+
+ multiboot_uint16_t vbe_mode;
+ multiboot_uint16_t vbe_interface_seg;
+ multiboot_uint16_t vbe_interface_off;
+ multiboot_uint16_t vbe_interface_len;
+
+ struct multiboot_vbe_info_block vbe_control_info;
+ struct multiboot_vbe_mode_info_block vbe_mode_info;
+};
+
+struct multiboot_tag_framebuffer_common
+{
+ multiboot_uint32_t type;
+ multiboot_uint32_t size;
+
+ multiboot_uint64_t framebuffer_addr;
+ multiboot_uint32_t framebuffer_pitch;
+ multiboot_uint32_t framebuffer_width;
+ multiboot_uint32_t framebuffer_height;
+ multiboot_uint8_t framebuffer_bpp;
+#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0
+#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1
+#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2
+ multiboot_uint8_t framebuffer_type;
+ multiboot_uint16_t reserved;
+};
+
+struct multiboot_tag_framebuffer
+{
+ struct multiboot_tag_framebuffer_common common;
+
+ union
+ {
+ struct
+ {
+ multiboot_uint16_t framebuffer_palette_num_colors;
+ struct multiboot_color framebuffer_palette[0];
+ };
+ struct
+ {
+ multiboot_uint8_t framebuffer_red_field_position;
+ multiboot_uint8_t framebuffer_red_mask_size;
+ multiboot_uint8_t framebuffer_green_field_position;
+ multiboot_uint8_t framebuffer_green_mask_size;
+ multiboot_uint8_t framebuffer_blue_field_position;
+ multiboot_uint8_t framebuffer_blue_mask_size;
+ };
+ };
+};
+
+struct multiboot_tag_elf_sections
+{
+ multiboot_uint32_t type;
+ multiboot_uint32_t size;
+ multiboot_uint32_t num;
+ multiboot_uint32_t entsize;
+ multiboot_uint32_t shndx;
+ char sections[0];
+};
+
+struct multiboot_tag_apm
+{
+ multiboot_uint32_t type;
+ multiboot_uint32_t size;
+ multiboot_uint16_t version;
+ multiboot_uint16_t cseg;
+ multiboot_uint32_t offset;
+ multiboot_uint16_t cseg_16;
+ multiboot_uint16_t dseg;
+ multiboot_uint16_t flags;
+ multiboot_uint16_t cseg_len;
+ multiboot_uint16_t cseg_16_len;
+ multiboot_uint16_t dseg_len;
+};
+
+struct multiboot_tag_efi32
+{
+ multiboot_uint32_t type;
+ multiboot_uint32_t size;
+ multiboot_uint32_t pointer;
+};
+
+struct multiboot_tag_efi64
+{
+ multiboot_uint32_t type;
+ multiboot_uint32_t size;
+ multiboot_uint64_t pointer;
+};
+
+struct multiboot_tag_smbios
+{
+ multiboot_uint32_t type;
+ multiboot_uint32_t size;
+ multiboot_uint8_t major;
+ multiboot_uint8_t minor;
+ multiboot_uint8_t reserved[6];
+ multiboot_uint8_t tables[0];
+};
+
+struct multiboot_tag_old_acpi
+{
+ multiboot_uint32_t type;
+ multiboot_uint32_t size;
+ multiboot_uint8_t rsdp[0];
+};
+
+struct multiboot_tag_new_acpi
+{
+ multiboot_uint32_t type;
+ multiboot_uint32_t size;
+ multiboot_uint8_t rsdp[0];
+};
+
+struct multiboot_tag_network
+{
+ multiboot_uint32_t type;
+ multiboot_uint32_t size;
+ multiboot_uint8_t dhcpack[0];
+};
+
+struct multiboot_tag_efi_mmap
+{
+ multiboot_uint32_t type;
+ multiboot_uint32_t size;
+ multiboot_uint32_t descr_size;
+ multiboot_uint32_t descr_vers;
+ multiboot_uint8_t efi_mmap[0];
+};
+
+struct multiboot_tag_efi32_ih
+{
+ multiboot_uint32_t type;
+ multiboot_uint32_t size;
+ multiboot_uint32_t pointer;
+};
+
+struct multiboot_tag_efi64_ih
+{
+ multiboot_uint32_t type;
+ multiboot_uint32_t size;
+ multiboot_uint64_t pointer;
+};
+
+struct multiboot_tag_load_base_addr
+{
+ multiboot_uint32_t type;
+ multiboot_uint32_t size;
+ multiboot_uint32_t load_base_addr;
+};
+
+#endif /* ! ASM_FILE */
+
+#endif /* ! MULTIBOOT_HEADER */
diff --git a/include/xen/arch-x86/xen-x86_32.h b/include/xen/arch-x86/xen-x86_32.h
new file mode 100644
index 0000000..7eca6cd
--- /dev/null
+++ b/include/xen/arch-x86/xen-x86_32.h
@@ -0,0 +1,169 @@
+/******************************************************************************
+ * xen-x86_32.h
+ *
+ * Guest OS interface to x86 32-bit Xen.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright (c) 2004-2007, K A Fraser
+ */
+
+#ifndef __XEN_PUBLIC_ARCH_X86_XEN_X86_32_H__
+#define __XEN_PUBLIC_ARCH_X86_XEN_X86_32_H__
+
+/*
+ * Hypercall interface:
+ * Input: %ebx, %ecx, %edx, %esi, %edi, %ebp (arguments 1-6)
+ * Output: %eax
+ * Access is via hypercall page (set up by guest loader or via a Xen MSR):
+ * call hypercall_page + hypercall-number * 32
+ * Clobbered: Argument registers (e.g., 2-arg hypercall clobbers %ebx,%ecx)
+ */
+
+/*
+ * These flat segments are in the Xen-private section of every GDT. Since these
+ * are also present in the initial GDT, many OSes will be able to avoid
+ * installing their own GDT.
+ */
+#define FLAT_RING1_CS 0xe019 /* GDT index 259 */
+#define FLAT_RING1_DS 0xe021 /* GDT index 260 */
+#define FLAT_RING1_SS 0xe021 /* GDT index 260 */
+#define FLAT_RING3_CS 0xe02b /* GDT index 261 */
+#define FLAT_RING3_DS 0xe033 /* GDT index 262 */
+#define FLAT_RING3_SS 0xe033 /* GDT index 262 */
+
+#define FLAT_KERNEL_CS FLAT_RING1_CS
+#define FLAT_KERNEL_DS FLAT_RING1_DS
+#define FLAT_KERNEL_SS FLAT_RING1_SS
+#define FLAT_USER_CS FLAT_RING3_CS
+#define FLAT_USER_DS FLAT_RING3_DS
+#define FLAT_USER_SS FLAT_RING3_SS
+
+#define __HYPERVISOR_VIRT_START_PAE 0xF5800000
+#define __MACH2PHYS_VIRT_START_PAE 0xF5800000
+#define __MACH2PHYS_VIRT_END_PAE 0xF6800000
+#define HYPERVISOR_VIRT_START_PAE xen_mk_ulong(__HYPERVISOR_VIRT_START_PAE)
+#define MACH2PHYS_VIRT_START_PAE xen_mk_ulong(__MACH2PHYS_VIRT_START_PAE)
+#define MACH2PHYS_VIRT_END_PAE xen_mk_ulong(__MACH2PHYS_VIRT_END_PAE)
+
+/* Non-PAE bounds are obsolete. */
+#define __HYPERVISOR_VIRT_START_NONPAE 0xFC000000
+#define __MACH2PHYS_VIRT_START_NONPAE 0xFC000000
+#define __MACH2PHYS_VIRT_END_NONPAE 0xFC400000
+#define HYPERVISOR_VIRT_START_NONPAE \
+ xen_mk_ulong(__HYPERVISOR_VIRT_START_NONPAE)
+#define MACH2PHYS_VIRT_START_NONPAE \
+ xen_mk_ulong(__MACH2PHYS_VIRT_START_NONPAE)
+#define MACH2PHYS_VIRT_END_NONPAE \
+ xen_mk_ulong(__MACH2PHYS_VIRT_END_NONPAE)
+
+#define __HYPERVISOR_VIRT_START __HYPERVISOR_VIRT_START_PAE
+#define __MACH2PHYS_VIRT_START __MACH2PHYS_VIRT_START_PAE
+#define __MACH2PHYS_VIRT_END __MACH2PHYS_VIRT_END_PAE
+
+#ifndef HYPERVISOR_VIRT_START
+#define HYPERVISOR_VIRT_START xen_mk_ulong(__HYPERVISOR_VIRT_START)
+#endif
+
+#define MACH2PHYS_VIRT_START xen_mk_ulong(__MACH2PHYS_VIRT_START)
+#define MACH2PHYS_VIRT_END xen_mk_ulong(__MACH2PHYS_VIRT_END)
+#define MACH2PHYS_NR_ENTRIES ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>2)
+#ifndef machine_to_phys_mapping
+#define machine_to_phys_mapping ((unsigned long *)MACH2PHYS_VIRT_START)
+#endif
+
+/* 32-/64-bit invariability for control interfaces (domctl/sysctl). */
+#if defined(__XEN__) || defined(__XEN_TOOLS__)
+#undef ___DEFINE_XEN_GUEST_HANDLE
+#define ___DEFINE_XEN_GUEST_HANDLE(name, type) \
+ typedef struct { type *p; } \
+ __guest_handle_ ## name; \
+ typedef struct { union { type *p; uint64_aligned_t q; }; } \
+ __guest_handle_64_ ## name
+#undef set_xen_guest_handle_raw
+#define set_xen_guest_handle_raw(hnd, val) \
+ do { if ( sizeof(hnd) == 8 ) *(uint64_t *)&(hnd) = 0; \
+ (hnd).p = val; \
+ } while ( 0 )
+#define int64_aligned_t int64_t __attribute__((aligned(8)))
+#define uint64_aligned_t uint64_t __attribute__((aligned(8)))
+#define __XEN_GUEST_HANDLE_64(name) __guest_handle_64_ ## name
+#define XEN_GUEST_HANDLE_64(name) __XEN_GUEST_HANDLE_64(name)
+#endif
+
+#ifndef __ASSEMBLY__
+
+struct cpu_user_regs {
+ uint32_t ebx;
+ uint32_t ecx;
+ uint32_t edx;
+ uint32_t esi;
+ uint32_t edi;
+ uint32_t ebp;
+ uint32_t eax;
+ uint16_t error_code; /* private */
+ uint16_t entry_vector; /* private */
+ uint32_t eip;
+ uint16_t cs;
+ uint8_t saved_upcall_mask;
+ uint8_t _pad0;
+ uint32_t eflags; /* eflags.IF == !saved_upcall_mask */
+ uint32_t esp;
+ uint16_t ss, _pad1;
+ uint16_t es, _pad2;
+ uint16_t ds, _pad3;
+ uint16_t fs, _pad4;
+ uint16_t gs, _pad5;
+};
+typedef struct cpu_user_regs cpu_user_regs_t;
+DEFINE_XEN_GUEST_HANDLE(cpu_user_regs_t);
+
+/*
+ * Page-directory addresses above 4GB do not fit into architectural %cr3.
+ * When accessing %cr3, or equivalent field in vcpu_guest_context, guests
+ * must use the following accessor macros to pack/unpack valid MFNs.
+ */
+#define xen_pfn_to_cr3(pfn) (((unsigned)(pfn) << 12) | ((unsigned)(pfn) >> 20))
+#define xen_cr3_to_pfn(cr3) (((unsigned)(cr3) >> 12) | ((unsigned)(cr3) << 20))
+
+struct arch_vcpu_info {
+ unsigned long cr2;
+ unsigned long pad[5]; /* sizeof(vcpu_info_t) == 64 */
+};
+typedef struct arch_vcpu_info arch_vcpu_info_t;
+
+struct xen_callback {
+ unsigned long cs;
+ unsigned long eip;
+};
+typedef struct xen_callback xen_callback_t;
+
+#endif /* !__ASSEMBLY__ */
+
+#endif /* __XEN_PUBLIC_ARCH_X86_XEN_X86_32_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/include/xen/arch-x86/xen-x86_64.h b/include/xen/arch-x86/xen-x86_64.h
new file mode 100644
index 0000000..5e18613
--- /dev/null
+++ b/include/xen/arch-x86/xen-x86_64.h
@@ -0,0 +1,202 @@
+/******************************************************************************
+ * xen-x86_64.h
+ *
+ * Guest OS interface to x86 64-bit Xen.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright (c) 2004-2006, K A Fraser
+ */
+
+#ifndef __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__
+#define __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__
+
+/*
+ * Hypercall interface:
+ * Input: %rdi, %rsi, %rdx, %r10, %r8, %r9 (arguments 1-6)
+ * Output: %rax
+ * Access is via hypercall page (set up by guest loader or via a Xen MSR):
+ * call hypercall_page + hypercall-number * 32
+ * Clobbered: argument registers (e.g., 2-arg hypercall clobbers %rdi,%rsi)
+ */
+
+/*
+ * 64-bit segment selectors
+ * These flat segments are in the Xen-private section of every GDT. Since these
+ * are also present in the initial GDT, many OSes will be able to avoid
+ * installing their own GDT.
+ */
+
+#define FLAT_RING3_CS32 0xe023 /* GDT index 260 */
+#define FLAT_RING3_CS64 0xe033 /* GDT index 261 */
+#define FLAT_RING3_DS32 0xe02b /* GDT index 262 */
+#define FLAT_RING3_DS64 0x0000 /* NULL selector */
+#define FLAT_RING3_SS32 0xe02b /* GDT index 262 */
+#define FLAT_RING3_SS64 0xe02b /* GDT index 262 */
+
+#define FLAT_KERNEL_DS64 FLAT_RING3_DS64
+#define FLAT_KERNEL_DS32 FLAT_RING3_DS32
+#define FLAT_KERNEL_DS FLAT_KERNEL_DS64
+#define FLAT_KERNEL_CS64 FLAT_RING3_CS64
+#define FLAT_KERNEL_CS32 FLAT_RING3_CS32
+#define FLAT_KERNEL_CS FLAT_KERNEL_CS64
+#define FLAT_KERNEL_SS64 FLAT_RING3_SS64
+#define FLAT_KERNEL_SS32 FLAT_RING3_SS32
+#define FLAT_KERNEL_SS FLAT_KERNEL_SS64
+
+#define FLAT_USER_DS64 FLAT_RING3_DS64
+#define FLAT_USER_DS32 FLAT_RING3_DS32
+#define FLAT_USER_DS FLAT_USER_DS64
+#define FLAT_USER_CS64 FLAT_RING3_CS64
+#define FLAT_USER_CS32 FLAT_RING3_CS32
+#define FLAT_USER_CS FLAT_USER_CS64
+#define FLAT_USER_SS64 FLAT_RING3_SS64
+#define FLAT_USER_SS32 FLAT_RING3_SS32
+#define FLAT_USER_SS FLAT_USER_SS64
+
+#define __HYPERVISOR_VIRT_START 0xFFFF800000000000
+#define __HYPERVISOR_VIRT_END 0xFFFF880000000000
+#define __MACH2PHYS_VIRT_START 0xFFFF800000000000
+#define __MACH2PHYS_VIRT_END 0xFFFF804000000000
+
+#ifndef HYPERVISOR_VIRT_START
+#define HYPERVISOR_VIRT_START xen_mk_ulong(__HYPERVISOR_VIRT_START)
+#define HYPERVISOR_VIRT_END xen_mk_ulong(__HYPERVISOR_VIRT_END)
+#endif
+
+#define MACH2PHYS_VIRT_START xen_mk_ulong(__MACH2PHYS_VIRT_START)
+#define MACH2PHYS_VIRT_END xen_mk_ulong(__MACH2PHYS_VIRT_END)
+#define MACH2PHYS_NR_ENTRIES ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>3)
+#ifndef machine_to_phys_mapping
+#define machine_to_phys_mapping ((unsigned long *)HYPERVISOR_VIRT_START)
+#endif
+
+/*
+ * int HYPERVISOR_set_segment_base(unsigned int which, unsigned long base)
+ * @which == SEGBASE_* ; @base == 64-bit base address
+ * Returns 0 on success.
+ */
+#define SEGBASE_FS 0
+#define SEGBASE_GS_USER 1
+#define SEGBASE_GS_KERNEL 2
+#define SEGBASE_GS_USER_SEL 3 /* Set user %gs specified in base[15:0] */
+
+/*
+ * int HYPERVISOR_iret(void)
+ * All arguments are on the kernel stack, in the following format.
+ * Never returns if successful. Current kernel context is lost.
+ * The saved CS is mapped as follows:
+ * RING0 -> RING3 kernel mode.
+ * RING1 -> RING3 kernel mode.
+ * RING2 -> RING3 kernel mode.
+ * RING3 -> RING3 user mode.
+ * However RING0 indicates that the guest kernel should return to iteself
+ * directly with
+ * orb $3,1*8(%rsp)
+ * iretq
+ * If flags contains VGCF_in_syscall:
+ * Restore RAX, RIP, RFLAGS, RSP.
+ * Discard R11, RCX, CS, SS.
+ * Otherwise:
+ * Restore RAX, R11, RCX, CS:RIP, RFLAGS, SS:RSP.
+ * All other registers are saved on hypercall entry and restored to user.
+ */
+/* Guest exited in SYSCALL context? Return to guest with SYSRET? */
+#define _VGCF_in_syscall 8
+#define VGCF_in_syscall (1<<_VGCF_in_syscall)
+#define VGCF_IN_SYSCALL VGCF_in_syscall
+
+#ifndef __ASSEMBLY__
+
+struct iret_context {
+ /* Top of stack (%rsp at point of hypercall). */
+ uint64_t rax, r11, rcx, flags, rip, cs, rflags, rsp, ss;
+ /* Bottom of iret stack frame. */
+};
+
+#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
+/* Anonymous union includes both 32- and 64-bit names (e.g., eax/rax). */
+#define __DECL_REG(name) union { \
+ uint64_t r ## name, e ## name; \
+ uint32_t _e ## name; \
+}
+#else
+/* Non-gcc sources must always use the proper 64-bit name (e.g., rax). */
+#define __DECL_REG(name) uint64_t r ## name
+#endif
+
+struct cpu_user_regs {
+ uint64_t r15;
+ uint64_t r14;
+ uint64_t r13;
+ uint64_t r12;
+ __DECL_REG(bp);
+ __DECL_REG(bx);
+ uint64_t r11;
+ uint64_t r10;
+ uint64_t r9;
+ uint64_t r8;
+ __DECL_REG(ax);
+ __DECL_REG(cx);
+ __DECL_REG(dx);
+ __DECL_REG(si);
+ __DECL_REG(di);
+ uint32_t error_code; /* private */
+ uint32_t entry_vector; /* private */
+ __DECL_REG(ip);
+ uint16_t cs, _pad0[1];
+ uint8_t saved_upcall_mask;
+ uint8_t _pad1[3];
+ __DECL_REG(flags); /* rflags.IF == !saved_upcall_mask */
+ __DECL_REG(sp);
+ uint16_t ss, _pad2[3];
+ uint16_t es, _pad3[3];
+ uint16_t ds, _pad4[3];
+ uint16_t fs, _pad5[3]; /* Non-zero => takes precedence over fs_base. */
+ uint16_t gs, _pad6[3]; /* Non-zero => takes precedence over gs_base_usr. */
+};
+typedef struct cpu_user_regs cpu_user_regs_t;
+DEFINE_XEN_GUEST_HANDLE(cpu_user_regs_t);
+
+#undef __DECL_REG
+
+#define xen_pfn_to_cr3(pfn) ((unsigned long)(pfn) << 12)
+#define xen_cr3_to_pfn(cr3) ((unsigned long)(cr3) >> 12)
+
+struct arch_vcpu_info {
+ unsigned long cr2;
+ unsigned long pad; /* sizeof(vcpu_info_t) == 64 */
+};
+typedef struct arch_vcpu_info arch_vcpu_info_t;
+
+typedef unsigned long xen_callback_t;
+
+#endif /* !__ASSEMBLY__ */
+
+#endif /* __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/include/xen/arch-x86/xen.h b/include/xen/arch-x86/xen.h
new file mode 100644
index 0000000..56be26c
--- /dev/null
+++ b/include/xen/arch-x86/xen.h
@@ -0,0 +1,280 @@
+/******************************************************************************
+ * arch-x86/xen.h
+ *
+ * Guest OS interface to x86 Xen.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright (c) 2004-2006, K A Fraser
+ */
+
+#include "../xen.h"
+
+#ifndef __XEN_PUBLIC_ARCH_X86_XEN_H__
+#define __XEN_PUBLIC_ARCH_X86_XEN_H__
+
+/* Structural guest handles introduced in 0x00030201. */
+#if __XEN_INTERFACE_VERSION__ >= 0x00030201
+#define ___DEFINE_XEN_GUEST_HANDLE(name, type) \
+ typedef struct { type *p; } __guest_handle_ ## name
+#else
+#define ___DEFINE_XEN_GUEST_HANDLE(name, type) \
+ typedef type * __guest_handle_ ## name
+#endif
+
+/*
+ * XEN_GUEST_HANDLE represents a guest pointer, when passed as a field
+ * in a struct in memory.
+ * XEN_GUEST_HANDLE_PARAM represent a guest pointer, when passed as an
+ * hypercall argument.
+ * XEN_GUEST_HANDLE_PARAM and XEN_GUEST_HANDLE are the same on X86 but
+ * they might not be on other architectures.
+ */
+#define __DEFINE_XEN_GUEST_HANDLE(name, type) \
+ ___DEFINE_XEN_GUEST_HANDLE(name, type); \
+ ___DEFINE_XEN_GUEST_HANDLE(const_##name, const type)
+#define DEFINE_XEN_GUEST_HANDLE(name) __DEFINE_XEN_GUEST_HANDLE(name, name)
+#define __XEN_GUEST_HANDLE(name) __guest_handle_ ## name
+#define XEN_GUEST_HANDLE(name) __XEN_GUEST_HANDLE(name)
+#define XEN_GUEST_HANDLE_PARAM(name) XEN_GUEST_HANDLE(name)
+#define set_xen_guest_handle_raw(hnd, val) do { (hnd).p = val; } while (0)
+#ifdef __XEN_TOOLS__
+#define get_xen_guest_handle(val, hnd) do { val = (hnd).p; } while (0)
+#endif
+#define set_xen_guest_handle(hnd, val) set_xen_guest_handle_raw(hnd, val)
+
+#if defined(__i386__)
+#include "xen-x86_32.h"
+#elif defined(__x86_64__)
+#include "xen-x86_64.h"
+#endif
+
+#ifndef __ASSEMBLY__
+typedef unsigned long xen_pfn_t;
+#define PRI_xen_pfn "lx"
+#endif
+
+#define XEN_HAVE_PV_GUEST_ENTRY 1
+
+#define XEN_HAVE_PV_UPCALL_MASK 1
+
+/*
+ * `incontents 200 segdesc Segment Descriptor Tables
+ */
+/*
+ * ` enum neg_errnoval
+ * ` HYPERVISOR_set_gdt(const xen_pfn_t frames[], unsigned int entries);
+ * `
+ */
+/*
+ * A number of GDT entries are reserved by Xen. These are not situated at the
+ * start of the GDT because some stupid OSes export hard-coded selector values
+ * in their ABI. These hard-coded values are always near the start of the GDT,
+ * so Xen places itself out of the way, at the far end of the GDT.
+ *
+ * NB The LDT is set using the MMUEXT_SET_LDT op of HYPERVISOR_mmuext_op
+ */
+#define FIRST_RESERVED_GDT_PAGE 14
+#define FIRST_RESERVED_GDT_BYTE (FIRST_RESERVED_GDT_PAGE * 4096)
+#define FIRST_RESERVED_GDT_ENTRY (FIRST_RESERVED_GDT_BYTE / 8)
+
+
+/*
+ * ` enum neg_errnoval
+ * ` HYPERVISOR_update_descriptor(u64 pa, u64 desc);
+ * `
+ * ` @pa The machine physical address of the descriptor to
+ * ` update. Must be either a descriptor page or writable.
+ * ` @desc The descriptor value to update, in the same format as a
+ * ` native descriptor table entry.
+ */
+
+/* Maximum number of virtual CPUs in legacy multi-processor guests. */
+#define XEN_LEGACY_MAX_VCPUS 32
+
+#ifndef __ASSEMBLY__
+
+typedef unsigned long xen_ulong_t;
+#define PRI_xen_ulong "lx"
+
+/*
+ * ` enum neg_errnoval
+ * ` HYPERVISOR_stack_switch(unsigned long ss, unsigned long esp);
+ * `
+ * Sets the stack segment and pointer for the current vcpu.
+ */
+
+/*
+ * ` enum neg_errnoval
+ * ` HYPERVISOR_set_trap_table(const struct trap_info traps[]);
+ * `
+ */
+/*
+ * Send an array of these to HYPERVISOR_set_trap_table().
+ * Terminate the array with a sentinel entry, with traps[].address==0.
+ * The privilege level specifies which modes may enter a trap via a software
+ * interrupt. On x86/64, since rings 1 and 2 are unavailable, we allocate
+ * privilege levels as follows:
+ * Level == 0: Noone may enter
+ * Level == 1: Kernel may enter
+ * Level == 2: Kernel may enter
+ * Level == 3: Everyone may enter
+ */
+#define TI_GET_DPL(_ti) ((_ti)->flags & 3)
+#define TI_GET_IF(_ti) ((_ti)->flags & 4)
+#define TI_SET_DPL(_ti,_dpl) ((_ti)->flags |= (_dpl))
+#define TI_SET_IF(_ti,_if) ((_ti)->flags |= ((!!(_if))<<2))
+struct trap_info {
+ uint8_t vector; /* exception vector */
+ uint8_t flags; /* 0-3: privilege level; 4: clear event enable? */
+ uint16_t cs; /* code selector */
+ unsigned long address; /* code offset */
+};
+typedef struct trap_info trap_info_t;
+DEFINE_XEN_GUEST_HANDLE(trap_info_t);
+
+typedef uint64_t tsc_timestamp_t; /* RDTSC timestamp */
+
+/*
+ * The following is all CPU context. Note that the fpu_ctxt block is filled
+ * in by FXSAVE if the CPU has feature FXSR; otherwise FSAVE is used.
+ *
+ * Also note that when calling DOMCTL_setvcpucontext and VCPU_initialise
+ * for HVM and PVH guests, not all information in this structure is updated:
+ *
+ * - For HVM guests, the structures read include: fpu_ctxt (if
+ * VGCT_I387_VALID is set), flags, user_regs, debugreg[*]
+ *
+ * - PVH guests are the same as HVM guests, but additionally use ctrlreg[3] to
+ * set cr3. All other fields not used should be set to 0.
+ */
+struct vcpu_guest_context {
+ /* FPU registers come first so they can be aligned for FXSAVE/FXRSTOR. */
+ struct { char x[512]; } fpu_ctxt; /* User-level FPU registers */
+#define VGCF_I387_VALID (1<<0)
+#define VGCF_IN_KERNEL (1<<2)
+#define _VGCF_i387_valid 0
+#define VGCF_i387_valid (1<<_VGCF_i387_valid)
+#define _VGCF_in_kernel 2
+#define VGCF_in_kernel (1<<_VGCF_in_kernel)
+#define _VGCF_failsafe_disables_events 3
+#define VGCF_failsafe_disables_events (1<<_VGCF_failsafe_disables_events)
+#define _VGCF_syscall_disables_events 4
+#define VGCF_syscall_disables_events (1<<_VGCF_syscall_disables_events)
+#define _VGCF_online 5
+#define VGCF_online (1<<_VGCF_online)
+ unsigned long flags; /* VGCF_* flags */
+ struct cpu_user_regs user_regs; /* User-level CPU registers */
+ struct trap_info trap_ctxt[256]; /* Virtual IDT */
+ unsigned long ldt_base, ldt_ents; /* LDT (linear address, # ents) */
+ unsigned long gdt_frames[16], gdt_ents; /* GDT (machine frames, # ents) */
+ unsigned long kernel_ss, kernel_sp; /* Virtual TSS (only SS1/SP1) */
+ /* NB. User pagetable on x86/64 is placed in ctrlreg[1]. */
+ unsigned long ctrlreg[8]; /* CR0-CR7 (control registers) */
+ unsigned long debugreg[8]; /* DB0-DB7 (debug registers) */
+#ifdef __i386__
+ unsigned long event_callback_cs; /* CS:EIP of event callback */
+ unsigned long event_callback_eip;
+ unsigned long failsafe_callback_cs; /* CS:EIP of failsafe callback */
+ unsigned long failsafe_callback_eip;
+#else
+ unsigned long event_callback_eip;
+ unsigned long failsafe_callback_eip;
+#ifdef __XEN__
+ union {
+ unsigned long syscall_callback_eip;
+ struct {
+ unsigned int event_callback_cs; /* compat CS of event cb */
+ unsigned int failsafe_callback_cs; /* compat CS of failsafe cb */
+ };
+ };
+#else
+ unsigned long syscall_callback_eip;
+#endif
+#endif
+ unsigned long vm_assist; /* VMASST_TYPE_* bitmap */
+#ifdef __x86_64__
+ /* Segment base addresses. */
+ uint64_t fs_base;
+ uint64_t gs_base_kernel;
+ uint64_t gs_base_user;
+#endif
+};
+typedef struct vcpu_guest_context vcpu_guest_context_t;
+DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);
+
+struct arch_shared_info {
+ unsigned long max_pfn; /* max pfn that appears in table */
+ /* Frame containing list of mfns containing list of mfns containing p2m. */
+ xen_pfn_t pfn_to_mfn_frame_list_list;
+ unsigned long nmi_reason;
+ uint64_t pad[32];
+};
+typedef struct arch_shared_info arch_shared_info_t;
+
+#endif /* !__ASSEMBLY__ */
+
+/*
+ * ` enum neg_errnoval
+ * ` HYPERVISOR_fpu_taskswitch(int set);
+ * `
+ * Sets (if set!=0) or clears (if set==0) CR0.TS.
+ */
+
+/*
+ * ` enum neg_errnoval
+ * ` HYPERVISOR_set_debugreg(int regno, unsigned long value);
+ *
+ * ` unsigned long
+ * ` HYPERVISOR_get_debugreg(int regno);
+ * For 0<=reg<=7, returns the debug register value.
+ * For other values of reg, returns ((unsigned long)-EINVAL).
+ * (Unfortunately, this interface is defective.)
+ */
+
+/*
+ * Prefix forces emulation of some non-trapping instructions.
+ * Currently only CPUID.
+ */
+#ifdef __ASSEMBLY__
+#define XEN_EMULATE_PREFIX .byte 0x0f,0x0b,0x78,0x65,0x6e ;
+#define XEN_CPUID XEN_EMULATE_PREFIX cpuid
+#else
+#define XEN_EMULATE_PREFIX ".byte 0x0f,0x0b,0x78,0x65,0x6e ; "
+#define XEN_CPUID XEN_EMULATE_PREFIX "cpuid"
+#endif
+
+/*
+ * Debug console IO port, also called "port E9 hack". Each character written
+ * to this IO port will be printed on the hypervisor console, subject to log
+ * level restrictions.
+ */
+#define XEN_HVM_DEBUGCONS_IOPORT 0xe9
+
+#endif /* __XEN_PUBLIC_ARCH_X86_XEN_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/include/xen/elfnote.h b/include/xen/elfnote.h
new file mode 100644
index 0000000..71cd4ec
--- /dev/null
+++ b/include/xen/elfnote.h
@@ -0,0 +1,281 @@
+/******************************************************************************
+ * elfnote.h
+ *
+ * Definitions used for the Xen ELF notes.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright (c) 2006, Ian Campbell, XenSource Ltd.
+ */
+
+#ifndef __XEN_PUBLIC_ELFNOTE_H__
+#define __XEN_PUBLIC_ELFNOTE_H__
+
+/*
+ * `incontents 200 elfnotes ELF notes
+ *
+ * The notes should live in a PT_NOTE segment and have "Xen" in the
+ * name field.
+ *
+ * Numeric types are either 4 or 8 bytes depending on the content of
+ * the desc field.
+ *
+ * LEGACY indicated the fields in the legacy __xen_guest string which
+ * this a note type replaces.
+ *
+ * String values (for non-legacy) are NULL terminated ASCII, also known
+ * as ASCIZ type.
+ */
+
+/*
+ * NAME=VALUE pair (string).
+ */
+#define XEN_ELFNOTE_INFO 0
+
+/*
+ * The virtual address of the entry point (numeric).
+ *
+ * LEGACY: VIRT_ENTRY
+ */
+#define XEN_ELFNOTE_ENTRY 1
+
+/* The virtual address of the hypercall transfer page (numeric).
+ *
+ * LEGACY: HYPERCALL_PAGE. (n.b. legacy value is a physical page
+ * number not a virtual address)
+ */
+#define XEN_ELFNOTE_HYPERCALL_PAGE 2
+
+/* The virtual address where the kernel image should be mapped (numeric).
+ *
+ * Defaults to 0.
+ *
+ * LEGACY: VIRT_BASE
+ */
+#define XEN_ELFNOTE_VIRT_BASE 3
+
+/*
+ * The offset of the ELF paddr field from the actual required
+ * pseudo-physical address (numeric).
+ *
+ * This is used to maintain backwards compatibility with older kernels
+ * which wrote __PAGE_OFFSET into that field. This field defaults to 0
+ * if not present.
+ *
+ * LEGACY: ELF_PADDR_OFFSET. (n.b. legacy default is VIRT_BASE)
+ */
+#define XEN_ELFNOTE_PADDR_OFFSET 4
+
+/*
+ * The version of Xen that we work with (string).
+ *
+ * LEGACY: XEN_VER
+ */
+#define XEN_ELFNOTE_XEN_VERSION 5
+
+/*
+ * The name of the guest operating system (string).
+ *
+ * LEGACY: GUEST_OS
+ */
+#define XEN_ELFNOTE_GUEST_OS 6
+
+/*
+ * The version of the guest operating system (string).
+ *
+ * LEGACY: GUEST_VER
+ */
+#define XEN_ELFNOTE_GUEST_VERSION 7
+
+/*
+ * The loader type (string).
+ *
+ * LEGACY: LOADER
+ */
+#define XEN_ELFNOTE_LOADER 8
+
+/*
+ * The kernel supports PAE (x86/32 only, string = "yes", "no" or
+ * "bimodal").
+ *
+ * For compatibility with Xen 3.0.3 and earlier the "bimodal" setting
+ * may be given as "yes,bimodal" which will cause older Xen to treat
+ * this kernel as PAE.
+ *
+ * LEGACY: PAE (n.b. The legacy interface included a provision to
+ * indicate 'extended-cr3' support allowing L3 page tables to be
+ * placed above 4G. It is assumed that any kernel new enough to use
+ * these ELF notes will include this and therefore "yes" here is
+ * equivalent to "yes[entended-cr3]" in the __xen_guest interface.
+ */
+#define XEN_ELFNOTE_PAE_MODE 9
+
+/*
+ * The features supported/required by this kernel (string).
+ *
+ * The string must consist of a list of feature names (as given in
+ * features.h, without the "XENFEAT_" prefix) separated by '|'
+ * characters. If a feature is required for the kernel to function
+ * then the feature name must be preceded by a '!' character.
+ *
+ * LEGACY: FEATURES
+ */
+#define XEN_ELFNOTE_FEATURES 10
+
+/*
+ * The kernel requires the symbol table to be loaded (string = "yes" or "no")
+ * LEGACY: BSD_SYMTAB (n.b. The legacy treated the presence or absence
+ * of this string as a boolean flag rather than requiring "yes" or
+ * "no".
+ */
+#define XEN_ELFNOTE_BSD_SYMTAB 11
+
+/*
+ * The lowest address the hypervisor hole can begin at (numeric).
+ *
+ * This must not be set higher than HYPERVISOR_VIRT_START. Its presence
+ * also indicates to the hypervisor that the kernel can deal with the
+ * hole starting at a higher address.
+ */
+#define XEN_ELFNOTE_HV_START_LOW 12
+
+/*
+ * List of maddr_t-sized mask/value pairs describing how to recognize
+ * (non-present) L1 page table entries carrying valid MFNs (numeric).
+ */
+#define XEN_ELFNOTE_L1_MFN_VALID 13
+
+/*
+ * Whether or not the guest supports cooperative suspend cancellation.
+ * This is a numeric value.
+ *
+ * Default is 0
+ */
+#define XEN_ELFNOTE_SUSPEND_CANCEL 14
+
+/*
+ * The (non-default) location the initial phys-to-machine map should be
+ * placed at by the hypervisor (Dom0) or the tools (DomU).
+ * The kernel must be prepared for this mapping to be established using
+ * large pages, despite such otherwise not being available to guests.
+ * The kernel must also be able to handle the page table pages used for
+ * this mapping not being accessible through the initial mapping.
+ * (Only x86-64 supports this at present.)
+ */
+#define XEN_ELFNOTE_INIT_P2M 15
+
+/*
+ * Whether or not the guest can deal with being passed an initrd not
+ * mapped through its initial page tables.
+ */
+#define XEN_ELFNOTE_MOD_START_PFN 16
+
+/*
+ * The features supported by this kernel (numeric).
+ *
+ * Other than XEN_ELFNOTE_FEATURES on pre-4.2 Xen, this note allows a
+ * kernel to specify support for features that older hypervisors don't
+ * know about. The set of features 4.2 and newer hypervisors will
+ * consider supported by the kernel is the combination of the sets
+ * specified through this and the string note.
+ *
+ * LEGACY: FEATURES
+ */
+#define XEN_ELFNOTE_SUPPORTED_FEATURES 17
+
+/*
+ * Physical entry point into the kernel.
+ *
+ * 32bit entry point into the kernel. When requested to launch the
+ * guest kernel in a HVM container, Xen will use this entry point to
+ * launch the guest in 32bit protected mode with paging disabled.
+ * Ignored otherwise.
+ */
+#define XEN_ELFNOTE_PHYS32_ENTRY 18
+
+/*
+ * The number of the highest elfnote defined.
+ */
+#define XEN_ELFNOTE_MAX XEN_ELFNOTE_PHYS32_ENTRY
+
+/*
+ * System information exported through crash notes.
+ *
+ * The kexec / kdump code will create one XEN_ELFNOTE_CRASH_INFO
+ * note in case of a system crash. This note will contain various
+ * information about the system, see xen/include/xen/elfcore.h.
+ */
+#define XEN_ELFNOTE_CRASH_INFO 0x1000001
+
+/*
+ * System registers exported through crash notes.
+ *
+ * The kexec / kdump code will create one XEN_ELFNOTE_CRASH_REGS
+ * note per cpu in case of a system crash. This note is architecture
+ * specific and will contain registers not saved in the "CORE" note.
+ * See xen/include/xen/elfcore.h for more information.
+ */
+#define XEN_ELFNOTE_CRASH_REGS 0x1000002
+
+
+/*
+ * xen dump-core none note.
+ * xm dump-core code will create one XEN_ELFNOTE_DUMPCORE_NONE
+ * in its dump file to indicate that the file is xen dump-core
+ * file. This note doesn't have any other information.
+ * See tools/libxc/xc_core.h for more information.
+ */
+#define XEN_ELFNOTE_DUMPCORE_NONE 0x2000000
+
+/*
+ * xen dump-core header note.
+ * xm dump-core code will create one XEN_ELFNOTE_DUMPCORE_HEADER
+ * in its dump file.
+ * See tools/libxc/xc_core.h for more information.
+ */
+#define XEN_ELFNOTE_DUMPCORE_HEADER 0x2000001
+
+/*
+ * xen dump-core xen version note.
+ * xm dump-core code will create one XEN_ELFNOTE_DUMPCORE_XEN_VERSION
+ * in its dump file. It contains the xen version obtained via the
+ * XENVER hypercall.
+ * See tools/libxc/xc_core.h for more information.
+ */
+#define XEN_ELFNOTE_DUMPCORE_XEN_VERSION 0x2000002
+
+/*
+ * xen dump-core format version note.
+ * xm dump-core code will create one XEN_ELFNOTE_DUMPCORE_FORMAT_VERSION
+ * in its dump file. It contains a format version identifier.
+ * See tools/libxc/xc_core.h for more information.
+ */
+#define XEN_ELFNOTE_DUMPCORE_FORMAT_VERSION 0x2000003
+
+#endif /* __XEN_PUBLIC_ELFNOTE_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/include/xen/event_channel.h b/include/xen/event_channel.h
new file mode 100644
index 0000000..49ac8cc
--- /dev/null
+++ b/include/xen/event_channel.h
@@ -0,0 +1,381 @@
+/******************************************************************************
+ * event_channel.h
+ *
+ * Event channels between domains.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright (c) 2003-2004, K A Fraser.
+ */
+
+#ifndef __XEN_PUBLIC_EVENT_CHANNEL_H__
+#define __XEN_PUBLIC_EVENT_CHANNEL_H__
+
+#include "xen.h"
+
+/*
+ * `incontents 150 evtchn Event Channels
+ *
+ * Event channels are the basic primitive provided by Xen for event
+ * notifications. An event is the Xen equivalent of a hardware
+ * interrupt. They essentially store one bit of information, the event
+ * of interest is signalled by transitioning this bit from 0 to 1.
+ *
+ * Notifications are received by a guest via an upcall from Xen,
+ * indicating when an event arrives (setting the bit). Further
+ * notifications are masked until the bit is cleared again (therefore,
+ * guests must check the value of the bit after re-enabling event
+ * delivery to ensure no missed notifications).
+ *
+ * Event notifications can be masked by setting a flag; this is
+ * equivalent to disabling interrupts and can be used to ensure
+ * atomicity of certain operations in the guest kernel.
+ *
+ * Event channels are represented by the evtchn_* fields in
+ * struct shared_info and struct vcpu_info.
+ */
+
+/*
+ * ` enum neg_errnoval
+ * ` HYPERVISOR_event_channel_op(enum event_channel_op cmd, void *args)
+ * `
+ * @cmd == EVTCHNOP_* (event-channel operation).
+ * @args == struct evtchn_* Operation-specific extra arguments (NULL if none).
+ */
+
+/* ` enum event_channel_op { // EVTCHNOP_* => struct evtchn_* */
+#define EVTCHNOP_bind_interdomain 0
+#define EVTCHNOP_bind_virq 1
+#define EVTCHNOP_bind_pirq 2
+#define EVTCHNOP_close 3
+#define EVTCHNOP_send 4
+#define EVTCHNOP_status 5
+#define EVTCHNOP_alloc_unbound 6
+#define EVTCHNOP_bind_ipi 7
+#define EVTCHNOP_bind_vcpu 8
+#define EVTCHNOP_unmask 9
+#define EVTCHNOP_reset 10
+#define EVTCHNOP_init_control 11
+#define EVTCHNOP_expand_array 12
+#define EVTCHNOP_set_priority 13
+/* ` } */
+
+typedef uint32_t evtchn_port_t;
+DEFINE_XEN_GUEST_HANDLE(evtchn_port_t);
+
+/*
+ * EVTCHNOP_alloc_unbound: Allocate a port in domain <dom> and mark as
+ * accepting interdomain bindings from domain <remote_dom>. A fresh port
+ * is allocated in <dom> and returned as <port>.
+ * NOTES:
+ * 1. If the caller is unprivileged then <dom> must be DOMID_SELF.
+ * 2. <rdom> may be DOMID_SELF, allowing loopback connections.
+ */
+struct evtchn_alloc_unbound {
+ /* IN parameters */
+ domid_t dom, remote_dom;
+ /* OUT parameters */
+ evtchn_port_t port;
+};
+typedef struct evtchn_alloc_unbound evtchn_alloc_unbound_t;
+
+/*
+ * EVTCHNOP_bind_interdomain: Construct an interdomain event channel between
+ * the calling domain and <remote_dom>. <remote_dom,remote_port> must identify
+ * a port that is unbound and marked as accepting bindings from the calling
+ * domain. A fresh port is allocated in the calling domain and returned as
+ * <local_port>.
+ *
+ * In case the peer domain has already tried to set our event channel
+ * pending, before it was bound, EVTCHNOP_bind_interdomain always sets
+ * the local event channel pending.
+ *
+ * The usual pattern of use, in the guest's upcall (or subsequent
+ * handler) is as follows: (Re-enable the event channel for subsequent
+ * signalling and then) check for the existence of whatever condition
+ * is being waited for by other means, and take whatever action is
+ * needed (if any).
+ *
+ * NOTES:
+ * 1. <remote_dom> may be DOMID_SELF, allowing loopback connections.
+ */
+struct evtchn_bind_interdomain {
+ /* IN parameters. */
+ domid_t remote_dom;
+ evtchn_port_t remote_port;
+ /* OUT parameters. */
+ evtchn_port_t local_port;
+};
+typedef struct evtchn_bind_interdomain evtchn_bind_interdomain_t;
+
+/*
+ * EVTCHNOP_bind_virq: Bind a local event channel to VIRQ <irq> on specified
+ * vcpu.
+ * NOTES:
+ * 1. Virtual IRQs are classified as per-vcpu or global. See the VIRQ list
+ * in xen.h for the classification of each VIRQ.
+ * 2. Global VIRQs must be allocated on VCPU0 but can subsequently be
+ * re-bound via EVTCHNOP_bind_vcpu.
+ * 3. Per-vcpu VIRQs may be bound to at most one event channel per vcpu.
+ * The allocated event channel is bound to the specified vcpu and the
+ * binding cannot be changed.
+ */
+struct evtchn_bind_virq {
+ /* IN parameters. */
+ uint32_t virq; /* enum virq */
+ uint32_t vcpu;
+ /* OUT parameters. */
+ evtchn_port_t port;
+};
+typedef struct evtchn_bind_virq evtchn_bind_virq_t;
+
+/*
+ * EVTCHNOP_bind_pirq: Bind a local event channel to a real IRQ (PIRQ <irq>).
+ * NOTES:
+ * 1. A physical IRQ may be bound to at most one event channel per domain.
+ * 2. Only a sufficiently-privileged domain may bind to a physical IRQ.
+ */
+struct evtchn_bind_pirq {
+ /* IN parameters. */
+ uint32_t pirq;
+#define BIND_PIRQ__WILL_SHARE 1
+ uint32_t flags; /* BIND_PIRQ__* */
+ /* OUT parameters. */
+ evtchn_port_t port;
+};
+typedef struct evtchn_bind_pirq evtchn_bind_pirq_t;
+
+/*
+ * EVTCHNOP_bind_ipi: Bind a local event channel to receive events.
+ * NOTES:
+ * 1. The allocated event channel is bound to the specified vcpu. The binding
+ * may not be changed.
+ */
+struct evtchn_bind_ipi {
+ uint32_t vcpu;
+ /* OUT parameters. */
+ evtchn_port_t port;
+};
+typedef struct evtchn_bind_ipi evtchn_bind_ipi_t;
+
+/*
+ * EVTCHNOP_close: Close a local event channel <port>. If the channel is
+ * interdomain then the remote end is placed in the unbound state
+ * (EVTCHNSTAT_unbound), awaiting a new connection.
+ */
+struct evtchn_close {
+ /* IN parameters. */
+ evtchn_port_t port;
+};
+typedef struct evtchn_close evtchn_close_t;
+
+/*
+ * EVTCHNOP_send: Send an event to the remote end of the channel whose local
+ * endpoint is <port>.
+ */
+struct evtchn_send {
+ /* IN parameters. */
+ evtchn_port_t port;
+};
+typedef struct evtchn_send evtchn_send_t;
+
+/*
+ * EVTCHNOP_status: Get the current status of the communication channel which
+ * has an endpoint at <dom, port>.
+ * NOTES:
+ * 1. <dom> may be specified as DOMID_SELF.
+ * 2. Only a sufficiently-privileged domain may obtain the status of an event
+ * channel for which <dom> is not DOMID_SELF.
+ */
+struct evtchn_status {
+ /* IN parameters */
+ domid_t dom;
+ evtchn_port_t port;
+ /* OUT parameters */
+#define EVTCHNSTAT_closed 0 /* Channel is not in use. */
+#define EVTCHNSTAT_unbound 1 /* Channel is waiting interdom connection.*/
+#define EVTCHNSTAT_interdomain 2 /* Channel is connected to remote domain. */
+#define EVTCHNSTAT_pirq 3 /* Channel is bound to a phys IRQ line. */
+#define EVTCHNSTAT_virq 4 /* Channel is bound to a virtual IRQ line */
+#define EVTCHNSTAT_ipi 5 /* Channel is bound to a virtual IPI line */
+ uint32_t status;
+ uint32_t vcpu; /* VCPU to which this channel is bound. */
+ union {
+ struct {
+ domid_t dom;
+ } unbound; /* EVTCHNSTAT_unbound */
+ struct {
+ domid_t dom;
+ evtchn_port_t port;
+ } interdomain; /* EVTCHNSTAT_interdomain */
+ uint32_t pirq; /* EVTCHNSTAT_pirq */
+ uint32_t virq; /* EVTCHNSTAT_virq */
+ } u;
+};
+typedef struct evtchn_status evtchn_status_t;
+
+/*
+ * EVTCHNOP_bind_vcpu: Specify which vcpu a channel should notify when an
+ * event is pending.
+ * NOTES:
+ * 1. IPI-bound channels always notify the vcpu specified at bind time.
+ * This binding cannot be changed.
+ * 2. Per-VCPU VIRQ channels always notify the vcpu specified at bind time.
+ * This binding cannot be changed.
+ * 3. All other channels notify vcpu0 by default. This default is set when
+ * the channel is allocated (a port that is freed and subsequently reused
+ * has its binding reset to vcpu0).
+ */
+struct evtchn_bind_vcpu {
+ /* IN parameters. */
+ evtchn_port_t port;
+ uint32_t vcpu;
+};
+typedef struct evtchn_bind_vcpu evtchn_bind_vcpu_t;
+
+/*
+ * EVTCHNOP_unmask: Unmask the specified local event-channel port and deliver
+ * a notification to the appropriate VCPU if an event is pending.
+ */
+struct evtchn_unmask {
+ /* IN parameters. */
+ evtchn_port_t port;
+};
+typedef struct evtchn_unmask evtchn_unmask_t;
+
+/*
+ * EVTCHNOP_reset: Close all event channels associated with specified domain.
+ * NOTES:
+ * 1. <dom> may be specified as DOMID_SELF.
+ * 2. Only a sufficiently-privileged domain may specify other than DOMID_SELF.
+ */
+struct evtchn_reset {
+ /* IN parameters. */
+ domid_t dom;
+};
+typedef struct evtchn_reset evtchn_reset_t;
+
+/*
+ * EVTCHNOP_init_control: initialize the control block for the FIFO ABI.
+ *
+ * Note: any events that are currently pending will not be resent and
+ * will be lost. Guests should call this before binding any event to
+ * avoid losing any events.
+ */
+struct evtchn_init_control {
+ /* IN parameters. */
+ uint64_t control_gfn;
+ uint32_t offset;
+ uint32_t vcpu;
+ /* OUT parameters. */
+ uint8_t link_bits;
+ uint8_t _pad[7];
+};
+typedef struct evtchn_init_control evtchn_init_control_t;
+
+/*
+ * EVTCHNOP_expand_array: add an additional page to the event array.
+ */
+struct evtchn_expand_array {
+ /* IN parameters. */
+ uint64_t array_gfn;
+};
+typedef struct evtchn_expand_array evtchn_expand_array_t;
+
+/*
+ * EVTCHNOP_set_priority: set the priority for an event channel.
+ */
+struct evtchn_set_priority {
+ /* IN parameters. */
+ uint32_t port;
+ uint32_t priority;
+};
+typedef struct evtchn_set_priority evtchn_set_priority_t;
+
+/*
+ * ` enum neg_errnoval
+ * ` HYPERVISOR_event_channel_op_compat(struct evtchn_op *op)
+ * `
+ * Superceded by new event_channel_op() hypercall since 0x00030202.
+ */
+struct evtchn_op {
+ uint32_t cmd; /* enum event_channel_op */
+ union {
+ struct evtchn_alloc_unbound alloc_unbound;
+ struct evtchn_bind_interdomain bind_interdomain;
+ struct evtchn_bind_virq bind_virq;
+ struct evtchn_bind_pirq bind_pirq;
+ struct evtchn_bind_ipi bind_ipi;
+ struct evtchn_close close;
+ struct evtchn_send send;
+ struct evtchn_status status;
+ struct evtchn_bind_vcpu bind_vcpu;
+ struct evtchn_unmask unmask;
+ } u;
+};
+typedef struct evtchn_op evtchn_op_t;
+DEFINE_XEN_GUEST_HANDLE(evtchn_op_t);
+
+/*
+ * 2-level ABI
+ */
+
+#define EVTCHN_2L_NR_CHANNELS (sizeof(xen_ulong_t) * sizeof(xen_ulong_t) * 64)
+
+/*
+ * FIFO ABI
+ */
+
+/* Events may have priorities from 0 (highest) to 15 (lowest). */
+#define EVTCHN_FIFO_PRIORITY_MAX 0
+#define EVTCHN_FIFO_PRIORITY_DEFAULT 7
+#define EVTCHN_FIFO_PRIORITY_MIN 15
+
+#define EVTCHN_FIFO_MAX_QUEUES (EVTCHN_FIFO_PRIORITY_MIN + 1)
+
+typedef uint32_t event_word_t;
+
+#define EVTCHN_FIFO_PENDING 31
+#define EVTCHN_FIFO_MASKED 30
+#define EVTCHN_FIFO_LINKED 29
+#define EVTCHN_FIFO_BUSY 28
+
+#define EVTCHN_FIFO_LINK_BITS 17
+#define EVTCHN_FIFO_LINK_MASK ((1 << EVTCHN_FIFO_LINK_BITS) - 1)
+
+#define EVTCHN_FIFO_NR_CHANNELS (1 << EVTCHN_FIFO_LINK_BITS)
+
+struct evtchn_fifo_control_block {
+ uint32_t ready;
+ uint32_t _rsvd;
+ uint32_t head[EVTCHN_FIFO_MAX_QUEUES];
+};
+typedef struct evtchn_fifo_control_block evtchn_fifo_control_block_t;
+
+#endif /* __XEN_PUBLIC_EVENT_CHANNEL_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/include/xen/grant_table.h b/include/xen/grant_table.h
new file mode 100644
index 0000000..b8a3d6c
--- /dev/null
+++ b/include/xen/grant_table.h
@@ -0,0 +1,662 @@
+/******************************************************************************
+ * grant_table.h
+ *
+ * Interface for granting foreign access to page frames, and receiving
+ * page-ownership transfers.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright (c) 2004, K A Fraser
+ */
+
+#ifndef __XEN_PUBLIC_GRANT_TABLE_H__
+#define __XEN_PUBLIC_GRANT_TABLE_H__
+
+#include "xen.h"
+
+/*
+ * `incontents 150 gnttab Grant Tables
+ *
+ * Xen's grant tables provide a generic mechanism to memory sharing
+ * between domains. This shared memory interface underpins the split
+ * device drivers for block and network IO.
+ *
+ * Each domain has its own grant table. This is a data structure that
+ * is shared with Xen; it allows the domain to tell Xen what kind of
+ * permissions other domains have on its pages. Entries in the grant
+ * table are identified by grant references. A grant reference is an
+ * integer, which indexes into the grant table. It acts as a
+ * capability which the grantee can use to perform operations on the
+ * granter’s memory.
+ *
+ * This capability-based system allows shared-memory communications
+ * between unprivileged domains. A grant reference also encapsulates
+ * the details of a shared page, removing the need for a domain to
+ * know the real machine address of a page it is sharing. This makes
+ * it possible to share memory correctly with domains running in
+ * fully virtualised memory.
+ */
+
+/***********************************
+ * GRANT TABLE REPRESENTATION
+ */
+
+/* Some rough guidelines on accessing and updating grant-table entries
+ * in a concurrency-safe manner. For more information, Linux contains a
+ * reference implementation for guest OSes (drivers/xen/grant_table.c, see
+ * http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=drivers/xen/grant-table.c;hb=HEAD
+ *
+ * NB. WMB is a no-op on current-generation x86 processors. However, a
+ * compiler barrier will still be required.
+ *
+ * Introducing a valid entry into the grant table:
+ * 1. Write ent->domid.
+ * 2. Write ent->frame:
+ * GTF_permit_access: Frame to which access is permitted.
+ * GTF_accept_transfer: Pseudo-phys frame slot being filled by new
+ * frame, or zero if none.
+ * 3. Write memory barrier (WMB).
+ * 4. Write ent->flags, inc. valid type.
+ *
+ * Invalidating an unused GTF_permit_access entry:
+ * 1. flags = ent->flags.
+ * 2. Observe that !(flags & (GTF_reading|GTF_writing)).
+ * 3. Check result of SMP-safe CMPXCHG(&ent->flags, flags, 0).
+ * NB. No need for WMB as reuse of entry is control-dependent on success of
+ * step 3, and all architectures guarantee ordering of ctrl-dep writes.
+ *
+ * Invalidating an in-use GTF_permit_access entry:
+ * This cannot be done directly. Request assistance from the domain controller
+ * which can set a timeout on the use of a grant entry and take necessary
+ * action. (NB. This is not yet implemented!).
+ *
+ * Invalidating an unused GTF_accept_transfer entry:
+ * 1. flags = ent->flags.
+ * 2. Observe that !(flags & GTF_transfer_committed). [*]
+ * 3. Check result of SMP-safe CMPXCHG(&ent->flags, flags, 0).
+ * NB. No need for WMB as reuse of entry is control-dependent on success of
+ * step 3, and all architectures guarantee ordering of ctrl-dep writes.
+ * [*] If GTF_transfer_committed is set then the grant entry is 'committed'.
+ * The guest must /not/ modify the grant entry until the address of the
+ * transferred frame is written. It is safe for the guest to spin waiting
+ * for this to occur (detect by observing GTF_transfer_completed in
+ * ent->flags).
+ *
+ * Invalidating a committed GTF_accept_transfer entry:
+ * 1. Wait for (ent->flags & GTF_transfer_completed).
+ *
+ * Changing a GTF_permit_access from writable to read-only:
+ * Use SMP-safe CMPXCHG to set GTF_readonly, while checking !GTF_writing.
+ *
+ * Changing a GTF_permit_access from read-only to writable:
+ * Use SMP-safe bit-setting instruction.
+ */
+
+/*
+ * Reference to a grant entry in a specified domain's grant table.
+ */
+typedef uint32_t grant_ref_t;
+
+/*
+ * A grant table comprises a packed array of grant entries in one or more
+ * page frames shared between Xen and a guest.
+ * [XEN]: This field is written by Xen and read by the sharing guest.
+ * [GST]: This field is written by the guest and read by Xen.
+ */
+
+/*
+ * Version 1 of the grant table entry structure is maintained purely
+ * for backwards compatibility. New guests should use version 2.
+ */
+#if __XEN_INTERFACE_VERSION__ < 0x0003020a
+#define grant_entry_v1 grant_entry
+#define grant_entry_v1_t grant_entry_t
+#endif
+struct grant_entry_v1 {
+ /* GTF_xxx: various type and flag information. [XEN,GST] */
+ uint16_t flags;
+ /* The domain being granted foreign privileges. [GST] */
+ domid_t domid;
+ /*
+ * GTF_permit_access: Frame that @domid is allowed to map and access. [GST]
+ * GTF_accept_transfer: Frame whose ownership transferred by @domid. [XEN]
+ */
+ uint32_t frame;
+};
+typedef struct grant_entry_v1 grant_entry_v1_t;
+
+/* The first few grant table entries will be preserved across grant table
+ * version changes and may be pre-populated at domain creation by tools.
+ */
+#define GNTTAB_NR_RESERVED_ENTRIES 8
+#define GNTTAB_RESERVED_CONSOLE 0
+#define GNTTAB_RESERVED_XENSTORE 1
+
+/*
+ * Type of grant entry.
+ * GTF_invalid: This grant entry grants no privileges.
+ * GTF_permit_access: Allow @domid to map/access @frame.
+ * GTF_accept_transfer: Allow @domid to transfer ownership of one page frame
+ * to this guest. Xen writes the page number to @frame.
+ * GTF_transitive: Allow @domid to transitively access a subrange of
+ * @trans_grant in @trans_domid. No mappings are allowed.
+ */
+#define GTF_invalid (0U<<0)
+#define GTF_permit_access (1U<<0)
+#define GTF_accept_transfer (2U<<0)
+#define GTF_transitive (3U<<0)
+#define GTF_type_mask (3U<<0)
+
+/*
+ * Subflags for GTF_permit_access.
+ * GTF_readonly: Restrict @domid to read-only mappings and accesses. [GST]
+ * GTF_reading: Grant entry is currently mapped for reading by @domid. [XEN]
+ * GTF_writing: Grant entry is currently mapped for writing by @domid. [XEN]
+ * GTF_PAT, GTF_PWT, GTF_PCD: (x86) cache attribute flags for the grant [GST]
+ * GTF_sub_page: Grant access to only a subrange of the page. @domid
+ * will only be allowed to copy from the grant, and not
+ * map it. [GST]
+ */
+#define _GTF_readonly (2)
+#define GTF_readonly (1U<<_GTF_readonly)
+#define _GTF_reading (3)
+#define GTF_reading (1U<<_GTF_reading)
+#define _GTF_writing (4)
+#define GTF_writing (1U<<_GTF_writing)
+#define _GTF_PWT (5)
+#define GTF_PWT (1U<<_GTF_PWT)
+#define _GTF_PCD (6)
+#define GTF_PCD (1U<<_GTF_PCD)
+#define _GTF_PAT (7)
+#define GTF_PAT (1U<<_GTF_PAT)
+#define _GTF_sub_page (8)
+#define GTF_sub_page (1U<<_GTF_sub_page)
+
+/*
+ * Subflags for GTF_accept_transfer:
+ * GTF_transfer_committed: Xen sets this flag to indicate that it is committed
+ * to transferring ownership of a page frame. When a guest sees this flag
+ * it must /not/ modify the grant entry until GTF_transfer_completed is
+ * set by Xen.
+ * GTF_transfer_completed: It is safe for the guest to spin-wait on this flag
+ * after reading GTF_transfer_committed. Xen will always write the frame
+ * address, followed by ORing this flag, in a timely manner.
+ */
+#define _GTF_transfer_committed (2)
+#define GTF_transfer_committed (1U<<_GTF_transfer_committed)
+#define _GTF_transfer_completed (3)
+#define GTF_transfer_completed (1U<<_GTF_transfer_completed)
+
+/*
+ * Version 2 grant table entries. These fulfil the same role as
+ * version 1 entries, but can represent more complicated operations.
+ * Any given domain will have either a version 1 or a version 2 table,
+ * and every entry in the table will be the same version.
+ *
+ * The interface by which domains use grant references does not depend
+ * on the grant table version in use by the other domain.
+ */
+#if __XEN_INTERFACE_VERSION__ >= 0x0003020a
+/*
+ * Version 1 and version 2 grant entries share a common prefix. The
+ * fields of the prefix are documented as part of struct
+ * grant_entry_v1.
+ */
+struct grant_entry_header {
+ uint16_t flags;
+ domid_t domid;
+};
+typedef struct grant_entry_header grant_entry_header_t;
+
+/*
+ * Version 2 of the grant entry structure.
+ */
+union grant_entry_v2 {
+ grant_entry_header_t hdr;
+
+ /*
+ * This member is used for V1-style full page grants, where either:
+ *
+ * -- hdr.type is GTF_accept_transfer, or
+ * -- hdr.type is GTF_permit_access and GTF_sub_page is not set.
+ *
+ * In that case, the frame field has the same semantics as the
+ * field of the same name in the V1 entry structure.
+ */
+ struct {
+ grant_entry_header_t hdr;
+ uint32_t pad0;
+ uint64_t frame;
+ } full_page;
+
+ /*
+ * If the grant type is GTF_grant_access and GTF_sub_page is set,
+ * @domid is allowed to access bytes [@page_off,@page_off+@length)
+ * in frame @frame.
+ */
+ struct {
+ grant_entry_header_t hdr;
+ uint16_t page_off;
+ uint16_t length;
+ uint64_t frame;
+ } sub_page;
+
+ /*
+ * If the grant is GTF_transitive, @domid is allowed to use the
+ * grant @gref in domain @trans_domid, as if it was the local
+ * domain. Obviously, the transitive access must be compatible
+ * with the original grant.
+ *
+ * The current version of Xen does not allow transitive grants
+ * to be mapped.
+ */
+ struct {
+ grant_entry_header_t hdr;
+ domid_t trans_domid;
+ uint16_t pad0;
+ grant_ref_t gref;
+ } transitive;
+
+ uint32_t __spacer[4]; /* Pad to a power of two */
+};
+typedef union grant_entry_v2 grant_entry_v2_t;
+
+typedef uint16_t grant_status_t;
+
+#endif /* __XEN_INTERFACE_VERSION__ */
+
+/***********************************
+ * GRANT TABLE QUERIES AND USES
+ */
+
+/* ` enum neg_errnoval
+ * ` HYPERVISOR_grant_table_op(enum grant_table_op cmd,
+ * ` void *args,
+ * ` unsigned int count)
+ * `
+ *
+ * @args points to an array of a per-command data structure. The array
+ * has @count members
+ */
+
+/* ` enum grant_table_op { // GNTTABOP_* => struct gnttab_* */
+#define GNTTABOP_map_grant_ref 0
+#define GNTTABOP_unmap_grant_ref 1
+#define GNTTABOP_setup_table 2
+#define GNTTABOP_dump_table 3
+#define GNTTABOP_transfer 4
+#define GNTTABOP_copy 5
+#define GNTTABOP_query_size 6
+#define GNTTABOP_unmap_and_replace 7
+#if __XEN_INTERFACE_VERSION__ >= 0x0003020a
+#define GNTTABOP_set_version 8
+#define GNTTABOP_get_status_frames 9
+#define GNTTABOP_get_version 10
+#define GNTTABOP_swap_grant_ref 11
+#endif /* __XEN_INTERFACE_VERSION__ */
+/* ` } */
+
+/*
+ * Handle to track a mapping created via a grant reference.
+ */
+typedef uint32_t grant_handle_t;
+
+/*
+ * GNTTABOP_map_grant_ref: Map the grant entry (<dom>,<ref>) for access
+ * by devices and/or host CPUs. If successful, <handle> is a tracking number
+ * that must be presented later to destroy the mapping(s). On error, <handle>
+ * is a negative status code.
+ * NOTES:
+ * 1. If GNTMAP_device_map is specified then <dev_bus_addr> is the address
+ * via which I/O devices may access the granted frame.
+ * 2. If GNTMAP_host_map is specified then a mapping will be added at
+ * either a host virtual address in the current address space, or at
+ * a PTE at the specified machine address. The type of mapping to
+ * perform is selected through the GNTMAP_contains_pte flag, and the
+ * address is specified in <host_addr>.
+ * 3. Mappings should only be destroyed via GNTTABOP_unmap_grant_ref. If a
+ * host mapping is destroyed by other means then it is *NOT* guaranteed
+ * to be accounted to the correct grant reference!
+ */
+struct gnttab_map_grant_ref {
+ /* IN parameters. */
+ uint64_t host_addr;
+ uint32_t flags; /* GNTMAP_* */
+ grant_ref_t ref;
+ domid_t dom;
+ /* OUT parameters. */
+ int16_t status; /* => enum grant_status */
+ grant_handle_t handle;
+ uint64_t dev_bus_addr;
+};
+typedef struct gnttab_map_grant_ref gnttab_map_grant_ref_t;
+DEFINE_XEN_GUEST_HANDLE(gnttab_map_grant_ref_t);
+
+/*
+ * GNTTABOP_unmap_grant_ref: Destroy one or more grant-reference mappings
+ * tracked by <handle>. If <host_addr> or <dev_bus_addr> is zero, that
+ * field is ignored. If non-zero, they must refer to a device/host mapping
+ * that is tracked by <handle>
+ * NOTES:
+ * 1. The call may fail in an undefined manner if either mapping is not
+ * tracked by <handle>.
+ * 3. After executing a batch of unmaps, it is guaranteed that no stale
+ * mappings will remain in the device or host TLBs.
+ */
+struct gnttab_unmap_grant_ref {
+ /* IN parameters. */
+ uint64_t host_addr;
+ uint64_t dev_bus_addr;
+ grant_handle_t handle;
+ /* OUT parameters. */
+ int16_t status; /* => enum grant_status */
+};
+typedef struct gnttab_unmap_grant_ref gnttab_unmap_grant_ref_t;
+DEFINE_XEN_GUEST_HANDLE(gnttab_unmap_grant_ref_t);
+
+/*
+ * GNTTABOP_setup_table: Set up a grant table for <dom> comprising at least
+ * <nr_frames> pages. The frame addresses are written to the <frame_list>.
+ * Only <nr_frames> addresses are written, even if the table is larger.
+ * NOTES:
+ * 1. <dom> may be specified as DOMID_SELF.
+ * 2. Only a sufficiently-privileged domain may specify <dom> != DOMID_SELF.
+ * 3. Xen may not support more than a single grant-table page per domain.
+ */
+struct gnttab_setup_table {
+ /* IN parameters. */
+ domid_t dom;
+ uint32_t nr_frames;
+ /* OUT parameters. */
+ int16_t status; /* => enum grant_status */
+#if __XEN_INTERFACE_VERSION__ < 0x00040300
+ XEN_GUEST_HANDLE(ulong) frame_list;
+#else
+ XEN_GUEST_HANDLE(xen_pfn_t) frame_list;
+#endif
+};
+typedef struct gnttab_setup_table gnttab_setup_table_t;
+DEFINE_XEN_GUEST_HANDLE(gnttab_setup_table_t);
+
+/*
+ * GNTTABOP_dump_table: Dump the contents of the grant table to the
+ * xen console. Debugging use only.
+ */
+struct gnttab_dump_table {
+ /* IN parameters. */
+ domid_t dom;
+ /* OUT parameters. */
+ int16_t status; /* => enum grant_status */
+};
+typedef struct gnttab_dump_table gnttab_dump_table_t;
+DEFINE_XEN_GUEST_HANDLE(gnttab_dump_table_t);
+
+/*
+ * GNTTABOP_transfer_grant_ref: Transfer <frame> to a foreign domain. The
+ * foreign domain has previously registered its interest in the transfer via
+ * <domid, ref>.
+ *
+ * Note that, even if the transfer fails, the specified page no longer belongs
+ * to the calling domain *unless* the error is GNTST_bad_page.
+ */
+struct gnttab_transfer {
+ /* IN parameters. */
+ xen_pfn_t mfn;
+ domid_t domid;
+ grant_ref_t ref;
+ /* OUT parameters. */
+ int16_t status;
+};
+typedef struct gnttab_transfer gnttab_transfer_t;
+DEFINE_XEN_GUEST_HANDLE(gnttab_transfer_t);
+
+
+/*
+ * GNTTABOP_copy: Hypervisor based copy
+ * source and destinations can be eithers MFNs or, for foreign domains,
+ * grant references. the foreign domain has to grant read/write access
+ * in its grant table.
+ *
+ * The flags specify what type source and destinations are (either MFN
+ * or grant reference).
+ *
+ * Note that this can also be used to copy data between two domains
+ * via a third party if the source and destination domains had previously
+ * grant appropriate access to their pages to the third party.
+ *
+ * source_offset specifies an offset in the source frame, dest_offset
+ * the offset in the target frame and len specifies the number of
+ * bytes to be copied.
+ */
+
+#define _GNTCOPY_source_gref (0)
+#define GNTCOPY_source_gref (1<<_GNTCOPY_source_gref)
+#define _GNTCOPY_dest_gref (1)
+#define GNTCOPY_dest_gref (1<<_GNTCOPY_dest_gref)
+
+struct gnttab_copy {
+ /* IN parameters. */
+ struct {
+ union {
+ grant_ref_t ref;
+ xen_pfn_t gmfn;
+ } u;
+ domid_t domid;
+ uint16_t offset;
+ } source, dest;
+ uint16_t len;
+ uint16_t flags; /* GNTCOPY_* */
+ /* OUT parameters. */
+ int16_t status;
+};
+typedef struct gnttab_copy gnttab_copy_t;
+DEFINE_XEN_GUEST_HANDLE(gnttab_copy_t);
+
+/*
+ * GNTTABOP_query_size: Query the current and maximum sizes of the shared
+ * grant table.
+ * NOTES:
+ * 1. <dom> may be specified as DOMID_SELF.
+ * 2. Only a sufficiently-privileged domain may specify <dom> != DOMID_SELF.
+ */
+struct gnttab_query_size {
+ /* IN parameters. */
+ domid_t dom;
+ /* OUT parameters. */
+ uint32_t nr_frames;
+ uint32_t max_nr_frames;
+ int16_t status; /* => enum grant_status */
+};
+typedef struct gnttab_query_size gnttab_query_size_t;
+DEFINE_XEN_GUEST_HANDLE(gnttab_query_size_t);
+
+/*
+ * GNTTABOP_unmap_and_replace: Destroy one or more grant-reference mappings
+ * tracked by <handle> but atomically replace the page table entry with one
+ * pointing to the machine address under <new_addr>. <new_addr> will be
+ * redirected to the null entry.
+ * NOTES:
+ * 1. The call may fail in an undefined manner if either mapping is not
+ * tracked by <handle>.
+ * 2. After executing a batch of unmaps, it is guaranteed that no stale
+ * mappings will remain in the device or host TLBs.
+ */
+struct gnttab_unmap_and_replace {
+ /* IN parameters. */
+ uint64_t host_addr;
+ uint64_t new_addr;
+ grant_handle_t handle;
+ /* OUT parameters. */
+ int16_t status; /* => enum grant_status */
+};
+typedef struct gnttab_unmap_and_replace gnttab_unmap_and_replace_t;
+DEFINE_XEN_GUEST_HANDLE(gnttab_unmap_and_replace_t);
+
+#if __XEN_INTERFACE_VERSION__ >= 0x0003020a
+/*
+ * GNTTABOP_set_version: Request a particular version of the grant
+ * table shared table structure. This operation can only be performed
+ * once in any given domain. It must be performed before any grants
+ * are activated; otherwise, the domain will be stuck with version 1.
+ * The only defined versions are 1 and 2.
+ */
+struct gnttab_set_version {
+ /* IN/OUT parameters */
+ uint32_t version;
+};
+typedef struct gnttab_set_version gnttab_set_version_t;
+DEFINE_XEN_GUEST_HANDLE(gnttab_set_version_t);
+
+
+/*
+ * GNTTABOP_get_status_frames: Get the list of frames used to store grant
+ * status for <dom>. In grant format version 2, the status is separated
+ * from the other shared grant fields to allow more efficient synchronization
+ * using barriers instead of atomic cmpexch operations.
+ * <nr_frames> specify the size of vector <frame_list>.
+ * The frame addresses are returned in the <frame_list>.
+ * Only <nr_frames> addresses are returned, even if the table is larger.
+ * NOTES:
+ * 1. <dom> may be specified as DOMID_SELF.
+ * 2. Only a sufficiently-privileged domain may specify <dom> != DOMID_SELF.
+ */
+struct gnttab_get_status_frames {
+ /* IN parameters. */
+ uint32_t nr_frames;
+ domid_t dom;
+ /* OUT parameters. */
+ int16_t status; /* => enum grant_status */
+ XEN_GUEST_HANDLE(uint64_t) frame_list;
+};
+typedef struct gnttab_get_status_frames gnttab_get_status_frames_t;
+DEFINE_XEN_GUEST_HANDLE(gnttab_get_status_frames_t);
+
+/*
+ * GNTTABOP_get_version: Get the grant table version which is in
+ * effect for domain <dom>.
+ */
+struct gnttab_get_version {
+ /* IN parameters */
+ domid_t dom;
+ uint16_t pad;
+ /* OUT parameters */
+ uint32_t version;
+};
+typedef struct gnttab_get_version gnttab_get_version_t;
+DEFINE_XEN_GUEST_HANDLE(gnttab_get_version_t);
+
+/*
+ * GNTTABOP_swap_grant_ref: Swap the contents of two grant entries.
+ */
+struct gnttab_swap_grant_ref {
+ /* IN parameters */
+ grant_ref_t ref_a;
+ grant_ref_t ref_b;
+ /* OUT parameters */
+ int16_t status; /* => enum grant_status */
+};
+typedef struct gnttab_swap_grant_ref gnttab_swap_grant_ref_t;
+DEFINE_XEN_GUEST_HANDLE(gnttab_swap_grant_ref_t);
+
+#endif /* __XEN_INTERFACE_VERSION__ */
+
+/*
+ * Bitfield values for gnttab_map_grant_ref.flags.
+ */
+ /* Map the grant entry for access by I/O devices. */
+#define _GNTMAP_device_map (0)
+#define GNTMAP_device_map (1<<_GNTMAP_device_map)
+ /* Map the grant entry for access by host CPUs. */
+#define _GNTMAP_host_map (1)
+#define GNTMAP_host_map (1<<_GNTMAP_host_map)
+ /* Accesses to the granted frame will be restricted to read-only access. */
+#define _GNTMAP_readonly (2)
+#define GNTMAP_readonly (1<<_GNTMAP_readonly)
+ /*
+ * GNTMAP_host_map subflag:
+ * 0 => The host mapping is usable only by the guest OS.
+ * 1 => The host mapping is usable by guest OS + current application.
+ */
+#define _GNTMAP_application_map (3)
+#define GNTMAP_application_map (1<<_GNTMAP_application_map)
+
+ /*
+ * GNTMAP_contains_pte subflag:
+ * 0 => This map request contains a host virtual address.
+ * 1 => This map request contains the machine addess of the PTE to update.
+ */
+#define _GNTMAP_contains_pte (4)
+#define GNTMAP_contains_pte (1<<_GNTMAP_contains_pte)
+
+#define _GNTMAP_can_fail (5)
+#define GNTMAP_can_fail (1<<_GNTMAP_can_fail)
+
+/*
+ * Bits to be placed in guest kernel available PTE bits (architecture
+ * dependent; only supported when XENFEAT_gnttab_map_avail_bits is set).
+ */
+#define _GNTMAP_guest_avail0 (16)
+#define GNTMAP_guest_avail_mask ((uint32_t)~0 << _GNTMAP_guest_avail0)
+
+/*
+ * Values for error status returns. All errors are -ve.
+ */
+/* ` enum grant_status { */
+#define GNTST_okay (0) /* Normal return. */
+#define GNTST_general_error (-1) /* General undefined error. */
+#define GNTST_bad_domain (-2) /* Unrecognsed domain id. */
+#define GNTST_bad_gntref (-3) /* Unrecognised or inappropriate gntref. */
+#define GNTST_bad_handle (-4) /* Unrecognised or inappropriate handle. */
+#define GNTST_bad_virt_addr (-5) /* Inappropriate virtual address to map. */
+#define GNTST_bad_dev_addr (-6) /* Inappropriate device address to unmap.*/
+#define GNTST_no_device_space (-7) /* Out of space in I/O MMU. */
+#define GNTST_permission_denied (-8) /* Not enough privilege for operation. */
+#define GNTST_bad_page (-9) /* Specified page was invalid for op. */
+#define GNTST_bad_copy_arg (-10) /* copy arguments cross page boundary. */
+#define GNTST_address_too_big (-11) /* transfer page address too large. */
+#define GNTST_eagain (-12) /* Operation not done; try again. */
+/* ` } */
+
+#define GNTTABOP_error_msgs { \
+ "okay", \
+ "undefined error", \
+ "unrecognised domain id", \
+ "invalid grant reference", \
+ "invalid mapping handle", \
+ "invalid virtual address", \
+ "invalid device address", \
+ "no spare translation slot in the I/O MMU", \
+ "permission denied", \
+ "bad page", \
+ "copy arguments cross page boundary", \
+ "page address size too large", \
+ "operation not done; try again" \
+}
+
+#endif /* __XEN_PUBLIC_GRANT_TABLE_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/include/xen/hvm/hvm_op.h b/include/xen/hvm/hvm_op.h
new file mode 100644
index 0000000..0bdafdf
--- /dev/null
+++ b/include/xen/hvm/hvm_op.h
@@ -0,0 +1,296 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright (c) 2007, Keir Fraser
+ */
+
+#ifndef __XEN_PUBLIC_HVM_HVM_OP_H__
+#define __XEN_PUBLIC_HVM_HVM_OP_H__
+
+#include "../xen.h"
+#include "../trace.h"
+#include "../event_channel.h"
+
+/* Get/set subcommands: extra argument == pointer to xen_hvm_param struct. */
+#define HVMOP_set_param 0
+#define HVMOP_get_param 1
+struct xen_hvm_param {
+ domid_t domid; /* IN */
+ uint32_t index; /* IN */
+ uint64_t value; /* IN/OUT */
+};
+typedef struct xen_hvm_param xen_hvm_param_t;
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_param_t);
+
+#if __XEN_INTERFACE_VERSION__ < 0x00040900
+
+/* Set the logical level of one of a domain's PCI INTx wires. */
+#define HVMOP_set_pci_intx_level 2
+struct xen_hvm_set_pci_intx_level {
+ /* Domain to be updated. */
+ domid_t domid;
+ /* PCI INTx identification in PCI topology (domain:bus:device:intx). */
+ uint8_t domain, bus, device, intx;
+ /* Assertion level (0 = unasserted, 1 = asserted). */
+ uint8_t level;
+};
+typedef struct xen_hvm_set_pci_intx_level xen_hvm_set_pci_intx_level_t;
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_pci_intx_level_t);
+
+/* Set the logical level of one of a domain's ISA IRQ wires. */
+#define HVMOP_set_isa_irq_level 3
+struct xen_hvm_set_isa_irq_level {
+ /* Domain to be updated. */
+ domid_t domid;
+ /* ISA device identification, by ISA IRQ (0-15). */
+ uint8_t isa_irq;
+ /* Assertion level (0 = unasserted, 1 = asserted). */
+ uint8_t level;
+};
+typedef struct xen_hvm_set_isa_irq_level xen_hvm_set_isa_irq_level_t;
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_isa_irq_level_t);
+
+#define HVMOP_set_pci_link_route 4
+struct xen_hvm_set_pci_link_route {
+ /* Domain to be updated. */
+ domid_t domid;
+ /* PCI link identifier (0-3). */
+ uint8_t link;
+ /* ISA IRQ (1-15), or 0 (disable link). */
+ uint8_t isa_irq;
+};
+typedef struct xen_hvm_set_pci_link_route xen_hvm_set_pci_link_route_t;
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_pci_link_route_t);
+
+#endif /* __XEN_INTERFACE_VERSION__ < 0x00040900 */
+
+/* Flushes all VCPU TLBs: @arg must be NULL. */
+#define HVMOP_flush_tlbs 5
+
+typedef enum {
+ HVMMEM_ram_rw, /* Normal read/write guest RAM */
+ HVMMEM_ram_ro, /* Read-only; writes are discarded */
+ HVMMEM_mmio_dm, /* Reads and write go to the device model */
+#if __XEN_INTERFACE_VERSION__ < 0x00040700
+ HVMMEM_mmio_write_dm, /* Read-only; writes go to the device model */
+#else
+ HVMMEM_unused, /* Placeholder; setting memory to this type
+ will fail for code after 4.7.0 */
+#endif
+ HVMMEM_ioreq_server /* Memory type claimed by an ioreq server; type
+ changes to this value are only allowed after
+ an ioreq server has claimed its ownership.
+ Only pages with HVMMEM_ram_rw are allowed to
+ change to this type; conversely, pages with
+ this type are only allowed to be changed back
+ to HVMMEM_ram_rw. */
+} hvmmem_type_t;
+
+/* Hint from PV drivers for pagetable destruction. */
+#define HVMOP_pagetable_dying 9
+struct xen_hvm_pagetable_dying {
+ /* Domain with a pagetable about to be destroyed. */
+ domid_t domid;
+ uint16_t pad[3]; /* align next field on 8-byte boundary */
+ /* guest physical address of the toplevel pagetable dying */
+ uint64_t gpa;
+};
+typedef struct xen_hvm_pagetable_dying xen_hvm_pagetable_dying_t;
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_pagetable_dying_t);
+
+/* Get the current Xen time, in nanoseconds since system boot. */
+#define HVMOP_get_time 10
+struct xen_hvm_get_time {
+ uint64_t now; /* OUT */
+};
+typedef struct xen_hvm_get_time xen_hvm_get_time_t;
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_get_time_t);
+
+#define HVMOP_xentrace 11
+struct xen_hvm_xentrace {
+ uint16_t event, extra_bytes;
+ uint8_t extra[TRACE_EXTRA_MAX * sizeof(uint32_t)];
+};
+typedef struct xen_hvm_xentrace xen_hvm_xentrace_t;
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_xentrace_t);
+
+/* Following tools-only interfaces may change in future. */
+#if defined(__XEN__) || defined(__XEN_TOOLS__)
+
+/* Deprecated by XENMEM_access_op_set_access */
+#define HVMOP_set_mem_access 12
+
+/* Deprecated by XENMEM_access_op_get_access */
+#define HVMOP_get_mem_access 13
+
+#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */
+
+#define HVMOP_get_mem_type 15
+/* Return hvmmem_type_t for the specified pfn. */
+struct xen_hvm_get_mem_type {
+ /* Domain to be queried. */
+ domid_t domid;
+ /* OUT variable. */
+ uint16_t mem_type;
+ uint16_t pad[2]; /* align next field on 8-byte boundary */
+ /* IN variable. */
+ uint64_t pfn;
+};
+typedef struct xen_hvm_get_mem_type xen_hvm_get_mem_type_t;
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_get_mem_type_t);
+
+/* Following tools-only interfaces may change in future. */
+#if defined(__XEN__) || defined(__XEN_TOOLS__)
+
+/*
+ * Definitions relating to DMOP_create_ioreq_server. (Defined here for
+ * backwards compatibility).
+ */
+
+#define HVM_IOREQSRV_BUFIOREQ_OFF 0
+#define HVM_IOREQSRV_BUFIOREQ_LEGACY 1
+/*
+ * Use this when read_pointer gets updated atomically and
+ * the pointer pair gets read atomically:
+ */
+#define HVM_IOREQSRV_BUFIOREQ_ATOMIC 2
+
+#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */
+
+#if defined(__i386__) || defined(__x86_64__)
+
+/*
+ * HVMOP_set_evtchn_upcall_vector: Set a <vector> that should be used for event
+ * channel upcalls on the specified <vcpu>. If set,
+ * this vector will be used in preference to the
+ * domain global callback via (see
+ * HVM_PARAM_CALLBACK_IRQ).
+ */
+#define HVMOP_set_evtchn_upcall_vector 23
+struct xen_hvm_evtchn_upcall_vector {
+ uint32_t vcpu;
+ uint8_t vector;
+};
+typedef struct xen_hvm_evtchn_upcall_vector xen_hvm_evtchn_upcall_vector_t;
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_evtchn_upcall_vector_t);
+
+#endif /* defined(__i386__) || defined(__x86_64__) */
+
+#define HVMOP_guest_request_vm_event 24
+
+/* HVMOP_altp2m: perform altp2m state operations */
+#define HVMOP_altp2m 25
+
+#define HVMOP_ALTP2M_INTERFACE_VERSION 0x00000001
+
+struct xen_hvm_altp2m_domain_state {
+ /* IN or OUT variable on/off */
+ uint8_t state;
+};
+typedef struct xen_hvm_altp2m_domain_state xen_hvm_altp2m_domain_state_t;
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_altp2m_domain_state_t);
+
+struct xen_hvm_altp2m_vcpu_enable_notify {
+ uint32_t vcpu_id;
+ uint32_t pad;
+ /* #VE info area gfn */
+ uint64_t gfn;
+};
+typedef struct xen_hvm_altp2m_vcpu_enable_notify xen_hvm_altp2m_vcpu_enable_notify_t;
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_altp2m_vcpu_enable_notify_t);
+
+struct xen_hvm_altp2m_view {
+ /* IN/OUT variable */
+ uint16_t view;
+ /* Create view only: default access type
+ * NOTE: currently ignored */
+ uint16_t hvmmem_default_access; /* xenmem_access_t */
+};
+typedef struct xen_hvm_altp2m_view xen_hvm_altp2m_view_t;
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_altp2m_view_t);
+
+struct xen_hvm_altp2m_set_mem_access {
+ /* view */
+ uint16_t view;
+ /* Memory type */
+ uint16_t hvmmem_access; /* xenmem_access_t */
+ uint32_t pad;
+ /* gfn */
+ uint64_t gfn;
+};
+typedef struct xen_hvm_altp2m_set_mem_access xen_hvm_altp2m_set_mem_access_t;
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_altp2m_set_mem_access_t);
+
+struct xen_hvm_altp2m_change_gfn {
+ /* view */
+ uint16_t view;
+ uint16_t pad1;
+ uint32_t pad2;
+ /* old gfn */
+ uint64_t old_gfn;
+ /* new gfn, INVALID_GFN (~0UL) means revert */
+ uint64_t new_gfn;
+};
+typedef struct xen_hvm_altp2m_change_gfn xen_hvm_altp2m_change_gfn_t;
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_altp2m_change_gfn_t);
+
+struct xen_hvm_altp2m_op {
+ uint32_t version; /* HVMOP_ALTP2M_INTERFACE_VERSION */
+ uint32_t cmd;
+/* Get/set the altp2m state for a domain */
+#define HVMOP_altp2m_get_domain_state 1
+#define HVMOP_altp2m_set_domain_state 2
+/* Set the current VCPU to receive altp2m event notifications */
+#define HVMOP_altp2m_vcpu_enable_notify 3
+/* Create a new view */
+#define HVMOP_altp2m_create_p2m 4
+/* Destroy a view */
+#define HVMOP_altp2m_destroy_p2m 5
+/* Switch view for an entire domain */
+#define HVMOP_altp2m_switch_p2m 6
+/* Notify that a page of memory is to have specific access types */
+#define HVMOP_altp2m_set_mem_access 7
+/* Change a p2m entry to have a different gfn->mfn mapping */
+#define HVMOP_altp2m_change_gfn 8
+ domid_t domain;
+ uint16_t pad1;
+ uint32_t pad2;
+ union {
+ struct xen_hvm_altp2m_domain_state domain_state;
+ struct xen_hvm_altp2m_vcpu_enable_notify enable_notify;
+ struct xen_hvm_altp2m_view view;
+ struct xen_hvm_altp2m_set_mem_access set_mem_access;
+ struct xen_hvm_altp2m_change_gfn change_gfn;
+ uint8_t pad[64];
+ } u;
+};
+typedef struct xen_hvm_altp2m_op xen_hvm_altp2m_op_t;
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_altp2m_op_t);
+
+#endif /* __XEN_PUBLIC_HVM_HVM_OP_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/include/xen/hvm/params.h b/include/xen/hvm/params.h
new file mode 100644
index 0000000..2ec2e7c
--- /dev/null
+++ b/include/xen/hvm/params.h
@@ -0,0 +1,284 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright (c) 2007, Keir Fraser
+ */
+
+#ifndef __XEN_PUBLIC_HVM_PARAMS_H__
+#define __XEN_PUBLIC_HVM_PARAMS_H__
+
+#include "hvm_op.h"
+
+/*
+ * Parameter space for HVMOP_{set,get}_param.
+ */
+
+#define HVM_PARAM_CALLBACK_IRQ 0
+#define HVM_PARAM_CALLBACK_IRQ_TYPE_MASK xen_mk_ullong(0xFF00000000000000)
+/*
+ * How should CPU0 event-channel notifications be delivered?
+ *
+ * If val == 0 then CPU0 event-channel notifications are not delivered.
+ * If val != 0, val[63:56] encodes the type, as follows:
+ */
+
+#define HVM_PARAM_CALLBACK_TYPE_GSI 0
+/*
+ * val[55:0] is a delivery GSI. GSI 0 cannot be used, as it aliases val == 0,
+ * and disables all notifications.
+ */
+
+#define HVM_PARAM_CALLBACK_TYPE_PCI_INTX 1
+/*
+ * val[55:0] is a delivery PCI INTx line:
+ * Domain = val[47:32], Bus = val[31:16] DevFn = val[15:8], IntX = val[1:0]
+ */
+
+#if defined(__i386__) || defined(__x86_64__)
+#define HVM_PARAM_CALLBACK_TYPE_VECTOR 2
+/*
+ * val[7:0] is a vector number. Check for XENFEAT_hvm_callback_vector to know
+ * if this delivery method is available.
+ */
+#elif defined(__arm__) || defined(__aarch64__)
+#define HVM_PARAM_CALLBACK_TYPE_PPI 2
+/*
+ * val[55:16] needs to be zero.
+ * val[15:8] is interrupt flag of the PPI used by event-channel:
+ * bit 8: the PPI is edge(1) or level(0) triggered
+ * bit 9: the PPI is active low(1) or high(0)
+ * val[7:0] is a PPI number used by event-channel.
+ * This is only used by ARM/ARM64 and masking/eoi the interrupt associated to
+ * the notification is handled by the interrupt controller.
+ */
+#define HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_MASK 0xFF00
+#define HVM_PARAM_CALLBACK_TYPE_PPI_FLAG_LOW_LEVEL 2
+#endif
+
+/*
+ * These are not used by Xen. They are here for convenience of HVM-guest
+ * xenbus implementations.
+ */
+#define HVM_PARAM_STORE_PFN 1
+#define HVM_PARAM_STORE_EVTCHN 2
+
+#define HVM_PARAM_PAE_ENABLED 4
+
+#define HVM_PARAM_IOREQ_PFN 5
+
+#define HVM_PARAM_BUFIOREQ_PFN 6
+#define HVM_PARAM_BUFIOREQ_EVTCHN 26
+
+#if defined(__i386__) || defined(__x86_64__)
+
+/*
+ * Viridian enlightenments
+ *
+ * (See http://download.microsoft.com/download/A/B/4/AB43A34E-BDD0-4FA6-BDEF-79EEF16E880B/Hypervisor%20Top%20Level%20Functional%20Specification%20v4.0.docx)
+ *
+ * To expose viridian enlightenments to the guest set this parameter
+ * to the desired feature mask. The base feature set must be present
+ * in any valid feature mask.
+ */
+#define HVM_PARAM_VIRIDIAN 9
+
+/* Base+Freq viridian feature sets:
+ *
+ * - Hypercall MSRs (HV_X64_MSR_GUEST_OS_ID and HV_X64_MSR_HYPERCALL)
+ * - APIC access MSRs (HV_X64_MSR_EOI, HV_X64_MSR_ICR and HV_X64_MSR_TPR)
+ * - Virtual Processor index MSR (HV_X64_MSR_VP_INDEX)
+ * - Timer frequency MSRs (HV_X64_MSR_TSC_FREQUENCY and
+ * HV_X64_MSR_APIC_FREQUENCY)
+ */
+#define _HVMPV_base_freq 0
+#define HVMPV_base_freq (1 << _HVMPV_base_freq)
+
+/* Feature set modifications */
+
+/* Disable timer frequency MSRs (HV_X64_MSR_TSC_FREQUENCY and
+ * HV_X64_MSR_APIC_FREQUENCY).
+ * This modification restores the viridian feature set to the
+ * original 'base' set exposed in releases prior to Xen 4.4.
+ */
+#define _HVMPV_no_freq 1
+#define HVMPV_no_freq (1 << _HVMPV_no_freq)
+
+/* Enable Partition Time Reference Counter (HV_X64_MSR_TIME_REF_COUNT) */
+#define _HVMPV_time_ref_count 2
+#define HVMPV_time_ref_count (1 << _HVMPV_time_ref_count)
+
+/* Enable Reference TSC Page (HV_X64_MSR_REFERENCE_TSC) */
+#define _HVMPV_reference_tsc 3
+#define HVMPV_reference_tsc (1 << _HVMPV_reference_tsc)
+
+/* Use Hypercall for remote TLB flush */
+#define _HVMPV_hcall_remote_tlb_flush 4
+#define HVMPV_hcall_remote_tlb_flush (1 << _HVMPV_hcall_remote_tlb_flush)
+
+/* Use APIC assist */
+#define _HVMPV_apic_assist 5
+#define HVMPV_apic_assist (1 << _HVMPV_apic_assist)
+
+/* Enable crash MSRs */
+#define _HVMPV_crash_ctl 6
+#define HVMPV_crash_ctl (1 << _HVMPV_crash_ctl)
+
+#define HVMPV_feature_mask \
+ (HVMPV_base_freq | \
+ HVMPV_no_freq | \
+ HVMPV_time_ref_count | \
+ HVMPV_reference_tsc | \
+ HVMPV_hcall_remote_tlb_flush | \
+ HVMPV_apic_assist | \
+ HVMPV_crash_ctl)
+
+#endif
+
+/*
+ * Set mode for virtual timers (currently x86 only):
+ * delay_for_missed_ticks (default):
+ * Do not advance a vcpu's time beyond the correct delivery time for
+ * interrupts that have been missed due to preemption. Deliver missed
+ * interrupts when the vcpu is rescheduled and advance the vcpu's virtual
+ * time stepwise for each one.
+ * no_delay_for_missed_ticks:
+ * As above, missed interrupts are delivered, but guest time always tracks
+ * wallclock (i.e., real) time while doing so.
+ * no_missed_ticks_pending:
+ * No missed interrupts are held pending. Instead, to ensure ticks are
+ * delivered at some non-zero rate, if we detect missed ticks then the
+ * internal tick alarm is not disabled if the VCPU is preempted during the
+ * next tick period.
+ * one_missed_tick_pending:
+ * Missed interrupts are collapsed together and delivered as one 'late tick'.
+ * Guest time always tracks wallclock (i.e., real) time.
+ */
+#define HVM_PARAM_TIMER_MODE 10
+#define HVMPTM_delay_for_missed_ticks 0
+#define HVMPTM_no_delay_for_missed_ticks 1
+#define HVMPTM_no_missed_ticks_pending 2
+#define HVMPTM_one_missed_tick_pending 3
+
+/* Boolean: Enable virtual HPET (high-precision event timer)? (x86-only) */
+#define HVM_PARAM_HPET_ENABLED 11
+
+/* Identity-map page directory used by Intel EPT when CR0.PG=0. */
+#define HVM_PARAM_IDENT_PT 12
+
+/* Device Model domain, defaults to 0. */
+#define HVM_PARAM_DM_DOMAIN 13
+
+/* ACPI S state: currently support S0 and S3 on x86. */
+#define HVM_PARAM_ACPI_S_STATE 14
+
+/* TSS used on Intel when CR0.PE=0. */
+#define HVM_PARAM_VM86_TSS 15
+
+/* Boolean: Enable aligning all periodic vpts to reduce interrupts */
+#define HVM_PARAM_VPT_ALIGN 16
+
+/* Console debug shared memory ring and event channel */
+#define HVM_PARAM_CONSOLE_PFN 17
+#define HVM_PARAM_CONSOLE_EVTCHN 18
+
+/*
+ * Select location of ACPI PM1a and TMR control blocks. Currently two locations
+ * are supported, specified by version 0 or 1 in this parameter:
+ * - 0: default, use the old addresses
+ * PM1A_EVT == 0x1f40; PM1A_CNT == 0x1f44; PM_TMR == 0x1f48
+ * - 1: use the new default qemu addresses
+ * PM1A_EVT == 0xb000; PM1A_CNT == 0xb004; PM_TMR == 0xb008
+ * You can find these address definitions in <hvm/ioreq.h>
+ */
+#define HVM_PARAM_ACPI_IOPORTS_LOCATION 19
+
+/* Deprecated */
+#define HVM_PARAM_MEMORY_EVENT_CR0 20
+#define HVM_PARAM_MEMORY_EVENT_CR3 21
+#define HVM_PARAM_MEMORY_EVENT_CR4 22
+#define HVM_PARAM_MEMORY_EVENT_INT3 23
+#define HVM_PARAM_MEMORY_EVENT_SINGLE_STEP 25
+#define HVM_PARAM_MEMORY_EVENT_MSR 30
+
+/* Boolean: Enable nestedhvm (hvm only) */
+#define HVM_PARAM_NESTEDHVM 24
+
+/* Params for the mem event rings */
+#define HVM_PARAM_PAGING_RING_PFN 27
+#define HVM_PARAM_MONITOR_RING_PFN 28
+#define HVM_PARAM_SHARING_RING_PFN 29
+
+/* SHUTDOWN_* action in case of a triple fault */
+#define HVM_PARAM_TRIPLE_FAULT_REASON 31
+
+#define HVM_PARAM_IOREQ_SERVER_PFN 32
+#define HVM_PARAM_NR_IOREQ_SERVER_PAGES 33
+
+/* Location of the VM Generation ID in guest physical address space. */
+#define HVM_PARAM_VM_GENERATION_ID_ADDR 34
+
+/*
+ * Set mode for altp2m:
+ * disabled: don't activate altp2m (default)
+ * mixed: allow access to all altp2m ops for both in-guest and external tools
+ * external: allow access to external privileged tools only
+ * limited: guest only has limited access (ie. control VMFUNC and #VE)
+ */
+#define HVM_PARAM_ALTP2M 35
+#define XEN_ALTP2M_disabled 0
+#define XEN_ALTP2M_mixed 1
+#define XEN_ALTP2M_external 2
+#define XEN_ALTP2M_limited 3
+
+/*
+ * Size of the x87 FPU FIP/FDP registers that the hypervisor needs to
+ * save/restore. This is a workaround for a hardware limitation that
+ * does not allow the full FIP/FDP and FCS/FDS to be restored.
+ *
+ * Valid values are:
+ *
+ * 8: save/restore 64-bit FIP/FDP and clear FCS/FDS (default if CPU
+ * has FPCSDS feature).
+ *
+ * 4: save/restore 32-bit FIP/FDP, FCS/FDS, and clear upper 32-bits of
+ * FIP/FDP.
+ *
+ * 0: allow hypervisor to choose based on the value of FIP/FDP
+ * (default if CPU does not have FPCSDS).
+ *
+ * If FPCSDS (bit 13 in CPUID leaf 0x7, subleaf 0x0) is set, the CPU
+ * never saves FCS/FDS and this parameter should be left at the
+ * default of 8.
+ */
+#define HVM_PARAM_X87_FIP_WIDTH 36
+
+/*
+ * TSS (and its size) used on Intel when CR0.PE=0. The address occupies
+ * the low 32 bits, while the size is in the high 32 ones.
+ */
+#define HVM_PARAM_VM86_TSS_SIZED 37
+
+/* Enable MCA capabilities. */
+#define HVM_PARAM_MCA_CAP 38
+#define XEN_HVM_MCA_CAP_LMCE (xen_mk_ullong(1) << 0)
+#define XEN_HVM_MCA_CAP_MASK XEN_HVM_MCA_CAP_LMCE
+
+#define HVM_NR_PARAMS 39
+
+#endif /* __XEN_PUBLIC_HVM_PARAMS_H__ */
diff --git a/include/xen/hvm/start_info.h b/include/xen/hvm/start_info.h
new file mode 100644
index 0000000..6484159
--- /dev/null
+++ b/include/xen/hvm/start_info.h
@@ -0,0 +1,98 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright (c) 2016, Citrix Systems, Inc.
+ */
+
+#ifndef __XEN_PUBLIC_ARCH_X86_HVM_START_INFO_H__
+#define __XEN_PUBLIC_ARCH_X86_HVM_START_INFO_H__
+
+/*
+ * Start of day structure passed to PVH guests and to HVM guests in %ebx.
+ *
+ * NOTE: nothing will be loaded at physical address 0, so a 0 value in any
+ * of the address fields should be treated as not present.
+ *
+ * 0 +----------------+
+ * | magic | Contains the magic value XEN_HVM_START_MAGIC_VALUE
+ * | | ("xEn3" with the 0x80 bit of the "E" set).
+ * 4 +----------------+
+ * | version | Version of this structure. Current version is 0. New
+ * | | versions are guaranteed to be backwards-compatible.
+ * 8 +----------------+
+ * | flags | SIF_xxx flags.
+ * 12 +----------------+
+ * | nr_modules | Number of modules passed to the kernel.
+ * 16 +----------------+
+ * | modlist_paddr | Physical address of an array of modules
+ * | | (layout of the structure below).
+ * 24 +----------------+
+ * | cmdline_paddr | Physical address of the command line,
+ * | | a zero-terminated ASCII string.
+ * 32 +----------------+
+ * | rsdp_paddr | Physical address of the RSDP ACPI data structure.
+ * 40 +----------------+
+ *
+ * The layout of each entry in the module structure is the following:
+ *
+ * 0 +----------------+
+ * | paddr | Physical address of the module.
+ * 8 +----------------+
+ * | size | Size of the module in bytes.
+ * 16 +----------------+
+ * | cmdline_paddr | Physical address of the command line,
+ * | | a zero-terminated ASCII string.
+ * 24 +----------------+
+ * | reserved |
+ * 32 +----------------+
+ *
+ * The address and sizes are always a 64bit little endian unsigned integer.
+ *
+ * NB: Xen on x86 will always try to place all the data below the 4GiB
+ * boundary.
+ */
+#define XEN_HVM_START_MAGIC_VALUE 0x336ec578
+
+/*
+ * C representation of the x86/HVM start info layout.
+ *
+ * The canonical definition of this layout is above, this is just a way to
+ * represent the layout described there using C types.
+ */
+struct hvm_start_info {
+ uint32_t magic; /* Contains the magic value 0x336ec578 */
+ /* ("xEn3" with the 0x80 bit of the "E" set).*/
+ uint32_t version; /* Version of this structure. */
+ uint32_t flags; /* SIF_xxx flags. */
+ uint32_t nr_modules; /* Number of modules passed to the kernel. */
+ uint64_t modlist_paddr; /* Physical address of an array of */
+ /* hvm_modlist_entry. */
+ uint64_t cmdline_paddr; /* Physical address of the command line. */
+ uint64_t rsdp_paddr; /* Physical address of the RSDP ACPI data */
+ /* structure. */
+};
+
+struct hvm_modlist_entry {
+ uint64_t paddr; /* Physical address of the module. */
+ uint64_t size; /* Size of the module in bytes. */
+ uint64_t cmdline_paddr; /* Physical address of the command line. */
+ uint64_t reserved;
+};
+
+#endif /* __XEN_PUBLIC_ARCH_X86_HVM_START_INFO_H__ */
diff --git a/include/xen/io/blkif.h b/include/xen/io/blkif.h
new file mode 100644
index 0000000..c3e169c
--- /dev/null
+++ b/include/xen/io/blkif.h
@@ -0,0 +1,608 @@
+/******************************************************************************
+ * blkif.h
+ *
+ * Unified block-device I/O interface for Xen guest OSes.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright (c) 2003-2004, Keir Fraser
+ * Copyright (c) 2012, Spectra Logic Corporation
+ */
+
+#ifndef __XEN_PUBLIC_IO_BLKIF_H__
+#define __XEN_PUBLIC_IO_BLKIF_H__
+
+#include "ring.h"
+#include "../grant_table.h"
+
+/*
+ * Front->back notifications: When enqueuing a new request, sending a
+ * notification can be made conditional on req_event (i.e., the generic
+ * hold-off mechanism provided by the ring macros). Backends must set
+ * req_event appropriately (e.g., using RING_FINAL_CHECK_FOR_REQUESTS()).
+ *
+ * Back->front notifications: When enqueuing a new response, sending a
+ * notification can be made conditional on rsp_event (i.e., the generic
+ * hold-off mechanism provided by the ring macros). Frontends must set
+ * rsp_event appropriately (e.g., using RING_FINAL_CHECK_FOR_RESPONSES()).
+ */
+
+#ifndef blkif_vdev_t
+#define blkif_vdev_t uint16_t
+#endif
+#define blkif_sector_t uint64_t
+
+/*
+ * Feature and Parameter Negotiation
+ * =================================
+ * The two halves of a Xen block driver utilize nodes within the XenStore to
+ * communicate capabilities and to negotiate operating parameters. This
+ * section enumerates these nodes which reside in the respective front and
+ * backend portions of the XenStore, following the XenBus convention.
+ *
+ * All data in the XenStore is stored as strings. Nodes specifying numeric
+ * values are encoded in decimal. Integer value ranges listed below are
+ * expressed as fixed sized integer types capable of storing the conversion
+ * of a properly formated node string, without loss of information.
+ *
+ * Any specified default value is in effect if the corresponding XenBus node
+ * is not present in the XenStore.
+ *
+ * XenStore nodes in sections marked "PRIVATE" are solely for use by the
+ * driver side whose XenBus tree contains them.
+ *
+ * XenStore nodes marked "DEPRECATED" in their notes section should only be
+ * used to provide interoperability with legacy implementations.
+ *
+ * See the XenBus state transition diagram below for details on when XenBus
+ * nodes must be published and when they can be queried.
+ *
+ *****************************************************************************
+ * Backend XenBus Nodes
+ *****************************************************************************
+ *
+ *------------------ Backend Device Identification (PRIVATE) ------------------
+ *
+ * mode
+ * Values: "r" (read only), "w" (writable)
+ *
+ * The read or write access permissions to the backing store to be
+ * granted to the frontend.
+ *
+ * params
+ * Values: string
+ *
+ * A free formatted string providing sufficient information for the
+ * backend driver to open the backing device. (e.g. the path to the
+ * file or block device representing the backing store.)
+ *
+ * type
+ * Values: "file", "phy", "tap"
+ *
+ * The type of the backing device/object.
+ *
+ *--------------------------------- Features ---------------------------------
+ *
+ * feature-barrier
+ * Values: 0/1 (boolean)
+ * Default Value: 0
+ *
+ * A value of "1" indicates that the backend can process requests
+ * containing the BLKIF_OP_WRITE_BARRIER request opcode. Requests
+ * of this type may still be returned at any time with the
+ * BLKIF_RSP_EOPNOTSUPP result code.
+ *
+ * feature-flush-cache
+ * Values: 0/1 (boolean)
+ * Default Value: 0
+ *
+ * A value of "1" indicates that the backend can process requests
+ * containing the BLKIF_OP_FLUSH_DISKCACHE request opcode. Requests
+ * of this type may still be returned at any time with the
+ * BLKIF_RSP_EOPNOTSUPP result code.
+ *
+ * feature-discard
+ * Values: 0/1 (boolean)
+ * Default Value: 0
+ *
+ * A value of "1" indicates that the backend can process requests
+ * containing the BLKIF_OP_DISCARD request opcode. Requests
+ * of this type may still be returned at any time with the
+ * BLKIF_RSP_EOPNOTSUPP result code.
+ *
+ * feature-persistent
+ * Values: 0/1 (boolean)
+ * Default Value: 0
+ * Notes: 7
+ *
+ * A value of "1" indicates that the backend can keep the grants used
+ * by the frontend driver mapped, so the same set of grants should be
+ * used in all transactions. The maximum number of grants the backend
+ * can map persistently depends on the implementation, but ideally it
+ * should be RING_SIZE * BLKIF_MAX_SEGMENTS_PER_REQUEST. Using this
+ * feature the backend doesn't need to unmap each grant, preventing
+ * costly TLB flushes. The backend driver should only map grants
+ * persistently if the frontend supports it. If a backend driver chooses
+ * to use the persistent protocol when the frontend doesn't support it,
+ * it will probably hit the maximum number of persistently mapped grants
+ * (due to the fact that the frontend won't be reusing the same grants),
+ * and fall back to non-persistent mode. Backend implementations may
+ * shrink or expand the number of persistently mapped grants without
+ * notifying the frontend depending on memory constraints (this might
+ * cause a performance degradation).
+ *
+ * If a backend driver wants to limit the maximum number of persistently
+ * mapped grants to a value less than RING_SIZE *
+ * BLKIF_MAX_SEGMENTS_PER_REQUEST a LRU strategy should be used to
+ * discard the grants that are less commonly used. Using a LRU in the
+ * backend driver paired with a LIFO queue in the frontend will
+ * allow us to have better performance in this scenario.
+ *
+ *----------------------- Request Transport Parameters ------------------------
+ *
+ * max-ring-page-order
+ * Values: <uint32_t>
+ * Default Value: 0
+ * Notes: 1, 3
+ *
+ * The maximum supported size of the request ring buffer in units of
+ * lb(machine pages). (e.g. 0 == 1 page, 1 = 2 pages, 2 == 4 pages,
+ * etc.).
+ *
+ * max-ring-pages
+ * Values: <uint32_t>
+ * Default Value: 1
+ * Notes: DEPRECATED, 2, 3
+ *
+ * The maximum supported size of the request ring buffer in units of
+ * machine pages. The value must be a power of 2.
+ *
+ *------------------------- Backend Device Properties -------------------------
+ *
+ * discard-alignment
+ * Values: <uint32_t>
+ * Default Value: 0
+ * Notes: 4, 5
+ *
+ * The offset, in bytes from the beginning of the virtual block device,
+ * to the first, addressable, discard extent on the underlying device.
+ *
+ * discard-granularity
+ * Values: <uint32_t>
+ * Default Value: <"sector-size">
+ * Notes: 4
+ *
+ * The size, in bytes, of the individually addressable discard extents
+ * of the underlying device.
+ *
+ * discard-secure
+ * Values: 0/1 (boolean)
+ * Default Value: 0
+ * Notes: 10
+ *
+ * A value of "1" indicates that the backend can process BLKIF_OP_DISCARD
+ * requests with the BLKIF_DISCARD_SECURE flag set.
+ *
+ * info
+ * Values: <uint32_t> (bitmap)
+ *
+ * A collection of bit flags describing attributes of the backing
+ * device. The VDISK_* macros define the meaning of each bit
+ * location.
+ *
+ * sector-size
+ * Values: <uint32_t>
+ *
+ * The logical sector size, in bytes, of the backend device.
+ *
+ * physical-sector-size
+ * Values: <uint32_t>
+ *
+ * The physical sector size, in bytes, of the backend device.
+ *
+ * sectors
+ * Values: <uint64_t>
+ *
+ * The size of the backend device, expressed in units of its logical
+ * sector size ("sector-size").
+ *
+ *****************************************************************************
+ * Frontend XenBus Nodes
+ *****************************************************************************
+ *
+ *----------------------- Request Transport Parameters -----------------------
+ *
+ * event-channel
+ * Values: <uint32_t>
+ *
+ * The identifier of the Xen event channel used to signal activity
+ * in the ring buffer.
+ *
+ * ring-ref
+ * Values: <uint32_t>
+ * Notes: 6
+ *
+ * The Xen grant reference granting permission for the backend to map
+ * the sole page in a single page sized ring buffer.
+ *
+ * ring-ref%u
+ * Values: <uint32_t>
+ * Notes: 6
+ *
+ * For a frontend providing a multi-page ring, a "number of ring pages"
+ * sized list of nodes, each containing a Xen grant reference granting
+ * permission for the backend to map the page of the ring located
+ * at page index "%u". Page indexes are zero based.
+ *
+ * protocol
+ * Values: string (XEN_IO_PROTO_ABI_*)
+ * Default Value: XEN_IO_PROTO_ABI_NATIVE
+ *
+ * The machine ABI rules governing the format of all ring request and
+ * response structures.
+ *
+ * ring-page-order
+ * Values: <uint32_t>
+ * Default Value: 0
+ * Maximum Value: MAX(ffs(max-ring-pages) - 1, max-ring-page-order)
+ * Notes: 1, 3
+ *
+ * The size of the frontend allocated request ring buffer in units
+ * of lb(machine pages). (e.g. 0 == 1 page, 1 = 2 pages, 2 == 4 pages,
+ * etc.).
+ *
+ * num-ring-pages
+ * Values: <uint32_t>
+ * Default Value: 1
+ * Maximum Value: MAX(max-ring-pages,(0x1 << max-ring-page-order))
+ * Notes: DEPRECATED, 2, 3
+ *
+ * The size of the frontend allocated request ring buffer in units of
+ * machine pages. The value must be a power of 2.
+ *
+ * feature-persistent
+ * Values: 0/1 (boolean)
+ * Default Value: 0
+ * Notes: 7, 8, 9
+ *
+ * A value of "1" indicates that the frontend will reuse the same grants
+ * for all transactions, allowing the backend to map them with write
+ * access (even when it should be read-only). If the frontend hits the
+ * maximum number of allowed persistently mapped grants, it can fallback
+ * to non persistent mode. This will cause a performance degradation,
+ * since the the backend driver will still try to map those grants
+ * persistently. Since the persistent grants protocol is compatible with
+ * the previous protocol, a frontend driver can choose to work in
+ * persistent mode even when the backend doesn't support it.
+ *
+ * It is recommended that the frontend driver stores the persistently
+ * mapped grants in a LIFO queue, so a subset of all persistently mapped
+ * grants gets used commonly. This is done in case the backend driver
+ * decides to limit the maximum number of persistently mapped grants
+ * to a value less than RING_SIZE * BLKIF_MAX_SEGMENTS_PER_REQUEST.
+ *
+ *------------------------- Virtual Device Properties -------------------------
+ *
+ * device-type
+ * Values: "disk", "cdrom", "floppy", etc.
+ *
+ * virtual-device
+ * Values: <uint32_t>
+ *
+ * A value indicating the physical device to virtualize within the
+ * frontend's domain. (e.g. "The first ATA disk", "The third SCSI
+ * disk", etc.)
+ *
+ * See docs/misc/vbd-interface.txt for details on the format of this
+ * value.
+ *
+ * Notes
+ * -----
+ * (1) Multi-page ring buffer scheme first developed in the Citrix XenServer
+ * PV drivers.
+ * (2) Multi-page ring buffer scheme first used in some RedHat distributions
+ * including a distribution deployed on certain nodes of the Amazon
+ * EC2 cluster.
+ * (3) Support for multi-page ring buffers was implemented independently,
+ * in slightly different forms, by both Citrix and RedHat/Amazon.
+ * For full interoperability, block front and backends should publish
+ * identical ring parameters, adjusted for unit differences, to the
+ * XenStore nodes used in both schemes.
+ * (4) Devices that support discard functionality may internally allocate space
+ * (discardable extents) in units that are larger than the exported logical
+ * block size. If the backing device has such discardable extents the
+ * backend should provide both discard-granularity and discard-alignment.
+ * Providing just one of the two may be considered an error by the frontend.
+ * Backends supporting discard should include discard-granularity and
+ * discard-alignment even if it supports discarding individual sectors.
+ * Frontends should assume discard-alignment == 0 and discard-granularity
+ * == sector size if these keys are missing.
+ * (5) The discard-alignment parameter allows a physical device to be
+ * partitioned into virtual devices that do not necessarily begin or
+ * end on a discardable extent boundary.
+ * (6) When there is only a single page allocated to the request ring,
+ * 'ring-ref' is used to communicate the grant reference for this
+ * page to the backend. When using a multi-page ring, the 'ring-ref'
+ * node is not created. Instead 'ring-ref0' - 'ring-refN' are used.
+ * (7) When using persistent grants data has to be copied from/to the page
+ * where the grant is currently mapped. The overhead of doing this copy
+ * however doesn't suppress the speed improvement of not having to unmap
+ * the grants.
+ * (8) The frontend driver has to allow the backend driver to map all grants
+ * with write access, even when they should be mapped read-only, since
+ * further requests may reuse these grants and require write permissions.
+ * (9) Linux implementation doesn't have a limit on the maximum number of
+ * grants that can be persistently mapped in the frontend driver, but
+ * due to the frontent driver implementation it should never be bigger
+ * than RING_SIZE * BLKIF_MAX_SEGMENTS_PER_REQUEST.
+ *(10) The discard-secure property may be present and will be set to 1 if the
+ * backing device supports secure discard.
+ */
+
+/*
+ * STATE DIAGRAMS
+ *
+ *****************************************************************************
+ * Startup *
+ *****************************************************************************
+ *
+ * Tool stack creates front and back nodes with state XenbusStateInitialising.
+ *
+ * Front Back
+ * ================================= =====================================
+ * XenbusStateInitialising XenbusStateInitialising
+ * o Query virtual device o Query backend device identification
+ * properties. data.
+ * o Setup OS device instance. o Open and validate backend device.
+ * o Publish backend features and
+ * transport parameters.
+ * |
+ * |
+ * V
+ * XenbusStateInitWait
+ *
+ * o Query backend features and
+ * transport parameters.
+ * o Allocate and initialize the
+ * request ring.
+ * o Publish transport parameters
+ * that will be in effect during
+ * this connection.
+ * |
+ * |
+ * V
+ * XenbusStateInitialised
+ *
+ * o Query frontend transport parameters.
+ * o Connect to the request ring and
+ * event channel.
+ * o Publish backend device properties.
+ * |
+ * |
+ * V
+ * XenbusStateConnected
+ *
+ * o Query backend device properties.
+ * o Finalize OS virtual device
+ * instance.
+ * |
+ * |
+ * V
+ * XenbusStateConnected
+ *
+ * Note: Drivers that do not support any optional features, or the negotiation
+ * of transport parameters, can skip certain states in the state machine:
+ *
+ * o A frontend may transition to XenbusStateInitialised without
+ * waiting for the backend to enter XenbusStateInitWait. In this
+ * case, default transport parameters are in effect and any
+ * transport parameters published by the frontend must contain
+ * their default values.
+ *
+ * o A backend may transition to XenbusStateInitialised, bypassing
+ * XenbusStateInitWait, without waiting for the frontend to first
+ * enter the XenbusStateInitialised state. In this case, default
+ * transport parameters are in effect and any transport parameters
+ * published by the backend must contain their default values.
+ *
+ * Drivers that support optional features and/or transport parameter
+ * negotiation must tolerate these additional state transition paths.
+ * In general this means performing the work of any skipped state
+ * transition, if it has not already been performed, in addition to the
+ * work associated with entry into the current state.
+ */
+
+/*
+ * REQUEST CODES.
+ */
+#define BLKIF_OP_READ 0
+#define BLKIF_OP_WRITE 1
+/*
+ * All writes issued prior to a request with the BLKIF_OP_WRITE_BARRIER
+ * operation code ("barrier request") must be completed prior to the
+ * execution of the barrier request. All writes issued after the barrier
+ * request must not execute until after the completion of the barrier request.
+ *
+ * Optional. See "feature-barrier" XenBus node documentation above.
+ */
+#define BLKIF_OP_WRITE_BARRIER 2
+/*
+ * Commit any uncommitted contents of the backing device's volatile cache
+ * to stable storage.
+ *
+ * Optional. See "feature-flush-cache" XenBus node documentation above.
+ */
+#define BLKIF_OP_FLUSH_DISKCACHE 3
+/*
+ * Used in SLES sources for device specific command packet
+ * contained within the request. Reserved for that purpose.
+ */
+#define BLKIF_OP_RESERVED_1 4
+/*
+ * Indicate to the backend device that a region of storage is no longer in
+ * use, and may be discarded at any time without impact to the client. If
+ * the BLKIF_DISCARD_SECURE flag is set on the request, all copies of the
+ * discarded region on the device must be rendered unrecoverable before the
+ * command returns.
+ *
+ * This operation is analogous to performing a trim (ATA) or unamp (SCSI),
+ * command on a native device.
+ *
+ * More information about trim/unmap operations can be found at:
+ * http://t13.org/Documents/UploadedDocuments/docs2008/
+ * e07154r6-Data_Set_Management_Proposal_for_ATA-ACS2.doc
+ * http://www.seagate.com/staticfiles/support/disc/manuals/
+ * Interface%20manuals/100293068c.pdf
+ *
+ * Optional. See "feature-discard", "discard-alignment",
+ * "discard-granularity", and "discard-secure" in the XenBus node
+ * documentation above.
+ */
+#define BLKIF_OP_DISCARD 5
+
+/*
+ * Recognized if "feature-max-indirect-segments" in present in the backend
+ * xenbus info. The "feature-max-indirect-segments" node contains the maximum
+ * number of segments allowed by the backend per request. If the node is
+ * present, the frontend might use blkif_request_indirect structs in order to
+ * issue requests with more than BLKIF_MAX_SEGMENTS_PER_REQUEST (11). The
+ * maximum number of indirect segments is fixed by the backend, but the
+ * frontend can issue requests with any number of indirect segments as long as
+ * it's less than the number provided by the backend. The indirect_grefs field
+ * in blkif_request_indirect should be filled by the frontend with the
+ * grant references of the pages that are holding the indirect segments.
+ * These pages are filled with an array of blkif_request_segment that hold the
+ * information about the segments. The number of indirect pages to use is
+ * determined by the number of segments an indirect request contains. Every
+ * indirect page can contain a maximum of
+ * (PAGE_SIZE / sizeof(struct blkif_request_segment)) segments, so to
+ * calculate the number of indirect pages to use we have to do
+ * ceil(indirect_segments / (PAGE_SIZE / sizeof(struct blkif_request_segment))).
+ *
+ * If a backend does not recognize BLKIF_OP_INDIRECT, it should *not*
+ * create the "feature-max-indirect-segments" node!
+ */
+#define BLKIF_OP_INDIRECT 6
+
+/*
+ * Maximum scatter/gather segments per request.
+ * This is carefully chosen so that sizeof(blkif_ring_t) <= PAGE_SIZE.
+ * NB. This could be 12 if the ring indexes weren't stored in the same page.
+ */
+#define BLKIF_MAX_SEGMENTS_PER_REQUEST 11
+
+/*
+ * Maximum number of indirect pages to use per request.
+ */
+#define BLKIF_MAX_INDIRECT_PAGES_PER_REQUEST 8
+
+/*
+ * NB. first_sect and last_sect in blkif_request_segment, as well as
+ * sector_number in blkif_request, are always expressed in 512-byte units.
+ * However they must be properly aligned to the real sector size of the
+ * physical disk, which is reported in the "physical-sector-size" node in
+ * the backend xenbus info. Also the xenbus "sectors" node is expressed in
+ * 512-byte units.
+ */
+struct blkif_request_segment {
+ grant_ref_t gref; /* reference to I/O buffer frame */
+ /* @first_sect: first sector in frame to transfer (inclusive). */
+ /* @last_sect: last sector in frame to transfer (inclusive). */
+ uint8_t first_sect, last_sect;
+};
+
+/*
+ * Starting ring element for any I/O request.
+ */
+struct blkif_request {
+ uint8_t operation; /* BLKIF_OP_??? */
+ uint8_t nr_segments; /* number of segments */
+ blkif_vdev_t handle; /* only for read/write requests */
+ uint64_t id; /* private guest value, echoed in resp */
+ blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */
+ struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
+};
+typedef struct blkif_request blkif_request_t;
+
+/*
+ * Cast to this structure when blkif_request.operation == BLKIF_OP_DISCARD
+ * sizeof(struct blkif_request_discard) <= sizeof(struct blkif_request)
+ */
+struct blkif_request_discard {
+ uint8_t operation; /* BLKIF_OP_DISCARD */
+ uint8_t flag; /* BLKIF_DISCARD_SECURE or zero */
+#define BLKIF_DISCARD_SECURE (1<<0) /* ignored if discard-secure=0 */
+ blkif_vdev_t handle; /* same as for read/write requests */
+ uint64_t id; /* private guest value, echoed in resp */
+ blkif_sector_t sector_number;/* start sector idx on disk */
+ uint64_t nr_sectors; /* number of contiguous sectors to discard*/
+};
+typedef struct blkif_request_discard blkif_request_discard_t;
+
+struct blkif_request_indirect {
+ uint8_t operation; /* BLKIF_OP_INDIRECT */
+ uint8_t indirect_op; /* BLKIF_OP_{READ/WRITE} */
+ uint16_t nr_segments; /* number of segments */
+ uint64_t id; /* private guest value, echoed in resp */
+ blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */
+ blkif_vdev_t handle; /* same as for read/write requests */
+ grant_ref_t indirect_grefs[BLKIF_MAX_INDIRECT_PAGES_PER_REQUEST];
+#ifdef __i386__
+ uint64_t pad; /* Make it 64 byte aligned on i386 */
+#endif
+};
+typedef struct blkif_request_indirect blkif_request_indirect_t;
+
+struct blkif_response {
+ uint64_t id; /* copied from request */
+ uint8_t operation; /* copied from request */
+ int16_t status; /* BLKIF_RSP_??? */
+};
+typedef struct blkif_response blkif_response_t;
+
+/*
+ * STATUS RETURN CODES.
+ */
+ /* Operation not supported (only happens on barrier writes). */
+#define BLKIF_RSP_EOPNOTSUPP -2
+ /* Operation failed for some unspecified reason (-EIO). */
+#define BLKIF_RSP_ERROR -1
+ /* Operation completed successfully. */
+#define BLKIF_RSP_OKAY 0
+
+/*
+ * Generate blkif ring structures and types.
+ */
+DEFINE_RING_TYPES(blkif, struct blkif_request, struct blkif_response);
+
+#define VDISK_CDROM 0x1
+#define VDISK_REMOVABLE 0x2
+#define VDISK_READONLY 0x4
+
+#endif /* __XEN_PUBLIC_IO_BLKIF_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/include/xen/io/console.h b/include/xen/io/console.h
new file mode 100644
index 0000000..e2cd97f
--- /dev/null
+++ b/include/xen/io/console.h
@@ -0,0 +1,51 @@
+/******************************************************************************
+ * console.h
+ *
+ * Console I/O interface for Xen guest OSes.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright (c) 2005, Keir Fraser
+ */
+
+#ifndef __XEN_PUBLIC_IO_CONSOLE_H__
+#define __XEN_PUBLIC_IO_CONSOLE_H__
+
+typedef uint32_t XENCONS_RING_IDX;
+
+#define MASK_XENCONS_IDX(idx, ring) ((idx) & (sizeof(ring)-1))
+
+struct xencons_interface {
+ char in[1024];
+ char out[2048];
+ XENCONS_RING_IDX in_cons, in_prod;
+ XENCONS_RING_IDX out_cons, out_prod;
+};
+
+#endif /* __XEN_PUBLIC_IO_CONSOLE_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/include/xen/io/protocols.h b/include/xen/io/protocols.h
new file mode 100644
index 0000000..80b196b
--- /dev/null
+++ b/include/xen/io/protocols.h
@@ -0,0 +1,40 @@
+/******************************************************************************
+ * protocols.h
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __XEN_PROTOCOLS_H__
+#define __XEN_PROTOCOLS_H__
+
+#define XEN_IO_PROTO_ABI_X86_32 "x86_32-abi"
+#define XEN_IO_PROTO_ABI_X86_64 "x86_64-abi"
+#define XEN_IO_PROTO_ABI_ARM "arm-abi"
+
+#if defined(__i386__)
+# define XEN_IO_PROTO_ABI_NATIVE XEN_IO_PROTO_ABI_X86_32
+#elif defined(__x86_64__)
+# define XEN_IO_PROTO_ABI_NATIVE XEN_IO_PROTO_ABI_X86_64
+#elif defined(__arm__) || defined(__aarch64__)
+# define XEN_IO_PROTO_ABI_NATIVE XEN_IO_PROTO_ABI_ARM
+#else
+# error arch fixup needed here
+#endif
+
+#endif
diff --git a/include/xen/io/ring.h b/include/xen/io/ring.h
new file mode 100644
index 0000000..73e13d7
--- /dev/null
+++ b/include/xen/io/ring.h
@@ -0,0 +1,312 @@
+/******************************************************************************
+ * ring.h
+ *
+ * Shared producer-consumer ring macros.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Tim Deegan and Andrew Warfield November 2004.
+ */
+
+#ifndef __XEN_PUBLIC_IO_RING_H__
+#define __XEN_PUBLIC_IO_RING_H__
+
+#include "../xen-compat.h"
+
+#if __XEN_INTERFACE_VERSION__ < 0x00030208
+#define xen_mb() mb()
+#define xen_rmb() rmb()
+#define xen_wmb() wmb()
+#endif
+
+typedef unsigned int RING_IDX;
+
+/* Round a 32-bit unsigned constant down to the nearest power of two. */
+#define __RD2(_x) (((_x) & 0x00000002) ? 0x2 : ((_x) & 0x1))
+#define __RD4(_x) (((_x) & 0x0000000c) ? __RD2((_x)>>2)<<2 : __RD2(_x))
+#define __RD8(_x) (((_x) & 0x000000f0) ? __RD4((_x)>>4)<<4 : __RD4(_x))
+#define __RD16(_x) (((_x) & 0x0000ff00) ? __RD8((_x)>>8)<<8 : __RD8(_x))
+#define __RD32(_x) (((_x) & 0xffff0000) ? __RD16((_x)>>16)<<16 : __RD16(_x))
+
+/*
+ * Calculate size of a shared ring, given the total available space for the
+ * ring and indexes (_sz), and the name tag of the request/response structure.
+ * A ring contains as many entries as will fit, rounded down to the nearest
+ * power of two (so we can mask with (size-1) to loop around).
+ */
+#define __CONST_RING_SIZE(_s, _sz) \
+ (__RD32(((_sz) - offsetof(struct _s##_sring, ring)) / \
+ sizeof(((struct _s##_sring *)0)->ring[0])))
+/*
+ * The same for passing in an actual pointer instead of a name tag.
+ */
+#define __RING_SIZE(_s, _sz) \
+ (__RD32(((_sz) - (long)(_s)->ring + (long)(_s)) / sizeof((_s)->ring[0])))
+
+/*
+ * Macros to make the correct C datatypes for a new kind of ring.
+ *
+ * To make a new ring datatype, you need to have two message structures,
+ * let's say request_t, and response_t already defined.
+ *
+ * In a header where you want the ring datatype declared, you then do:
+ *
+ * DEFINE_RING_TYPES(mytag, request_t, response_t);
+ *
+ * These expand out to give you a set of types, as you can see below.
+ * The most important of these are:
+ *
+ * mytag_sring_t - The shared ring.
+ * mytag_front_ring_t - The 'front' half of the ring.
+ * mytag_back_ring_t - The 'back' half of the ring.
+ *
+ * To initialize a ring in your code you need to know the location and size
+ * of the shared memory area (PAGE_SIZE, for instance). To initialise
+ * the front half:
+ *
+ * mytag_front_ring_t front_ring;
+ * SHARED_RING_INIT((mytag_sring_t *)shared_page);
+ * FRONT_RING_INIT(&front_ring, (mytag_sring_t *)shared_page, PAGE_SIZE);
+ *
+ * Initializing the back follows similarly (note that only the front
+ * initializes the shared ring):
+ *
+ * mytag_back_ring_t back_ring;
+ * BACK_RING_INIT(&back_ring, (mytag_sring_t *)shared_page, PAGE_SIZE);
+ */
+
+#define DEFINE_RING_TYPES(__name, __req_t, __rsp_t) \
+ \
+/* Shared ring entry */ \
+union __name##_sring_entry { \
+ __req_t req; \
+ __rsp_t rsp; \
+}; \
+ \
+/* Shared ring page */ \
+struct __name##_sring { \
+ RING_IDX req_prod, req_event; \
+ RING_IDX rsp_prod, rsp_event; \
+ union { \
+ struct { \
+ uint8_t smartpoll_active; \
+ } netif; \
+ struct { \
+ uint8_t msg; \
+ } tapif_user; \
+ uint8_t pvt_pad[4]; \
+ } private; \
+ uint8_t __pad[44]; \
+ union __name##_sring_entry ring[1]; /* variable-length */ \
+}; \
+ \
+/* "Front" end's private variables */ \
+struct __name##_front_ring { \
+ RING_IDX req_prod_pvt; \
+ RING_IDX rsp_cons; \
+ unsigned int nr_ents; \
+ struct __name##_sring *sring; \
+}; \
+ \
+/* "Back" end's private variables */ \
+struct __name##_back_ring { \
+ RING_IDX rsp_prod_pvt; \
+ RING_IDX req_cons; \
+ unsigned int nr_ents; \
+ struct __name##_sring *sring; \
+}; \
+ \
+/* Syntactic sugar */ \
+typedef struct __name##_sring __name##_sring_t; \
+typedef struct __name##_front_ring __name##_front_ring_t; \
+typedef struct __name##_back_ring __name##_back_ring_t
+
+/*
+ * Macros for manipulating rings.
+ *
+ * FRONT_RING_whatever works on the "front end" of a ring: here
+ * requests are pushed on to the ring and responses taken off it.
+ *
+ * BACK_RING_whatever works on the "back end" of a ring: here
+ * requests are taken off the ring and responses put on.
+ *
+ * N.B. these macros do NO INTERLOCKS OR FLOW CONTROL.
+ * This is OK in 1-for-1 request-response situations where the
+ * requestor (front end) never has more than RING_SIZE()-1
+ * outstanding requests.
+ */
+
+/* Initialising empty rings */
+#define SHARED_RING_INIT(_s) do { \
+ (_s)->req_prod = (_s)->rsp_prod = 0; \
+ (_s)->req_event = (_s)->rsp_event = 1; \
+ (void)memset((_s)->private.pvt_pad, 0, sizeof((_s)->private.pvt_pad)); \
+ (void)memset((_s)->__pad, 0, sizeof((_s)->__pad)); \
+} while(0)
+
+#define FRONT_RING_INIT(_r, _s, __size) do { \
+ (_r)->req_prod_pvt = 0; \
+ (_r)->rsp_cons = 0; \
+ (_r)->nr_ents = __RING_SIZE(_s, __size); \
+ (_r)->sring = (_s); \
+} while (0)
+
+#define BACK_RING_INIT(_r, _s, __size) do { \
+ (_r)->rsp_prod_pvt = 0; \
+ (_r)->req_cons = 0; \
+ (_r)->nr_ents = __RING_SIZE(_s, __size); \
+ (_r)->sring = (_s); \
+} while (0)
+
+/* How big is this ring? */
+#define RING_SIZE(_r) \
+ ((_r)->nr_ents)
+
+/* Number of free requests (for use on front side only). */
+#define RING_FREE_REQUESTS(_r) \
+ (RING_SIZE(_r) - ((_r)->req_prod_pvt - (_r)->rsp_cons))
+
+/* Test if there is an empty slot available on the front ring.
+ * (This is only meaningful from the front. )
+ */
+#define RING_FULL(_r) \
+ (RING_FREE_REQUESTS(_r) == 0)
+
+/* Test if there are outstanding messages to be processed on a ring. */
+#define RING_HAS_UNCONSUMED_RESPONSES(_r) \
+ ((_r)->sring->rsp_prod - (_r)->rsp_cons)
+
+#ifdef __GNUC__
+#define RING_HAS_UNCONSUMED_REQUESTS(_r) ({ \
+ unsigned int req = (_r)->sring->req_prod - (_r)->req_cons; \
+ unsigned int rsp = RING_SIZE(_r) - \
+ ((_r)->req_cons - (_r)->rsp_prod_pvt); \
+ req < rsp ? req : rsp; \
+})
+#else
+/* Same as above, but without the nice GCC ({ ... }) syntax. */
+#define RING_HAS_UNCONSUMED_REQUESTS(_r) \
+ ((((_r)->sring->req_prod - (_r)->req_cons) < \
+ (RING_SIZE(_r) - ((_r)->req_cons - (_r)->rsp_prod_pvt))) ? \
+ ((_r)->sring->req_prod - (_r)->req_cons) : \
+ (RING_SIZE(_r) - ((_r)->req_cons - (_r)->rsp_prod_pvt)))
+#endif
+
+/* Direct access to individual ring elements, by index. */
+#define RING_GET_REQUEST(_r, _idx) \
+ (&((_r)->sring->ring[((_idx) & (RING_SIZE(_r) - 1))].req))
+
+#define RING_GET_RESPONSE(_r, _idx) \
+ (&((_r)->sring->ring[((_idx) & (RING_SIZE(_r) - 1))].rsp))
+
+/* Loop termination condition: Would the specified index overflow the ring? */
+#define RING_REQUEST_CONS_OVERFLOW(_r, _cons) \
+ (((_cons) - (_r)->rsp_prod_pvt) >= RING_SIZE(_r))
+
+/* Ill-behaved frontend determination: Can there be this many requests? */
+#define RING_REQUEST_PROD_OVERFLOW(_r, _prod) \
+ (((_prod) - (_r)->rsp_prod_pvt) > RING_SIZE(_r))
+
+#define RING_PUSH_REQUESTS(_r) do { \
+ xen_wmb(); /* back sees requests /before/ updated producer index */ \
+ (_r)->sring->req_prod = (_r)->req_prod_pvt; \
+} while (0)
+
+#define RING_PUSH_RESPONSES(_r) do { \
+ xen_wmb(); /* front sees resps /before/ updated producer index */ \
+ (_r)->sring->rsp_prod = (_r)->rsp_prod_pvt; \
+} while (0)
+
+/*
+ * Notification hold-off (req_event and rsp_event):
+ *
+ * When queueing requests or responses on a shared ring, it may not always be
+ * necessary to notify the remote end. For example, if requests are in flight
+ * in a backend, the front may be able to queue further requests without
+ * notifying the back (if the back checks for new requests when it queues
+ * responses).
+ *
+ * When enqueuing requests or responses:
+ *
+ * Use RING_PUSH_{REQUESTS,RESPONSES}_AND_CHECK_NOTIFY(). The second argument
+ * is a boolean return value. True indicates that the receiver requires an
+ * asynchronous notification.
+ *
+ * After dequeuing requests or responses (before sleeping the connection):
+ *
+ * Use RING_FINAL_CHECK_FOR_REQUESTS() or RING_FINAL_CHECK_FOR_RESPONSES().
+ * The second argument is a boolean return value. True indicates that there
+ * are pending messages on the ring (i.e., the connection should not be put
+ * to sleep).
+ *
+ * These macros will set the req_event/rsp_event field to trigger a
+ * notification on the very next message that is enqueued. If you want to
+ * create batches of work (i.e., only receive a notification after several
+ * messages have been enqueued) then you will need to create a customised
+ * version of the FINAL_CHECK macro in your own code, which sets the event
+ * field appropriately.
+ */
+
+#define RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(_r, _notify) do { \
+ RING_IDX __old = (_r)->sring->req_prod; \
+ RING_IDX __new = (_r)->req_prod_pvt; \
+ xen_wmb(); /* back sees requests /before/ updated producer index */ \
+ (_r)->sring->req_prod = __new; \
+ xen_mb(); /* back sees new requests /before/ we check req_event */ \
+ (_notify) = ((RING_IDX)(__new - (_r)->sring->req_event) < \
+ (RING_IDX)(__new - __old)); \
+} while (0)
+
+#define RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(_r, _notify) do { \
+ RING_IDX __old = (_r)->sring->rsp_prod; \
+ RING_IDX __new = (_r)->rsp_prod_pvt; \
+ xen_wmb(); /* front sees resps /before/ updated producer index */ \
+ (_r)->sring->rsp_prod = __new; \
+ xen_mb(); /* front sees new resps /before/ we check rsp_event */ \
+ (_notify) = ((RING_IDX)(__new - (_r)->sring->rsp_event) < \
+ (RING_IDX)(__new - __old)); \
+} while (0)
+
+#define RING_FINAL_CHECK_FOR_REQUESTS(_r, _work_to_do) do { \
+ (_work_to_do) = RING_HAS_UNCONSUMED_REQUESTS(_r); \
+ if (_work_to_do) break; \
+ (_r)->sring->req_event = (_r)->req_cons + 1; \
+ xen_mb(); \
+ (_work_to_do) = RING_HAS_UNCONSUMED_REQUESTS(_r); \
+} while (0)
+
+#define RING_FINAL_CHECK_FOR_RESPONSES(_r, _work_to_do) do { \
+ (_work_to_do) = RING_HAS_UNCONSUMED_RESPONSES(_r); \
+ if (_work_to_do) break; \
+ (_r)->sring->rsp_event = (_r)->rsp_cons + 1; \
+ xen_mb(); \
+ (_work_to_do) = RING_HAS_UNCONSUMED_RESPONSES(_r); \
+} while (0)
+
+#endif /* __XEN_PUBLIC_IO_RING_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/include/xen/io/xenbus.h b/include/xen/io/xenbus.h
new file mode 100644
index 0000000..927f9db
--- /dev/null
+++ b/include/xen/io/xenbus.h
@@ -0,0 +1,80 @@
+/*****************************************************************************
+ * xenbus.h
+ *
+ * Xenbus protocol details.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright (C) 2005 XenSource Ltd.
+ */
+
+#ifndef _XEN_PUBLIC_IO_XENBUS_H
+#define _XEN_PUBLIC_IO_XENBUS_H
+
+/*
+ * The state of either end of the Xenbus, i.e. the current communication
+ * status of initialisation across the bus. States here imply nothing about
+ * the state of the connection between the driver and the kernel's device
+ * layers.
+ */
+enum xenbus_state {
+ XenbusStateUnknown = 0,
+
+ XenbusStateInitialising = 1,
+
+ /*
+ * InitWait: Finished early initialisation but waiting for information
+ * from the peer or hotplug scripts.
+ */
+ XenbusStateInitWait = 2,
+
+ /*
+ * Initialised: Waiting for a connection from the peer.
+ */
+ XenbusStateInitialised = 3,
+
+ XenbusStateConnected = 4,
+
+ /*
+ * Closing: The device is being closed due to an error or an unplug event.
+ */
+ XenbusStateClosing = 5,
+
+ XenbusStateClosed = 6,
+
+ /*
+ * Reconfiguring: The device is being reconfigured.
+ */
+ XenbusStateReconfiguring = 7,
+
+ XenbusStateReconfigured = 8
+};
+typedef enum xenbus_state XenbusState;
+
+#endif /* _XEN_PUBLIC_IO_XENBUS_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/include/xen/io/xs_wire.h b/include/xen/io/xs_wire.h
new file mode 100644
index 0000000..585f0c8
--- /dev/null
+++ b/include/xen/io/xs_wire.h
@@ -0,0 +1,138 @@
+/*
+ * Details of the "wire" protocol between Xen Store Daemon and client
+ * library or guest kernel.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright (C) 2005 Rusty Russell IBM Corporation
+ */
+
+#ifndef _XS_WIRE_H
+#define _XS_WIRE_H
+
+enum xsd_sockmsg_type
+{
+ XS_DEBUG,
+ XS_DIRECTORY,
+ XS_READ,
+ XS_GET_PERMS,
+ XS_WATCH,
+ XS_UNWATCH,
+ XS_TRANSACTION_START,
+ XS_TRANSACTION_END,
+ XS_INTRODUCE,
+ XS_RELEASE,
+ XS_GET_DOMAIN_PATH,
+ XS_WRITE,
+ XS_MKDIR,
+ XS_RM,
+ XS_SET_PERMS,
+ XS_WATCH_EVENT,
+ XS_ERROR,
+ XS_IS_DOMAIN_INTRODUCED,
+ XS_RESUME,
+ XS_SET_TARGET,
+ XS_RESTRICT,
+ XS_RESET_WATCHES
+};
+
+#define XS_WRITE_NONE "NONE"
+#define XS_WRITE_CREATE "CREATE"
+#define XS_WRITE_CREATE_EXCL "CREATE|EXCL"
+
+/* We hand errors as strings, for portability. */
+struct xsd_errors
+{
+ int errnum;
+ const char *errstring;
+};
+#ifdef EINVAL
+#define XSD_ERROR(x) { x, #x }
+/* LINTED: static unused */
+static struct xsd_errors xsd_errors[]
+#if defined(__GNUC__)
+__attribute__((unused))
+#endif
+ = {
+ XSD_ERROR(EINVAL),
+ XSD_ERROR(EACCES),
+ XSD_ERROR(EEXIST),
+ XSD_ERROR(EISDIR),
+ XSD_ERROR(ENOENT),
+ XSD_ERROR(ENOMEM),
+ XSD_ERROR(ENOSPC),
+ XSD_ERROR(EIO),
+ XSD_ERROR(ENOTEMPTY),
+ XSD_ERROR(ENOSYS),
+ XSD_ERROR(EROFS),
+ XSD_ERROR(EBUSY),
+ XSD_ERROR(EAGAIN),
+ XSD_ERROR(EISCONN),
+ XSD_ERROR(E2BIG)
+};
+#endif
+
+struct xsd_sockmsg
+{
+ uint32_t type; /* XS_??? */
+ uint32_t req_id;/* Request identifier, echoed in daemon's response. */
+ uint32_t tx_id; /* Transaction id (0 if not related to a transaction). */
+ uint32_t len; /* Length of data following this. */
+
+ /* Generally followed by nul-terminated string(s). */
+};
+
+enum xs_watch_type
+{
+ XS_WATCH_PATH = 0,
+ XS_WATCH_TOKEN
+};
+
+/*
+ * `incontents 150 xenstore_struct XenStore wire protocol.
+ *
+ * Inter-domain shared memory communications. */
+#define XENSTORE_RING_SIZE 1024
+typedef uint32_t XENSTORE_RING_IDX;
+#define MASK_XENSTORE_IDX(idx) ((idx) & (XENSTORE_RING_SIZE-1))
+struct xenstore_domain_interface {
+ char req[XENSTORE_RING_SIZE]; /* Requests to xenstore daemon. */
+ char rsp[XENSTORE_RING_SIZE]; /* Replies and async watch events. */
+ XENSTORE_RING_IDX req_cons, req_prod;
+ XENSTORE_RING_IDX rsp_cons, rsp_prod;
+};
+
+/* Violating this is very bad. See docs/misc/xenstore.txt. */
+#define XENSTORE_PAYLOAD_MAX 4096
+
+/* Violating these just gets you an error back */
+#define XENSTORE_ABS_PATH_MAX 3072
+#define XENSTORE_REL_PATH_MAX 2048
+
+#endif /* _XS_WIRE_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/include/xen/memory.h b/include/xen/memory.h
new file mode 100644
index 0000000..20deef5
--- /dev/null
+++ b/include/xen/memory.h
@@ -0,0 +1,665 @@
+/******************************************************************************
+ * memory.h
+ *
+ * Memory reservation and information.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright (c) 2005, Keir Fraser <keir@xensource.com>
+ */
+
+#ifndef __XEN_PUBLIC_MEMORY_H__
+#define __XEN_PUBLIC_MEMORY_H__
+
+#include "xen.h"
+#include "physdev.h"
+
+/*
+ * Increase or decrease the specified domain's memory reservation. Returns the
+ * number of extents successfully allocated or freed.
+ * arg == addr of struct xen_memory_reservation.
+ */
+#define XENMEM_increase_reservation 0
+#define XENMEM_decrease_reservation 1
+#define XENMEM_populate_physmap 6
+
+#if __XEN_INTERFACE_VERSION__ >= 0x00030209
+/*
+ * Maximum # bits addressable by the user of the allocated region (e.g., I/O
+ * devices often have a 32-bit limitation even in 64-bit systems). If zero
+ * then the user has no addressing restriction. This field is not used by
+ * XENMEM_decrease_reservation.
+ */
+#define XENMEMF_address_bits(x) (x)
+#define XENMEMF_get_address_bits(x) ((x) & 0xffu)
+/* NUMA node to allocate from. */
+#define XENMEMF_node(x) (((x) + 1) << 8)
+#define XENMEMF_get_node(x) ((((x) >> 8) - 1) & 0xffu)
+/* Flag to populate physmap with populate-on-demand entries */
+#define XENMEMF_populate_on_demand (1<<16)
+/* Flag to request allocation only from the node specified */
+#define XENMEMF_exact_node_request (1<<17)
+#define XENMEMF_exact_node(n) (XENMEMF_node(n) | XENMEMF_exact_node_request)
+/* Flag to indicate the node specified is virtual node */
+#define XENMEMF_vnode (1<<18)
+#endif
+
+struct xen_memory_reservation {
+
+ /*
+ * XENMEM_increase_reservation:
+ * OUT: MFN (*not* GMFN) bases of extents that were allocated
+ * XENMEM_decrease_reservation:
+ * IN: GMFN bases of extents to free
+ * XENMEM_populate_physmap:
+ * IN: GPFN bases of extents to populate with memory
+ * OUT: GMFN bases of extents that were allocated
+ * (NB. This command also updates the mach_to_phys translation table)
+ * XENMEM_claim_pages:
+ * IN: must be zero
+ */
+ XEN_GUEST_HANDLE(xen_pfn_t) extent_start;
+
+ /* Number of extents, and size/alignment of each (2^extent_order pages). */
+ xen_ulong_t nr_extents;
+ unsigned int extent_order;
+
+#if __XEN_INTERFACE_VERSION__ >= 0x00030209
+ /* XENMEMF flags. */
+ unsigned int mem_flags;
+#else
+ unsigned int address_bits;
+#endif
+
+ /*
+ * Domain whose reservation is being changed.
+ * Unprivileged domains can specify only DOMID_SELF.
+ */
+ domid_t domid;
+};
+typedef struct xen_memory_reservation xen_memory_reservation_t;
+DEFINE_XEN_GUEST_HANDLE(xen_memory_reservation_t);
+
+/*
+ * An atomic exchange of memory pages. If return code is zero then
+ * @out.extent_list provides GMFNs of the newly-allocated memory.
+ * Returns zero on complete success, otherwise a negative error code.
+ * On complete success then always @nr_exchanged == @in.nr_extents.
+ * On partial success @nr_exchanged indicates how much work was done.
+ *
+ * Note that only PV guests can use this operation.
+ */
+#define XENMEM_exchange 11
+struct xen_memory_exchange {
+ /*
+ * [IN] Details of memory extents to be exchanged (GMFN bases).
+ * Note that @in.address_bits is ignored and unused.
+ */
+ struct xen_memory_reservation in;
+
+ /*
+ * [IN/OUT] Details of new memory extents.
+ * We require that:
+ * 1. @in.domid == @out.domid
+ * 2. @in.nr_extents << @in.extent_order ==
+ * @out.nr_extents << @out.extent_order
+ * 3. @in.extent_start and @out.extent_start lists must not overlap
+ * 4. @out.extent_start lists GPFN bases to be populated
+ * 5. @out.extent_start is overwritten with allocated GMFN bases
+ */
+ struct xen_memory_reservation out;
+
+ /*
+ * [OUT] Number of input extents that were successfully exchanged:
+ * 1. The first @nr_exchanged input extents were successfully
+ * deallocated.
+ * 2. The corresponding first entries in the output extent list correctly
+ * indicate the GMFNs that were successfully exchanged.
+ * 3. All other input and output extents are untouched.
+ * 4. If not all input exents are exchanged then the return code of this
+ * command will be non-zero.
+ * 5. THIS FIELD MUST BE INITIALISED TO ZERO BY THE CALLER!
+ */
+ xen_ulong_t nr_exchanged;
+};
+typedef struct xen_memory_exchange xen_memory_exchange_t;
+DEFINE_XEN_GUEST_HANDLE(xen_memory_exchange_t);
+
+/*
+ * Returns the maximum machine frame number of mapped RAM in this system.
+ * This command always succeeds (it never returns an error code).
+ * arg == NULL.
+ */
+#define XENMEM_maximum_ram_page 2
+
+/*
+ * Returns the current or maximum memory reservation, in pages, of the
+ * specified domain (may be DOMID_SELF). Returns -ve errcode on failure.
+ * arg == addr of domid_t.
+ */
+#define XENMEM_current_reservation 3
+#define XENMEM_maximum_reservation 4
+
+/*
+ * Returns the maximum GPFN in use by the guest, or -ve errcode on failure.
+ */
+#define XENMEM_maximum_gpfn 14
+
+/*
+ * Returns a list of MFN bases of 2MB extents comprising the machine_to_phys
+ * mapping table. Architectures which do not have a m2p table do not implement
+ * this command.
+ * arg == addr of xen_machphys_mfn_list_t.
+ */
+#define XENMEM_machphys_mfn_list 5
+struct xen_machphys_mfn_list {
+ /*
+ * Size of the 'extent_start' array. Fewer entries will be filled if the
+ * machphys table is smaller than max_extents * 2MB.
+ */
+ unsigned int max_extents;
+
+ /*
+ * Pointer to buffer to fill with list of extent starts. If there are
+ * any large discontiguities in the machine address space, 2MB gaps in
+ * the machphys table will be represented by an MFN base of zero.
+ */
+ XEN_GUEST_HANDLE(xen_pfn_t) extent_start;
+
+ /*
+ * Number of extents written to the above array. This will be smaller
+ * than 'max_extents' if the machphys table is smaller than max_e * 2MB.
+ */
+ unsigned int nr_extents;
+};
+typedef struct xen_machphys_mfn_list xen_machphys_mfn_list_t;
+DEFINE_XEN_GUEST_HANDLE(xen_machphys_mfn_list_t);
+
+/*
+ * For a compat caller, this is identical to XENMEM_machphys_mfn_list.
+ *
+ * For a non compat caller, this functions similarly to
+ * XENMEM_machphys_mfn_list, but returns the mfns making up the compatibility
+ * m2p table.
+ */
+#define XENMEM_machphys_compat_mfn_list 25
+
+/*
+ * Returns the location in virtual address space of the machine_to_phys
+ * mapping table. Architectures which do not have a m2p table, or which do not
+ * map it by default into guest address space, do not implement this command.
+ * arg == addr of xen_machphys_mapping_t.
+ */
+#define XENMEM_machphys_mapping 12
+struct xen_machphys_mapping {
+ xen_ulong_t v_start, v_end; /* Start and end virtual addresses. */
+ xen_ulong_t max_mfn; /* Maximum MFN that can be looked up. */
+};
+typedef struct xen_machphys_mapping xen_machphys_mapping_t;
+DEFINE_XEN_GUEST_HANDLE(xen_machphys_mapping_t);
+
+/* Source mapping space. */
+/* ` enum phys_map_space { */
+#define XENMAPSPACE_shared_info 0 /* shared info page */
+#define XENMAPSPACE_grant_table 1 /* grant table page */
+#define XENMAPSPACE_gmfn 2 /* GMFN */
+#define XENMAPSPACE_gmfn_range 3 /* GMFN range, XENMEM_add_to_physmap only. */
+#define XENMAPSPACE_gmfn_foreign 4 /* GMFN from another dom,
+ * XENMEM_add_to_physmap_batch only. */
+#define XENMAPSPACE_dev_mmio 5 /* device mmio region
+ ARM only; the region is mapped in
+ Stage-2 using the Normal Memory
+ Inner/Outer Write-Back Cacheable
+ memory attribute. */
+/* ` } */
+
+/*
+ * Sets the GPFN at which a particular page appears in the specified guest's
+ * pseudophysical address space.
+ * arg == addr of xen_add_to_physmap_t.
+ */
+#define XENMEM_add_to_physmap 7
+struct xen_add_to_physmap {
+ /* Which domain to change the mapping for. */
+ domid_t domid;
+
+ /* Number of pages to go through for gmfn_range */
+ uint16_t size;
+
+ unsigned int space; /* => enum phys_map_space */
+
+#define XENMAPIDX_grant_table_status 0x80000000
+
+ /* Index into space being mapped. */
+ xen_ulong_t idx;
+
+ /* GPFN in domid where the source mapping page should appear. */
+ xen_pfn_t gpfn;
+};
+typedef struct xen_add_to_physmap xen_add_to_physmap_t;
+DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_t);
+
+/* A batched version of add_to_physmap. */
+#define XENMEM_add_to_physmap_batch 23
+struct xen_add_to_physmap_batch {
+ /* IN */
+ /* Which domain to change the mapping for. */
+ domid_t domid;
+ uint16_t space; /* => enum phys_map_space */
+
+ /* Number of pages to go through */
+ uint16_t size;
+
+#if __XEN_INTERFACE_VERSION__ < 0x00040700
+ domid_t foreign_domid; /* IFF gmfn_foreign. Should be 0 for other spaces. */
+#else
+ union xen_add_to_physmap_batch_extra {
+ domid_t foreign_domid; /* gmfn_foreign */
+ uint16_t res0; /* All the other spaces. Should be 0 */
+ } u;
+#endif
+
+ /* Indexes into space being mapped. */
+ XEN_GUEST_HANDLE(xen_ulong_t) idxs;
+
+ /* GPFN in domid where the source mapping page should appear. */
+ XEN_GUEST_HANDLE(xen_pfn_t) gpfns;
+
+ /* OUT */
+
+ /* Per index error code. */
+ XEN_GUEST_HANDLE(int) errs;
+};
+typedef struct xen_add_to_physmap_batch xen_add_to_physmap_batch_t;
+DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_batch_t);
+
+#if __XEN_INTERFACE_VERSION__ < 0x00040400
+#define XENMEM_add_to_physmap_range XENMEM_add_to_physmap_batch
+#define xen_add_to_physmap_range xen_add_to_physmap_batch
+typedef struct xen_add_to_physmap_batch xen_add_to_physmap_range_t;
+DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_range_t);
+#endif
+
+/*
+ * Unmaps the page appearing at a particular GPFN from the specified guest's
+ * pseudophysical address space.
+ * arg == addr of xen_remove_from_physmap_t.
+ */
+#define XENMEM_remove_from_physmap 15
+struct xen_remove_from_physmap {
+ /* Which domain to change the mapping for. */
+ domid_t domid;
+
+ /* GPFN of the current mapping of the page. */
+ xen_pfn_t gpfn;
+};
+typedef struct xen_remove_from_physmap xen_remove_from_physmap_t;
+DEFINE_XEN_GUEST_HANDLE(xen_remove_from_physmap_t);
+
+/*** REMOVED ***/
+/*#define XENMEM_translate_gpfn_list 8*/
+
+/*
+ * Returns the pseudo-physical memory map as it was when the domain
+ * was started (specified by XENMEM_set_memory_map).
+ * arg == addr of xen_memory_map_t.
+ */
+#define XENMEM_memory_map 9
+struct xen_memory_map {
+ /*
+ * On call the number of entries which can be stored in buffer. On
+ * return the number of entries which have been stored in
+ * buffer.
+ */
+ unsigned int nr_entries;
+
+ /*
+ * Entries in the buffer are in the same format as returned by the
+ * BIOS INT 0x15 EAX=0xE820 call.
+ */
+ XEN_GUEST_HANDLE(void) buffer;
+};
+typedef struct xen_memory_map xen_memory_map_t;
+DEFINE_XEN_GUEST_HANDLE(xen_memory_map_t);
+
+/*
+ * Returns the real physical memory map. Passes the same structure as
+ * XENMEM_memory_map.
+ * Specifying buffer as NULL will return the number of entries required
+ * to store the complete memory map.
+ * arg == addr of xen_memory_map_t.
+ */
+#define XENMEM_machine_memory_map 10
+
+/*
+ * Set the pseudo-physical memory map of a domain, as returned by
+ * XENMEM_memory_map.
+ * arg == addr of xen_foreign_memory_map_t.
+ */
+#define XENMEM_set_memory_map 13
+struct xen_foreign_memory_map {
+ domid_t domid;
+ struct xen_memory_map map;
+};
+typedef struct xen_foreign_memory_map xen_foreign_memory_map_t;
+DEFINE_XEN_GUEST_HANDLE(xen_foreign_memory_map_t);
+
+#define XENMEM_set_pod_target 16
+#define XENMEM_get_pod_target 17
+struct xen_pod_target {
+ /* IN */
+ uint64_t target_pages;
+ /* OUT */
+ uint64_t tot_pages;
+ uint64_t pod_cache_pages;
+ uint64_t pod_entries;
+ /* IN */
+ domid_t domid;
+};
+typedef struct xen_pod_target xen_pod_target_t;
+
+#if defined(__XEN__) || defined(__XEN_TOOLS__)
+
+#ifndef uint64_aligned_t
+#define uint64_aligned_t uint64_t
+#endif
+
+/*
+ * Get the number of MFNs saved through memory sharing.
+ * The call never fails.
+ */
+#define XENMEM_get_sharing_freed_pages 18
+#define XENMEM_get_sharing_shared_pages 19
+
+#define XENMEM_paging_op 20
+#define XENMEM_paging_op_nominate 0
+#define XENMEM_paging_op_evict 1
+#define XENMEM_paging_op_prep 2
+
+struct xen_mem_paging_op {
+ uint8_t op; /* XENMEM_paging_op_* */
+ domid_t domain;
+
+ /* PAGING_PREP IN: buffer to immediately fill page in */
+ uint64_aligned_t buffer;
+ /* Other OPs */
+ uint64_aligned_t gfn; /* IN: gfn of page being operated on */
+};
+typedef struct xen_mem_paging_op xen_mem_paging_op_t;
+DEFINE_XEN_GUEST_HANDLE(xen_mem_paging_op_t);
+
+#define XENMEM_access_op 21
+#define XENMEM_access_op_set_access 0
+#define XENMEM_access_op_get_access 1
+/*
+ * XENMEM_access_op_enable_emulate and XENMEM_access_op_disable_emulate are
+ * currently unused, but since they have been in use please do not reuse them.
+ *
+ * #define XENMEM_access_op_enable_emulate 2
+ * #define XENMEM_access_op_disable_emulate 3
+ */
+#define XENMEM_access_op_set_access_multi 4
+
+typedef enum {
+ XENMEM_access_n,
+ XENMEM_access_r,
+ XENMEM_access_w,
+ XENMEM_access_rw,
+ XENMEM_access_x,
+ XENMEM_access_rx,
+ XENMEM_access_wx,
+ XENMEM_access_rwx,
+ /*
+ * Page starts off as r-x, but automatically
+ * change to r-w on a write
+ */
+ XENMEM_access_rx2rw,
+ /*
+ * Log access: starts off as n, automatically
+ * goes to rwx, generating an event without
+ * pausing the vcpu
+ */
+ XENMEM_access_n2rwx,
+ /* Take the domain default */
+ XENMEM_access_default
+} xenmem_access_t;
+
+struct xen_mem_access_op {
+ /* XENMEM_access_op_* */
+ uint8_t op;
+ /* xenmem_access_t */
+ uint8_t access;
+ domid_t domid;
+ /*
+ * Number of pages for set op (or size of pfn_list for
+ * XENMEM_access_op_set_access_multi)
+ * Ignored on setting default access and other ops
+ */
+ uint32_t nr;
+ /*
+ * First pfn for set op
+ * pfn for get op
+ * ~0ull is used to set and get the default access for pages
+ */
+ uint64_aligned_t pfn;
+ /*
+ * List of pfns to set access for
+ * Used only with XENMEM_access_op_set_access_multi
+ */
+ XEN_GUEST_HANDLE(const_uint64) pfn_list;
+ /*
+ * Corresponding list of access settings for pfn_list
+ * Used only with XENMEM_access_op_set_access_multi
+ */
+ XEN_GUEST_HANDLE(const_uint8) access_list;
+};
+typedef struct xen_mem_access_op xen_mem_access_op_t;
+DEFINE_XEN_GUEST_HANDLE(xen_mem_access_op_t);
+
+#define XENMEM_sharing_op 22
+#define XENMEM_sharing_op_nominate_gfn 0
+#define XENMEM_sharing_op_nominate_gref 1
+#define XENMEM_sharing_op_share 2
+#define XENMEM_sharing_op_debug_gfn 3
+#define XENMEM_sharing_op_debug_mfn 4
+#define XENMEM_sharing_op_debug_gref 5
+#define XENMEM_sharing_op_add_physmap 6
+#define XENMEM_sharing_op_audit 7
+#define XENMEM_sharing_op_range_share 8
+
+#define XENMEM_SHARING_OP_S_HANDLE_INVALID (-10)
+#define XENMEM_SHARING_OP_C_HANDLE_INVALID (-9)
+
+/* The following allows sharing of grant refs. This is useful
+ * for sharing utilities sitting as "filters" in IO backends
+ * (e.g. memshr + blktap(2)). The IO backend is only exposed
+ * to grant references, and this allows sharing of the grefs */
+#define XENMEM_SHARING_OP_FIELD_IS_GREF_FLAG (xen_mk_ullong(1) << 62)
+
+#define XENMEM_SHARING_OP_FIELD_MAKE_GREF(field, val) \
+ (field) = (XENMEM_SHARING_OP_FIELD_IS_GREF_FLAG | val)
+#define XENMEM_SHARING_OP_FIELD_IS_GREF(field) \
+ ((field) & XENMEM_SHARING_OP_FIELD_IS_GREF_FLAG)
+#define XENMEM_SHARING_OP_FIELD_GET_GREF(field) \
+ ((field) & (~XENMEM_SHARING_OP_FIELD_IS_GREF_FLAG))
+
+struct xen_mem_sharing_op {
+ uint8_t op; /* XENMEM_sharing_op_* */
+ domid_t domain;
+
+ union {
+ struct mem_sharing_op_nominate { /* OP_NOMINATE_xxx */
+ union {
+ uint64_aligned_t gfn; /* IN: gfn to nominate */
+ uint32_t grant_ref; /* IN: grant ref to nominate */
+ } u;
+ uint64_aligned_t handle; /* OUT: the handle */
+ } nominate;
+ struct mem_sharing_op_share { /* OP_SHARE/ADD_PHYSMAP */
+ uint64_aligned_t source_gfn; /* IN: the gfn of the source page */
+ uint64_aligned_t source_handle; /* IN: handle to the source page */
+ uint64_aligned_t client_gfn; /* IN: the client gfn */
+ uint64_aligned_t client_handle; /* IN: handle to the client page */
+ domid_t client_domain; /* IN: the client domain id */
+ } share;
+ struct mem_sharing_op_range { /* OP_RANGE_SHARE */
+ uint64_aligned_t first_gfn; /* IN: the first gfn */
+ uint64_aligned_t last_gfn; /* IN: the last gfn */
+ uint64_aligned_t opaque; /* Must be set to 0 */
+ domid_t client_domain; /* IN: the client domain id */
+ uint16_t _pad[3]; /* Must be set to 0 */
+ } range;
+ struct mem_sharing_op_debug { /* OP_DEBUG_xxx */
+ union {
+ uint64_aligned_t gfn; /* IN: gfn to debug */
+ uint64_aligned_t mfn; /* IN: mfn to debug */
+ uint32_t gref; /* IN: gref to debug */
+ } u;
+ } debug;
+ } u;
+};
+typedef struct xen_mem_sharing_op xen_mem_sharing_op_t;
+DEFINE_XEN_GUEST_HANDLE(xen_mem_sharing_op_t);
+
+/*
+ * Attempt to stake a claim for a domain on a quantity of pages
+ * of system RAM, but _not_ assign specific pageframes. Only
+ * arithmetic is performed so the hypercall is very fast and need
+ * not be preemptible, thus sidestepping time-of-check-time-of-use
+ * races for memory allocation. Returns 0 if the hypervisor page
+ * allocator has atomically and successfully claimed the requested
+ * number of pages, else non-zero.
+ *
+ * Any domain may have only one active claim. When sufficient memory
+ * has been allocated to resolve the claim, the claim silently expires.
+ * Claiming zero pages effectively resets any outstanding claim and
+ * is always successful.
+ *
+ * Note that a valid claim may be staked even after memory has been
+ * allocated for a domain. In this case, the claim is not incremental,
+ * i.e. if the domain's tot_pages is 3, and a claim is staked for 10,
+ * only 7 additional pages are claimed.
+ *
+ * Caller must be privileged or the hypercall fails.
+ */
+#define XENMEM_claim_pages 24
+
+/*
+ * XENMEM_claim_pages flags - the are no flags at this time.
+ * The zero value is appropriate.
+ */
+
+/*
+ * With some legacy devices, certain guest-physical addresses cannot safely
+ * be used for other purposes, e.g. to map guest RAM. This hypercall
+ * enumerates those regions so the toolstack can avoid using them.
+ */
+#define XENMEM_reserved_device_memory_map 27
+struct xen_reserved_device_memory {
+ xen_pfn_t start_pfn;
+ xen_ulong_t nr_pages;
+};
+typedef struct xen_reserved_device_memory xen_reserved_device_memory_t;
+DEFINE_XEN_GUEST_HANDLE(xen_reserved_device_memory_t);
+
+struct xen_reserved_device_memory_map {
+#define XENMEM_RDM_ALL 1 /* Request all regions (ignore dev union). */
+ /* IN */
+ uint32_t flags;
+ /*
+ * IN/OUT
+ *
+ * Gets set to the required number of entries when too low,
+ * signaled by error code -ERANGE.
+ */
+ unsigned int nr_entries;
+ /* OUT */
+ XEN_GUEST_HANDLE(xen_reserved_device_memory_t) buffer;
+ /* IN */
+ union {
+ struct physdev_pci_device pci;
+ } dev;
+};
+typedef struct xen_reserved_device_memory_map xen_reserved_device_memory_map_t;
+DEFINE_XEN_GUEST_HANDLE(xen_reserved_device_memory_map_t);
+
+#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */
+
+/*
+ * XENMEM_get_vnumainfo used by guest to get
+ * vNUMA topology from hypervisor.
+ */
+#define XENMEM_get_vnumainfo 26
+
+/* vNUMA node memory ranges */
+struct xen_vmemrange {
+ uint64_t start, end;
+ unsigned int flags;
+ unsigned int nid;
+};
+typedef struct xen_vmemrange xen_vmemrange_t;
+DEFINE_XEN_GUEST_HANDLE(xen_vmemrange_t);
+
+/*
+ * vNUMA topology specifies vNUMA node number, distance table,
+ * memory ranges and vcpu mapping provided for guests.
+ * XENMEM_get_vnumainfo hypercall expects to see from guest
+ * nr_vnodes, nr_vmemranges and nr_vcpus to indicate available memory.
+ * After filling guests structures, nr_vnodes, nr_vmemranges and nr_vcpus
+ * copied back to guest. Domain returns expected values of nr_vnodes,
+ * nr_vmemranges and nr_vcpus to guest if the values where incorrect.
+ */
+struct xen_vnuma_topology_info {
+ /* IN */
+ domid_t domid;
+ uint16_t pad;
+ /* IN/OUT */
+ unsigned int nr_vnodes;
+ unsigned int nr_vcpus;
+ unsigned int nr_vmemranges;
+ /* OUT */
+ union {
+ XEN_GUEST_HANDLE(uint) h;
+ uint64_t pad;
+ } vdistance;
+ union {
+ XEN_GUEST_HANDLE(uint) h;
+ uint64_t pad;
+ } vcpu_to_vnode;
+ union {
+ XEN_GUEST_HANDLE(xen_vmemrange_t) h;
+ uint64_t pad;
+ } vmemrange;
+};
+typedef struct xen_vnuma_topology_info xen_vnuma_topology_info_t;
+DEFINE_XEN_GUEST_HANDLE(xen_vnuma_topology_info_t);
+
+/* Next available subop number is 28 */
+
+#endif /* __XEN_PUBLIC_MEMORY_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/include/xen/physdev.h b/include/xen/physdev.h
new file mode 100644
index 0000000..b6faf83
--- /dev/null
+++ b/include/xen/physdev.h
@@ -0,0 +1,387 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright (c) 2006, Keir Fraser
+ */
+
+#ifndef __XEN_PUBLIC_PHYSDEV_H__
+#define __XEN_PUBLIC_PHYSDEV_H__
+
+#include "xen.h"
+
+/*
+ * Prototype for this hypercall is:
+ * int physdev_op(int cmd, void *args)
+ * @cmd == PHYSDEVOP_??? (physdev operation).
+ * @args == Operation-specific extra arguments (NULL if none).
+ */
+
+/*
+ * Notify end-of-interrupt (EOI) for the specified IRQ.
+ * @arg == pointer to physdev_eoi structure.
+ */
+#define PHYSDEVOP_eoi 12
+struct physdev_eoi {
+ /* IN */
+ uint32_t irq;
+};
+typedef struct physdev_eoi physdev_eoi_t;
+DEFINE_XEN_GUEST_HANDLE(physdev_eoi_t);
+
+/*
+ * Register a shared page for the hypervisor to indicate whether the guest
+ * must issue PHYSDEVOP_eoi. The semantics of PHYSDEVOP_eoi change slightly
+ * once the guest used this function in that the associated event channel
+ * will automatically get unmasked. The page registered is used as a bit
+ * array indexed by Xen's PIRQ value.
+ */
+#define PHYSDEVOP_pirq_eoi_gmfn_v1 17
+/*
+ * Register a shared page for the hypervisor to indicate whether the
+ * guest must issue PHYSDEVOP_eoi. This hypercall is very similar to
+ * PHYSDEVOP_pirq_eoi_gmfn_v1 but it doesn't change the semantics of
+ * PHYSDEVOP_eoi. The page registered is used as a bit array indexed by
+ * Xen's PIRQ value.
+ */
+#define PHYSDEVOP_pirq_eoi_gmfn_v2 28
+struct physdev_pirq_eoi_gmfn {
+ /* IN */
+ xen_pfn_t gmfn;
+};
+typedef struct physdev_pirq_eoi_gmfn physdev_pirq_eoi_gmfn_t;
+DEFINE_XEN_GUEST_HANDLE(physdev_pirq_eoi_gmfn_t);
+
+/*
+ * Query the status of an IRQ line.
+ * @arg == pointer to physdev_irq_status_query structure.
+ */
+#define PHYSDEVOP_irq_status_query 5
+struct physdev_irq_status_query {
+ /* IN */
+ uint32_t irq;
+ /* OUT */
+ uint32_t flags; /* XENIRQSTAT_* */
+};
+typedef struct physdev_irq_status_query physdev_irq_status_query_t;
+DEFINE_XEN_GUEST_HANDLE(physdev_irq_status_query_t);
+
+/* Need to call PHYSDEVOP_eoi when the IRQ has been serviced? */
+#define _XENIRQSTAT_needs_eoi (0)
+#define XENIRQSTAT_needs_eoi (1U<<_XENIRQSTAT_needs_eoi)
+
+/* IRQ shared by multiple guests? */
+#define _XENIRQSTAT_shared (1)
+#define XENIRQSTAT_shared (1U<<_XENIRQSTAT_shared)
+
+/*
+ * Set the current VCPU's I/O privilege level.
+ * @arg == pointer to physdev_set_iopl structure.
+ */
+#define PHYSDEVOP_set_iopl 6
+struct physdev_set_iopl {
+ /* IN */
+ uint32_t iopl;
+};
+typedef struct physdev_set_iopl physdev_set_iopl_t;
+DEFINE_XEN_GUEST_HANDLE(physdev_set_iopl_t);
+
+/*
+ * Set the current VCPU's I/O-port permissions bitmap.
+ * @arg == pointer to physdev_set_iobitmap structure.
+ */
+#define PHYSDEVOP_set_iobitmap 7
+struct physdev_set_iobitmap {
+ /* IN */
+#if __XEN_INTERFACE_VERSION__ >= 0x00030205
+ XEN_GUEST_HANDLE(uint8) bitmap;
+#else
+ uint8_t *bitmap;
+#endif
+ uint32_t nr_ports;
+};
+typedef struct physdev_set_iobitmap physdev_set_iobitmap_t;
+DEFINE_XEN_GUEST_HANDLE(physdev_set_iobitmap_t);
+
+/*
+ * Read or write an IO-APIC register.
+ * @arg == pointer to physdev_apic structure.
+ */
+#define PHYSDEVOP_apic_read 8
+#define PHYSDEVOP_apic_write 9
+struct physdev_apic {
+ /* IN */
+ unsigned long apic_physbase;
+ uint32_t reg;
+ /* IN or OUT */
+ uint32_t value;
+};
+typedef struct physdev_apic physdev_apic_t;
+DEFINE_XEN_GUEST_HANDLE(physdev_apic_t);
+
+/*
+ * Allocate or free a physical upcall vector for the specified IRQ line.
+ * @arg == pointer to physdev_irq structure.
+ */
+#define PHYSDEVOP_alloc_irq_vector 10
+#define PHYSDEVOP_free_irq_vector 11
+struct physdev_irq {
+ /* IN */
+ uint32_t irq;
+ /* IN or OUT */
+ uint32_t vector;
+};
+typedef struct physdev_irq physdev_irq_t;
+DEFINE_XEN_GUEST_HANDLE(physdev_irq_t);
+
+#define MAP_PIRQ_TYPE_MSI 0x0
+#define MAP_PIRQ_TYPE_GSI 0x1
+#define MAP_PIRQ_TYPE_UNKNOWN 0x2
+#define MAP_PIRQ_TYPE_MSI_SEG 0x3
+#define MAP_PIRQ_TYPE_MULTI_MSI 0x4
+
+#define PHYSDEVOP_map_pirq 13
+struct physdev_map_pirq {
+ domid_t domid;
+ /* IN */
+ int type;
+ /* IN (ignored for ..._MULTI_MSI) */
+ int index;
+ /* IN or OUT */
+ int pirq;
+ /* IN - high 16 bits hold segment for ..._MSI_SEG and ..._MULTI_MSI */
+ int bus;
+ /* IN */
+ int devfn;
+ /* IN (also OUT for ..._MULTI_MSI) */
+ int entry_nr;
+ /* IN */
+ uint64_t table_base;
+};
+typedef struct physdev_map_pirq physdev_map_pirq_t;
+DEFINE_XEN_GUEST_HANDLE(physdev_map_pirq_t);
+
+#define PHYSDEVOP_unmap_pirq 14
+struct physdev_unmap_pirq {
+ domid_t domid;
+ /* IN */
+ int pirq;
+};
+
+typedef struct physdev_unmap_pirq physdev_unmap_pirq_t;
+DEFINE_XEN_GUEST_HANDLE(physdev_unmap_pirq_t);
+
+#define PHYSDEVOP_manage_pci_add 15
+#define PHYSDEVOP_manage_pci_remove 16
+struct physdev_manage_pci {
+ /* IN */
+ uint8_t bus;
+ uint8_t devfn;
+};
+
+typedef struct physdev_manage_pci physdev_manage_pci_t;
+DEFINE_XEN_GUEST_HANDLE(physdev_manage_pci_t);
+
+#define PHYSDEVOP_restore_msi 19
+struct physdev_restore_msi {
+ /* IN */
+ uint8_t bus;
+ uint8_t devfn;
+};
+typedef struct physdev_restore_msi physdev_restore_msi_t;
+DEFINE_XEN_GUEST_HANDLE(physdev_restore_msi_t);
+
+#define PHYSDEVOP_manage_pci_add_ext 20
+struct physdev_manage_pci_ext {
+ /* IN */
+ uint8_t bus;
+ uint8_t devfn;
+ unsigned is_extfn;
+ unsigned is_virtfn;
+ struct {
+ uint8_t bus;
+ uint8_t devfn;
+ } physfn;
+};
+
+typedef struct physdev_manage_pci_ext physdev_manage_pci_ext_t;
+DEFINE_XEN_GUEST_HANDLE(physdev_manage_pci_ext_t);
+
+/*
+ * Argument to physdev_op_compat() hypercall. Superceded by new physdev_op()
+ * hypercall since 0x00030202.
+ */
+struct physdev_op {
+ uint32_t cmd;
+ union {
+ struct physdev_irq_status_query irq_status_query;
+ struct physdev_set_iopl set_iopl;
+ struct physdev_set_iobitmap set_iobitmap;
+ struct physdev_apic apic_op;
+ struct physdev_irq irq_op;
+ } u;
+};
+typedef struct physdev_op physdev_op_t;
+DEFINE_XEN_GUEST_HANDLE(physdev_op_t);
+
+#define PHYSDEVOP_setup_gsi 21
+struct physdev_setup_gsi {
+ int gsi;
+ /* IN */
+ uint8_t triggering;
+ /* IN */
+ uint8_t polarity;
+ /* IN */
+};
+
+typedef struct physdev_setup_gsi physdev_setup_gsi_t;
+DEFINE_XEN_GUEST_HANDLE(physdev_setup_gsi_t);
+
+/* leave PHYSDEVOP 22 free */
+
+/* type is MAP_PIRQ_TYPE_GSI or MAP_PIRQ_TYPE_MSI
+ * the hypercall returns a free pirq */
+#define PHYSDEVOP_get_free_pirq 23
+struct physdev_get_free_pirq {
+ /* IN */
+ int type;
+ /* OUT */
+ uint32_t pirq;
+};
+
+typedef struct physdev_get_free_pirq physdev_get_free_pirq_t;
+DEFINE_XEN_GUEST_HANDLE(physdev_get_free_pirq_t);
+
+#define XEN_PCI_MMCFG_RESERVED 0x1
+
+#define PHYSDEVOP_pci_mmcfg_reserved 24
+struct physdev_pci_mmcfg_reserved {
+ uint64_t address;
+ uint16_t segment;
+ uint8_t start_bus;
+ uint8_t end_bus;
+ uint32_t flags;
+};
+typedef struct physdev_pci_mmcfg_reserved physdev_pci_mmcfg_reserved_t;
+DEFINE_XEN_GUEST_HANDLE(physdev_pci_mmcfg_reserved_t);
+
+#define XEN_PCI_DEV_EXTFN 0x1
+#define XEN_PCI_DEV_VIRTFN 0x2
+#define XEN_PCI_DEV_PXM 0x4
+
+#define PHYSDEVOP_pci_device_add 25
+struct physdev_pci_device_add {
+ /* IN */
+ uint16_t seg;
+ uint8_t bus;
+ uint8_t devfn;
+ uint32_t flags;
+ struct {
+ uint8_t bus;
+ uint8_t devfn;
+ } physfn;
+ /*
+ * Optional parameters array.
+ * First element ([0]) is PXM domain associated with the device (if
+ * XEN_PCI_DEV_PXM is set)
+ */
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+ uint32_t optarr[];
+#elif defined(__GNUC__)
+ uint32_t optarr[0];
+#endif
+};
+typedef struct physdev_pci_device_add physdev_pci_device_add_t;
+DEFINE_XEN_GUEST_HANDLE(physdev_pci_device_add_t);
+
+#define PHYSDEVOP_pci_device_remove 26
+#define PHYSDEVOP_restore_msi_ext 27
+/*
+ * Dom0 should use these two to announce MMIO resources assigned to
+ * MSI-X capable devices won't (prepare) or may (release) change.
+ */
+#define PHYSDEVOP_prepare_msix 30
+#define PHYSDEVOP_release_msix 31
+struct physdev_pci_device {
+ /* IN */
+ uint16_t seg;
+ uint8_t bus;
+ uint8_t devfn;
+};
+typedef struct physdev_pci_device physdev_pci_device_t;
+DEFINE_XEN_GUEST_HANDLE(physdev_pci_device_t);
+
+#define PHYSDEVOP_DBGP_RESET_PREPARE 1
+#define PHYSDEVOP_DBGP_RESET_DONE 2
+
+#define PHYSDEVOP_DBGP_BUS_UNKNOWN 0
+#define PHYSDEVOP_DBGP_BUS_PCI 1
+
+#define PHYSDEVOP_dbgp_op 29
+struct physdev_dbgp_op {
+ /* IN */
+ uint8_t op;
+ uint8_t bus;
+ union {
+ struct physdev_pci_device pci;
+ } u;
+};
+typedef struct physdev_dbgp_op physdev_dbgp_op_t;
+DEFINE_XEN_GUEST_HANDLE(physdev_dbgp_op_t);
+
+/*
+ * Notify that some PIRQ-bound event channels have been unmasked.
+ * ** This command is obsolete since interface version 0x00030202 and is **
+ * ** unsupported by newer versions of Xen. **
+ */
+#define PHYSDEVOP_IRQ_UNMASK_NOTIFY 4
+
+#if __XEN_INTERFACE_VERSION__ < 0x00040600
+/*
+ * These all-capitals physdev operation names are superceded by the new names
+ * (defined above) since interface version 0x00030202. The guard above was
+ * added post-4.5 only though and hence shouldn't check for 0x00030202.
+ */
+#define PHYSDEVOP_IRQ_STATUS_QUERY PHYSDEVOP_irq_status_query
+#define PHYSDEVOP_SET_IOPL PHYSDEVOP_set_iopl
+#define PHYSDEVOP_SET_IOBITMAP PHYSDEVOP_set_iobitmap
+#define PHYSDEVOP_APIC_READ PHYSDEVOP_apic_read
+#define PHYSDEVOP_APIC_WRITE PHYSDEVOP_apic_write
+#define PHYSDEVOP_ASSIGN_VECTOR PHYSDEVOP_alloc_irq_vector
+#define PHYSDEVOP_FREE_VECTOR PHYSDEVOP_free_irq_vector
+#define PHYSDEVOP_IRQ_NEEDS_UNMASK_NOTIFY XENIRQSTAT_needs_eoi
+#define PHYSDEVOP_IRQ_SHARED XENIRQSTAT_shared
+#endif
+
+#if __XEN_INTERFACE_VERSION__ < 0x00040200
+#define PHYSDEVOP_pirq_eoi_gmfn PHYSDEVOP_pirq_eoi_gmfn_v1
+#else
+#define PHYSDEVOP_pirq_eoi_gmfn PHYSDEVOP_pirq_eoi_gmfn_v2
+#endif
+
+#endif /* __XEN_PUBLIC_PHYSDEV_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/include/xen/sched.h b/include/xen/sched.h
new file mode 100644
index 0000000..a30b11d
--- /dev/null
+++ b/include/xen/sched.h
@@ -0,0 +1,174 @@
+/******************************************************************************
+ * sched.h
+ *
+ * Scheduler state interactions
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright (c) 2005, Keir Fraser <keir@xensource.com>
+ */
+
+#ifndef __XEN_PUBLIC_SCHED_H__
+#define __XEN_PUBLIC_SCHED_H__
+
+#include "event_channel.h"
+
+/*
+ * `incontents 150 sched Guest Scheduler Operations
+ *
+ * The SCHEDOP interface provides mechanisms for a guest to interact
+ * with the scheduler, including yield, blocking and shutting itself
+ * down.
+ */
+
+/*
+ * The prototype for this hypercall is:
+ * ` long HYPERVISOR_sched_op(enum sched_op cmd, void *arg, ...)
+ *
+ * @cmd == SCHEDOP_??? (scheduler operation).
+ * @arg == Operation-specific extra argument(s), as described below.
+ * ... == Additional Operation-specific extra arguments, described below.
+ *
+ * Versions of Xen prior to 3.0.2 provided only the following legacy version
+ * of this hypercall, supporting only the commands yield, block and shutdown:
+ * long sched_op(int cmd, unsigned long arg)
+ * @cmd == SCHEDOP_??? (scheduler operation).
+ * @arg == 0 (SCHEDOP_yield and SCHEDOP_block)
+ * == SHUTDOWN_* code (SCHEDOP_shutdown)
+ *
+ * This legacy version is available to new guests as:
+ * ` long HYPERVISOR_sched_op_compat(enum sched_op cmd, unsigned long arg)
+ */
+
+/* ` enum sched_op { // SCHEDOP_* => struct sched_* */
+/*
+ * Voluntarily yield the CPU.
+ * @arg == NULL.
+ */
+#define SCHEDOP_yield 0
+
+/*
+ * Block execution of this VCPU until an event is received for processing.
+ * If called with event upcalls masked, this operation will atomically
+ * reenable event delivery and check for pending events before blocking the
+ * VCPU. This avoids a "wakeup waiting" race.
+ * @arg == NULL.
+ */
+#define SCHEDOP_block 1
+
+/*
+ * Halt execution of this domain (all VCPUs) and notify the system controller.
+ * @arg == pointer to sched_shutdown_t structure.
+ *
+ * If the sched_shutdown_t reason is SHUTDOWN_suspend then this
+ * hypercall takes an additional extra argument which should be the
+ * MFN of the guest's start_info_t.
+ *
+ * In addition, which reason is SHUTDOWN_suspend this hypercall
+ * returns 1 if suspend was cancelled or the domain was merely
+ * checkpointed, and 0 if it is resuming in a new domain.
+ */
+#define SCHEDOP_shutdown 2
+
+/*
+ * Poll a set of event-channel ports. Return when one or more are pending. An
+ * optional timeout may be specified.
+ * @arg == pointer to sched_poll_t structure.
+ */
+#define SCHEDOP_poll 3
+
+/*
+ * Declare a shutdown for another domain. The main use of this function is
+ * in interpreting shutdown requests and reasons for fully-virtualized
+ * domains. A para-virtualized domain may use SCHEDOP_shutdown directly.
+ * @arg == pointer to sched_remote_shutdown_t structure.
+ */
+#define SCHEDOP_remote_shutdown 4
+
+/*
+ * Latch a shutdown code, so that when the domain later shuts down it
+ * reports this code to the control tools.
+ * @arg == sched_shutdown_t, as for SCHEDOP_shutdown.
+ */
+#define SCHEDOP_shutdown_code 5
+
+/*
+ * Setup, poke and destroy a domain watchdog timer.
+ * @arg == pointer to sched_watchdog_t structure.
+ * With id == 0, setup a domain watchdog timer to cause domain shutdown
+ * after timeout, returns watchdog id.
+ * With id != 0 and timeout == 0, destroy domain watchdog timer.
+ * With id != 0 and timeout != 0, poke watchdog timer and set new timeout.
+ */
+#define SCHEDOP_watchdog 6
+/* ` } */
+
+struct sched_shutdown {
+ unsigned int reason; /* SHUTDOWN_* => enum sched_shutdown_reason */
+};
+typedef struct sched_shutdown sched_shutdown_t;
+DEFINE_XEN_GUEST_HANDLE(sched_shutdown_t);
+
+struct sched_poll {
+ XEN_GUEST_HANDLE(evtchn_port_t) ports;
+ unsigned int nr_ports;
+ uint64_t timeout;
+};
+typedef struct sched_poll sched_poll_t;
+DEFINE_XEN_GUEST_HANDLE(sched_poll_t);
+
+struct sched_remote_shutdown {
+ domid_t domain_id; /* Remote domain ID */
+ unsigned int reason; /* SHUTDOWN_* => enum sched_shutdown_reason */
+};
+typedef struct sched_remote_shutdown sched_remote_shutdown_t;
+DEFINE_XEN_GUEST_HANDLE(sched_remote_shutdown_t);
+
+struct sched_watchdog {
+ uint32_t id; /* watchdog ID */
+ uint32_t timeout; /* timeout */
+};
+typedef struct sched_watchdog sched_watchdog_t;
+DEFINE_XEN_GUEST_HANDLE(sched_watchdog_t);
+
+/*
+ * Reason codes for SCHEDOP_shutdown. These may be interpreted by control
+ * software to determine the appropriate action. For the most part, Xen does
+ * not care about the shutdown code.
+ */
+/* ` enum sched_shutdown_reason { */
+#define SHUTDOWN_poweroff 0 /* Domain exited normally. Clean up and kill. */
+#define SHUTDOWN_reboot 1 /* Clean up, kill, and then restart. */
+#define SHUTDOWN_suspend 2 /* Clean up, save suspend info, kill. */
+#define SHUTDOWN_crash 3 /* Tell controller we've crashed. */
+#define SHUTDOWN_watchdog 4 /* Restart because watchdog time expired. */
+#define SHUTDOWN_MAX 4 /* Maximum valid shutdown reason. */
+/* ` } */
+
+#endif /* __XEN_PUBLIC_SCHED_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/include/xen/trace.h b/include/xen/trace.h
new file mode 100644
index 0000000..a00c017
--- /dev/null
+++ b/include/xen/trace.h
@@ -0,0 +1,339 @@
+/******************************************************************************
+ * include/public/trace.h
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Mark Williamson, (C) 2004 Intel Research Cambridge
+ * Copyright (C) 2005 Bin Ren
+ */
+
+#ifndef __XEN_PUBLIC_TRACE_H__
+#define __XEN_PUBLIC_TRACE_H__
+
+#define TRACE_EXTRA_MAX 7
+#define TRACE_EXTRA_SHIFT 28
+
+/* Trace classes */
+#define TRC_CLS_SHIFT 16
+#define TRC_GEN 0x0001f000 /* General trace */
+#define TRC_SCHED 0x0002f000 /* Xen Scheduler trace */
+#define TRC_DOM0OP 0x0004f000 /* Xen DOM0 operation trace */
+#define TRC_HVM 0x0008f000 /* Xen HVM trace */
+#define TRC_MEM 0x0010f000 /* Xen memory trace */
+#define TRC_PV 0x0020f000 /* Xen PV traces */
+#define TRC_SHADOW 0x0040f000 /* Xen shadow tracing */
+#define TRC_HW 0x0080f000 /* Xen hardware-related traces */
+#define TRC_GUEST 0x0800f000 /* Guest-generated traces */
+#define TRC_ALL 0x0ffff000
+#define TRC_HD_TO_EVENT(x) ((x)&0x0fffffff)
+#define TRC_HD_CYCLE_FLAG (1UL<<31)
+#define TRC_HD_INCLUDES_CYCLE_COUNT(x) ( !!( (x) & TRC_HD_CYCLE_FLAG ) )
+#define TRC_HD_EXTRA(x) (((x)>>TRACE_EXTRA_SHIFT)&TRACE_EXTRA_MAX)
+
+/* Trace subclasses */
+#define TRC_SUBCLS_SHIFT 12
+
+/* trace subclasses for SVM */
+#define TRC_HVM_ENTRYEXIT 0x00081000 /* VMENTRY and #VMEXIT */
+#define TRC_HVM_HANDLER 0x00082000 /* various HVM handlers */
+#define TRC_HVM_EMUL 0x00084000 /* emulated devices */
+
+#define TRC_SCHED_MIN 0x00021000 /* Just runstate changes */
+#define TRC_SCHED_CLASS 0x00022000 /* Scheduler-specific */
+#define TRC_SCHED_VERBOSE 0x00028000 /* More inclusive scheduling */
+
+/*
+ * The highest 3 bits of the last 12 bits of TRC_SCHED_CLASS above are
+ * reserved for encoding what scheduler produced the information. The
+ * actual event is encoded in the last 9 bits.
+ *
+ * This means we have 8 scheduling IDs available (which means at most 8
+ * schedulers generating events) and, in each scheduler, up to 512
+ * different events.
+ */
+#define TRC_SCHED_ID_BITS 3
+#define TRC_SCHED_ID_SHIFT (TRC_SUBCLS_SHIFT - TRC_SCHED_ID_BITS)
+#define TRC_SCHED_ID_MASK (((1UL<<TRC_SCHED_ID_BITS) - 1) << TRC_SCHED_ID_SHIFT)
+#define TRC_SCHED_EVT_MASK (~(TRC_SCHED_ID_MASK))
+
+/* Per-scheduler IDs, to identify scheduler specific events */
+#define TRC_SCHED_CSCHED 0
+#define TRC_SCHED_CSCHED2 1
+/* #define XEN_SCHEDULER_SEDF 2 (Removed) */
+#define TRC_SCHED_ARINC653 3
+#define TRC_SCHED_RTDS 4
+#define TRC_SCHED_SNULL 5
+
+/* Per-scheduler tracing */
+#define TRC_SCHED_CLASS_EVT(_c, _e) \
+ ( ( TRC_SCHED_CLASS | \
+ ((TRC_SCHED_##_c << TRC_SCHED_ID_SHIFT) & TRC_SCHED_ID_MASK) ) + \
+ (_e & TRC_SCHED_EVT_MASK) )
+
+/* Trace classes for DOM0 operations */
+#define TRC_DOM0_DOMOPS 0x00041000 /* Domains manipulations */
+
+/* Trace classes for Hardware */
+#define TRC_HW_PM 0x00801000 /* Power management traces */
+#define TRC_HW_IRQ 0x00802000 /* Traces relating to the handling of IRQs */
+
+/* Trace events per class */
+#define TRC_LOST_RECORDS (TRC_GEN + 1)
+#define TRC_TRACE_WRAP_BUFFER (TRC_GEN + 2)
+#define TRC_TRACE_CPU_CHANGE (TRC_GEN + 3)
+
+#define TRC_SCHED_RUNSTATE_CHANGE (TRC_SCHED_MIN + 1)
+#define TRC_SCHED_CONTINUE_RUNNING (TRC_SCHED_MIN + 2)
+#define TRC_SCHED_DOM_ADD (TRC_SCHED_VERBOSE + 1)
+#define TRC_SCHED_DOM_REM (TRC_SCHED_VERBOSE + 2)
+#define TRC_SCHED_SLEEP (TRC_SCHED_VERBOSE + 3)
+#define TRC_SCHED_WAKE (TRC_SCHED_VERBOSE + 4)
+#define TRC_SCHED_YIELD (TRC_SCHED_VERBOSE + 5)
+#define TRC_SCHED_BLOCK (TRC_SCHED_VERBOSE + 6)
+#define TRC_SCHED_SHUTDOWN (TRC_SCHED_VERBOSE + 7)
+#define TRC_SCHED_CTL (TRC_SCHED_VERBOSE + 8)
+#define TRC_SCHED_ADJDOM (TRC_SCHED_VERBOSE + 9)
+#define TRC_SCHED_SWITCH (TRC_SCHED_VERBOSE + 10)
+#define TRC_SCHED_S_TIMER_FN (TRC_SCHED_VERBOSE + 11)
+#define TRC_SCHED_T_TIMER_FN (TRC_SCHED_VERBOSE + 12)
+#define TRC_SCHED_DOM_TIMER_FN (TRC_SCHED_VERBOSE + 13)
+#define TRC_SCHED_SWITCH_INFPREV (TRC_SCHED_VERBOSE + 14)
+#define TRC_SCHED_SWITCH_INFNEXT (TRC_SCHED_VERBOSE + 15)
+#define TRC_SCHED_SHUTDOWN_CODE (TRC_SCHED_VERBOSE + 16)
+#define TRC_SCHED_SWITCH_INFCONT (TRC_SCHED_VERBOSE + 17)
+
+#define TRC_DOM0_DOM_ADD (TRC_DOM0_DOMOPS + 1)
+#define TRC_DOM0_DOM_REM (TRC_DOM0_DOMOPS + 2)
+
+#define TRC_MEM_PAGE_GRANT_MAP (TRC_MEM + 1)
+#define TRC_MEM_PAGE_GRANT_UNMAP (TRC_MEM + 2)
+#define TRC_MEM_PAGE_GRANT_TRANSFER (TRC_MEM + 3)
+#define TRC_MEM_SET_P2M_ENTRY (TRC_MEM + 4)
+#define TRC_MEM_DECREASE_RESERVATION (TRC_MEM + 5)
+#define TRC_MEM_POD_POPULATE (TRC_MEM + 16)
+#define TRC_MEM_POD_ZERO_RECLAIM (TRC_MEM + 17)
+#define TRC_MEM_POD_SUPERPAGE_SPLINTER (TRC_MEM + 18)
+
+#define TRC_PV_ENTRY 0x00201000 /* Hypervisor entry points for PV guests. */
+#define TRC_PV_SUBCALL 0x00202000 /* Sub-call in a multicall hypercall */
+
+#define TRC_PV_HYPERCALL (TRC_PV_ENTRY + 1)
+#define TRC_PV_TRAP (TRC_PV_ENTRY + 3)
+#define TRC_PV_PAGE_FAULT (TRC_PV_ENTRY + 4)
+#define TRC_PV_FORCED_INVALID_OP (TRC_PV_ENTRY + 5)
+#define TRC_PV_EMULATE_PRIVOP (TRC_PV_ENTRY + 6)
+#define TRC_PV_EMULATE_4GB (TRC_PV_ENTRY + 7)
+#define TRC_PV_MATH_STATE_RESTORE (TRC_PV_ENTRY + 8)
+#define TRC_PV_PAGING_FIXUP (TRC_PV_ENTRY + 9)
+#define TRC_PV_GDT_LDT_MAPPING_FAULT (TRC_PV_ENTRY + 10)
+#define TRC_PV_PTWR_EMULATION (TRC_PV_ENTRY + 11)
+#define TRC_PV_PTWR_EMULATION_PAE (TRC_PV_ENTRY + 12)
+#define TRC_PV_HYPERCALL_V2 (TRC_PV_ENTRY + 13)
+#define TRC_PV_HYPERCALL_SUBCALL (TRC_PV_SUBCALL + 14)
+
+/*
+ * TRC_PV_HYPERCALL_V2 format
+ *
+ * Only some of the hypercall argument are recorded. Bit fields A0 to
+ * A5 in the first extra word are set if the argument is present and
+ * the arguments themselves are packed sequentially in the following
+ * words.
+ *
+ * The TRC_64_FLAG bit is not set for these events (even if there are
+ * 64-bit arguments in the record).
+ *
+ * Word
+ * 0 bit 31 30|29 28|27 26|25 24|23 22|21 20|19 ... 0
+ * A5 |A4 |A3 |A2 |A1 |A0 |Hypercall op
+ * 1 First 32 bit (or low word of first 64 bit) arg in record
+ * 2 Second 32 bit (or high word of first 64 bit) arg in record
+ * ...
+ *
+ * A0-A5 bitfield values:
+ *
+ * 00b Argument not present
+ * 01b 32-bit argument present
+ * 10b 64-bit argument present
+ * 11b Reserved
+ */
+#define TRC_PV_HYPERCALL_V2_ARG_32(i) (0x1 << (20 + 2*(i)))
+#define TRC_PV_HYPERCALL_V2_ARG_64(i) (0x2 << (20 + 2*(i)))
+#define TRC_PV_HYPERCALL_V2_ARG_MASK (0xfff00000)
+
+#define TRC_SHADOW_NOT_SHADOW (TRC_SHADOW + 1)
+#define TRC_SHADOW_FAST_PROPAGATE (TRC_SHADOW + 2)
+#define TRC_SHADOW_FAST_MMIO (TRC_SHADOW + 3)
+#define TRC_SHADOW_FALSE_FAST_PATH (TRC_SHADOW + 4)
+#define TRC_SHADOW_MMIO (TRC_SHADOW + 5)
+#define TRC_SHADOW_FIXUP (TRC_SHADOW + 6)
+#define TRC_SHADOW_DOMF_DYING (TRC_SHADOW + 7)
+#define TRC_SHADOW_EMULATE (TRC_SHADOW + 8)
+#define TRC_SHADOW_EMULATE_UNSHADOW_USER (TRC_SHADOW + 9)
+#define TRC_SHADOW_EMULATE_UNSHADOW_EVTINJ (TRC_SHADOW + 10)
+#define TRC_SHADOW_EMULATE_UNSHADOW_UNHANDLED (TRC_SHADOW + 11)
+#define TRC_SHADOW_WRMAP_BF (TRC_SHADOW + 12)
+#define TRC_SHADOW_PREALLOC_UNPIN (TRC_SHADOW + 13)
+#define TRC_SHADOW_RESYNC_FULL (TRC_SHADOW + 14)
+#define TRC_SHADOW_RESYNC_ONLY (TRC_SHADOW + 15)
+
+/* trace events per subclass */
+#define TRC_HVM_NESTEDFLAG (0x400)
+#define TRC_HVM_VMENTRY (TRC_HVM_ENTRYEXIT + 0x01)
+#define TRC_HVM_VMEXIT (TRC_HVM_ENTRYEXIT + 0x02)
+#define TRC_HVM_VMEXIT64 (TRC_HVM_ENTRYEXIT + TRC_64_FLAG + 0x02)
+#define TRC_HVM_PF_XEN (TRC_HVM_HANDLER + 0x01)
+#define TRC_HVM_PF_XEN64 (TRC_HVM_HANDLER + TRC_64_FLAG + 0x01)
+#define TRC_HVM_PF_INJECT (TRC_HVM_HANDLER + 0x02)
+#define TRC_HVM_PF_INJECT64 (TRC_HVM_HANDLER + TRC_64_FLAG + 0x02)
+#define TRC_HVM_INJ_EXC (TRC_HVM_HANDLER + 0x03)
+#define TRC_HVM_INJ_VIRQ (TRC_HVM_HANDLER + 0x04)
+#define TRC_HVM_REINJ_VIRQ (TRC_HVM_HANDLER + 0x05)
+#define TRC_HVM_IO_READ (TRC_HVM_HANDLER + 0x06)
+#define TRC_HVM_IO_WRITE (TRC_HVM_HANDLER + 0x07)
+#define TRC_HVM_CR_READ (TRC_HVM_HANDLER + 0x08)
+#define TRC_HVM_CR_READ64 (TRC_HVM_HANDLER + TRC_64_FLAG + 0x08)
+#define TRC_HVM_CR_WRITE (TRC_HVM_HANDLER + 0x09)
+#define TRC_HVM_CR_WRITE64 (TRC_HVM_HANDLER + TRC_64_FLAG + 0x09)
+#define TRC_HVM_DR_READ (TRC_HVM_HANDLER + 0x0A)
+#define TRC_HVM_DR_WRITE (TRC_HVM_HANDLER + 0x0B)
+#define TRC_HVM_MSR_READ (TRC_HVM_HANDLER + 0x0C)
+#define TRC_HVM_MSR_WRITE (TRC_HVM_HANDLER + 0x0D)
+#define TRC_HVM_CPUID (TRC_HVM_HANDLER + 0x0E)
+#define TRC_HVM_INTR (TRC_HVM_HANDLER + 0x0F)
+#define TRC_HVM_NMI (TRC_HVM_HANDLER + 0x10)
+#define TRC_HVM_SMI (TRC_HVM_HANDLER + 0x11)
+#define TRC_HVM_VMMCALL (TRC_HVM_HANDLER + 0x12)
+#define TRC_HVM_HLT (TRC_HVM_HANDLER + 0x13)
+#define TRC_HVM_INVLPG (TRC_HVM_HANDLER + 0x14)
+#define TRC_HVM_INVLPG64 (TRC_HVM_HANDLER + TRC_64_FLAG + 0x14)
+#define TRC_HVM_MCE (TRC_HVM_HANDLER + 0x15)
+#define TRC_HVM_IOPORT_READ (TRC_HVM_HANDLER + 0x16)
+#define TRC_HVM_IOMEM_READ (TRC_HVM_HANDLER + 0x17)
+#define TRC_HVM_CLTS (TRC_HVM_HANDLER + 0x18)
+#define TRC_HVM_LMSW (TRC_HVM_HANDLER + 0x19)
+#define TRC_HVM_LMSW64 (TRC_HVM_HANDLER + TRC_64_FLAG + 0x19)
+#define TRC_HVM_RDTSC (TRC_HVM_HANDLER + 0x1a)
+#define TRC_HVM_INTR_WINDOW (TRC_HVM_HANDLER + 0x20)
+#define TRC_HVM_NPF (TRC_HVM_HANDLER + 0x21)
+#define TRC_HVM_REALMODE_EMULATE (TRC_HVM_HANDLER + 0x22)
+#define TRC_HVM_TRAP (TRC_HVM_HANDLER + 0x23)
+#define TRC_HVM_TRAP_DEBUG (TRC_HVM_HANDLER + 0x24)
+#define TRC_HVM_VLAPIC (TRC_HVM_HANDLER + 0x25)
+
+#define TRC_HVM_IOPORT_WRITE (TRC_HVM_HANDLER + 0x216)
+#define TRC_HVM_IOMEM_WRITE (TRC_HVM_HANDLER + 0x217)
+
+/* Trace events for emulated devices */
+#define TRC_HVM_EMUL_HPET_START_TIMER (TRC_HVM_EMUL + 0x1)
+#define TRC_HVM_EMUL_PIT_START_TIMER (TRC_HVM_EMUL + 0x2)
+#define TRC_HVM_EMUL_RTC_START_TIMER (TRC_HVM_EMUL + 0x3)
+#define TRC_HVM_EMUL_LAPIC_START_TIMER (TRC_HVM_EMUL + 0x4)
+#define TRC_HVM_EMUL_HPET_STOP_TIMER (TRC_HVM_EMUL + 0x5)
+#define TRC_HVM_EMUL_PIT_STOP_TIMER (TRC_HVM_EMUL + 0x6)
+#define TRC_HVM_EMUL_RTC_STOP_TIMER (TRC_HVM_EMUL + 0x7)
+#define TRC_HVM_EMUL_LAPIC_STOP_TIMER (TRC_HVM_EMUL + 0x8)
+#define TRC_HVM_EMUL_PIT_TIMER_CB (TRC_HVM_EMUL + 0x9)
+#define TRC_HVM_EMUL_LAPIC_TIMER_CB (TRC_HVM_EMUL + 0xA)
+#define TRC_HVM_EMUL_PIC_INT_OUTPUT (TRC_HVM_EMUL + 0xB)
+#define TRC_HVM_EMUL_PIC_KICK (TRC_HVM_EMUL + 0xC)
+#define TRC_HVM_EMUL_PIC_INTACK (TRC_HVM_EMUL + 0xD)
+#define TRC_HVM_EMUL_PIC_POSEDGE (TRC_HVM_EMUL + 0xE)
+#define TRC_HVM_EMUL_PIC_NEGEDGE (TRC_HVM_EMUL + 0xF)
+#define TRC_HVM_EMUL_PIC_PEND_IRQ_CALL (TRC_HVM_EMUL + 0x10)
+#define TRC_HVM_EMUL_LAPIC_PIC_INTR (TRC_HVM_EMUL + 0x11)
+
+/* trace events for per class */
+#define TRC_PM_FREQ_CHANGE (TRC_HW_PM + 0x01)
+#define TRC_PM_IDLE_ENTRY (TRC_HW_PM + 0x02)
+#define TRC_PM_IDLE_EXIT (TRC_HW_PM + 0x03)
+
+/* Trace events for IRQs */
+#define TRC_HW_IRQ_MOVE_CLEANUP_DELAY (TRC_HW_IRQ + 0x1)
+#define TRC_HW_IRQ_MOVE_CLEANUP (TRC_HW_IRQ + 0x2)
+#define TRC_HW_IRQ_BIND_VECTOR (TRC_HW_IRQ + 0x3)
+#define TRC_HW_IRQ_CLEAR_VECTOR (TRC_HW_IRQ + 0x4)
+#define TRC_HW_IRQ_MOVE_FINISH (TRC_HW_IRQ + 0x5)
+#define TRC_HW_IRQ_ASSIGN_VECTOR (TRC_HW_IRQ + 0x6)
+#define TRC_HW_IRQ_UNMAPPED_VECTOR (TRC_HW_IRQ + 0x7)
+#define TRC_HW_IRQ_HANDLED (TRC_HW_IRQ + 0x8)
+
+/*
+ * Event Flags
+ *
+ * Some events (e.g, TRC_PV_TRAP and TRC_HVM_IOMEM_READ) have multiple
+ * record formats. These event flags distinguish between the
+ * different formats.
+ */
+#define TRC_64_FLAG 0x100 /* Addresses are 64 bits (instead of 32 bits) */
+
+/* This structure represents a single trace buffer record. */
+struct t_rec {
+ uint32_t event:28;
+ uint32_t extra_u32:3; /* # entries in trailing extra_u32[] array */
+ uint32_t cycles_included:1; /* u.cycles or u.no_cycles? */
+ union {
+ struct {
+ uint32_t cycles_lo, cycles_hi; /* cycle counter timestamp */
+ uint32_t extra_u32[7]; /* event data items */
+ } cycles;
+ struct {
+ uint32_t extra_u32[7]; /* event data items */
+ } nocycles;
+ } u;
+};
+
+/*
+ * This structure contains the metadata for a single trace buffer. The head
+ * field, indexes into an array of struct t_rec's.
+ */
+struct t_buf {
+ /* Assume the data buffer size is X. X is generally not a power of 2.
+ * CONS and PROD are incremented modulo (2*X):
+ * 0 <= cons < 2*X
+ * 0 <= prod < 2*X
+ * This is done because addition modulo X breaks at 2^32 when X is not a
+ * power of 2:
+ * (((2^32 - 1) % X) + 1) % X != (2^32) % X
+ */
+ uint32_t cons; /* Offset of next item to be consumed by control tools. */
+ uint32_t prod; /* Offset of next item to be produced by Xen. */
+ /* Records follow immediately after the meta-data header. */
+};
+
+/* Structure used to pass MFNs to the trace buffers back to trace consumers.
+ * Offset is an offset into the mapped structure where the mfn list will be held.
+ * MFNs will be at ((unsigned long *)(t_info))+(t_info->cpu_offset[cpu]).
+ */
+struct t_info {
+ uint16_t tbuf_size; /* Size in pages of each trace buffer */
+ uint16_t mfn_offset[]; /* Offset within t_info structure of the page list per cpu */
+ /* MFN lists immediately after the header */
+};
+
+#endif /* __XEN_PUBLIC_TRACE_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/include/xen/xen-compat.h b/include/xen/xen-compat.h
new file mode 100644
index 0000000..3eb80a0
--- /dev/null
+++ b/include/xen/xen-compat.h
@@ -0,0 +1,44 @@
+/******************************************************************************
+ * xen-compat.h
+ *
+ * Guest OS interface to Xen. Compatibility layer.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright (c) 2006, Christian Limpach
+ */
+
+#ifndef __XEN_PUBLIC_XEN_COMPAT_H__
+#define __XEN_PUBLIC_XEN_COMPAT_H__
+
+#define __XEN_LATEST_INTERFACE_VERSION__ 0x00040400
+
+#if defined(__XEN__) || defined(__XEN_TOOLS__)
+/* Xen is built with matching headers and implements the latest interface. */
+#define __XEN_INTERFACE_VERSION__ __XEN_LATEST_INTERFACE_VERSION__
+#elif !defined(__XEN_INTERFACE_VERSION__)
+/* Guests which do not specify a version get the legacy interface. */
+#define __XEN_INTERFACE_VERSION__ 0x00000000
+#endif
+
+#if __XEN_INTERFACE_VERSION__ > __XEN_LATEST_INTERFACE_VERSION__
+#error "These header files do not support the requested interface version."
+#endif
+
+#endif /* __XEN_PUBLIC_XEN_COMPAT_H__ */
diff --git a/include/xen/xen.h b/include/xen/xen.h
new file mode 100644
index 0000000..308109f
--- /dev/null
+++ b/include/xen/xen.h
@@ -0,0 +1,998 @@
+/******************************************************************************
+ * xen.h
+ *
+ * Guest OS interface to Xen.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright (c) 2004, K A Fraser
+ */
+
+#ifndef __XEN_PUBLIC_XEN_H__
+#define __XEN_PUBLIC_XEN_H__
+
+#include "xen-compat.h"
+
+#if defined(__i386__) || defined(__x86_64__)
+#include "arch-x86/xen.h"
+#elif defined(__arm__) || defined (__aarch64__)
+#include "arch-arm.h"
+#else
+#error "Unsupported architecture"
+#endif
+
+#ifndef __ASSEMBLY__
+/* Guest handles for primitive C types. */
+DEFINE_XEN_GUEST_HANDLE(char);
+__DEFINE_XEN_GUEST_HANDLE(uchar, unsigned char);
+DEFINE_XEN_GUEST_HANDLE(int);
+__DEFINE_XEN_GUEST_HANDLE(uint, unsigned int);
+#if __XEN_INTERFACE_VERSION__ < 0x00040300
+DEFINE_XEN_GUEST_HANDLE(long);
+__DEFINE_XEN_GUEST_HANDLE(ulong, unsigned long);
+#endif
+DEFINE_XEN_GUEST_HANDLE(void);
+
+DEFINE_XEN_GUEST_HANDLE(uint64_t);
+DEFINE_XEN_GUEST_HANDLE(xen_pfn_t);
+DEFINE_XEN_GUEST_HANDLE(xen_ulong_t);
+
+/* Turn a plain number into a C unsigned (long (long)) constant. */
+#define __xen_mk_uint(x) x ## U
+#define __xen_mk_ulong(x) x ## UL
+#ifndef __xen_mk_ullong
+# define __xen_mk_ullong(x) x ## ULL
+#endif
+#define xen_mk_uint(x) __xen_mk_uint(x)
+#define xen_mk_ulong(x) __xen_mk_ulong(x)
+#define xen_mk_ullong(x) __xen_mk_ullong(x)
+
+#else
+
+/* In assembly code we cannot use C numeric constant suffixes. */
+#define xen_mk_uint(x) x
+#define xen_mk_ulong(x) x
+#define xen_mk_ullong(x) x
+
+#endif
+
+/*
+ * HYPERCALLS
+ */
+
+/* `incontents 100 hcalls List of hypercalls
+ * ` enum hypercall_num { // __HYPERVISOR_* => HYPERVISOR_*()
+ */
+
+#define __HYPERVISOR_set_trap_table 0
+#define __HYPERVISOR_mmu_update 1
+#define __HYPERVISOR_set_gdt 2
+#define __HYPERVISOR_stack_switch 3
+#define __HYPERVISOR_set_callbacks 4
+#define __HYPERVISOR_fpu_taskswitch 5
+#define __HYPERVISOR_sched_op_compat 6 /* compat since 0x00030101 */
+#define __HYPERVISOR_platform_op 7
+#define __HYPERVISOR_set_debugreg 8
+#define __HYPERVISOR_get_debugreg 9
+#define __HYPERVISOR_update_descriptor 10
+#define __HYPERVISOR_memory_op 12
+#define __HYPERVISOR_multicall 13
+#define __HYPERVISOR_update_va_mapping 14
+#define __HYPERVISOR_set_timer_op 15
+#define __HYPERVISOR_event_channel_op_compat 16 /* compat since 0x00030202 */
+#define __HYPERVISOR_xen_version 17
+#define __HYPERVISOR_console_io 18
+#define __HYPERVISOR_physdev_op_compat 19 /* compat since 0x00030202 */
+#define __HYPERVISOR_grant_table_op 20
+#define __HYPERVISOR_vm_assist 21
+#define __HYPERVISOR_update_va_mapping_otherdomain 22
+#define __HYPERVISOR_iret 23 /* x86 only */
+#define __HYPERVISOR_vcpu_op 24
+#define __HYPERVISOR_set_segment_base 25 /* x86/64 only */
+#define __HYPERVISOR_mmuext_op 26
+#define __HYPERVISOR_xsm_op 27
+#define __HYPERVISOR_nmi_op 28
+#define __HYPERVISOR_sched_op 29
+#define __HYPERVISOR_callback_op 30
+#define __HYPERVISOR_xenoprof_op 31
+#define __HYPERVISOR_event_channel_op 32
+#define __HYPERVISOR_physdev_op 33
+#define __HYPERVISOR_hvm_op 34
+#define __HYPERVISOR_sysctl 35
+#define __HYPERVISOR_domctl 36
+#define __HYPERVISOR_kexec_op 37
+#define __HYPERVISOR_tmem_op 38
+#define __HYPERVISOR_xc_reserved_op 39 /* reserved for XenClient */
+#define __HYPERVISOR_xenpmu_op 40
+#define __HYPERVISOR_dm_op 41
+
+/* Architecture-specific hypercall definitions. */
+#define __HYPERVISOR_arch_0 48
+#define __HYPERVISOR_arch_1 49
+#define __HYPERVISOR_arch_2 50
+#define __HYPERVISOR_arch_3 51
+#define __HYPERVISOR_arch_4 52
+#define __HYPERVISOR_arch_5 53
+#define __HYPERVISOR_arch_6 54
+#define __HYPERVISOR_arch_7 55
+
+/* ` } */
+
+/*
+ * HYPERCALL COMPATIBILITY.
+ */
+
+/* New sched_op hypercall introduced in 0x00030101. */
+#if __XEN_INTERFACE_VERSION__ < 0x00030101
+#undef __HYPERVISOR_sched_op
+#define __HYPERVISOR_sched_op __HYPERVISOR_sched_op_compat
+#endif
+
+/* New event-channel and physdev hypercalls introduced in 0x00030202. */
+#if __XEN_INTERFACE_VERSION__ < 0x00030202
+#undef __HYPERVISOR_event_channel_op
+#define __HYPERVISOR_event_channel_op __HYPERVISOR_event_channel_op_compat
+#undef __HYPERVISOR_physdev_op
+#define __HYPERVISOR_physdev_op __HYPERVISOR_physdev_op_compat
+#endif
+
+/* New platform_op hypercall introduced in 0x00030204. */
+#if __XEN_INTERFACE_VERSION__ < 0x00030204
+#define __HYPERVISOR_dom0_op __HYPERVISOR_platform_op
+#endif
+
+/*
+ * VIRTUAL INTERRUPTS
+ *
+ * Virtual interrupts that a guest OS may receive from Xen.
+ *
+ * In the side comments, 'V.' denotes a per-VCPU VIRQ while 'G.' denotes a
+ * global VIRQ. The former can be bound once per VCPU and cannot be re-bound.
+ * The latter can be allocated only once per guest: they must initially be
+ * allocated to VCPU0 but can subsequently be re-bound.
+ */
+/* ` enum virq { */
+#define VIRQ_TIMER 0 /* V. Timebase update, and/or requested timeout. */
+#define VIRQ_DEBUG 1 /* V. Request guest to dump debug info. */
+#define VIRQ_CONSOLE 2 /* G. (DOM0) Bytes received on emergency console. */
+#define VIRQ_DOM_EXC 3 /* G. (DOM0) Exceptional event for some domain. */
+#define VIRQ_TBUF 4 /* G. (DOM0) Trace buffer has records available. */
+#define VIRQ_DEBUGGER 6 /* G. (DOM0) A domain has paused for debugging. */
+#define VIRQ_XENOPROF 7 /* V. XenOprofile interrupt: new sample available */
+#define VIRQ_CON_RING 8 /* G. (DOM0) Bytes received on console */
+#define VIRQ_PCPU_STATE 9 /* G. (DOM0) PCPU state changed */
+#define VIRQ_MEM_EVENT 10 /* G. (DOM0) A memory event has occured */
+#define VIRQ_XC_RESERVED 11 /* G. Reserved for XenClient */
+#define VIRQ_ENOMEM 12 /* G. (DOM0) Low on heap memory */
+#define VIRQ_XENPMU 13 /* V. PMC interrupt */
+
+/* Architecture-specific VIRQ definitions. */
+#define VIRQ_ARCH_0 16
+#define VIRQ_ARCH_1 17
+#define VIRQ_ARCH_2 18
+#define VIRQ_ARCH_3 19
+#define VIRQ_ARCH_4 20
+#define VIRQ_ARCH_5 21
+#define VIRQ_ARCH_6 22
+#define VIRQ_ARCH_7 23
+/* ` } */
+
+#define NR_VIRQS 24
+
+/*
+ * ` enum neg_errnoval
+ * ` HYPERVISOR_mmu_update(const struct mmu_update reqs[],
+ * ` unsigned count, unsigned *done_out,
+ * ` unsigned foreigndom)
+ * `
+ * @reqs is an array of mmu_update_t structures ((ptr, val) pairs).
+ * @count is the length of the above array.
+ * @pdone is an output parameter indicating number of completed operations
+ * @foreigndom[15:0]: FD, the expected owner of data pages referenced in this
+ * hypercall invocation. Can be DOMID_SELF.
+ * @foreigndom[31:16]: PFD, the expected owner of pagetable pages referenced
+ * in this hypercall invocation. The value of this field
+ * (x) encodes the PFD as follows:
+ * x == 0 => PFD == DOMID_SELF
+ * x != 0 => PFD == x - 1
+ *
+ * Sub-commands: ptr[1:0] specifies the appropriate MMU_* command.
+ * -------------
+ * ptr[1:0] == MMU_NORMAL_PT_UPDATE:
+ * Updates an entry in a page table belonging to PFD. If updating an L1 table,
+ * and the new table entry is valid/present, the mapped frame must belong to
+ * FD. If attempting to map an I/O page then the caller assumes the privilege
+ * of the FD.
+ * FD == DOMID_IO: Permit /only/ I/O mappings, at the priv level of the caller.
+ * FD == DOMID_XEN: Map restricted areas of Xen's heap space.
+ * ptr[:2] -- Machine address of the page-table entry to modify.
+ * val -- Value to write.
+ *
+ * There also certain implicit requirements when using this hypercall. The
+ * pages that make up a pagetable must be mapped read-only in the guest.
+ * This prevents uncontrolled guest updates to the pagetable. Xen strictly
+ * enforces this, and will disallow any pagetable update which will end up
+ * mapping pagetable page RW, and will disallow using any writable page as a
+ * pagetable. In practice it means that when constructing a page table for a
+ * process, thread, etc, we MUST be very dilligient in following these rules:
+ * 1). Start with top-level page (PGD or in Xen language: L4). Fill out
+ * the entries.
+ * 2). Keep on going, filling out the upper (PUD or L3), and middle (PMD
+ * or L2).
+ * 3). Start filling out the PTE table (L1) with the PTE entries. Once
+ * done, make sure to set each of those entries to RO (so writeable bit
+ * is unset). Once that has been completed, set the PMD (L2) for this
+ * PTE table as RO.
+ * 4). When completed with all of the PMD (L2) entries, and all of them have
+ * been set to RO, make sure to set RO the PUD (L3). Do the same
+ * operation on PGD (L4) pagetable entries that have a PUD (L3) entry.
+ * 5). Now before you can use those pages (so setting the cr3), you MUST also
+ * pin them so that the hypervisor can verify the entries. This is done
+ * via the HYPERVISOR_mmuext_op(MMUEXT_PIN_L4_TABLE, guest physical frame
+ * number of the PGD (L4)). And this point the HYPERVISOR_mmuext_op(
+ * MMUEXT_NEW_BASEPTR, guest physical frame number of the PGD (L4)) can be
+ * issued.
+ * For 32-bit guests, the L4 is not used (as there is less pagetables), so
+ * instead use L3.
+ * At this point the pagetables can be modified using the MMU_NORMAL_PT_UPDATE
+ * hypercall. Also if so desired the OS can also try to write to the PTE
+ * and be trapped by the hypervisor (as the PTE entry is RO).
+ *
+ * To deallocate the pages, the operations are the reverse of the steps
+ * mentioned above. The argument is MMUEXT_UNPIN_TABLE for all levels and the
+ * pagetable MUST not be in use (meaning that the cr3 is not set to it).
+ *
+ * ptr[1:0] == MMU_MACHPHYS_UPDATE:
+ * Updates an entry in the machine->pseudo-physical mapping table.
+ * ptr[:2] -- Machine address within the frame whose mapping to modify.
+ * The frame must belong to the FD, if one is specified.
+ * val -- Value to write into the mapping entry.
+ *
+ * ptr[1:0] == MMU_PT_UPDATE_PRESERVE_AD:
+ * As MMU_NORMAL_PT_UPDATE above, but A/D bits currently in the PTE are ORed
+ * with those in @val.
+ *
+ * @val is usually the machine frame number along with some attributes.
+ * The attributes by default follow the architecture defined bits. Meaning that
+ * if this is a X86_64 machine and four page table layout is used, the layout
+ * of val is:
+ * - 63 if set means No execute (NX)
+ * - 46-13 the machine frame number
+ * - 12 available for guest
+ * - 11 available for guest
+ * - 10 available for guest
+ * - 9 available for guest
+ * - 8 global
+ * - 7 PAT (PSE is disabled, must use hypercall to make 4MB or 2MB pages)
+ * - 6 dirty
+ * - 5 accessed
+ * - 4 page cached disabled
+ * - 3 page write through
+ * - 2 userspace accessible
+ * - 1 writeable
+ * - 0 present
+ *
+ * The one bits that does not fit with the default layout is the PAGE_PSE
+ * also called PAGE_PAT). The MMUEXT_[UN]MARK_SUPER arguments to the
+ * HYPERVISOR_mmuext_op serve as mechanism to set a pagetable to be 4MB
+ * (or 2MB) instead of using the PAGE_PSE bit.
+ *
+ * The reason that the PAGE_PSE (bit 7) is not being utilized is due to Xen
+ * using it as the Page Attribute Table (PAT) bit - for details on it please
+ * refer to Intel SDM 10.12. The PAT allows to set the caching attributes of
+ * pages instead of using MTRRs.
+ *
+ * The PAT MSR is as follows (it is a 64-bit value, each entry is 8 bits):
+ * PAT4 PAT0
+ * +-----+-----+----+----+----+-----+----+----+
+ * | UC | UC- | WC | WB | UC | UC- | WC | WB | <= Linux
+ * +-----+-----+----+----+----+-----+----+----+
+ * | UC | UC- | WT | WB | UC | UC- | WT | WB | <= BIOS (default when machine boots)
+ * +-----+-----+----+----+----+-----+----+----+
+ * | rsv | rsv | WP | WC | UC | UC- | WT | WB | <= Xen
+ * +-----+-----+----+----+----+-----+----+----+
+ *
+ * The lookup of this index table translates to looking up
+ * Bit 7, Bit 4, and Bit 3 of val entry:
+ *
+ * PAT/PSE (bit 7) ... PCD (bit 4) .. PWT (bit 3).
+ *
+ * If all bits are off, then we are using PAT0. If bit 3 turned on,
+ * then we are using PAT1, if bit 3 and bit 4, then PAT2..
+ *
+ * As you can see, the Linux PAT1 translates to PAT4 under Xen. Which means
+ * that if a guest that follows Linux's PAT setup and would like to set Write
+ * Combined on pages it MUST use PAT4 entry. Meaning that Bit 7 (PAGE_PAT) is
+ * set. For example, under Linux it only uses PAT0, PAT1, and PAT2 for the
+ * caching as:
+ *
+ * WB = none (so PAT0)
+ * WC = PWT (bit 3 on)
+ * UC = PWT | PCD (bit 3 and 4 are on).
+ *
+ * To make it work with Xen, it needs to translate the WC bit as so:
+ *
+ * PWT (so bit 3 on) --> PAT (so bit 7 is on) and clear bit 3
+ *
+ * And to translate back it would:
+ *
+ * PAT (bit 7 on) --> PWT (bit 3 on) and clear bit 7.
+ */
+#define MMU_NORMAL_PT_UPDATE 0 /* checked '*ptr = val'. ptr is MA. */
+#define MMU_MACHPHYS_UPDATE 1 /* ptr = MA of frame to modify entry for */
+#define MMU_PT_UPDATE_PRESERVE_AD 2 /* atomically: *ptr = val | (*ptr&(A|D)) */
+
+/*
+ * MMU EXTENDED OPERATIONS
+ *
+ * ` enum neg_errnoval
+ * ` HYPERVISOR_mmuext_op(mmuext_op_t uops[],
+ * ` unsigned int count,
+ * ` unsigned int *pdone,
+ * ` unsigned int foreigndom)
+ */
+/* HYPERVISOR_mmuext_op() accepts a list of mmuext_op structures.
+ * A foreigndom (FD) can be specified (or DOMID_SELF for none).
+ * Where the FD has some effect, it is described below.
+ *
+ * cmd: MMUEXT_(UN)PIN_*_TABLE
+ * mfn: Machine frame number to be (un)pinned as a p.t. page.
+ * The frame must belong to the FD, if one is specified.
+ *
+ * cmd: MMUEXT_NEW_BASEPTR
+ * mfn: Machine frame number of new page-table base to install in MMU.
+ *
+ * cmd: MMUEXT_NEW_USER_BASEPTR [x86/64 only]
+ * mfn: Machine frame number of new page-table base to install in MMU
+ * when in user space.
+ *
+ * cmd: MMUEXT_TLB_FLUSH_LOCAL
+ * No additional arguments. Flushes local TLB.
+ *
+ * cmd: MMUEXT_INVLPG_LOCAL
+ * linear_addr: Linear address to be flushed from the local TLB.
+ *
+ * cmd: MMUEXT_TLB_FLUSH_MULTI
+ * vcpumask: Pointer to bitmap of VCPUs to be flushed.
+ *
+ * cmd: MMUEXT_INVLPG_MULTI
+ * linear_addr: Linear address to be flushed.
+ * vcpumask: Pointer to bitmap of VCPUs to be flushed.
+ *
+ * cmd: MMUEXT_TLB_FLUSH_ALL
+ * No additional arguments. Flushes all VCPUs' TLBs.
+ *
+ * cmd: MMUEXT_INVLPG_ALL
+ * linear_addr: Linear address to be flushed from all VCPUs' TLBs.
+ *
+ * cmd: MMUEXT_FLUSH_CACHE
+ * No additional arguments. Writes back and flushes cache contents.
+ *
+ * cmd: MMUEXT_FLUSH_CACHE_GLOBAL
+ * No additional arguments. Writes back and flushes cache contents
+ * on all CPUs in the system.
+ *
+ * cmd: MMUEXT_SET_LDT
+ * linear_addr: Linear address of LDT base (NB. must be page-aligned).
+ * nr_ents: Number of entries in LDT.
+ *
+ * cmd: MMUEXT_CLEAR_PAGE
+ * mfn: Machine frame number to be cleared.
+ *
+ * cmd: MMUEXT_COPY_PAGE
+ * mfn: Machine frame number of the destination page.
+ * src_mfn: Machine frame number of the source page.
+ *
+ * cmd: MMUEXT_[UN]MARK_SUPER
+ * mfn: Machine frame number of head of superpage to be [un]marked.
+ */
+/* ` enum mmuext_cmd { */
+#define MMUEXT_PIN_L1_TABLE 0
+#define MMUEXT_PIN_L2_TABLE 1
+#define MMUEXT_PIN_L3_TABLE 2
+#define MMUEXT_PIN_L4_TABLE 3
+#define MMUEXT_UNPIN_TABLE 4
+#define MMUEXT_NEW_BASEPTR 5
+#define MMUEXT_TLB_FLUSH_LOCAL 6
+#define MMUEXT_INVLPG_LOCAL 7
+#define MMUEXT_TLB_FLUSH_MULTI 8
+#define MMUEXT_INVLPG_MULTI 9
+#define MMUEXT_TLB_FLUSH_ALL 10
+#define MMUEXT_INVLPG_ALL 11
+#define MMUEXT_FLUSH_CACHE 12
+#define MMUEXT_SET_LDT 13
+#define MMUEXT_NEW_USER_BASEPTR 15
+#define MMUEXT_CLEAR_PAGE 16
+#define MMUEXT_COPY_PAGE 17
+#define MMUEXT_FLUSH_CACHE_GLOBAL 18
+#define MMUEXT_MARK_SUPER 19
+#define MMUEXT_UNMARK_SUPER 20
+/* ` } */
+
+#ifndef __ASSEMBLY__
+struct mmuext_op {
+ unsigned int cmd; /* => enum mmuext_cmd */
+ union {
+ /* [UN]PIN_TABLE, NEW_BASEPTR, NEW_USER_BASEPTR
+ * CLEAR_PAGE, COPY_PAGE, [UN]MARK_SUPER */
+ xen_pfn_t mfn;
+ /* INVLPG_LOCAL, INVLPG_ALL, SET_LDT */
+ unsigned long linear_addr;
+ } arg1;
+ union {
+ /* SET_LDT */
+ unsigned int nr_ents;
+ /* TLB_FLUSH_MULTI, INVLPG_MULTI */
+#if __XEN_INTERFACE_VERSION__ >= 0x00030205
+ XEN_GUEST_HANDLE(const_void) vcpumask;
+#else
+ const void *vcpumask;
+#endif
+ /* COPY_PAGE */
+ xen_pfn_t src_mfn;
+ } arg2;
+};
+typedef struct mmuext_op mmuext_op_t;
+DEFINE_XEN_GUEST_HANDLE(mmuext_op_t);
+#endif
+
+/*
+ * ` enum neg_errnoval
+ * ` HYPERVISOR_update_va_mapping(unsigned long va, u64 val,
+ * ` enum uvm_flags flags)
+ * `
+ * ` enum neg_errnoval
+ * ` HYPERVISOR_update_va_mapping_otherdomain(unsigned long va, u64 val,
+ * ` enum uvm_flags flags,
+ * ` domid_t domid)
+ * `
+ * ` @va: The virtual address whose mapping we want to change
+ * ` @val: The new page table entry, must contain a machine address
+ * ` @flags: Control TLB flushes
+ */
+/* These are passed as 'flags' to update_va_mapping. They can be ORed. */
+/* When specifying UVMF_MULTI, also OR in a pointer to a CPU bitmap. */
+/* UVMF_LOCAL is merely UVMF_MULTI with a NULL bitmap pointer. */
+/* ` enum uvm_flags { */
+#define UVMF_NONE (xen_mk_ulong(0)<<0) /* No flushing at all. */
+#define UVMF_TLB_FLUSH (xen_mk_ulong(1)<<0) /* Flush entire TLB(s). */
+#define UVMF_INVLPG (xen_mk_ulong(2)<<0) /* Flush only one entry. */
+#define UVMF_FLUSHTYPE_MASK (xen_mk_ulong(3)<<0)
+#define UVMF_MULTI (xen_mk_ulong(0)<<2) /* Flush subset of TLBs. */
+#define UVMF_LOCAL (xen_mk_ulong(0)<<2) /* Flush local TLB. */
+#define UVMF_ALL (xen_mk_ulong(1)<<2) /* Flush all TLBs. */
+/* ` } */
+
+/*
+ * Commands to HYPERVISOR_console_io().
+ */
+#define CONSOLEIO_write 0
+#define CONSOLEIO_read 1
+
+/*
+ * Commands to HYPERVISOR_vm_assist().
+ */
+#define VMASST_CMD_enable 0
+#define VMASST_CMD_disable 1
+
+/* x86/32 guests: simulate full 4GB segment limits. */
+#define VMASST_TYPE_4gb_segments 0
+
+/* x86/32 guests: trap (vector 15) whenever above vmassist is used. */
+#define VMASST_TYPE_4gb_segments_notify 1
+
+/*
+ * x86 guests: support writes to bottom-level PTEs.
+ * NB1. Page-directory entries cannot be written.
+ * NB2. Guest must continue to remove all writable mappings of PTEs.
+ */
+#define VMASST_TYPE_writable_pagetables 2
+
+/* x86/PAE guests: support PDPTs above 4GB. */
+#define VMASST_TYPE_pae_extended_cr3 3
+
+/*
+ * x86 guests: Sane behaviour for virtual iopl
+ * - virtual iopl updated from do_iret() hypercalls.
+ * - virtual iopl reported in bounce frames.
+ * - guest kernels assumed to be level 0 for the purpose of iopl checks.
+ */
+#define VMASST_TYPE_architectural_iopl 4
+
+/*
+ * All guests: activate update indicator in vcpu_runstate_info
+ * Enable setting the XEN_RUNSTATE_UPDATE flag in guest memory mapped
+ * vcpu_runstate_info during updates of the runstate information.
+ */
+#define VMASST_TYPE_runstate_update_flag 5
+
+/*
+ * x86/64 guests: strictly hide M2P from user mode.
+ * This allows the guest to control respective hypervisor behavior:
+ * - when not set, L4 tables get created with the respective slot blank,
+ * and whenever the L4 table gets used as a kernel one the missing
+ * mapping gets inserted,
+ * - when set, L4 tables get created with the respective slot initialized
+ * as before, and whenever the L4 table gets used as a user one the
+ * mapping gets zapped.
+ */
+#define VMASST_TYPE_m2p_strict 32
+
+#if __XEN_INTERFACE_VERSION__ < 0x00040600
+#define MAX_VMASST_TYPE 3
+#endif
+
+/* Domain ids >= DOMID_FIRST_RESERVED cannot be used for ordinary domains. */
+#define DOMID_FIRST_RESERVED xen_mk_uint(0x7FF0)
+
+/* DOMID_SELF is used in certain contexts to refer to oneself. */
+#define DOMID_SELF xen_mk_uint(0x7FF0)
+
+/*
+ * DOMID_IO is used to restrict page-table updates to mapping I/O memory.
+ * Although no Foreign Domain need be specified to map I/O pages, DOMID_IO
+ * is useful to ensure that no mappings to the OS's own heap are accidentally
+ * installed. (e.g., in Linux this could cause havoc as reference counts
+ * aren't adjusted on the I/O-mapping code path).
+ * This only makes sense as HYPERVISOR_mmu_update()'s and
+ * HYPERVISOR_update_va_mapping_otherdomain()'s "foreigndom" argument. For
+ * HYPERVISOR_mmu_update() context it can be specified by any calling domain,
+ * otherwise it's only permitted if the caller is privileged.
+ */
+#define DOMID_IO xen_mk_uint(0x7FF1)
+
+/*
+ * DOMID_XEN is used to allow privileged domains to map restricted parts of
+ * Xen's heap space (e.g., the machine_to_phys table).
+ * This only makes sense as
+ * - HYPERVISOR_mmu_update()'s, HYPERVISOR_mmuext_op()'s, or
+ * HYPERVISOR_update_va_mapping_otherdomain()'s "foreigndom" argument,
+ * - with XENMAPSPACE_gmfn_foreign,
+ * and is only permitted if the caller is privileged.
+ */
+#define DOMID_XEN xen_mk_uint(0x7FF2)
+
+/*
+ * DOMID_COW is used as the owner of sharable pages */
+#define DOMID_COW xen_mk_uint(0x7FF3)
+
+/* DOMID_INVALID is used to identify pages with unknown owner. */
+#define DOMID_INVALID xen_mk_uint(0x7FF4)
+
+/* Idle domain. */
+#define DOMID_IDLE xen_mk_uint(0x7FFF)
+
+#ifndef __ASSEMBLY__
+
+typedef uint16_t domid_t;
+
+/*
+ * Send an array of these to HYPERVISOR_mmu_update().
+ * NB. The fields are natural pointer/address size for this architecture.
+ */
+struct mmu_update {
+ uint64_t ptr; /* Machine address of PTE. */
+ uint64_t val; /* New contents of PTE. */
+};
+typedef struct mmu_update mmu_update_t;
+DEFINE_XEN_GUEST_HANDLE(mmu_update_t);
+
+/*
+ * ` enum neg_errnoval
+ * ` HYPERVISOR_multicall(multicall_entry_t call_list[],
+ * ` uint32_t nr_calls);
+ *
+ * NB. The fields are logically the natural register size for this
+ * architecture. In cases where xen_ulong_t is larger than this then
+ * any unused bits in the upper portion must be zero.
+ */
+struct multicall_entry {
+ xen_ulong_t op, result;
+ xen_ulong_t args[6];
+};
+typedef struct multicall_entry multicall_entry_t;
+DEFINE_XEN_GUEST_HANDLE(multicall_entry_t);
+
+#if __XEN_INTERFACE_VERSION__ < 0x00040400
+/*
+ * Event channel endpoints per domain (when using the 2-level ABI):
+ * 1024 if a long is 32 bits; 4096 if a long is 64 bits.
+ */
+#define NR_EVENT_CHANNELS EVTCHN_2L_NR_CHANNELS
+#endif
+
+struct vcpu_time_info {
+ /*
+ * Updates to the following values are preceded and followed by an
+ * increment of 'version'. The guest can therefore detect updates by
+ * looking for changes to 'version'. If the least-significant bit of
+ * the version number is set then an update is in progress and the guest
+ * must wait to read a consistent set of values.
+ * The correct way to interact with the version number is similar to
+ * Linux's seqlock: see the implementations of read_seqbegin/read_seqretry.
+ */
+ uint32_t version;
+ uint32_t pad0;
+ uint64_t tsc_timestamp; /* TSC at last update of time vals. */
+ uint64_t system_time; /* Time, in nanosecs, since boot. */
+ /*
+ * Current system time:
+ * system_time +
+ * ((((tsc - tsc_timestamp) << tsc_shift) * tsc_to_system_mul) >> 32)
+ * CPU frequency (Hz):
+ * ((10^9 << 32) / tsc_to_system_mul) >> tsc_shift
+ */
+ uint32_t tsc_to_system_mul;
+ int8_t tsc_shift;
+#if __XEN_INTERFACE_VERSION__ > 0x040600
+ uint8_t flags;
+ uint8_t pad1[2];
+#else
+ int8_t pad1[3];
+#endif
+}; /* 32 bytes */
+typedef struct vcpu_time_info vcpu_time_info_t;
+
+#define XEN_PVCLOCK_TSC_STABLE_BIT (1 << 0)
+#define XEN_PVCLOCK_GUEST_STOPPED (1 << 1)
+
+struct vcpu_info {
+ /*
+ * 'evtchn_upcall_pending' is written non-zero by Xen to indicate
+ * a pending notification for a particular VCPU. It is then cleared
+ * by the guest OS /before/ checking for pending work, thus avoiding
+ * a set-and-check race. Note that the mask is only accessed by Xen
+ * on the CPU that is currently hosting the VCPU. This means that the
+ * pending and mask flags can be updated by the guest without special
+ * synchronisation (i.e., no need for the x86 LOCK prefix).
+ * This may seem suboptimal because if the pending flag is set by
+ * a different CPU then an IPI may be scheduled even when the mask
+ * is set. However, note:
+ * 1. The task of 'interrupt holdoff' is covered by the per-event-
+ * channel mask bits. A 'noisy' event that is continually being
+ * triggered can be masked at source at this very precise
+ * granularity.
+ * 2. The main purpose of the per-VCPU mask is therefore to restrict
+ * reentrant execution: whether for concurrency control, or to
+ * prevent unbounded stack usage. Whatever the purpose, we expect
+ * that the mask will be asserted only for short periods at a time,
+ * and so the likelihood of a 'spurious' IPI is suitably small.
+ * The mask is read before making an event upcall to the guest: a
+ * non-zero mask therefore guarantees that the VCPU will not receive
+ * an upcall activation. The mask is cleared when the VCPU requests
+ * to block: this avoids wakeup-waiting races.
+ */
+ uint8_t evtchn_upcall_pending;
+#ifdef XEN_HAVE_PV_UPCALL_MASK
+ uint8_t evtchn_upcall_mask;
+#else /* XEN_HAVE_PV_UPCALL_MASK */
+ uint8_t pad0;
+#endif /* XEN_HAVE_PV_UPCALL_MASK */
+ xen_ulong_t evtchn_pending_sel;
+ struct arch_vcpu_info arch;
+ struct vcpu_time_info time;
+}; /* 64 bytes (x86) */
+#ifndef __XEN__
+typedef struct vcpu_info vcpu_info_t;
+#endif
+
+/*
+ * `incontents 200 startofday_shared Start-of-day shared data structure
+ * Xen/kernel shared data -- pointer provided in start_info.
+ *
+ * This structure is defined to be both smaller than a page, and the
+ * only data on the shared page, but may vary in actual size even within
+ * compatible Xen versions; guests should not rely on the size
+ * of this structure remaining constant.
+ */
+struct shared_info {
+ struct vcpu_info vcpu_info[XEN_LEGACY_MAX_VCPUS];
+
+ /*
+ * A domain can create "event channels" on which it can send and receive
+ * asynchronous event notifications. There are three classes of event that
+ * are delivered by this mechanism:
+ * 1. Bi-directional inter- and intra-domain connections. Domains must
+ * arrange out-of-band to set up a connection (usually by allocating
+ * an unbound 'listener' port and avertising that via a storage service
+ * such as xenstore).
+ * 2. Physical interrupts. A domain with suitable hardware-access
+ * privileges can bind an event-channel port to a physical interrupt
+ * source.
+ * 3. Virtual interrupts ('events'). A domain can bind an event-channel
+ * port to a virtual interrupt source, such as the virtual-timer
+ * device or the emergency console.
+ *
+ * Event channels are addressed by a "port index". Each channel is
+ * associated with two bits of information:
+ * 1. PENDING -- notifies the domain that there is a pending notification
+ * to be processed. This bit is cleared by the guest.
+ * 2. MASK -- if this bit is clear then a 0->1 transition of PENDING
+ * will cause an asynchronous upcall to be scheduled. This bit is only
+ * updated by the guest. It is read-only within Xen. If a channel
+ * becomes pending while the channel is masked then the 'edge' is lost
+ * (i.e., when the channel is unmasked, the guest must manually handle
+ * pending notifications as no upcall will be scheduled by Xen).
+ *
+ * To expedite scanning of pending notifications, any 0->1 pending
+ * transition on an unmasked channel causes a corresponding bit in a
+ * per-vcpu selector word to be set. Each bit in the selector covers a
+ * 'C long' in the PENDING bitfield array.
+ */
+ xen_ulong_t evtchn_pending[sizeof(xen_ulong_t) * 8];
+ xen_ulong_t evtchn_mask[sizeof(xen_ulong_t) * 8];
+
+ /*
+ * Wallclock time: updated only by control software. Guests should base
+ * their gettimeofday() syscall on this wallclock-base value.
+ */
+ uint32_t wc_version; /* Version counter: see vcpu_time_info_t. */
+ uint32_t wc_sec; /* Secs 00:00:00 UTC, Jan 1, 1970. */
+ uint32_t wc_nsec; /* Nsecs 00:00:00 UTC, Jan 1, 1970. */
+#if !defined(__i386__)
+ uint32_t wc_sec_hi;
+# define xen_wc_sec_hi wc_sec_hi
+#elif !defined(__XEN__) && !defined(__XEN_TOOLS__)
+# define xen_wc_sec_hi arch.wc_sec_hi
+#endif
+
+ struct arch_shared_info arch;
+
+};
+#ifndef __XEN__
+typedef struct shared_info shared_info_t;
+#endif
+
+/*
+ * `incontents 200 startofday Start-of-day memory layout
+ *
+ * 1. The domain is started within contiguous virtual-memory region.
+ * 2. The contiguous region ends on an aligned 4MB boundary.
+ * 3. This the order of bootstrap elements in the initial virtual region:
+ * a. relocated kernel image
+ * b. initial ram disk [mod_start, mod_len]
+ * (may be omitted)
+ * c. list of allocated page frames [mfn_list, nr_pages]
+ * (unless relocated due to XEN_ELFNOTE_INIT_P2M)
+ * d. start_info_t structure [register rSI (x86)]
+ * in case of dom0 this page contains the console info, too
+ * e. unless dom0: xenstore ring page
+ * f. unless dom0: console ring page
+ * g. bootstrap page tables [pt_base and CR3 (x86)]
+ * h. bootstrap stack [register ESP (x86)]
+ * 4. Bootstrap elements are packed together, but each is 4kB-aligned.
+ * 5. The list of page frames forms a contiguous 'pseudo-physical' memory
+ * layout for the domain. In particular, the bootstrap virtual-memory
+ * region is a 1:1 mapping to the first section of the pseudo-physical map.
+ * 6. All bootstrap elements are mapped read-writable for the guest OS. The
+ * only exception is the bootstrap page table, which is mapped read-only.
+ * 7. There is guaranteed to be at least 512kB padding after the final
+ * bootstrap element. If necessary, the bootstrap virtual region is
+ * extended by an extra 4MB to ensure this.
+ *
+ * Note: Prior to 25833:bb85bbccb1c9. ("x86/32-on-64 adjust Dom0 initial page
+ * table layout") a bug caused the pt_base (3.g above) and cr3 to not point
+ * to the start of the guest page tables (it was offset by two pages).
+ * This only manifested itself on 32-on-64 dom0 kernels and not 32-on-64 domU
+ * or 64-bit kernels of any colour. The page tables for a 32-on-64 dom0 got
+ * allocated in the order: 'first L1','first L2', 'first L3', so the offset
+ * to the page table base is by two pages back. The initial domain if it is
+ * 32-bit and runs under a 64-bit hypervisor should _NOT_ use two of the
+ * pages preceding pt_base and mark them as reserved/unused.
+ */
+#ifdef XEN_HAVE_PV_GUEST_ENTRY
+struct start_info {
+ /* THE FOLLOWING ARE FILLED IN BOTH ON INITIAL BOOT AND ON RESUME. */
+ char magic[32]; /* "xen-<version>-<platform>". */
+ unsigned long nr_pages; /* Total pages allocated to this domain. */
+ unsigned long shared_info; /* MACHINE address of shared info struct. */
+ uint32_t flags; /* SIF_xxx flags. */
+ xen_pfn_t store_mfn; /* MACHINE page number of shared page. */
+ uint32_t store_evtchn; /* Event channel for store communication. */
+ union {
+ struct {
+ xen_pfn_t mfn; /* MACHINE page number of console page. */
+ uint32_t evtchn; /* Event channel for console page. */
+ } domU;
+ struct {
+ uint32_t info_off; /* Offset of console_info struct. */
+ uint32_t info_size; /* Size of console_info struct from start.*/
+ } dom0;
+ } console;
+ /* THE FOLLOWING ARE ONLY FILLED IN ON INITIAL BOOT (NOT RESUME). */
+ unsigned long pt_base; /* VIRTUAL address of page directory. */
+ unsigned long nr_pt_frames; /* Number of bootstrap p.t. frames. */
+ unsigned long mfn_list; /* VIRTUAL address of page-frame list. */
+ unsigned long mod_start; /* VIRTUAL address of pre-loaded module */
+ /* (PFN of pre-loaded module if */
+ /* SIF_MOD_START_PFN set in flags). */
+ unsigned long mod_len; /* Size (bytes) of pre-loaded module. */
+#define MAX_GUEST_CMDLINE 1024
+ int8_t cmd_line[MAX_GUEST_CMDLINE];
+ /* The pfn range here covers both page table and p->m table frames. */
+ unsigned long first_p2m_pfn;/* 1st pfn forming initial P->M table. */
+ unsigned long nr_p2m_frames;/* # of pfns forming initial P->M table. */
+};
+typedef struct start_info start_info_t;
+
+/* New console union for dom0 introduced in 0x00030203. */
+#if __XEN_INTERFACE_VERSION__ < 0x00030203
+#define console_mfn console.domU.mfn
+#define console_evtchn console.domU.evtchn
+#endif
+#endif /* XEN_HAVE_PV_GUEST_ENTRY */
+
+/* These flags are passed in the 'flags' field of start_info_t. */
+#define SIF_PRIVILEGED (1<<0) /* Is the domain privileged? */
+#define SIF_INITDOMAIN (1<<1) /* Is this the initial control domain? */
+#define SIF_MULTIBOOT_MOD (1<<2) /* Is mod_start a multiboot module? */
+#define SIF_MOD_START_PFN (1<<3) /* Is mod_start a PFN? */
+#define SIF_VIRT_P2M_4TOOLS (1<<4) /* Do Xen tools understand a virt. mapped */
+ /* P->M making the 3 level tree obsolete? */
+#define SIF_PM_MASK (0xFF<<8) /* reserve 1 byte for xen-pm options */
+
+/*
+ * A multiboot module is a package containing modules very similar to a
+ * multiboot module array. The only differences are:
+ * - the array of module descriptors is by convention simply at the beginning
+ * of the multiboot module,
+ * - addresses in the module descriptors are based on the beginning of the
+ * multiboot module,
+ * - the number of modules is determined by a termination descriptor that has
+ * mod_start == 0.
+ *
+ * This permits to both build it statically and reference it in a configuration
+ * file, and let the PV guest easily rebase the addresses to virtual addresses
+ * and at the same time count the number of modules.
+ */
+struct xen_multiboot_mod_list
+{
+ /* Address of first byte of the module */
+ uint32_t mod_start;
+ /* Address of last byte of the module (inclusive) */
+ uint32_t mod_end;
+ /* Address of zero-terminated command line */
+ uint32_t cmdline;
+ /* Unused, must be zero */
+ uint32_t pad;
+};
+/*
+ * `incontents 200 startofday_dom0_console Dom0_console
+ *
+ * The console structure in start_info.console.dom0
+ *
+ * This structure includes a variety of information required to
+ * have a working VGA/VESA console.
+ */
+typedef struct dom0_vga_console_info {
+ uint8_t video_type; /* DOM0_VGA_CONSOLE_??? */
+#define XEN_VGATYPE_TEXT_MODE_3 0x03
+#define XEN_VGATYPE_VESA_LFB 0x23
+#define XEN_VGATYPE_EFI_LFB 0x70
+
+ union {
+ struct {
+ /* Font height, in pixels. */
+ uint16_t font_height;
+ /* Cursor location (column, row). */
+ uint16_t cursor_x, cursor_y;
+ /* Number of rows and columns (dimensions in characters). */
+ uint16_t rows, columns;
+ } text_mode_3;
+
+ struct {
+ /* Width and height, in pixels. */
+ uint16_t width, height;
+ /* Bytes per scan line. */
+ uint16_t bytes_per_line;
+ /* Bits per pixel. */
+ uint16_t bits_per_pixel;
+ /* LFB physical address, and size (in units of 64kB). */
+ uint32_t lfb_base;
+ uint32_t lfb_size;
+ /* RGB mask offsets and sizes, as defined by VBE 1.2+ */
+ uint8_t red_pos, red_size;
+ uint8_t green_pos, green_size;
+ uint8_t blue_pos, blue_size;
+ uint8_t rsvd_pos, rsvd_size;
+#if __XEN_INTERFACE_VERSION__ >= 0x00030206
+ /* VESA capabilities (offset 0xa, VESA command 0x4f00). */
+ uint32_t gbl_caps;
+ /* Mode attributes (offset 0x0, VESA command 0x4f01). */
+ uint16_t mode_attrs;
+#endif
+ } vesa_lfb;
+ } u;
+} dom0_vga_console_info_t;
+#define xen_vga_console_info dom0_vga_console_info
+#define xen_vga_console_info_t dom0_vga_console_info_t
+
+typedef uint8_t xen_domain_handle_t[16];
+
+__DEFINE_XEN_GUEST_HANDLE(uint8, uint8_t);
+__DEFINE_XEN_GUEST_HANDLE(uint16, uint16_t);
+__DEFINE_XEN_GUEST_HANDLE(uint32, uint32_t);
+__DEFINE_XEN_GUEST_HANDLE(uint64, uint64_t);
+
+typedef struct {
+ uint8_t a[16];
+} xen_uuid_t;
+
+/*
+ * XEN_DEFINE_UUID(0x00112233, 0x4455, 0x6677, 0x8899,
+ * 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff)
+ * will construct UUID 00112233-4455-6677-8899-aabbccddeeff presented as
+ * {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
+ * 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};
+ *
+ * NB: This is compatible with Linux kernel and with libuuid, but it is not
+ * compatible with Microsoft, as they use mixed-endian encoding (some
+ * components are little-endian, some are big-endian).
+ */
+#define XEN_DEFINE_UUID_(a, b, c, d, e1, e2, e3, e4, e5, e6) \
+ {{((a) >> 24) & 0xFF, ((a) >> 16) & 0xFF, \
+ ((a) >> 8) & 0xFF, ((a) >> 0) & 0xFF, \
+ ((b) >> 8) & 0xFF, ((b) >> 0) & 0xFF, \
+ ((c) >> 8) & 0xFF, ((c) >> 0) & 0xFF, \
+ ((d) >> 8) & 0xFF, ((d) >> 0) & 0xFF, \
+ e1, e2, e3, e4, e5, e6}}
+
+#if defined(__STDC_VERSION__) ? __STDC_VERSION__ >= 199901L : defined(__GNUC__)
+#define XEN_DEFINE_UUID(a, b, c, d, e1, e2, e3, e4, e5, e6) \
+ ((xen_uuid_t)XEN_DEFINE_UUID_(a, b, c, d, e1, e2, e3, e4, e5, e6))
+#else
+#define XEN_DEFINE_UUID(a, b, c, d, e1, e2, e3, e4, e5, e6) \
+ XEN_DEFINE_UUID_(a, b, c, d, e1, e2, e3, e4, e5, e6)
+#endif /* __STDC_VERSION__ / __GNUC__ */
+
+#endif /* !__ASSEMBLY__ */
+
+/* Default definitions for macros used by domctl/sysctl. */
+#if defined(__XEN__) || defined(__XEN_TOOLS__)
+
+#ifndef int64_aligned_t
+#define int64_aligned_t int64_t
+#endif
+#ifndef uint64_aligned_t
+#define uint64_aligned_t uint64_t
+#endif
+#ifndef XEN_GUEST_HANDLE_64
+#define XEN_GUEST_HANDLE_64(name) XEN_GUEST_HANDLE(name)
+#endif
+
+#ifndef __ASSEMBLY__
+struct xenctl_bitmap {
+ XEN_GUEST_HANDLE_64(uint8) bitmap;
+ uint32_t nr_bits;
+};
+#endif
+
+#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */
+
+#endif /* __XEN_PUBLIC_XEN_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */