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

linld: pascal convention calls
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Nov 09 16:37:55 2018 +0100 (2018-11-09)
parents 46b511e941a7
children ab907169f156
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 "\t-b 1088k" NL
29 "Use quotes: \"cl=...\" if you need spaces in cmdline" NL
30 "Use cl=@filename to get it from a file"
31 #if 1
32 NL NL "Examples:" NL
33 "\tLINLD -f -b 64m initrd=rootfs4.gz,rootfs3.gz,rootfs2.gz,rootfs1.gz \"cl=rw root=/dev/null video=-32\""
34 NL NL "\tLINLD image=memtest"
35 #endif
36 );
37 }
39 static char buf_cmdline[128];
40 int main(int argc, char *argv[]) {
42 (void) argc;
44 // Believe it or not - this enables A20
45 // on my box! Must be DOS in HMA... -vda
46 puts("LINLD v" VERSION_STR "+");
48 // Parse command line
49 if (argv[1]) {for (char i=0;;) {
50 char *s;
51 next:
52 argv++;
53 s=*argv;
54 i++;
55 if (!s) {
56 puts(load_kernel());
57 load_initrd();
58 boot_kernel();
59 }
60 if(strhead(s,"image=") == 0) {
61 s+=6;
62 set_kernel_name:
63 kernel_name=s;
64 }
65 else if(strhead(s,"initrd=") == 0) {
66 s+=7;
67 initrd_name=s;
68 }
69 else if(strhead(s,"vga=") == 0) {
70 s+=4;
71 vid_mode = strtol(s); // support normal, extended & ask
72 }
73 else switch (*(u16 *)s|0x2002) {
74 case 0x662F: // -F /f
75 skip_alloc++;
76 goto next;
77 case 0x622F: // -B /b
78 argv++;
79 base_himem = strtol(*argv);
80 goto next;
81 default:
82 if(strhead(s,"cl=") == 0) {
83 cmdline=s+=3;
84 if (*s == '@') {
85 static struct image_himem image;
86 char c;
88 s++;
89 image.errmsg = "Error in cl=@file";
90 open_image(s, &image);
91 cmdline=s=(char *)malloc_or_die(image.size);
92 s+=image.size;
93 read(image.fd, (void *)cmdline, image.size);
94 // Strip any trailing cr/lf
95 c='\0';
96 do {
97 // Replace all other cr/lfs with spaces
98 s--;
99 if(*s>=' ') c=' ';
100 else *s = c;
101 } while (s>cmdline);
102 puts("Kernel command line:");
103 puts(cmdline);
104 }
105 }
106 else if(strhead(s,"root=") == 0) {
107 s+=5;
108 root_dev = strtol(s);
109 goto addincmdline;
110 }
111 else if(strhead(s,"mem=") == 0) {
112 s+=4;
113 topmem = strtol(s);
114 goto addincmdline;
115 }
116 else if(cmdline == (const char *) buf_cmdline + 1) {
117 addincmdline:
118 strcatb(buf_cmdline,*argv);
119 }
120 else if(i == 1 && fileattr(s) != -1) {
121 cmdline = (const char *) buf_cmdline + 1;
122 goto set_kernel_name;
123 }
124 else
125 break;
126 }
127 }}
128 syntax();
130 // Let compiler be happy
131 return _AX;
132 }