dmesgから認識しているデバイスの木構造を表示する。
あまりちゃんと内容確認してないんで例によってバグは愛嬌。
vm-evalをよりそれらしく変更。cut-sea:2006/03/27 04:08:39 PST
そうか。vm-evalがデフォルトで色々やりすぎるのは自由度を奪うのだ。
本来レジスタを用意したらプログラム側でいじれるべきで、
それはここでは、いじろうといじるまいとvaluesで全部返させることと同義だね。
それを色々いじると出力をもっと変えることも出来るハズ。
逆に自由度を犠牲にして全部裏方でやってやれば汎用性はなくなるが、
簡単なプログラムで機能を実現できると。実に当たり前ですが。
どっちに振るかだけど、今のコードからcont(続きのcode)も解放すれば、
自分で制御できるようになるワケだ。
逆に前バージョンでは意味もなくstackレジスタだけ解放してたけど、
これだけだと意味はない。そこまでやるならスタックも裏で処理させるのがいい。
それなりにレジスタを解放するか、ほとんど全く解放しないかですな。cut-sea:2006/03/28 07:44:27 PST
#! /usr/bin/env gosh
(use srfi-1)
(use gauche.process)
(define-syntax where
(syntax-rules ()
((_ (proc v1 ...) e1 ...)
(letrec ((v1 e1) ...) (proc v1 ...)))))
(define (analysis-dmesg)
;; utility
(define (racons asc a d)
(append asc (list (cons a d))))
(define (rcons lst item)
(append lst (list item)))
;; special utility
(define (branch stack rest)
(define (end? p)
(if (assoc p rest) #f #t))
(cons #t
(fold (lambda (p s)
(cons (end? p) s)) '() stack)))
(define (indent n dev br)
(if (= n 0)
(format #t (if (car br) "`-- ~a~%" "|-- ~a~%") dev)
(begin
(format #t (if (car br) " " "| "))
(indent (- n 1) dev (cdr br)))))
;; hierarchic sort
(define (hierarchic-sort pairs)
(define (sort pairs)
(define (insert item sorted)
(receive (prev rest)
(span (lambda (p)
(not (equal? (cdr p) (car item))))
sorted)
(receive (same post)
(span (lambda (p)
(equal? (cdr p) (car item)))
rest)
(append prev same (list item) post))))
(fold (lambda (elm sorted) (insert elm sorted)) '() pairs))
(sort (sort pairs)))
;; virtual machine
(define (vm-eval proc parent child flag stack code)
(or (null? code)
(let1 cont (cdr code)
(receive (pa ch flg st)
(where (proc p c flg s b eb)
(caar code) (cdar code)
(member p stack) (or flg '())
(branch s cont) (branch (cons p s) cont))
(vm-eval proc pa ch flg st cont)))))
;; dmesg string lines to parent&child assoc list
(define (dmesg->pairs)
(define (depend-pair ln seed)
(cond ((#/^(\w+):?[ \t]+at[ \t](\w+):?/ ln)
=> (lambda (m) (racons seed (m 2) (m 1))))
(else seed)))
(fold depend-pair '() (process-output->string-list "/sbin/dmesg")))
;; main eval loop
;; you can use parent/child/flag/stack register in lambda program.
;; but branch/extrabranch register is read only.
(vm-eval (lambda (p c flg st br eb)
(if flg
(begin
(indent (length st) c br)
(values p c flg (cons c st)))
(begin
(indent 0 p br) (indent 1 c eb)
(values p c flg (list c p)))))
#f #f #f '() (hierarchic-sort (dmesg->pairs))))
(define (main . args)
(analysis-dmesg))
NetBSD 2.0.2 (NKISI) #1: Mon Aug 29 22:46:45 JST 2005
cut-sea@nkisi:/sys/arch/i386/compile/NKISI
total memory = 479 MB
avail memory = 461 MB
BIOS32 rev. 0 found at 0xf0010
mainbus0 (root)
cpu0 at mainbus0: (uniprocessor)
cpu0: AMD Unknown K7 (Athlon) (686-class), 1603.74 MHz, id 0x10fc0
cpu0: features 78bfbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR>
cpu0: features 78bfbff<PGE,MCA,CMOV,PAT,PSE36,MPC,MMX>
cpu0: features 78bfbff<FXSR,SSE,SSE2>
pci0 at mainbus0 bus 0: configuration mode 1
pci0: i/o space, memory space enabled, rd/line, rd/mult, wr/inv ok
pchb0 at pci0 dev 0 function 0
pchb0: VIA Technologies product 0x0204 (rev. 0x00)
agp0 at pchb0: aperture at 0xd0000000, size 0xf600000
pchb1 at pci0 dev 0 function 1
pchb1: VIA Technologies product 0x1204 (rev. 0x00)
pchb2 at pci0 dev 0 function 2
pchb2: VIA Technologies product 0x2204 (rev. 0x00)
pchb3 at pci0 dev 0 function 3
pchb3: VIA Technologies product 0x3204 (rev. 0x00)
pchb4 at pci0 dev 0 function 4
pchb4: VIA Technologies product 0x4204 (rev. 0x00)
pchb5 at pci0 dev 0 function 7
pchb5: VIA Technologies product 0x7204 (rev. 0x00)
ppb0 at pci0 dev 1 function 0: VIA Technologies product 0xb188 (rev. 0x00)
pci1 at ppb0 bus 1
pci1: i/o space, memory space enabled
vga1 at pci1 dev 0 function 0: VIA Technologies product 0x3108 (rev. 0x01)
wsdisplay0 at vga1 kbdmux 1: console (80x25, vt100 emulation)
wsmux1: connecting to wsdisplay0
cbb0 at pci0 dev 10 function 0: ENE Technology, Inc. CB1410 Cardbus Controller (rev. 0x01)
uhci0 at pci0 dev 16 function 0: VIA Technologies VT83C572 USB Controller (rev. 0x80)
uhci0: interrupting at irq 10
usb0 at uhci0: USB revision 1.0
uhub0 at usb0
uhub0: VIA Technologies UHCI root hub, class 9/0, rev 1.00/1.00, addr 1
uhub0: 2 ports with 2 removable, self powered
uhci1 at pci0 dev 16 function 1: VIA Technologies VT83C572 USB Controller (rev. 0x80)
uhci1: interrupting at irq 3
usb1 at uhci1: USB revision 1.0
uhub1 at usb1
uhub1: VIA Technologies UHCI root hub, class 9/0, rev 1.00/1.00, addr 1
uhub1: 2 ports with 2 removable, self powered
uhci2 at pci0 dev 16 function 2: VIA Technologies VT83C572 USB Controller (rev. 0x80)
uhci2: interrupting at irq 11
usb2 at uhci2: USB revision 1.0
uhub2 at usb2
uhub2: VIA Technologies UHCI root hub, class 9/0, rev 1.00/1.00, addr 1
uhub2: 2 ports with 2 removable, self powered
ehci0 at pci0 dev 16 function 3: VIA Technologies VT8237 EHCI USB Controller (rev. 0x82)
ehci0: interrupting at irq 5
ehci0: EHCI version 1.0
ehci0: companion controllers, 2 ports each: uhci0 uhci1 uhci2
usb3 at ehci0: USB revision 2.0
uhub3 at usb3
uhub3: VIA Technologie EHCI root hub, class 9/0, rev 2.00/1.00, addr 1
uhub3: 6 ports with 6 removable, self powered
pcib0 at pci0 dev 17 function 0
pcib0: VIA Technologies VT8235 (Apollo KT400) PCI-ISA Bridge (rev. 0x00)
viaide0 at pci0 dev 17 function 1
viaide0: VIA Technologies VT8235 ATA133 controller
viaide0: bus-master DMA support present
viaide0: primary channel configured to compatibility mode
viaide0: primary channel interrupting at irq 14
atabus0 at viaide0 channel 0
viaide0: secondary channel configured to compatibility mode
viaide0: secondary channel interrupting at irq 15
atabus1 at viaide0 channel 1
auvia0 at pci0 dev 17 function 5: VIA VT8235 AC'97 (rev 0x50)
auvia0: interrupting at irq 11
auvia0: ac97: VIA Technologies unknown (0x56494170) codec; headphone, 18 bit DAC, 18 bit ADC, KS Waves 3D
auvia0: ac97: ext id 9c3<AC97_23,LDAC,SDAC,CDAC,DRA,VRA>
audio0 at auvia0: full duplex, mmap, independent
VIA Technologies VT82C686A MC-97 Modem Controller (miscellaneous communications, revision 0x80) at pci0 dev 17 function 6 not configured
vr0 at pci0 dev 18 function 0: VIA VT6102 (Rhine II) 10/100 Ethernet
vr0: interrupting at irq 11
vr0: Ethernet address: **:**:**:**:**:**
ukphy0 at vr0 phy 1: Generic IEEE 802.3u media interface
ukphy0: OUI 0x0002c6, model 0x0032, rev. 10
ukphy0: 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, auto
pchb6 at pci0 dev 24 function 0
pchb6: Advanced Micro Devices AMD64 HyperTransport configuration (rev. 0x00)
pchb7 at pci0 dev 24 function 1
pchb7: Advanced Micro Devices AMD64 Address Map configuration (rev. 0x00)
pchb8 at pci0 dev 24 function 2
pchb8: Advanced Micro Devices AMD64 DRAM configuration (rev. 0x00)
pchb9 at pci0 dev 24 function 3
pchb9: Advanced Micro Devices AMD64 Miscellaneous configuration (rev. 0x00)
cbb0: interrupting at irq 11
cardslot0 at cbb0 slot 0 flags 0
cardbus0 at cardslot0: bus 2 device 0
pcmcia0 at cardslot0
isa0 at pcib0
pckbc0 at isa0 port 0x60-0x64
pckbd0 at pckbc0 (kbd slot)
pckbc0: using irq 1 for kbd slot
wskbd0 at pckbd0: console keyboard, using wsdisplay0
pms0 at pckbc0 (aux slot)
pckbc0: using irq 12 for aux slot
wsmouse0 at pms0 mux 0
pcppi0 at isa0 port 0x61
midi0 at pcppi0: PC speaker
sysbeep0 at pcppi0
isapnp0 at isa0 port 0x279: ISA Plug 'n Play device support
npx0 at isa0 port 0xf0-0xff: using exception 16
isapnp0: no ISA Plug 'n Play devices found
Kernelized RAIDframe activated
wd0 at atabus0 drive 0: <FUJITSU MHT2040AT>
wd0: drive supports 16-sector PIO transfers, LBA addressing
wd0: 38154 MB, 77520 cyl, 16 head, 63 sec, 512 bytes/sect x 78140160 sectors
wd0: 32-bit data port
wd0: drive supports PIO mode 4, DMA mode 2, Ultra-DMA mode 5 (Ultra/100)
wd0(viaide0:0:0): using PIO mode 4, Ultra-DMA mode 5 (Ultra/100) (using DMA data transfers)
atapibus0 at atabus1: 2 targets
cd0 at atapibus0 drive 0: <Slimtype COMBO SOSC-2483K, , KK0A> cdrom removable
cd0: 32-bit data port
cd0: drive supports PIO mode 4, DMA mode 2, Ultra-DMA mode 2 (Ultra/33)
cd0(viaide0:1:0): using PIO mode 4, Ultra-DMA mode 2 (Ultra/33) (using DMA data transfers)
ral0 at cardbus0 dev 0 function 0
ral0: 802.11 address **:**:**:**:**:**
ral0: MAC/BBP RT2560 (rev 0x04), RF RT2525
ral0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
ral0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps
boot device: wd0
root on wd0a dumps on wd0b
uhidev0 at uhub0 port 2 configuration 1 interface 0
uhidev0: Acrox USB & PS/2 Mouse, rev 1.10/0.01, addr 2, iclass 3/1
ums0 at uhidev0: 5 buttons and Z dir.
wsmouse1 at ums0 mux 0
root file system type: ffs
uhub4 at uhub1 port 1
uhub4: Chicony Generic USB Hub, class 9/0, rev 1.10/1.00, addr 2
uhub4: 3 ports with 2 removable, bus powered
uhidev1 at uhub4 port 1 configuration 1 interface 0
uhidev1: Chicony PFU-65 USB Keyboard, rev 1.10/1.00, addr 3, iclass 3/1
ukbd0 at uhidev1
wskbd1 at ukbd0 mux 1
wskbd1: connecting to wsdisplay0
wsdisplay0: screen 1 added (80x25, vt100 emulation)
wsdisplay0: screen 2 added (80x25, vt100 emulation)
wsdisplay0: screen 3 added (80x25, vt100 emulation)
wsdisplay0: screen 4 added (80x25, vt100 emulation)
ral0: interrupting at 11
`-- mainbus0
+-- cpu0
`-- pci0
+-- pchb0
| `-- agp0
+-- pchb1
+-- pchb2
+-- pchb3
+-- pchb4
+-- pchb5
+-- ppb0
| `-- pci1
| `-- vga1
| `-- wsdisplay0
+-- cbb0
| `-- cardslot0
| +-- cardbus0
| | `-- ral0
| `-- pcmcia0
+-- uhci0
| `-- usb0
| `-- uhub0
| `-- uhidev0
| `-- ums0
| `-- wsmouse1
+-- uhci1
| `-- usb1
| `-- uhub1
| `-- uhub4
| `-- uhidev1
| `-- ukbd0
| `-- wskbd1
+-- uhci2
| `-- usb2
| `-- uhub2
+-- ehci0
| `-- usb3
| `-- uhub3
+-- pcib0
| `-- isa0
| +-- pckbc0
| | +-- pckbd0
| | | `-- wskbd0
| | `-- pms0
| | `-- wsmouse0
| +-- pcppi0
| | +-- midi0
| | `-- sysbeep0
| +-- isapnp0
| `-- npx0
+-- viaide0
| +-- atabus0
| | `-- wd0
| `-- atabus1
| `-- atapibus0
| `-- cd0
+-- auvia0
| `-- audio0
+-- vr0
| `-- ukphy0
+-- pchb6
+-- pchb7
+-- pchb8
`-- pchb9