Ticket #94: pci-header.awk

File pci-header.awk, 5.7 KB (added by johndrinkwater, 19 years ago)

A new version, doesnt require pipe usage

Line 
1# Clean PCI header script
2#
3# Copyright 2006, Haiku.
4# Distributed under the terms of the MIT License.
5#
6# Authors:
7# John Drinkwater, john@nextraweb.com
8#
9# Use with http://pciids.sourceforge.net/pci.ids
10# run as: awk -v HEADERFILE=pcihdr.h -f pci-header.awk pci.ids
11
12BEGIN {
13 FS = " "
14 ofile = HEADERFILE
15 print "#if 0" > ofile
16 print "#\tPCIHDR.H: PCI Vendors, Devices, and Class Type information\n#" > ofile
17 print "#\tGenerated by pci-clean, sourced from the web at the following URL:\n#\thttp://pciids.sourceforge.net/pci.ids\n#" > ofile
18 print "#\tHeader created on " strftime( "%A, %d %b %Y %H:%M:%S %Z", systime() ) > ofile
19 print "#endif" > ofile
20
21 print "\ntypedef struct _PCI_VENTABLE\n{\n\tunsigned short\tVenId ;\n\tchar *\tVenFull ;\n} PCI_VENTABLE, *PPCI_VENTABLE ;\n" > ofile
22 print "PCI_VENTABLE\tPciVenTable [] =\n{" > ofile
23
24}
25
26# matches vendor - starts with an id as first thing on the line
27/^[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]] / {
28 if ( vendor++ > 0 ) { a = ",\n" } else { a = "" }
29 vend = substr($0, 7); gsub( /\"/, "\\\"", vend )
30 printf a "\t{ 0x" $1 ", \"" vend "\" }" > ofile
31 # store vendor ID for possible devices afterwards
32 currentVendor = $1
33}
34
35# matches device
36/^\t[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]] / {
37
38 device = substr($0, 8); gsub( /\"/, "\\\"", device )
39 devicecount++
40 devices[devicecount, 1] = currentVendor
41 devices[devicecount, 2] = $1
42 devices[devicecount, 3] = device
43}
44
45# matches subvendor device
46/^\t\t[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]] / {
47
48 device = substr($0, 14); gsub( /\"/, "\\\"", device )
49 devicecount++
50 devices[devicecount, 1] = $1
51 devices[devicecount, 2] = $2
52 devices[devicecount, 3] = device
53}
54
55# match device class - store data for later
56/^C [[:xdigit:]][[:xdigit:]] / {
57 class = $2
58 classdes = substr($0, 7); gsub( /\"/, "\\\"", classdes )
59}
60
61# match subclass, use device class data captured earlier, and output
62/^\t[[:xdigit:]][[:xdigit:]] / {
63 # if ( currentclass != class) { classes = classes "\n"; currentclass = class }
64 subclassdes = substr($0, 6); gsub( /\"/, "\\\"", subclassdes )
65 subclass = $1
66 classcount++;
67 classes[classcount, 1] = class
68 classes[classcount, 2] = subclass
69 classes[classcount, 3] = "00"
70 classes[classcount, 4] = classdes
71 classes[classcount, 5] = subclassdes
72 classes[classcount, 6] = ""
73}
74
75# match programming interface
76/^\t\t[[:xdigit:]][[:xdigit:]] / {
77 #if ( $1 != "00" ) {
78 #if ( length(classes) > 0 ) classes = classes ",\n"
79 progif = substr($0, 7); gsub( /\"/, "\\\"", progif )
80
81 classcount++;
82 classes[classcount, 1] = class
83 classes[classcount, 2] = subclass
84 classes[classcount, 3] = $1
85 classes[classcount, 4] = classdes
86 classes[classcount, 5] = subclassdes
87 classes[classcount, 6] = progif
88 #}
89}
90
91# We've processed the file, now output.
92END {
93
94 print "\n};\n\n// Use this value for loop control during searching:\n#define\tPCI_VENTABLE_LEN\t(sizeof(PciVenTable)/sizeof(PCI_VENTABLE))\n" > ofile
95
96 if ( devicecount > 0 ) {
97
98 print "typedef struct _PCI_DEVTABLE\n{\n\tunsigned short VenId ;\n\tunsigned short DevId ;\n\tchar *\tChipDesc ;\n} PCI_DEVTABLE, *PPCI_DEVTABLE ;\n" > ofile
99 print "PCI_DEVTABLE\tPciDevTable [] =\n{" > ofile
100 for (i = 1; i <= devicecount; i++) {
101 if (i != 1) { a = ",\n" } else { a = "" }
102 printf a "\t{ 0x" devices[i, 1] ", 0x" devices[i, 2] ", \"" devices[i, 3] "\" }" > ofile
103 }
104 print "\n} ;\n\n// Use this value for loop control during searching:\n#define PCI_DEVTABLE_LEN (sizeof(PciDevTable)/sizeof(PCI_DEVTABLE))\n" > ofile
105
106 }
107
108 if ( classcount > 0 ) {
109 print "typedef struct _PCI_CLASSCODETABLE\n{\n\tunsigned char BaseClass ;\n\tunsigned char SubClass ;\n\tunsigned char ProgIf ;\n\tchar *\t\tBaseDesc ;\n\tchar *\t\tSubDesc ;\n\tchar *\t\tProgDesc ;\n} PCI_CLASSCODETABLE, *PPCI_CLASSCODETABLE ;\n" > ofile
110 print "PCI_CLASSCODETABLE PciClassCodeTable [] =\n{" > ofile
111 for (i = 1; i <= classcount; i++) {
112 if (i != 1) { a = ",\n" } else { a = "" }
113 if ( ( classes[i, 1] == classes[i+1, 1] ) && ( classes[i, 2] == classes[i+1, 2] ) && ( classes[i, 3] == classes[i+1, 3] ) ) {
114 } else {
115 printf a "\t{ 0x" classes[i, 1] ", 0x" classes[i, 2] ", 0x" classes[i, 3] ", \"" classes[i, 4] "\", \"" classes[i, 5] "\", \"" classes[i, 6] "\" }" > ofile
116 }
117 }
118 print "\n} ;\n\n// Use this value for loop control during searching:\n#define PCI_CLASSCODETABLE_LEN (sizeof(PciClassCodeTable)/sizeof(PCI_CLASSCODETABLE))\n" > ofile
119
120 }
121
122 print "char *\tPciCommandFlags [] =\n{\n\t\"I/O Access\",\n\t\"Memory Access\",\n\t\"Bus Mastering\",\n\t\"Special Cycles\",\n\t\"Memory Write & Invalidate\",\n\t\"Palette Snoop\",\n\t\"Parity Errors\",\n\t\"Wait Cycles\",\n\t\"System Errors\",\n\t\"Fast Back-To-Back\",\n\t\"Reserved 10\",\n\t\"Reserved 11\",\n\t\"Reserved 12\",\n\t\"Reserved 13\",\n\t\"Reserved 14\",\n\t\"Reserved 15\"\n} ;\n" > ofile
123 print "// Use this value for loop control during searching:\n#define PCI_COMMANDFLAGS_LEN (sizeof(PciCommandFlags)/sizeof(char *))\n" > ofile
124 print "char *\tPciStatusFlags [] =\n{\n\t\"Reserved 0\",\n\t\"Reserved 1\",\n\t\"Reserved 2\",\n\t\"Reserved 3\",\n\t\"Reserved 4\",\n\t\"66 MHz Capable\",\n\t\"User-Defined Features\",\n\t\"Fast Back-To-Back\",\n\t\"Data Parity Reported\",\n\t\"\",\n\t\"\",\n\t\"Signalled Target Abort\",\n\t\"Received Target Abort\",\n\t\"Received Master Abort\",\n\t\"Signalled System Error\",\n\t\"Detected Parity Error\"\n} ;\n" > ofile
125 print "// Use this value for loop control during searching:\n#define PCI_STATUSFLAGS_LEN (sizeof(PciStatusFlags)/sizeof(char *))\n" > ofile
126 print "char *\tPciDevSelFlags [] =\n{\n\t\"Fast Devsel Speed\",\n\t\"Medium Devsel Speed\",\n\t\"Slow Devsel Speed\",\n\t\"Reserved 9&10\"\n} ;\n" > ofile
127 print "// Use this value for loop control during searching:\n#define PCI_DEVSELFLAGS_LEN (sizeof(PciDevSelFlags)/sizeof(char *))\n\n" > ofile
128
129}
130
131