Index: arch/ia64/Makefile.inc
===================================================================
--- arch/ia64/Makefile.inc	(revision 79f1f38f331a80351aa543a6fed4a212c5e49201)
+++ arch/ia64/Makefile.inc	(revision 9db5b66ca088c0a98965fe9d47a06117c9df7272)
@@ -17,4 +17,5 @@
 arch_sources= \
 	arch/start.S \
+	arch/asm.S \
 	arch/fake.s \
 	arch/putchar.c \
Index: arch/ia64/include/context.h
===================================================================
--- arch/ia64/include/context.h	(revision 79f1f38f331a80351aa543a6fed4a212c5e49201)
+++ arch/ia64/include/context.h	(revision 9db5b66ca088c0a98965fe9d47a06117c9df7272)
@@ -32,11 +32,39 @@
 #include <arch/types.h>
 
-
-
 struct context {
-	__u64 sp;
-	__u64 pc;
+	__u64 r1;
+	__u64 r2;
+	__u64 r3;
+	__u64 r4;
+	__u64 r5;
+	__u64 r6;
+	__u64 r7;
+	__u64 r8;
+	__u64 r9;
+	__u64 r10;
+	__u64 r11;
+	__u64 sp;		/* r12 */
+	__u64 r13;
+	__u64 r14;
+	__u64 r15;
+	__u64 r16;
+	__u64 r17;
+	__u64 r18;
+	__u64 r19;
+	__u64 r20;
+	__u64 r21;
+	__u64 r22;
+	__u64 r23;
+	__u64 r24;
+	__u64 r25;
+	__u64 r26;
+	__u64 r27;
+	__u64 r28;
+	__u64 r29;
+	__u64 r30;
+	__u64 r31;
+	__u64 pc;		/* b0 */
 	pri_t pri;
-};
+} __attribute__ ((packed));
 
 #endif
Index: arch/ia64/src/asm.S
===================================================================
--- arch/ia64/src/asm.S	(revision 9db5b66ca088c0a98965fe9d47a06117c9df7272)
+++ arch/ia64/src/asm.S	(revision 9db5b66ca088c0a98965fe9d47a06117c9df7272)
@@ -0,0 +1,40 @@
+#
+# Copyright (C) 2005 Jakub Jermar
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+.text
+
+.global memcpy
+memcpy:
+	/*
+	 * Switch the role of first two arguments
+	 */
+	sub r33 = r32, r33	;;
+	add r32 = r32, r33	;;
+	sub r33 = r33, r32	
+		
+	br _memcopy
Index: arch/ia64/src/context.S
===================================================================
--- arch/ia64/src/context.S	(revision 79f1f38f331a80351aa543a6fed4a212c5e49201)
+++ arch/ia64/src/context.S	(revision 9db5b66ca088c0a98965fe9d47a06117c9df7272)
@@ -33,6 +33,96 @@
 
 context_save:
+	alloc loc0 = ar.pfs, 1, 2, 0, 0
+	
+	/*
+	 * TODO: save the rest of the context registers.
+	 */
+
+	st8 [in0] = r1, 8	;;
+	st8 [in0] = r2, 8	;;
+	st8 [in0] = r3, 8	;;
+	st8 [in0] = r4, 8	;;
+	st8 [in0] = r5, 8	;;
+	st8 [in0] = r6, 8	;;
+	st8 [in0] = r7, 8	;;
+	st8 [in0] = r8, 8	;;
+	st8 [in0] = r9, 8	;;
+	st8 [in0] = r10, 8	;;
+	st8 [in0] = r11, 8	;;
+	st8 [in0] = r12, 8	;;	/* save sp */
+	st8 [in0] = r13, 8	;;
+	st8 [in0] = r14, 8	;;
+	st8 [in0] = r15, 8	;;
+	st8 [in0] = r16, 8	;;
+	st8 [in0] = r17, 8	;;
+	st8 [in0] = r18, 8	;;
+	st8 [in0] = r19, 8	;;
+	st8 [in0] = r20, 8	;;
+	st8 [in0] = r21, 8	;;
+	st8 [in0] = r22, 8	;;
+	st8 [in0] = r23, 8	;;
+	st8 [in0] = r24, 8	;;
+	st8 [in0] = r25, 8	;;
+	st8 [in0] = r26, 8	;;
+	st8 [in0] = r27, 8	;;
+	st8 [in0] = r28, 8	;;
+	st8 [in0] = r29, 8	;;
+	st8 [in0] = r30, 8	;;
+	st8 [in0] = r31, 8	;;
+
+	/* save pc */
+	mov loc1 = b0		;;
+	st8 [in0] = loc1, 8
+	
+	mov ar.pfs = loc0
+	
+	add r8 = r0, r0, 1 		/* context_save returns 1 */
 	br.ret.sptk.many rp
 
 context_restore:
+	alloc loc0 = ar.pfs, 1, 2, 0, 0
+
+	/*
+	 * TODO: restore the rest of the context registers.
+	 */
+	
+	ld8 r1 = [in0], 8	;;
+	ld8 r2 = [in0], 8	;;
+	ld8 r3 = [in0], 8	;;
+	ld8 r4 = [in0], 8	;;
+	ld8 r5 = [in0], 8	;;
+	ld8 r6 = [in0], 8	;;
+	ld8 r7 = [in0], 8	;;
+	ld8 r8 = [in0], 8	;;
+	ld8 r9 = [in0], 8	;;
+	ld8 r10 = [in0], 8	;;
+	ld8 r11 = [in0], 8	;;
+	ld8 r12 = [in0], 8	;;	/* restore sp */
+	ld8 r13 = [in0], 8	;;
+	ld8 r14 = [in0], 8	;;
+	ld8 r15 = [in0], 8	;;
+	ld8 r16 = [in0], 8	;;
+	ld8 r17 = [in0], 8	;;
+	ld8 r18 = [in0], 8	;;
+	ld8 r19 = [in0], 8	;;
+	ld8 r20 = [in0], 8	;;
+	ld8 r21 = [in0], 8	;;
+	ld8 r22 = [in0], 8	;;
+	ld8 r23 = [in0], 8	;;
+	ld8 r24 = [in0], 8	;;
+	ld8 r25 = [in0], 8	;;
+	ld8 r26 = [in0], 8	;;
+	ld8 r27 = [in0], 8	;;
+	ld8 r28 = [in0], 8	;;
+	ld8 r29 = [in0], 8	;;
+	ld8 r30 = [in0], 8	;;
+	ld8 r31 = [in0], 8	;;
+
+	/* restore pc */
+	ld8 loc1 = [in0], 8	;;
+	mov b0 = loc1
+	
+	mov ar.pfs = loc0
+	
+	mov r8 = r0			/* context_restore returns 0 */
 	br.ret.sptk.many rp
Index: arch/mips/Makefile.inc
===================================================================
--- arch/mips/Makefile.inc	(revision 79f1f38f331a80351aa543a6fed4a212c5e49201)
+++ arch/mips/Makefile.inc	(revision 9db5b66ca088c0a98965fe9d47a06117c9df7272)
@@ -27,5 +27,4 @@
 	arch/interrupt.c \
 	arch/cache.c \
-	arch/lib/memstr.c \
 	arch/cpu/cpu.c \
 	arch/mm/frame.c \
Index: arch/mips/src/asm.s
===================================================================
--- arch/mips/src/asm.s	(revision 79f1f38f331a80351aa543a6fed4a212c5e49201)
+++ arch/mips/src/asm.s	(revision 9db5b66ca088c0a98965fe9d47a06117c9df7272)
@@ -144,4 +144,9 @@
 
 
+.global memsetb
+memsetb:
+	j _memsetb
+	nop
+
 # THIS IS USERSPACE CODE
 .global utext
Index: ch/mips/src/lib/memstr.c
===================================================================
--- arch/mips/src/lib/memstr.c	(revision 79f1f38f331a80351aa543a6fed4a212c5e49201)
+++ 	(revision )
@@ -1,47 +1,0 @@
-/*
- * Copyright (C) 2001-2004 Jakub Jermar
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <memstr.h>
-#include <arch/types.h>
-
-void memcopy(__address src, __address dst, int cnt)
-{
-	int i;
-	
-	for (i=0; i<cnt; i++)
-		*((__u8 *) (dst + i)) = *((__u8 *) (src + i));
-}
-
-void memsetb(__address dst, int cnt, __u8 x)
-{
-	int i;
-	__u8 *p = (__u8 *) dst;
-	
-	for(i=0; i<cnt; i++)
-		p[i] = x;
-}
Index: include/memstr.h
===================================================================
--- include/memstr.h	(revision 79f1f38f331a80351aa543a6fed4a212c5e49201)
+++ include/memstr.h	(revision 9db5b66ca088c0a98965fe9d47a06117c9df7272)
@@ -39,3 +39,9 @@
 extern int memcmp(__address src, __address dst, int cnt);
 
+/*
+ * Architecture independent variants.
+ */
+extern void _memcopy(__address src, __address dst, int cnt);
+extern void _memsetb(__address dst, int cnt, __u8 x);
+
 #endif
Index: src/Makefile
===================================================================
--- src/Makefile	(revision 79f1f38f331a80351aa543a6fed4a212c5e49201)
+++ src/Makefile	(revision 9db5b66ca088c0a98965fe9d47a06117c9df7272)
@@ -16,4 +16,5 @@
 	lib/func.c \
 	lib/list.c \
+	lib/memstr.c \
 	debug/print.c \
 	time/clock.c \
Index: src/lib/memstr.c
===================================================================
--- src/lib/memstr.c	(revision 9db5b66ca088c0a98965fe9d47a06117c9df7272)
+++ src/lib/memstr.c	(revision 9db5b66ca088c0a98965fe9d47a06117c9df7272)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2001-2004 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <memstr.h>
+#include <arch/types.h>
+
+void _memcopy(__address src, __address dst, int cnt)
+{
+	int i;
+	
+	for (i=0; i<cnt; i++)
+		*((__u8 *) (dst + i)) = *((__u8 *) (src + i));
+}
+
+void _memsetb(__address dst, int cnt, __u8 x)
+{
+	int i;
+	__u8 *p = (__u8 *) dst;
+	
+	for(i=0; i<cnt; i++)
+		p[i] = x;
+}
