Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: Confused re: endianness

2005-10-18 by rtstofer

> 
> You might have a hardware problem where you are byte swapping?  
Try 
> running an IDENTIFY_DRIVE (0xec) command on the CF.  This will 
send you 
> back a bunch of bytes structured as:
> 
> =============== begin ==================
> struct DriveID {
>   Word Signature;
>   Word NumCylinders;
>   Word Reserved1;
>   Word NumHeads;
>   Word NumUnBytePerTrack;
>   Word NumUnBytePerSector;
>   Word NumSectorsPerTrack;
>   DWord NumberSectorsPerCard;
>   Word Reserved2;
>   char SerialNumber[20];
>   Word BufferType;
>   Word BufferSize;
>   Word EccBytesPassed;
>   char FirmwareRev [8];
>   char ModelNumber [40];
>   Word Max1SectorRW;
>   Word DWnotSupported;
>   Word Capabilities;
>   Word Reserved3;
> };
> =============== end ===================
> 
> Try looking at the text string: ModelNumber.  That will tell you 
if byte 
> swapping is the problem.
> 
> I ran into byte swapping issues between the IDE registers and the 
Data 
> register while working with a big-endian controller (MC68EZ328).
> 
> IIRC, something tells me that the drive data is Big-Endian on the 
CF and 
> IDE drives...
> 
> 
> TomW

Yes, for the firmware revision and model ASCII strings the chars are 
in big endian word order.  NumberSectorsPerCard is also in big 
endian word order.

But, I'm at the next step: reading LBA sector 0.  Here the sector 
dump shows the data in little endian word and byte order.  In fact, 
when I point a WORD pointer (16 bit) into the buffer, I get the 
right answer: LSB MSB in ascending order.

The hangup seems to be when I point a DWORD pointer at some 
location.  It picks up those two bytes in ascending order and then 
backs up and picks up the two bytes ahead of the pointer as the 
MSW.  I was expecting LSW MSW in ascending order where I am pointing 
at LSW.  What I get is MSW LSW even though I am pointing at LSW.

Curious!  The bytes are in the proper order.  Alignment issue?

My workaround?  Use something like memcpy to get the data into the 
structure.

Richard

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.