xref: /freebsd/sys/powerpc/aim/locore32.S (revision 88640c0e8b6f503426cce9ea1337098c241d3801)
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 <machine/vmparam.h>
37#include "opt_platform.h"
38
39/* Locate the per-CPU data structure */
40#define GET_CPUINFO(r)  \
41        mfsprg0  r
42
43/*
44 * Compiled KERNBASE location and the kernel load address
45 */
46        .globl  kernbase
47        .set    kernbase, KERNBASE
48
49/*
50 * Globals
51 */
52	.data
53	.align 3
54GLOBAL(__startkernel)
55	.long	begin
56GLOBAL(__endkernel)
57	.long	end
58	.align	4
59#define	TMPSTKSZ	8192		/* 8K temporary stack */
60GLOBAL(tmpstk)
61	.space	TMPSTKSZ
62
63	.text
64	.globl	btext
65btext:
66
67/*
68 * Main kernel entry point.
69 */
70	.text
71	.globl	__start
72__start:
73	/* Figure out where we are */
74	bl	1f
75	.long	_DYNAMIC-.
76	.long	_GLOBAL_OFFSET_TABLE_-.
77	.long	tmpstk-.
781:	mflr	%r30
79
80	/* Set up temporary stack pointer */
81	lwz	%r1,8(%r30)
82	add	%r1,%r1,%r30
83	addi	%r1,%r1,(8+TMPSTKSZ-40)
84
85	/* Relocate self */
86	stw	%r3,16(%r1)
87	stw	%r4,20(%r1)
88	stw	%r5,24(%r1)
89	stw	%r6,28(%r1)
90	stw	%r7,32(%r1)
91
92	lwz	%r3,0(%r30) /* _DYNAMIC in %r3 */
93	add	%r3,%r3,%r30
94	lwz	%r4,4(%r30) /* GOT pointer */
95	add	%r4,%r4,%r30
96	lwz	%r4,4(%r4)  /* got[0] is _DYNAMIC link addr */
97	subf	%r4,%r4,%r3 /* subtract to calculate relocbase */
98	bl	elf_reloc_self
99
100	lwz	%r3,16(%r1)
101	lwz	%r4,20(%r1)
102	lwz	%r5,24(%r1)
103	lwz	%r6,28(%r1)
104	lwz	%r7,32(%r1)
105
106	/* MD setup */
107	bl	powerpc_init
108
109	/* Set stack pointer to new value and branch to mi_startup */
110	mr	%r1, %r3
111	li	%r3, 0
112	stw	%r3, 0(%r1)
113	bl	mi_startup
114
115	/* mi_startup() does not return */
116	b	.
117
118#include <powerpc/aim/trap_subr32.S>
119