Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 23 Oct 2006 10:05:36 GMT
From:      Oleksandr Tymoshenko <gonzo@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 108299 for review
Message-ID:  <200610231005.k9NA5a7M005309@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=108299

Change 108299 by gonzo@gonzo_hq on 2006/10/23 10:05:12

	o Implement functions from "copystr" family.

Affected files ...

.. //depot/projects/mips2/src/sys/mips/mips/copystr.S#4 edit

Differences ...

==== //depot/projects/mips2/src/sys/mips/mips/copystr.S#4 (text+ko) ====

@@ -34,14 +34,13 @@
 #include <sys/errno.h>
 
 /*
- * XXXMIPS: Implement these routines
- */
-/*
  * copystr(9)
  * <v0>int copystr(<a0>const void *src, <a1>void *dst, <a2>size_t len,
  *                 <a3>size_t *done)
  */
 ENTRY(copystr)
+	.set noreorder
+	.set noat
 	move	v0, zero
 	beqz	a2, 2f
 	move	t1, zero
@@ -62,13 +61,88 @@
 	sw	t1, 0(a3)
 4:	jr	ra
 	nop
+	.set reorder
+	.set at
 END(copystr)
 
-
-ENTRY(copyinstr)
-	break
+/*
+ * int copyinstr(void *uaddr, void *kaddr, size_t maxlen, size_t *lencopied)
+ * Copy a NIL-terminated string, at most maxlen characters long, from the
+ * user's address space.  Return the number of characters copied (including
+ * the NIL) in *lencopied.  If the string is too long, return ENAMETOOLONG;
+ * else return 0 or EFAULT.
+ */
+LEAF(copyinstr)
+	.set noreorder
+	.set noat
+	lw	t2, pcpup
+	lw	v1, PC_CURPCB(t2)
+	la	v0, _C_LABEL(copystrerr)
+	blt	a0, zero, _C_LABEL(copystrerr)
+	sw	v0, PCB_ONFAULT(v1)
+	move	t0, a2
+	beq	a2, zero, 4f
+1:
+	lbu	v0, 0(a0)
+	subu	a2, a2, 1
+	beq	v0, zero, 2f
+	sb	v0, 0(a1)
+	addu	a0, a0, 1
+	bne	a2, zero, 1b
+	addu	a1, a1, 1
+4:
+	li	v0, ENAMETOOLONG
+2:
+	beq	a3, zero, 3f
+	subu	a2, t0, a2
+	sw	a2, 0(a3)
+3:
+	j	ra				# v0 is 0 or ENAMETOOLONG
+	sw	zero, PCB_ONFAULT(v1)
+	.set reorder
+	.set at
 END(copyinstr)
 
-ENTRY(copyoutstr)
-	break
+/*
+ * int copyoutstr(void *uaddr, void *kaddr, size_t maxlen, size_t *lencopied);
+ * Copy a NIL-terminated string, at most maxlen characters long, into the
+ * user's address space.  Return the number of characters copied (including
+ * the NIL) in *lencopied.  If the string is too long, return ENAMETOOLONG;
+ * else return 0 or EFAULT.
+ */
+LEAF(copyoutstr)
+	.set noreorder
+	.set noat
+	lw	t2, pcpup
+	lw	v1, PC_CURPCB(t2)
+	la	v0, _C_LABEL(copystrerr)
+	blt	a1, zero, _C_LABEL(copystrerr)
+	sw	v0, PCB_ONFAULT(v1)
+	move	t0, a2
+	beq	a2, zero, 4f
+1:
+	lbu	v0, 0(a0)
+	subu	a2, a2, 1
+	beq	v0, zero, 2f
+	sb	v0, 0(a1)
+	addu	a0, a0, 1
+	bne	a2, zero, 1b
+	addu	a1, a1, 1
+4:
+	li	v0, ENAMETOOLONG
+2:
+	beq	a3, zero, 3f
+	subu	a2, t0, a2
+	sw	a2, 0(a3)
+3:
+	j	ra				# v0 is 0 or ENAMETOOLONG
+	sw	zero, PCB_ONFAULT(v1)
+	.set reorder
+	.set at
 END(copyoutstr)
+
+LEAF(copystrerr)
+	sw	zero, PCB_ONFAULT(v1)
+	j	ra
+	li	v0, EFAULT			# return EFAULT
+END(copystrerr)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200610231005.k9NA5a7M005309>