From: John Snow <jsnow@redhat.com>
To: 乔天香 <tianxiang.qiao@gmail.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] Character order of ATA identity
Date: Fri, 17 Apr 2015 18:45:38 -0400 [thread overview]
Message-ID: <55318D12.3090307@redhat.com> (raw)
In-Reply-To: <CAJfS=t0N0Z6-HM4ZMfXKo8byStBP64FjNHB4yH_VwSM538jZgA@mail.gmail.com>
On 04/16/2015 02:07 PM, 乔天香 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 = 0; i < len; i++) {
> 65 if (*src)
> 66 v = *src++;
> 67 else
> 68 v = ' ';
> 69 str[i^1] = v;
> 70 }
> 71 }
>
>
> And it is called like:
>
> 112 padstr((char *)(p + 27), s->drive_model_str, 40); /* model */
>
> Now I'm wondering why it does this "byte swapping"? I read the ATA
> specification about this *ATA identify* command and didn't find anything
> 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
array of 2 byte chunks. Any historical reasons for doing so are not
known to me, but:
Please check out ATA8 ATA/ATAPI Command Set 3, Revision 1b (or whichever
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
within the IDE system.
Thanks,
--js
prev parent reply other threads:[~2015-04-17 23:47 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-16 18:07 [Qemu-devel] Character order of ATA identity 乔天香
2015-04-17 22:45 ` John Snow [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=55318D12.3090307@redhat.com \
--to=jsnow@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=tianxiang.qiao@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).