rev |
line source |
pascal@19515
|
1 // This file is distributed under GPL
|
pascal@19515
|
2 //
|
pascal@19515
|
3 // LINLD main() lives here
|
pascal@19515
|
4
|
pascal@19515
|
5 #include "crtl.h"
|
pascal@19515
|
6 #include "common.h"
|
pascal@19515
|
7
|
pascal@21984
|
8 const char* cmdline = "auto";
|
pascal@19515
|
9 const char* kernel_name = "bzImage";
|
pascal@21984
|
10 #ifdef USE_ARGSTR
|
pascal@21984
|
11 const char* initrd_name = NULL;
|
pascal@21984
|
12 #else
|
pascal@19515
|
13 const char* initrd_name;
|
pascal@21984
|
14 #endif
|
pascal@20528
|
15 u32 root_dev;
|
pascal@20528
|
16 u32 vid_mode; // -3 = ask
|
pascal@20528
|
17 // -2 = Extended VGA
|
pascal@20528
|
18 // -1 = Normal VGA
|
pascal@20528
|
19 // n = as "n" was pressed
|
pascal@20528
|
20 u32 topmem;
|
pascal@21569
|
21 u32 base_himem;
|
pascal@19515
|
22
|
pascal@19515
|
23 inline void syntax() {
|
pascal@19515
|
24 die("Syntax:" NL
|
pascal@19515
|
25 "LINLD [image=file] [initrd=files] [vga=mode] [root=num] [mem=max] [cl=cmdline]" NL
|
pascal@19515
|
26 "vga mode: ask,extended,normal or dec/oct/hex number" NL
|
pascal@19538
|
27 "-f force" NL
|
pascal@21984
|
28 "-64 for cpu64 only" NL
|
pascal@19515
|
29 "Defaults:" NL
|
pascal@19515
|
30 "\timage=bzImage" NL
|
pascal@19515
|
31 "\tinitrd,vga,root=(void)" NL
|
pascal@19515
|
32 "\tmem=256m" NL
|
pascal@19515
|
33 "\tcl=auto" NL
|
pascal@19580
|
34 "\t-b 1088k" NL
|
pascal@19515
|
35 "Use quotes: \"cl=...\" if you need spaces in cmdline" NL
|
pascal@19538
|
36 "Use cl=@filename to get it from a file"
|
pascal@19515
|
37 #if 1
|
pascal@19515
|
38 NL NL "Examples:" NL
|
pascal@21569
|
39 "\tLINLD -f -b 64m "
|
pascal@21569
|
40 "initrd=rootfs4.gz,rootfs3.gz,rootfs2.gz,rootfs1.gz "
|
pascal@21822
|
41 "\"cl=video=-32\""
|
pascal@20451
|
42 NL NL "\tLINLD image=memtest"
|
pascal@19515
|
43 #endif
|
pascal@19515
|
44 );
|
pascal@19515
|
45 }
|
pascal@19515
|
46
|
pascal@20453
|
47 static char buf_cmdline[128];
|
pascal@19515
|
48 int main(int argc, char *argv[]) {
|
pascal@19571
|
49
|
pascal@19571
|
50 (void) argc;
|
pascal@19571
|
51
|
pascal@21569
|
52 ((u16*) &base_himem)[1] |= (_1m+_64k)>>16; // base_himem = _1m+_64k
|
pascal@19515
|
53 puts("LINLD v" VERSION_STR "+");
|
pascal@19515
|
54
|
pascal@19538
|
55 // Parse command line
|
pascal@20751
|
56 #ifdef USE_ARGSTR
|
pascal@21576
|
57 if (!argv[1]) syntax();
|
pascal@21984
|
58 for (;;) {
|
pascal@20751
|
59 const char **clp = &cmdline;
|
pascal@20751
|
60 argv++;
|
pascal@21984
|
61 if (!*argv) goto boot;
|
pascal@21984
|
62 if ((*(u16 *)*argv|2) == 0x362F) { // -64 /64
|
pascal@21984
|
63 if (cpuhaslm() == 0) exit();
|
pascal@21984
|
64 }
|
pascal@21984
|
65 if ((*(u16 *)*argv|0x2002) == 0x662F) { // -F /f
|
pascal@22632
|
66 skip_alloc--;
|
pascal@21984
|
67 }
|
pascal@21984
|
68 else if (argstr(*argv,"cl|image|initrd",clp) != -1);
|
pascal@21984
|
69 else if (fileexist(*argv) != -1)
|
pascal@21984
|
70 kernel_name=*argv;
|
pascal@21984
|
71 else if (argnum(*argv,"root|vga|mem|-b",&root_dev) != -1);
|
pascal@21984
|
72 else {
|
pascal@21984
|
73 *clp = (const char *) buf_cmdline + 1;
|
pascal@21984
|
74 strcatb((const char *) buf_cmdline,*argv);
|
pascal@21984
|
75 boot:
|
pascal@20751
|
76 puts(*clp);
|
pascal@20751
|
77 set_cmdline(*clp);
|
pascal@22170
|
78 load_kernel();
|
pascal@22170
|
79 puts(version_string);
|
pascal@20751
|
80 load_initrd();
|
pascal@20751
|
81 boot_kernel();
|
pascal@20751
|
82 }
|
pascal@20751
|
83 }
|
pascal@20751
|
84 #else
|
pascal@21576
|
85 if (!argv[1]) syntax();
|
pascal@21576
|
86 while (1) {
|
pascal@19571
|
87 char *s;
|
pascal@19580
|
88 next:
|
pascal@19571
|
89 argv++;
|
pascal@19571
|
90 s=*argv;
|
pascal@19538
|
91 if (!s) {
|
pascal@22170
|
92 load_kernel();
|
pascal@22170
|
93 puts(version_string);
|
pascal@19538
|
94 load_initrd();
|
pascal@19538
|
95 boot_kernel();
|
pascal@19538
|
96 }
|
pascal@21791
|
97 if(strhead(s,"initrd=") != -1) {
|
pascal@21569
|
98 initrd_name=s+7;
|
pascal@19538
|
99 }
|
pascal@21628
|
100 else if(strhead(s,"vga=") != -1) {
|
pascal@21569
|
101 *(u16*)&vid_mode = (u16)strtol(s+7); // support normal, extended & ask
|
pascal@19515
|
102 }
|
pascal@19580
|
103 else switch (*(u16 *)s|0x2002) {
|
pascal@21984
|
104 case 0x362F: // -64 /64
|
pascal@21984
|
105 if (cpuhaslm() == 0) exit();
|
pascal@21984
|
106 goto next;
|
pascal@19580
|
107 case 0x662F: // -F /f
|
pascal@22632
|
108 skip_alloc--;
|
pascal@19580
|
109 goto next;
|
pascal@19580
|
110 case 0x622F: // -B /b
|
pascal@19580
|
111 argv++;
|
pascal@21569
|
112 ((u16 *)&base_himem)[1] = (u16)(strtol(*argv)>>16);
|
pascal@19580
|
113 goto next;
|
pascal@19580
|
114 default:
|
pascal@21628
|
115 if(strhead(s,"cl=") != -1) {
|
pascal@20793
|
116 cmdline=s+=3;
|
pascal@20793
|
117 if (*s == '@') {
|
pascal@20793
|
118 static struct image_himem image;
|
pascal@20793
|
119 char c;
|
pascal@19538
|
120
|
pascal@20793
|
121 s++;
|
pascal@20793
|
122 image.errmsg = "Error in cl=@file";
|
pascal@21649
|
123 open_image(&image, s);
|
pascal@21569
|
124 s+=read(image.fd, (void *)cmdline=s=
|
pascal@21569
|
125 (char *)malloc_or_die(image.size), image.size);
|
pascal@20793
|
126 // Strip any trailing cr/lf
|
pascal@20793
|
127 c='\0';
|
pascal@20793
|
128 do {
|
pascal@19538
|
129 // Replace all other cr/lfs with spaces
|
pascal@19538
|
130 s--;
|
pascal@19538
|
131 if(*s>=' ') c=' ';
|
pascal@19538
|
132 else *s = c;
|
pascal@20793
|
133 } while (s>cmdline);
|
pascal@20793
|
134 puts("Kernel command line:");
|
pascal@20793
|
135 puts(cmdline);
|
pascal@20793
|
136 }
|
pascal@20793
|
137 }
|
pascal@21628
|
138 else if(strhead(s,"root=") != -1) {
|
pascal@21569
|
139 *(u16*)&root_dev = (u16)strtol(s+5);
|
pascal@20793
|
140 goto addincmdline;
|
pascal@20793
|
141 }
|
pascal@21628
|
142 else if(strhead(s,"mem=") != -1) {
|
pascal@21569
|
143 ((u16 *)&topmem)[1] = (u16)(strtol(s+4)>>16);
|
pascal@20793
|
144 goto addincmdline;
|
pascal@20793
|
145 }
|
pascal@21791
|
146 else if(strhead(s,"image=") != -1) {
|
pascal@21791
|
147 s+=6;
|
pascal@21791
|
148 set_kernel_name:
|
pascal@21791
|
149 kernel_name=s;
|
pascal@21791
|
150 }
|
pascal@20793
|
151 else {
|
pascal@20793
|
152 addincmdline:
|
pascal@20793
|
153 if(cmdline == (const char *) buf_cmdline + 1) {
|
pascal@20793
|
154 strcatb(buf_cmdline,*argv);
|
pascal@20793
|
155 }
|
pascal@20793
|
156 else {
|
pascal@20793
|
157 if(fileexist(s) != -1) goto set_kernel_name;
|
pascal@20793
|
158 cmdline = (const char *) buf_cmdline + 1;
|
pascal@20793
|
159 goto addincmdline;
|
pascal@20793
|
160 }
|
pascal@20793
|
161 }
|
pascal@19580
|
162 }
|
pascal@20793
|
163 }
|
pascal@20751
|
164 #endif
|
pascal@19515
|
165
|
pascal@19515
|
166 // Let compiler be happy
|
pascal@22183
|
167 //return _AX;
|
pascal@19515
|
168 }
|