/*
 * multiboot.h
 *
 * Copyright (C) 2013 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _MULTIBOOT_H_
#define _MULTIBOOT_H_

#include "../common.h"

typedef struct
{
    dword_t size;
    dword_t reserved;
} multiboot_header_t;

typedef enum
{
    MULTIBOOT_INFO_END = 0,

    MULTIBOOT_INFO_CMDLINE,
    MULTIBOOT_INFO_LOADER,
    MULTIBOOT_INFO_MODULES,
    MULTIBOOT_INFO_MEMORY,
    MULTIBOOT_INFO_BOOT_DEVICE,
    MULTIBOOT_INFO_MEMORY_MAP,
    MULTIBOOT_INFO_VBE_INFO,
    MULTIBOOT_INFO_FRAMEBUFFER,
    MULTIBOOT_INFO_SECTIONS,
    MULTIBOOT_INFO_APM,
    MULTIBOOT_INFO_EFI32,
    MULTIBOOT_INFO_EFI64,
    MULTIBOOT_INFO_SMBIOS,
    MULTIBOOT_INFO_ACPI1_RSDP,
    MULTIBOOT_INFO_ACPI2_RSDP,
    MULTIBOOT_INFO_NETWORK,
    MULTIBOOT_INFO_EFI_MEMORY_MAP,
    MULTIBOOT_INFO_EFI_SERVICES,
    MULTIBOOT_INFO_EFI32_IMAGE_HANDLE,
    MULTIBOOT_INFO_EFI64_IMAGE_HANDLE,
    MULTIBOOT_INFO_BASE_ADDRESS,
} multiboot_info_type_t;

typedef struct
{
    dword_t type;
    dword_t size;
} multiboot_tag_t;

typedef struct
{
    dword_t type;
    dword_t size;
    char string[VARIABLE_SIZE];
} multiboot_tag_cmdline_t, multiboot_tag_loader_t;

typedef struct
{
    dword_t type;
    dword_t size;
    dword_t mod_start;
    dword_t mod_end;
    char string[VARIABLE_SIZE];
} multiboot_tag_module_t;

typedef struct
{
    dword_t type;
    dword_t size;
    dword_t mem_lower;
    dword_t mem_upper;
} multiboot_tag_memory_t;

typedef struct
{
    dword_t type;
    dword_t size;
    dword_t bios_device;
    dword_t partition;
    dword_t sub_partition;
} multiboot_tag_boot_device_t;

typedef struct
{
    union
    {
        struct { dword_t base_low, base_high; };
        qword_t base;
    };

    union
    {
        struct { dword_t length_low, length_high; };
        qword_t length;
    };

    dword_t type;
    dword_t reserved;
} multiboot_mmap_entry_t;

typedef struct
{
    dword_t type;
    dword_t size;
    dword_t entry_size;
    dword_t entry_version;
} multiboot_tag_mmap_t;

typedef struct
{
    dword_t type;
    dword_t size;
    word_t vbe_mode;
    word_t vbe_interface_seg;
    word_t vbe_interface_off;
    word_t vbe_interface_Len;
    byte_t vbe_control_info[512];
    byte_t vbe_mode_info[256];
} multiboot_tag_vbe_t;

typedef struct
{
    dword_t type;
    dword_t size;
    qword_t fb_address;
    dword_t fb_pitch;
    dword_t fb_width;
    dword_t fb_height;
    byte_t fb_bpp;
    byte_t fb_type;
    byte_t fb_reserved;

    union
    {
        struct
        {
            dword_t palette_size;

            struct
            {
                byte_t red, green, blue;
            } palette[VARIABLE_SIZE];
        };

        struct
        {
            byte_t red_field_pos;
            byte_t red_mask_size;
            byte_t green_field_pos;
            byte_t green_mask_size;
            byte_t blue_field_pos;
            byte_t blue_mask_size;
        };
    };
} multiboot_tag_framebuffer_t;

typedef struct
{
    dword_t type;
    dword_t size;
    dword_t num;
    dword_t entsize;
    dword_t shndx;
} multiboot_tag_sections_t;

#endif
