1174294Sobrien/*-
238494Sobrien * Copyright (c) 2007 Semihalf, Rafal Jaworowski <raj@semihalf.com>
338494Sobrien * All rights reserved.
438494Sobrien *
538494Sobrien * Redistribution and use in source and binary forms, with or without
638494Sobrien * modification, are permitted provided that the following conditions
738494Sobrien * are met:
838494Sobrien * 1. Redistributions of source code must retain the above copyright
938494Sobrien *    notice, this list of conditions and the following disclaimer.
1038494Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1138494Sobrien *    notice, this list of conditions and the following disclaimer in the
1238494Sobrien *    documentation and/or other materials provided with the distribution.
1338494Sobrien *
1438494Sobrien * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1538494Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1638494Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1738494Sobrien * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1838494Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1938494Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2038494Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2138494Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2238494Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2338494Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2438494Sobrien * SUCH DAMAGE.
2538494Sobrien *
2638494Sobrien * $FreeBSD: stable/11/stand/powerpc/uboot/start.S 182726 2008-09-03 16:38:27Z raj $
2738494Sobrien */
2838494Sobrien
2938494Sobrien#include <machine/asm.h>
3038494Sobrien
3138494Sobrien/*
3238494Sobrien * Entry point to the loader that U-Boot passes control to.
3338494Sobrien */
3438494Sobrien	.text
3538494Sobrien	.globl	_start
3638494Sobrien_start:
3738494Sobrien	/* 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 */
42	lis	%r11, saved_regs@ha
43	addi	%r11, %r11, saved_regs@l
44	stw	%r14, 0(%r11)
45	/* Disable interrupts */
46	mfmsr	%r11
47	andi.	%r11, %r11, ~0x8000@l
48	mtmsr	%r11
49	b	main
50
51/*
52 * syscall()
53 */
54ENTRY(syscall)
55	stwu	%r1, -16(%r1)
56	mflr	%r0
57	stw	%r14, 8(%r1)
58	stw	%r0, 20(%r1)
59	/* Restore U-Boot's r14 */
60	lis	%r11, saved_regs@ha
61	addi	%r11, %r11, saved_regs@l
62	lwz	%r14, 0(%r11)
63	/* Enable interrupts */
64	mfmsr	%r11
65	ori	%r11, %r11, 0x8000@l
66	mtmsr	%r11
67	/* Call into U-Boot */
68	lis	%r11, syscall_ptr@ha
69	addi	%r11, %r11, syscall_ptr@l
70	lwz	%r11, 0(%r11)
71	mtctr	%r11
72	bctrl
73	/* Disable interrupts */
74	mfmsr	%r11
75	andi.	%r11, %r11, ~0x8000@l
76	mtmsr	%r11
77	/* Epilogue */
78	lwz	%r11, 0(%r1)
79	lwz	%r0, 4(%r11)
80	mtlr	%r0
81	lwz	%r14, 8(%r1)
82	mr	%r1, %r11
83	blr
84
85/*
86 * Data section
87 */
88	.data
89GLOBAL(syscall_ptr)
90	.long	0
91GLOBAL(saved_regs)
92	.long	0	/* R14 */
93GLOBAL(uboot_address)
94	.long	0
95