VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / arch / ia64 / kernel / head.S
1 /*
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
6  * entry point.
7  *
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.
18  */
19
20 #include <linux/config.h>
21
22 #include <asm/asmmacro.h>
23 #include <asm/fpu.h>
24 #include <asm/kregs.h>
25 #include <asm/mmu_context.h>
26 #include <asm/offsets.h>
27 #include <asm/pal.h>
28 #include <asm/pgtable.h>
29 #include <asm/processor.h>
30 #include <asm/ptrace.h>
31 #include <asm/system.h>
32
33         .section __special_page_section,"ax"
34
35         .global empty_zero_page
36 empty_zero_page:
37         .skip PAGE_SIZE
38
39         .global swapper_pg_dir
40 swapper_pg_dir:
41         .skip PAGE_SIZE
42
43         .rodata
44 halt_msg:
45         stringz "Halting kernel\n"
46
47         .text
48
49         .global start_ap
50
51         /*
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.
55          */
56 GLOBAL_ENTRY(_start)
57 start_ap:
58         .prologue
59         .save rp, r0            // terminate unwind chain with a NULL rp
60         .body
61
62         rsm psr.i | psr.ic
63         ;;
64         srlz.i
65         ;;
66         /*
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
71          */
72         mov r16=((ia64_rid(IA64_REGION_ID_KERNEL, (5<<61)) << 8) | (PAGE_SHIFT << 2) | 1)
73         movl r17=(5<<61)
74         mov r18=((ia64_rid(IA64_REGION_ID_KERNEL, (6<<61)) << 8) | (IA64_GRANULE_SHIFT << 2))
75         movl r19=(6<<61)
76         mov r20=((ia64_rid(IA64_REGION_ID_KERNEL, (7<<61)) << 8) | (IA64_GRANULE_SHIFT << 2))
77         movl r21=(7<<61)
78         ;;
79         mov rr[r17]=r16
80         mov rr[r19]=r18
81         mov rr[r21]=r20
82         ;;
83         /*
84          * Now pin mappings into the TLB for kernel text and data
85          */
86         mov r18=KERNEL_TR_PAGE_SHIFT<<2
87         movl r17=KERNEL_START
88         ;;
89         mov cr.itir=r18
90         mov cr.ifa=r17
91         mov r16=IA64_TR_KERNEL
92         mov r3=ip
93         movl r18=PAGE_KERNEL
94         ;;
95         dep r2=0,r3,0,KERNEL_TR_PAGE_SHIFT
96         ;;
97         or r18=r2,r18
98         ;;
99         srlz.i
100         ;;
101         itr.i itr[r16]=r18
102         ;;
103         itr.d dtr[r16]=r18
104         ;;
105         srlz.i
106
107         /*
108          * Switch into virtual mode:
109          */
110         movl r16=(IA64_PSR_IT|IA64_PSR_IC|IA64_PSR_DT|IA64_PSR_RT|IA64_PSR_DFH|IA64_PSR_BN \
111                   |IA64_PSR_DI)
112         ;;
113         mov cr.ipsr=r16
114         movl r17=1f
115         ;;
116         mov cr.iip=r17
117         mov cr.ifs=r0
118         ;;
119         rfi
120         ;;
121 1:      // now we are in virtual mode
122
123         // set IVT entry point---can't access I/O ports without it
124         movl r3=ia64_ivt
125         ;;
126         mov cr.iva=r3
127         movl r2=FPSR_DEFAULT
128         ;;
129         srlz.i
130         movl gp=__gp
131
132         mov ar.fpsr=r2
133         ;;
134
135 #define isAP    p2      // are we an Application Processor?
136 #define isBP    p3      // are we the Bootstrap Processor?
137
138 #ifdef CONFIG_SMP
139         /*
140          * Find the init_task for the currently booting CPU.  At poweron, and in
141          * UP mode, task_for_booting_cpu is NULL.
142          */
143         movl r3=task_for_booting_cpu
144         ;;
145         ld8 r3=[r3]
146         movl r2=init_task
147         ;;
148         cmp.eq isBP,isAP=r3,r0
149         ;;
150 (isAP)  mov r2=r3
151 #else
152         movl r2=init_task
153         cmp.eq isBP,isAP=r0,r0
154 #endif
155         ;;
156         tpa r3=r2               // r3 == phys addr of task struct
157         mov r16=-1
158 (isBP)  br.cond.dpnt .load_current // BP stack is on region 5 --- no need to map it
159
160         // load mapping for stack (virtaddr in r2, physaddr in r3)
161         rsm psr.ic
162         movl r17=PAGE_KERNEL
163         ;;
164         srlz.d
165         dep r18=0,r3,0,12
166         ;;
167         or r18=r17,r18
168         dep r2=-1,r3,61,3       // IMVA of task
169         ;;
170         mov r17=rr[r2]
171         shr.u r16=r3,IA64_GRANULE_SHIFT
172         ;;
173         dep r17=0,r17,8,24
174         ;;
175         mov cr.itir=r17
176         mov cr.ifa=r2
177
178         mov r19=IA64_TR_CURRENT_STACK
179         ;;
180         itr.d dtr[r19]=r18
181         ;;
182         ssm psr.ic
183         srlz.d
184         ;;
185
186 .load_current:
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
190         mov r13=r2
191         /*
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).
197          */
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
201         ;;
202         loadrs                  // clear the dirty partition
203         ;;
204         mov ar.bspstore=r2      // establish the new RSE stack
205         ;;
206         mov ar.rsc=0x3          // place RSE in eager mode
207
208 (isBP)  dep r28=-1,r28,61,3     // make address virtual
209 (isBP)  movl r2=ia64_boot_param
210         ;;
211 (isBP)  st8 [r2]=r28            // save the address of the boot param area passed by the bootloader
212
213 #ifdef CONFIG_IA64_EARLY_PRINTK
214         .rodata
215 alive_msg:
216         stringz "I'm alive and well\n"
217 alive_msg_end:
218         .previous
219
220         alloc r2=ar.pfs,0,0,2,0
221         movl out0=alive_msg
222         movl out1=alive_msg_end-alive_msg-1
223         ;;
224         br.call.sptk.many rp=early_printk
225 1:      // force new bundle
226 #endif /* CONFIG_IA64_EARLY_PRINTK */
227
228 #ifdef CONFIG_SMP
229 (isAP)  br.call.sptk.many rp=start_secondary
230 .ret0:
231 (isAP)  br.cond.sptk self
232 #endif
233
234         // This is executed by the bootstrap processor (bsp) only:
235
236 #ifdef CONFIG_IA64_FW_EMU
237         // initialize PAL & SAL emulator:
238         br.call.sptk.many rp=sys_fw_init
239 .ret1:
240 #endif
241         br.call.sptk.many rp=start_kernel
242 .ret2:  addl r3=@ltoff(halt_msg),gp
243         ;;
244         alloc r2=ar.pfs,8,0,2,0
245         ;;
246         ld8 out0=[r3]
247         br.call.sptk.many b0=console_print
248 self:   br.sptk.many self               // endless loop
249 END(_start)
250
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
255         mov r18=0
256         add r19=IA64_NUM_DBG_REGS*8,in0
257         ;;
258 1:      mov r16=dbr[r18]
259 #ifdef CONFIG_ITANIUM
260         ;;
261         srlz.d
262 #endif
263         mov r17=ibr[r18]
264         add r18=1,r18
265         ;;
266         st8.nta [in0]=r16,8
267         st8.nta [r19]=r17,8
268         br.cloop.sptk.many 1b
269         ;;
270         mov ar.lc=r20                   // restore ar.lc
271         br.ret.sptk.many rp
272 END(ia64_save_debug_regs)
273
274 GLOBAL_ENTRY(ia64_load_debug_regs)
275         alloc r16=ar.pfs,1,0,0,0
276         lfetch.nta [in0]
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
280         mov r18=-1
281         ;;
282 1:      ld8.nta r16=[in0],8
283         ld8.nta r17=[r19],8
284         add r18=1,r18
285         ;;
286         mov dbr[r18]=r16
287 #ifdef CONFIG_ITANIUM
288         ;;
289         srlz.d                          // Errata 132 (NoFix status)
290 #endif
291         mov ibr[r18]=r17
292         br.cloop.sptk.many 1b
293         ;;
294         mov ar.lc=r20                   // restore ar.lc
295         br.ret.sptk.many rp
296 END(ia64_load_debug_regs)
297
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
302         ;;
303         stf.spill.nta [loc0]=f127,-256
304         stf.spill.nta [loc1]=f119,-256
305         ;;
306         stf.spill.nta [loc0]=f111,-256
307         stf.spill.nta [loc1]=f103,-256
308         ;;
309         stf.spill.nta [loc0]=f95,-256
310         stf.spill.nta [loc1]=f87,-256
311         ;;
312         stf.spill.nta [loc0]=f79,-256
313         stf.spill.nta [loc1]=f71,-256
314         ;;
315         stf.spill.nta [loc0]=f63,-256
316         stf.spill.nta [loc1]=f55,-256
317         adds loc2=96*16-32,in0
318         ;;
319         stf.spill.nta [loc0]=f47,-256
320         stf.spill.nta [loc1]=f39,-256
321         adds loc3=96*16-32-128,in0
322         ;;
323         stf.spill.nta [loc2]=f126,-256
324         stf.spill.nta [loc3]=f118,-256
325         ;;
326         stf.spill.nta [loc2]=f110,-256
327         stf.spill.nta [loc3]=f102,-256
328         ;;
329         stf.spill.nta [loc2]=f94,-256
330         stf.spill.nta [loc3]=f86,-256
331         ;;
332         stf.spill.nta [loc2]=f78,-256
333         stf.spill.nta [loc3]=f70,-256
334         ;;
335         stf.spill.nta [loc2]=f62,-256
336         stf.spill.nta [loc3]=f54,-256
337         adds loc0=96*16-48,in0
338         ;;
339         stf.spill.nta [loc2]=f46,-256
340         stf.spill.nta [loc3]=f38,-256
341         adds loc1=96*16-48-128,in0
342         ;;
343         stf.spill.nta [loc0]=f125,-256
344         stf.spill.nta [loc1]=f117,-256
345         ;;
346         stf.spill.nta [loc0]=f109,-256
347         stf.spill.nta [loc1]=f101,-256
348         ;;
349         stf.spill.nta [loc0]=f93,-256
350         stf.spill.nta [loc1]=f85,-256
351         ;;
352         stf.spill.nta [loc0]=f77,-256
353         stf.spill.nta [loc1]=f69,-256
354         ;;
355         stf.spill.nta [loc0]=f61,-256
356         stf.spill.nta [loc1]=f53,-256
357         adds loc2=96*16-64,in0
358         ;;
359         stf.spill.nta [loc0]=f45,-256
360         stf.spill.nta [loc1]=f37,-256
361         adds loc3=96*16-64-128,in0
362         ;;
363         stf.spill.nta [loc2]=f124,-256
364         stf.spill.nta [loc3]=f116,-256
365         ;;
366         stf.spill.nta [loc2]=f108,-256
367         stf.spill.nta [loc3]=f100,-256
368         ;;
369         stf.spill.nta [loc2]=f92,-256
370         stf.spill.nta [loc3]=f84,-256
371         ;;
372         stf.spill.nta [loc2]=f76,-256
373         stf.spill.nta [loc3]=f68,-256
374         ;;
375         stf.spill.nta [loc2]=f60,-256
376         stf.spill.nta [loc3]=f52,-256
377         adds loc0=96*16-80,in0
378         ;;
379         stf.spill.nta [loc2]=f44,-256
380         stf.spill.nta [loc3]=f36,-256
381         adds loc1=96*16-80-128,in0
382         ;;
383         stf.spill.nta [loc0]=f123,-256
384         stf.spill.nta [loc1]=f115,-256
385         ;;
386         stf.spill.nta [loc0]=f107,-256
387         stf.spill.nta [loc1]=f99,-256
388         ;;
389         stf.spill.nta [loc0]=f91,-256
390         stf.spill.nta [loc1]=f83,-256
391         ;;
392         stf.spill.nta [loc0]=f75,-256
393         stf.spill.nta [loc1]=f67,-256
394         ;;
395         stf.spill.nta [loc0]=f59,-256
396         stf.spill.nta [loc1]=f51,-256
397         adds loc2=96*16-96,in0
398         ;;
399         stf.spill.nta [loc0]=f43,-256
400         stf.spill.nta [loc1]=f35,-256
401         adds loc3=96*16-96-128,in0
402         ;;
403         stf.spill.nta [loc2]=f122,-256
404         stf.spill.nta [loc3]=f114,-256
405         ;;
406         stf.spill.nta [loc2]=f106,-256
407         stf.spill.nta [loc3]=f98,-256
408         ;;
409         stf.spill.nta [loc2]=f90,-256
410         stf.spill.nta [loc3]=f82,-256
411         ;;
412         stf.spill.nta [loc2]=f74,-256
413         stf.spill.nta [loc3]=f66,-256
414         ;;
415         stf.spill.nta [loc2]=f58,-256
416         stf.spill.nta [loc3]=f50,-256
417         adds loc0=96*16-112,in0
418         ;;
419         stf.spill.nta [loc2]=f42,-256
420         stf.spill.nta [loc3]=f34,-256
421         adds loc1=96*16-112-128,in0
422         ;;
423         stf.spill.nta [loc0]=f121,-256
424         stf.spill.nta [loc1]=f113,-256
425         ;;
426         stf.spill.nta [loc0]=f105,-256
427         stf.spill.nta [loc1]=f97,-256
428         ;;
429         stf.spill.nta [loc0]=f89,-256
430         stf.spill.nta [loc1]=f81,-256
431         ;;
432         stf.spill.nta [loc0]=f73,-256
433         stf.spill.nta [loc1]=f65,-256
434         ;;
435         stf.spill.nta [loc0]=f57,-256
436         stf.spill.nta [loc1]=f49,-256
437         adds loc2=96*16-128,in0
438         ;;
439         stf.spill.nta [loc0]=f41,-256
440         stf.spill.nta [loc1]=f33,-256
441         adds loc3=96*16-128-128,in0
442         ;;
443         stf.spill.nta [loc2]=f120,-256
444         stf.spill.nta [loc3]=f112,-256
445         ;;
446         stf.spill.nta [loc2]=f104,-256
447         stf.spill.nta [loc3]=f96,-256
448         ;;
449         stf.spill.nta [loc2]=f88,-256
450         stf.spill.nta [loc3]=f80,-256
451         ;;
452         stf.spill.nta [loc2]=f72,-256
453         stf.spill.nta [loc3]=f64,-256
454         ;;
455         stf.spill.nta [loc2]=f56,-256
456         stf.spill.nta [loc3]=f48,-256
457         ;;
458         stf.spill.nta [loc2]=f40
459         stf.spill.nta [loc3]=f32
460         br.ret.sptk.many rp
461 END(__ia64_save_fpu)
462
463 GLOBAL_ENTRY(__ia64_load_fpu)
464         alloc r2=ar.pfs,1,2,0,0
465         adds r3=128,in0
466         adds r14=256,in0
467         adds r15=384,in0
468         mov loc0=512
469         mov loc1=-1024+16
470         ;;
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
475         ;;
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
480         ;;
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
485         ;;
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
490         ;;
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
495         ;;
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
500         ;;
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
505         ;;
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
510         ;;
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
515         ;;
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
520         ;;
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
525         ;;
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
530         ;;
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
535         ;;
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
540         ;;
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
545         ;;
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
550         ;;
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
555         ;;
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
560         ;;
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
565         ;;
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
570         ;;
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
575         ;;
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
580         ;;
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
585         ;;
586         ldf.fill.nta f103=[in0]
587         ldf.fill.nta f111=[ r3]
588         ldf.fill.nta f119=[r14]
589         ldf.fill.nta f127=[r15]
590         br.ret.sptk.many rp
591 END(__ia64_load_fpu)
592
593 GLOBAL_ENTRY(__ia64_init_fpu)
594         stf.spill [sp]=f0               // M3
595         mov      f32=f0                 // F
596         nop.b    0
597
598         ldfps    f33,f34=[sp]           // M0
599         ldfps    f35,f36=[sp]           // M1
600         mov      f37=f0                 // F
601         ;;
602
603         setf.s   f38=r0                 // M2
604         setf.s   f39=r0                 // M3
605         mov      f40=f0                 // F
606
607         ldfps    f41,f42=[sp]           // M0
608         ldfps    f43,f44=[sp]           // M1
609         mov      f45=f0                 // F
610
611         setf.s   f46=r0                 // M2
612         setf.s   f47=r0                 // M3
613         mov      f48=f0                 // F
614
615         ldfps    f49,f50=[sp]           // M0
616         ldfps    f51,f52=[sp]           // M1
617         mov      f53=f0                 // F
618
619         setf.s   f54=r0                 // M2
620         setf.s   f55=r0                 // M3
621         mov      f56=f0                 // F
622
623         ldfps    f57,f58=[sp]           // M0
624         ldfps    f59,f60=[sp]           // M1
625         mov      f61=f0                 // F
626
627         setf.s   f62=r0                 // M2
628         setf.s   f63=r0                 // M3
629         mov      f64=f0                 // F
630
631         ldfps    f65,f66=[sp]           // M0
632         ldfps    f67,f68=[sp]           // M1
633         mov      f69=f0                 // F
634
635         setf.s   f70=r0                 // M2
636         setf.s   f71=r0                 // M3
637         mov      f72=f0                 // F
638
639         ldfps    f73,f74=[sp]           // M0
640         ldfps    f75,f76=[sp]           // M1
641         mov      f77=f0                 // F
642
643         setf.s   f78=r0                 // M2
644         setf.s   f79=r0                 // M3
645         mov      f80=f0                 // F
646
647         ldfps    f81,f82=[sp]           // M0
648         ldfps    f83,f84=[sp]           // M1
649         mov      f85=f0                 // F
650
651         setf.s   f86=r0                 // M2
652         setf.s   f87=r0                 // M3
653         mov      f88=f0                 // F
654
655         /*
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.
661          */
662
663         ldfps    f89,f90=[sp]           // M0
664         ldfps    f91,f92=[sp]           // M1
665         mov      f93=f0                 // F
666
667         setf.s   f94=r0                 // M2
668         setf.s   f95=r0                 // M3
669         mov      f96=f0                 // F
670
671         ldfps    f97,f98=[sp]           // M0
672         ldfps    f99,f100=[sp]          // M1
673         mov      f101=f0                // F
674
675         setf.s   f102=r0                // M2
676         setf.s   f103=r0                // M3
677         mov      f104=f0                // F
678
679         ldfps    f105,f106=[sp]         // M0
680         ldfps    f107,f108=[sp]         // M1
681         mov      f109=f0                // F
682
683         setf.s   f110=r0                // M2
684         setf.s   f111=r0                // M3
685         mov      f112=f0                // F
686
687         ldfps    f113,f114=[sp]         // M0
688         ldfps    f115,f116=[sp]         // M1
689         mov      f117=f0                // F
690
691         setf.s   f118=r0                // M2
692         setf.s   f119=r0                // M3
693         mov      f120=f0                // F
694
695         ldfps    f121,f122=[sp]         // M0
696         ldfps    f123,f124=[sp]         // M1
697         mov      f125=f0                // F
698
699         setf.s   f126=r0                // M2
700         setf.s   f127=r0                // M3
701         br.ret.sptk.many rp             // F
702 END(__ia64_init_fpu)
703
704 /*
705  * Switch execution mode from virtual to physical
706  *
707  * Inputs:
708  *      r16 = new psr to establish
709  * Output:
710  *      r19 = old virtual address of ar.bsp
711  *      r20 = old virtual address of sp
712  *
713  * Note: RSE must already be in enforced lazy mode
714  */
715 GLOBAL_ENTRY(ia64_switch_mode_phys)
716  {
717         alloc r2=ar.pfs,0,0,0,0
718         rsm psr.i | psr.ic              // disable interrupts and interrupt collection
719         mov r15=ip
720  }
721         ;;
722  {
723         flushrs                         // must be first insn in group
724         srlz.i
725  }
726         ;;
727         mov cr.ipsr=r16                 // set new PSR
728         add r3=1f-ia64_switch_mode_phys,r15
729
730         mov r19=ar.bsp
731         mov r20=sp
732         mov r14=rp                      // get return address into a general register
733         ;;
734
735         // going to physical mode, use tpa to translate virt->phys
736         tpa r17=r19
737         tpa r3=r3
738         tpa sp=sp
739         tpa r14=r14
740         ;;
741
742         mov r18=ar.rnat                 // save ar.rnat
743         mov ar.bspstore=r17             // this steps on ar.rnat
744         mov cr.iip=r3
745         mov cr.ifs=r0
746         ;;
747         mov ar.rnat=r18                 // restore ar.rnat
748         rfi                             // must be last insn in group
749         ;;
750 1:      mov rp=r14
751         br.ret.sptk.many rp
752 END(ia64_switch_mode_phys)
753
754 /*
755  * Switch execution mode from physical to virtual
756  *
757  * Inputs:
758  *      r16 = new psr to establish
759  *      r19 = new bspstore to establish
760  *      r20 = new sp to establish
761  *
762  * Note: RSE must already be in enforced lazy mode
763  */
764 GLOBAL_ENTRY(ia64_switch_mode_virt)
765  {
766         alloc r2=ar.pfs,0,0,0,0
767         rsm psr.i | psr.ic              // disable interrupts and interrupt collection
768         mov r15=ip
769  }
770         ;;
771  {
772         flushrs                         // must be first insn in group
773         srlz.i
774  }
775         ;;
776         mov cr.ipsr=r16                 // set new PSR
777         add r3=1f-ia64_switch_mode_virt,r15
778
779         mov r14=rp                      // get return address into a general register
780         ;;
781
782         // going to virtual
783         //   - for code addresses, set upper bits of addr to KERNEL_START
784         //   - for stack addresses, set upper 3 bits to 0xe.... Dont change any of the
785         //     lower bits since we want it to stay identity mapped
786         movl r18=KERNEL_START
787         dep r3=0,r3,KERNEL_TR_PAGE_SHIFT,64-KERNEL_TR_PAGE_SHIFT
788         dep r14=0,r14,KERNEL_TR_PAGE_SHIFT,64-KERNEL_TR_PAGE_SHIFT
789         mov sp=r20
790         ;;
791         or r3=r3,r18
792         or r14=r14,r18
793         ;;
794
795         mov r18=ar.rnat                 // save ar.rnat
796         mov ar.bspstore=r19             // this steps on ar.rnat
797         mov cr.iip=r3
798         mov cr.ifs=r0
799         ;;
800         mov ar.rnat=r18                 // restore ar.rnat
801         rfi                             // must be last insn in group
802         ;;
803 1:      mov rp=r14
804         br.ret.sptk.many rp
805 END(ia64_switch_mode_virt)
806
807 GLOBAL_ENTRY(ia64_delay_loop)
808         .prologue
809 {       nop 0                   // work around GAS unwind info generation bug...
810         .save ar.lc,r2
811         mov r2=ar.lc
812         .body
813         ;;
814         mov ar.lc=r32
815 }
816         ;;
817         // force loop to be 32-byte aligned (GAS bug means we cannot use .align
818         // inside function body without corrupting unwind info).
819 {       nop 0 }
820 1:      br.cloop.sptk.few 1b
821         ;;
822         mov ar.lc=r2
823         br.ret.sptk.many rp
824 END(ia64_delay_loop)
825
826 /*
827  * Return a CPU-local timestamp in nano-seconds.  This timestamp is
828  * NOT synchronized across CPUs its return value must never be
829  * compared against the values returned on another CPU.  The usage in
830  * kernel/sched.c ensures that.
831  *
832  * The return-value of sched_clock() is NOT supposed to wrap-around.
833  * If it did, it would cause some scheduling hiccups (at the worst).
834  * Fortunately, with a 64-bit cycle-counter ticking at 100GHz, even
835  * that would happen only once every 5+ years.
836  *
837  * The code below basically calculates:
838  *
839  *   (ia64_get_itc() * local_cpu_data->nsec_per_cyc) >> IA64_NSEC_PER_CYC_SHIFT
840  *
841  * except that the multiplication and the shift are done with 128-bit
842  * intermediate precision so that we can produce a full 64-bit result.
843  */
844 GLOBAL_ENTRY(sched_clock)
845         addl r8=THIS_CPU(cpu_info) + IA64_CPUINFO_NSEC_PER_CYC_OFFSET,r0
846         mov.m r9=ar.itc         // fetch cycle-counter                          (35 cyc)
847         ;;
848         ldf8 f8=[r8]
849         ;;
850         setf.sig f9=r9          // certain to stall, so issue it _after_ ldf8...
851         ;;
852         xmpy.lu f10=f9,f8       // calculate low 64 bits of 128-bit product     (4 cyc)
853         xmpy.hu f11=f9,f8       // calculate high 64 bits of 128-bit product
854         ;;
855         getf.sig r8=f10         //                                              (5 cyc)
856         getf.sig r9=f11
857         ;;
858         shrp r8=r9,r8,IA64_NSEC_PER_CYC_SHIFT
859         br.ret.sptk.many rp
860 END(sched_clock)
861
862 GLOBAL_ENTRY(start_kernel_thread)
863         .prologue
864         .save rp, r0                            // this is the end of the call-chain
865         .body
866         alloc r2 = ar.pfs, 0, 0, 2, 0
867         mov out0 = r9
868         mov out1 = r11;;
869         br.call.sptk.many rp = kernel_thread_helper;;
870         mov out0 = r8
871         br.call.sptk.many rp = sys_exit;;
872 1:      br.sptk.few 1b                          // not reached
873 END(start_kernel_thread)
874
875 #ifdef CONFIG_IA64_BRL_EMU
876
877 /*
878  *  Assembly routines used by brl_emu.c to set preserved register state.
879  */
880
881 #define SET_REG(reg)                            \
882  GLOBAL_ENTRY(ia64_set_##reg);                  \
883         alloc r16=ar.pfs,1,0,0,0;               \
884         mov reg=r32;                            \
885         ;;                                      \
886         br.ret.sptk.many rp;                    \
887  END(ia64_set_##reg)
888
889 SET_REG(b1);
890 SET_REG(b2);
891 SET_REG(b3);
892 SET_REG(b4);
893 SET_REG(b5);
894
895 #endif /* CONFIG_IA64_BRL_EMU */
896
897 #ifdef CONFIG_SMP
898         /*
899          * This routine handles spinlock contention.  It uses a non-standard calling
900          * convention to avoid converting leaf routines into interior routines.  Because
901          * of this special convention, there are several restrictions:
902          *
903          * - do not use gp relative variables, this code is called from the kernel
904          *   and from modules, r1 is undefined.
905          * - do not use stacked registers, the caller owns them.
906          * - do not use the scratch stack space, the caller owns it.
907          * - do not use any registers other than the ones listed below
908          *
909          * Inputs:
910          *   ar.pfs - saved CFM of caller
911          *   ar.ccv - 0 (and available for use)
912          *   r27    - flags from spin_lock_irqsave or 0.  Must be preserved.
913          *   r28    - available for use.
914          *   r29    - available for use.
915          *   r30    - available for use.
916          *   r31    - address of lock, available for use.
917          *   b6     - return address
918          *   p14    - available for use.
919          *   p15    - used to track flag status.
920          *
921          * If you patch this code to use more registers, do not forget to update
922          * the clobber lists for spin_lock() in include/asm-ia64/spinlock.h.
923          */
924
925 #if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 3)
926
927 GLOBAL_ENTRY(ia64_spinlock_contention_pre3_4)
928         .prologue
929         .save ar.pfs, r0        // this code effectively has a zero frame size
930         .save rp, r28
931         .body
932         nop 0
933         tbit.nz p15,p0=r27,IA64_PSR_I_BIT
934         .restore sp             // pop existing prologue after next insn
935         mov b6 = r28
936         .prologue
937         .save ar.pfs, r0
938         .altrp b6
939         .body
940         ;;
941 (p15)   ssm psr.i               // reenable interrupts if they were on
942                                 // DavidM says that srlz.d is slow and is not required in this case
943 .wait:
944         // exponential backoff, kdb, lockmeter etc. go in here
945         hint @pause
946         ld4 r30=[r31]           // don't use ld4.bias; if it's contended, we won't write the word
947         nop 0
948         ;;
949         cmp4.ne p14,p0=r30,r0
950 (p14)   br.cond.sptk.few .wait
951 (p15)   rsm psr.i               // disable interrupts if we reenabled them
952         br.cond.sptk.few b6     // lock is now free, try to acquire
953 END(ia64_spinlock_contention_pre3_4)
954
955 #else
956
957 GLOBAL_ENTRY(ia64_spinlock_contention)
958         .prologue
959         .altrp b6
960         .body
961         tbit.nz p15,p0=r27,IA64_PSR_I_BIT
962         ;;
963 .wait:
964 (p15)   ssm psr.i               // reenable interrupts if they were on
965                                 // DavidM says that srlz.d is slow and is not required in this case
966 .wait2:
967         // exponential backoff, kdb, lockmeter etc. go in here
968         hint @pause
969         ld4 r30=[r31]           // don't use ld4.bias; if it's contended, we won't write the word
970         ;;
971         cmp4.ne p14,p0=r30,r0
972         mov r30 = 1
973 (p14)   br.cond.sptk.few .wait2
974 (p15)   rsm psr.i               // disable interrupts if we reenabled them
975         ;;
976         cmpxchg4.acq r30=[r31], r30, ar.ccv
977         ;;
978         cmp4.ne p14,p0=r0,r30
979 (p14)   br.cond.sptk.few .wait
980
981         br.ret.sptk.many b6     // lock is now taken
982 END(ia64_spinlock_contention)
983
984 #endif
985
986 #endif /* CONFIG_SMP */