MEMDISK: Use aligning memcpy/memset, compile with -mregparm=3 syslinux-3.70-pre14
authorH. Peter Anvin <hpa@zytor.com>
Fri, 6 Jun 2008 19:38:42 +0000 (12:38 -0700)
committerH. Peter Anvin <hpa@zytor.com>
Fri, 6 Jun 2008 19:38:42 +0000 (12:38 -0700)
Use the aligning memcpy/memset from libcom32.  Switch memdisk to
compiling with -mregparm=3, except for the interfaces to assembly.

memdisk/Makefile
memdisk/memcpy.S
memdisk/memdisk.h
memdisk/memset.S
memdisk/setup.c

index d30fe85..1ce43c2 100644 (file)
@@ -24,7 +24,7 @@ ALIGN   := $(call gcc_ok,-falign-functions=0 -falign-jumps=0 -falign-loops=0,-ma
 FREE    := $(call gcc_ok,-ffreestanding,) $(call gcc_ok,-fno-stack-protector,)
 
 CFLAGS   =  $(M32) $(FREE) -g -W -Wall -Wno-sign-compare \
-          -Os -fomit-frame-pointer -march=i386 $(ALIGN) \
+          -Os -fomit-frame-pointer -march=i386 -mregparm=3 $(ALIGN) \
           -DVERSION='"$(VERSION)"' -DDATE='"$(DATE)"'
 SFLAGS  = $(M32) -march=i386 -D__ASSEMBLY__
 LDFLAGS  = $(M32) -g
index 82ec870..5f2c4ec 100644 (file)
@@ -1,28 +1,86 @@
-#
-# memcpy.S
-#
-# Simple memcpy() implementation
-#
+/* ----------------------------------------------------------------------- *
+ *
+ *   Copyright 2008 H. Peter Anvin - All Rights Reserved
+ *
+ *   Permission is hereby granted, free of charge, to any person
+ *   obtaining a copy of this software and associated documentation
+ *   files (the "Software"), to deal in the Software without
+ *   restriction, including without limitation the rights to use,
+ *   copy, modify, merge, publish, distribute, sublicense, and/or
+ *   sell copies of the Software, and to permit persons to whom
+ *   the Software is furnished to do so, subject to the following
+ *   conditions:
+ *
+ *   The above copyright notice and this permission notice shall
+ *   be included in all copies or substantial portions of the Software.
+ *
+ *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ *   OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ *   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ *   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ *   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ *   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ *   OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * memcpy.S
+ *
+ * Reasonably efficient memcpy, using aligned transfers at least
+ * for the destination operand.
+ */
 
        .text
-       .globl memcpy
-       .type memcpy, @function
+       .globl  memcpy
+       .type   memcpy, @function
 memcpy:
-       cld
-       pushl %edi
-       pushl %esi
-       movl 12(%esp),%edi
-       movl 16(%esp),%esi
-       movl 20(%esp),%eax
-       movl %eax,%ecx
-       shrl $2,%ecx
-       rep ; movsl
-       movl %eax,%ecx
-       andl $3,%ecx
-       rep ; movsb
-       movl 12(%esp),%eax
-       popl %esi
-       popl %edi
+       jecxz   1f
+
+       pushl   %esi
+       pushl   %edi
+       pushl   %eax            /* Return value */
+
+       movl    %eax,%edi
+       movl    %edx,%esi
+
+       /* Initial alignment */
+       movl    %edi,%edx
+       shrl    $1,%edx
+       jnc     11f
+       movsb
+       decl    %ecx
+11:
+       movb    %cl,%al
+       cmpl    $2,%ecx
+       jb      13f
+
+       shrl    $1,%edx
+       jnc     12f
+       movsw
+       subl    $2,%ecx
+12:
+       /* Bulk transfer */
+       movb    %cl,%al
+       shrl    $2,%ecx
+       rep; movsl
+
+       /* Final alignment */
+       testb   $2,%al
+       jz      14f
+       movsw
+13:
+14:
+       testb   $1,%al
+       jz      15f
+       movsb
+15:
+
+       popl    %eax            /* Return value */
+       popl    %edi
+       popl    %esi
+1:     
        ret
 
-       .size memcpy,.-memcpy
+       .size   memcpy, .-memcpy
index ad650e5..bb2057d 100644 (file)
 /* The real-mode segment */
 #define LOW_SEG 0x0800
 
+#define __cdecl __attribute__((cdecl,regparm(0)))
+
 typedef void (*syscall_t)(uint8_t, com32sys_t *, com32sys_t *);
-extern syscall_t syscall;
+extern __cdecl syscall_t syscall;
 extern void *sys_bounce;
 
 /* What to call when we're dead */
index c663885..4b2583c 100644 (file)
@@ -1,29 +1,86 @@
-#
-# memset.S
-#
-# Simple memset() implementation
-#
+/* ----------------------------------------------------------------------- *
+ *
+ *   Copyright 2008 H. Peter Anvin - All Rights Reserved
+ *
+ *   Permission is hereby granted, free of charge, to any person
+ *   obtaining a copy of this software and associated documentation
+ *   files (the "Software"), to deal in the Software without
+ *   restriction, including without limitation the rights to use,
+ *   copy, modify, merge, publish, distribute, sublicense, and/or
+ *   sell copies of the Software, and to permit persons to whom
+ *   the Software is furnished to do so, subject to the following
+ *   conditions:
+ *
+ *   The above copyright notice and this permission notice shall
+ *   be included in all copies or substantial portions of the Software.
+ *
+ *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ *   OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ *   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ *   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ *   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ *   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ *   OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * ----------------------------------------------------------------------- */
 
+/*
+ * memset.S
+ *
+ * Reasonably efficient memset, using aligned transfers at least
+ * for the destination operand.
+ */
+
+       .globl  memset
+       .type   memset,@function
        .text
-       .globl memset
-       .type memset, @function
 memset:
-       cld
-       pushl %edi
-       pushl %esi
-       movl 12(%esp),%edi
-       movzbl 16(%esp),%eax
-       movl 20(%esp),%esi
-       imull $0x01010101,%eax
-       movl %esi,%ecx
-       shrl $2,%ecx
-       rep ; stosl
-       movl %esi,%ecx
-       andl $3,%ecx
-       rep ; stosb
-       movl 12(%esp),%eax
-       popl %esi
-       popl %edi
+       jecxz   6f
+
+       pushl   %edi
+       pushl   %ebx
+       pushl   %eax            /* Return value */
+
+       movl    %eax,%edi
+       movb    %dl,%dh
+       movzwl  %dx,%eax
+       shll    $16,%edx
+       orl     %edx,%eax
+       
+       /* Initial alignment */
+       movl    %edi,%edx
+       shrl    $1,%edx
+       jnc     1f
+       stosb
+       decl    %ecx
+1:
+       movb    %cl,%bl
+       cmpl    $2,%ecx
+       jb      3f
+       shrl    $1,%edx
+       jnc     2f
+       stosw
+       subl    $2,%ecx
+2:
+       /* Bulk transfer */
+       movb    %cl,%bl
+       shrl    $2,%ecx
+       rep; stosl
+
+       testb   $2,%bl
+       jz      4f
+       stosw
+3:
+4:
+       testb   $1,%bl
+       jz      5f
+       stosb
+5:
+       popl    %eax            /* Return value */
+       popl    %ebx
+       popl    %edi
+6:
        ret
 
-       .size memcpy,.-memcpy
+       .size   memset, .-memset
index 829893a..298720a 100644 (file)
@@ -551,10 +551,10 @@ static uint32_t pnp_install_check(void)
  * Returns the drive number (which is then passed in %dl to the
  * called routine.)
  */
-syscall_t syscall;
+__cdecl syscall_t syscall;
 void *sys_bounce;
 
-void setup(syscall_t cs_syscall, void *cs_bounce)
+__cdecl void setup(__cdecl syscall_t cs_syscall, void *cs_bounce)
 {
   unsigned int bin_size = (int) &_binary_memdisk_bin_size;
   struct memdisk_header *hptr;