[OpenBIOS] [PATCH 9/10] Divide by zero check

Artyom Tarasenko atar4qemu at gmail.com
Wed Aug 10 09:56:44 CEST 2011


On Tue, Aug 9, 2011 at 11:55 PM, William Hahne <will07c5 at gmail.com> wrote:
> It is possible for BootX to purposefully divide by zero expecting 0 as the
> result.

OBP behaves differently. It puts the result only if there was no
devision by zero:

ok showstack
ok 0 0 /
Trap 3e
ok 1 0 /
Trap 3e
ok 10 8 /
2 ok

Maybe it has to be done platform-dependent.

> Index: kernel/forth.c
> ===================================================================
> --- kernel/forth.c (revision 1041)
> +++ kernel/forth.c (working copy)
> @@ -1157,6 +1157,12 @@
>  {
>   const ucell b = POP();
>   const ducell a = DPOP();
> +
> + if (b == 0) { // can't divide by zero
> +            PUSH(0);
> +            DPUSH(0);
> +            return;
> + }
>  #ifdef NEED_FAKE_INT128_T
>          if (a.hi != 0) {
>              fprintf(stderr, "mudivmod called (0x%016llx %016llx /
> 0x%016llx)\n",
> --
> OpenBIOS                 http://openbios.org/
> Mailinglist:  http://lists.openbios.org/mailman/listinfo
> Free your System - May the Forth be with you
>



-- 
Regards,
Artyom Tarasenko

solaris/sparc under qemu blog: http://tyom.blogspot.com/



More information about the OpenBIOS mailing list