2 * Here is where the ball gets rolling as far as the kernel is concerned.
3 * When control is transferred to _start, the bootload has already
4 * loaded us to the correct address. All that's left to do here is
5 * to set up the kernel's global pointer and jump to the kernel
8 * Copyright (C) 1998-2001, 2003 Hewlett-Packard Co
9 * David Mosberger-Tang <davidm@hpl.hp.com>
10 * Stephane Eranian <eranian@hpl.hp.com>
11 * Copyright (C) 1999 VA Linux Systems
12 * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
13 * Copyright (C) 1999 Intel Corp.
14 * Copyright (C) 1999 Asit Mallick <Asit.K.Mallick@intel.com>
15 * Copyright (C) 1999 Don Dugger <Don.Dugger@intel.com>
16 * Copyright (C) 2002 Fenghua Yu <fenghua.yu@intel.com>
17 * -Optimize __ia64_save_fpu() and __ia64_load_fpu() for Itanium 2.
20 #include <linux/config.h>
22 #include <asm/asmmacro.h>
24 #include <asm/kregs.h>
25 #include <asm/mmu_context.h>
26 #include <asm/offsets.h>
28 #include <asm/pgtable.h>
29 #include <asm/processor.h>
30 #include <asm/ptrace.h>
31 #include <asm/system.h>
33 .section __special_page_section,"ax"
35 .global empty_zero_page
39 .global swapper_pg_dir
45 stringz "Halting kernel\n"
52 * Start the kernel. When the bootloader passes control to _start(), r28
53 * points to the address of the boot parameter area. Execution reaches
54 * here in physical mode.
59 .save rp, r0 // terminate unwind chain with a NULL rp
67 * Initialize kernel region registers:
68 * rr[5]: VHPT enabled, page size = PAGE_SHIFT
69 * rr[6]: VHPT disabled, page size = IA64_GRANULE_SHIFT
70 * rr[7]: VHPT disabled, page size = IA64_GRANULE_SHIFT
72 mov r16=((ia64_rid(IA64_REGION_ID_KERNEL, (5<<61)) << 8) | (PAGE_SHIFT << 2) | 1)
74 mov r18=((ia64_rid(IA64_REGION_ID_KERNEL, (6<<61)) << 8) | (IA64_GRANULE_SHIFT << 2))
76 mov r20=((ia64_rid(IA64_REGION_ID_KERNEL, (7<<61)) << 8) | (IA64_GRANULE_SHIFT << 2))
84 * Now pin mappings into the TLB for kernel text and data
86 mov r18=KERNEL_TR_PAGE_SHIFT<<2
91 mov r16=IA64_TR_KERNEL
95 dep r2=0,r3,0,KERNEL_TR_PAGE_SHIFT
108 * Switch into virtual mode:
110 movl r16=(IA64_PSR_IT|IA64_PSR_IC|IA64_PSR_DT|IA64_PSR_RT|IA64_PSR_DFH|IA64_PSR_BN \
121 1: // now we are in virtual mode
123 // set IVT entry point---can't access I/O ports without it
135 #define isAP p2 // are we an Application Processor?
136 #define isBP p3 // are we the Bootstrap Processor?
140 * Find the init_task for the currently booting CPU. At poweron, and in
141 * UP mode, task_for_booting_cpu is NULL.
143 movl r3=task_for_booting_cpu
148 cmp.eq isBP,isAP=r3,r0
153 cmp.eq isBP,isAP=r0,r0
156 tpa r3=r2 // r3 == phys addr of task struct
158 (isBP) br.cond.dpnt .load_current // BP stack is on region 5 --- no need to map it
160 // load mapping for stack (virtaddr in r2, physaddr in r3)
168 dep r2=-1,r3,61,3 // IMVA of task
171 shr.u r16=r3,IA64_GRANULE_SHIFT
178 mov r19=IA64_TR_CURRENT_STACK
187 // load the "current" pointer (r13) and ar.k6 with the current task
188 mov IA64_KR(CURRENT)=r2 // virtual address
189 mov IA64_KR(CURRENT_STACK)=r16
192 * Reserve space at the top of the stack for "struct pt_regs". Kernel threads
193 * don't store interesting values in that structure, but the space still needs
194 * to be there because time-critical stuff such as the context switching can
195 * be implemented more efficiently (for example, __switch_to()
196 * always sets the psr.dfh bit of the task it is switching to).
198 addl r12=IA64_STK_OFFSET-IA64_PT_REGS_SIZE-16,r2
199 addl r2=IA64_RBS_OFFSET,r2 // initialize the RSE
200 mov ar.rsc=0 // place RSE in enforced lazy mode
202 loadrs // clear the dirty partition
204 mov ar.bspstore=r2 // establish the new RSE stack
206 mov ar.rsc=0x3 // place RSE in eager mode
208 (isBP) dep r28=-1,r28,61,3 // make address virtual
209 (isBP) movl r2=ia64_boot_param
211 (isBP) st8 [r2]=r28 // save the address of the boot param area passed by the bootloader
213 #ifdef CONFIG_IA64_EARLY_PRINTK
216 stringz "I'm alive and well\n"
220 alloc r2=ar.pfs,0,0,2,0
222 movl out1=alive_msg_end-alive_msg-1
224 br.call.sptk.many rp=early_printk
225 1: // force new bundle
226 #endif /* CONFIG_IA64_EARLY_PRINTK */
229 (isAP) br.call.sptk.many rp=start_secondary
231 (isAP) br.cond.sptk self
234 // This is executed by the bootstrap processor (bsp) only:
236 #ifdef CONFIG_IA64_FW_EMU
237 // initialize PAL & SAL emulator:
238 br.call.sptk.many rp=sys_fw_init
241 br.call.sptk.many rp=start_kernel
242 .ret2: addl r3=@ltoff(halt_msg),gp
244 alloc r2=ar.pfs,8,0,2,0
247 br.call.sptk.many b0=console_print
248 self: br.sptk.many self // endless loop
251 GLOBAL_ENTRY(ia64_save_debug_regs)
252 alloc r16=ar.pfs,1,0,0,0
253 mov r20=ar.lc // preserve ar.lc
254 mov ar.lc=IA64_NUM_DBG_REGS-1
256 add r19=IA64_NUM_DBG_REGS*8,in0
259 #ifdef CONFIG_ITANIUM
268 br.cloop.sptk.many 1b
270 mov ar.lc=r20 // restore ar.lc
272 END(ia64_save_debug_regs)
274 GLOBAL_ENTRY(ia64_load_debug_regs)
275 alloc r16=ar.pfs,1,0,0,0
277 mov r20=ar.lc // preserve ar.lc
278 add r19=IA64_NUM_DBG_REGS*8,in0
279 mov ar.lc=IA64_NUM_DBG_REGS-1
282 1: ld8.nta r16=[in0],8
287 #ifdef CONFIG_ITANIUM
289 srlz.d // Errata 132 (NoFix status)
292 br.cloop.sptk.many 1b
294 mov ar.lc=r20 // restore ar.lc
296 END(ia64_load_debug_regs)
298 GLOBAL_ENTRY(__ia64_save_fpu)
299 alloc r2=ar.pfs,1,4,0,0
300 adds loc0=96*16-16,in0
301 adds loc1=96*16-16-128,in0
303 stf.spill.nta [loc0]=f127,-256
304 stf.spill.nta [loc1]=f119,-256
306 stf.spill.nta [loc0]=f111,-256
307 stf.spill.nta [loc1]=f103,-256
309 stf.spill.nta [loc0]=f95,-256
310 stf.spill.nta [loc1]=f87,-256
312 stf.spill.nta [loc0]=f79,-256
313 stf.spill.nta [loc1]=f71,-256
315 stf.spill.nta [loc0]=f63,-256
316 stf.spill.nta [loc1]=f55,-256
317 adds loc2=96*16-32,in0
319 stf.spill.nta [loc0]=f47,-256
320 stf.spill.nta [loc1]=f39,-256
321 adds loc3=96*16-32-128,in0
323 stf.spill.nta [loc2]=f126,-256
324 stf.spill.nta [loc3]=f118,-256
326 stf.spill.nta [loc2]=f110,-256
327 stf.spill.nta [loc3]=f102,-256
329 stf.spill.nta [loc2]=f94,-256
330 stf.spill.nta [loc3]=f86,-256
332 stf.spill.nta [loc2]=f78,-256
333 stf.spill.nta [loc3]=f70,-256
335 stf.spill.nta [loc2]=f62,-256
336 stf.spill.nta [loc3]=f54,-256
337 adds loc0=96*16-48,in0
339 stf.spill.nta [loc2]=f46,-256
340 stf.spill.nta [loc3]=f38,-256
341 adds loc1=96*16-48-128,in0
343 stf.spill.nta [loc0]=f125,-256
344 stf.spill.nta [loc1]=f117,-256
346 stf.spill.nta [loc0]=f109,-256
347 stf.spill.nta [loc1]=f101,-256
349 stf.spill.nta [loc0]=f93,-256
350 stf.spill.nta [loc1]=f85,-256
352 stf.spill.nta [loc0]=f77,-256
353 stf.spill.nta [loc1]=f69,-256
355 stf.spill.nta [loc0]=f61,-256
356 stf.spill.nta [loc1]=f53,-256
357 adds loc2=96*16-64,in0
359 stf.spill.nta [loc0]=f45,-256
360 stf.spill.nta [loc1]=f37,-256
361 adds loc3=96*16-64-128,in0
363 stf.spill.nta [loc2]=f124,-256
364 stf.spill.nta [loc3]=f116,-256
366 stf.spill.nta [loc2]=f108,-256
367 stf.spill.nta [loc3]=f100,-256
369 stf.spill.nta [loc2]=f92,-256
370 stf.spill.nta [loc3]=f84,-256
372 stf.spill.nta [loc2]=f76,-256
373 stf.spill.nta [loc3]=f68,-256
375 stf.spill.nta [loc2]=f60,-256
376 stf.spill.nta [loc3]=f52,-256
377 adds loc0=96*16-80,in0
379 stf.spill.nta [loc2]=f44,-256
380 stf.spill.nta [loc3]=f36,-256
381 adds loc1=96*16-80-128,in0
383 stf.spill.nta [loc0]=f123,-256
384 stf.spill.nta [loc1]=f115,-256
386 stf.spill.nta [loc0]=f107,-256
387 stf.spill.nta [loc1]=f99,-256
389 stf.spill.nta [loc0]=f91,-256
390 stf.spill.nta [loc1]=f83,-256
392 stf.spill.nta [loc0]=f75,-256
393 stf.spill.nta [loc1]=f67,-256
395 stf.spill.nta [loc0]=f59,-256
396 stf.spill.nta [loc1]=f51,-256
397 adds loc2=96*16-96,in0
399 stf.spill.nta [loc0]=f43,-256
400 stf.spill.nta [loc1]=f35,-256
401 adds loc3=96*16-96-128,in0
403 stf.spill.nta [loc2]=f122,-256
404 stf.spill.nta [loc3]=f114,-256
406 stf.spill.nta [loc2]=f106,-256
407 stf.spill.nta [loc3]=f98,-256
409 stf.spill.nta [loc2]=f90,-256
410 stf.spill.nta [loc3]=f82,-256
412 stf.spill.nta [loc2]=f74,-256
413 stf.spill.nta [loc3]=f66,-256
415 stf.spill.nta [loc2]=f58,-256
416 stf.spill.nta [loc3]=f50,-256
417 adds loc0=96*16-112,in0
419 stf.spill.nta [loc2]=f42,-256
420 stf.spill.nta [loc3]=f34,-256
421 adds loc1=96*16-112-128,in0
423 stf.spill.nta [loc0]=f121,-256
424 stf.spill.nta [loc1]=f113,-256
426 stf.spill.nta [loc0]=f105,-256
427 stf.spill.nta [loc1]=f97,-256
429 stf.spill.nta [loc0]=f89,-256
430 stf.spill.nta [loc1]=f81,-256
432 stf.spill.nta [loc0]=f73,-256
433 stf.spill.nta [loc1]=f65,-256
435 stf.spill.nta [loc0]=f57,-256
436 stf.spill.nta [loc1]=f49,-256
437 adds loc2=96*16-128,in0
439 stf.spill.nta [loc0]=f41,-256
440 stf.spill.nta [loc1]=f33,-256
441 adds loc3=96*16-128-128,in0
443 stf.spill.nta [loc2]=f120,-256
444 stf.spill.nta [loc3]=f112,-256
446 stf.spill.nta [loc2]=f104,-256
447 stf.spill.nta [loc3]=f96,-256
449 stf.spill.nta [loc2]=f88,-256
450 stf.spill.nta [loc3]=f80,-256
452 stf.spill.nta [loc2]=f72,-256
453 stf.spill.nta [loc3]=f64,-256
455 stf.spill.nta [loc2]=f56,-256
456 stf.spill.nta [loc3]=f48,-256
458 stf.spill.nta [loc2]=f40
459 stf.spill.nta [loc3]=f32
463 GLOBAL_ENTRY(__ia64_load_fpu)
464 alloc r2=ar.pfs,1,2,0,0
471 ldf.fill.nta f32=[in0],loc0
472 ldf.fill.nta f40=[ r3],loc0
473 ldf.fill.nta f48=[r14],loc0
474 ldf.fill.nta f56=[r15],loc0
476 ldf.fill.nta f64=[in0],loc0
477 ldf.fill.nta f72=[ r3],loc0
478 ldf.fill.nta f80=[r14],loc0
479 ldf.fill.nta f88=[r15],loc0
481 ldf.fill.nta f96=[in0],loc1
482 ldf.fill.nta f104=[ r3],loc1
483 ldf.fill.nta f112=[r14],loc1
484 ldf.fill.nta f120=[r15],loc1
486 ldf.fill.nta f33=[in0],loc0
487 ldf.fill.nta f41=[ r3],loc0
488 ldf.fill.nta f49=[r14],loc0
489 ldf.fill.nta f57=[r15],loc0
491 ldf.fill.nta f65=[in0],loc0
492 ldf.fill.nta f73=[ r3],loc0
493 ldf.fill.nta f81=[r14],loc0
494 ldf.fill.nta f89=[r15],loc0
496 ldf.fill.nta f97=[in0],loc1
497 ldf.fill.nta f105=[ r3],loc1
498 ldf.fill.nta f113=[r14],loc1
499 ldf.fill.nta f121=[r15],loc1
501 ldf.fill.nta f34=[in0],loc0
502 ldf.fill.nta f42=[ r3],loc0
503 ldf.fill.nta f50=[r14],loc0
504 ldf.fill.nta f58=[r15],loc0
506 ldf.fill.nta f66=[in0],loc0
507 ldf.fill.nta f74=[ r3],loc0
508 ldf.fill.nta f82=[r14],loc0
509 ldf.fill.nta f90=[r15],loc0
511 ldf.fill.nta f98=[in0],loc1
512 ldf.fill.nta f106=[ r3],loc1
513 ldf.fill.nta f114=[r14],loc1
514 ldf.fill.nta f122=[r15],loc1
516 ldf.fill.nta f35=[in0],loc0
517 ldf.fill.nta f43=[ r3],loc0
518 ldf.fill.nta f51=[r14],loc0
519 ldf.fill.nta f59=[r15],loc0
521 ldf.fill.nta f67=[in0],loc0
522 ldf.fill.nta f75=[ r3],loc0
523 ldf.fill.nta f83=[r14],loc0
524 ldf.fill.nta f91=[r15],loc0
526 ldf.fill.nta f99=[in0],loc1
527 ldf.fill.nta f107=[ r3],loc1
528 ldf.fill.nta f115=[r14],loc1
529 ldf.fill.nta f123=[r15],loc1
531 ldf.fill.nta f36=[in0],loc0
532 ldf.fill.nta f44=[ r3],loc0
533 ldf.fill.nta f52=[r14],loc0
534 ldf.fill.nta f60=[r15],loc0
536 ldf.fill.nta f68=[in0],loc0
537 ldf.fill.nta f76=[ r3],loc0
538 ldf.fill.nta f84=[r14],loc0
539 ldf.fill.nta f92=[r15],loc0
541 ldf.fill.nta f100=[in0],loc1
542 ldf.fill.nta f108=[ r3],loc1
543 ldf.fill.nta f116=[r14],loc1
544 ldf.fill.nta f124=[r15],loc1
546 ldf.fill.nta f37=[in0],loc0
547 ldf.fill.nta f45=[ r3],loc0
548 ldf.fill.nta f53=[r14],loc0
549 ldf.fill.nta f61=[r15],loc0
551 ldf.fill.nta f69=[in0],loc0
552 ldf.fill.nta f77=[ r3],loc0
553 ldf.fill.nta f85=[r14],loc0
554 ldf.fill.nta f93=[r15],loc0
556 ldf.fill.nta f101=[in0],loc1
557 ldf.fill.nta f109=[ r3],loc1
558 ldf.fill.nta f117=[r14],loc1
559 ldf.fill.nta f125=[r15],loc1
561 ldf.fill.nta f38 =[in0],loc0
562 ldf.fill.nta f46 =[ r3],loc0
563 ldf.fill.nta f54 =[r14],loc0
564 ldf.fill.nta f62 =[r15],loc0
566 ldf.fill.nta f70 =[in0],loc0
567 ldf.fill.nta f78 =[ r3],loc0
568 ldf.fill.nta f86 =[r14],loc0
569 ldf.fill.nta f94 =[r15],loc0
571 ldf.fill.nta f102=[in0],loc1
572 ldf.fill.nta f110=[ r3],loc1
573 ldf.fill.nta f118=[r14],loc1
574 ldf.fill.nta f126=[r15],loc1
576 ldf.fill.nta f39 =[in0],loc0
577 ldf.fill.nta f47 =[ r3],loc0
578 ldf.fill.nta f55 =[r14],loc0
579 ldf.fill.nta f63 =[r15],loc0
581 ldf.fill.nta f71 =[in0],loc0
582 ldf.fill.nta f79 =[ r3],loc0
583 ldf.fill.nta f87 =[r14],loc0
584 ldf.fill.nta f95 =[r15],loc0
586 ldf.fill.nta f103=[in0]
587 ldf.fill.nta f111=[ r3]
588 ldf.fill.nta f119=[r14]
589 ldf.fill.nta f127=[r15]
593 GLOBAL_ENTRY(__ia64_init_fpu)
594 stf.spill [sp]=f0 // M3
598 ldfps f33,f34=[sp] // M0
599 ldfps f35,f36=[sp] // M1
607 ldfps f41,f42=[sp] // M0
608 ldfps f43,f44=[sp] // M1
615 ldfps f49,f50=[sp] // M0
616 ldfps f51,f52=[sp] // M1
623 ldfps f57,f58=[sp] // M0
624 ldfps f59,f60=[sp] // M1
631 ldfps f65,f66=[sp] // M0
632 ldfps f67,f68=[sp] // M1
639 ldfps f73,f74=[sp] // M0
640 ldfps f75,f76=[sp] // M1
647 ldfps f81,f82=[sp] // M0
648 ldfps f83,f84=[sp] // M1
656 * When the instructions are cached, it would be faster to initialize
657 * the remaining registers with simply mov instructions (F-unit).
658 * This gets the time down to ~29 cycles. However, this would use up
659 * 33 bundles, whereas continuing with the above pattern yields
660 * 10 bundles and ~30 cycles.
663 ldfps f89,f90=[sp] // M0
664 ldfps f91,f92=[sp] // M1
671 ldfps f97,f98=[sp] // M0
672 ldfps f99,f100=[sp] // M1
679 ldfps f105,f106=[sp] // M0
680 ldfps f107,f108=[sp] // M1
687 ldfps f113,f114=[sp] // M0
688 ldfps f115,f116=[sp] // M1
695 ldfps f121,f122=[sp] // M0
696 ldfps f123,f124=[sp] // M1
701 br.ret.sptk.many rp // F
705 * Switch execution mode from virtual to physical
708 * r16 = new psr to establish
710 * r19 = old virtual address of ar.bsp
711 * r20 = old virtual address of sp
713 * Note: RSE must already be in enforced lazy mode
715 GLOBAL_ENTRY(ia64_switch_mode_phys)
717 alloc r2=ar.pfs,0,0,0,0
718 rsm psr.i | psr.ic // disable interrupts and interrupt collection
723 flushrs // must be first insn in group
727 mov cr.ipsr=r16 // set new PSR
728 add r3=1f-ia64_switch_mode_phys,r15
732 mov r14=rp // get return address into a general register
735 // going to physical mode, use tpa to translate virt->phys
742 mov r18=ar.rnat // save ar.rnat
743 mov ar.bspstore=r17 // this steps on ar.rnat
747 mov ar.rnat=r18 // restore ar.rnat
748 rfi // must be last insn in group
752 END(ia64_switch_mode_phys)
755 * Switch execution mode from physical to virtual
758 * r16 = new psr to establish
759 * r19 = new bspstore to establish
760 * r20 = new sp to establish
762 * Note: RSE must already be in enforced lazy mode
764 GLOBAL_ENTRY(ia64_switch_mode_virt)
766 alloc r2=ar.pfs,0,0,0,0
767 rsm psr.i | psr.ic // disable interrupts and interrupt collection
772 flushrs // must be first insn in group
776 mov cr.ipsr=r16 // set new PSR
777 add r3=1f-ia64_switch_mode_virt,r15
779 mov r14=rp // get return address into a general register
783 // - for code addresses, set upper bits of addr to KERNEL_START
784 // - for stack addresses, copy from input argument
785 movl r18=KERNEL_START
786 dep r3=0,r3,KERNEL_TR_PAGE_SHIFT,64-KERNEL_TR_PAGE_SHIFT
787 dep r14=0,r14,KERNEL_TR_PAGE_SHIFT,64-KERNEL_TR_PAGE_SHIFT
794 mov r18=ar.rnat // save ar.rnat
795 mov ar.bspstore=r19 // this steps on ar.rnat
799 mov ar.rnat=r18 // restore ar.rnat
800 rfi // must be last insn in group
804 END(ia64_switch_mode_virt)
806 GLOBAL_ENTRY(ia64_delay_loop)
808 { nop 0 // work around GAS unwind info generation bug...
816 // force loop to be 32-byte aligned (GAS bug means we cannot use .align
817 // inside function body without corrupting unwind info).
819 1: br.cloop.sptk.few 1b
826 * Return a CPU-local timestamp in nano-seconds. This timestamp is
827 * NOT synchronized across CPUs its return value must never be
828 * compared against the values returned on another CPU. The usage in
829 * kernel/sched.c ensures that.
831 * The return-value of sched_clock() is NOT supposed to wrap-around.
832 * If it did, it would cause some scheduling hiccups (at the worst).
833 * Fortunately, with a 64-bit cycle-counter ticking at 100GHz, even
834 * that would happen only once every 5+ years.
836 * The code below basically calculates:
838 * (ia64_get_itc() * local_cpu_data->nsec_per_cyc) >> IA64_NSEC_PER_CYC_SHIFT
840 * except that the multiplication and the shift are done with 128-bit
841 * intermediate precision so that we can produce a full 64-bit result.
843 GLOBAL_ENTRY(sched_clock)
844 addl r8=THIS_CPU(cpu_info) + IA64_CPUINFO_NSEC_PER_CYC_OFFSET,r0
845 mov.m r9=ar.itc // fetch cycle-counter (35 cyc)
849 setf.sig f9=r9 // certain to stall, so issue it _after_ ldf8...
851 xmpy.lu f10=f9,f8 // calculate low 64 bits of 128-bit product (4 cyc)
852 xmpy.hu f11=f9,f8 // calculate high 64 bits of 128-bit product
854 getf.sig r8=f10 // (5 cyc)
857 shrp r8=r9,r8,IA64_NSEC_PER_CYC_SHIFT
861 GLOBAL_ENTRY(start_kernel_thread)
863 .save rp, r0 // this is the end of the call-chain
865 alloc r2 = ar.pfs, 0, 0, 2, 0
868 br.call.sptk.many rp = kernel_thread_helper;;
870 br.call.sptk.many rp = sys_exit;;
871 1: br.sptk.few 1b // not reached
872 END(start_kernel_thread)
874 #ifdef CONFIG_IA64_BRL_EMU
877 * Assembly routines used by brl_emu.c to set preserved register state.
880 #define SET_REG(reg) \
881 GLOBAL_ENTRY(ia64_set_##reg); \
882 alloc r16=ar.pfs,1,0,0,0; \
885 br.ret.sptk.many rp; \
894 #endif /* CONFIG_IA64_BRL_EMU */
898 * This routine handles spinlock contention. It uses a non-standard calling
899 * convention to avoid converting leaf routines into interior routines. Because
900 * of this special convention, there are several restrictions:
902 * - do not use gp relative variables, this code is called from the kernel
903 * and from modules, r1 is undefined.
904 * - do not use stacked registers, the caller owns them.
905 * - do not use the scratch stack space, the caller owns it.
906 * - do not use any registers other than the ones listed below
909 * ar.pfs - saved CFM of caller
910 * ar.ccv - 0 (and available for use)
911 * r27 - flags from spin_lock_irqsave or 0. Must be preserved.
912 * r28 - available for use.
913 * r29 - available for use.
914 * r30 - available for use.
915 * r31 - address of lock, available for use.
916 * b6 - return address
917 * p14 - available for use.
918 * p15 - used to track flag status.
920 * If you patch this code to use more registers, do not forget to update
921 * the clobber lists for spin_lock() in include/asm-ia64/spinlock.h.
924 #if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 3)
926 GLOBAL_ENTRY(ia64_spinlock_contention_pre3_4)
928 .save ar.pfs, r0 // this code effectively has a zero frame size
932 tbit.nz p15,p0=r27,IA64_PSR_I_BIT
933 .restore sp // pop existing prologue after next insn
940 (p15) ssm psr.i // reenable interrupts if they were on
941 // DavidM says that srlz.d is slow and is not required in this case
943 // exponential backoff, kdb, lockmeter etc. go in here
945 ld4 r30=[r31] // don't use ld4.bias; if it's contended, we won't write the word
948 cmp4.ne p14,p0=r30,r0
949 (p14) br.cond.sptk.few .wait
950 (p15) rsm psr.i // disable interrupts if we reenabled them
951 br.cond.sptk.few b6 // lock is now free, try to acquire
952 END(ia64_spinlock_contention_pre3_4)
956 GLOBAL_ENTRY(ia64_spinlock_contention)
960 tbit.nz p15,p0=r27,IA64_PSR_I_BIT
963 (p15) ssm psr.i // reenable interrupts if they were on
964 // DavidM says that srlz.d is slow and is not required in this case
966 // exponential backoff, kdb, lockmeter etc. go in here
968 ld4 r30=[r31] // don't use ld4.bias; if it's contended, we won't write the word
970 cmp4.ne p14,p0=r30,r0
972 (p14) br.cond.sptk.few .wait2
973 (p15) rsm psr.i // disable interrupts if we reenabled them
975 cmpxchg4.acq r30=[r31], r30, ar.ccv
977 cmp4.ne p14,p0=r0,r30
978 (p14) br.cond.sptk.few .wait
980 br.ret.sptk.many b6 // lock is now taken
981 END(ia64_spinlock_contention)
985 #endif /* CONFIG_SMP */