2 /******************************************************************************
5 * Copyright: Telford Tools, Inc.
8 * Copyright (C) 2001 By Joachim Martillo, Telford Tools, Inc.
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
15 ******************************************************************************
17 /******************************************************************************
18 * REVISION HISTORY: (Most Recent First)
19 * -------------------------------------
20 * 2-Apr-91 ALEX Introduced "fn_calc_novram_crc32()".
21 ******************************************************************************
24 /****************************************************/
26 /****************************************************/
31 /****************************************************/
33 /****************************************************/
35 #define k_poly ((unsigned int)(0xedb88320))
36 #define k_crc_table_size (256)
39 pragma Code ("rkernel");
40 pragma Off(cross_jump);
43 /****************************************************/
45 /****************************************************/
48 pragma Data (Export,"fastbss");
49 #endif // defined(AMD29K)
51 unsigned int gg_a_crc_table[k_crc_table_size];
55 #endif // defined(AMD29K)
58 /****************************************************/
59 /* global procedures */
60 /****************************************************/
67 for (i_table = 0; i_table < k_crc_table_size; i_table++)
69 unsigned int result = 0;
72 for (i_bit = 0; i_bit < 8; i_bit++)
74 unsigned int bit = ((i_table & (1 << i_bit)) != 0);
76 if ((bit ^ (result & 1)) != 0)
77 result = (result >> 1) ^ k_poly;
82 gg_a_crc_table[i_table] = result;
85 } /* end of fn_init_crc_table */
87 /****************************************************/
90 fn_calc_memory_chunk_crc32(void *p, unsigned int n_bytes, unsigned int crc)
92 unsigned char *p_uc = (unsigned char*)p;
93 unsigned int result = ~crc;
97 result = (result >> 8) ^ gg_a_crc_table[(result ^ *p_uc++) & 0xff];
102 } /* end of fn_calc_memory_chunk_crc32 */
104 /****************************************************/
107 fn_calc_memory_crc32(void *p, unsigned int n_bytes)
109 fnm_assert_stmt(n_bytes > 4);
111 return(fn_calc_memory_chunk_crc32(p, n_bytes, k_initial_crc_value));
113 } /* end of fn_calc_memory_crc32 */
115 /****************************************************/
118 fn_check_memory_crc32(void *p, unsigned int n_bytes, unsigned int crc)
120 return(fn_calc_memory_crc32(p, n_bytes) == crc);
122 } /* end of fn_check_memory_crc32 */
125 /****************************************************/
126 /* Adds current longword to the crc value and */
127 /* returns that value. */
129 fn_update_crc(char *val, unsigned int crcval)
133 /* ----< break long into bytes >---- */
134 /* ----< put bytes into crc >---- */
135 for (i = 0; i < 4; i++)
137 crcval = gg_a_crc_table[(crcval ^ val[i]) & 0xff] ^
138 ((crcval >> 8) & 0x00ffffff);
141 } /* endfunc--fn_update_crc */
144 /****************************************************/
145 /****************************************************/
146 /* End source file "crc32.c" */
147 /****************************************************/
148 /****************************************************/