1203697Sneel/*-
2203697Sneel * Copyright (c) 2010 Neelkanth Natu
3203697Sneel * All rights reserved.
4203697Sneel *
5203697Sneel * Redistribution and use in source and binary forms, with or without
6203697Sneel * modification, are permitted provided that the following conditions
7203697Sneel * are met:
8203697Sneel * 1. Redistributions of source code must retain the above copyright
9203697Sneel *    notice, this list of conditions and the following disclaimer.
10203697Sneel * 2. Redistributions in binary form must reproduce the above copyright
11203697Sneel *    notice, this list of conditions and the following disclaimer in the
12203697Sneel *    documentation and/or other materials provided with the distribution.
13203697Sneel *
14203697Sneel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15203697Sneel * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16203697Sneel * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17203697Sneel * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18203697Sneel * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19203697Sneel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20203697Sneel * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21203697Sneel * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22203697Sneel * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23203697Sneel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24203697Sneel * SUCH DAMAGE.
25203697Sneel *
26203697Sneel * $FreeBSD$
27203697Sneel */
28203697Sneel
29203697Sneel#include <machine/asm.h>
30203697Sneel#include <machine/cpu.h>
31203697Sneel#include <machine/cpuregs.h>
32203697Sneel
33203697Sneel#include "assym.s"
34203697Sneel
35203697Sneel	.text
36203697Sneel	.set	noat
37203697Sneel	.set	noreorder
38203697Sneel
39211218Sjchandra/* XXX move this to a header file */
40211218Sjchandra#if defined(CPU_CNMIPS)
41206721Sjmallett#define CLEAR_STATUS \
42210038Simp	mfc0    a0, MIPS_COP_0_STATUS   ;\
43206721Sjmallett	li      a2, (MIPS_SR_KX | MIPS_SR_SX | MIPS_SR_UX) ; \
44206721Sjmallett	or      a0, a0, a2	        ; \
45232630Sjmallett	li      a2, ~(MIPS_SR_INT_IE | MIPS_SR_EXL | MIPS_SR_KSU_USER | MIPS_SR_BEV) ; \
46206721Sjmallett	and     a0, a0, a2              ; \
47210038Simp        mtc0    a0, MIPS_COP_0_STATUS
48211218Sjchandra#elif defined(__mips_n64)
49211218Sjchandra#define CLEAR_STATUS \
50211218Sjchandra	li	a0, (MIPS_SR_KX | MIPS_SR_UX) ; \
51211218Sjchandra	mtc0	a0, MIPS_COP_0_STATUS
52206721Sjmallett#else
53206721Sjmallett#define CLEAR_STATUS \
54210038Simp	mtc0	zero, MIPS_COP_0_STATUS
55206721Sjmallett#endif
56206721Sjmallett
57203697SneelGLOBAL(mpentry)
58206721Sjmallett	CLEAR_STATUS			/* disable interrupts */
59203697Sneel
60210038Simp	mtc0	zero, MIPS_COP_0_CAUSE	/* clear soft interrupts */
61203697Sneel
62210986Sneel	li	t0, MIPS_CCA_CACHED	/* make sure kseg0 is cached */
63203697Sneel	mtc0	t0, MIPS_COP_0_CONFIG
64203697Sneel	COP0_SYNC
65203697Sneel
66203697Sneel	jal	platform_processor_id	/* get the processor number */
67203697Sneel	nop
68203697Sneel	move	s0, v0
69203697Sneel
70203697Sneel	/*
71203697Sneel	 * Initialize stack and call machine startup
72203697Sneel	 */
73203697Sneel	PTR_LA	sp, _C_LABEL(pcpu_space)
74206746Sjmallett	addiu	sp, (PAGE_SIZE * 2) - CALLFRAME_SIZ
75203697Sneel	sll	t0, s0, PAGE_SHIFT + 1
76203697Sneel	addu	sp, sp, t0
77203697Sneel
78203697Sneel	/* Zero out old ra and old fp for debugger */
79204617Simp	sw      zero, CALLFRAME_SIZ - 4(sp)
80204617Simp	sw      zero, CALLFRAME_SIZ - 8(sp)
81203697Sneel
82203697Sneel	PTR_LA	gp, _C_LABEL(_gp)
83203697Sneel
84203697Sneel	jal	platform_init_ap
85203697Sneel	move	a0, s0
86203697Sneel	jal	smp_init_secondary
87203697Sneel	move	a0, s0
88203697Sneel
89203697Sneel	PANIC("AP startup failed!")
90