Macros for symbols used in both ASM and C

-The macros take care of prepending the leading underscore when
 necessary.
This commit is contained in:
Arun Thomas
2010-08-17 16:44:07 +00:00
parent c8cfcab5db
commit 9a21d1a2fd
209 changed files with 1511 additions and 1863 deletions
+4 -5
View File
@@ -4,10 +4,9 @@
/* void *_memmove(void *s1, const void *s2, size_t n) */
/* Copy a chunk of memory. Handle overlap. */
/* */
.text
.globl __memmove, __memcpy
.balign 16
__memmove:
#include <machine/asm.h>
ENTRY(_memmove)
push %ebp
movl %esp, %ebp
push %esi
@@ -19,7 +18,7 @@ __memmove:
subl %esi, %eax
cmpl %ecx, %eax
jb downwards /* if (s2 - s1) < n then copy downwards */
__memcpy:
LABEL(_memcpy)
cld /* Clear direction bit: upwards */
cmpl $16, %ecx
jb upbyte /* Don't bother being smart with short arrays */
+3 -4
View File
@@ -4,10 +4,9 @@
/* char *_strncat(char *s1, const char *s2, size_t edx) */
/* Append string s2 to s1. */
/* */
.text
.globl __strncat
.balign 16
__strncat:
#include <machine/asm.h>
ENTRY(_strncat)
push %ebp
movl %esp, %ebp
push %esi
+3 -4
View File
@@ -4,10 +4,9 @@
/* int strncmp(const char *s1, const char *s2, size_t ecx) */
/* Compare two strings. */
/* */
.text
.globl __strncmp
.balign 16
__strncmp:
#include <machine/asm.h>
ENTRY(_strncmp)
push %ebp
movl %esp, %ebp
push %esi
+3 -4
View File
@@ -4,10 +4,9 @@
/* char *_strncpy(char *s1, const char *s2, size_t ecx) */
/* Copy string s2 to s1. */
/* */
.text
.globl __strncpy
.balign 16
__strncpy:
#include <machine/asm.h>
ENTRY(_strncpy)
movl 12(%ebp), %edi /* edi = string s2 */
xorb %al, %al /* Look for a zero byte */
movl %ecx, %edx /* Save maximum count */
+3 -4
View File
@@ -4,10 +4,9 @@
/* size_t _strnlen(const char *s, size_t ecx) */
/* Return the length of a string. */
/* */
.text
.globl __strnlen
.balign 16
__strnlen:
#include <machine/asm.h>
ENTRY(_strnlen)
push %ebp
movl %esp, %ebp
push %edi
+4 -5
View File
@@ -7,16 +7,15 @@
/* (Alas it is not without some use, it reports the number of bytes */
/* after the bytes that are equal. So it can't be simply replaced.) */
/* */
.text
.globl _bcmp
.balign 16
_bcmp:
#include <machine/asm.h>
ENTRY(bcmp)
push %ebp
movl %esp, %ebp
push 16(%ebp)
push 12(%ebp)
push 8(%ebp)
call _memcmp /* Let memcmp do the work */
call _C_LABEL(memcmp) /* Let memcmp do the work */
testl %eax, %eax
je equal
subl 8(%ebp), %edx /* Memcmp was nice enough to leave "esi" in edx */
+4 -5
View File
@@ -5,11 +5,10 @@
/* Copy a chunk of memory. Handle overlap. */
/* This is a BSD routine that escaped from the kernel. Don't use. */
/* */
.text
.globl _bcopy
.balign 16
_bcopy:
#include <machine/asm.h>
ENTRY(bcopy)
movl 4(%esp), %eax /* Exchange string arguments */
xchgl 8(%esp), %eax
movl %eax, 4(%esp)
jmp __memmove /* Call the proper routine */
jmp _C_LABEL(_memmove) /* Call the proper routine */
+4 -5
View File
@@ -5,15 +5,14 @@
/* Set a chunk of memory to zero. */
/* This is a BSD routine that escaped from the kernel. Don't use. */
/* */
.text
.globl _bzero
.balign 16
_bzero:
#include <machine/asm.h>
ENTRY(bzero)
push %ebp
movl %esp, %ebp
push 12(%ebp) /* Size */
push $0 /* Zero */
push 8(%ebp) /* String */
call _memset /* Call the proper routine */
call _C_LABEL(memset) /* Call the proper routine */
leave
ret
+4 -5
View File
@@ -5,8 +5,7 @@
/* Look for a character in a string. Has suffered from a hostile */
/* takeover by strchr(). */
/* */
.text
.globl _index
.balign 16
_index:
jmp _strchr
#include <machine/asm.h>
ENTRY(index)
jmp _C_LABEL(strchr)
+3 -4
View File
@@ -4,10 +4,9 @@
/* void *memchr(const void *s, int c, size_t n) */
/* Look for a character in a chunk of memory. */
/* */
.text
.globl _memchr
.balign 16
_memchr:
#include <machine/asm.h>
ENTRY(memchr)
push %ebp
movl %esp, %ebp
push %edi
+3 -4
View File
@@ -4,10 +4,9 @@
/* int memcmp(const void *s1, const void *s2, size_t n) */
/* Compare two chunks of memory. */
/* */
.text
.globl _memcmp
.balign 16
_memcmp:
#include <machine/asm.h>
ENTRY(memcmp)
cld
push %ebp
movl %esp, %ebp
+4 -5
View File
@@ -8,10 +8,9 @@
/* negligible, but you are dealing with a programmer who believes that if */
/* anything can go wrong, it should go wrong. */
/* */
.text
.globl _memcpy
.balign 16
_memcpy:
#include <machine/asm.h>
ENTRY(memcpy)
push %ebp
movl %esp, %ebp
push %esi
@@ -20,4 +19,4 @@ _memcpy:
movl 12(%ebp), %esi /* String s2 */
movl 16(%ebp), %ecx /* Length */
/* No overlap check here */
jmp __memcpy /* Call the part of __memmove that copies up */
jmp _C_LABEL(_memcpy) /* Call the part of __memmove that copies up */
+4 -5
View File
@@ -4,8 +4,7 @@
/* void *memmove(void *s1, const void *s2, size_t n) */
/* Copy a chunk of memory. Handle overlap. */
/* */
.text
.globl _memmove
.balign 16
_memmove:
jmp __memmove /* Call common code */
#include <machine/asm.h>
ENTRY(memmove)
jmp _C_LABEL(_memmove) /* Call common code */
+3 -4
View File
@@ -4,10 +4,9 @@
/* void *memset(void *s, int c, size_t n) */
/* Set a chunk of memory to the same byte value. */
/* */
.text
.globl _memset
.balign 16
_memset:
#include <machine/asm.h>
ENTRY(memset)
push %ebp
movl %esp, %ebp
push %edi
+4 -5
View File
@@ -5,8 +5,7 @@
/* Look for the last occurrence a character in a string. Has suffered */
/* from a hostile takeover by strrchr(). */
/* */
.text
.globl _rindex
.balign 16
_rindex:
jmp _strrchr
#include <machine/asm.h>
ENTRY(rindex)
jmp _C_LABEL(strrchr)
+4 -5
View File
@@ -4,9 +4,8 @@
/* char *strcat(char *s1, const char *s2) */
/* Append string s2 to s1. */
/* */
.text
.globl _strcat
.balign 16
_strcat:
#include <machine/asm.h>
ENTRY(strcat)
movl $-1, %edx /* Unlimited length */
jmp __strncat /* Common code */
jmp _C_LABEL(_strncat) /* Common code */
+3 -4
View File
@@ -4,10 +4,9 @@
/* char *strchr(const char *s, int c) */
/* Look for a character in a string. */
/* */
.text
.globl _strchr
.balign 16
_strchr:
#include <machine/asm.h>
ENTRY(strchr)
push %ebp
movl %esp, %ebp
push %edi
+4 -5
View File
@@ -4,9 +4,8 @@
/* int strcmp(const char *s1, const char *s2) */
/* Compare two strings. */
/* */
.text
.globl _strcmp
.balign 16
_strcmp:
#include <machine/asm.h>
ENTRY(strcmp)
movl $-1, %ecx /* Unlimited length */
jmp __strncmp /* Common code */
jmp _C_LABEL(_strncmp) /* Common code */
+4 -5
View File
@@ -4,16 +4,15 @@
/* char *strcpy(char *s1, const char *s2) */
/* Copy string s2 to s1. */
/* */
.text
.globl _strcpy
.balign 16
_strcpy:
#include <machine/asm.h>
ENTRY(strcpy)
push %ebp
movl %esp, %ebp
push %esi
push %edi
movl $-1, %ecx /* Unlimited length */
call __strncpy /* Common code */
call _C_LABEL(_strncpy) /* Common code */
movl 8(%ebp), %eax /* Return s1 */
pop %edi
pop %esi
+4 -5
View File
@@ -4,9 +4,8 @@
/* size_t strlen(const char *s) */
/* Return the length of a string. */
/* */
.text
.globl _strlen
.balign 16
_strlen:
#include <machine/asm.h>
ENTRY(strlen)
movl $-1, %ecx /* Unlimited length */
jmp __strnlen /* Common code */
jmp _C_LABEL(_strnlen) /* Common code */
+4 -5
View File
@@ -4,9 +4,8 @@
/* size_t strncat(char *s1, const char *s2, size_t n) */
/* Append string s2 to s1. */
/* */
.text
.globl _strncat
.balign 16
_strncat:
#include <machine/asm.h>
ENTRY(strncat)
movl 12(%esp), %edx /* Maximum length */
jmp __strncat /* Common code */
jmp _C_LABEL(_strncat) /* Common code */
+4 -5
View File
@@ -4,9 +4,8 @@
/* int strncmp(const char *s1, const char *s2, size_t n) */
/* Compare two strings. */
/* */
.text
.globl _strncmp
.balign 16
_strncmp:
#include <machine/asm.h>
ENTRY(strncmp)
movl 12(%esp), %ecx /* Maximum length */
jmp __strncmp /* Common code */
jmp _C_LABEL(_strncmp) /* Common code */
+4 -5
View File
@@ -4,16 +4,15 @@
/* char *strncpy(char *s1, const char *s2, size_t n) */
/* Copy string s2 to s1. */
/* */
.text
.globl _strncpy
.balign 16
_strncpy:
#include <machine/asm.h>
ENTRY(strncpy)
push %ebp
movl %esp, %ebp
push %esi
push %edi
movl 16(%ebp), %ecx /* Maximum length */
call __strncpy /* Common code */
call _C_LABEL(_strncpy) /* Common code */
movl %edx, %ecx /* Number of bytes not copied */
rep stosb /* strncpy always copies n bytes by null padding */
+4 -5
View File
@@ -4,9 +4,8 @@
/* size_t strnlen(const char *s, size_t n) */
/* Return the length of a string. */
/* */
.text
.globl _strnlen
.balign 16
_strnlen:
#include <machine/asm.h>
ENTRY(strnlen)
movl 8(%esp), %ecx /* Maximum length */
jmp __strnlen /* Common code */
jmp _C_LABEL(_strnlen) /* Common code */
+3 -4
View File
@@ -4,10 +4,9 @@
/* char *strrchr(const char *s, int c) */
/* Look for the last occurrence a character in a string. */
/* */
.text
.globl _strrchr
.balign 16
_strrchr:
#include <machine/asm.h>
ENTRY(strrchr)
push %ebp
movl %esp, %ebp
push %edi