* [Qemu-devel] Should we check arguments for function `from_bcd` and `to_bcd`?
@ 2018-03-22 7:03 Su Hang
2018-03-22 9:12 ` Paolo Bonzini
0 siblings, 1 reply; 3+ messages in thread
From: Su Hang @ 2018-03-22 7:03 UTC (permalink / raw)
To: qemu-devel
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).
"""(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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] Should we check arguments for function `from_bcd` and `to_bcd`?
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
2018-03-22 10:33 ` Su Hang
0 siblings, 1 reply; 3+ messages in thread
From: Paolo Bonzini @ 2018-03-22 9:12 UTC (permalink / raw)
To: Su Hang, qemu-devel
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
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] Should we check arguments for function `from_bcd` and `to_bcd`?
2018-03-22 9:12 ` Paolo Bonzini
@ 2018-03-22 10:33 ` Su Hang
0 siblings, 0 replies; 3+ messages in thread
From: Su Hang @ 2018-03-22 10:33 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: qemu-devel
Thanks for your reply. :-)
Su Hang
"Paolo Bonzini" <pbonzini@redhat.com>wrote:
> 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
> >
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-03-22 10:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2018-03-22 10:33 ` Su Hang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.