xref: /freebsd/sys/powerpc/aim/locore32.S (revision d356ca0c3ffa363d5bfbc237b44f53b3f88fd415)
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.s"
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-32)
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
90	lwz	%r3,0(%r30) /* _DYNAMIC in %r3 */
91	add	%r3,%r3,%r30
92	lwz	%r4,4(%r30) /* GOT pointer */
93	add	%r4,%r4,%r30
94	lwz	%r4,4(%r4)  /* got[0] is _DYNAMIC link addr */
95	subf	%r4,%r4,%r3 /* subtract to calculate relocbase */
96	bl	elf_reloc_self
97
98	lwz	%r3,16(%r1)
99	lwz	%r4,20(%r1)
100	lwz	%r5,24(%r1)
101	lwz	%r6,28(%r1)
102
103	/* MD setup */
104	bl	powerpc_init
105
106	/* Set stack pointer to new value and branch to mi_startup */
107	mr	%r1, %r3
108	li	%r3, 0
109	stw	%r3, 0(%r1)
110	bl	mi_startup
111
112	/* mi_startup() does not return */
113	b	.
114
115#include <powerpc/aim/trap_subr32.S>
116