Annotation of researchv9/jerq/src/32ld/pcheck.c, revision 1.1

1.1     ! root        1: /*
        !             2: **     Packet check bytes calculation
        !             3: */
        !             4: 
        !             5: #ifdef vax
        !             6: /*
        !             7: **     Vax "crc" instruction look-up table for polynomial = 0120001
        !             8: */
        !             9: 
        !            10: unsigned long  crc16t[] =
        !            11: {
        !            12:               0, 0146001, 0154001,  012000, 0170001,  036000,  024000, 0162001
        !            13:        ,0120001,  066000,  074000, 0132001,  050000, 0116001, 0104001,  042000
        !            14: };
        !            15: 
        !            16: /*ARGSUSED*/
        !            17: int
        !            18: crc(s, n)
        !            19:        unsigned char * s;
        !            20:        int             n;
        !            21: {
        !            22:        asm("   crc     _crc16t,$0,8(ap),*4(ap) ");
        !            23:        asm("   cmpw    r0,(r3)                 ");
        !            24:        asm("   beqlu   OK                      ");
        !            25:        asm("   movw    r0,(r3)                 ");
        !            26:        asm("   movl    $1,r0                   ");
        !            27:        asm("   ret                             ");
        !            28:        asm("OK:movw    r0,(r3)                 ");
        !            29:        return 0;
        !            30: }
        !            31: 
        !            32: #else  vax
        !            33: 
        !            34: 
        !            35: /*
        !            36: **     crc-16:  x**16 + x**15 + x**2 + 1
        !            37: */
        !            38: 
        !            39: typedef unsigned char  uchar;
        !            40: typedef unsigned short ushort;
        !            41: 
        !            42: #define        lobyte(X)       (X&0xff)
        !            43: #define        hibyte(X)       ((X>>8)&0xff)
        !            44: 
        !            45: ushort crc16t_32[2][16]        =
        !            46: {
        !            47:        0, 0140301, 0140601, 0500, 0141401, 01700, 01200, 0141101,
        !            48:        0143001, 03300, 003600, 0143501, 02400, 0142701, 0142201, 02100,
        !            49:        0, 0146001, 0154001, 012000, 0170001, 036000, 024000, 0162001,
        !            50:        0120001, 066000, 074000, 0132001, 050000, 0116001, 0104001, 042000
        !            51: };
        !            52: 
        !            53: /*#ifndef      mc68000*/
        !            54: int
        !            55: crc(buffer, nbytes)
        !            56:        register uchar *buffer;
        !            57:        int             nbytes;
        !            58: {
        !            59:        register ushort tcrc = 0;
        !            60:        register int    temp;
        !            61:        register int    i;
        !            62: 
        !            63:        if ( (i = nbytes) > 0 )
        !            64:        do
        !            65:        {
        !            66:                temp = tcrc ^ *buffer++;
        !            67:                tcrc = crc16t_32[0][temp & 017]
        !            68:                         ^ crc16t_32[1][(temp>>4) & 017]
        !            69:                         ^ (tcrc>>8);
        !            70:        }
        !            71:        while
        !            72:                ( --i > 0 );
        !            73: 
        !            74:        if ( lobyte(tcrc) != *buffer )
        !            75:                i++;
        !            76:        *buffer++ = lobyte(tcrc);
        !            77: 
        !            78:        if ( hibyte(tcrc) != *buffer )
        !            79:                i++;
        !            80:        *buffer++ = hibyte(tcrc);
        !            81: 
        !            82:        return i;
        !            83: }
        !            84: /*#else        mc68000
        !            85: asm("  text                    ");
        !            86: asm("  global  crc             ");
        !            87: asm("crc:                      ");
        !            88: asm("  link    %fp,&crcF       ");
        !            89: asm("  movm.l  &crcM,crcS(%fp) ");
        !            90: asm("  mov.l   8(%fp),%a2      ");
        !            91: asm("  mov.l   &0,%d2          ");
        !            92: asm("  mov.w   12(%fp),%d4     ");
        !            93: asm("  ble     crc%140         ");
        !            94: asm("crc%170:                  ");
        !            95: asm("  mov.b   (%a2)+,%d3      ");
        !            96: asm("  eor.b   %d2,%d3         ");
        !            97: asm("  mov.l   &15,%d0         ");
        !            98: asm("  and.b   %d3,%d0         ");
        !            99: asm("  add.l   %d0,%d0         ");
        !           100: asm("  mov.l   &crc16t_3,%a1   ");
        !           101: asm("  mov.w   0(%a1,%d0.l),%d0");
        !           102: asm("  lsr.b   &3,%d3          ");
        !           103: asm("  and.w   &30,%d3         ");
        !           104: asm("  mov.l   &crc16t_3+32,%a0");
        !           105: asm("  mov.w   0(%a0,%d3.w),%d1");
        !           106: asm("  eor.w   %d0,%d1         ");
        !           107: asm("  lsr.w   &8,%d2          ");
        !           108: asm("  eor.w   %d1,%d2         ");
        !           109: asm("  sub.w   &1,%d4          ");
        !           110: asm("  bgt     crc%170         ");
        !           111: asm("crc%140:                  ");
        !           112: asm("  cmp.b   %d2,(%a2)       ");
        !           113: asm("  beq     crc%180         ");
        !           114: asm("  add.w   &1,%d4          ");
        !           115: asm("crc%180:                  ");
        !           116: asm("  mov.b   %d2,(%a2)+      ");
        !           117: asm("  lsr.w   &8,%d2          ");
        !           118: asm("  cmp.b   %d2,(%a2)       ");
        !           119: asm("  beq     crc%190         ");
        !           120: asm("  add.w   &1,%d4          ");
        !           121: asm("crc%190:                  ");
        !           122: asm("  mov.b   %d2,(%a2)+      ");
        !           123: asm("  mov.w   %d4,%d0         ");
        !           124: asm("  movm.l  crcS(%fp),&crcM ");
        !           125: asm("  unlk    %fp             ");
        !           126: asm("  rts                     ");
        !           127: asm("  set     crcS,-16        ");
        !           128: asm("  set     crcF,-22        ");
        !           129: asm("  set     crcM,02034      ");
        !           130: #endif mc68000 */
        !           131: #endif vax

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.