unixALib.s
上传用户:baixin
上传日期:2008-03-13
资源大小:4795k
文件大小:5k
开发平台:

MultiPlatform

  1. /* unixALib.s - i80x86 network assembly routines */
  2. /* Copyright 1984-2001 Wind River Systems, Inc. */
  3. /*
  4. modification history
  5. --------------------
  6. 01f,22aug01,hdn  added FUNC/FUNC_LABEL, replaced .align with .balign
  7. 01e,15sep93,hdn  deleted 486 specific functions ntohl() etc.
  8. 01d,01jun93,hdn  updated to 5.1.
  9.   - fixed #else and #endif
  10.   - changed VOID to void
  11.   - changed ASMLANGUAGE to _ASMLANGUAGE
  12.   - changed copyright notice
  13. 01c,26mar93,hdn  added ntohl for 486's new instruction bswap.
  14. 01b,18nov92,hdn  fixed a bug in cksum.
  15. 01a,07apr92,hdn  written based on TRON version.
  16. */ 
  17. #define _ASMLANGUAGE
  18. #include "vxWorks.h"
  19. #include "asm.h"
  20. .data
  21. .globl FUNC(copyright_wind_river)
  22. .long FUNC(copyright_wind_river)
  23. #ifndef PORTABLE
  24. /* internals */
  25. .globl GTEXT(cksum)
  26. .globl  GTEXT(_insque)
  27. .globl  GTEXT(_remque)
  28. .text
  29. .balign 16
  30. /**************************************************************************
  31. * cksum - compute check sum
  32. *
  33. * return 16bit one's complement sum of 'sum' and the 16bit one's 
  34. * complement sum of the string 'string' of byte length 'len'.
  35. * Complicated by 'len' or 'sumlen' not being even.
  36. *
  37. * RETURNS  int
  38. *
  39. * int cksum (sum, string, len, sumlen);
  40. */ 
  41. FUNC_LABEL(cksum)
  42. pushl %ebx
  43. pushl %esi
  44. movl SP_ARG1+8(%esp),%eax /* sum */
  45. movl SP_ARG2+8(%esp),%esi /* addr */
  46. movl SP_ARG3+8(%esp),%edx /* len */
  47. testl $1,SP_ARG4+8(%esp) /* previously summed len */
  48. je ckEvenSum
  49. xorl %ecx,%ecx
  50. movb (%esi),%ch /* move the first byte into %ch */
  51. clc /* clear C flag */
  52. adcl %ecx,%eax /* add the 1st byte before others */
  53. incl %esi /* addr+=1 */
  54. decl %edx /* len-=1 */
  55. ckEvenSum:
  56. movl %edx,%ecx
  57. movl %edx,%ebx
  58. andl $3,%ebx /* %ebx = count % 4 */
  59. shrl $2,%ecx /* %ecx = count / 4 */
  60. clc /* clear C flag */
  61. je ckEndLoop /* jump if Loop Counter is 0 */
  62. ckInLoop:
  63. adcl (%esi),%eax /* add word + previous carry */
  64. leal 4(%esi),%esi /* addr+=4, no flags have changed */
  65. decl %ecx /* C flag doesn't change */
  66. jnz ckInLoop
  67. ckEndLoop:
  68. movl %eax,%ecx
  69. lahf
  70. testl $2,%ebx /* another word to add ? */
  71. jne ckNextWord
  72. testl $1,%ebx /* another byte to add ? */
  73. jne ckNextByte
  74. jmp ckGetOut
  75. .balign 16,0x90
  76. ckNextWord:
  77. sahf
  78. adcw (%esi),%cx
  79. lahf
  80. leal 2(%esi),%esi
  81. testl $1,%ebx /* another byte to add ? */
  82. je ckGetOut
  83. ckNextByte:
  84. movzbl (%esi),%edx
  85. sahf
  86. adcw %dx,%cx
  87. lahf
  88. ckGetOut:
  89. movl %ecx,%edx /* fold 32 bits sum to 16 bits */
  90. shrl $16,%edx /* swap high-half and low-half */
  91. sahf
  92. adcw %dx,%cx /* add high-half and low-half */
  93. jnc ckNoCarry
  94. addw $1,%cx /* add C flag, if it is set */
  95. ckNoCarry:
  96. movl %ecx,%eax
  97. andl $0xffff,%eax
  98. popl %esi
  99. popl %ebx
  100. ret
  101. /****************************************************************************
  102. * insque - insert a node into a linked list
  103. *
  104. .ne 11
  105. .CS
  106. *  BEFORE                          AFTER
  107. *  %ecx            %eax            %ecx            %edx(new)        %eax
  108. *  _______         _______         _______         _______         _______
  109. * |       |       |       |       |       |       |       |       |       |
  110. * | pNext | ----> |       |       | pNext | ----> | pNext | ----> |       |
  111. * |_______|       |_______| ====> |_______|       |_______|       |_______|
  112. * |       |       |       |       |       |       |       |       |       |
  113. * |       | <---- | pPrev |       |       | <---- | pPrev | <---- | pPrev |
  114. * |_______|       |_______|       |_______|       |_______|       |_______|
  115. .CE
  116. *
  117. */
  118. .balign 16,0x90
  119. FUNC_LABEL(_insque)
  120. movl SP_ARG1(%esp),%edx
  121. movl SP_ARG2(%esp),%ecx
  122. movl (%ecx),%eax
  123. movl %eax,(%edx)
  124. movl %ecx,4(%edx)
  125. movl %edx,(%ecx)
  126. movl %edx,4(%eax)
  127. ret
  128. /****************************************************************************
  129. * remque - delete a node from a linked list
  130. *
  131. .ne 11
  132. .CS
  133. *  BEFORE                                          AFTER
  134. *  %eax            %edx            %ecx            %eax            %ecx
  135. *  _______         _______         _______         _______         _______
  136. * |       |       |       |       |       |       |       |       |       |
  137. * | pNext | ----> | pNext | ----> |       |       | pNext | ----> |       |
  138. * |_______|       |_______|       |_______| ====> |_______|       |_______|
  139. * |       |       |       |       |       |       |       |       |       |
  140. * |       | <---- | pPrev | <---- | pPrev |       |       | <---- | pPrev |
  141. * |_______|       |_______|       |_______|       |_______|       |_______|
  142. .CE
  143. *
  144. */
  145. .balign 16,0x90
  146. FUNC_LABEL(_remque)
  147. movl SP_ARG1(%esp),%edx
  148. movl 4(%edx),%eax
  149. movl (%edx),%ecx
  150. movl %eax,4(%ecx)
  151. movl %ecx,(%eax)
  152. ret
  153. #endif /* !PORTABLE */