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 ***************************************/
52 #define CIRRUS_ID_CLGD5422 (0x23<<2)
53 #define CIRRUS_ID_CLGD5426 (0x24<<2)
54 #define CIRRUS_ID_CLGD5424 (0x25<<2)
55 #define CIRRUS_ID_CLGD5428 (0x26<<2)
56 #define CIRRUS_ID_CLGD5430 (0x28<<2)
57 #define CIRRUS_ID_CLGD5434 (0x2A<<2)
58 #define CIRRUS_ID_CLGD5436 (0x2B<<2)
59 #define CIRRUS_ID_CLGD5446 (0x2E<<2)
62 #define CIRRUS_SR7_BPP_VGA 0x00
63 #define CIRRUS_SR7_BPP_SVGA 0x01
64 #define CIRRUS_SR7_BPP_MASK 0x0e
65 #define CIRRUS_SR7_BPP_8 0x00
66 #define CIRRUS_SR7_BPP_16_DOUBLEVCLK 0x02
67 #define CIRRUS_SR7_BPP_24 0x04
68 #define CIRRUS_SR7_BPP_16 0x06
69 #define CIRRUS_SR7_BPP_32 0x08
70 #define CIRRUS_SR7_ISAADDR_MASK 0xe0
73 #define CIRRUS_MEMSIZE_512k 0x08
74 #define CIRRUS_MEMSIZE_1M 0x10
75 #define CIRRUS_MEMSIZE_2M 0x18
76 #define CIRRUS_MEMFLAGS_BANKSWITCH 0x80 // bank switching is enabled.
79 #define CIRRUS_CURSOR_SHOW 0x01
80 #define CIRRUS_CURSOR_HIDDENPEL 0x02
81 #define CIRRUS_CURSOR_LARGE 0x04 // 64x64 if set, 32x32 if clear
84 #define CIRRUS_BUSTYPE_VLBFAST 0x10
85 #define CIRRUS_BUSTYPE_PCI 0x20
86 #define CIRRUS_BUSTYPE_VLBSLOW 0x30
87 #define CIRRUS_BUSTYPE_ISA 0x38
88 #define CIRRUS_MMIO_ENABLE 0x04
89 #define CIRRUS_MMIO_USE_PCIADDR 0x40 // 0xb8000 if cleared.
90 #define CIRRUS_MEMSIZEEXT_DOUBLE 0x80
93 #define CIRRUS_BANKING_DUAL 0x01
94 #define CIRRUS_BANKING_GRANULARITY_16K 0x20 // set:16k, clear:4k
97 #define CIRRUS_BLTMODE_BACKWARDS 0x01
98 #define CIRRUS_BLTMODE_MEMSYSDEST 0x02
99 #define CIRRUS_BLTMODE_MEMSYSSRC 0x04
100 #define CIRRUS_BLTMODE_TRANSPARENTCOMP 0x08
101 #define CIRRUS_BLTMODE_PATTERNCOPY 0x40
102 #define CIRRUS_BLTMODE_COLOREXPAND 0x80
103 #define CIRRUS_BLTMODE_PIXELWIDTHMASK 0x30
104 #define CIRRUS_BLTMODE_PIXELWIDTH8 0x00
105 #define CIRRUS_BLTMODE_PIXELWIDTH16 0x10
106 #define CIRRUS_BLTMODE_PIXELWIDTH24 0x20
107 #define CIRRUS_BLTMODE_PIXELWIDTH32 0x30
110 #define CIRRUS_BLT_BUSY 0x01
111 #define CIRRUS_BLT_START 0x02
112 #define CIRRUS_BLT_RESET 0x04
113 #define CIRRUS_BLT_FIFOUSED 0x10
114 #define CIRRUS_BLT_AUTOSTART 0x80
117 #define CIRRUS_ROP_0 0x00
118 #define CIRRUS_ROP_SRC_AND_DST 0x05
119 #define CIRRUS_ROP_NOP 0x06
120 #define CIRRUS_ROP_SRC_AND_NOTDST 0x09
121 #define CIRRUS_ROP_NOTDST 0x0b
122 #define CIRRUS_ROP_SRC 0x0d
123 #define CIRRUS_ROP_1 0x0e
124 #define CIRRUS_ROP_NOTSRC_AND_DST 0x50
125 #define CIRRUS_ROP_SRC_XOR_DST 0x59
126 #define CIRRUS_ROP_SRC_OR_DST 0x6d
127 #define CIRRUS_ROP_NOTSRC_OR_NOTDST 0x90
128 #define CIRRUS_ROP_SRC_NOTXOR_DST 0x95
129 #define CIRRUS_ROP_SRC_OR_NOTDST 0xad
130 #define CIRRUS_ROP_NOTSRC 0xd0
131 #define CIRRUS_ROP_NOTSRC_OR_DST 0xd6
132 #define CIRRUS_ROP_NOTSRC_AND_NOTDST 0xda
134 #define CIRRUS_ROP_NOP_INDEX 2
135 #define CIRRUS_ROP_SRC_INDEX 5
138 #define CIRRUS_BLTMODEEXT_SOLIDFILL 0x04
139 #define CIRRUS_BLTMODEEXT_COLOREXPINV 0x02
140 #define CIRRUS_BLTMODEEXT_DWORDGRANULARITY 0x01
143 #define CIRRUS_MMIO_BLTBGCOLOR 0x00 // dword
144 #define CIRRUS_MMIO_BLTFGCOLOR 0x04 // dword
145 #define CIRRUS_MMIO_BLTWIDTH 0x08 // word
146 #define CIRRUS_MMIO_BLTHEIGHT 0x0a // word
147 #define CIRRUS_MMIO_BLTDESTPITCH 0x0c // word
148 #define CIRRUS_MMIO_BLTSRCPITCH 0x0e // word
149 #define CIRRUS_MMIO_BLTDESTADDR 0x10 // dword
150 #define CIRRUS_MMIO_BLTSRCADDR 0x14 // dword
151 #define CIRRUS_MMIO_BLTWRITEMASK 0x17 // byte
152 #define CIRRUS_MMIO_BLTMODE 0x18 // byte
153 #define CIRRUS_MMIO_BLTROP 0x1a // byte
154 #define CIRRUS_MMIO_BLTMODEEXT 0x1b // byte
155 #define CIRRUS_MMIO_BLTTRANSPARENTCOLOR 0x1c // word?
156 #define CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK 0x20 // word?
157 #define CIRRUS_MMIO_LINEARDRAW_START_X 0x24 // word
158 #define CIRRUS_MMIO_LINEARDRAW_START_Y 0x26 // word
159 #define CIRRUS_MMIO_LINEARDRAW_END_X 0x28 // word
160 #define CIRRUS_MMIO_LINEARDRAW_END_Y 0x2a // word
161 #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_INC 0x2c // byte
162 #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_ROLLOVER 0x2d // byte
163 #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_MASK 0x2e // byte
164 #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_ACCUM 0x2f // byte
165 #define CIRRUS_MMIO_BRESENHAM_K1 0x30 // word
166 #define CIRRUS_MMIO_BRESENHAM_K3 0x32 // word
167 #define CIRRUS_MMIO_BRESENHAM_ERROR 0x34 // word
168 #define CIRRUS_MMIO_BRESENHAM_DELTA_MAJOR 0x36 // word
169 #define CIRRUS_MMIO_BRESENHAM_DIRECTION 0x38 // byte
170 #define CIRRUS_MMIO_LINEDRAW_MODE 0x39 // byte
171 #define CIRRUS_MMIO_BLTSTATUS 0x40 // byte
173 #define CIRRUS_PNPMMIO_SIZE 0x1000
175 #define BLTUNSAFE(s) \
177 ( /* check dst is within bounds */ \
178 (s)->cirrus_blt_height * ABS((s)->cirrus_blt_dstpitch) \
179 + ((s)->cirrus_blt_dstaddr & (s)->cirrus_addr_mask) > \
182 ( /* check src is within bounds */ \
183 (s)->cirrus_blt_height * ABS((s)->cirrus_blt_srcpitch) \
184 + ((s)->cirrus_blt_srcaddr & (s)->cirrus_addr_mask) > \
189 struct CirrusVGAState
;
190 typedef void (*cirrus_bitblt_rop_t
) (struct CirrusVGAState
*s
,
191 uint8_t * dst
, const uint8_t * src
,
192 int dstpitch
, int srcpitch
,
193 int bltwidth
, int bltheight
);
194 typedef void (*cirrus_fill_t
)(struct CirrusVGAState
*s
,
195 uint8_t *dst
, int dst_pitch
, int width
, int height
);
197 typedef struct CirrusVGAState
{
200 MemoryRegion cirrus_linear_io
;
201 MemoryRegion cirrus_linear_bitblt_io
;
202 MemoryRegion cirrus_mmio_io
;
203 MemoryRegion pci_bar
;
204 bool linear_vram
; /* vga.vram mapped over cirrus_linear_io */
205 MemoryRegion low_mem_container
; /* container for 0xa0000-0xc0000 */
206 MemoryRegion low_mem
; /* always mapped, overridden by: */
207 MemoryRegion cirrus_bank
[2]; /* aliases at 0xa0000-0xb0000 */
208 uint32_t cirrus_addr_mask
;
209 uint32_t linear_mmio_mask
;
210 uint8_t cirrus_shadow_gr0
;
211 uint8_t cirrus_shadow_gr1
;
212 uint8_t cirrus_hidden_dac_lockindex
;
213 uint8_t cirrus_hidden_dac_data
;
214 uint32_t cirrus_bank_base
[2];
215 uint32_t cirrus_bank_limit
[2];
216 uint8_t cirrus_hidden_palette
[48];
217 uint32_t hw_cursor_x
;
218 uint32_t hw_cursor_y
;
219 int cirrus_blt_pixelwidth
;
220 int cirrus_blt_width
;
221 int cirrus_blt_height
;
222 int cirrus_blt_dstpitch
;
223 int cirrus_blt_srcpitch
;
224 uint32_t cirrus_blt_fgcol
;
225 uint32_t cirrus_blt_bgcol
;
226 uint32_t cirrus_blt_dstaddr
;
227 uint32_t cirrus_blt_srcaddr
;
228 uint8_t cirrus_blt_mode
;
229 uint8_t cirrus_blt_modeext
;
230 cirrus_bitblt_rop_t cirrus_rop
;
231 #define CIRRUS_BLTBUFSIZE (2048 * 4) /* one line width */
232 uint8_t cirrus_bltbuf
[CIRRUS_BLTBUFSIZE
];
233 uint8_t *cirrus_srcptr
;
234 uint8_t *cirrus_srcptr_end
;
235 uint32_t cirrus_srccounter
;
236 /* hwcursor display state */
237 int last_hw_cursor_size
;
238 int last_hw_cursor_x
;
239 int last_hw_cursor_y
;
240 int last_hw_cursor_y_start
;
241 int last_hw_cursor_y_end
;
242 int real_vram_size
; /* XXX: suppress that */
247 typedef struct PCICirrusVGAState
{
249 CirrusVGAState cirrus_vga
;
252 typedef struct ISACirrusVGAState
{
254 CirrusVGAState cirrus_vga
;
257 static uint8_t rop_to_index
[256];
259 /***************************************
263 ***************************************/
266 static void cirrus_bitblt_reset(CirrusVGAState
*s
);
267 static void cirrus_update_memory_access(CirrusVGAState
*s
);
269 /***************************************
273 ***************************************/
275 static void cirrus_bitblt_rop_nop(CirrusVGAState
*s
,
276 uint8_t *dst
,const uint8_t *src
,
277 int dstpitch
,int srcpitch
,
278 int bltwidth
,int bltheight
)
282 static void cirrus_bitblt_fill_nop(CirrusVGAState
*s
,
284 int dstpitch
, int bltwidth
,int bltheight
)
289 #define ROP_FN(d, s) 0
290 #include "cirrus_vga_rop.h"
292 #define ROP_NAME src_and_dst
293 #define ROP_FN(d, s) (s) & (d)
294 #include "cirrus_vga_rop.h"
296 #define ROP_NAME src_and_notdst
297 #define ROP_FN(d, s) (s) & (~(d))
298 #include "cirrus_vga_rop.h"
300 #define ROP_NAME notdst
301 #define ROP_FN(d, s) ~(d)
302 #include "cirrus_vga_rop.h"
305 #define ROP_FN(d, s) s
306 #include "cirrus_vga_rop.h"
309 #define ROP_FN(d, s) ~0
310 #include "cirrus_vga_rop.h"
312 #define ROP_NAME notsrc_and_dst
313 #define ROP_FN(d, s) (~(s)) & (d)
314 #include "cirrus_vga_rop.h"
316 #define ROP_NAME src_xor_dst
317 #define ROP_FN(d, s) (s) ^ (d)
318 #include "cirrus_vga_rop.h"
320 #define ROP_NAME src_or_dst
321 #define ROP_FN(d, s) (s) | (d)
322 #include "cirrus_vga_rop.h"
324 #define ROP_NAME notsrc_or_notdst
325 #define ROP_FN(d, s) (~(s)) | (~(d))
326 #include "cirrus_vga_rop.h"
328 #define ROP_NAME src_notxor_dst
329 #define ROP_FN(d, s) ~((s) ^ (d))
330 #include "cirrus_vga_rop.h"
332 #define ROP_NAME src_or_notdst
333 #define ROP_FN(d, s) (s) | (~(d))
334 #include "cirrus_vga_rop.h"
336 #define ROP_NAME notsrc
337 #define ROP_FN(d, s) (~(s))
338 #include "cirrus_vga_rop.h"
340 #define ROP_NAME notsrc_or_dst
341 #define ROP_FN(d, s) (~(s)) | (d)
342 #include "cirrus_vga_rop.h"
344 #define ROP_NAME notsrc_and_notdst
345 #define ROP_FN(d, s) (~(s)) & (~(d))
346 #include "cirrus_vga_rop.h"
348 static const cirrus_bitblt_rop_t cirrus_fwd_rop
[16] = {
349 cirrus_bitblt_rop_fwd_0
,
350 cirrus_bitblt_rop_fwd_src_and_dst
,
351 cirrus_bitblt_rop_nop
,
352 cirrus_bitblt_rop_fwd_src_and_notdst
,
353 cirrus_bitblt_rop_fwd_notdst
,
354 cirrus_bitblt_rop_fwd_src
,
355 cirrus_bitblt_rop_fwd_1
,
356 cirrus_bitblt_rop_fwd_notsrc_and_dst
,
357 cirrus_bitblt_rop_fwd_src_xor_dst
,
358 cirrus_bitblt_rop_fwd_src_or_dst
,
359 cirrus_bitblt_rop_fwd_notsrc_or_notdst
,
360 cirrus_bitblt_rop_fwd_src_notxor_dst
,
361 cirrus_bitblt_rop_fwd_src_or_notdst
,
362 cirrus_bitblt_rop_fwd_notsrc
,
363 cirrus_bitblt_rop_fwd_notsrc_or_dst
,
364 cirrus_bitblt_rop_fwd_notsrc_and_notdst
,
367 static const cirrus_bitblt_rop_t cirrus_bkwd_rop
[16] = {
368 cirrus_bitblt_rop_bkwd_0
,
369 cirrus_bitblt_rop_bkwd_src_and_dst
,
370 cirrus_bitblt_rop_nop
,
371 cirrus_bitblt_rop_bkwd_src_and_notdst
,
372 cirrus_bitblt_rop_bkwd_notdst
,
373 cirrus_bitblt_rop_bkwd_src
,
374 cirrus_bitblt_rop_bkwd_1
,
375 cirrus_bitblt_rop_bkwd_notsrc_and_dst
,
376 cirrus_bitblt_rop_bkwd_src_xor_dst
,
377 cirrus_bitblt_rop_bkwd_src_or_dst
,
378 cirrus_bitblt_rop_bkwd_notsrc_or_notdst
,
379 cirrus_bitblt_rop_bkwd_src_notxor_dst
,
380 cirrus_bitblt_rop_bkwd_src_or_notdst
,
381 cirrus_bitblt_rop_bkwd_notsrc
,
382 cirrus_bitblt_rop_bkwd_notsrc_or_dst
,
383 cirrus_bitblt_rop_bkwd_notsrc_and_notdst
,
386 #define TRANSP_ROP(name) {\
390 #define TRANSP_NOP(func) {\
395 static const cirrus_bitblt_rop_t cirrus_fwd_transp_rop
[16][2] = {
396 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_0
),
397 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_and_dst
),
398 TRANSP_NOP(cirrus_bitblt_rop_nop
),
399 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_and_notdst
),
400 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notdst
),
401 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src
),
402 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_1
),
403 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc_and_dst
),
404 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_xor_dst
),
405 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_or_dst
),
406 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc_or_notdst
),
407 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_notxor_dst
),
408 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_or_notdst
),
409 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc
),
410 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc_or_dst
),
411 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc_and_notdst
),
414 static const cirrus_bitblt_rop_t cirrus_bkwd_transp_rop
[16][2] = {
415 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_0
),
416 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_and_dst
),
417 TRANSP_NOP(cirrus_bitblt_rop_nop
),
418 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_and_notdst
),
419 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notdst
),
420 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src
),
421 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_1
),
422 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc_and_dst
),
423 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_xor_dst
),
424 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_or_dst
),
425 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc_or_notdst
),
426 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_notxor_dst
),
427 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_or_notdst
),
428 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc
),
429 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc_or_dst
),
430 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc_and_notdst
),
433 #define ROP2(name) {\
440 #define ROP_NOP2(func) {\
447 static const cirrus_bitblt_rop_t cirrus_patternfill
[16][4] = {
448 ROP2(cirrus_patternfill_0
),
449 ROP2(cirrus_patternfill_src_and_dst
),
450 ROP_NOP2(cirrus_bitblt_rop_nop
),
451 ROP2(cirrus_patternfill_src_and_notdst
),
452 ROP2(cirrus_patternfill_notdst
),
453 ROP2(cirrus_patternfill_src
),
454 ROP2(cirrus_patternfill_1
),
455 ROP2(cirrus_patternfill_notsrc_and_dst
),
456 ROP2(cirrus_patternfill_src_xor_dst
),
457 ROP2(cirrus_patternfill_src_or_dst
),
458 ROP2(cirrus_patternfill_notsrc_or_notdst
),
459 ROP2(cirrus_patternfill_src_notxor_dst
),
460 ROP2(cirrus_patternfill_src_or_notdst
),
461 ROP2(cirrus_patternfill_notsrc
),
462 ROP2(cirrus_patternfill_notsrc_or_dst
),
463 ROP2(cirrus_patternfill_notsrc_and_notdst
),
466 static const cirrus_bitblt_rop_t cirrus_colorexpand_transp
[16][4] = {
467 ROP2(cirrus_colorexpand_transp_0
),
468 ROP2(cirrus_colorexpand_transp_src_and_dst
),
469 ROP_NOP2(cirrus_bitblt_rop_nop
),
470 ROP2(cirrus_colorexpand_transp_src_and_notdst
),
471 ROP2(cirrus_colorexpand_transp_notdst
),
472 ROP2(cirrus_colorexpand_transp_src
),
473 ROP2(cirrus_colorexpand_transp_1
),
474 ROP2(cirrus_colorexpand_transp_notsrc_and_dst
),
475 ROP2(cirrus_colorexpand_transp_src_xor_dst
),
476 ROP2(cirrus_colorexpand_transp_src_or_dst
),
477 ROP2(cirrus_colorexpand_transp_notsrc_or_notdst
),
478 ROP2(cirrus_colorexpand_transp_src_notxor_dst
),
479 ROP2(cirrus_colorexpand_transp_src_or_notdst
),
480 ROP2(cirrus_colorexpand_transp_notsrc
),
481 ROP2(cirrus_colorexpand_transp_notsrc_or_dst
),
482 ROP2(cirrus_colorexpand_transp_notsrc_and_notdst
),
485 static const cirrus_bitblt_rop_t cirrus_colorexpand
[16][4] = {
486 ROP2(cirrus_colorexpand_0
),
487 ROP2(cirrus_colorexpand_src_and_dst
),
488 ROP_NOP2(cirrus_bitblt_rop_nop
),
489 ROP2(cirrus_colorexpand_src_and_notdst
),
490 ROP2(cirrus_colorexpand_notdst
),
491 ROP2(cirrus_colorexpand_src
),
492 ROP2(cirrus_colorexpand_1
),
493 ROP2(cirrus_colorexpand_notsrc_and_dst
),
494 ROP2(cirrus_colorexpand_src_xor_dst
),
495 ROP2(cirrus_colorexpand_src_or_dst
),
496 ROP2(cirrus_colorexpand_notsrc_or_notdst
),
497 ROP2(cirrus_colorexpand_src_notxor_dst
),
498 ROP2(cirrus_colorexpand_src_or_notdst
),
499 ROP2(cirrus_colorexpand_notsrc
),
500 ROP2(cirrus_colorexpand_notsrc_or_dst
),
501 ROP2(cirrus_colorexpand_notsrc_and_notdst
),
504 static const cirrus_bitblt_rop_t cirrus_colorexpand_pattern_transp
[16][4] = {
505 ROP2(cirrus_colorexpand_pattern_transp_0
),
506 ROP2(cirrus_colorexpand_pattern_transp_src_and_dst
),
507 ROP_NOP2(cirrus_bitblt_rop_nop
),
508 ROP2(cirrus_colorexpand_pattern_transp_src_and_notdst
),
509 ROP2(cirrus_colorexpand_pattern_transp_notdst
),
510 ROP2(cirrus_colorexpand_pattern_transp_src
),
511 ROP2(cirrus_colorexpand_pattern_transp_1
),
512 ROP2(cirrus_colorexpand_pattern_transp_notsrc_and_dst
),
513 ROP2(cirrus_colorexpand_pattern_transp_src_xor_dst
),
514 ROP2(cirrus_colorexpand_pattern_transp_src_or_dst
),
515 ROP2(cirrus_colorexpand_pattern_transp_notsrc_or_notdst
),
516 ROP2(cirrus_colorexpand_pattern_transp_src_notxor_dst
),
517 ROP2(cirrus_colorexpand_pattern_transp_src_or_notdst
),
518 ROP2(cirrus_colorexpand_pattern_transp_notsrc
),
519 ROP2(cirrus_colorexpand_pattern_transp_notsrc_or_dst
),
520 ROP2(cirrus_colorexpand_pattern_transp_notsrc_and_notdst
),
523 static const cirrus_bitblt_rop_t cirrus_colorexpand_pattern
[16][4] = {
524 ROP2(cirrus_colorexpand_pattern_0
),
525 ROP2(cirrus_colorexpand_pattern_src_and_dst
),
526 ROP_NOP2(cirrus_bitblt_rop_nop
),
527 ROP2(cirrus_colorexpand_pattern_src_and_notdst
),
528 ROP2(cirrus_colorexpand_pattern_notdst
),
529 ROP2(cirrus_colorexpand_pattern_src
),
530 ROP2(cirrus_colorexpand_pattern_1
),
531 ROP2(cirrus_colorexpand_pattern_notsrc_and_dst
),
532 ROP2(cirrus_colorexpand_pattern_src_xor_dst
),
533 ROP2(cirrus_colorexpand_pattern_src_or_dst
),
534 ROP2(cirrus_colorexpand_pattern_notsrc_or_notdst
),
535 ROP2(cirrus_colorexpand_pattern_src_notxor_dst
),
536 ROP2(cirrus_colorexpand_pattern_src_or_notdst
),
537 ROP2(cirrus_colorexpand_pattern_notsrc
),
538 ROP2(cirrus_colorexpand_pattern_notsrc_or_dst
),
539 ROP2(cirrus_colorexpand_pattern_notsrc_and_notdst
),
542 static const cirrus_fill_t cirrus_fill
[16][4] = {
544 ROP2(cirrus_fill_src_and_dst
),
545 ROP_NOP2(cirrus_bitblt_fill_nop
),
546 ROP2(cirrus_fill_src_and_notdst
),
547 ROP2(cirrus_fill_notdst
),
548 ROP2(cirrus_fill_src
),
550 ROP2(cirrus_fill_notsrc_and_dst
),
551 ROP2(cirrus_fill_src_xor_dst
),
552 ROP2(cirrus_fill_src_or_dst
),
553 ROP2(cirrus_fill_notsrc_or_notdst
),
554 ROP2(cirrus_fill_src_notxor_dst
),
555 ROP2(cirrus_fill_src_or_notdst
),
556 ROP2(cirrus_fill_notsrc
),
557 ROP2(cirrus_fill_notsrc_or_dst
),
558 ROP2(cirrus_fill_notsrc_and_notdst
),
561 static inline void cirrus_bitblt_fgcol(CirrusVGAState
*s
)
564 switch (s
->cirrus_blt_pixelwidth
) {
566 s
->cirrus_blt_fgcol
= s
->cirrus_shadow_gr1
;
569 color
= s
->cirrus_shadow_gr1
| (s
->vga
.gr
[0x11] << 8);
570 s
->cirrus_blt_fgcol
= le16_to_cpu(color
);
573 s
->cirrus_blt_fgcol
= s
->cirrus_shadow_gr1
|
574 (s
->vga
.gr
[0x11] << 8) | (s
->vga
.gr
[0x13] << 16);
578 color
= s
->cirrus_shadow_gr1
| (s
->vga
.gr
[0x11] << 8) |
579 (s
->vga
.gr
[0x13] << 16) | (s
->vga
.gr
[0x15] << 24);
580 s
->cirrus_blt_fgcol
= le32_to_cpu(color
);
585 static inline void cirrus_bitblt_bgcol(CirrusVGAState
*s
)
588 switch (s
->cirrus_blt_pixelwidth
) {
590 s
->cirrus_blt_bgcol
= s
->cirrus_shadow_gr0
;
593 color
= s
->cirrus_shadow_gr0
| (s
->vga
.gr
[0x10] << 8);
594 s
->cirrus_blt_bgcol
= le16_to_cpu(color
);
597 s
->cirrus_blt_bgcol
= s
->cirrus_shadow_gr0
|
598 (s
->vga
.gr
[0x10] << 8) | (s
->vga
.gr
[0x12] << 16);
602 color
= s
->cirrus_shadow_gr0
| (s
->vga
.gr
[0x10] << 8) |
603 (s
->vga
.gr
[0x12] << 16) | (s
->vga
.gr
[0x14] << 24);
604 s
->cirrus_blt_bgcol
= le32_to_cpu(color
);
609 static void cirrus_invalidate_region(CirrusVGAState
* s
, int off_begin
,
610 int off_pitch
, int bytesperline
,
617 for (y
= 0; y
< lines
; y
++) {
619 off_cur_end
= (off_cur
+ bytesperline
) & s
->cirrus_addr_mask
;
620 memory_region_set_dirty(&s
->vga
.vram
, off_cur
, off_cur_end
- off_cur
);
621 off_begin
+= off_pitch
;
625 static int cirrus_bitblt_common_patterncopy(CirrusVGAState
* s
,
630 dst
= s
->vga
.vram_ptr
+ (s
->cirrus_blt_dstaddr
& s
->cirrus_addr_mask
);
635 (*s
->cirrus_rop
) (s
, dst
, src
,
636 s
->cirrus_blt_dstpitch
, 0,
637 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
638 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
,
639 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_width
,
640 s
->cirrus_blt_height
);
646 static int cirrus_bitblt_solidfill(CirrusVGAState
*s
, int blt_rop
)
648 cirrus_fill_t rop_func
;
652 rop_func
= cirrus_fill
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
653 rop_func(s
, s
->vga
.vram_ptr
+ (s
->cirrus_blt_dstaddr
& s
->cirrus_addr_mask
),
654 s
->cirrus_blt_dstpitch
,
655 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
656 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
,
657 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_width
,
658 s
->cirrus_blt_height
);
659 cirrus_bitblt_reset(s
);
663 /***************************************
665 * bitblt (video-to-video)
667 ***************************************/
669 static int cirrus_bitblt_videotovideo_patterncopy(CirrusVGAState
* s
)
671 return cirrus_bitblt_common_patterncopy(s
,
672 s
->vga
.vram_ptr
+ ((s
->cirrus_blt_srcaddr
& ~7) &
673 s
->cirrus_addr_mask
));
676 static void cirrus_do_copy(CirrusVGAState
*s
, int dst
, int src
, int w
, int h
)
683 /* make sure to only copy if it's a plain copy ROP */
684 if (*s
->cirrus_rop
== cirrus_bitblt_rop_fwd_src
||
685 *s
->cirrus_rop
== cirrus_bitblt_rop_bkwd_src
) {
689 depth
= s
->vga
.get_bpp(&s
->vga
) / 8;
690 s
->vga
.get_resolution(&s
->vga
, &width
, &height
);
693 sx
= (src
% ABS(s
->cirrus_blt_srcpitch
)) / depth
;
694 sy
= (src
/ ABS(s
->cirrus_blt_srcpitch
));
695 dx
= (dst
% ABS(s
->cirrus_blt_dstpitch
)) / depth
;
696 dy
= (dst
/ ABS(s
->cirrus_blt_dstpitch
));
698 /* normalize width */
701 /* if we're doing a backward copy, we have to adjust
702 our x/y to be the upper left corner (instead of the lower
704 if (s
->cirrus_blt_dstpitch
< 0) {
705 sx
-= (s
->cirrus_blt_width
/ depth
) - 1;
706 dx
-= (s
->cirrus_blt_width
/ depth
) - 1;
707 sy
-= s
->cirrus_blt_height
- 1;
708 dy
-= s
->cirrus_blt_height
- 1;
711 /* are we in the visible portion of memory? */
712 if (sx
>= 0 && sy
>= 0 && dx
>= 0 && dy
>= 0 &&
713 (sx
+ w
) <= width
&& (sy
+ h
) <= height
&&
714 (dx
+ w
) <= width
&& (dy
+ h
) <= height
) {
719 /* we have to flush all pending changes so that the copy
720 is generated at the appropriate moment in time */
724 (*s
->cirrus_rop
) (s
, s
->vga
.vram_ptr
+
725 (s
->cirrus_blt_dstaddr
& s
->cirrus_addr_mask
),
727 (s
->cirrus_blt_srcaddr
& s
->cirrus_addr_mask
),
728 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_srcpitch
,
729 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
732 qemu_console_copy(s
->vga
.ds
,
734 s
->cirrus_blt_width
/ depth
,
735 s
->cirrus_blt_height
);
737 /* we don't have to notify the display that this portion has
738 changed since qemu_console_copy implies this */
740 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
,
741 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_width
,
742 s
->cirrus_blt_height
);
745 static int cirrus_bitblt_videotovideo_copy(CirrusVGAState
* s
)
750 cirrus_do_copy(s
, s
->cirrus_blt_dstaddr
- s
->vga
.start_addr
,
751 s
->cirrus_blt_srcaddr
- s
->vga
.start_addr
,
752 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
757 /***************************************
759 * bitblt (cpu-to-video)
761 ***************************************/
763 static void cirrus_bitblt_cputovideo_next(CirrusVGAState
* s
)
768 if (s
->cirrus_srccounter
> 0) {
769 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PATTERNCOPY
) {
770 cirrus_bitblt_common_patterncopy(s
, s
->cirrus_bltbuf
);
772 s
->cirrus_srccounter
= 0;
773 cirrus_bitblt_reset(s
);
775 /* at least one scan line */
777 (*s
->cirrus_rop
)(s
, s
->vga
.vram_ptr
+
778 (s
->cirrus_blt_dstaddr
& s
->cirrus_addr_mask
),
779 s
->cirrus_bltbuf
, 0, 0, s
->cirrus_blt_width
, 1);
780 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
, 0,
781 s
->cirrus_blt_width
, 1);
782 s
->cirrus_blt_dstaddr
+= s
->cirrus_blt_dstpitch
;
783 s
->cirrus_srccounter
-= s
->cirrus_blt_srcpitch
;
784 if (s
->cirrus_srccounter
<= 0)
786 /* more bytes than needed can be transferred because of
787 word alignment, so we keep them for the next line */
788 /* XXX: keep alignment to speed up transfer */
789 end_ptr
= s
->cirrus_bltbuf
+ s
->cirrus_blt_srcpitch
;
790 copy_count
= s
->cirrus_srcptr_end
- end_ptr
;
791 memmove(s
->cirrus_bltbuf
, end_ptr
, copy_count
);
792 s
->cirrus_srcptr
= s
->cirrus_bltbuf
+ copy_count
;
793 s
->cirrus_srcptr_end
= s
->cirrus_bltbuf
+ s
->cirrus_blt_srcpitch
;
794 } while (s
->cirrus_srcptr
>= s
->cirrus_srcptr_end
);
799 /***************************************
803 ***************************************/
805 static void cirrus_bitblt_reset(CirrusVGAState
* s
)
810 ~(CIRRUS_BLT_START
| CIRRUS_BLT_BUSY
| CIRRUS_BLT_FIFOUSED
);
811 need_update
= s
->cirrus_srcptr
!= &s
->cirrus_bltbuf
[0]
812 || s
->cirrus_srcptr_end
!= &s
->cirrus_bltbuf
[0];
813 s
->cirrus_srcptr
= &s
->cirrus_bltbuf
[0];
814 s
->cirrus_srcptr_end
= &s
->cirrus_bltbuf
[0];
815 s
->cirrus_srccounter
= 0;
818 cirrus_update_memory_access(s
);
821 static int cirrus_bitblt_cputovideo(CirrusVGAState
* s
)
825 s
->cirrus_blt_mode
&= ~CIRRUS_BLTMODE_MEMSYSSRC
;
826 s
->cirrus_srcptr
= &s
->cirrus_bltbuf
[0];
827 s
->cirrus_srcptr_end
= &s
->cirrus_bltbuf
[0];
829 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PATTERNCOPY
) {
830 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_COLOREXPAND
) {
831 s
->cirrus_blt_srcpitch
= 8;
833 /* XXX: check for 24 bpp */
834 s
->cirrus_blt_srcpitch
= 8 * 8 * s
->cirrus_blt_pixelwidth
;
836 s
->cirrus_srccounter
= s
->cirrus_blt_srcpitch
;
838 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_COLOREXPAND
) {
839 w
= s
->cirrus_blt_width
/ s
->cirrus_blt_pixelwidth
;
840 if (s
->cirrus_blt_modeext
& CIRRUS_BLTMODEEXT_DWORDGRANULARITY
)
841 s
->cirrus_blt_srcpitch
= ((w
+ 31) >> 5);
843 s
->cirrus_blt_srcpitch
= ((w
+ 7) >> 3);
845 /* always align input size to 32 bits */
846 s
->cirrus_blt_srcpitch
= (s
->cirrus_blt_width
+ 3) & ~3;
848 s
->cirrus_srccounter
= s
->cirrus_blt_srcpitch
* s
->cirrus_blt_height
;
850 s
->cirrus_srcptr
= s
->cirrus_bltbuf
;
851 s
->cirrus_srcptr_end
= s
->cirrus_bltbuf
+ s
->cirrus_blt_srcpitch
;
852 cirrus_update_memory_access(s
);
856 static int cirrus_bitblt_videotocpu(CirrusVGAState
* s
)
860 printf("cirrus: bitblt (video to cpu) is not implemented yet\n");
865 static int cirrus_bitblt_videotovideo(CirrusVGAState
* s
)
869 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PATTERNCOPY
) {
870 ret
= cirrus_bitblt_videotovideo_patterncopy(s
);
872 ret
= cirrus_bitblt_videotovideo_copy(s
);
875 cirrus_bitblt_reset(s
);
879 static void cirrus_bitblt_start(CirrusVGAState
* s
)
883 s
->vga
.gr
[0x31] |= CIRRUS_BLT_BUSY
;
885 s
->cirrus_blt_width
= (s
->vga
.gr
[0x20] | (s
->vga
.gr
[0x21] << 8)) + 1;
886 s
->cirrus_blt_height
= (s
->vga
.gr
[0x22] | (s
->vga
.gr
[0x23] << 8)) + 1;
887 s
->cirrus_blt_dstpitch
= (s
->vga
.gr
[0x24] | (s
->vga
.gr
[0x25] << 8));
888 s
->cirrus_blt_srcpitch
= (s
->vga
.gr
[0x26] | (s
->vga
.gr
[0x27] << 8));
889 s
->cirrus_blt_dstaddr
=
890 (s
->vga
.gr
[0x28] | (s
->vga
.gr
[0x29] << 8) | (s
->vga
.gr
[0x2a] << 16));
891 s
->cirrus_blt_srcaddr
=
892 (s
->vga
.gr
[0x2c] | (s
->vga
.gr
[0x2d] << 8) | (s
->vga
.gr
[0x2e] << 16));
893 s
->cirrus_blt_mode
= s
->vga
.gr
[0x30];
894 s
->cirrus_blt_modeext
= s
->vga
.gr
[0x33];
895 blt_rop
= s
->vga
.gr
[0x32];
898 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",
901 s
->cirrus_blt_modeext
,
903 s
->cirrus_blt_height
,
904 s
->cirrus_blt_dstpitch
,
905 s
->cirrus_blt_srcpitch
,
906 s
->cirrus_blt_dstaddr
,
907 s
->cirrus_blt_srcaddr
,
911 switch (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PIXELWIDTHMASK
) {
912 case CIRRUS_BLTMODE_PIXELWIDTH8
:
913 s
->cirrus_blt_pixelwidth
= 1;
915 case CIRRUS_BLTMODE_PIXELWIDTH16
:
916 s
->cirrus_blt_pixelwidth
= 2;
918 case CIRRUS_BLTMODE_PIXELWIDTH24
:
919 s
->cirrus_blt_pixelwidth
= 3;
921 case CIRRUS_BLTMODE_PIXELWIDTH32
:
922 s
->cirrus_blt_pixelwidth
= 4;
926 printf("cirrus: bitblt - pixel width is unknown\n");
930 s
->cirrus_blt_mode
&= ~CIRRUS_BLTMODE_PIXELWIDTHMASK
;
933 cirrus_blt_mode
& (CIRRUS_BLTMODE_MEMSYSSRC
|
934 CIRRUS_BLTMODE_MEMSYSDEST
))
935 == (CIRRUS_BLTMODE_MEMSYSSRC
| CIRRUS_BLTMODE_MEMSYSDEST
)) {
937 printf("cirrus: bitblt - memory-to-memory copy is requested\n");
942 if ((s
->cirrus_blt_modeext
& CIRRUS_BLTMODEEXT_SOLIDFILL
) &&
943 (s
->cirrus_blt_mode
& (CIRRUS_BLTMODE_MEMSYSDEST
|
944 CIRRUS_BLTMODE_TRANSPARENTCOMP
|
945 CIRRUS_BLTMODE_PATTERNCOPY
|
946 CIRRUS_BLTMODE_COLOREXPAND
)) ==
947 (CIRRUS_BLTMODE_PATTERNCOPY
| CIRRUS_BLTMODE_COLOREXPAND
)) {
948 cirrus_bitblt_fgcol(s
);
949 cirrus_bitblt_solidfill(s
, blt_rop
);
951 if ((s
->cirrus_blt_mode
& (CIRRUS_BLTMODE_COLOREXPAND
|
952 CIRRUS_BLTMODE_PATTERNCOPY
)) ==
953 CIRRUS_BLTMODE_COLOREXPAND
) {
955 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_TRANSPARENTCOMP
) {
956 if (s
->cirrus_blt_modeext
& CIRRUS_BLTMODEEXT_COLOREXPINV
)
957 cirrus_bitblt_bgcol(s
);
959 cirrus_bitblt_fgcol(s
);
960 s
->cirrus_rop
= cirrus_colorexpand_transp
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
962 cirrus_bitblt_fgcol(s
);
963 cirrus_bitblt_bgcol(s
);
964 s
->cirrus_rop
= cirrus_colorexpand
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
966 } else if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PATTERNCOPY
) {
967 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_COLOREXPAND
) {
968 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_TRANSPARENTCOMP
) {
969 if (s
->cirrus_blt_modeext
& CIRRUS_BLTMODEEXT_COLOREXPINV
)
970 cirrus_bitblt_bgcol(s
);
972 cirrus_bitblt_fgcol(s
);
973 s
->cirrus_rop
= cirrus_colorexpand_pattern_transp
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
975 cirrus_bitblt_fgcol(s
);
976 cirrus_bitblt_bgcol(s
);
977 s
->cirrus_rop
= cirrus_colorexpand_pattern
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
980 s
->cirrus_rop
= cirrus_patternfill
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
983 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_TRANSPARENTCOMP
) {
984 if (s
->cirrus_blt_pixelwidth
> 2) {
985 printf("src transparent without colorexpand must be 8bpp or 16bpp\n");
988 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_BACKWARDS
) {
989 s
->cirrus_blt_dstpitch
= -s
->cirrus_blt_dstpitch
;
990 s
->cirrus_blt_srcpitch
= -s
->cirrus_blt_srcpitch
;
991 s
->cirrus_rop
= cirrus_bkwd_transp_rop
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
993 s
->cirrus_rop
= cirrus_fwd_transp_rop
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
996 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_BACKWARDS
) {
997 s
->cirrus_blt_dstpitch
= -s
->cirrus_blt_dstpitch
;
998 s
->cirrus_blt_srcpitch
= -s
->cirrus_blt_srcpitch
;
999 s
->cirrus_rop
= cirrus_bkwd_rop
[rop_to_index
[blt_rop
]];
1001 s
->cirrus_rop
= cirrus_fwd_rop
[rop_to_index
[blt_rop
]];
1005 // setup bitblt engine.
1006 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_MEMSYSSRC
) {
1007 if (!cirrus_bitblt_cputovideo(s
))
1009 } else if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_MEMSYSDEST
) {
1010 if (!cirrus_bitblt_videotocpu(s
))
1013 if (!cirrus_bitblt_videotovideo(s
))
1019 cirrus_bitblt_reset(s
);
1022 static void cirrus_write_bitblt(CirrusVGAState
* s
, unsigned reg_value
)
1026 old_value
= s
->vga
.gr
[0x31];
1027 s
->vga
.gr
[0x31] = reg_value
;
1029 if (((old_value
& CIRRUS_BLT_RESET
) != 0) &&
1030 ((reg_value
& CIRRUS_BLT_RESET
) == 0)) {
1031 cirrus_bitblt_reset(s
);
1032 } else if (((old_value
& CIRRUS_BLT_START
) == 0) &&
1033 ((reg_value
& CIRRUS_BLT_START
) != 0)) {
1034 cirrus_bitblt_start(s
);
1039 /***************************************
1043 ***************************************/
1045 static void cirrus_get_offsets(VGACommonState
*s1
,
1046 uint32_t *pline_offset
,
1047 uint32_t *pstart_addr
,
1048 uint32_t *pline_compare
)
1050 CirrusVGAState
* s
= container_of(s1
, CirrusVGAState
, vga
);
1051 uint32_t start_addr
, line_offset
, line_compare
;
1053 line_offset
= s
->vga
.cr
[0x13]
1054 | ((s
->vga
.cr
[0x1b] & 0x10) << 4);
1056 *pline_offset
= line_offset
;
1058 start_addr
= (s
->vga
.cr
[0x0c] << 8)
1060 | ((s
->vga
.cr
[0x1b] & 0x01) << 16)
1061 | ((s
->vga
.cr
[0x1b] & 0x0c) << 15)
1062 | ((s
->vga
.cr
[0x1d] & 0x80) << 12);
1063 *pstart_addr
= start_addr
;
1065 line_compare
= s
->vga
.cr
[0x18] |
1066 ((s
->vga
.cr
[0x07] & 0x10) << 4) |
1067 ((s
->vga
.cr
[0x09] & 0x40) << 3);
1068 *pline_compare
= line_compare
;
1071 static uint32_t cirrus_get_bpp16_depth(CirrusVGAState
* s
)
1075 switch (s
->cirrus_hidden_dac_data
& 0xf) {
1078 break; /* Sierra HiColor */
1081 break; /* XGA HiColor */
1084 printf("cirrus: invalid DAC value %x in 16bpp\n",
1085 (s
->cirrus_hidden_dac_data
& 0xf));
1093 static int cirrus_get_bpp(VGACommonState
*s1
)
1095 CirrusVGAState
* s
= container_of(s1
, CirrusVGAState
, vga
);
1098 if ((s
->vga
.sr
[0x07] & 0x01) != 0) {
1100 switch (s
->vga
.sr
[0x07] & CIRRUS_SR7_BPP_MASK
) {
1101 case CIRRUS_SR7_BPP_8
:
1104 case CIRRUS_SR7_BPP_16_DOUBLEVCLK
:
1105 ret
= cirrus_get_bpp16_depth(s
);
1107 case CIRRUS_SR7_BPP_24
:
1110 case CIRRUS_SR7_BPP_16
:
1111 ret
= cirrus_get_bpp16_depth(s
);
1113 case CIRRUS_SR7_BPP_32
:
1118 printf("cirrus: unknown bpp - sr7=%x\n", s
->vga
.sr
[0x7]);
1131 static void cirrus_get_resolution(VGACommonState
*s
, int *pwidth
, int *pheight
)
1135 width
= (s
->cr
[0x01] + 1) * 8;
1136 height
= s
->cr
[0x12] |
1137 ((s
->cr
[0x07] & 0x02) << 7) |
1138 ((s
->cr
[0x07] & 0x40) << 3);
1139 height
= (height
+ 1);
1140 /* interlace support */
1141 if (s
->cr
[0x1a] & 0x01)
1142 height
= height
* 2;
1147 /***************************************
1151 ***************************************/
1153 static void cirrus_update_bank_ptr(CirrusVGAState
* s
, unsigned bank_index
)
1158 if ((s
->vga
.gr
[0x0b] & 0x01) != 0) /* dual bank */
1159 offset
= s
->vga
.gr
[0x09 + bank_index
];
1160 else /* single bank */
1161 offset
= s
->vga
.gr
[0x09];
1163 if ((s
->vga
.gr
[0x0b] & 0x20) != 0)
1168 if (s
->real_vram_size
<= offset
)
1171 limit
= s
->real_vram_size
- offset
;
1173 if (((s
->vga
.gr
[0x0b] & 0x01) == 0) && (bank_index
!= 0)) {
1174 if (limit
> 0x8000) {
1183 s
->cirrus_bank_base
[bank_index
] = offset
;
1184 s
->cirrus_bank_limit
[bank_index
] = limit
;
1186 s
->cirrus_bank_base
[bank_index
] = 0;
1187 s
->cirrus_bank_limit
[bank_index
] = 0;
1191 /***************************************
1193 * I/O access between 0x3c4-0x3c5
1195 ***************************************/
1197 static int cirrus_vga_read_sr(CirrusVGAState
* s
)
1199 switch (s
->vga
.sr_index
) {
1200 case 0x00: // Standard VGA
1201 case 0x01: // Standard VGA
1202 case 0x02: // Standard VGA
1203 case 0x03: // Standard VGA
1204 case 0x04: // Standard VGA
1205 return s
->vga
.sr
[s
->vga
.sr_index
];
1206 case 0x06: // Unlock Cirrus extensions
1207 return s
->vga
.sr
[s
->vga
.sr_index
];
1211 case 0x70: // Graphics Cursor X
1215 case 0xf0: // Graphics Cursor X
1216 return s
->vga
.sr
[0x10];
1220 case 0x71: // Graphics Cursor Y
1224 case 0xf1: // Graphics Cursor Y
1225 return s
->vga
.sr
[0x11];
1227 case 0x07: // Extended Sequencer Mode
1228 case 0x08: // EEPROM Control
1229 case 0x09: // Scratch Register 0
1230 case 0x0a: // Scratch Register 1
1231 case 0x0b: // VCLK 0
1232 case 0x0c: // VCLK 1
1233 case 0x0d: // VCLK 2
1234 case 0x0e: // VCLK 3
1235 case 0x0f: // DRAM Control
1236 case 0x12: // Graphics Cursor Attribute
1237 case 0x13: // Graphics Cursor Pattern Address
1238 case 0x14: // Scratch Register 2
1239 case 0x15: // Scratch Register 3
1240 case 0x16: // Performance Tuning Register
1241 case 0x17: // Configuration Readback and Extended Control
1242 case 0x18: // Signature Generator Control
1243 case 0x19: // Signal Generator Result
1244 case 0x1a: // Signal Generator Result
1245 case 0x1b: // VCLK 0 Denominator & Post
1246 case 0x1c: // VCLK 1 Denominator & Post
1247 case 0x1d: // VCLK 2 Denominator & Post
1248 case 0x1e: // VCLK 3 Denominator & Post
1249 case 0x1f: // BIOS Write Enable and MCLK select
1251 printf("cirrus: handled inport sr_index %02x\n", s
->vga
.sr_index
);
1253 return s
->vga
.sr
[s
->vga
.sr_index
];
1256 printf("cirrus: inport sr_index %02x\n", s
->vga
.sr_index
);
1263 static void cirrus_vga_write_sr(CirrusVGAState
* s
, uint32_t val
)
1265 switch (s
->vga
.sr_index
) {
1266 case 0x00: // Standard VGA
1267 case 0x01: // Standard VGA
1268 case 0x02: // Standard VGA
1269 case 0x03: // Standard VGA
1270 case 0x04: // Standard VGA
1271 s
->vga
.sr
[s
->vga
.sr_index
] = val
& sr_mask
[s
->vga
.sr_index
];
1272 if (s
->vga
.sr_index
== 1)
1273 s
->vga
.update_retrace_info(&s
->vga
);
1275 case 0x06: // Unlock Cirrus extensions
1278 s
->vga
.sr
[s
->vga
.sr_index
] = 0x12;
1280 s
->vga
.sr
[s
->vga
.sr_index
] = 0x0f;
1286 case 0x70: // Graphics Cursor X
1290 case 0xf0: // Graphics Cursor X
1291 s
->vga
.sr
[0x10] = val
;
1292 s
->hw_cursor_x
= (val
<< 3) | (s
->vga
.sr_index
>> 5);
1297 case 0x71: // Graphics Cursor Y
1301 case 0xf1: // Graphics Cursor Y
1302 s
->vga
.sr
[0x11] = val
;
1303 s
->hw_cursor_y
= (val
<< 3) | (s
->vga
.sr_index
>> 5);
1305 case 0x07: // Extended Sequencer Mode
1306 cirrus_update_memory_access(s
);
1307 case 0x08: // EEPROM Control
1308 case 0x09: // Scratch Register 0
1309 case 0x0a: // Scratch Register 1
1310 case 0x0b: // VCLK 0
1311 case 0x0c: // VCLK 1
1312 case 0x0d: // VCLK 2
1313 case 0x0e: // VCLK 3
1314 case 0x0f: // DRAM Control
1315 case 0x12: // Graphics Cursor Attribute
1316 case 0x13: // Graphics Cursor Pattern Address
1317 case 0x14: // Scratch Register 2
1318 case 0x15: // Scratch Register 3
1319 case 0x16: // Performance Tuning Register
1320 case 0x18: // Signature Generator Control
1321 case 0x19: // Signature Generator Result
1322 case 0x1a: // Signature Generator Result
1323 case 0x1b: // VCLK 0 Denominator & Post
1324 case 0x1c: // VCLK 1 Denominator & Post
1325 case 0x1d: // VCLK 2 Denominator & Post
1326 case 0x1e: // VCLK 3 Denominator & Post
1327 case 0x1f: // BIOS Write Enable and MCLK select
1328 s
->vga
.sr
[s
->vga
.sr_index
] = val
;
1330 printf("cirrus: handled outport sr_index %02x, sr_value %02x\n",
1331 s
->vga
.sr_index
, val
);
1334 case 0x17: // Configuration Readback and Extended Control
1335 s
->vga
.sr
[s
->vga
.sr_index
] = (s
->vga
.sr
[s
->vga
.sr_index
] & 0x38)
1337 cirrus_update_memory_access(s
);
1341 printf("cirrus: outport sr_index %02x, sr_value %02x\n",
1342 s
->vga
.sr_index
, val
);
1348 /***************************************
1350 * I/O access at 0x3c6
1352 ***************************************/
1354 static int cirrus_read_hidden_dac(CirrusVGAState
* s
)
1356 if (++s
->cirrus_hidden_dac_lockindex
== 5) {
1357 s
->cirrus_hidden_dac_lockindex
= 0;
1358 return s
->cirrus_hidden_dac_data
;
1363 static void cirrus_write_hidden_dac(CirrusVGAState
* s
, int reg_value
)
1365 if (s
->cirrus_hidden_dac_lockindex
== 4) {
1366 s
->cirrus_hidden_dac_data
= reg_value
;
1367 #if defined(DEBUG_CIRRUS)
1368 printf("cirrus: outport hidden DAC, value %02x\n", reg_value
);
1371 s
->cirrus_hidden_dac_lockindex
= 0;
1374 /***************************************
1376 * I/O access at 0x3c9
1378 ***************************************/
1380 static int cirrus_vga_read_palette(CirrusVGAState
* s
)
1384 if ((s
->vga
.sr
[0x12] & CIRRUS_CURSOR_HIDDENPEL
)) {
1385 val
= s
->cirrus_hidden_palette
[(s
->vga
.dac_read_index
& 0x0f) * 3 +
1386 s
->vga
.dac_sub_index
];
1388 val
= s
->vga
.palette
[s
->vga
.dac_read_index
* 3 + s
->vga
.dac_sub_index
];
1390 if (++s
->vga
.dac_sub_index
== 3) {
1391 s
->vga
.dac_sub_index
= 0;
1392 s
->vga
.dac_read_index
++;
1397 static void cirrus_vga_write_palette(CirrusVGAState
* s
, int reg_value
)
1399 s
->vga
.dac_cache
[s
->vga
.dac_sub_index
] = reg_value
;
1400 if (++s
->vga
.dac_sub_index
== 3) {
1401 if ((s
->vga
.sr
[0x12] & CIRRUS_CURSOR_HIDDENPEL
)) {
1402 memcpy(&s
->cirrus_hidden_palette
[(s
->vga
.dac_write_index
& 0x0f) * 3],
1403 s
->vga
.dac_cache
, 3);
1405 memcpy(&s
->vga
.palette
[s
->vga
.dac_write_index
* 3], s
->vga
.dac_cache
, 3);
1407 /* XXX update cursor */
1408 s
->vga
.dac_sub_index
= 0;
1409 s
->vga
.dac_write_index
++;
1413 /***************************************
1415 * I/O access between 0x3ce-0x3cf
1417 ***************************************/
1419 static int cirrus_vga_read_gr(CirrusVGAState
* s
, unsigned reg_index
)
1421 switch (reg_index
) {
1422 case 0x00: // Standard VGA, BGCOLOR 0x000000ff
1423 return s
->cirrus_shadow_gr0
;
1424 case 0x01: // Standard VGA, FGCOLOR 0x000000ff
1425 return s
->cirrus_shadow_gr1
;
1426 case 0x02: // Standard VGA
1427 case 0x03: // Standard VGA
1428 case 0x04: // Standard VGA
1429 case 0x06: // Standard VGA
1430 case 0x07: // Standard VGA
1431 case 0x08: // Standard VGA
1432 return s
->vga
.gr
[s
->vga
.gr_index
];
1433 case 0x05: // Standard VGA, Cirrus extended mode
1438 if (reg_index
< 0x3a) {
1439 return s
->vga
.gr
[reg_index
];
1442 printf("cirrus: inport gr_index %02x\n", reg_index
);
1449 cirrus_vga_write_gr(CirrusVGAState
* s
, unsigned reg_index
, int reg_value
)
1451 #if defined(DEBUG_BITBLT) && 0
1452 printf("gr%02x: %02x\n", reg_index
, reg_value
);
1454 switch (reg_index
) {
1455 case 0x00: // Standard VGA, BGCOLOR 0x000000ff
1456 s
->vga
.gr
[reg_index
] = reg_value
& gr_mask
[reg_index
];
1457 s
->cirrus_shadow_gr0
= reg_value
;
1459 case 0x01: // Standard VGA, FGCOLOR 0x000000ff
1460 s
->vga
.gr
[reg_index
] = reg_value
& gr_mask
[reg_index
];
1461 s
->cirrus_shadow_gr1
= reg_value
;
1463 case 0x02: // Standard VGA
1464 case 0x03: // Standard VGA
1465 case 0x04: // Standard VGA
1466 case 0x06: // Standard VGA
1467 case 0x07: // Standard VGA
1468 case 0x08: // Standard VGA
1469 s
->vga
.gr
[reg_index
] = reg_value
& gr_mask
[reg_index
];
1471 case 0x05: // Standard VGA, Cirrus extended mode
1472 s
->vga
.gr
[reg_index
] = reg_value
& 0x7f;
1473 cirrus_update_memory_access(s
);
1475 case 0x09: // bank offset #0
1476 case 0x0A: // bank offset #1
1477 s
->vga
.gr
[reg_index
] = reg_value
;
1478 cirrus_update_bank_ptr(s
, 0);
1479 cirrus_update_bank_ptr(s
, 1);
1480 cirrus_update_memory_access(s
);
1483 s
->vga
.gr
[reg_index
] = reg_value
;
1484 cirrus_update_bank_ptr(s
, 0);
1485 cirrus_update_bank_ptr(s
, 1);
1486 cirrus_update_memory_access(s
);
1488 case 0x10: // BGCOLOR 0x0000ff00
1489 case 0x11: // FGCOLOR 0x0000ff00
1490 case 0x12: // BGCOLOR 0x00ff0000
1491 case 0x13: // FGCOLOR 0x00ff0000
1492 case 0x14: // BGCOLOR 0xff000000
1493 case 0x15: // FGCOLOR 0xff000000
1494 case 0x20: // BLT WIDTH 0x0000ff
1495 case 0x22: // BLT HEIGHT 0x0000ff
1496 case 0x24: // BLT DEST PITCH 0x0000ff
1497 case 0x26: // BLT SRC PITCH 0x0000ff
1498 case 0x28: // BLT DEST ADDR 0x0000ff
1499 case 0x29: // BLT DEST ADDR 0x00ff00
1500 case 0x2c: // BLT SRC ADDR 0x0000ff
1501 case 0x2d: // BLT SRC ADDR 0x00ff00
1502 case 0x2f: // BLT WRITEMASK
1503 case 0x30: // BLT MODE
1504 case 0x32: // RASTER OP
1505 case 0x33: // BLT MODEEXT
1506 case 0x34: // BLT TRANSPARENT COLOR 0x00ff
1507 case 0x35: // BLT TRANSPARENT COLOR 0xff00
1508 case 0x38: // BLT TRANSPARENT COLOR MASK 0x00ff
1509 case 0x39: // BLT TRANSPARENT COLOR MASK 0xff00
1510 s
->vga
.gr
[reg_index
] = reg_value
;
1512 case 0x21: // BLT WIDTH 0x001f00
1513 case 0x23: // BLT HEIGHT 0x001f00
1514 case 0x25: // BLT DEST PITCH 0x001f00
1515 case 0x27: // BLT SRC PITCH 0x001f00
1516 s
->vga
.gr
[reg_index
] = reg_value
& 0x1f;
1518 case 0x2a: // BLT DEST ADDR 0x3f0000
1519 s
->vga
.gr
[reg_index
] = reg_value
& 0x3f;
1520 /* if auto start mode, starts bit blt now */
1521 if (s
->vga
.gr
[0x31] & CIRRUS_BLT_AUTOSTART
) {
1522 cirrus_bitblt_start(s
);
1525 case 0x2e: // BLT SRC ADDR 0x3f0000
1526 s
->vga
.gr
[reg_index
] = reg_value
& 0x3f;
1528 case 0x31: // BLT STATUS/START
1529 cirrus_write_bitblt(s
, reg_value
);
1533 printf("cirrus: outport gr_index %02x, gr_value %02x\n", reg_index
,
1540 /***************************************
1542 * I/O access between 0x3d4-0x3d5
1544 ***************************************/
1546 static int cirrus_vga_read_cr(CirrusVGAState
* s
, unsigned reg_index
)
1548 switch (reg_index
) {
1549 case 0x00: // Standard VGA
1550 case 0x01: // Standard VGA
1551 case 0x02: // Standard VGA
1552 case 0x03: // Standard VGA
1553 case 0x04: // Standard VGA
1554 case 0x05: // Standard VGA
1555 case 0x06: // Standard VGA
1556 case 0x07: // Standard VGA
1557 case 0x08: // Standard VGA
1558 case 0x09: // Standard VGA
1559 case 0x0a: // Standard VGA
1560 case 0x0b: // Standard VGA
1561 case 0x0c: // Standard VGA
1562 case 0x0d: // Standard VGA
1563 case 0x0e: // Standard VGA
1564 case 0x0f: // Standard VGA
1565 case 0x10: // Standard VGA
1566 case 0x11: // Standard VGA
1567 case 0x12: // Standard VGA
1568 case 0x13: // Standard VGA
1569 case 0x14: // Standard VGA
1570 case 0x15: // Standard VGA
1571 case 0x16: // Standard VGA
1572 case 0x17: // Standard VGA
1573 case 0x18: // Standard VGA
1574 return s
->vga
.cr
[s
->vga
.cr_index
];
1575 case 0x24: // Attribute Controller Toggle Readback (R)
1576 return (s
->vga
.ar_flip_flop
<< 7);
1577 case 0x19: // Interlace End
1578 case 0x1a: // Miscellaneous Control
1579 case 0x1b: // Extended Display Control
1580 case 0x1c: // Sync Adjust and Genlock
1581 case 0x1d: // Overlay Extended Control
1582 case 0x22: // Graphics Data Latches Readback (R)
1583 case 0x25: // Part Status
1584 case 0x27: // Part ID (R)
1585 return s
->vga
.cr
[s
->vga
.cr_index
];
1586 case 0x26: // Attribute Controller Index Readback (R)
1587 return s
->vga
.ar_index
& 0x3f;
1591 printf("cirrus: inport cr_index %02x\n", reg_index
);
1597 static void cirrus_vga_write_cr(CirrusVGAState
* s
, int reg_value
)
1599 switch (s
->vga
.cr_index
) {
1600 case 0x00: // Standard VGA
1601 case 0x01: // Standard VGA
1602 case 0x02: // Standard VGA
1603 case 0x03: // Standard VGA
1604 case 0x04: // Standard VGA
1605 case 0x05: // Standard VGA
1606 case 0x06: // Standard VGA
1607 case 0x07: // Standard VGA
1608 case 0x08: // Standard VGA
1609 case 0x09: // Standard VGA
1610 case 0x0a: // Standard VGA
1611 case 0x0b: // Standard VGA
1612 case 0x0c: // Standard VGA
1613 case 0x0d: // Standard VGA
1614 case 0x0e: // Standard VGA
1615 case 0x0f: // Standard VGA
1616 case 0x10: // Standard VGA
1617 case 0x11: // Standard VGA
1618 case 0x12: // Standard VGA
1619 case 0x13: // Standard VGA
1620 case 0x14: // Standard VGA
1621 case 0x15: // Standard VGA
1622 case 0x16: // Standard VGA
1623 case 0x17: // Standard VGA
1624 case 0x18: // Standard VGA
1625 /* handle CR0-7 protection */
1626 if ((s
->vga
.cr
[0x11] & 0x80) && s
->vga
.cr_index
<= 7) {
1627 /* can always write bit 4 of CR7 */
1628 if (s
->vga
.cr_index
== 7)
1629 s
->vga
.cr
[7] = (s
->vga
.cr
[7] & ~0x10) | (reg_value
& 0x10);
1632 s
->vga
.cr
[s
->vga
.cr_index
] = reg_value
;
1633 switch(s
->vga
.cr_index
) {
1641 s
->vga
.update_retrace_info(&s
->vga
);
1645 case 0x19: // Interlace End
1646 case 0x1a: // Miscellaneous Control
1647 case 0x1b: // Extended Display Control
1648 case 0x1c: // Sync Adjust and Genlock
1649 case 0x1d: // Overlay Extended Control
1650 s
->vga
.cr
[s
->vga
.cr_index
] = reg_value
;
1652 printf("cirrus: handled outport cr_index %02x, cr_value %02x\n",
1653 s
->vga
.cr_index
, reg_value
);
1656 case 0x22: // Graphics Data Latches Readback (R)
1657 case 0x24: // Attribute Controller Toggle Readback (R)
1658 case 0x26: // Attribute Controller Index Readback (R)
1659 case 0x27: // Part ID (R)
1661 case 0x25: // Part Status
1664 printf("cirrus: outport cr_index %02x, cr_value %02x\n",
1665 s
->vga
.cr_index
, reg_value
);
1671 /***************************************
1673 * memory-mapped I/O (bitblt)
1675 ***************************************/
1677 static uint8_t cirrus_mmio_blt_read(CirrusVGAState
* s
, unsigned address
)
1682 case (CIRRUS_MMIO_BLTBGCOLOR
+ 0):
1683 value
= cirrus_vga_read_gr(s
, 0x00);
1685 case (CIRRUS_MMIO_BLTBGCOLOR
+ 1):
1686 value
= cirrus_vga_read_gr(s
, 0x10);
1688 case (CIRRUS_MMIO_BLTBGCOLOR
+ 2):
1689 value
= cirrus_vga_read_gr(s
, 0x12);
1691 case (CIRRUS_MMIO_BLTBGCOLOR
+ 3):
1692 value
= cirrus_vga_read_gr(s
, 0x14);
1694 case (CIRRUS_MMIO_BLTFGCOLOR
+ 0):
1695 value
= cirrus_vga_read_gr(s
, 0x01);
1697 case (CIRRUS_MMIO_BLTFGCOLOR
+ 1):
1698 value
= cirrus_vga_read_gr(s
, 0x11);
1700 case (CIRRUS_MMIO_BLTFGCOLOR
+ 2):
1701 value
= cirrus_vga_read_gr(s
, 0x13);
1703 case (CIRRUS_MMIO_BLTFGCOLOR
+ 3):
1704 value
= cirrus_vga_read_gr(s
, 0x15);
1706 case (CIRRUS_MMIO_BLTWIDTH
+ 0):
1707 value
= cirrus_vga_read_gr(s
, 0x20);
1709 case (CIRRUS_MMIO_BLTWIDTH
+ 1):
1710 value
= cirrus_vga_read_gr(s
, 0x21);
1712 case (CIRRUS_MMIO_BLTHEIGHT
+ 0):
1713 value
= cirrus_vga_read_gr(s
, 0x22);
1715 case (CIRRUS_MMIO_BLTHEIGHT
+ 1):
1716 value
= cirrus_vga_read_gr(s
, 0x23);
1718 case (CIRRUS_MMIO_BLTDESTPITCH
+ 0):
1719 value
= cirrus_vga_read_gr(s
, 0x24);
1721 case (CIRRUS_MMIO_BLTDESTPITCH
+ 1):
1722 value
= cirrus_vga_read_gr(s
, 0x25);
1724 case (CIRRUS_MMIO_BLTSRCPITCH
+ 0):
1725 value
= cirrus_vga_read_gr(s
, 0x26);
1727 case (CIRRUS_MMIO_BLTSRCPITCH
+ 1):
1728 value
= cirrus_vga_read_gr(s
, 0x27);
1730 case (CIRRUS_MMIO_BLTDESTADDR
+ 0):
1731 value
= cirrus_vga_read_gr(s
, 0x28);
1733 case (CIRRUS_MMIO_BLTDESTADDR
+ 1):
1734 value
= cirrus_vga_read_gr(s
, 0x29);
1736 case (CIRRUS_MMIO_BLTDESTADDR
+ 2):
1737 value
= cirrus_vga_read_gr(s
, 0x2a);
1739 case (CIRRUS_MMIO_BLTSRCADDR
+ 0):
1740 value
= cirrus_vga_read_gr(s
, 0x2c);
1742 case (CIRRUS_MMIO_BLTSRCADDR
+ 1):
1743 value
= cirrus_vga_read_gr(s
, 0x2d);
1745 case (CIRRUS_MMIO_BLTSRCADDR
+ 2):
1746 value
= cirrus_vga_read_gr(s
, 0x2e);
1748 case CIRRUS_MMIO_BLTWRITEMASK
:
1749 value
= cirrus_vga_read_gr(s
, 0x2f);
1751 case CIRRUS_MMIO_BLTMODE
:
1752 value
= cirrus_vga_read_gr(s
, 0x30);
1754 case CIRRUS_MMIO_BLTROP
:
1755 value
= cirrus_vga_read_gr(s
, 0x32);
1757 case CIRRUS_MMIO_BLTMODEEXT
:
1758 value
= cirrus_vga_read_gr(s
, 0x33);
1760 case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR
+ 0):
1761 value
= cirrus_vga_read_gr(s
, 0x34);
1763 case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR
+ 1):
1764 value
= cirrus_vga_read_gr(s
, 0x35);
1766 case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK
+ 0):
1767 value
= cirrus_vga_read_gr(s
, 0x38);
1769 case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK
+ 1):
1770 value
= cirrus_vga_read_gr(s
, 0x39);
1772 case CIRRUS_MMIO_BLTSTATUS
:
1773 value
= cirrus_vga_read_gr(s
, 0x31);
1777 printf("cirrus: mmio read - address 0x%04x\n", address
);
1782 return (uint8_t) value
;
1785 static void cirrus_mmio_blt_write(CirrusVGAState
* s
, unsigned address
,
1789 case (CIRRUS_MMIO_BLTBGCOLOR
+ 0):
1790 cirrus_vga_write_gr(s
, 0x00, value
);
1792 case (CIRRUS_MMIO_BLTBGCOLOR
+ 1):
1793 cirrus_vga_write_gr(s
, 0x10, value
);
1795 case (CIRRUS_MMIO_BLTBGCOLOR
+ 2):
1796 cirrus_vga_write_gr(s
, 0x12, value
);
1798 case (CIRRUS_MMIO_BLTBGCOLOR
+ 3):
1799 cirrus_vga_write_gr(s
, 0x14, value
);
1801 case (CIRRUS_MMIO_BLTFGCOLOR
+ 0):
1802 cirrus_vga_write_gr(s
, 0x01, value
);
1804 case (CIRRUS_MMIO_BLTFGCOLOR
+ 1):
1805 cirrus_vga_write_gr(s
, 0x11, value
);
1807 case (CIRRUS_MMIO_BLTFGCOLOR
+ 2):
1808 cirrus_vga_write_gr(s
, 0x13, value
);
1810 case (CIRRUS_MMIO_BLTFGCOLOR
+ 3):
1811 cirrus_vga_write_gr(s
, 0x15, value
);
1813 case (CIRRUS_MMIO_BLTWIDTH
+ 0):
1814 cirrus_vga_write_gr(s
, 0x20, value
);
1816 case (CIRRUS_MMIO_BLTWIDTH
+ 1):
1817 cirrus_vga_write_gr(s
, 0x21, value
);
1819 case (CIRRUS_MMIO_BLTHEIGHT
+ 0):
1820 cirrus_vga_write_gr(s
, 0x22, value
);
1822 case (CIRRUS_MMIO_BLTHEIGHT
+ 1):
1823 cirrus_vga_write_gr(s
, 0x23, value
);
1825 case (CIRRUS_MMIO_BLTDESTPITCH
+ 0):
1826 cirrus_vga_write_gr(s
, 0x24, value
);
1828 case (CIRRUS_MMIO_BLTDESTPITCH
+ 1):
1829 cirrus_vga_write_gr(s
, 0x25, value
);
1831 case (CIRRUS_MMIO_BLTSRCPITCH
+ 0):
1832 cirrus_vga_write_gr(s
, 0x26, value
);
1834 case (CIRRUS_MMIO_BLTSRCPITCH
+ 1):
1835 cirrus_vga_write_gr(s
, 0x27, value
);
1837 case (CIRRUS_MMIO_BLTDESTADDR
+ 0):
1838 cirrus_vga_write_gr(s
, 0x28, value
);
1840 case (CIRRUS_MMIO_BLTDESTADDR
+ 1):
1841 cirrus_vga_write_gr(s
, 0x29, value
);
1843 case (CIRRUS_MMIO_BLTDESTADDR
+ 2):
1844 cirrus_vga_write_gr(s
, 0x2a, value
);
1846 case (CIRRUS_MMIO_BLTDESTADDR
+ 3):
1849 case (CIRRUS_MMIO_BLTSRCADDR
+ 0):
1850 cirrus_vga_write_gr(s
, 0x2c, value
);
1852 case (CIRRUS_MMIO_BLTSRCADDR
+ 1):
1853 cirrus_vga_write_gr(s
, 0x2d, value
);
1855 case (CIRRUS_MMIO_BLTSRCADDR
+ 2):
1856 cirrus_vga_write_gr(s
, 0x2e, value
);
1858 case CIRRUS_MMIO_BLTWRITEMASK
:
1859 cirrus_vga_write_gr(s
, 0x2f, value
);
1861 case CIRRUS_MMIO_BLTMODE
:
1862 cirrus_vga_write_gr(s
, 0x30, value
);
1864 case CIRRUS_MMIO_BLTROP
:
1865 cirrus_vga_write_gr(s
, 0x32, value
);
1867 case CIRRUS_MMIO_BLTMODEEXT
:
1868 cirrus_vga_write_gr(s
, 0x33, value
);
1870 case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR
+ 0):
1871 cirrus_vga_write_gr(s
, 0x34, value
);
1873 case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR
+ 1):
1874 cirrus_vga_write_gr(s
, 0x35, value
);
1876 case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK
+ 0):
1877 cirrus_vga_write_gr(s
, 0x38, value
);
1879 case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK
+ 1):
1880 cirrus_vga_write_gr(s
, 0x39, value
);
1882 case CIRRUS_MMIO_BLTSTATUS
:
1883 cirrus_vga_write_gr(s
, 0x31, value
);
1887 printf("cirrus: mmio write - addr 0x%04x val 0x%02x (ignored)\n",
1894 /***************************************
1898 ***************************************/
1900 static void cirrus_mem_writeb_mode4and5_8bpp(CirrusVGAState
* s
,
1906 unsigned val
= mem_value
;
1909 dst
= s
->vga
.vram_ptr
+ (offset
&= s
->cirrus_addr_mask
);
1910 for (x
= 0; x
< 8; x
++) {
1912 *dst
= s
->cirrus_shadow_gr1
;
1913 } else if (mode
== 5) {
1914 *dst
= s
->cirrus_shadow_gr0
;
1919 memory_region_set_dirty(&s
->vga
.vram
, offset
, 8);
1922 static void cirrus_mem_writeb_mode4and5_16bpp(CirrusVGAState
* s
,
1928 unsigned val
= mem_value
;
1931 dst
= s
->vga
.vram_ptr
+ (offset
&= s
->cirrus_addr_mask
);
1932 for (x
= 0; x
< 8; x
++) {
1934 *dst
= s
->cirrus_shadow_gr1
;
1935 *(dst
+ 1) = s
->vga
.gr
[0x11];
1936 } else if (mode
== 5) {
1937 *dst
= s
->cirrus_shadow_gr0
;
1938 *(dst
+ 1) = s
->vga
.gr
[0x10];
1943 memory_region_set_dirty(&s
->vga
.vram
, offset
, 16);
1946 /***************************************
1948 * memory access between 0xa0000-0xbffff
1950 ***************************************/
1952 static uint64_t cirrus_vga_mem_read(void *opaque
,
1956 CirrusVGAState
*s
= opaque
;
1957 unsigned bank_index
;
1958 unsigned bank_offset
;
1961 if ((s
->vga
.sr
[0x07] & 0x01) == 0) {
1962 return vga_mem_readb(&s
->vga
, addr
);
1965 if (addr
< 0x10000) {
1966 /* XXX handle bitblt */
1968 bank_index
= addr
>> 15;
1969 bank_offset
= addr
& 0x7fff;
1970 if (bank_offset
< s
->cirrus_bank_limit
[bank_index
]) {
1971 bank_offset
+= s
->cirrus_bank_base
[bank_index
];
1972 if ((s
->vga
.gr
[0x0B] & 0x14) == 0x14) {
1974 } else if (s
->vga
.gr
[0x0B] & 0x02) {
1977 bank_offset
&= s
->cirrus_addr_mask
;
1978 val
= *(s
->vga
.vram_ptr
+ bank_offset
);
1981 } else if (addr
>= 0x18000 && addr
< 0x18100) {
1982 /* memory-mapped I/O */
1984 if ((s
->vga
.sr
[0x17] & 0x44) == 0x04) {
1985 val
= cirrus_mmio_blt_read(s
, addr
& 0xff);
1990 printf("cirrus: mem_readb " TARGET_FMT_plx
"\n", addr
);
1996 static void cirrus_vga_mem_write(void *opaque
,
2001 CirrusVGAState
*s
= opaque
;
2002 unsigned bank_index
;
2003 unsigned bank_offset
;
2006 if ((s
->vga
.sr
[0x07] & 0x01) == 0) {
2007 vga_mem_writeb(&s
->vga
, 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
->vga
.gr
[0x0B] & 0x14) == 0x14) {
2026 } else if (s
->vga
.gr
[0x0B] & 0x02) {
2029 bank_offset
&= s
->cirrus_addr_mask
;
2030 mode
= s
->vga
.gr
[0x05] & 0x7;
2031 if (mode
< 4 || mode
> 5 || ((s
->vga
.gr
[0x0B] & 0x4) == 0)) {
2032 *(s
->vga
.vram_ptr
+ bank_offset
) = mem_value
;
2033 memory_region_set_dirty(&s
->vga
.vram
, bank_offset
,
2036 if ((s
->vga
.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
->vga
.sr
[0x17] & 0x44) == 0x04) {
2051 cirrus_mmio_blt_write(s
, addr
& 0xff, mem_value
);
2055 printf("cirrus: mem_writeb " TARGET_FMT_plx
" value %02x\n", addr
,
2061 static const MemoryRegionOps cirrus_vga_mem_ops
= {
2062 .read
= cirrus_vga_mem_read
,
2063 .write
= cirrus_vga_mem_write
,
2064 .endianness
= DEVICE_LITTLE_ENDIAN
,
2066 .min_access_size
= 1,
2067 .max_access_size
= 1,
2071 /***************************************
2075 ***************************************/
2077 static inline void invalidate_cursor1(CirrusVGAState
*s
)
2079 if (s
->last_hw_cursor_size
) {
2080 vga_invalidate_scanlines(&s
->vga
,
2081 s
->last_hw_cursor_y
+ s
->last_hw_cursor_y_start
,
2082 s
->last_hw_cursor_y
+ s
->last_hw_cursor_y_end
);
2086 static inline void cirrus_cursor_compute_yrange(CirrusVGAState
*s
)
2090 int y
, y_min
, y_max
;
2092 src
= s
->vga
.vram_ptr
+ s
->real_vram_size
- 16 * 1024;
2093 if (s
->vga
.sr
[0x12] & CIRRUS_CURSOR_LARGE
) {
2094 src
+= (s
->vga
.sr
[0x13] & 0x3c) * 256;
2097 for(y
= 0; y
< 64; y
++) {
2098 content
= ((uint32_t *)src
)[0] |
2099 ((uint32_t *)src
)[1] |
2100 ((uint32_t *)src
)[2] |
2101 ((uint32_t *)src
)[3];
2111 src
+= (s
->vga
.sr
[0x13] & 0x3f) * 256;
2114 for(y
= 0; y
< 32; y
++) {
2115 content
= ((uint32_t *)src
)[0] |
2116 ((uint32_t *)(src
+ 128))[0];
2126 if (y_min
> y_max
) {
2127 s
->last_hw_cursor_y_start
= 0;
2128 s
->last_hw_cursor_y_end
= 0;
2130 s
->last_hw_cursor_y_start
= y_min
;
2131 s
->last_hw_cursor_y_end
= y_max
+ 1;
2135 /* NOTE: we do not currently handle the cursor bitmap change, so we
2136 update the cursor only if it moves. */
2137 static void cirrus_cursor_invalidate(VGACommonState
*s1
)
2139 CirrusVGAState
*s
= container_of(s1
, CirrusVGAState
, vga
);
2142 if (!(s
->vga
.sr
[0x12] & CIRRUS_CURSOR_SHOW
)) {
2145 if (s
->vga
.sr
[0x12] & CIRRUS_CURSOR_LARGE
)
2150 /* invalidate last cursor and new cursor if any change */
2151 if (s
->last_hw_cursor_size
!= size
||
2152 s
->last_hw_cursor_x
!= s
->hw_cursor_x
||
2153 s
->last_hw_cursor_y
!= s
->hw_cursor_y
) {
2155 invalidate_cursor1(s
);
2157 s
->last_hw_cursor_size
= size
;
2158 s
->last_hw_cursor_x
= s
->hw_cursor_x
;
2159 s
->last_hw_cursor_y
= s
->hw_cursor_y
;
2160 /* compute the real cursor min and max y */
2161 cirrus_cursor_compute_yrange(s
);
2162 invalidate_cursor1(s
);
2167 #include "cirrus_vga_template.h"
2170 #include "cirrus_vga_template.h"
2173 #include "cirrus_vga_template.h"
2175 static void cirrus_cursor_draw_line(VGACommonState
*s1
, uint8_t *d1
, int scr_y
)
2177 CirrusVGAState
*s
= container_of(s1
, CirrusVGAState
, vga
);
2178 int w
, h
, bpp
, x1
, x2
, poffset
;
2179 unsigned int color0
, color1
;
2180 const uint8_t *palette
, *src
;
2183 if (!(s
->vga
.sr
[0x12] & CIRRUS_CURSOR_SHOW
))
2185 /* fast test to see if the cursor intersects with the scan line */
2186 if (s
->vga
.sr
[0x12] & CIRRUS_CURSOR_LARGE
) {
2191 if (scr_y
< s
->hw_cursor_y
||
2192 scr_y
>= (s
->hw_cursor_y
+ h
))
2195 src
= s
->vga
.vram_ptr
+ s
->real_vram_size
- 16 * 1024;
2196 if (s
->vga
.sr
[0x12] & CIRRUS_CURSOR_LARGE
) {
2197 src
+= (s
->vga
.sr
[0x13] & 0x3c) * 256;
2198 src
+= (scr_y
- s
->hw_cursor_y
) * 16;
2200 content
= ((uint32_t *)src
)[0] |
2201 ((uint32_t *)src
)[1] |
2202 ((uint32_t *)src
)[2] |
2203 ((uint32_t *)src
)[3];
2205 src
+= (s
->vga
.sr
[0x13] & 0x3f) * 256;
2206 src
+= (scr_y
- s
->hw_cursor_y
) * 4;
2208 content
= ((uint32_t *)src
)[0] |
2209 ((uint32_t *)(src
+ 128))[0];
2211 /* if nothing to draw, no need to continue */
2216 x1
= s
->hw_cursor_x
;
2217 if (x1
>= s
->vga
.last_scr_width
)
2219 x2
= s
->hw_cursor_x
+ w
;
2220 if (x2
> s
->vga
.last_scr_width
)
2221 x2
= s
->vga
.last_scr_width
;
2223 palette
= s
->cirrus_hidden_palette
;
2224 color0
= s
->vga
.rgb_to_pixel(c6_to_8(palette
[0x0 * 3]),
2225 c6_to_8(palette
[0x0 * 3 + 1]),
2226 c6_to_8(palette
[0x0 * 3 + 2]));
2227 color1
= s
->vga
.rgb_to_pixel(c6_to_8(palette
[0xf * 3]),
2228 c6_to_8(palette
[0xf * 3 + 1]),
2229 c6_to_8(palette
[0xf * 3 + 2]));
2230 bpp
= ((ds_get_bits_per_pixel(s
->vga
.ds
) + 7) >> 3);
2232 switch(ds_get_bits_per_pixel(s
->vga
.ds
)) {
2236 vga_draw_cursor_line_8(d1
, src
, poffset
, w
, color0
, color1
, 0xff);
2239 vga_draw_cursor_line_16(d1
, src
, poffset
, w
, color0
, color1
, 0x7fff);
2242 vga_draw_cursor_line_16(d1
, src
, poffset
, w
, color0
, color1
, 0xffff);
2245 vga_draw_cursor_line_32(d1
, src
, poffset
, w
, color0
, color1
, 0xffffff);
2250 /***************************************
2254 ***************************************/
2256 static uint64_t cirrus_linear_read(void *opaque
, hwaddr addr
,
2259 CirrusVGAState
*s
= opaque
;
2262 addr
&= s
->cirrus_addr_mask
;
2264 if (((s
->vga
.sr
[0x17] & 0x44) == 0x44) &&
2265 ((addr
& s
->linear_mmio_mask
) == s
->linear_mmio_mask
)) {
2266 /* memory-mapped I/O */
2267 ret
= cirrus_mmio_blt_read(s
, addr
& 0xff);
2269 /* XXX handle bitblt */
2273 if ((s
->vga
.gr
[0x0B] & 0x14) == 0x14) {
2275 } else if (s
->vga
.gr
[0x0B] & 0x02) {
2278 addr
&= s
->cirrus_addr_mask
;
2279 ret
= *(s
->vga
.vram_ptr
+ addr
);
2285 static void cirrus_linear_write(void *opaque
, hwaddr addr
,
2286 uint64_t val
, unsigned size
)
2288 CirrusVGAState
*s
= opaque
;
2291 addr
&= s
->cirrus_addr_mask
;
2293 if (((s
->vga
.sr
[0x17] & 0x44) == 0x44) &&
2294 ((addr
& s
->linear_mmio_mask
) == s
->linear_mmio_mask
)) {
2295 /* memory-mapped I/O */
2296 cirrus_mmio_blt_write(s
, addr
& 0xff, val
);
2297 } else if (s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
) {
2299 *s
->cirrus_srcptr
++ = (uint8_t) val
;
2300 if (s
->cirrus_srcptr
>= s
->cirrus_srcptr_end
) {
2301 cirrus_bitblt_cputovideo_next(s
);
2305 if ((s
->vga
.gr
[0x0B] & 0x14) == 0x14) {
2307 } else if (s
->vga
.gr
[0x0B] & 0x02) {
2310 addr
&= s
->cirrus_addr_mask
;
2312 mode
= s
->vga
.gr
[0x05] & 0x7;
2313 if (mode
< 4 || mode
> 5 || ((s
->vga
.gr
[0x0B] & 0x4) == 0)) {
2314 *(s
->vga
.vram_ptr
+ addr
) = (uint8_t) val
;
2315 memory_region_set_dirty(&s
->vga
.vram
, addr
, 1);
2317 if ((s
->vga
.gr
[0x0B] & 0x14) != 0x14) {
2318 cirrus_mem_writeb_mode4and5_8bpp(s
, mode
, addr
, val
);
2320 cirrus_mem_writeb_mode4and5_16bpp(s
, mode
, addr
, val
);
2326 /***************************************
2328 * system to screen memory access
2330 ***************************************/
2333 static uint64_t cirrus_linear_bitblt_read(void *opaque
,
2337 CirrusVGAState
*s
= opaque
;
2340 /* XXX handle bitblt */
2346 static void cirrus_linear_bitblt_write(void *opaque
,
2351 CirrusVGAState
*s
= opaque
;
2353 if (s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
) {
2355 *s
->cirrus_srcptr
++ = (uint8_t) val
;
2356 if (s
->cirrus_srcptr
>= s
->cirrus_srcptr_end
) {
2357 cirrus_bitblt_cputovideo_next(s
);
2362 static const MemoryRegionOps cirrus_linear_bitblt_io_ops
= {
2363 .read
= cirrus_linear_bitblt_read
,
2364 .write
= cirrus_linear_bitblt_write
,
2365 .endianness
= DEVICE_LITTLE_ENDIAN
,
2367 .min_access_size
= 1,
2368 .max_access_size
= 1,
2372 static void map_linear_vram_bank(CirrusVGAState
*s
, unsigned bank
)
2374 MemoryRegion
*mr
= &s
->cirrus_bank
[bank
];
2375 bool enabled
= !(s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
)
2376 && !((s
->vga
.sr
[0x07] & 0x01) == 0)
2377 && !((s
->vga
.gr
[0x0B] & 0x14) == 0x14)
2378 && !(s
->vga
.gr
[0x0B] & 0x02);
2380 memory_region_set_enabled(mr
, enabled
);
2381 memory_region_set_alias_offset(mr
, s
->cirrus_bank_base
[bank
]);
2384 static void map_linear_vram(CirrusVGAState
*s
)
2386 if (s
->bustype
== CIRRUS_BUSTYPE_PCI
&& !s
->linear_vram
) {
2387 s
->linear_vram
= true;
2388 memory_region_add_subregion_overlap(&s
->pci_bar
, 0, &s
->vga
.vram
, 1);
2390 map_linear_vram_bank(s
, 0);
2391 map_linear_vram_bank(s
, 1);
2394 static void unmap_linear_vram(CirrusVGAState
*s
)
2396 if (s
->bustype
== CIRRUS_BUSTYPE_PCI
&& s
->linear_vram
) {
2397 s
->linear_vram
= false;
2398 memory_region_del_subregion(&s
->pci_bar
, &s
->vga
.vram
);
2400 memory_region_set_enabled(&s
->cirrus_bank
[0], false);
2401 memory_region_set_enabled(&s
->cirrus_bank
[1], false);
2404 /* Compute the memory access functions */
2405 static void cirrus_update_memory_access(CirrusVGAState
*s
)
2409 memory_region_transaction_begin();
2410 if ((s
->vga
.sr
[0x17] & 0x44) == 0x44) {
2412 } else if (s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
) {
2415 if ((s
->vga
.gr
[0x0B] & 0x14) == 0x14) {
2417 } else if (s
->vga
.gr
[0x0B] & 0x02) {
2421 mode
= s
->vga
.gr
[0x05] & 0x7;
2422 if (mode
< 4 || mode
> 5 || ((s
->vga
.gr
[0x0B] & 0x4) == 0)) {
2426 unmap_linear_vram(s
);
2429 memory_region_transaction_commit();
2435 static uint32_t cirrus_vga_ioport_read(void *opaque
, uint32_t addr
)
2437 CirrusVGAState
*c
= opaque
;
2438 VGACommonState
*s
= &c
->vga
;
2441 qemu_flush_coalesced_mmio_buffer();
2443 if (vga_ioport_invalid(s
, addr
)) {
2448 if (s
->ar_flip_flop
== 0) {
2455 index
= s
->ar_index
& 0x1f;
2468 val
= cirrus_vga_read_sr(c
);
2470 #ifdef DEBUG_VGA_REG
2471 printf("vga: read SR%x = 0x%02x\n", s
->sr_index
, val
);
2475 val
= cirrus_read_hidden_dac(c
);
2481 val
= s
->dac_write_index
;
2482 c
->cirrus_hidden_dac_lockindex
= 0;
2485 val
= cirrus_vga_read_palette(c
);
2497 val
= cirrus_vga_read_gr(c
, s
->gr_index
);
2498 #ifdef DEBUG_VGA_REG
2499 printf("vga: read GR%x = 0x%02x\n", s
->gr_index
, val
);
2508 val
= cirrus_vga_read_cr(c
, s
->cr_index
);
2509 #ifdef DEBUG_VGA_REG
2510 printf("vga: read CR%x = 0x%02x\n", s
->cr_index
, val
);
2515 /* just toggle to fool polling */
2516 val
= s
->st01
= s
->retrace(s
);
2517 s
->ar_flip_flop
= 0;
2524 #if defined(DEBUG_VGA)
2525 printf("VGA: read addr=0x%04x data=0x%02x\n", addr
, val
);
2530 static void cirrus_vga_ioport_write(void *opaque
, uint32_t addr
, uint32_t val
)
2532 CirrusVGAState
*c
= opaque
;
2533 VGACommonState
*s
= &c
->vga
;
2536 qemu_flush_coalesced_mmio_buffer();
2538 /* check port range access depending on color/monochrome mode */
2539 if (vga_ioport_invalid(s
, addr
)) {
2543 printf("VGA: write addr=0x%04x data=0x%02x\n", addr
, val
);
2548 if (s
->ar_flip_flop
== 0) {
2552 index
= s
->ar_index
& 0x1f;
2555 s
->ar
[index
] = val
& 0x3f;
2558 s
->ar
[index
] = val
& ~0x10;
2564 s
->ar
[index
] = val
& ~0xc0;
2567 s
->ar
[index
] = val
& ~0xf0;
2570 s
->ar
[index
] = val
& ~0xf0;
2576 s
->ar_flip_flop
^= 1;
2579 s
->msr
= val
& ~0x10;
2580 s
->update_retrace_info(s
);
2586 #ifdef DEBUG_VGA_REG
2587 printf("vga: write SR%x = 0x%02x\n", s
->sr_index
, val
);
2589 cirrus_vga_write_sr(c
, val
);
2593 cirrus_write_hidden_dac(c
, val
);
2596 s
->dac_read_index
= val
;
2597 s
->dac_sub_index
= 0;
2601 s
->dac_write_index
= val
;
2602 s
->dac_sub_index
= 0;
2606 cirrus_vga_write_palette(c
, val
);
2612 #ifdef DEBUG_VGA_REG
2613 printf("vga: write GR%x = 0x%02x\n", s
->gr_index
, val
);
2615 cirrus_vga_write_gr(c
, s
->gr_index
, val
);
2623 #ifdef DEBUG_VGA_REG
2624 printf("vga: write CR%x = 0x%02x\n", s
->cr_index
, val
);
2626 cirrus_vga_write_cr(c
, val
);
2630 s
->fcr
= val
& 0x10;
2635 /***************************************
2637 * memory-mapped I/O access
2639 ***************************************/
2641 static uint64_t cirrus_mmio_read(void *opaque
, hwaddr addr
,
2644 CirrusVGAState
*s
= opaque
;
2646 if (addr
>= 0x100) {
2647 return cirrus_mmio_blt_read(s
, addr
- 0x100);
2649 return cirrus_vga_ioport_read(s
, addr
+ 0x3c0);
2653 static void cirrus_mmio_write(void *opaque
, hwaddr addr
,
2654 uint64_t val
, unsigned size
)
2656 CirrusVGAState
*s
= opaque
;
2658 if (addr
>= 0x100) {
2659 cirrus_mmio_blt_write(s
, addr
- 0x100, val
);
2661 cirrus_vga_ioport_write(s
, addr
+ 0x3c0, val
);
2665 static const MemoryRegionOps cirrus_mmio_io_ops
= {
2666 .read
= cirrus_mmio_read
,
2667 .write
= cirrus_mmio_write
,
2668 .endianness
= DEVICE_LITTLE_ENDIAN
,
2670 .min_access_size
= 1,
2671 .max_access_size
= 1,
2675 /* load/save state */
2677 static int cirrus_post_load(void *opaque
, int version_id
)
2679 CirrusVGAState
*s
= opaque
;
2681 s
->vga
.gr
[0x00] = s
->cirrus_shadow_gr0
& 0x0f;
2682 s
->vga
.gr
[0x01] = s
->cirrus_shadow_gr1
& 0x0f;
2684 cirrus_update_memory_access(s
);
2686 s
->vga
.graphic_mode
= -1;
2687 cirrus_update_bank_ptr(s
, 0);
2688 cirrus_update_bank_ptr(s
, 1);
2692 static const VMStateDescription vmstate_cirrus_vga
= {
2693 .name
= "cirrus_vga",
2695 .minimum_version_id
= 1,
2696 .minimum_version_id_old
= 1,
2697 .post_load
= cirrus_post_load
,
2698 .fields
= (VMStateField
[]) {
2699 VMSTATE_UINT32(vga
.latch
, CirrusVGAState
),
2700 VMSTATE_UINT8(vga
.sr_index
, CirrusVGAState
),
2701 VMSTATE_BUFFER(vga
.sr
, CirrusVGAState
),
2702 VMSTATE_UINT8(vga
.gr_index
, CirrusVGAState
),
2703 VMSTATE_UINT8(cirrus_shadow_gr0
, CirrusVGAState
),
2704 VMSTATE_UINT8(cirrus_shadow_gr1
, CirrusVGAState
),
2705 VMSTATE_BUFFER_START_MIDDLE(vga
.gr
, CirrusVGAState
, 2),
2706 VMSTATE_UINT8(vga
.ar_index
, CirrusVGAState
),
2707 VMSTATE_BUFFER(vga
.ar
, CirrusVGAState
),
2708 VMSTATE_INT32(vga
.ar_flip_flop
, CirrusVGAState
),
2709 VMSTATE_UINT8(vga
.cr_index
, CirrusVGAState
),
2710 VMSTATE_BUFFER(vga
.cr
, CirrusVGAState
),
2711 VMSTATE_UINT8(vga
.msr
, CirrusVGAState
),
2712 VMSTATE_UINT8(vga
.fcr
, CirrusVGAState
),
2713 VMSTATE_UINT8(vga
.st00
, CirrusVGAState
),
2714 VMSTATE_UINT8(vga
.st01
, CirrusVGAState
),
2715 VMSTATE_UINT8(vga
.dac_state
, CirrusVGAState
),
2716 VMSTATE_UINT8(vga
.dac_sub_index
, CirrusVGAState
),
2717 VMSTATE_UINT8(vga
.dac_read_index
, CirrusVGAState
),
2718 VMSTATE_UINT8(vga
.dac_write_index
, CirrusVGAState
),
2719 VMSTATE_BUFFER(vga
.dac_cache
, CirrusVGAState
),
2720 VMSTATE_BUFFER(vga
.palette
, CirrusVGAState
),
2721 VMSTATE_INT32(vga
.bank_offset
, CirrusVGAState
),
2722 VMSTATE_UINT8(cirrus_hidden_dac_lockindex
, CirrusVGAState
),
2723 VMSTATE_UINT8(cirrus_hidden_dac_data
, CirrusVGAState
),
2724 VMSTATE_UINT32(hw_cursor_x
, CirrusVGAState
),
2725 VMSTATE_UINT32(hw_cursor_y
, CirrusVGAState
),
2726 /* XXX: we do not save the bitblt state - we assume we do not save
2727 the state when the blitter is active */
2728 VMSTATE_END_OF_LIST()
2732 static const VMStateDescription vmstate_pci_cirrus_vga
= {
2733 .name
= "cirrus_vga",
2735 .minimum_version_id
= 2,
2736 .minimum_version_id_old
= 2,
2737 .fields
= (VMStateField
[]) {
2738 VMSTATE_PCI_DEVICE(dev
, PCICirrusVGAState
),
2739 VMSTATE_STRUCT(cirrus_vga
, PCICirrusVGAState
, 0,
2740 vmstate_cirrus_vga
, CirrusVGAState
),
2741 VMSTATE_END_OF_LIST()
2745 /***************************************
2749 ***************************************/
2751 static void cirrus_reset(void *opaque
)
2753 CirrusVGAState
*s
= opaque
;
2755 vga_common_reset(&s
->vga
);
2756 unmap_linear_vram(s
);
2757 s
->vga
.sr
[0x06] = 0x0f;
2758 if (s
->device_id
== CIRRUS_ID_CLGD5446
) {
2759 /* 4MB 64 bit memory config, always PCI */
2760 s
->vga
.sr
[0x1F] = 0x2d; // MemClock
2761 s
->vga
.gr
[0x18] = 0x0f; // fastest memory configuration
2762 s
->vga
.sr
[0x0f] = 0x98;
2763 s
->vga
.sr
[0x17] = 0x20;
2764 s
->vga
.sr
[0x15] = 0x04; /* memory size, 3=2MB, 4=4MB */
2766 s
->vga
.sr
[0x1F] = 0x22; // MemClock
2767 s
->vga
.sr
[0x0F] = CIRRUS_MEMSIZE_2M
;
2768 s
->vga
.sr
[0x17] = s
->bustype
;
2769 s
->vga
.sr
[0x15] = 0x03; /* memory size, 3=2MB, 4=4MB */
2771 s
->vga
.cr
[0x27] = s
->device_id
;
2773 s
->cirrus_hidden_dac_lockindex
= 5;
2774 s
->cirrus_hidden_dac_data
= 0;
2777 static const MemoryRegionOps cirrus_linear_io_ops
= {
2778 .read
= cirrus_linear_read
,
2779 .write
= cirrus_linear_write
,
2780 .endianness
= DEVICE_LITTLE_ENDIAN
,
2782 .min_access_size
= 1,
2783 .max_access_size
= 1,
2787 static void cirrus_init_common(CirrusVGAState
* s
, int device_id
, int is_pci
,
2788 MemoryRegion
*system_memory
)
2795 for(i
= 0;i
< 256; i
++)
2796 rop_to_index
[i
] = CIRRUS_ROP_NOP_INDEX
; /* nop rop */
2797 rop_to_index
[CIRRUS_ROP_0
] = 0;
2798 rop_to_index
[CIRRUS_ROP_SRC_AND_DST
] = 1;
2799 rop_to_index
[CIRRUS_ROP_NOP
] = 2;
2800 rop_to_index
[CIRRUS_ROP_SRC_AND_NOTDST
] = 3;
2801 rop_to_index
[CIRRUS_ROP_NOTDST
] = 4;
2802 rop_to_index
[CIRRUS_ROP_SRC
] = 5;
2803 rop_to_index
[CIRRUS_ROP_1
] = 6;
2804 rop_to_index
[CIRRUS_ROP_NOTSRC_AND_DST
] = 7;
2805 rop_to_index
[CIRRUS_ROP_SRC_XOR_DST
] = 8;
2806 rop_to_index
[CIRRUS_ROP_SRC_OR_DST
] = 9;
2807 rop_to_index
[CIRRUS_ROP_NOTSRC_OR_NOTDST
] = 10;
2808 rop_to_index
[CIRRUS_ROP_SRC_NOTXOR_DST
] = 11;
2809 rop_to_index
[CIRRUS_ROP_SRC_OR_NOTDST
] = 12;
2810 rop_to_index
[CIRRUS_ROP_NOTSRC
] = 13;
2811 rop_to_index
[CIRRUS_ROP_NOTSRC_OR_DST
] = 14;
2812 rop_to_index
[CIRRUS_ROP_NOTSRC_AND_NOTDST
] = 15;
2813 s
->device_id
= device_id
;
2815 s
->bustype
= CIRRUS_BUSTYPE_PCI
;
2817 s
->bustype
= CIRRUS_BUSTYPE_ISA
;
2820 register_ioport_write(0x3c0, 16, 1, cirrus_vga_ioport_write
, s
);
2822 register_ioport_write(0x3b4, 2, 1, cirrus_vga_ioport_write
, s
);
2823 register_ioport_write(0x3d4, 2, 1, cirrus_vga_ioport_write
, s
);
2824 register_ioport_write(0x3ba, 1, 1, cirrus_vga_ioport_write
, s
);
2825 register_ioport_write(0x3da, 1, 1, cirrus_vga_ioport_write
, s
);
2827 register_ioport_read(0x3c0, 16, 1, cirrus_vga_ioport_read
, s
);
2829 register_ioport_read(0x3b4, 2, 1, cirrus_vga_ioport_read
, s
);
2830 register_ioport_read(0x3d4, 2, 1, cirrus_vga_ioport_read
, s
);
2831 register_ioport_read(0x3ba, 1, 1, cirrus_vga_ioport_read
, s
);
2832 register_ioport_read(0x3da, 1, 1, cirrus_vga_ioport_read
, s
);
2834 memory_region_init(&s
->low_mem_container
,
2835 "cirrus-lowmem-container",
2838 memory_region_init_io(&s
->low_mem
, &cirrus_vga_mem_ops
, s
,
2839 "cirrus-low-memory", 0x20000);
2840 memory_region_add_subregion(&s
->low_mem_container
, 0, &s
->low_mem
);
2841 for (i
= 0; i
< 2; ++i
) {
2842 static const char *names
[] = { "vga.bank0", "vga.bank1" };
2843 MemoryRegion
*bank
= &s
->cirrus_bank
[i
];
2844 memory_region_init_alias(bank
, names
[i
], &s
->vga
.vram
, 0, 0x8000);
2845 memory_region_set_enabled(bank
, false);
2846 memory_region_add_subregion_overlap(&s
->low_mem_container
, i
* 0x8000,
2849 memory_region_add_subregion_overlap(system_memory
,
2850 isa_mem_base
+ 0x000a0000,
2851 &s
->low_mem_container
,
2853 memory_region_set_coalescing(&s
->low_mem
);
2855 /* I/O handler for LFB */
2856 memory_region_init_io(&s
->cirrus_linear_io
, &cirrus_linear_io_ops
, s
,
2857 "cirrus-linear-io", s
->vga
.vram_size_mb
2859 memory_region_set_flush_coalesced(&s
->cirrus_linear_io
);
2861 /* I/O handler for LFB */
2862 memory_region_init_io(&s
->cirrus_linear_bitblt_io
,
2863 &cirrus_linear_bitblt_io_ops
,
2865 "cirrus-bitblt-mmio",
2867 memory_region_set_flush_coalesced(&s
->cirrus_linear_bitblt_io
);
2869 /* I/O handler for memory-mapped I/O */
2870 memory_region_init_io(&s
->cirrus_mmio_io
, &cirrus_mmio_io_ops
, s
,
2871 "cirrus-mmio", CIRRUS_PNPMMIO_SIZE
);
2872 memory_region_set_flush_coalesced(&s
->cirrus_mmio_io
);
2875 (s
->device_id
== CIRRUS_ID_CLGD5446
) ? 4096 * 1024 : 2048 * 1024;
2877 /* XXX: s->vga.vram_size must be a power of two */
2878 s
->cirrus_addr_mask
= s
->real_vram_size
- 1;
2879 s
->linear_mmio_mask
= s
->real_vram_size
- 256;
2881 s
->vga
.get_bpp
= cirrus_get_bpp
;
2882 s
->vga
.get_offsets
= cirrus_get_offsets
;
2883 s
->vga
.get_resolution
= cirrus_get_resolution
;
2884 s
->vga
.cursor_invalidate
= cirrus_cursor_invalidate
;
2885 s
->vga
.cursor_draw_line
= cirrus_cursor_draw_line
;
2887 qemu_register_reset(cirrus_reset
, s
);
2890 /***************************************
2894 ***************************************/
2896 static int vga_initfn(ISADevice
*dev
)
2898 ISACirrusVGAState
*d
= DO_UPCAST(ISACirrusVGAState
, dev
, dev
);
2899 VGACommonState
*s
= &d
->cirrus_vga
.vga
;
2902 cirrus_init_common(&d
->cirrus_vga
, CIRRUS_ID_CLGD5430
, 0,
2903 isa_address_space(dev
));
2904 s
->ds
= graphic_console_init(s
->update
, s
->invalidate
,
2905 s
->screen_dump
, s
->text_update
,
2907 rom_add_vga(VGABIOS_CIRRUS_FILENAME
);
2908 /* XXX ISA-LFB support */
2909 /* FIXME not qdev yet */
2913 static Property isa_vga_cirrus_properties
[] = {
2914 DEFINE_PROP_UINT32("vgamem_mb", struct ISACirrusVGAState
,
2915 cirrus_vga
.vga
.vram_size_mb
, 8),
2916 DEFINE_PROP_END_OF_LIST(),
2919 static void isa_cirrus_vga_class_init(ObjectClass
*klass
, void *data
)
2921 ISADeviceClass
*k
= ISA_DEVICE_CLASS(klass
);
2922 DeviceClass
*dc
= DEVICE_CLASS(klass
);
2924 dc
->vmsd
= &vmstate_cirrus_vga
;
2925 k
->init
= vga_initfn
;
2926 dc
->props
= isa_vga_cirrus_properties
;
2929 static TypeInfo isa_cirrus_vga_info
= {
2930 .name
= "isa-cirrus-vga",
2931 .parent
= TYPE_ISA_DEVICE
,
2932 .instance_size
= sizeof(ISACirrusVGAState
),
2933 .class_init
= isa_cirrus_vga_class_init
,
2936 /***************************************
2940 ***************************************/
2942 static int pci_cirrus_vga_initfn(PCIDevice
*dev
)
2944 PCICirrusVGAState
*d
= DO_UPCAST(PCICirrusVGAState
, dev
, dev
);
2945 CirrusVGAState
*s
= &d
->cirrus_vga
;
2946 PCIDeviceClass
*pc
= PCI_DEVICE_GET_CLASS(dev
);
2947 int16_t device_id
= pc
->device_id
;
2950 vga_common_init(&s
->vga
);
2951 cirrus_init_common(s
, device_id
, 1, pci_address_space(dev
));
2952 s
->vga
.ds
= graphic_console_init(s
->vga
.update
, s
->vga
.invalidate
,
2953 s
->vga
.screen_dump
, s
->vga
.text_update
,
2958 memory_region_init(&s
->pci_bar
, "cirrus-pci-bar0", 0x2000000);
2960 /* XXX: add byte swapping apertures */
2961 memory_region_add_subregion(&s
->pci_bar
, 0, &s
->cirrus_linear_io
);
2962 memory_region_add_subregion(&s
->pci_bar
, 0x1000000,
2963 &s
->cirrus_linear_bitblt_io
);
2965 /* setup memory space */
2967 /* memory #1 memory-mapped I/O */
2968 /* XXX: s->vga.vram_size must be a power of two */
2969 pci_register_bar(&d
->dev
, 0, PCI_BASE_ADDRESS_MEM_PREFETCH
, &s
->pci_bar
);
2970 if (device_id
== CIRRUS_ID_CLGD5446
) {
2971 pci_register_bar(&d
->dev
, 1, 0, &s
->cirrus_mmio_io
);
2976 static Property pci_vga_cirrus_properties
[] = {
2977 DEFINE_PROP_UINT32("vgamem_mb", struct PCICirrusVGAState
,
2978 cirrus_vga
.vga
.vram_size_mb
, 8),
2979 DEFINE_PROP_END_OF_LIST(),
2982 static void cirrus_vga_class_init(ObjectClass
*klass
, void *data
)
2984 DeviceClass
*dc
= DEVICE_CLASS(klass
);
2985 PCIDeviceClass
*k
= PCI_DEVICE_CLASS(klass
);
2988 k
->init
= pci_cirrus_vga_initfn
;
2989 k
->romfile
= VGABIOS_CIRRUS_FILENAME
;
2990 k
->vendor_id
= PCI_VENDOR_ID_CIRRUS
;
2991 k
->device_id
= CIRRUS_ID_CLGD5446
;
2992 k
->class_id
= PCI_CLASS_DISPLAY_VGA
;
2993 dc
->desc
= "Cirrus CLGD 54xx VGA";
2994 dc
->vmsd
= &vmstate_pci_cirrus_vga
;
2995 dc
->props
= pci_vga_cirrus_properties
;
2998 static TypeInfo cirrus_vga_info
= {
2999 .name
= "cirrus-vga",
3000 .parent
= TYPE_PCI_DEVICE
,
3001 .instance_size
= sizeof(PCICirrusVGAState
),
3002 .class_init
= cirrus_vga_class_init
,
3005 static void cirrus_vga_register_types(void)
3007 type_register_static(&isa_cirrus_vga_info
);
3008 type_register_static(&cirrus_vga_info
);
3011 type_init(cirrus_vga_register_types
)