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/
29 #include "qemu/osdep.h"
30 #include "qapi/error.h"
33 #include "hw/pci/pci.h"
34 #include "ui/console.h"
35 #include "ui/pixel_ops.h"
37 #include "hw/loader.h"
41 * - destination write mask support not complete (bits 5..7)
42 * - optimize linear mappings
43 * - optimize bitblt functions
46 //#define DEBUG_CIRRUS
47 //#define DEBUG_BITBLT
49 /***************************************
53 ***************************************/
56 #define CIRRUS_ID_CLGD5422 (0x23<<2)
57 #define CIRRUS_ID_CLGD5426 (0x24<<2)
58 #define CIRRUS_ID_CLGD5424 (0x25<<2)
59 #define CIRRUS_ID_CLGD5428 (0x26<<2)
60 #define CIRRUS_ID_CLGD5430 (0x28<<2)
61 #define CIRRUS_ID_CLGD5434 (0x2A<<2)
62 #define CIRRUS_ID_CLGD5436 (0x2B<<2)
63 #define CIRRUS_ID_CLGD5446 (0x2E<<2)
66 #define CIRRUS_SR7_BPP_VGA 0x00
67 #define CIRRUS_SR7_BPP_SVGA 0x01
68 #define CIRRUS_SR7_BPP_MASK 0x0e
69 #define CIRRUS_SR7_BPP_8 0x00
70 #define CIRRUS_SR7_BPP_16_DOUBLEVCLK 0x02
71 #define CIRRUS_SR7_BPP_24 0x04
72 #define CIRRUS_SR7_BPP_16 0x06
73 #define CIRRUS_SR7_BPP_32 0x08
74 #define CIRRUS_SR7_ISAADDR_MASK 0xe0
77 #define CIRRUS_MEMSIZE_512k 0x08
78 #define CIRRUS_MEMSIZE_1M 0x10
79 #define CIRRUS_MEMSIZE_2M 0x18
80 #define CIRRUS_MEMFLAGS_BANKSWITCH 0x80 // bank switching is enabled.
83 #define CIRRUS_CURSOR_SHOW 0x01
84 #define CIRRUS_CURSOR_HIDDENPEL 0x02
85 #define CIRRUS_CURSOR_LARGE 0x04 // 64x64 if set, 32x32 if clear
88 #define CIRRUS_BUSTYPE_VLBFAST 0x10
89 #define CIRRUS_BUSTYPE_PCI 0x20
90 #define CIRRUS_BUSTYPE_VLBSLOW 0x30
91 #define CIRRUS_BUSTYPE_ISA 0x38
92 #define CIRRUS_MMIO_ENABLE 0x04
93 #define CIRRUS_MMIO_USE_PCIADDR 0x40 // 0xb8000 if cleared.
94 #define CIRRUS_MEMSIZEEXT_DOUBLE 0x80
97 #define CIRRUS_BANKING_DUAL 0x01
98 #define CIRRUS_BANKING_GRANULARITY_16K 0x20 // set:16k, clear:4k
101 #define CIRRUS_BLTMODE_BACKWARDS 0x01
102 #define CIRRUS_BLTMODE_MEMSYSDEST 0x02
103 #define CIRRUS_BLTMODE_MEMSYSSRC 0x04
104 #define CIRRUS_BLTMODE_TRANSPARENTCOMP 0x08
105 #define CIRRUS_BLTMODE_PATTERNCOPY 0x40
106 #define CIRRUS_BLTMODE_COLOREXPAND 0x80
107 #define CIRRUS_BLTMODE_PIXELWIDTHMASK 0x30
108 #define CIRRUS_BLTMODE_PIXELWIDTH8 0x00
109 #define CIRRUS_BLTMODE_PIXELWIDTH16 0x10
110 #define CIRRUS_BLTMODE_PIXELWIDTH24 0x20
111 #define CIRRUS_BLTMODE_PIXELWIDTH32 0x30
114 #define CIRRUS_BLT_BUSY 0x01
115 #define CIRRUS_BLT_START 0x02
116 #define CIRRUS_BLT_RESET 0x04
117 #define CIRRUS_BLT_FIFOUSED 0x10
118 #define CIRRUS_BLT_AUTOSTART 0x80
121 #define CIRRUS_ROP_0 0x00
122 #define CIRRUS_ROP_SRC_AND_DST 0x05
123 #define CIRRUS_ROP_NOP 0x06
124 #define CIRRUS_ROP_SRC_AND_NOTDST 0x09
125 #define CIRRUS_ROP_NOTDST 0x0b
126 #define CIRRUS_ROP_SRC 0x0d
127 #define CIRRUS_ROP_1 0x0e
128 #define CIRRUS_ROP_NOTSRC_AND_DST 0x50
129 #define CIRRUS_ROP_SRC_XOR_DST 0x59
130 #define CIRRUS_ROP_SRC_OR_DST 0x6d
131 #define CIRRUS_ROP_NOTSRC_OR_NOTDST 0x90
132 #define CIRRUS_ROP_SRC_NOTXOR_DST 0x95
133 #define CIRRUS_ROP_SRC_OR_NOTDST 0xad
134 #define CIRRUS_ROP_NOTSRC 0xd0
135 #define CIRRUS_ROP_NOTSRC_OR_DST 0xd6
136 #define CIRRUS_ROP_NOTSRC_AND_NOTDST 0xda
138 #define CIRRUS_ROP_NOP_INDEX 2
139 #define CIRRUS_ROP_SRC_INDEX 5
142 #define CIRRUS_BLTMODEEXT_SOLIDFILL 0x04
143 #define CIRRUS_BLTMODEEXT_COLOREXPINV 0x02
144 #define CIRRUS_BLTMODEEXT_DWORDGRANULARITY 0x01
147 #define CIRRUS_MMIO_BLTBGCOLOR 0x00 // dword
148 #define CIRRUS_MMIO_BLTFGCOLOR 0x04 // dword
149 #define CIRRUS_MMIO_BLTWIDTH 0x08 // word
150 #define CIRRUS_MMIO_BLTHEIGHT 0x0a // word
151 #define CIRRUS_MMIO_BLTDESTPITCH 0x0c // word
152 #define CIRRUS_MMIO_BLTSRCPITCH 0x0e // word
153 #define CIRRUS_MMIO_BLTDESTADDR 0x10 // dword
154 #define CIRRUS_MMIO_BLTSRCADDR 0x14 // dword
155 #define CIRRUS_MMIO_BLTWRITEMASK 0x17 // byte
156 #define CIRRUS_MMIO_BLTMODE 0x18 // byte
157 #define CIRRUS_MMIO_BLTROP 0x1a // byte
158 #define CIRRUS_MMIO_BLTMODEEXT 0x1b // byte
159 #define CIRRUS_MMIO_BLTTRANSPARENTCOLOR 0x1c // word?
160 #define CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK 0x20 // word?
161 #define CIRRUS_MMIO_LINEARDRAW_START_X 0x24 // word
162 #define CIRRUS_MMIO_LINEARDRAW_START_Y 0x26 // word
163 #define CIRRUS_MMIO_LINEARDRAW_END_X 0x28 // word
164 #define CIRRUS_MMIO_LINEARDRAW_END_Y 0x2a // word
165 #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_INC 0x2c // byte
166 #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_ROLLOVER 0x2d // byte
167 #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_MASK 0x2e // byte
168 #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_ACCUM 0x2f // byte
169 #define CIRRUS_MMIO_BRESENHAM_K1 0x30 // word
170 #define CIRRUS_MMIO_BRESENHAM_K3 0x32 // word
171 #define CIRRUS_MMIO_BRESENHAM_ERROR 0x34 // word
172 #define CIRRUS_MMIO_BRESENHAM_DELTA_MAJOR 0x36 // word
173 #define CIRRUS_MMIO_BRESENHAM_DIRECTION 0x38 // byte
174 #define CIRRUS_MMIO_LINEDRAW_MODE 0x39 // byte
175 #define CIRRUS_MMIO_BLTSTATUS 0x40 // byte
177 #define CIRRUS_PNPMMIO_SIZE 0x1000
179 struct CirrusVGAState
;
180 typedef void (*cirrus_bitblt_rop_t
) (struct CirrusVGAState
*s
,
181 uint8_t * dst
, const uint8_t * src
,
182 int dstpitch
, int srcpitch
,
183 int bltwidth
, int bltheight
);
184 typedef void (*cirrus_fill_t
)(struct CirrusVGAState
*s
,
185 uint8_t *dst
, int dst_pitch
, int width
, int height
);
187 typedef struct CirrusVGAState
{
190 MemoryRegion cirrus_vga_io
;
191 MemoryRegion cirrus_linear_io
;
192 MemoryRegion cirrus_linear_bitblt_io
;
193 MemoryRegion cirrus_mmio_io
;
194 MemoryRegion pci_bar
;
195 bool linear_vram
; /* vga.vram mapped over cirrus_linear_io */
196 MemoryRegion low_mem_container
; /* container for 0xa0000-0xc0000 */
197 MemoryRegion low_mem
; /* always mapped, overridden by: */
198 MemoryRegion cirrus_bank
[2]; /* aliases at 0xa0000-0xb0000 */
199 uint32_t cirrus_addr_mask
;
200 uint32_t linear_mmio_mask
;
201 uint8_t cirrus_shadow_gr0
;
202 uint8_t cirrus_shadow_gr1
;
203 uint8_t cirrus_hidden_dac_lockindex
;
204 uint8_t cirrus_hidden_dac_data
;
205 uint32_t cirrus_bank_base
[2];
206 uint32_t cirrus_bank_limit
[2];
207 uint8_t cirrus_hidden_palette
[48];
208 int cirrus_blt_pixelwidth
;
209 int cirrus_blt_width
;
210 int cirrus_blt_height
;
211 int cirrus_blt_dstpitch
;
212 int cirrus_blt_srcpitch
;
213 uint32_t cirrus_blt_fgcol
;
214 uint32_t cirrus_blt_bgcol
;
215 uint32_t cirrus_blt_dstaddr
;
216 uint32_t cirrus_blt_srcaddr
;
217 uint8_t cirrus_blt_mode
;
218 uint8_t cirrus_blt_modeext
;
219 cirrus_bitblt_rop_t cirrus_rop
;
220 #define CIRRUS_BLTBUFSIZE (2048 * 4) /* one line width */
221 uint8_t cirrus_bltbuf
[CIRRUS_BLTBUFSIZE
];
222 uint8_t *cirrus_srcptr
;
223 uint8_t *cirrus_srcptr_end
;
224 uint32_t cirrus_srccounter
;
225 /* hwcursor display state */
226 int last_hw_cursor_size
;
227 int last_hw_cursor_x
;
228 int last_hw_cursor_y
;
229 int last_hw_cursor_y_start
;
230 int last_hw_cursor_y_end
;
231 int real_vram_size
; /* XXX: suppress that */
236 typedef struct PCICirrusVGAState
{
238 CirrusVGAState cirrus_vga
;
241 #define TYPE_PCI_CIRRUS_VGA "cirrus-vga"
242 #define PCI_CIRRUS_VGA(obj) \
243 OBJECT_CHECK(PCICirrusVGAState, (obj), TYPE_PCI_CIRRUS_VGA)
245 #define TYPE_ISA_CIRRUS_VGA "isa-cirrus-vga"
246 #define ISA_CIRRUS_VGA(obj) \
247 OBJECT_CHECK(ISACirrusVGAState, (obj), TYPE_ISA_CIRRUS_VGA)
249 typedef struct ISACirrusVGAState
{
250 ISADevice parent_obj
;
252 CirrusVGAState cirrus_vga
;
255 static uint8_t rop_to_index
[256];
257 /***************************************
261 ***************************************/
264 static void cirrus_bitblt_reset(CirrusVGAState
*s
);
265 static void cirrus_update_memory_access(CirrusVGAState
*s
);
267 /***************************************
271 ***************************************/
273 static bool blit_region_is_unsafe(struct CirrusVGAState
*s
,
274 int32_t pitch
, int32_t addr
)
281 + ((int64_t)s
->cirrus_blt_height
- 1) * pitch
282 - s
->cirrus_blt_width
;
283 if (min
< -1 || addr
>= s
->vga
.vram_size
) {
288 + ((int64_t)s
->cirrus_blt_height
-1) * pitch
289 + s
->cirrus_blt_width
;
290 if (max
> s
->vga
.vram_size
) {
297 static bool blit_is_unsafe(struct CirrusVGAState
*s
, bool dst_only
)
299 /* should be the case, see cirrus_bitblt_start */
300 assert(s
->cirrus_blt_width
> 0);
301 assert(s
->cirrus_blt_height
> 0);
303 if (s
->cirrus_blt_width
> CIRRUS_BLTBUFSIZE
) {
307 if (blit_region_is_unsafe(s
, s
->cirrus_blt_dstpitch
,
308 s
->cirrus_blt_dstaddr
)) {
314 if (blit_region_is_unsafe(s
, s
->cirrus_blt_srcpitch
,
315 s
->cirrus_blt_srcaddr
)) {
322 static void cirrus_bitblt_rop_nop(CirrusVGAState
*s
,
323 uint8_t *dst
,const uint8_t *src
,
324 int dstpitch
,int srcpitch
,
325 int bltwidth
,int bltheight
)
329 static void cirrus_bitblt_fill_nop(CirrusVGAState
*s
,
331 int dstpitch
, int bltwidth
,int bltheight
)
336 #define ROP_FN(d, s) 0
337 #include "cirrus_vga_rop.h"
339 #define ROP_NAME src_and_dst
340 #define ROP_FN(d, s) (s) & (d)
341 #include "cirrus_vga_rop.h"
343 #define ROP_NAME src_and_notdst
344 #define ROP_FN(d, s) (s) & (~(d))
345 #include "cirrus_vga_rop.h"
347 #define ROP_NAME notdst
348 #define ROP_FN(d, s) ~(d)
349 #include "cirrus_vga_rop.h"
352 #define ROP_FN(d, s) s
353 #include "cirrus_vga_rop.h"
356 #define ROP_FN(d, s) ~0
357 #include "cirrus_vga_rop.h"
359 #define ROP_NAME notsrc_and_dst
360 #define ROP_FN(d, s) (~(s)) & (d)
361 #include "cirrus_vga_rop.h"
363 #define ROP_NAME src_xor_dst
364 #define ROP_FN(d, s) (s) ^ (d)
365 #include "cirrus_vga_rop.h"
367 #define ROP_NAME src_or_dst
368 #define ROP_FN(d, s) (s) | (d)
369 #include "cirrus_vga_rop.h"
371 #define ROP_NAME notsrc_or_notdst
372 #define ROP_FN(d, s) (~(s)) | (~(d))
373 #include "cirrus_vga_rop.h"
375 #define ROP_NAME src_notxor_dst
376 #define ROP_FN(d, s) ~((s) ^ (d))
377 #include "cirrus_vga_rop.h"
379 #define ROP_NAME src_or_notdst
380 #define ROP_FN(d, s) (s) | (~(d))
381 #include "cirrus_vga_rop.h"
383 #define ROP_NAME notsrc
384 #define ROP_FN(d, s) (~(s))
385 #include "cirrus_vga_rop.h"
387 #define ROP_NAME notsrc_or_dst
388 #define ROP_FN(d, s) (~(s)) | (d)
389 #include "cirrus_vga_rop.h"
391 #define ROP_NAME notsrc_and_notdst
392 #define ROP_FN(d, s) (~(s)) & (~(d))
393 #include "cirrus_vga_rop.h"
395 static const cirrus_bitblt_rop_t cirrus_fwd_rop
[16] = {
396 cirrus_bitblt_rop_fwd_0
,
397 cirrus_bitblt_rop_fwd_src_and_dst
,
398 cirrus_bitblt_rop_nop
,
399 cirrus_bitblt_rop_fwd_src_and_notdst
,
400 cirrus_bitblt_rop_fwd_notdst
,
401 cirrus_bitblt_rop_fwd_src
,
402 cirrus_bitblt_rop_fwd_1
,
403 cirrus_bitblt_rop_fwd_notsrc_and_dst
,
404 cirrus_bitblt_rop_fwd_src_xor_dst
,
405 cirrus_bitblt_rop_fwd_src_or_dst
,
406 cirrus_bitblt_rop_fwd_notsrc_or_notdst
,
407 cirrus_bitblt_rop_fwd_src_notxor_dst
,
408 cirrus_bitblt_rop_fwd_src_or_notdst
,
409 cirrus_bitblt_rop_fwd_notsrc
,
410 cirrus_bitblt_rop_fwd_notsrc_or_dst
,
411 cirrus_bitblt_rop_fwd_notsrc_and_notdst
,
414 static const cirrus_bitblt_rop_t cirrus_bkwd_rop
[16] = {
415 cirrus_bitblt_rop_bkwd_0
,
416 cirrus_bitblt_rop_bkwd_src_and_dst
,
417 cirrus_bitblt_rop_nop
,
418 cirrus_bitblt_rop_bkwd_src_and_notdst
,
419 cirrus_bitblt_rop_bkwd_notdst
,
420 cirrus_bitblt_rop_bkwd_src
,
421 cirrus_bitblt_rop_bkwd_1
,
422 cirrus_bitblt_rop_bkwd_notsrc_and_dst
,
423 cirrus_bitblt_rop_bkwd_src_xor_dst
,
424 cirrus_bitblt_rop_bkwd_src_or_dst
,
425 cirrus_bitblt_rop_bkwd_notsrc_or_notdst
,
426 cirrus_bitblt_rop_bkwd_src_notxor_dst
,
427 cirrus_bitblt_rop_bkwd_src_or_notdst
,
428 cirrus_bitblt_rop_bkwd_notsrc
,
429 cirrus_bitblt_rop_bkwd_notsrc_or_dst
,
430 cirrus_bitblt_rop_bkwd_notsrc_and_notdst
,
433 #define TRANSP_ROP(name) {\
437 #define TRANSP_NOP(func) {\
442 static const cirrus_bitblt_rop_t cirrus_fwd_transp_rop
[16][2] = {
443 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_0
),
444 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_and_dst
),
445 TRANSP_NOP(cirrus_bitblt_rop_nop
),
446 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_and_notdst
),
447 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notdst
),
448 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src
),
449 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_1
),
450 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc_and_dst
),
451 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_xor_dst
),
452 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_or_dst
),
453 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc_or_notdst
),
454 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_notxor_dst
),
455 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_or_notdst
),
456 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc
),
457 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc_or_dst
),
458 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc_and_notdst
),
461 static const cirrus_bitblt_rop_t cirrus_bkwd_transp_rop
[16][2] = {
462 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_0
),
463 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_and_dst
),
464 TRANSP_NOP(cirrus_bitblt_rop_nop
),
465 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_and_notdst
),
466 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notdst
),
467 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src
),
468 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_1
),
469 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc_and_dst
),
470 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_xor_dst
),
471 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_or_dst
),
472 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc_or_notdst
),
473 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_notxor_dst
),
474 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_or_notdst
),
475 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc
),
476 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc_or_dst
),
477 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc_and_notdst
),
480 #define ROP2(name) {\
487 #define ROP_NOP2(func) {\
494 static const cirrus_bitblt_rop_t cirrus_patternfill
[16][4] = {
495 ROP2(cirrus_patternfill_0
),
496 ROP2(cirrus_patternfill_src_and_dst
),
497 ROP_NOP2(cirrus_bitblt_rop_nop
),
498 ROP2(cirrus_patternfill_src_and_notdst
),
499 ROP2(cirrus_patternfill_notdst
),
500 ROP2(cirrus_patternfill_src
),
501 ROP2(cirrus_patternfill_1
),
502 ROP2(cirrus_patternfill_notsrc_and_dst
),
503 ROP2(cirrus_patternfill_src_xor_dst
),
504 ROP2(cirrus_patternfill_src_or_dst
),
505 ROP2(cirrus_patternfill_notsrc_or_notdst
),
506 ROP2(cirrus_patternfill_src_notxor_dst
),
507 ROP2(cirrus_patternfill_src_or_notdst
),
508 ROP2(cirrus_patternfill_notsrc
),
509 ROP2(cirrus_patternfill_notsrc_or_dst
),
510 ROP2(cirrus_patternfill_notsrc_and_notdst
),
513 static const cirrus_bitblt_rop_t cirrus_colorexpand_transp
[16][4] = {
514 ROP2(cirrus_colorexpand_transp_0
),
515 ROP2(cirrus_colorexpand_transp_src_and_dst
),
516 ROP_NOP2(cirrus_bitblt_rop_nop
),
517 ROP2(cirrus_colorexpand_transp_src_and_notdst
),
518 ROP2(cirrus_colorexpand_transp_notdst
),
519 ROP2(cirrus_colorexpand_transp_src
),
520 ROP2(cirrus_colorexpand_transp_1
),
521 ROP2(cirrus_colorexpand_transp_notsrc_and_dst
),
522 ROP2(cirrus_colorexpand_transp_src_xor_dst
),
523 ROP2(cirrus_colorexpand_transp_src_or_dst
),
524 ROP2(cirrus_colorexpand_transp_notsrc_or_notdst
),
525 ROP2(cirrus_colorexpand_transp_src_notxor_dst
),
526 ROP2(cirrus_colorexpand_transp_src_or_notdst
),
527 ROP2(cirrus_colorexpand_transp_notsrc
),
528 ROP2(cirrus_colorexpand_transp_notsrc_or_dst
),
529 ROP2(cirrus_colorexpand_transp_notsrc_and_notdst
),
532 static const cirrus_bitblt_rop_t cirrus_colorexpand
[16][4] = {
533 ROP2(cirrus_colorexpand_0
),
534 ROP2(cirrus_colorexpand_src_and_dst
),
535 ROP_NOP2(cirrus_bitblt_rop_nop
),
536 ROP2(cirrus_colorexpand_src_and_notdst
),
537 ROP2(cirrus_colorexpand_notdst
),
538 ROP2(cirrus_colorexpand_src
),
539 ROP2(cirrus_colorexpand_1
),
540 ROP2(cirrus_colorexpand_notsrc_and_dst
),
541 ROP2(cirrus_colorexpand_src_xor_dst
),
542 ROP2(cirrus_colorexpand_src_or_dst
),
543 ROP2(cirrus_colorexpand_notsrc_or_notdst
),
544 ROP2(cirrus_colorexpand_src_notxor_dst
),
545 ROP2(cirrus_colorexpand_src_or_notdst
),
546 ROP2(cirrus_colorexpand_notsrc
),
547 ROP2(cirrus_colorexpand_notsrc_or_dst
),
548 ROP2(cirrus_colorexpand_notsrc_and_notdst
),
551 static const cirrus_bitblt_rop_t cirrus_colorexpand_pattern_transp
[16][4] = {
552 ROP2(cirrus_colorexpand_pattern_transp_0
),
553 ROP2(cirrus_colorexpand_pattern_transp_src_and_dst
),
554 ROP_NOP2(cirrus_bitblt_rop_nop
),
555 ROP2(cirrus_colorexpand_pattern_transp_src_and_notdst
),
556 ROP2(cirrus_colorexpand_pattern_transp_notdst
),
557 ROP2(cirrus_colorexpand_pattern_transp_src
),
558 ROP2(cirrus_colorexpand_pattern_transp_1
),
559 ROP2(cirrus_colorexpand_pattern_transp_notsrc_and_dst
),
560 ROP2(cirrus_colorexpand_pattern_transp_src_xor_dst
),
561 ROP2(cirrus_colorexpand_pattern_transp_src_or_dst
),
562 ROP2(cirrus_colorexpand_pattern_transp_notsrc_or_notdst
),
563 ROP2(cirrus_colorexpand_pattern_transp_src_notxor_dst
),
564 ROP2(cirrus_colorexpand_pattern_transp_src_or_notdst
),
565 ROP2(cirrus_colorexpand_pattern_transp_notsrc
),
566 ROP2(cirrus_colorexpand_pattern_transp_notsrc_or_dst
),
567 ROP2(cirrus_colorexpand_pattern_transp_notsrc_and_notdst
),
570 static const cirrus_bitblt_rop_t cirrus_colorexpand_pattern
[16][4] = {
571 ROP2(cirrus_colorexpand_pattern_0
),
572 ROP2(cirrus_colorexpand_pattern_src_and_dst
),
573 ROP_NOP2(cirrus_bitblt_rop_nop
),
574 ROP2(cirrus_colorexpand_pattern_src_and_notdst
),
575 ROP2(cirrus_colorexpand_pattern_notdst
),
576 ROP2(cirrus_colorexpand_pattern_src
),
577 ROP2(cirrus_colorexpand_pattern_1
),
578 ROP2(cirrus_colorexpand_pattern_notsrc_and_dst
),
579 ROP2(cirrus_colorexpand_pattern_src_xor_dst
),
580 ROP2(cirrus_colorexpand_pattern_src_or_dst
),
581 ROP2(cirrus_colorexpand_pattern_notsrc_or_notdst
),
582 ROP2(cirrus_colorexpand_pattern_src_notxor_dst
),
583 ROP2(cirrus_colorexpand_pattern_src_or_notdst
),
584 ROP2(cirrus_colorexpand_pattern_notsrc
),
585 ROP2(cirrus_colorexpand_pattern_notsrc_or_dst
),
586 ROP2(cirrus_colorexpand_pattern_notsrc_and_notdst
),
589 static const cirrus_fill_t cirrus_fill
[16][4] = {
591 ROP2(cirrus_fill_src_and_dst
),
592 ROP_NOP2(cirrus_bitblt_fill_nop
),
593 ROP2(cirrus_fill_src_and_notdst
),
594 ROP2(cirrus_fill_notdst
),
595 ROP2(cirrus_fill_src
),
597 ROP2(cirrus_fill_notsrc_and_dst
),
598 ROP2(cirrus_fill_src_xor_dst
),
599 ROP2(cirrus_fill_src_or_dst
),
600 ROP2(cirrus_fill_notsrc_or_notdst
),
601 ROP2(cirrus_fill_src_notxor_dst
),
602 ROP2(cirrus_fill_src_or_notdst
),
603 ROP2(cirrus_fill_notsrc
),
604 ROP2(cirrus_fill_notsrc_or_dst
),
605 ROP2(cirrus_fill_notsrc_and_notdst
),
608 static inline void cirrus_bitblt_fgcol(CirrusVGAState
*s
)
611 switch (s
->cirrus_blt_pixelwidth
) {
613 s
->cirrus_blt_fgcol
= s
->cirrus_shadow_gr1
;
616 color
= s
->cirrus_shadow_gr1
| (s
->vga
.gr
[0x11] << 8);
617 s
->cirrus_blt_fgcol
= le16_to_cpu(color
);
620 s
->cirrus_blt_fgcol
= s
->cirrus_shadow_gr1
|
621 (s
->vga
.gr
[0x11] << 8) | (s
->vga
.gr
[0x13] << 16);
625 color
= s
->cirrus_shadow_gr1
| (s
->vga
.gr
[0x11] << 8) |
626 (s
->vga
.gr
[0x13] << 16) | (s
->vga
.gr
[0x15] << 24);
627 s
->cirrus_blt_fgcol
= le32_to_cpu(color
);
632 static inline void cirrus_bitblt_bgcol(CirrusVGAState
*s
)
635 switch (s
->cirrus_blt_pixelwidth
) {
637 s
->cirrus_blt_bgcol
= s
->cirrus_shadow_gr0
;
640 color
= s
->cirrus_shadow_gr0
| (s
->vga
.gr
[0x10] << 8);
641 s
->cirrus_blt_bgcol
= le16_to_cpu(color
);
644 s
->cirrus_blt_bgcol
= s
->cirrus_shadow_gr0
|
645 (s
->vga
.gr
[0x10] << 8) | (s
->vga
.gr
[0x12] << 16);
649 color
= s
->cirrus_shadow_gr0
| (s
->vga
.gr
[0x10] << 8) |
650 (s
->vga
.gr
[0x12] << 16) | (s
->vga
.gr
[0x14] << 24);
651 s
->cirrus_blt_bgcol
= le32_to_cpu(color
);
656 static void cirrus_invalidate_region(CirrusVGAState
* s
, int off_begin
,
657 int off_pitch
, int bytesperline
,
665 off_begin
-= bytesperline
- 1;
668 for (y
= 0; y
< lines
; y
++) {
670 off_cur_end
= (off_cur
+ bytesperline
) & s
->cirrus_addr_mask
;
671 assert(off_cur_end
>= off_cur
);
672 memory_region_set_dirty(&s
->vga
.vram
, off_cur
, off_cur_end
- off_cur
);
673 off_begin
+= off_pitch
;
677 static int cirrus_bitblt_common_patterncopy(CirrusVGAState
*s
, bool videosrc
)
679 uint32_t patternsize
;
683 dst
= s
->vga
.vram_ptr
+ s
->cirrus_blt_dstaddr
;
686 switch (s
->vga
.get_bpp(&s
->vga
)) {
700 s
->cirrus_blt_srcaddr
&= ~(patternsize
- 1);
701 if (s
->cirrus_blt_srcaddr
+ patternsize
> s
->vga
.vram_size
) {
704 src
= s
->vga
.vram_ptr
+ s
->cirrus_blt_srcaddr
;
706 src
= s
->cirrus_bltbuf
;
709 if (blit_is_unsafe(s
, true)) {
713 (*s
->cirrus_rop
) (s
, dst
, src
,
714 s
->cirrus_blt_dstpitch
, 0,
715 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
716 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
,
717 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_width
,
718 s
->cirrus_blt_height
);
724 static int cirrus_bitblt_solidfill(CirrusVGAState
*s
, int blt_rop
)
726 cirrus_fill_t rop_func
;
728 if (blit_is_unsafe(s
, true)) {
731 rop_func
= cirrus_fill
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
732 rop_func(s
, s
->vga
.vram_ptr
+ s
->cirrus_blt_dstaddr
,
733 s
->cirrus_blt_dstpitch
,
734 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
735 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
,
736 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_width
,
737 s
->cirrus_blt_height
);
738 cirrus_bitblt_reset(s
);
742 /***************************************
744 * bitblt (video-to-video)
746 ***************************************/
748 static int cirrus_bitblt_videotovideo_patterncopy(CirrusVGAState
* s
)
750 return cirrus_bitblt_common_patterncopy(s
, true);
753 static int cirrus_do_copy(CirrusVGAState
*s
, int dst
, int src
, int w
, int h
)
760 /* make sure to only copy if it's a plain copy ROP */
761 if (*s
->cirrus_rop
== cirrus_bitblt_rop_fwd_src
||
762 *s
->cirrus_rop
== cirrus_bitblt_rop_bkwd_src
) {
766 depth
= s
->vga
.get_bpp(&s
->vga
) / 8;
770 s
->vga
.get_resolution(&s
->vga
, &width
, &height
);
773 sx
= (src
% ABS(s
->cirrus_blt_srcpitch
)) / depth
;
774 sy
= (src
/ ABS(s
->cirrus_blt_srcpitch
));
775 dx
= (dst
% ABS(s
->cirrus_blt_dstpitch
)) / depth
;
776 dy
= (dst
/ ABS(s
->cirrus_blt_dstpitch
));
778 /* normalize width */
781 /* if we're doing a backward copy, we have to adjust
782 our x/y to be the upper left corner (instead of the lower
784 if (s
->cirrus_blt_dstpitch
< 0) {
785 sx
-= (s
->cirrus_blt_width
/ depth
) - 1;
786 dx
-= (s
->cirrus_blt_width
/ depth
) - 1;
787 sy
-= s
->cirrus_blt_height
- 1;
788 dy
-= s
->cirrus_blt_height
- 1;
791 /* are we in the visible portion of memory? */
792 if (sx
>= 0 && sy
>= 0 && dx
>= 0 && dy
>= 0 &&
793 (sx
+ w
) <= width
&& (sy
+ h
) <= height
&&
794 (dx
+ w
) <= width
&& (dy
+ h
) <= height
) {
799 (*s
->cirrus_rop
) (s
, s
->vga
.vram_ptr
+ s
->cirrus_blt_dstaddr
,
800 s
->vga
.vram_ptr
+ s
->cirrus_blt_srcaddr
,
801 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_srcpitch
,
802 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
805 dpy_gfx_update(s
->vga
.con
, dx
, dy
,
806 s
->cirrus_blt_width
/ depth
,
807 s
->cirrus_blt_height
);
810 /* we don't have to notify the display that this portion has
811 changed since qemu_console_copy implies this */
813 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
,
814 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_width
,
815 s
->cirrus_blt_height
);
820 static int cirrus_bitblt_videotovideo_copy(CirrusVGAState
* s
)
822 if (blit_is_unsafe(s
, false))
825 return cirrus_do_copy(s
, s
->cirrus_blt_dstaddr
- s
->vga
.start_addr
,
826 s
->cirrus_blt_srcaddr
- s
->vga
.start_addr
,
827 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
830 /***************************************
832 * bitblt (cpu-to-video)
834 ***************************************/
836 static void cirrus_bitblt_cputovideo_next(CirrusVGAState
* s
)
841 if (s
->cirrus_srccounter
> 0) {
842 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PATTERNCOPY
) {
843 cirrus_bitblt_common_patterncopy(s
, false);
845 s
->cirrus_srccounter
= 0;
846 cirrus_bitblt_reset(s
);
848 /* at least one scan line */
850 (*s
->cirrus_rop
)(s
, s
->vga
.vram_ptr
+ s
->cirrus_blt_dstaddr
,
851 s
->cirrus_bltbuf
, 0, 0, s
->cirrus_blt_width
, 1);
852 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
, 0,
853 s
->cirrus_blt_width
, 1);
854 s
->cirrus_blt_dstaddr
+= s
->cirrus_blt_dstpitch
;
855 s
->cirrus_srccounter
-= s
->cirrus_blt_srcpitch
;
856 if (s
->cirrus_srccounter
<= 0)
858 /* more bytes than needed can be transferred because of
859 word alignment, so we keep them for the next line */
860 /* XXX: keep alignment to speed up transfer */
861 end_ptr
= s
->cirrus_bltbuf
+ s
->cirrus_blt_srcpitch
;
862 copy_count
= s
->cirrus_srcptr_end
- end_ptr
;
863 memmove(s
->cirrus_bltbuf
, end_ptr
, copy_count
);
864 s
->cirrus_srcptr
= s
->cirrus_bltbuf
+ copy_count
;
865 s
->cirrus_srcptr_end
= s
->cirrus_bltbuf
+ s
->cirrus_blt_srcpitch
;
866 } while (s
->cirrus_srcptr
>= s
->cirrus_srcptr_end
);
871 /***************************************
875 ***************************************/
877 static void cirrus_bitblt_reset(CirrusVGAState
* s
)
882 ~(CIRRUS_BLT_START
| CIRRUS_BLT_BUSY
| CIRRUS_BLT_FIFOUSED
);
883 need_update
= s
->cirrus_srcptr
!= &s
->cirrus_bltbuf
[0]
884 || s
->cirrus_srcptr_end
!= &s
->cirrus_bltbuf
[0];
885 s
->cirrus_srcptr
= &s
->cirrus_bltbuf
[0];
886 s
->cirrus_srcptr_end
= &s
->cirrus_bltbuf
[0];
887 s
->cirrus_srccounter
= 0;
890 cirrus_update_memory_access(s
);
893 static int cirrus_bitblt_cputovideo(CirrusVGAState
* s
)
897 if (blit_is_unsafe(s
, true)) {
901 s
->cirrus_blt_mode
&= ~CIRRUS_BLTMODE_MEMSYSSRC
;
902 s
->cirrus_srcptr
= &s
->cirrus_bltbuf
[0];
903 s
->cirrus_srcptr_end
= &s
->cirrus_bltbuf
[0];
905 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PATTERNCOPY
) {
906 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_COLOREXPAND
) {
907 s
->cirrus_blt_srcpitch
= 8;
909 /* XXX: check for 24 bpp */
910 s
->cirrus_blt_srcpitch
= 8 * 8 * s
->cirrus_blt_pixelwidth
;
912 s
->cirrus_srccounter
= s
->cirrus_blt_srcpitch
;
914 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_COLOREXPAND
) {
915 w
= s
->cirrus_blt_width
/ s
->cirrus_blt_pixelwidth
;
916 if (s
->cirrus_blt_modeext
& CIRRUS_BLTMODEEXT_DWORDGRANULARITY
)
917 s
->cirrus_blt_srcpitch
= ((w
+ 31) >> 5);
919 s
->cirrus_blt_srcpitch
= ((w
+ 7) >> 3);
921 /* always align input size to 32 bits */
922 s
->cirrus_blt_srcpitch
= (s
->cirrus_blt_width
+ 3) & ~3;
924 s
->cirrus_srccounter
= s
->cirrus_blt_srcpitch
* s
->cirrus_blt_height
;
927 /* the blit_is_unsafe call above should catch this */
928 assert(s
->cirrus_blt_srcpitch
<= CIRRUS_BLTBUFSIZE
);
930 s
->cirrus_srcptr
= s
->cirrus_bltbuf
;
931 s
->cirrus_srcptr_end
= s
->cirrus_bltbuf
+ s
->cirrus_blt_srcpitch
;
932 cirrus_update_memory_access(s
);
936 static int cirrus_bitblt_videotocpu(CirrusVGAState
* s
)
940 printf("cirrus: bitblt (video to cpu) is not implemented yet\n");
945 static int cirrus_bitblt_videotovideo(CirrusVGAState
* s
)
949 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PATTERNCOPY
) {
950 ret
= cirrus_bitblt_videotovideo_patterncopy(s
);
952 ret
= cirrus_bitblt_videotovideo_copy(s
);
955 cirrus_bitblt_reset(s
);
959 static void cirrus_bitblt_start(CirrusVGAState
* s
)
963 s
->vga
.gr
[0x31] |= CIRRUS_BLT_BUSY
;
965 s
->cirrus_blt_width
= (s
->vga
.gr
[0x20] | (s
->vga
.gr
[0x21] << 8)) + 1;
966 s
->cirrus_blt_height
= (s
->vga
.gr
[0x22] | (s
->vga
.gr
[0x23] << 8)) + 1;
967 s
->cirrus_blt_dstpitch
= (s
->vga
.gr
[0x24] | (s
->vga
.gr
[0x25] << 8));
968 s
->cirrus_blt_srcpitch
= (s
->vga
.gr
[0x26] | (s
->vga
.gr
[0x27] << 8));
969 s
->cirrus_blt_dstaddr
=
970 (s
->vga
.gr
[0x28] | (s
->vga
.gr
[0x29] << 8) | (s
->vga
.gr
[0x2a] << 16));
971 s
->cirrus_blt_srcaddr
=
972 (s
->vga
.gr
[0x2c] | (s
->vga
.gr
[0x2d] << 8) | (s
->vga
.gr
[0x2e] << 16));
973 s
->cirrus_blt_mode
= s
->vga
.gr
[0x30];
974 s
->cirrus_blt_modeext
= s
->vga
.gr
[0x33];
975 blt_rop
= s
->vga
.gr
[0x32];
977 s
->cirrus_blt_dstaddr
&= s
->cirrus_addr_mask
;
978 s
->cirrus_blt_srcaddr
&= s
->cirrus_addr_mask
;
981 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",
984 s
->cirrus_blt_modeext
,
986 s
->cirrus_blt_height
,
987 s
->cirrus_blt_dstpitch
,
988 s
->cirrus_blt_srcpitch
,
989 s
->cirrus_blt_dstaddr
,
990 s
->cirrus_blt_srcaddr
,
994 switch (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PIXELWIDTHMASK
) {
995 case CIRRUS_BLTMODE_PIXELWIDTH8
:
996 s
->cirrus_blt_pixelwidth
= 1;
998 case CIRRUS_BLTMODE_PIXELWIDTH16
:
999 s
->cirrus_blt_pixelwidth
= 2;
1001 case CIRRUS_BLTMODE_PIXELWIDTH24
:
1002 s
->cirrus_blt_pixelwidth
= 3;
1004 case CIRRUS_BLTMODE_PIXELWIDTH32
:
1005 s
->cirrus_blt_pixelwidth
= 4;
1009 printf("cirrus: bitblt - pixel width is unknown\n");
1013 s
->cirrus_blt_mode
&= ~CIRRUS_BLTMODE_PIXELWIDTHMASK
;
1016 cirrus_blt_mode
& (CIRRUS_BLTMODE_MEMSYSSRC
|
1017 CIRRUS_BLTMODE_MEMSYSDEST
))
1018 == (CIRRUS_BLTMODE_MEMSYSSRC
| CIRRUS_BLTMODE_MEMSYSDEST
)) {
1020 printf("cirrus: bitblt - memory-to-memory copy is requested\n");
1025 if ((s
->cirrus_blt_modeext
& CIRRUS_BLTMODEEXT_SOLIDFILL
) &&
1026 (s
->cirrus_blt_mode
& (CIRRUS_BLTMODE_MEMSYSDEST
|
1027 CIRRUS_BLTMODE_TRANSPARENTCOMP
|
1028 CIRRUS_BLTMODE_PATTERNCOPY
|
1029 CIRRUS_BLTMODE_COLOREXPAND
)) ==
1030 (CIRRUS_BLTMODE_PATTERNCOPY
| CIRRUS_BLTMODE_COLOREXPAND
)) {
1031 cirrus_bitblt_fgcol(s
);
1032 cirrus_bitblt_solidfill(s
, blt_rop
);
1034 if ((s
->cirrus_blt_mode
& (CIRRUS_BLTMODE_COLOREXPAND
|
1035 CIRRUS_BLTMODE_PATTERNCOPY
)) ==
1036 CIRRUS_BLTMODE_COLOREXPAND
) {
1038 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_TRANSPARENTCOMP
) {
1039 if (s
->cirrus_blt_modeext
& CIRRUS_BLTMODEEXT_COLOREXPINV
)
1040 cirrus_bitblt_bgcol(s
);
1042 cirrus_bitblt_fgcol(s
);
1043 s
->cirrus_rop
= cirrus_colorexpand_transp
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
1045 cirrus_bitblt_fgcol(s
);
1046 cirrus_bitblt_bgcol(s
);
1047 s
->cirrus_rop
= cirrus_colorexpand
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
1049 } else if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PATTERNCOPY
) {
1050 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_COLOREXPAND
) {
1051 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_TRANSPARENTCOMP
) {
1052 if (s
->cirrus_blt_modeext
& CIRRUS_BLTMODEEXT_COLOREXPINV
)
1053 cirrus_bitblt_bgcol(s
);
1055 cirrus_bitblt_fgcol(s
);
1056 s
->cirrus_rop
= cirrus_colorexpand_pattern_transp
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
1058 cirrus_bitblt_fgcol(s
);
1059 cirrus_bitblt_bgcol(s
);
1060 s
->cirrus_rop
= cirrus_colorexpand_pattern
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
1063 s
->cirrus_rop
= cirrus_patternfill
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
1066 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_TRANSPARENTCOMP
) {
1067 if (s
->cirrus_blt_pixelwidth
> 2) {
1068 printf("src transparent without colorexpand must be 8bpp or 16bpp\n");
1071 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_BACKWARDS
) {
1072 s
->cirrus_blt_dstpitch
= -s
->cirrus_blt_dstpitch
;
1073 s
->cirrus_blt_srcpitch
= -s
->cirrus_blt_srcpitch
;
1074 s
->cirrus_rop
= cirrus_bkwd_transp_rop
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
1076 s
->cirrus_rop
= cirrus_fwd_transp_rop
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
1079 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_BACKWARDS
) {
1080 s
->cirrus_blt_dstpitch
= -s
->cirrus_blt_dstpitch
;
1081 s
->cirrus_blt_srcpitch
= -s
->cirrus_blt_srcpitch
;
1082 s
->cirrus_rop
= cirrus_bkwd_rop
[rop_to_index
[blt_rop
]];
1084 s
->cirrus_rop
= cirrus_fwd_rop
[rop_to_index
[blt_rop
]];
1088 // setup bitblt engine.
1089 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_MEMSYSSRC
) {
1090 if (!cirrus_bitblt_cputovideo(s
))
1092 } else if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_MEMSYSDEST
) {
1093 if (!cirrus_bitblt_videotocpu(s
))
1096 if (!cirrus_bitblt_videotovideo(s
))
1102 cirrus_bitblt_reset(s
);
1105 static void cirrus_write_bitblt(CirrusVGAState
* s
, unsigned reg_value
)
1109 old_value
= s
->vga
.gr
[0x31];
1110 s
->vga
.gr
[0x31] = reg_value
;
1112 if (((old_value
& CIRRUS_BLT_RESET
) != 0) &&
1113 ((reg_value
& CIRRUS_BLT_RESET
) == 0)) {
1114 cirrus_bitblt_reset(s
);
1115 } else if (((old_value
& CIRRUS_BLT_START
) == 0) &&
1116 ((reg_value
& CIRRUS_BLT_START
) != 0)) {
1117 cirrus_bitblt_start(s
);
1122 /***************************************
1126 ***************************************/
1128 static void cirrus_get_offsets(VGACommonState
*s1
,
1129 uint32_t *pline_offset
,
1130 uint32_t *pstart_addr
,
1131 uint32_t *pline_compare
)
1133 CirrusVGAState
* s
= container_of(s1
, CirrusVGAState
, vga
);
1134 uint32_t start_addr
, line_offset
, line_compare
;
1136 line_offset
= s
->vga
.cr
[0x13]
1137 | ((s
->vga
.cr
[0x1b] & 0x10) << 4);
1139 *pline_offset
= line_offset
;
1141 start_addr
= (s
->vga
.cr
[0x0c] << 8)
1143 | ((s
->vga
.cr
[0x1b] & 0x01) << 16)
1144 | ((s
->vga
.cr
[0x1b] & 0x0c) << 15)
1145 | ((s
->vga
.cr
[0x1d] & 0x80) << 12);
1146 *pstart_addr
= start_addr
;
1148 line_compare
= s
->vga
.cr
[0x18] |
1149 ((s
->vga
.cr
[0x07] & 0x10) << 4) |
1150 ((s
->vga
.cr
[0x09] & 0x40) << 3);
1151 *pline_compare
= line_compare
;
1154 static uint32_t cirrus_get_bpp16_depth(CirrusVGAState
* s
)
1158 switch (s
->cirrus_hidden_dac_data
& 0xf) {
1161 break; /* Sierra HiColor */
1164 break; /* XGA HiColor */
1167 printf("cirrus: invalid DAC value %x in 16bpp\n",
1168 (s
->cirrus_hidden_dac_data
& 0xf));
1176 static int cirrus_get_bpp(VGACommonState
*s1
)
1178 CirrusVGAState
* s
= container_of(s1
, CirrusVGAState
, vga
);
1181 if ((s
->vga
.sr
[0x07] & 0x01) != 0) {
1183 switch (s
->vga
.sr
[0x07] & CIRRUS_SR7_BPP_MASK
) {
1184 case CIRRUS_SR7_BPP_8
:
1187 case CIRRUS_SR7_BPP_16_DOUBLEVCLK
:
1188 ret
= cirrus_get_bpp16_depth(s
);
1190 case CIRRUS_SR7_BPP_24
:
1193 case CIRRUS_SR7_BPP_16
:
1194 ret
= cirrus_get_bpp16_depth(s
);
1196 case CIRRUS_SR7_BPP_32
:
1201 printf("cirrus: unknown bpp - sr7=%x\n", s
->vga
.sr
[0x7]);
1214 static void cirrus_get_resolution(VGACommonState
*s
, int *pwidth
, int *pheight
)
1218 width
= (s
->cr
[0x01] + 1) * 8;
1219 height
= s
->cr
[0x12] |
1220 ((s
->cr
[0x07] & 0x02) << 7) |
1221 ((s
->cr
[0x07] & 0x40) << 3);
1222 height
= (height
+ 1);
1223 /* interlace support */
1224 if (s
->cr
[0x1a] & 0x01)
1225 height
= height
* 2;
1230 /***************************************
1234 ***************************************/
1236 static void cirrus_update_bank_ptr(CirrusVGAState
* s
, unsigned bank_index
)
1241 if ((s
->vga
.gr
[0x0b] & 0x01) != 0) /* dual bank */
1242 offset
= s
->vga
.gr
[0x09 + bank_index
];
1243 else /* single bank */
1244 offset
= s
->vga
.gr
[0x09];
1246 if ((s
->vga
.gr
[0x0b] & 0x20) != 0)
1251 if (s
->real_vram_size
<= offset
)
1254 limit
= s
->real_vram_size
- offset
;
1256 if (((s
->vga
.gr
[0x0b] & 0x01) == 0) && (bank_index
!= 0)) {
1257 if (limit
> 0x8000) {
1266 s
->cirrus_bank_base
[bank_index
] = offset
;
1267 s
->cirrus_bank_limit
[bank_index
] = limit
;
1269 s
->cirrus_bank_base
[bank_index
] = 0;
1270 s
->cirrus_bank_limit
[bank_index
] = 0;
1274 /***************************************
1276 * I/O access between 0x3c4-0x3c5
1278 ***************************************/
1280 static int cirrus_vga_read_sr(CirrusVGAState
* s
)
1282 switch (s
->vga
.sr_index
) {
1283 case 0x00: // Standard VGA
1284 case 0x01: // Standard VGA
1285 case 0x02: // Standard VGA
1286 case 0x03: // Standard VGA
1287 case 0x04: // Standard VGA
1288 return s
->vga
.sr
[s
->vga
.sr_index
];
1289 case 0x06: // Unlock Cirrus extensions
1290 return s
->vga
.sr
[s
->vga
.sr_index
];
1294 case 0x70: // Graphics Cursor X
1298 case 0xf0: // Graphics Cursor X
1299 return s
->vga
.sr
[0x10];
1303 case 0x71: // Graphics Cursor Y
1307 case 0xf1: // Graphics Cursor Y
1308 return s
->vga
.sr
[0x11];
1310 case 0x07: // Extended Sequencer Mode
1311 case 0x08: // EEPROM Control
1312 case 0x09: // Scratch Register 0
1313 case 0x0a: // Scratch Register 1
1314 case 0x0b: // VCLK 0
1315 case 0x0c: // VCLK 1
1316 case 0x0d: // VCLK 2
1317 case 0x0e: // VCLK 3
1318 case 0x0f: // DRAM Control
1319 case 0x12: // Graphics Cursor Attribute
1320 case 0x13: // Graphics Cursor Pattern Address
1321 case 0x14: // Scratch Register 2
1322 case 0x15: // Scratch Register 3
1323 case 0x16: // Performance Tuning Register
1324 case 0x17: // Configuration Readback and Extended Control
1325 case 0x18: // Signature Generator Control
1326 case 0x19: // Signal Generator Result
1327 case 0x1a: // Signal Generator Result
1328 case 0x1b: // VCLK 0 Denominator & Post
1329 case 0x1c: // VCLK 1 Denominator & Post
1330 case 0x1d: // VCLK 2 Denominator & Post
1331 case 0x1e: // VCLK 3 Denominator & Post
1332 case 0x1f: // BIOS Write Enable and MCLK select
1334 printf("cirrus: handled inport sr_index %02x\n", s
->vga
.sr_index
);
1336 return s
->vga
.sr
[s
->vga
.sr_index
];
1339 printf("cirrus: inport sr_index %02x\n", s
->vga
.sr_index
);
1346 static void cirrus_vga_write_sr(CirrusVGAState
* s
, uint32_t val
)
1348 switch (s
->vga
.sr_index
) {
1349 case 0x00: // Standard VGA
1350 case 0x01: // Standard VGA
1351 case 0x02: // Standard VGA
1352 case 0x03: // Standard VGA
1353 case 0x04: // Standard VGA
1354 s
->vga
.sr
[s
->vga
.sr_index
] = val
& sr_mask
[s
->vga
.sr_index
];
1355 if (s
->vga
.sr_index
== 1)
1356 s
->vga
.update_retrace_info(&s
->vga
);
1358 case 0x06: // Unlock Cirrus extensions
1361 s
->vga
.sr
[s
->vga
.sr_index
] = 0x12;
1363 s
->vga
.sr
[s
->vga
.sr_index
] = 0x0f;
1369 case 0x70: // Graphics Cursor X
1373 case 0xf0: // Graphics Cursor X
1374 s
->vga
.sr
[0x10] = val
;
1375 s
->vga
.hw_cursor_x
= (val
<< 3) | (s
->vga
.sr_index
>> 5);
1380 case 0x71: // Graphics Cursor Y
1384 case 0xf1: // Graphics Cursor Y
1385 s
->vga
.sr
[0x11] = val
;
1386 s
->vga
.hw_cursor_y
= (val
<< 3) | (s
->vga
.sr_index
>> 5);
1388 case 0x07: // Extended Sequencer Mode
1389 cirrus_update_memory_access(s
);
1390 case 0x08: // EEPROM Control
1391 case 0x09: // Scratch Register 0
1392 case 0x0a: // Scratch Register 1
1393 case 0x0b: // VCLK 0
1394 case 0x0c: // VCLK 1
1395 case 0x0d: // VCLK 2
1396 case 0x0e: // VCLK 3
1397 case 0x0f: // DRAM Control
1398 case 0x13: // Graphics Cursor Pattern Address
1399 case 0x14: // Scratch Register 2
1400 case 0x15: // Scratch Register 3
1401 case 0x16: // Performance Tuning Register
1402 case 0x18: // Signature Generator Control
1403 case 0x19: // Signature Generator Result
1404 case 0x1a: // Signature Generator Result
1405 case 0x1b: // VCLK 0 Denominator & Post
1406 case 0x1c: // VCLK 1 Denominator & Post
1407 case 0x1d: // VCLK 2 Denominator & Post
1408 case 0x1e: // VCLK 3 Denominator & Post
1409 case 0x1f: // BIOS Write Enable and MCLK select
1410 s
->vga
.sr
[s
->vga
.sr_index
] = val
;
1412 printf("cirrus: handled outport sr_index %02x, sr_value %02x\n",
1413 s
->vga
.sr_index
, val
);
1416 case 0x12: // Graphics Cursor Attribute
1417 s
->vga
.sr
[0x12] = val
;
1418 s
->vga
.force_shadow
= !!(val
& CIRRUS_CURSOR_SHOW
);
1420 printf("cirrus: cursor ctl SR12=%02x (force shadow: %d)\n",
1421 val
, s
->vga
.force_shadow
);
1424 case 0x17: // Configuration Readback and Extended Control
1425 s
->vga
.sr
[s
->vga
.sr_index
] = (s
->vga
.sr
[s
->vga
.sr_index
] & 0x38)
1427 cirrus_update_memory_access(s
);
1431 printf("cirrus: outport sr_index %02x, sr_value %02x\n",
1432 s
->vga
.sr_index
, val
);
1438 /***************************************
1440 * I/O access at 0x3c6
1442 ***************************************/
1444 static int cirrus_read_hidden_dac(CirrusVGAState
* s
)
1446 if (++s
->cirrus_hidden_dac_lockindex
== 5) {
1447 s
->cirrus_hidden_dac_lockindex
= 0;
1448 return s
->cirrus_hidden_dac_data
;
1453 static void cirrus_write_hidden_dac(CirrusVGAState
* s
, int reg_value
)
1455 if (s
->cirrus_hidden_dac_lockindex
== 4) {
1456 s
->cirrus_hidden_dac_data
= reg_value
;
1457 #if defined(DEBUG_CIRRUS)
1458 printf("cirrus: outport hidden DAC, value %02x\n", reg_value
);
1461 s
->cirrus_hidden_dac_lockindex
= 0;
1464 /***************************************
1466 * I/O access at 0x3c9
1468 ***************************************/
1470 static int cirrus_vga_read_palette(CirrusVGAState
* s
)
1474 if ((s
->vga
.sr
[0x12] & CIRRUS_CURSOR_HIDDENPEL
)) {
1475 val
= s
->cirrus_hidden_palette
[(s
->vga
.dac_read_index
& 0x0f) * 3 +
1476 s
->vga
.dac_sub_index
];
1478 val
= s
->vga
.palette
[s
->vga
.dac_read_index
* 3 + s
->vga
.dac_sub_index
];
1480 if (++s
->vga
.dac_sub_index
== 3) {
1481 s
->vga
.dac_sub_index
= 0;
1482 s
->vga
.dac_read_index
++;
1487 static void cirrus_vga_write_palette(CirrusVGAState
* s
, int reg_value
)
1489 s
->vga
.dac_cache
[s
->vga
.dac_sub_index
] = reg_value
;
1490 if (++s
->vga
.dac_sub_index
== 3) {
1491 if ((s
->vga
.sr
[0x12] & CIRRUS_CURSOR_HIDDENPEL
)) {
1492 memcpy(&s
->cirrus_hidden_palette
[(s
->vga
.dac_write_index
& 0x0f) * 3],
1493 s
->vga
.dac_cache
, 3);
1495 memcpy(&s
->vga
.palette
[s
->vga
.dac_write_index
* 3], s
->vga
.dac_cache
, 3);
1497 /* XXX update cursor */
1498 s
->vga
.dac_sub_index
= 0;
1499 s
->vga
.dac_write_index
++;
1503 /***************************************
1505 * I/O access between 0x3ce-0x3cf
1507 ***************************************/
1509 static int cirrus_vga_read_gr(CirrusVGAState
* s
, unsigned reg_index
)
1511 switch (reg_index
) {
1512 case 0x00: // Standard VGA, BGCOLOR 0x000000ff
1513 return s
->cirrus_shadow_gr0
;
1514 case 0x01: // Standard VGA, FGCOLOR 0x000000ff
1515 return s
->cirrus_shadow_gr1
;
1516 case 0x02: // Standard VGA
1517 case 0x03: // Standard VGA
1518 case 0x04: // Standard VGA
1519 case 0x06: // Standard VGA
1520 case 0x07: // Standard VGA
1521 case 0x08: // Standard VGA
1522 return s
->vga
.gr
[s
->vga
.gr_index
];
1523 case 0x05: // Standard VGA, Cirrus extended mode
1528 if (reg_index
< 0x3a) {
1529 return s
->vga
.gr
[reg_index
];
1532 printf("cirrus: inport gr_index %02x\n", reg_index
);
1539 cirrus_vga_write_gr(CirrusVGAState
* s
, unsigned reg_index
, int reg_value
)
1541 #if defined(DEBUG_BITBLT) && 0
1542 printf("gr%02x: %02x\n", reg_index
, reg_value
);
1544 switch (reg_index
) {
1545 case 0x00: // Standard VGA, BGCOLOR 0x000000ff
1546 s
->vga
.gr
[reg_index
] = reg_value
& gr_mask
[reg_index
];
1547 s
->cirrus_shadow_gr0
= reg_value
;
1549 case 0x01: // Standard VGA, FGCOLOR 0x000000ff
1550 s
->vga
.gr
[reg_index
] = reg_value
& gr_mask
[reg_index
];
1551 s
->cirrus_shadow_gr1
= reg_value
;
1553 case 0x02: // Standard VGA
1554 case 0x03: // Standard VGA
1555 case 0x04: // Standard VGA
1556 case 0x06: // Standard VGA
1557 case 0x07: // Standard VGA
1558 case 0x08: // Standard VGA
1559 s
->vga
.gr
[reg_index
] = reg_value
& gr_mask
[reg_index
];
1561 case 0x05: // Standard VGA, Cirrus extended mode
1562 s
->vga
.gr
[reg_index
] = reg_value
& 0x7f;
1563 cirrus_update_memory_access(s
);
1565 case 0x09: // bank offset #0
1566 case 0x0A: // bank offset #1
1567 s
->vga
.gr
[reg_index
] = reg_value
;
1568 cirrus_update_bank_ptr(s
, 0);
1569 cirrus_update_bank_ptr(s
, 1);
1570 cirrus_update_memory_access(s
);
1573 s
->vga
.gr
[reg_index
] = reg_value
;
1574 cirrus_update_bank_ptr(s
, 0);
1575 cirrus_update_bank_ptr(s
, 1);
1576 cirrus_update_memory_access(s
);
1578 case 0x10: // BGCOLOR 0x0000ff00
1579 case 0x11: // FGCOLOR 0x0000ff00
1580 case 0x12: // BGCOLOR 0x00ff0000
1581 case 0x13: // FGCOLOR 0x00ff0000
1582 case 0x14: // BGCOLOR 0xff000000
1583 case 0x15: // FGCOLOR 0xff000000
1584 case 0x20: // BLT WIDTH 0x0000ff
1585 case 0x22: // BLT HEIGHT 0x0000ff
1586 case 0x24: // BLT DEST PITCH 0x0000ff
1587 case 0x26: // BLT SRC PITCH 0x0000ff
1588 case 0x28: // BLT DEST ADDR 0x0000ff
1589 case 0x29: // BLT DEST ADDR 0x00ff00
1590 case 0x2c: // BLT SRC ADDR 0x0000ff
1591 case 0x2d: // BLT SRC ADDR 0x00ff00
1592 case 0x2f: // BLT WRITEMASK
1593 case 0x30: // BLT MODE
1594 case 0x32: // RASTER OP
1595 case 0x33: // BLT MODEEXT
1596 case 0x34: // BLT TRANSPARENT COLOR 0x00ff
1597 case 0x35: // BLT TRANSPARENT COLOR 0xff00
1598 case 0x38: // BLT TRANSPARENT COLOR MASK 0x00ff
1599 case 0x39: // BLT TRANSPARENT COLOR MASK 0xff00
1600 s
->vga
.gr
[reg_index
] = reg_value
;
1602 case 0x21: // BLT WIDTH 0x001f00
1603 case 0x23: // BLT HEIGHT 0x001f00
1604 case 0x25: // BLT DEST PITCH 0x001f00
1605 case 0x27: // BLT SRC PITCH 0x001f00
1606 s
->vga
.gr
[reg_index
] = reg_value
& 0x1f;
1608 case 0x2a: // BLT DEST ADDR 0x3f0000
1609 s
->vga
.gr
[reg_index
] = reg_value
& 0x3f;
1610 /* if auto start mode, starts bit blt now */
1611 if (s
->vga
.gr
[0x31] & CIRRUS_BLT_AUTOSTART
) {
1612 cirrus_bitblt_start(s
);
1615 case 0x2e: // BLT SRC ADDR 0x3f0000
1616 s
->vga
.gr
[reg_index
] = reg_value
& 0x3f;
1618 case 0x31: // BLT STATUS/START
1619 cirrus_write_bitblt(s
, reg_value
);
1623 printf("cirrus: outport gr_index %02x, gr_value %02x\n", reg_index
,
1630 /***************************************
1632 * I/O access between 0x3d4-0x3d5
1634 ***************************************/
1636 static int cirrus_vga_read_cr(CirrusVGAState
* s
, unsigned reg_index
)
1638 switch (reg_index
) {
1639 case 0x00: // Standard VGA
1640 case 0x01: // Standard VGA
1641 case 0x02: // Standard VGA
1642 case 0x03: // Standard VGA
1643 case 0x04: // Standard VGA
1644 case 0x05: // Standard VGA
1645 case 0x06: // Standard VGA
1646 case 0x07: // Standard VGA
1647 case 0x08: // Standard VGA
1648 case 0x09: // Standard VGA
1649 case 0x0a: // Standard VGA
1650 case 0x0b: // Standard VGA
1651 case 0x0c: // Standard VGA
1652 case 0x0d: // Standard VGA
1653 case 0x0e: // Standard VGA
1654 case 0x0f: // Standard VGA
1655 case 0x10: // Standard VGA
1656 case 0x11: // Standard VGA
1657 case 0x12: // Standard VGA
1658 case 0x13: // Standard VGA
1659 case 0x14: // Standard VGA
1660 case 0x15: // Standard VGA
1661 case 0x16: // Standard VGA
1662 case 0x17: // Standard VGA
1663 case 0x18: // Standard VGA
1664 return s
->vga
.cr
[s
->vga
.cr_index
];
1665 case 0x24: // Attribute Controller Toggle Readback (R)
1666 return (s
->vga
.ar_flip_flop
<< 7);
1667 case 0x19: // Interlace End
1668 case 0x1a: // Miscellaneous Control
1669 case 0x1b: // Extended Display Control
1670 case 0x1c: // Sync Adjust and Genlock
1671 case 0x1d: // Overlay Extended Control
1672 case 0x22: // Graphics Data Latches Readback (R)
1673 case 0x25: // Part Status
1674 case 0x27: // Part ID (R)
1675 return s
->vga
.cr
[s
->vga
.cr_index
];
1676 case 0x26: // Attribute Controller Index Readback (R)
1677 return s
->vga
.ar_index
& 0x3f;
1681 printf("cirrus: inport cr_index %02x\n", reg_index
);
1687 static void cirrus_vga_write_cr(CirrusVGAState
* s
, int reg_value
)
1689 switch (s
->vga
.cr_index
) {
1690 case 0x00: // Standard VGA
1691 case 0x01: // Standard VGA
1692 case 0x02: // Standard VGA
1693 case 0x03: // Standard VGA
1694 case 0x04: // Standard VGA
1695 case 0x05: // Standard VGA
1696 case 0x06: // Standard VGA
1697 case 0x07: // Standard VGA
1698 case 0x08: // Standard VGA
1699 case 0x09: // Standard VGA
1700 case 0x0a: // Standard VGA
1701 case 0x0b: // Standard VGA
1702 case 0x0c: // Standard VGA
1703 case 0x0d: // Standard VGA
1704 case 0x0e: // Standard VGA
1705 case 0x0f: // Standard VGA
1706 case 0x10: // Standard VGA
1707 case 0x11: // Standard VGA
1708 case 0x12: // Standard VGA
1709 case 0x13: // Standard VGA
1710 case 0x14: // Standard VGA
1711 case 0x15: // Standard VGA
1712 case 0x16: // Standard VGA
1713 case 0x17: // Standard VGA
1714 case 0x18: // Standard VGA
1715 /* handle CR0-7 protection */
1716 if ((s
->vga
.cr
[0x11] & 0x80) && s
->vga
.cr_index
<= 7) {
1717 /* can always write bit 4 of CR7 */
1718 if (s
->vga
.cr_index
== 7)
1719 s
->vga
.cr
[7] = (s
->vga
.cr
[7] & ~0x10) | (reg_value
& 0x10);
1722 s
->vga
.cr
[s
->vga
.cr_index
] = reg_value
;
1723 switch(s
->vga
.cr_index
) {
1731 s
->vga
.update_retrace_info(&s
->vga
);
1735 case 0x19: // Interlace End
1736 case 0x1a: // Miscellaneous Control
1737 case 0x1b: // Extended Display Control
1738 case 0x1c: // Sync Adjust and Genlock
1739 case 0x1d: // Overlay Extended Control
1740 s
->vga
.cr
[s
->vga
.cr_index
] = reg_value
;
1742 printf("cirrus: handled outport cr_index %02x, cr_value %02x\n",
1743 s
->vga
.cr_index
, reg_value
);
1746 case 0x22: // Graphics Data Latches Readback (R)
1747 case 0x24: // Attribute Controller Toggle Readback (R)
1748 case 0x26: // Attribute Controller Index Readback (R)
1749 case 0x27: // Part ID (R)
1751 case 0x25: // Part Status
1754 printf("cirrus: outport cr_index %02x, cr_value %02x\n",
1755 s
->vga
.cr_index
, reg_value
);
1761 /***************************************
1763 * memory-mapped I/O (bitblt)
1765 ***************************************/
1767 static uint8_t cirrus_mmio_blt_read(CirrusVGAState
* s
, unsigned address
)
1772 case (CIRRUS_MMIO_BLTBGCOLOR
+ 0):
1773 value
= cirrus_vga_read_gr(s
, 0x00);
1775 case (CIRRUS_MMIO_BLTBGCOLOR
+ 1):
1776 value
= cirrus_vga_read_gr(s
, 0x10);
1778 case (CIRRUS_MMIO_BLTBGCOLOR
+ 2):
1779 value
= cirrus_vga_read_gr(s
, 0x12);
1781 case (CIRRUS_MMIO_BLTBGCOLOR
+ 3):
1782 value
= cirrus_vga_read_gr(s
, 0x14);
1784 case (CIRRUS_MMIO_BLTFGCOLOR
+ 0):
1785 value
= cirrus_vga_read_gr(s
, 0x01);
1787 case (CIRRUS_MMIO_BLTFGCOLOR
+ 1):
1788 value
= cirrus_vga_read_gr(s
, 0x11);
1790 case (CIRRUS_MMIO_BLTFGCOLOR
+ 2):
1791 value
= cirrus_vga_read_gr(s
, 0x13);
1793 case (CIRRUS_MMIO_BLTFGCOLOR
+ 3):
1794 value
= cirrus_vga_read_gr(s
, 0x15);
1796 case (CIRRUS_MMIO_BLTWIDTH
+ 0):
1797 value
= cirrus_vga_read_gr(s
, 0x20);
1799 case (CIRRUS_MMIO_BLTWIDTH
+ 1):
1800 value
= cirrus_vga_read_gr(s
, 0x21);
1802 case (CIRRUS_MMIO_BLTHEIGHT
+ 0):
1803 value
= cirrus_vga_read_gr(s
, 0x22);
1805 case (CIRRUS_MMIO_BLTHEIGHT
+ 1):
1806 value
= cirrus_vga_read_gr(s
, 0x23);
1808 case (CIRRUS_MMIO_BLTDESTPITCH
+ 0):
1809 value
= cirrus_vga_read_gr(s
, 0x24);
1811 case (CIRRUS_MMIO_BLTDESTPITCH
+ 1):
1812 value
= cirrus_vga_read_gr(s
, 0x25);
1814 case (CIRRUS_MMIO_BLTSRCPITCH
+ 0):
1815 value
= cirrus_vga_read_gr(s
, 0x26);
1817 case (CIRRUS_MMIO_BLTSRCPITCH
+ 1):
1818 value
= cirrus_vga_read_gr(s
, 0x27);
1820 case (CIRRUS_MMIO_BLTDESTADDR
+ 0):
1821 value
= cirrus_vga_read_gr(s
, 0x28);
1823 case (CIRRUS_MMIO_BLTDESTADDR
+ 1):
1824 value
= cirrus_vga_read_gr(s
, 0x29);
1826 case (CIRRUS_MMIO_BLTDESTADDR
+ 2):
1827 value
= cirrus_vga_read_gr(s
, 0x2a);
1829 case (CIRRUS_MMIO_BLTSRCADDR
+ 0):
1830 value
= cirrus_vga_read_gr(s
, 0x2c);
1832 case (CIRRUS_MMIO_BLTSRCADDR
+ 1):
1833 value
= cirrus_vga_read_gr(s
, 0x2d);
1835 case (CIRRUS_MMIO_BLTSRCADDR
+ 2):
1836 value
= cirrus_vga_read_gr(s
, 0x2e);
1838 case CIRRUS_MMIO_BLTWRITEMASK
:
1839 value
= cirrus_vga_read_gr(s
, 0x2f);
1841 case CIRRUS_MMIO_BLTMODE
:
1842 value
= cirrus_vga_read_gr(s
, 0x30);
1844 case CIRRUS_MMIO_BLTROP
:
1845 value
= cirrus_vga_read_gr(s
, 0x32);
1847 case CIRRUS_MMIO_BLTMODEEXT
:
1848 value
= cirrus_vga_read_gr(s
, 0x33);
1850 case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR
+ 0):
1851 value
= cirrus_vga_read_gr(s
, 0x34);
1853 case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR
+ 1):
1854 value
= cirrus_vga_read_gr(s
, 0x35);
1856 case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK
+ 0):
1857 value
= cirrus_vga_read_gr(s
, 0x38);
1859 case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK
+ 1):
1860 value
= cirrus_vga_read_gr(s
, 0x39);
1862 case CIRRUS_MMIO_BLTSTATUS
:
1863 value
= cirrus_vga_read_gr(s
, 0x31);
1867 printf("cirrus: mmio read - address 0x%04x\n", address
);
1872 trace_vga_cirrus_write_blt(address
, value
);
1873 return (uint8_t) value
;
1876 static void cirrus_mmio_blt_write(CirrusVGAState
* s
, unsigned address
,
1879 trace_vga_cirrus_write_blt(address
, value
);
1881 case (CIRRUS_MMIO_BLTBGCOLOR
+ 0):
1882 cirrus_vga_write_gr(s
, 0x00, value
);
1884 case (CIRRUS_MMIO_BLTBGCOLOR
+ 1):
1885 cirrus_vga_write_gr(s
, 0x10, value
);
1887 case (CIRRUS_MMIO_BLTBGCOLOR
+ 2):
1888 cirrus_vga_write_gr(s
, 0x12, value
);
1890 case (CIRRUS_MMIO_BLTBGCOLOR
+ 3):
1891 cirrus_vga_write_gr(s
, 0x14, value
);
1893 case (CIRRUS_MMIO_BLTFGCOLOR
+ 0):
1894 cirrus_vga_write_gr(s
, 0x01, value
);
1896 case (CIRRUS_MMIO_BLTFGCOLOR
+ 1):
1897 cirrus_vga_write_gr(s
, 0x11, value
);
1899 case (CIRRUS_MMIO_BLTFGCOLOR
+ 2):
1900 cirrus_vga_write_gr(s
, 0x13, value
);
1902 case (CIRRUS_MMIO_BLTFGCOLOR
+ 3):
1903 cirrus_vga_write_gr(s
, 0x15, value
);
1905 case (CIRRUS_MMIO_BLTWIDTH
+ 0):
1906 cirrus_vga_write_gr(s
, 0x20, value
);
1908 case (CIRRUS_MMIO_BLTWIDTH
+ 1):
1909 cirrus_vga_write_gr(s
, 0x21, value
);
1911 case (CIRRUS_MMIO_BLTHEIGHT
+ 0):
1912 cirrus_vga_write_gr(s
, 0x22, value
);
1914 case (CIRRUS_MMIO_BLTHEIGHT
+ 1):
1915 cirrus_vga_write_gr(s
, 0x23, value
);
1917 case (CIRRUS_MMIO_BLTDESTPITCH
+ 0):
1918 cirrus_vga_write_gr(s
, 0x24, value
);
1920 case (CIRRUS_MMIO_BLTDESTPITCH
+ 1):
1921 cirrus_vga_write_gr(s
, 0x25, value
);
1923 case (CIRRUS_MMIO_BLTSRCPITCH
+ 0):
1924 cirrus_vga_write_gr(s
, 0x26, value
);
1926 case (CIRRUS_MMIO_BLTSRCPITCH
+ 1):
1927 cirrus_vga_write_gr(s
, 0x27, value
);
1929 case (CIRRUS_MMIO_BLTDESTADDR
+ 0):
1930 cirrus_vga_write_gr(s
, 0x28, value
);
1932 case (CIRRUS_MMIO_BLTDESTADDR
+ 1):
1933 cirrus_vga_write_gr(s
, 0x29, value
);
1935 case (CIRRUS_MMIO_BLTDESTADDR
+ 2):
1936 cirrus_vga_write_gr(s
, 0x2a, value
);
1938 case (CIRRUS_MMIO_BLTDESTADDR
+ 3):
1941 case (CIRRUS_MMIO_BLTSRCADDR
+ 0):
1942 cirrus_vga_write_gr(s
, 0x2c, value
);
1944 case (CIRRUS_MMIO_BLTSRCADDR
+ 1):
1945 cirrus_vga_write_gr(s
, 0x2d, value
);
1947 case (CIRRUS_MMIO_BLTSRCADDR
+ 2):
1948 cirrus_vga_write_gr(s
, 0x2e, value
);
1950 case CIRRUS_MMIO_BLTWRITEMASK
:
1951 cirrus_vga_write_gr(s
, 0x2f, value
);
1953 case CIRRUS_MMIO_BLTMODE
:
1954 cirrus_vga_write_gr(s
, 0x30, value
);
1956 case CIRRUS_MMIO_BLTROP
:
1957 cirrus_vga_write_gr(s
, 0x32, value
);
1959 case CIRRUS_MMIO_BLTMODEEXT
:
1960 cirrus_vga_write_gr(s
, 0x33, value
);
1962 case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR
+ 0):
1963 cirrus_vga_write_gr(s
, 0x34, value
);
1965 case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR
+ 1):
1966 cirrus_vga_write_gr(s
, 0x35, value
);
1968 case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK
+ 0):
1969 cirrus_vga_write_gr(s
, 0x38, value
);
1971 case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK
+ 1):
1972 cirrus_vga_write_gr(s
, 0x39, value
);
1974 case CIRRUS_MMIO_BLTSTATUS
:
1975 cirrus_vga_write_gr(s
, 0x31, value
);
1979 printf("cirrus: mmio write - addr 0x%04x val 0x%02x (ignored)\n",
1986 /***************************************
1990 ***************************************/
1992 static void cirrus_mem_writeb_mode4and5_8bpp(CirrusVGAState
* s
,
1998 unsigned val
= mem_value
;
2001 dst
= s
->vga
.vram_ptr
+ (offset
&= s
->cirrus_addr_mask
);
2002 for (x
= 0; x
< 8; x
++) {
2004 *dst
= s
->cirrus_shadow_gr1
;
2005 } else if (mode
== 5) {
2006 *dst
= s
->cirrus_shadow_gr0
;
2011 memory_region_set_dirty(&s
->vga
.vram
, offset
, 8);
2014 static void cirrus_mem_writeb_mode4and5_16bpp(CirrusVGAState
* s
,
2020 unsigned val
= mem_value
;
2023 dst
= s
->vga
.vram_ptr
+ (offset
&= s
->cirrus_addr_mask
);
2024 for (x
= 0; x
< 8; x
++) {
2026 *dst
= s
->cirrus_shadow_gr1
;
2027 *(dst
+ 1) = s
->vga
.gr
[0x11];
2028 } else if (mode
== 5) {
2029 *dst
= s
->cirrus_shadow_gr0
;
2030 *(dst
+ 1) = s
->vga
.gr
[0x10];
2035 memory_region_set_dirty(&s
->vga
.vram
, offset
, 16);
2038 /***************************************
2040 * memory access between 0xa0000-0xbffff
2042 ***************************************/
2044 static uint64_t cirrus_vga_mem_read(void *opaque
,
2048 CirrusVGAState
*s
= opaque
;
2049 unsigned bank_index
;
2050 unsigned bank_offset
;
2053 if ((s
->vga
.sr
[0x07] & 0x01) == 0) {
2054 return vga_mem_readb(&s
->vga
, addr
);
2057 if (addr
< 0x10000) {
2058 /* XXX handle bitblt */
2060 bank_index
= addr
>> 15;
2061 bank_offset
= addr
& 0x7fff;
2062 if (bank_offset
< s
->cirrus_bank_limit
[bank_index
]) {
2063 bank_offset
+= s
->cirrus_bank_base
[bank_index
];
2064 if ((s
->vga
.gr
[0x0B] & 0x14) == 0x14) {
2066 } else if (s
->vga
.gr
[0x0B] & 0x02) {
2069 bank_offset
&= s
->cirrus_addr_mask
;
2070 val
= *(s
->vga
.vram_ptr
+ bank_offset
);
2073 } else if (addr
>= 0x18000 && addr
< 0x18100) {
2074 /* memory-mapped I/O */
2076 if ((s
->vga
.sr
[0x17] & 0x44) == 0x04) {
2077 val
= cirrus_mmio_blt_read(s
, addr
& 0xff);
2082 printf("cirrus: mem_readb " TARGET_FMT_plx
"\n", addr
);
2088 static void cirrus_vga_mem_write(void *opaque
,
2093 CirrusVGAState
*s
= opaque
;
2094 unsigned bank_index
;
2095 unsigned bank_offset
;
2098 if ((s
->vga
.sr
[0x07] & 0x01) == 0) {
2099 vga_mem_writeb(&s
->vga
, addr
, mem_value
);
2103 if (addr
< 0x10000) {
2104 if (s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
) {
2106 *s
->cirrus_srcptr
++ = (uint8_t) mem_value
;
2107 if (s
->cirrus_srcptr
>= s
->cirrus_srcptr_end
) {
2108 cirrus_bitblt_cputovideo_next(s
);
2112 bank_index
= addr
>> 15;
2113 bank_offset
= addr
& 0x7fff;
2114 if (bank_offset
< s
->cirrus_bank_limit
[bank_index
]) {
2115 bank_offset
+= s
->cirrus_bank_base
[bank_index
];
2116 if ((s
->vga
.gr
[0x0B] & 0x14) == 0x14) {
2118 } else if (s
->vga
.gr
[0x0B] & 0x02) {
2121 bank_offset
&= s
->cirrus_addr_mask
;
2122 mode
= s
->vga
.gr
[0x05] & 0x7;
2123 if (mode
< 4 || mode
> 5 || ((s
->vga
.gr
[0x0B] & 0x4) == 0)) {
2124 *(s
->vga
.vram_ptr
+ bank_offset
) = mem_value
;
2125 memory_region_set_dirty(&s
->vga
.vram
, bank_offset
,
2128 if ((s
->vga
.gr
[0x0B] & 0x14) != 0x14) {
2129 cirrus_mem_writeb_mode4and5_8bpp(s
, mode
,
2133 cirrus_mem_writeb_mode4and5_16bpp(s
, mode
,
2140 } else if (addr
>= 0x18000 && addr
< 0x18100) {
2141 /* memory-mapped I/O */
2142 if ((s
->vga
.sr
[0x17] & 0x44) == 0x04) {
2143 cirrus_mmio_blt_write(s
, addr
& 0xff, mem_value
);
2147 printf("cirrus: mem_writeb " TARGET_FMT_plx
" value 0x%02" PRIu64
"\n", addr
,
2153 static const MemoryRegionOps cirrus_vga_mem_ops
= {
2154 .read
= cirrus_vga_mem_read
,
2155 .write
= cirrus_vga_mem_write
,
2156 .endianness
= DEVICE_LITTLE_ENDIAN
,
2158 .min_access_size
= 1,
2159 .max_access_size
= 1,
2163 /***************************************
2167 ***************************************/
2169 static inline void invalidate_cursor1(CirrusVGAState
*s
)
2171 if (s
->last_hw_cursor_size
) {
2172 vga_invalidate_scanlines(&s
->vga
,
2173 s
->last_hw_cursor_y
+ s
->last_hw_cursor_y_start
,
2174 s
->last_hw_cursor_y
+ s
->last_hw_cursor_y_end
);
2178 static inline void cirrus_cursor_compute_yrange(CirrusVGAState
*s
)
2182 int y
, y_min
, y_max
;
2184 src
= s
->vga
.vram_ptr
+ s
->real_vram_size
- 16 * 1024;
2185 if (s
->vga
.sr
[0x12] & CIRRUS_CURSOR_LARGE
) {
2186 src
+= (s
->vga
.sr
[0x13] & 0x3c) * 256;
2189 for(y
= 0; y
< 64; y
++) {
2190 content
= ((uint32_t *)src
)[0] |
2191 ((uint32_t *)src
)[1] |
2192 ((uint32_t *)src
)[2] |
2193 ((uint32_t *)src
)[3];
2203 src
+= (s
->vga
.sr
[0x13] & 0x3f) * 256;
2206 for(y
= 0; y
< 32; y
++) {
2207 content
= ((uint32_t *)src
)[0] |
2208 ((uint32_t *)(src
+ 128))[0];
2218 if (y_min
> y_max
) {
2219 s
->last_hw_cursor_y_start
= 0;
2220 s
->last_hw_cursor_y_end
= 0;
2222 s
->last_hw_cursor_y_start
= y_min
;
2223 s
->last_hw_cursor_y_end
= y_max
+ 1;
2227 /* NOTE: we do not currently handle the cursor bitmap change, so we
2228 update the cursor only if it moves. */
2229 static void cirrus_cursor_invalidate(VGACommonState
*s1
)
2231 CirrusVGAState
*s
= container_of(s1
, CirrusVGAState
, vga
);
2234 if (!(s
->vga
.sr
[0x12] & CIRRUS_CURSOR_SHOW
)) {
2237 if (s
->vga
.sr
[0x12] & CIRRUS_CURSOR_LARGE
)
2242 /* invalidate last cursor and new cursor if any change */
2243 if (s
->last_hw_cursor_size
!= size
||
2244 s
->last_hw_cursor_x
!= s
->vga
.hw_cursor_x
||
2245 s
->last_hw_cursor_y
!= s
->vga
.hw_cursor_y
) {
2247 invalidate_cursor1(s
);
2249 s
->last_hw_cursor_size
= size
;
2250 s
->last_hw_cursor_x
= s
->vga
.hw_cursor_x
;
2251 s
->last_hw_cursor_y
= s
->vga
.hw_cursor_y
;
2252 /* compute the real cursor min and max y */
2253 cirrus_cursor_compute_yrange(s
);
2254 invalidate_cursor1(s
);
2258 static void vga_draw_cursor_line(uint8_t *d1
,
2259 const uint8_t *src1
,
2261 unsigned int color0
,
2262 unsigned int color1
,
2263 unsigned int color_xor
)
2265 const uint8_t *plane0
, *plane1
;
2271 plane1
= src1
+ poffset
;
2272 for (x
= 0; x
< w
; x
++) {
2273 b0
= (plane0
[x
>> 3] >> (7 - (x
& 7))) & 1;
2274 b1
= (plane1
[x
>> 3] >> (7 - (x
& 7))) & 1;
2275 switch (b0
| (b1
<< 1)) {
2279 ((uint32_t *)d
)[0] ^= color_xor
;
2282 ((uint32_t *)d
)[0] = color0
;
2285 ((uint32_t *)d
)[0] = color1
;
2292 static void cirrus_cursor_draw_line(VGACommonState
*s1
, uint8_t *d1
, int scr_y
)
2294 CirrusVGAState
*s
= container_of(s1
, CirrusVGAState
, vga
);
2295 int w
, h
, x1
, x2
, poffset
;
2296 unsigned int color0
, color1
;
2297 const uint8_t *palette
, *src
;
2300 if (!(s
->vga
.sr
[0x12] & CIRRUS_CURSOR_SHOW
))
2302 /* fast test to see if the cursor intersects with the scan line */
2303 if (s
->vga
.sr
[0x12] & CIRRUS_CURSOR_LARGE
) {
2308 if (scr_y
< s
->vga
.hw_cursor_y
||
2309 scr_y
>= (s
->vga
.hw_cursor_y
+ h
)) {
2313 src
= s
->vga
.vram_ptr
+ s
->real_vram_size
- 16 * 1024;
2314 if (s
->vga
.sr
[0x12] & CIRRUS_CURSOR_LARGE
) {
2315 src
+= (s
->vga
.sr
[0x13] & 0x3c) * 256;
2316 src
+= (scr_y
- s
->vga
.hw_cursor_y
) * 16;
2318 content
= ((uint32_t *)src
)[0] |
2319 ((uint32_t *)src
)[1] |
2320 ((uint32_t *)src
)[2] |
2321 ((uint32_t *)src
)[3];
2323 src
+= (s
->vga
.sr
[0x13] & 0x3f) * 256;
2324 src
+= (scr_y
- s
->vga
.hw_cursor_y
) * 4;
2328 content
= ((uint32_t *)src
)[0] |
2329 ((uint32_t *)(src
+ 128))[0];
2331 /* if nothing to draw, no need to continue */
2336 x1
= s
->vga
.hw_cursor_x
;
2337 if (x1
>= s
->vga
.last_scr_width
)
2339 x2
= s
->vga
.hw_cursor_x
+ w
;
2340 if (x2
> s
->vga
.last_scr_width
)
2341 x2
= s
->vga
.last_scr_width
;
2343 palette
= s
->cirrus_hidden_palette
;
2344 color0
= rgb_to_pixel32(c6_to_8(palette
[0x0 * 3]),
2345 c6_to_8(palette
[0x0 * 3 + 1]),
2346 c6_to_8(palette
[0x0 * 3 + 2]));
2347 color1
= rgb_to_pixel32(c6_to_8(palette
[0xf * 3]),
2348 c6_to_8(palette
[0xf * 3 + 1]),
2349 c6_to_8(palette
[0xf * 3 + 2]));
2351 vga_draw_cursor_line(d1
, src
, poffset
, w
, color0
, color1
, 0xffffff);
2354 /***************************************
2358 ***************************************/
2360 static uint64_t cirrus_linear_read(void *opaque
, hwaddr addr
,
2363 CirrusVGAState
*s
= opaque
;
2366 addr
&= s
->cirrus_addr_mask
;
2368 if (((s
->vga
.sr
[0x17] & 0x44) == 0x44) &&
2369 ((addr
& s
->linear_mmio_mask
) == s
->linear_mmio_mask
)) {
2370 /* memory-mapped I/O */
2371 ret
= cirrus_mmio_blt_read(s
, addr
& 0xff);
2373 /* XXX handle bitblt */
2377 if ((s
->vga
.gr
[0x0B] & 0x14) == 0x14) {
2379 } else if (s
->vga
.gr
[0x0B] & 0x02) {
2382 addr
&= s
->cirrus_addr_mask
;
2383 ret
= *(s
->vga
.vram_ptr
+ addr
);
2389 static void cirrus_linear_write(void *opaque
, hwaddr addr
,
2390 uint64_t val
, unsigned size
)
2392 CirrusVGAState
*s
= opaque
;
2395 addr
&= s
->cirrus_addr_mask
;
2397 if (((s
->vga
.sr
[0x17] & 0x44) == 0x44) &&
2398 ((addr
& s
->linear_mmio_mask
) == s
->linear_mmio_mask
)) {
2399 /* memory-mapped I/O */
2400 cirrus_mmio_blt_write(s
, addr
& 0xff, val
);
2401 } else if (s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
) {
2403 *s
->cirrus_srcptr
++ = (uint8_t) val
;
2404 if (s
->cirrus_srcptr
>= s
->cirrus_srcptr_end
) {
2405 cirrus_bitblt_cputovideo_next(s
);
2409 if ((s
->vga
.gr
[0x0B] & 0x14) == 0x14) {
2411 } else if (s
->vga
.gr
[0x0B] & 0x02) {
2414 addr
&= s
->cirrus_addr_mask
;
2416 mode
= s
->vga
.gr
[0x05] & 0x7;
2417 if (mode
< 4 || mode
> 5 || ((s
->vga
.gr
[0x0B] & 0x4) == 0)) {
2418 *(s
->vga
.vram_ptr
+ addr
) = (uint8_t) val
;
2419 memory_region_set_dirty(&s
->vga
.vram
, addr
, 1);
2421 if ((s
->vga
.gr
[0x0B] & 0x14) != 0x14) {
2422 cirrus_mem_writeb_mode4and5_8bpp(s
, mode
, addr
, val
);
2424 cirrus_mem_writeb_mode4and5_16bpp(s
, mode
, addr
, val
);
2430 /***************************************
2432 * system to screen memory access
2434 ***************************************/
2437 static uint64_t cirrus_linear_bitblt_read(void *opaque
,
2441 CirrusVGAState
*s
= opaque
;
2444 /* XXX handle bitblt */
2450 static void cirrus_linear_bitblt_write(void *opaque
,
2455 CirrusVGAState
*s
= opaque
;
2457 if (s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
) {
2459 *s
->cirrus_srcptr
++ = (uint8_t) val
;
2460 if (s
->cirrus_srcptr
>= s
->cirrus_srcptr_end
) {
2461 cirrus_bitblt_cputovideo_next(s
);
2466 static const MemoryRegionOps cirrus_linear_bitblt_io_ops
= {
2467 .read
= cirrus_linear_bitblt_read
,
2468 .write
= cirrus_linear_bitblt_write
,
2469 .endianness
= DEVICE_LITTLE_ENDIAN
,
2471 .min_access_size
= 1,
2472 .max_access_size
= 1,
2476 static void map_linear_vram_bank(CirrusVGAState
*s
, unsigned bank
)
2478 MemoryRegion
*mr
= &s
->cirrus_bank
[bank
];
2479 bool enabled
= !(s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
)
2480 && !((s
->vga
.sr
[0x07] & 0x01) == 0)
2481 && !((s
->vga
.gr
[0x0B] & 0x14) == 0x14)
2482 && !(s
->vga
.gr
[0x0B] & 0x02);
2484 memory_region_set_enabled(mr
, enabled
);
2485 memory_region_set_alias_offset(mr
, s
->cirrus_bank_base
[bank
]);
2488 static void map_linear_vram(CirrusVGAState
*s
)
2490 if (s
->bustype
== CIRRUS_BUSTYPE_PCI
&& !s
->linear_vram
) {
2491 s
->linear_vram
= true;
2492 memory_region_add_subregion_overlap(&s
->pci_bar
, 0, &s
->vga
.vram
, 1);
2494 map_linear_vram_bank(s
, 0);
2495 map_linear_vram_bank(s
, 1);
2498 static void unmap_linear_vram(CirrusVGAState
*s
)
2500 if (s
->bustype
== CIRRUS_BUSTYPE_PCI
&& s
->linear_vram
) {
2501 s
->linear_vram
= false;
2502 memory_region_del_subregion(&s
->pci_bar
, &s
->vga
.vram
);
2504 memory_region_set_enabled(&s
->cirrus_bank
[0], false);
2505 memory_region_set_enabled(&s
->cirrus_bank
[1], false);
2508 /* Compute the memory access functions */
2509 static void cirrus_update_memory_access(CirrusVGAState
*s
)
2513 memory_region_transaction_begin();
2514 if ((s
->vga
.sr
[0x17] & 0x44) == 0x44) {
2516 } else if (s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
) {
2519 if ((s
->vga
.gr
[0x0B] & 0x14) == 0x14) {
2521 } else if (s
->vga
.gr
[0x0B] & 0x02) {
2525 mode
= s
->vga
.gr
[0x05] & 0x7;
2526 if (mode
< 4 || mode
> 5 || ((s
->vga
.gr
[0x0B] & 0x4) == 0)) {
2530 unmap_linear_vram(s
);
2533 memory_region_transaction_commit();
2539 static uint64_t cirrus_vga_ioport_read(void *opaque
, hwaddr addr
,
2542 CirrusVGAState
*c
= opaque
;
2543 VGACommonState
*s
= &c
->vga
;
2548 if (vga_ioport_invalid(s
, addr
)) {
2553 if (s
->ar_flip_flop
== 0) {
2560 index
= s
->ar_index
& 0x1f;
2573 val
= cirrus_vga_read_sr(c
);
2575 #ifdef DEBUG_VGA_REG
2576 printf("vga: read SR%x = 0x%02x\n", s
->sr_index
, val
);
2580 val
= cirrus_read_hidden_dac(c
);
2586 val
= s
->dac_write_index
;
2587 c
->cirrus_hidden_dac_lockindex
= 0;
2590 val
= cirrus_vga_read_palette(c
);
2602 val
= cirrus_vga_read_gr(c
, s
->gr_index
);
2603 #ifdef DEBUG_VGA_REG
2604 printf("vga: read GR%x = 0x%02x\n", s
->gr_index
, val
);
2613 val
= cirrus_vga_read_cr(c
, s
->cr_index
);
2614 #ifdef DEBUG_VGA_REG
2615 printf("vga: read CR%x = 0x%02x\n", s
->cr_index
, val
);
2620 /* just toggle to fool polling */
2621 val
= s
->st01
= s
->retrace(s
);
2622 s
->ar_flip_flop
= 0;
2629 trace_vga_cirrus_read_io(addr
, val
);
2633 static void cirrus_vga_ioport_write(void *opaque
, hwaddr addr
, uint64_t val
,
2636 CirrusVGAState
*c
= opaque
;
2637 VGACommonState
*s
= &c
->vga
;
2642 /* check port range access depending on color/monochrome mode */
2643 if (vga_ioport_invalid(s
, addr
)) {
2646 trace_vga_cirrus_write_io(addr
, val
);
2650 if (s
->ar_flip_flop
== 0) {
2654 index
= s
->ar_index
& 0x1f;
2657 s
->ar
[index
] = val
& 0x3f;
2660 s
->ar
[index
] = val
& ~0x10;
2666 s
->ar
[index
] = val
& ~0xc0;
2669 s
->ar
[index
] = val
& ~0xf0;
2672 s
->ar
[index
] = val
& ~0xf0;
2678 s
->ar_flip_flop
^= 1;
2681 s
->msr
= val
& ~0x10;
2682 s
->update_retrace_info(s
);
2688 #ifdef DEBUG_VGA_REG
2689 printf("vga: write SR%x = 0x%02" PRIu64
"\n", s
->sr_index
, val
);
2691 cirrus_vga_write_sr(c
, val
);
2694 cirrus_write_hidden_dac(c
, val
);
2697 s
->dac_read_index
= val
;
2698 s
->dac_sub_index
= 0;
2702 s
->dac_write_index
= val
;
2703 s
->dac_sub_index
= 0;
2707 cirrus_vga_write_palette(c
, val
);
2713 #ifdef DEBUG_VGA_REG
2714 printf("vga: write GR%x = 0x%02" PRIu64
"\n", s
->gr_index
, val
);
2716 cirrus_vga_write_gr(c
, s
->gr_index
, val
);
2724 #ifdef DEBUG_VGA_REG
2725 printf("vga: write CR%x = 0x%02"PRIu64
"\n", s
->cr_index
, val
);
2727 cirrus_vga_write_cr(c
, val
);
2731 s
->fcr
= val
& 0x10;
2736 /***************************************
2738 * memory-mapped I/O access
2740 ***************************************/
2742 static uint64_t cirrus_mmio_read(void *opaque
, hwaddr addr
,
2745 CirrusVGAState
*s
= opaque
;
2747 if (addr
>= 0x100) {
2748 return cirrus_mmio_blt_read(s
, addr
- 0x100);
2750 return cirrus_vga_ioport_read(s
, addr
+ 0x10, size
);
2754 static void cirrus_mmio_write(void *opaque
, hwaddr addr
,
2755 uint64_t val
, unsigned size
)
2757 CirrusVGAState
*s
= opaque
;
2759 if (addr
>= 0x100) {
2760 cirrus_mmio_blt_write(s
, addr
- 0x100, val
);
2762 cirrus_vga_ioport_write(s
, addr
+ 0x10, val
, size
);
2766 static const MemoryRegionOps cirrus_mmio_io_ops
= {
2767 .read
= cirrus_mmio_read
,
2768 .write
= cirrus_mmio_write
,
2769 .endianness
= DEVICE_LITTLE_ENDIAN
,
2771 .min_access_size
= 1,
2772 .max_access_size
= 1,
2776 /* load/save state */
2778 static int cirrus_post_load(void *opaque
, int version_id
)
2780 CirrusVGAState
*s
= opaque
;
2782 s
->vga
.gr
[0x00] = s
->cirrus_shadow_gr0
& 0x0f;
2783 s
->vga
.gr
[0x01] = s
->cirrus_shadow_gr1
& 0x0f;
2785 cirrus_update_memory_access(s
);
2787 s
->vga
.graphic_mode
= -1;
2788 cirrus_update_bank_ptr(s
, 0);
2789 cirrus_update_bank_ptr(s
, 1);
2793 static const VMStateDescription vmstate_cirrus_vga
= {
2794 .name
= "cirrus_vga",
2796 .minimum_version_id
= 1,
2797 .post_load
= cirrus_post_load
,
2798 .fields
= (VMStateField
[]) {
2799 VMSTATE_UINT32(vga
.latch
, CirrusVGAState
),
2800 VMSTATE_UINT8(vga
.sr_index
, CirrusVGAState
),
2801 VMSTATE_BUFFER(vga
.sr
, CirrusVGAState
),
2802 VMSTATE_UINT8(vga
.gr_index
, CirrusVGAState
),
2803 VMSTATE_UINT8(cirrus_shadow_gr0
, CirrusVGAState
),
2804 VMSTATE_UINT8(cirrus_shadow_gr1
, CirrusVGAState
),
2805 VMSTATE_BUFFER_START_MIDDLE(vga
.gr
, CirrusVGAState
, 2),
2806 VMSTATE_UINT8(vga
.ar_index
, CirrusVGAState
),
2807 VMSTATE_BUFFER(vga
.ar
, CirrusVGAState
),
2808 VMSTATE_INT32(vga
.ar_flip_flop
, CirrusVGAState
),
2809 VMSTATE_UINT8(vga
.cr_index
, CirrusVGAState
),
2810 VMSTATE_BUFFER(vga
.cr
, CirrusVGAState
),
2811 VMSTATE_UINT8(vga
.msr
, CirrusVGAState
),
2812 VMSTATE_UINT8(vga
.fcr
, CirrusVGAState
),
2813 VMSTATE_UINT8(vga
.st00
, CirrusVGAState
),
2814 VMSTATE_UINT8(vga
.st01
, CirrusVGAState
),
2815 VMSTATE_UINT8(vga
.dac_state
, CirrusVGAState
),
2816 VMSTATE_UINT8(vga
.dac_sub_index
, CirrusVGAState
),
2817 VMSTATE_UINT8(vga
.dac_read_index
, CirrusVGAState
),
2818 VMSTATE_UINT8(vga
.dac_write_index
, CirrusVGAState
),
2819 VMSTATE_BUFFER(vga
.dac_cache
, CirrusVGAState
),
2820 VMSTATE_BUFFER(vga
.palette
, CirrusVGAState
),
2821 VMSTATE_INT32(vga
.bank_offset
, CirrusVGAState
),
2822 VMSTATE_UINT8(cirrus_hidden_dac_lockindex
, CirrusVGAState
),
2823 VMSTATE_UINT8(cirrus_hidden_dac_data
, CirrusVGAState
),
2824 VMSTATE_UINT32(vga
.hw_cursor_x
, CirrusVGAState
),
2825 VMSTATE_UINT32(vga
.hw_cursor_y
, CirrusVGAState
),
2826 /* XXX: we do not save the bitblt state - we assume we do not save
2827 the state when the blitter is active */
2828 VMSTATE_END_OF_LIST()
2832 static const VMStateDescription vmstate_pci_cirrus_vga
= {
2833 .name
= "cirrus_vga",
2835 .minimum_version_id
= 2,
2836 .fields
= (VMStateField
[]) {
2837 VMSTATE_PCI_DEVICE(dev
, PCICirrusVGAState
),
2838 VMSTATE_STRUCT(cirrus_vga
, PCICirrusVGAState
, 0,
2839 vmstate_cirrus_vga
, CirrusVGAState
),
2840 VMSTATE_END_OF_LIST()
2844 /***************************************
2848 ***************************************/
2850 static void cirrus_reset(void *opaque
)
2852 CirrusVGAState
*s
= opaque
;
2854 vga_common_reset(&s
->vga
);
2855 unmap_linear_vram(s
);
2856 s
->vga
.sr
[0x06] = 0x0f;
2857 if (s
->device_id
== CIRRUS_ID_CLGD5446
) {
2858 /* 4MB 64 bit memory config, always PCI */
2859 s
->vga
.sr
[0x1F] = 0x2d; // MemClock
2860 s
->vga
.gr
[0x18] = 0x0f; // fastest memory configuration
2861 s
->vga
.sr
[0x0f] = 0x98;
2862 s
->vga
.sr
[0x17] = 0x20;
2863 s
->vga
.sr
[0x15] = 0x04; /* memory size, 3=2MB, 4=4MB */
2865 s
->vga
.sr
[0x1F] = 0x22; // MemClock
2866 s
->vga
.sr
[0x0F] = CIRRUS_MEMSIZE_2M
;
2867 s
->vga
.sr
[0x17] = s
->bustype
;
2868 s
->vga
.sr
[0x15] = 0x03; /* memory size, 3=2MB, 4=4MB */
2870 s
->vga
.cr
[0x27] = s
->device_id
;
2872 s
->cirrus_hidden_dac_lockindex
= 5;
2873 s
->cirrus_hidden_dac_data
= 0;
2876 static const MemoryRegionOps cirrus_linear_io_ops
= {
2877 .read
= cirrus_linear_read
,
2878 .write
= cirrus_linear_write
,
2879 .endianness
= DEVICE_LITTLE_ENDIAN
,
2881 .min_access_size
= 1,
2882 .max_access_size
= 1,
2886 static const MemoryRegionOps cirrus_vga_io_ops
= {
2887 .read
= cirrus_vga_ioport_read
,
2888 .write
= cirrus_vga_ioport_write
,
2889 .endianness
= DEVICE_LITTLE_ENDIAN
,
2891 .min_access_size
= 1,
2892 .max_access_size
= 1,
2896 static void cirrus_init_common(CirrusVGAState
*s
, Object
*owner
,
2897 int device_id
, int is_pci
,
2898 MemoryRegion
*system_memory
,
2899 MemoryRegion
*system_io
)
2906 for(i
= 0;i
< 256; i
++)
2907 rop_to_index
[i
] = CIRRUS_ROP_NOP_INDEX
; /* nop rop */
2908 rop_to_index
[CIRRUS_ROP_0
] = 0;
2909 rop_to_index
[CIRRUS_ROP_SRC_AND_DST
] = 1;
2910 rop_to_index
[CIRRUS_ROP_NOP
] = 2;
2911 rop_to_index
[CIRRUS_ROP_SRC_AND_NOTDST
] = 3;
2912 rop_to_index
[CIRRUS_ROP_NOTDST
] = 4;
2913 rop_to_index
[CIRRUS_ROP_SRC
] = 5;
2914 rop_to_index
[CIRRUS_ROP_1
] = 6;
2915 rop_to_index
[CIRRUS_ROP_NOTSRC_AND_DST
] = 7;
2916 rop_to_index
[CIRRUS_ROP_SRC_XOR_DST
] = 8;
2917 rop_to_index
[CIRRUS_ROP_SRC_OR_DST
] = 9;
2918 rop_to_index
[CIRRUS_ROP_NOTSRC_OR_NOTDST
] = 10;
2919 rop_to_index
[CIRRUS_ROP_SRC_NOTXOR_DST
] = 11;
2920 rop_to_index
[CIRRUS_ROP_SRC_OR_NOTDST
] = 12;
2921 rop_to_index
[CIRRUS_ROP_NOTSRC
] = 13;
2922 rop_to_index
[CIRRUS_ROP_NOTSRC_OR_DST
] = 14;
2923 rop_to_index
[CIRRUS_ROP_NOTSRC_AND_NOTDST
] = 15;
2924 s
->device_id
= device_id
;
2926 s
->bustype
= CIRRUS_BUSTYPE_PCI
;
2928 s
->bustype
= CIRRUS_BUSTYPE_ISA
;
2931 /* Register ioport 0x3b0 - 0x3df */
2932 memory_region_init_io(&s
->cirrus_vga_io
, owner
, &cirrus_vga_io_ops
, s
,
2934 memory_region_set_flush_coalesced(&s
->cirrus_vga_io
);
2935 memory_region_add_subregion(system_io
, 0x3b0, &s
->cirrus_vga_io
);
2937 memory_region_init(&s
->low_mem_container
, owner
,
2938 "cirrus-lowmem-container",
2941 memory_region_init_io(&s
->low_mem
, owner
, &cirrus_vga_mem_ops
, s
,
2942 "cirrus-low-memory", 0x20000);
2943 memory_region_add_subregion(&s
->low_mem_container
, 0, &s
->low_mem
);
2944 for (i
= 0; i
< 2; ++i
) {
2945 static const char *names
[] = { "vga.bank0", "vga.bank1" };
2946 MemoryRegion
*bank
= &s
->cirrus_bank
[i
];
2947 memory_region_init_alias(bank
, owner
, names
[i
], &s
->vga
.vram
,
2949 memory_region_set_enabled(bank
, false);
2950 memory_region_add_subregion_overlap(&s
->low_mem_container
, i
* 0x8000,
2953 memory_region_add_subregion_overlap(system_memory
,
2955 &s
->low_mem_container
,
2957 memory_region_set_coalescing(&s
->low_mem
);
2959 /* I/O handler for LFB */
2960 memory_region_init_io(&s
->cirrus_linear_io
, owner
, &cirrus_linear_io_ops
, s
,
2961 "cirrus-linear-io", s
->vga
.vram_size_mb
2963 memory_region_set_flush_coalesced(&s
->cirrus_linear_io
);
2965 /* I/O handler for LFB */
2966 memory_region_init_io(&s
->cirrus_linear_bitblt_io
, owner
,
2967 &cirrus_linear_bitblt_io_ops
,
2969 "cirrus-bitblt-mmio",
2971 memory_region_set_flush_coalesced(&s
->cirrus_linear_bitblt_io
);
2973 /* I/O handler for memory-mapped I/O */
2974 memory_region_init_io(&s
->cirrus_mmio_io
, owner
, &cirrus_mmio_io_ops
, s
,
2975 "cirrus-mmio", CIRRUS_PNPMMIO_SIZE
);
2976 memory_region_set_flush_coalesced(&s
->cirrus_mmio_io
);
2979 (s
->device_id
== CIRRUS_ID_CLGD5446
) ? 4096 * 1024 : 2048 * 1024;
2981 /* XXX: s->vga.vram_size must be a power of two */
2982 s
->cirrus_addr_mask
= s
->real_vram_size
- 1;
2983 s
->linear_mmio_mask
= s
->real_vram_size
- 256;
2985 s
->vga
.get_bpp
= cirrus_get_bpp
;
2986 s
->vga
.get_offsets
= cirrus_get_offsets
;
2987 s
->vga
.get_resolution
= cirrus_get_resolution
;
2988 s
->vga
.cursor_invalidate
= cirrus_cursor_invalidate
;
2989 s
->vga
.cursor_draw_line
= cirrus_cursor_draw_line
;
2991 qemu_register_reset(cirrus_reset
, s
);
2994 /***************************************
2998 ***************************************/
3000 static void isa_cirrus_vga_realizefn(DeviceState
*dev
, Error
**errp
)
3002 ISADevice
*isadev
= ISA_DEVICE(dev
);
3003 ISACirrusVGAState
*d
= ISA_CIRRUS_VGA(dev
);
3004 VGACommonState
*s
= &d
->cirrus_vga
.vga
;
3006 /* follow real hardware, cirrus card emulated has 4 MB video memory.
3007 Also accept 8 MB/16 MB for backward compatibility. */
3008 if (s
->vram_size_mb
!= 4 && s
->vram_size_mb
!= 8 &&
3009 s
->vram_size_mb
!= 16) {
3010 error_setg(errp
, "Invalid cirrus_vga ram size '%u'",
3014 vga_common_init(s
, OBJECT(dev
), true);
3015 cirrus_init_common(&d
->cirrus_vga
, OBJECT(dev
), CIRRUS_ID_CLGD5430
, 0,
3016 isa_address_space(isadev
),
3017 isa_address_space_io(isadev
));
3018 s
->con
= graphic_console_init(dev
, 0, s
->hw_ops
, s
);
3019 rom_add_vga(VGABIOS_CIRRUS_FILENAME
);
3020 /* XXX ISA-LFB support */
3021 /* FIXME not qdev yet */
3024 static Property isa_cirrus_vga_properties
[] = {
3025 DEFINE_PROP_UINT32("vgamem_mb", struct ISACirrusVGAState
,
3026 cirrus_vga
.vga
.vram_size_mb
, 8),
3027 DEFINE_PROP_END_OF_LIST(),
3030 static void isa_cirrus_vga_class_init(ObjectClass
*klass
, void *data
)
3032 DeviceClass
*dc
= DEVICE_CLASS(klass
);
3034 dc
->vmsd
= &vmstate_cirrus_vga
;
3035 dc
->realize
= isa_cirrus_vga_realizefn
;
3036 dc
->props
= isa_cirrus_vga_properties
;
3037 set_bit(DEVICE_CATEGORY_DISPLAY
, dc
->categories
);
3040 static const TypeInfo isa_cirrus_vga_info
= {
3041 .name
= TYPE_ISA_CIRRUS_VGA
,
3042 .parent
= TYPE_ISA_DEVICE
,
3043 .instance_size
= sizeof(ISACirrusVGAState
),
3044 .class_init
= isa_cirrus_vga_class_init
,
3047 /***************************************
3051 ***************************************/
3053 static void pci_cirrus_vga_realize(PCIDevice
*dev
, Error
**errp
)
3055 PCICirrusVGAState
*d
= PCI_CIRRUS_VGA(dev
);
3056 CirrusVGAState
*s
= &d
->cirrus_vga
;
3057 PCIDeviceClass
*pc
= PCI_DEVICE_GET_CLASS(dev
);
3058 int16_t device_id
= pc
->device_id
;
3060 /* follow real hardware, cirrus card emulated has 4 MB video memory.
3061 Also accept 8 MB/16 MB for backward compatibility. */
3062 if (s
->vga
.vram_size_mb
!= 4 && s
->vga
.vram_size_mb
!= 8 &&
3063 s
->vga
.vram_size_mb
!= 16) {
3064 error_setg(errp
, "Invalid cirrus_vga ram size '%u'",
3065 s
->vga
.vram_size_mb
);
3069 vga_common_init(&s
->vga
, OBJECT(dev
), true);
3070 cirrus_init_common(s
, OBJECT(dev
), device_id
, 1, pci_address_space(dev
),
3071 pci_address_space_io(dev
));
3072 s
->vga
.con
= graphic_console_init(DEVICE(dev
), 0, s
->vga
.hw_ops
, &s
->vga
);
3076 memory_region_init(&s
->pci_bar
, OBJECT(dev
), "cirrus-pci-bar0", 0x2000000);
3078 /* XXX: add byte swapping apertures */
3079 memory_region_add_subregion(&s
->pci_bar
, 0, &s
->cirrus_linear_io
);
3080 memory_region_add_subregion(&s
->pci_bar
, 0x1000000,
3081 &s
->cirrus_linear_bitblt_io
);
3083 /* setup memory space */
3085 /* memory #1 memory-mapped I/O */
3086 /* XXX: s->vga.vram_size must be a power of two */
3087 pci_register_bar(&d
->dev
, 0, PCI_BASE_ADDRESS_MEM_PREFETCH
, &s
->pci_bar
);
3088 if (device_id
== CIRRUS_ID_CLGD5446
) {
3089 pci_register_bar(&d
->dev
, 1, 0, &s
->cirrus_mmio_io
);
3093 static Property pci_vga_cirrus_properties
[] = {
3094 DEFINE_PROP_UINT32("vgamem_mb", struct PCICirrusVGAState
,
3095 cirrus_vga
.vga
.vram_size_mb
, 8),
3096 DEFINE_PROP_END_OF_LIST(),
3099 static void cirrus_vga_class_init(ObjectClass
*klass
, void *data
)
3101 DeviceClass
*dc
= DEVICE_CLASS(klass
);
3102 PCIDeviceClass
*k
= PCI_DEVICE_CLASS(klass
);
3104 k
->realize
= pci_cirrus_vga_realize
;
3105 k
->romfile
= VGABIOS_CIRRUS_FILENAME
;
3106 k
->vendor_id
= PCI_VENDOR_ID_CIRRUS
;
3107 k
->device_id
= CIRRUS_ID_CLGD5446
;
3108 k
->class_id
= PCI_CLASS_DISPLAY_VGA
;
3109 set_bit(DEVICE_CATEGORY_DISPLAY
, dc
->categories
);
3110 dc
->desc
= "Cirrus CLGD 54xx VGA";
3111 dc
->vmsd
= &vmstate_pci_cirrus_vga
;
3112 dc
->props
= pci_vga_cirrus_properties
;
3113 dc
->hotpluggable
= false;
3116 static const TypeInfo cirrus_vga_info
= {
3117 .name
= TYPE_PCI_CIRRUS_VGA
,
3118 .parent
= TYPE_PCI_DEVICE
,
3119 .instance_size
= sizeof(PCICirrusVGAState
),
3120 .class_init
= cirrus_vga_class_init
,
3123 static void cirrus_vga_register_types(void)
3125 type_register_static(&isa_cirrus_vga_info
);
3126 type_register_static(&cirrus_vga_info
);
3129 type_init(cirrus_vga_register_types
)