1 \ *****************************************************************************
2 \ * Copyright (c) 2004, 2011 IBM Corporation
3 \ * All rights reserved.
4 \ * This program and the accompanying materials
5 \ * are made available under the terms of the BSD License
6 \ * which accompanies this distribution, and is available at
7 \ * http://www.opensource.org/licenses/bsd-license.php
10 \ * IBM Corporation - initial implementation
11 \ ****************************************************************************/
19 false value eva-debug?
20 true value fcode-debug?
26 create token-table 2000 cells allot \ 1000h = 4096d
36 ' read-fcode# to fcode@
38 ( ---------------------------------------------------- )
40 : execute-rom-fcode ( addr len | false -- )
43 diagnostic-mode? IF ." , executing ..." cr THEN
44 dup >r r@ alloc-mem dup >r swap rmove
45 r@ set-ip evaluate-fcode
46 diagnostic-mode? IF ." Done." cr THEN
51 : rom-code-ignored ( image-addr name len -- image-addr )
53 type ." code found in image " dup . ." , ignoring ..." cr
59 : pci-find-rom ( baseaddr -- addr )
62 diagnostic-mode? IF ." Device ROM header found at " dup . cr THEN
69 : pci-find-fcode ( baseaddr -- addr len | false )
71 1ff NOT and \ Image must start at 512 byte boundary
74 dup 18 + rw@-le + ( pcir-addr )
75 \ Check for PCIR magic ... since pcir-addr might not be
76 \ 4-byte aligned, we've got to use two reads here:
77 dup rw@-le 4350 ( 'PC' ) <> ( pcir-addr hasPC? )
78 over 2+ rw@-le 5249 ( 'IR' ) <> OR IF
80 ." Invalid PCI Data structure, ignoring ROM contents" cr
84 dup 14 + rb@ CASE \ Get image code type
85 0 OF s" Intel x86 BIOS" rom-code-ignored ENDOF
88 ." Open Firmware FCode found in image at " dup . cr
90 dup 1ff NOT AND \ Back to the ROM image header
91 dup 2+ rw@-le + \ Pointer to FCODE (PCI bus binding ch.9)
92 swap 10 + rw@-le 200 * \ Image length
95 2 OF s" HP PA RISC" rom-code-ignored ENDOF
96 3 OF s" EFI" rom-code-ignored ENDOF
97 dup OF s" Unknown type" rom-code-ignored ENDOF
99 dup 15 + rb@ 80 and IF \ End of last image?
102 dup 10 + rw@-le 200 * + \ Next image start
107 \ Prepare and run a FCODE program from a PCI Option ROM.
108 : pci-execute-fcode ( baseaddr -- )
109 pci-find-fcode dup 0= IF
112 fc-set-pci-mmio-tokens \ Prepare PCI access functions
114 ['] execute-rom-fcode CATCH IF
115 cr ." FCODE failed!" cr
118 fc-set-normal-mmio-tokens \ Restore normal MMIO access functions