diff options
author | Mitya Selivanov <automainint@guattari.tech> | 2024-07-17 05:10:05 +0200 |
---|---|---|
committer | Mitya Selivanov <automainint@guattari.tech> | 2024-07-17 05:10:05 +0200 |
commit | a5c5ade229d0cfff7ba01d179d9a17699570faed (patch) | |
tree | 0ab3fb561cc942d6c47fd95dda376b2a690aebd7 | |
parent | b9c3084138b3e6b0c3d88d3cf5cf94f0c3ab5ff5 (diff) | |
download | bxgen-a5c5ade229d0cfff7ba01d179d9a17699570faed.zip |
ordering macros
-rwxr-xr-x | bxgen.c | 76 |
1 files changed, 36 insertions, 40 deletions
@@ -1046,9 +1046,6 @@ void write_f64(i32 bit_order, i32 byte_order, i32 f64_dword_order, f64 x, void * } } -#define HBIO host_bit_order() -#define HBYO host_byte_order() - #define HO_u8 host_bit_order() #define HO_u16 host_bit_order(), host_byte_order() #define HO_u32 host_bit_order(), host_byte_order() @@ -1217,7 +1214,7 @@ u32 ar_find_symbol_offset_by_name(u8 *ar_symbol_table, u8 *ar_end, c8 *name, c8 BX_ASSERT(name != NULL); BX_ASSERT(name_end > name); - u32 count = read_u32(HBIO, BE, ar_symbol_table, ar_end); + u32 count = read_u32(host_bit_order(), BE, ar_symbol_table, ar_end); i64 len = name_end - name; @@ -1227,7 +1224,7 @@ u32 ar_find_symbol_offset_by_name(u8 *ar_symbol_table, u8 *ar_end, c8 *name, c8 for (; index < count; ++index) { BX_ASSERT(s + len <= (c8 *) ar_end); if (s[len] == '\0' && bx_mem_eq(s, name, len)) - return read_u32(HBIO, BE, ar_symbol_table + 4 * (index + 1), ar_end); + return read_u32(host_bit_order(), BE, ar_symbol_table + 4 * (index + 1), ar_end); while (*s != '\0' && s < (c8 *) ar_end) ++s; BX_ASSERT(s < (c8 *) ar_end); @@ -1243,7 +1240,7 @@ u16 elf_section_names_table_index( u8 *elf_begin, u8 *elf_end ) { - return read_u16(HBIO, HBYO, elf_begin + 62, elf_end); + return read_u16(HO_u16, elf_begin + 62, elf_end); } Offset_Count elf_section_headers( @@ -1251,8 +1248,8 @@ Offset_Count elf_section_headers( u8 *elf_end ) { return (Offset_Count) { - .offset = read_u64(HBIO, HBYO, elf_begin + 40, elf_end), - .count = read_u16(HBIO, HBYO, elf_begin + 60, elf_end), + .offset = read_u64(HO_u64, elf_begin + 40, elf_end), + .count = read_u16(HO_u16, elf_begin + 60, elf_end), }; } @@ -1273,8 +1270,8 @@ Offset_Size elf_section_names_data( u8 *begin = elf_begin + elf_section_header_offset(elf_begin, elf_end, string_table_index); return (Offset_Size) { - .offset = read_u64(HBIO, HBYO, begin + 24, elf_end), - .size = read_u64(HBIO, HBYO, begin + 32, elf_end), + .offset = read_u64(HO_u64, begin + 24, elf_end), + .size = read_u64(HO_u64, begin + 32, elf_end), }; } @@ -1307,7 +1304,7 @@ u64 elf_find_section_header_by_name( for (u16 i = 0; i < headers.count; ++i) { u8 *begin = elf_begin + headers.offset + i * ELF_SECTION_HEADER_SIZE; - u32 name_offset = read_u32(HBIO, HBYO, begin, elf_end); + u32 name_offset = read_u32(HO_u32, begin, elf_end); if (name_offset + name_size <= names.size && bx_mem_eq(elf_begin + names.offset + name_offset, name, name_size)) @@ -1325,7 +1322,7 @@ Section_Header elf_section_data_by_offset( ) { Offset_Size names = elf_section_names_data(elf_begin, elf_end); u8 * begin = elf_begin + offset; - u32 name_index = read_u32(HBIO, HBYO, begin, elf_end); + u32 name_index = read_u32(HO_u32, begin, elf_end); return (Section_Header) { .name = elf_name_in_string_table( @@ -1334,11 +1331,11 @@ Section_Header elf_section_data_by_offset( names, name_index ), - .type = read_u32(HBIO, HBYO, begin + 4, elf_end), - .flags = read_u64(HBIO, HBYO, begin + 8, elf_end), + .type = read_u32(HO_u32, begin + 4, elf_end), + .flags = read_u64(HO_u64, begin + 8, elf_end), .data = { - .offset = read_u64(HBIO, HBYO, begin + 24, elf_end), - .size = read_u64(HBIO, HBYO, begin + 32, elf_end), + .offset = read_u64(HO_u64, begin + 24, elf_end), + .size = read_u64(HO_u64, begin + 32, elf_end), }, }; } @@ -1529,35 +1526,35 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data u16 string_table_index; u16 string_table_offset; - BX_ASSERT(read_u8(HBIO, elf_begin) == ELF_MAGIC[0]); - BX_ASSERT(read_u8(HBIO, elf_begin + 1) == ELF_MAGIC[1]); - BX_ASSERT(read_u8(HBIO, elf_begin + 2) == ELF_MAGIC[2]); - BX_ASSERT(read_u8(HBIO, elf_begin + 3) == ELF_MAGIC[3]); - BX_ASSERT(read_u8(HBIO, elf_begin + 4) == ELF_64); - BX_ASSERT(read_u8(HBIO, elf_begin + 5) == ELF_2_LE); - BX_ASSERT(read_u8(HBIO, elf_begin + 6) == ELF_VERSION); - u8 osabi = read_u8(HBIO, elf_begin + 7); + BX_ASSERT(read_u8(HO_u8, elf_begin) == ELF_MAGIC[0]); + BX_ASSERT(read_u8(HO_u8, elf_begin + 1) == ELF_MAGIC[1]); + BX_ASSERT(read_u8(HO_u8, elf_begin + 2) == ELF_MAGIC[2]); + BX_ASSERT(read_u8(HO_u8, elf_begin + 3) == ELF_MAGIC[3]); + BX_ASSERT(read_u8(HO_u8, elf_begin + 4) == ELF_64); + BX_ASSERT(read_u8(HO_u8, elf_begin + 5) == ELF_2_LE); + BX_ASSERT(read_u8(HO_u8, elf_begin + 6) == ELF_VERSION); + u8 osabi = read_u8(HO_u8, elf_begin + 7); BX_ASSERT(osabi == ELF_SYS_V || osabi == ELF_LINUX); - BX_ASSERT(read_u8(HBIO, elf_begin + 8) == ELF_ABI_VERSION); + BX_ASSERT(read_u8(HO_u8, elf_begin + 8) == ELF_ABI_VERSION); - BX_ASSERT(read_u16(HBIO, HBYO, elf_begin + 16, elf_end) == ELF_RELOCATABLE); - BX_ASSERT(read_u16(HBIO, HBYO, elf_begin + 18, elf_end) == ELF_X86_64); - BX_ASSERT(read_u32(HBIO, HBYO, elf_begin + 20, elf_end) == ELF_VERSION); - BX_ASSERT(read_u64(HBIO, HBYO, elf_begin + 24, elf_end) == 0); // entry - BX_ASSERT(read_u64(HBIO, HBYO, elf_begin + 32, elf_end) == 0); // program header offset + BX_ASSERT(read_u16(HO_u16, elf_begin + 16, elf_end) == ELF_RELOCATABLE); + BX_ASSERT(read_u16(HO_u16, elf_begin + 18, elf_end) == ELF_X86_64); + BX_ASSERT(read_u32(HO_u32, elf_begin + 20, elf_end) == ELF_VERSION); + BX_ASSERT(read_u64(HO_u64, elf_begin + 24, elf_end) == 0); // entry + BX_ASSERT(read_u64(HO_u64, elf_begin + 32, elf_end) == 0); // program header offset - section_header_offset = read_u64(HBIO, HBYO, elf_begin + 40, elf_end); + section_header_offset = read_u64(HO_u64, elf_begin + 40, elf_end); - BX_ASSERT(read_u32(HBIO, HBYO, elf_begin + 48, elf_end) == 0); // flags - BX_ASSERT(read_u16(HBIO, HBYO, elf_begin + 52, elf_end) == ELF_HEADER_SIZE); - BX_ASSERT(read_u16(HBIO, HBYO, elf_begin + 54, elf_end) == 0); // program header size - BX_ASSERT(read_u16(HBIO, HBYO, elf_begin + 56, elf_end) == 0); // program header count - BX_ASSERT(read_u16(HBIO, HBYO, elf_begin + 58, elf_end) == ELF_SECTION_HEADER_SIZE); + BX_ASSERT(read_u32(HO_u32, elf_begin + 48, elf_end) == 0); // flags + BX_ASSERT(read_u16(HO_u16, elf_begin + 52, elf_end) == ELF_HEADER_SIZE); + BX_ASSERT(read_u16(HO_u16, elf_begin + 54, elf_end) == 0); // program header size + BX_ASSERT(read_u16(HO_u16, elf_begin + 56, elf_end) == 0); // program header count + BX_ASSERT(read_u16(HO_u16, elf_begin + 58, elf_end) == ELF_SECTION_HEADER_SIZE); - section_count = read_u16(HBIO, HBYO, elf_begin + 60, elf_end); - string_table_index = read_u16(HBIO, HBYO, elf_begin + 62, elf_end); + section_count = read_u16(HO_u16, elf_begin + 60, elf_end); + string_table_index = read_u16(HO_u16, elf_begin + 62, elf_end); - string_table_offset = read_u64(HBIO, HBYO, elf_begin + section_header_offset + string_table_index * ELF_SECTION_HEADER_SIZE + 24, elf_end); + string_table_offset = read_u64(HO_u64, elf_begin + section_header_offset + string_table_index * ELF_SECTION_HEADER_SIZE + 24, elf_end); (void) ar_symbol_table; (void) ar_string_table; @@ -2549,7 +2546,6 @@ int main(int argc, char **argv) { printf("host f64 dword order: %s\n\n", host_f64_dword_order() == LE ? "LE" : "BE"); printf("entity - %d bytes\n", (i32) sizeof(Entity)); - printf("binary output buffer - %d MB\n\n", (i32) sizeof(Binary_Output) / (1024 * 1024)); i64 main = p_new("main"); i64 n0 = n_i64(42); |