wok view linld/stuff/src/LINLD.CPP @ rev 23992

linld: skip xmm_alloc
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Dec 12 10:41:29 2020 +0000 (2020-12-12)
parents 78bc4b109dd6
children 34d90fb03f57
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 #ifdef WITH_XMM_ALLOC
28 "-f force" NL
29 #endif
30 "-64 for cpu64 only" NL
31 "Defaults:" NL
32 "\timage=bzImage" NL
33 "\tinitrd,vga,root=(void)" NL
34 "\tmem=256m" NL
35 "\tcl=auto" NL
36 "\t-b 1088k" NL
37 "Use quotes: \"cl=...\" if you need spaces in cmdline" NL
38 "Use cl=@filename to get it from a file"
39 #if 1
40 NL NL "Examples:" NL
41 "\tLINLD "
42 #ifdef WITH_XMM_ALLOC
43 "-f "
44 #endif
45 "-b 64m "
46 "initrd=rootfs4.gz,rootfs3.gz,rootfs2.gz,rootfs1.gz "
47 "\"cl=root=/dev/null video=-32\""
48 NL NL "\tLINLD image=memtest"
49 #endif
50 );
51 }
53 static char buf_cmdline[128];
54 int main(int argc, char *argv[]) {
56 (void) argc;
58 ((u16*) &base_himem)[1] |= (_1m+_64k)>>16; // base_himem = _1m+_64k
59 puts("LINLD v" VERSION_STR "+");
61 // Parse command line
62 #ifdef USE_ARGSTR
63 if (!argv[1]) syntax();
64 const char **clp = &cmdline;
65 for (;;) {
66 argv++;
67 if (!*argv) break;
68 if ((*(u16 *)*argv|2) == 0x362F) { // -64 /64
69 if (cpuhaslm() == 0) exit();
70 continue;
71 }
72 #ifdef WITH_XMM_ALLOC
73 if ((*(u16 *)*argv|0x2002) == 0x662F) { // -F /f
74 skip_alloc--;
75 continue;
76 }
77 #endif
78 if (argstr(*argv,"cl|image|initrd",clp) != -1 && **argv == 'c') continue;
79 if (fileexist(*argv) != -1) {
80 kernel_name=*argv;
81 continue;
82 }
83 argnum(*argv,"root|vga|mem|-b",&root_dev);
84 *clp = (const char *) buf_cmdline + 1;
85 strcatb((const char *) buf_cmdline,*argv);
86 }
87 puts(*clp);
88 set_cmdline(*clp);
89 load_kernel();
90 load_initrd();
91 boot_kernel();
92 #else
93 if (!argv[1]) syntax();
94 while (1) {
95 char *s;
96 next:
97 argv++;
98 s=*argv;
99 if (!s) {
100 load_kernel();
101 puts(version_string);
102 load_initrd();
103 boot_kernel();
104 }
105 if(strhead(s,"initrd=") != -1) {
106 initrd_name=s+7;
107 }
108 else if(strhead(s,"vga=") != -1) {
109 *(u16*)&vid_mode = (u16)strtol(s+7); // support normal, extended & ask
110 }
111 else switch (*(u16 *)s|0x2002) {
112 case 0x362F: // -64 /64
113 if (cpuhaslm() == 0) exit();
114 goto next;
115 #ifdef WITH_XMM_ALLOC
116 case 0x662F: // -F /f
117 skip_alloc--;
118 goto next;
119 #endif
120 case 0x622F: // -B /b
121 argv++;
122 ((u16 *)&base_himem)[1] = (u16)(strtol(*argv)>>16);
123 goto next;
124 default:
125 if(strhead(s,"cl=") != -1) {
126 cmdline=s+=3;
127 if (*s == '@') {
128 static struct image_himem image;
129 char c;
131 s++;
132 image.errmsg = "Error in cl=@file";
133 open_image(&image, s);
134 s+=read(image.fd, (void *)cmdline=s=
135 (char *)malloc_or_die(image.size), image.size);
136 // Strip any trailing cr/lf
137 c='\0';
138 do {
139 // Replace all other cr/lfs with spaces
140 s--;
141 if(*s>=' ') c=' ';
142 else *s = c;
143 } while (s>cmdline);
144 puts("Kernel command line:");
145 puts(cmdline);
146 }
147 }
148 else if(strhead(s,"root=") != -1) {
149 *(u16*)&root_dev = (u16)strtol(s+5);
150 goto addincmdline;
151 }
152 else if(strhead(s,"mem=") != -1) {
153 ((u16 *)&topmem)[1] = (u16)(strtol(s+4)>>16);
154 goto addincmdline;
155 }
156 else if(strhead(s,"image=") != -1) {
157 s+=6;
158 set_kernel_name:
159 kernel_name=s;
160 }
161 else {
162 addincmdline:
163 if(cmdline == (const char *) buf_cmdline + 1) {
164 strcatb(buf_cmdline,*argv);
165 }
166 else {
167 if(fileexist(s) != -1) goto set_kernel_name;
168 cmdline = (const char *) buf_cmdline + 1;
169 goto addincmdline;
170 }
171 }
172 }
173 }
174 #endif
176 // Let compiler be happy
177 //return _AX;
178 }