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, 2005 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.
18 * Copyright (C) 2004 Ashok Raj <ashok.raj@intel.com>
19 * Support for CPU Hotplug
23 #include <asm/asmmacro.h>
25 #include <asm/kregs.h>
26 #include <asm/mmu_context.h>
27 #include <asm/asm-offsets.h>
29 #include <asm/paravirt.h>
30 #include <asm/pgtable.h>
31 #include <asm/processor.h>
32 #include <asm/ptrace.h>
33 #include <asm/system.h>
34 #include <asm/mca_asm.h>
35 #include <linux/init.h>
36 #include <linux/linkage.h>
39 #ifdef CONFIG_HOTPLUG_CPU
40 #define SAL_PSR_BITS_TO_SET \
41 (IA64_PSR_AC | IA64_PSR_BN | IA64_PSR_MFH | IA64_PSR_MFL)
43 #define SAVE_FROM_REG(src, ptr, dest) \
47 #define RESTORE_REG(reg, ptr, _tmp) \
48 ld8 _tmp=[ptr],0x08;; \
51 #define SAVE_BREAK_REGS(ptr, _idx, _breg, _dest)\
52 mov ar.lc=IA64_NUM_DBG_REGS-1;; \
55 SAVE_FROM_REG(_breg[_idx], ptr, _dest);; \
59 #define RESTORE_BREAK_REGS(ptr, _idx, _breg, _tmp, _lbl)\
60 mov ar.lc=IA64_NUM_DBG_REGS-1;; \
62 _lbl: RESTORE_REG(_breg[_idx], ptr, _tmp);; \
64 br.cloop.sptk.many _lbl
66 #define SAVE_ONE_RR(num, _reg, _tmp) \
67 movl _tmp=(num<<61);; \
70 #define SAVE_REGION_REGS(_tmp, _r0, _r1, _r2, _r3, _r4, _r5, _r6, _r7) \
71 SAVE_ONE_RR(0,_r0, _tmp);; \
72 SAVE_ONE_RR(1,_r1, _tmp);; \
73 SAVE_ONE_RR(2,_r2, _tmp);; \
74 SAVE_ONE_RR(3,_r3, _tmp);; \
75 SAVE_ONE_RR(4,_r4, _tmp);; \
76 SAVE_ONE_RR(5,_r5, _tmp);; \
77 SAVE_ONE_RR(6,_r6, _tmp);; \
78 SAVE_ONE_RR(7,_r7, _tmp);;
80 #define STORE_REGION_REGS(ptr, _r0, _r1, _r2, _r3, _r4, _r5, _r6, _r7) \
90 #define RESTORE_REGION_REGS(ptr, _idx1, _idx2, _tmp) \
94 dep.z _idx2=_idx1,61,3;; \
96 mov rr[_idx2]=_tmp;; \
99 br.cloop.sptk.few RestRR
101 #define SET_AREA_FOR_BOOTING_CPU(reg1, reg2) \
102 movl reg1=sal_state_for_booting_cpu;; \
106 * Adjust region registers saved before starting to save
107 * break regs and rest of the states that need to be preserved.
109 #define SAL_TO_OS_BOOT_HANDOFF_STATE_SAVE(_reg1,_reg2,_pred) \
110 SAVE_FROM_REG(b0,_reg1,_reg2);; \
111 SAVE_FROM_REG(b1,_reg1,_reg2);; \
112 SAVE_FROM_REG(b2,_reg1,_reg2);; \
113 SAVE_FROM_REG(b3,_reg1,_reg2);; \
114 SAVE_FROM_REG(b4,_reg1,_reg2);; \
115 SAVE_FROM_REG(b5,_reg1,_reg2);; \
116 st8 [_reg1]=r1,0x08;; \
117 st8 [_reg1]=r12,0x08;; \
118 st8 [_reg1]=r13,0x08;; \
119 SAVE_FROM_REG(ar.fpsr,_reg1,_reg2);; \
120 SAVE_FROM_REG(ar.pfs,_reg1,_reg2);; \
121 SAVE_FROM_REG(ar.rnat,_reg1,_reg2);; \
122 SAVE_FROM_REG(ar.unat,_reg1,_reg2);; \
123 SAVE_FROM_REG(ar.bspstore,_reg1,_reg2);; \
124 SAVE_FROM_REG(cr.dcr,_reg1,_reg2);; \
125 SAVE_FROM_REG(cr.iva,_reg1,_reg2);; \
126 SAVE_FROM_REG(cr.pta,_reg1,_reg2);; \
127 SAVE_FROM_REG(cr.itv,_reg1,_reg2);; \
128 SAVE_FROM_REG(cr.pmv,_reg1,_reg2);; \
129 SAVE_FROM_REG(cr.cmcv,_reg1,_reg2);; \
130 SAVE_FROM_REG(cr.lrr0,_reg1,_reg2);; \
131 SAVE_FROM_REG(cr.lrr1,_reg1,_reg2);; \
132 st8 [_reg1]=r4,0x08;; \
133 st8 [_reg1]=r5,0x08;; \
134 st8 [_reg1]=r6,0x08;; \
135 st8 [_reg1]=r7,0x08;; \
136 st8 [_reg1]=_pred,0x08;; \
137 SAVE_FROM_REG(ar.lc, _reg1, _reg2);; \
138 stf.spill.nta [_reg1]=f2,16;; \
139 stf.spill.nta [_reg1]=f3,16;; \
140 stf.spill.nta [_reg1]=f4,16;; \
141 stf.spill.nta [_reg1]=f5,16;; \
142 stf.spill.nta [_reg1]=f16,16;; \
143 stf.spill.nta [_reg1]=f17,16;; \
144 stf.spill.nta [_reg1]=f18,16;; \
145 stf.spill.nta [_reg1]=f19,16;; \
146 stf.spill.nta [_reg1]=f20,16;; \
147 stf.spill.nta [_reg1]=f21,16;; \
148 stf.spill.nta [_reg1]=f22,16;; \
149 stf.spill.nta [_reg1]=f23,16;; \
150 stf.spill.nta [_reg1]=f24,16;; \
151 stf.spill.nta [_reg1]=f25,16;; \
152 stf.spill.nta [_reg1]=f26,16;; \
153 stf.spill.nta [_reg1]=f27,16;; \
154 stf.spill.nta [_reg1]=f28,16;; \
155 stf.spill.nta [_reg1]=f29,16;; \
156 stf.spill.nta [_reg1]=f30,16;; \
157 stf.spill.nta [_reg1]=f31,16;;
160 #define SET_AREA_FOR_BOOTING_CPU(a1, a2)
161 #define SAL_TO_OS_BOOT_HANDOFF_STATE_SAVE(a1,a2, a3)
162 #define SAVE_REGION_REGS(_tmp, _r0, _r1, _r2, _r3, _r4, _r5, _r6, _r7)
163 #define STORE_REGION_REGS(ptr, _r0, _r1, _r2, _r3, _r4, _r5, _r6, _r7)
166 #define SET_ONE_RR(num, pgsize, _tmp1, _tmp2, vhpt) \
167 movl _tmp1=(num << 61);; \
168 mov _tmp2=((ia64_rid(IA64_REGION_ID_KERNEL, (num<<61)) << 8) | (pgsize << 2) | vhpt);; \
171 .section __special_page_section,"ax"
173 .global empty_zero_page
177 .global swapper_pg_dir
183 stringz "Halting kernel\n"
185 .section .text.head,"ax"
190 * Start the kernel. When the bootloader passes control to _start(), r28
191 * points to the address of the boot parameter area. Execution reaches
192 * here in physical mode.
197 .save rp, r0 // terminate unwind chain with a NULL rp
205 flushrs // must be first insn in group
210 * Save the region registers, predicate before they get clobbered
212 SAVE_REGION_REGS(r2, r8,r9,r10,r11,r12,r13,r14,r15);
216 * Initialize kernel region registers:
217 * rr[0]: VHPT enabled, page size = PAGE_SHIFT
218 * rr[1]: VHPT enabled, page size = PAGE_SHIFT
219 * rr[2]: VHPT enabled, page size = PAGE_SHIFT
220 * rr[3]: VHPT enabled, page size = PAGE_SHIFT
221 * rr[4]: VHPT enabled, page size = PAGE_SHIFT
222 * rr[5]: VHPT enabled, page size = PAGE_SHIFT
223 * rr[6]: VHPT disabled, page size = IA64_GRANULE_SHIFT
224 * rr[7]: VHPT disabled, page size = IA64_GRANULE_SHIFT
225 * We initialize all of them to prevent inadvertently assuming
226 * something about the state of address translation early in boot.
228 SET_ONE_RR(0, PAGE_SHIFT, r2, r16, 1);;
229 SET_ONE_RR(1, PAGE_SHIFT, r2, r16, 1);;
230 SET_ONE_RR(2, PAGE_SHIFT, r2, r16, 1);;
231 SET_ONE_RR(3, PAGE_SHIFT, r2, r16, 1);;
232 SET_ONE_RR(4, PAGE_SHIFT, r2, r16, 1);;
233 SET_ONE_RR(5, PAGE_SHIFT, r2, r16, 1);;
234 SET_ONE_RR(6, IA64_GRANULE_SHIFT, r2, r16, 0);;
235 SET_ONE_RR(7, IA64_GRANULE_SHIFT, r2, r16, 0);;
237 * Now pin mappings into the TLB for kernel text and data
239 mov r18=KERNEL_TR_PAGE_SHIFT<<2
240 movl r17=KERNEL_START
244 mov r16=IA64_TR_KERNEL
248 dep r2=0,r3,0,KERNEL_TR_PAGE_SHIFT
261 * Switch into virtual mode:
263 movl r16=(IA64_PSR_IT|IA64_PSR_IC|IA64_PSR_DT|IA64_PSR_RT|IA64_PSR_DFH|IA64_PSR_BN \
264 |IA64_PSR_DI|IA64_PSR_AC)
274 1: // now we are in virtual mode
276 SET_AREA_FOR_BOOTING_CPU(r2, r16);
278 STORE_REGION_REGS(r16, r8,r9,r10,r11,r12,r13,r14,r15);
279 SAL_TO_OS_BOOT_HANDOFF_STATE_SAVE(r16,r17,r25)
282 // set IVT entry point---can't access I/O ports without it
294 #define isAP p2 // are we an Application Processor?
295 #define isBP p3 // are we the Bootstrap Processor?
299 * Find the init_task for the currently booting CPU. At poweron, and in
300 * UP mode, task_for_booting_cpu is NULL.
302 movl r3=task_for_booting_cpu
307 cmp.eq isBP,isAP=r3,r0
312 cmp.eq isBP,isAP=r0,r0
315 tpa r3=r2 // r3 == phys addr of task struct
317 (isBP) br.cond.dpnt .load_current // BP stack is on region 5 --- no need to map it
319 // load mapping for stack (virtaddr in r2, physaddr in r3)
327 dep r2=-1,r3,61,3 // IMVA of task
330 shr.u r16=r3,IA64_GRANULE_SHIFT
337 mov r19=IA64_TR_CURRENT_STACK
346 // load the "current" pointer (r13) and ar.k6 with the current task
347 mov IA64_KR(CURRENT)=r2 // virtual address
348 mov IA64_KR(CURRENT_STACK)=r16
351 * Reserve space at the top of the stack for "struct pt_regs". Kernel
352 * threads don't store interesting values in that structure, but the space
353 * still needs to be there because time-critical stuff such as the context
354 * switching can be implemented more efficiently (for example, __switch_to()
355 * always sets the psr.dfh bit of the task it is switching to).
358 addl r12=IA64_STK_OFFSET-IA64_PT_REGS_SIZE-16,r2
359 addl r2=IA64_RBS_OFFSET,r2 // initialize the RSE
360 mov ar.rsc=0 // place RSE in enforced lazy mode
362 loadrs // clear the dirty partition
363 movl r19=__phys_per_cpu_start
364 mov r18=PERCPU_PAGE_SIZE
371 movl r20=__cpu0_per_cpu
379 (p7) br.cond.dptk.few 1b
386 .pred.rel.mutex isBP,isAP
387 (isBP) mov IA64_KR(PER_CPU_DATA)=r19 // per-CPU base for cpu0
388 (isAP) mov IA64_KR(PER_CPU_DATA)=r0 // clear physical per-CPU base
390 mov ar.bspstore=r2 // establish the new RSE stack
392 mov ar.rsc=0x3 // place RSE in eager mode
394 (isBP) dep r28=-1,r28,61,3 // make address virtual
395 (isBP) movl r2=ia64_boot_param
397 (isBP) st8 [r2]=r28 // save the address of the boot param area passed by the bootloader
399 #ifdef CONFIG_PARAVIRT
401 movl r14=hypervisor_setup_hooks
402 movl r15=hypervisor_type
403 mov r16=num_hypervisor_hooks
407 cmp.ltu p7,p0=r2,r16 // array size check
413 (p7) cmp.ne.unc p7,p0=r9,r0 // no actual branch to NULL
415 (p7) br.call.sptk.many rp=b1
419 default_setup_hook = 0 // Currently nothing needs to be done.
423 .global hypervisor_type
425 data8 PARAVIRT_HYPERVISOR_TYPE_DEFAULT
427 // must have the same order with PARAVIRT_HYPERVISOR_TYPE_xxx
429 hypervisor_setup_hooks:
430 data8 default_setup_hook
432 num_hypervisor_hooks = (. - hypervisor_setup_hooks) / 8
438 (isAP) br.call.sptk.many rp=start_secondary
440 (isAP) br.cond.sptk self
443 // This is executed by the bootstrap processor (bsp) only:
445 #ifdef CONFIG_IA64_FW_EMU
446 // initialize PAL & SAL emulator:
447 br.call.sptk.many rp=sys_fw_init
450 br.call.sptk.many rp=start_kernel
451 .ret2: addl r3=@ltoff(halt_msg),gp
453 alloc r2=ar.pfs,8,0,2,0
456 br.call.sptk.many b0=console_print
459 br.sptk.many self // endless loop
464 GLOBAL_ENTRY(ia64_save_debug_regs)
465 alloc r16=ar.pfs,1,0,0,0
466 mov r20=ar.lc // preserve ar.lc
467 mov ar.lc=IA64_NUM_DBG_REGS-1
469 add r19=IA64_NUM_DBG_REGS*8,in0
472 #ifdef CONFIG_ITANIUM
481 br.cloop.sptk.many 1b
483 mov ar.lc=r20 // restore ar.lc
485 END(ia64_save_debug_regs)
487 GLOBAL_ENTRY(ia64_load_debug_regs)
488 alloc r16=ar.pfs,1,0,0,0
490 mov r20=ar.lc // preserve ar.lc
491 add r19=IA64_NUM_DBG_REGS*8,in0
492 mov ar.lc=IA64_NUM_DBG_REGS-1
495 1: ld8.nta r16=[in0],8
500 #ifdef CONFIG_ITANIUM
502 srlz.d // Errata 132 (NoFix status)
505 br.cloop.sptk.many 1b
507 mov ar.lc=r20 // restore ar.lc
509 END(ia64_load_debug_regs)
511 GLOBAL_ENTRY(__ia64_save_fpu)
512 alloc r2=ar.pfs,1,4,0,0
513 adds loc0=96*16-16,in0
514 adds loc1=96*16-16-128,in0
516 stf.spill.nta [loc0]=f127,-256
517 stf.spill.nta [loc1]=f119,-256
519 stf.spill.nta [loc0]=f111,-256
520 stf.spill.nta [loc1]=f103,-256
522 stf.spill.nta [loc0]=f95,-256
523 stf.spill.nta [loc1]=f87,-256
525 stf.spill.nta [loc0]=f79,-256
526 stf.spill.nta [loc1]=f71,-256
528 stf.spill.nta [loc0]=f63,-256
529 stf.spill.nta [loc1]=f55,-256
530 adds loc2=96*16-32,in0
532 stf.spill.nta [loc0]=f47,-256
533 stf.spill.nta [loc1]=f39,-256
534 adds loc3=96*16-32-128,in0
536 stf.spill.nta [loc2]=f126,-256
537 stf.spill.nta [loc3]=f118,-256
539 stf.spill.nta [loc2]=f110,-256
540 stf.spill.nta [loc3]=f102,-256
542 stf.spill.nta [loc2]=f94,-256
543 stf.spill.nta [loc3]=f86,-256
545 stf.spill.nta [loc2]=f78,-256
546 stf.spill.nta [loc3]=f70,-256
548 stf.spill.nta [loc2]=f62,-256
549 stf.spill.nta [loc3]=f54,-256
550 adds loc0=96*16-48,in0
552 stf.spill.nta [loc2]=f46,-256
553 stf.spill.nta [loc3]=f38,-256
554 adds loc1=96*16-48-128,in0
556 stf.spill.nta [loc0]=f125,-256
557 stf.spill.nta [loc1]=f117,-256
559 stf.spill.nta [loc0]=f109,-256
560 stf.spill.nta [loc1]=f101,-256
562 stf.spill.nta [loc0]=f93,-256
563 stf.spill.nta [loc1]=f85,-256
565 stf.spill.nta [loc0]=f77,-256
566 stf.spill.nta [loc1]=f69,-256
568 stf.spill.nta [loc0]=f61,-256
569 stf.spill.nta [loc1]=f53,-256
570 adds loc2=96*16-64,in0
572 stf.spill.nta [loc0]=f45,-256
573 stf.spill.nta [loc1]=f37,-256
574 adds loc3=96*16-64-128,in0
576 stf.spill.nta [loc2]=f124,-256
577 stf.spill.nta [loc3]=f116,-256
579 stf.spill.nta [loc2]=f108,-256
580 stf.spill.nta [loc3]=f100,-256
582 stf.spill.nta [loc2]=f92,-256
583 stf.spill.nta [loc3]=f84,-256
585 stf.spill.nta [loc2]=f76,-256
586 stf.spill.nta [loc3]=f68,-256
588 stf.spill.nta [loc2]=f60,-256
589 stf.spill.nta [loc3]=f52,-256
590 adds loc0=96*16-80,in0
592 stf.spill.nta [loc2]=f44,-256
593 stf.spill.nta [loc3]=f36,-256
594 adds loc1=96*16-80-128,in0
596 stf.spill.nta [loc0]=f123,-256
597 stf.spill.nta [loc1]=f115,-256
599 stf.spill.nta [loc0]=f107,-256
600 stf.spill.nta [loc1]=f99,-256
602 stf.spill.nta [loc0]=f91,-256
603 stf.spill.nta [loc1]=f83,-256
605 stf.spill.nta [loc0]=f75,-256
606 stf.spill.nta [loc1]=f67,-256
608 stf.spill.nta [loc0]=f59,-256
609 stf.spill.nta [loc1]=f51,-256
610 adds loc2=96*16-96,in0
612 stf.spill.nta [loc0]=f43,-256
613 stf.spill.nta [loc1]=f35,-256
614 adds loc3=96*16-96-128,in0
616 stf.spill.nta [loc2]=f122,-256
617 stf.spill.nta [loc3]=f114,-256
619 stf.spill.nta [loc2]=f106,-256
620 stf.spill.nta [loc3]=f98,-256
622 stf.spill.nta [loc2]=f90,-256
623 stf.spill.nta [loc3]=f82,-256
625 stf.spill.nta [loc2]=f74,-256
626 stf.spill.nta [loc3]=f66,-256
628 stf.spill.nta [loc2]=f58,-256
629 stf.spill.nta [loc3]=f50,-256
630 adds loc0=96*16-112,in0
632 stf.spill.nta [loc2]=f42,-256
633 stf.spill.nta [loc3]=f34,-256
634 adds loc1=96*16-112-128,in0
636 stf.spill.nta [loc0]=f121,-256
637 stf.spill.nta [loc1]=f113,-256
639 stf.spill.nta [loc0]=f105,-256
640 stf.spill.nta [loc1]=f97,-256
642 stf.spill.nta [loc0]=f89,-256
643 stf.spill.nta [loc1]=f81,-256
645 stf.spill.nta [loc0]=f73,-256
646 stf.spill.nta [loc1]=f65,-256
648 stf.spill.nta [loc0]=f57,-256
649 stf.spill.nta [loc1]=f49,-256
650 adds loc2=96*16-128,in0
652 stf.spill.nta [loc0]=f41,-256
653 stf.spill.nta [loc1]=f33,-256
654 adds loc3=96*16-128-128,in0
656 stf.spill.nta [loc2]=f120,-256
657 stf.spill.nta [loc3]=f112,-256
659 stf.spill.nta [loc2]=f104,-256
660 stf.spill.nta [loc3]=f96,-256
662 stf.spill.nta [loc2]=f88,-256
663 stf.spill.nta [loc3]=f80,-256
665 stf.spill.nta [loc2]=f72,-256
666 stf.spill.nta [loc3]=f64,-256
668 stf.spill.nta [loc2]=f56,-256
669 stf.spill.nta [loc3]=f48,-256
671 stf.spill.nta [loc2]=f40
672 stf.spill.nta [loc3]=f32
676 GLOBAL_ENTRY(__ia64_load_fpu)
677 alloc r2=ar.pfs,1,2,0,0
684 ldf.fill.nta f32=[in0],loc0
685 ldf.fill.nta f40=[ r3],loc0
686 ldf.fill.nta f48=[r14],loc0
687 ldf.fill.nta f56=[r15],loc0
689 ldf.fill.nta f64=[in0],loc0
690 ldf.fill.nta f72=[ r3],loc0
691 ldf.fill.nta f80=[r14],loc0
692 ldf.fill.nta f88=[r15],loc0
694 ldf.fill.nta f96=[in0],loc1
695 ldf.fill.nta f104=[ r3],loc1
696 ldf.fill.nta f112=[r14],loc1
697 ldf.fill.nta f120=[r15],loc1
699 ldf.fill.nta f33=[in0],loc0
700 ldf.fill.nta f41=[ r3],loc0
701 ldf.fill.nta f49=[r14],loc0
702 ldf.fill.nta f57=[r15],loc0
704 ldf.fill.nta f65=[in0],loc0
705 ldf.fill.nta f73=[ r3],loc0
706 ldf.fill.nta f81=[r14],loc0
707 ldf.fill.nta f89=[r15],loc0
709 ldf.fill.nta f97=[in0],loc1
710 ldf.fill.nta f105=[ r3],loc1
711 ldf.fill.nta f113=[r14],loc1
712 ldf.fill.nta f121=[r15],loc1
714 ldf.fill.nta f34=[in0],loc0
715 ldf.fill.nta f42=[ r3],loc0
716 ldf.fill.nta f50=[r14],loc0
717 ldf.fill.nta f58=[r15],loc0
719 ldf.fill.nta f66=[in0],loc0
720 ldf.fill.nta f74=[ r3],loc0
721 ldf.fill.nta f82=[r14],loc0
722 ldf.fill.nta f90=[r15],loc0
724 ldf.fill.nta f98=[in0],loc1
725 ldf.fill.nta f106=[ r3],loc1
726 ldf.fill.nta f114=[r14],loc1
727 ldf.fill.nta f122=[r15],loc1
729 ldf.fill.nta f35=[in0],loc0
730 ldf.fill.nta f43=[ r3],loc0
731 ldf.fill.nta f51=[r14],loc0
732 ldf.fill.nta f59=[r15],loc0
734 ldf.fill.nta f67=[in0],loc0
735 ldf.fill.nta f75=[ r3],loc0
736 ldf.fill.nta f83=[r14],loc0
737 ldf.fill.nta f91=[r15],loc0
739 ldf.fill.nta f99=[in0],loc1
740 ldf.fill.nta f107=[ r3],loc1
741 ldf.fill.nta f115=[r14],loc1
742 ldf.fill.nta f123=[r15],loc1
744 ldf.fill.nta f36=[in0],loc0
745 ldf.fill.nta f44=[ r3],loc0
746 ldf.fill.nta f52=[r14],loc0
747 ldf.fill.nta f60=[r15],loc0
749 ldf.fill.nta f68=[in0],loc0
750 ldf.fill.nta f76=[ r3],loc0
751 ldf.fill.nta f84=[r14],loc0
752 ldf.fill.nta f92=[r15],loc0
754 ldf.fill.nta f100=[in0],loc1
755 ldf.fill.nta f108=[ r3],loc1
756 ldf.fill.nta f116=[r14],loc1
757 ldf.fill.nta f124=[r15],loc1
759 ldf.fill.nta f37=[in0],loc0
760 ldf.fill.nta f45=[ r3],loc0
761 ldf.fill.nta f53=[r14],loc0
762 ldf.fill.nta f61=[r15],loc0
764 ldf.fill.nta f69=[in0],loc0
765 ldf.fill.nta f77=[ r3],loc0
766 ldf.fill.nta f85=[r14],loc0
767 ldf.fill.nta f93=[r15],loc0
769 ldf.fill.nta f101=[in0],loc1
770 ldf.fill.nta f109=[ r3],loc1
771 ldf.fill.nta f117=[r14],loc1
772 ldf.fill.nta f125=[r15],loc1
774 ldf.fill.nta f38 =[in0],loc0
775 ldf.fill.nta f46 =[ r3],loc0
776 ldf.fill.nta f54 =[r14],loc0
777 ldf.fill.nta f62 =[r15],loc0
779 ldf.fill.nta f70 =[in0],loc0
780 ldf.fill.nta f78 =[ r3],loc0
781 ldf.fill.nta f86 =[r14],loc0
782 ldf.fill.nta f94 =[r15],loc0
784 ldf.fill.nta f102=[in0],loc1
785 ldf.fill.nta f110=[ r3],loc1
786 ldf.fill.nta f118=[r14],loc1
787 ldf.fill.nta f126=[r15],loc1
789 ldf.fill.nta f39 =[in0],loc0
790 ldf.fill.nta f47 =[ r3],loc0
791 ldf.fill.nta f55 =[r14],loc0
792 ldf.fill.nta f63 =[r15],loc0
794 ldf.fill.nta f71 =[in0],loc0
795 ldf.fill.nta f79 =[ r3],loc0
796 ldf.fill.nta f87 =[r14],loc0
797 ldf.fill.nta f95 =[r15],loc0
799 ldf.fill.nta f103=[in0]
800 ldf.fill.nta f111=[ r3]
801 ldf.fill.nta f119=[r14]
802 ldf.fill.nta f127=[r15]
806 GLOBAL_ENTRY(__ia64_init_fpu)
807 stf.spill [sp]=f0 // M3
811 ldfps f33,f34=[sp] // M0
812 ldfps f35,f36=[sp] // M1
820 ldfps f41,f42=[sp] // M0
821 ldfps f43,f44=[sp] // M1
828 ldfps f49,f50=[sp] // M0
829 ldfps f51,f52=[sp] // M1
836 ldfps f57,f58=[sp] // M0
837 ldfps f59,f60=[sp] // M1
844 ldfps f65,f66=[sp] // M0
845 ldfps f67,f68=[sp] // M1
852 ldfps f73,f74=[sp] // M0
853 ldfps f75,f76=[sp] // M1
860 ldfps f81,f82=[sp] // M0
861 ldfps f83,f84=[sp] // M1
869 * When the instructions are cached, it would be faster to initialize
870 * the remaining registers with simply mov instructions (F-unit).
871 * This gets the time down to ~29 cycles. However, this would use up
872 * 33 bundles, whereas continuing with the above pattern yields
873 * 10 bundles and ~30 cycles.
876 ldfps f89,f90=[sp] // M0
877 ldfps f91,f92=[sp] // M1
884 ldfps f97,f98=[sp] // M0
885 ldfps f99,f100=[sp] // M1
892 ldfps f105,f106=[sp] // M0
893 ldfps f107,f108=[sp] // M1
900 ldfps f113,f114=[sp] // M0
901 ldfps f115,f116=[sp] // M1
908 ldfps f121,f122=[sp] // M0
909 ldfps f123,f124=[sp] // M1
914 br.ret.sptk.many rp // F
918 * Switch execution mode from virtual to physical
921 * r16 = new psr to establish
923 * r19 = old virtual address of ar.bsp
924 * r20 = old virtual address of sp
926 * Note: RSE must already be in enforced lazy mode
928 GLOBAL_ENTRY(ia64_switch_mode_phys)
930 rsm psr.i | psr.ic // disable interrupts and interrupt collection
935 flushrs // must be first insn in group
939 mov cr.ipsr=r16 // set new PSR
940 add r3=1f-ia64_switch_mode_phys,r15
944 mov r14=rp // get return address into a general register
947 // going to physical mode, use tpa to translate virt->phys
954 mov r18=ar.rnat // save ar.rnat
955 mov ar.bspstore=r17 // this steps on ar.rnat
959 mov ar.rnat=r18 // restore ar.rnat
960 rfi // must be last insn in group
964 END(ia64_switch_mode_phys)
967 * Switch execution mode from physical to virtual
970 * r16 = new psr to establish
971 * r19 = new bspstore to establish
972 * r20 = new sp to establish
974 * Note: RSE must already be in enforced lazy mode
976 GLOBAL_ENTRY(ia64_switch_mode_virt)
978 rsm psr.i | psr.ic // disable interrupts and interrupt collection
983 flushrs // must be first insn in group
987 mov cr.ipsr=r16 // set new PSR
988 add r3=1f-ia64_switch_mode_virt,r15
990 mov r14=rp // get return address into a general register
994 // - for code addresses, set upper bits of addr to KERNEL_START
995 // - for stack addresses, copy from input argument
996 movl r18=KERNEL_START
997 dep r3=0,r3,KERNEL_TR_PAGE_SHIFT,64-KERNEL_TR_PAGE_SHIFT
998 dep r14=0,r14,KERNEL_TR_PAGE_SHIFT,64-KERNEL_TR_PAGE_SHIFT
1005 mov r18=ar.rnat // save ar.rnat
1006 mov ar.bspstore=r19 // this steps on ar.rnat
1010 mov ar.rnat=r18 // restore ar.rnat
1011 rfi // must be last insn in group
1015 END(ia64_switch_mode_virt)
1017 GLOBAL_ENTRY(ia64_delay_loop)
1019 { nop 0 // work around GAS unwind info generation bug...
1027 // force loop to be 32-byte aligned (GAS bug means we cannot use .align
1028 // inside function body without corrupting unwind info).
1030 1: br.cloop.sptk.few 1b
1034 END(ia64_delay_loop)
1037 * Return a CPU-local timestamp in nano-seconds. This timestamp is
1038 * NOT synchronized across CPUs its return value must never be
1039 * compared against the values returned on another CPU. The usage in
1040 * kernel/sched.c ensures that.
1042 * The return-value of sched_clock() is NOT supposed to wrap-around.
1043 * If it did, it would cause some scheduling hiccups (at the worst).
1044 * Fortunately, with a 64-bit cycle-counter ticking at 100GHz, even
1045 * that would happen only once every 5+ years.
1047 * The code below basically calculates:
1049 * (ia64_get_itc() * local_cpu_data->nsec_per_cyc) >> IA64_NSEC_PER_CYC_SHIFT
1051 * except that the multiplication and the shift are done with 128-bit
1052 * intermediate precision so that we can produce a full 64-bit result.
1054 GLOBAL_ENTRY(ia64_native_sched_clock)
1055 addl r8=THIS_CPU(cpu_info) + IA64_CPUINFO_NSEC_PER_CYC_OFFSET,r0
1056 mov.m r9=ar.itc // fetch cycle-counter (35 cyc)
1060 setf.sig f9=r9 // certain to stall, so issue it _after_ ldf8...
1062 xmpy.lu f10=f9,f8 // calculate low 64 bits of 128-bit product (4 cyc)
1063 xmpy.hu f11=f9,f8 // calculate high 64 bits of 128-bit product
1065 getf.sig r8=f10 // (5 cyc)
1068 shrp r8=r9,r8,IA64_NSEC_PER_CYC_SHIFT
1070 END(ia64_native_sched_clock)
1071 #ifndef CONFIG_PARAVIRT
1072 //unsigned long long
1073 //sched_clock(void) __attribute__((alias("ia64_native_sched_clock")));
1075 sched_clock = ia64_native_sched_clock
1078 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
1079 GLOBAL_ENTRY(cycle_to_cputime)
1080 alloc r16=ar.pfs,1,0,0,0
1081 addl r8=THIS_CPU(cpu_info) + IA64_CPUINFO_NSEC_PER_CYC_OFFSET,r0
1087 xmpy.lu f10=f9,f8 // calculate low 64 bits of 128-bit product (4 cyc)
1088 xmpy.hu f11=f9,f8 // calculate high 64 bits of 128-bit product
1090 getf.sig r8=f10 // (5 cyc)
1093 shrp r8=r9,r8,IA64_NSEC_PER_CYC_SHIFT
1095 END(cycle_to_cputime)
1096 #endif /* CONFIG_VIRT_CPU_ACCOUNTING */
1098 GLOBAL_ENTRY(start_kernel_thread)
1100 .save rp, r0 // this is the end of the call-chain
1102 alloc r2 = ar.pfs, 0, 0, 2, 0
1105 br.call.sptk.many rp = kernel_thread_helper;;
1107 br.call.sptk.many rp = sys_exit;;
1108 1: br.sptk.few 1b // not reached
1109 END(start_kernel_thread)
1111 #ifdef CONFIG_IA64_BRL_EMU
1114 * Assembly routines used by brl_emu.c to set preserved register state.
1117 #define SET_REG(reg) \
1118 GLOBAL_ENTRY(ia64_set_##reg); \
1119 alloc r16=ar.pfs,1,0,0,0; \
1122 br.ret.sptk.many rp; \
1131 #endif /* CONFIG_IA64_BRL_EMU */
1135 * This routine handles spinlock contention. It uses a non-standard calling
1136 * convention to avoid converting leaf routines into interior routines. Because
1137 * of this special convention, there are several restrictions:
1139 * - do not use gp relative variables, this code is called from the kernel
1140 * and from modules, r1 is undefined.
1141 * - do not use stacked registers, the caller owns them.
1142 * - do not use the scratch stack space, the caller owns it.
1143 * - do not use any registers other than the ones listed below
1146 * ar.pfs - saved CFM of caller
1147 * ar.ccv - 0 (and available for use)
1148 * r27 - flags from spin_lock_irqsave or 0. Must be preserved.
1149 * r28 - available for use.
1150 * r29 - available for use.
1151 * r30 - available for use.
1152 * r31 - address of lock, available for use.
1153 * b6 - return address
1154 * p14 - available for use.
1155 * p15 - used to track flag status.
1157 * If you patch this code to use more registers, do not forget to update
1158 * the clobber lists for spin_lock() in arch/ia64/include/asm/spinlock.h.
1161 #if (__GNUC__ == 3 && __GNUC_MINOR__ < 3)
1163 GLOBAL_ENTRY(ia64_spinlock_contention_pre3_4)
1165 .save ar.pfs, r0 // this code effectively has a zero frame size
1169 tbit.nz p15,p0=r27,IA64_PSR_I_BIT
1170 .restore sp // pop existing prologue after next insn
1177 (p15) ssm psr.i // reenable interrupts if they were on
1178 // DavidM says that srlz.d is slow and is not required in this case
1180 // exponential backoff, kdb, lockmeter etc. go in here
1182 ld4 r30=[r31] // don't use ld4.bias; if it's contended, we won't write the word
1185 cmp4.ne p14,p0=r30,r0
1186 (p14) br.cond.sptk.few .wait
1187 (p15) rsm psr.i // disable interrupts if we reenabled them
1188 br.cond.sptk.few b6 // lock is now free, try to acquire
1189 .global ia64_spinlock_contention_pre3_4_end // for kernprof
1190 ia64_spinlock_contention_pre3_4_end:
1191 END(ia64_spinlock_contention_pre3_4)
1195 GLOBAL_ENTRY(ia64_spinlock_contention)
1199 tbit.nz p15,p0=r27,IA64_PSR_I_BIT
1202 (p15) ssm psr.i // reenable interrupts if they were on
1203 // DavidM says that srlz.d is slow and is not required in this case
1205 // exponential backoff, kdb, lockmeter etc. go in here
1207 ld4 r30=[r31] // don't use ld4.bias; if it's contended, we won't write the word
1209 cmp4.ne p14,p0=r30,r0
1211 (p14) br.cond.sptk.few .wait2
1212 (p15) rsm psr.i // disable interrupts if we reenabled them
1214 cmpxchg4.acq r30=[r31], r30, ar.ccv
1216 cmp4.ne p14,p0=r0,r30
1217 (p14) br.cond.sptk.few .wait
1219 br.ret.sptk.many b6 // lock is now taken
1220 END(ia64_spinlock_contention)
1224 #ifdef CONFIG_HOTPLUG_CPU
1225 GLOBAL_ENTRY(ia64_jump_to_sal)
1226 alloc r16=ar.pfs,1,0,0,0;;
1233 movl r18=tlb_purge_done;;
1234 DATA_VA_TO_PA(r18);;
1235 mov b1=r18 // Return location
1236 movl r18=ia64_do_tlb_purge;;
1237 DATA_VA_TO_PA(r18);;
1238 mov b2=r18 // doing tlb_flush work
1239 mov ar.rsc=0 // Put RSE in enforced lazy, LE mode
1241 DATA_VA_TO_PA(r17);;
1243 movl r16=SAL_PSR_BITS_TO_SET;;
1249 * Invalidate all TLB data/inst
1251 br.sptk.many b2;; // jump to tlb purge code
1254 RESTORE_REGION_REGS(r25, r17,r18,r19);;
1255 RESTORE_REG(b0, r25, r17);;
1256 RESTORE_REG(b1, r25, r17);;
1257 RESTORE_REG(b2, r25, r17);;
1258 RESTORE_REG(b3, r25, r17);;
1259 RESTORE_REG(b4, r25, r17);;
1260 RESTORE_REG(b5, r25, r17);;
1262 ld8 r12=[r25],0x08;;
1263 ld8 r13=[r25],0x08;;
1264 RESTORE_REG(ar.fpsr, r25, r17);;
1265 RESTORE_REG(ar.pfs, r25, r17);;
1266 RESTORE_REG(ar.rnat, r25, r17);;
1267 RESTORE_REG(ar.unat, r25, r17);;
1268 RESTORE_REG(ar.bspstore, r25, r17);;
1269 RESTORE_REG(cr.dcr, r25, r17);;
1270 RESTORE_REG(cr.iva, r25, r17);;
1271 RESTORE_REG(cr.pta, r25, r17);;
1272 srlz.d;; // required not to violate RAW dependency
1273 RESTORE_REG(cr.itv, r25, r17);;
1274 RESTORE_REG(cr.pmv, r25, r17);;
1275 RESTORE_REG(cr.cmcv, r25, r17);;
1276 RESTORE_REG(cr.lrr0, r25, r17);;
1277 RESTORE_REG(cr.lrr1, r25, r17);;
1282 ld8 r17=[r25],0x08;;
1284 RESTORE_REG(ar.lc, r25, r17);;
1286 * Now Restore floating point regs
1288 ldf.fill.nta f2=[r25],16;;
1289 ldf.fill.nta f3=[r25],16;;
1290 ldf.fill.nta f4=[r25],16;;
1291 ldf.fill.nta f5=[r25],16;;
1292 ldf.fill.nta f16=[r25],16;;
1293 ldf.fill.nta f17=[r25],16;;
1294 ldf.fill.nta f18=[r25],16;;
1295 ldf.fill.nta f19=[r25],16;;
1296 ldf.fill.nta f20=[r25],16;;
1297 ldf.fill.nta f21=[r25],16;;
1298 ldf.fill.nta f22=[r25],16;;
1299 ldf.fill.nta f23=[r25],16;;
1300 ldf.fill.nta f24=[r25],16;;
1301 ldf.fill.nta f25=[r25],16;;
1302 ldf.fill.nta f26=[r25],16;;
1303 ldf.fill.nta f27=[r25],16;;
1304 ldf.fill.nta f28=[r25],16;;
1305 ldf.fill.nta f29=[r25],16;;
1306 ldf.fill.nta f30=[r25],16;;
1307 ldf.fill.nta f31=[r25],16;;
1310 * Now that we have done all the register restores
1311 * we are now ready for the big DIVE to SAL Land
1315 br.ret.sptk.many b0;;
1316 END(ia64_jump_to_sal)
1317 #endif /* CONFIG_HOTPLUG_CPU */
1319 #endif /* CONFIG_SMP */