/* strtok (str, delim) -- Return next DELIM separated token from STR.
For Intel 80686.
- Copyright (C) 1998, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1998-2014 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
+ Lesser General Public License for more details.
- You should have received a copy of the GNU Library General Public
- License along with the GNU C Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
#include <sysdep.h>
#include "asm-syntax.h"
-#include "bp-sym.h"
-#include "bp-asm.h"
/* This file can be used for three variants of the strtok function:
We do a common implementation here. */
-#ifndef USE_AS_STRTOK_R
+#ifdef USE_AS_STRTOK_R
+# define SAVE_PTR 0(%ecx)
+#else
.bss
.local save_ptr
- ASM_TYPE_DIRECTIVE (save_ptr, @object)
+ .type save_ptr, @object
.size save_ptr, 4
save_ptr:
.space 4
-#define FUNCTION BP_SYM (strtok)
+# ifdef PIC
+# define SAVE_PTR save_ptr@GOTOFF(%ebx)
+# else
+# define SAVE_PTR save_ptr
+# endif
+
+# define FUNCTION strtok
+#endif
+
+#if !defined USE_AS_STRTOK_R && defined PIC
+# define PARMS 4+256+4 /* space for table and saved PIC register */
+#else
+# define PARMS 4+256 /* space for table */
+#endif
+#define RTN PARMS
+#define STR RTN
+#define DELIM STR+4
+#ifdef USE_AS_STRTOK_R
+# define SAVE DELIM+4
#endif
.text
ret
#endif
-#define PARMS LINKAGE /* no space for saved regs */
-#define RTN PARMS
-#define STR RTN+RTN_SIZE
-#define DELIM STR+PTR_SIZE
-#define SAVE DELIM+PTR_SIZE
-
-ENTRY (BP_SYM (FUNCTION))
- ENTER
+ENTRY (FUNCTION)
#if !defined USE_AS_STRTOK_R && defined PIC
pushl %ebx /* Save PIC register. */
+ cfi_adjust_cfa_offset (4)
+ cfi_rel_offset (ebx, 0)
call 0b
addl $_GLOBAL_OFFSET_TABLE_, %ebx
#endif
table. */
movl %edi, %edx
subl $256, %esp
+ cfi_adjust_cfa_offset (256)
movl $64, %ecx
movl %esp, %edi
xorl %eax, %eax
/* Note: %ecx = 0 !!! */
movl %edx, %edi
-#if !defined USE_AS_STRTOK_R && defined PIC
- movl 264(%esp), %edx /* Get start of string. */
-#else
- movl 260(%esp), %edx /* Get start of string. */
-#endif
+ movl STR(%esp), %edx /* Get start of string. */
#ifdef USE_AS_STRTOK_R
/* The value is stored in the third argument. */
- movl 268(%esp), %eax
+ movl SAVE(%esp), %eax
movl (%eax), %eax
#else
/* The value is in the local variable defined above. But
we have to take care for PIC code. */
-# ifndef PIC
- movl save_ptr, %eax
-# else
- movl save_ptr@GOTOFF(%ebx), %eax
-# endif
+ movl SAVE_PTR, %eax
#endif
/* If the pointer is NULL we have to use the stored value of
the last run. */
cmpl $0, %edx
cmove %eax, %edx
-
-#if !defined USE_AS_STRTOK_R && defined PIC
- movl 268(%esp), %eax /* Get start of delimiter set. */
-#else
- movl 264(%esp), %eax /* Get start of delimiter set. */
-#endif
+ testl %edx, %edx
+ jz L(returnNULL)
+ movl DELIM(%esp), %eax /* Get start of delimiter set. */
/* For understanding the following code remember that %ecx == 0 now.
Although all the following instruction only modify %cl we always
L(10): incl %edx
L(9): incl %edx
-L(8): /* Remove the stopset table. */
- addl $256, %esp
-
- cmpl %eax, %edx
+L(8): cmpl %eax, %edx
je L(returnNULL) /* There was no token anymore. */
movb $0, (%edx) /* Terminate string. */
leal 1(%edx), %ecx
cmovne %ecx, %edx
-L(return):
/* Store the pointer to the next character. */
#ifdef USE_AS_STRTOK_R
- movl 12(%esp), %ecx
- movl %edx, (%ecx)
-#else
-# ifndef PIC
- movl %edx, save_ptr
-# else
- movl %edx, save_ptr@GOTOFF(%ebx)
+ movl SAVE(%esp), %ecx
+#endif
+ movl %edx, SAVE_PTR
+
+L(epilogue):
+ /* Remove the stopset table. */
+ addl $256, %esp
+ cfi_adjust_cfa_offset (-256)
+#if !defined USE_AS_STRTOK_R && defined PIC
popl %ebx
-# endif
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (ebx)
#endif
ret
L(returnNULL):
xorl %eax, %eax
- jmp L(return)
-END (BP_SYM (FUNCTION))
+#ifdef USE_AS_STRTOK_R
+ movl SAVE(%esp), %ecx
+#endif
+ movl %edx, SAVE_PTR
+ jmp L(epilogue)
+
+END (FUNCTION)