[OpenBIOS] [RFCv2 2/2] PPC: Mimic Apple's OpenFirmware behaviour if a divide by zero occurs.
Mark Cave-Ayland
mark.cave-ayland at ilande.co.uk
Fri Jan 11 12:38:03 CET 2013
As reported by Amadeusz Sławiński using a real Mac, if anything is divided by
zero then we should return zero:
0 > 2 0 / ok
1 > u. 0 ok
This resolves a bug in BootX which (un)intentionally divides by zero during
boot.
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland at ilande.co.uk>
---
openbios-devel/arch/ppc/ppc.fs | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/openbios-devel/arch/ppc/ppc.fs b/openbios-devel/arch/ppc/ppc.fs
index 6995ba9..e07765b 100644
--- a/openbios-devel/arch/ppc/ppc.fs
+++ b/openbios-devel/arch/ppc/ppc.fs
@@ -55,3 +55,23 @@
\ Set by BootX when booting Mac OS X
defer spin
+
+\ BootX has a bug whereby it divides by zero when booting from any device
+\ other than the network (see openbios list archive for details). The
+\ behaviour on real hardware is for the trap to "catch" the exception and
+\ then continue.
+\
+\ Since OpenBIOS PPC can't trap into Forth, we emulate this behaviour by
+\ checking for divide by zero and returning the same result as real hardware
+\ which is a single zero e.g.
+\
+\ 0 > 2 0 / ok
+\ 1 > u. 0 ok
+
+:noname
+ dup 0= if
+ 3drop 0 0 0
+ else
+ mu/mod
+ then
+; to (mu/mod)
--
1.7.10.4
More information about the OpenBIOS
mailing list