From: Cormac O'Brien cormac@c-obrien.org
--- 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..f9989ed 100644 --- a/arch/ppc/qemu/init.c +++ b/arch/ppc/qemu/init.c @@ -680,6 +680,57 @@ static void ffilll(void) } }
+/* adler32 (len buf adler -- checksum) + * + * Adapted from Mark Adler's zlib implementation */ + +#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 = POP(); + char *buf = POP(); + uint32_t adler = 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 +996,9 @@ arch_of_init(void)
/* Implementation of filll word (required by BootX) */ bind_func("filll", ffilll); + + /* Implementation of Adler-32 required by Mac OS 9 */ + bind_func("adler32", adler32);
bind_func("platform-boot", boot); bind_func("(go)", go);
Am 19.04.2015 um 20:07 schrieb Cormac O'Brien:
From: Cormac O'Brien cormac@c-obrien.org
Not sure how strict we take this for OpenBIOS these days, but I notice that you haven't signed this off. You mention below another implementation - what license is that under, and did you copy code or just the algorithm? Would be worth a mention in the commit message.
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..f9989ed 100644 --- a/arch/ppc/qemu/init.c +++ b/arch/ppc/qemu/init.c @@ -680,6 +680,57 @@ static void ffilll(void) } }
+/* adler32 (len buf adler -- checksum)
- Adapted from Mark Adler's zlib implementation */
FWIW this end-of-comment looks unusual...
+#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 = POP();
- char *buf = POP();
- uint32_t adler = 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 +996,9 @@ arch_of_init(void)
/* Implementation of filll word (required by BootX) */ bind_func("filll", ffilll);
- /* Implementation of Adler-32 required by Mac OS 9 */
- bind_func("adler32", adler32);
I know OpenBIOS is inconsistent at this in places, but please make sure the two lines you add use the same indentation. :) Surrounding lines seem to use four spaces, not tabs.
bind_func("platform-boot", boot); bind_func("(go)", go);
Regards, Andreas
On 19/04/15 19:07, Cormac O'Brien wrote:
From: Cormac O'Brien cormac@c-obrien.org
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..f9989ed 100644 --- a/arch/ppc/qemu/init.c +++ b/arch/ppc/qemu/init.c @@ -680,6 +680,57 @@ static void ffilll(void) } }
+/* adler32 (len buf adler -- checksum)
I think this stack diagram is back-to-front?
- Adapted from Mark Adler's zlib implementation */
+#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 = POP();
- char *buf = POP();
- uint32_t adler = 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 +996,9 @@ arch_of_init(void)
/* Implementation of filll word (required by BootX) */ bind_func("filll", ffilll);
/* Implementation of Adler-32 required by Mac OS 9 */
bind_func("adler32", adler32);
bind_func("platform-boot", boot); bind_func("(go)", go);
One thing to think about here is the subject line: I'd probably go for a "ppc:" or similar prefix in order for two reasons: firstly there is more than one init.c in the codebase, and secondly it's easy to tell from the git shortlog that this patch only affects PPC and no other architecture.
Possibly there are a few minor whitespace changes that need some touching up, but I'm generally happy with the mechanics of this patch - I think with these minor points taken care of and a Signed-off-by then this is ready for commit.
ATB,
Mark.
On 20/04/15 14:07, Andreas Färber wrote:
Am 19.04.2015 um 20:07 schrieb Cormac O'Brien:
From: Cormac O'Brien cormac@c-obrien.org
Not sure how strict we take this for OpenBIOS these days, but I notice that you haven't signed this off. You mention below another implementation - what license is that under, and did you copy code or just the algorithm? Would be worth a mention in the commit message.
According to Wikipedia (*ahem*), the zlib license is deemed GPL-compatible so I don't believe the license should be an issue here.
ATB,
Mark.
On 2015-Apr-20 15:39 , Mark Cave-Ayland wrote:
According to Wikipedia (*ahem*), the zlib license is deemed GPL-compatible so I don't believe the license should be an issue here.
Please don't quote Wikipedia, quote the source it cites:
https://www.gnu.org/licenses/license-list.html#ZLib
According to *Gnu.org*, Zlib is compatible with the GPL.
On 20/04/15 20:42, Tarl Neustaedter wrote:
On 2015-Apr-20 15:39 , Mark Cave-Ayland wrote:
According to Wikipedia (*ahem*), the zlib license is deemed GPL-compatible so I don't believe the license should be an issue here.
Please don't quote Wikipedia, quote the source it cites:
https://www.gnu.org/licenses/license-list.html#ZLib
According to *Gnu.org*, Zlib is compatible with the GPL.
Ha indeed - much better :)
ATB,
Mark.