ff50c19875638642c8a3c7e5a2a5e41907a46372
[linux-flexiantxendom0-3.2.10.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, r4            // terminate unwind chain with a NULL rp
60         mov r4=r0
61         .body
62
63         /*
64          * Initialize the region register for region 7 and install a translation register
65          * that maps the kernel's text and data:
66          */
67         rsm psr.i | psr.ic
68         mov r16=((ia64_rid(IA64_REGION_ID_KERNEL, PAGE_OFFSET) << 8) | (IA64_GRANULE_SHIFT << 2))
69         ;;
70         srlz.i
71         mov r18=KERNEL_TR_PAGE_SHIFT<<2
72         movl r17=KERNEL_START
73         ;;
74         mov rr[r17]=r16
75         mov cr.itir=r18
76         mov cr.ifa=r17
77         mov r16=IA64_TR_KERNEL
78         movl r18=((1 << KERNEL_TR_PAGE_SHIFT) | PAGE_KERNEL)
79         ;;
80         srlz.i
81         ;;
82         itr.i itr[r16]=r18
83         ;;
84         itr.d dtr[r16]=r18
85         ;;
86         srlz.i
87
88         /*
89          * Switch into virtual mode:
90          */
91         movl r16=(IA64_PSR_IT|IA64_PSR_IC|IA64_PSR_DT|IA64_PSR_RT|IA64_PSR_DFH|IA64_PSR_BN \
92                   |IA64_PSR_DI)
93         ;;
94         mov cr.ipsr=r16
95         movl r17=1f
96         ;;
97         mov cr.iip=r17
98         mov cr.ifs=r0
99         ;;
100         rfi
101         ;;
102 1:      // now we are in virtual mode
103
104         // set IVT entry point---can't access I/O ports without it
105         movl r3=ia64_ivt
106         ;;
107         mov cr.iva=r3
108         movl r2=FPSR_DEFAULT
109         ;;
110         srlz.i
111         movl gp=__gp
112
113         mov ar.fpsr=r2
114         ;;
115
116 #ifdef CONFIG_IA64_EARLY_PRINTK
117         mov r3=(6<<8) | (IA64_GRANULE_SHIFT<<2)
118         movl r2=6<<61
119         ;;
120         mov rr[r2]=r3
121         ;;
122         srlz.i
123         ;;
124 #endif
125
126 #define isAP    p2      // are we an Application Processor?
127 #define isBP    p3      // are we the Bootstrap Processor?
128
129 #ifdef CONFIG_SMP
130         /*
131          * Find the init_task for the currently booting CPU.  At poweron, and in
132          * UP mode, task_for_booting_cpu is NULL.
133          */
134         movl r3=task_for_booting_cpu
135         ;;
136         ld8 r3=[r3]
137         movl r2=init_thread_union
138         ;;
139         cmp.eq isBP,isAP=r3,r0
140         ;;
141 (isAP)  mov r2=r3
142 #else
143         movl r2=init_thread_union
144         cmp.eq isBP,isAP=r0,r0
145 #endif
146         mov r16=KERNEL_TR_PAGE_NUM
147         ;;
148
149         // load the "current" pointer (r13) and ar.k6 with the current task
150         mov IA64_KR(CURRENT)=r2         // virtual address
151         // initialize k4 to a safe value (64-128MB is mapped by TR_KERNEL)
152         mov IA64_KR(CURRENT_STACK)=r16
153         mov r13=r2
154         /*
155          * Reserve space at the top of the stack for "struct pt_regs".  Kernel threads
156          * don't store interesting values in that structure, but the space still needs
157          * to be there because time-critical stuff such as the context switching can
158          * be implemented more efficiently (for example, __switch_to()
159          * always sets the psr.dfh bit of the task it is switching to).
160          */
161         addl r12=IA64_STK_OFFSET-IA64_PT_REGS_SIZE-16,r2
162         addl r2=IA64_RBS_OFFSET,r2      // initialize the RSE
163         mov ar.rsc=0            // place RSE in enforced lazy mode
164         ;;
165         loadrs                  // clear the dirty partition
166         ;;
167         mov ar.bspstore=r2      // establish the new RSE stack
168         ;;
169         mov ar.rsc=0x3          // place RSE in eager mode
170
171 (isBP)  dep r28=-1,r28,61,3     // make address virtual
172 (isBP)  movl r2=ia64_boot_param
173         ;;
174 (isBP)  st8 [r2]=r28            // save the address of the boot param area passed by the bootloader
175
176 #ifdef CONFIG_IA64_EARLY_PRINTK
177         .rodata
178 alive_msg:
179         stringz "I'm alive and well\n"
180 alive_msg_end:
181         .previous
182
183         alloc r2=ar.pfs,0,0,2,0
184         movl out0=alive_msg
185         movl out1=alive_msg_end-alive_msg-1
186         ;;
187         br.call.sptk.many rp=early_printk
188 1:      // force new bundle
189 #endif /* CONFIG_IA64_EARLY_PRINTK */
190
191 #ifdef CONFIG_SMP
192 (isAP)  br.call.sptk.many rp=start_secondary
193 .ret0:
194 (isAP)  br.cond.sptk self
195 #endif
196
197         // This is executed by the bootstrap processor (bsp) only:
198
199 #ifdef CONFIG_IA64_FW_EMU
200         // initialize PAL & SAL emulator:
201         br.call.sptk.many rp=sys_fw_init
202 .ret1:
203 #endif
204         br.call.sptk.many rp=start_kernel
205 .ret2:  addl r3=@ltoff(halt_msg),gp
206         ;;
207         alloc r2=ar.pfs,8,0,2,0
208         ;;
209         ld8 out0=[r3]
210         br.call.sptk.many b0=console_print
211 self:   br.sptk.many self               // endless loop
212 END(_start)
213
214 GLOBAL_ENTRY(ia64_save_debug_regs)
215         alloc r16=ar.pfs,1,0,0,0
216         mov r20=ar.lc                   // preserve ar.lc
217         mov ar.lc=IA64_NUM_DBG_REGS-1
218         mov r18=0
219         add r19=IA64_NUM_DBG_REGS*8,in0
220         ;;
221 1:      mov r16=dbr[r18]
222 #ifdef CONFIG_ITANIUM
223         ;;
224         srlz.d
225 #endif
226         mov r17=ibr[r18]
227         add r18=1,r18
228         ;;
229         st8.nta [in0]=r16,8
230         st8.nta [r19]=r17,8
231         br.cloop.sptk.many 1b
232         ;;
233         mov ar.lc=r20                   // restore ar.lc
234         br.ret.sptk.many rp
235 END(ia64_save_debug_regs)
236
237 GLOBAL_ENTRY(ia64_load_debug_regs)
238         alloc r16=ar.pfs,1,0,0,0
239         lfetch.nta [in0]
240         mov r20=ar.lc                   // preserve ar.lc
241         add r19=IA64_NUM_DBG_REGS*8,in0
242         mov ar.lc=IA64_NUM_DBG_REGS-1
243         mov r18=-1
244         ;;
245 1:      ld8.nta r16=[in0],8
246         ld8.nta r17=[r19],8
247         add r18=1,r18
248         ;;
249         mov dbr[r18]=r16
250 #ifdef CONFIG_ITANIUM
251         ;;
252         srlz.d                          // Errata 132 (NoFix status)
253 #endif
254         mov ibr[r18]=r17
255         br.cloop.sptk.many 1b
256         ;;
257         mov ar.lc=r20                   // restore ar.lc
258         br.ret.sptk.many rp
259 END(ia64_load_debug_regs)
260
261 GLOBAL_ENTRY(__ia64_save_fpu)
262         alloc r2=ar.pfs,1,4,0,0
263         adds loc0=96*16-16,in0
264         adds loc1=96*16-16-128,in0
265         ;;
266         stf.spill.nta [loc0]=f127,-256
267         stf.spill.nta [loc1]=f119,-256
268         ;;
269         stf.spill.nta [loc0]=f111,-256
270         stf.spill.nta [loc1]=f103,-256
271         ;;
272         stf.spill.nta [loc0]=f95,-256
273         stf.spill.nta [loc1]=f87,-256
274         ;;
275         stf.spill.nta [loc0]=f79,-256
276         stf.spill.nta [loc1]=f71,-256
277         ;;
278         stf.spill.nta [loc0]=f63,-256
279         stf.spill.nta [loc1]=f55,-256
280         adds loc2=96*16-32,in0
281         ;;
282         stf.spill.nta [loc0]=f47,-256
283         stf.spill.nta [loc1]=f39,-256
284         adds loc3=96*16-32-128,in0
285         ;;
286         stf.spill.nta [loc2]=f126,-256
287         stf.spill.nta [loc3]=f118,-256
288         ;;
289         stf.spill.nta [loc2]=f110,-256
290         stf.spill.nta [loc3]=f102,-256
291         ;;
292         stf.spill.nta [loc2]=f94,-256
293         stf.spill.nta [loc3]=f86,-256
294         ;;
295         stf.spill.nta [loc2]=f78,-256
296         stf.spill.nta [loc3]=f70,-256
297         ;;
298         stf.spill.nta [loc2]=f62,-256
299         stf.spill.nta [loc3]=f54,-256
300         adds loc0=96*16-48,in0
301         ;;
302         stf.spill.nta [loc2]=f46,-256
303         stf.spill.nta [loc3]=f38,-256
304         adds loc1=96*16-48-128,in0
305         ;;
306         stf.spill.nta [loc0]=f125,-256
307         stf.spill.nta [loc1]=f117,-256
308         ;;
309         stf.spill.nta [loc0]=f109,-256
310         stf.spill.nta [loc1]=f101,-256
311         ;;
312         stf.spill.nta [loc0]=f93,-256
313         stf.spill.nta [loc1]=f85,-256
314         ;;
315         stf.spill.nta [loc0]=f77,-256
316         stf.spill.nta [loc1]=f69,-256
317         ;;
318         stf.spill.nta [loc0]=f61,-256
319         stf.spill.nta [loc1]=f53,-256
320         adds loc2=96*16-64,in0
321         ;;
322         stf.spill.nta [loc0]=f45,-256
323         stf.spill.nta [loc1]=f37,-256
324         adds loc3=96*16-64-128,in0
325         ;;
326         stf.spill.nta [loc2]=f124,-256
327         stf.spill.nta [loc3]=f116,-256
328         ;;
329         stf.spill.nta [loc2]=f108,-256
330         stf.spill.nta [loc3]=f100,-256
331         ;;
332         stf.spill.nta [loc2]=f92,-256
333         stf.spill.nta [loc3]=f84,-256
334         ;;
335         stf.spill.nta [loc2]=f76,-256
336         stf.spill.nta [loc3]=f68,-256
337         ;;
338         stf.spill.nta [loc2]=f60,-256
339         stf.spill.nta [loc3]=f52,-256
340         adds loc0=96*16-80,in0
341         ;;
342         stf.spill.nta [loc2]=f44,-256
343         stf.spill.nta [loc3]=f36,-256
344         adds loc1=96*16-80-128,in0
345         ;;
346         stf.spill.nta [loc0]=f123,-256
347         stf.spill.nta [loc1]=f115,-256
348         ;;
349         stf.spill.nta [loc0]=f107,-256
350         stf.spill.nta [loc1]=f99,-256
351         ;;
352         stf.spill.nta [loc0]=f91,-256
353         stf.spill.nta [loc1]=f83,-256
354         ;;
355         stf.spill.nta [loc0]=f75,-256
356         stf.spill.nta [loc1]=f67,-256
357         ;;
358         stf.spill.nta [loc0]=f59,-256
359         stf.spill.nta [loc1]=f51,-256
360         adds loc2=96*16-96,in0
361         ;;
362         stf.spill.nta [loc0]=f43,-256
363         stf.spill.nta [loc1]=f35,-256
364         adds loc3=96*16-96-128,in0
365         ;;
366         stf.spill.nta [loc2]=f122,-256
367         stf.spill.nta [loc3]=f114,-256
368         ;;
369         stf.spill.nta [loc2]=f106,-256
370         stf.spill.nta [loc3]=f98,-256
371         ;;
372         stf.spill.nta [loc2]=f90,-256
373         stf.spill.nta [loc3]=f82,-256
374         ;;
375         stf.spill.nta [loc2]=f74,-256
376         stf.spill.nta [loc3]=f66,-256
377         ;;
378         stf.spill.nta [loc2]=f58,-256
379         stf.spill.nta [loc3]=f50,-256
380         adds loc0=96*16-112,in0
381         ;;
382         stf.spill.nta [loc2]=f42,-256
383         stf.spill.nta [loc3]=f34,-256
384         adds loc1=96*16-112-128,in0
385         ;;
386         stf.spill.nta [loc0]=f121,-256
387         stf.spill.nta [loc1]=f113,-256
388         ;;
389         stf.spill.nta [loc0]=f105,-256
390         stf.spill.nta [loc1]=f97,-256
391         ;;
392         stf.spill.nta [loc0]=f89,-256
393         stf.spill.nta [loc1]=f81,-256
394         ;;
395         stf.spill.nta [loc0]=f73,-256
396         stf.spill.nta [loc1]=f65,-256
397         ;;
398         stf.spill.nta [loc0]=f57,-256
399         stf.spill.nta [loc1]=f49,-256
400         adds loc2=96*16-128,in0
401         ;;
402         stf.spill.nta [loc0]=f41,-256
403         stf.spill.nta [loc1]=f33,-256
404         adds loc3=96*16-128-128,in0
405         ;;
406         stf.spill.nta [loc2]=f120,-256
407         stf.spill.nta [loc3]=f112,-256
408         ;;
409         stf.spill.nta [loc2]=f104,-256
410         stf.spill.nta [loc3]=f96,-256
411         ;;
412         stf.spill.nta [loc2]=f88,-256
413         stf.spill.nta [loc3]=f80,-256
414         ;;
415         stf.spill.nta [loc2]=f72,-256
416         stf.spill.nta [loc3]=f64,-256
417         ;;
418         stf.spill.nta [loc2]=f56,-256
419         stf.spill.nta [loc3]=f48,-256
420         ;;
421         stf.spill.nta [loc2]=f40
422         stf.spill.nta [loc3]=f32
423         br.ret.sptk.many rp
424 END(__ia64_save_fpu)
425
426 GLOBAL_ENTRY(__ia64_load_fpu)
427         alloc r2=ar.pfs,1,2,0,0
428         adds r3=128,in0
429         adds r14=256,in0
430         adds r15=384,in0
431         mov loc0=512
432         mov loc1=-1024+16
433         ;;
434         ldf.fill.nta f32=[in0],loc0
435         ldf.fill.nta f40=[ r3],loc0
436         ldf.fill.nta f48=[r14],loc0
437         ldf.fill.nta f56=[r15],loc0
438         ;;
439         ldf.fill.nta f64=[in0],loc0
440         ldf.fill.nta f72=[ r3],loc0
441         ldf.fill.nta f80=[r14],loc0
442         ldf.fill.nta f88=[r15],loc0
443         ;;
444         ldf.fill.nta f96=[in0],loc1
445         ldf.fill.nta f104=[ r3],loc1
446         ldf.fill.nta f112=[r14],loc1
447         ldf.fill.nta f120=[r15],loc1
448         ;;
449         ldf.fill.nta f33=[in0],loc0
450         ldf.fill.nta f41=[ r3],loc0
451         ldf.fill.nta f49=[r14],loc0
452         ldf.fill.nta f57=[r15],loc0
453         ;;
454         ldf.fill.nta f65=[in0],loc0
455         ldf.fill.nta f73=[ r3],loc0
456         ldf.fill.nta f81=[r14],loc0
457         ldf.fill.nta f89=[r15],loc0
458         ;;
459         ldf.fill.nta f97=[in0],loc1
460         ldf.fill.nta f105=[ r3],loc1
461         ldf.fill.nta f113=[r14],loc1
462         ldf.fill.nta f121=[r15],loc1
463         ;;
464         ldf.fill.nta f34=[in0],loc0
465         ldf.fill.nta f42=[ r3],loc0
466         ldf.fill.nta f50=[r14],loc0
467         ldf.fill.nta f58=[r15],loc0
468         ;;
469         ldf.fill.nta f66=[in0],loc0
470         ldf.fill.nta f74=[ r3],loc0
471         ldf.fill.nta f82=[r14],loc0
472         ldf.fill.nta f90=[r15],loc0
473         ;;
474         ldf.fill.nta f98=[in0],loc1
475         ldf.fill.nta f106=[ r3],loc1
476         ldf.fill.nta f114=[r14],loc1
477         ldf.fill.nta f122=[r15],loc1
478         ;;
479         ldf.fill.nta f35=[in0],loc0
480         ldf.fill.nta f43=[ r3],loc0
481         ldf.fill.nta f51=[r14],loc0
482         ldf.fill.nta f59=[r15],loc0
483         ;;
484         ldf.fill.nta f67=[in0],loc0
485         ldf.fill.nta f75=[ r3],loc0
486         ldf.fill.nta f83=[r14],loc0
487         ldf.fill.nta f91=[r15],loc0
488         ;;
489         ldf.fill.nta f99=[in0],loc1
490         ldf.fill.nta f107=[ r3],loc1
491         ldf.fill.nta f115=[r14],loc1
492         ldf.fill.nta f123=[r15],loc1
493         ;;
494         ldf.fill.nta f36=[in0],loc0
495         ldf.fill.nta f44=[ r3],loc0
496         ldf.fill.nta f52=[r14],loc0
497         ldf.fill.nta f60=[r15],loc0
498         ;;
499         ldf.fill.nta f68=[in0],loc0
500         ldf.fill.nta f76=[ r3],loc0
501         ldf.fill.nta f84=[r14],loc0
502         ldf.fill.nta f92=[r15],loc0
503         ;;
504         ldf.fill.nta f100=[in0],loc1
505         ldf.fill.nta f108=[ r3],loc1
506         ldf.fill.nta f116=[r14],loc1
507         ldf.fill.nta f124=[r15],loc1
508         ;;
509         ldf.fill.nta f37=[in0],loc0
510         ldf.fill.nta f45=[ r3],loc0
511         ldf.fill.nta f53=[r14],loc0
512         ldf.fill.nta f61=[r15],loc0
513         ;;
514         ldf.fill.nta f69=[in0],loc0
515         ldf.fill.nta f77=[ r3],loc0
516         ldf.fill.nta f85=[r14],loc0
517         ldf.fill.nta f93=[r15],loc0
518         ;;
519         ldf.fill.nta f101=[in0],loc1
520         ldf.fill.nta f109=[ r3],loc1
521         ldf.fill.nta f117=[r14],loc1
522         ldf.fill.nta f125=[r15],loc1
523         ;;
524         ldf.fill.nta f38 =[in0],loc0
525         ldf.fill.nta f46 =[ r3],loc0
526         ldf.fill.nta f54 =[r14],loc0
527         ldf.fill.nta f62 =[r15],loc0
528         ;;
529         ldf.fill.nta f70 =[in0],loc0
530         ldf.fill.nta f78 =[ r3],loc0
531         ldf.fill.nta f86 =[r14],loc0
532         ldf.fill.nta f94 =[r15],loc0
533         ;;
534         ldf.fill.nta f102=[in0],loc1
535         ldf.fill.nta f110=[ r3],loc1
536         ldf.fill.nta f118=[r14],loc1
537         ldf.fill.nta f126=[r15],loc1
538         ;;
539         ldf.fill.nta f39 =[in0],loc0
540         ldf.fill.nta f47 =[ r3],loc0
541         ldf.fill.nta f55 =[r14],loc0
542         ldf.fill.nta f63 =[r15],loc0
543         ;;
544         ldf.fill.nta f71 =[in0],loc0
545         ldf.fill.nta f79 =[ r3],loc0
546         ldf.fill.nta f87 =[r14],loc0
547         ldf.fill.nta f95 =[r15],loc0
548         ;;
549         ldf.fill.nta f103=[in0]
550         ldf.fill.nta f111=[ r3]
551         ldf.fill.nta f119=[r14]
552         ldf.fill.nta f127=[r15]
553         br.ret.sptk.many rp
554 END(__ia64_load_fpu)
555
556 GLOBAL_ENTRY(__ia64_init_fpu)
557         stf.spill [sp]=f0               // M3
558         mov      f32=f0                 // F
559         nop.b    0
560
561         ldfps    f33,f34=[sp]           // M0
562         ldfps    f35,f36=[sp]           // M1
563         mov      f37=f0                 // F
564         ;;
565
566         setf.s   f38=r0                 // M2
567         setf.s   f39=r0                 // M3
568         mov      f40=f0                 // F
569
570         ldfps    f41,f42=[sp]           // M0
571         ldfps    f43,f44=[sp]           // M1
572         mov      f45=f0                 // F
573
574         setf.s   f46=r0                 // M2
575         setf.s   f47=r0                 // M3
576         mov      f48=f0                 // F
577
578         ldfps    f49,f50=[sp]           // M0
579         ldfps    f51,f52=[sp]           // M1
580         mov      f53=f0                 // F
581
582         setf.s   f54=r0                 // M2
583         setf.s   f55=r0                 // M3
584         mov      f56=f0                 // F
585
586         ldfps    f57,f58=[sp]           // M0
587         ldfps    f59,f60=[sp]           // M1
588         mov      f61=f0                 // F
589
590         setf.s   f62=r0                 // M2
591         setf.s   f63=r0                 // M3
592         mov      f64=f0                 // F
593
594         ldfps    f65,f66=[sp]           // M0
595         ldfps    f67,f68=[sp]           // M1
596         mov      f69=f0                 // F
597
598         setf.s   f70=r0                 // M2
599         setf.s   f71=r0                 // M3
600         mov      f72=f0                 // F
601
602         ldfps    f73,f74=[sp]           // M0
603         ldfps    f75,f76=[sp]           // M1
604         mov      f77=f0                 // F
605
606         setf.s   f78=r0                 // M2
607         setf.s   f79=r0                 // M3
608         mov      f80=f0                 // F
609
610         ldfps    f81,f82=[sp]           // M0
611         ldfps    f83,f84=[sp]           // M1
612         mov      f85=f0                 // F
613
614         setf.s   f86=r0                 // M2
615         setf.s   f87=r0                 // M3
616         mov      f88=f0                 // F
617
618         /*
619          * When the instructions are cached, it would be faster to initialize
620          * the remaining registers with simply mov instructions (F-unit).
621          * This gets the time down to ~29 cycles.  However, this would use up
622          * 33 bundles, whereas continuing with the above pattern yields
623          * 10 bundles and ~30 cycles.
624          */
625
626         ldfps    f89,f90=[sp]           // M0
627         ldfps    f91,f92=[sp]           // M1
628         mov      f93=f0                 // F
629
630         setf.s   f94=r0                 // M2
631         setf.s   f95=r0                 // M3
632         mov      f96=f0                 // F
633
634         ldfps    f97,f98=[sp]           // M0
635         ldfps    f99,f100=[sp]          // M1
636         mov      f101=f0                // F
637
638         setf.s   f102=r0                // M2
639         setf.s   f103=r0                // M3
640         mov      f104=f0                // F
641
642         ldfps    f105,f106=[sp]         // M0
643         ldfps    f107,f108=[sp]         // M1
644         mov      f109=f0                // F
645
646         setf.s   f110=r0                // M2
647         setf.s   f111=r0                // M3
648         mov      f112=f0                // F
649
650         ldfps    f113,f114=[sp]         // M0
651         ldfps    f115,f116=[sp]         // M1
652         mov      f117=f0                // F
653
654         setf.s   f118=r0                // M2
655         setf.s   f119=r0                // M3
656         mov      f120=f0                // F
657
658         ldfps    f121,f122=[sp]         // M0
659         ldfps    f123,f124=[sp]         // M1
660         mov      f125=f0                // F
661
662         setf.s   f126=r0                // M2
663         setf.s   f127=r0                // M3
664         br.ret.sptk.many rp             // F
665 END(__ia64_init_fpu)
666
667 /*
668  * Switch execution mode from virtual to physical or vice versa.
669  *
670  * Inputs:
671  *      r16 = new psr to establish
672  *
673  * Note: RSE must already be in enforced lazy mode
674  */
675 GLOBAL_ENTRY(ia64_switch_mode)
676  {
677         alloc r2=ar.pfs,0,0,0,0
678         rsm psr.i | psr.ic              // disable interrupts and interrupt collection
679         mov r15=ip
680  }
681         ;;
682  {
683         flushrs                         // must be first insn in group
684         srlz.i
685         shr.u r19=r15,61                // r19 <- top 3 bits of current IP
686  }
687         ;;
688         mov cr.ipsr=r16                 // set new PSR
689         add r3=1f-ia64_switch_mode,r15
690         xor r15=0x7,r19                 // flip the region bits
691
692         mov r17=ar.bsp
693         mov r14=rp                      // get return address into a general register
694
695         // switch RSE backing store:
696         ;;
697         dep r17=r15,r17,61,3            // make ar.bsp physical or virtual
698         mov r18=ar.rnat                 // save ar.rnat
699         ;;
700         mov ar.bspstore=r17             // this steps on ar.rnat
701         dep r3=r15,r3,61,3              // make rfi return address physical or virtual
702         ;;
703         mov cr.iip=r3
704         mov cr.ifs=r0
705         dep sp=r15,sp,61,3              // make stack pointer physical or virtual
706         ;;
707         mov ar.rnat=r18                 // restore ar.rnat
708         dep r14=r15,r14,61,3            // make function return address physical or virtual
709         rfi                             // must be last insn in group
710         ;;
711 1:      mov rp=r14
712         br.ret.sptk.many rp
713 END(ia64_switch_mode)
714
715 #ifdef CONFIG_IA64_BRL_EMU
716
717 /*
718  *  Assembly routines used by brl_emu.c to set preserved register state.
719  */
720
721 #define SET_REG(reg)                            \
722  GLOBAL_ENTRY(ia64_set_##reg);                  \
723         alloc r16=ar.pfs,1,0,0,0;               \
724         mov reg=r32;                            \
725         ;;                                      \
726         br.ret.sptk.many rp;                    \
727  END(ia64_set_##reg)
728
729 SET_REG(b1);
730 SET_REG(b2);
731 SET_REG(b3);
732 SET_REG(b4);
733 SET_REG(b5);
734
735 #endif /* CONFIG_IA64_BRL_EMU */
736
737 #ifdef CONFIG_SMP
738         /*
739          * This routine handles spinlock contention.  It uses a non-standard calling
740          * convention to avoid converting leaf routines into interior routines.  Because
741          * of this special convention, there are several restrictions:
742          *
743          * - do not use gp relative variables, this code is called from the kernel
744          *   and from modules, r1 is undefined.
745          * - do not use stacked registers, the caller owns them.
746          * - do not use the scratch stack space, the caller owns it.
747          * - do not use any registers other than the ones listed below
748          *
749          * Inputs:
750          *   ar.pfs - saved CFM of caller
751          *   ar.ccv - 0 (and available for use)
752          *   r28    - available for use.
753          *   r29    - available for use.
754          *   r30    - available for use.
755          *   r31    - address of lock, available for use.
756          *   b7     - return address
757          *   p14    - available for use.
758          *
759          * If you patch this code to use more registers, do not forget to update
760          * the clobber lists for spin_lock() in include/asm-ia64/spinlock.h.
761          */
762
763 #if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 4)
764
765 GLOBAL_ENTRY(ia64_spinlock_contention_pre3_4)
766         .prologue
767         .save ar.pfs, r0        // this code effectively has a zero frame size
768         .save rp, r28
769         .body
770         nop 0
771         nop 0
772         .restore sp             // pop existing prologue after next insn
773         mov b6 = r28
774         .prologue
775         .save ar.pfs, r0
776         .altrp b6
777         .body
778 .wait:
779         // exponential backoff, kdb, lockmeter etc. go in here
780         hint @pause
781         ld4.bias r30=[r31]
782         nop 0
783         ;;
784         cmp4.eq p14,p0=r30,r0
785 (p14)   br.cond.sptk.few b6     // lock is now free, try to acquire
786         br.cond.sptk.few .wait
787 END(ia64_spinlock_contention_pre3_4)
788
789 #else
790
791 GLOBAL_ENTRY(ia64_spinlock_contention)
792         .prologue
793         .altrp b6
794         .body
795 .wait:
796         // exponential backoff, kdb, lockmeter etc. go in here
797         hint @pause
798         ld4.bias r30=[r31]
799         ;;
800         cmp4.ne p14,p0=r30,r0
801         mov r30 = 1
802 (p14)   br.cond.sptk.few .wait
803         ;;
804         cmpxchg4.acq r30=[r31], r30, ar.ccv
805         ;;
806         cmp4.ne p14,p0=r0,r30
807 (p14)   br.cond.sptk.few .wait
808
809         br.ret.sptk.many b6     // lock is now taken
810 END(ia64_spinlock_contention)
811
812 #endif
813
814 #endif /* CONFIG_SMP */