xref: /freebsd/sys/powerpc/aim/locore32.S (revision d37eb51047221dc3322b34db1038ff3aa533883f)
1
2/*-
3 * Copyright (C) 2010-2016 Nathan Whitehorn
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include "assym.inc"
28
29#include <sys/syscall.h>
30
31#include <machine/trap.h>
32#include <machine/param.h>
33#include <machine/spr.h>
34#include <machine/asm.h>
35#include <machine/vmparam.h>
36#include "opt_platform.h"
37
38/* Locate the per-CPU data structure */
39#define GET_CPUINFO(r)  \
40        mfsprg0  r
41
42/*
43 * Compiled KERNBASE location and the kernel load address
44 */
45        .globl  kernbase
46        .set    kernbase, KERNBASE
47
48/*
49 * Globals
50 */
51	.data
52	.align 3
53GLOBAL(__startkernel)
54	.long	begin
55GLOBAL(__endkernel)
56	.long	end
57	.align	4
58#define	TMPSTKSZ	8192		/* 8K temporary stack */
59GLOBAL(tmpstk)
60	.space	TMPSTKSZ
61
62#ifdef KDB
63#define TRAPSTKSZ       4096            /* 4k trap stack */
64GLOBAL(trapstk)
65        .space        TRAPSTKSZ
66#endif
67
68	.text
69	.globl	btext
70btext:
71
72/*
73 * Main kernel entry point.
74 */
75	.text
76	.globl	__start
77__start:
78	/* Figure out where we are */
79	bl	1f
80	.long	_DYNAMIC-.
81	.long	_GLOBAL_OFFSET_TABLE_-.
82	.long	tmpstk-.
831:	mflr	%r30
84
85	/* Set up temporary stack pointer */
86	lwz	%r1,8(%r30)
87	add	%r1,%r1,%r30
88	addi	%r1,%r1,(8+TMPSTKSZ-40)
89
90	/* Relocate self */
91	stw	%r3,16(%r1)
92	stw	%r4,20(%r1)
93	stw	%r5,24(%r1)
94	stw	%r6,28(%r1)
95	stw	%r7,32(%r1)
96
97	lwz	%r3,0(%r30) /* _DYNAMIC in %r3 */
98	add	%r3,%r3,%r30
99	lwz	%r4,4(%r30) /* GOT pointer */
100	add	%r4,%r4,%r30
101	lwz	%r4,4(%r4)  /* got[0] is _DYNAMIC link addr */
102	subf	%r4,%r4,%r3 /* subtract to calculate relocbase */
103	bl	elf_reloc_self
104
105	lwz	%r3,16(%r1)
106	lwz	%r4,20(%r1)
107	lwz	%r5,24(%r1)
108	lwz	%r6,28(%r1)
109	lwz	%r7,32(%r1)
110
111	/* MD setup */
112	bl	powerpc_init
113
114	/* Set stack pointer to new value and branch to mi_startup */
115	mr	%r1, %r3
116	li	%r3, 0
117	stw	%r3, 0(%r1)
118	bl	mi_startup
119
120	/* mi_startup() does not return */
121	b	.
122
123#include <powerpc/aim/trap_subr32.S>
124