source: mainline/uspace/lib/c/arch/mips32/src/asm.S@ 26346bd

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 26346bd was 26346bd, checked in by Martin Decky <martin@…>, 13 years ago

mips32: implement memset() and memcpy()

  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*
2 * Copyright (c) 2013 Martin Decky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29.text
30
31.set noat
32.set noreorder
33.set nomacro
34
35.global memset
36.global memcpy
37
38memset:
39 move $v0, $a0
40 beqz $a2, 0f
41 addiu $t1, $a2, -1
42
43 negu $t0, $a0
44 andi $t0, $t0, 0x3
45 sltu $v1, $a2, $t0
46 bnez $v1, 1f
47 andi $a1, $a1, 0xff
48
49 7:
50 sltiu $v1, $a2, 4
51 beqz $v1, 2f
52 move $v1, $v0
53
54 move $t0, $a2
55
56 3:
57 sb $a1, 0($v1)
58 addiu $v1, $v1, 1
59 subu $a3, $v1, $v0
60 sltu $a3, $a3, $t0
61 bnez $a3, 3b
62 addiu $t1, $t1, -1
63
64 beq $a2, $t0, 0f
65 subu $a2, $a2, $t0
66
67 8:
68 srl $a0, $a2, 0x2
69 sll $t4, $a0, 0x2
70 beqz $t4, 4f
71 sll $t2, $a1, 0x10
72
73 sll $t3, $a1, 0x8
74 or $t3, $a1, $t3
75 sll $a3, $a1, 0x18
76 or $t3, $t3, $t2
77 or $t3, $t3, $a3
78 addu $t0, $v0, $t0
79 move $a3, $zero
80
81 5:
82 addiu $a3, $a3, 1
83 sltu $t2, $a3, $a0
84 sw $t3, 0($t0)
85 bnez $t2, 5b
86 addiu $t0, $t0, 4
87
88 addu $v1, $v1, $t4
89 beq $a2, $t4, 0f
90 subu $t1, $t1, $t4
91
92 4:
93 addiu $t1, $t1, 1
94 addu $t1, $v1, $t1
95 sb $a1, 0($v1)
96
97 6:
98 addiu $v1, $v1, 1
99 bnel $v1, $t1, 6b
100 sb $a1, 0($v1)
101
102 0:
103 jr $ra
104 nop
105
106 1:
107 j 7b
108 move $t0, $a2
109
110 2:
111 bnez $t0, 3b
112 nop
113
114 j 8b
115 subu $a2, $a2, $t0
116
117memcpy:
118 move $t2, $a0 /* save dst */
119
120 addiu $v0, $a1, 3
121 li $v1, -4 /* 0xfffffffffffffffc */
122 and $v0, $v0, $v1
123 beq $a1, $v0, 3f
124 move $t0, $a0
125
126 0:
127 beq $a2, $zero, 2f
128 move $a3, $zero
129
130 1:
131 addu $v0, $a1, $a3
132 lbu $a0, 0($v0)
133 addu $v1, $t0, $a3
134 addiu $a3, $a3, 1
135 bne $a3, $a2, 1b
136 sb $a0, 0($v1)
137
138 2:
139 jr $ra
140 move $v0, $t2
141
142 3:
143 addiu $v0, $a0, 3
144 and $v0, $v0, $v1
145 bne $a0, $v0, 0b
146 srl $t1, $a2, 2
147
148 beq $t1, $zero, 5f
149 move $a3, $zero
150
151 move $a3, $zero
152 move $a0, $zero
153
154 4:
155 addu $v0, $a1, $a0
156 lw $v1, 0($v0)
157 addiu $a3, $a3, 1
158 addu $v0, $t0, $a0
159 sw $v1, 0($v0)
160 bne $a3, $t1, 4b
161 addiu $a0, $a0, 4
162
163 5:
164 andi $a2, $a2, 0x3
165 beq $a2, $zero, 2b
166 nop
167
168 sll $v0, $a3, 2
169 addu $t1, $v0, $t0
170 move $a3, $zero
171 addu $t0, $v0, $a1
172
173 6:
174 addu $v0, $t0, $a3
175 lbu $a0, 0($v0)
176 addu $v1, $t1, $a3
177 addiu $a3, $a3, 1
178 bne $a3, $a2, 6b
179 sb $a0, 0($v1)
180
181 jr $ra
182 move $v0, $t2
Note: See TracBrowser for help on using the repository browser.