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

mate-control-center; update bdeps
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Feb 22 09:33:32 2017 +0100 (2017-02-22)
parents e428345df29a
children 6f494adb2c71
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 u16 root_dev;
12 u16 vid_mode; // -3 = ask
13 // -2 = Extended VGA
14 // -1 = Normal VGA
15 // n = as "n" was pressed
17 inline void syntax() {
18 die("Syntax:" NL
19 "LINLD [image=file] [initrd=files] [vga=mode] [root=num] [mem=max] [cl=cmdline]" NL
20 "vga mode: ask,extended,normal or dec/oct/hex number" NL
21 "-f force" NL
22 "Defaults:" NL
23 "\timage=bzImage" NL
24 "\tinitrd,vga,root=(void)" NL
25 "\tmem=256m" NL
26 "\tcl=auto" NL
27 "\t-b 1088k" NL
28 "Use quotes: \"cl=...\" if you need spaces in cmdline" NL
29 "Use cl=@filename to get it from a file"
30 #if 1
31 NL NL "Examples:" NL
32 "\tlinld -f -b 64m initrd=rootfs4.gz,rootfs3.gz,rootfs2.gz,rootfs1.gz \"cl=rw root=/dev/null video=-32\""
33 NL NL "\tlinld image=memtest"
34 #endif
35 );
36 }
38 static char _cmdline[256];
39 int main(int argc, char *argv[]) {
41 (void) argc;
43 // Believe it or not - this enables A20
44 // on my box! Must be DOS in HMA... -vda
45 puts("LINLD v" VERSION_STR "+");
47 // Parse command line
48 if (argv[1]) {for (char i=0;;) {
49 char *s;
50 next:
51 argv++;
52 s=*argv;
53 i++;
54 if (!s) {
55 puts(load_kernel());
56 load_initrd();
57 boot_kernel();
58 }
59 if(strhead(s,"image=") == 0) {
60 s+=6;
61 kernel_name=s;
62 }
63 else if(strhead(s,"initrd=") == 0) {
64 s+=7;
65 initrd_name=s;
66 }
67 else if(strhead(s,"vga=") == 0) {
68 s+=4;
69 vid_mode = strtol(s); // support normal, extended & ask
70 }
71 else switch (*(u16 *)s|0x2002) {
72 case 0x662F: // -F /f
73 skip_alloc++;
74 goto next;
75 case 0x622F: // -B /b
76 argv++;
77 base_himem = strtol(*argv);
78 goto next;
79 default:
80 if(strhead(s,"cl=") == 0) {
81 cmdline=s+=3;
82 if (*s == '@') {
83 static struct image_himem image;
84 char c;
86 s++;
87 image.errmsg = "Error in cl=@file";
88 open_image(s, &image);
89 cmdline=s=(char *)malloc_or_die(image.size);
90 s+=image.size;
91 read(image.fd, (void *)cmdline, image.size);
92 // Strip any trailing cr/lf
93 c='\0';
94 do {
95 // Replace all other cr/lfs with spaces
96 s--;
97 if(*s>=' ') c=' ';
98 else *s = c;
99 } while (s>cmdline);
100 puts("Kernel command line:");
101 puts(cmdline);
102 }
103 }
104 else if(strhead(s,"root=") == 0) {
105 s+=5;
106 root_dev = strtol(s);
107 goto addincmdline;
108 }
109 else if(strhead(s,"mem=") == 0) {
110 s+=4;
111 topmem = strtol(s);
112 goto addincmdline;
113 }
114 else if(cmdline == (const char *) _cmdline) {
115 addincmdline:
116 strcatb(_cmdline,*argv);
117 }
118 else if(i == 1 && fileattr(s) != -1) {
119 kernel_name = s;
120 cmdline = (const char *) _cmdline;
121 }
122 else
123 break;
124 }
125 }}
126 syntax();
128 // Let compiler be happy
129 return _AX;
130 }