[fpc-pascal] Question C to Pascal translation ....Re: Wraper for libpciaccess ?

Brian vmst at golden.net
Thu Feb 5 17:05:56 CET 2015


Ref  libpciaccess.h
Any suggestions on the conversions below ? Thanks in advance. Brian

C Union
-----------

00043 struct pci_device_iterator {
    unsigned next_index;

    enum {
      match_any,
      match_slot,
      match_id
    } mode;

    union {
      struct pci_slot_match   slot;
      struct pci_id_match     id;
    } match;
};

... is this conversion correct ?

 pci_device_iterator = packed record
                       next_index : longword; // ???
                        Mode : (match_any, match_slot, match_id);      
                         
                          match : packed record
                                   case integer of // union
                                    0 : (
                                         slot: pci_slot_match;
                                        );
                                    1 : (
                                         id : pci_id_match;
                                        );
                                   end;   
                        end;


----------


H2PAS converts this to ...
00245 struct pci_mem_region {
    /**
     * When the region is mapped, this is the pointer to the memory.
     *
     * This field is \b only set when the deprecated \c
pci_device_map_region
     * interface is used.  Use \c pci_device_map_range instead.
     *
     * \deprecated
     */
00254     void *memory;


    /**
     * Base physical address of the region within its bus / domain.
     *
     * \warning
     * This address is really only useful to other devices in the same
     * domain.  It's probably \b not the address applications will ever
     * use.
     * 
     * \warning
     * Most (all?) platform back-ends leave this field unset.
     */
00268     pciaddr_t bus_addr;


    /**
     * Base physical address of the region from the CPU's point of view.
     * 
     * This address is typically passed to \c pci_device_map_range to create
     * a mapping of the region to the CPU's virtual address space.
     */
00277     pciaddr_t base_addr;


    /**
     * Size, in bytes, of the region.
     */
00283     pciaddr_t size;


    /**
     * Is the region I/O ports or memory?
     */
00289     unsigned is_IO:1;

    /**
     * Is the memory region prefetchable?
     *
     * \note
     * This can only be set if \c is_IO is not set.
     */
00297     unsigned is_prefetchable:1;


    /**
     * Is the memory at a 64-bit address?
     *
     * \note
     * This can only be set if \c is_IO is not set.
     */
00306     unsigned is_64:1;
};


Not certain if I believe this .....

      pci_mem_region = record
          memory : pointer;
          bus_addr : pciaddr_t;
          base_addr : pciaddr_t;
          size : pciaddr_t;
          flag0 : word;
        end;


    const
      bm_pci_mem_region_is_IO = $1;
      bp_pci_mem_region_is_IO = 0;
      bm_pci_mem_region_is_prefetchable = $2;
      bp_pci_mem_region_is_prefetchable = 1;
      bm_pci_mem_region_is_64 = $4;
      bp_pci_mem_region_is_64 = 2;

    function is_IO(var a : pci_mem_region) : dword;
    procedure set_is_IO(var a : pci_mem_region; __is_IO : dword);
    function is_prefetchable(var a : pci_mem_region) : dword;
    procedure set_is_prefetchable(var a : pci_mem_region; __is_prefetchable
: dword);
    function is_64(var a : pci_mem_region) : dword;
    procedure set_is_64(var a : pci_mem_region; __is_64 : dword);



--
View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Wraper-for-libpciaccess-tp5720127p5720944.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.



More information about the fpc-pascal mailing list