mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "H. Peter Anvin" <hpa@zytor.com>
To: torvalds@linux-foundation.org, andi@firstfloor.org,
	linux-kernel@vger.kernel.org
Cc: "H. Peter Anvin" <hpa@zytor.com>
Subject: [x86 setup 16/33] String-handling functions for the new x86 setup code.
Date: Wed, 11 Jul 2007 12:18:41 -0700	[thread overview]
Message-ID: <1184181541746-git-send-email-hpa@zytor.com> (raw)
Message-ID: <8697ab9d1471721ca1c40a2224191d276c78ea0e.1184181208.git.hpa@zytor.com> (raw)
In-Reply-To: <11841815411443-git-send-email-hpa@zytor.com>
In-Reply-To: <7aca4ce0a222438c94300a2ea535270a21db8812.1184181208.git.hpa@zytor.com>

From: H. Peter Anvin <hpa@zytor.com>

strcmp(), memcpy(), memset(), as well as routines to copy to and from
other segments (as pointed to by fs and gs).

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
 arch/i386/boot/copy.S   |  101 +++++++++++++++++++++++++++++++++++++++++++++++
 arch/i386/boot/string.c |   52 ++++++++++++++++++++++++
 2 files changed, 153 insertions(+), 0 deletions(-)
 create mode 100644 arch/i386/boot/copy.S
 create mode 100644 arch/i386/boot/string.c

diff --git a/arch/i386/boot/copy.S b/arch/i386/boot/copy.S
new file mode 100644
index 0000000..ef127e5
--- /dev/null
+++ b/arch/i386/boot/copy.S
@@ -0,0 +1,101 @@
+/* ----------------------------------------------------------------------- *
+ *
+ *   Copyright (C) 1991, 1992 Linus Torvalds
+ *   Copyright 2007 rPath, Inc. - All Rights Reserved
+ *
+ *   This file is part of the Linux kernel, and is made available under
+ *   the terms of the GNU General Public License version 2.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * arch/i386/boot/copy.S
+ *
+ * Memory copy routines
+ */
+
+	.code16gcc
+	.text
+
+	.globl	memcpy
+	.type	memcpy, @function
+memcpy:
+	pushw	%si
+	pushw	%di
+	movw	%ax, %di
+	movw	%dx, %si
+	pushw	%cx
+	shrw	$2, %cx
+	rep; movsl
+	popw	%cx
+	andw	$3, %cx
+	rep; movsb
+	popw	%di
+	popw	%si
+	ret
+	.size	memcpy, .-memcpy
+
+	.globl	memset
+	.type	memset, @function
+memset:
+	pushw	%di
+	movw	%ax, %di
+	movzbl	%dl, %eax
+	imull	$0x01010101,%eax
+	pushw	%cx
+	shrw	$2, %cx
+	rep; stosl
+	popw	%cx
+	andw	$3, %cx
+	rep; stosb
+	popw	%di
+	ret
+	.size	memset, .-memset
+
+	.globl	copy_from_fs
+	.type	copy_from_fs, @function
+copy_from_fs:
+	pushw	%ds
+	pushw	%fs
+	popw	%ds
+	call	memcpy
+	popw	%ds
+	ret
+	.size	copy_from_fs, .-copy_from_fs
+
+	.globl	copy_to_fs
+	.type	copy_to_fs, @function
+copy_to_fs:
+	pushw	%es
+	pushw	%fs
+	popw	%es
+	call	memcpy
+	popw	%es
+	ret
+	.size	copy_to_fs, .-copy_to_fs
+
+#if 0 /* Not currently used, but can be enabled as needed */
+
+	.globl	copy_from_gs
+	.type	copy_from_gs, @function
+copy_from_gs:
+	pushw	%ds
+	pushw	%gs
+	popw	%ds
+	call	memcpy
+	popw	%ds
+	ret
+	.size	copy_from_gs, .-copy_from_gs
+	.globl	copy_to_gs
+
+	.type	copy_to_gs, @function
+copy_to_gs:
+	pushw	%es
+	pushw	%gs
+	popw	%es
+	call	memcpy
+	popw	%es
+	ret
+	.size	copy_to_gs, .-copy_to_gs
+
+#endif
diff --git a/arch/i386/boot/string.c b/arch/i386/boot/string.c
new file mode 100644
index 0000000..481a220
--- /dev/null
+++ b/arch/i386/boot/string.c
@@ -0,0 +1,52 @@
+/* -*- linux-c -*- ------------------------------------------------------- *
+ *
+ *   Copyright (C) 1991, 1992 Linus Torvalds
+ *   Copyright 2007 rPath, Inc. - All Rights Reserved
+ *
+ *   This file is part of the Linux kernel, and is made available under
+ *   the terms of the GNU General Public License version 2.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * arch/i386/boot/string.c
+ *
+ * Very basic string functions
+ */
+
+#include "boot.h"
+
+int strcmp(const char *str1, const char *str2)
+{
+	const unsigned char *s1 = (const unsigned char *)str1;
+	const unsigned char *s2 = (const unsigned char *)str2;
+	int delta = 0;
+
+	while (*s1 || *s2) {
+		delta = *s2 - *s1;
+		if (delta)
+			return delta;
+		s1++;
+		s2++;
+	}
+	return 0;
+}
+
+size_t strnlen(const char *s, size_t maxlen)
+{
+	const char *es = s;
+	while (*es && maxlen) {
+		es++;
+		maxlen--;
+	}
+
+	return (es - s);
+}
+
+unsigned int atou(const char *s)
+{
+	unsigned int i = 0;
+	while (isdigit(*s))
+		i = i * 10 + (*s++ - '0');
+	return i;
+}
-- 
1.5.2.2


  parent reply	other threads:[~2007-07-11 19:24 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-11 19:18 x86 setup code rewrite in C - revised H. Peter Anvin
     [not found] ` <7aca4ce0a222438c94300a2ea535270a21db8812.1184181208.git.hpa@zytor.com>
2007-07-11 19:18   ` [x86 setup 01/33] x86 setup: MAINTAINERS: formally take responsibility for the i386 boot code H. Peter Anvin
     [not found]   ` <e2ef08d659e025247a9de7e16784d695161c317e.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 02/33] hd.c: remove BIOS/CMOS queries H. Peter Anvin
     [not found]   ` <c20a5e19075b8eb5a5dd5f350c2012a71f072d56.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 03/33] include/asm-i386/boot.h: This is <asm/boot.h>, not <linux/boot.h> H. Peter Anvin
     [not found]   ` <c74269f00504931e6a653be3b4f0684ca8753561.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 04/33] Unify the CPU features vectors between i386 and x86-64 H. Peter Anvin
     [not found]   ` <6ca6bf20ba1c8bef47e0042657fd9dccad3404b8.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 05/33] Change CONFIG_X86_MINIMUM_CPU_MODEL to CONFIG_X86_MINIMUM_CPU_FAMILY H. Peter Anvin
     [not found]   ` <068e40b5e554720f1c3f1a966f5ea3d16cb8bbc5.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 06/33] Clean up struct screen_info (<linux/screen_info.h>) H. Peter Anvin
     [not found]   ` <b7ce2cdc4470b799c0ca96459898a24d1d04e8f5.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 07/33] Use a new CPU feature word to cover all Intel features that are spread around H. Peter Anvin
     [not found]   ` <e21d26f6728a59ddc9f19efdc111c5ed069cd1c0.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 08/33] Define zero-page offset 0x1e4 as a scratch field, and use it H. Peter Anvin
     [not found]   ` <e6a39812b9f6930a943ec96de73f270cb07cc2c2.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 09/33] Make definitions for struct e820entry and struct e820map consistent H. Peter Anvin
     [not found]   ` <ee5aac7aaaa45d7bab8fe9bc2e5ac4fb8b9c3e44.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 10/33] Make struct boot_params a real structure, and remove obsolete fields H. Peter Anvin
     [not found]   ` <e75ca1b52aabe4d87c9db5d29eaff7fe5505bde4.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 11/33] x86-64: add CONFIG_PHYSICAL_ALIGN for consistency with i386 H. Peter Anvin
     [not found]   ` <9c629383add61d72f69fde427153cb6b57f22188.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 12/33] x86-64: add symbolic constants for the boot segment selectors H. Peter Anvin
     [not found]   ` <ab1907cf095c021d5e721b9df84d7c4e6de82e66.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 13/33] Header file to produce 16-bit code with gcc H. Peter Anvin
     [not found]   ` <949c4631547d635d11605ddab03a18aa6e74483d.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 14/33] Top header file for new x86 setup code H. Peter Anvin
     [not found]   ` <03eade29601f9ca92ea95e241aaa7bfbcaaf0c6c.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 15/33] Simple bitops for the " H. Peter Anvin
     [not found]   ` <8697ab9d1471721ca1c40a2224191d276c78ea0e.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` H. Peter Anvin [this message]
     [not found]   ` <fe891becb7c2f4551a36056287a16696d77a8afa.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 17/33] A20 handling code H. Peter Anvin
     [not found]   ` <d1d88acb7f06459e4d906701132bfeffebfb04a3.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 18/33] APM probing code H. Peter Anvin
     [not found]   ` <f0db7b1f909cdf2dd895c5c44273dd46ffb5addc.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 19/33] Command-line parsing code for the new x86 setup code H. Peter Anvin
     [not found]   ` <f38ae9eb84193af6271ed2294992f589fabc8b3d.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 20/33] Console-writing " H. Peter Anvin
     [not found]   ` <6ffab1ac3c68a7cdc06ae6c54c5d564b47d49e17.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 21/33] Version string " H. Peter Anvin
     [not found]   ` <39a01d42c01c5034adea3b442c6698983bd4d921.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 22/33] CPU features verification " H. Peter Anvin
     [not found]   ` <099b1190b55993dc1ee0ac7bf4faa3bf55ce5223.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 23/33] EDD probing code " H. Peter Anvin
     [not found]   ` <16466ebe45a5054920bf2e67083663eccf8da662.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 24/33] MCA support for " H. Peter Anvin
     [not found]   ` <67bea0be0e4af894483cd7d8e725631d24e9c263.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 25/33] Memory probing support for the " H. Peter Anvin
     [not found]   ` <76894ec63ab814078b628b5697e1b86d6421b187.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 26/33] Voyager " H. Peter Anvin
     [not found]   ` <43b8a8153855d9af17029fcfcadebd8d4b14b7c4.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 28/33] Code for actual protected-mode entry H. Peter Anvin
     [not found]   ` <1a615a45477fc9b51fcb45279215881cc92dd794.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 29/33] Assembly header and main routine for new x86 setup code H. Peter Anvin
     [not found]   ` <5024dde46d1d0a742fcdcfcbff6a1112cb6c4729.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 30/33] Linker script for the " H. Peter Anvin
     [not found]   ` <70ac788a6377732e01a3f870f1bb2fe216f5b995.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 31/33] Use the new x86 setup code for i386 H. Peter Anvin
2007-07-13  9:27       ` Tilman Schmidt
     [not found]   ` <1208e1483b0e4e17d27fb07f9cdbb6945f9b1fb0.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 32/33] Use the new x86 setup code for x86-64; unify with i386 H. Peter Anvin
     [not found]   ` <5823c605b63bb9712f05fa73ab07d66a4f6e0f92.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 33/33] Remove old i386 setup code H. Peter Anvin
     [not found]   ` <509992ad2f618e07db2c72a96f8f5d708bfc6991.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 27/33] Video mode probing support for the new x86 " H. Peter Anvin
2007-07-16 10:59     ` Martin Mares
2007-07-11 20:08 ` x86 setup code rewrite in C - revised Jeff Garzik
2007-07-11 20:29   ` H. Peter Anvin
2007-07-12 17:24 ` Linus Torvalds
2007-07-12 17:30   ` Andrew Morton
2007-07-12 17:49     ` Linus Torvalds
2007-07-12 19:38   ` Andi Kleen
  -- strict thread matches above, loose matches on Subject: below --
2007-07-10  2:51 x86 setup code rewrite in C H. Peter Anvin
2007-07-10  2:51 ` [x86 setup 01/33] x86 setup: MAINTAINERS: formally take responsibility for the i386 boot code H. Peter Anvin
2007-07-10  2:51   ` [x86 setup 02/33] hd.c: remove BIOS/CMOS queries H. Peter Anvin
2007-07-10  2:51     ` [x86 setup 03/33] include/asm-i386/boot.h: This is <asm/boot.h>, not <linux/boot.h> H. Peter Anvin
2007-07-10  2:51       ` [x86 setup 04/33] Unify the CPU features vectors between i386 and x86-64 H. Peter Anvin
2007-07-10  2:51         ` [x86 setup 05/33] Change CONFIG_X86_MINIMUM_CPU_MODEL to CONFIG_X86_MINIMUM_CPU_FAMILY H. Peter Anvin
2007-07-10  2:51           ` [x86 setup 06/33] Clean up struct screen_info (<linux/screen_info.h>) H. Peter Anvin
2007-07-10  2:51             ` [x86 setup 07/33] Use a new CPU feature word to cover all Intel features that are spread around H. Peter Anvin
2007-07-10  2:51               ` [x86 setup 08/33] Define zero-page offset 0x1e4 as a scratch field, and use it H. Peter Anvin
2007-07-10  2:51                 ` [x86 setup 09/33] Make definitions for struct e820entry and struct e820map consistent H. Peter Anvin
2007-07-10  2:51                   ` [x86 setup 10/33] Make struct boot_params a real structure, and remove obsolete fields H. Peter Anvin
2007-07-10  2:51                     ` [x86 setup 11/33] x86-64: add CONFIG_PHYSICAL_ALIGN for consistency with i386 H. Peter Anvin
2007-07-10  2:51                       ` [x86 setup 12/33] x86-64: add symbolic constants for the boot segment selectors H. Peter Anvin
2007-07-10  2:51                         ` [x86 setup 13/33] Header file to produce 16-bit code with gcc H. Peter Anvin
2007-07-10  2:51                           ` [x86 setup 14/33] Top header file for new x86 setup code H. Peter Anvin
2007-07-10  2:51                             ` [x86 setup 15/33] Simple bitops for the " H. Peter Anvin
     [not found]                               ` <2034f71d414def30de582fb59573295cadbdabb4.1184032748.git.hpa@zytor.com>
     [not found]                                 ` <d5bd30fc697149284a73e09efe54884ab178de7e.1184032749.git.hpa@zytor.com>
2007-07-10  2:51                                   ` [x86 setup 16/33] String-handling functions " H. Peter Anvin
2007-07-10 18:25                                     ` Jan Engelhardt
2007-07-10 18:35                                       ` H. Peter Anvin
2007-07-10 20:10                                         ` Segher Boessenkool
2007-07-10 20:44                                           ` H. Peter Anvin
2007-07-10 21:14                                             ` Segher Boessenkool
2007-07-11 12:46                                               ` Andi Kleen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1184181541746-git-send-email-hpa@zytor.com \
    --to=hpa@zytor.com \
    --cc=andi@firstfloor.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome