How to manage bitfield xfer from PC-SPARC?

How to manage bitfield xfer from PC-SPARC?

Post by Steve Sanders » Fri, 10 Feb 1995 06:37:24



  Problem:  I need to get a block of data (a structure) from PC->SPARC
  over a serial line.  The actual data transfer using read() is no problem,
  but this structure contains bitfields.  The byte reordering for multi-byte
  values is no problem, but bitfields are NOT handled the same at all.
  Has anyone done anything similar to this before, and have some easier
  way out than pure manual twiddling?

  The problem: the bits themselves have to be reversed. Also, I'm not sure
  yet whether the SPARC allocates the whole 16 bits for an unsigned short:5,
  or whether it only allocates those 5 bits!  I believe the PC allocates
  the whole amount, and the rest is just wasted, but at least it's easy to
  manipulate code-wise.  I need some kind of "converter" to reassemble the
  structure on the SPARC side from the data sent by the PC.

  I'm using Watcom C 9.5 and SUN SPARCCompiler C 3.0
--
Steve Sanderson           |   In God we trust;

 
 
 

How to manage bitfield xfer from PC-SPARC?

Post by Dave Carn » Sun, 12 Feb 1995 12:28:45


:   Problem:  I need to get a block of data (a structure) from PC->SPARC
:   over a serial line.  The actual data transfer using read() is no problem,
:   but this structure contains bitfields.  The byte reordering for multi-byte
:   values is no problem, but bitfields are NOT handled the same at all.
:   Has anyone done anything similar to this before, and have some easier
:   way out than pure manual twiddling?
:  
:   The problem: the bits themselves have to be reversed. Also, I'm not sure
:   yet whether the SPARC allocates the whole 16 bits for an unsigned short:5,
:   or whether it only allocates those 5 bits!  I believe the PC allocates
:   the whole amount, and the rest is just wasted, but at least it's easy to
:   manipulate code-wise.  I need some kind of "converter" to reassemble the
:   structure on the SPARC side from the data sent by the PC.
:  
:   I'm using Watcom C 9.5 and SUN SPARCCompiler C 3.0

You need to do something like:
     struct x {
        union {
            struct {
#if defined(Intel)
              int rest : 30;
              int  b : 1;
              int  a : 1;
#else
              int  a : 1;
              int  b : 1;
              int rest : 30;
#endif
            } bfld;
            int intfld;
        } U;
        :
        rest of struct...
    };

    Then before you send:
       z.U.intfld = htonl(z.U.intfld);

    after you recv:
       z.U.intfld = htonl(z.U.intfld);

    On the sparc, these macros do nothing.  On the PC, these macros
change the byte order of the int.  See the man on htonl().
Oh! One more tip.  Always pad every element in the data struct to
even 4 byte boundaries or differneces between the way padding is done
between the boxes will get ya.

Yes. It's a pain in the %&*.  Believe me I know.

Dave *
Senior Network Programmer / NationsBank - CRT

 
 
 

1. Ser Port Xfer Sparc Solaris <-> PC?

Has anyone done this? I have been researching ways to do this...Could someone
who has done this please email me their solution: wiring (232 2,3,7+?),
admin (any eeprom commands?, sys mon commands, shell scripts?), and
finally software...(ioctl calls? tcsetattr?)

Thanks much in advance...Please email if possible...

John Brookes

2. wuftp statistics programs

3. SPARC FTP xfer speeds

4. Help setting up Linux server

5. Help with Xfer from Unix to PC Dos

6. (none)

7. PC file Xfer help

8. Where's the Shirts

9. HELP:Need PC Term/File Xfer Program for PC6300

10. Has anyone managed to build a Sparc crosscompiler for linux

11. Who managed to compile Linux/Sparc?

12. Printing with PC NetLink 1.2 and HP Jetadmin managed printers

13. Good PC based X Client to manage Digital Unix