Deleted Added
full compact
main.c (84617) main.c (106738)
1/*-
2 * Copyright (c) 2000 Benno Rice <benno@jeamland.net>
3 * Copyright (c) 2000 Stephane Potvin <sepotvin@videotron.ca>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS 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
25 * SUCH DAMAGE.
26 *
1/*-
2 * Copyright (c) 2000 Benno Rice <benno@jeamland.net>
3 * Copyright (c) 2000 Stephane Potvin <sepotvin@videotron.ca>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS 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
25 * SUCH DAMAGE.
26 *
27 * $FreeBSD: head/sys/boot/ofw/common/main.c 84617 2001-10-07 13:22:25Z benno $
27 * $FreeBSD: head/sys/boot/ofw/common/main.c 106738 2002-11-10 19:17:36Z jake $
28 */
29
30#include <stand.h>
31#include "openfirm.h"
32#include "libofw.h"
33#include "bootstrap.h"
34
28 */
29
30#include <stand.h>
31#include "openfirm.h"
32#include "libofw.h"
33#include "bootstrap.h"
34
35struct ofw_devdesc currdev; /* our current device */
36struct arch_switch archsw; /* MI/MD interface boundary */
37
38extern char end[];
39extern char bootprog_name[];
40extern char bootprog_rev[];
41extern char bootprog_date[];
42extern char bootprog_maker[];
43
44phandle_t chosen;
45
46#define HEAP_SIZE 0x40000
47
48void
49init_heap(void)
50{
51 void *base;
52
53 if ((base = ofw_alloc_heap(HEAP_SIZE)) == (void *)0xffffffff) {
54 printf("Heap memory claim failed!\n");
55 OF_enter();
56 }
57
58 setheap(base, base + (HEAP_SIZE / sizeof(base)));
59}
60
61uint32_t
62memsize(void)
63{
64 ihandle_t meminstance;
65 phandle_t memory;
66 struct ofw_reg reg;
67
68 OF_getprop(chosen, "memory", &meminstance, sizeof(meminstance));
69 memory = OF_instance_to_package(meminstance);
70
71 OF_getprop(memory, "reg", &reg, sizeof(reg));
72
73 return (reg.size);
74}
75
76int
77main(int (*openfirm)(void *))
78{
79 int i;
80 char bootpath[64];
81 char *ch;
82
83 /*
84 * Initalise the OpenFirmware routines by giving them the entry point.
85 */
86 OF_init(openfirm);
87
88 chosen = OF_finddevice("/chosen");
89
90 /*
91 * Set up console.
92 */
93 cons_probe();
94
95 /*
96 * Initialise the heap as early as possible. Once this is done,
97 * alloc() is usable. The stack is buried inside us, so this is
98 * safe.
99 */
100 init_heap();
101
102 /*
103 * Initialise the block cache
104 */
105 bcache_init(32, 512); /* 16k XXX tune this */
106
107 /*
108 * March through the device switch probing for things.
109 */
110 for (i = 0; devsw[i] != NULL; i++)
111 if (devsw[i]->dv_init != NULL)
112 (devsw[i]->dv_init)();
113
114 printf("\n");
115 printf("%s, Revision %s\n", bootprog_name, bootprog_rev);
116 printf("(%s, %s)\n", bootprog_maker, bootprog_date);
117 printf("Memory: %dKB\n", memsize() / 1024);
118
119 OF_getprop(chosen, "bootpath", bootpath, 64);
120 ch = index(bootpath, ':');
121 *ch = '\0';
122 printf("Booted from: %s\n", bootpath);
123
124 printf("\n");
125
35struct arch_switch archsw; /* MI/MD interface boundary */
36
37extern char end[];
38extern char bootprog_name[];
39extern char bootprog_rev[];
40extern char bootprog_date[];
41extern char bootprog_maker[];
42
43phandle_t chosen;
44
45#define HEAP_SIZE 0x40000
46
47void
48init_heap(void)
49{
50 void *base;
51
52 if ((base = ofw_alloc_heap(HEAP_SIZE)) == (void *)0xffffffff) {
53 printf("Heap memory claim failed!\n");
54 OF_enter();
55 }
56
57 setheap(base, base + (HEAP_SIZE / sizeof(base)));
58}
59
60uint32_t
61memsize(void)
62{
63 ihandle_t meminstance;
64 phandle_t memory;
65 struct ofw_reg reg;
66
67 OF_getprop(chosen, "memory", &meminstance, sizeof(meminstance));
68 memory = OF_instance_to_package(meminstance);
69
70 OF_getprop(memory, "reg", &reg, sizeof(reg));
71
72 return (reg.size);
73}
74
75int
76main(int (*openfirm)(void *))
77{
78 int i;
79 char bootpath[64];
80 char *ch;
81
82 /*
83 * Initalise the OpenFirmware routines by giving them the entry point.
84 */
85 OF_init(openfirm);
86
87 chosen = OF_finddevice("/chosen");
88
89 /*
90 * Set up console.
91 */
92 cons_probe();
93
94 /*
95 * Initialise the heap as early as possible. Once this is done,
96 * alloc() is usable. The stack is buried inside us, so this is
97 * safe.
98 */
99 init_heap();
100
101 /*
102 * Initialise the block cache
103 */
104 bcache_init(32, 512); /* 16k XXX tune this */
105
106 /*
107 * March through the device switch probing for things.
108 */
109 for (i = 0; devsw[i] != NULL; i++)
110 if (devsw[i]->dv_init != NULL)
111 (devsw[i]->dv_init)();
112
113 printf("\n");
114 printf("%s, Revision %s\n", bootprog_name, bootprog_rev);
115 printf("(%s, %s)\n", bootprog_maker, bootprog_date);
116 printf("Memory: %dKB\n", memsize() / 1024);
117
118 OF_getprop(chosen, "bootpath", bootpath, 64);
119 ch = index(bootpath, ':');
120 *ch = '\0';
121 printf("Booted from: %s\n", bootpath);
122
123 printf("\n");
124
126 switch (ofw_devicetype(bootpath)) {
127 case DEVT_DISK:
128 currdev.d_dev = &ofwdisk;
129 currdev.d_type = DEVT_DISK;
130 strncpy(currdev.d_kind.ofwdisk.path, bootpath, 64);
131 currdev.d_kind.ofwdisk.unit = ofwd_getunit(bootpath);
132
133 if (currdev.d_kind.ofwdisk.unit == -1) {
134 printf("Could not locate boot device.\n");
135 OF_exit();
136 }
137
138 break;
139
140 case DEVT_NET:
141 currdev.d_dev = &netdev;
142 currdev.d_type = DEVT_NET;
143 strncpy(currdev.d_kind.netif.path, bootpath, 64);
144 /* XXX Only works when we only look for one net device */
145 currdev.d_kind.netif.unit = 0;
146
147 break;
148
149 case DEVT_NONE:
150 default:
151 printf("\n");
152 printf("Could not establish type of boot device.\n");
153 OF_exit();
154 /* NOTREACHED */
155 break;
156 }
157
158 env_setenv("currdev", EV_VOLATILE, ofw_fmtdev(&currdev),
125 env_setenv("currdev", EV_VOLATILE, bootpath,
159 ofw_setcurrdev, env_nounset);
126 ofw_setcurrdev, env_nounset);
160 env_setenv("loaddev", EV_VOLATILE, ofw_fmtdev(&currdev), env_noset,
127 env_setenv("loaddev", EV_VOLATILE, bootpath, env_noset,
161 env_nounset);
162 setenv("LINES", "24", 1); /* optional */
163
164 archsw.arch_getdev = ofw_getdev;
165 archsw.arch_copyin = ofw_copyin;
166 archsw.arch_copyout = ofw_copyout;
167 archsw.arch_readin = ofw_readin;
168 archsw.arch_autoload = ofw_autoload;
169
170 interact(); /* doesn't return */
171
172 OF_exit();
173
174 return 0;
175}
176
177COMMAND_SET(halt, "halt", "halt the system", command_halt);
178
179static int
180command_halt(int argc, char *argv[])
181{
182
183 OF_exit();
184 return (CMD_OK);
185}
186
187COMMAND_SET(memmap, "memmap", "print memory map", command_memmap);
188
189int
190command_memmap(int argc, char **argv)
191{
192
193 ofw_memmap();
194 return (CMD_OK);
195}
128 env_nounset);
129 setenv("LINES", "24", 1); /* optional */
130
131 archsw.arch_getdev = ofw_getdev;
132 archsw.arch_copyin = ofw_copyin;
133 archsw.arch_copyout = ofw_copyout;
134 archsw.arch_readin = ofw_readin;
135 archsw.arch_autoload = ofw_autoload;
136
137 interact(); /* doesn't return */
138
139 OF_exit();
140
141 return 0;
142}
143
144COMMAND_SET(halt, "halt", "halt the system", command_halt);
145
146static int
147command_halt(int argc, char *argv[])
148{
149
150 OF_exit();
151 return (CMD_OK);
152}
153
154COMMAND_SET(memmap, "memmap", "print memory map", command_memmap);
155
156int
157command_memmap(int argc, char **argv)
158{
159
160 ofw_memmap();
161 return (CMD_OK);
162}