PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/sys/boot/forth/pnp.4th

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