GNU Linux-libre 4.9.331-gnu1
[releases.git] / arch / parisc / kernel / head.S
1 /* This file is subject to the terms and conditions of the GNU General Public
2  * License.  See the file "COPYING" in the main directory of this archive
3  * for more details.
4  *
5  * Copyright (C) 1999-2007 by Helge Deller <deller@gmx.de>
6  * Copyright 1999 SuSE GmbH (Philipp Rumpf)
7  * Copyright 1999 Philipp Rumpf (prumpf@tux.org)
8  * Copyright 2000 Hewlett Packard (Paul Bame, bame@puffin.external.hp.com)
9  * Copyright (C) 2001 Grant Grundler (Hewlett Packard)
10  * Copyright (C) 2004 Kyle McMartin <kyle@debian.org>
11  *
12  * Initial Version 04-23-1999 by Helge Deller <deller@gmx.de>
13  */
14
15 #include <asm/asm-offsets.h>
16 #include <asm/psw.h>
17 #include <asm/pdc.h>
18         
19 #include <asm/assembly.h>
20 #include <asm/pgtable.h>
21
22 #include <linux/linkage.h>
23 #include <linux/init.h>
24
25         .level  1.1
26
27         __INITDATA
28 ENTRY(boot_args)
29         .word 0 /* arg0 */
30         .word 0 /* arg1 */
31         .word 0 /* arg2 */
32         .word 0 /* arg3 */
33 END(boot_args)
34
35         __HEAD
36
37         .align  4
38         .import init_thread_union,data
39         .import fault_vector_20,code    /* IVA parisc 2.0 32 bit */
40 #ifndef CONFIG_64BIT
41         .import fault_vector_11,code    /* IVA parisc 1.1 32 bit */
42         .import $global$                /* forward declaration */
43 #endif /*!CONFIG_64BIT*/
44 ENTRY(parisc_kernel_start)
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         load32          PA(__bss_start),%r3
60         load32          PA(__bss_stop),%r4
61 $bss_loop:
62         cmpb,<<,n       %r3,%r4,$bss_loop
63         stw,ma          %r0,4(%r3)
64
65         /* Save away the arguments the boot loader passed in (32 bit args) */
66         load32          PA(boot_args),%r1
67         stw,ma          %arg0,4(%r1)
68         stw,ma          %arg1,4(%r1)
69         stw,ma          %arg2,4(%r1)
70         stw,ma          %arg3,4(%r1)
71
72 #if !defined(CONFIG_64BIT) && defined(CONFIG_PA20)
73         /* This 32-bit kernel was compiled for PA2.0 CPUs. Check current CPU
74          * and halt kernel if we detect a PA1.x CPU. */
75         ldi             32,%r10
76         mtctl           %r10,%cr11
77         .level 2.0
78         mfctl,w         %cr11,%r10
79         .level 1.1
80         comib,<>,n      0,%r10,$cpu_ok
81
82         load32          PA(msg1),%arg0
83         ldi             msg1_end-msg1,%arg1
84 $iodc_panic:
85         copy            %arg0, %r10
86         copy            %arg1, %r11
87         load32          PA(init_stack),%sp
88 #define MEM_CONS 0x3A0
89         ldw             MEM_CONS+32(%r0),%arg0  // HPA
90         ldi             ENTRY_IO_COUT,%arg1
91         ldw             MEM_CONS+36(%r0),%arg2  // SPA
92         ldw             MEM_CONS+8(%r0),%arg3   // layers
93         load32          PA(__bss_start),%r1
94         stw             %r1,-52(%sp)            // arg4
95         stw             %r0,-56(%sp)            // arg5
96         stw             %r10,-60(%sp)           // arg6 = ptr to text
97         stw             %r11,-64(%sp)           // arg7 = len
98         stw             %r0,-68(%sp)            // arg8
99         load32          PA(.iodc_panic_ret), %rp
100         ldw             MEM_CONS+40(%r0),%r1    // ENTRY_IODC
101         bv,n            (%r1)
102 .iodc_panic_ret:
103         b .                             /* wait endless with ... */
104         or              %r10,%r10,%r10  /* qemu idle sleep */
105 msg1:   .ascii "Can't boot kernel which was built for PA8x00 CPUs on this machine.\r\n"
106 msg1_end:
107
108 $cpu_ok:
109 #endif
110
111         .level  PA_ASM_LEVEL
112
113         /* Initialize startup VM. Just map first 16/32 MB of memory */
114         load32          PA(swapper_pg_dir),%r4
115         mtctl           %r4,%cr24       /* Initialize kernel root pointer */
116         mtctl           %r4,%cr25       /* Initialize user root pointer */
117
118 #if CONFIG_PGTABLE_LEVELS == 3
119         /* Set pmd in pgd */
120         load32          PA(pmd0),%r5
121         shrd            %r5,PxD_VALUE_SHIFT,%r3 
122         ldo             (PxD_FLAG_PRESENT+PxD_FLAG_VALID)(%r3),%r3
123         stw             %r3,ASM_PGD_ENTRY*ASM_PGD_ENTRY_SIZE(%r4)
124         ldo             ASM_PMD_ENTRY*ASM_PMD_ENTRY_SIZE(%r5),%r4
125 #else
126         /* 2-level page table, so pmd == pgd */
127         ldo             ASM_PGD_ENTRY*ASM_PGD_ENTRY_SIZE(%r4),%r4
128 #endif
129
130         /* Fill in pmd with enough pte directories */
131         load32          PA(pg0),%r1
132         SHRREG          %r1,PxD_VALUE_SHIFT,%r3
133         ldo             (PxD_FLAG_PRESENT+PxD_FLAG_VALID)(%r3),%r3
134
135         ldi             ASM_PT_INITIAL,%r1
136
137 1:
138         stw             %r3,0(%r4)
139         ldo             (PAGE_SIZE >> PxD_VALUE_SHIFT)(%r3),%r3
140         addib,>         -1,%r1,1b
141 #if CONFIG_PGTABLE_LEVELS == 3
142         ldo             ASM_PMD_ENTRY_SIZE(%r4),%r4
143 #else
144         ldo             ASM_PGD_ENTRY_SIZE(%r4),%r4
145 #endif
146
147
148         /* Now initialize the PTEs themselves.  We use RWX for
149          * everything ... it will get remapped correctly later */
150         ldo             0+_PAGE_KERNEL_RWX(%r0),%r3 /* Hardwired 0 phys addr start */
151         load32          (1<<(KERNEL_INITIAL_ORDER-PAGE_SHIFT)),%r11 /* PFN count */
152         load32          PA(pg0),%r1
153
154 $pgt_fill_loop:
155         STREGM          %r3,ASM_PTE_ENTRY_SIZE(%r1)
156         ldo             (1<<PFN_PTE_SHIFT)(%r3),%r3 /* add one PFN */
157         addib,>         -1,%r11,$pgt_fill_loop
158         nop
159
160         /* Load the return address...er...crash 'n burn */
161         copy            %r0,%r2
162
163         /* And the RFI Target address too */
164         load32          start_parisc,%r11
165
166         /* And the initial task pointer */
167         load32          init_thread_union,%r6
168         mtctl           %r6,%cr30
169
170         /* And the stack pointer too */
171         ldo             THREAD_SZ_ALGN(%r6),%sp
172
173 #if defined(CONFIG_64BIT) && defined(CONFIG_FUNCTION_TRACER)
174         .import _mcount,data
175         /* initialize mcount FPTR */
176         /* Get the global data pointer */
177         loadgp
178         load32          PA(_mcount), %r10
179         std             %dp,0x18(%r10)
180 #endif
181
182 #ifdef CONFIG_SMP
183         /* Set the smp rendezvous address into page zero.
184         ** It would be safer to do this in init_smp_config() but
185         ** it's just way easier to deal with here because
186         ** of 64-bit function ptrs and the address is local to this file.
187         */
188         load32          PA(smp_slave_stext),%r10
189         stw             %r10,0x10(%r0)  /* MEM_RENDEZ */
190         stw             %r0,0x28(%r0)   /* MEM_RENDEZ_HI - assume addr < 4GB */
191
192         /* FALLTHROUGH */
193         .procend
194
195         /*
196         ** Code Common to both Monarch and Slave processors.
197         ** Entry:
198         **
199         **  1.1:        
200         **    %r11 must contain RFI target address.
201         **    %r25/%r26 args to pass to target function
202         **    %r2  in case rfi target decides it didn't like something
203         **
204         **  2.0w:
205         **    %r3  PDCE_PROC address
206         **    %r11 RFI target address
207         **
208         ** Caller must init: SR4-7, %sp, %r10, %cr24/25, 
209         */
210 common_stext:
211         .proc
212         .callinfo
213 #else
214         /* Clear PDC entry point - we won't use it */
215         stw             %r0,0x10(%r0)   /* MEM_RENDEZ */
216         stw             %r0,0x28(%r0)   /* MEM_RENDEZ_HI */
217 #endif /*CONFIG_SMP*/
218
219 #ifdef CONFIG_64BIT
220         tophys_r1       %sp
221
222         /* Save the rfi target address */
223         ldd             TI_TASK-THREAD_SZ_ALGN(%sp), %r10
224         tophys_r1       %r10
225         std             %r11,  TASK_PT_GR11(%r10)
226         /* Switch to wide mode Superdome doesn't support narrow PDC
227         ** calls.
228         */
229 1:      mfia            %rp             /* clear upper part of pcoq */
230         ldo             2f-1b(%rp),%rp
231         depdi           0,31,32,%rp
232         bv              (%rp)
233         ssm             PSW_SM_W,%r0
234
235         /* Set Wide mode as the "Default" (eg for traps)
236         ** First trap occurs *right* after (or part of) rfi for slave CPUs.
237         ** Someday, palo might not do this for the Monarch either.
238         */
239 2:
240 #define MEM_PDC_LO 0x388
241 #define MEM_PDC_HI 0x35C
242         ldw             MEM_PDC_LO(%r0),%r3
243         ldw             MEM_PDC_HI(%r0),%r6
244         depd            %r6, 31, 32, %r3        /* move to upper word */
245
246         mfctl           %cr30,%r6               /* PCX-W2 firmware bug */
247
248         ldo             PDC_PSW(%r0),%arg0              /* 21 */
249         ldo             PDC_PSW_SET_DEFAULTS(%r0),%arg1 /* 2 */
250         ldo             PDC_PSW_WIDE_BIT(%r0),%arg2     /* 2 */
251         load32          PA(stext_pdc_ret), %rp
252         bv              (%r3)
253         copy            %r0,%arg3
254
255 stext_pdc_ret:
256         mtctl           %r6,%cr30               /* restore task thread info */
257
258         /* restore rfi target address*/
259         ldd             TI_TASK-THREAD_SZ_ALGN(%sp), %r10
260         tophys_r1       %r10
261         ldd             TASK_PT_GR11(%r10), %r11
262         tovirt_r1       %sp
263 #endif
264         
265         /* PARANOID: clear user scratch/user space SR's */
266         mtsp    %r0,%sr0
267         mtsp    %r0,%sr1
268         mtsp    %r0,%sr2
269         mtsp    %r0,%sr3
270
271         /* Initialize Protection Registers */
272         mtctl   %r0,%cr8
273         mtctl   %r0,%cr9
274         mtctl   %r0,%cr12
275         mtctl   %r0,%cr13
276
277         /* Initialize the global data pointer */
278         loadgp
279
280         /* Set up our interrupt table.  HPMCs might not work after this! 
281          *
282          * We need to install the correct iva for PA1.1 or PA2.0. The
283          * following short sequence of instructions can determine this
284          * (without being illegal on a PA1.1 machine).
285          */
286 #ifndef CONFIG_64BIT
287         ldi             32,%r10
288         mtctl           %r10,%cr11
289         .level 2.0
290         mfctl,w         %cr11,%r10
291         .level 1.1
292         comib,<>,n      0,%r10,$is_pa20
293         ldil            L%PA(fault_vector_11),%r10
294         b               $install_iva
295         ldo             R%PA(fault_vector_11)(%r10),%r10
296
297 $is_pa20:
298         .level          PA_ASM_LEVEL /* restore 1.1 || 2.0w */
299 #endif /*!CONFIG_64BIT*/
300         load32          PA(fault_vector_20),%r10
301
302 $install_iva:
303         mtctl           %r10,%cr14
304
305         b               aligned_rfi  /* Prepare to RFI! Man all the cannons! */
306         nop
307
308         .align 128
309 aligned_rfi:
310         pcxt_ssm_bug
311
312         rsm             PSW_SM_QUIET,%r0        /* off troublesome PSW bits */
313         /* Don't need NOPs, have 8 compliant insn before rfi */
314
315         mtctl           %r0,%cr17       /* Clear IIASQ tail */
316         mtctl           %r0,%cr17       /* Clear IIASQ head */
317
318         /* Load RFI target into PC queue */
319         mtctl           %r11,%cr18      /* IIAOQ head */
320         ldo             4(%r11),%r11
321         mtctl           %r11,%cr18      /* IIAOQ tail */
322
323         load32          KERNEL_PSW,%r10
324         mtctl           %r10,%ipsw
325         
326         /* Jump through hyperspace to Virt Mode */
327         rfi
328         nop
329
330         .procend
331
332 #ifdef CONFIG_SMP
333
334         .import smp_init_current_idle_task,data
335         .import smp_callin,code
336
337 #ifndef CONFIG_64BIT
338 smp_callin_rtn:
339         .proc
340         .callinfo
341         break   1,1             /*  Break if returned from start_secondary */
342         nop
343         nop
344         .procend
345 #endif /*!CONFIG_64BIT*/
346
347 /***************************************************************************
348 * smp_slave_stext is executed by all non-monarch Processors when the Monarch
349 * pokes the slave CPUs in smp.c:smp_boot_cpus().
350 *
351 * Once here, registers values are initialized in order to branch to virtual
352 * mode. Once all available/eligible CPUs are in virtual mode, all are
353 * released and start out by executing their own idle task.
354 *****************************************************************************/
355 smp_slave_stext:
356         .proc
357         .callinfo
358
359         /*
360         ** Initialize Space registers
361         */
362         mtsp       %r0,%sr4
363         mtsp       %r0,%sr5
364         mtsp       %r0,%sr6
365         mtsp       %r0,%sr7
366
367         /*  Initialize the SP - monarch sets up smp_init_current_idle_task */
368         load32          PA(smp_init_current_idle_task),%sp
369         LDREG           0(%sp),%sp      /* load task address */
370         tophys_r1       %sp
371         LDREG           TASK_THREAD_INFO(%sp),%sp
372         mtctl           %sp,%cr30       /* store in cr30 */
373         ldo             THREAD_SZ_ALGN(%sp),%sp
374
375         /* point CPU to kernel page tables */
376         load32          PA(swapper_pg_dir),%r4
377         mtctl           %r4,%cr24       /* Initialize kernel root pointer */
378         mtctl           %r4,%cr25       /* Initialize user root pointer */
379
380 #ifdef CONFIG_64BIT
381         /* Setup PDCE_PROC entry */
382         copy            %arg0,%r3
383 #else
384         /* Load RFI *return* address in case smp_callin bails */
385         load32          smp_callin_rtn,%r2
386 #endif
387         
388         /* Load RFI target address.  */
389         load32          smp_callin,%r11
390         
391         /* ok...common code can handle the rest */
392         b               common_stext
393         nop
394
395         .procend
396 #endif /* CONFIG_SMP */
397
398 ENDPROC(parisc_kernel_start)
399
400 #ifndef CONFIG_64BIT
401         .section .data..read_mostly
402
403         .align  4
404         .export $global$,data
405
406         .type   $global$,@object
407         .size   $global$,4
408 $global$:       
409         .word 0
410 #endif /*!CONFIG_64BIT*/