Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 1 file changed
  • 0 comments
  • 1 contributor
Apr 20, 2013
Yann Sionneau Add implementation of copyin.9 7d4c915
Yann Sionneau Fix typo in copyout.9
Add needed "const" qualifier as well
75703dc

Showing 1 changed file with 37 additions and 2 deletions. Show diff stats Hide diff stats

  1. 39  sys/arch/lm32/lm32/copy.c
39  sys/arch/lm32/lm32/copy.c
@@ -10,6 +10,7 @@
10 10
 
11 11
 void do_pmap_load(void);
12 12
 int copyout(const void *kaddr, void *uaddr, size_t len);
  13
+int copyin(const void *uaddr, void *kaddr, size_t len);
13 14
 
14 15
 void do_pmap_load(void)
15 16
 {
@@ -30,12 +31,46 @@ void do_pmap_load(void)
30 31
 
31 32
 }
32 33
 
  34
+int copyin(const void *uaddr, void *kaddr, size_t len)
  35
+{
  36
+	const uint32_t *uaddr_32 = uaddr;
  37
+	const uint8_t *uaddr_8 = uaddr;
  38
+	uint32_t *kaddr_32 = kaddr;
  39
+	uint8_t *kaddr_8 = kaddr;
  40
+	int count;
  41
+
  42
+	if ( curcpu()->ci_want_pmapload )
  43
+		do_pmap_load();
  44
+
  45
+	kaddr_8 += len;
  46
+	if ((size_t)kaddr_8 < len)
  47
+		return EFAULT;
  48
+	if ((size_t)uaddr_8 > VM_MAXUSER_ADDRESS)
  49
+		return EFAULT;
  50
+
  51
+	count = len;
  52
+	count >>= 2;     /* count = count / 4 */
  53
+	while ( count-- > 0)
  54
+		*kaddr_32++ = *uaddr_32++;
  55
+
  56
+	count = len & 0x3;  /* test if it is a multiple of 4 */
  57
+	if (count == 0)
  58
+		return 0;
  59
+
  60
+	kaddr_8 = (uint8_t *)kaddr + len - count;
  61
+
  62
+	while (count-- > 0)
  63
+		*kaddr_8++ = *uaddr_8++;
  64
+
  65
+	return 0;
  66
+}
  67
+
33 68
 int copyout(const void *kaddr, void *uaddr, size_t len)
34 69
 {
35 70
 	uint32_t *uaddr_32 = uaddr;
36 71
 	uint8_t *uaddr_8 = uaddr;
37  
-	uint32_t *kaddr_32 = uaddr;
38  
-	uint8_t *kaddr_8 = uaddr;
  72
+	const uint32_t *kaddr_32 = kaddr;
  73
+	const uint8_t *kaddr_8 = kaddr;
39 74
 	int count;
40 75
 
41 76
 	if ( curcpu()->ci_want_pmapload )

No commit comments for this range

Something went wrong with that request. Please try again.