patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / arch / parisc / kernel / head64.S
1 /*
2  *
3  * This file is subject to the terms and conditions of the GNU General Public
4  * License.  See the file "COPYING" in the main directory of this archive
5  * for more details.
6  *
7  * Copyright (C) 1999 by Helge Deller
8  * Copyright 1999 SuSE GmbH (Philipp Rumpf)
9  * Copyright 1999 Philipp Rumpf (prumpf@tux.org)
10  * Copyright 2000 Hewlett Packard (Paul Bame, bame@puffin.external.hp.com)
11  * Copyright (C) 2001 Grant Grundler (Hewlett Packard)
12  *
13  * Initial Version 04-23-1999 by Helge Deller <deller@gmx.de>
14  */
15
16
17 #include <linux/autoconf.h>     /* for CONFIG_SMP */
18
19 #include <asm/offsets.h>
20 #include <asm/psw.h>
21
22 #include <asm/assembly.h>
23 #include <asm/pgtable.h>
24 #include <asm/pdc.h>            /* for PDC_PSW defines */
25
26
27         .level 2.0w
28
29         .data
30
31         .export boot_args
32 boot_args:
33         .word 0 /* arg0 */
34         .word 0 /* arg1 */
35         .word 0 /* arg2 */
36         .word 0 /* arg3 */
37
38         .text
39         .align  4       
40
41         .export stext
42         .export _stext,data             /* Kernel want it this way! */
43 _stext:
44 stext:
45         .proc
46         .callinfo
47
48         /* Make sure sr4-sr7 are set to zero for the kernel address space */
49         mtsp    %r0,%sr4
50         mtsp    %r0,%sr5
51         mtsp    %r0,%sr6
52         mtsp    %r0,%sr7
53
54         /* Clear BSS (shouldn't the boot loader do this?) */
55
56         .import __bss_start,data
57         .import __bss_stop,data
58
59         ldil            L%PA(__bss_start),%r3
60         ldo             R%PA(__bss_start)(%r3),%r3
61         ldil            L%PA(__bss_stop),%r4
62         ldo             R%PA(__bss_stop)(%r4),%r4
63 $bss_loop:
64         cmpb,<<,n       %r3,%r4,$bss_loop
65         stb,ma          %r0,1(%r3)
66
67         /* Save away the arguments the boot loader passed in (32 bit args) */
68
69         ldil            L%PA(boot_args),%r1
70         ldo             R%PA(boot_args)(%r1),%r1
71         stw,ma          %arg0,4(%r1)
72         stw,ma          %arg1,4(%r1)
73         stw,ma          %arg2,4(%r1)
74         stw,ma          %arg3,4(%r1)
75
76         /* Initialize startup VM. Just map first 8 MB of memory */
77
78         ldil            L%PA(pg0),%r1
79         ldo             R%PA(pg0)(%r1),%r1
80
81         ldil            L%PA(pmd0),%r5
82         ldo             R%PA(pmd0)(%r5),%r5
83         ldo             _PAGE_TABLE(%r5),%r3
84
85         ldil            L%PA(swapper_pg_dir),%r4
86         ldo             R%PA(swapper_pg_dir)(%r4),%r4
87
88         mtctl           %r4,%cr24       /* Initialize kernel root pointer */
89         mtctl           %r4,%cr25       /* Initialize user root pointer */
90
91         stw             %r3,ASM_PGD_ENTRY*ASM_PGD_ENTRY_SIZE(%r4)
92
93         ldo             _PAGE_TABLE(%r1),%r3
94         ldo             ASM_PMD_ENTRY*ASM_PMD_ENTRY_SIZE(%r5),%r5
95         ldi             ASM_PT_INITIAL,%r1
96 1:
97         stw             %r3,0(%r5)
98         ldo             ASM_PAGE_SIZE(%r3),%r3
99         addib,>         -1,%r1,1b
100         ldo             ASM_PMD_ENTRY_SIZE(%r5),%r5
101
102         ldo             _PAGE_KERNEL(%r0),%r3 /* Hardwired 0 phys addr start */
103         ldil            L%PA(pg0),%r1
104         ldo             R%PA(pg0)(%r1),%r1
105
106 $pgt_fill_loop:
107         std,ma          %r3,ASM_PTE_ENTRY_SIZE(%r1)
108         ldo             ASM_PAGE_SIZE(%r3),%r3
109         bb,>=           %r3,31-KERNEL_INITIAL_ORDER,$pgt_fill_loop
110         nop
111
112         /* And the RFI Target address too */
113         load32          start_kernel, %r11
114
115         /* And the stack pointer too */
116         load32          PA(init_thread_union+THREAD_SZ_ALGN),%sp
117
118         /* And the initial task pointer */
119
120         load32          init_thread_union,%r6
121         mtctl           %r6,%cr30
122
123         /* And the interrupt stack */
124
125         load32          interrupt_stack,%r6
126         mtctl           %r6,%cr31
127
128         /* Act like PDC just called us - that's how slave CPUs enter */
129 #define MEM_PDC_LO 0x388
130 #define MEM_PDC_HI 0x35C
131         ldw             MEM_PDC_LO(%r0),%r3
132         ldw             MEM_PDC_HI(%r0),%r6
133         depd            %r6, 31, 32, %r3        /* move to upper word */
134
135 #ifdef CONFIG_SMP
136         /* Set the smp rendevous address into page zero.
137         ** It would be safer to do this in init_smp_config() but
138         ** it's just way easier to deal with here because
139         ** of 64-bit function ptrs and the address is local to this file.
140         */
141         ldil            L%PA(smp_slave_stext),%r10
142         ldo             R%PA(smp_slave_stext)(%r10),%r10
143         stw             %r10,0x10(%r0)  /* MEM_RENDEZ */
144         stw             %r0,0x28(%r0)   /* MEM_RENDEZ_HI - assume addr < 4GB */
145
146         /* FALLTHROUGH */
147         .procend
148
149         /*
150         ** Code Common to both Monarch and Slave processors.
151         ** Entry:
152         **    %r3       PDCE_PROC address
153         **    %r11      RFI target address.
154         **
155         ** Caller must init: SR4-7, %sp, %r10, %cr24/25, 
156         */
157 common_stext:
158         .proc
159         .callinfo
160 #else /* CONFIG_SMP */
161         /* Clear PDC's CPU handoff address - we won't use it */
162         stw             %r0,0x10(%r0)   /* MEM_RENDEZ */
163         stw             %r0,0x28(%r0)   /* MEM_RENDEZ_HI */
164 #endif /* CONFIG_SMP */
165
166         /* Save the rfi target address */
167         ldd             TI_TASK-THREAD_SZ_ALGN(%sp), %r10
168         tophys_r1       %r10
169         std             %r11,  TASK_PT_GR11(%r10)
170
171         /* Switch to wide mode; Superdome doesn't support narrow PDC
172         ** calls.
173         */
174 1:      mfia            %rp             /* clear upper part of pcoq */
175         ldo             2f-1b(%rp),%rp
176         depdi           0,31,32,%rp
177         bv              (%rp)
178         ssm             PSW_SM_W,%r0
179 2:
180
181         /* Set Wide mode as the "Default" (eg for traps)
182         ** First trap occurs *right* after (or part of) rfi for slave CPUs.
183         ** Someday, palo might not do this for the Monarch either.
184         */
185
186         ldo             PDC_PSW(%r0),%arg0              /* 21 */
187         ldo             PDC_PSW_SET_DEFAULTS(%r0),%arg1 /* 2 */
188         ldo             PDC_PSW_WIDE_BIT(%r0),%arg2     /* 2 */
189
190         load32          PA(stext_pdc_ret), %rp
191
192         bv              (%r3)
193         copy            %r0,%arg3
194
195 stext_pdc_ret:
196         /* restore rfi target address*/
197         ldd             TI_TASK-THREAD_SZ_ALGN(%sp), %r10
198         tophys_r1       %r10
199         ldd             TASK_PT_GR11(%r10), %r11
200
201         /* PARANOID: clear user scratch/user space SR's */
202         mtsp    %r0,%sr0
203         mtsp    %r0,%sr1
204         mtsp    %r0,%sr2
205         mtsp    %r0,%sr3
206
207         /* Initialize Protection Registers */
208         mtctl   %r0,%cr8
209         mtctl   %r0,%cr9
210         mtctl   %r0,%cr12
211         mtctl   %r0,%cr13
212
213         /* Prepare to RFI! Man all the cannons! */
214         tovirt_r1       %sp
215
216         /* Initialize the global data pointer */
217         load32          __gp,%dp
218
219         /* Set up our interrupt table.  HPMCs might not work after this! */
220         ldil            L%PA(fault_vector_20),%r10
221         ldo             R%PA(fault_vector_20)(%r10),%r10
222         mtctl           %r10,%cr14
223
224         b               aligned_rfi
225         nop
226
227         /* the magic spell */
228         .align          256
229 aligned_rfi:
230         ssm             0,0
231         nop             /* 1 */
232         nop             /* 2 */
233         nop             /* 3 */
234         nop             /* 4 */
235         nop             /* 5 */
236         nop             /* 6 */
237         nop             /* 7 */
238         nop             /* 8 */
239
240         /* turn off troublesome PSW bits */
241         rsm             PSW_Q+PSW_I+PSW_D+PSW_P+PSW_R, %r0
242
243         /* kernel PSW:
244          *  - no interruptions except HPMC and TOC (which are handled by PDC)
245          *  - Q bit set (IODC / PDC interruptions)
246          *  - big-endian
247          *  - virtually mapped
248          */
249         load32          KERNEL_PSW,%r10
250         mtctl           %r10,%ipsw
251
252         /* Set the space pointers for the post-RFI world
253         ** Clear the two-level IIA Space Queue, effectively setting
254         ** Kernel space.
255         */
256         mtctl           %r0,%cr17       /* Clear IIASQ tail */
257         mtctl           %r0,%cr17       /* Clear IIASQ head */
258
259         /* Load RFI target into PC queue */
260         mtctl           %r11,%cr18      /* IIAOQ head */
261         ldo             4(%r11),%r11
262         mtctl           %r11,%cr18      /* IIAOQ tail */
263
264         /* Jump to hyperspace */
265         rfi
266         nop
267
268         .procend
269
270
271 #ifdef CONFIG_SMP
272
273         .import smp_init_current_idle_task,data
274         .import smp_callin,code
275
276 /***************************************************************************
277 *
278 * smp_slave_stext is executed by all non-monarch Processors when the Monarch
279 * pokes the slave CPUs in smp.c:smp_boot_cpus().
280 *
281 * Once here, registers values are initialized in order to branch to virtual
282 * mode. Once all available/eligible CPUs are in virtual mode, all are
283 * released and start out by executing their own idle task.
284 *****************************************************************************/
285
286
287 smp_slave_stext:
288         .proc
289         .callinfo
290
291         /*
292         ** Initialize Space registers
293         */
294         mtsp       %r0,%sr4
295         mtsp       %r0,%sr5
296         mtsp       %r0,%sr6
297         mtsp       %r0,%sr7
298
299         /*  Initialize the SP - monarch sets up smp_init_current_idle_task */
300         load32          PA(smp_init_current_idle_task),%sp
301         ldd             0(%sp),%sp      /* load task address */
302         ldd             TASK_THREAD_INFO(%sp), %sp
303         mtctl           %sp,%cr30       /* store in cr30 */
304         ldo             THREAD_SZ_ALGN(%sp),%sp
305         tophys_r1       %sp
306
307         /* point CPU to kernel page tables */
308         load32          PA(swapper_pg_dir),%r4
309         mtctl           %r4,%cr24       /* Initialize kernel root pointer */
310         mtctl           %r4,%cr25       /* Initialize user root pointer */
311
312         /* Setup PDCE_PROC entry */
313         copy            %arg0,%r3
314
315         /* Load RFI target address.  */
316         load32          smp_callin, %r11
317         
318         /* ok...common code can handle the rest */
319         b               common_stext
320         nop
321
322         .procend
323 #endif /* CONFIG_SMP */
324