Advertisement
Guest User

Untitled

a guest
Jun 18th, 2015
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.20 KB | None | 0 0
  1. From 1113c9e1def4cb7b9ed3f232ccc8eea268c1265e Mon Sep 17 00:00:00 2001
  2. From: Cormac O'Brien <i.am.cormac.obrien@gmail.com>
  3. Date: Thu, 18 Jun 2015 14:37:48 -0500
  4. Subject: [PATCH] ppc: add Adler-32 checksum capability
  5.  
  6. This patch provides an implementation of the adler32 Forth word as required by
  7. Mac OS 9 and BootX.
  8.  
  9. Signed-off-by: Cormac O'Brien <i.am.cormac.obrien@gmail.com>
  10.  
  11. ---
  12. arch/ppc/qemu/init.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++
  13. 1 file changed, 57 insertions(+)
  14.  
  15. diff --git a/arch/ppc/qemu/init.c b/arch/ppc/qemu/init.c
  16. index 4fe8b72..5cc45ae 100644
  17. --- a/arch/ppc/qemu/init.c
  18. +++ b/arch/ppc/qemu/init.c
  19. @@ -680,6 +680,60 @@ static void ffilll(void)
  20. }
  21. }
  22.  
  23. +/*
  24. + * adler32 ( adler buf len -- checksum )
  25. + *
  26. + * Adapted from Mark Adler's original implementation (zlib license)
  27. + *
  28. + * Both OS 9 and BootX require this word for payload validation.
  29. + */
  30. +
  31. +#define DO1(buf,i) {s1 += buf[i]; s2 += s1;}
  32. +#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
  33. +#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
  34. +#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
  35. +#define DO16(buf) DO8(buf,0); DO8(buf,8);
  36. +
  37. +static void adler32(void)
  38. +{
  39. + uint32_t len = (uint32_t)POP();
  40. + char *buf = (char *)POP();
  41. + uint32_t adler = (uint32_t)POP();
  42. +
  43. + if (buf == NULL) {
  44. + RET(-1);
  45. + }
  46. +
  47. + uint32_t base = 65521;
  48. + uint32_t nmax = 5552;
  49. +
  50. + uint32_t s1 = adler & 0xffff;
  51. + uint32_t s2 = (adler >> 16) & 0xffff;
  52. +
  53. + uint32_t k;
  54. + while (len > 0) {
  55. + k = (len < nmax ? len : nmax);
  56. + len -= k;
  57. +
  58. + while (k >= 16) {
  59. + DO16(buf);
  60. + buf += 16;
  61. + k -= 16;
  62. + }
  63. + if (k != 0) {
  64. + do {
  65. + s1 += *buf++;
  66. + s2 += s1;
  67. + } while (--k);
  68. + }
  69. +
  70. + s1 %= base;
  71. + s2 %= base;
  72. + }
  73. +
  74. + RET(s2 << 16 | s1);
  75. +}
  76. +
  77. void
  78. arch_of_init(void)
  79. {
  80. @@ -945,6 +999,9 @@ arch_of_init(void)
  81.  
  82. /* Implementation of filll word (required by BootX) */
  83. bind_func("filll", ffilll);
  84. +
  85. + /* Implementation of adler32 word (required by OS 9, BootX) */
  86. + bind_func("adler32", adler32);
  87.  
  88. bind_func("platform-boot", boot);
  89. bind_func("(go)", go);
  90. --
  91. 2.4.4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement