2 * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
3 * Copyright (c) 1998,2000 Doug Rabson <dfr@freebsd.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
35 #include "bootstrap.h"
37 #include "libuserboot.h"
39 #define USERBOOT_VERSION USERBOOT_VERSION_2
41 struct loader_callbacks *callbacks;
44 extern char bootprog_name[];
45 extern char bootprog_rev[];
46 extern char bootprog_date[];
47 extern char bootprog_maker[];
50 struct arch_switch archsw; /* MI/MD interface boundary */
52 static void extract_currdev(void);
58 CALLBACK(delay, usec);
70 loader_main(struct loader_callbacks *cb, void *arg, int version, int ndisks)
72 static char malloc[512*1024];
75 if (version != USERBOOT_VERSION)
80 userboot_disk_maxunit = ndisks;
83 * initialise the heap as early as possible. Once this is done,
84 * alloc() is usable. The stack is buried inside us, so this is
87 setheap((void *)malloc, (void *)(malloc + 512*1024));
95 * March through the device switch probing for things.
97 for (i = 0; devsw[i] != NULL; i++)
98 if (devsw[i]->dv_init != NULL)
99 (devsw[i]->dv_init)();
102 printf("%s, Revision %s\n", bootprog_name, bootprog_rev);
103 printf("(%s, %s)\n", bootprog_maker, bootprog_date);
105 printf("Memory: %ld k\n", memsize() / 1024);
108 setenv("LINES", "24", 1); /* optional */
110 archsw.arch_autoload = userboot_autoload;
111 archsw.arch_getdev = userboot_getdev;
112 archsw.arch_copyin = userboot_copyin;
113 archsw.arch_copyout = userboot_copyout;
114 archsw.arch_readin = userboot_readin;
121 interact(); /* doesn't return */
127 * Set the 'current device' by (if possible) recovering the boot device as
128 * supplied by the initial bootstrap.
131 extract_currdev(void)
133 struct disk_devdesc dev;
135 //bzero(&dev, sizeof(dev));
137 if (userboot_disk_maxunit > 0) {
138 dev.d_dev = &userboot_disk;
139 dev.d_type = dev.d_dev->dv_type;
144 * Figure out if we are using MBR or GPT - for GPT we
145 * set the partition to 0 since everything is a GPT slice.
147 if (dev.d_dev->dv_open(NULL, &dev))
148 dev.d_partition = 255;
150 dev.d_dev = &host_dev;
151 dev.d_type = dev.d_dev->dv_type;
155 env_setenv("currdev", EV_VOLATILE, userboot_fmtdev(&dev),
156 userboot_setcurrdev, env_nounset);
157 env_setenv("loaddev", EV_VOLATILE, userboot_fmtdev(&dev),
158 env_noset, env_nounset);
161 COMMAND_SET(quit, "quit", "exit the loader", command_quit);
164 command_quit(int argc, char *argv[])
167 exit(USERBOOT_EXIT_QUIT);
171 COMMAND_SET(reboot, "reboot", "reboot the system", command_reboot);
174 command_reboot(int argc, char *argv[])
177 exit(USERBOOT_EXIT_REBOOT);