Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * This file is subject to the terms and conditions of the GNU General Public
0003  * License.  See the file "COPYING" in the main directory of this archive
0004  * for more details.
0005  *
0006  * Copyright (C) 1994, 1995 Waldorf Electronics
0007  * Written by Ralf Baechle and Andreas Busse
0008  * Copyright (C) 1994 - 99, 2003, 06 Ralf Baechle
0009  * Copyright (C) 1996 Paul M. Antoine
0010  * Modified for DECStation and hence R3000 support by Paul M. Antoine
0011  * Further modifications by David S. Miller and Harald Koerfgen
0012  * Copyright (C) 1999 Silicon Graphics, Inc.
0013  * Kevin Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
0014  * Copyright (C) 2000 MIPS Technologies, Inc.  All rights reserved.
0015  */
0016 #include <linux/init.h>
0017 #include <linux/threads.h>
0018 
0019 #include <asm/addrspace.h>
0020 #include <asm/asm.h>
0021 #include <asm/asmmacro.h>
0022 #include <asm/irqflags.h>
0023 #include <asm/regdef.h>
0024 #include <asm/mipsregs.h>
0025 #include <asm/stackframe.h>
0026 
0027 #include <kernel-entry-init.h>
0028 
0029     /*
0030      * For the moment disable interrupts, mark the kernel mode and
0031      * set ST0_KX so that the CPU does not spit fire when using
0032      * 64-bit addresses.  A full initialization of the CPU's status
0033      * register is done later in per_cpu_trap_init().
0034      */
0035     .macro  setup_c0_status set clr
0036     .set    push
0037     mfc0    t0, CP0_STATUS
0038     or  t0, ST0_KERNEL_CUMASK|\set|0x1f|\clr
0039     xor t0, 0x1f|\clr
0040     mtc0    t0, CP0_STATUS
0041     .set    noreorder
0042     sll zero,3              # ehb
0043     .set    pop
0044     .endm
0045 
0046     .macro  setup_c0_status_pri
0047 #ifdef CONFIG_64BIT
0048     setup_c0_status ST0_KX 0
0049 #else
0050     setup_c0_status 0 0
0051 #endif
0052     .endm
0053 
0054     .macro  setup_c0_status_sec
0055 #ifdef CONFIG_64BIT
0056     setup_c0_status ST0_KX ST0_BEV
0057 #else
0058     setup_c0_status 0 ST0_BEV
0059 #endif
0060     .endm
0061 
0062 #ifndef CONFIG_NO_EXCEPT_FILL
0063     /*
0064      * Reserved space for exception handlers.
0065      * Necessary for machines which link their kernels at KSEG0.
0066      */
0067     .fill   0x400
0068 #endif
0069 
0070 EXPORT(_stext)
0071 
0072 #ifdef CONFIG_BOOT_RAW
0073     /*
0074      * Give us a fighting chance of running if execution beings at the
0075      * kernel load address.  This is needed because this platform does
0076      * not have a ELF loader yet.
0077      */
0078 FEXPORT(__kernel_entry)
0079     j   kernel_entry
0080 #endif /* CONFIG_BOOT_RAW */
0081 
0082     __REF
0083 
0084 NESTED(kernel_entry, 16, sp)            # kernel entry point
0085 
0086     kernel_entry_setup          # cpu specific setup
0087 
0088     setup_c0_status_pri
0089 
0090     /* We might not get launched at the address the kernel is linked to,
0091        so we jump there.  */
0092     PTR_LA  t0, 0f
0093     jr  t0
0094 0:
0095 
0096     PTR_LA      t0, __bss_start     # clear .bss
0097     LONG_S      zero, (t0)
0098     PTR_LA      t1, __bss_stop - LONGSIZE
0099 1:
0100     PTR_ADDIU   t0, LONGSIZE
0101     LONG_S      zero, (t0)
0102     bne     t0, t1, 1b
0103 
0104     LONG_S      a0, fw_arg0     # firmware arguments
0105     LONG_S      a1, fw_arg1
0106     LONG_S      a2, fw_arg2
0107     LONG_S      a3, fw_arg3
0108 
0109     MTC0        zero, CP0_CONTEXT   # clear context register
0110 #ifdef CONFIG_64BIT
0111     MTC0        zero, CP0_XCONTEXT
0112 #endif
0113     PTR_LA      $28, init_thread_union
0114     /* Set the SP after an empty pt_regs.  */
0115     PTR_LI      sp, _THREAD_SIZE - 32 - PT_SIZE
0116     PTR_ADDU    sp, $28
0117     back_to_back_c0_hazard
0118     set_saved_sp    sp, t0, t1
0119     PTR_SUBU    sp, 4 * SZREG       # init stack pointer
0120 
0121 #ifdef CONFIG_RELOCATABLE
0122     /* Copy kernel and apply the relocations */
0123     jal     relocate_kernel
0124 
0125     /* Repoint the sp into the new kernel image */
0126     PTR_LI      sp, _THREAD_SIZE - 32 - PT_SIZE
0127     PTR_ADDU    sp, $28
0128     set_saved_sp    sp, t0, t1
0129     PTR_SUBU    sp, 4 * SZREG       # init stack pointer
0130 
0131     /*
0132      * relocate_kernel returns the entry point either
0133      * in the relocated kernel or the original if for
0134      * some reason relocation failed - jump there now
0135      * with instruction hazard barrier because of the
0136      * newly sync'd icache.
0137      */
0138     jr.hb       v0
0139 #else  /* !CONFIG_RELOCATABLE */
0140     j       start_kernel
0141 #endif /* !CONFIG_RELOCATABLE */
0142     END(kernel_entry)
0143 
0144 #ifdef CONFIG_SMP
0145 /*
0146  * SMP slave cpus entry point.  Board specific code for bootstrap calls this
0147  * function after setting up the stack and gp registers.
0148  */
0149 NESTED(smp_bootstrap, 16, sp)
0150     smp_slave_setup
0151     setup_c0_status_sec
0152     j   start_secondary
0153     END(smp_bootstrap)
0154 #endif /* CONFIG_SMP */