Skip to content

Commit

Permalink
multiboot: add multiboot information structure
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianfreyer committed Feb 20, 2018
1 parent bb8b70e commit e952761
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 1 deletion.
2 changes: 1 addition & 1 deletion multiboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void *entry = NULL;
struct multiboot*
mb_scan(void *kernel, size_t kernsz)
{
struct multiboot *mb = malloc(sizeof(struct multiboot));
struct multiboot *mb = calloc(1, sizeof(struct multiboot));
uint32_t* magic = NULL;

printf("Scanning for multiboot header...\r\n");
Expand Down
80 changes: 80 additions & 0 deletions multiboot.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@
#define MULTIBOOT_FLAG_MEMORY (1<<1)
#define MULTIBOOT_FLAG_ALIGN4k (1<<0)

#define MULTIBOOT_FRAMEBUFFER (1<<12)
#define MULTIBOOT_VBE (1<<11)
#define MULTIBOOT_APM_TABLE (1<<10)
#define MULTIBOOT_BOOTLOADER_NAME (1<<9)
#define MULTIBOOT_CONFIG_TABLE (1<<8)
#define MULTIBOOT_DRIVES (1<<7)
#define MULTIBOOT_MMAP (1<<6)
#define MULTIBOOT_SYMS_ELF (1<<5)
#define MULTIBOOT_SYMS_AOUT (1<<4)
#define MULTIBOOT_MODS (1<<3)
#define MULTIBOOT_CMDLINE (1<<2)
#define MULTIBOOT_BOOTDEVICE (1<<1)
#define MULTIBOOT_MEMINFO (1<<0)

#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0
#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1
#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2

#define PACKED __attribute__((packed))

struct multiboot_header {
Expand All @@ -57,6 +75,67 @@ struct multiboot_header {
uint32_t depth;
} PACKED;

struct multiboot_info {
uint32_t flags;
uint32_t mem_lower;
uint32_t mem_upper;
uint32_t boot_device;
uint32_t cmdline;
uint32_t mods_count;
uint32_t mods_addr;
union {
struct {
uint32_t num;
uint32_t size;
uint32_t addr;
uint32_t shndx;
} PACKED elf;
struct {
uint32_t tabsize;
uint32_t strsize;
uint32_t addr;
uint32_t reserved;
} PACKED aout;
} syms;
uint32_t mmap_length;
uint32_t mmap_addr;
uint32_t drives_length;
uint32_t drives_addr;
uint32_t config_table;
uint32_t boot_loader_name;
uint32_t apm_table;
struct {
uint32_t control_info;
uint32_t mode_info;
uint16_t mode;
uint16_t interface_seg;
uint16_t interface_off;
uint16_t interface_len;
} PACKED vbe;
struct {
uint64_t addr;
uint32_t pitch;
uint32_t width;
uint32_t height;
uint8_t bpp;
uint8_t type;
union {
struct {
uint32_t addr;
uint16_t num_colors;
} PACKED palette;
struct {
uint8_t red_field_position;
uint8_t red_mask_size;
uint8_t green_field_position;
uint8_t green_mask_size;
uint8_t blue_field_position;
uint8_t blue_mask_size;
} PACKED rgb;
} color_info;
} PACKED framebuffer;
} PACKED;

struct multiboot2_header {
uint32_t magic;
uint32_t architecture;
Expand All @@ -80,6 +159,7 @@ struct multiboot {
struct multiboot2_header* header;
} mb2;
} header;
struct multiboot_info info;
};

/**
Expand Down
71 changes: 71 additions & 0 deletions tests/test-multiboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,76 @@ ATF_TC_BODY(load_elf, tc)
ATF_CHECK_EQ_MSG(0, error, "multiboot_load_elf failed");
}

ATF_TC(sizeof_multiboot_info);
ATF_TC_HEAD(sizeof_multiboot_info, tc)
{
atf_tc_set_md_var(tc, "descr", "Check multiboot info size");
}
ATF_TC_BODY(sizeof_multiboot_info, tc)
{
ATF_CHECK_EQ(0, offsetof(struct multiboot_info, flags));
ATF_CHECK_EQ(4, offsetof(struct multiboot_info, mem_lower));
ATF_CHECK_EQ(8, offsetof(struct multiboot_info, mem_upper));
ATF_CHECK_EQ(12, offsetof(struct multiboot_info, boot_device));
ATF_CHECK_EQ(16, offsetof(struct multiboot_info, cmdline));
ATF_CHECK_EQ(20, offsetof(struct multiboot_info, mods_count));
ATF_CHECK_EQ(24, offsetof(struct multiboot_info, mods_addr));
ATF_CHECK_EQ(28, offsetof(struct multiboot_info, syms));
ATF_CHECK_EQ(28, offsetof(struct multiboot_info, syms.aout));
ATF_CHECK_EQ(28, offsetof(struct multiboot_info, syms.aout.tabsize));
ATF_CHECK_EQ(32, offsetof(struct multiboot_info, syms.aout.strsize));
ATF_CHECK_EQ(36, offsetof(struct multiboot_info, syms.aout.addr));
ATF_CHECK_EQ(40, offsetof(struct multiboot_info, syms.aout.reserved));
ATF_CHECK_EQ(28, offsetof(struct multiboot_info, syms.elf));
ATF_CHECK_EQ(28, offsetof(struct multiboot_info, syms.elf.num));
ATF_CHECK_EQ(32, offsetof(struct multiboot_info, syms.elf.size));
ATF_CHECK_EQ(36, offsetof(struct multiboot_info, syms.elf.addr));
ATF_CHECK_EQ(40, offsetof(struct multiboot_info, syms.elf.shndx));
ATF_CHECK_EQ(44, offsetof(struct multiboot_info, mmap_length));
ATF_CHECK_EQ(48, offsetof(struct multiboot_info, mmap_addr));
ATF_CHECK_EQ(52, offsetof(struct multiboot_info, drives_length));
ATF_CHECK_EQ(56, offsetof(struct multiboot_info, drives_addr));
ATF_CHECK_EQ(60, offsetof(struct multiboot_info, config_table));
ATF_CHECK_EQ(64, offsetof(struct multiboot_info, boot_loader_name));
ATF_CHECK_EQ(68, offsetof(struct multiboot_info, apm_table));
ATF_CHECK_EQ(72, offsetof(struct multiboot_info, vbe));
ATF_CHECK_EQ(72, offsetof(struct multiboot_info, vbe.control_info));
ATF_CHECK_EQ(76, offsetof(struct multiboot_info, vbe.mode_info));
ATF_CHECK_EQ(80, offsetof(struct multiboot_info, vbe.mode));
ATF_CHECK_EQ(82, offsetof(struct multiboot_info, vbe.interface_seg));
ATF_CHECK_EQ(84, offsetof(struct multiboot_info, vbe.interface_off));
ATF_CHECK_EQ(86, offsetof(struct multiboot_info, vbe.interface_len));
ATF_CHECK_EQ(88, offsetof(struct multiboot_info, framebuffer));
ATF_CHECK_EQ(88, offsetof(struct multiboot_info, framebuffer.addr));
ATF_CHECK_EQ(96, offsetof(struct multiboot_info, framebuffer.pitch));
ATF_CHECK_EQ(100, offsetof(struct multiboot_info, framebuffer.width));
ATF_CHECK_EQ(104, offsetof(struct multiboot_info, framebuffer.height));
ATF_CHECK_EQ(108, offsetof(struct multiboot_info, framebuffer.bpp));
ATF_CHECK_EQ(109, offsetof(struct multiboot_info, framebuffer.type));
ATF_CHECK_EQ(110, offsetof(struct multiboot_info, framebuffer.color_info));
ATF_CHECK_EQ(110, offsetof(struct multiboot_info,
framebuffer.color_info.palette.addr));
ATF_CHECK_EQ(114, offsetof(struct multiboot_info,
framebuffer.color_info.palette.num_colors));
ATF_CHECK_EQ(110, offsetof(struct multiboot_info,
framebuffer.color_info.rgb.red_field_position));
ATF_CHECK_EQ(111, offsetof(struct multiboot_info,
framebuffer.color_info.rgb.red_mask_size));
ATF_CHECK_EQ(112, offsetof(struct multiboot_info,
framebuffer.color_info.rgb.green_field_position));
ATF_CHECK_EQ(113, offsetof(struct multiboot_info,
framebuffer.color_info.rgb.green_mask_size));
ATF_CHECK_EQ(114, offsetof(struct multiboot_info,
framebuffer.color_info.rgb.blue_field_position));
ATF_CHECK_EQ(115, offsetof(struct multiboot_info,
framebuffer.color_info.rgb.blue_mask_size));

ATF_CHECK_EQ_MSG(116, sizeof(struct multiboot_info),
"struct multiboot_info should be %d bytes long, but it is "
"actually %d bytes long",
116, sizeof(struct multiboot_info));

}

ATF_TP_ADD_TCS(tp)
{
Expand All @@ -343,6 +413,7 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, load_aout);
ATF_TP_ADD_TC(tp, load_elf_direct);
ATF_TP_ADD_TC(tp, load_elf);
ATF_TP_ADD_TC(tp, sizeof_multiboot_info);

return atf_no_error();
}

0 comments on commit e952761

Please sign in to comment.