xref: /freebsd/stand/uboot/arch/powerpc/start.S (revision 9f44a47fd07924afc035991af15d84e6585dea4f)
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 * $FreeBSD$
27 */
28
29#include <machine/asm.h>
30
31/*
32 * Entry point to the loader that U-Boot passes control to.
33 */
34	.text
35	.globl	_start
36_start:
37	/* Hint where to look for the API signature */
38	lis	%r11, uboot_address@ha
39	addi	%r11, %r11, uboot_address@l
40	stw	%r1, 0(%r11)
41	/* Save U-Boot's r14 and r30 */
42	lis	%r11, saved_regs@ha
43	addi	%r11, %r11, saved_regs@l
44	stw	%r14, 0(%r11)
45	stw	%r30, 4(%r11)
46	/* Disable interrupts */
47	mfmsr	%r11
48	andi.	%r11, %r11, ~0x8000@l
49	mtmsr	%r11
50	b	main
51
52/*
53 * syscall()
54 */
55ENTRY(syscall)
56	stwu	%r1, -32(%r1)
57	mflr	%r0
58	stw	%r14, 8(%r1)
59	stw	%r30, 12(%r1)
60	stw	%r0, 36(%r1)
61	/* Restore U-Boot's r14 and r30 */
62	lis	%r11, saved_regs@ha
63	addi	%r11, %r11, saved_regs@l
64	lwz	%r14, 0(%r11)
65	lwz	%r30, 4(%r11)
66	/* Enable interrupts */
67	mfmsr	%r11
68	ori	%r11, %r11, 0x8000@l
69	mtmsr	%r11
70	/* Call into U-Boot */
71	lis	%r11, syscall_ptr@ha
72	addi	%r11, %r11, syscall_ptr@l
73	lwz	%r11, 0(%r11)
74	mtctr	%r11
75	bctrl
76	/* Disable interrupts */
77	mfmsr	%r11
78	andi.	%r11, %r11, ~0x8000@l
79	mtmsr	%r11
80	/* Epilogue */
81	lwz	%r11, 0(%r1)
82	lwz	%r0, 4(%r11)
83	mtlr	%r0
84	lwz	%r14, 8(%r1)
85	lwz	%r30, 12(%r1)
86	mr	%r1, %r11
87	blr
88END(syscall)
89
90/*
91 * Data section
92 */
93	.data
94GLOBAL(syscall_ptr)
95	.long	0
96GLOBAL(saved_regs)
97	.long	0	/* R14 */
98	.long	0	/* R30 */
99GLOBAL(uboot_address)
100	.long	0
101