|
|
1.1 root 1: \ ***************************************************************************** 1.1.1.2 ! root 2: \ * Copyright (c) 2004, 2011 IBM Corporation 1.1 root 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 8: \ * 9: \ * Contributors: 10: \ * IBM Corporation - initial implementation 11: \ ****************************************************************************/ 12: 13: 14: variable ip 15: variable fcode-end 16: variable fcode-num 17: 1 value fcode-spread 1.1.1.2 ! root 18: 2 value fcode-offset 1.1 root 19: false value eva-debug? 1.1.1.2 ! root 20: true value fcode-debug? 1.1 root 21: defer fcode-rb@ 22: defer fcode@ 23: 24: ' c@ to fcode-rb@ 25: 26: create token-table 2000 cells allot \ 1000h = 4096d 27: 1.1.1.2 ! root 28: #include "core.fs" ! 29: #include "1275.fs" ! 30: #include "tokens.fs" ! 31: #include "locals.fs" 1.1 root 32: 33: 0 value buff 34: 0 value buff-size 35: 36: ' read-fcode# to fcode@ 37: 38: ( ---------------------------------------------------- ) 39: 1.1.1.2 ! root 40: : execute-rom-fcode ( addr len | false -- ) ! 41: reset-fcode-end ! 42: ?dup IF ! 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 ! 47: r> r> free-mem ! 48: THEN ! 49: ; ! 50: ! 51: : rom-code-ignored ( image-addr name len -- image-addr ) ! 52: diagnostic-mode? IF ! 53: type ." code found in image " dup . ." , ignoring ..." cr ! 54: ELSE ! 55: 2drop ! 56: THEN 1.1 root 57: ; 58: 59: : pci-find-rom ( baseaddr -- addr ) 1.1.1.2 ! root 60: dup IF ! 61: dup rw@-le aa55 = IF ! 62: diagnostic-mode? IF ." Device ROM header found at " dup . cr THEN ! 63: ELSE ! 64: drop 0 ! 65: THEN ! 66: THEN 1.1 root 67: ; 68: 69: : pci-find-fcode ( baseaddr -- addr len | false ) 1.1.1.2 ! root 70: BEGIN ! 71: 1ff NOT and \ Image must start at 512 byte boundary ! 72: pci-find-rom dup ! 73: WHILE ! 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 ! 79: diagnostic-mode? IF ! 80: ." Invalid PCI Data structure, ignoring ROM contents" cr ! 81: THEN ! 82: drop false EXIT ! 83: THEN ( pcir-addr ) ! 84: dup 14 + rb@ CASE \ Get image code type ! 85: 0 OF s" Intel x86 BIOS" rom-code-ignored ENDOF ! 86: 1 OF ! 87: diagnostic-mode? IF ! 88: ." Open Firmware FCode found in image at " dup . cr ! 89: THEN ! 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 ! 93: EXIT ! 94: ENDOF ! 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 ! 98: ENDCASE ! 99: dup 15 + rb@ 80 and IF \ End of last image? ! 100: drop false EXIT ! 101: THEN ! 102: dup 10 + rw@-le 200 * + \ Next image start ! 103: REPEAT 1.1 root 104: ; 105: 1.1.1.2 ! root 106: ! 107: \ Prepare and run a FCODE program from a PCI Option ROM. ! 108: : pci-execute-fcode ( baseaddr -- ) ! 109: pci-find-fcode dup 0= IF ! 110: 2drop EXIT ! 111: THEN ( addr len ) ! 112: fc-set-pci-mmio-tokens \ Prepare PCI access functions ! 113: \ Now run the FCODE: ! 114: ['] execute-rom-fcode CATCH IF ! 115: cr ." FCODE failed!" cr ! 116: 2drop ! 117: THEN ! 118: fc-set-normal-mmio-tokens \ Restore normal MMIO access functions 1.1 root 119: ;
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.