~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Bochs x86 Emulator
bochs/crc.cc

Version: ~ [ 2.3.5 ] ~ [ 2.3 ] ~

** Warning: Cannot open xref database.

1 ///////////////////////////////////////////////////////////////////////// 2 // $Id: crc.cc,v 1.1 2006/01/24 19:03:53 sshwarts Exp $ 3 ///////////////////////////////////////////////////////////////////////// 4 // 5 // I grabbed these CRC routines from the following source: 6 // http://www.landfield.com/faqs/compression-faq/part1/section-25.html 7 // 8 // These routines are very useful, so I'm including them in bochs. 9 // They are not covered by the license, as they are not my doing. 10 // My gratitude to the author for offering them on the 'net. 11 // 12 // I only changed the u_long to Bit32u, and u_char to Bit8u, and gave 13 // the functions prototypes. 14 // 15 // -Kevin 16 // 17 // ************************************************************************** 18 // The following C code (by Rob Warnock <rpw3@sgi.com>) does CRC-32 in 19 // BigEndian/BigEndian byte/bit order. That is, the data is sent most 20 // significant byte first, and each of the bits within a byte is sent most 21 // significant bit first, as in FDDI. You will need to twiddle with it to do 22 // Ethernet CRC, i.e., BigEndian/LittleEndian byte/bit order. [Left as an 23 // exercise for the reader.] 24 // 25 // The CRCs this code generates agree with the vendor-supplied Verilog models 26 // of several of the popular FDDI "MAC" chips. 27 // ************************************************************************** 28 29 #include "config.h" 30 31 /* Initialized first time "crc32()" is called. If you prefer, you can 32 * statically initialize it at compile time. [Another exercise.] 33 */ 34 static Bit32u crc32_table[256]; 35 36 /* 37 * Build auxiliary table for parallel byte-at-a-time CRC-32. 38 */ 39 #define CRC32_POLY 0x04c11db7 /* AUTODIN II, Ethernet, & FDDI */ 40 41 static void init_crc32(void) 42 { 43 int i, j; 44 Bit32u c; 45 46 for (i = 0; i < 256; ++i) { 47 for (c = i << 24, j = 8; j > 0; --j) 48 c = c & 0x80000000 ? (c << 1) ^ CRC32_POLY : (c << 1); 49 crc32_table[i] = c; 50 } 51 } 52 53 Bit32u crc32(const Bit8u *buf, int len) 54 { 55 const Bit8u *p; 56 Bit32u crc; 57 58 if (!crc32_table[1]) /* if not already done, */ 59 init_crc32(); /* build table */ 60 61 crc = 0xffffffff; /* preload shift register, per CRC-32 spec */ 62 for (p = buf; len > 0; ++p, --len) 63 crc = (crc << 8) ^ crc32_table[(crc >> 24) ^ *p]; 64 return ~crc; /* transmit complement, per CRC-32 spec */ 65 } 66

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.