Deleted Added
sdiff udiff text old ( 266885 ) new ( 266893 )
full compact
1/*-
2 * Copyright (c) 2013-2014 Robert N. M. Watson
3 * All rights reserved.
4 *
5 * This software was developed by SRI International and the University of
6 * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
7 * ("CTSRD"), as part of the DARPA CRASH research programme.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: head/sys/boot/mips/beri/loader/main.c 266885 2014-05-30 13:53:37Z hselasky $");
33
34#include <sys/param.h>
35#include <sys/linker.h>
36#include <sys/reboot.h>
37
38#include <machine/bootinfo.h>
39#include <machine/elf.h>
40
41#include <stand.h>
42#include <bootstrap.h>
43#include <loader.h>
44#include <mips.h>
45
46static int __elfN(exec)(struct preloaded_file *);
47static void extract_currdev(struct bootinfo *);
48
49struct devsw *devsw[] = {
50 &beri_cfi_disk,
51 &beri_sdcard_disk,
52 NULL
53};
54
55struct arch_switch archsw;
56
57struct file_format *file_formats[] = {
58 &beri_elf,
59 NULL
60};
61
62struct fs_ops *file_system[] = {
63#ifdef LOADER_UFS_SUPPORT
64 &ufs_fsops,
65#endif
66 NULL
67};
68
69struct console *consoles[] = {
70 &altera_jtag_uart_console,
71 NULL
72};
73
74extern void __bss_start, __bss_end;
75extern void __heap_start, __heap_end;
76
77static int
78__elfN(exec)(struct preloaded_file *fp)
79{
80
81 return (EFTYPE);
82}
83
84/*
85 * Capture arguments from boot2 for later reuse when launching the kernel.
86 * Note that we choose not to maintain a pointer to boo2_bootinfop after
87 * initial argument processing: this is because we might load the kernel over
88 * the spot where boot2 was running, so we can't pass that pointer on to the
89 * kernel. To be on the safe side, never reference it outside of the body of
90 * main(), instead preserving a copy.
91 */
92int boot2_argc;
93char **boot2_argv;
94char **boot2_envv;
95
96struct bootinfo boot2_bootinfo;
97
98int
99main(int argc, char *argv[], char *envv[], struct bootinfo *bootinfop)
100{
101 struct devsw **dp;
102
103 /* NB: Must be sure to bzero() before using any globals. */
104 bzero(&__bss_start, (uintptr_t)&__bss_end - (uintptr_t)&__bss_start);
105
106 boot2_argc = argc;
107 boot2_argv = argv;
108 boot2_envv = envv;
109 boot2_bootinfo = *bootinfop; /* Copy rather than by reference. */
110
111 setheap((void *)&__heap_start, (void *)&__heap_end);
112
113 /*
114 * Pick up console settings from boot2; probe console.
115 */
116 if (bootinfop->bi_boot2opts & RB_MULTIPLE) {
117 if (bootinfop->bi_boot2opts & RB_SERIAL)
118 setenv("console", "comconsole vidconsole", 1);
119 else
120 setenv("console", "vidconsole comconsole", 1);
121 } else if (bootinfop->bi_boot2opts & RB_SERIAL)
122 setenv("console", "comconsole", 1);
123 else if (bootinfop->bi_boot2opts & RB_MUTE)
124 setenv("console", "nullconsole", 1);
125 cons_probe();
126 setenv("LINES", "24", 1);
127
128 printf("%s(%d, %p, %p, %p (%p))\n", __func__, argc, argv, envv,
129 bootinfop, (void *)bootinfop->bi_memsize);
130
131 /*
132 * Initialise devices.
133 */
134 for (dp = devsw; *dp != NULL; dp++) {
135 if ((*dp)->dv_init != NULL)
136 (*dp)->dv_init();
137 }
138 extract_currdev(bootinfop);
139
140 printf("\n");
141 printf("%s, Revision %s\n", bootprog_name, bootprog_rev);
142 printf("(%s, %s)\n", bootprog_maker, bootprog_date);
143#if 0
144 printf("bootpath=\"%s\"\n", bootpath);
145#endif
146
147 interact();
148 return (0);
149}
150
151static void
152extract_currdev(struct bootinfo *bootinfop)
153{
154 const char *bootdev;
155
156 /*
157 * Pick up boot device information from boot2.
158 *
159 * XXXRW: Someday: device units.
160 */
161 switch(bootinfop->bi_boot_dev_type) {
162 case BOOTINFO_DEV_TYPE_DRAM:
163 bootdev = "dram0";
164 break;
165
166 case BOOTINFO_DEV_TYPE_CFI:
167 bootdev = "cfi0";
168 break;
169
170 case BOOTINFO_DEV_TYPE_SDCARD:
171 bootdev = "sdcard0";
172 break;
173
174 default:
175 bootdev = NULL;
176 }
177
178 if (bootdev != NULL) {
179 env_setenv("currdev", EV_VOLATILE, bootdev, NULL, env_nounset);
180 env_setenv("loaddev", EV_VOLATILE, bootdev, env_noset,
181 env_nounset);
182 }
183}
184
185void
186abort(void)
187{
188
189 printf("error: loader abort\n");
190 while (1);
191}
192
193void
194exit(int code)
195{
196
197 printf("error: loader exit\n");
198 while (1);
199}
200
201void
202longjmperror(void)
203{
204
205 printf("error: loader longjmp error\n");
206 while (1);
207}
208
209time_t
210time(time_t *tloc)
211{
212
213 /* We can't provide time since UTC, so just provide time since boot. */
214 return (cp0_count_get() / 100000000);
215}
216
217/*
218 * Delay - in usecs
219 *
220 * NOTE: We are assuming that the CPU is running at 100MHz.
221 */
222void
223delay(int usecs)
224{
225 uint32_t delta;
226 uint32_t curr;
227 uint32_t last;
228
229 last = cp0_count_get();
230 while (usecs > 0) {
231 curr = cp0_count_get();
232 delta = curr - last;
233 while (usecs > 0 && delta >= 100) {
234 usecs--;
235 last += 100;
236 delta -= 100;
237 }
238 }
239}