Skip to content

Commit de30786

Browse files
committed
multiboot: add multiboot information structure
1 parent 0069228 commit de30786

File tree

2 files changed

+151
-0
lines changed

2 files changed

+151
-0
lines changed

multiboot.h

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,24 @@
4040
#define MULTIBOOT_FLAG_MEMORY (1<<1)
4141
#define MULTIBOOT_FLAG_ALIGN4k (1<<0)
4242

43+
#define MULTIBOOT_FRAMEBUFFER (1<<12)
44+
#define MULTIBOOT_VBE (1<<11)
45+
#define MULTIBOOT_APM_TABLE (1<<10)
46+
#define MULTIBOOT_BOOTLOADER_NAME (1<<9)
47+
#define MULTIBOOT_CONFIG_TABLE (1<<8)
48+
#define MULTIBOOT_DRIVES (1<<7)
49+
#define MULTIBOOT_MMAP (1<<6)
50+
#define MULTIBOOT_SYMS_ELF (1<<5)
51+
#define MULTIBOOT_SYMS_AOUT (1<<4)
52+
#define MULTIBOOT_MODS (1<<3)
53+
#define MULTIBOOT_CMDLINE (1<<2)
54+
#define MULTIBOOT_BOOTDEVICE (1<<1)
55+
#define MULTIBOOT_MEMINFO (1<<0)
56+
57+
#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0
58+
#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1
59+
#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2
60+
4361
#define PACKED __attribute__((packed))
4462

4563
struct multiboot_header {
@@ -57,6 +75,67 @@ struct multiboot_header {
5775
uint32_t depth;
5876
} PACKED;
5977

78+
struct multiboot_info {
79+
uint32_t flags;
80+
uint32_t mem_lower;
81+
uint32_t mem_upper;
82+
uint32_t boot_device;
83+
uint32_t cmdline;
84+
uint32_t mods_count;
85+
uint32_t mods_addr;
86+
union {
87+
struct {
88+
uint32_t num;
89+
uint32_t size;
90+
uint32_t addr;
91+
uint32_t shndx;
92+
} PACKED elf;
93+
struct {
94+
uint32_t tabsize;
95+
uint32_t strsize;
96+
uint32_t addr;
97+
uint32_t reserved;
98+
} PACKED aout;
99+
} syms;
100+
uint32_t mmap_length;
101+
uint32_t mmap_addr;
102+
uint32_t drives_length;
103+
uint32_t drives_addr;
104+
uint32_t config_table;
105+
uint32_t boot_loader_name;
106+
uint32_t apm_table;
107+
struct {
108+
uint32_t control_info;
109+
uint32_t mode_info;
110+
uint16_t mode;
111+
uint16_t interface_seg;
112+
uint16_t interface_off;
113+
uint16_t interface_len;
114+
} PACKED vbe;
115+
struct {
116+
uint64_t addr;
117+
uint32_t pitch;
118+
uint32_t width;
119+
uint32_t height;
120+
uint8_t bpp;
121+
uint8_t type;
122+
union {
123+
struct {
124+
uint32_t addr;
125+
uint16_t num_colors;
126+
} PACKED palette;
127+
struct {
128+
uint8_t red_field_position;
129+
uint8_t red_mask_size;
130+
uint8_t green_field_position;
131+
uint8_t green_mask_size;
132+
uint8_t blue_field_position;
133+
uint8_t blue_mask_size;
134+
} PACKED rgb;
135+
} color_info;
136+
} PACKED framebuffer;
137+
} PACKED;
138+
60139
struct multiboot2_header {
61140
uint32_t magic;
62141
uint32_t architecture;
@@ -80,6 +159,7 @@ struct multiboot {
80159
struct multiboot2_header* header;
81160
} mb2;
82161
} header;
162+
struct multiboot_info info;
83163
};
84164

85165
/**

tests/test-multiboot.c

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,76 @@ ATF_TC_BODY(load_elf, tc)
333333
ATF_CHECK_EQ_MSG(0, error, "multiboot_load_elf failed");
334334
}
335335

336+
ATF_TC(sizeof_multiboot_info);
337+
ATF_TC_HEAD(sizeof_multiboot_info, tc)
338+
{
339+
atf_tc_set_md_var(tc, "descr", "Check multiboot info size");
340+
}
341+
ATF_TC_BODY(sizeof_multiboot_info, tc)
342+
{
343+
ATF_CHECK_EQ(0, offsetof(struct multiboot_info, flags));
344+
ATF_CHECK_EQ(4, offsetof(struct multiboot_info, mem_lower));
345+
ATF_CHECK_EQ(8, offsetof(struct multiboot_info, mem_upper));
346+
ATF_CHECK_EQ(12, offsetof(struct multiboot_info, boot_device));
347+
ATF_CHECK_EQ(16, offsetof(struct multiboot_info, cmdline));
348+
ATF_CHECK_EQ(20, offsetof(struct multiboot_info, mods_count));
349+
ATF_CHECK_EQ(24, offsetof(struct multiboot_info, mods_addr));
350+
ATF_CHECK_EQ(28, offsetof(struct multiboot_info, syms));
351+
ATF_CHECK_EQ(28, offsetof(struct multiboot_info, syms.aout));
352+
ATF_CHECK_EQ(28, offsetof(struct multiboot_info, syms.aout.tabsize));
353+
ATF_CHECK_EQ(32, offsetof(struct multiboot_info, syms.aout.strsize));
354+
ATF_CHECK_EQ(36, offsetof(struct multiboot_info, syms.aout.addr));
355+
ATF_CHECK_EQ(40, offsetof(struct multiboot_info, syms.aout.reserved));
356+
ATF_CHECK_EQ(28, offsetof(struct multiboot_info, syms.elf));
357+
ATF_CHECK_EQ(28, offsetof(struct multiboot_info, syms.elf.num));
358+
ATF_CHECK_EQ(32, offsetof(struct multiboot_info, syms.elf.size));
359+
ATF_CHECK_EQ(36, offsetof(struct multiboot_info, syms.elf.addr));
360+
ATF_CHECK_EQ(40, offsetof(struct multiboot_info, syms.elf.shndx));
361+
ATF_CHECK_EQ(44, offsetof(struct multiboot_info, mmap_length));
362+
ATF_CHECK_EQ(48, offsetof(struct multiboot_info, mmap_addr));
363+
ATF_CHECK_EQ(52, offsetof(struct multiboot_info, drives_length));
364+
ATF_CHECK_EQ(56, offsetof(struct multiboot_info, drives_addr));
365+
ATF_CHECK_EQ(60, offsetof(struct multiboot_info, config_table));
366+
ATF_CHECK_EQ(64, offsetof(struct multiboot_info, boot_loader_name));
367+
ATF_CHECK_EQ(68, offsetof(struct multiboot_info, apm_table));
368+
ATF_CHECK_EQ(72, offsetof(struct multiboot_info, vbe));
369+
ATF_CHECK_EQ(72, offsetof(struct multiboot_info, vbe.control_info));
370+
ATF_CHECK_EQ(76, offsetof(struct multiboot_info, vbe.mode_info));
371+
ATF_CHECK_EQ(80, offsetof(struct multiboot_info, vbe.mode));
372+
ATF_CHECK_EQ(82, offsetof(struct multiboot_info, vbe.interface_seg));
373+
ATF_CHECK_EQ(84, offsetof(struct multiboot_info, vbe.interface_off));
374+
ATF_CHECK_EQ(86, offsetof(struct multiboot_info, vbe.interface_len));
375+
ATF_CHECK_EQ(88, offsetof(struct multiboot_info, framebuffer));
376+
ATF_CHECK_EQ(88, offsetof(struct multiboot_info, framebuffer.addr));
377+
ATF_CHECK_EQ(96, offsetof(struct multiboot_info, framebuffer.pitch));
378+
ATF_CHECK_EQ(100, offsetof(struct multiboot_info, framebuffer.width));
379+
ATF_CHECK_EQ(104, offsetof(struct multiboot_info, framebuffer.height));
380+
ATF_CHECK_EQ(108, offsetof(struct multiboot_info, framebuffer.bpp));
381+
ATF_CHECK_EQ(109, offsetof(struct multiboot_info, framebuffer.type));
382+
ATF_CHECK_EQ(110, offsetof(struct multiboot_info, framebuffer.color_info));
383+
ATF_CHECK_EQ(110, offsetof(struct multiboot_info,
384+
framebuffer.color_info.palette.addr));
385+
ATF_CHECK_EQ(114, offsetof(struct multiboot_info,
386+
framebuffer.color_info.palette.num_colors));
387+
ATF_CHECK_EQ(110, offsetof(struct multiboot_info,
388+
framebuffer.color_info.rgb.red_field_position));
389+
ATF_CHECK_EQ(111, offsetof(struct multiboot_info,
390+
framebuffer.color_info.rgb.red_mask_size));
391+
ATF_CHECK_EQ(112, offsetof(struct multiboot_info,
392+
framebuffer.color_info.rgb.green_field_position));
393+
ATF_CHECK_EQ(113, offsetof(struct multiboot_info,
394+
framebuffer.color_info.rgb.green_mask_size));
395+
ATF_CHECK_EQ(114, offsetof(struct multiboot_info,
396+
framebuffer.color_info.rgb.blue_field_position));
397+
ATF_CHECK_EQ(115, offsetof(struct multiboot_info,
398+
framebuffer.color_info.rgb.blue_mask_size));
399+
400+
ATF_CHECK_EQ_MSG(116, sizeof(struct multiboot_info),
401+
"struct multiboot_info should be %d bytes long, but it is "
402+
"actually %d bytes long",
403+
116, sizeof(struct multiboot_info));
404+
405+
}
336406

337407
ATF_TP_ADD_TCS(tp)
338408
{
@@ -343,6 +413,7 @@ ATF_TP_ADD_TCS(tp)
343413
ATF_TP_ADD_TC(tp, load_aout);
344414
ATF_TP_ADD_TC(tp, load_elf_direct);
345415
ATF_TP_ADD_TC(tp, load_elf);
416+
ATF_TP_ADD_TC(tp, sizeof_multiboot_info);
346417

347418
return atf_no_error();
348419
}

0 commit comments

Comments
 (0)