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