xref: /freebsd/sys/powerpc/aim/locore64.S (revision 1f4bcc459a76b7aa664f3fd557684cd0ba6da352)
1/* $FreeBSD$ */
2
3/*-
4 * Copyright (C) 2010-2016 Nathan Whitehorn
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 * $FreeBSD$
28 */
29
30#include "assym.s"
31
32#include <sys/syscall.h>
33
34#include <machine/trap.h>
35#include <machine/param.h>
36#include <machine/spr.h>
37#include <machine/asm.h>
38
39#ifdef _CALL_ELF
40.abiversion _CALL_ELF
41#endif
42
43/* Glue for linker script */
44.globl  kernbase
45.set    kernbase, KERNBASE
46
47/*
48 * Globals
49 */
50	.data
51	.align 3
52GLOBAL(__startkernel)
53	.llong	begin
54GLOBAL(__endkernel)
55	.llong	end
56
57	.align	4
58#define	TMPSTKSZ	16384		/* 16K temporary stack */
59GLOBAL(tmpstk)
60	.space	TMPSTKSZ
61
62TOC_ENTRY(tmpstk)
63
64	.text
65	.globl	btext
66btext:
67
68/*
69 * Main kernel entry point.
70 *
71 * Calling convention:
72 * r3: Flattened Device Tree pointer (or zero)
73 * r4: ignored
74 * r5: OF client interface pointer (or zero)
75 * r6: Loader metadata pointer (or zero)
76 */
77	.text
78ASENTRY_NOPROF(__start)
79	/* Set up the TOC pointer */
80	b	0f
81	.align 3
820:	nop
83	bl	1f
84	.llong	__tocbase + 0x8000 - .
851:	mflr	%r2
86	ld	%r1,0(%r2)
87	add	%r2,%r1,%r2
88
89	/* Get load offset */
90	ld	%r31,-0x8000(%r2) /* First TOC entry is TOC base */
91	subf    %r31,%r31,%r2	/* Subtract from real TOC base to get base */
92
93	/* Set up the stack pointer */
94	ld	%r1,TOC_REF(tmpstk)(%r2)
95	addi	%r1,%r1,TMPSTKSZ-96
96	add	%r1,%r1,%r31
97
98	/* Relocate kernel */
99	std	%r3,48(%r1)
100	std	%r4,56(%r1)
101	std	%r5,64(%r1)
102	std	%r6,72(%r1)
103	bl	1f
104	.llong _DYNAMIC-.
1051:	mflr	%r3
106	ld	%r4,0(%r3)
107	add	%r3,%r4,%r3
108	mr	%r4,%r31
109	bl	elf_reloc_self
110	nop
111	ld	%r3,48(%r1)
112	ld	%r4,56(%r1)
113	ld	%r5,64(%r1)
114	ld	%r6,72(%r1)
115
116	/* Begin CPU init */
117	mr	%r4,%r2 /* Replace ignored r4 with tocbase for trap handlers */
118	bl	powerpc_init
119	nop
120
121	/* Set stack pointer to new value and branch to mi_startup */
122	mr	%r1, %r3
123	li	%r3, 0
124	std	%r3, 0(%r1)
125	bl	mi_startup
126	nop
127
128	/* Unreachable */
129	b	.
130
131#include <powerpc/aim/trap_subr64.S>
132