Rev 1220 | Rev 1277 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
162 | decky | 1 | # |
2 | # Copyright (C) 2005 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 | |||
845 | decky | 29 | #include <arch/asm/regname.h> |
191 | decky | 30 | |
162 | decky | 31 | .text |
32 | |||
1220 | decky | 33 | .global userspace_asm |
1004 | decky | 34 | .global iret |
210 | decky | 35 | .global memsetb |
36 | .global memcpy |
||
185 | decky | 37 | |
1220 | decky | 38 | userspace_asm: |
39 | |||
40 | # r3 = uspace_uarg |
||
41 | # r4 = stack |
||
1267 | decky | 42 | # r5 = entry |
43 | |||
44 | # disable interrupts |
||
1220 | decky | 45 | |
46 | mfmsr r31 |
||
47 | rlwinm r31, r31, 0, 17, 15 |
||
48 | mtmsr r31 |
||
49 | |||
50 | # set entry point |
||
51 | |||
52 | mtsrr0 r5 |
||
53 | |||
54 | # set problem state, enable interrupts |
||
55 | |||
1267 | decky | 56 | ori r31, r31, msr_pr |
57 | ori r31, r31, msr_ee |
||
1220 | decky | 58 | mtsrr1 r31 |
59 | |||
60 | # set stack |
||
61 | |||
62 | mr sp, r4 |
||
63 | |||
64 | # jump to userspace |
||
65 | |||
66 | rfi |
||
67 | |||
1004 | decky | 68 | iret: |
69 | lwz r0, 0(sp) |
||
70 | lwz r2, 4(sp) |
||
71 | lwz r3, 8(sp) |
||
72 | lwz r4, 12(sp) |
||
73 | lwz r5, 16(sp) |
||
74 | lwz r6, 20(sp) |
||
75 | lwz r7, 24(sp) |
||
76 | lwz r8, 28(sp) |
||
77 | lwz r9, 32(sp) |
||
78 | lwz r10, 36(sp) |
||
79 | lwz r11, 40(sp) |
||
1267 | decky | 80 | lwz r13, 44(sp) |
81 | lwz r14, 48(sp) |
||
82 | lwz r15, 52(sp) |
||
83 | lwz r16, 56(sp) |
||
84 | lwz r17, 60(sp) |
||
85 | lwz r18, 64(sp) |
||
86 | lwz r19, 68(sp) |
||
87 | lwz r20, 72(sp) |
||
88 | lwz r21, 76(sp) |
||
89 | lwz r22, 80(sp) |
||
90 | lwz r23, 84(sp) |
||
91 | lwz r24, 88(sp) |
||
92 | lwz r25, 92(sp) |
||
93 | lwz r26, 96(sp) |
||
94 | lwz r27, 100(sp) |
||
95 | lwz r28, 104(sp) |
||
96 | lwz r29, 108(sp) |
||
97 | lwz r30, 112(sp) |
||
98 | lwz r31, 116(sp) |
||
1004 | decky | 99 | |
1267 | decky | 100 | lwz r12, 120(sp) |
101 | mtsrr0 r12 |
||
1004 | decky | 102 | |
1267 | decky | 103 | lwz r12, 124(sp) |
104 | mtsrr1 r12 |
||
105 | |||
106 | lwz r12, 128(sp) |
||
107 | mtlr r12 |
||
108 | |||
109 | lwz r12, 132(sp) |
||
110 | mtcr r12 |
||
111 | |||
112 | lwz r12, 136(sp) |
||
113 | mtctr r12 |
||
114 | |||
115 | lwz r12, 140(sp) |
||
116 | mtxer r12 |
||
117 | |||
118 | mfsprg1 sp |
||
119 | mfsprg2 r12 |
||
120 | |||
1004 | decky | 121 | rfi |
122 | |||
210 | decky | 123 | memsetb: |
124 | rlwimi r5, r5, 8, 16, 23 |
||
125 | rlwimi r5, r5, 16, 0, 15 |
||
126 | |||
127 | addi r14, r3, -4 |
||
128 | |||
129 | cmplwi 0, r4, 4 |
||
130 | blt 7f |
||
131 | |||
132 | stwu r5, 4(r14) |
||
133 | beqlr |
||
134 | |||
135 | andi. r15, r14, 3 |
||
136 | add r4, r15, r4 |
||
137 | subf r14, r15, r14 |
||
138 | srwi r15, r4, 2 |
||
139 | mtctr r15 |
||
140 | |||
141 | bdz 6f |
||
142 | |||
143 | 1: |
||
144 | stwu r5, 4(r14) |
||
145 | bdnz 1b |
||
146 | |||
147 | 6: |
||
148 | |||
149 | andi. r4, r4, 3 |
||
150 | |||
151 | 7: |
||
152 | |||
153 | cmpwi 0, r4, 0 |
||
154 | beqlr |
||
155 | |||
156 | mtctr r4 |
||
157 | addi r6, r6, 3 |
||
158 | |||
159 | 8: |
||
160 | |||
161 | stbu r5, 1(r14) |
||
162 | bdnz 8b |
||
163 | |||
164 | blr |
||
165 | |||
166 | memcpy: |
||
860 | decky | 167 | srwi. r7, r5, 3 |
168 | addi r6, r3, -4 |
||
169 | addi r4, r4, -4 |
||
170 | beq 2f |
||
171 | |||
172 | andi. r0, r6, 3 |
||
173 | mtctr r7 |
||
174 | bne 5f |
||
175 | |||
176 | 1: |
||
177 | |||
178 | lwz r7, 4(r4) |
||
179 | lwzu r8, 8(r4) |
||
180 | stw r7, 4(r6) |
||
181 | stwu r8, 8(r6) |
||
182 | bdnz 1b |
||
183 | |||
184 | andi. r5, r5, 7 |
||
185 | |||
186 | 2: |
||
187 | |||
188 | cmplwi 0, r5, 4 |
||
189 | blt 3f |
||
190 | |||
191 | lwzu r0, 4(r4) |
||
192 | addi r5, r5, -4 |
||
193 | stwu r0, 4(r6) |
||
194 | |||
195 | 3: |
||
196 | |||
197 | cmpwi 0, r5, 0 |
||
198 | beqlr |
||
199 | mtctr r5 |
||
200 | addi r4, r4, 3 |
||
201 | addi r6, r6, 3 |
||
202 | |||
203 | 4: |
||
204 | |||
205 | lbzu r0, 1(r4) |
||
206 | stbu r0, 1(r6) |
||
207 | bdnz 4b |
||
210 | decky | 208 | blr |
860 | decky | 209 | |
210 | 5: |
||
211 | |||
212 | subfic r0, r0, 4 |
||
213 | mtctr r0 |
||
214 | |||
215 | 6: |
||
216 | |||
217 | lbz r7, 4(r4) |
||
218 | addi r4, r4, 1 |
||
219 | stb r7, 4(r6) |
||
220 | addi r6, r6, 1 |
||
221 | bdnz 6b |
||
222 | subf r5, r0, r5 |
||
223 | rlwinm. r7, r5, 32-3, 3, 31 |
||
224 | beq 2b |
||
225 | mtctr r7 |
||
226 | b 1b |