diff --git a/include/kernaux/multiboot2.h b/include/kernaux/multiboot2.h index 929a636..ffee6f2 100644 --- a/include/kernaux/multiboot2.h +++ b/include/kernaux/multiboot2.h @@ -308,6 +308,12 @@ __attribute__((packed)); * Helper functions * ********************/ +const struct KernAux_Multiboot2_TagBase *KernAux_Multiboot2_first_tag_with_type( + const struct KernAux_Multiboot2 *multiboot2, + enum KernAux_Multiboot2_TagType tag_type +) +__attribute__((nonnull)); + const char *KernAux_Multiboot2_boot_cmd_line( const struct KernAux_Multiboot2 *multiboot2 ) diff --git a/src/multiboot2/helpers.c b/src/multiboot2/helpers.c index e02beae..49ea68c 100644 --- a/src/multiboot2/helpers.c +++ b/src/multiboot2/helpers.c @@ -1,7 +1,8 @@ #include -const char *KernAux_Multiboot2_boot_cmd_line( - const struct KernAux_Multiboot2 *const multiboot2 +const struct KernAux_Multiboot2_TagBase *KernAux_Multiboot2_first_tag_with_type( + const struct KernAux_Multiboot2 *const multiboot2, + const enum KernAux_Multiboot2_TagType tag_type ) { const struct KernAux_Multiboot2_TagBase *tag_base = (struct KernAux_Multiboot2_TagBase*)multiboot2->data; @@ -11,11 +12,8 @@ const char *KernAux_Multiboot2_boot_cmd_line( return 0; } - if (tag_base->type == KERNAUX_MULTIBOOT2_TAGTYPE_BOOT_CMD_LINE) { - const struct KernAux_Multiboot2_Tag_BootCmdLine *const tag = - (struct KernAux_Multiboot2_Tag_BootCmdLine*)tag_base; - - return tag->cmdline; + if (tag_base->type == tag_type) { + return tag_base; } tag_base = (struct KernAux_Multiboot2_TagBase*)( @@ -25,3 +23,20 @@ const char *KernAux_Multiboot2_boot_cmd_line( return 0; } + +const char *KernAux_Multiboot2_boot_cmd_line( + const struct KernAux_Multiboot2 *const multiboot2 +) { + const struct KernAux_Multiboot2_Tag_BootCmdLine *const tag = + (struct KernAux_Multiboot2_Tag_BootCmdLine*) + KernAux_Multiboot2_first_tag_with_type( + multiboot2, + KERNAUX_MULTIBOOT2_TAGTYPE_BOOT_CMD_LINE + ); + + if (!tag) { + return 0; + } + + return tag->cmdline; +} diff --git a/tests/multiboot2_example1.h b/tests/multiboot2_example1.h new file mode 100644 index 0000000..7582b11 --- /dev/null +++ b/tests/multiboot2_example1.h @@ -0,0 +1,56 @@ +static const unsigned char multiboot2_example1[864] = { + 96, 3, 0, 0, 0, 0, 0, 0, 21, 0, 0, 0, 12, 0, 0, 0, + 0, 0, 64, 0, 0, 0, 232, 133, 1, 0, 0, 0, 21, 0, 0, 0, + 104, 101, 108, 108, 111, 32, 107, 101, 114, 110, 101, 108, 0, 139, 69, 228, + 2, 0, 0, 0, 30, 0, 0, 0, 71, 82, 85, 66, 32, 50, 46, 48, + 50, 45, 50, 117, 98, 117, 110, 116, 117, 56, 46, 50, 48, 0, 0, 0, + 10, 0, 0, 0, 28, 0, 0, 0, 2, 1, 0, 240, 207, 212, 0, 0, + 0, 240, 0, 240, 3, 0, 240, 255, 240, 255, 240, 255, 1, 0, 0, 0, + 3, 0, 0, 0, 29, 0, 0, 0, 0, 32, 16, 0, 156, 50, 16, 0, + 104, 101, 108, 108, 111, 32, 109, 111, 100, 117, 108, 101, 0, 131, 255, 16, + 3, 0, 0, 0, 17, 0, 0, 0, 0, 64, 16, 0, 84, 82, 16, 0, + 0, 232, 99, 9, 0, 0, 235, 53, 6, 0, 0, 0, 160, 0, 0, 0, + 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 252, 9, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, + 0, 252, 9, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, + 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 238, 7, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 254, 7, 0, 0, 0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 0, 0, 0, + 1, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, + 20, 0, 16, 0, 20, 112, 0, 0, 176, 12, 0, 0, 8, 0, 0, 0, + 72, 0, 0, 0, 4, 0, 0, 0, 16, 0, 0, 0, 9, 0, 0, 0, + 3, 0, 0, 0, 0, 0, 0, 0, 196, 12, 16, 0, 196, 124, 0, 0, + 208, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 17, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, + 148, 26, 16, 0, 148, 138, 0, 0, 71, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 217, 255, 255, 137, + 4, 0, 0, 0, 16, 0, 0, 0, 127, 2, 0, 0, 128, 251, 1, 0, + 5, 0, 0, 0, 20, 0, 0, 0, 224, 0, 0, 0, 255, 255, 255, 255, + 255, 255, 255, 255, 208, 137, 69, 212, 8, 0, 0, 0, 32, 0, 0, 0, + 0, 128, 11, 0, 0, 0, 0, 0, 160, 0, 0, 0, 80, 0, 0, 0, + 25, 0, 0, 0, 16, 2, 0, 0, 14, 0, 0, 0, 28, 0, 0, 0, + 82, 83, 68, 32, 80, 84, 82, 32, 60, 66, 79, 67, 72, 83, 32, 0, + 252, 21, 254, 7, 236, 0, 0, 235, 0, 0, 0, 0, 8, 0, 0, 0, +}; diff --git a/tests/multiboot2_example2.h b/tests/multiboot2_example2.h new file mode 100644 index 0000000..452d0df --- /dev/null +++ b/tests/multiboot2_example2.h @@ -0,0 +1,378 @@ +static const struct { + struct KernAux_Multiboot2 multiboot2; + + struct { + struct KernAux_Multiboot2_Tag_BootCmdLine tag; + char cmdline[15]; + } tag_boot_cmd_line; + + unsigned char _align1[1]; + + struct { + struct KernAux_Multiboot2_Tag_BootLoaderName tag; + char name[22]; + } tag_boot_loader_name; + + unsigned char _align2[2]; + + struct { + struct KernAux_Multiboot2_Tag_Module tag; + char cmdline[17]; + } tag_module1; + + unsigned char _align3[7]; + + struct { + struct KernAux_Multiboot2_Tag_Module tag; + char cmdline[17]; + } tag_module2; + + unsigned char _align4[7]; + + struct KernAux_Multiboot2_Tag_BasicMemoryInfo tag_basic_memory_info; + + struct KernAux_Multiboot2_Tag_BIOSBootDevice tag_bios_boot_device; + + unsigned char _align5[4]; + + struct { + struct KernAux_Multiboot2_Tag_MemoryMap tag; + + unsigned char + data[160 - sizeof(struct KernAux_Multiboot2_Tag_MemoryMap)]; + } tag_memory_map; + + struct KernAux_Multiboot2_Tag_VBEInfo tag_vbe_info; + + struct { + struct KernAux_Multiboot2_Tag_FramebufferInfo tag; + unsigned char data[8]; + } tag_framebuffer_info; + + unsigned char _align6[1]; + + struct { + struct KernAux_Multiboot2_Tag_ELFSymbols tag; + + unsigned char + data[420 - sizeof(struct KernAux_Multiboot2_Tag_ELFSymbols)]; + } tag_elf_symbols; + + unsigned char _align7[4]; + + struct KernAux_Multiboot2_Tag_APMTable tag_apm_table; + + unsigned char _align8[4]; + + struct KernAux_Multiboot2_Tag_EFI32bitSystemTablePtr tag_efi_32bit_system_table_ptr; + + unsigned char _align9[4]; + + struct KernAux_Multiboot2_Tag_EFI64bitSystemTablePtr tag_efi_64bit_system_table_ptr; + + struct { + struct KernAux_Multiboot2_Tag_SMBIOSTables tag; + unsigned char data[8]; + } tag_smbios_tables; + + struct { + struct KernAux_Multiboot2_Tag_ACPIOldRSDP tag; + unsigned char data[8]; + } tag_acpi_old_rsdp; + + struct { + struct KernAux_Multiboot2_Tag_ACPINewRSDP tag; + unsigned char data[8]; + } tag_acpi_new_rsdp; + + struct { + struct KernAux_Multiboot2_Tag_NetworkingInfo tag; + unsigned char data[8]; + } tag_networking_info; + + struct { + struct KernAux_Multiboot2_Tag_EFIMemoryMap tag; + unsigned char data[8]; + } tag_efi_memory_map; + + struct KernAux_Multiboot2_Tag_EFIBootServicesNotTerminated + tag_efi_boot_services_not_terminated; + + struct KernAux_Multiboot2_Tag_EFI32bitImageHandlePtr + tag_efi_32bit_image_handle_ptr; + + unsigned char _align10[4]; + + struct KernAux_Multiboot2_Tag_EFI64bitImageHandlePtr + tag_efi_64bit_image_handle_ptr; + + struct KernAux_Multiboot2_Tag_ImageLoadBasePhysAddr + tag_image_load_base_phys_addr; + + unsigned char _align11[4]; + + struct KernAux_Multiboot2_Tag_None tag_none; +} multiboot2_example2 = { + .multiboot2 = { + .total_size = sizeof(multiboot2_example2), + .reserved1 = 0, + }, + .tag_boot_cmd_line = { + .tag = { + .base = { + .type = KERNAUX_MULTIBOOT2_TAGTYPE_BOOT_CMD_LINE, + .size = sizeof(multiboot2_example2.tag_boot_cmd_line), + }, + }, + .cmdline = "Hello, Kernel!\0", + }, + .tag_boot_loader_name = { + .tag = { + .base = { + .type = KERNAUX_MULTIBOOT2_TAGTYPE_BOOT_LOADER_NAME, + .size = sizeof(multiboot2_example2.tag_boot_loader_name), + }, + }, + .name = "GRUB 2.02-2ubuntu8.20\0", + }, + .tag_module1 = { + .tag = { + .base = { + .type = KERNAUX_MULTIBOOT2_TAGTYPE_MODULE, + .size = sizeof(multiboot2_example2.tag_module1), + }, + .mod_start = 123, + .mod_end = 456, + }, + .cmdline = "Hello, Module 1!\0", + }, + .tag_module2 = { + .tag = { + .base = { + .type = KERNAUX_MULTIBOOT2_TAGTYPE_MODULE, + .size = sizeof(multiboot2_example2.tag_module2), + }, + .mod_start = 123, + .mod_end = 456, + }, + .cmdline = "Hello, Module 2!\0", + }, + .tag_basic_memory_info = { + .base = { + .type = KERNAUX_MULTIBOOT2_TAGTYPE_BASIC_MEMORY_INFO, + .size = sizeof(multiboot2_example2.tag_basic_memory_info), + }, + .mem_lower = 123, + .mem_upper = 456, + }, + .tag_bios_boot_device = { + .base = { + .type = KERNAUX_MULTIBOOT2_TAGTYPE_BIOS_BOOT_DEVICE, + .size = sizeof(multiboot2_example2.tag_bios_boot_device), + }, + .bios_dev = 0, + .partition = 1, + .sub_partition = 2, + }, + .tag_memory_map = { + .tag = { + .base = { + .type = KERNAUX_MULTIBOOT2_TAGTYPE_MEMORY_MAP, + .size = sizeof(multiboot2_example2.tag_memory_map), + }, + .entry_size = 24, + .entry_version = 0, + }, + .data = { + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 252, 9, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, + 0, 252, 9, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, + 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 238, 7, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 254, 7, 0, 0, 0, 0, + 0, 0, 2, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 252, 255, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, + 2, 0, 0, 0, 0, 0, 0, 0, + }, + }, + .tag_vbe_info = { + .base = { + .type = KERNAUX_MULTIBOOT2_TAGTYPE_VBE_INFO, + .size = sizeof(multiboot2_example2.tag_vbe_info), + }, + .vbe_mode = 0, + .vbe_interface_seg = 123, + .vbe_interface_off = 456, + .vbe_interface_len = 789, + }, + .tag_framebuffer_info = { + .tag = { + .base = { + .type = KERNAUX_MULTIBOOT2_TAGTYPE_FRAMEBUFFER_INFO, + .size = sizeof(multiboot2_example2.tag_framebuffer_info), + }, + .framebuffer_addr = 123, + .framebuffer_pitch = 456, + .framebuffer_width = 123, + .framebuffer_height = 456, + .framebuffer_bpp = 8, + .framebuffer_type = 1, + }, + .data = {0, 1, 2, 3, 4, 5, 6, 7}, + }, + .tag_elf_symbols = { + .tag = { + .base = { + .type = KERNAUX_MULTIBOOT2_TAGTYPE_ELF_SYMBOLS, + .size = sizeof(multiboot2_example2.tag_elf_symbols), + }, + .num = 10, + .ent_size = 0, + .shndx = 40, + .reserved1 = 0, + }, + .data = { + 9, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 27, 0, 0, 0, 1, 0, 0, 0, 6, 0, 0, 0, + 0, 0, 64, 0, 0, 16, 0, 0, 150, 53, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 33, 0, 0, 0, + 1, 0, 0, 0, 2, 0, 0, 0, 0, 64, 64, 0, 0, 80, 0, 0, + 8, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, + 0, 0, 0, 0, 41, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, + 8, 75, 64, 0, 8, 91, 0, 0, 132, 10, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 51, 0, 0, 0, + 1, 0, 0, 0, 3, 0, 0, 0, 0, 96, 64, 0, 0, 112, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, + 0, 0, 0, 0, 57, 0, 0, 0, 8, 0, 0, 0, 3, 0, 0, 0, + 0, 112, 64, 0, 1, 112, 0, 0, 64, 169, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, + 1, 0, 0, 0, 48, 0, 0, 0, 0, 0, 16, 0, 1, 112, 0, 0, + 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, + 20, 0, 16, 0, 20, 112, 0, 0, 176, 12, 0, 0, 8, 0, 0, 0, + 72, 0, 0, 0, 4, 0, 0, 0, 16, 0, 0, 0, 9, 0, 0, 0, + 3, 0, 0, 0, 0, 0, 0, 0, 196, 12, 16, 0, 196, 124, 0, 0, + 208, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 17, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, + 148, 26, 16, 0, 148, 138, 0, 0, 71, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, + }, + }, + .tag_apm_table = { + .base = { + .type = KERNAUX_MULTIBOOT2_TAGTYPE_APM_TABLE, + .size = sizeof(multiboot2_example2.tag_apm_table), + }, + .version = 0, + .cseg = 123, + .offset = 456, + .cseg_16 = 789, + .dseg = 123, + .flags = 1, + .cseg_len = 456, + .cseg_16_len = 789, + .dseg_len = 123, + }, + .tag_efi_32bit_system_table_ptr = { + .base = { + .type = KERNAUX_MULTIBOOT2_TAGTYPE_EFI_32BIT_SYSTEM_TABLE_PTR, + .size = sizeof(multiboot2_example2.tag_efi_32bit_system_table_ptr), + }, + .pointer = 0, + }, + .tag_efi_64bit_system_table_ptr = { + .base = { + .type = KERNAUX_MULTIBOOT2_TAGTYPE_EFI_64BIT_SYSTEM_TABLE_PTR, + .size = sizeof(multiboot2_example2.tag_efi_64bit_system_table_ptr), + }, + .pointer = 0, + }, + .tag_smbios_tables = { + .tag = { + .base = { + .type = KERNAUX_MULTIBOOT2_TAGTYPE_SMBIOS_TABLES, + .size = sizeof(multiboot2_example2.tag_smbios_tables), + }, + .major = 1, + .minor = 2, + .reserved1 = {0, 0, 0, 0, 0, 0}, + }, + .data = {0, 0, 0, 0, 0, 0, 0, 0}, + }, + .tag_acpi_old_rsdp = { + .tag = { + .base = { + .type = KERNAUX_MULTIBOOT2_TAGTYPE_ACPI_OLD_RSDP, + .size = sizeof(multiboot2_example2.tag_acpi_old_rsdp), + }, + }, + .data = {0, 0, 0, 0, 0, 0, 0, 0}, + }, + .tag_acpi_new_rsdp = { + .tag = { + .base = { + .type = KERNAUX_MULTIBOOT2_TAGTYPE_ACPI_NEW_RSDP, + .size = sizeof(multiboot2_example2.tag_acpi_new_rsdp), + }, + }, + .data = {0, 0, 0, 0, 0, 0, 0, 0}, + }, + .tag_networking_info = { + .tag = { + .base = { + .type = KERNAUX_MULTIBOOT2_TAGTYPE_NETWORKING_INFO, + .size = sizeof(multiboot2_example2.tag_networking_info), + }, + }, + .data = {0, 0, 0, 0, 0, 0, 0, 0}, + }, + .tag_efi_memory_map = { + .tag = { + .base = { + .type = KERNAUX_MULTIBOOT2_TAGTYPE_EFI_MEMORY_MAP, + .size = sizeof(multiboot2_example2.tag_efi_memory_map), + }, + .descriptor_size = 123, + .descriptor_version = 1, + }, + .data = {0, 0, 0, 0, 0, 0, 0, 0}, + }, + .tag_efi_boot_services_not_terminated = { + .base = { + .type = KERNAUX_MULTIBOOT2_TAGTYPE_EFI_BOOT_SERVICES_NOT_TERMINATED, + .size = sizeof( + multiboot2_example2.tag_efi_boot_services_not_terminated + ), + }, + }, + .tag_efi_32bit_image_handle_ptr = { + .base = { + .type = KERNAUX_MULTIBOOT2_TAGTYPE_EFI_32BIT_IMAGE_HANDLE_PTR, + .size = sizeof(multiboot2_example2.tag_efi_32bit_image_handle_ptr), + }, + .pointer = 0, + }, + .tag_efi_64bit_image_handle_ptr = { + .base = { + .type = KERNAUX_MULTIBOOT2_TAGTYPE_EFI_64BIT_IMAGE_HANDLE_PTR, + .size = sizeof(multiboot2_example2.tag_efi_64bit_image_handle_ptr), + }, + .pointer = 0, + }, + .tag_image_load_base_phys_addr = { + .base = { + .type = KERNAUX_MULTIBOOT2_TAGTYPE_IMAGE_LOAD_BASE_PHYS_ADDR, + .size = sizeof(multiboot2_example2.tag_image_load_base_phys_addr), + }, + .load_base_addr = 123, + }, + .tag_none = { + .base = { + .type = KERNAUX_MULTIBOOT2_TAGTYPE_NONE, + .size = sizeof(multiboot2_example2.tag_none), + }, + }, +}; diff --git a/tests/multiboot2_print1.c b/tests/multiboot2_print1.c index 5f2e2bf..a9399be 100644 --- a/tests/multiboot2_print1.c +++ b/tests/multiboot2_print1.c @@ -3,71 +3,16 @@ #include #include -static const unsigned char multiboot2_example[864] = { - 96, 3, 0, 0, 0, 0, 0, 0, 21, 0, 0, 0, 12, 0, 0, 0, - 0, 0, 64, 0, 0, 0, 232, 133, 1, 0, 0, 0, 21, 0, 0, 0, - 104, 101, 108, 108, 111, 32, 107, 101, 114, 110, 101, 108, 0, 139, 69, 228, - 2, 0, 0, 0, 30, 0, 0, 0, 71, 82, 85, 66, 32, 50, 46, 48, - 50, 45, 50, 117, 98, 117, 110, 116, 117, 56, 46, 50, 48, 0, 0, 0, - 10, 0, 0, 0, 28, 0, 0, 0, 2, 1, 0, 240, 207, 212, 0, 0, - 0, 240, 0, 240, 3, 0, 240, 255, 240, 255, 240, 255, 1, 0, 0, 0, - 3, 0, 0, 0, 29, 0, 0, 0, 0, 32, 16, 0, 156, 50, 16, 0, - 104, 101, 108, 108, 111, 32, 109, 111, 100, 117, 108, 101, 0, 131, 255, 16, - 3, 0, 0, 0, 17, 0, 0, 0, 0, 64, 16, 0, 84, 82, 16, 0, - 0, 232, 99, 9, 0, 0, 235, 53, 6, 0, 0, 0, 160, 0, 0, 0, - 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 252, 9, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, - 0, 252, 9, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, - 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, - 0, 0, 1, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 238, 7, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 254, 7, 0, 0, 0, 0, - 0, 0, 2, 0, 0, 0, 0, 0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 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, - 20, 0, 16, 0, 20, 112, 0, 0, 176, 12, 0, 0, 8, 0, 0, 0, - 72, 0, 0, 0, 4, 0, 0, 0, 16, 0, 0, 0, 9, 0, 0, 0, - 3, 0, 0, 0, 0, 0, 0, 0, 196, 12, 16, 0, 196, 124, 0, 0, - 208, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, - 0, 0, 0, 0, 17, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, - 148, 26, 16, 0, 148, 138, 0, 0, 71, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 217, 255, 255, 137, - 4, 0, 0, 0, 16, 0, 0, 0, 127, 2, 0, 0, 128, 251, 1, 0, - 5, 0, 0, 0, 20, 0, 0, 0, 224, 0, 0, 0, 255, 255, 255, 255, - 255, 255, 255, 255, 208, 137, 69, 212, 8, 0, 0, 0, 32, 0, 0, 0, - 0, 128, 11, 0, 0, 0, 0, 0, 160, 0, 0, 0, 80, 0, 0, 0, - 25, 0, 0, 0, 16, 2, 0, 0, 14, 0, 0, 0, 28, 0, 0, 0, - 82, 83, 68, 32, 80, 84, 82, 32, 60, 66, 79, 67, 72, 83, 32, 0, - 252, 21, 254, 7, 236, 0, 0, 235, 0, 0, 0, 0, 8, 0, 0, 0, -}; +#include "multiboot2_example1.h" int main() { assert(KernAux_Multiboot2_is_valid( - (struct KernAux_Multiboot2*)multiboot2_example + (struct KernAux_Multiboot2*)multiboot2_example1 )); KernAux_Multiboot2_print( - (struct KernAux_Multiboot2*)multiboot2_example, + (struct KernAux_Multiboot2*)multiboot2_example1, (void (*)(const char *format, ...))printf ); diff --git a/tests/multiboot2_print2.c b/tests/multiboot2_print2.c index 5be9290..5110a8f 100644 --- a/tests/multiboot2_print2.c +++ b/tests/multiboot2_print2.c @@ -3,390 +3,14 @@ #include #include -static const struct { - struct KernAux_Multiboot2 multiboot2; - - struct { - struct KernAux_Multiboot2_Tag_BootCmdLine tag; - char cmdline[15]; - } tag_boot_cmd_line; - - unsigned char _align1[1]; - - struct { - struct KernAux_Multiboot2_Tag_BootLoaderName tag; - char name[22]; - } tag_boot_loader_name; - - unsigned char _align2[2]; - - struct { - struct KernAux_Multiboot2_Tag_Module tag; - char cmdline[17]; - } tag_module1; - - unsigned char _align3[7]; - - struct { - struct KernAux_Multiboot2_Tag_Module tag; - char cmdline[17]; - } tag_module2; - - unsigned char _align4[7]; - - struct KernAux_Multiboot2_Tag_BasicMemoryInfo tag_basic_memory_info; - - struct KernAux_Multiboot2_Tag_BIOSBootDevice tag_bios_boot_device; - - unsigned char _align5[4]; - - struct { - struct KernAux_Multiboot2_Tag_MemoryMap tag; - - unsigned char - data[160 - sizeof(struct KernAux_Multiboot2_Tag_MemoryMap)]; - } tag_memory_map; - - struct KernAux_Multiboot2_Tag_VBEInfo tag_vbe_info; - - struct { - struct KernAux_Multiboot2_Tag_FramebufferInfo tag; - unsigned char data[8]; - } tag_framebuffer_info; - - unsigned char _align6[1]; - - struct { - struct KernAux_Multiboot2_Tag_ELFSymbols tag; - - unsigned char - data[420 - sizeof(struct KernAux_Multiboot2_Tag_ELFSymbols)]; - } tag_elf_symbols; - - unsigned char _align7[4]; - - struct KernAux_Multiboot2_Tag_APMTable tag_apm_table; - - unsigned char _align8[4]; - - struct KernAux_Multiboot2_Tag_EFI32bitSystemTablePtr tag_efi_32bit_system_table_ptr; - - unsigned char _align9[4]; - - struct KernAux_Multiboot2_Tag_EFI64bitSystemTablePtr tag_efi_64bit_system_table_ptr; - - struct { - struct KernAux_Multiboot2_Tag_SMBIOSTables tag; - unsigned char data[8]; - } tag_smbios_tables; - - struct { - struct KernAux_Multiboot2_Tag_ACPIOldRSDP tag; - unsigned char data[8]; - } tag_acpi_old_rsdp; - - struct { - struct KernAux_Multiboot2_Tag_ACPINewRSDP tag; - unsigned char data[8]; - } tag_acpi_new_rsdp; - - struct { - struct KernAux_Multiboot2_Tag_NetworkingInfo tag; - unsigned char data[8]; - } tag_networking_info; - - struct { - struct KernAux_Multiboot2_Tag_EFIMemoryMap tag; - unsigned char data[8]; - } tag_efi_memory_map; - - struct KernAux_Multiboot2_Tag_EFIBootServicesNotTerminated - tag_efi_boot_services_not_terminated; - - struct KernAux_Multiboot2_Tag_EFI32bitImageHandlePtr - tag_efi_32bit_image_handle_ptr; - - unsigned char _align10[4]; - - struct KernAux_Multiboot2_Tag_EFI64bitImageHandlePtr - tag_efi_64bit_image_handle_ptr; - - struct KernAux_Multiboot2_Tag_ImageLoadBasePhysAddr - tag_image_load_base_phys_addr; - - unsigned char _align11[4]; - - struct KernAux_Multiboot2_Tag_None tag_none; -} multiboot2_example = { - .multiboot2 = { - .total_size = sizeof(multiboot2_example), - .reserved1 = 0, - }, - .tag_boot_cmd_line = { - .tag = { - .base = { - .type = KERNAUX_MULTIBOOT2_TAGTYPE_BOOT_CMD_LINE, - .size = sizeof(multiboot2_example.tag_boot_cmd_line), - }, - }, - .cmdline = "Hello, Kernel!\0", - }, - .tag_boot_loader_name = { - .tag = { - .base = { - .type = KERNAUX_MULTIBOOT2_TAGTYPE_BOOT_LOADER_NAME, - .size = sizeof(multiboot2_example.tag_boot_loader_name), - }, - }, - .name = "GRUB 2.02-2ubuntu8.20\0", - }, - .tag_module1 = { - .tag = { - .base = { - .type = KERNAUX_MULTIBOOT2_TAGTYPE_MODULE, - .size = sizeof(multiboot2_example.tag_module1), - }, - .mod_start = 123, - .mod_end = 456, - }, - .cmdline = "Hello, Module 1!\0", - }, - .tag_module2 = { - .tag = { - .base = { - .type = KERNAUX_MULTIBOOT2_TAGTYPE_MODULE, - .size = sizeof(multiboot2_example.tag_module2), - }, - .mod_start = 123, - .mod_end = 456, - }, - .cmdline = "Hello, Module 2!\0", - }, - .tag_basic_memory_info = { - .base = { - .type = KERNAUX_MULTIBOOT2_TAGTYPE_BASIC_MEMORY_INFO, - .size = sizeof(multiboot2_example.tag_basic_memory_info), - }, - .mem_lower = 123, - .mem_upper = 456, - }, - .tag_bios_boot_device = { - .base = { - .type = KERNAUX_MULTIBOOT2_TAGTYPE_BIOS_BOOT_DEVICE, - .size = sizeof(multiboot2_example.tag_bios_boot_device), - }, - .bios_dev = 0, - .partition = 1, - .sub_partition = 2, - }, - .tag_memory_map = { - .tag = { - .base = { - .type = KERNAUX_MULTIBOOT2_TAGTYPE_MEMORY_MAP, - .size = sizeof(multiboot2_example.tag_memory_map), - }, - .entry_size = 24, - .entry_version = 0, - }, - .data = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 252, 9, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, - 0, 252, 9, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, - 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, - 0, 0, 1, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 238, 7, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 254, 7, 0, 0, 0, 0, - 0, 0, 2, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 252, 255, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, - 2, 0, 0, 0, 0, 0, 0, 0, - }, - }, - .tag_vbe_info = { - .base = { - .type = KERNAUX_MULTIBOOT2_TAGTYPE_VBE_INFO, - .size = sizeof(multiboot2_example.tag_vbe_info), - }, - .vbe_mode = 0, - .vbe_interface_seg = 123, - .vbe_interface_off = 456, - .vbe_interface_len = 789, - }, - .tag_framebuffer_info = { - .tag = { - .base = { - .type = KERNAUX_MULTIBOOT2_TAGTYPE_FRAMEBUFFER_INFO, - .size = sizeof(multiboot2_example.tag_framebuffer_info), - }, - .framebuffer_addr = 123, - .framebuffer_pitch = 456, - .framebuffer_width = 123, - .framebuffer_height = 456, - .framebuffer_bpp = 8, - .framebuffer_type = 1, - }, - .data = {0, 1, 2, 3, 4, 5, 6, 7}, - }, - .tag_elf_symbols = { - .tag = { - .base = { - .type = KERNAUX_MULTIBOOT2_TAGTYPE_ELF_SYMBOLS, - .size = sizeof(multiboot2_example.tag_elf_symbols), - }, - .num = 10, - .ent_size = 0, - .shndx = 40, - .reserved1 = 0, - }, - .data = { - 9, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 27, 0, 0, 0, 1, 0, 0, 0, 6, 0, 0, 0, - 0, 0, 64, 0, 0, 16, 0, 0, 150, 53, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 33, 0, 0, 0, - 1, 0, 0, 0, 2, 0, 0, 0, 0, 64, 64, 0, 0, 80, 0, 0, - 8, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, - 0, 0, 0, 0, 41, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, - 8, 75, 64, 0, 8, 91, 0, 0, 132, 10, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 51, 0, 0, 0, - 1, 0, 0, 0, 3, 0, 0, 0, 0, 96, 64, 0, 0, 112, 0, 0, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, - 0, 0, 0, 0, 57, 0, 0, 0, 8, 0, 0, 0, 3, 0, 0, 0, - 0, 112, 64, 0, 1, 112, 0, 0, 64, 169, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, - 1, 0, 0, 0, 48, 0, 0, 0, 0, 0, 16, 0, 1, 112, 0, 0, - 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, - 1, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, - 20, 0, 16, 0, 20, 112, 0, 0, 176, 12, 0, 0, 8, 0, 0, 0, - 72, 0, 0, 0, 4, 0, 0, 0, 16, 0, 0, 0, 9, 0, 0, 0, - 3, 0, 0, 0, 0, 0, 0, 0, 196, 12, 16, 0, 196, 124, 0, 0, - 208, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, - 0, 0, 0, 0, 17, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, - 148, 26, 16, 0, 148, 138, 0, 0, 71, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, - }, - }, - .tag_apm_table = { - .base = { - .type = KERNAUX_MULTIBOOT2_TAGTYPE_APM_TABLE, - .size = sizeof(multiboot2_example.tag_apm_table), - }, - .version = 0, - .cseg = 123, - .offset = 456, - .cseg_16 = 789, - .dseg = 123, - .flags = 1, - .cseg_len = 456, - .cseg_16_len = 789, - .dseg_len = 123, - }, - .tag_efi_32bit_system_table_ptr = { - .base = { - .type = KERNAUX_MULTIBOOT2_TAGTYPE_EFI_32BIT_SYSTEM_TABLE_PTR, - .size = sizeof(multiboot2_example.tag_efi_32bit_system_table_ptr), - }, - .pointer = 0, - }, - .tag_efi_64bit_system_table_ptr = { - .base = { - .type = KERNAUX_MULTIBOOT2_TAGTYPE_EFI_64BIT_SYSTEM_TABLE_PTR, - .size = sizeof(multiboot2_example.tag_efi_64bit_system_table_ptr), - }, - .pointer = 0, - }, - .tag_smbios_tables = { - .tag = { - .base = { - .type = KERNAUX_MULTIBOOT2_TAGTYPE_SMBIOS_TABLES, - .size = sizeof(multiboot2_example.tag_smbios_tables), - }, - .major = 1, - .minor = 2, - .reserved1 = {0, 0, 0, 0, 0, 0}, - }, - .data = {0, 0, 0, 0, 0, 0, 0, 0}, - }, - .tag_acpi_old_rsdp = { - .tag = { - .base = { - .type = KERNAUX_MULTIBOOT2_TAGTYPE_ACPI_OLD_RSDP, - .size = sizeof(multiboot2_example.tag_acpi_old_rsdp), - }, - }, - .data = {0, 0, 0, 0, 0, 0, 0, 0}, - }, - .tag_acpi_new_rsdp = { - .tag = { - .base = { - .type = KERNAUX_MULTIBOOT2_TAGTYPE_ACPI_NEW_RSDP, - .size = sizeof(multiboot2_example.tag_acpi_new_rsdp), - }, - }, - .data = {0, 0, 0, 0, 0, 0, 0, 0}, - }, - .tag_networking_info = { - .tag = { - .base = { - .type = KERNAUX_MULTIBOOT2_TAGTYPE_NETWORKING_INFO, - .size = sizeof(multiboot2_example.tag_networking_info), - }, - }, - .data = {0, 0, 0, 0, 0, 0, 0, 0}, - }, - .tag_efi_memory_map = { - .tag = { - .base = { - .type = KERNAUX_MULTIBOOT2_TAGTYPE_EFI_MEMORY_MAP, - .size = sizeof(multiboot2_example.tag_efi_memory_map), - }, - .descriptor_size = 123, - .descriptor_version = 1, - }, - .data = {0, 0, 0, 0, 0, 0, 0, 0}, - }, - .tag_efi_boot_services_not_terminated = { - .base = { - .type = KERNAUX_MULTIBOOT2_TAGTYPE_EFI_BOOT_SERVICES_NOT_TERMINATED, - .size = - sizeof(multiboot2_example.tag_efi_boot_services_not_terminated), - }, - }, - .tag_efi_32bit_image_handle_ptr = { - .base = { - .type = KERNAUX_MULTIBOOT2_TAGTYPE_EFI_32BIT_IMAGE_HANDLE_PTR, - .size = sizeof(multiboot2_example.tag_efi_32bit_image_handle_ptr), - }, - .pointer = 0, - }, - .tag_efi_64bit_image_handle_ptr = { - .base = { - .type = KERNAUX_MULTIBOOT2_TAGTYPE_EFI_64BIT_IMAGE_HANDLE_PTR, - .size = sizeof(multiboot2_example.tag_efi_64bit_image_handle_ptr), - }, - .pointer = 0, - }, - .tag_image_load_base_phys_addr = { - .base = { - .type = KERNAUX_MULTIBOOT2_TAGTYPE_IMAGE_LOAD_BASE_PHYS_ADDR, - .size = sizeof(multiboot2_example.tag_image_load_base_phys_addr), - }, - .load_base_addr = 123, - }, - .tag_none = { - .base = { - .type = KERNAUX_MULTIBOOT2_TAGTYPE_NONE, - .size = sizeof(multiboot2_example.tag_none), - }, - }, -}; +#include "multiboot2_example2.h" int main() { - assert(KernAux_Multiboot2_is_valid(&multiboot2_example.multiboot2)); + assert(KernAux_Multiboot2_is_valid(&multiboot2_example2.multiboot2)); KernAux_Multiboot2_print( - &multiboot2_example.multiboot2, + &multiboot2_example2.multiboot2, (void (*)(const char *format, ...))printf ); diff --git a/tests/test_multiboot2_helpers.c b/tests/test_multiboot2_helpers.c index af193fd..a4c480b 100644 --- a/tests/test_multiboot2_helpers.c +++ b/tests/test_multiboot2_helpers.c @@ -2,6 +2,9 @@ #include +#include "multiboot2_example1.h" +#include "multiboot2_example2.h" + static const struct { struct KernAux_Multiboot2 multiboot2; struct KernAux_Multiboot2_Tag_None tag_none; @@ -108,6 +111,14 @@ static const struct { int main() { + assert(KernAux_Multiboot2_is_valid( + (struct KernAux_Multiboot2*)multiboot2_example1 + )); + + assert(KernAux_Multiboot2_is_valid( + &multiboot2_example2.multiboot2 + )); + assert(KernAux_Multiboot2_is_valid( &multiboot2_without_boot_cmd_line.multiboot2 )); @@ -126,6 +137,206 @@ int main() ) == 0 ); + // KernAux_Multiboot2_first_tag_with_type + + assert( + KernAux_Multiboot2_first_tag_with_type( + (struct KernAux_Multiboot2*)multiboot2_example1, + KERNAUX_MULTIBOOT2_TAGTYPE_EFI_32BIT_SYSTEM_TABLE_PTR + ) == 0 + ); + + assert( + KernAux_Multiboot2_first_tag_with_type( + (struct KernAux_Multiboot2*)multiboot2_example1, + KERNAUX_MULTIBOOT2_TAGTYPE_EFI_64BIT_SYSTEM_TABLE_PTR + ) == 0 + ); + + assert( + KernAux_Multiboot2_first_tag_with_type( + (struct KernAux_Multiboot2*)multiboot2_example1, + KERNAUX_MULTIBOOT2_TAGTYPE_SMBIOS_TABLES + ) == 0 + ); + + assert( + KernAux_Multiboot2_first_tag_with_type( + (struct KernAux_Multiboot2*)multiboot2_example1, + KERNAUX_MULTIBOOT2_TAGTYPE_ACPI_NEW_RSDP + ) == 0 + ); + + assert( + KernAux_Multiboot2_first_tag_with_type( + (struct KernAux_Multiboot2*)multiboot2_example1, + KERNAUX_MULTIBOOT2_TAGTYPE_NETWORKING_INFO + ) == 0 + ); + + assert( + KernAux_Multiboot2_first_tag_with_type( + (struct KernAux_Multiboot2*)multiboot2_example1, + KERNAUX_MULTIBOOT2_TAGTYPE_EFI_MEMORY_MAP + ) == 0 + ); + + assert( + KernAux_Multiboot2_first_tag_with_type( + (struct KernAux_Multiboot2*)multiboot2_example1, + KERNAUX_MULTIBOOT2_TAGTYPE_EFI_BOOT_SERVICES_NOT_TERMINATED + ) == 0 + ); + + assert( + KernAux_Multiboot2_first_tag_with_type( + (struct KernAux_Multiboot2*)multiboot2_example1, + KERNAUX_MULTIBOOT2_TAGTYPE_EFI_32BIT_IMAGE_HANDLE_PTR + ) == 0 + ); + + assert( + KernAux_Multiboot2_first_tag_with_type( + (struct KernAux_Multiboot2*)multiboot2_example1, + KERNAUX_MULTIBOOT2_TAGTYPE_EFI_64BIT_IMAGE_HANDLE_PTR + ) == 0 + ); + + assert( + KernAux_Multiboot2_first_tag_with_type( + &multiboot2_example2.multiboot2, + KERNAUX_MULTIBOOT2_TAGTYPE_NONE + ) == &multiboot2_example2.tag_none.base + ); + + assert( + KernAux_Multiboot2_first_tag_with_type( + &multiboot2_example2.multiboot2, + KERNAUX_MULTIBOOT2_TAGTYPE_BOOT_CMD_LINE + ) == &multiboot2_example2.tag_boot_cmd_line.tag.base + ); + + assert( + KernAux_Multiboot2_first_tag_with_type( + &multiboot2_example2.multiboot2, + KERNAUX_MULTIBOOT2_TAGTYPE_BOOT_LOADER_NAME + ) == &multiboot2_example2.tag_boot_loader_name.tag.base + ); + + assert( + KernAux_Multiboot2_first_tag_with_type( + &multiboot2_example2.multiboot2, + KERNAUX_MULTIBOOT2_TAGTYPE_MODULE + ) == &multiboot2_example2.tag_module1.tag.base + ); + + assert( + KernAux_Multiboot2_first_tag_with_type( + &multiboot2_example2.multiboot2, + KERNAUX_MULTIBOOT2_TAGTYPE_BASIC_MEMORY_INFO + ) == &multiboot2_example2.tag_basic_memory_info.base + ); + + assert( + KernAux_Multiboot2_first_tag_with_type( + &multiboot2_example2.multiboot2, + KERNAUX_MULTIBOOT2_TAGTYPE_FRAMEBUFFER_INFO + ) == &multiboot2_example2.tag_framebuffer_info.tag.base + ); + + assert( + KernAux_Multiboot2_first_tag_with_type( + &multiboot2_example2.multiboot2, + KERNAUX_MULTIBOOT2_TAGTYPE_ELF_SYMBOLS + ) == &multiboot2_example2.tag_elf_symbols.tag.base + ); + + assert( + KernAux_Multiboot2_first_tag_with_type( + &multiboot2_example2.multiboot2, + KERNAUX_MULTIBOOT2_TAGTYPE_APM_TABLE + ) == &multiboot2_example2.tag_apm_table.base + ); + + assert( + KernAux_Multiboot2_first_tag_with_type( + &multiboot2_example2.multiboot2, + KERNAUX_MULTIBOOT2_TAGTYPE_EFI_32BIT_SYSTEM_TABLE_PTR + ) == &multiboot2_example2.tag_efi_32bit_system_table_ptr.base + ); + + assert( + KernAux_Multiboot2_first_tag_with_type( + &multiboot2_example2.multiboot2, + KERNAUX_MULTIBOOT2_TAGTYPE_EFI_64BIT_SYSTEM_TABLE_PTR + ) == &multiboot2_example2.tag_efi_64bit_system_table_ptr.base + ); + + assert( + KernAux_Multiboot2_first_tag_with_type( + &multiboot2_example2.multiboot2, + KERNAUX_MULTIBOOT2_TAGTYPE_SMBIOS_TABLES + ) == &multiboot2_example2.tag_smbios_tables.tag.base + ); + + assert( + KernAux_Multiboot2_first_tag_with_type( + &multiboot2_example2.multiboot2, + KERNAUX_MULTIBOOT2_TAGTYPE_ACPI_OLD_RSDP + ) == &multiboot2_example2.tag_acpi_old_rsdp.tag.base + ); + + assert( + KernAux_Multiboot2_first_tag_with_type( + &multiboot2_example2.multiboot2, + KERNAUX_MULTIBOOT2_TAGTYPE_ACPI_NEW_RSDP + ) == &multiboot2_example2.tag_acpi_new_rsdp.tag.base + ); + + assert( + KernAux_Multiboot2_first_tag_with_type( + &multiboot2_example2.multiboot2, + KERNAUX_MULTIBOOT2_TAGTYPE_NETWORKING_INFO + ) == &multiboot2_example2.tag_networking_info.tag.base + ); + + assert( + KernAux_Multiboot2_first_tag_with_type( + &multiboot2_example2.multiboot2, + KERNAUX_MULTIBOOT2_TAGTYPE_EFI_MEMORY_MAP + ) == &multiboot2_example2.tag_efi_memory_map.tag.base + ); + + assert( + KernAux_Multiboot2_first_tag_with_type( + &multiboot2_example2.multiboot2, + KERNAUX_MULTIBOOT2_TAGTYPE_EFI_BOOT_SERVICES_NOT_TERMINATED + ) == &multiboot2_example2.tag_efi_boot_services_not_terminated.base + ); + + assert( + KernAux_Multiboot2_first_tag_with_type( + &multiboot2_example2.multiboot2, + KERNAUX_MULTIBOOT2_TAGTYPE_EFI_32BIT_IMAGE_HANDLE_PTR + ) == &multiboot2_example2.tag_efi_32bit_image_handle_ptr.base + ); + + assert( + KernAux_Multiboot2_first_tag_with_type( + &multiboot2_example2.multiboot2, + KERNAUX_MULTIBOOT2_TAGTYPE_EFI_64BIT_IMAGE_HANDLE_PTR + ) == &multiboot2_example2.tag_efi_64bit_image_handle_ptr.base + ); + + assert( + KernAux_Multiboot2_first_tag_with_type( + &multiboot2_example2.multiboot2, + KERNAUX_MULTIBOOT2_TAGTYPE_IMAGE_LOAD_BASE_PHYS_ADDR + ) == &multiboot2_example2.tag_image_load_base_phys_addr.base + ); + + // KernAux_Multiboot2_boot_cmd_line + assert( KernAux_Multiboot2_boot_cmd_line( &multiboot2_with_some_boot_cmd_line.multiboot2 diff --git a/tests/test_multiboot2_validation.c b/tests/test_multiboot2_validation.c index 864479d..12da064 100644 --- a/tests/test_multiboot2_validation.c +++ b/tests/test_multiboot2_validation.c @@ -2,6 +2,9 @@ #include +#include "multiboot2_example1.h" +#include "multiboot2_example2.h" + /************ * Tag_None * ************/ @@ -750,63 +753,6 @@ static const struct { }, }; -static const unsigned char multiboot2_example[864] = { - 96, 3, 0, 0, 0, 0, 0, 0, 21, 0, 0, 0, 12, 0, 0, 0, - 0, 0, 64, 0, 0, 0, 232, 133, 1, 0, 0, 0, 21, 0, 0, 0, - 104, 101, 108, 108, 111, 32, 107, 101, 114, 110, 101, 108, 0, 139, 69, 228, - 2, 0, 0, 0, 30, 0, 0, 0, 71, 82, 85, 66, 32, 50, 46, 48, - 50, 45, 50, 117, 98, 117, 110, 116, 117, 56, 46, 50, 48, 0, 0, 0, - 10, 0, 0, 0, 28, 0, 0, 0, 2, 1, 0, 240, 207, 212, 0, 0, - 0, 240, 0, 240, 3, 0, 240, 255, 240, 255, 240, 255, 1, 0, 0, 0, - 3, 0, 0, 0, 29, 0, 0, 0, 0, 32, 16, 0, 156, 50, 16, 0, - 104, 101, 108, 108, 111, 32, 109, 111, 100, 117, 108, 101, 0, 131, 255, 16, - 3, 0, 0, 0, 17, 0, 0, 0, 0, 64, 16, 0, 84, 82, 16, 0, - 0, 232, 99, 9, 0, 0, 235, 53, 6, 0, 0, 0, 160, 0, 0, 0, - 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 252, 9, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, - 0, 252, 9, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, - 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, - 0, 0, 1, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 238, 7, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 254, 7, 0, 0, 0, 0, - 0, 0, 2, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 252, 255, 0, 0, 0, 0, 0, 0, 4, 0, 0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 0, 8, 0, 0, 0, - 72, 0, 0, 0, 4, 0, 0, 0, 16, 0, 0, 0, 9, 0, 0, 0, - 3, 0, 0, 0, 0, 0, 0, 0, 196, 12, 16, 0, 196, 124, 0, 0, - 208, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, - 0, 0, 0, 0, 17, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, - 148, 26, 16, 0, 148, 138, 0, 0, 71, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 217, 255, 255, 137, - 4, 0, 0, 0, 16, 0, 0, 0, 127, 2, 0, 0, 128, 251, 1, 0, - 5, 0, 0, 0, 20, 0, 0, 0, 224, 0, 0, 0, 255, 255, 255, 255, - 255, 255, 255, 255, 208, 137, 69, 212, 8, 0, 0, 0, 32, 0, 0, 0, - 0, 128, 11, 0, 0, 0, 0, 0, 160, 0, 0, 0, 80, 0, 0, 0, - 25, 0, 0, 0, 16, 2, 0, 0, 14, 0, 0, 0, 28, 0, 0, 0, - 82, 83, 68, 32, 80, 84, 82, 32, 60, 66, 79, 67, 72, 83, 32, 0, - 252, 21, 254, 7, 236, 0, 0, 235, 0, 0, 0, 0, 8, 0, 0, 0, -}; - /******** * main * ********/ @@ -816,7 +762,11 @@ int main() // Multiboot2 assert(KernAux_Multiboot2_is_valid( - (struct KernAux_Multiboot2*)multiboot2_example + (struct KernAux_Multiboot2*)&multiboot2_example1 + )); + + assert(KernAux_Multiboot2_is_valid( + (struct KernAux_Multiboot2*)&multiboot2_example2 )); assert(KernAux_Multiboot2_is_valid(&multiboot2_empty_valid.multiboot2));