1 # gr28-gr31, fr31, icc3, fcc3 are used as tmps.
2 # consider them call clobbered by these macros.
13 ; enable data and insn caches in copy-back mode
14 ; Also enable all registers
15 or_spr_immed 0xc80003c0,hsr0
16 and_spr_immed 0xfffff3ff,hsr0
18 ; turn on psr.nem, psr.cm, psr.ef, psr.em, psr.esr,
19 ; disable external interrupts
20 or_spr_immed 0x69f8,psr
22 ; If fsr exists, enable all fp_exceptions except inexact
25 subicc gr28,0x2,gr0,icc3 ; is fr400?
27 or_spr_immed 0x3d000000,fsr0
30 ; Set the stack pointer
32 setlo 0xfffc,sp ; TODO -- what's a good value for this?
37 movgs gr28,tbr ; TODO -- what's a good value for this?
39 ; Go to user mode -- causes too many problems
40 ;and_spr_immed 0xfffffffb,psr
43 ; Set GR with another GR
44 .macro set_gr_gr src targ
48 ; Set GR with immediate value
49 .macro set_gr_immed val reg
50 .if (\val >= -32768) && (\val <= 23767)
53 setlo.p %lo(\val),\reg
58 .macro set_gr_limmed valh vall reg
63 ; Set GR with address value
64 .macro set_gr_addr addr reg
65 sethi.p %hi(\addr),\reg
70 .macro set_gr_spr src targ
74 ; Set GR with a value from memory
75 .macro set_gr_mem addr reg
76 set_gr_addr \addr,gr28
80 ; Increment GR with immediate value
81 .macro inc_gr_immed val reg
82 .if (\val >= -2048) && (\val <= 2047)
85 set_gr_immed \val,gr28
90 ; AND GR with immediate value
91 .macro and_gr_immed val reg
92 .if (\val >= -2048) && (\val <= 2047)
95 set_gr_immed \val,gr28
100 ; OR GR with immediate value
101 .macro or_gr_immed val reg
102 .if (\val >= -2048) && (\val <= 2047)
105 set_gr_immed \val,gr28
110 ; Set FR with another FR
111 .macro set_fr_fr src targ
115 ; Set FR with integer immediate value
116 .macro set_fr_iimmed valh vall reg
117 set_gr_limmed \valh,\vall,gr28
121 ; Set FR with integer immediate value
122 .macro set_fr_immed val reg
123 set_gr_immed \val,gr28
127 ; Set FR with a value from memory
128 .macro set_fr_mem addr reg
129 set_gr_addr \addr,gr28
133 ; Set double FR with another double FR
134 .macro set_dfr_dfr src targ
138 ; Set double FR with a value from memory
139 .macro set_dfr_mem addr reg
140 set_gr_addr \addr,gr28
144 ; Set CPR with immediate value
145 .macro set_cpr_immed val reg
147 set_gr_immed \val,gr29
152 .macro set_cpr_limmed valh vall reg
154 set_gr_limmed \valh,\vall,gr29
159 ; Set SPR with immediate value
160 .macro set_spr_immed val reg
161 set_gr_immed \val,gr28
165 .macro set_spr_limmed valh vall reg
166 set_gr_limmed \valh,\vall,gr28
170 .macro set_spr_addr addr reg
171 set_gr_addr \addr,gr28
175 ; increment SPR with immediate value
176 .macro inc_spr_immed val reg
178 inc_gr_immed \val,gr28
182 ; OR spr with immediate value
183 .macro or_spr_immed val reg
185 set_gr_immed \val,gr29
190 ; AND spr with immediate value
191 .macro and_spr_immed val reg
193 set_gr_immed \val,gr29
198 ; Set accumulator with immediate value
199 .macro set_acc_immed val reg
200 set_fr_immed \val,fr31
204 ; Set accumulator guard with immediate value
205 .macro set_accg_immed val reg
206 set_fr_immed \val,fr31
210 ; Set memory with immediate value
211 .macro set_mem_immed val base
212 set_gr_immed \val,gr28
216 .macro set_mem_limmed valh vall base
217 set_gr_limmed \valh,\vall,gr28
221 ; Set memory with GR value
222 .macro set_mem_gr reg addr
223 set_gr_addr \addr,gr28
227 ; Test the value of a general register against another general register
228 .macro test_gr_gr reg1 reg2
229 subcc \reg1,\reg2,gr0,icc3
235 ; Test the value of an immediate against a general register
236 .macro test_gr_immed val reg
237 .if (\val >= -512) && (\val <= 511)
238 subicc \reg,\val,gr0,icc3
240 set_gr_immed \val,gr28
241 subcc \reg,gr28,gr0,icc3
248 .macro test_gr_limmed valh vall reg
249 set_gr_limmed \valh,\vall,gr28
250 subcc \reg,gr28,gr0,icc3
256 ; Test the value of an floating register against an integer immediate
257 .macro test_fr_limmed valh vall reg
259 set_gr_limmed \valh,\vall,gr28
260 subcc gr29,gr28,gr0,icc3
266 .macro test_fr_iimmed val reg
268 set_gr_immed \val,gr28
269 subcc gr29,gr28,gr0,icc3
275 ; Test the value of a floating register against another floating point register
276 .macro test_fr_fr reg1 reg2
277 fcmps \reg1,\reg2,fcc3
278 fbeq fcc3,0,test_gr\@
283 ; Test the value of a double floating register against another
284 ; double floating point register
285 .macro test_dfr_dfr reg1 reg2
286 fcmpd \reg1,\reg2,fcc3
287 fbeq fcc3,0,test_gr\@
292 ; Test the value of a special purpose register against an integer immediate
293 .macro test_spr_immed val reg
295 set_gr_immed \val,gr28
296 subcc gr29,gr28,gr0,icc3
302 .macro test_spr_limmed valh vall reg
304 set_gr_limmed \valh,\vall,gr28
305 subcc gr29,gr28,gr0,icc3
311 .macro test_spr_gr spr gr
316 .macro test_spr_addr addr reg
318 set_gr_addr \addr,gr28
322 ; Test spr bits masked and shifted against the given value
323 .macro test_spr_bits mask,shift,val,reg
325 set_gr_immed \mask,gr29
327 srli gr28,\shift,gr29
328 test_gr_immed \val,gr29
332 ; Test the value of an accumulator against an integer immediate
333 .macro test_acc_immed val reg
335 test_fr_iimmed \val,fr31
338 ; Test the value of an accumulator against an integer immediate
339 .macro test_acc_limmed valh vall reg
341 test_fr_limmed \valh,\vall,fr31
344 ; Test the value of an accumulator guard against an integer immediate
345 .macro test_accg_immed val reg
347 test_fr_iimmed \val,fr31
350 ; Test CPR against an immediate value
351 .macro test_cpr_limmed valh vall reg
354 test_mem_limmed \valh,\vall,gr31
357 ; Test the value of an immediate against memory
358 .macro test_mem_immed val base
360 .if (\val >= -512) && (\val <= 511)
361 subicc gr29,\val,gr0,icc3
363 set_gr_immed \val,gr28
364 subcc gr29,gr28,gr0,icc3
371 .macro test_mem_limmed valh vall base
373 set_gr_limmed \valh,\vall,gr28
374 subcc gr29,gr28,gr0,icc3
380 ; Set an integer condition code
381 .macro set_icc mask iccno
383 smuli gr29,\iccno,gr30
385 set_gr_immed 0xf,gr28
390 set_gr_immed \mask,gr28
396 ; Test the condition codes
397 .macro test_icc N Z V C iccno
424 ; Set an floating point condition code
425 .macro set_fcc mask fccno
427 smuli gr29,\fccno,gr30
428 set_gr_immed 0xf,gr28
433 set_gr_immed \mask,gr28
439 ; Test the condition codes
440 .macro test_fcc val fccno
442 smuli gr29,\fccno,gr30
446 test_gr_immed \val,gr29
450 .macro set_psr_et val
453 ori gr28,1,gr28 ; Turn on SPR.ET
455 andi gr28,0xfffffffe,gr28 ; Turn off SPR.ET
460 ; Floating point constants
461 .macro float_constants
470 finf: .long 0x7f800000
471 fninf: .long 0xff800000
472 fmax: .long 0x7f7fffff
473 fmin: .long 0xff7fffff
474 feps: .long 0x00400000
475 fneps: .long 0x80400000
476 fnan1: .long 0x7fc00000
477 fnan2: .long 0x7f800001
480 .macro double_constants
489 dinf: .long 0x7ff00000
491 dninf: .long 0xfff00000
493 dmax: .long 0x7fefffff
495 dmin: .long 0xffefffff
497 deps: .long 0x00080000
499 dneps: .long 0x80080000
501 dnan1: .long 0x7ff80000
503 dnan2: .long 0x7ff00000
507 ; Load floating point constants
508 .macro load_float_constants
512 set_fr_mem fneps,fr12
523 set_fr_mem fnan1,fr56
524 set_fr_mem fnan2,fr60
527 .macro load_float_constants1
531 set_fr_mem fneps,fr13
542 set_fr_mem fnan1,fr57
543 set_fr_mem fnan2,fr61
546 .macro load_float_constants2
550 set_fr_mem fneps,fr14
561 set_fr_mem fnan1,fr58
562 set_fr_mem fnan2,fr62
565 .macro load_float_constants3
569 set_fr_mem fneps,fr15
580 set_fr_mem fnan1,fr59
581 set_fr_mem fnan2,fr63
584 .macro load_double_constants
585 set_dfr_mem dninf,fr0
588 set_dfr_mem dneps,fr12
591 set_dfr_mem deps,fr24
597 set_dfr_mem dmax,fr48
598 set_dfr_mem dinf,fr52
599 set_dfr_mem dnan1,fr56
600 set_dfr_mem dnan2,fr60
603 ; Lock the insn cache at the given address
604 .macro lock_insn_cache address
608 ; Lock the data cache at the given address
609 .macro lock_data_cache address
613 ; Invalidate the data cache at the given address
614 .macro invalidate_data_cache address
618 ; Flush the data cache at the given address
619 .macro flush_data_cache address
623 ; Write a bctrlr 0,0 insn at the address contained in the given register
624 .macro set_bctrlr_0_0 address
625 set_mem_immed 0x80382000,\address ; bctrlr 0,0
626 flush_data_cache \address
629 ; Exit with return code
642 set_gr_addr passmsg,gr9
653 set_gr_addr failmsg,gr9