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