FreeBSD/Linux Kernel Cross Reference
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.3 2009/01/05 20:09:54 luigi Exp $
26
27
28 \ The following pnp code is used in pnp.4th and pnp.c
29 structure: STAILQ_HEAD
30 ptr stqh_first \ type*
31 ptr stqh_last \ type**
32 ;structure
33
34 structure: STAILQ_ENTRY
35 ptr stqe_next \ type*
36 ;structure
37
38 structure: pnphandler
39 ptr pnph.name
40 ptr pnph.enumerate
41 ;structure
42
43 structure: pnpident
44 ptr pnpid.ident \ char*
45 sizeof STAILQ_ENTRY cells member: pnpid.link \ pnpident
46 ;structure
47
48 structure: pnpinfo \ sync with sys/boot/config/bootstrap.h
49 ptr pnpi.desc
50 int pnpi.revision
51 ptr pnpi.module \ (char*) module args
52 int pnpi.argc
53 ptr pnpi.argv
54 ptr pnpi.handler \ pnphandler
55 sizeof STAILQ_HEAD member: pnpi.ident \ pnpident
56 sizeof STAILQ_ENTRY member: pnpi.link \ pnpinfo
57 ;structure
58 \ end of pnp support
59
60 pnpdevices drop
61
62 : enumerate
63 pnphandlers begin
64 dup @
65 while
66 ." Probing " dup @ pnph.name @ dup strlen type ." ..." cr
67 0 over @ pnph.enumerate @ ccall drop
68 cell+
69 repeat
70 ;
71
72 : summary
73 ." PNP scan summary:" cr
74 pnpdevices stqh_first @
75 begin
76 dup
77 while
78 dup pnpi.ident stqh_first @ pnpid.ident @ dup strlen type
79 dup pnpi.desc @ ?dup if
80 ." : "
81 dup strlen type
82 then
83 cr
84 pnpi.link stqe_next @
85 repeat
86 drop
87 ;
88
89 : compare-pnpid ( addr addr' -- flag )
90 begin
91 over c@ over c@ <> if drop drop false exit then
92 over c@ over c@ and
93 while
94 char+ swap char+ swap
95 repeat
96 c@ swap c@ or 0=
97 ;
98
99 : search-pnpid ( id -- flag )
100 >r
101 pnpdevices stqh_first @
102 begin ( pnpinfo )
103 dup
104 while
105 dup pnpi.ident stqh_first @
106 begin ( pnpinfo pnpident )
107 dup pnpid.ident @ r@ compare-pnpid
108 if
109 r> drop
110 \ XXX Temporary debugging message
111 ." Found " pnpid.ident @ dup strlen type
112 pnpi.desc @ ?dup if
113 ." : " dup strlen type
114 then cr
115 \ drop drop
116 true
117 exit
118 then
119 pnpid.link stqe_next @
120 ?dup 0=
121 until
122 pnpi.link stqe_next @
123 repeat
124 r> drop
125 drop
126 false
127 ;
128
129 : skip-space ( addr -- addr' )
130 begin
131 dup c@ bl =
132 over c@ 9 = or
133 while
134 char+
135 repeat
136 ;
137
138 : skip-to-space ( addr -- addr' )
139 begin
140 dup c@ bl <>
141 over c@ 9 <> and
142 over c@ and
143 while
144 char+
145 repeat
146 ;
147
148 : premature-end? ( addr -- addr flag )
149 postpone dup postpone c@ postpone 0=
150 postpone if postpone exit postpone then
151 ; immediate
152
153 0 value filename
154 0 value timestamp
155 0 value id
156
157 only forth also support-functions
158
159 : (load) load ;
160
161 : check-pnpid ( -- )
162 line_buffer .addr @
163 \ Search for filename
164 skip-space premature-end?
165 dup to filename
166 \ Search for end of filename
167 skip-to-space premature-end?
168 0 over c! char+
169 \ Search for timestamp
170 skip-space premature-end?
171 dup to timestamp
172 skip-to-space premature-end?
173 0 over c! char+
174 \ Search for ids
175 begin
176 skip-space premature-end?
177 dup to id
178 skip-to-space dup c@ >r
179 0 over c! char+
180 id search-pnpid if
181 filename dup strlen 1 ['] (load) catch if
182 drop drop drop
183 ." Error loading " filename dup strlen type cr
184 then
185 r> drop exit
186 then
187 r> 0=
188 until
189 ;
190
191 : load-pnp
192 0 to end_of_file?
193 reset_line_reading
194 s" /boot/pnpid.conf" O_RDONLY fopen fd !
195 fd @ -1 <> if
196 begin
197 end_of_file? 0=
198 while
199 read_line
200 check-pnpid
201 repeat
202 fd @ fclose
203 then
204 ;
205
Cache object: e72cfe02104ac82ec98eda79bc833cf5
|