Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / platform / pc32 / boot / dosboot / fbsdboot.c
1 /*\r
2  *      fbsdboot.c              Boot FreeBSD from DOS\r
3  *\r
4  *      (C) 1994 by Christian Gusenbauer (cg@fimp01.fim.uni-linz.ac.at)\r
5  *      All Rights Reserved.\r
6  * \r
7  *      Permission to use, copy, modify and distribute this software and its\r
8  *      documentation is hereby granted, provided that both the copyright\r
9  *      notice and this permission notice appear in all copies of the\r
10  *      software, derivative works or modified versions, and any portions\r
11  *      thereof, and that both notices appear in supporting documentation.\r
12  * \r
13  *      I ALLOW YOU USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. I DISCLAIM\r
14  *      ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE\r
15  *      USE OF THIS SOFTWARE.\r
16  * \r
17  */\r
18 #include <dos.h>\r
19 #include <stdio.h>\r
20 #include <process.h>\r
21 \r
22 #include "reboot.h"\r
23 #include "boot.h"\r
24 #include "bootinfo.h"\r
25 #include "dosboot.h"\r
26 #include "protmod.h"\r
27 \r
28 #define MAV     1\r
29 #define MIV     7\r
30 \r
31 #define ptr2pa(x)       (((((long)(x))&0xffff0000l)>>12l)+(((long)(x))&0xffffl))\r
32 \r
33 static void usage(char *name)\r
34 {\r
35         fprintf(stderr, "FreeBSD boot Version %d.%d\n", MAV, MIV);\r
36         fprintf(stderr, "(c) 1994, 1995 Christian Gusenbauer,\n    cg@fimp01.fim.uni-linz.ac.at\n\n");\r
37         fprintf(stderr, "usage: %s [ options ] [ kernelname ]\n", name);\r
38         fprintf(stderr, "where options are:\n");\r
39         fprintf(stderr, "\t-r ... use compiled-in rootdev\n");\r
40         fprintf(stderr, "\t-s ... reboot to single user only\n");\r
41         fprintf(stderr, "\t-a ... ask for file name to reboot from\n");\r
42         fprintf(stderr, "\t-d ... give control to kernel debugger\n");\r
43         fprintf(stderr, "\t-g ... give control to GDB debugger\n");\r
44         fprintf(stderr, "\t-c ... invoke user configuration routing\n");\r
45         fprintf(stderr, "\t-v ... print all potentially useful info\n");\r
46         fprintf(stderr, "\t-C ... use cdrom as root\n");\r
47         fprintf(stderr, "\t-D ... boot a kernel from a DOS medium\n");\r
48         fprintf(stderr, "\t       (default: c:\\kernel)\n");\r
49         exit(1);\r
50 }\r
51 \r
52 static unsigned int memsize(int x)\r
53 {\r
54         unsigned int rt=0;\r
55 \r
56         switch (x) {\r
57                 case 1:\r
58                         _asm {\r
59                                 mov             bl,1\r
60                                 mov     ah,88h\r
61                                 int             15h\r
62                                 mov             rt,ax\r
63                         }\r
64                         break;\r
65                 default:\r
66                         _asm {\r
67                                 int             12h\r
68                                 mov             rt,ax\r
69                         }\r
70                         break;\r
71         }\r
72         return rt;\r
73 }\r
74 \r
75 int main(int argc, char *argv[])\r
76 {\r
77         char *kernel="/kernel", *ptr;\r
78         int i, dos=0;\r
79         long howto=0;\r
80         extern unsigned long get_diskinfo(int);\r
81 \r
82         VCPIboot = 0;\r
83         slice = 0;\r
84 \r
85         for (i = 1; i < argc; i++) {                    /* check arguments */\r
86                 if (argv[i][0] != '-') {                        /* kernel name */\r
87                         kernel = argv[i];\r
88                         break;\r
89                 }\r
90                 ptr = &argv[i][1];\r
91                 while (*ptr) {                                          /* check options */\r
92                         switch(*ptr) {\r
93                                 case 'r': howto |= RB_DFLTROOT; break;\r
94                                 case 's': howto |= RB_SINGLE; break;\r
95                                 case 'a': howto |= RB_ASKNAME; break;\r
96                                 case 'c': howto |= RB_CONFIG; break;\r
97                                 case 'd': howto |= RB_KDB; break;\r
98                                 case 'g': howto |= RB_GDB; break;\r
99                                 case 'v': howto |= RB_VERBOSE; break;\r
100                                 case 'C': howto |= RB_CDROM; break;\r
101                                 case 'D': dos = 1; kernel = "c:\\kernel"; break;\r
102                                 case '?':\r
103                                 default: usage(argv[0]);\r
104                         }\r
105                         ptr++;\r
106                 }\r
107         }\r
108 \r
109         bootinfo.bi_version = BOOTINFO_VERSION;\r
110         for (i = 0; i < N_BIOS_GEOM; i++)\r
111                 bootinfo.bi_bios_geom[i] = get_diskinfo(0x80+i);\r
112         bootinfo.bi_basemem = memsize(0);\r
113         bootinfo.bi_extmem = memsize(1);\r
114         bootinfo.bi_memsizes_valid = 0;         /* that is not yet valid!! */\r
115         bootinfo.bi_kernelname = (char *) ptr2pa(kernel);\r
116         bootinfo.bi_nfs_diskless = NULL;\r
117         bootinfo.bi_size = sizeof(bootinfo);\r
118 \r
119         if (dos)\r
120                 dosboot(howto, kernel);         /* boot given kernel from DOS partition */\r
121         else\r
122                 bsdboot(0x80, howto, kernel);   /* boot from FreeBSD partition */\r
123         return 0;\r
124 }\r