start.S revision 183878
1183878Sraj/*-
2183878Sraj * Copyright (c) 2008 Semihalf, Rafal Czubak
3183878Sraj * All rights reserved.
4183878Sraj *
5183878Sraj * Redistribution and use in source and binary forms, with or without
6183878Sraj * modification, are permitted provided that the following conditions
7183878Sraj * are met:
8183878Sraj * 1. Redistributions of source code must retain the above copyright
9183878Sraj *    notice, this list of conditions and the following disclaimer.
10183878Sraj * 2. Redistributions in binary form must reproduce the above copyright
11183878Sraj *    notice, this list of conditions and the following disclaimer in the
12183878Sraj *    documentation and/or other materials provided with the distribution.
13183878Sraj *
14183878Sraj * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15183878Sraj * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16183878Sraj * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17183878Sraj * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18183878Sraj * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19183878Sraj * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20183878Sraj * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21183878Sraj * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22183878Sraj * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23183878Sraj * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24183878Sraj * SUCH DAMAGE.
25183878Sraj *
26183878Sraj * $FreeBSD: head/sys/boot/arm/uboot/start.S 183878 2008-10-14 10:11:14Z raj $
27183878Sraj */
28183878Sraj
29183878Sraj#include <machine/asm.h>
30183878Sraj
31183878Sraj/*
32183878Sraj * Entry point to the loader that U-Boot passes control to.
33183878Sraj */
34183878Sraj	.text
35183878Sraj	.globl	_start
36183878Sraj_start:
37183878Sraj	/* Hint where to look for the API signature */
38183878Sraj	ldr	ip, =uboot_address
39183878Sraj	str	sp, [ip]
40183878Sraj
41183878Sraj	/* Save U-Boot's r8 */
42183878Sraj	ldr	ip, =saved_regs
43183878Sraj	str	r8, [ip, #0]
44183878Sraj
45183878Sraj	/* Start loader */
46183878Sraj	b	main
47183878Sraj
48183878Sraj/*
49183878Sraj * syscall()
50183878Sraj */
51183878SrajENTRY(syscall)
52183878Sraj	/* Save caller's lr */
53183878Sraj	ldr	ip, =saved_regs
54183878Sraj	str	lr, [ip, #4]
55183878Sraj	/* Save loader's r8 */
56183878Sraj	ldr	ip, =saved_regs
57183878Sraj	str	r8, [ip, #8]
58183878Sraj
59183878Sraj	/* Restore U-Boot's r8 */
60183878Sraj	ldr	ip, =saved_regs
61183878Sraj	ldr	r8, [ip, #0]
62183878Sraj	/* Call into U-Boot */
63183878Sraj	ldr	lr, =return_from_syscall
64183878Sraj	ldr	ip, =syscall_ptr
65183878Sraj	ldr	pc, [ip]
66183878Sraj
67183878Srajreturn_from_syscall:
68183878Sraj	/* Restore loader's r8 */
69183878Sraj	ldr	ip, =saved_regs
70183878Sraj	ldr	r8, [ip, #8]
71183878Sraj	/* Restore caller's lr */
72183878Sraj	ldr	ip, =saved_regs
73183878Sraj	ldr	lr, [ip, #4]
74183878Sraj	/* Return to caller */
75183878Sraj	mov	pc, lr
76183878Sraj
77183878Sraj/*
78183878Sraj * Data section
79183878Sraj */
80183878Sraj	.data
81183878Sraj	.align	4
82183878Sraj	.globl	syscall_ptr
83183878Srajsyscall_ptr:
84183878Sraj	.long	0
85183878Sraj
86183878Sraj	.globl	uboot_address
87183878Srajuboot_address:
88183878Sraj	.long	0
89183878Sraj
90183878Srajsaved_regs:
91183878Sraj	.long	0	/* U-Boot's r8 */
92183878Sraj	.long	0	/* Loader's r8 */
93183878Sraj	.long	0	/* Loader's lr */
94