1 #! /usr/bin/awk -f
2 #
3 # This is a transition aid. It extracts old-style configuration information
4 # from a config file and writes an equivalent device.hints file to stdout.
5 # You can use that with loader(8) or statically compile it in with the
6 # 'hints' directive. See how GENERIC and GENERIC.hints fit together for
7 # a static example. You should use loader(8) if at all possible.
8 #
9 # $FreeBSD$
10
11 # skip commented lines, empty lines and not "device" lines
12 /^[ \t]*#/ || /^[ \t]*$/ || !/[ \t]*device/ { next; }
13
14 # input format :
15 # device <name><unit> at <controler>[?] [key [val]]...
16 # possible keys are :
17 # disable, port #, irq #, drq #, drive #, iomem #, iosiz #,
18 # flags #, bus #, target #, unit #.
19 # output format :
20 # hint.<name>.<unit>.<key>=<val>
21 # mapped keys are :
22 # iomem -> maddr, iosiz -> msize.
23 {
24 gsub ("#.*", ""); # delete comments
25 gsub ("\"", ""); # and double-quotes
26 nameunit = $2; # <name><unit>
27 at = $3; # at
28 controler = $4; # <controler>[?]
29 rest = 5; # optional keys begin at indice 5
30 if (at != "at" || controler == "")
31 next; # skip devices w/o controlers
32 name = nameunit;
33 sub ("[0-9]*$", "", name); # get the name
34 unit = nameunit;
35 sub ("^" name, "", unit); # and the unit
36 sub ("\?$", "", controler);
37 printf "hint.%s.%s.at=\"%s\"\n", name, unit, controler;
38 # for each keys, if any ?
39 for (key = $rest; rest <= NF; key = $(++rest)) {
40 # skip auto-detect keys (the one w/ a ?)
41 if (key == "port?" || key == "drq?" || key == "irq?" || \
42 key == "iomem?" || key == "iosiz?")
43 continue;
44 # disable has no value, so, give it one
45 if (key == "disable") {
46 printf "hint.%s.%s.disabled=\"1\"\n", name, unit;
47 continue;
48 }
49 # recognized keys
50 if (key == "port" || key == "irq" || key == "drq" || \
51 key == "drive" || key == "iomem" || key == "iosiz" || \
52 key == "flags" || key == "bus" || key == "target" || \
53 key == "unit") {
54 val = $(++rest);
55 if (val == "?") # has above
56 continue;
57 if (key == "port") {
58 # map port macros to static values
59 sub ("IO_AHA0", "0x330", val);
60 sub ("IO_AHA1", "0x334", val);
61 sub ("IO_ASC1", "0x3EB", val);
62 sub ("IO_ASC2", "0x22B", val);
63 sub ("IO_ASC3", "0x26B", val);
64 sub ("IO_ASC4", "0x2AB", val);
65 sub ("IO_ASC5", "0x2EB", val);
66 sub ("IO_ASC6", "0x32B", val);
67 sub ("IO_ASC7", "0x36B", val);
68 sub ("IO_ASC8", "0x3AB", val);
69 sub ("IO_BT0", "0x330", val);
70 sub ("IO_BT1", "0x334", val);
71 sub ("IO_CGA", "0x3D0", val);
72 sub ("IO_COM1", "0x3F8", val);
73 sub ("IO_COM2", "0x2F8", val);
74 sub ("IO_COM3", "0x3E8", val);
75 sub ("IO_COM4", "0x2E8", val);
76 sub ("IO_DMA1", "0x000", val);
77 sub ("IO_DMA2", "0x0C0", val);
78 sub ("IO_DMAPG", "0x080", val);
79 sub ("IO_FD1", "0x3F0", val);
80 sub ("IO_FD2", "0x370", val);
81 sub ("IO_GAME", "0x201", val);
82 sub ("IO_GSC1", "0x270", val);
83 sub ("IO_GSC2", "0x2E0", val);
84 sub ("IO_GSC3", "0x370", val);
85 sub ("IO_GSC4", "0x3E0", val);
86 sub ("IO_ICU1", "0x020", val);
87 sub ("IO_ICU2", "0x0A0", val);
88 sub ("IO_KBD", "0x060", val);
89 sub ("IO_LPT1", "0x378", val);
90 sub ("IO_LPT2", "0x278", val);
91 sub ("IO_LPT3", "0x3BC", val);
92 sub ("IO_MDA", "0x3B0", val);
93 sub ("IO_NMI", "0x070", val);
94 sub ("IO_NPX", "0x0F0", val);
95 sub ("IO_PMP1", "0x026", val);
96 sub ("IO_PMP2", "0x178", val);
97 sub ("IO_PPI", "0x061", val);
98 sub ("IO_RTC", "0x070", val);
99 sub ("IO_TIMER1", "0x040", val);
100 sub ("IO_TIMER2", "0x048", val);
101 sub ("IO_UHA0", "0x330", val);
102 sub ("IO_VGA", "0x3C0", val);
103 sub ("IO_WD1", "0x1F0", val);
104 sub ("IO_WD2", "0x170", val);
105 } else {
106 # map key names
107 sub ("iomem", "maddr", key);
108 sub ("iosiz", "msize", key);
109 }
110 printf "hint.%s.%s.%s=\"%s\"\n", name, unit, key, val;
111 continue;
112 }
113 printf ("unrecognized config token '%s:%s' on line %s\n",
114 rest, key, NR); # > "/dev/stderr";
115 }
116 }
Cache object: 0ac712de39f77c57e113cd5f6edd8df5
|