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/
38 * - destination write mask support not complete (bits 5..7)
39 * - optimize linear mappings
40 * - optimize bitblt functions
43 //#define DEBUG_CIRRUS
44 //#define DEBUG_BITBLT
46 /***************************************
50 ***************************************/
53 #define CIRRUS_ID_CLGD5422 (0x23<<2)
54 #define CIRRUS_ID_CLGD5426 (0x24<<2)
55 #define CIRRUS_ID_CLGD5424 (0x25<<2)
56 #define CIRRUS_ID_CLGD5428 (0x26<<2)
57 #define CIRRUS_ID_CLGD5430 (0x28<<2)
58 #define CIRRUS_ID_CLGD5434 (0x2A<<2)
59 #define CIRRUS_ID_CLGD5436 (0x2B<<2)
60 #define CIRRUS_ID_CLGD5446 (0x2E<<2)
63 #define CIRRUS_SR7_BPP_VGA 0x00
64 #define CIRRUS_SR7_BPP_SVGA 0x01
65 #define CIRRUS_SR7_BPP_MASK 0x0e
66 #define CIRRUS_SR7_BPP_8 0x00
67 #define CIRRUS_SR7_BPP_16_DOUBLEVCLK 0x02
68 #define CIRRUS_SR7_BPP_24 0x04
69 #define CIRRUS_SR7_BPP_16 0x06
70 #define CIRRUS_SR7_BPP_32 0x08
71 #define CIRRUS_SR7_ISAADDR_MASK 0xe0
74 #define CIRRUS_MEMSIZE_512k 0x08
75 #define CIRRUS_MEMSIZE_1M 0x10
76 #define CIRRUS_MEMSIZE_2M 0x18
77 #define CIRRUS_MEMFLAGS_BANKSWITCH 0x80 // bank switching is enabled.
80 #define CIRRUS_CURSOR_SHOW 0x01
81 #define CIRRUS_CURSOR_HIDDENPEL 0x02
82 #define CIRRUS_CURSOR_LARGE 0x04 // 64x64 if set, 32x32 if clear
85 #define CIRRUS_BUSTYPE_VLBFAST 0x10
86 #define CIRRUS_BUSTYPE_PCI 0x20
87 #define CIRRUS_BUSTYPE_VLBSLOW 0x30
88 #define CIRRUS_BUSTYPE_ISA 0x38
89 #define CIRRUS_MMIO_ENABLE 0x04
90 #define CIRRUS_MMIO_USE_PCIADDR 0x40 // 0xb8000 if cleared.
91 #define CIRRUS_MEMSIZEEXT_DOUBLE 0x80
94 #define CIRRUS_BANKING_DUAL 0x01
95 #define CIRRUS_BANKING_GRANULARITY_16K 0x20 // set:16k, clear:4k
98 #define CIRRUS_BLTMODE_BACKWARDS 0x01
99 #define CIRRUS_BLTMODE_MEMSYSDEST 0x02
100 #define CIRRUS_BLTMODE_MEMSYSSRC 0x04
101 #define CIRRUS_BLTMODE_TRANSPARENTCOMP 0x08
102 #define CIRRUS_BLTMODE_PATTERNCOPY 0x40
103 #define CIRRUS_BLTMODE_COLOREXPAND 0x80
104 #define CIRRUS_BLTMODE_PIXELWIDTHMASK 0x30
105 #define CIRRUS_BLTMODE_PIXELWIDTH8 0x00
106 #define CIRRUS_BLTMODE_PIXELWIDTH16 0x10
107 #define CIRRUS_BLTMODE_PIXELWIDTH24 0x20
108 #define CIRRUS_BLTMODE_PIXELWIDTH32 0x30
111 #define CIRRUS_BLT_BUSY 0x01
112 #define CIRRUS_BLT_START 0x02
113 #define CIRRUS_BLT_RESET 0x04
114 #define CIRRUS_BLT_FIFOUSED 0x10
115 #define CIRRUS_BLT_AUTOSTART 0x80
118 #define CIRRUS_ROP_0 0x00
119 #define CIRRUS_ROP_SRC_AND_DST 0x05
120 #define CIRRUS_ROP_NOP 0x06
121 #define CIRRUS_ROP_SRC_AND_NOTDST 0x09
122 #define CIRRUS_ROP_NOTDST 0x0b
123 #define CIRRUS_ROP_SRC 0x0d
124 #define CIRRUS_ROP_1 0x0e
125 #define CIRRUS_ROP_NOTSRC_AND_DST 0x50
126 #define CIRRUS_ROP_SRC_XOR_DST 0x59
127 #define CIRRUS_ROP_SRC_OR_DST 0x6d
128 #define CIRRUS_ROP_NOTSRC_OR_NOTDST 0x90
129 #define CIRRUS_ROP_SRC_NOTXOR_DST 0x95
130 #define CIRRUS_ROP_SRC_OR_NOTDST 0xad
131 #define CIRRUS_ROP_NOTSRC 0xd0
132 #define CIRRUS_ROP_NOTSRC_OR_DST 0xd6
133 #define CIRRUS_ROP_NOTSRC_AND_NOTDST 0xda
135 #define CIRRUS_ROP_NOP_INDEX 2
136 #define CIRRUS_ROP_SRC_INDEX 5
139 #define CIRRUS_BLTMODEEXT_SOLIDFILL 0x04
140 #define CIRRUS_BLTMODEEXT_COLOREXPINV 0x02
141 #define CIRRUS_BLTMODEEXT_DWORDGRANULARITY 0x01
144 #define CIRRUS_MMIO_BLTBGCOLOR 0x00 // dword
145 #define CIRRUS_MMIO_BLTFGCOLOR 0x04 // dword
146 #define CIRRUS_MMIO_BLTWIDTH 0x08 // word
147 #define CIRRUS_MMIO_BLTHEIGHT 0x0a // word
148 #define CIRRUS_MMIO_BLTDESTPITCH 0x0c // word
149 #define CIRRUS_MMIO_BLTSRCPITCH 0x0e // word
150 #define CIRRUS_MMIO_BLTDESTADDR 0x10 // dword
151 #define CIRRUS_MMIO_BLTSRCADDR 0x14 // dword
152 #define CIRRUS_MMIO_BLTWRITEMASK 0x17 // byte
153 #define CIRRUS_MMIO_BLTMODE 0x18 // byte
154 #define CIRRUS_MMIO_BLTROP 0x1a // byte
155 #define CIRRUS_MMIO_BLTMODEEXT 0x1b // byte
156 #define CIRRUS_MMIO_BLTTRANSPARENTCOLOR 0x1c // word?
157 #define CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK 0x20 // word?
158 #define CIRRUS_MMIO_LINEARDRAW_START_X 0x24 // word
159 #define CIRRUS_MMIO_LINEARDRAW_START_Y 0x26 // word
160 #define CIRRUS_MMIO_LINEARDRAW_END_X 0x28 // word
161 #define CIRRUS_MMIO_LINEARDRAW_END_Y 0x2a // word
162 #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_INC 0x2c // byte
163 #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_ROLLOVER 0x2d // byte
164 #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_MASK 0x2e // byte
165 #define CIRRUS_MMIO_LINEARDRAW_LINESTYLE_ACCUM 0x2f // byte
166 #define CIRRUS_MMIO_BRESENHAM_K1 0x30 // word
167 #define CIRRUS_MMIO_BRESENHAM_K3 0x32 // word
168 #define CIRRUS_MMIO_BRESENHAM_ERROR 0x34 // word
169 #define CIRRUS_MMIO_BRESENHAM_DELTA_MAJOR 0x36 // word
170 #define CIRRUS_MMIO_BRESENHAM_DIRECTION 0x38 // byte
171 #define CIRRUS_MMIO_LINEDRAW_MODE 0x39 // byte
172 #define CIRRUS_MMIO_BLTSTATUS 0x40 // byte
174 // PCI 0x04: command(word), 0x06(word): status
175 #define PCI_COMMAND_IOACCESS 0x0001
176 #define PCI_COMMAND_MEMACCESS 0x0002
177 #define PCI_COMMAND_BUSMASTER 0x0004
178 #define PCI_COMMAND_SPECIALCYCLE 0x0008
179 #define PCI_COMMAND_MEMWRITEINVALID 0x0010
180 #define PCI_COMMAND_PALETTESNOOPING 0x0020
181 #define PCI_COMMAND_PARITYDETECTION 0x0040
182 #define PCI_COMMAND_ADDRESSDATASTEPPING 0x0080
183 #define PCI_COMMAND_SERR 0x0100
184 #define PCI_COMMAND_BACKTOBACKTRANS 0x0200
185 // PCI 0x08, 0xff000000 (0x09-0x0b:class,0x08:rev)
186 #define PCI_CLASS_BASE_DISPLAY 0x03
187 // PCI 0x08, 0x00ff0000
188 #define PCI_CLASS_SUB_VGA 0x00
189 // PCI 0x0c, 0x00ff0000 (0x0c:cacheline,0x0d:latency,0x0e:headertype,0x0f:Built-in self test)
190 // 0x10-0x3f (headertype 00h)
191 // PCI 0x10,0x14,0x18,0x1c,0x20,0x24: base address mapping registers
192 // 0x10: MEMBASE, 0x14: IOBASE(hard-coded in XFree86 3.x)
193 #define PCI_MAP_MEM 0x0
194 #define PCI_MAP_IO 0x1
195 #define PCI_MAP_MEM_ADDR_MASK (~0xf)
196 #define PCI_MAP_IO_ADDR_MASK (~0x3)
197 #define PCI_MAP_MEMFLAGS_32BIT 0x0
198 #define PCI_MAP_MEMFLAGS_32BIT_1M 0x1
199 #define PCI_MAP_MEMFLAGS_64BIT 0x4
200 #define PCI_MAP_MEMFLAGS_CACHEABLE 0x8
201 // PCI 0x28: cardbus CIS pointer
202 // PCI 0x2c: subsystem vendor id, 0x2e: subsystem id
203 // PCI 0x30: expansion ROM base address
204 #define PCI_ROMBIOS_ENABLED 0x1
205 // PCI 0x34: 0xffffff00=reserved, 0x000000ff=capabilities pointer
206 // PCI 0x38: reserved
207 // PCI 0x3c: 0x3c=int-line, 0x3d=int-pin, 0x3e=min-gnt, 0x3f=maax-lat
209 #define CIRRUS_PNPMMIO_SIZE 0x1000
211 #define ABS(a) ((signed)(a) > 0 ? a : -a)
213 #define BLTUNSAFE(s) \
215 ( /* check dst is within bounds */ \
216 (s)->cirrus_blt_height * ABS((s)->cirrus_blt_dstpitch) \
217 + ((s)->cirrus_blt_dstaddr & (s)->cirrus_addr_mask) > \
220 ( /* check src is within bounds */ \
221 (s)->cirrus_blt_height * ABS((s)->cirrus_blt_srcpitch) \
222 + ((s)->cirrus_blt_srcaddr & (s)->cirrus_addr_mask) > \
227 struct CirrusVGAState
;
228 typedef void (*cirrus_bitblt_rop_t
) (struct CirrusVGAState
*s
,
229 uint8_t * dst
, const uint8_t * src
,
230 int dstpitch
, int srcpitch
,
231 int bltwidth
, int bltheight
);
232 typedef void (*cirrus_fill_t
)(struct CirrusVGAState
*s
,
233 uint8_t *dst
, int dst_pitch
, int width
, int height
);
235 typedef struct CirrusVGAState
{
238 int cirrus_linear_io_addr
;
239 int cirrus_linear_bitblt_io_addr
;
240 int cirrus_mmio_io_addr
;
241 uint32_t cirrus_addr_mask
;
242 uint32_t linear_mmio_mask
;
243 uint8_t cirrus_shadow_gr0
;
244 uint8_t cirrus_shadow_gr1
;
245 uint8_t cirrus_hidden_dac_lockindex
;
246 uint8_t cirrus_hidden_dac_data
;
247 uint32_t cirrus_bank_base
[2];
248 uint32_t cirrus_bank_limit
[2];
249 uint8_t cirrus_hidden_palette
[48];
250 uint32_t hw_cursor_x
;
251 uint32_t hw_cursor_y
;
252 int cirrus_blt_pixelwidth
;
253 int cirrus_blt_width
;
254 int cirrus_blt_height
;
255 int cirrus_blt_dstpitch
;
256 int cirrus_blt_srcpitch
;
257 uint32_t cirrus_blt_fgcol
;
258 uint32_t cirrus_blt_bgcol
;
259 uint32_t cirrus_blt_dstaddr
;
260 uint32_t cirrus_blt_srcaddr
;
261 uint8_t cirrus_blt_mode
;
262 uint8_t cirrus_blt_modeext
;
263 cirrus_bitblt_rop_t cirrus_rop
;
264 #define CIRRUS_BLTBUFSIZE (2048 * 4) /* one line width */
265 uint8_t cirrus_bltbuf
[CIRRUS_BLTBUFSIZE
];
266 uint8_t *cirrus_srcptr
;
267 uint8_t *cirrus_srcptr_end
;
268 uint32_t cirrus_srccounter
;
269 /* hwcursor display state */
270 int last_hw_cursor_size
;
271 int last_hw_cursor_x
;
272 int last_hw_cursor_y
;
273 int last_hw_cursor_y_start
;
274 int last_hw_cursor_y_end
;
275 int real_vram_size
; /* XXX: suppress that */
280 typedef struct PCICirrusVGAState
{
282 CirrusVGAState cirrus_vga
;
285 static uint8_t rop_to_index
[256];
287 /***************************************
291 ***************************************/
294 static void cirrus_bitblt_reset(CirrusVGAState
*s
);
295 static void cirrus_update_memory_access(CirrusVGAState
*s
);
297 /***************************************
301 ***************************************/
303 static void cirrus_bitblt_rop_nop(CirrusVGAState
*s
,
304 uint8_t *dst
,const uint8_t *src
,
305 int dstpitch
,int srcpitch
,
306 int bltwidth
,int bltheight
)
310 static void cirrus_bitblt_fill_nop(CirrusVGAState
*s
,
312 int dstpitch
, int bltwidth
,int bltheight
)
317 #define ROP_OP(d, s) d = 0
318 #include "cirrus_vga_rop.h"
320 #define ROP_NAME src_and_dst
321 #define ROP_OP(d, s) d = (s) & (d)
322 #include "cirrus_vga_rop.h"
324 #define ROP_NAME src_and_notdst
325 #define ROP_OP(d, s) d = (s) & (~(d))
326 #include "cirrus_vga_rop.h"
328 #define ROP_NAME notdst
329 #define ROP_OP(d, s) d = ~(d)
330 #include "cirrus_vga_rop.h"
333 #define ROP_OP(d, s) d = s
334 #include "cirrus_vga_rop.h"
337 #define ROP_OP(d, s) d = ~0
338 #include "cirrus_vga_rop.h"
340 #define ROP_NAME notsrc_and_dst
341 #define ROP_OP(d, s) d = (~(s)) & (d)
342 #include "cirrus_vga_rop.h"
344 #define ROP_NAME src_xor_dst
345 #define ROP_OP(d, s) d = (s) ^ (d)
346 #include "cirrus_vga_rop.h"
348 #define ROP_NAME src_or_dst
349 #define ROP_OP(d, s) d = (s) | (d)
350 #include "cirrus_vga_rop.h"
352 #define ROP_NAME notsrc_or_notdst
353 #define ROP_OP(d, s) d = (~(s)) | (~(d))
354 #include "cirrus_vga_rop.h"
356 #define ROP_NAME src_notxor_dst
357 #define ROP_OP(d, s) d = ~((s) ^ (d))
358 #include "cirrus_vga_rop.h"
360 #define ROP_NAME src_or_notdst
361 #define ROP_OP(d, s) d = (s) | (~(d))
362 #include "cirrus_vga_rop.h"
364 #define ROP_NAME notsrc
365 #define ROP_OP(d, s) d = (~(s))
366 #include "cirrus_vga_rop.h"
368 #define ROP_NAME notsrc_or_dst
369 #define ROP_OP(d, s) d = (~(s)) | (d)
370 #include "cirrus_vga_rop.h"
372 #define ROP_NAME notsrc_and_notdst
373 #define ROP_OP(d, s) d = (~(s)) & (~(d))
374 #include "cirrus_vga_rop.h"
376 static const cirrus_bitblt_rop_t cirrus_fwd_rop
[16] = {
377 cirrus_bitblt_rop_fwd_0
,
378 cirrus_bitblt_rop_fwd_src_and_dst
,
379 cirrus_bitblt_rop_nop
,
380 cirrus_bitblt_rop_fwd_src_and_notdst
,
381 cirrus_bitblt_rop_fwd_notdst
,
382 cirrus_bitblt_rop_fwd_src
,
383 cirrus_bitblt_rop_fwd_1
,
384 cirrus_bitblt_rop_fwd_notsrc_and_dst
,
385 cirrus_bitblt_rop_fwd_src_xor_dst
,
386 cirrus_bitblt_rop_fwd_src_or_dst
,
387 cirrus_bitblt_rop_fwd_notsrc_or_notdst
,
388 cirrus_bitblt_rop_fwd_src_notxor_dst
,
389 cirrus_bitblt_rop_fwd_src_or_notdst
,
390 cirrus_bitblt_rop_fwd_notsrc
,
391 cirrus_bitblt_rop_fwd_notsrc_or_dst
,
392 cirrus_bitblt_rop_fwd_notsrc_and_notdst
,
395 static const cirrus_bitblt_rop_t cirrus_bkwd_rop
[16] = {
396 cirrus_bitblt_rop_bkwd_0
,
397 cirrus_bitblt_rop_bkwd_src_and_dst
,
398 cirrus_bitblt_rop_nop
,
399 cirrus_bitblt_rop_bkwd_src_and_notdst
,
400 cirrus_bitblt_rop_bkwd_notdst
,
401 cirrus_bitblt_rop_bkwd_src
,
402 cirrus_bitblt_rop_bkwd_1
,
403 cirrus_bitblt_rop_bkwd_notsrc_and_dst
,
404 cirrus_bitblt_rop_bkwd_src_xor_dst
,
405 cirrus_bitblt_rop_bkwd_src_or_dst
,
406 cirrus_bitblt_rop_bkwd_notsrc_or_notdst
,
407 cirrus_bitblt_rop_bkwd_src_notxor_dst
,
408 cirrus_bitblt_rop_bkwd_src_or_notdst
,
409 cirrus_bitblt_rop_bkwd_notsrc
,
410 cirrus_bitblt_rop_bkwd_notsrc_or_dst
,
411 cirrus_bitblt_rop_bkwd_notsrc_and_notdst
,
414 #define TRANSP_ROP(name) {\
418 #define TRANSP_NOP(func) {\
423 static const cirrus_bitblt_rop_t cirrus_fwd_transp_rop
[16][2] = {
424 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_0
),
425 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_and_dst
),
426 TRANSP_NOP(cirrus_bitblt_rop_nop
),
427 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_and_notdst
),
428 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notdst
),
429 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src
),
430 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_1
),
431 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc_and_dst
),
432 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_xor_dst
),
433 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_or_dst
),
434 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc_or_notdst
),
435 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_notxor_dst
),
436 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_src_or_notdst
),
437 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc
),
438 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc_or_dst
),
439 TRANSP_ROP(cirrus_bitblt_rop_fwd_transp_notsrc_and_notdst
),
442 static const cirrus_bitblt_rop_t cirrus_bkwd_transp_rop
[16][2] = {
443 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_0
),
444 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_and_dst
),
445 TRANSP_NOP(cirrus_bitblt_rop_nop
),
446 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_and_notdst
),
447 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notdst
),
448 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src
),
449 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_1
),
450 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc_and_dst
),
451 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_xor_dst
),
452 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_or_dst
),
453 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc_or_notdst
),
454 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_notxor_dst
),
455 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_src_or_notdst
),
456 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc
),
457 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc_or_dst
),
458 TRANSP_ROP(cirrus_bitblt_rop_bkwd_transp_notsrc_and_notdst
),
461 #define ROP2(name) {\
468 #define ROP_NOP2(func) {\
475 static const cirrus_bitblt_rop_t cirrus_patternfill
[16][4] = {
476 ROP2(cirrus_patternfill_0
),
477 ROP2(cirrus_patternfill_src_and_dst
),
478 ROP_NOP2(cirrus_bitblt_rop_nop
),
479 ROP2(cirrus_patternfill_src_and_notdst
),
480 ROP2(cirrus_patternfill_notdst
),
481 ROP2(cirrus_patternfill_src
),
482 ROP2(cirrus_patternfill_1
),
483 ROP2(cirrus_patternfill_notsrc_and_dst
),
484 ROP2(cirrus_patternfill_src_xor_dst
),
485 ROP2(cirrus_patternfill_src_or_dst
),
486 ROP2(cirrus_patternfill_notsrc_or_notdst
),
487 ROP2(cirrus_patternfill_src_notxor_dst
),
488 ROP2(cirrus_patternfill_src_or_notdst
),
489 ROP2(cirrus_patternfill_notsrc
),
490 ROP2(cirrus_patternfill_notsrc_or_dst
),
491 ROP2(cirrus_patternfill_notsrc_and_notdst
),
494 static const cirrus_bitblt_rop_t cirrus_colorexpand_transp
[16][4] = {
495 ROP2(cirrus_colorexpand_transp_0
),
496 ROP2(cirrus_colorexpand_transp_src_and_dst
),
497 ROP_NOP2(cirrus_bitblt_rop_nop
),
498 ROP2(cirrus_colorexpand_transp_src_and_notdst
),
499 ROP2(cirrus_colorexpand_transp_notdst
),
500 ROP2(cirrus_colorexpand_transp_src
),
501 ROP2(cirrus_colorexpand_transp_1
),
502 ROP2(cirrus_colorexpand_transp_notsrc_and_dst
),
503 ROP2(cirrus_colorexpand_transp_src_xor_dst
),
504 ROP2(cirrus_colorexpand_transp_src_or_dst
),
505 ROP2(cirrus_colorexpand_transp_notsrc_or_notdst
),
506 ROP2(cirrus_colorexpand_transp_src_notxor_dst
),
507 ROP2(cirrus_colorexpand_transp_src_or_notdst
),
508 ROP2(cirrus_colorexpand_transp_notsrc
),
509 ROP2(cirrus_colorexpand_transp_notsrc_or_dst
),
510 ROP2(cirrus_colorexpand_transp_notsrc_and_notdst
),
513 static const cirrus_bitblt_rop_t cirrus_colorexpand
[16][4] = {
514 ROP2(cirrus_colorexpand_0
),
515 ROP2(cirrus_colorexpand_src_and_dst
),
516 ROP_NOP2(cirrus_bitblt_rop_nop
),
517 ROP2(cirrus_colorexpand_src_and_notdst
),
518 ROP2(cirrus_colorexpand_notdst
),
519 ROP2(cirrus_colorexpand_src
),
520 ROP2(cirrus_colorexpand_1
),
521 ROP2(cirrus_colorexpand_notsrc_and_dst
),
522 ROP2(cirrus_colorexpand_src_xor_dst
),
523 ROP2(cirrus_colorexpand_src_or_dst
),
524 ROP2(cirrus_colorexpand_notsrc_or_notdst
),
525 ROP2(cirrus_colorexpand_src_notxor_dst
),
526 ROP2(cirrus_colorexpand_src_or_notdst
),
527 ROP2(cirrus_colorexpand_notsrc
),
528 ROP2(cirrus_colorexpand_notsrc_or_dst
),
529 ROP2(cirrus_colorexpand_notsrc_and_notdst
),
532 static const cirrus_bitblt_rop_t cirrus_colorexpand_pattern_transp
[16][4] = {
533 ROP2(cirrus_colorexpand_pattern_transp_0
),
534 ROP2(cirrus_colorexpand_pattern_transp_src_and_dst
),
535 ROP_NOP2(cirrus_bitblt_rop_nop
),
536 ROP2(cirrus_colorexpand_pattern_transp_src_and_notdst
),
537 ROP2(cirrus_colorexpand_pattern_transp_notdst
),
538 ROP2(cirrus_colorexpand_pattern_transp_src
),
539 ROP2(cirrus_colorexpand_pattern_transp_1
),
540 ROP2(cirrus_colorexpand_pattern_transp_notsrc_and_dst
),
541 ROP2(cirrus_colorexpand_pattern_transp_src_xor_dst
),
542 ROP2(cirrus_colorexpand_pattern_transp_src_or_dst
),
543 ROP2(cirrus_colorexpand_pattern_transp_notsrc_or_notdst
),
544 ROP2(cirrus_colorexpand_pattern_transp_src_notxor_dst
),
545 ROP2(cirrus_colorexpand_pattern_transp_src_or_notdst
),
546 ROP2(cirrus_colorexpand_pattern_transp_notsrc
),
547 ROP2(cirrus_colorexpand_pattern_transp_notsrc_or_dst
),
548 ROP2(cirrus_colorexpand_pattern_transp_notsrc_and_notdst
),
551 static const cirrus_bitblt_rop_t cirrus_colorexpand_pattern
[16][4] = {
552 ROP2(cirrus_colorexpand_pattern_0
),
553 ROP2(cirrus_colorexpand_pattern_src_and_dst
),
554 ROP_NOP2(cirrus_bitblt_rop_nop
),
555 ROP2(cirrus_colorexpand_pattern_src_and_notdst
),
556 ROP2(cirrus_colorexpand_pattern_notdst
),
557 ROP2(cirrus_colorexpand_pattern_src
),
558 ROP2(cirrus_colorexpand_pattern_1
),
559 ROP2(cirrus_colorexpand_pattern_notsrc_and_dst
),
560 ROP2(cirrus_colorexpand_pattern_src_xor_dst
),
561 ROP2(cirrus_colorexpand_pattern_src_or_dst
),
562 ROP2(cirrus_colorexpand_pattern_notsrc_or_notdst
),
563 ROP2(cirrus_colorexpand_pattern_src_notxor_dst
),
564 ROP2(cirrus_colorexpand_pattern_src_or_notdst
),
565 ROP2(cirrus_colorexpand_pattern_notsrc
),
566 ROP2(cirrus_colorexpand_pattern_notsrc_or_dst
),
567 ROP2(cirrus_colorexpand_pattern_notsrc_and_notdst
),
570 static const cirrus_fill_t cirrus_fill
[16][4] = {
572 ROP2(cirrus_fill_src_and_dst
),
573 ROP_NOP2(cirrus_bitblt_fill_nop
),
574 ROP2(cirrus_fill_src_and_notdst
),
575 ROP2(cirrus_fill_notdst
),
576 ROP2(cirrus_fill_src
),
578 ROP2(cirrus_fill_notsrc_and_dst
),
579 ROP2(cirrus_fill_src_xor_dst
),
580 ROP2(cirrus_fill_src_or_dst
),
581 ROP2(cirrus_fill_notsrc_or_notdst
),
582 ROP2(cirrus_fill_src_notxor_dst
),
583 ROP2(cirrus_fill_src_or_notdst
),
584 ROP2(cirrus_fill_notsrc
),
585 ROP2(cirrus_fill_notsrc_or_dst
),
586 ROP2(cirrus_fill_notsrc_and_notdst
),
589 static inline void cirrus_bitblt_fgcol(CirrusVGAState
*s
)
592 switch (s
->cirrus_blt_pixelwidth
) {
594 s
->cirrus_blt_fgcol
= s
->cirrus_shadow_gr1
;
597 color
= s
->cirrus_shadow_gr1
| (s
->vga
.gr
[0x11] << 8);
598 s
->cirrus_blt_fgcol
= le16_to_cpu(color
);
601 s
->cirrus_blt_fgcol
= s
->cirrus_shadow_gr1
|
602 (s
->vga
.gr
[0x11] << 8) | (s
->vga
.gr
[0x13] << 16);
606 color
= s
->cirrus_shadow_gr1
| (s
->vga
.gr
[0x11] << 8) |
607 (s
->vga
.gr
[0x13] << 16) | (s
->vga
.gr
[0x15] << 24);
608 s
->cirrus_blt_fgcol
= le32_to_cpu(color
);
613 static inline void cirrus_bitblt_bgcol(CirrusVGAState
*s
)
616 switch (s
->cirrus_blt_pixelwidth
) {
618 s
->cirrus_blt_bgcol
= s
->cirrus_shadow_gr0
;
621 color
= s
->cirrus_shadow_gr0
| (s
->vga
.gr
[0x10] << 8);
622 s
->cirrus_blt_bgcol
= le16_to_cpu(color
);
625 s
->cirrus_blt_bgcol
= s
->cirrus_shadow_gr0
|
626 (s
->vga
.gr
[0x10] << 8) | (s
->vga
.gr
[0x12] << 16);
630 color
= s
->cirrus_shadow_gr0
| (s
->vga
.gr
[0x10] << 8) |
631 (s
->vga
.gr
[0x12] << 16) | (s
->vga
.gr
[0x14] << 24);
632 s
->cirrus_blt_bgcol
= le32_to_cpu(color
);
637 static void cirrus_invalidate_region(CirrusVGAState
* s
, int off_begin
,
638 int off_pitch
, int bytesperline
,
645 for (y
= 0; y
< lines
; y
++) {
647 off_cur_end
= (off_cur
+ bytesperline
) & s
->cirrus_addr_mask
;
648 off_cur
&= TARGET_PAGE_MASK
;
649 while (off_cur
< off_cur_end
) {
650 cpu_physical_memory_set_dirty(s
->vga
.vram_offset
+ off_cur
);
651 off_cur
+= TARGET_PAGE_SIZE
;
653 off_begin
+= off_pitch
;
657 static int cirrus_bitblt_common_patterncopy(CirrusVGAState
* s
,
662 dst
= s
->vga
.vram_ptr
+ (s
->cirrus_blt_dstaddr
& s
->cirrus_addr_mask
);
667 (*s
->cirrus_rop
) (s
, dst
, src
,
668 s
->cirrus_blt_dstpitch
, 0,
669 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
670 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
,
671 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_width
,
672 s
->cirrus_blt_height
);
678 static int cirrus_bitblt_solidfill(CirrusVGAState
*s
, int blt_rop
)
680 cirrus_fill_t rop_func
;
684 rop_func
= cirrus_fill
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
685 rop_func(s
, s
->vga
.vram_ptr
+ (s
->cirrus_blt_dstaddr
& s
->cirrus_addr_mask
),
686 s
->cirrus_blt_dstpitch
,
687 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
688 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
,
689 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_width
,
690 s
->cirrus_blt_height
);
691 cirrus_bitblt_reset(s
);
695 /***************************************
697 * bitblt (video-to-video)
699 ***************************************/
701 static int cirrus_bitblt_videotovideo_patterncopy(CirrusVGAState
* s
)
703 return cirrus_bitblt_common_patterncopy(s
,
704 s
->vga
.vram_ptr
+ ((s
->cirrus_blt_srcaddr
& ~7) &
705 s
->cirrus_addr_mask
));
708 static void cirrus_do_copy(CirrusVGAState
*s
, int dst
, int src
, int w
, int h
)
716 depth
= s
->vga
.get_bpp(&s
->vga
) / 8;
717 s
->vga
.get_resolution(&s
->vga
, &width
, &height
);
720 sx
= (src
% ABS(s
->cirrus_blt_srcpitch
)) / depth
;
721 sy
= (src
/ ABS(s
->cirrus_blt_srcpitch
));
722 dx
= (dst
% ABS(s
->cirrus_blt_dstpitch
)) / depth
;
723 dy
= (dst
/ ABS(s
->cirrus_blt_dstpitch
));
725 /* normalize width */
728 /* if we're doing a backward copy, we have to adjust
729 our x/y to be the upper left corner (instead of the lower
731 if (s
->cirrus_blt_dstpitch
< 0) {
732 sx
-= (s
->cirrus_blt_width
/ depth
) - 1;
733 dx
-= (s
->cirrus_blt_width
/ depth
) - 1;
734 sy
-= s
->cirrus_blt_height
- 1;
735 dy
-= s
->cirrus_blt_height
- 1;
738 /* are we in the visible portion of memory? */
739 if (sx
>= 0 && sy
>= 0 && dx
>= 0 && dy
>= 0 &&
740 (sx
+ w
) <= width
&& (sy
+ h
) <= height
&&
741 (dx
+ w
) <= width
&& (dy
+ h
) <= height
) {
745 /* make to sure only copy if it's a plain copy ROP */
746 if (*s
->cirrus_rop
!= cirrus_bitblt_rop_fwd_src
&&
747 *s
->cirrus_rop
!= cirrus_bitblt_rop_bkwd_src
)
750 /* we have to flush all pending changes so that the copy
751 is generated at the appropriate moment in time */
755 (*s
->cirrus_rop
) (s
, s
->vga
.vram_ptr
+
756 (s
->cirrus_blt_dstaddr
& s
->cirrus_addr_mask
),
758 (s
->cirrus_blt_srcaddr
& s
->cirrus_addr_mask
),
759 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_srcpitch
,
760 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
763 qemu_console_copy(s
->vga
.ds
,
765 s
->cirrus_blt_width
/ depth
,
766 s
->cirrus_blt_height
);
768 /* we don't have to notify the display that this portion has
769 changed since qemu_console_copy implies this */
771 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
,
772 s
->cirrus_blt_dstpitch
, s
->cirrus_blt_width
,
773 s
->cirrus_blt_height
);
776 static int cirrus_bitblt_videotovideo_copy(CirrusVGAState
* s
)
781 cirrus_do_copy(s
, s
->cirrus_blt_dstaddr
- s
->vga
.start_addr
,
782 s
->cirrus_blt_srcaddr
- s
->vga
.start_addr
,
783 s
->cirrus_blt_width
, s
->cirrus_blt_height
);
788 /***************************************
790 * bitblt (cpu-to-video)
792 ***************************************/
794 static void cirrus_bitblt_cputovideo_next(CirrusVGAState
* s
)
799 if (s
->cirrus_srccounter
> 0) {
800 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PATTERNCOPY
) {
801 cirrus_bitblt_common_patterncopy(s
, s
->cirrus_bltbuf
);
803 s
->cirrus_srccounter
= 0;
804 cirrus_bitblt_reset(s
);
806 /* at least one scan line */
808 (*s
->cirrus_rop
)(s
, s
->vga
.vram_ptr
+
809 (s
->cirrus_blt_dstaddr
& s
->cirrus_addr_mask
),
810 s
->cirrus_bltbuf
, 0, 0, s
->cirrus_blt_width
, 1);
811 cirrus_invalidate_region(s
, s
->cirrus_blt_dstaddr
, 0,
812 s
->cirrus_blt_width
, 1);
813 s
->cirrus_blt_dstaddr
+= s
->cirrus_blt_dstpitch
;
814 s
->cirrus_srccounter
-= s
->cirrus_blt_srcpitch
;
815 if (s
->cirrus_srccounter
<= 0)
817 /* more bytes than needed can be transfered because of
818 word alignment, so we keep them for the next line */
819 /* XXX: keep alignment to speed up transfer */
820 end_ptr
= s
->cirrus_bltbuf
+ s
->cirrus_blt_srcpitch
;
821 copy_count
= s
->cirrus_srcptr_end
- end_ptr
;
822 memmove(s
->cirrus_bltbuf
, end_ptr
, copy_count
);
823 s
->cirrus_srcptr
= s
->cirrus_bltbuf
+ copy_count
;
824 s
->cirrus_srcptr_end
= s
->cirrus_bltbuf
+ s
->cirrus_blt_srcpitch
;
825 } while (s
->cirrus_srcptr
>= s
->cirrus_srcptr_end
);
830 /***************************************
834 ***************************************/
836 static void cirrus_bitblt_reset(CirrusVGAState
* s
)
841 ~(CIRRUS_BLT_START
| CIRRUS_BLT_BUSY
| CIRRUS_BLT_FIFOUSED
);
842 need_update
= s
->cirrus_srcptr
!= &s
->cirrus_bltbuf
[0]
843 || s
->cirrus_srcptr_end
!= &s
->cirrus_bltbuf
[0];
844 s
->cirrus_srcptr
= &s
->cirrus_bltbuf
[0];
845 s
->cirrus_srcptr_end
= &s
->cirrus_bltbuf
[0];
846 s
->cirrus_srccounter
= 0;
849 cirrus_update_memory_access(s
);
852 static int cirrus_bitblt_cputovideo(CirrusVGAState
* s
)
856 s
->cirrus_blt_mode
&= ~CIRRUS_BLTMODE_MEMSYSSRC
;
857 s
->cirrus_srcptr
= &s
->cirrus_bltbuf
[0];
858 s
->cirrus_srcptr_end
= &s
->cirrus_bltbuf
[0];
860 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PATTERNCOPY
) {
861 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_COLOREXPAND
) {
862 s
->cirrus_blt_srcpitch
= 8;
864 /* XXX: check for 24 bpp */
865 s
->cirrus_blt_srcpitch
= 8 * 8 * s
->cirrus_blt_pixelwidth
;
867 s
->cirrus_srccounter
= s
->cirrus_blt_srcpitch
;
869 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_COLOREXPAND
) {
870 w
= s
->cirrus_blt_width
/ s
->cirrus_blt_pixelwidth
;
871 if (s
->cirrus_blt_modeext
& CIRRUS_BLTMODEEXT_DWORDGRANULARITY
)
872 s
->cirrus_blt_srcpitch
= ((w
+ 31) >> 5);
874 s
->cirrus_blt_srcpitch
= ((w
+ 7) >> 3);
876 /* always align input size to 32 bits */
877 s
->cirrus_blt_srcpitch
= (s
->cirrus_blt_width
+ 3) & ~3;
879 s
->cirrus_srccounter
= s
->cirrus_blt_srcpitch
* s
->cirrus_blt_height
;
881 s
->cirrus_srcptr
= s
->cirrus_bltbuf
;
882 s
->cirrus_srcptr_end
= s
->cirrus_bltbuf
+ s
->cirrus_blt_srcpitch
;
883 cirrus_update_memory_access(s
);
887 static int cirrus_bitblt_videotocpu(CirrusVGAState
* s
)
891 printf("cirrus: bitblt (video to cpu) is not implemented yet\n");
896 static int cirrus_bitblt_videotovideo(CirrusVGAState
* s
)
900 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PATTERNCOPY
) {
901 ret
= cirrus_bitblt_videotovideo_patterncopy(s
);
903 ret
= cirrus_bitblt_videotovideo_copy(s
);
906 cirrus_bitblt_reset(s
);
910 static void cirrus_bitblt_start(CirrusVGAState
* s
)
914 s
->vga
.gr
[0x31] |= CIRRUS_BLT_BUSY
;
916 s
->cirrus_blt_width
= (s
->vga
.gr
[0x20] | (s
->vga
.gr
[0x21] << 8)) + 1;
917 s
->cirrus_blt_height
= (s
->vga
.gr
[0x22] | (s
->vga
.gr
[0x23] << 8)) + 1;
918 s
->cirrus_blt_dstpitch
= (s
->vga
.gr
[0x24] | (s
->vga
.gr
[0x25] << 8));
919 s
->cirrus_blt_srcpitch
= (s
->vga
.gr
[0x26] | (s
->vga
.gr
[0x27] << 8));
920 s
->cirrus_blt_dstaddr
=
921 (s
->vga
.gr
[0x28] | (s
->vga
.gr
[0x29] << 8) | (s
->vga
.gr
[0x2a] << 16));
922 s
->cirrus_blt_srcaddr
=
923 (s
->vga
.gr
[0x2c] | (s
->vga
.gr
[0x2d] << 8) | (s
->vga
.gr
[0x2e] << 16));
924 s
->cirrus_blt_mode
= s
->vga
.gr
[0x30];
925 s
->cirrus_blt_modeext
= s
->vga
.gr
[0x33];
926 blt_rop
= s
->vga
.gr
[0x32];
929 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",
932 s
->cirrus_blt_modeext
,
934 s
->cirrus_blt_height
,
935 s
->cirrus_blt_dstpitch
,
936 s
->cirrus_blt_srcpitch
,
937 s
->cirrus_blt_dstaddr
,
938 s
->cirrus_blt_srcaddr
,
942 switch (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PIXELWIDTHMASK
) {
943 case CIRRUS_BLTMODE_PIXELWIDTH8
:
944 s
->cirrus_blt_pixelwidth
= 1;
946 case CIRRUS_BLTMODE_PIXELWIDTH16
:
947 s
->cirrus_blt_pixelwidth
= 2;
949 case CIRRUS_BLTMODE_PIXELWIDTH24
:
950 s
->cirrus_blt_pixelwidth
= 3;
952 case CIRRUS_BLTMODE_PIXELWIDTH32
:
953 s
->cirrus_blt_pixelwidth
= 4;
957 printf("cirrus: bitblt - pixel width is unknown\n");
961 s
->cirrus_blt_mode
&= ~CIRRUS_BLTMODE_PIXELWIDTHMASK
;
964 cirrus_blt_mode
& (CIRRUS_BLTMODE_MEMSYSSRC
|
965 CIRRUS_BLTMODE_MEMSYSDEST
))
966 == (CIRRUS_BLTMODE_MEMSYSSRC
| CIRRUS_BLTMODE_MEMSYSDEST
)) {
968 printf("cirrus: bitblt - memory-to-memory copy is requested\n");
973 if ((s
->cirrus_blt_modeext
& CIRRUS_BLTMODEEXT_SOLIDFILL
) &&
974 (s
->cirrus_blt_mode
& (CIRRUS_BLTMODE_MEMSYSDEST
|
975 CIRRUS_BLTMODE_TRANSPARENTCOMP
|
976 CIRRUS_BLTMODE_PATTERNCOPY
|
977 CIRRUS_BLTMODE_COLOREXPAND
)) ==
978 (CIRRUS_BLTMODE_PATTERNCOPY
| CIRRUS_BLTMODE_COLOREXPAND
)) {
979 cirrus_bitblt_fgcol(s
);
980 cirrus_bitblt_solidfill(s
, blt_rop
);
982 if ((s
->cirrus_blt_mode
& (CIRRUS_BLTMODE_COLOREXPAND
|
983 CIRRUS_BLTMODE_PATTERNCOPY
)) ==
984 CIRRUS_BLTMODE_COLOREXPAND
) {
986 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_TRANSPARENTCOMP
) {
987 if (s
->cirrus_blt_modeext
& CIRRUS_BLTMODEEXT_COLOREXPINV
)
988 cirrus_bitblt_bgcol(s
);
990 cirrus_bitblt_fgcol(s
);
991 s
->cirrus_rop
= cirrus_colorexpand_transp
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
993 cirrus_bitblt_fgcol(s
);
994 cirrus_bitblt_bgcol(s
);
995 s
->cirrus_rop
= cirrus_colorexpand
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
997 } else if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_PATTERNCOPY
) {
998 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_COLOREXPAND
) {
999 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_TRANSPARENTCOMP
) {
1000 if (s
->cirrus_blt_modeext
& CIRRUS_BLTMODEEXT_COLOREXPINV
)
1001 cirrus_bitblt_bgcol(s
);
1003 cirrus_bitblt_fgcol(s
);
1004 s
->cirrus_rop
= cirrus_colorexpand_pattern_transp
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
1006 cirrus_bitblt_fgcol(s
);
1007 cirrus_bitblt_bgcol(s
);
1008 s
->cirrus_rop
= cirrus_colorexpand_pattern
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
1011 s
->cirrus_rop
= cirrus_patternfill
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
1014 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_TRANSPARENTCOMP
) {
1015 if (s
->cirrus_blt_pixelwidth
> 2) {
1016 printf("src transparent without colorexpand must be 8bpp or 16bpp\n");
1019 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_BACKWARDS
) {
1020 s
->cirrus_blt_dstpitch
= -s
->cirrus_blt_dstpitch
;
1021 s
->cirrus_blt_srcpitch
= -s
->cirrus_blt_srcpitch
;
1022 s
->cirrus_rop
= cirrus_bkwd_transp_rop
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
1024 s
->cirrus_rop
= cirrus_fwd_transp_rop
[rop_to_index
[blt_rop
]][s
->cirrus_blt_pixelwidth
- 1];
1027 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_BACKWARDS
) {
1028 s
->cirrus_blt_dstpitch
= -s
->cirrus_blt_dstpitch
;
1029 s
->cirrus_blt_srcpitch
= -s
->cirrus_blt_srcpitch
;
1030 s
->cirrus_rop
= cirrus_bkwd_rop
[rop_to_index
[blt_rop
]];
1032 s
->cirrus_rop
= cirrus_fwd_rop
[rop_to_index
[blt_rop
]];
1036 // setup bitblt engine.
1037 if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_MEMSYSSRC
) {
1038 if (!cirrus_bitblt_cputovideo(s
))
1040 } else if (s
->cirrus_blt_mode
& CIRRUS_BLTMODE_MEMSYSDEST
) {
1041 if (!cirrus_bitblt_videotocpu(s
))
1044 if (!cirrus_bitblt_videotovideo(s
))
1050 cirrus_bitblt_reset(s
);
1053 static void cirrus_write_bitblt(CirrusVGAState
* s
, unsigned reg_value
)
1057 old_value
= s
->vga
.gr
[0x31];
1058 s
->vga
.gr
[0x31] = reg_value
;
1060 if (((old_value
& CIRRUS_BLT_RESET
) != 0) &&
1061 ((reg_value
& CIRRUS_BLT_RESET
) == 0)) {
1062 cirrus_bitblt_reset(s
);
1063 } else if (((old_value
& CIRRUS_BLT_START
) == 0) &&
1064 ((reg_value
& CIRRUS_BLT_START
) != 0)) {
1065 cirrus_bitblt_start(s
);
1070 /***************************************
1074 ***************************************/
1076 static void cirrus_get_offsets(VGACommonState
*s1
,
1077 uint32_t *pline_offset
,
1078 uint32_t *pstart_addr
,
1079 uint32_t *pline_compare
)
1081 CirrusVGAState
* s
= container_of(s1
, CirrusVGAState
, vga
);
1082 uint32_t start_addr
, line_offset
, line_compare
;
1084 line_offset
= s
->vga
.cr
[0x13]
1085 | ((s
->vga
.cr
[0x1b] & 0x10) << 4);
1087 *pline_offset
= line_offset
;
1089 start_addr
= (s
->vga
.cr
[0x0c] << 8)
1091 | ((s
->vga
.cr
[0x1b] & 0x01) << 16)
1092 | ((s
->vga
.cr
[0x1b] & 0x0c) << 15)
1093 | ((s
->vga
.cr
[0x1d] & 0x80) << 12);
1094 *pstart_addr
= start_addr
;
1096 line_compare
= s
->vga
.cr
[0x18] |
1097 ((s
->vga
.cr
[0x07] & 0x10) << 4) |
1098 ((s
->vga
.cr
[0x09] & 0x40) << 3);
1099 *pline_compare
= line_compare
;
1102 static uint32_t cirrus_get_bpp16_depth(CirrusVGAState
* s
)
1106 switch (s
->cirrus_hidden_dac_data
& 0xf) {
1109 break; /* Sierra HiColor */
1112 break; /* XGA HiColor */
1115 printf("cirrus: invalid DAC value %x in 16bpp\n",
1116 (s
->cirrus_hidden_dac_data
& 0xf));
1124 static int cirrus_get_bpp(VGACommonState
*s1
)
1126 CirrusVGAState
* s
= container_of(s1
, CirrusVGAState
, vga
);
1129 if ((s
->vga
.sr
[0x07] & 0x01) != 0) {
1131 switch (s
->vga
.sr
[0x07] & CIRRUS_SR7_BPP_MASK
) {
1132 case CIRRUS_SR7_BPP_8
:
1135 case CIRRUS_SR7_BPP_16_DOUBLEVCLK
:
1136 ret
= cirrus_get_bpp16_depth(s
);
1138 case CIRRUS_SR7_BPP_24
:
1141 case CIRRUS_SR7_BPP_16
:
1142 ret
= cirrus_get_bpp16_depth(s
);
1144 case CIRRUS_SR7_BPP_32
:
1149 printf("cirrus: unknown bpp - sr7=%x\n", s
->vga
.sr
[0x7]);
1162 static void cirrus_get_resolution(VGACommonState
*s
, int *pwidth
, int *pheight
)
1166 width
= (s
->cr
[0x01] + 1) * 8;
1167 height
= s
->cr
[0x12] |
1168 ((s
->cr
[0x07] & 0x02) << 7) |
1169 ((s
->cr
[0x07] & 0x40) << 3);
1170 height
= (height
+ 1);
1171 /* interlace support */
1172 if (s
->cr
[0x1a] & 0x01)
1173 height
= height
* 2;
1178 /***************************************
1182 ***************************************/
1184 static void cirrus_update_bank_ptr(CirrusVGAState
* s
, unsigned bank_index
)
1189 if ((s
->vga
.gr
[0x0b] & 0x01) != 0) /* dual bank */
1190 offset
= s
->vga
.gr
[0x09 + bank_index
];
1191 else /* single bank */
1192 offset
= s
->vga
.gr
[0x09];
1194 if ((s
->vga
.gr
[0x0b] & 0x20) != 0)
1199 if (s
->real_vram_size
<= offset
)
1202 limit
= s
->real_vram_size
- offset
;
1204 if (((s
->vga
.gr
[0x0b] & 0x01) == 0) && (bank_index
!= 0)) {
1205 if (limit
> 0x8000) {
1214 /* Thinking about changing bank base? First, drop the dirty bitmap information
1215 * on the current location, otherwise we lose this pointer forever */
1216 if (s
->vga
.lfb_vram_mapped
) {
1217 target_phys_addr_t base_addr
= isa_mem_base
+ 0xa0000 + bank_index
* 0x8000;
1218 cpu_physical_sync_dirty_bitmap(base_addr
, base_addr
+ 0x8000);
1220 s
->cirrus_bank_base
[bank_index
] = offset
;
1221 s
->cirrus_bank_limit
[bank_index
] = limit
;
1223 s
->cirrus_bank_base
[bank_index
] = 0;
1224 s
->cirrus_bank_limit
[bank_index
] = 0;
1228 /***************************************
1230 * I/O access between 0x3c4-0x3c5
1232 ***************************************/
1234 static int cirrus_vga_read_sr(CirrusVGAState
* s
)
1236 switch (s
->vga
.sr_index
) {
1237 case 0x00: // Standard VGA
1238 case 0x01: // Standard VGA
1239 case 0x02: // Standard VGA
1240 case 0x03: // Standard VGA
1241 case 0x04: // Standard VGA
1242 return s
->vga
.sr
[s
->vga
.sr_index
];
1243 case 0x06: // Unlock Cirrus extensions
1244 return s
->vga
.sr
[s
->vga
.sr_index
];
1248 case 0x70: // Graphics Cursor X
1252 case 0xf0: // Graphics Cursor X
1253 return s
->vga
.sr
[0x10];
1257 case 0x71: // Graphics Cursor Y
1261 case 0xf1: // Graphics Cursor Y
1262 return s
->vga
.sr
[0x11];
1264 case 0x07: // Extended Sequencer Mode
1265 case 0x08: // EEPROM Control
1266 case 0x09: // Scratch Register 0
1267 case 0x0a: // Scratch Register 1
1268 case 0x0b: // VCLK 0
1269 case 0x0c: // VCLK 1
1270 case 0x0d: // VCLK 2
1271 case 0x0e: // VCLK 3
1272 case 0x0f: // DRAM Control
1273 case 0x12: // Graphics Cursor Attribute
1274 case 0x13: // Graphics Cursor Pattern Address
1275 case 0x14: // Scratch Register 2
1276 case 0x15: // Scratch Register 3
1277 case 0x16: // Performance Tuning Register
1278 case 0x17: // Configuration Readback and Extended Control
1279 case 0x18: // Signature Generator Control
1280 case 0x19: // Signal Generator Result
1281 case 0x1a: // Signal Generator Result
1282 case 0x1b: // VCLK 0 Denominator & Post
1283 case 0x1c: // VCLK 1 Denominator & Post
1284 case 0x1d: // VCLK 2 Denominator & Post
1285 case 0x1e: // VCLK 3 Denominator & Post
1286 case 0x1f: // BIOS Write Enable and MCLK select
1288 printf("cirrus: handled inport sr_index %02x\n", s
->vga
.sr_index
);
1290 return s
->vga
.sr
[s
->vga
.sr_index
];
1293 printf("cirrus: inport sr_index %02x\n", s
->vga
.sr_index
);
1300 static void cirrus_vga_write_sr(CirrusVGAState
* s
, uint32_t val
)
1302 switch (s
->vga
.sr_index
) {
1303 case 0x00: // Standard VGA
1304 case 0x01: // Standard VGA
1305 case 0x02: // Standard VGA
1306 case 0x03: // Standard VGA
1307 case 0x04: // Standard VGA
1308 s
->vga
.sr
[s
->vga
.sr_index
] = val
& sr_mask
[s
->vga
.sr_index
];
1309 if (s
->vga
.sr_index
== 1)
1310 s
->vga
.update_retrace_info(&s
->vga
);
1312 case 0x06: // Unlock Cirrus extensions
1315 s
->vga
.sr
[s
->vga
.sr_index
] = 0x12;
1317 s
->vga
.sr
[s
->vga
.sr_index
] = 0x0f;
1323 case 0x70: // Graphics Cursor X
1327 case 0xf0: // Graphics Cursor X
1328 s
->vga
.sr
[0x10] = val
;
1329 s
->hw_cursor_x
= (val
<< 3) | (s
->vga
.sr_index
>> 5);
1334 case 0x71: // Graphics Cursor Y
1338 case 0xf1: // Graphics Cursor Y
1339 s
->vga
.sr
[0x11] = val
;
1340 s
->hw_cursor_y
= (val
<< 3) | (s
->vga
.sr_index
>> 5);
1342 case 0x07: // Extended Sequencer Mode
1343 cirrus_update_memory_access(s
);
1344 case 0x08: // EEPROM Control
1345 case 0x09: // Scratch Register 0
1346 case 0x0a: // Scratch Register 1
1347 case 0x0b: // VCLK 0
1348 case 0x0c: // VCLK 1
1349 case 0x0d: // VCLK 2
1350 case 0x0e: // VCLK 3
1351 case 0x0f: // DRAM Control
1352 case 0x12: // Graphics Cursor Attribute
1353 case 0x13: // Graphics Cursor Pattern Address
1354 case 0x14: // Scratch Register 2
1355 case 0x15: // Scratch Register 3
1356 case 0x16: // Performance Tuning Register
1357 case 0x18: // Signature Generator Control
1358 case 0x19: // Signature Generator Result
1359 case 0x1a: // Signature Generator Result
1360 case 0x1b: // VCLK 0 Denominator & Post
1361 case 0x1c: // VCLK 1 Denominator & Post
1362 case 0x1d: // VCLK 2 Denominator & Post
1363 case 0x1e: // VCLK 3 Denominator & Post
1364 case 0x1f: // BIOS Write Enable and MCLK select
1365 s
->vga
.sr
[s
->vga
.sr_index
] = val
;
1367 printf("cirrus: handled outport sr_index %02x, sr_value %02x\n",
1368 s
->vga
.sr_index
, val
);
1371 case 0x17: // Configuration Readback and Extended Control
1372 s
->vga
.sr
[s
->vga
.sr_index
] = (s
->vga
.sr
[s
->vga
.sr_index
] & 0x38)
1374 cirrus_update_memory_access(s
);
1378 printf("cirrus: outport sr_index %02x, sr_value %02x\n",
1379 s
->vga
.sr_index
, val
);
1385 /***************************************
1387 * I/O access at 0x3c6
1389 ***************************************/
1391 static int cirrus_read_hidden_dac(CirrusVGAState
* s
)
1393 if (++s
->cirrus_hidden_dac_lockindex
== 5) {
1394 s
->cirrus_hidden_dac_lockindex
= 0;
1395 return s
->cirrus_hidden_dac_data
;
1400 static void cirrus_write_hidden_dac(CirrusVGAState
* s
, int reg_value
)
1402 if (s
->cirrus_hidden_dac_lockindex
== 4) {
1403 s
->cirrus_hidden_dac_data
= reg_value
;
1404 #if defined(DEBUG_CIRRUS)
1405 printf("cirrus: outport hidden DAC, value %02x\n", reg_value
);
1408 s
->cirrus_hidden_dac_lockindex
= 0;
1411 /***************************************
1413 * I/O access at 0x3c9
1415 ***************************************/
1417 static int cirrus_vga_read_palette(CirrusVGAState
* s
)
1421 if ((s
->vga
.sr
[0x12] & CIRRUS_CURSOR_HIDDENPEL
)) {
1422 val
= s
->cirrus_hidden_palette
[(s
->vga
.dac_read_index
& 0x0f) * 3 +
1423 s
->vga
.dac_sub_index
];
1425 val
= s
->vga
.palette
[s
->vga
.dac_read_index
* 3 + s
->vga
.dac_sub_index
];
1427 if (++s
->vga
.dac_sub_index
== 3) {
1428 s
->vga
.dac_sub_index
= 0;
1429 s
->vga
.dac_read_index
++;
1434 static void cirrus_vga_write_palette(CirrusVGAState
* s
, int reg_value
)
1436 s
->vga
.dac_cache
[s
->vga
.dac_sub_index
] = reg_value
;
1437 if (++s
->vga
.dac_sub_index
== 3) {
1438 if ((s
->vga
.sr
[0x12] & CIRRUS_CURSOR_HIDDENPEL
)) {
1439 memcpy(&s
->cirrus_hidden_palette
[(s
->vga
.dac_write_index
& 0x0f) * 3],
1440 s
->vga
.dac_cache
, 3);
1442 memcpy(&s
->vga
.palette
[s
->vga
.dac_write_index
* 3], s
->vga
.dac_cache
, 3);
1444 /* XXX update cursor */
1445 s
->vga
.dac_sub_index
= 0;
1446 s
->vga
.dac_write_index
++;
1450 /***************************************
1452 * I/O access between 0x3ce-0x3cf
1454 ***************************************/
1456 static int cirrus_vga_read_gr(CirrusVGAState
* s
, unsigned reg_index
)
1458 switch (reg_index
) {
1459 case 0x00: // Standard VGA, BGCOLOR 0x000000ff
1460 return s
->cirrus_shadow_gr0
;
1461 case 0x01: // Standard VGA, FGCOLOR 0x000000ff
1462 return s
->cirrus_shadow_gr1
;
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 return s
->vga
.gr
[s
->vga
.gr_index
];
1470 case 0x05: // Standard VGA, Cirrus extended mode
1475 if (reg_index
< 0x3a) {
1476 return s
->vga
.gr
[reg_index
];
1479 printf("cirrus: inport gr_index %02x\n", reg_index
);
1486 cirrus_vga_write_gr(CirrusVGAState
* s
, unsigned reg_index
, int reg_value
)
1488 #if defined(DEBUG_BITBLT) && 0
1489 printf("gr%02x: %02x\n", reg_index
, reg_value
);
1491 switch (reg_index
) {
1492 case 0x00: // Standard VGA, BGCOLOR 0x000000ff
1493 s
->cirrus_shadow_gr0
= reg_value
;
1495 case 0x01: // Standard VGA, FGCOLOR 0x000000ff
1496 s
->cirrus_shadow_gr1
= reg_value
;
1498 case 0x02: // Standard VGA
1499 case 0x03: // Standard VGA
1500 case 0x04: // Standard VGA
1501 case 0x06: // Standard VGA
1502 case 0x07: // Standard VGA
1503 case 0x08: // Standard VGA
1504 s
->vga
.gr
[reg_index
] = reg_value
& gr_mask
[reg_index
];
1506 case 0x05: // Standard VGA, Cirrus extended mode
1507 s
->vga
.gr
[reg_index
] = reg_value
& 0x7f;
1508 cirrus_update_memory_access(s
);
1510 case 0x09: // bank offset #0
1511 case 0x0A: // bank offset #1
1512 s
->vga
.gr
[reg_index
] = reg_value
;
1513 cirrus_update_bank_ptr(s
, 0);
1514 cirrus_update_bank_ptr(s
, 1);
1515 cirrus_update_memory_access(s
);
1518 s
->vga
.gr
[reg_index
] = reg_value
;
1519 cirrus_update_bank_ptr(s
, 0);
1520 cirrus_update_bank_ptr(s
, 1);
1521 cirrus_update_memory_access(s
);
1523 case 0x10: // BGCOLOR 0x0000ff00
1524 case 0x11: // FGCOLOR 0x0000ff00
1525 case 0x12: // BGCOLOR 0x00ff0000
1526 case 0x13: // FGCOLOR 0x00ff0000
1527 case 0x14: // BGCOLOR 0xff000000
1528 case 0x15: // FGCOLOR 0xff000000
1529 case 0x20: // BLT WIDTH 0x0000ff
1530 case 0x22: // BLT HEIGHT 0x0000ff
1531 case 0x24: // BLT DEST PITCH 0x0000ff
1532 case 0x26: // BLT SRC PITCH 0x0000ff
1533 case 0x28: // BLT DEST ADDR 0x0000ff
1534 case 0x29: // BLT DEST ADDR 0x00ff00
1535 case 0x2c: // BLT SRC ADDR 0x0000ff
1536 case 0x2d: // BLT SRC ADDR 0x00ff00
1537 case 0x2f: // BLT WRITEMASK
1538 case 0x30: // BLT MODE
1539 case 0x32: // RASTER OP
1540 case 0x33: // BLT MODEEXT
1541 case 0x34: // BLT TRANSPARENT COLOR 0x00ff
1542 case 0x35: // BLT TRANSPARENT COLOR 0xff00
1543 case 0x38: // BLT TRANSPARENT COLOR MASK 0x00ff
1544 case 0x39: // BLT TRANSPARENT COLOR MASK 0xff00
1545 s
->vga
.gr
[reg_index
] = reg_value
;
1547 case 0x21: // BLT WIDTH 0x001f00
1548 case 0x23: // BLT HEIGHT 0x001f00
1549 case 0x25: // BLT DEST PITCH 0x001f00
1550 case 0x27: // BLT SRC PITCH 0x001f00
1551 s
->vga
.gr
[reg_index
] = reg_value
& 0x1f;
1553 case 0x2a: // BLT DEST ADDR 0x3f0000
1554 s
->vga
.gr
[reg_index
] = reg_value
& 0x3f;
1555 /* if auto start mode, starts bit blt now */
1556 if (s
->vga
.gr
[0x31] & CIRRUS_BLT_AUTOSTART
) {
1557 cirrus_bitblt_start(s
);
1560 case 0x2e: // BLT SRC ADDR 0x3f0000
1561 s
->vga
.gr
[reg_index
] = reg_value
& 0x3f;
1563 case 0x31: // BLT STATUS/START
1564 cirrus_write_bitblt(s
, reg_value
);
1568 printf("cirrus: outport gr_index %02x, gr_value %02x\n", reg_index
,
1575 /***************************************
1577 * I/O access between 0x3d4-0x3d5
1579 ***************************************/
1581 static int cirrus_vga_read_cr(CirrusVGAState
* s
, unsigned reg_index
)
1583 switch (reg_index
) {
1584 case 0x00: // Standard VGA
1585 case 0x01: // Standard VGA
1586 case 0x02: // Standard VGA
1587 case 0x03: // Standard VGA
1588 case 0x04: // Standard VGA
1589 case 0x05: // Standard VGA
1590 case 0x06: // Standard VGA
1591 case 0x07: // Standard VGA
1592 case 0x08: // Standard VGA
1593 case 0x09: // Standard VGA
1594 case 0x0a: // Standard VGA
1595 case 0x0b: // Standard VGA
1596 case 0x0c: // Standard VGA
1597 case 0x0d: // Standard VGA
1598 case 0x0e: // Standard VGA
1599 case 0x0f: // Standard VGA
1600 case 0x10: // Standard VGA
1601 case 0x11: // Standard VGA
1602 case 0x12: // Standard VGA
1603 case 0x13: // Standard VGA
1604 case 0x14: // Standard VGA
1605 case 0x15: // Standard VGA
1606 case 0x16: // Standard VGA
1607 case 0x17: // Standard VGA
1608 case 0x18: // Standard VGA
1609 return s
->vga
.cr
[s
->vga
.cr_index
];
1610 case 0x24: // Attribute Controller Toggle Readback (R)
1611 return (s
->vga
.ar_flip_flop
<< 7);
1612 case 0x19: // Interlace End
1613 case 0x1a: // Miscellaneous Control
1614 case 0x1b: // Extended Display Control
1615 case 0x1c: // Sync Adjust and Genlock
1616 case 0x1d: // Overlay Extended Control
1617 case 0x22: // Graphics Data Latches Readback (R)
1618 case 0x25: // Part Status
1619 case 0x27: // Part ID (R)
1620 return s
->vga
.cr
[s
->vga
.cr_index
];
1621 case 0x26: // Attribute Controller Index Readback (R)
1622 return s
->vga
.ar_index
& 0x3f;
1626 printf("cirrus: inport cr_index %02x\n", reg_index
);
1632 static void cirrus_vga_write_cr(CirrusVGAState
* s
, int reg_value
)
1634 switch (s
->vga
.cr_index
) {
1635 case 0x00: // Standard VGA
1636 case 0x01: // Standard VGA
1637 case 0x02: // Standard VGA
1638 case 0x03: // Standard VGA
1639 case 0x04: // Standard VGA
1640 case 0x05: // Standard VGA
1641 case 0x06: // Standard VGA
1642 case 0x07: // Standard VGA
1643 case 0x08: // Standard VGA
1644 case 0x09: // Standard VGA
1645 case 0x0a: // Standard VGA
1646 case 0x0b: // Standard VGA
1647 case 0x0c: // Standard VGA
1648 case 0x0d: // Standard VGA
1649 case 0x0e: // Standard VGA
1650 case 0x0f: // Standard VGA
1651 case 0x10: // Standard VGA
1652 case 0x11: // Standard VGA
1653 case 0x12: // Standard VGA
1654 case 0x13: // Standard VGA
1655 case 0x14: // Standard VGA
1656 case 0x15: // Standard VGA
1657 case 0x16: // Standard VGA
1658 case 0x17: // Standard VGA
1659 case 0x18: // Standard VGA
1660 /* handle CR0-7 protection */
1661 if ((s
->vga
.cr
[0x11] & 0x80) && s
->vga
.cr_index
<= 7) {
1662 /* can always write bit 4 of CR7 */
1663 if (s
->vga
.cr_index
== 7)
1664 s
->vga
.cr
[7] = (s
->vga
.cr
[7] & ~0x10) | (reg_value
& 0x10);
1667 s
->vga
.cr
[s
->vga
.cr_index
] = reg_value
;
1668 switch(s
->vga
.cr_index
) {
1676 s
->vga
.update_retrace_info(&s
->vga
);
1680 case 0x19: // Interlace End
1681 case 0x1a: // Miscellaneous Control
1682 case 0x1b: // Extended Display Control
1683 case 0x1c: // Sync Adjust and Genlock
1684 case 0x1d: // Overlay Extended Control
1685 s
->vga
.cr
[s
->vga
.cr_index
] = reg_value
;
1687 printf("cirrus: handled outport cr_index %02x, cr_value %02x\n",
1688 s
->vga
.cr_index
, reg_value
);
1691 case 0x22: // Graphics Data Latches Readback (R)
1692 case 0x24: // Attribute Controller Toggle Readback (R)
1693 case 0x26: // Attribute Controller Index Readback (R)
1694 case 0x27: // Part ID (R)
1696 case 0x25: // Part Status
1699 printf("cirrus: outport cr_index %02x, cr_value %02x\n",
1700 s
->vga
.cr_index
, reg_value
);
1706 /***************************************
1708 * memory-mapped I/O (bitblt)
1710 ***************************************/
1712 static uint8_t cirrus_mmio_blt_read(CirrusVGAState
* s
, unsigned address
)
1717 case (CIRRUS_MMIO_BLTBGCOLOR
+ 0):
1718 value
= cirrus_vga_read_gr(s
, 0x00);
1720 case (CIRRUS_MMIO_BLTBGCOLOR
+ 1):
1721 value
= cirrus_vga_read_gr(s
, 0x10);
1723 case (CIRRUS_MMIO_BLTBGCOLOR
+ 2):
1724 value
= cirrus_vga_read_gr(s
, 0x12);
1726 case (CIRRUS_MMIO_BLTBGCOLOR
+ 3):
1727 value
= cirrus_vga_read_gr(s
, 0x14);
1729 case (CIRRUS_MMIO_BLTFGCOLOR
+ 0):
1730 value
= cirrus_vga_read_gr(s
, 0x01);
1732 case (CIRRUS_MMIO_BLTFGCOLOR
+ 1):
1733 value
= cirrus_vga_read_gr(s
, 0x11);
1735 case (CIRRUS_MMIO_BLTFGCOLOR
+ 2):
1736 value
= cirrus_vga_read_gr(s
, 0x13);
1738 case (CIRRUS_MMIO_BLTFGCOLOR
+ 3):
1739 value
= cirrus_vga_read_gr(s
, 0x15);
1741 case (CIRRUS_MMIO_BLTWIDTH
+ 0):
1742 value
= cirrus_vga_read_gr(s
, 0x20);
1744 case (CIRRUS_MMIO_BLTWIDTH
+ 1):
1745 value
= cirrus_vga_read_gr(s
, 0x21);
1747 case (CIRRUS_MMIO_BLTHEIGHT
+ 0):
1748 value
= cirrus_vga_read_gr(s
, 0x22);
1750 case (CIRRUS_MMIO_BLTHEIGHT
+ 1):
1751 value
= cirrus_vga_read_gr(s
, 0x23);
1753 case (CIRRUS_MMIO_BLTDESTPITCH
+ 0):
1754 value
= cirrus_vga_read_gr(s
, 0x24);
1756 case (CIRRUS_MMIO_BLTDESTPITCH
+ 1):
1757 value
= cirrus_vga_read_gr(s
, 0x25);
1759 case (CIRRUS_MMIO_BLTSRCPITCH
+ 0):
1760 value
= cirrus_vga_read_gr(s
, 0x26);
1762 case (CIRRUS_MMIO_BLTSRCPITCH
+ 1):
1763 value
= cirrus_vga_read_gr(s
, 0x27);
1765 case (CIRRUS_MMIO_BLTDESTADDR
+ 0):
1766 value
= cirrus_vga_read_gr(s
, 0x28);
1768 case (CIRRUS_MMIO_BLTDESTADDR
+ 1):
1769 value
= cirrus_vga_read_gr(s
, 0x29);
1771 case (CIRRUS_MMIO_BLTDESTADDR
+ 2):
1772 value
= cirrus_vga_read_gr(s
, 0x2a);
1774 case (CIRRUS_MMIO_BLTSRCADDR
+ 0):
1775 value
= cirrus_vga_read_gr(s
, 0x2c);
1777 case (CIRRUS_MMIO_BLTSRCADDR
+ 1):
1778 value
= cirrus_vga_read_gr(s
, 0x2d);
1780 case (CIRRUS_MMIO_BLTSRCADDR
+ 2):
1781 value
= cirrus_vga_read_gr(s
, 0x2e);
1783 case CIRRUS_MMIO_BLTWRITEMASK
:
1784 value
= cirrus_vga_read_gr(s
, 0x2f);
1786 case CIRRUS_MMIO_BLTMODE
:
1787 value
= cirrus_vga_read_gr(s
, 0x30);
1789 case CIRRUS_MMIO_BLTROP
:
1790 value
= cirrus_vga_read_gr(s
, 0x32);
1792 case CIRRUS_MMIO_BLTMODEEXT
:
1793 value
= cirrus_vga_read_gr(s
, 0x33);
1795 case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR
+ 0):
1796 value
= cirrus_vga_read_gr(s
, 0x34);
1798 case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR
+ 1):
1799 value
= cirrus_vga_read_gr(s
, 0x35);
1801 case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK
+ 0):
1802 value
= cirrus_vga_read_gr(s
, 0x38);
1804 case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK
+ 1):
1805 value
= cirrus_vga_read_gr(s
, 0x39);
1807 case CIRRUS_MMIO_BLTSTATUS
:
1808 value
= cirrus_vga_read_gr(s
, 0x31);
1812 printf("cirrus: mmio read - address 0x%04x\n", address
);
1817 return (uint8_t) value
;
1820 static void cirrus_mmio_blt_write(CirrusVGAState
* s
, unsigned address
,
1824 case (CIRRUS_MMIO_BLTBGCOLOR
+ 0):
1825 cirrus_vga_write_gr(s
, 0x00, value
);
1827 case (CIRRUS_MMIO_BLTBGCOLOR
+ 1):
1828 cirrus_vga_write_gr(s
, 0x10, value
);
1830 case (CIRRUS_MMIO_BLTBGCOLOR
+ 2):
1831 cirrus_vga_write_gr(s
, 0x12, value
);
1833 case (CIRRUS_MMIO_BLTBGCOLOR
+ 3):
1834 cirrus_vga_write_gr(s
, 0x14, value
);
1836 case (CIRRUS_MMIO_BLTFGCOLOR
+ 0):
1837 cirrus_vga_write_gr(s
, 0x01, value
);
1839 case (CIRRUS_MMIO_BLTFGCOLOR
+ 1):
1840 cirrus_vga_write_gr(s
, 0x11, value
);
1842 case (CIRRUS_MMIO_BLTFGCOLOR
+ 2):
1843 cirrus_vga_write_gr(s
, 0x13, value
);
1845 case (CIRRUS_MMIO_BLTFGCOLOR
+ 3):
1846 cirrus_vga_write_gr(s
, 0x15, value
);
1848 case (CIRRUS_MMIO_BLTWIDTH
+ 0):
1849 cirrus_vga_write_gr(s
, 0x20, value
);
1851 case (CIRRUS_MMIO_BLTWIDTH
+ 1):
1852 cirrus_vga_write_gr(s
, 0x21, value
);
1854 case (CIRRUS_MMIO_BLTHEIGHT
+ 0):
1855 cirrus_vga_write_gr(s
, 0x22, value
);
1857 case (CIRRUS_MMIO_BLTHEIGHT
+ 1):
1858 cirrus_vga_write_gr(s
, 0x23, value
);
1860 case (CIRRUS_MMIO_BLTDESTPITCH
+ 0):
1861 cirrus_vga_write_gr(s
, 0x24, value
);
1863 case (CIRRUS_MMIO_BLTDESTPITCH
+ 1):
1864 cirrus_vga_write_gr(s
, 0x25, value
);
1866 case (CIRRUS_MMIO_BLTSRCPITCH
+ 0):
1867 cirrus_vga_write_gr(s
, 0x26, value
);
1869 case (CIRRUS_MMIO_BLTSRCPITCH
+ 1):
1870 cirrus_vga_write_gr(s
, 0x27, value
);
1872 case (CIRRUS_MMIO_BLTDESTADDR
+ 0):
1873 cirrus_vga_write_gr(s
, 0x28, value
);
1875 case (CIRRUS_MMIO_BLTDESTADDR
+ 1):
1876 cirrus_vga_write_gr(s
, 0x29, value
);
1878 case (CIRRUS_MMIO_BLTDESTADDR
+ 2):
1879 cirrus_vga_write_gr(s
, 0x2a, value
);
1881 case (CIRRUS_MMIO_BLTDESTADDR
+ 3):
1884 case (CIRRUS_MMIO_BLTSRCADDR
+ 0):
1885 cirrus_vga_write_gr(s
, 0x2c, value
);
1887 case (CIRRUS_MMIO_BLTSRCADDR
+ 1):
1888 cirrus_vga_write_gr(s
, 0x2d, value
);
1890 case (CIRRUS_MMIO_BLTSRCADDR
+ 2):
1891 cirrus_vga_write_gr(s
, 0x2e, value
);
1893 case CIRRUS_MMIO_BLTWRITEMASK
:
1894 cirrus_vga_write_gr(s
, 0x2f, value
);
1896 case CIRRUS_MMIO_BLTMODE
:
1897 cirrus_vga_write_gr(s
, 0x30, value
);
1899 case CIRRUS_MMIO_BLTROP
:
1900 cirrus_vga_write_gr(s
, 0x32, value
);
1902 case CIRRUS_MMIO_BLTMODEEXT
:
1903 cirrus_vga_write_gr(s
, 0x33, value
);
1905 case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR
+ 0):
1906 cirrus_vga_write_gr(s
, 0x34, value
);
1908 case (CIRRUS_MMIO_BLTTRANSPARENTCOLOR
+ 1):
1909 cirrus_vga_write_gr(s
, 0x35, value
);
1911 case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK
+ 0):
1912 cirrus_vga_write_gr(s
, 0x38, value
);
1914 case (CIRRUS_MMIO_BLTTRANSPARENTCOLORMASK
+ 1):
1915 cirrus_vga_write_gr(s
, 0x39, value
);
1917 case CIRRUS_MMIO_BLTSTATUS
:
1918 cirrus_vga_write_gr(s
, 0x31, value
);
1922 printf("cirrus: mmio write - addr 0x%04x val 0x%02x (ignored)\n",
1929 /***************************************
1933 * assume TARGET_PAGE_SIZE >= 16
1935 ***************************************/
1937 static void cirrus_mem_writeb_mode4and5_8bpp(CirrusVGAState
* s
,
1943 unsigned val
= mem_value
;
1946 dst
= s
->vga
.vram_ptr
+ (offset
&= s
->cirrus_addr_mask
);
1947 for (x
= 0; x
< 8; x
++) {
1949 *dst
= s
->cirrus_shadow_gr1
;
1950 } else if (mode
== 5) {
1951 *dst
= s
->cirrus_shadow_gr0
;
1956 cpu_physical_memory_set_dirty(s
->vga
.vram_offset
+ offset
);
1957 cpu_physical_memory_set_dirty(s
->vga
.vram_offset
+ offset
+ 7);
1960 static void cirrus_mem_writeb_mode4and5_16bpp(CirrusVGAState
* s
,
1966 unsigned val
= mem_value
;
1969 dst
= s
->vga
.vram_ptr
+ (offset
&= s
->cirrus_addr_mask
);
1970 for (x
= 0; x
< 8; x
++) {
1972 *dst
= s
->cirrus_shadow_gr1
;
1973 *(dst
+ 1) = s
->vga
.gr
[0x11];
1974 } else if (mode
== 5) {
1975 *dst
= s
->cirrus_shadow_gr0
;
1976 *(dst
+ 1) = s
->vga
.gr
[0x10];
1981 cpu_physical_memory_set_dirty(s
->vga
.vram_offset
+ offset
);
1982 cpu_physical_memory_set_dirty(s
->vga
.vram_offset
+ offset
+ 15);
1985 /***************************************
1987 * memory access between 0xa0000-0xbffff
1989 ***************************************/
1991 static uint32_t cirrus_vga_mem_readb(void *opaque
, target_phys_addr_t addr
)
1993 CirrusVGAState
*s
= opaque
;
1994 unsigned bank_index
;
1995 unsigned bank_offset
;
1998 if ((s
->vga
.sr
[0x07] & 0x01) == 0) {
1999 return vga_mem_readb(s
, addr
);
2004 if (addr
< 0x10000) {
2005 /* XXX handle bitblt */
2007 bank_index
= addr
>> 15;
2008 bank_offset
= addr
& 0x7fff;
2009 if (bank_offset
< s
->cirrus_bank_limit
[bank_index
]) {
2010 bank_offset
+= s
->cirrus_bank_base
[bank_index
];
2011 if ((s
->vga
.gr
[0x0B] & 0x14) == 0x14) {
2013 } else if (s
->vga
.gr
[0x0B] & 0x02) {
2016 bank_offset
&= s
->cirrus_addr_mask
;
2017 val
= *(s
->vga
.vram_ptr
+ bank_offset
);
2020 } else if (addr
>= 0x18000 && addr
< 0x18100) {
2021 /* memory-mapped I/O */
2023 if ((s
->vga
.sr
[0x17] & 0x44) == 0x04) {
2024 val
= cirrus_mmio_blt_read(s
, addr
& 0xff);
2029 printf("cirrus: mem_readb " TARGET_FMT_plx
"\n", addr
);
2035 static uint32_t cirrus_vga_mem_readw(void *opaque
, target_phys_addr_t addr
)
2038 #ifdef TARGET_WORDS_BIGENDIAN
2039 v
= cirrus_vga_mem_readb(opaque
, addr
) << 8;
2040 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 1);
2042 v
= cirrus_vga_mem_readb(opaque
, addr
);
2043 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 1) << 8;
2048 static uint32_t cirrus_vga_mem_readl(void *opaque
, target_phys_addr_t addr
)
2051 #ifdef TARGET_WORDS_BIGENDIAN
2052 v
= cirrus_vga_mem_readb(opaque
, addr
) << 24;
2053 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 1) << 16;
2054 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 2) << 8;
2055 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 3);
2057 v
= cirrus_vga_mem_readb(opaque
, addr
);
2058 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 1) << 8;
2059 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 2) << 16;
2060 v
|= cirrus_vga_mem_readb(opaque
, addr
+ 3) << 24;
2065 static void cirrus_vga_mem_writeb(void *opaque
, target_phys_addr_t addr
,
2068 CirrusVGAState
*s
= opaque
;
2069 unsigned bank_index
;
2070 unsigned bank_offset
;
2073 if ((s
->vga
.sr
[0x07] & 0x01) == 0) {
2074 vga_mem_writeb(s
, addr
, mem_value
);
2080 if (addr
< 0x10000) {
2081 if (s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
) {
2083 *s
->cirrus_srcptr
++ = (uint8_t) mem_value
;
2084 if (s
->cirrus_srcptr
>= s
->cirrus_srcptr_end
) {
2085 cirrus_bitblt_cputovideo_next(s
);
2089 bank_index
= addr
>> 15;
2090 bank_offset
= addr
& 0x7fff;
2091 if (bank_offset
< s
->cirrus_bank_limit
[bank_index
]) {
2092 bank_offset
+= s
->cirrus_bank_base
[bank_index
];
2093 if ((s
->vga
.gr
[0x0B] & 0x14) == 0x14) {
2095 } else if (s
->vga
.gr
[0x0B] & 0x02) {
2098 bank_offset
&= s
->cirrus_addr_mask
;
2099 mode
= s
->vga
.gr
[0x05] & 0x7;
2100 if (mode
< 4 || mode
> 5 || ((s
->vga
.gr
[0x0B] & 0x4) == 0)) {
2101 *(s
->vga
.vram_ptr
+ bank_offset
) = mem_value
;
2102 cpu_physical_memory_set_dirty(s
->vga
.vram_offset
+
2105 if ((s
->vga
.gr
[0x0B] & 0x14) != 0x14) {
2106 cirrus_mem_writeb_mode4and5_8bpp(s
, mode
,
2110 cirrus_mem_writeb_mode4and5_16bpp(s
, mode
,
2117 } else if (addr
>= 0x18000 && addr
< 0x18100) {
2118 /* memory-mapped I/O */
2119 if ((s
->vga
.sr
[0x17] & 0x44) == 0x04) {
2120 cirrus_mmio_blt_write(s
, addr
& 0xff, mem_value
);
2124 printf("cirrus: mem_writeb " TARGET_FMT_plx
" value %02x\n", addr
,
2130 static void cirrus_vga_mem_writew(void *opaque
, target_phys_addr_t addr
, uint32_t val
)
2132 #ifdef TARGET_WORDS_BIGENDIAN
2133 cirrus_vga_mem_writeb(opaque
, addr
, (val
>> 8) & 0xff);
2134 cirrus_vga_mem_writeb(opaque
, addr
+ 1, val
& 0xff);
2136 cirrus_vga_mem_writeb(opaque
, addr
, val
& 0xff);
2137 cirrus_vga_mem_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2141 static void cirrus_vga_mem_writel(void *opaque
, target_phys_addr_t addr
, uint32_t val
)
2143 #ifdef TARGET_WORDS_BIGENDIAN
2144 cirrus_vga_mem_writeb(opaque
, addr
, (val
>> 24) & 0xff);
2145 cirrus_vga_mem_writeb(opaque
, addr
+ 1, (val
>> 16) & 0xff);
2146 cirrus_vga_mem_writeb(opaque
, addr
+ 2, (val
>> 8) & 0xff);
2147 cirrus_vga_mem_writeb(opaque
, addr
+ 3, val
& 0xff);
2149 cirrus_vga_mem_writeb(opaque
, addr
, val
& 0xff);
2150 cirrus_vga_mem_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2151 cirrus_vga_mem_writeb(opaque
, addr
+ 2, (val
>> 16) & 0xff);
2152 cirrus_vga_mem_writeb(opaque
, addr
+ 3, (val
>> 24) & 0xff);
2156 static CPUReadMemoryFunc
* const cirrus_vga_mem_read
[3] = {
2157 cirrus_vga_mem_readb
,
2158 cirrus_vga_mem_readw
,
2159 cirrus_vga_mem_readl
,
2162 static CPUWriteMemoryFunc
* const cirrus_vga_mem_write
[3] = {
2163 cirrus_vga_mem_writeb
,
2164 cirrus_vga_mem_writew
,
2165 cirrus_vga_mem_writel
,
2168 /***************************************
2172 ***************************************/
2174 static inline void invalidate_cursor1(CirrusVGAState
*s
)
2176 if (s
->last_hw_cursor_size
) {
2177 vga_invalidate_scanlines(&s
->vga
,
2178 s
->last_hw_cursor_y
+ s
->last_hw_cursor_y_start
,
2179 s
->last_hw_cursor_y
+ s
->last_hw_cursor_y_end
);
2183 static inline void cirrus_cursor_compute_yrange(CirrusVGAState
*s
)
2187 int y
, y_min
, y_max
;
2189 src
= s
->vga
.vram_ptr
+ s
->real_vram_size
- 16 * 1024;
2190 if (s
->vga
.sr
[0x12] & CIRRUS_CURSOR_LARGE
) {
2191 src
+= (s
->vga
.sr
[0x13] & 0x3c) * 256;
2194 for(y
= 0; y
< 64; y
++) {
2195 content
= ((uint32_t *)src
)[0] |
2196 ((uint32_t *)src
)[1] |
2197 ((uint32_t *)src
)[2] |
2198 ((uint32_t *)src
)[3];
2208 src
+= (s
->vga
.sr
[0x13] & 0x3f) * 256;
2211 for(y
= 0; y
< 32; y
++) {
2212 content
= ((uint32_t *)src
)[0] |
2213 ((uint32_t *)(src
+ 128))[0];
2223 if (y_min
> y_max
) {
2224 s
->last_hw_cursor_y_start
= 0;
2225 s
->last_hw_cursor_y_end
= 0;
2227 s
->last_hw_cursor_y_start
= y_min
;
2228 s
->last_hw_cursor_y_end
= y_max
+ 1;
2232 /* NOTE: we do not currently handle the cursor bitmap change, so we
2233 update the cursor only if it moves. */
2234 static void cirrus_cursor_invalidate(VGACommonState
*s1
)
2236 CirrusVGAState
*s
= container_of(s1
, CirrusVGAState
, vga
);
2239 if (!(s
->vga
.sr
[0x12] & CIRRUS_CURSOR_SHOW
)) {
2242 if (s
->vga
.sr
[0x12] & CIRRUS_CURSOR_LARGE
)
2247 /* invalidate last cursor and new cursor if any change */
2248 if (s
->last_hw_cursor_size
!= size
||
2249 s
->last_hw_cursor_x
!= s
->hw_cursor_x
||
2250 s
->last_hw_cursor_y
!= s
->hw_cursor_y
) {
2252 invalidate_cursor1(s
);
2254 s
->last_hw_cursor_size
= size
;
2255 s
->last_hw_cursor_x
= s
->hw_cursor_x
;
2256 s
->last_hw_cursor_y
= s
->hw_cursor_y
;
2257 /* compute the real cursor min and max y */
2258 cirrus_cursor_compute_yrange(s
);
2259 invalidate_cursor1(s
);
2263 static void cirrus_cursor_draw_line(VGACommonState
*s1
, uint8_t *d1
, int scr_y
)
2265 CirrusVGAState
*s
= container_of(s1
, CirrusVGAState
, vga
);
2266 int w
, h
, bpp
, x1
, x2
, poffset
;
2267 unsigned int color0
, color1
;
2268 const uint8_t *palette
, *src
;
2271 if (!(s
->vga
.sr
[0x12] & CIRRUS_CURSOR_SHOW
))
2273 /* fast test to see if the cursor intersects with the scan line */
2274 if (s
->vga
.sr
[0x12] & CIRRUS_CURSOR_LARGE
) {
2279 if (scr_y
< s
->hw_cursor_y
||
2280 scr_y
>= (s
->hw_cursor_y
+ h
))
2283 src
= s
->vga
.vram_ptr
+ s
->real_vram_size
- 16 * 1024;
2284 if (s
->vga
.sr
[0x12] & CIRRUS_CURSOR_LARGE
) {
2285 src
+= (s
->vga
.sr
[0x13] & 0x3c) * 256;
2286 src
+= (scr_y
- s
->hw_cursor_y
) * 16;
2288 content
= ((uint32_t *)src
)[0] |
2289 ((uint32_t *)src
)[1] |
2290 ((uint32_t *)src
)[2] |
2291 ((uint32_t *)src
)[3];
2293 src
+= (s
->vga
.sr
[0x13] & 0x3f) * 256;
2294 src
+= (scr_y
- s
->hw_cursor_y
) * 4;
2296 content
= ((uint32_t *)src
)[0] |
2297 ((uint32_t *)(src
+ 128))[0];
2299 /* if nothing to draw, no need to continue */
2304 x1
= s
->hw_cursor_x
;
2305 if (x1
>= s
->vga
.last_scr_width
)
2307 x2
= s
->hw_cursor_x
+ w
;
2308 if (x2
> s
->vga
.last_scr_width
)
2309 x2
= s
->vga
.last_scr_width
;
2311 palette
= s
->cirrus_hidden_palette
;
2312 color0
= s
->vga
.rgb_to_pixel(c6_to_8(palette
[0x0 * 3]),
2313 c6_to_8(palette
[0x0 * 3 + 1]),
2314 c6_to_8(palette
[0x0 * 3 + 2]));
2315 color1
= s
->vga
.rgb_to_pixel(c6_to_8(palette
[0xf * 3]),
2316 c6_to_8(palette
[0xf * 3 + 1]),
2317 c6_to_8(palette
[0xf * 3 + 2]));
2318 bpp
= ((ds_get_bits_per_pixel(s
->vga
.ds
) + 7) >> 3);
2320 switch(ds_get_bits_per_pixel(s
->vga
.ds
)) {
2324 vga_draw_cursor_line_8(d1
, src
, poffset
, w
, color0
, color1
, 0xff);
2327 vga_draw_cursor_line_16(d1
, src
, poffset
, w
, color0
, color1
, 0x7fff);
2330 vga_draw_cursor_line_16(d1
, src
, poffset
, w
, color0
, color1
, 0xffff);
2333 vga_draw_cursor_line_32(d1
, src
, poffset
, w
, color0
, color1
, 0xffffff);
2338 /***************************************
2342 ***************************************/
2344 static uint32_t cirrus_linear_readb(void *opaque
, target_phys_addr_t addr
)
2346 CirrusVGAState
*s
= opaque
;
2349 addr
&= s
->cirrus_addr_mask
;
2351 if (((s
->vga
.sr
[0x17] & 0x44) == 0x44) &&
2352 ((addr
& s
->linear_mmio_mask
) == s
->linear_mmio_mask
)) {
2353 /* memory-mapped I/O */
2354 ret
= cirrus_mmio_blt_read(s
, addr
& 0xff);
2356 /* XXX handle bitblt */
2360 if ((s
->vga
.gr
[0x0B] & 0x14) == 0x14) {
2362 } else if (s
->vga
.gr
[0x0B] & 0x02) {
2365 addr
&= s
->cirrus_addr_mask
;
2366 ret
= *(s
->vga
.vram_ptr
+ addr
);
2372 static uint32_t cirrus_linear_readw(void *opaque
, target_phys_addr_t addr
)
2375 #ifdef TARGET_WORDS_BIGENDIAN
2376 v
= cirrus_linear_readb(opaque
, addr
) << 8;
2377 v
|= cirrus_linear_readb(opaque
, addr
+ 1);
2379 v
= cirrus_linear_readb(opaque
, addr
);
2380 v
|= cirrus_linear_readb(opaque
, addr
+ 1) << 8;
2385 static uint32_t cirrus_linear_readl(void *opaque
, target_phys_addr_t addr
)
2388 #ifdef TARGET_WORDS_BIGENDIAN
2389 v
= cirrus_linear_readb(opaque
, addr
) << 24;
2390 v
|= cirrus_linear_readb(opaque
, addr
+ 1) << 16;
2391 v
|= cirrus_linear_readb(opaque
, addr
+ 2) << 8;
2392 v
|= cirrus_linear_readb(opaque
, addr
+ 3);
2394 v
= cirrus_linear_readb(opaque
, addr
);
2395 v
|= cirrus_linear_readb(opaque
, addr
+ 1) << 8;
2396 v
|= cirrus_linear_readb(opaque
, addr
+ 2) << 16;
2397 v
|= cirrus_linear_readb(opaque
, addr
+ 3) << 24;
2402 static void cirrus_linear_writeb(void *opaque
, target_phys_addr_t addr
,
2405 CirrusVGAState
*s
= opaque
;
2408 addr
&= s
->cirrus_addr_mask
;
2410 if (((s
->vga
.sr
[0x17] & 0x44) == 0x44) &&
2411 ((addr
& s
->linear_mmio_mask
) == s
->linear_mmio_mask
)) {
2412 /* memory-mapped I/O */
2413 cirrus_mmio_blt_write(s
, addr
& 0xff, val
);
2414 } else if (s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
) {
2416 *s
->cirrus_srcptr
++ = (uint8_t) val
;
2417 if (s
->cirrus_srcptr
>= s
->cirrus_srcptr_end
) {
2418 cirrus_bitblt_cputovideo_next(s
);
2422 if ((s
->vga
.gr
[0x0B] & 0x14) == 0x14) {
2424 } else if (s
->vga
.gr
[0x0B] & 0x02) {
2427 addr
&= s
->cirrus_addr_mask
;
2429 mode
= s
->vga
.gr
[0x05] & 0x7;
2430 if (mode
< 4 || mode
> 5 || ((s
->vga
.gr
[0x0B] & 0x4) == 0)) {
2431 *(s
->vga
.vram_ptr
+ addr
) = (uint8_t) val
;
2432 cpu_physical_memory_set_dirty(s
->vga
.vram_offset
+ addr
);
2434 if ((s
->vga
.gr
[0x0B] & 0x14) != 0x14) {
2435 cirrus_mem_writeb_mode4and5_8bpp(s
, mode
, addr
, val
);
2437 cirrus_mem_writeb_mode4and5_16bpp(s
, mode
, addr
, val
);
2443 static void cirrus_linear_writew(void *opaque
, target_phys_addr_t addr
,
2446 #ifdef TARGET_WORDS_BIGENDIAN
2447 cirrus_linear_writeb(opaque
, addr
, (val
>> 8) & 0xff);
2448 cirrus_linear_writeb(opaque
, addr
+ 1, val
& 0xff);
2450 cirrus_linear_writeb(opaque
, addr
, val
& 0xff);
2451 cirrus_linear_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2455 static void cirrus_linear_writel(void *opaque
, target_phys_addr_t addr
,
2458 #ifdef TARGET_WORDS_BIGENDIAN
2459 cirrus_linear_writeb(opaque
, addr
, (val
>> 24) & 0xff);
2460 cirrus_linear_writeb(opaque
, addr
+ 1, (val
>> 16) & 0xff);
2461 cirrus_linear_writeb(opaque
, addr
+ 2, (val
>> 8) & 0xff);
2462 cirrus_linear_writeb(opaque
, addr
+ 3, val
& 0xff);
2464 cirrus_linear_writeb(opaque
, addr
, val
& 0xff);
2465 cirrus_linear_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2466 cirrus_linear_writeb(opaque
, addr
+ 2, (val
>> 16) & 0xff);
2467 cirrus_linear_writeb(opaque
, addr
+ 3, (val
>> 24) & 0xff);
2472 static CPUReadMemoryFunc
* const cirrus_linear_read
[3] = {
2473 cirrus_linear_readb
,
2474 cirrus_linear_readw
,
2475 cirrus_linear_readl
,
2478 static CPUWriteMemoryFunc
* const cirrus_linear_write
[3] = {
2479 cirrus_linear_writeb
,
2480 cirrus_linear_writew
,
2481 cirrus_linear_writel
,
2484 /***************************************
2486 * system to screen memory access
2488 ***************************************/
2491 static uint32_t cirrus_linear_bitblt_readb(void *opaque
, target_phys_addr_t addr
)
2495 /* XXX handle bitblt */
2500 static uint32_t cirrus_linear_bitblt_readw(void *opaque
, target_phys_addr_t addr
)
2503 #ifdef TARGET_WORDS_BIGENDIAN
2504 v
= cirrus_linear_bitblt_readb(opaque
, addr
) << 8;
2505 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 1);
2507 v
= cirrus_linear_bitblt_readb(opaque
, addr
);
2508 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 1) << 8;
2513 static uint32_t cirrus_linear_bitblt_readl(void *opaque
, target_phys_addr_t addr
)
2516 #ifdef TARGET_WORDS_BIGENDIAN
2517 v
= cirrus_linear_bitblt_readb(opaque
, addr
) << 24;
2518 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 1) << 16;
2519 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 2) << 8;
2520 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 3);
2522 v
= cirrus_linear_bitblt_readb(opaque
, addr
);
2523 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 1) << 8;
2524 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 2) << 16;
2525 v
|= cirrus_linear_bitblt_readb(opaque
, addr
+ 3) << 24;
2530 static void cirrus_linear_bitblt_writeb(void *opaque
, target_phys_addr_t addr
,
2533 CirrusVGAState
*s
= opaque
;
2535 if (s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
) {
2537 *s
->cirrus_srcptr
++ = (uint8_t) val
;
2538 if (s
->cirrus_srcptr
>= s
->cirrus_srcptr_end
) {
2539 cirrus_bitblt_cputovideo_next(s
);
2544 static void cirrus_linear_bitblt_writew(void *opaque
, target_phys_addr_t addr
,
2547 #ifdef TARGET_WORDS_BIGENDIAN
2548 cirrus_linear_bitblt_writeb(opaque
, addr
, (val
>> 8) & 0xff);
2549 cirrus_linear_bitblt_writeb(opaque
, addr
+ 1, val
& 0xff);
2551 cirrus_linear_bitblt_writeb(opaque
, addr
, val
& 0xff);
2552 cirrus_linear_bitblt_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2556 static void cirrus_linear_bitblt_writel(void *opaque
, target_phys_addr_t addr
,
2559 #ifdef TARGET_WORDS_BIGENDIAN
2560 cirrus_linear_bitblt_writeb(opaque
, addr
, (val
>> 24) & 0xff);
2561 cirrus_linear_bitblt_writeb(opaque
, addr
+ 1, (val
>> 16) & 0xff);
2562 cirrus_linear_bitblt_writeb(opaque
, addr
+ 2, (val
>> 8) & 0xff);
2563 cirrus_linear_bitblt_writeb(opaque
, addr
+ 3, val
& 0xff);
2565 cirrus_linear_bitblt_writeb(opaque
, addr
, val
& 0xff);
2566 cirrus_linear_bitblt_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2567 cirrus_linear_bitblt_writeb(opaque
, addr
+ 2, (val
>> 16) & 0xff);
2568 cirrus_linear_bitblt_writeb(opaque
, addr
+ 3, (val
>> 24) & 0xff);
2573 static CPUReadMemoryFunc
* const cirrus_linear_bitblt_read
[3] = {
2574 cirrus_linear_bitblt_readb
,
2575 cirrus_linear_bitblt_readw
,
2576 cirrus_linear_bitblt_readl
,
2579 static CPUWriteMemoryFunc
* const cirrus_linear_bitblt_write
[3] = {
2580 cirrus_linear_bitblt_writeb
,
2581 cirrus_linear_bitblt_writew
,
2582 cirrus_linear_bitblt_writel
,
2585 static void map_linear_vram(CirrusVGAState
*s
)
2587 if (!s
->vga
.map_addr
&& s
->vga
.lfb_addr
&& s
->vga
.lfb_end
) {
2588 s
->vga
.map_addr
= s
->vga
.lfb_addr
;
2589 s
->vga
.map_end
= s
->vga
.lfb_end
;
2590 cpu_register_physical_memory(s
->vga
.map_addr
, s
->vga
.map_end
- s
->vga
.map_addr
, s
->vga
.vram_offset
);
2593 if (!s
->vga
.map_addr
)
2596 s
->vga
.lfb_vram_mapped
= 0;
2598 if (!(s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
)
2599 && !((s
->vga
.sr
[0x07] & 0x01) == 0)
2600 && !((s
->vga
.gr
[0x0B] & 0x14) == 0x14)
2601 && !(s
->vga
.gr
[0x0B] & 0x02)) {
2603 cpu_register_physical_memory(isa_mem_base
+ 0xa0000, 0x8000,
2604 (s
->vga
.vram_offset
+ s
->cirrus_bank_base
[0]) | IO_MEM_RAM
);
2605 cpu_register_physical_memory(isa_mem_base
+ 0xa8000, 0x8000,
2606 (s
->vga
.vram_offset
+ s
->cirrus_bank_base
[1]) | IO_MEM_RAM
);
2608 s
->vga
.lfb_vram_mapped
= 1;
2611 cpu_register_physical_memory(isa_mem_base
+ 0xa0000, 0x20000,
2612 s
->vga
.vga_io_memory
);
2615 vga_dirty_log_start(&s
->vga
);
2618 static void unmap_linear_vram(CirrusVGAState
*s
)
2620 if (s
->vga
.map_addr
&& s
->vga
.lfb_addr
&& s
->vga
.lfb_end
)
2621 s
->vga
.map_addr
= s
->vga
.map_end
= 0;
2623 cpu_register_physical_memory(isa_mem_base
+ 0xa0000, 0x20000,
2624 s
->vga
.vga_io_memory
);
2627 /* Compute the memory access functions */
2628 static void cirrus_update_memory_access(CirrusVGAState
*s
)
2632 if ((s
->vga
.sr
[0x17] & 0x44) == 0x44) {
2634 } else if (s
->cirrus_srcptr
!= s
->cirrus_srcptr_end
) {
2637 if ((s
->vga
.gr
[0x0B] & 0x14) == 0x14) {
2639 } else if (s
->vga
.gr
[0x0B] & 0x02) {
2643 mode
= s
->vga
.gr
[0x05] & 0x7;
2644 if (mode
< 4 || mode
> 5 || ((s
->vga
.gr
[0x0B] & 0x4) == 0)) {
2648 unmap_linear_vram(s
);
2656 static uint32_t cirrus_vga_ioport_read(void *opaque
, uint32_t addr
)
2658 CirrusVGAState
*c
= opaque
;
2659 VGACommonState
*s
= &c
->vga
;
2662 if (vga_ioport_invalid(s
, addr
)) {
2667 if (s
->ar_flip_flop
== 0) {
2674 index
= s
->ar_index
& 0x1f;
2687 val
= cirrus_vga_read_sr(c
);
2689 #ifdef DEBUG_VGA_REG
2690 printf("vga: read SR%x = 0x%02x\n", s
->sr_index
, val
);
2694 val
= cirrus_read_hidden_dac(c
);
2700 val
= s
->dac_write_index
;
2701 c
->cirrus_hidden_dac_lockindex
= 0;
2704 val
= cirrus_vga_read_palette(c
);
2716 val
= cirrus_vga_read_gr(c
, s
->gr_index
);
2717 #ifdef DEBUG_VGA_REG
2718 printf("vga: read GR%x = 0x%02x\n", s
->gr_index
, val
);
2727 val
= cirrus_vga_read_cr(c
, s
->cr_index
);
2728 #ifdef DEBUG_VGA_REG
2729 printf("vga: read CR%x = 0x%02x\n", s
->cr_index
, val
);
2734 /* just toggle to fool polling */
2735 val
= s
->st01
= s
->retrace(s
);
2736 s
->ar_flip_flop
= 0;
2743 #if defined(DEBUG_VGA)
2744 printf("VGA: read addr=0x%04x data=0x%02x\n", addr
, val
);
2749 static void cirrus_vga_ioport_write(void *opaque
, uint32_t addr
, uint32_t val
)
2751 CirrusVGAState
*c
= opaque
;
2752 VGACommonState
*s
= &c
->vga
;
2755 /* check port range access depending on color/monochrome mode */
2756 if (vga_ioport_invalid(s
, addr
)) {
2760 printf("VGA: write addr=0x%04x data=0x%02x\n", addr
, val
);
2765 if (s
->ar_flip_flop
== 0) {
2769 index
= s
->ar_index
& 0x1f;
2772 s
->ar
[index
] = val
& 0x3f;
2775 s
->ar
[index
] = val
& ~0x10;
2781 s
->ar
[index
] = val
& ~0xc0;
2784 s
->ar
[index
] = val
& ~0xf0;
2787 s
->ar
[index
] = val
& ~0xf0;
2793 s
->ar_flip_flop
^= 1;
2796 s
->msr
= val
& ~0x10;
2797 s
->update_retrace_info(s
);
2803 #ifdef DEBUG_VGA_REG
2804 printf("vga: write SR%x = 0x%02x\n", s
->sr_index
, val
);
2806 cirrus_vga_write_sr(c
, val
);
2810 cirrus_write_hidden_dac(c
, val
);
2813 s
->dac_read_index
= val
;
2814 s
->dac_sub_index
= 0;
2818 s
->dac_write_index
= val
;
2819 s
->dac_sub_index
= 0;
2823 cirrus_vga_write_palette(c
, val
);
2829 #ifdef DEBUG_VGA_REG
2830 printf("vga: write GR%x = 0x%02x\n", s
->gr_index
, val
);
2832 cirrus_vga_write_gr(c
, s
->gr_index
, val
);
2840 #ifdef DEBUG_VGA_REG
2841 printf("vga: write CR%x = 0x%02x\n", s
->cr_index
, val
);
2843 cirrus_vga_write_cr(c
, val
);
2847 s
->fcr
= val
& 0x10;
2852 /***************************************
2854 * memory-mapped I/O access
2856 ***************************************/
2858 static uint32_t cirrus_mmio_readb(void *opaque
, target_phys_addr_t addr
)
2860 CirrusVGAState
*s
= opaque
;
2862 addr
&= CIRRUS_PNPMMIO_SIZE
- 1;
2864 if (addr
>= 0x100) {
2865 return cirrus_mmio_blt_read(s
, addr
- 0x100);
2867 return cirrus_vga_ioport_read(s
, addr
+ 0x3c0);
2871 static uint32_t cirrus_mmio_readw(void *opaque
, target_phys_addr_t addr
)
2874 #ifdef TARGET_WORDS_BIGENDIAN
2875 v
= cirrus_mmio_readb(opaque
, addr
) << 8;
2876 v
|= cirrus_mmio_readb(opaque
, addr
+ 1);
2878 v
= cirrus_mmio_readb(opaque
, addr
);
2879 v
|= cirrus_mmio_readb(opaque
, addr
+ 1) << 8;
2884 static uint32_t cirrus_mmio_readl(void *opaque
, target_phys_addr_t addr
)
2887 #ifdef TARGET_WORDS_BIGENDIAN
2888 v
= cirrus_mmio_readb(opaque
, addr
) << 24;
2889 v
|= cirrus_mmio_readb(opaque
, addr
+ 1) << 16;
2890 v
|= cirrus_mmio_readb(opaque
, addr
+ 2) << 8;
2891 v
|= cirrus_mmio_readb(opaque
, addr
+ 3);
2893 v
= cirrus_mmio_readb(opaque
, addr
);
2894 v
|= cirrus_mmio_readb(opaque
, addr
+ 1) << 8;
2895 v
|= cirrus_mmio_readb(opaque
, addr
+ 2) << 16;
2896 v
|= cirrus_mmio_readb(opaque
, addr
+ 3) << 24;
2901 static void cirrus_mmio_writeb(void *opaque
, target_phys_addr_t addr
,
2904 CirrusVGAState
*s
= opaque
;
2906 addr
&= CIRRUS_PNPMMIO_SIZE
- 1;
2908 if (addr
>= 0x100) {
2909 cirrus_mmio_blt_write(s
, addr
- 0x100, val
);
2911 cirrus_vga_ioport_write(s
, addr
+ 0x3c0, val
);
2915 static void cirrus_mmio_writew(void *opaque
, target_phys_addr_t addr
,
2918 #ifdef TARGET_WORDS_BIGENDIAN
2919 cirrus_mmio_writeb(opaque
, addr
, (val
>> 8) & 0xff);
2920 cirrus_mmio_writeb(opaque
, addr
+ 1, val
& 0xff);
2922 cirrus_mmio_writeb(opaque
, addr
, val
& 0xff);
2923 cirrus_mmio_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2927 static void cirrus_mmio_writel(void *opaque
, target_phys_addr_t addr
,
2930 #ifdef TARGET_WORDS_BIGENDIAN
2931 cirrus_mmio_writeb(opaque
, addr
, (val
>> 24) & 0xff);
2932 cirrus_mmio_writeb(opaque
, addr
+ 1, (val
>> 16) & 0xff);
2933 cirrus_mmio_writeb(opaque
, addr
+ 2, (val
>> 8) & 0xff);
2934 cirrus_mmio_writeb(opaque
, addr
+ 3, val
& 0xff);
2936 cirrus_mmio_writeb(opaque
, addr
, val
& 0xff);
2937 cirrus_mmio_writeb(opaque
, addr
+ 1, (val
>> 8) & 0xff);
2938 cirrus_mmio_writeb(opaque
, addr
+ 2, (val
>> 16) & 0xff);
2939 cirrus_mmio_writeb(opaque
, addr
+ 3, (val
>> 24) & 0xff);
2944 static CPUReadMemoryFunc
* const cirrus_mmio_read
[3] = {
2950 static CPUWriteMemoryFunc
* const cirrus_mmio_write
[3] = {
2956 /* load/save state */
2958 static void cirrus_vga_save(QEMUFile
*f
, void *opaque
)
2960 CirrusVGAState
*s
= opaque
;
2962 qemu_put_be32s(f
, &s
->vga
.latch
);
2963 qemu_put_8s(f
, &s
->vga
.sr_index
);
2964 qemu_put_buffer(f
, s
->vga
.sr
, 256);
2965 qemu_put_8s(f
, &s
->vga
.gr_index
);
2966 qemu_put_8s(f
, &s
->cirrus_shadow_gr0
);
2967 qemu_put_8s(f
, &s
->cirrus_shadow_gr1
);
2968 qemu_put_buffer(f
, s
->vga
.gr
+ 2, 254);
2969 qemu_put_8s(f
, &s
->vga
.ar_index
);
2970 qemu_put_buffer(f
, s
->vga
.ar
, 21);
2971 qemu_put_be32(f
, s
->vga
.ar_flip_flop
);
2972 qemu_put_8s(f
, &s
->vga
.cr_index
);
2973 qemu_put_buffer(f
, s
->vga
.cr
, 256);
2974 qemu_put_8s(f
, &s
->vga
.msr
);
2975 qemu_put_8s(f
, &s
->vga
.fcr
);
2976 qemu_put_8s(f
, &s
->vga
.st00
);
2977 qemu_put_8s(f
, &s
->vga
.st01
);
2979 qemu_put_8s(f
, &s
->vga
.dac_state
);
2980 qemu_put_8s(f
, &s
->vga
.dac_sub_index
);
2981 qemu_put_8s(f
, &s
->vga
.dac_read_index
);
2982 qemu_put_8s(f
, &s
->vga
.dac_write_index
);
2983 qemu_put_buffer(f
, s
->vga
.dac_cache
, 3);
2984 qemu_put_buffer(f
, s
->vga
.palette
, 768);
2986 qemu_put_be32(f
, s
->vga
.bank_offset
);
2988 qemu_put_8s(f
, &s
->cirrus_hidden_dac_lockindex
);
2989 qemu_put_8s(f
, &s
->cirrus_hidden_dac_data
);
2991 qemu_put_be32s(f
, &s
->hw_cursor_x
);
2992 qemu_put_be32s(f
, &s
->hw_cursor_y
);
2993 /* XXX: we do not save the bitblt state - we assume we do not save
2994 the state when the blitter is active */
2997 static int cirrus_vga_load(QEMUFile
*f
, void *opaque
, int version_id
)
2999 CirrusVGAState
*s
= opaque
;
3004 qemu_get_be32s(f
, &s
->vga
.latch
);
3005 qemu_get_8s(f
, &s
->vga
.sr_index
);
3006 qemu_get_buffer(f
, s
->vga
.sr
, 256);
3007 qemu_get_8s(f
, &s
->vga
.gr_index
);
3008 qemu_get_8s(f
, &s
->cirrus_shadow_gr0
);
3009 qemu_get_8s(f
, &s
->cirrus_shadow_gr1
);
3010 s
->vga
.gr
[0x00] = s
->cirrus_shadow_gr0
& 0x0f;
3011 s
->vga
.gr
[0x01] = s
->cirrus_shadow_gr1
& 0x0f;
3012 qemu_get_buffer(f
, s
->vga
.gr
+ 2, 254);
3013 qemu_get_8s(f
, &s
->vga
.ar_index
);
3014 qemu_get_buffer(f
, s
->vga
.ar
, 21);
3015 s
->vga
.ar_flip_flop
=qemu_get_be32(f
);
3016 qemu_get_8s(f
, &s
->vga
.cr_index
);
3017 qemu_get_buffer(f
, s
->vga
.cr
, 256);
3018 qemu_get_8s(f
, &s
->vga
.msr
);
3019 qemu_get_8s(f
, &s
->vga
.fcr
);
3020 qemu_get_8s(f
, &s
->vga
.st00
);
3021 qemu_get_8s(f
, &s
->vga
.st01
);
3023 qemu_get_8s(f
, &s
->vga
.dac_state
);
3024 qemu_get_8s(f
, &s
->vga
.dac_sub_index
);
3025 qemu_get_8s(f
, &s
->vga
.dac_read_index
);
3026 qemu_get_8s(f
, &s
->vga
.dac_write_index
);
3027 qemu_get_buffer(f
, s
->vga
.dac_cache
, 3);
3028 qemu_get_buffer(f
, s
->vga
.palette
, 768);
3030 s
->vga
.bank_offset
= qemu_get_be32(f
);
3032 qemu_get_8s(f
, &s
->cirrus_hidden_dac_lockindex
);
3033 qemu_get_8s(f
, &s
->cirrus_hidden_dac_data
);
3035 qemu_get_be32s(f
, &s
->hw_cursor_x
);
3036 qemu_get_be32s(f
, &s
->hw_cursor_y
);
3038 cirrus_update_memory_access(s
);
3040 s
->vga
.graphic_mode
= -1;
3041 cirrus_update_bank_ptr(s
, 0);
3042 cirrus_update_bank_ptr(s
, 1);
3046 static void pci_cirrus_vga_save(QEMUFile
*f
, void *opaque
)
3048 PCICirrusVGAState
*s
= opaque
;
3050 pci_device_save(&s
->dev
, f
);
3051 cirrus_vga_save(f
, &s
->cirrus_vga
);
3054 static int pci_cirrus_vga_load(QEMUFile
*f
, void *opaque
, int version_id
)
3056 PCICirrusVGAState
*s
= opaque
;
3062 if (version_id
>= 2) {
3063 ret
= pci_device_load(&s
->dev
, f
);
3068 return cirrus_vga_load(f
, &s
->cirrus_vga
, version_id
);
3071 /***************************************
3075 ***************************************/
3077 static void cirrus_reset(void *opaque
)
3079 CirrusVGAState
*s
= opaque
;
3081 vga_common_reset(&s
->vga
);
3082 unmap_linear_vram(s
);
3083 s
->vga
.sr
[0x06] = 0x0f;
3084 if (s
->device_id
== CIRRUS_ID_CLGD5446
) {
3085 /* 4MB 64 bit memory config, always PCI */
3086 s
->vga
.sr
[0x1F] = 0x2d; // MemClock
3087 s
->vga
.gr
[0x18] = 0x0f; // fastest memory configuration
3088 s
->vga
.sr
[0x0f] = 0x98;
3089 s
->vga
.sr
[0x17] = 0x20;
3090 s
->vga
.sr
[0x15] = 0x04; /* memory size, 3=2MB, 4=4MB */
3092 s
->vga
.sr
[0x1F] = 0x22; // MemClock
3093 s
->vga
.sr
[0x0F] = CIRRUS_MEMSIZE_2M
;
3094 s
->vga
.sr
[0x17] = s
->bustype
;
3095 s
->vga
.sr
[0x15] = 0x03; /* memory size, 3=2MB, 4=4MB */
3097 s
->vga
.cr
[0x27] = s
->device_id
;
3099 /* Win2K seems to assume that the pattern buffer is at 0xff
3101 memset(s
->vga
.vram_ptr
, 0xff, s
->real_vram_size
);
3103 s
->cirrus_hidden_dac_lockindex
= 5;
3104 s
->cirrus_hidden_dac_data
= 0;
3107 static void cirrus_init_common(CirrusVGAState
* s
, int device_id
, int is_pci
)
3114 for(i
= 0;i
< 256; i
++)
3115 rop_to_index
[i
] = CIRRUS_ROP_NOP_INDEX
; /* nop rop */
3116 rop_to_index
[CIRRUS_ROP_0
] = 0;
3117 rop_to_index
[CIRRUS_ROP_SRC_AND_DST
] = 1;
3118 rop_to_index
[CIRRUS_ROP_NOP
] = 2;
3119 rop_to_index
[CIRRUS_ROP_SRC_AND_NOTDST
] = 3;
3120 rop_to_index
[CIRRUS_ROP_NOTDST
] = 4;
3121 rop_to_index
[CIRRUS_ROP_SRC
] = 5;
3122 rop_to_index
[CIRRUS_ROP_1
] = 6;
3123 rop_to_index
[CIRRUS_ROP_NOTSRC_AND_DST
] = 7;
3124 rop_to_index
[CIRRUS_ROP_SRC_XOR_DST
] = 8;
3125 rop_to_index
[CIRRUS_ROP_SRC_OR_DST
] = 9;
3126 rop_to_index
[CIRRUS_ROP_NOTSRC_OR_NOTDST
] = 10;
3127 rop_to_index
[CIRRUS_ROP_SRC_NOTXOR_DST
] = 11;
3128 rop_to_index
[CIRRUS_ROP_SRC_OR_NOTDST
] = 12;
3129 rop_to_index
[CIRRUS_ROP_NOTSRC
] = 13;
3130 rop_to_index
[CIRRUS_ROP_NOTSRC_OR_DST
] = 14;
3131 rop_to_index
[CIRRUS_ROP_NOTSRC_AND_NOTDST
] = 15;
3132 s
->device_id
= device_id
;
3134 s
->bustype
= CIRRUS_BUSTYPE_PCI
;
3136 s
->bustype
= CIRRUS_BUSTYPE_ISA
;
3139 register_ioport_write(0x3c0, 16, 1, cirrus_vga_ioport_write
, s
);
3141 register_ioport_write(0x3b4, 2, 1, cirrus_vga_ioport_write
, s
);
3142 register_ioport_write(0x3d4, 2, 1, cirrus_vga_ioport_write
, s
);
3143 register_ioport_write(0x3ba, 1, 1, cirrus_vga_ioport_write
, s
);
3144 register_ioport_write(0x3da, 1, 1, cirrus_vga_ioport_write
, s
);
3146 register_ioport_read(0x3c0, 16, 1, cirrus_vga_ioport_read
, s
);
3148 register_ioport_read(0x3b4, 2, 1, cirrus_vga_ioport_read
, s
);
3149 register_ioport_read(0x3d4, 2, 1, cirrus_vga_ioport_read
, s
);
3150 register_ioport_read(0x3ba, 1, 1, cirrus_vga_ioport_read
, s
);
3151 register_ioport_read(0x3da, 1, 1, cirrus_vga_ioport_read
, s
);
3153 s
->vga
.vga_io_memory
= cpu_register_io_memory(cirrus_vga_mem_read
,
3154 cirrus_vga_mem_write
, s
);
3155 cpu_register_physical_memory(isa_mem_base
+ 0x000a0000, 0x20000,
3156 s
->vga
.vga_io_memory
);
3157 qemu_register_coalesced_mmio(isa_mem_base
+ 0x000a0000, 0x20000);
3159 /* I/O handler for LFB */
3160 s
->cirrus_linear_io_addr
=
3161 cpu_register_io_memory(cirrus_linear_read
, cirrus_linear_write
, s
);
3163 /* I/O handler for LFB */
3164 s
->cirrus_linear_bitblt_io_addr
=
3165 cpu_register_io_memory(cirrus_linear_bitblt_read
,
3166 cirrus_linear_bitblt_write
, s
);
3168 /* I/O handler for memory-mapped I/O */
3169 s
->cirrus_mmio_io_addr
=
3170 cpu_register_io_memory(cirrus_mmio_read
, cirrus_mmio_write
, s
);
3173 (s
->device_id
== CIRRUS_ID_CLGD5446
) ? 4096 * 1024 : 2048 * 1024;
3175 /* XXX: s->vga.vram_size must be a power of two */
3176 s
->cirrus_addr_mask
= s
->real_vram_size
- 1;
3177 s
->linear_mmio_mask
= s
->real_vram_size
- 256;
3179 s
->vga
.get_bpp
= cirrus_get_bpp
;
3180 s
->vga
.get_offsets
= cirrus_get_offsets
;
3181 s
->vga
.get_resolution
= cirrus_get_resolution
;
3182 s
->vga
.cursor_invalidate
= cirrus_cursor_invalidate
;
3183 s
->vga
.cursor_draw_line
= cirrus_cursor_draw_line
;
3185 qemu_register_reset(cirrus_reset
, s
);
3189 /***************************************
3193 ***************************************/
3195 void isa_cirrus_vga_init(void)
3199 s
= qemu_mallocz(sizeof(CirrusVGAState
));
3201 vga_common_init(&s
->vga
, VGA_RAM_SIZE
);
3202 cirrus_init_common(s
, CIRRUS_ID_CLGD5430
, 0);
3203 s
->vga
.ds
= graphic_console_init(s
->vga
.update
, s
->vga
.invalidate
,
3204 s
->vga
.screen_dump
, s
->vga
.text_update
,
3206 register_savevm("cirrus_vga", 0, 2, cirrus_vga_save
, cirrus_vga_load
, s
);
3207 /* XXX ISA-LFB support */
3210 /***************************************
3214 ***************************************/
3216 static void cirrus_pci_lfb_map(PCIDevice
*d
, int region_num
,
3217 uint32_t addr
, uint32_t size
, int type
)
3219 CirrusVGAState
*s
= &DO_UPCAST(PCICirrusVGAState
, dev
, d
)->cirrus_vga
;
3221 /* XXX: add byte swapping apertures */
3222 cpu_register_physical_memory(addr
, s
->vga
.vram_size
,
3223 s
->cirrus_linear_io_addr
);
3224 cpu_register_physical_memory(addr
+ 0x1000000, 0x400000,
3225 s
->cirrus_linear_bitblt_io_addr
);
3227 s
->vga
.map_addr
= s
->vga
.map_end
= 0;
3228 s
->vga
.lfb_addr
= addr
& TARGET_PAGE_MASK
;
3229 s
->vga
.lfb_end
= ((addr
+ VGA_RAM_SIZE
) + TARGET_PAGE_SIZE
- 1) & TARGET_PAGE_MASK
;
3230 /* account for overflow */
3231 if (s
->vga
.lfb_end
< addr
+ VGA_RAM_SIZE
)
3232 s
->vga
.lfb_end
= addr
+ VGA_RAM_SIZE
;
3234 vga_dirty_log_start(&s
->vga
);
3237 static void cirrus_pci_mmio_map(PCIDevice
*d
, int region_num
,
3238 uint32_t addr
, uint32_t size
, int type
)
3240 CirrusVGAState
*s
= &DO_UPCAST(PCICirrusVGAState
, dev
, d
)->cirrus_vga
;
3242 cpu_register_physical_memory(addr
, CIRRUS_PNPMMIO_SIZE
,
3243 s
->cirrus_mmio_io_addr
);
3246 static void pci_cirrus_write_config(PCIDevice
*d
,
3247 uint32_t address
, uint32_t val
, int len
)
3249 PCICirrusVGAState
*pvs
= DO_UPCAST(PCICirrusVGAState
, dev
, d
);
3250 CirrusVGAState
*s
= &pvs
->cirrus_vga
;
3252 pci_default_write_config(d
, address
, val
, len
);
3253 if (s
->vga
.map_addr
&& d
->io_regions
[0].addr
== -1)
3254 s
->vga
.map_addr
= 0;
3255 cirrus_update_memory_access(s
);
3258 static int pci_cirrus_vga_initfn(PCIDevice
*dev
)
3260 PCICirrusVGAState
*d
= DO_UPCAST(PCICirrusVGAState
, dev
, dev
);
3261 CirrusVGAState
*s
= &d
->cirrus_vga
;
3262 uint8_t *pci_conf
= d
->dev
.config
;
3263 int device_id
= CIRRUS_ID_CLGD5446
;
3266 vga_common_init(&s
->vga
, VGA_RAM_SIZE
);
3267 cirrus_init_common(s
, device_id
, 1);
3268 s
->vga
.ds
= graphic_console_init(s
->vga
.update
, s
->vga
.invalidate
,
3269 s
->vga
.screen_dump
, s
->vga
.text_update
,
3273 pci_config_set_vendor_id(pci_conf
, PCI_VENDOR_ID_CIRRUS
);
3274 pci_config_set_device_id(pci_conf
, device_id
);
3275 pci_conf
[0x04] = PCI_COMMAND_IOACCESS
| PCI_COMMAND_MEMACCESS
;
3276 pci_config_set_class(pci_conf
, PCI_CLASS_DISPLAY_VGA
);
3277 pci_conf
[PCI_HEADER_TYPE
] = PCI_HEADER_TYPE_NORMAL
;
3279 /* setup memory space */
3281 /* memory #1 memory-mapped I/O */
3282 /* XXX: s->vga.vram_size must be a power of two */
3283 pci_register_bar((PCIDevice
*)d
, 0, 0x2000000,
3284 PCI_ADDRESS_SPACE_MEM_PREFETCH
, cirrus_pci_lfb_map
);
3285 if (device_id
== CIRRUS_ID_CLGD5446
) {
3286 pci_register_bar((PCIDevice
*)d
, 1, CIRRUS_PNPMMIO_SIZE
,
3287 PCI_ADDRESS_SPACE_MEM
, cirrus_pci_mmio_map
);
3289 register_savevm("cirrus_vga", 0, 2, pci_cirrus_vga_save
, pci_cirrus_vga_load
, d
);
3294 void pci_cirrus_vga_init(PCIBus
*bus
)
3296 pci_create_simple(bus
, -1, "Cirrus VGA");
3299 static PCIDeviceInfo cirrus_vga_info
= {
3300 .qdev
.name
= "Cirrus VGA",
3301 .qdev
.size
= sizeof(PCICirrusVGAState
),
3302 .init
= pci_cirrus_vga_initfn
,
3303 .config_write
= pci_cirrus_write_config
,
3306 static void cirrus_vga_register(void)
3308 pci_qdev_register(&cirrus_vga_info
);
3310 device_init(cirrus_vga_register
);