VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[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         shrd            %r5,PxD_VALUE_SHIFT,%r3
84         ldo             (PxD_FLAG_PRESENT+PxD_FLAG_VALID)(%r3),%r3
85
86         ldil            L%PA(swapper_pg_dir),%r4
87         ldo             R%PA(swapper_pg_dir)(%r4),%r4
88
89         mtctl           %r4,%cr24       /* Initialize kernel root pointer */
90         mtctl           %r4,%cr25       /* Initialize user root pointer */
91
92         stw             %r3,ASM_PGD_ENTRY*ASM_PGD_ENTRY_SIZE(%r4)
93
94         shrd            %r1,PxD_VALUE_SHIFT,%r3
95         ldo             (PxD_FLAG_PRESENT+PxD_FLAG_VALID)(%r3),%r3
96         ldo             ASM_PMD_ENTRY*ASM_PMD_ENTRY_SIZE(%r5),%r5
97         ldi             ASM_PT_INITIAL,%r1
98 1:
99         stw             %r3,0(%r5)
100         ldo             (ASM_PAGE_SIZE >> PxD_VALUE_SHIFT)(%r3),%r3
101         addib,>         -1,%r1,1b
102         ldo             ASM_PMD_ENTRY_SIZE(%r5),%r5
103
104         ldo             _PAGE_KERNEL(%r0),%r3 /* Hardwired 0 phys addr start */
105         ldil            L%PA(pg0),%r1
106         ldo             R%PA(pg0)(%r1),%r1
107
108 $pgt_fill_loop:
109         std,ma          %r3,ASM_PTE_ENTRY_SIZE(%r1)
110         ldo             ASM_PAGE_SIZE(%r3),%r3
111         bb,>=           %r3,31-KERNEL_INITIAL_ORDER,$pgt_fill_loop
112         nop
113
114         /* And the RFI Target address too */
115         load32          start_kernel, %r11
116
117         /* And the stack pointer too */
118         load32          PA(init_thread_union+THREAD_SZ_ALGN),%sp
119
120         /* And the initial task pointer */
121
122         load32          init_thread_union,%r6
123         mtctl           %r6,%cr30
124
125         /* And the interrupt stack */
126
127         load32          interrupt_stack,%r6
128         mtctl           %r6,%cr31
129
130         /* Act like PDC just called us - that's how slave CPUs enter */
131 #define MEM_PDC_LO 0x388
132 #define MEM_PDC_HI 0x35C
133         ldw             MEM_PDC_LO(%r0),%r3
134         ldw             MEM_PDC_HI(%r0),%r6
135         depd            %r6, 31, 32, %r3        /* move to upper word */
136
137 #ifdef CONFIG_SMP
138         /* Set the smp rendevous address into page zero.
139         ** It would be safer to do this in init_smp_config() but
140         ** it's just way easier to deal with here because
141         ** of 64-bit function ptrs and the address is local to this file.
142         */
143         ldil            L%PA(smp_slave_stext),%r10
144         ldo             R%PA(smp_slave_stext)(%r10),%r10
145         stw             %r10,0x10(%r0)  /* MEM_RENDEZ */
146         stw             %r0,0x28(%r0)   /* MEM_RENDEZ_HI - assume addr < 4GB */
147
148         /* FALLTHROUGH */
149         .procend
150
151         /*
152         ** Code Common to both Monarch and Slave processors.
153         ** Entry:
154         **    %r3       PDCE_PROC address
155         **    %r11      RFI target address.
156         **
157         ** Caller must init: SR4-7, %sp, %r10, %cr24/25, 
158         */
159 common_stext:
160         .proc
161         .callinfo
162 #else /* CONFIG_SMP */
163         /* Clear PDC's CPU handoff address - we won't use it */
164         stw             %r0,0x10(%r0)   /* MEM_RENDEZ */
165         stw             %r0,0x28(%r0)   /* MEM_RENDEZ_HI */
166 #endif /* CONFIG_SMP */
167
168         /* Save the rfi target address */
169         ldd             TI_TASK-THREAD_SZ_ALGN(%sp), %r10
170         tophys_r1       %r10
171         std             %r11,  TASK_PT_GR11(%r10)
172
173         /* Switch to wide mode; Superdome doesn't support narrow PDC
174         ** calls.
175         */
176 1:      mfia            %rp             /* clear upper part of pcoq */
177         ldo             2f-1b(%rp),%rp
178         depdi           0,31,32,%rp
179         bv              (%rp)
180         ssm             PSW_SM_W,%r0
181 2:
182
183         /* Set Wide mode as the "Default" (eg for traps)
184         ** First trap occurs *right* after (or part of) rfi for slave CPUs.
185         ** Someday, palo might not do this for the Monarch either.
186         */
187
188         ldo             PDC_PSW(%r0),%arg0              /* 21 */
189         ldo             PDC_PSW_SET_DEFAULTS(%r0),%arg1 /* 2 */
190         ldo             PDC_PSW_WIDE_BIT(%r0),%arg2     /* 2 */
191
192         load32          PA(stext_pdc_ret), %rp
193
194         bv              (%r3)
195         copy            %r0,%arg3
196
197 stext_pdc_ret:
198         /* restore rfi target address*/
199         ldd             TI_TASK-THREAD_SZ_ALGN(%sp), %r10
200         tophys_r1       %r10
201         ldd             TASK_PT_GR11(%r10), %r11
202
203         /* PARANOID: clear user scratch/user space SR's */
204         mtsp    %r0,%sr0
205         mtsp    %r0,%sr1
206         mtsp    %r0,%sr2
207         mtsp    %r0,%sr3
208
209         /* Initialize Protection Registers */
210         mtctl   %r0,%cr8
211         mtctl   %r0,%cr9
212         mtctl   %r0,%cr12
213         mtctl   %r0,%cr13
214
215         /* Prepare to RFI! Man all the cannons! */
216         tovirt_r1       %sp
217
218         /* Initialize the global data pointer */
219         load32          __gp,%dp
220
221         /* Set up our interrupt table.  HPMCs might not work after this! */
222         ldil            L%PA(fault_vector_20),%r10
223         ldo             R%PA(fault_vector_20)(%r10),%r10
224         mtctl           %r10,%cr14
225
226         b               aligned_rfi
227         nop
228
229         /* the magic spell */
230         .align          256
231 aligned_rfi:
232         ssm             0,0
233         nop             /* 1 */
234         nop             /* 2 */
235         nop             /* 3 */
236         nop             /* 4 */
237         nop             /* 5 */
238         nop             /* 6 */
239         nop             /* 7 */
240         nop             /* 8 */
241
242         /* turn off troublesome PSW bits */
243         rsm             PSW_Q+PSW_I+PSW_D+PSW_P+PSW_R, %r0
244
245         /* kernel PSW:
246          *  - no interruptions except HPMC and TOC (which are handled by PDC)
247          *  - Q bit set (IODC / PDC interruptions)
248          *  - big-endian
249          *  - virtually mapped
250          */
251         load32          KERNEL_PSW,%r10
252         mtctl           %r10,%ipsw
253
254         /* Set the space pointers for the post-RFI world
255         ** Clear the two-level IIA Space Queue, effectively setting
256         ** Kernel space.
257         */
258         mtctl           %r0,%cr17       /* Clear IIASQ tail */
259         mtctl           %r0,%cr17       /* Clear IIASQ head */
260
261         /* Load RFI target into PC queue */
262         mtctl           %r11,%cr18      /* IIAOQ head */
263         ldo             4(%r11),%r11
264         mtctl           %r11,%cr18      /* IIAOQ tail */
265
266         /* Jump to hyperspace */
267         rfi
268         nop
269
270         .procend
271
272
273 #ifdef CONFIG_SMP
274
275         .import smp_init_current_idle_task,data
276         .import smp_callin,code
277
278 /***************************************************************************
279 *
280 * smp_slave_stext is executed by all non-monarch Processors when the Monarch
281 * pokes the slave CPUs in smp.c:smp_boot_cpus().
282 *
283 * Once here, registers values are initialized in order to branch to virtual
284 * mode. Once all available/eligible CPUs are in virtual mode, all are
285 * released and start out by executing their own idle task.
286 *****************************************************************************/
287
288
289 smp_slave_stext:
290         .proc
291         .callinfo
292
293         /*
294         ** Initialize Space registers
295         */
296         mtsp       %r0,%sr4
297         mtsp       %r0,%sr5
298         mtsp       %r0,%sr6
299         mtsp       %r0,%sr7
300
301         /*  Initialize the SP - monarch sets up smp_init_current_idle_task */
302         load32          PA(smp_init_current_idle_task),%sp
303         ldd             0(%sp),%sp      /* load task address */
304         tophys_r1       %sp
305         ldd             TASK_THREAD_INFO(%sp), %sp
306         mtctl           %sp,%cr30       /* store in cr30 */
307         ldo             THREAD_SZ_ALGN(%sp),%sp
308         tophys_r1       %sp
309
310         /* point CPU to kernel page tables */
311         load32          PA(swapper_pg_dir),%r4
312         mtctl           %r4,%cr24       /* Initialize kernel root pointer */
313         mtctl           %r4,%cr25       /* Initialize user root pointer */
314
315         /* Setup PDCE_PROC entry */
316         copy            %arg0,%r3
317
318         /* Load RFI target address.  */
319         load32          smp_callin, %r11
320         
321         /* ok...common code can handle the rest */
322         b               common_stext
323         nop
324
325         .procend
326 #endif /* CONFIG_SMP */
327