Merge from vendor branch BIND:
[dragonfly.git] / sys / boot / forth / pnp.4th
1 \ Copyright (c) 2000 Daniel C. Sobral <dcs@freebsd.org>
2 \ All rights reserved.
3 \
4 \ Redistribution and use in source and binary forms, with or without
5 \ modification, are permitted provided that the following conditions
6 \ are met:
7 \ 1. Redistributions of source code must retain the above copyright
8 \    notice, this list of conditions and the following disclaimer.
9 \ 2. Redistributions in binary form must reproduce the above copyright
10 \    notice, this list of conditions and the following disclaimer in the
11 \    documentation and/or other materials provided with the distribution.
12 \
13 \ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 \ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 \ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 \ ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 \ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 \ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 \ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 \ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 \ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 \ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 \ SUCH DAMAGE.
24 \
25 \ $FreeBSD: src/sys/boot/forth/pnp.4th,v 1.2 2001/12/11 00:49:34 jhb Exp $
26 \ $DragonFly: src/sys/boot/forth/pnp.4th,v 1.1 2003/11/10 06:08:34 dillon Exp $
27
28 pnpdevices drop
29
30 : enumerate
31   pnphandlers begin
32     dup @
33   while
34     ." Probing " dup @ pnph.name @ dup strlen type ." ..." cr
35     0 over @ pnph.enumerate @ ccall drop
36     cell+
37   repeat
38 ;
39
40 : summary
41   ." PNP scan summary:" cr
42   pnpdevices stqh_first @
43   begin
44     dup
45   while
46     dup pnpi.ident stqh_first @ pnpid.ident @ dup strlen type
47     dup pnpi.desc @ ?dup if
48       ."  : "
49       dup strlen type
50     then
51     cr
52     pnpi.link stqe_next @
53   repeat
54   drop
55 ;
56
57 : compare-pnpid ( addr addr' -- flag )
58   begin
59     over c@ over c@ <> if drop drop false exit then
60     over c@ over c@ and
61   while
62     char+ swap char+ swap
63   repeat
64   c@ swap c@ or 0=
65 ;
66
67 : search-pnpid  ( id -- flag )
68   >r
69   pnpdevices stqh_first @
70   begin ( pnpinfo )
71     dup
72   while
73     dup pnpi.ident stqh_first @
74     begin ( pnpinfo pnpident )
75       dup pnpid.ident @ r@ compare-pnpid
76       if
77         r> drop
78         \ XXX Temporary debugging message
79         ." Found " pnpid.ident @ dup strlen type
80         pnpi.desc @ ?dup if
81           ." : " dup strlen type
82         then cr
83         \ drop drop
84         true
85         exit
86       then
87       pnpid.link stqe_next @
88       ?dup 0=
89     until
90     pnpi.link stqe_next @
91   repeat
92   r> drop
93   drop
94   false
95 ;
96
97 : skip-space  ( addr -- addr' )
98   begin
99     dup c@ bl =
100     over c@ 9 = or
101   while
102     char+
103   repeat
104 ;
105
106 : skip-to-space  ( addr -- addr' )
107   begin
108     dup c@ bl <>
109     over c@ 9 <> and
110     over c@ and
111   while
112     char+
113   repeat
114 ;
115
116 : premature-end?  ( addr -- addr flag )
117   postpone dup postpone c@ postpone 0=
118   postpone if postpone exit postpone then
119 ; immediate
120
121 0 value filename
122 0 value timestamp
123 0 value id
124
125 only forth also support-functions
126
127 : (load) load ;
128
129 : check-pnpid  ( -- )
130   line_buffer .addr @ 
131   \ Search for filename
132   skip-space premature-end?
133   dup to filename
134   \ Search for end of filename
135   skip-to-space premature-end?
136   0 over c!  char+
137   \ Search for timestamp
138   skip-space premature-end?
139   dup to timestamp
140   skip-to-space premature-end?
141   0 over c!  char+
142   \ Search for ids
143   begin
144     skip-space premature-end?
145     dup to id
146     skip-to-space dup c@ >r
147     0 over c!  char+
148     id search-pnpid if
149       filename dup strlen 1 ['] (load) catch if
150         drop drop drop
151         ." Error loading " filename dup strlen type cr
152       then
153       r> drop exit
154     then
155     r> 0=
156   until
157 ;
158
159 : load-pnp
160   0 to end_of_file?
161   reset_line_reading
162   s" /boot/pnpid.conf" O_RDONLY fopen fd !
163   fd @ -1 <> if
164     begin
165       end_of_file? 0=
166     while
167       read_line
168       check-pnpid
169     repeat
170     fd @ fclose
171   then
172 ;
173