]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/bootstrap_custom/server/src/koptions.cc
benchmarks: use better bench. bootstrap: Fix slow memory access bug.
[l4.git] / l4 / pkg / bootstrap_custom / server / src / koptions.cc
1
2 #include <stdio.h>
3 #include <ctype.h>
4 #include <string.h>
5 #include <stddef.h>
6 #include <stdlib.h>
7
8 #include "koptions.h"
9
10 static struct {
11   const char *s;
12   unsigned int flag;
13 } boolean_opts[] = {
14   { " -wait",              L4_kernel_options::F_wait              },
15   { " -serial_esc",        L4_kernel_options::F_serial_esc        },
16   { " -noserial",          L4_kernel_options::F_noserial          },
17   { " -noscreen",          L4_kernel_options::F_noscreen          },
18   { " -esc",               L4_kernel_options::F_esc               },
19   { " -nojdb",             L4_kernel_options::F_nojdb             },
20   { " -nokdb",             L4_kernel_options::F_nokdb             },
21   { " -nohlt",             L4_kernel_options::F_nohlt             },
22   { " -apic",              L4_kernel_options::F_apic              },
23   { " -loadcnt",           L4_kernel_options::F_loadcnt           },
24   { " -watchdog",          L4_kernel_options::F_watchdog          },
25   { " -irq0",              L4_kernel_options::F_irq0              },
26   { " -nosfn",             L4_kernel_options::F_nosfn             },
27   { " -jdb_never_stop",    L4_kernel_options::F_jdb_never_stop    },
28 };
29
30 static struct {
31   const char *s;
32   unsigned int flag;
33   unsigned int offset;
34 } unsigned_opts[] = {
35   { " -kmemsize",     L4_kernel_options::F_kmemsize,
36                       offsetof(L4_kernel_options::Options, kmemsize) },
37   { " -tbuf_entries", L4_kernel_options::F_tbuf_entries,
38                       offsetof(L4_kernel_options::Options, tbuf_entries) },
39   { " -out_buf",      L4_kernel_options::F_out_buf,
40                       offsetof(L4_kernel_options::Options, out_buf) },
41 };
42
43 #define MEMBERSIZE(type, member) sizeof(((type *)0)->member)
44
45 static struct {
46   const char *s;
47   unsigned int flag;
48   unsigned int size;
49   unsigned int offset;
50 } string_opts[] = {
51   { " -jdb_cmd",      L4_kernel_options::F_jdb_cmd,
52                       MEMBERSIZE(L4_kernel_options::Options, jdb_cmd),
53                       offsetof(L4_kernel_options::Options, jdb_cmd) },
54 };
55
56 static void kcmdline_show(L4_kernel_options::Options *lko)
57 {
58   printf("Location: %016lx  Size: %zd Bytes\n",
59          (unsigned long)lko, sizeof(*lko));
60   printf("Flags: %08x\n", lko->flags);
61   for (unsigned i = 0; i < sizeof(boolean_opts) / sizeof(boolean_opts[0]); ++i)
62     {
63       if (lko->flags & boolean_opts[i].flag)
64         printf("  %s\n", boolean_opts[i].s);
65     }
66
67   if (lko->flags & L4_kernel_options::F_kmemsize)
68     printf("Kmemsize: %dKiB\n", lko->kmemsize);
69   if (lko->flags & L4_kernel_options::F_tbuf_entries)
70     printf("Tbuf entries: %d\n", lko->tbuf_entries);
71   if (lko->flags & L4_kernel_options::F_out_buf)
72     printf("Out bufs: %d\n", lko->out_buf);
73
74   if (lko->jdb_cmd[0])
75     printf("JDB command: %s\n", lko->jdb_cmd);
76 }
77
78 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
79
80 void kcmdline_parse(char const *cmdline,
81                     L4_kernel_options::Options *lko)
82 {
83   if (0)
84     printf("Kernel command-line: %s\n", cmdline);
85
86   // boolean options
87   for (unsigned i = 0; i < ARRAY_SIZE(boolean_opts); ++i)
88     if (strstr(cmdline, boolean_opts[i].s))
89       lko->flags |= boolean_opts[i].flag;
90
91   // integer options
92   for (unsigned i = 0; i < ARRAY_SIZE(unsigned_opts); ++i)
93     {
94       char *c;
95       unsigned len = strlen(unsigned_opts[i].s);
96       if ((c = strstr(cmdline, unsigned_opts[i].s))
97           && (c[len] == ' ' || c[len] == '='))
98         {
99           lko->flags |= unsigned_opts[i].flag;
100           *(unsigned *)((char *)lko + unsigned_opts[i].offset)
101             = strtol(c + len + 1, 0, 0);
102         }
103     }
104
105   // string options
106   for (unsigned i = 0; i < ARRAY_SIZE(string_opts); ++i)
107     {
108       char *c;
109       unsigned len = strlen(string_opts[i].s);
110       if ((c = strstr(cmdline, string_opts[i].s))
111           && (c[len] == ' ' || c[len] == '='))
112         {
113           char *dst = (char *)lko + string_opts[i].offset;
114           lko->flags |= string_opts[i].flag;
115           c += len + 1;
116           while (*c && *c != ' '
117                  && (dst < (char *)lko + string_opts[i].offset +
118                             string_opts[i].size - 1))
119             *dst++ = *c++;
120           *dst = 0;
121         }
122     }
123
124   // warnings
125   if (strstr(cmdline, "-comport")
126       || strstr(cmdline, "-comspeed")
127       || strstr(cmdline, "-comirq"))
128     printf("WARNING: Command line options -comport, -comspeed and -comirq\n"
129            "         have been moved to bootstrap and are shared beetween\n"
130            "         Fiasco and bootstrap now. Please remove them from\n"
131            "         your Fiasco command line, they do not have an effect\n"
132            "         there.\n");
133
134   if (0)
135     kcmdline_show(lko);
136 }