]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sbin/kget/kget.c
This commit was generated by cvs2svn to compensate for changes in r56083,
[FreeBSD/FreeBSD.git] / sbin / kget / kget.c
1 /*-
2  * Copyright (c) 1999 Andrzej Bialecki <abial@freebsd.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28
29 #include <stdio.h>
30 #include <string.h>
31 #include <sys/types.h>
32 #include <sys/sysctl.h>
33 #include <isa/isa_device.h>
34 #if 0
35 #include <isa/pnp.h>
36 #endif
37
38 struct isa_device *id;
39 struct pnp_cinfo *c;
40 char *p;
41
42 int
43 main(int argc, char *argv[])
44 {
45         int len,i;
46         char *buf;
47         char *mib1="machdep.uc_devlist";
48         char *mib2="machdep.uc_pnplist";
49         char name[9];
50         FILE *fout;
51
52         if(argc<2) {
53                 fout=stdout;
54         } else {
55                 if(strcmp(argv[1],"-")==0) {
56                         fout=stdout;
57                 } else {
58                         fout=fopen(argv[1],"w");
59                         if(fout==NULL) {
60                                 perror("opening output file");
61                                 exit(1);
62                         }
63                 }
64         }
65
66         /* We use sysctlbyname, because the oid is unknown (OID_AUTO) */
67
68         /* First, print the changes made to ISA devices */
69         /* get the buffer size */
70         i=sysctlbyname(mib1,NULL,&len,NULL,NULL);
71         if(i) {
72                 perror("buffer sizing");
73                 exit(-1);
74         }
75         buf=(char *)malloc(len*sizeof(char));
76         i=sysctlbyname(mib1,buf,&len,NULL,NULL);
77         if(i) {
78                 perror("retrieving data");
79                 exit(-1);
80         }
81         i=0;
82         while(i<len) {
83                 id=(struct isa_device *)(buf+i);
84                 p=(buf+i+sizeof(struct isa_device));
85                 strncpy(name,p,8);
86                 if(!id->id_enabled) {
87                         fprintf(fout,"di %s%d\n",name,id->id_unit);
88                 } else {
89                         fprintf(fout,"en %s%d\n",name,id->id_unit);
90                         if(id->id_iobase>0) {
91                                 fprintf(fout,"po %s%d %#x\n",name,id->id_unit,
92                                         id->id_iobase);
93                         }
94                         if(id->id_irq>0) {
95                                 fprintf(fout,"ir %s%d %d\n",name,id->id_unit,
96                                         ffs(id->id_irq)-1);
97                         }
98                         if(id->id_drq>0) {
99                                 fprintf(fout,"dr %s%d %d\n",name,id->id_unit,
100                                         id->id_drq);
101                         }
102                         if(id->id_maddr>0) {
103                                 fprintf(fout,"iom %s%d %#x\n",name,id->id_unit,
104                                         id->id_maddr);
105                         }
106                         if(id->id_msize>0) {
107                                 fprintf(fout,"ios %s%d %d\n",name,id->id_unit,
108                                         id->id_msize);
109                         }
110                         fprintf(fout,"f %s%d %#x\n",name,id->id_unit,
111                                 id->id_flags);
112                 }
113                 i+=sizeof(struct isa_device)+8;
114         }
115         free(buf);
116 #if 0
117         /* Now, print the changes to PnP override table */
118         /* get the buffer size */
119         i=sysctlbyname(mib2,NULL,&len,NULL,NULL);
120         if(i) {
121                 /* Hmm.. No PnP table? */
122                 goto finish;
123         }
124         buf=(char *)malloc(len*sizeof(char));
125         i=sysctlbyname(mib2,buf,&len,NULL,NULL);
126         if(i) {
127                 perror("retrieving data");
128                 exit(-1);
129         }
130         i=0;
131         /* Print the PnP override table. Taken from userconfig.c */
132         do {
133                 c = (struct pnp_cinfo *)(buf+i);
134                 if (c->csn >0 && c->csn != 255) {
135                         int pmax, mmax;
136                         char buf1[256];
137
138                         if(c->enable==0) {
139                                 fprintf(fout,"pnp %d %d disable\n",
140                                         c->csn, c->ldn);
141                                 continue;
142                         }
143                         fprintf(fout,"pnp %d %d %s irq0 %d irq1 %d drq0 %d drq1 %d",
144                                 c->csn, c->ldn,
145                                 c->override ? "os":"bios",
146                                 c->irq[0], c->irq[1], c->drq[0], c->drq[1]);
147                         if (c->flags)
148                                 fprintf(fout," flags 0x%lx",c->flags);
149                         pmax=0;
150                         while(c->port[pmax]!=0 && pmax<8) {
151                                 fprintf(fout," port%d %d",pmax,c->port[pmax]);
152                                 pmax++;
153                         }
154                         mmax=0;
155                         while(c->mem[mmax].base!=0 && mmax<8) {
156                                 fprintf(fout," mem%d %d",mmax,c->mem[mmax].base);
157                                 mmax++;
158                         }
159                         fprintf(fout,"\n");
160                 }
161
162         } while ((i+=sizeof(struct pnp_cinfo))<len);
163         free(buf);
164 #endif
165 finish:
166         fprintf(fout,"q\n");
167         fclose(fout);
168         exit(0);
169 }