25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: cpu_sparc_instr.c,v 1.21 2006/07/02 11:01:19 debug Exp $ |
* $Id: cpu_sparc_instr.c,v 1.23 2006/07/24 22:32:44 debug Exp $ |
29 |
* |
* |
30 |
* SPARC instructions. |
* SPARC instructions. |
31 |
* |
* |
106 |
|
|
107 |
|
|
108 |
/* |
/* |
109 |
|
* bl |
110 |
|
* |
111 |
|
* arg[0] = int32_t displacement compared to the start of the current page |
112 |
|
*/ |
113 |
|
X(bl) |
114 |
|
{ |
115 |
|
MODE_uint_t old_pc = cpu->pc; |
116 |
|
int n = (cpu->cd.sparc.ccr & SPARC_CCR_N) ? 1 : 0; |
117 |
|
int v = (cpu->cd.sparc.ccr & SPARC_CCR_V) ? 1 : 0; |
118 |
|
int cond = n ^ v; |
119 |
|
cpu->delay_slot = TO_BE_DELAYED; |
120 |
|
ic[1].f(cpu, ic+1); |
121 |
|
cpu->n_translated_instrs ++; |
122 |
|
if (!(cpu->delay_slot & EXCEPTION_IN_DELAY_SLOT)) { |
123 |
|
/* Note: Must be non-delayed when jumping to the new pc: */ |
124 |
|
cpu->delay_slot = NOT_DELAYED; |
125 |
|
if (cond) { |
126 |
|
old_pc &= ~((SPARC_IC_ENTRIES_PER_PAGE - 1) |
127 |
|
<< SPARC_INSTR_ALIGNMENT_SHIFT); |
128 |
|
cpu->pc = old_pc + (int32_t)ic->arg[0]; |
129 |
|
quick_pc_to_pointers(cpu); |
130 |
|
} |
131 |
|
} else |
132 |
|
cpu->delay_slot = NOT_DELAYED; |
133 |
|
} |
134 |
|
X(bl_xcc) |
135 |
|
{ |
136 |
|
MODE_uint_t old_pc = cpu->pc; |
137 |
|
int n = ((cpu->cd.sparc.ccr >> SPARC_CCR_XCC_SHIFT) & SPARC_CCR_N)? 1:0; |
138 |
|
int v = ((cpu->cd.sparc.ccr >> SPARC_CCR_XCC_SHIFT) & SPARC_CCR_V)? 1:0; |
139 |
|
int cond = n ^ v; |
140 |
|
cpu->delay_slot = TO_BE_DELAYED; |
141 |
|
ic[1].f(cpu, ic+1); |
142 |
|
cpu->n_translated_instrs ++; |
143 |
|
if (!(cpu->delay_slot & EXCEPTION_IN_DELAY_SLOT)) { |
144 |
|
/* Note: Must be non-delayed when jumping to the new pc: */ |
145 |
|
cpu->delay_slot = NOT_DELAYED; |
146 |
|
if (cond) { |
147 |
|
old_pc &= ~((SPARC_IC_ENTRIES_PER_PAGE - 1) |
148 |
|
<< SPARC_INSTR_ALIGNMENT_SHIFT); |
149 |
|
cpu->pc = old_pc + (int32_t)ic->arg[0]; |
150 |
|
quick_pc_to_pointers(cpu); |
151 |
|
} |
152 |
|
} else |
153 |
|
cpu->delay_slot = NOT_DELAYED; |
154 |
|
} |
155 |
|
|
156 |
|
|
157 |
|
/* |
158 |
|
* bne |
159 |
|
* |
160 |
|
* arg[0] = int32_t displacement compared to the start of the current page |
161 |
|
*/ |
162 |
|
X(bne) |
163 |
|
{ |
164 |
|
MODE_uint_t old_pc = cpu->pc; |
165 |
|
int cond = (cpu->cd.sparc.ccr & SPARC_CCR_Z) ? 0 : 1; |
166 |
|
cpu->delay_slot = TO_BE_DELAYED; |
167 |
|
ic[1].f(cpu, ic+1); |
168 |
|
cpu->n_translated_instrs ++; |
169 |
|
if (!(cpu->delay_slot & EXCEPTION_IN_DELAY_SLOT)) { |
170 |
|
/* Note: Must be non-delayed when jumping to the new pc: */ |
171 |
|
cpu->delay_slot = NOT_DELAYED; |
172 |
|
if (cond) { |
173 |
|
old_pc &= ~((SPARC_IC_ENTRIES_PER_PAGE - 1) |
174 |
|
<< SPARC_INSTR_ALIGNMENT_SHIFT); |
175 |
|
cpu->pc = old_pc + (int32_t)ic->arg[0]; |
176 |
|
quick_pc_to_pointers(cpu); |
177 |
|
} |
178 |
|
} else |
179 |
|
cpu->delay_slot = NOT_DELAYED; |
180 |
|
} |
181 |
|
X(bne_a) |
182 |
|
{ |
183 |
|
MODE_uint_t old_pc = cpu->pc; |
184 |
|
int cond = (cpu->cd.sparc.ccr & SPARC_CCR_Z) ? 0 : 1; |
185 |
|
cpu->delay_slot = TO_BE_DELAYED; |
186 |
|
if (!cond) { |
187 |
|
/* Nullify the delay slot: */ |
188 |
|
cpu->cd.sparc.next_ic ++; |
189 |
|
return; |
190 |
|
} |
191 |
|
ic[1].f(cpu, ic+1); |
192 |
|
cpu->n_translated_instrs ++; |
193 |
|
if (!(cpu->delay_slot & EXCEPTION_IN_DELAY_SLOT)) { |
194 |
|
/* Note: Must be non-delayed when jumping to the new pc: */ |
195 |
|
cpu->delay_slot = NOT_DELAYED; |
196 |
|
old_pc &= ~((SPARC_IC_ENTRIES_PER_PAGE - 1) |
197 |
|
<< SPARC_INSTR_ALIGNMENT_SHIFT); |
198 |
|
cpu->pc = old_pc + (int32_t)ic->arg[0]; |
199 |
|
quick_pc_to_pointers(cpu); |
200 |
|
} else |
201 |
|
cpu->delay_slot = NOT_DELAYED; |
202 |
|
} |
203 |
|
|
204 |
|
|
205 |
|
/* |
206 |
|
* bg |
207 |
|
* |
208 |
|
* arg[0] = int32_t displacement compared to the start of the current page |
209 |
|
*/ |
210 |
|
X(bg) |
211 |
|
{ |
212 |
|
MODE_uint_t old_pc = cpu->pc; |
213 |
|
int n = (cpu->cd.sparc.ccr & SPARC_CCR_N) ? 1 : 0; |
214 |
|
int v = (cpu->cd.sparc.ccr & SPARC_CCR_V) ? 1 : 0; |
215 |
|
int z = (cpu->cd.sparc.ccr & SPARC_CCR_Z) ? 1 : 0; |
216 |
|
int cond = !(z | (n ^ v)); |
217 |
|
cpu->delay_slot = TO_BE_DELAYED; |
218 |
|
ic[1].f(cpu, ic+1); |
219 |
|
cpu->n_translated_instrs ++; |
220 |
|
if (!(cpu->delay_slot & EXCEPTION_IN_DELAY_SLOT)) { |
221 |
|
/* Note: Must be non-delayed when jumping to the new pc: */ |
222 |
|
cpu->delay_slot = NOT_DELAYED; |
223 |
|
if (cond) { |
224 |
|
old_pc &= ~((SPARC_IC_ENTRIES_PER_PAGE - 1) |
225 |
|
<< SPARC_INSTR_ALIGNMENT_SHIFT); |
226 |
|
cpu->pc = old_pc + (int32_t)ic->arg[0]; |
227 |
|
quick_pc_to_pointers(cpu); |
228 |
|
} |
229 |
|
} else |
230 |
|
cpu->delay_slot = NOT_DELAYED; |
231 |
|
} |
232 |
|
X(bg_xcc) |
233 |
|
{ |
234 |
|
MODE_uint_t old_pc = cpu->pc; |
235 |
|
int n = ((cpu->cd.sparc.ccr >> SPARC_CCR_XCC_SHIFT) & SPARC_CCR_N)? 1:0; |
236 |
|
int v = ((cpu->cd.sparc.ccr >> SPARC_CCR_XCC_SHIFT) & SPARC_CCR_V)? 1:0; |
237 |
|
int z = ((cpu->cd.sparc.ccr >> SPARC_CCR_XCC_SHIFT) & SPARC_CCR_Z)? 1:0; |
238 |
|
int cond = !(z | (n ^ v)); |
239 |
|
cpu->delay_slot = TO_BE_DELAYED; |
240 |
|
ic[1].f(cpu, ic+1); |
241 |
|
cpu->n_translated_instrs ++; |
242 |
|
if (!(cpu->delay_slot & EXCEPTION_IN_DELAY_SLOT)) { |
243 |
|
/* Note: Must be non-delayed when jumping to the new pc: */ |
244 |
|
cpu->delay_slot = NOT_DELAYED; |
245 |
|
if (cond) { |
246 |
|
old_pc &= ~((SPARC_IC_ENTRIES_PER_PAGE - 1) |
247 |
|
<< SPARC_INSTR_ALIGNMENT_SHIFT); |
248 |
|
cpu->pc = old_pc + (int32_t)ic->arg[0]; |
249 |
|
quick_pc_to_pointers(cpu); |
250 |
|
} |
251 |
|
} else |
252 |
|
cpu->delay_slot = NOT_DELAYED; |
253 |
|
} |
254 |
|
|
255 |
|
|
256 |
|
/* |
257 |
|
* bge |
258 |
|
* |
259 |
|
* arg[0] = int32_t displacement compared to the start of the current page |
260 |
|
*/ |
261 |
|
X(bge) |
262 |
|
{ |
263 |
|
MODE_uint_t old_pc = cpu->pc; |
264 |
|
int n = (cpu->cd.sparc.ccr & SPARC_CCR_N) ? 1 : 0; |
265 |
|
int v = (cpu->cd.sparc.ccr & SPARC_CCR_V) ? 1 : 0; |
266 |
|
int cond = !(n ^ v); |
267 |
|
cpu->delay_slot = TO_BE_DELAYED; |
268 |
|
ic[1].f(cpu, ic+1); |
269 |
|
cpu->n_translated_instrs ++; |
270 |
|
if (!(cpu->delay_slot & EXCEPTION_IN_DELAY_SLOT)) { |
271 |
|
/* Note: Must be non-delayed when jumping to the new pc: */ |
272 |
|
cpu->delay_slot = NOT_DELAYED; |
273 |
|
if (cond) { |
274 |
|
old_pc &= ~((SPARC_IC_ENTRIES_PER_PAGE - 1) |
275 |
|
<< SPARC_INSTR_ALIGNMENT_SHIFT); |
276 |
|
cpu->pc = old_pc + (int32_t)ic->arg[0]; |
277 |
|
quick_pc_to_pointers(cpu); |
278 |
|
} |
279 |
|
} else |
280 |
|
cpu->delay_slot = NOT_DELAYED; |
281 |
|
} |
282 |
|
X(bge_xcc) |
283 |
|
{ |
284 |
|
MODE_uint_t old_pc = cpu->pc; |
285 |
|
int n = ((cpu->cd.sparc.ccr >> SPARC_CCR_XCC_SHIFT) & SPARC_CCR_N)? 1:0; |
286 |
|
int v = ((cpu->cd.sparc.ccr >> SPARC_CCR_XCC_SHIFT) & SPARC_CCR_V)? 1:0; |
287 |
|
int cond = !(n ^ v); |
288 |
|
cpu->delay_slot = TO_BE_DELAYED; |
289 |
|
ic[1].f(cpu, ic+1); |
290 |
|
cpu->n_translated_instrs ++; |
291 |
|
if (!(cpu->delay_slot & EXCEPTION_IN_DELAY_SLOT)) { |
292 |
|
/* Note: Must be non-delayed when jumping to the new pc: */ |
293 |
|
cpu->delay_slot = NOT_DELAYED; |
294 |
|
if (cond) { |
295 |
|
old_pc &= ~((SPARC_IC_ENTRIES_PER_PAGE - 1) |
296 |
|
<< SPARC_INSTR_ALIGNMENT_SHIFT); |
297 |
|
cpu->pc = old_pc + (int32_t)ic->arg[0]; |
298 |
|
quick_pc_to_pointers(cpu); |
299 |
|
} |
300 |
|
} else |
301 |
|
cpu->delay_slot = NOT_DELAYED; |
302 |
|
} |
303 |
|
|
304 |
|
|
305 |
|
/* |
306 |
|
* be |
307 |
|
* |
308 |
|
* arg[0] = int32_t displacement compared to the start of the current page |
309 |
|
*/ |
310 |
|
X(be) |
311 |
|
{ |
312 |
|
MODE_uint_t old_pc = cpu->pc; |
313 |
|
int cond = cpu->cd.sparc.ccr & SPARC_CCR_Z; |
314 |
|
cpu->delay_slot = TO_BE_DELAYED; |
315 |
|
ic[1].f(cpu, ic+1); |
316 |
|
cpu->n_translated_instrs ++; |
317 |
|
if (!(cpu->delay_slot & EXCEPTION_IN_DELAY_SLOT)) { |
318 |
|
/* Note: Must be non-delayed when jumping to the new pc: */ |
319 |
|
cpu->delay_slot = NOT_DELAYED; |
320 |
|
if (cond) { |
321 |
|
old_pc &= ~((SPARC_IC_ENTRIES_PER_PAGE - 1) |
322 |
|
<< SPARC_INSTR_ALIGNMENT_SHIFT); |
323 |
|
cpu->pc = old_pc + (int32_t)ic->arg[0]; |
324 |
|
quick_pc_to_pointers(cpu); |
325 |
|
} |
326 |
|
} else |
327 |
|
cpu->delay_slot = NOT_DELAYED; |
328 |
|
} |
329 |
|
X(be_xcc) |
330 |
|
{ |
331 |
|
MODE_uint_t old_pc = cpu->pc; |
332 |
|
int cond = (cpu->cd.sparc.ccr >> SPARC_CCR_XCC_SHIFT) & SPARC_CCR_Z; |
333 |
|
cpu->delay_slot = TO_BE_DELAYED; |
334 |
|
ic[1].f(cpu, ic+1); |
335 |
|
cpu->n_translated_instrs ++; |
336 |
|
if (!(cpu->delay_slot & EXCEPTION_IN_DELAY_SLOT)) { |
337 |
|
/* Note: Must be non-delayed when jumping to the new pc: */ |
338 |
|
cpu->delay_slot = NOT_DELAYED; |
339 |
|
if (cond) { |
340 |
|
old_pc &= ~((SPARC_IC_ENTRIES_PER_PAGE - 1) |
341 |
|
<< SPARC_INSTR_ALIGNMENT_SHIFT); |
342 |
|
cpu->pc = old_pc + (int32_t)ic->arg[0]; |
343 |
|
quick_pc_to_pointers(cpu); |
344 |
|
} |
345 |
|
} else |
346 |
|
cpu->delay_slot = NOT_DELAYED; |
347 |
|
} |
348 |
|
|
349 |
|
|
350 |
|
/* |
351 |
* ba |
* ba |
352 |
* |
* |
353 |
* arg[0] = int32_t displacement compared to the start of the current page |
* arg[0] = int32_t displacement compared to the start of the current page |
371 |
|
|
372 |
|
|
373 |
/* |
/* |
374 |
|
* brnz |
375 |
|
* |
376 |
|
* arg[0] = int32_t displacement compared to the start of the current page |
377 |
|
* arg[1] = ptr to rs1 |
378 |
|
*/ |
379 |
|
X(brnz) |
380 |
|
{ |
381 |
|
MODE_uint_t old_pc = cpu->pc; |
382 |
|
int cond = reg(ic->arg[1]) != 0; |
383 |
|
cpu->delay_slot = TO_BE_DELAYED; |
384 |
|
ic[1].f(cpu, ic+1); |
385 |
|
cpu->n_translated_instrs ++; |
386 |
|
if (!(cpu->delay_slot & EXCEPTION_IN_DELAY_SLOT)) { |
387 |
|
/* Note: Must be non-delayed when jumping to the new pc: */ |
388 |
|
cpu->delay_slot = NOT_DELAYED; |
389 |
|
if (cond) { |
390 |
|
old_pc &= ~((SPARC_IC_ENTRIES_PER_PAGE - 1) |
391 |
|
<< SPARC_INSTR_ALIGNMENT_SHIFT); |
392 |
|
cpu->pc = old_pc + (int32_t)ic->arg[0]; |
393 |
|
quick_pc_to_pointers(cpu); |
394 |
|
} |
395 |
|
} else |
396 |
|
cpu->delay_slot = NOT_DELAYED; |
397 |
|
} |
398 |
|
|
399 |
|
|
400 |
|
/* |
401 |
* Jump and link |
* Jump and link |
402 |
* |
* |
403 |
* arg[0] = ptr to rs1 |
* arg[0] = ptr to rs1 |
606 |
X(sra_imm) { reg(ic->arg[2]) = (int32_t)reg(ic->arg[0]) >> ic->arg[1]; } |
X(sra_imm) { reg(ic->arg[2]) = (int32_t)reg(ic->arg[0]) >> ic->arg[1]; } |
607 |
X(srax_imm) { reg(ic->arg[2]) = (int64_t)reg(ic->arg[0]) >> ic->arg[1]; } |
X(srax_imm) { reg(ic->arg[2]) = (int64_t)reg(ic->arg[0]) >> ic->arg[1]; } |
608 |
|
|
609 |
|
X(udiv) |
610 |
|
{ |
611 |
|
uint64_t z = (cpu->cd.sparc.y << 32) | (uint32_t)reg(ic->arg[0]); |
612 |
|
z /= (uint32_t)reg(ic->arg[1]); |
613 |
|
if (z > 0xffffffff) |
614 |
|
z = 0xffffffff; |
615 |
|
reg(ic->arg[2]) = z; |
616 |
|
} |
617 |
|
X(udiv_imm) |
618 |
|
{ |
619 |
|
uint64_t z = (cpu->cd.sparc.y << 32) | (uint32_t)reg(ic->arg[0]); |
620 |
|
z /= (uint32_t)ic->arg[1]; |
621 |
|
if (z > 0xffffffff) |
622 |
|
z = 0xffffffff; |
623 |
|
reg(ic->arg[2]) = z; |
624 |
|
} |
625 |
|
|
626 |
|
|
627 |
/* |
/* |
628 |
* Save: |
* Save: |
671 |
|
|
672 |
|
|
673 |
/* |
/* |
674 |
|
* Add with ccr update: |
675 |
|
* |
676 |
|
* arg[0] = ptr to rs1 |
677 |
|
* arg[1] = ptr to rs2 or an immediate value (int32_t) |
678 |
|
* arg[2] = ptr to rd |
679 |
|
*/ |
680 |
|
int32_t sparc_addcc32(struct cpu *cpu, int32_t rs1, int32_t rs2); |
681 |
|
#ifdef MODE32 |
682 |
|
int32_t sparc_addcc32(struct cpu *cpu, int32_t rs1, int32_t rs2) |
683 |
|
#else |
684 |
|
int64_t sparc_addcc64(struct cpu *cpu, int64_t rs1, int64_t rs2) |
685 |
|
#endif |
686 |
|
{ |
687 |
|
int cc = 0, sign1 = 0, sign2 = 0, signd = 0, mask = SPARC_CCR_ICC_MASK; |
688 |
|
MODE_int_t rd = rs1 + rs2; |
689 |
|
if (rd == 0) |
690 |
|
cc = SPARC_CCR_Z; |
691 |
|
else if (rd < 0) |
692 |
|
cc = SPARC_CCR_N, signd = 1; |
693 |
|
if (rs1 < 0) |
694 |
|
sign1 = 1; |
695 |
|
if (rs2 < 0) |
696 |
|
sign2 = 1; |
697 |
|
if (sign1 == sign2 && sign1 != signd) |
698 |
|
cc |= SPARC_CCR_V; |
699 |
|
/* TODO: SPARC_CCR_C */ |
700 |
|
#ifndef MODE32 |
701 |
|
mask <<= SPARC_CCR_XCC_SHIFT; |
702 |
|
cc <<= SPARC_CCR_XCC_SHIFT; |
703 |
|
#endif |
704 |
|
cpu->cd.sparc.ccr &= ~mask; |
705 |
|
cpu->cd.sparc.ccr |= cc; |
706 |
|
return rd; |
707 |
|
} |
708 |
|
X(addcc) |
709 |
|
{ |
710 |
|
/* Like add, but updates the ccr, and does both 32-bit and |
711 |
|
64-bit comparison at the same time. */ |
712 |
|
MODE_int_t rs1 = reg(ic->arg[0]), rs2 = reg(ic->arg[1]), rd; |
713 |
|
rd = sparc_addcc32(cpu, rs1, rs2); |
714 |
|
#ifndef MODE32 |
715 |
|
rd = sparc_addcc64(cpu, rs1, rs2); |
716 |
|
#endif |
717 |
|
reg(ic->arg[2]) = rd; |
718 |
|
} |
719 |
|
X(addcc_imm) |
720 |
|
{ |
721 |
|
MODE_int_t rs1 = reg(ic->arg[0]), rs2 = (int32_t)ic->arg[1], rd; |
722 |
|
rd = sparc_addcc32(cpu, rs1, rs2); |
723 |
|
#ifndef MODE32 |
724 |
|
rd = sparc_addcc64(cpu, rs1, rs2); |
725 |
|
#endif |
726 |
|
reg(ic->arg[2]) = rd; |
727 |
|
} |
728 |
|
|
729 |
|
|
730 |
|
/* |
731 |
|
* And with ccr update: |
732 |
|
* |
733 |
|
* arg[0] = ptr to rs1 |
734 |
|
* arg[1] = ptr to rs2 or an immediate value (int32_t) |
735 |
|
* arg[2] = ptr to rd |
736 |
|
*/ |
737 |
|
int32_t sparc_andcc32(struct cpu *cpu, int32_t rs1, int32_t rs2); |
738 |
|
#ifdef MODE32 |
739 |
|
int32_t sparc_andcc32(struct cpu *cpu, int32_t rs1, int32_t rs2) |
740 |
|
#else |
741 |
|
int64_t sparc_andcc64(struct cpu *cpu, int64_t rs1, int64_t rs2) |
742 |
|
#endif |
743 |
|
{ |
744 |
|
int cc = 0, mask = SPARC_CCR_ICC_MASK; |
745 |
|
MODE_int_t rd = rs1 & rs2; |
746 |
|
if (rd == 0) |
747 |
|
cc = SPARC_CCR_Z; |
748 |
|
else if (rd < 0) |
749 |
|
cc = SPARC_CCR_N; |
750 |
|
/* Note: SPARC_CCR_C and SPARC_CCR_V are always zero. */ |
751 |
|
#ifndef MODE32 |
752 |
|
mask <<= SPARC_CCR_XCC_SHIFT; |
753 |
|
cc <<= SPARC_CCR_XCC_SHIFT; |
754 |
|
#endif |
755 |
|
cpu->cd.sparc.ccr &= ~mask; |
756 |
|
cpu->cd.sparc.ccr |= cc; |
757 |
|
return rd; |
758 |
|
} |
759 |
|
X(andcc) |
760 |
|
{ |
761 |
|
/* Like and, but updates the ccr, and does both 32-bit and |
762 |
|
64-bit comparison at the same time. */ |
763 |
|
MODE_int_t rs1 = reg(ic->arg[0]), rs2 = reg(ic->arg[1]), rd; |
764 |
|
rd = sparc_andcc32(cpu, rs1, rs2); |
765 |
|
#ifndef MODE32 |
766 |
|
rd = sparc_andcc64(cpu, rs1, rs2); |
767 |
|
#endif |
768 |
|
reg(ic->arg[2]) = rd; |
769 |
|
} |
770 |
|
X(andcc_imm) |
771 |
|
{ |
772 |
|
MODE_int_t rs1 = reg(ic->arg[0]), rs2 = (int32_t)ic->arg[1], rd; |
773 |
|
rd = sparc_andcc32(cpu, rs1, rs2); |
774 |
|
#ifndef MODE32 |
775 |
|
rd = sparc_andcc64(cpu, rs1, rs2); |
776 |
|
#endif |
777 |
|
reg(ic->arg[2]) = rd; |
778 |
|
} |
779 |
|
|
780 |
|
|
781 |
|
/* |
782 |
* Subtract with ccr update: |
* Subtract with ccr update: |
783 |
* |
* |
784 |
* arg[0] = ptr to rs1 |
* arg[0] = ptr to rs1 |
839 |
|
|
840 |
|
|
841 |
/* |
/* |
842 |
* rd: Read special register: |
* rd: Read special register |
843 |
* |
* |
844 |
* arg[2] = ptr to rd |
* arg[2] = ptr to rd |
845 |
*/ |
*/ |
850 |
|
|
851 |
|
|
852 |
/* |
/* |
853 |
|
* rdpr: Read privileged register |
854 |
|
* |
855 |
|
* arg[2] = ptr to rd |
856 |
|
*/ |
857 |
|
X(rdpr_tba) |
858 |
|
{ |
859 |
|
reg(ic->arg[2]) = cpu->cd.sparc.tba; |
860 |
|
} |
861 |
|
X(rdpr_ver) |
862 |
|
{ |
863 |
|
reg(ic->arg[2]) = cpu->cd.sparc.ver; |
864 |
|
} |
865 |
|
|
866 |
|
|
867 |
|
/* |
868 |
* wrpr: Write to privileged register |
* wrpr: Write to privileged register |
869 |
* |
* |
870 |
* arg[0] = ptr to rs1 |
* arg[0] = ptr to rs1 |
1040 |
|
|
1041 |
case 0: switch (op2) { |
case 0: switch (op2) { |
1042 |
|
|
1043 |
|
case 1: /* branch (icc or xcc) */ |
1044 |
|
tmpi32 = (iword << 13); |
1045 |
|
tmpi32 >>= 11; |
1046 |
|
ic->arg[0] = (int32_t)tmpi32 + (addr & 0xffc); |
1047 |
|
/* rd contains the annul bit concatenated with 4 bits |
1048 |
|
of condition code. cc=0 for icc, 2 for xcc: */ |
1049 |
|
/* TODO: samepage */ |
1050 |
|
switch (rd + (cc << 5)) { |
1051 |
|
case 0x01: ic->f = instr(be); break; |
1052 |
|
case 0x03: ic->f = instr(bl); break; |
1053 |
|
case 0x09: ic->f = instr(bne); break; |
1054 |
|
case 0x0a: ic->f = instr(bg); break; |
1055 |
|
case 0x0b: ic->f = instr(bge); break; |
1056 |
|
case 0x19: ic->f = instr(bne_a); break; |
1057 |
|
case 0x41: ic->f = instr(be_xcc); break; |
1058 |
|
case 0x43: ic->f = instr(bl_xcc); break; |
1059 |
|
case 0x4a: ic->f = instr(bg_xcc); break; |
1060 |
|
case 0x4b: ic->f = instr(bge_xcc); break; |
1061 |
|
default:fatal("Unimplemented branch, 0x%x\n", |
1062 |
|
rd + (cc<<5)); |
1063 |
|
goto bad; |
1064 |
|
} |
1065 |
|
break; |
1066 |
|
|
1067 |
case 2: /* branch (32-bit integer comparison) */ |
case 2: /* branch (32-bit integer comparison) */ |
1068 |
tmpi32 = (iword << 10); |
tmpi32 = (iword << 10); |
1069 |
tmpi32 >>= 8; |
tmpi32 >>= 8; |
1072 |
of condition code: */ |
of condition code: */ |
1073 |
/* TODO: samepage */ |
/* TODO: samepage */ |
1074 |
switch (rd) { |
switch (rd) { |
1075 |
case 0x08:/* ba */ |
case 0x01: ic->f = instr(be); break; |
1076 |
ic->f = instr(ba); |
case 0x03: ic->f = instr(bl); break; |
1077 |
break; |
case 0x08: ic->f = instr(ba); break; |
1078 |
default:goto bad; |
case 0x0b: ic->f = instr(bge); break; |
1079 |
|
default:fatal("Unimplemented branch rd=%i\n", rd); |
1080 |
|
goto bad; |
1081 |
|
} |
1082 |
|
break; |
1083 |
|
|
1084 |
|
case 3: /* branch on register, 64-bit integer comparison */ |
1085 |
|
tmpi32 = ((iword & 0x300000) >> 6) | (iword & 0x3fff); |
1086 |
|
tmpi32 <<= 16; |
1087 |
|
tmpi32 >>= 14; |
1088 |
|
ic->arg[0] = (int32_t)tmpi32 + (addr & 0xffc); |
1089 |
|
ic->arg[1] = (size_t)&cpu->cd.sparc.r[rs1]; |
1090 |
|
/* TODO: samepage */ |
1091 |
|
switch (btype) { |
1092 |
|
case 0x05: ic->f = instr(brnz); break; |
1093 |
|
default:fatal("Unimplemented branch 0x%x\n", rd); |
1094 |
|
goto bad; |
1095 |
} |
} |
1096 |
break; |
break; |
1097 |
|
|
1127 |
case 2: /* or */ |
case 2: /* or */ |
1128 |
case 3: /* xor */ |
case 3: /* xor */ |
1129 |
case 4: /* sub */ |
case 4: /* sub */ |
1130 |
|
case 14:/* udiv */ |
1131 |
|
case 16:/* addcc */ |
1132 |
|
case 17:/* andcc */ |
1133 |
case 20:/* subcc (cmp) */ |
case 20:/* subcc (cmp) */ |
1134 |
case 37:/* sll */ |
case 37:/* sll */ |
1135 |
case 38:/* srl */ |
case 38:/* srl */ |
1145 |
case 2: ic->f = instr(or_imm); break; |
case 2: ic->f = instr(or_imm); break; |
1146 |
case 3: ic->f = instr(xor_imm); break; |
case 3: ic->f = instr(xor_imm); break; |
1147 |
case 4: ic->f = instr(sub_imm); break; |
case 4: ic->f = instr(sub_imm); break; |
1148 |
|
case 14:ic->f = instr(udiv_imm); break; |
1149 |
|
case 16:ic->f = instr(addcc_imm); break; |
1150 |
|
case 17:ic->f = instr(andcc_imm); break; |
1151 |
case 20:ic->f = instr(subcc_imm); break; |
case 20:ic->f = instr(subcc_imm); break; |
1152 |
case 37:if (siconst & 0x1000) { |
case 37:if (siconst & 0x1000) { |
1153 |
ic->f = instr(sllx_imm); |
ic->f = instr(sllx_imm); |
1191 |
case 2: ic->f = instr(or); break; |
case 2: ic->f = instr(or); break; |
1192 |
case 3: ic->f = instr(xor); break; |
case 3: ic->f = instr(xor); break; |
1193 |
case 4: ic->f = instr(sub); break; |
case 4: ic->f = instr(sub); break; |
1194 |
|
case 14:ic->f = instr(udiv); break; |
1195 |
|
case 16:ic->f = instr(addcc); break; |
1196 |
|
case 17:ic->f = instr(andcc); break; |
1197 |
case 20:ic->f = instr(subcc); break; |
case 20:ic->f = instr(subcc); break; |
1198 |
case 37:if (siconst & 0x1000) { |
case 37:if (siconst & 0x1000) { |
1199 |
ic->f = instr(sllx); |
ic->f = instr(sllx); |
1226 |
* Some opcodes should write to the scratch |
* Some opcodes should write to the scratch |
1227 |
* register instead of becoming NOPs, when |
* register instead of becoming NOPs, when |
1228 |
* rd is the zero register. |
* rd is the zero register. |
1229 |
|
* |
1230 |
|
* Any opcode which updates the condition |
1231 |
|
* codes, or anything which changes register |
1232 |
|
* windows. |
1233 |
*/ |
*/ |
1234 |
switch (op2) { |
switch (op2) { |
1235 |
|
case 16:/* addcc */ |
1236 |
|
case 17:/* andcc */ |
1237 |
case 20:/* subcc */ |
case 20:/* subcc */ |
1238 |
case 60:/* save */ |
case 60:/* save */ |
1239 |
ic->arg[2] = (size_t) |
ic->arg[2] = (size_t) |
1256 |
goto bad; |
goto bad; |
1257 |
} |
} |
1258 |
break; |
break; |
1259 |
|
|
1260 |
|
case 42:/* rdpr on sparcv9 */ |
1261 |
|
if (cpu->is_32bit) { |
1262 |
|
fatal("opcode 2,42 not yet implemented" |
1263 |
|
" for 32-bit cpus\n"); |
1264 |
|
goto bad; |
1265 |
|
} |
1266 |
|
ic->arg[2] = (size_t)&cpu->cd.sparc.r[rd]; |
1267 |
|
if (rd == SPARC_ZEROREG) |
1268 |
|
ic->f = instr(nop); |
1269 |
|
switch (rs1) { |
1270 |
|
case 5: ic->f = instr(rdpr_tba); break; |
1271 |
|
case 31: ic->f = instr(rdpr_ver); break; |
1272 |
|
default:fatal("Unimplemented rs1=%i\n", rs1); |
1273 |
|
goto bad; |
1274 |
|
} |
1275 |
|
break; |
1276 |
|
|
1277 |
case 48:/* wr (Note: works as xor) */ |
case 48:/* wr (Note: works as xor) */ |
1278 |
ic->arg[0] = (size_t)&cpu->cd.sparc.r[rs1]; |
ic->arg[0] = (size_t)&cpu->cd.sparc.r[rs1]; |