From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35553) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YjFyq-0002mq-OA for qemu-devel@nongnu.org; Fri, 17 Apr 2015 19:47:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YjFyp-0004YC-OW for qemu-devel@nongnu.org; Fri, 17 Apr 2015 19:47:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34874) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YjFyp-0004Y0-I3 for qemu-devel@nongnu.org; Fri, 17 Apr 2015 19:47:27 -0400 Message-ID: <55318D12.3090307@redhat.com> Date: Fri, 17 Apr 2015 18:45:38 -0400 From: John Snow MIME-Version: 1.0 References: In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] Character order of ATA identity List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?UTF-8?B?5LmU5aSp6aaZ?= , qemu-devel@nongnu.org On 04/16/2015 02:07 PM, =E4=B9=94=E5=A4=A9=E9=A6=99 wrote: > Hi, all > Hi! > I'm learning operating system and trying to write a little toy kernel. > Before doing disk I/O, I issued the *ATA identify* command to obtain > information about the master device on the primary channel. When I ran > my code with QEMU, I found it gives some ASCII string fields in a wrong > byte order, for example, the model name is given as: > > EQUMH RADDSI K > > but actually it should be > > QEMU HARDDISK > > So I referred to the source code file `hw/ide/core.c` and found a > function doing this: > > > 61 static void padstr(char *str, const char *src, int len) > 62 { > 63 int i, v; > 64 for(i =3D 0; i < len; i++) { > 65 if (*src) > 66 v =3D *src++; > 67 else > 68 v =3D ' '; > 69 str[i^1] =3D v; > 70 } > 71 } > > > And it is called like: > > 112 padstr((char *)(p + 27), s->drive_model_str, 40); /* mode= l */ > > Now I'm wondering why it does this "byte swapping"? I read the ATA > specification about this *ATA identify* command and didn't find anythin= g > related to byte order. Is it required by hardware? > > Thanks for your kind help. The reason is that the ASCII data is, for whatever reason, stored as an=20 array of 2 byte chunks. Any historical reasons for doing so are not=20 known to me, but: Please check out ATA8 ATA/ATAPI Command Set 3, Revision 1b (or whichever=20 ATA spec you have handy) Section 3.3.10 "ATA string convention" 'Each pair of bytes in an ATA string is swapped as shown in table 5.' Why? It's a mystery to me. Please don't hesitate to comment on any other oddities you come across=20 within the IDE system. Thanks, --js