aboutsummaryrefslogtreecommitdiffstats
path: root/memdisk
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2008-06-06 12:38:42 -0700
committerH. Peter Anvin <hpa@zytor.com>2008-06-06 12:38:42 -0700
commit6389a53252be6f3eaf8248ee6d58dff88697aad0 (patch)
tree6fc64e26c4ff906e42fd7b87de33d6d575826871 /memdisk
parent6ecbbad5bfee20dddccdbe0629125c7b6ca41211 (diff)
downloadsyslinux.git-6389a53252be6f3eaf8248ee6d58dff88697aad0.tar.gz
syslinux.git-6389a53252be6f3eaf8248ee6d58dff88697aad0.tar.xz
syslinux.git-6389a53252be6f3eaf8248ee6d58dff88697aad0.zip
MEMDISK: Use aligning memcpy/memset, compile with -mregparm=3syslinux-3.70-pre14
Use the aligning memcpy/memset from libcom32. Switch memdisk to compiling with -mregparm=3, except for the interfaces to assembly.
Diffstat (limited to 'memdisk')
-rw-r--r--memdisk/Makefile2
-rw-r--r--memdisk/memcpy.S104
-rw-r--r--memdisk/memdisk.h4
-rw-r--r--memdisk/memset.S105
-rw-r--r--memdisk/setup.c4
5 files changed, 168 insertions, 51 deletions
diff --git a/memdisk/Makefile b/memdisk/Makefile
index d30fe853..1ce43c2a 100644
--- a/memdisk/Makefile
+++ b/memdisk/Makefile
@@ -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
diff --git a/memdisk/memcpy.S b/memdisk/memcpy.S
index 82ec870e..5f2c4ec7 100644
--- a/memdisk/memcpy.S
+++ b/memdisk/memcpy.S
@@ -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
diff --git a/memdisk/memdisk.h b/memdisk/memdisk.h
index ad650e54..bb2057de 100644
--- a/memdisk/memdisk.h
+++ b/memdisk/memdisk.h
@@ -25,8 +25,10 @@
/* 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 */
diff --git a/memdisk/memset.S b/memdisk/memset.S
index c6638854..4b2583c3 100644
--- a/memdisk/memset.S
+++ b/memdisk/memset.S
@@ -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
diff --git a/memdisk/setup.c b/memdisk/setup.c
index 829893a7..298720a5 100644
--- a/memdisk/setup.c
+++ b/memdisk/setup.c
@@ -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;