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