]> code.delx.au - refind/blobdiff - refind/crc32.h
CRC32 functions
[refind] / refind / crc32.h
diff --git a/refind/crc32.h b/refind/crc32.h
new file mode 100644 (file)
index 0000000..f7c7639
--- /dev/null
@@ -0,0 +1,58 @@
+/*-\r
+ *  COPYRIGHT (C) 1986 Gary S. Brown.  You may use this program, or\r
+ *  code or tables extracted from it, as desired without restriction.\r
+ *\r
+ *  First, the polynomial itself and its table of feedback terms.  The\r
+ *  polynomial is\r
+ *  X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0\r
+ *\r
+ *  Note that we take it "backwards" and put the highest-order term in\r
+ *  the lowest-order bit.  The X^32 term is "implied"; the LSB is the\r
+ *  X^31 term, etc.  The X^0 term (usually shown as "+1") results in\r
+ *  the MSB being 1\r
+ *\r
+ *  Note that the usual hardware shift register implementation, which\r
+ *  is what we're using (we're merely optimizing it by doing eight-bit\r
+ *  chunks at a time) shifts bits into the lowest-order term.  In our\r
+ *  implementation, that means shifting towards the right.  Why do we\r
+ *  do it this way?  Because the calculated CRC must be transmitted in\r
+ *  order from highest-order term to lowest-order term.  UARTs transmit\r
+ *  characters in order from LSB to MSB.  By storing the CRC this way\r
+ *  we hand it to the UART in the order low-byte to high-byte; the UART\r
+ *  sends each low-bit to hight-bit; and the result is transmission bit\r
+ *  by bit from highest- to lowest-order term without requiring any bit\r
+ *  shuffling on our part.  Reception works similarly\r
+ *\r
+ *  The feedback terms table consists of 256, 32-bit entries.  Notes\r
+ *\r
+ *      The table can be generated at runtime if desired; code to do so\r
+ *      is shown later.  It might not be obvious, but the feedback\r
+ *      terms simply represent the results of eight shift/xor opera\r
+ *      tions for all combinations of data and CRC register values\r
+ *\r
+ *      The values must be right-shifted by eight bits by the "updcrc\r
+ *      logic; the shift must be unsigned (bring in zeroes).  On some\r
+ *      hardware you could probably optimize the shift in assembler by\r
+ *      using byte-swap instructions\r
+ *      polynomial $edb88320\r
+ *\r
+ *\r
+ * CRC32 code derived from work by Gary S. Brown.\r
+ */\r
+/*\r
+ * Modified slightly for use on EFI by Rod Smith\r
+ */\r
+\r
+#ifndef __CRC32_H_\r
+#define __CRC32_H_\r
+\r
+#ifdef __MAKEWITH_GNUEFI\r
+#include "efi.h"\r
+#include "efilib.h"\r
+#else\r
+#include "../include/tiano_includes.h"\r
+#endif\r
+\r
+UINT32 crc32(UINT32 crc, const VOID *buf, UINTN size);\r
+\r
+#endif
\ No newline at end of file