2 * QEMU Cirrus CLGD 54xx VGA Emulator.
4 * Copyright (c) 2004 Fabrice Bellard
5 * Copyright (c) 2004 Makoto Suzuki (suzu)
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 * Reference: Finn Thogersons' VGADOC4b
27 * available at http://home.worldonline.dk/~finth/
37 * - destination write mask support not complete (bits 5..7)
38 * - optimize linear mappings
39 * - optimize bitblt functions
42 //#define DEBUG_CIRRUS
43 //#define DEBUG_BITBLT
45 /***************************************
49 ***************************************/
51 #define qemu_MIN(a,b) ((a) < (b) ? (a) : (b))
54 #define CIRRUS_ID_CLGD5422 (0x23<<2)
55 #define CIRRUS_ID_CLGD5426 (0x24<<2)
56 #define CIRRUS_ID_CLGD5424 (0x25<<2)
57 #define CIRRUS_ID_CLGD5428 (0x26<<2)
58 #define CIRRUS_ID_CLGD5430 (0x28<<2)
59 #define CIRRUS_ID_CLGD5434 (0x2A<<2)
60 #define CIRRUS_ID_CLGD5436 (0x2B<<2)
61 #define CIRRUS_ID_CLGD5446 (0x2E<<2)
64 #define CIRRUS_SR7_BPP_VGA 0x00
65 #define CIRRUS_SR7_BPP_SVGA 0x01
66 #define CIRRUS_SR7_BPP_MASK 0x0e
67 #define CIRRUS_SR7_BPP_8 0x00
68 #define CIRRUS_SR7_BPP_16_DOUBLEVCLK 0x02
69 #define CIRRUS_SR7_BPP_24 0x04
70 #define CIRRUS_SR7_BPP_16 0x06
71 #define CIRRUS_SR7_BPP_32 0x08
72 #define CIRRUS_SR7_ISAADDR_MASK 0xe0
75 #define CIRRUS_MEMSIZE_512k 0x08
76 #define CIRRUS_MEMSIZE_1M 0x10
77 #define CIRRUS_MEMSIZE_2M 0x18
78 #define CIRRUS_MEMFLAGS_BANKSWITCH 0x80 // bank switching is enabled.
81 #define CIRRUS_CURSOR_SHOW 0x01
82 #define CIRRUS_CURSOR_HIDDENPEL 0x02
83 #define CIRRUS_CURSOR_LARGE 0x04 // 64x64 if set, 32x32 if clear
86 #define CIRRUS_BUSTYPE_VLBFAST 0x10
87 #define CIRRUS_BUSTYPE_PCI 0x20
88 #define CIRRUS_BUSTYPE_VLBSLOW 0x30
89 #define CIRRUS_BUSTYPE_ISA 0x38
90 #define CIRRUS_MMIO_ENABLE 0x04
91 #define CIRRUS_MMIO_USE_PCIADDR 0x40 // 0xb8000 if cleared.
92 #define CIRRUS_MEMSIZEEXT_DOUBLE 0x80
95 #define CIRRUS_BANKING_DUAL 0x01
96 #define CIRRUS_BANKING_GRANULARITY_16K 0x20 // set:16k, clear:4k
99 #define CIRRUS_BLTMODE_BACKWARDS 0x01
100 #define CIRRUS_BLTMODE_MEMSYSDEST 0x02
101 #define CIRRUS_BLTMODE_MEMSYSSRC 0x04
102 #define CIRRUS_BLTMODE_TRANSPARENTCOMP 0x08
103 #define CIRRUS_BLTMODE_PATTERNCOPY 0x40
104 #define CIRRUS_BLTMODE_COLOREXPAND 0x80
105 #define CIRRUS_BLTMODE_PIXELWIDTHMASK 0x30
106 #define CIRRUS_BLTMODE_PIXELWIDTH8 0x00
107 #define CIRRUS_BLTMODE_PIXELWIDTH16 0x10
108 #define CIRRUS_BLTMODE_PIXELWIDTH24 0x20
109 #define CIRRUS_BLTMODE_PIXELWIDTH32 0x30
112 #define CIRRUS_BLT_BUSY 0x01
113 #define CIRRUS_BLT_START 0x02
114 #define CIRRUS_BLT_RESET 0x04
115 #define CIRRUS_BLT_FIFOUSED 0x10
116 #define CIRRUS_BLT_AUTOSTART 0x80
119 #define CIRRUS_ROP_0 0x00
120 #define CIRRUS_ROP_SRC_AND_DST 0x05
121 #define CIRRUS_ROP_NOP 0x06
122 #define CIRRUS_ROP_SRC_AND_NOTDST 0x09
123 #define CIRRUS_ROP_NOTDST 0x0b
124 #define CIRRUS_ROP_SRC 0x0d
125 #define CIRRUS_ROP_1 0x0e
126 #define CIRRUS_ROP_NOTSRC_AND_DST 0x50
127 #define CIRRUS_ROP_SRC_XOR_DST 0x59
128 #define CIRRUS_ROP_SRC_OR_DST 0x6d
129 #define CIRRUS_ROP_NOTSRC_OR_NOTDST 0x90
130 #define CIRRUS_ROP_SRC_NOTXOR_DST 0x95
131 #define CIRRUS_ROP_SRC_OR_NOTDST 0xad
132 #define CIRRUS_ROP_NOTSRC 0xd0
133 #define CIRRUS_ROP_NOTSRC_OR_DST 0xd6
134 #define CIRRUS_ROP_NOTSRC_AND_NOTDST 0xda
136 #define CIRRUS_ROP_NOP_INDEX 2
137 #define CIRRUS_ROP_SRC_INDEX 5
140 #define CIRRUS_BLTMODEEXT_SOLIDFILL 0x04
141 #define CIRRUS_BLTMODEEXT_COLOREXPINV 0x02
142 #define CIRRUS_BLTMODEEXT_DWORDGRANULARITY 0x01
145 #define CIRRUS_MMIO_BLTBGCOLOR 0x00 // dword
146 #define CIRRUS_MMIO_BLTFGCOLOR 0x04 // dword
147 #define CIRRUS_MMIO_BLTWIDTH 0x08 // word
148 #define CIRRUS_MMIO_BLTHEIGHT 0x0a // word
149 #define CIRRUS_MMIO_BLTDESTPITCH 0x0c // word
150 #define CIRRUS_MMIO_BLTSRCPITCH 0x0e // word
151 #define CIRRUS_MMIO_BLTDESTADDR 0x10 // dword
152 #define CIRRUS_MMIO_BLTSRCADDR 0x14 // dword
153 #define CIRRUS_MMIO_BLTWRITEMASK 0x17 // byte
154 #define CIRRUS_MMIO_BLTMODE 0x18 // byte
155 #define CIRRUS_MMIO_BLTROP 0x1a // byte
156 #define CIRRUS_MMIO_BLTMODEEXT 0x1b // byte
157 #define CIRRUS_MMIO_BLTTRANSPARENTCOLOR 0x1c // word?
158 #define CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK 0x20 // word?
159 #define CIRRUS_MMIO_LINEARDRAW_START_X 0x24 // word
160 #define CIRRUS_MMIO_LINEARDRAW_START_Y 0x26 // word
161 #define CIRRUS_MMIO_LINEARDRAW_END_X 0x28 // word
162 #define CIRRUS_MMIO_LINEARDRAW_END_Y 0x2a // word
163 #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_INC 0x2c // byte
164 #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_ROLLOVER 0x2d // byte
165 #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_MASK 0x2e // byte
166 #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_ACCUM 0x2f // byte
167 #define CIRRUS_MMIO_BRESENHAM_K1 0x30 // word
168 #define CIRRUS_MMIO_BRESENHAM_K3 0x32 // word
169 #define CIRRUS_MMIO_BRESENHAM_ERROR 0x34 // word
170 #define CIRRUS_MMIO_BRESENHAM_DELTA_MAJOR 0x36 // word
171 #define CIRRUS_MMIO_BRESENHAM_DIRECTION 0x38 // byte
172 #define CIRRUS_MMIO_LINEDRAW_MODE 0x39 // byte
173 #define CIRRUS_MMIO_BLTSTATUS 0x40 // byte
175 // PCI 0x00: vendor, 0x02: device
176 #define PCI_VENDOR_CIRRUS 0x1013
177 #define PCI_DEVICE_CLGD5462 0x00d0
178 #define PCI_DEVICE_CLGD5465 0x00d6
180 // PCI 0x04: command(word), 0x06(word): status
181 #define PCI_COMMAND_IOACCESS 0x0001
182 #define PCI_COMMAND_MEMACCESS 0x0002
183 #define PCI_COMMAND_BUSMASTER 0x0004
184 #define PCI_COMMAND_SPECIALCYCLE 0x0008
185 #define PCI_COMMAND_MEMWRITEINVALID 0x0010
186 #define PCI_COMMAND_PALETTESNOOPING 0x0020
187 #define PCI_COMMAND_PARITYDETECTION 0x0040
188 #define PCI_COMMAND_ADDRESSDATASTEPPING 0x0080
189 #define PCI_COMMAND_SERR 0x0100
190 #define PCI_COMMAND_BACKTOBACKTRANS 0x0200
191 // PCI 0x08, 0xff000000 (0x09-0x0b:class,0x08:rev)
192 #define PCI_CLASS_BASE_DISPLAY 0x03
193 // PCI 0x08, 0x00ff0000
194 #define PCI_CLASS_SUB_VGA 0x00
195 // PCI 0x0c, 0x00ff0000 (0x0c:cacheline,0x0d:latency,0x0e:headertype,0x0f:Built-in self test)
196 #define PCI_CLASS_HEADERTYPE_00h 0x00
197 // 0x10-0x3f (headertype 00h)
198 // PCI 0x10,0x14,0x18,0x1c,0x20,0x24: base address mapping registers
199 // 0x10: MEMBASE, 0x14: IOBASE(hard-coded in XFree86 3.x)
200 #define PCI_MAP_MEM 0x0
201 #define PCI_MAP_IO 0x1
202 #define PCI_MAP_MEM_ADDR_MASK (~0xf)
203 #define PCI_MAP_IO_ADDR_MASK (~0x3)
204 #define PCI_MAP_MEMFLAGS_32BIT 0x0
205 #define PCI_MAP_MEMFLAGS_32BIT_1M 0x1
206 #define PCI_MAP_MEMFLAGS_64BIT 0x4
207 #define PCI_MAP_MEMFLAGS_CACHEABLE 0x8
208 // PCI 0x28: cardbus CIS pointer
209 // PCI 0x2c: subsystem vendor id, 0x2e: subsystem id
210 // PCI 0x30: expansion ROM base address
211 #define PCI_ROMBIOS_ENABLED 0x1
212 // PCI 0x34: 0xffffff00=reserved, 0x000000ff=capabilities pointer
213 // PCI 0x38: reserved
214 // PCI 0x3c: 0x3c=int-line, 0x3d=int-pin, 0x3e=min-gnt, 0x3f=maax-lat
216 #define CIRRUS_PNPMMIO_SIZE 0x1000
219 /* I/O and memory hook */
220 #define CIRRUS_HOOK_NOT_HANDLED 0
221 #define CIRRUS_HOOK_HANDLED 1
223 struct CirrusVGAState
;
224 typedef void (*cirrus_bitblt_rop_t
) (struct CirrusVGAState
*s
,
225 uint8_t * dst
, const uint8_t * src
,
226 int dstpitch
, int srcpitch
,
227 int bltwidth
, int bltheight
);
228 typedef void (*cirrus_fill_t
)(struct CirrusVGAState
*s
,
229 uint8_t *dst
, int dst_pitch
, int width
, int height
);
231 typedef struct CirrusVGAState
{
234 int cirrus_linear_io_addr
;
235 int cirrus_linear_bitblt_io_addr
;
236 int cirrus_mmio_io_addr
;
238 unsigned long cirrus_lfb_addr
;
239 unsigned long cirrus_lfb_end
;
241 uint32_t aliased_bank_base
[2];
242 uint32_t aliased_bank_limit
[2];
244 uint32_t cirrus_addr_mask
;
245 uint32_t linear_mmio_mask
;
246 uint8_t cirrus_shadow_gr0
;
247 uint8_t cirrus_shadow_gr1
;
248 uint8_t cirrus_hidden_dac_lockindex
;
249 uint8_t cirrus_hidden_dac_data
;
250 uint32_t cirrus_bank_base
[2];
251 uint32_t cirrus_bank_limit
[2];
252 uint8_t cirrus_hidden_palette
[48];
253 uint32_t hw_cursor_x
;
254 uint32_t hw_cursor_y
;
255 int cirrus_blt_pixelwidth
;
256 int cirrus_blt_width
;
257 int cirrus_blt_height
;
258 int cirrus_blt_dstpitch
;
259 int cirrus_blt_srcpitch
;
260 uint32_t cirrus_blt_fgcol
;
261 uint32_t cirrus_blt_bgcol
;
262 uint32_t cirrus_blt_dstaddr
;
263 uint32_t cirrus_blt_srcaddr
;
264 uint8_t cirrus_blt_mode
;
265 uint8_t cirrus_blt_modeext
;
266 cirrus_bitblt_rop_t cirrus_rop
;
267 #define CIRRUS_BLTBUFSIZE (2048 * 4) /* one line width */
268 uint8_t cirrus_bltbuf
[CIRRUS_BLTBUFSIZE
];
269 uint8_t *cirrus_srcptr
;
270 uint8_t *cirrus_srcptr_end
;
271 uint32_t cirrus_srccounter
;
272 /* hwcursor display state */
273 int last_hw_cursor_size
;
274 int last_hw_cursor_x
;
275 int last_hw_cursor_y
;
276 int last_hw_cursor_y_start
;
277 int last_hw_cursor_y_end
;
278 int real_vram_size
; /* XXX: suppress that */
279 CPUWriteMemoryFunc
**cirrus_linear_write
;
281 unsigned long map_addr
;
282 unsigned long map_end
;
286 typedef struct PCICirrusVGAState
{
288 CirrusVGAState cirrus_vga
;
291 static uint8_t rop_to_index
[256];
293 /***************************************
297 ***************************************/
300 static void cirrus_bitblt_reset(CirrusVGAState
*s
);
301 static void cirrus_update_memory_access(CirrusVGAState
*s
);
303 /***************************************
307 ***************************************/
309 static void cirrus_bitblt_rop_nop(CirrusVGAState
*s
,
310 uint8_t *dst
,const uint8_t *src
,
311 int dstpitch
,int srcpitch
,
312 int bltwidth
,int bltheight
)
316 static void cirrus_bitblt_fill_nop(CirrusVGAState
*s
,
318 int dstpitch
, int bltwidth
,int bltheight
)
323 #define ROP_OP(d, s) d = 0
324 #include "cirrus_vga_rop.h"
326 #define ROP_NAME src_and_dst
327 #define ROP_OP(d, s) d = (s) & (d)
328 #include "cirrus_vga_rop.h"
330 #define ROP_NAME src_and_notdst
331 #define ROP_OP(d, s) d = (s) & (~(d))
332 #include "cirrus_vga_rop.h"
334 #define ROP_NAME notdst
335 #define ROP_OP(d, s) d = ~(d)
336 #include "cirrus_vga_rop.h"
339 #define ROP_OP(d, s) d = s
340 #include "cirrus_vga_rop.h"
343 #define ROP_OP(d, s) d = ~0
344 #include "cirrus_vga_rop.h"
346 #define ROP_NAME notsrc_and_dst
347 #define ROP_OP(d, s) d = (~(s)) & (d)
348 #include "cirrus_vga_rop.h"
350 #define ROP_NAME src_xor_dst
351 #define ROP_OP(d, s) d = (s) ^ (d)
352 #include "cirrus_vga_rop.h"
354 #define ROP_NAME src_or_dst
355 #define ROP_OP(d, s) d = (s) | (d)
356 #include "cirrus_vga_rop.h"
358 #define ROP_NAME notsrc_or_notdst
359 #define ROP_OP(d, s) d = (~(s)) | (~(d))
360 #include "cirrus_vga_rop.h"
362 #define ROP_NAME src_notxor_dst
363 #define ROP_OP(d, s) d = ~((s) ^ (d))
364 #include "cirrus_vga_rop.h"
366 #define ROP_NAME src_or_notdst
367 #define ROP_OP(d, s) d = (s) | (~(d))
368 #include "cirrus_vga_rop.h"
370 #define ROP_NAME notsrc
371 #define ROP_OP(d, s) d = (~(s))
372 #include "cirrus_vga_rop.h"
374 #define ROP_NAME notsrc_or_dst
375 #define ROP_OP(d, s) d = (~(s)) | (d)
376 #include "cirrus_vga_rop.h"
378 #define ROP_NAME notsrc_and_notdst
379 #define ROP_OP(d, s) d = (~(s)) & (~(d))
380 #include "cirrus_vga_rop.h"
382 static const cirrus_bitblt_rop_t cirrus_fwd_rop
[16] = {
383 cirrus_bitblt_rop_fwd_0
,
384 cirrus_bitblt_rop_fwd_src_and_dst
,
385 cirrus_bitblt_rop_nop
,
386 cirrus_bitblt_rop_fwd_src_and_notdst
,
387 cirrus_bitblt_rop_fwd_notdst
,
388 cirrus_bitblt_rop_fwd_src
,
389 cirrus_bitblt_rop_fwd_1
,
390 cirrus_bitblt_rop_fwd_notsrc_and_dst
,
391 cirrus_bitblt_rop_fwd_src_xor_dst
,
392 cirrus_bitblt_rop_fwd_src_or_dst
,
393 cirrus_bitblt_rop_fwd_notsrc_or_notdst
,
394 cirrus_bitblt_rop_fwd_src_notxor_dst
,
395 cirrus_bitblt_rop_fwd_src_or_notdst
,
396 cirrus_bitblt_rop_fwd_notsrc
,
397 cirrus_bitblt_rop_fwd_notsrc_or_dst
,
398 cirrus_bitblt_rop_fwd_notsrc_and_notdst
,
401 static const cirrus_bitblt_rop_t cirrus_bkwd_rop
[16] = {
402 cirrus_bitblt_rop_bkwd_0
,
403 cirrus_bitblt_rop_bkwd_src_and_dst
,
404 cirrus_bitblt_rop_nop
,
405 cirrus_bitblt_rop_bkwd_src_and_notdst
,
406 cirrus_bitblt_rop_bkwd_notdst
,
407 cirrus_bitblt_rop_bkwd_src
,
408 cirrus_bitblt_rop_bkwd_1
,
409 cirrus_bitblt_rop_bkwd_notsrc_and_dst
,
410 cirrus_bitblt_rop_bkwd_src_xor_dst
,
411 cirrus_bitblt_rop_bkwd_src_or_dst
,
412 cirrus_bitblt_rop_bkwd_notsrc_or_notdst
,
413 cirrus_bitblt_rop_bkwd_src_notxor_dst
,
414 cirrus_bitblt_rop_bkwd_src_or_notdst
,
415 cirrus_bitblt_rop_bkwd_notsrc
,
416 cirrus_bitblt_rop_bkwd_notsrc_or_dst
,
417 cirrus_bitblt_rop_bkwd_notsrc_and_notdst
,
420 #define ROP2(name) {\
427 #define ROP_NOP2(func) {\
434 static const cirrus_bitblt_rop_t cirrus_patternfill
[16][4] = {
435 ROP2(cirrus_patternfill_0
),
436 ROP2(cirrus_patternfill_src_and_dst
),
437 ROP_NOP2(cirrus_bitblt_rop_nop
),
438 ROP2(cirrus_patternfill_src_and_notdst
),
439 ROP2(cirrus_patternfill_notdst
),
440 ROP2(cirrus_patternfill_src
),
441 ROP2(cirrus_patternfill_1
),
442 ROP2(cirrus_patternfill_notsrc_and_dst
),
443 ROP2(cirrus_patternfill_src_xor_dst
),
444 ROP2(cirrus_patternfill_src_or_dst
),
445 ROP2(cirrus_patternfill_notsrc_or_notdst
),
446 ROP2(cirrus_patternfill_src_notxor_dst
),
447 ROP2(cirrus_patternfill_src_or_notdst
),
448 ROP2(cirrus_patternfill_notsrc
),
449 ROP2(cirrus_patternfill_notsrc_or_dst
),
450 ROP2(cirrus_patternfill_notsrc_and_notdst
),
453 static const cirrus_bitblt_rop_t cirrus_colorexpand_transp
[16][4] = {
454 ROP2(cirrus_colorexpand_transp_0
),
455 ROP2(cirrus_colorexpand_transp_src_and_dst
),
456 ROP_NOP2(cirrus_bitblt_rop_nop
),
457 ROP2(cirrus_colorexpand_transp_src_and_notdst
),
458 ROP2(cirrus_colorexpand_transp_notdst
),
459 ROP2(cirrus_colorexpand_transp_src
),
460 ROP2(cirrus_colorexpand_transp_1
),
461 ROP2(cirrus_colorexpand_transp_notsrc_and_dst
),
462 ROP2(cirrus_colorexpand_transp_src_xor_dst
),
463 ROP2(cirrus_colorexpand_transp_src_or_dst
),
464 ROP2(cirrus_colorexpand_transp_notsrc_or_notdst
),
465 ROP2(cirrus_colorexpand_transp_src_notxor_dst
),
466 ROP2(cirrus_colorexpand_transp_src_or_notdst
),
467 ROP2(cirrus_colorexpand_transp_notsrc
),
468 ROP2(cirrus_colorexpand_transp_notsrc_or_dst
),
469 ROP2(cirrus_colorexpand_transp_notsrc_and_notdst
),
472 static const cirrus_bitblt_rop_t cirrus_colorexpand
[16][4] = {
473 ROP2(cirrus_colorexpand_0
),
474 ROP2(cirrus_colorexpand_src_and_dst
),
475 ROP_NOP2(cirrus_bitblt_rop_nop
),
476 ROP2(cirrus_colorexpand_src_and_notdst
),
477 ROP2(cirrus_colorexpand_notdst
),
478 ROP2(cirrus_colorexpand_src
),
479 ROP2(cirrus_colorexpand_1
),
480 ROP2(cirrus_colorexpand_notsrc_and_dst
),
481 ROP2(cirrus_colorexpand_src_xor_dst
),
482 ROP2(cirrus_colorexpand_src_or_dst
),
483 ROP2(cirrus_colorexpand_notsrc_or_notdst
),
484 ROP2(cirrus_colorexpand_src_notxor_dst
),
485 ROP2(cirrus_colorexpand_src_or_notdst
),
486 ROP2(cirrus_colorexpand_notsrc
),
487 ROP2(cirrus_colorexpand_notsrc_or_dst
),
488 ROP2(cirrus_colorexpand_notsrc_and_notdst
),
491 static const cirrus_bitblt_rop_t cirrus_colorexpand_pattern_transp
[16][4] = {
492 ROP2(cirrus_colorexpand_pattern_transp_0
),
493 ROP2(cirrus_colorexpand_pattern_transp_src_and_dst
),
494 ROP_NOP2(cirrus_bitblt_rop_nop
),
495 ROP2(cirrus_colorexpand_pattern_transp_src_and_notdst
),
496 ROP2(cirrus_colorexpand_pattern_transp_notdst
),
497 ROP2(cirrus_colorexpand_pattern_transp_src
),
498 ROP2(cirrus_colorexpand_pattern_transp_1
),
499 ROP2(cirrus_colorexpand_pattern_transp_notsrc_and_dst
),
500 ROP2(cirrus_colorexpand_pattern_transp_src_xor_dst
),
501 ROP2(cirrus_colorexpand_pattern_transp_src_or_dst
),
502 ROP2(cirrus_colorexpand_pattern_transp_notsrc_or_notdst
),
503 ROP2(cirrus_colorexpand_pattern_transp_src_notxor_dst
),
504 ROP2(cirrus_colorexpand_pattern_transp_src_or_notdst
),
505 ROP2(cirrus_colorexpand_pattern_transp_notsrc
),
506 ROP2(cirrus_colorexpand_pattern_transp_notsrc_or_dst
),
507 ROP2(cirrus_colorexpand_pattern_transp_notsrc_and_notdst
),
510 static const cirrus_bitblt_rop_t cirrus_colorexpand_pattern
[16][4] = {
511 ROP2(cirrus_colorexpand_pattern_0
),
512 ROP2(cirrus_colorexpand_pattern_src_and_dst
),
513 ROP_NOP2(cirrus_bitblt_rop_nop
),
514 ROP2(cirrus_colorexpand_pattern_src_and_notdst
),
515 ROP2(cirrus_colorexpand_pattern_notdst
),
516 ROP2(cirrus_colorexpand_pattern_src
),
517 ROP2(cirrus_colorexpand_pattern_1
),
518 ROP2(cirrus_colorexpand_pattern_notsrc_and_dst
),
519 ROP2(cirrus_colorexpand_pattern_src_xor_dst
),
520 ROP2(cirrus_colorexpand_pattern_src_or_dst
),
521 ROP2(cirrus_colorexpand_pattern_notsrc_or_notdst
),
522 ROP2(cirrus_colorexpand_pattern_src_notxor_dst
),
523 ROP2(cirrus_colorexpand_pattern_src_or_notdst
),
524 ROP2(cirrus_colorexpand_pattern_notsrc
),
525 ROP2(cirrus_colorexpand_pattern_notsrc_or_dst
),
526 ROP2(cirrus_colorexpand_pattern_notsrc_and_notdst
),
529 static const cirrus_fill_t cirrus_fill
[16][4] = {
531 ROP2(cirrus_fill_src_and_dst
),
532 ROP_NOP2(cirrus_bitblt_fill_nop
),
533 ROP2(cirrus_fill_src_and_notdst
),
534 ROP2(cirrus_fill_notdst
),
535 ROP2(cirrus_fill_src
),
537 ROP2(cirrus_fill_notsrc_and_dst
),
538 ROP2(cirrus_fill_src_xor_dst
),
539 ROP2(cirrus_fill_src_or_dst
),
540 ROP2(cirrus_fill_notsrc_or_notdst
),
541 ROP2(cirrus_fill_src_notxor_dst
),
542 ROP2(cirrus_fill_src_or_notdst
),
543 ROP2(cirrus_fill_notsrc
),
544 ROP2(cirrus_fill_notsrc_or_dst
),
545 ROP2(cirrus_fill_notsrc_and_notdst
),
548 static inline void cirrus_bitblt_fgcol(CirrusVGAState
*s
)
551 switch (s
->cirrus_blt_pixelwidth
) {
553 s
->cirrus_blt_fgcol
= s
->cirrus_shadow_gr1
;
556 color
= s
->cirrus_shadow_gr1
| (s
->gr
[0x11] << 8);
557 s
->cirrus_blt_fgcol
= le16_to_cpu(color
);
560 s
->cirrus_blt_fgcol
= s
->cirrus_shadow_gr1
|
561 (s
->gr
[0x11] << 8) | (s
->gr
[0x13] << 16);
565 color
= s
->cirrus_shadow_gr1
| (s
->gr
[0x11] << 8) |
566 (s
->gr
[0x13] << 16) | (s
->gr
[0x15] << 24);
567 s
->cirrus_blt_fgcol
= le32_to_cpu(color
);
572 static inline void cirrus_bitblt_bgcol(CirrusVGAState
*s
)
575 switch (s
->cirrus_blt_pixelwidth
) {
577 s
->cirrus_blt_bgcol
= s
->cirrus_shadow_gr0
;
580 color
= s
->cirrus_shadow_gr0
| (s
->gr
[0x10] << 8);
581 s
->cirrus_blt_bgcol
= le16_to_cpu(color
);
584 s
->cirrus_blt_bgcol
= s
->cirrus_shadow_gr0
|
585 (s
->gr
[0x10] << 8) | (s
->gr
[0x12] << 16);
589 color
= s
->cirrus_shadow_gr0
| (s
->gr
[0x10] << 8) |
590 (s
->gr
[0x12] << 16) | (s
->gr
[0x14] << 24);
591 s
->cirrus_blt_bgcol
= le32_to_cpu(color
);
596 static void cirrus_invalidate_region(CirrusVGAState
* s
, int off_begin
,
597 int off_pitch
, int bytesperline
,
604 for (y
= 0; y
< lines
; y
++) {
606 off_cur_end
= off_cur
+ bytesperline
;
607 off_cur
&= TARGET_PAGE_MASK
;
608 while (off_cur
< off_cur_end
) {
609 cpu_physical_memory_set_dirty(s
->vram_offset
+ off_cur
);
610 off_cur
+= TARGET_PAGE_SIZE
;
612 off_begin
+= off_pitch
;
616 static int cirrus_bitblt_common_patterncopy(CirrusVGAState
* s
,
621 dst
= s
->vram_ptr
+ s
->cirrus_blt_dstaddr
;
622 (*s
->cirrus_rop
) (s
, dst
, src
,
623 s
->cirrus_blt_dstpitch
, 0,
624 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
625 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
,
626 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_width
,
627 s
->cirrus_blt_height
);
633 static int cirrus_bitblt_solidfill(CirrusVGAState
*s
, int blt_rop
)
635 cirrus_fill_t rop_func
;
637 rop_func
= cirrus_fill
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
638 rop_func(s
, s
->vram_ptr
+ s
->cirrus_blt_dstaddr
,
639 s
->cirrus_blt_dstpitch
,
640 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
641 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
,
642 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_width
,
643 s
->cirrus_blt_height
);
644 cirrus_bitblt_reset(s
);
648 /***************************************
650 * bitblt (video-to-video)
652 ***************************************/
654 static int cirrus_bitblt_videotovideo_patterncopy(CirrusVGAState
* s
)
656 return cirrus_bitblt_common_patterncopy(s
,
658 (s
->cirrus_blt_srcaddr
& ~7));
661 static void cirrus_do_copy(CirrusVGAState
*s
, int dst
, int src
, int w
, int h
)
669 depth
= s
->get_bpp((VGAState
*)s
) / 8;
670 s
->get_resolution((VGAState
*)s
, &width
, &height
);
673 sx
= (src
% (width
* depth
)) / depth
;
674 sy
= (src
/ (width
* depth
));
675 dx
= (dst
% (width
*depth
)) / depth
;
676 dy
= (dst
/ (width
* depth
));
678 /* normalize width */
681 /* if we're doing a backward copy, we have to adjust
682 our x/y to be the upper left corner (instead of the lower
684 if (s
->cirrus_blt_dstpitch
< 0) {
685 sx
-= (s
->cirrus_blt_width
/ depth
) - 1;
686 dx
-= (s
->cirrus_blt_width
/ depth
) - 1;
687 sy
-= s
->cirrus_blt_height
- 1;
688 dy
-= s
->cirrus_blt_height
- 1;
691 /* are we in the visible portion of memory? */
692 if (sx
>= 0 && sy
>= 0 && dx
>= 0 && dy
>= 0 &&
693 (sx
+ w
) <= width
&& (sy
+ h
) <= height
&&
694 (dx
+ w
) <= width
&& (dy
+ h
) <= height
) {
698 /* make to sure only copy if it's a plain copy ROP */
699 if (*s
->cirrus_rop
!= cirrus_bitblt_rop_fwd_src
&&
700 *s
->cirrus_rop
!= cirrus_bitblt_rop_bkwd_src
)
703 /* we have to flush all pending changes so that the copy
704 is generated at the appropriate moment in time */
708 (*s
->cirrus_rop
) (s
, s
->vram_ptr
+ s
->cirrus_blt_dstaddr
,
709 s
->vram_ptr
+ s
->cirrus_blt_srcaddr
,
710 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_srcpitch
,
711 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
714 s
->ds
->dpy_copy(s
->ds
,
716 s
->cirrus_blt_width
/ depth
,
717 s
->cirrus_blt_height
);
719 /* we don't have to notify the display that this portion has
720 changed since dpy_copy implies this */
723 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
,
724 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_width
,
725 s
->cirrus_blt_height
);
728 static int cirrus_bitblt_videotovideo_copy(CirrusVGAState
* s
)
730 if (s
->ds
->dpy_copy
) {
731 cirrus_do_copy(s
, s
->cirrus_blt_dstaddr
- s
->start_addr
,
732 s
->cirrus_blt_srcaddr
- s
->start_addr
,
733 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
735 (*s
->cirrus_rop
) (s
, s
->vram_ptr
+ s
->cirrus_blt_dstaddr
,
736 s
->vram_ptr
+ s
->cirrus_blt_srcaddr
,
737 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_srcpitch
,
738 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
740 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
,
741 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_width
,
742 s
->cirrus_blt_height
);
748 /***************************************
750 * bitblt (cpu-to-video)
752 ***************************************/
754 static void cirrus_bitblt_cputovideo_next(CirrusVGAState
* s
)
759 if (s
->cirrus_srccounter
> 0) {
760 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PATTERNCOPY
) {
761 cirrus_bitblt_common_patterncopy(s
, s
->cirrus_bltbuf
);
763 s
->cirrus_srccounter
= 0;
764 cirrus_bitblt_reset(s
);
766 /* at least one scan line */
768 (*s
->cirrus_rop
)(s
, s
->vram_ptr
+ s
->cirrus_blt_dstaddr
,
769 s
->cirrus_bltbuf
, 0, 0, s
->cirrus_blt_width
, 1);
770 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
, 0,
771 s
->cirrus_blt_width
, 1);
772 s
->cirrus_blt_dstaddr
+= s
->cirrus_blt_dstpitch
;
773 s
->cirrus_srccounter
-= s
->cirrus_blt_srcpitch
;
774 if (s
->cirrus_srccounter
<= 0)
776 /* more bytes than needed can be transfered because of
777 word alignment, so we keep them for the next line */
778 /* XXX: keep alignment to speed up transfer */
779 end_ptr
= s
->cirrus_bltbuf
+ s
->cirrus_blt_srcpitch
;
780 copy_count
= s
->cirrus_srcptr_end
- end_ptr
;
781 memmove(s
->cirrus_bltbuf
, end_ptr
, copy_count
);
782 s
->cirrus_srcptr
= s
->cirrus_bltbuf
+ copy_count
;
783 s
->cirrus_srcptr_end
= s
->cirrus_bltbuf
+ s
->cirrus_blt_srcpitch
;
784 } while (s
->cirrus_srcptr
>= s
->cirrus_srcptr_end
);
789 /***************************************
793 ***************************************/
795 static void cirrus_bitblt_reset(CirrusVGAState
* s
)
798 ~(CIRRUS_BLT_START
| CIRRUS_BLT_BUSY
| CIRRUS_BLT_FIFOUSED
);
799 s
->cirrus_srcptr
= &s
->cirrus_bltbuf
[0];
800 s
->cirrus_srcptr_end
= &s
->cirrus_bltbuf
[0];
801 s
->cirrus_srccounter
= 0;
802 cirrus_update_memory_access(s
);
805 static int cirrus_bitblt_cputovideo(CirrusVGAState
* s
)
809 s
->cirrus_blt_mode
&= ~CIRRUS_BLTMODE_MEMSYSSRC
;
810 s
->cirrus_srcptr
= &s
->cirrus_bltbuf
[0];
811 s
->cirrus_srcptr_end
= &s
->cirrus_bltbuf
[0];
813 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PATTERNCOPY
) {
814 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_COLOREXPAND
) {
815 s
->cirrus_blt_srcpitch
= 8;
817 /* XXX: check for 24 bpp */
818 s
->cirrus_blt_srcpitch
= 8 * 8 * s
->cirrus_blt_pixelwidth
;
820 s
->cirrus_srccounter
= s
->cirrus_blt_srcpitch
;
822 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_COLOREXPAND
) {
823 w
= s
->cirrus_blt_width
/ s
->cirrus_blt_pixelwidth
;
824 if (s
->cirrus_blt_modeext
& CIRRUS_BLTMODEEXT_DWORDGRANULARITY
)
825 s
->cirrus_blt_srcpitch
= ((w
+ 31) >> 5);
827 s
->cirrus_blt_srcpitch
= ((w
+ 7) >> 3);
829 /* always align input size to 32 bits */
830 s
->cirrus_blt_srcpitch
= (s
->cirrus_blt_width
+ 3) & ~3;
832 s
->cirrus_srccounter
= s
->cirrus_blt_srcpitch
* s
->cirrus_blt_height
;
834 s
->cirrus_srcptr
= s
->cirrus_bltbuf
;
835 s
->cirrus_srcptr_end
= s
->cirrus_bltbuf
+ s
->cirrus_blt_srcpitch
;
836 cirrus_update_memory_access(s
);
840 static int cirrus_bitblt_videotocpu(CirrusVGAState
* s
)
844 printf("cirrus: bitblt (video to cpu) is not implemented yet\n");
849 static int cirrus_bitblt_videotovideo(CirrusVGAState
* s
)
853 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PATTERNCOPY
) {
854 ret
= cirrus_bitblt_videotovideo_patterncopy(s
);
856 ret
= cirrus_bitblt_videotovideo_copy(s
);
859 cirrus_bitblt_reset(s
);
863 static void cirrus_bitblt_start(CirrusVGAState
* s
)
867 s
->gr
[0x31] |= CIRRUS_BLT_BUSY
;
869 s
->cirrus_blt_width
= (s
->gr
[0x20] | (s
->gr
[0x21] << 8)) + 1;
870 s
->cirrus_blt_height
= (s
->gr
[0x22] | (s
->gr
[0x23] << 8)) + 1;
871 s
->cirrus_blt_dstpitch
= (s
->gr
[0x24] | (s
->gr
[0x25] << 8));
872 s
->cirrus_blt_srcpitch
= (s
->gr
[0x26] | (s
->gr
[0x27] << 8));
873 s
->cirrus_blt_dstaddr
=
874 (s
->gr
[0x28] | (s
->gr
[0x29] << 8) | (s
->gr
[0x2a] << 16));
875 s
->cirrus_blt_srcaddr
=
876 (s
->gr
[0x2c] | (s
->gr
[0x2d] << 8) | (s
->gr
[0x2e] << 16));
877 s
->cirrus_blt_mode
= s
->gr
[0x30];
878 s
->cirrus_blt_modeext
= s
->gr
[0x33];
879 blt_rop
= s
->gr
[0x32];
882 printf("rop=0x%02x mode=0x%02x modeext=0x%02x w=%d h=%d dpitch=%d spitch=%d daddr=0x%08x saddr=0x%08x writemask=0x%02x\n",
885 s
->cirrus_blt_modeext
,
887 s
->cirrus_blt_height
,
888 s
->cirrus_blt_dstpitch
,
889 s
->cirrus_blt_srcpitch
,
890 s
->cirrus_blt_dstaddr
,
891 s
->cirrus_blt_srcaddr
,
895 switch (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PIXELWIDTHMASK
) {
896 case CIRRUS_BLTMODE_PIXELWIDTH8
:
897 s
->cirrus_blt_pixelwidth
= 1;
899 case CIRRUS_BLTMODE_PIXELWIDTH16
:
900 s
->cirrus_blt_pixelwidth
= 2;
902 case CIRRUS_BLTMODE_PIXELWIDTH24
:
903 s
->cirrus_blt_pixelwidth
= 3;
905 case CIRRUS_BLTMODE_PIXELWIDTH32
:
906 s
->cirrus_blt_pixelwidth
= 4;
910 printf("cirrus: bitblt - pixel width is unknown\n");
914 s
->cirrus_blt_mode
&= ~CIRRUS_BLTMODE_PIXELWIDTHMASK
;
917 cirrus_blt_mode
& (CIRRUS_BLTMODE_MEMSYSSRC
|
918 CIRRUS_BLTMODE_MEMSYSDEST
))
919 == (CIRRUS_BLTMODE_MEMSYSSRC
| CIRRUS_BLTMODE_MEMSYSDEST
)) {
921 printf("cirrus: bitblt - memory-to-memory copy is requested\n");
926 if ((s
->cirrus_blt_modeext
& CIRRUS_BLTMODEEXT_SOLIDFILL
) &&
927 (s
->cirrus_blt_mode
& (CIRRUS_BLTMODE_MEMSYSDEST
|
928 CIRRUS_BLTMODE_TRANSPARENTCOMP
|
929 CIRRUS_BLTMODE_PATTERNCOPY
|
930 CIRRUS_BLTMODE_COLOREXPAND
)) ==
931 (CIRRUS_BLTMODE_PATTERNCOPY
| CIRRUS_BLTMODE_COLOREXPAND
)) {
932 cirrus_bitblt_fgcol(s
);
933 cirrus_bitblt_solidfill(s
, blt_rop
);
935 if ((s
->cirrus_blt_mode
& (CIRRUS_BLTMODE_COLOREXPAND
|
936 CIRRUS_BLTMODE_PATTERNCOPY
)) ==
937 CIRRUS_BLTMODE_COLOREXPAND
) {
939 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_TRANSPARENTCOMP
) {
940 if (s
->cirrus_blt_modeext
& CIRRUS_BLTMODEEXT_COLOREXPINV
)
941 cirrus_bitblt_bgcol(s
);
943 cirrus_bitblt_fgcol(s
);
944 s
->cirrus_rop
= cirrus_colorexpand_transp
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
946 cirrus_bitblt_fgcol(s
);
947 cirrus_bitblt_bgcol(s
);
948 s
->cirrus_rop
= cirrus_colorexpand
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
950 } else if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PATTERNCOPY
) {
951 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_COLOREXPAND
) {
952 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_TRANSPARENTCOMP
) {
953 if (s
->cirrus_blt_modeext
& CIRRUS_BLTMODEEXT_COLOREXPINV
)
954 cirrus_bitblt_bgcol(s
);
956 cirrus_bitblt_fgcol(s
);
957 s
->cirrus_rop
= cirrus_colorexpand_pattern_transp
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
959 cirrus_bitblt_fgcol(s
);
960 cirrus_bitblt_bgcol(s
);
961 s
->cirrus_rop
= cirrus_colorexpand_pattern
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
964 s
->cirrus_rop
= cirrus_patternfill
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
967 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_BACKWARDS
) {
968 s
->cirrus_blt_dstpitch
= -s
->cirrus_blt_dstpitch
;
969 s
->cirrus_blt_srcpitch
= -s
->cirrus_blt_srcpitch
;
970 s
->cirrus_rop
= cirrus_bkwd_rop
[rop_to_index
[blt_rop
]];
972 s
->cirrus_rop
= cirrus_fwd_rop
[rop_to_index
[blt_rop
]];
976 // setup bitblt engine.
977 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_MEMSYSSRC
) {
978 if (!cirrus_bitblt_cputovideo(s
))
980 } else if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_MEMSYSDEST
) {
981 if (!cirrus_bitblt_videotocpu(s
))
984 if (!cirrus_bitblt_videotovideo(s
))
990 cirrus_bitblt_reset(s
);
993 static void cirrus_write_bitblt(CirrusVGAState
* s
, unsigned reg_value
)
997 old_value
= s
->gr
[0x31];
998 s
->gr
[0x31] = reg_value
;
1000 if (((old_value
& CIRRUS_BLT_RESET
) != 0) &&
1001 ((reg_value
& CIRRUS_BLT_RESET
) == 0)) {
1002 cirrus_bitblt_reset(s
);
1003 } else if (((old_value
& CIRRUS_BLT_START
) == 0) &&
1004 ((reg_value
& CIRRUS_BLT_START
) != 0)) {
1005 cirrus_bitblt_start(s
);
1010 /***************************************
1014 ***************************************/
1016 static void cirrus_get_offsets(VGAState
*s1
,
1017 uint32_t *pline_offset
,
1018 uint32_t *pstart_addr
,
1019 uint32_t *pline_compare
)
1021 CirrusVGAState
* s
= (CirrusVGAState
*)s1
;
1022 uint32_t start_addr
, line_offset
, line_compare
;
1024 line_offset
= s
->cr
[0x13]
1025 | ((s
->cr
[0x1b] & 0x10) << 4);
1027 *pline_offset
= line_offset
;
1029 start_addr
= (s
->cr
[0x0c] << 8)
1031 | ((s
->cr
[0x1b] & 0x01) << 16)
1032 | ((s
->cr
[0x1b] & 0x0c) << 15)
1033 | ((s
->cr
[0x1d] & 0x80) << 12);
1034 *pstart_addr
= start_addr
;
1036 line_compare
= s
->cr
[0x18] |
1037 ((s
->cr
[0x07] & 0x10) << 4) |
1038 ((s
->cr
[0x09] & 0x40) << 3);
1039 *pline_compare
= line_compare
;
1042 static uint32_t cirrus_get_bpp16_depth(CirrusVGAState
* s
)
1046 switch (s
->cirrus_hidden_dac_data
& 0xf) {
1049 break; /* Sierra HiColor */
1052 break; /* XGA HiColor */
1055 printf("cirrus: invalid DAC value %x in 16bpp\n",
1056 (s
->cirrus_hidden_dac_data
& 0xf));
1064 static int cirrus_get_bpp(VGAState
*s1
)
1066 CirrusVGAState
* s
= (CirrusVGAState
*)s1
;
1069 if ((s
->sr
[0x07] & 0x01) != 0) {
1071 switch (s
->sr
[0x07] & CIRRUS_SR7_BPP_MASK
) {
1072 case CIRRUS_SR7_BPP_8
:
1075 case CIRRUS_SR7_BPP_16_DOUBLEVCLK
:
1076 ret
= cirrus_get_bpp16_depth(s
);
1078 case CIRRUS_SR7_BPP_24
:
1081 case CIRRUS_SR7_BPP_16
:
1082 ret
= cirrus_get_bpp16_depth(s
);
1084 case CIRRUS_SR7_BPP_32
:
1089 printf("cirrus: unknown bpp - sr7=%x\n", s
->sr
[0x7]);
1102 static void cirrus_get_resolution(VGAState
*s
, int *pwidth
, int *pheight
)
1106 width
= (s
->cr
[0x01] + 1) * 8;
1107 height
= s
->cr
[0x12] |
1108 ((s
->cr
[0x07] & 0x02) << 7) |
1109 ((s
->cr
[0x07] & 0x40) << 3);
1110 height
= (height
+ 1);
1111 /* interlace support */
1112 if (s
->cr
[0x1a] & 0x01)
1113 height
= height
* 2;
1118 /***************************************
1122 ***************************************/
1124 static void cirrus_update_bank_ptr(CirrusVGAState
* s
, unsigned bank_index
)
1129 if ((s
->gr
[0x0b] & 0x01) != 0) /* dual bank */
1130 offset
= s
->gr
[0x09 + bank_index
];
1131 else /* single bank */
1132 offset
= s
->gr
[0x09];
1134 if ((s
->gr
[0x0b] & 0x20) != 0)
1139 if (s
->real_vram_size
<= offset
)
1142 limit
= s
->real_vram_size
- offset
;
1144 if (((s
->gr
[0x0b] & 0x01) == 0) && (bank_index
!= 0)) {
1145 if (limit
> 0x8000) {
1154 s
->cirrus_bank_base
[bank_index
] = offset
;
1155 s
->cirrus_bank_limit
[bank_index
] = limit
;
1157 s
->cirrus_bank_base
[bank_index
] = 0;
1158 s
->cirrus_bank_limit
[bank_index
] = 0;
1162 /***************************************
1164 * I/O access between 0x3c4-0x3c5
1166 ***************************************/
1169 cirrus_hook_read_sr(CirrusVGAState
* s
, unsigned reg_index
, int *reg_value
)
1171 switch (reg_index
) {
1172 case 0x00: // Standard VGA
1173 case 0x01: // Standard VGA
1174 case 0x02: // Standard VGA
1175 case 0x03: // Standard VGA
1176 case 0x04: // Standard VGA
1177 return CIRRUS_HOOK_NOT_HANDLED
;
1178 case 0x06: // Unlock Cirrus extensions
1179 *reg_value
= s
->sr
[reg_index
];
1184 case 0x70: // Graphics Cursor X
1188 case 0xf0: // Graphics Cursor X
1189 *reg_value
= s
->sr
[0x10];
1194 case 0x71: // Graphics Cursor Y
1198 case 0xf1: // Graphics Cursor Y
1199 *reg_value
= s
->sr
[0x11];
1202 case 0x07: // Extended Sequencer Mode
1203 case 0x08: // EEPROM Control
1204 case 0x09: // Scratch Register 0
1205 case 0x0a: // Scratch Register 1
1206 case 0x0b: // VCLK 0
1207 case 0x0c: // VCLK 1
1208 case 0x0d: // VCLK 2
1209 case 0x0e: // VCLK 3
1210 case 0x0f: // DRAM Control
1211 case 0x12: // Graphics Cursor Attribute
1212 case 0x13: // Graphics Cursor Pattern Address
1213 case 0x14: // Scratch Register 2
1214 case 0x15: // Scratch Register 3
1215 case 0x16: // Performance Tuning Register
1216 case 0x17: // Configuration Readback and Extended Control
1217 case 0x18: // Signature Generator Control
1218 case 0x19: // Signal Generator Result
1219 case 0x1a: // Signal Generator Result
1220 case 0x1b: // VCLK 0 Denominator & Post
1221 case 0x1c: // VCLK 1 Denominator & Post
1222 case 0x1d: // VCLK 2 Denominator & Post
1223 case 0x1e: // VCLK 3 Denominator & Post
1224 case 0x1f: // BIOS Write Enable and MCLK select
1226 printf("cirrus: handled inport sr_index %02x\n", reg_index
);
1228 *reg_value
= s
->sr
[reg_index
];
1232 printf("cirrus: inport sr_index %02x\n", reg_index
);
1238 return CIRRUS_HOOK_HANDLED
;
1242 cirrus_hook_write_sr(CirrusVGAState
* s
, unsigned reg_index
, int reg_value
)
1244 switch (reg_index
) {
1245 case 0x00: // Standard VGA
1246 case 0x01: // Standard VGA
1247 case 0x02: // Standard VGA
1248 case 0x03: // Standard VGA
1249 case 0x04: // Standard VGA
1250 return CIRRUS_HOOK_NOT_HANDLED
;
1251 case 0x06: // Unlock Cirrus extensions
1253 if (reg_value
== 0x12) {
1254 s
->sr
[reg_index
] = 0x12;
1256 s
->sr
[reg_index
] = 0x0f;
1262 case 0x70: // Graphics Cursor X
1266 case 0xf0: // Graphics Cursor X
1267 s
->sr
[0x10] = reg_value
;
1268 s
->hw_cursor_x
= (reg_value
<< 3) | (reg_index
>> 5);
1273 case 0x71: // Graphics Cursor Y
1277 case 0xf1: // Graphics Cursor Y
1278 s
->sr
[0x11] = reg_value
;
1279 s
->hw_cursor_y
= (reg_value
<< 3) | (reg_index
>> 5);
1281 case 0x07: // Extended Sequencer Mode
1282 case 0x08: // EEPROM Control
1283 case 0x09: // Scratch Register 0
1284 case 0x0a: // Scratch Register 1
1285 case 0x0b: // VCLK 0
1286 case 0x0c: // VCLK 1
1287 case 0x0d: // VCLK 2
1288 case 0x0e: // VCLK 3
1289 case 0x0f: // DRAM Control
1290 case 0x12: // Graphics Cursor Attribute
1291 case 0x13: // Graphics Cursor Pattern Address
1292 case 0x14: // Scratch Register 2
1293 case 0x15: // Scratch Register 3
1294 case 0x16: // Performance Tuning Register
1295 case 0x18: // Signature Generator Control
1296 case 0x19: // Signature Generator Result
1297 case 0x1a: // Signature Generator Result
1298 case 0x1b: // VCLK 0 Denominator & Post
1299 case 0x1c: // VCLK 1 Denominator & Post
1300 case 0x1d: // VCLK 2 Denominator & Post
1301 case 0x1e: // VCLK 3 Denominator & Post
1302 case 0x1f: // BIOS Write Enable and MCLK select
1303 s
->sr
[reg_index
] = reg_value
;
1305 printf("cirrus: handled outport sr_index %02x, sr_value %02x\n",
1306 reg_index
, reg_value
);
1308 if (reg_index
== 0x07)
1309 cirrus_update_memory_access(s
);
1311 case 0x17: // Configuration Readback and Extended Control
1312 s
->sr
[reg_index
] = (s
->sr
[reg_index
] & 0x38) | (reg_value
& 0xc7);
1313 cirrus_update_memory_access(s
);
1317 printf("cirrus: outport sr_index %02x, sr_value %02x\n", reg_index
,
1323 return CIRRUS_HOOK_HANDLED
;
1326 /***************************************
1328 * I/O access at 0x3c6
1330 ***************************************/
1332 static void cirrus_read_hidden_dac(CirrusVGAState
* s
, int *reg_value
)
1335 if (++s
->cirrus_hidden_dac_lockindex
== 5) {
1336 *reg_value
= s
->cirrus_hidden_dac_data
;
1337 s
->cirrus_hidden_dac_lockindex
= 0;
1341 static void cirrus_write_hidden_dac(CirrusVGAState
* s
, int reg_value
)
1343 if (s
->cirrus_hidden_dac_lockindex
== 4) {
1344 s
->cirrus_hidden_dac_data
= reg_value
;
1345 #if defined(DEBUG_CIRRUS)
1346 printf("cirrus: outport hidden DAC, value %02x\n", reg_value
);
1349 s
->cirrus_hidden_dac_lockindex
= 0;
1352 /***************************************
1354 * I/O access at 0x3c9
1356 ***************************************/
1358 static int cirrus_hook_read_palette(CirrusVGAState
* s
, int *reg_value
)
1360 if (!(s
->sr
[0x12] & CIRRUS_CURSOR_HIDDENPEL
))
1361 return CIRRUS_HOOK_NOT_HANDLED
;
1363 s
->cirrus_hidden_palette
[(s
->dac_read_index
& 0x0f) * 3 +
1365 if (++s
->dac_sub_index
== 3) {
1366 s
->dac_sub_index
= 0;
1367 s
->dac_read_index
++;
1369 return CIRRUS_HOOK_HANDLED
;
1372 static int cirrus_hook_write_palette(CirrusVGAState
* s
, int reg_value
)
1374 if (!(s
->sr
[0x12] & CIRRUS_CURSOR_HIDDENPEL
))
1375 return CIRRUS_HOOK_NOT_HANDLED
;
1376 s
->dac_cache
[s
->dac_sub_index
] = reg_value
;
1377 if (++s
->dac_sub_index
== 3) {
1378 memcpy(&s
->cirrus_hidden_palette
[(s
->dac_write_index
& 0x0f) * 3],
1380 /* XXX update cursor */
1381 s
->dac_sub_index
= 0;
1382 s
->dac_write_index
++;
1384 return CIRRUS_HOOK_HANDLED
;
1387 /***************************************
1389 * I/O access between 0x3ce-0x3cf
1391 ***************************************/
1394 cirrus_hook_read_gr(CirrusVGAState
* s
, unsigned reg_index
, int *reg_value
)
1396 switch (reg_index
) {
1397 case 0x00: // Standard VGA, BGCOLOR 0x000000ff
1398 *reg_value
= s
->cirrus_shadow_gr0
;
1399 return CIRRUS_HOOK_HANDLED
;
1400 case 0x01: // Standard VGA, FGCOLOR 0x000000ff
1401 *reg_value
= s
->cirrus_shadow_gr1
;
1402 return CIRRUS_HOOK_HANDLED
;
1403 case 0x02: // Standard VGA
1404 case 0x03: // Standard VGA
1405 case 0x04: // Standard VGA
1406 case 0x06: // Standard VGA
1407 case 0x07: // Standard VGA
1408 case 0x08: // Standard VGA
1409 return CIRRUS_HOOK_NOT_HANDLED
;
1410 case 0x05: // Standard VGA, Cirrus extended mode
1415 if (reg_index
< 0x3a) {
1416 *reg_value
= s
->gr
[reg_index
];
1419 printf("cirrus: inport gr_index %02x\n", reg_index
);
1424 return CIRRUS_HOOK_HANDLED
;
1428 cirrus_hook_write_gr(CirrusVGAState
* s
, unsigned reg_index
, int reg_value
)
1430 #if defined(DEBUG_BITBLT) && 0
1431 printf("gr%02x: %02x\n", reg_index
, reg_value
);
1433 switch (reg_index
) {
1434 case 0x00: // Standard VGA, BGCOLOR 0x000000ff
1435 s
->cirrus_shadow_gr0
= reg_value
;
1436 return CIRRUS_HOOK_NOT_HANDLED
;
1437 case 0x01: // Standard VGA, FGCOLOR 0x000000ff
1438 s
->cirrus_shadow_gr1
= reg_value
;
1439 return CIRRUS_HOOK_NOT_HANDLED
;
1440 case 0x02: // Standard VGA
1441 case 0x03: // Standard VGA
1442 case 0x04: // Standard VGA
1443 case 0x06: // Standard VGA
1444 case 0x07: // Standard VGA
1445 case 0x08: // Standard VGA
1446 return CIRRUS_HOOK_NOT_HANDLED
;
1447 case 0x05: // Standard VGA, Cirrus extended mode
1448 s
->gr
[reg_index
] = reg_value
& 0x7f;
1449 cirrus_update_memory_access(s
);
1451 case 0x09: // bank offset #0
1452 case 0x0A: // bank offset #1
1453 s
->gr
[reg_index
] = reg_value
;
1454 cirrus_update_bank_ptr(s
, 0);
1455 cirrus_update_bank_ptr(s
, 1);
1456 cirrus_update_memory_access(s
);
1459 s
->gr
[reg_index
] = reg_value
;
1460 cirrus_update_bank_ptr(s
, 0);
1461 cirrus_update_bank_ptr(s
, 1);
1462 cirrus_update_memory_access(s
);
1464 case 0x10: // BGCOLOR 0x0000ff00
1465 case 0x11: // FGCOLOR 0x0000ff00
1466 case 0x12: // BGCOLOR 0x00ff0000
1467 case 0x13: // FGCOLOR 0x00ff0000
1468 case 0x14: // BGCOLOR 0xff000000
1469 case 0x15: // FGCOLOR 0xff000000
1470 case 0x20: // BLT WIDTH 0x0000ff
1471 case 0x22: // BLT HEIGHT 0x0000ff
1472 case 0x24: // BLT DEST PITCH 0x0000ff
1473 case 0x26: // BLT SRC PITCH 0x0000ff
1474 case 0x28: // BLT DEST ADDR 0x0000ff
1475 case 0x29: // BLT DEST ADDR 0x00ff00
1476 case 0x2c: // BLT SRC ADDR 0x0000ff
1477 case 0x2d: // BLT SRC ADDR 0x00ff00
1478 case 0x2f: // BLT WRITEMASK
1479 case 0x30: // BLT MODE
1480 case 0x32: // RASTER OP
1481 case 0x33: // BLT MODEEXT
1482 case 0x34: // BLT TRANSPARENT COLOR 0x00ff
1483 case 0x35: // BLT TRANSPARENT COLOR 0xff00
1484 case 0x38: // BLT TRANSPARENT COLOR MASK 0x00ff
1485 case 0x39: // BLT TRANSPARENT COLOR MASK 0xff00
1486 s
->gr
[reg_index
] = reg_value
;
1488 case 0x21: // BLT WIDTH 0x001f00
1489 case 0x23: // BLT HEIGHT 0x001f00
1490 case 0x25: // BLT DEST PITCH 0x001f00
1491 case 0x27: // BLT SRC PITCH 0x001f00
1492 s
->gr
[reg_index
] = reg_value
& 0x1f;
1494 case 0x2a: // BLT DEST ADDR 0x3f0000
1495 s
->gr
[reg_index
] = reg_value
& 0x3f;
1496 /* if auto start mode, starts bit blt now */
1497 if (s
->gr
[0x31] & CIRRUS_BLT_AUTOSTART
) {
1498 cirrus_bitblt_start(s
);
1501 case 0x2e: // BLT SRC ADDR 0x3f0000
1502 s
->gr
[reg_index
] = reg_value
& 0x3f;
1504 case 0x31: // BLT STATUS/START
1505 cirrus_write_bitblt(s
, reg_value
);
1509 printf("cirrus: outport gr_index %02x, gr_value %02x\n", reg_index
,
1515 return CIRRUS_HOOK_HANDLED
;
1518 /***************************************
1520 * I/O access between 0x3d4-0x3d5
1522 ***************************************/
1525 cirrus_hook_read_cr(CirrusVGAState
* s
, unsigned reg_index
, int *reg_value
)
1527 switch (reg_index
) {
1528 case 0x00: // Standard VGA
1529 case 0x01: // Standard VGA
1530 case 0x02: // Standard VGA
1531 case 0x03: // Standard VGA
1532 case 0x04: // Standard VGA
1533 case 0x05: // Standard VGA
1534 case 0x06: // Standard VGA
1535 case 0x07: // Standard VGA
1536 case 0x08: // Standard VGA
1537 case 0x09: // Standard VGA
1538 case 0x0a: // Standard VGA
1539 case 0x0b: // Standard VGA
1540 case 0x0c: // Standard VGA
1541 case 0x0d: // Standard VGA
1542 case 0x0e: // Standard VGA
1543 case 0x0f: // Standard VGA
1544 case 0x10: // Standard VGA
1545 case 0x11: // Standard VGA
1546 case 0x12: // Standard VGA
1547 case 0x13: // Standard VGA
1548 case 0x14: // Standard VGA
1549 case 0x15: // Standard VGA
1550 case 0x16: // Standard VGA
1551 case 0x17: // Standard VGA
1552 case 0x18: // Standard VGA
1553 return CIRRUS_HOOK_NOT_HANDLED
;
1554 case 0x19: // Interlace End
1555 case 0x1a: // Miscellaneous Control
1556 case 0x1b: // Extended Display Control
1557 case 0x1c: // Sync Adjust and Genlock
1558 case 0x1d: // Overlay Extended Control
1559 case 0x22: // Graphics Data Latches Readback (R)
1560 case 0x24: // Attribute Controller Toggle Readback (R)
1561 case 0x25: // Part Status
1562 case 0x27: // Part ID (R)
1563 *reg_value
= s
->cr
[reg_index
];
1565 case 0x26: // Attribute Controller Index Readback (R)
1566 *reg_value
= s
->ar_index
& 0x3f;
1570 printf("cirrus: inport cr_index %02x\n", reg_index
);
1576 return CIRRUS_HOOK_HANDLED
;
1580 cirrus_hook_write_cr(CirrusVGAState
* s
, unsigned reg_index
, int reg_value
)
1582 switch (reg_index
) {
1583 case 0x00: // Standard VGA
1584 case 0x01: // Standard VGA
1585 case 0x02: // Standard VGA
1586 case 0x03: // Standard VGA
1587 case 0x04: // Standard VGA
1588 case 0x05: // Standard VGA
1589 case 0x06: // Standard VGA
1590 case 0x07: // Standard VGA
1591 case 0x08: // Standard VGA
1592 case 0x09: // Standard VGA
1593 case 0x0a: // Standard VGA
1594 case 0x0b: // Standard VGA
1595 case 0x0c: // Standard VGA
1596 case 0x0d: // Standard VGA
1597 case 0x0e: // Standard VGA
1598 case 0x0f: // Standard VGA
1599 case 0x10: // Standard VGA
1600 case 0x11: // Standard VGA
1601 case 0x12: // Standard VGA
1602 case 0x13: // Standard VGA
1603 case 0x14: // Standard VGA
1604 case 0x15: // Standard VGA
1605 case 0x16: // Standard VGA
1606 case 0x17: // Standard VGA
1607 case 0x18: // Standard VGA
1608 return CIRRUS_HOOK_NOT_HANDLED
;
1609 case 0x19: // Interlace End
1610 case 0x1a: // Miscellaneous Control
1611 case 0x1b: // Extended Display Control
1612 case 0x1c: // Sync Adjust and Genlock
1613 case 0x1d: // Overlay Extended Control
1614 s
->cr
[reg_index
] = reg_value
;
1616 printf("cirrus: handled outport cr_index %02x, cr_value %02x\n",
1617 reg_index
, reg_value
);
1620 case 0x22: // Graphics Data Latches Readback (R)
1621 case 0x24: // Attribute Controller Toggle Readback (R)
1622 case 0x26: // Attribute Controller Index Readback (R)
1623 case 0x27: // Part ID (R)
1625 case 0x25: // Part Status
1628 printf("cirrus: outport cr_index %02x, cr_value %02x\n", reg_index
,
1634 return CIRRUS_HOOK_HANDLED
;
1637 /***************************************
1639 * memory-mapped I/O (bitblt)
1641 ***************************************/
1643 static uint8_t cirrus_mmio_blt_read(CirrusVGAState
* s
, unsigned address
)
1648 case (CIRRUS_MMIO_BLTBGCOLOR
+ 0):
1649 cirrus_hook_read_gr(s
, 0x00, &value
);
1651 case (CIRRUS_MMIO_BLTBGCOLOR
+ 1):
1652 cirrus_hook_read_gr(s
, 0x10, &value
);
1654 case (CIRRUS_MMIO_BLTBGCOLOR
+ 2):
1655 cirrus_hook_read_gr(s
, 0x12, &value
);
1657 case (CIRRUS_MMIO_BLTBGCOLOR
+ 3):
1658 cirrus_hook_read_gr(s
, 0x14, &value
);
1660 case (CIRRUS_MMIO_BLTFGCOLOR
+ 0):
1661 cirrus_hook_read_gr(s
, 0x01, &value
);
1663 case (CIRRUS_MMIO_BLTFGCOLOR
+ 1):
1664 cirrus_hook_read_gr(s
, 0x11, &value
);
1666 case (CIRRUS_MMIO_BLTFGCOLOR
+ 2):
1667 cirrus_hook_read_gr(s
, 0x13, &value
);
1669 case (CIRRUS_MMIO_BLTFGCOLOR
+ 3):
1670 cirrus_hook_read_gr(s
, 0x15, &value
);
1672 case (CIRRUS_MMIO_BLTWIDTH
+ 0):
1673 cirrus_hook_read_gr(s
, 0x20, &value
);
1675 case (CIRRUS_MMIO_BLTWIDTH
+ 1):
1676 cirrus_hook_read_gr(s
, 0x21, &value
);
1678 case (CIRRUS_MMIO_BLTHEIGHT
+ 0):
1679 cirrus_hook_read_gr(s
, 0x22, &value
);
1681 case (CIRRUS_MMIO_BLTHEIGHT
+ 1):
1682 cirrus_hook_read_gr(s
, 0x23, &value
);
1684 case (CIRRUS_MMIO_BLTDESTPITCH
+ 0):
1685 cirrus_hook_read_gr(s
, 0x24, &value
);
1687 case (CIRRUS_MMIO_BLTDESTPITCH
+ 1):
1688 cirrus_hook_read_gr(s
, 0x25, &value
);
1690 case (CIRRUS_MMIO_BLTSRCPITCH
+ 0):
1691 cirrus_hook_read_gr(s
, 0x26, &value
);
1693 case (CIRRUS_MMIO_BLTSRCPITCH
+ 1):
1694 cirrus_hook_read_gr(s
, 0x27, &value
);
1696 case (CIRRUS_MMIO_BLTDESTADDR
+ 0):
1697 cirrus_hook_read_gr(s
, 0x28, &value
);
1699 case (CIRRUS_MMIO_BLTDESTADDR
+ 1):
1700 cirrus_hook_read_gr(s
, 0x29, &value
);
1702 case (CIRRUS_MMIO_BLTDESTADDR
+ 2):
1703 cirrus_hook_read_gr(s
, 0x2a, &value
);
1705 case (CIRRUS_MMIO_BLTSRCADDR
+ 0):
1706 cirrus_hook_read_gr(s
, 0x2c, &value
);
1708 case (CIRRUS_MMIO_BLTSRCADDR
+ 1):
1709 cirrus_hook_read_gr(s
, 0x2d, &value
);
1711 case (CIRRUS_MMIO_BLTSRCADDR
+ 2):
1712 cirrus_hook_read_gr(s
, 0x2e, &value
);
1714 case CIRRUS_MMIO_BLTWRITEMASK
:
1715 cirrus_hook_read_gr(s
, 0x2f, &value
);
1717 case CIRRUS_MMIO_BLTMODE
:
1718 cirrus_hook_read_gr(s
, 0x30, &value
);
1720 case CIRRUS_MMIO_BLTROP
:
1721 cirrus_hook_read_gr(s
, 0x32, &value
);
1723 case CIRRUS_MMIO_BLTMODEEXT
:
1724 cirrus_hook_read_gr(s
, 0x33, &value
);
1726 case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR
+ 0):
1727 cirrus_hook_read_gr(s
, 0x34, &value
);
1729 case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR
+ 1):
1730 cirrus_hook_read_gr(s
, 0x35, &value
);
1732 case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK
+ 0):
1733 cirrus_hook_read_gr(s
, 0x38, &value
);
1735 case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK
+ 1):
1736 cirrus_hook_read_gr(s
, 0x39, &value
);
1738 case CIRRUS_MMIO_BLTSTATUS
:
1739 cirrus_hook_read_gr(s
, 0x31, &value
);
1743 printf("cirrus: mmio read - address 0x%04x\n", address
);
1748 return (uint8_t) value
;
1751 static void cirrus_mmio_blt_write(CirrusVGAState
* s
, unsigned address
,
1755 case (CIRRUS_MMIO_BLTBGCOLOR
+ 0):
1756 cirrus_hook_write_gr(s
, 0x00, value
);
1758 case (CIRRUS_MMIO_BLTBGCOLOR
+ 1):
1759 cirrus_hook_write_gr(s
, 0x10, value
);
1761 case (CIRRUS_MMIO_BLTBGCOLOR
+ 2):
1762 cirrus_hook_write_gr(s
, 0x12, value
);
1764 case (CIRRUS_MMIO_BLTBGCOLOR
+ 3):
1765 cirrus_hook_write_gr(s
, 0x14, value
);
1767 case (CIRRUS_MMIO_BLTFGCOLOR
+ 0):
1768 cirrus_hook_write_gr(s
, 0x01, value
);
1770 case (CIRRUS_MMIO_BLTFGCOLOR
+ 1):
1771 cirrus_hook_write_gr(s
, 0x11, value
);
1773 case (CIRRUS_MMIO_BLTFGCOLOR
+ 2):
1774 cirrus_hook_write_gr(s
, 0x13, value
);
1776 case (CIRRUS_MMIO_BLTFGCOLOR
+ 3):
1777 cirrus_hook_write_gr(s
, 0x15, value
);
1779 case (CIRRUS_MMIO_BLTWIDTH
+ 0):
1780 cirrus_hook_write_gr(s
, 0x20, value
);
1782 case (CIRRUS_MMIO_BLTWIDTH
+ 1):
1783 cirrus_hook_write_gr(s
, 0x21, value
);
1785 case (CIRRUS_MMIO_BLTHEIGHT
+ 0):
1786 cirrus_hook_write_gr(s
, 0x22, value
);
1788 case (CIRRUS_MMIO_BLTHEIGHT
+ 1):
1789 cirrus_hook_write_gr(s
, 0x23, value
);
1791 case (CIRRUS_MMIO_BLTDESTPITCH
+ 0):
1792 cirrus_hook_write_gr(s
, 0x24, value
);
1794 case (CIRRUS_MMIO_BLTDESTPITCH
+ 1):
1795 cirrus_hook_write_gr(s
, 0x25, value
);
1797 case (CIRRUS_MMIO_BLTSRCPITCH
+ 0):
1798 cirrus_hook_write_gr(s
, 0x26, value
);
1800 case (CIRRUS_MMIO_BLTSRCPITCH
+ 1):
1801 cirrus_hook_write_gr(s
, 0x27, value
);
1803 case (CIRRUS_MMIO_BLTDESTADDR
+ 0):
1804 cirrus_hook_write_gr(s
, 0x28, value
);
1806 case (CIRRUS_MMIO_BLTDESTADDR
+ 1):
1807 cirrus_hook_write_gr(s
, 0x29, value
);
1809 case (CIRRUS_MMIO_BLTDESTADDR
+ 2):
1810 cirrus_hook_write_gr(s
, 0x2a, value
);
1812 case (CIRRUS_MMIO_BLTDESTADDR
+ 3):
1815 case (CIRRUS_MMIO_BLTSRCADDR
+ 0):
1816 cirrus_hook_write_gr(s
, 0x2c, value
);
1818 case (CIRRUS_MMIO_BLTSRCADDR
+ 1):
1819 cirrus_hook_write_gr(s
, 0x2d, value
);
1821 case (CIRRUS_MMIO_BLTSRCADDR
+ 2):
1822 cirrus_hook_write_gr(s
, 0x2e, value
);
1824 case CIRRUS_MMIO_BLTWRITEMASK
:
1825 cirrus_hook_write_gr(s
, 0x2f, value
);
1827 case CIRRUS_MMIO_BLTMODE
:
1828 cirrus_hook_write_gr(s
, 0x30, value
);
1830 case CIRRUS_MMIO_BLTROP
:
1831 cirrus_hook_write_gr(s
, 0x32, value
);
1833 case CIRRUS_MMIO_BLTMODEEXT
:
1834 cirrus_hook_write_gr(s
, 0x33, value
);
1836 case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR
+ 0):
1837 cirrus_hook_write_gr(s
, 0x34, value
);
1839 case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR
+ 1):
1840 cirrus_hook_write_gr(s
, 0x35, value
);
1842 case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK
+ 0):
1843 cirrus_hook_write_gr(s
, 0x38, value
);
1845 case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK
+ 1):
1846 cirrus_hook_write_gr(s
, 0x39, value
);
1848 case CIRRUS_MMIO_BLTSTATUS
:
1849 cirrus_hook_write_gr(s
, 0x31, value
);
1853 printf("cirrus: mmio write - addr 0x%04x val 0x%02x (ignored)\n",
1860 /***************************************
1864 * assume TARGET_PAGE_SIZE >= 16
1866 ***************************************/
1868 static void cirrus_mem_writeb_mode4and5_8bpp(CirrusVGAState
* s
,
1874 unsigned val
= mem_value
;
1877 dst
= s
->vram_ptr
+ offset
;
1878 for (x
= 0; x
< 8; x
++) {
1880 *dst
= s
->cirrus_shadow_gr1
;
1881 } else if (mode
== 5) {
1882 *dst
= s
->cirrus_shadow_gr0
;
1887 cpu_physical_memory_set_dirty(s
->vram_offset
+ offset
);
1888 cpu_physical_memory_set_dirty(s
->vram_offset
+ offset
+ 7);
1891 static void cirrus_mem_writeb_mode4and5_16bpp(CirrusVGAState
* s
,
1897 unsigned val
= mem_value
;
1900 dst
= s
->vram_ptr
+ offset
;
1901 for (x
= 0; x
< 8; x
++) {
1903 *dst
= s
->cirrus_shadow_gr1
;
1904 *(dst
+ 1) = s
->gr
[0x11];
1905 } else if (mode
== 5) {
1906 *dst
= s
->cirrus_shadow_gr0
;
1907 *(dst
+ 1) = s
->gr
[0x10];
1912 cpu_physical_memory_set_dirty(s
->vram_offset
+ offset
);
1913 cpu_physical_memory_set_dirty(s
->vram_offset
+ offset
+ 15);
1916 /***************************************
1918 * memory access between 0xa0000-0xbffff
1920 ***************************************/
1922 static uint32_t cirrus_vga_mem_readb(void *opaque
, target_phys_addr_t addr
)
1924 CirrusVGAState
*s
= opaque
;
1925 unsigned bank_index
;
1926 unsigned bank_offset
;
1929 if ((s
->sr
[0x07] & 0x01) == 0) {
1930 return vga_mem_readb(s
, addr
);
1935 if (addr
< 0x10000) {
1936 /* XXX handle bitblt */
1938 bank_index
= addr
>> 15;
1939 bank_offset
= addr
& 0x7fff;
1940 if (bank_offset
< s
->cirrus_bank_limit
[bank_index
]) {
1941 bank_offset
+= s
->cirrus_bank_base
[bank_index
];
1942 if ((s
->gr
[0x0B] & 0x14) == 0x14) {
1944 } else if (s
->gr
[0x0B] & 0x02) {
1947 bank_offset
&= s
->cirrus_addr_mask
;
1948 val
= *(s
->vram_ptr
+ bank_offset
);
1951 } else if (addr
>= 0x18000 && addr
< 0x18100) {
1952 /* memory-mapped I/O */
1954 if ((s
->sr
[0x17] & 0x44) == 0x04) {
1955 val
= cirrus_mmio_blt_read(s
, addr
& 0xff);
1960 printf("cirrus: mem_readb %06x\n", addr
);
1966 static uint32_t cirrus_vga_mem_readw(void *opaque
, target_phys_addr_t addr
)
1969 #ifdef TARGET_WORDS_BIGENDIAN
1970 v
= cirrus_vga_mem_readb(opaque
, addr
) << 8;
1971 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 1);
1973 v
= cirrus_vga_mem_readb(opaque
, addr
);
1974 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 1) << 8;
1979 static uint32_t cirrus_vga_mem_readl(void *opaque
, target_phys_addr_t addr
)
1982 #ifdef TARGET_WORDS_BIGENDIAN
1983 v
= cirrus_vga_mem_readb(opaque
, addr
) << 24;
1984 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 1) << 16;
1985 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 2) << 8;
1986 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 3);
1988 v
= cirrus_vga_mem_readb(opaque
, addr
);
1989 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 1) << 8;
1990 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 2) << 16;
1991 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 3) << 24;
1996 static void cirrus_vga_mem_writeb(void *opaque
, target_phys_addr_t addr
,
1999 CirrusVGAState
*s
= opaque
;
2000 unsigned bank_index
;
2001 unsigned bank_offset
;
2004 if ((s
->sr
[0x07] & 0x01) == 0) {
2005 vga_mem_writeb(s
, addr
, mem_value
);
2011 if (addr
< 0x10000) {
2012 if (s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
) {
2014 *s
->cirrus_srcptr
++ = (uint8_t) mem_value
;
2015 if (s
->cirrus_srcptr
>= s
->cirrus_srcptr_end
) {
2016 cirrus_bitblt_cputovideo_next(s
);
2020 bank_index
= addr
>> 15;
2021 bank_offset
= addr
& 0x7fff;
2022 if (bank_offset
< s
->cirrus_bank_limit
[bank_index
]) {
2023 bank_offset
+= s
->cirrus_bank_base
[bank_index
];
2024 if ((s
->gr
[0x0B] & 0x14) == 0x14) {
2026 } else if (s
->gr
[0x0B] & 0x02) {
2029 bank_offset
&= s
->cirrus_addr_mask
;
2030 mode
= s
->gr
[0x05] & 0x7;
2031 if (mode
< 4 || mode
> 5 || ((s
->gr
[0x0B] & 0x4) == 0)) {
2032 *(s
->vram_ptr
+ bank_offset
) = mem_value
;
2033 cpu_physical_memory_set_dirty(s
->vram_offset
+
2036 if ((s
->gr
[0x0B] & 0x14) != 0x14) {
2037 cirrus_mem_writeb_mode4and5_8bpp(s
, mode
,
2041 cirrus_mem_writeb_mode4and5_16bpp(s
, mode
,
2048 } else if (addr
>= 0x18000 && addr
< 0x18100) {
2049 /* memory-mapped I/O */
2050 if ((s
->sr
[0x17] & 0x44) == 0x04) {
2051 cirrus_mmio_blt_write(s
, addr
& 0xff, mem_value
);
2055 printf("cirrus: mem_writeb %06x value %02x\n", addr
, mem_value
);
2060 static void cirrus_vga_mem_writew(void *opaque
, target_phys_addr_t addr
, uint32_t val
)
2062 #ifdef TARGET_WORDS_BIGENDIAN
2063 cirrus_vga_mem_writeb(opaque
, addr
, (val
>> 8) & 0xff);
2064 cirrus_vga_mem_writeb(opaque
, addr
+ 1, val
& 0xff);
2066 cirrus_vga_mem_writeb(opaque
, addr
, val
& 0xff);
2067 cirrus_vga_mem_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2071 static void cirrus_vga_mem_writel(void *opaque
, target_phys_addr_t addr
, uint32_t val
)
2073 #ifdef TARGET_WORDS_BIGENDIAN
2074 cirrus_vga_mem_writeb(opaque
, addr
, (val
>> 24) & 0xff);
2075 cirrus_vga_mem_writeb(opaque
, addr
+ 1, (val
>> 16) & 0xff);
2076 cirrus_vga_mem_writeb(opaque
, addr
+ 2, (val
>> 8) & 0xff);
2077 cirrus_vga_mem_writeb(opaque
, addr
+ 3, val
& 0xff);
2079 cirrus_vga_mem_writeb(opaque
, addr
, val
& 0xff);
2080 cirrus_vga_mem_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2081 cirrus_vga_mem_writeb(opaque
, addr
+ 2, (val
>> 16) & 0xff);
2082 cirrus_vga_mem_writeb(opaque
, addr
+ 3, (val
>> 24) & 0xff);
2086 static CPUReadMemoryFunc
*cirrus_vga_mem_read
[3] = {
2087 cirrus_vga_mem_readb
,
2088 cirrus_vga_mem_readw
,
2089 cirrus_vga_mem_readl
,
2092 static CPUWriteMemoryFunc
*cirrus_vga_mem_write
[3] = {
2093 cirrus_vga_mem_writeb
,
2094 cirrus_vga_mem_writew
,
2095 cirrus_vga_mem_writel
,
2098 /***************************************
2102 ***************************************/
2104 static inline void invalidate_cursor1(CirrusVGAState
*s
)
2106 if (s
->last_hw_cursor_size
) {
2107 vga_invalidate_scanlines((VGAState
*)s
,
2108 s
->last_hw_cursor_y
+ s
->last_hw_cursor_y_start
,
2109 s
->last_hw_cursor_y
+ s
->last_hw_cursor_y_end
);
2113 static inline void cirrus_cursor_compute_yrange(CirrusVGAState
*s
)
2117 int y
, y_min
, y_max
;
2119 src
= s
->vram_ptr
+ s
->real_vram_size
- 16 * 1024;
2120 if (s
->sr
[0x12] & CIRRUS_CURSOR_LARGE
) {
2121 src
+= (s
->sr
[0x13] & 0x3c) * 256;
2124 for(y
= 0; y
< 64; y
++) {
2125 content
= ((uint32_t *)src
)[0] |
2126 ((uint32_t *)src
)[1] |
2127 ((uint32_t *)src
)[2] |
2128 ((uint32_t *)src
)[3];
2138 src
+= (s
->sr
[0x13] & 0x3f) * 256;
2141 for(y
= 0; y
< 32; y
++) {
2142 content
= ((uint32_t *)src
)[0] |
2143 ((uint32_t *)(src
+ 128))[0];
2153 if (y_min
> y_max
) {
2154 s
->last_hw_cursor_y_start
= 0;
2155 s
->last_hw_cursor_y_end
= 0;
2157 s
->last_hw_cursor_y_start
= y_min
;
2158 s
->last_hw_cursor_y_end
= y_max
+ 1;
2162 /* NOTE: we do not currently handle the cursor bitmap change, so we
2163 update the cursor only if it moves. */
2164 static void cirrus_cursor_invalidate(VGAState
*s1
)
2166 CirrusVGAState
*s
= (CirrusVGAState
*)s1
;
2169 if (!s
->sr
[0x12] & CIRRUS_CURSOR_SHOW
) {
2172 if (s
->sr
[0x12] & CIRRUS_CURSOR_LARGE
)
2177 /* invalidate last cursor and new cursor if any change */
2178 if (s
->last_hw_cursor_size
!= size
||
2179 s
->last_hw_cursor_x
!= s
->hw_cursor_x
||
2180 s
->last_hw_cursor_y
!= s
->hw_cursor_y
) {
2182 invalidate_cursor1(s
);
2184 s
->last_hw_cursor_size
= size
;
2185 s
->last_hw_cursor_x
= s
->hw_cursor_x
;
2186 s
->last_hw_cursor_y
= s
->hw_cursor_y
;
2187 /* compute the real cursor min and max y */
2188 cirrus_cursor_compute_yrange(s
);
2189 invalidate_cursor1(s
);
2193 static void cirrus_cursor_draw_line(VGAState
*s1
, uint8_t *d1
, int scr_y
)
2195 CirrusVGAState
*s
= (CirrusVGAState
*)s1
;
2196 int w
, h
, bpp
, x1
, x2
, poffset
;
2197 unsigned int color0
, color1
;
2198 const uint8_t *palette
, *src
;
2201 if (!(s
->sr
[0x12] & CIRRUS_CURSOR_SHOW
))
2203 /* fast test to see if the cursor intersects with the scan line */
2204 if (s
->sr
[0x12] & CIRRUS_CURSOR_LARGE
) {
2209 if (scr_y
< s
->hw_cursor_y
||
2210 scr_y
>= (s
->hw_cursor_y
+ h
))
2213 src
= s
->vram_ptr
+ s
->real_vram_size
- 16 * 1024;
2214 if (s
->sr
[0x12] & CIRRUS_CURSOR_LARGE
) {
2215 src
+= (s
->sr
[0x13] & 0x3c) * 256;
2216 src
+= (scr_y
- s
->hw_cursor_y
) * 16;
2218 content
= ((uint32_t *)src
)[0] |
2219 ((uint32_t *)src
)[1] |
2220 ((uint32_t *)src
)[2] |
2221 ((uint32_t *)src
)[3];
2223 src
+= (s
->sr
[0x13] & 0x3f) * 256;
2224 src
+= (scr_y
- s
->hw_cursor_y
) * 4;
2226 content
= ((uint32_t *)src
)[0] |
2227 ((uint32_t *)(src
+ 128))[0];
2229 /* if nothing to draw, no need to continue */
2234 x1
= s
->hw_cursor_x
;
2235 if (x1
>= s
->last_scr_width
)
2237 x2
= s
->hw_cursor_x
+ w
;
2238 if (x2
> s
->last_scr_width
)
2239 x2
= s
->last_scr_width
;
2241 palette
= s
->cirrus_hidden_palette
;
2242 color0
= s
->rgb_to_pixel(c6_to_8(palette
[0x0 * 3]),
2243 c6_to_8(palette
[0x0 * 3 + 1]),
2244 c6_to_8(palette
[0x0 * 3 + 2]));
2245 color1
= s
->rgb_to_pixel(c6_to_8(palette
[0xf * 3]),
2246 c6_to_8(palette
[0xf * 3 + 1]),
2247 c6_to_8(palette
[0xf * 3 + 2]));
2248 bpp
= ((s
->ds
->depth
+ 7) >> 3);
2250 switch(s
->ds
->depth
) {
2254 vga_draw_cursor_line_8(d1
, src
, poffset
, w
, color0
, color1
, 0xff);
2257 vga_draw_cursor_line_16(d1
, src
, poffset
, w
, color0
, color1
, 0x7fff);
2260 vga_draw_cursor_line_16(d1
, src
, poffset
, w
, color0
, color1
, 0xffff);
2263 vga_draw_cursor_line_32(d1
, src
, poffset
, w
, color0
, color1
, 0xffffff);
2268 /***************************************
2272 ***************************************/
2274 static uint32_t cirrus_linear_readb(void *opaque
, target_phys_addr_t addr
)
2276 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2279 addr
&= s
->cirrus_addr_mask
;
2281 if (((s
->sr
[0x17] & 0x44) == 0x44) &&
2282 ((addr
& s
->linear_mmio_mask
) == s
->linear_mmio_mask
)) {
2283 /* memory-mapped I/O */
2284 ret
= cirrus_mmio_blt_read(s
, addr
& 0xff);
2286 /* XXX handle bitblt */
2290 if ((s
->gr
[0x0B] & 0x14) == 0x14) {
2292 } else if (s
->gr
[0x0B] & 0x02) {
2295 addr
&= s
->cirrus_addr_mask
;
2296 ret
= *(s
->vram_ptr
+ addr
);
2302 static uint32_t cirrus_linear_readw(void *opaque
, target_phys_addr_t addr
)
2305 #ifdef TARGET_WORDS_BIGENDIAN
2306 v
= cirrus_linear_readb(opaque
, addr
) << 8;
2307 v
|= cirrus_linear_readb(opaque
, addr
+ 1);
2309 v
= cirrus_linear_readb(opaque
, addr
);
2310 v
|= cirrus_linear_readb(opaque
, addr
+ 1) << 8;
2315 static uint32_t cirrus_linear_readl(void *opaque
, target_phys_addr_t addr
)
2318 #ifdef TARGET_WORDS_BIGENDIAN
2319 v
= cirrus_linear_readb(opaque
, addr
) << 24;
2320 v
|= cirrus_linear_readb(opaque
, addr
+ 1) << 16;
2321 v
|= cirrus_linear_readb(opaque
, addr
+ 2) << 8;
2322 v
|= cirrus_linear_readb(opaque
, addr
+ 3);
2324 v
= cirrus_linear_readb(opaque
, addr
);
2325 v
|= cirrus_linear_readb(opaque
, addr
+ 1) << 8;
2326 v
|= cirrus_linear_readb(opaque
, addr
+ 2) << 16;
2327 v
|= cirrus_linear_readb(opaque
, addr
+ 3) << 24;
2332 static void cirrus_linear_writeb(void *opaque
, target_phys_addr_t addr
,
2335 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2338 addr
&= s
->cirrus_addr_mask
;
2340 if (((s
->sr
[0x17] & 0x44) == 0x44) &&
2341 ((addr
& s
->linear_mmio_mask
) == s
->linear_mmio_mask
)) {
2342 /* memory-mapped I/O */
2343 cirrus_mmio_blt_write(s
, addr
& 0xff, val
);
2344 } else if (s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
) {
2346 *s
->cirrus_srcptr
++ = (uint8_t) val
;
2347 if (s
->cirrus_srcptr
>= s
->cirrus_srcptr_end
) {
2348 cirrus_bitblt_cputovideo_next(s
);
2352 if ((s
->gr
[0x0B] & 0x14) == 0x14) {
2354 } else if (s
->gr
[0x0B] & 0x02) {
2357 addr
&= s
->cirrus_addr_mask
;
2359 mode
= s
->gr
[0x05] & 0x7;
2360 if (mode
< 4 || mode
> 5 || ((s
->gr
[0x0B] & 0x4) == 0)) {
2361 *(s
->vram_ptr
+ addr
) = (uint8_t) val
;
2362 cpu_physical_memory_set_dirty(s
->vram_offset
+ addr
);
2364 if ((s
->gr
[0x0B] & 0x14) != 0x14) {
2365 cirrus_mem_writeb_mode4and5_8bpp(s
, mode
, addr
, val
);
2367 cirrus_mem_writeb_mode4and5_16bpp(s
, mode
, addr
, val
);
2373 static void cirrus_linear_writew(void *opaque
, target_phys_addr_t addr
,
2376 #ifdef TARGET_WORDS_BIGENDIAN
2377 cirrus_linear_writeb(opaque
, addr
, (val
>> 8) & 0xff);
2378 cirrus_linear_writeb(opaque
, addr
+ 1, val
& 0xff);
2380 cirrus_linear_writeb(opaque
, addr
, val
& 0xff);
2381 cirrus_linear_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2385 static void cirrus_linear_writel(void *opaque
, target_phys_addr_t addr
,
2388 #ifdef TARGET_WORDS_BIGENDIAN
2389 cirrus_linear_writeb(opaque
, addr
, (val
>> 24) & 0xff);
2390 cirrus_linear_writeb(opaque
, addr
+ 1, (val
>> 16) & 0xff);
2391 cirrus_linear_writeb(opaque
, addr
+ 2, (val
>> 8) & 0xff);
2392 cirrus_linear_writeb(opaque
, addr
+ 3, val
& 0xff);
2394 cirrus_linear_writeb(opaque
, addr
, val
& 0xff);
2395 cirrus_linear_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2396 cirrus_linear_writeb(opaque
, addr
+ 2, (val
>> 16) & 0xff);
2397 cirrus_linear_writeb(opaque
, addr
+ 3, (val
>> 24) & 0xff);
2402 static CPUReadMemoryFunc
*cirrus_linear_read
[3] = {
2403 cirrus_linear_readb
,
2404 cirrus_linear_readw
,
2405 cirrus_linear_readl
,
2408 static CPUWriteMemoryFunc
*cirrus_linear_write
[3] = {
2409 cirrus_linear_writeb
,
2410 cirrus_linear_writew
,
2411 cirrus_linear_writel
,
2414 static void cirrus_linear_mem_writeb(void *opaque
, target_phys_addr_t addr
,
2417 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2419 addr
&= s
->cirrus_addr_mask
;
2420 *(s
->vram_ptr
+ addr
) = val
;
2421 cpu_physical_memory_set_dirty(s
->vram_offset
+ addr
);
2424 static void cirrus_linear_mem_writew(void *opaque
, target_phys_addr_t addr
,
2427 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2429 addr
&= s
->cirrus_addr_mask
;
2430 cpu_to_le16w((uint16_t *)(s
->vram_ptr
+ addr
), val
);
2431 cpu_physical_memory_set_dirty(s
->vram_offset
+ addr
);
2434 static void cirrus_linear_mem_writel(void *opaque
, target_phys_addr_t addr
,
2437 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2439 addr
&= s
->cirrus_addr_mask
;
2440 cpu_to_le32w((uint32_t *)(s
->vram_ptr
+ addr
), val
);
2441 cpu_physical_memory_set_dirty(s
->vram_offset
+ addr
);
2444 /***************************************
2446 * system to screen memory access
2448 ***************************************/
2451 static uint32_t cirrus_linear_bitblt_readb(void *opaque
, target_phys_addr_t addr
)
2455 /* XXX handle bitblt */
2460 static uint32_t cirrus_linear_bitblt_readw(void *opaque
, target_phys_addr_t addr
)
2463 #ifdef TARGET_WORDS_BIGENDIAN
2464 v
= cirrus_linear_bitblt_readb(opaque
, addr
) << 8;
2465 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 1);
2467 v
= cirrus_linear_bitblt_readb(opaque
, addr
);
2468 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 1) << 8;
2473 static uint32_t cirrus_linear_bitblt_readl(void *opaque
, target_phys_addr_t addr
)
2476 #ifdef TARGET_WORDS_BIGENDIAN
2477 v
= cirrus_linear_bitblt_readb(opaque
, addr
) << 24;
2478 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 1) << 16;
2479 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 2) << 8;
2480 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 3);
2482 v
= cirrus_linear_bitblt_readb(opaque
, addr
);
2483 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 1) << 8;
2484 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 2) << 16;
2485 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 3) << 24;
2490 static void cirrus_linear_bitblt_writeb(void *opaque
, target_phys_addr_t addr
,
2493 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2495 if (s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
) {
2497 *s
->cirrus_srcptr
++ = (uint8_t) val
;
2498 if (s
->cirrus_srcptr
>= s
->cirrus_srcptr_end
) {
2499 cirrus_bitblt_cputovideo_next(s
);
2504 static void cirrus_linear_bitblt_writew(void *opaque
, target_phys_addr_t addr
,
2507 #ifdef TARGET_WORDS_BIGENDIAN
2508 cirrus_linear_bitblt_writeb(opaque
, addr
, (val
>> 8) & 0xff);
2509 cirrus_linear_bitblt_writeb(opaque
, addr
+ 1, val
& 0xff);
2511 cirrus_linear_bitblt_writeb(opaque
, addr
, val
& 0xff);
2512 cirrus_linear_bitblt_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2516 static void cirrus_linear_bitblt_writel(void *opaque
, target_phys_addr_t addr
,
2519 #ifdef TARGET_WORDS_BIGENDIAN
2520 cirrus_linear_bitblt_writeb(opaque
, addr
, (val
>> 24) & 0xff);
2521 cirrus_linear_bitblt_writeb(opaque
, addr
+ 1, (val
>> 16) & 0xff);
2522 cirrus_linear_bitblt_writeb(opaque
, addr
+ 2, (val
>> 8) & 0xff);
2523 cirrus_linear_bitblt_writeb(opaque
, addr
+ 3, val
& 0xff);
2525 cirrus_linear_bitblt_writeb(opaque
, addr
, val
& 0xff);
2526 cirrus_linear_bitblt_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2527 cirrus_linear_bitblt_writeb(opaque
, addr
+ 2, (val
>> 16) & 0xff);
2528 cirrus_linear_bitblt_writeb(opaque
, addr
+ 3, (val
>> 24) & 0xff);
2533 static CPUReadMemoryFunc
*cirrus_linear_bitblt_read
[3] = {
2534 cirrus_linear_bitblt_readb
,
2535 cirrus_linear_bitblt_readw
,
2536 cirrus_linear_bitblt_readl
,
2539 static CPUWriteMemoryFunc
*cirrus_linear_bitblt_write
[3] = {
2540 cirrus_linear_bitblt_writeb
,
2541 cirrus_linear_bitblt_writew
,
2542 cirrus_linear_bitblt_writel
,
2547 #include "qemu-kvm.h"
2549 extern kvm_context_t kvm_context
;
2551 void *set_vram_mapping(unsigned long begin
, unsigned long end
)
2553 void *vram_pointer
= NULL
;
2555 /* align begin and end address */
2556 begin
= begin
& TARGET_PAGE_MASK
;
2557 end
= begin
+ VGA_RAM_SIZE
;
2558 end
= (end
+ TARGET_PAGE_SIZE
-1 ) & TARGET_PAGE_MASK
;
2560 vram_pointer
= kvm_create_phys_mem(kvm_context
, begin
, end
- begin
, 1,
2563 if (vram_pointer
== NULL
) {
2564 printf("set_vram_mapping: cannot allocate memory: %m\n");
2568 memset(vram_pointer
, 0, end
- begin
);
2570 return vram_pointer
;
2573 int unset_vram_mapping(unsigned long begin
, unsigned long end
)
2575 /* align begin and end address */
2576 end
= begin
+ VGA_RAM_SIZE
;
2577 begin
= begin
& TARGET_PAGE_MASK
;
2578 end
= (end
+ TARGET_PAGE_SIZE
-1 ) & TARGET_PAGE_MASK
;
2580 kvm_destroy_phys_mem(kvm_context
, begin
, end
- begin
);
2585 static void kvm_update_vga_alias(CirrusVGAState
*s
, int ok
, int bank
)
2587 unsigned limit
, base
;
2589 if (!ok
&& !s
->aliases_enabled
)
2591 limit
= s
->cirrus_bank_limit
[bank
];
2594 base
= s
->cirrus_lfb_addr
+ s
->cirrus_bank_base
[bank
];
2596 if (!s
->aliases_enabled
2597 || base
!= s
->aliased_bank_base
[bank
]
2598 || limit
!= s
->aliased_bank_limit
[bank
]) {
2599 kvm_create_memory_alias(kvm_context
, bank
,
2600 0xa0000 + bank
* 0x8000,
2602 s
->aliased_bank_base
[bank
] = base
;
2603 s
->aliased_bank_limit
[bank
] = limit
;
2606 kvm_destroy_memory_alias(kvm_context
, bank
);
2610 static void kvm_update_vga_aliases(CirrusVGAState
*s
, int ok
)
2613 kvm_update_vga_alias(s
, ok
, 0);
2614 kvm_update_vga_alias(s
, ok
, 1);
2616 s
->aliases_enabled
= ok
;
2621 /* Compute the memory access functions */
2622 static void cirrus_update_memory_access(CirrusVGAState
*s
)
2626 int want_vga_alias
= 0;
2629 if ((s
->sr
[0x17] & 0x44) == 0x44) {
2631 } else if (s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
) {
2634 if ((s
->gr
[0x0B] & 0x14) == 0x14) {
2636 } else if (s
->gr
[0x0B] & 0x02) {
2640 mode
= s
->gr
[0x05] & 0x7;
2641 if (mode
< 4 || mode
> 5 || ((s
->gr
[0x0B] & 0x4) == 0)) {
2643 if (kvm_allowed
&& s
->cirrus_lfb_addr
&& s
->cirrus_lfb_end
&&
2645 void *vram_pointer
, *old_vram
;
2647 vram_pointer
= set_vram_mapping(s
->cirrus_lfb_addr
,
2650 fprintf(stderr
, "NULL vram_pointer\n");
2652 old_vram
= vga_update_vram((VGAState
*)s
, vram_pointer
,
2654 qemu_free(old_vram
);
2656 s
->map_addr
= s
->cirrus_lfb_addr
;
2657 s
->map_end
= s
->cirrus_lfb_end
;
2660 && !(s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
)
2661 && !((s
->sr
[0x07] & 0x01) == 0)
2662 && !((s
->gr
[0x0B] & 0x14) == 0x14)
2663 && !(s
->gr
[0x0B] & 0x02))
2666 s
->cirrus_linear_write
[0] = cirrus_linear_mem_writeb
;
2667 s
->cirrus_linear_write
[1] = cirrus_linear_mem_writew
;
2668 s
->cirrus_linear_write
[2] = cirrus_linear_mem_writel
;
2672 if (kvm_allowed
&& s
->cirrus_lfb_addr
&& s
->cirrus_lfb_end
&&
2675 void *old_vram
= NULL
;
2677 error
= unset_vram_mapping(s
->cirrus_lfb_addr
,
2680 old_vram
= vga_update_vram((VGAState
*)s
, NULL
,
2683 munmap(old_vram
, s
->map_end
- s
->map_addr
);
2684 s
->map_addr
= s
->map_end
= 0;
2687 s
->cirrus_linear_write
[0] = cirrus_linear_writeb
;
2688 s
->cirrus_linear_write
[1] = cirrus_linear_writew
;
2689 s
->cirrus_linear_write
[2] = cirrus_linear_writel
;
2693 kvm_update_vga_aliases(s
, want_vga_alias
);
2700 static uint32_t vga_ioport_read(void *opaque
, uint32_t addr
)
2702 CirrusVGAState
*s
= opaque
;
2705 /* check port range access depending on color/monochrome mode */
2706 if ((addr
>= 0x3b0 && addr
<= 0x3bf && (s
->msr
& MSR_COLOR_EMULATION
))
2707 || (addr
>= 0x3d0 && addr
<= 0x3df
2708 && !(s
->msr
& MSR_COLOR_EMULATION
))) {
2713 if (s
->ar_flip_flop
== 0) {
2720 index
= s
->ar_index
& 0x1f;
2733 if (cirrus_hook_read_sr(s
, s
->sr_index
, &val
))
2735 val
= s
->sr
[s
->sr_index
];
2736 #ifdef DEBUG_VGA_REG
2737 printf("vga: read SR%x = 0x%02x\n", s
->sr_index
, val
);
2741 cirrus_read_hidden_dac(s
, &val
);
2747 val
= s
->dac_write_index
;
2748 s
->cirrus_hidden_dac_lockindex
= 0;
2751 if (cirrus_hook_read_palette(s
, &val
))
2753 val
= s
->palette
[s
->dac_read_index
* 3 + s
->dac_sub_index
];
2754 if (++s
->dac_sub_index
== 3) {
2755 s
->dac_sub_index
= 0;
2756 s
->dac_read_index
++;
2769 if (cirrus_hook_read_gr(s
, s
->gr_index
, &val
))
2771 val
= s
->gr
[s
->gr_index
];
2772 #ifdef DEBUG_VGA_REG
2773 printf("vga: read GR%x = 0x%02x\n", s
->gr_index
, val
);
2782 if (cirrus_hook_read_cr(s
, s
->cr_index
, &val
))
2784 val
= s
->cr
[s
->cr_index
];
2785 #ifdef DEBUG_VGA_REG
2786 printf("vga: read CR%x = 0x%02x\n", s
->cr_index
, val
);
2791 /* just toggle to fool polling */
2792 s
->st01
^= ST01_V_RETRACE
| ST01_DISP_ENABLE
;
2794 s
->ar_flip_flop
= 0;
2801 #if defined(DEBUG_VGA)
2802 printf("VGA: read addr=0x%04x data=0x%02x\n", addr
, val
);
2807 static void vga_ioport_write(void *opaque
, uint32_t addr
, uint32_t val
)
2809 CirrusVGAState
*s
= opaque
;
2812 /* check port range access depending on color/monochrome mode */
2813 if ((addr
>= 0x3b0 && addr
<= 0x3bf && (s
->msr
& MSR_COLOR_EMULATION
))
2814 || (addr
>= 0x3d0 && addr
<= 0x3df
2815 && !(s
->msr
& MSR_COLOR_EMULATION
)))
2819 printf("VGA: write addr=0x%04x data=0x%02x\n", addr
, val
);
2824 if (s
->ar_flip_flop
== 0) {
2828 index
= s
->ar_index
& 0x1f;
2831 s
->ar
[index
] = val
& 0x3f;
2834 s
->ar
[index
] = val
& ~0x10;
2840 s
->ar
[index
] = val
& ~0xc0;
2843 s
->ar
[index
] = val
& ~0xf0;
2846 s
->ar
[index
] = val
& ~0xf0;
2852 s
->ar_flip_flop
^= 1;
2855 s
->msr
= val
& ~0x10;
2861 if (cirrus_hook_write_sr(s
, s
->sr_index
, val
))
2863 #ifdef DEBUG_VGA_REG
2864 printf("vga: write SR%x = 0x%02x\n", s
->sr_index
, val
);
2866 s
->sr
[s
->sr_index
] = val
& sr_mask
[s
->sr_index
];
2869 cirrus_write_hidden_dac(s
, val
);
2872 s
->dac_read_index
= val
;
2873 s
->dac_sub_index
= 0;
2877 s
->dac_write_index
= val
;
2878 s
->dac_sub_index
= 0;
2882 if (cirrus_hook_write_palette(s
, val
))
2884 s
->dac_cache
[s
->dac_sub_index
] = val
;
2885 if (++s
->dac_sub_index
== 3) {
2886 memcpy(&s
->palette
[s
->dac_write_index
* 3], s
->dac_cache
, 3);
2887 s
->dac_sub_index
= 0;
2888 s
->dac_write_index
++;
2895 if (cirrus_hook_write_gr(s
, s
->gr_index
, val
))
2897 #ifdef DEBUG_VGA_REG
2898 printf("vga: write GR%x = 0x%02x\n", s
->gr_index
, val
);
2900 s
->gr
[s
->gr_index
] = val
& gr_mask
[s
->gr_index
];
2908 if (cirrus_hook_write_cr(s
, s
->cr_index
, val
))
2910 #ifdef DEBUG_VGA_REG
2911 printf("vga: write CR%x = 0x%02x\n", s
->cr_index
, val
);
2913 /* handle CR0-7 protection */
2914 if ((s
->cr
[0x11] & 0x80) && s
->cr_index
<= 7) {
2915 /* can always write bit 4 of CR7 */
2916 if (s
->cr_index
== 7)
2917 s
->cr
[7] = (s
->cr
[7] & ~0x10) | (val
& 0x10);
2920 switch (s
->cr_index
) {
2921 case 0x01: /* horizontal display end */
2926 case 0x12: /* veritcal display end */
2927 s
->cr
[s
->cr_index
] = val
;
2931 s
->cr
[s
->cr_index
] = val
;
2937 s
->fcr
= val
& 0x10;
2942 /***************************************
2944 * memory-mapped I/O access
2946 ***************************************/
2948 static uint32_t cirrus_mmio_readb(void *opaque
, target_phys_addr_t addr
)
2950 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2952 addr
&= CIRRUS_PNPMMIO_SIZE
- 1;
2954 if (addr
>= 0x100) {
2955 return cirrus_mmio_blt_read(s
, addr
- 0x100);
2957 return vga_ioport_read(s
, addr
+ 0x3c0);
2961 static uint32_t cirrus_mmio_readw(void *opaque
, target_phys_addr_t addr
)
2964 #ifdef TARGET_WORDS_BIGENDIAN
2965 v
= cirrus_mmio_readb(opaque
, addr
) << 8;
2966 v
|= cirrus_mmio_readb(opaque
, addr
+ 1);
2968 v
= cirrus_mmio_readb(opaque
, addr
);
2969 v
|= cirrus_mmio_readb(opaque
, addr
+ 1) << 8;
2974 static uint32_t cirrus_mmio_readl(void *opaque
, target_phys_addr_t addr
)
2977 #ifdef TARGET_WORDS_BIGENDIAN
2978 v
= cirrus_mmio_readb(opaque
, addr
) << 24;
2979 v
|= cirrus_mmio_readb(opaque
, addr
+ 1) << 16;
2980 v
|= cirrus_mmio_readb(opaque
, addr
+ 2) << 8;
2981 v
|= cirrus_mmio_readb(opaque
, addr
+ 3);
2983 v
= cirrus_mmio_readb(opaque
, addr
);
2984 v
|= cirrus_mmio_readb(opaque
, addr
+ 1) << 8;
2985 v
|= cirrus_mmio_readb(opaque
, addr
+ 2) << 16;
2986 v
|= cirrus_mmio_readb(opaque
, addr
+ 3) << 24;
2991 static void cirrus_mmio_writeb(void *opaque
, target_phys_addr_t addr
,
2994 CirrusVGAState
*s
= (CirrusVGAState
*) opaque
;
2996 addr
&= CIRRUS_PNPMMIO_SIZE
- 1;
2998 if (addr
>= 0x100) {
2999 cirrus_mmio_blt_write(s
, addr
- 0x100, val
);
3001 vga_ioport_write(s
, addr
+ 0x3c0, val
);
3005 static void cirrus_mmio_writew(void *opaque
, target_phys_addr_t addr
,
3008 #ifdef TARGET_WORDS_BIGENDIAN
3009 cirrus_mmio_writeb(opaque
, addr
, (val
>> 8) & 0xff);
3010 cirrus_mmio_writeb(opaque
, addr
+ 1, val
& 0xff);
3012 cirrus_mmio_writeb(opaque
, addr
, val
& 0xff);
3013 cirrus_mmio_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
3017 static void cirrus_mmio_writel(void *opaque
, target_phys_addr_t addr
,
3020 #ifdef TARGET_WORDS_BIGENDIAN
3021 cirrus_mmio_writeb(opaque
, addr
, (val
>> 24) & 0xff);
3022 cirrus_mmio_writeb(opaque
, addr
+ 1, (val
>> 16) & 0xff);
3023 cirrus_mmio_writeb(opaque
, addr
+ 2, (val
>> 8) & 0xff);
3024 cirrus_mmio_writeb(opaque
, addr
+ 3, val
& 0xff);
3026 cirrus_mmio_writeb(opaque
, addr
, val
& 0xff);
3027 cirrus_mmio_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
3028 cirrus_mmio_writeb(opaque
, addr
+ 2, (val
>> 16) & 0xff);
3029 cirrus_mmio_writeb(opaque
, addr
+ 3, (val
>> 24) & 0xff);
3034 static CPUReadMemoryFunc
*cirrus_mmio_read
[3] = {
3040 static CPUWriteMemoryFunc
*cirrus_mmio_write
[3] = {
3046 /* load/save state */
3048 static void cirrus_vga_save(QEMUFile
*f
, void *opaque
)
3050 CirrusVGAState
*s
= opaque
;
3053 pci_device_save(s
->pci_dev
, f
);
3055 qemu_put_be32s(f
, &s
->latch
);
3056 qemu_put_8s(f
, &s
->sr_index
);
3057 qemu_put_buffer(f
, s
->sr
, 256);
3058 qemu_put_8s(f
, &s
->gr_index
);
3059 qemu_put_8s(f
, &s
->cirrus_shadow_gr0
);
3060 qemu_put_8s(f
, &s
->cirrus_shadow_gr1
);
3061 qemu_put_buffer(f
, s
->gr
+ 2, 254);
3062 qemu_put_8s(f
, &s
->ar_index
);
3063 qemu_put_buffer(f
, s
->ar
, 21);
3064 qemu_put_be32s(f
, &s
->ar_flip_flop
);
3065 qemu_put_8s(f
, &s
->cr_index
);
3066 qemu_put_buffer(f
, s
->cr
, 256);
3067 qemu_put_8s(f
, &s
->msr
);
3068 qemu_put_8s(f
, &s
->fcr
);
3069 qemu_put_8s(f
, &s
->st00
);
3070 qemu_put_8s(f
, &s
->st01
);
3072 qemu_put_8s(f
, &s
->dac_state
);
3073 qemu_put_8s(f
, &s
->dac_sub_index
);
3074 qemu_put_8s(f
, &s
->dac_read_index
);
3075 qemu_put_8s(f
, &s
->dac_write_index
);
3076 qemu_put_buffer(f
, s
->dac_cache
, 3);
3077 qemu_put_buffer(f
, s
->palette
, 768);
3079 qemu_put_be32s(f
, &s
->bank_offset
);
3081 qemu_put_8s(f
, &s
->cirrus_hidden_dac_lockindex
);
3082 qemu_put_8s(f
, &s
->cirrus_hidden_dac_data
);
3084 qemu_put_be32s(f
, &s
->hw_cursor_x
);
3085 qemu_put_be32s(f
, &s
->hw_cursor_y
);
3086 /* XXX: we do not save the bitblt state - we assume we do not save
3087 the state when the blitter is active */
3090 if (kvm_allowed
) { /* XXX: KVM images ought to be loadable in QEMU */
3091 qemu_put_be32s(f
, &s
->real_vram_size
);
3092 qemu_put_buffer(f
, s
->vram_ptr
, s
->real_vram_size
);
3097 static int cirrus_vga_load(QEMUFile
*f
, void *opaque
, int version_id
)
3099 CirrusVGAState
*s
= opaque
;
3105 if (s
->pci_dev
&& version_id
>= 2) {
3106 ret
= pci_device_load(s
->pci_dev
, f
);
3111 qemu_get_be32s(f
, &s
->latch
);
3112 qemu_get_8s(f
, &s
->sr_index
);
3113 qemu_get_buffer(f
, s
->sr
, 256);
3114 qemu_get_8s(f
, &s
->gr_index
);
3115 qemu_get_8s(f
, &s
->cirrus_shadow_gr0
);
3116 qemu_get_8s(f
, &s
->cirrus_shadow_gr1
);
3117 s
->gr
[0x00] = s
->cirrus_shadow_gr0
& 0x0f;
3118 s
->gr
[0x01] = s
->cirrus_shadow_gr1
& 0x0f;
3119 qemu_get_buffer(f
, s
->gr
+ 2, 254);
3120 qemu_get_8s(f
, &s
->ar_index
);
3121 qemu_get_buffer(f
, s
->ar
, 21);
3122 qemu_get_be32s(f
, &s
->ar_flip_flop
);
3123 qemu_get_8s(f
, &s
->cr_index
);
3124 qemu_get_buffer(f
, s
->cr
, 256);
3125 qemu_get_8s(f
, &s
->msr
);
3126 qemu_get_8s(f
, &s
->fcr
);
3127 qemu_get_8s(f
, &s
->st00
);
3128 qemu_get_8s(f
, &s
->st01
);
3130 qemu_get_8s(f
, &s
->dac_state
);
3131 qemu_get_8s(f
, &s
->dac_sub_index
);
3132 qemu_get_8s(f
, &s
->dac_read_index
);
3133 qemu_get_8s(f
, &s
->dac_write_index
);
3134 qemu_get_buffer(f
, s
->dac_cache
, 3);
3135 qemu_get_buffer(f
, s
->palette
, 768);
3137 qemu_get_be32s(f
, &s
->bank_offset
);
3139 qemu_get_8s(f
, &s
->cirrus_hidden_dac_lockindex
);
3140 qemu_get_8s(f
, &s
->cirrus_hidden_dac_data
);
3142 qemu_get_be32s(f
, &s
->hw_cursor_x
);
3143 qemu_get_be32s(f
, &s
->hw_cursor_y
);
3148 qemu_get_be32s(f
, &real_vram_size
);
3149 if (real_vram_size
!= s
->real_vram_size
) {
3150 if (real_vram_size
> s
->real_vram_size
)
3151 real_vram_size
= s
->real_vram_size
;
3152 printf("%s: REAL_VRAM_SIZE MISMATCH !!!!!! SAVED=%d CURRENT=%d",
3153 __FUNCTION__
, real_vram_size
, s
->real_vram_size
);
3155 qemu_get_buffer(f
, s
->vram_ptr
, real_vram_size
);
3156 cirrus_update_memory_access(s
);
3162 s
->graphic_mode
= -1;
3163 cirrus_update_bank_ptr(s
, 0);
3164 cirrus_update_bank_ptr(s
, 1);
3168 /***************************************
3172 ***************************************/
3174 static void cirrus_init_common(CirrusVGAState
* s
, int device_id
, int is_pci
)
3176 int vga_io_memory
, i
;
3181 for(i
= 0;i
< 256; i
++)
3182 rop_to_index
[i
] = CIRRUS_ROP_NOP_INDEX
; /* nop rop */
3183 rop_to_index
[CIRRUS_ROP_0
] = 0;
3184 rop_to_index
[CIRRUS_ROP_SRC_AND_DST
] = 1;
3185 rop_to_index
[CIRRUS_ROP_NOP
] = 2;
3186 rop_to_index
[CIRRUS_ROP_SRC_AND_NOTDST
] = 3;
3187 rop_to_index
[CIRRUS_ROP_NOTDST
] = 4;
3188 rop_to_index
[CIRRUS_ROP_SRC
] = 5;
3189 rop_to_index
[CIRRUS_ROP_1
] = 6;
3190 rop_to_index
[CIRRUS_ROP_NOTSRC_AND_DST
] = 7;
3191 rop_to_index
[CIRRUS_ROP_SRC_XOR_DST
] = 8;
3192 rop_to_index
[CIRRUS_ROP_SRC_OR_DST
] = 9;
3193 rop_to_index
[CIRRUS_ROP_NOTSRC_OR_NOTDST
] = 10;
3194 rop_to_index
[CIRRUS_ROP_SRC_NOTXOR_DST
] = 11;
3195 rop_to_index
[CIRRUS_ROP_SRC_OR_NOTDST
] = 12;
3196 rop_to_index
[CIRRUS_ROP_NOTSRC
] = 13;
3197 rop_to_index
[CIRRUS_ROP_NOTSRC_OR_DST
] = 14;
3198 rop_to_index
[CIRRUS_ROP_NOTSRC_AND_NOTDST
] = 15;
3201 register_ioport_write(0x3c0, 16, 1, vga_ioport_write
, s
);
3203 register_ioport_write(0x3b4, 2, 1, vga_ioport_write
, s
);
3204 register_ioport_write(0x3d4, 2, 1, vga_ioport_write
, s
);
3205 register_ioport_write(0x3ba, 1, 1, vga_ioport_write
, s
);
3206 register_ioport_write(0x3da, 1, 1, vga_ioport_write
, s
);
3208 register_ioport_read(0x3c0, 16, 1, vga_ioport_read
, s
);
3210 register_ioport_read(0x3b4, 2, 1, vga_ioport_read
, s
);
3211 register_ioport_read(0x3d4, 2, 1, vga_ioport_read
, s
);
3212 register_ioport_read(0x3ba, 1, 1, vga_ioport_read
, s
);
3213 register_ioport_read(0x3da, 1, 1, vga_ioport_read
, s
);
3215 vga_io_memory
= cpu_register_io_memory(0, cirrus_vga_mem_read
,
3216 cirrus_vga_mem_write
, s
);
3217 cpu_register_physical_memory(isa_mem_base
+ 0x000a0000, 0x20000,
3221 if (device_id
== CIRRUS_ID_CLGD5446
) {
3222 /* 4MB 64 bit memory config, always PCI */
3223 s
->sr
[0x1F] = 0x2d; // MemClock
3224 s
->gr
[0x18] = 0x0f; // fastest memory configuration
3228 s
->sr
[0x15] = 0x04; /* memory size, 3=2MB, 4=4MB */
3229 s
->real_vram_size
= 4096 * 1024;
3233 s
->sr
[0x15] = 0x03; /* memory size, 3=2MB, 4=4MB */
3234 s
->real_vram_size
= 2048 * 1024;
3237 s
->sr
[0x1F] = 0x22; // MemClock
3238 s
->sr
[0x0F] = CIRRUS_MEMSIZE_2M
;
3240 s
->sr
[0x17] = CIRRUS_BUSTYPE_PCI
;
3242 s
->sr
[0x17] = CIRRUS_BUSTYPE_ISA
;
3243 s
->real_vram_size
= 2048 * 1024;
3244 s
->sr
[0x15] = 0x03; /* memory size, 3=2MB, 4=4MB */
3246 s
->cr
[0x27] = device_id
;
3248 /* Win2K seems to assume that the pattern buffer is at 0xff
3250 memset(s
->vram_ptr
, 0xff, s
->real_vram_size
);
3252 s
->cirrus_hidden_dac_lockindex
= 5;
3253 s
->cirrus_hidden_dac_data
= 0;
3255 /* I/O handler for LFB */
3256 s
->cirrus_linear_io_addr
=
3257 cpu_register_io_memory(0, cirrus_linear_read
, cirrus_linear_write
,
3259 s
->cirrus_linear_write
= cpu_get_io_memory_write(s
->cirrus_linear_io_addr
);
3261 /* I/O handler for LFB */
3262 s
->cirrus_linear_bitblt_io_addr
=
3263 cpu_register_io_memory(0, cirrus_linear_bitblt_read
, cirrus_linear_bitblt_write
,
3266 /* I/O handler for memory-mapped I/O */
3267 s
->cirrus_mmio_io_addr
=
3268 cpu_register_io_memory(0, cirrus_mmio_read
, cirrus_mmio_write
, s
);
3270 /* XXX: s->vram_size must be a power of two */
3271 s
->cirrus_addr_mask
= s
->real_vram_size
- 1;
3272 s
->linear_mmio_mask
= s
->real_vram_size
- 256;
3274 s
->get_bpp
= cirrus_get_bpp
;
3275 s
->get_offsets
= cirrus_get_offsets
;
3276 s
->get_resolution
= cirrus_get_resolution
;
3277 s
->cursor_invalidate
= cirrus_cursor_invalidate
;
3278 s
->cursor_draw_line
= cirrus_cursor_draw_line
;
3280 register_savevm("cirrus_vga", 0, 2, cirrus_vga_save
, cirrus_vga_load
, s
);
3283 /***************************************
3287 ***************************************/
3289 void isa_cirrus_vga_init(DisplayState
*ds
, uint8_t *vga_ram_base
,
3290 unsigned long vga_ram_offset
, int vga_ram_size
)
3294 s
= qemu_mallocz(sizeof(CirrusVGAState
));
3296 vga_common_init((VGAState
*)s
,
3297 ds
, vga_ram_base
, vga_ram_offset
, vga_ram_size
);
3298 cirrus_init_common(s
, CIRRUS_ID_CLGD5430
, 0);
3299 /* XXX ISA-LFB support */
3302 /***************************************
3306 ***************************************/
3308 static void cirrus_pci_lfb_map(PCIDevice
*d
, int region_num
,
3309 uint32_t addr
, uint32_t size
, int type
)
3311 CirrusVGAState
*s
= &((PCICirrusVGAState
*)d
)->cirrus_vga
;
3313 /* XXX: add byte swapping apertures */
3314 cpu_register_physical_memory(addr
, s
->vram_size
,
3315 s
->cirrus_linear_io_addr
);
3318 s
->cirrus_lfb_addr
= addr
;
3319 s
->cirrus_lfb_end
= addr
+ VGA_RAM_SIZE
;
3321 if (s
->map_addr
&& (s
->cirrus_lfb_addr
!= s
->map_addr
) &&
3322 (s
->cirrus_lfb_end
!= s
->map_end
))
3323 printf("cirrus vga map change while on lfb mode\n");
3327 cpu_register_physical_memory(addr
+ 0x1000000, 0x400000,
3328 s
->cirrus_linear_bitblt_io_addr
);
3331 static void cirrus_pci_mmio_map(PCIDevice
*d
, int region_num
,
3332 uint32_t addr
, uint32_t size
, int type
)
3334 CirrusVGAState
*s
= &((PCICirrusVGAState
*)d
)->cirrus_vga
;
3336 cpu_register_physical_memory(addr
, CIRRUS_PNPMMIO_SIZE
,
3337 s
->cirrus_mmio_io_addr
);
3340 void pci_cirrus_vga_init(PCIBus
*bus
, DisplayState
*ds
, uint8_t *vga_ram_base
,
3341 unsigned long vga_ram_offset
, int vga_ram_size
)
3343 PCICirrusVGAState
*d
;
3348 device_id
= CIRRUS_ID_CLGD5446
;
3350 /* setup PCI configuration registers */
3351 d
= (PCICirrusVGAState
*)pci_register_device(bus
, "Cirrus VGA",
3352 sizeof(PCICirrusVGAState
),
3354 pci_conf
= d
->dev
.config
;
3355 pci_conf
[0x00] = (uint8_t) (PCI_VENDOR_CIRRUS
& 0xff);
3356 pci_conf
[0x01] = (uint8_t) (PCI_VENDOR_CIRRUS
>> 8);
3357 pci_conf
[0x02] = (uint8_t) (device_id
& 0xff);
3358 pci_conf
[0x03] = (uint8_t) (device_id
>> 8);
3359 pci_conf
[0x04] = PCI_COMMAND_IOACCESS
| PCI_COMMAND_MEMACCESS
;
3360 pci_conf
[0x0a] = PCI_CLASS_SUB_VGA
;
3361 pci_conf
[0x0b] = PCI_CLASS_BASE_DISPLAY
;
3362 pci_conf
[0x0e] = PCI_CLASS_HEADERTYPE_00h
;
3366 vga_common_init((VGAState
*)s
,
3367 ds
, vga_ram_base
, vga_ram_offset
, vga_ram_size
);
3368 cirrus_init_common(s
, device_id
, 1);
3369 s
->pci_dev
= (PCIDevice
*)d
;
3371 /* setup memory space */
3373 /* memory #1 memory-mapped I/O */
3374 /* XXX: s->vram_size must be a power of two */
3375 pci_register_io_region((PCIDevice
*)d
, 0, 0x2000000,
3376 PCI_ADDRESS_SPACE_MEM_PREFETCH
, cirrus_pci_lfb_map
);
3377 if (device_id
== CIRRUS_ID_CLGD5446
) {
3378 pci_register_io_region((PCIDevice
*)d
, 1, CIRRUS_PNPMMIO_SIZE
,
3379 PCI_ADDRESS_SPACE_MEM
, cirrus_pci_mmio_map
);