xref: /freebsd/sys/powerpc/aim/locore32.S (revision f39bffc62c1395bde25d152c7f68fdf7cbaab414)
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
28#include "assym.inc"
29
30#include <sys/syscall.h>
31
32#include <machine/trap.h>
33#include <machine/param.h>
34#include <machine/spr.h>
35#include <machine/asm.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	.text
63	.globl	btext
64btext:
65
66/*
67 * Main kernel entry point.
68 */
69	.text
70	.globl	__start
71__start:
72	/* Figure out where we are */
73	bl	1f
74	.long	_DYNAMIC-.
75	.long	_GLOBAL_OFFSET_TABLE_-.
76	.long	tmpstk-.
771:	mflr	%r30
78
79	/* Set up temporary stack pointer */
80	lwz	%r1,8(%r30)
81	add	%r1,%r1,%r30
82	addi	%r1,%r1,(8+TMPSTKSZ-40)
83
84	/* Relocate self */
85	stw	%r3,16(%r1)
86	stw	%r4,20(%r1)
87	stw	%r5,24(%r1)
88	stw	%r6,28(%r1)
89	stw	%r7,32(%r1)
90
91	lwz	%r3,0(%r30) /* _DYNAMIC in %r3 */
92	add	%r3,%r3,%r30
93	lwz	%r4,4(%r30) /* GOT pointer */
94	add	%r4,%r4,%r30
95	lwz	%r4,4(%r4)  /* got[0] is _DYNAMIC link addr */
96	subf	%r4,%r4,%r3 /* subtract to calculate relocbase */
97	bl	elf_reloc_self
98
99	lwz	%r3,16(%r1)
100	lwz	%r4,20(%r1)
101	lwz	%r5,24(%r1)
102	lwz	%r6,28(%r1)
103	lwz	%r7,32(%r1)
104
105	/* MD setup */
106	bl	powerpc_init
107
108	/* Set stack pointer to new value and branch to mi_startup */
109	mr	%r1, %r3
110	li	%r3, 0
111	stw	%r3, 0(%r1)
112	bl	mi_startup
113
114	/* mi_startup() does not return */
115	b	.
116
117#include <powerpc/aim/trap_subr32.S>
118