xref: /netbsd-src/sys/arch/ia64/stand/ia64/ski/main.c (revision a01d771b17cae1619415c5040dba980ae0477c9e)
1 /*	$NetBSD: main.c,v 1.4 2012/12/27 20:21:51 martin Exp $	*/
2 
3 /*-
4  * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
5  * Copyright (c) 1998,2000 Doug Rabson <dfr@freebsd.org>
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29 
30 #include <sys/cdefs.h>
31 
32 #include <lib/libsa/stand.h>
33 #include <lib/libsa/loadfile.h>
34 
35 #include "bootstrap.h"
36 #include "libski.h"
37 
38 static int command_quit(int argc, char *argv[]);
39 
40 extern char bootprog_name[];
41 extern char bootprog_rev[];
42 int skifs_dev_init(void);
43 
44 struct bootblk_command commands[] = {
45 	COMMON_COMMANDS,
46 	{ "quit",	"exit the loader",	command_quit },
47 	{ NULL,		NULL,			NULL	     },
48 };
49 
50 struct ski_devdesc	currdev;	/* our current device */
51 struct arch_switch	archsw;		/* MI/MD interface boundary */
52 
53 static int
ski_autoload(void)54 ski_autoload(void)
55 {
56 
57 	return (0);
58 }
59 
60 void
ski_main(void)61 ski_main(void)
62 {
63 	static char malloc[512*1024];
64 	int i;
65 
66 	/*
67 	 * initialise the heap as early as possible.  Once this is done,
68 	 * alloc() is usable. The stack is buried inside us, so this is
69 	 * safe.
70 	 */
71 	setheap((void *)malloc, (void *)(malloc + 512*1024));
72 
73 	/*
74 	 * XXX Chicken-and-egg problem; we want to have console output
75 	 * early, but some console attributes may depend on reading from
76 	 * eg. the boot device, which we can't do yet.  We can use
77 	 * printf() etc. once this is done.
78 	 */
79 	cons_probe();
80 
81 	/*
82 	 * Initialise the block cache XXX: Fixme: do we need the bcache ?
83 	 */
84 	/*	bcache_init(32, 512);	*/	/* 16k XXX tune this */
85 
86 	/* Initialise skifs.c */
87 
88 	skifs_dev_init();
89 
90 	printf("\n");
91 	printf("%s, Revision %s\n", bootprog_name, bootprog_rev);
92 #if 0
93 	printf("Memory: %ld k\n", memsize() / 1024);
94 #endif
95 
96 	/* XXX presumes that biosdisk is first in devsw */
97 	currdev.d_dev = &devsw[0];
98 	currdev.d_type = DEVT_DISK;
99 	currdev.d_kind.skidisk.unit = 0;
100 	/* XXX should be able to detect this, default to autoprobe */
101 	currdev.d_kind.skidisk.slice = -1;
102 	/* default to 'a' */
103 	currdev.d_kind.skidisk.partition = 0;
104 
105 #if 0
106 	/* Create arc-specific variables */
107 	bootfile = GetEnvironmentVariable(ARCENV_BOOTFILE);
108 	if (bootfile)
109 		setenv("bootfile", bootfile, 1);
110 #endif
111 
112 	env_setenv("currdev", EV_VOLATILE, ski_fmtdev(&currdev),
113 	    (ev_sethook_t *) ski_setcurrdev, env_nounset);
114 	env_setenv("loaddev", EV_VOLATILE, ski_fmtdev(&currdev), env_noset,
115 	    env_nounset);
116 
117 	setenv("LINES", "24", 1);	/* optional */
118 
119 	archsw.arch_autoload = ski_autoload;
120 	archsw.arch_getdev = ski_getdev;
121 	archsw.arch_copyin = ski_copyin;
122 	archsw.arch_copyout = ski_copyout;
123 	archsw.arch_readin = ski_readin;
124 
125 	interact();			/* doesn't return */
126 
127 	exit(0);
128 }
129 
130 static int
command_quit(int argc,char * argv[])131 command_quit(int argc, char *argv[])
132 {
133 	exit(0);
134 	return (CMD_OK);
135 }
136