This patch adds an Adler-32 checksum function to OpenBIOS as required by Mac OS 9. This and the copyright patch have been split as requested by Mark Cave-Ayland.
Signed-off-by: Cormac O'Brien i.am.cormac.obrien@gmail.com
--- arch/ppc/qemu/init.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+)
diff --git a/arch/ppc/qemu/init.c b/arch/ppc/qemu/init.c index 4fe8b72..f261e82 100644 --- a/arch/ppc/qemu/init.c +++ b/arch/ppc/qemu/init.c @@ -680,6 +680,58 @@ static void ffilll(void) } }
+/* + * adler32 ( adler buf len -- checksum ) + * + * Adapted from Mark Adler's original implementation (zlib license) + */ + +#define DO1(buf,i) {s1 += buf[i]; s2 += s1;} +#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); +#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); +#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); +#define DO16(buf) DO8(buf,0); DO8(buf,8); + +static void adler32(void) +{ + uint32_t len = (uint32_t)POP(); + char *buf = (char *)POP(); + uint32_t adler = (uint32_t)POP(); + + if (buf == NULL) { + RET(-1); + } + + uint32_t base = 65521; + uint32_t nmax = 5552; + + uint32_t s1 = adler & 0xffff; + uint32_t s2 = (adler >> 16) & 0xffff; + + uint32_t k; + while (len > 0) { + k = (len < nmax ? len : nmax); + len -= k; + + while (k >= 16) { + DO16(buf); + buf += 16; + k -= 16; + } + if (k != 0) { + do { + s1 += *buf++; + s2 += s1; + } while (--k); + } + + s1 %= base; + s2 %= base; + } + + RET(s2 << 16 | s1); +} + void arch_of_init(void) { @@ -945,6 +997,8 @@ arch_of_init(void)
/* Implementation of filll word (required by BootX) */ bind_func("filll", ffilll); + + bind_func("adler32", adler32);
bind_func("platform-boot", boot); bind_func("(go)", go);
This patch modifies the adler32 word to set an Apple copyright string in the device tree in order to allow Mac OS 9 to boot.
Signed-off-by: Cormac O'Brien i.am.cormac.obrien@gmail.com
--- arch/ppc/qemu/init.c | 2 +- arch/ppc/qemu/qemu.fs | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/arch/ppc/qemu/init.c b/arch/ppc/qemu/init.c index d31b8ba..a5073a3 100644 --- a/arch/ppc/qemu/init.c +++ b/arch/ppc/qemu/init.c @@ -1003,7 +1003,7 @@ arch_of_init(void) /* Implementation of filll word (required by BootX) */ bind_func("filll", ffilll);
- bind_func("adler32", adler32); + bind_func("(adler32)", adler32);
bind_func("platform-boot", boot); bind_func("(go)", go); diff --git a/arch/ppc/qemu/qemu.fs b/arch/ppc/qemu/qemu.fs index 458af1b..939985a 100644 --- a/arch/ppc/qemu/qemu.fs +++ b/arch/ppc/qemu/qemu.fs @@ -93,3 +93,31 @@ variable keyboard-phandle 0 keyboard-phandle ! :noname set-defaults ; PREPOST-initializer + +\ ------------------------------------------------------------------------- +\ Adler-32 wrapper +\ ------------------------------------------------------------------------- + +: adler32 ( adler buf len -- checksum ) + \ Since Mac OS 9 is the only system using this word, we take this + \ opportunity to inject a copyright message that is necessary for the + \ system to boot. + " /" find-package if + " set-property" $find if + ( adler buf len phandle xt ) + >r >r + " Copyright 1983-2001 Apple Computer, Inc. THIS MESSAGE FOR COMPATIBILITY ONLY" + encode-string " copyright" + r> r> execute + else + ." Can't find " type cr + then + then + + " (adler32)" $find if + execute + else + 3drop 0 + ." Can't find" type cr + then +;
Am 10.06.2015 um 01:21 schrieb Cormac O'Brien i.am.cormac.obrien@gmail.com:
This patch modifies the adler32 word to set an Apple copyright string in the device tree in order to allow Mac OS 9 to boot.
Signed-off-by: Cormac O'Brien i.am.cormac.obrien@gmail.com
arch/ppc/qemu/init.c | 2 +- arch/ppc/qemu/qemu.fs | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/arch/ppc/qemu/init.c b/arch/ppc/qemu/init.c index d31b8ba..a5073a3 100644 --- a/arch/ppc/qemu/init.c +++ b/arch/ppc/qemu/init.c @@ -1003,7 +1003,7 @@ arch_of_init(void) /* Implementation of filll word (required by BootX) */ bind_func("filll", ffilll);
- bind_func("adler32", adler32);
bind_func("(adler32)", adler32);
bind_func("platform-boot", boot); bind_func("(go)", go);
diff --git a/arch/ppc/qemu/qemu.fs b/arch/ppc/qemu/qemu.fs index 458af1b..939985a 100644 --- a/arch/ppc/qemu/qemu.fs +++ b/arch/ppc/qemu/qemu.fs @@ -93,3 +93,31 @@ variable keyboard-phandle 0 keyboard-phandle ! :noname set-defaults ; PREPOST-initializer
+\ ------------------------------------------------------------------------- +\ Adler-32 wrapper +\ -------------------------------------------------------------------------
+: adler32 ( adler buf len -- checksum )
- \ Since Mac OS 9 is the only system using this word, we take this
- \ opportunity to inject a copyright message that is necessary for the
- \ system to boot.
- " /" find-package if
- " set-property" $find if
( adler buf len phandle xt )
>r >r
" Copyright 1983-2001 Apple Computer, Inc. THIS MESSAGE FOR COMPATIBILITY ONLY"
Segher suggested that the code doesn't verify the year part, so you could make this "Copyright not-by Apple Computer, Inc."
Alex
encode-string " copyright"
r> r> execute
- else
." Can't find " type cr
- then
- then
- " (adler32)" $find if
- execute
- else
- 3drop 0
- ." Can't find" type cr
- then
+;
2.4.2
On Wed, Jun 10, 2015 at 11:03:45AM +0200, Alexander Graf wrote:
" Copyright 1983-2001 Apple Computer, Inc. THIS MESSAGE FOR COMPATIBILITY ONLY"
Segher suggested that the code doesn't verify the year part, so you could make this "Copyright not-by Apple Computer, Inc."
Not exactly that, the "year part" is exactly nine chars; it's a memcmp(s, ".. ", 10) and a memcmp(s+19, " ..", 21).
So my suggestion (on IRC?) was "Copyright OpenBIOS; Apple Computer, Inc. made Mac OS and that wants to see a string like this" or something like that.
Segher
On 10/06/15 15:19, Segher Boessenkool wrote:
On Wed, Jun 10, 2015 at 11:03:45AM +0200, Alexander Graf wrote:
" Copyright 1983-2001 Apple Computer, Inc. THIS MESSAGE FOR COMPATIBILITY ONLY"
Segher suggested that the code doesn't verify the year part, so you could make this "Copyright not-by Apple Computer, Inc."
Not exactly that, the "year part" is exactly nine chars; it's a memcmp(s, ".. ", 10) and a memcmp(s+19, " ..", 21).
So my suggestion (on IRC?) was "Copyright OpenBIOS; Apple Computer, Inc. made Mac OS and that wants to see a string like this" or something like that.
I'm actually okay with the wording in the patch above (the above text seems particularly long-winded). My personal opinion is that we should try and leave it close to the original as possible in case other versions of OS 9 and/or OS 8 check different parts of the copyright string if someone is interested enough to try and boot them with QEMU ;)
ATB,
Mark.
On 10/06/15 00:21, Cormac O'Brien wrote:
This patch modifies the adler32 word to set an Apple copyright string in the device tree in order to allow Mac OS 9 to boot.
I think it's worth mentioning something here along the lines of "Since OS 9 checks the copyright string on boot and the OS 9 bootloader is one of the only users of adler32, use this word as a convenient injection point for a fake copyright message which is enough to fool OS 9 into booting". It's really just nit-picking on clarifying the message in the source below.
Signed-off-by: Cormac O'Brien i.am.cormac.obrien@gmail.com
arch/ppc/qemu/init.c | 2 +- arch/ppc/qemu/qemu.fs | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/arch/ppc/qemu/init.c b/arch/ppc/qemu/init.c index d31b8ba..a5073a3 100644 --- a/arch/ppc/qemu/init.c +++ b/arch/ppc/qemu/init.c @@ -1003,7 +1003,7 @@ arch_of_init(void) /* Implementation of filll word (required by BootX) */ bind_func("filll", ffilll);
- bind_func("adler32", adler32);
bind_func("(adler32)", adler32);
bind_func("platform-boot", boot); bind_func("(go)", go);
diff --git a/arch/ppc/qemu/qemu.fs b/arch/ppc/qemu/qemu.fs index 458af1b..939985a 100644 --- a/arch/ppc/qemu/qemu.fs +++ b/arch/ppc/qemu/qemu.fs @@ -93,3 +93,31 @@ variable keyboard-phandle 0 keyboard-phandle ! :noname set-defaults ; PREPOST-initializer
+\ ------------------------------------------------------------------------- +\ Adler-32 wrapper +\ -------------------------------------------------------------------------
+: adler32 ( adler buf len -- checksum )
- \ Since Mac OS 9 is the only system using this word, we take this
- \ opportunity to inject a copyright message that is necessary for the
- \ system to boot.
- " /" find-package if
- " set-property" $find if
( adler buf len phandle xt )
>r >r
" Copyright 1983-2001 Apple Computer, Inc. THIS MESSAGE FOR COMPATIBILITY ONLY"
encode-string " copyright"
r> r> execute
You should be able to get away with not using the R stack here - have a look at using 2swap instead.
- else
." Can't find " type cr
Whilst it's nice to have error checking, I could probably live without this particular else clause, since if the / node in the device tree is missing then the adler32 word is likely to be the very least of our problems...
- then
- then
- " (adler32)" $find if
- execute
- else
- 3drop 0
- ." Can't find" type cr
Maybe add (adler32) here so we know what can't be found?
- then
+;
Other than that, I think the patch looks good.
ATB,
Mark.
On 10/06/15 00:21, Cormac O'Brien wrote:
This patch adds an Adler-32 checksum function to OpenBIOS as required by Mac OS 9. This and the copyright patch have been split as requested by Mark Cave-Ayland.
Heh. I wouldn't worry about that last sentence, although I can fix that up on commit.
Signed-off-by: Cormac O'Brien i.am.cormac.obrien@gmail.com
arch/ppc/qemu/init.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+)
diff --git a/arch/ppc/qemu/init.c b/arch/ppc/qemu/init.c index 4fe8b72..f261e82 100644 --- a/arch/ppc/qemu/init.c +++ b/arch/ppc/qemu/init.c @@ -680,6 +680,58 @@ static void ffilll(void) } }
+/*
- adler32 ( adler buf len -- checksum )
- Adapted from Mark Adler's original implementation (zlib license)
- */
+#define DO1(buf,i) {s1 += buf[i]; s2 += s1;} +#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); +#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); +#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); +#define DO16(buf) DO8(buf,0); DO8(buf,8);
+static void adler32(void) +{
- uint32_t len = (uint32_t)POP();
- char *buf = (char *)POP();
- uint32_t adler = (uint32_t)POP();
- if (buf == NULL) {
RET(-1);
- }
- uint32_t base = 65521;
- uint32_t nmax = 5552;
- uint32_t s1 = adler & 0xffff;
- uint32_t s2 = (adler >> 16) & 0xffff;
- uint32_t k;
- while (len > 0) {
k = (len < nmax ? len : nmax);
len -= k;
while (k >= 16) {
DO16(buf);
buf += 16;
k -= 16;
}
if (k != 0) {
do {
s1 += *buf++;
s2 += s1;
} while (--k);
}
s1 %= base;
s2 %= base;
- }
- RET(s2 << 16 | s1);
+}
void arch_of_init(void) { @@ -945,6 +997,8 @@ arch_of_init(void)
/* Implementation of filll word (required by BootX) */ bind_func("filll", ffilll);
Small comment here about adler32 word being used by OS 9 (and possibly BootX according to Alex)? I know it's in the commit log but it's unusual enough that it's worth noting its users so we know which OSs we need to test if we decide to tweak the function in future (e.g. come up with a libopenbios version that works cross-architecture).
bind_func("adler32", adler32);
bind_func("platform-boot", boot); bind_func("(go)", go);
I'll compile-test it shortly, but the basic patch looks fairly solid. Given that QEMU freeze is coming up in a few days, I'll probably bundle up what we have in trunk now for 2.4 before committing this so then we have the freedom of the tree for the remainder of the summer :)
ATB,
Mark.