From: Paolo Bonzini <pbonzini@redhat.com>
To: Su Hang <suhang16@mails.ucas.ac.cn>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] Should we check arguments for function `from_bcd` and `to_bcd`?
Date: Thu, 22 Mar 2018 10:12:41 +0100 [thread overview]
Message-ID: <e75a8366-3a44-6e2d-fc95-f5c795991013@redhat.com> (raw)
In-Reply-To: <dca9a53.33fd5.1624c84a277.Coremail.suhang16@mails.ucas.ac.cn>
On 22/03/2018 08:03, Su Hang wrote:
> When I was reading 'qemu/hw/timer/m48t59.c'(Line:328) and run with
> `make check-qtest-ppc`,
> I found when write an invalid value 0xc to address 0x1FFF,
> `from_bcd` return 12 instead of raising an exception(or error).
Each device probably has a different behavior when a wrong value is
written to a register that expects valid BCD. Therefore, if you want to
model that, you have to fix it in hw/timer/m48t59.c, not in from_bcd and
to_bcd.
However, note that anything that the guest does should never cause an
assertion.
Thanks,
Paolo
> """(qemu/hw/timer/m48t59.c)
> case 0x1FFF:
> case 0x07FF:
> /* year */
> tmp = from_bcd(val);
> if (tmp >= 0 && tmp <= 99) {
> """
>
>
> """(qemu/include/qemu/bcd.h)
> /* Convert a byte between binary and BCD. */
> static inline uint8_t to_bcd(uint8_t val)
> {
> return ((val / 10) << 4) | (val % 10);
> }
>
> static inline uint8_t from_bcd(uint8_t val)
> {
> return ((val >> 4) * 10) + (val & 0x0f);
> }
> """
>
> Su Hang
>
next prev parent reply other threads:[~2018-03-22 9:12 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-22 7:03 [Qemu-devel] Should we check arguments for function `from_bcd` and `to_bcd`? Su Hang
2018-03-22 9:12 ` Paolo Bonzini [this message]
2018-03-22 10:33 ` Su Hang
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=e75a8366-3a44-6e2d-fc95-f5c795991013@redhat.com \
--to=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=suhang16@mails.ucas.ac.cn \
/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).