[OpenBIOS] [PATCH] ppc: add Adler-32 checksum support

Mark Cave-Ayland mark.cave-ayland at ilande.co.uk
Thu May 14 00:14:04 CEST 2015


On 10/05/15 15:36, Cormac O'Brien wrote:

> This patch adds an Adler-32 checksum word to the Forth dictionary, as 
> required by Mac OS 9.
> 
> Signed-off-by: Cormac O'Brien <i.am.cormac.obrien at gmail.com>
> Reviewed-by: Mark Cave-Ayland <mark.cave-ayland at ilande.co.uk>
> 
> ---
>  arch/ppc/qemu/init.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 55 insertions(+)
> 
> diff --git a/arch/ppc/qemu/init.c b/arch/ppc/qemu/init.c
> index 4fe8b72..682d6a2 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 = 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 +997,9 @@ arch_of_init(void)
>  
>      /* Implementation of filll word (required by BootX) */
>      bind_func("filll", ffilll);
> +
> +    /* Adler-32 required by Mac OS 9 */
> +    bind_func("adler32", adler32);
>      
>      bind_func("platform-boot", boot);
>      bind_func("(go)", go);

Unfortunately this fails for me on a compile test:

/home/build/src/openbios/openbios-git/openbios-devel/arch/ppc/qemu/init.c:
In function ‘adler32’:
/home/build/src/openbios/openbios-git/openbios-devel/arch/ppc/qemu/init.c:698:17:
error: initialization makes pointer from integer without a cast [-Werror]
     char *buf = POP();
                 ^
cc1: all warnings being treated as errors
make[1]: *** [target/arch/ppc/qemu/init.o] Error 1
make[1]: Leaving directory
`/home/build/src/openbios/openbios-git/openbios-devel/obj-ppc'
make: *** [build] Error 1


ATB,

Mark.




More information about the OpenBIOS mailing list