Annotation of coherent/b/STREAMS/i386/memory.s, revision 1.1

1.1     ! root        1: / memory-move operations for the Coherent kernel. The functions called here
        !             2: / do exactly the same thing as the regular C library version.
        !             3: 
        !             4:                .unixorder
        !             5: 
        !             6:                .globl  memset
        !             7: 
        !             8: dest           =       4
        !             9: ch             =       8
        !            10: len            =       12
        !            11: 
        !            12: memset:
        !            13:                movzxb  ch(%esp), %eax          / Fill pattern to %eax
        !            14:                movl    $0x01010101, %ecx       / Replicate fill byte into
        !            15:                mull    %ecx, %eax              / all of %eax (4 copies)
        !            16:                                                / (overwrites %edx too)
        !            17: 
        !            18:                movl    %edi, %edx              / Save %edi
        !            19:                movl    dest(%esp), %edi        / Get dest to %edi
        !            20: 
        !            21:                movl    len(%esp), %ecx         / Get length
        !            22:                shrl    $2, %ecx                / in longwords
        !            23: 
        !            24:                cld                             / Fill upwards
        !            25:                rep stosl                       / Perform the fill
        !            26: 
        !            27:                jnc     ?noword                 / Skip over residual word copy
        !            28: 
        !            29:                stosw
        !            30: ?noword:
        !            31:                testb   $1, len(%esp)           / Check low part of count
        !            32:                je      ?nobyte                 / Skip over residual byte copy
        !            33: 
        !            34:                stosb
        !            35: ?nobyte:
        !            36:                movl    %edx, %edi              / Restore %edi
        !            37:                movl    dest(%esp), %eax        / Return destination
        !            38:                ret
        !            39: 
        !            40: 
        !            41:                .globl  memcpy
        !            42: 
        !            43: dest           =       4
        !            44: src            =       8
        !            45: len            =       12
        !            46: 
        !            47: memcpy:
        !            48:                movl    %esi, %eax              / Save %esi
        !            49:                movl    src(%esp), %esi         / Get src
        !            50: 
        !            51:                movl    %edi, %edx              / Save %edi
        !            52:                movl    dest(%esp), %edi        / Get dest
        !            53: 
        !            54:                movl    len(%esp), %ecx         / Get length
        !            55:                shrl    $2, %ecx                / in longwords
        !            56: 
        !            57:                cld                             / Copy upwards
        !            58:                rep movsl                       / in longwords
        !            59: 
        !            60:                jnc     ?noword                 / Skip residual word copy
        !            61: 
        !            62:                movsw
        !            63: ?noword:
        !            64:                testb   $1, len(%esp)           / Check low byte of length
        !            65:                je      ?nobyte                 / Skip residual byte copy
        !            66: 
        !            67:                movsb
        !            68: ?nobyte:
        !            69:                movl    %edx, %edi              / Restore %edi
        !            70:                movl    %eax, %esi              / Restore %esi
        !            71:                movl    dest(%esp), %eax        / Return destination
        !            72:                ret
        !            73: 
        !            74: / String comparison with length limit.
        !            75: 
        !            76:                .globl  strncmp
        !            77: 
        !            78: left           =       4
        !            79: right          =       8
        !            80: len            =       12
        !            81: 
        !            82: strncmp:
        !            83:                movl    len(%esp), %ecx         / Maximum length
        !            84:                jecxz   ?strncmp_empty
        !            85: 
        !            86:                movl    %esi, %edx              / Preserve %esi
        !            87:                movl    left(%esp), %esi        / Get left
        !            88: 
        !            89:                pushl   %edi                    / Preserve %edi
        !            90:                movl    right+4(%esp), %edi     / Get right, adjusting the
        !            91:                                                / stack offset for push
        !            92: 
        !            93:                cld                             / Scan upwards
        !            94:                xorl    %eax, %eax              / Zero top bytes in %eax
        !            95: 
        !            96: ?strncmp_loop: lodsb                           / %al = * %ds:%esi ++
        !            97:                scasb                           / * %es:%edi ++ - %al ?
        !            98:                jne     ?strncmp_noteq
        !            99:                orb     %al, %al                / %al == 0 ?
        !           100:                loopne  ?strncmp_loop
        !           101: 
        !           102: / Either %al == 0 or %ecx == 0, and we have a match. Zero %eax
        !           103:                xorl    %eax, %eax
        !           104:                popl    %edi                    / Restore %edi
        !           105:                movl    %edx, %esi              / Restore %esi
        !           106:                ret
        !           107: 
        !           108: ?strncmp_noteq:
        !           109:                movb    $1, %al
        !           110:                ja      ?strncmp_less           / Branch if %al was > * right
        !           111:                                                / hence return %eax == 1
        !           112:                negl    %eax                    / Here if %al < * right,
        !           113:                                                / hence return %eax == -1
        !           114: ?strncmp_less:
        !           115:                popl    %edi                    / Restore %edi
        !           116:                movl    %edx, %esi              / Restore %esi
        !           117:                ret
        !           118: 
        !           119: ?strncmp_empty:        xorl    %eax, %eax              / Count == 0 => left == right
        !           120:                ret

unix.superglobalmegacorp.com

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