|
|
1.1 ! root 1: \ ***************************************************************************** ! 2: \ * Copyright (c) 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 ! 8: \ * ! 9: \ * Contributors: ! 10: \ * IBM Corporation - initial implementation ! 11: \ ****************************************************************************/ ! 12: ! 13: my-space pci-device-generic-setup ! 14: ! 15: \ Defaults, overriden from qemu ! 16: d# 800 VALUE disp-width ! 17: d# 600 VALUE disp-height ! 18: d# 8 VALUE disp-depth ! 19: ! 20: \ Determine base address ! 21: 10 config-l@ translate-my-address 3 not AND VALUE fb-base ! 22: ! 23: \ Fixed up later ! 24: -1 VALUE io-base ! 25: ! 26: \ We support only one instance ! 27: false VALUE is-installed? ! 28: ! 29: : vga-io-xlate ( port -- addr ) ! 30: io-base -1 = IF ! 31: dup translate-my-address fff not and to io-base ! 32: THEN ! 33: io-base + ! 34: ; ! 35: ! 36: : vga-w! ( value port -- ) ! 37: vga-io-xlate rw!-le ! 38: ; ! 39: ! 40: : vga-w@ ( port -- value ) ! 41: vga-io-xlate rw@-le ! 42: ; ! 43: ! 44: : vga-b! ( value port -- ) ! 45: vga-io-xlate rb! ! 46: ; ! 47: ! 48: : vga-b@ ( port -- value ) ! 49: vga-io-xlate rb@ ! 50: ; ! 51: ! 52: : vga-crt@ ( index -- value ) ! 53: 3d4 vga-b! ! 54: 3d5 vga-b@ ! 55: ; ! 56: ! 57: : vga-crt! ( value index -- ) ! 58: 3d4 vga-b! ! 59: 3d5 vga-b! ! 60: ; ! 61: ! 62: : vga-seq@ ( index -- value ) ! 63: 3c4 vga-b! ! 64: 3c5 vga-b@ ! 65: ; ! 66: ! 67: : vga-seq! ( value index -- ) ! 68: 3c4 vga-b! ! 69: 3c5 vga-b! ! 70: ; ! 71: ! 72: : vga-att@ ( index -- value ) ! 73: 3c0 vga-b! ! 74: 3c1 vga-b@ ! 75: ; ! 76: ! 77: : vga-att! ( value index -- ) ! 78: 3c0 vga-b! ! 79: 3c0 vga-b! ! 80: ; ! 81: ! 82: : vga-gfx@ ( index -- value ) ! 83: 3ce vga-b! ! 84: 3cf vga-b@ ! 85: ; ! 86: ! 87: : vga-gfx! ( value index -- ) ! 88: 3ce vga-b! ! 89: 3cf vga-b! ! 90: ; ! 91: ! 92: \ ************************************************************************** ! 93: \ ** These come from vga-display.fs and should probably be moved to a common ! 94: \ ** location. ! 95: ! 96: : draw-rectangle ( adr x y w h -- ) ! 97: is-installed? IF ! 98: 0 ?DO ! 99: 4dup ( adr x y w adr x y w ) ! 100: drop ( adr x y w adr x y ) ! 101: i + screen-width * + \ calculate offset into framebuffer ((y + i) * screen_width + x) ! 102: ( adr x y w adr offs ) ! 103: frame-buffer-adr + \ add to frame-buffer-adr ( adr x y w adr fb_adr ) ! 104: 1 pick 3 pick i * + swap 3 pick ( adr x y w adr adr_offs fb_adr w ) ! 105: rmove \ copy line ( adr x y w adr ) ! 106: drop ( adr x y w ) ! 107: LOOP ! 108: 4drop ! 109: ELSE ! 110: 4drop drop ! 111: THEN ! 112: ; ! 113: ! 114: : fill-rectangle ( number x y w h -- ) ! 115: is-installed? IF ! 116: 0 ?DO ! 117: 4dup ( number x y w number x y w ) ! 118: drop ( number x y w number x y ) ! 119: i + screen-width * + \ calculate offset into framebuffer ((y + i) * screen_width + x) ! 120: ( number x y w number offs ) ! 121: frame-buffer-adr + \ add to frame-buffer-adr ( number x y w number adr ) ! 122: 2 pick 2 pick ( number x y w number adr w number ) ! 123: rfill \ draw line ( number x y w number ) ! 124: drop ( number x y w ) ! 125: LOOP ! 126: 4drop ! 127: ELSE ! 128: 4drop drop ! 129: THEN ! 130: ; ! 131: ! 132: : read-rectangle ( adr x y w h -- ) ! 133: is-installed? IF ! 134: 0 ?DO ! 135: 4dup ( adr x y w adr x y w ) ! 136: drop ( adr x y w adr x y ) ! 137: i + screen-width * + \ calculate offset into framebuffer ((y + i) * screen_width + x) ! 138: ( adr x y w adr offs ) ! 139: frame-buffer-adr + \ add to frame-buffer-adr ( adr x y w adr fb_adr ) ! 140: 1 pick 3 pick i * + 3 pick ( adr x y w adr fb_adr adr_offs w ) ! 141: rmove \ copy line ( adr x y w adr ) ! 142: drop ( adr x y w ) ! 143: LOOP ! 144: 4drop ! 145: ELSE ! 146: 4drop drop ! 147: THEN ! 148: ; ! 149: ! 150: \ ** end of copy from vga-display.fs ! 151: \ ************************************************************************** ! 152: ! 153: : color! ( r g b number -- ) ! 154: 3c8 vga-b! ! 155: rot 2 >> 3c9 vga-b! ! 156: swap 2 >> 3c9 vga-b! ! 157: 2 >> 3c9 vga-b! ! 158: ; ! 159: ! 160: : color@ ( number -- r g b ) ! 161: 3c8 vga-b! ! 162: 3c9 vga-b@ 2 << ! 163: 3c9 vga-b@ 2 << ! 164: 3c9 vga-b@ 2 << ! 165: ; ! 166: ! 167: : set-colors ( adr number #numbers -- ) ! 168: over 3c8 vga-b! ! 169: swap DO ! 170: rb@ 2 >> 3c9 vga-b! ! 171: rb@ 2 >> 3c9 vga-b! ! 172: rb@ 2 >> 3c9 vga-b! ! 173: LOOP ! 174: 3drop ! 175: ; ! 176: ! 177: : get-colors ( adr number #numbers -- ) ! 178: 3drop ! 179: ; ! 180: ! 181: : default-palette ! 182: \ Grayscale ramp for now, be smarter later ! 183: 100 0 DO ! 184: i i i i color! ! 185: LOOP ! 186: ; ! 187: ! 188: ! 189: : init-mode ! 190: 3da vga-b@ drop \ reset flip flop ! 191: 0f 3c2 vga-b! \ color mode, ram enable, ... ! 192: 12 06 vga-seq! \ unlock extensions ! 193: 05 06 vga-gfx! \ graphic mode ! 194: \ set bit depth. Note: we should set the hidden ! 195: \ dac register to differenciate 15 and 16bpp, but ! 196: \ it's annoying and in practice we don't care as ! 197: \ we are only displaying in black & white atm ! 198: disp-depth CASE \ set depth ! 199: 8 OF 01 07 vga-seq! ENDOF ! 200: f OF 07 07 vga-seq! ENDOF ! 201: 10 OF 07 07 vga-seq! ENDOF ! 202: 20 OF 09 07 vga-seq! ENDOF ! 203: ENDCASE ! 204: ff 02 vga-seq! \ enable plane write ! 205: 0a 04 vga-seq! \ memory mode ! 206: 03 17 vga-crt! \ disable display ! 207: \ calculate line offset & split ! 208: disp-width disp-depth 7 + 8 / * 3 >> ! 209: dup ff and 13 vga-crt! \ bottom bits ! 210: 4 >> 10 and 1b vga-crt! \ top bit ! 211: disp-width 3 >> 1 - 01 vga-crt! \ H_DISP ! 212: disp-height 1 - ff and 12 vga-crt! \ V_DISP ! 213: disp-height 1 - 7 >> 2 and ! 214: disp-height 1 - 3 >> 40 and ! 215: or 10 or 07 vga-crt! \ OFLOW ! 216: ff 18 vga-crt! \ LINE_COMPARE ! 217: 40 09 vga-crt! \ MAX_SCAN ! 218: 08 04 vga-crt! \ SYNC_START ! 219: 0f 02 vga-crt! \ BLANK_START ! 220: 00 0c vga-crt! ! 221: 00 0d vga-crt! ! 222: 40 05 vga-gfx! \ gfx mode ! 223: 83 17 vga-crt! \ enable display ! 224: 33 3c0 vga-b! \ gfx in ar index ! 225: 00 3c0 vga-b! ! 226: 01 01 vga-seq! \ enable seq ! 227: ; ! 228: ! 229: : clear-screen ! 230: fb-base disp-width disp-height disp-depth 7 + 8 / * * 0 rfill ! 231: ; ! 232: ! 233: : read-settings ! 234: s" qemu,graphic-width" get-chosen IF ! 235: decode-int to disp-width 2drop ! 236: THEN ! 237: s" qemu,graphic-height" get-chosen IF ! 238: decode-int to disp-height 2drop ! 239: THEN ! 240: s" qemu,graphic-depth" get-chosen IF ! 241: decode-int nip nip ! 242: dup 8 = ! 243: over f = or ! 244: over 10 = or ! 245: over 20 = or IF ! 246: to disp-depth ! 247: ELSE ! 248: ." Unsupported bit depth, using 8bpp " drop cr ! 249: THEN ! 250: THEN ! 251: ; ! 252: ! 253: : add-legacy-reg ! 254: \ add legacy I/O Ports / Memory regions to assigned-addresses ! 255: \ see PCI Bus Binding Revision 2.1 Section 7. ! 256: s" reg" get-node get-property IF ! 257: \ "reg" does not exist, create new ! 258: encode-start ! 259: ELSE ! 260: \ "reg" does exist, copy it ! 261: encode-bytes ! 262: THEN ! 263: \ I/O Range 0x1ce-0x1d2 ! 264: my-space a1000000 or encode-int+ \ non-relocatable, aliased I/O space ! 265: 1ce encode-64+ 4 encode-64+ \ addr size ! 266: \ I/O Range 0x3B0-0x3BB ! 267: my-space a1000000 or encode-int+ \ non-relocatable, aliased I/O space ! 268: 3b0 encode-64+ c encode-64+ \ addr size ! 269: \ I/O Range 0x3C0-0x3DF ! 270: my-space a1000000 or encode-int+ \ non-relocatable, aliased I/O space ! 271: 3c0 encode-64+ 20 encode-64+ \ addr size ! 272: \ Memory Range 0xA0000-0xBFFFF ! 273: my-space a2000000 or encode-int+ \ non-relocatable, <1MB Memory space ! 274: a0000 encode-64+ 20000 encode-64+ \ addr size ! 275: s" reg" property \ store "reg" property ! 276: ; ! 277: ! 278: : setup-properties ! 279: \ Shouldn't this be done from open ? ! 280: disp-width encode-int s" width" property ! 281: disp-height encode-int s" height" property ! 282: disp-width disp-depth 7 + 8 / * encode-int s" linebytes" property ! 283: disp-depth encode-int s" depth" property ! 284: s" ISO8859-1" encode-string s" character-set" property \ i hope this is ok... ! 285: \ add "device_type" property ! 286: s" display" encode-string s" device_type" property ! 287: \ XXX We don't create an "address" property because Linux doesn't know what ! 288: \ to do with it for >32-bit ! 289: ; ! 290: ! 291: \ words for installation/removal, needed by is-install/is-remove, see display.fs ! 292: : display-remove ( -- ) ! 293: ; ! 294: ! 295: : display-install ( -- ) ! 296: is-installed? NOT IF ! 297: ." Installing QEMU fb" cr ! 298: fb-base to frame-buffer-adr ! 299: default-font ! 300: set-font ! 301: disp-width disp-height ! 302: disp-width char-width / disp-height char-height / ! 303: disp-depth 7 + 8 / ( width height #lines #cols depth ) ! 304: fb-install ! 305: true to is-installed? ! 306: THEN ! 307: ; ! 308: ! 309: : dimensions ( -- width height ) ! 310: disp-width disp-height ! 311: ; ! 312: ! 313: : set-alias ! 314: s" screen" find-alias 0= IF ! 315: \ no previous screen alias defined, define it... ! 316: s" screen" get-node node>path set-alias ! 317: ELSE ! 318: drop ! 319: THEN ! 320: ; ! 321: ! 322: ! 323: ." cirrus vga" cr ! 324: ! 325: pci-master-enable ! 326: pci-mem-enable ! 327: pci-io-enable ! 328: add-legacy-reg ! 329: read-settings ! 330: init-mode ! 331: clear-screen ! 332: default-palette ! 333: setup-properties ! 334: ' display-install is-install ! 335: ' display-remove is-remove ! 336: set-alias
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.