xref: /freebsd/stand/uboot/arch/powerpc/start.S (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1/*-
2 * Copyright (c) 2007 Semihalf, Rafal Jaworowski <raj@semihalf.com>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <machine/asm.h>
28
29/*
30 * Entry point to the loader that U-Boot passes control to.
31 */
32	.text
33	.globl	_start
34_start:
35	/* Hint where to look for the API signature */
36	lis	%r11, uboot_address@ha
37	addi	%r11, %r11, uboot_address@l
38	stw	%r1, 0(%r11)
39	/* Save U-Boot's r14 and r30 */
40	lis	%r11, saved_regs@ha
41	addi	%r11, %r11, saved_regs@l
42	stw	%r14, 0(%r11)
43	stw	%r30, 4(%r11)
44	/* Disable interrupts */
45	mfmsr	%r11
46	andi.	%r11, %r11, ~0x8000@l
47	mtmsr	%r11
48	b	main
49
50/*
51 * syscall()
52 */
53ENTRY(syscall)
54	stwu	%r1, -32(%r1)
55	mflr	%r0
56	stw	%r14, 8(%r1)
57	stw	%r30, 12(%r1)
58	stw	%r0, 36(%r1)
59	/* Restore U-Boot's r14 and r30 */
60	lis	%r11, saved_regs@ha
61	addi	%r11, %r11, saved_regs@l
62	lwz	%r14, 0(%r11)
63	lwz	%r30, 4(%r11)
64	/* Enable interrupts */
65	mfmsr	%r11
66	ori	%r11, %r11, 0x8000@l
67	mtmsr	%r11
68	/* Call into U-Boot */
69	lis	%r11, syscall_ptr@ha
70	addi	%r11, %r11, syscall_ptr@l
71	lwz	%r11, 0(%r11)
72	mtctr	%r11
73	bctrl
74	/* Disable interrupts */
75	mfmsr	%r11
76	andi.	%r11, %r11, ~0x8000@l
77	mtmsr	%r11
78	/* Epilogue */
79	lwz	%r11, 0(%r1)
80	lwz	%r0, 4(%r11)
81	mtlr	%r0
82	lwz	%r14, 8(%r1)
83	lwz	%r30, 12(%r1)
84	mr	%r1, %r11
85	blr
86END(syscall)
87
88/*
89 * Data section
90 */
91	.data
92GLOBAL(syscall_ptr)
93	.long	0
94GLOBAL(saved_regs)
95	.long	0	/* R14 */
96	.long	0	/* R30 */
97GLOBAL(uboot_address)
98	.long	0
99