]> cvs.zerfleddert.de Git - rsbs2/blame_incremental - rsb-crc.c
add something like the agilent crc implementation
[rsbs2] / rsb-crc.c
... / ...
CommitLineData
1#define POLY 0x04c11db7
2
3/* Theory of operation:
4 * (arm-elf-objdump -b binary -m arm -M reg-names-raw -D RSB_S2_SINGLE.bin)
5 *
6 * 440: push {r4, r5, r6, r7, r8, r9, r10, r11, r14}
7 * 444: mov r11, r0
8 * 448: mov r10, r1
9 * 44c: mov r14, r2
10 * 450: mov r6, #0 ; 0x0
11 * 454: b 0x4a0
12 * 458: add r3, r6, r10
13 * 45c: ldrb r3, [r3]
14 * 460: lsl r3, r3, #24
15 * 464: eor r11, r11, r3
16 * 468: mov r5, #8 ; 0x8
17 * 46c: and r3, r11, #-2147483648 ; 0x80000000
18 * 470: cmp r3, #0 ; 0x0
19 * 474: beq 0x48c
20 * 478: lsl r3, r11, #1
21 * 47c: ldr r12, [pc, #64] ; 0x4c4
22 * 480: eor r0, r3, r12
23 * 484: mov r11, r0
24 * 488: b 0x490
25 * 48c: lsl r11, r11, #1
26 * 490: sub r5, r5, #1 ; 0x1
27 * 494: cmp r5, #0 ; 0x0
28 * 498: bne 0x46c
29 * 49c: add r6, r6, #1 ; 0x1
30 * 4a0: cmp r6, r14
31 * 4a4: blt 0x458
32 * 4a8: mov r0, r11
33 * 4ac: pop {r4, r5, r6, r7, r8, r9, r10, r11, r15}
34 * 4c4: DATA: 0x04c11db7
35 */
36
37unsigned int rsb_crc(unsigned int r11, unsigned char *r10, unsigned int r14) {
38 unsigned int r6 = 0;
39 unsigned int r3;
40 int r5;
41
42 while (r6 < r14) {
43 r3 = (*(r6+r10)) << 24;
44 r11 = r11 ^ r3;
45
46 r5 = 8;
47
48 do {
49 r3 = r11 & 0x80000000;
50
51 if (r3 != 0) {
52 r3 = r11 << 1;
53 r11 = r3 ^ POLY;
54 } else {
55 r11 = r11 << 1;
56 }
57 r5--;
58 } while (r5);
59
60 r6++;
61 }
62
63 return r11;
64}
Impressum, Datenschutz