Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / atari / stand / tostools / loadbsd / loadbsd.c
blob06cfd81d5635b17dabf72309dee5557cef89cd15
1 /* $NetBSD: loadbsd.c,v 1.20 2009/03/18 10:22:26 cegger Exp $ */
3 /*
4 * Copyright (c) 1995 L. Weppelman
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * NetBSD loader for the Atari-TT.
32 #include <fcntl.h>
33 #include <stdio.h>
34 #include <osbind.h>
35 #include <stdarg.h>
36 #include <stdlib.h>
37 #include <string.h>
38 #include <unistd.h>
39 #include "libtos.h"
40 #include "tosdefs.h"
41 #include "cread.h"
43 char *Progname; /* How are we called */
44 int d_flag = 0; /* Output debugging output? */
45 int h_flag = 0; /* show help */
46 int N_flag = 0; /* No symbols? */
47 int s_flag = 0; /* St-ram only */
48 int t_flag = 0; /* Just test, do not execute */
49 int v_flag = 0; /* show version */
51 const char version[] = "$Revision: 1.21 $";
54 * Default name of kernel to boot, large enough to patch
56 char kname[80] = "n:/netbsd";
58 static osdsc_t kernelparms;
60 void help PROTO((void));
61 void usage PROTO((void));
62 void get_sys_info PROTO((osdsc_t *));
63 void start_kernel PROTO((osdsc_t *));
65 int
66 main(int argc, char **argv)
69 * Option parsing
71 extern int optind;
72 extern char *optarg;
73 int ch, err;
74 char *errmsg;
75 int fd;
76 osdsc_t *od;
78 init_toslib(argv[0]);
79 Progname = argv[0];
81 od = &kernelparms;
82 od->boothowto = RB_SINGLE;
84 while ((ch = getopt(argc, argv, "abdDhNstVwo:S:T:")) != -1) {
85 switch (ch) {
86 case 'a':
87 od->boothowto &= ~(RB_SINGLE);
88 od->boothowto |= RB_AUTOBOOT;
89 break;
90 case 'b':
91 od->boothowto |= RB_ASKNAME;
92 break;
93 case 'd':
94 od->boothowto |= RB_KDB;
95 break;
96 case 'D':
97 d_flag = 1;
98 break;
99 case 'h':
100 h_flag = 1;
101 break;
102 case 'N':
103 N_flag = 1;
104 break;
105 case 'o':
106 redirect_output(optarg);
107 break;
108 case 's':
109 s_flag = 1;
110 break;
111 case 'S':
112 od->stmem_size = atoi(optarg);
113 break;
114 case 't':
115 t_flag = 1;
116 break;
117 case 'T':
118 od->ttmem_size = atoi(optarg);
119 break;
120 case 'V':
121 v_flag = 1;
122 break;
123 case 'w':
124 set_wait_for_key();
125 break;
126 default:
127 usage();
130 argc -= optind;
131 argv += optind;
132 if (argc == 1)
133 strcpy(kname, argv[0]);
135 if (h_flag)
136 help();
137 if (v_flag)
138 eprintf("%s\r\n", version);
141 * Get system info to pass to NetBSD
143 get_sys_info(od);
144 if (d_flag) {
145 eprintf("Machine info:\r\n");
146 eprintf("ST-RAM size\t: %10d bytes\r\n",od->stmem_size);
147 eprintf("TT-RAM size\t: %10d bytes\r\n",od->ttmem_size);
148 eprintf("TT-RAM start\t: 0x%08x\r\n", od->ttmem_start);
149 eprintf("Cpu-type\t: 0x%08x\r\n", od->cputype);
153 * Find the kernel to boot and read it's exec-header
155 if ((fd = open(kname, O_RDONLY)) < 0)
156 fatal(-1, "Cannot open kernel '%s'", kname);
157 if ((err = elf_load(fd, od, &errmsg, !N_flag)) == -1) {
159 * Not ELF, try a.out
161 if (err = aout_load(fd, od, &errmsg, !N_flag)) {
162 if (err == -1)
163 errmsg = "Not an ELF or NMAGIC file '%s'";
164 fatal(-1, errmsg, kname);
167 else {
168 if (err)
169 fatal(-1, errmsg);
172 close(fd);
174 if (d_flag) {
175 eprintf("\r\nKernel info:\r\n");
176 eprintf("Kernel loadaddr\t: 0x%08x\r\n", od->kstart);
177 eprintf("Kernel size\t: %10d bytes\r\n", od->ksize);
178 eprintf("Kernel entry\t: 0x%08x\r\n", od->kentry);
179 eprintf("Kernel esym\t: 0x%08x\r\n", od->k_esym);
182 if (!t_flag)
183 start_kernel(od);
184 /* NOT REACHED */
186 eprintf("Kernel '%s' was loaded OK\r\n", kname);
187 xexit(0);
188 return 0;
191 void
192 get_sys_info(osdsc_t *od)
194 long stck;
196 stck = Super(0);
198 sys_info(od);
200 if (!(od->cputype & ATARI_ANYCPU))
201 fatal(-1, "Cannot determine CPU-type");
203 (void)Super(stck);
204 if (s_flag)
205 od->ttmem_size = od->ttmem_start = 0;
208 void
209 help(void)
211 eprintf("\r
212 NetBSD loader for the Atari-TT\r
214 Usage: %s [-abdhstVD] [-S <stram-size>] [-T <ttram-size>] [kernel]\r
216 Description of options:\r
218 \t-a Boot up to multi-user mode.\r
219 \t-b Ask for root device to use.\r
220 \t-d Enter kernel debugger.\r
221 \t-D printout debug information while loading\r
222 \t-h What you're getting right now.\r
223 `t-N No symbols must be loaded.\r
224 \t-o Write output to both <output file> and stdout.\r
225 \t-s Use only ST-compatible RAM\r
226 \t-S Set amount of ST-compatible RAM\r
227 \t-T Set amount of TT-compatible RAM\r
228 \t-t Test the loader. It will do everything except executing the\r
229 \t loaded kernel.\r
230 \t-V Print loader version.\r
231 \t-w Wait for a keypress before exiting.\r
232 ", Progname);
233 xexit(0);
236 void
237 usage(void)
239 eprintf("Usage: %s [-abdhstVD] [-S <stram-size>] "
240 "[-T <ttram-size>] [kernel]\r\n", Progname);
241 xexit(1);
244 void
245 start_kernel(osdsc_t *od)
247 long stck;
249 stck = Super(0);
250 bsd_startup(&(od->kp));
251 /* NOT REACHED */
253 (void)Super(stck);