Author Topic: XStruc - A structure with a union structure  (Read 11259 times)


  • Guest
XStruc - A structure with a union structure
« on: July 20, 2008, 02:43:06 AM »
Hello there,

I'm translating the following C to NASM:

/* The symbol table for a.out. */
     typedef struct aout_symbol_table
       unsigned long tabsize;
       unsigned long strsize;
       unsigned long addr;
       unsigned long reserved;
     } aout_symbol_table_t;

/* The section header table for ELF. */
     typedef struct elf_section_header_table
       unsigned long num;
       unsigned long size;
       unsigned long addr;
       unsigned long shndx;
     } elf_section_header_table_t;

/* The Multiboot information. */
     typedef struct multiboot_info
       unsigned long flags;
       unsigned long mem_lower;
       unsigned long mem_upper;
       unsigned long boot_device;
       unsigned long cmdline;
       unsigned long mods_count;
       unsigned long mods_addr;
         aout_symbol_table_t aout_sym;
         elf_section_header_table_t elf_sec;
       } u;
       unsigned long mmap_length;
       unsigned long mmap_addr;
     } multiboot_info_t;

Using the xstruc macros. I've got the following so far:

;A.out Symble Table

xstruc aout_symble_table
      xitemw   tabsize
      xitemw   strsize
      xitemw   addr
      xitemw   reserved

;ELF Section Header Table

xstruc elf_section_header_table
      xitemw   num
      xitemw   size
      xitemw   addr
      xitemw   shndx

;Multiboot Information

xstruc multiboot_information
      xitemw   flags
      xitemw  memory_lower
      xitemw   memory_upper
      xitemw  boot_device
      xitemw   cmdline
      xitemw  mods_count
      xitemw  mods_addr
      xunion u


However, I don't know how to translate the union part of the C structure i.e.

         aout_symbol_table_t aout_sym;
         elf_section_header_table_t elf_sec;
       } u;

I'd prefer not to define the other two structures within the union its self.

Cheers for you help,